[Orxonox-commit 3134] r7827 - code/branches/ai/src/orxonox/controllers

jo at orxonox.net jo at orxonox.net
Thu Jan 13 20:25:19 CET 2011


Author: jo
Date: 2011-01-13 20:25:19 +0100 (Thu, 13 Jan 2011)
New Revision: 7827

Added:
   code/branches/ai/src/orxonox/controllers/Detector.cc
   code/branches/ai/src/orxonox/controllers/Detector.h
Modified:
   code/branches/ai/src/orxonox/controllers/CMakeLists.txt
Log:
First draft. The detector tries to detect events that are critical for ai-bots. Furthermore the detected events have to be further analyzed.

Modified: code/branches/ai/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/ai/src/orxonox/controllers/CMakeLists.txt	2011-01-13 19:22:15 UTC (rev 7826)
+++ code/branches/ai/src/orxonox/controllers/CMakeLists.txt	2011-01-13 19:25:19 UTC (rev 7827)
@@ -8,4 +8,5 @@
   WaypointController.cc
   WaypointPatrolController.cc
   DroneController.cc
+  Detector.cc
 )

Added: code/branches/ai/src/orxonox/controllers/Detector.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/Detector.cc	                        (rev 0)
+++ code/branches/ai/src/orxonox/controllers/Detector.cc	2011-01-13 19:25:19 UTC (rev 7827)
@@ -0,0 +1,106 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more detls.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Johannes Ritz
+ *   Co-authors:
+ *      
+ *
+ */
+
+#include "Detector.h"
+
+#include "util/Math.h"
+#include "core/CoreIncludes.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+    const float NOT_UNDER_ATTACK_LIMIT=2.0f;
+
+    CreateFactory(Detector);
+
+    Detector::Detector(BaseObject* creator) : ArtificialController(creator)
+    {
+        RegisterObject(Detector);
+        this->healthLost = 0;
+        this->notUnderAttackTime = 2.0f;
+        this->bUnderAttack = false;
+        this->bot_ = orxonox_cast<Pawn*>(this->getControllableEntity());
+        if(bot_)
+            this->previousHealth = bot_->getHealth();
+        else
+            this->previousHealth = 0;
+        this->botLevel = 10.0f;
+        this->attacker_=0;
+    }
+
+    Detector::~Detector()
+    {
+    }
+    
+    void Detector::tick(float dt) //TODO: set a checking interval depending on ai-level
+    {
+        SUPER(Detector, tick, dt);
+        
+        notUnderAttackTime += dt;
+        if(bot_)
+        {
+            this->checkHealth();
+        }
+        else
+        {
+            bot_ = orxonox_cast<Pawn*>(this->getControllableEntity());
+        }
+        bUnderAttack = this->checkUnderAttack();
+    }
+    
+    void Detector::checkHealth() //finds out if bot lost life
+    {
+        float actualHealth = this->bot_->getHealth();
+        healthLost = previousHealth - actualHealth;
+        if (healthLost>0)
+        {
+            notUnderAttackTime=0;
+            this->analyseAttack();
+        }
+        previousHealth = actualHealth;
+    }
+    
+    bool Detector::checkUnderAttack()
+    {
+        return (NOT_UNDER_ATTACK_LIMIT > notUnderAttackTime);
+    }
+    
+    void Detector::analyseAttack()
+    {
+        if (attacker_)//attacker is already known
+            return;
+        else
+        {
+        ;
+        }       
+        ;//?? from where came the attack;
+        //Kombination aus isLooking at und object list und ???
+        //idea: if the attacker is viewable he is known. Else the attacking direction is know.
+        //callForHelp-Function to friendly pawns
+    }
+}

Added: code/branches/ai/src/orxonox/controllers/Detector.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/Detector.h	                        (rev 0)
+++ code/branches/ai/src/orxonox/controllers/Detector.h	2011-01-13 19:25:19 UTC (rev 7827)
@@ -0,0 +1,71 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more detls.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Johannes Ritz
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file Detector.h
+    @brief Definition of the Dectector class.
+*/
+
+#ifndef _Detector_H__
+#define _Detector_H__
+
+#include "OrxonoxPrereqs.h"
+
+//#include "core/BaseObject.h"
+#include "ArtificialController.h"
+#include "tools/interfaces/Tickable.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport Detector : public ArtificialController, public Tickable
+    {
+        public:
+            Detector(BaseObject* creator);
+            virtual ~Detector();
+            
+            virtual void tick(float dt);//< Each tick the actual situation is compared to the previous situation.
+            void checkHealth();//< Calls analyseAttack, if life is lost. TODO: what about damage of non-enemy sources?
+            bool checkUnderAttack(); //< Returns false if the enemy's attack (lifeloss) is temporarly over.
+            
+            
+            void analyseAttack(); //
+            
+        protected:
+            float botLevel;
+            WeakPtr<Pawn> bot_;
+            
+            float healthLost;
+            float previousHealth;
+            float notUnderAttackTime;
+            bool bUnderAttack;
+            WeakPtr<Pawn> attacker_;
+
+    };
+}
+
+#endif /* _Detector_H__ */




More information about the Orxonox-commit mailing list