[Orxonox-commit 1140] r5861 - in code/branches/core5/src: libraries/core orxonox/controllers orxonox/gametypes orxonox/worldentities/pawns

landauf at orxonox.net landauf at orxonox.net
Fri Oct 2 20:58:27 CEST 2009


Author: landauf
Date: 2009-10-02 20:58:27 +0200 (Fri, 02 Oct 2009)
New Revision: 5861

Modified:
   code/branches/core5/src/libraries/core/WeakPtr.h
   code/branches/core5/src/orxonox/controllers/ArtificialController.cc
   code/branches/core5/src/orxonox/controllers/ArtificialController.h
   code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
   code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc
Log:
un-PawnListener-ized ArtificialController

Modified: code/branches/core5/src/libraries/core/WeakPtr.h
===================================================================
--- code/branches/core5/src/libraries/core/WeakPtr.h	2009-10-02 18:41:33 UTC (rev 5860)
+++ code/branches/core5/src/libraries/core/WeakPtr.h	2009-10-02 18:58:27 UTC (rev 5861)
@@ -167,7 +167,7 @@
                 WeakPtr().swap(*this);
             }
             
-            inline void addCallback(Functor* callback)
+            inline void setCallback(Functor* callback)
             {
                 this->callback_ = callback;
             }

Modified: code/branches/core5/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/core5/src/orxonox/controllers/ArtificialController.cc	2009-10-02 18:41:33 UTC (rev 5860)
+++ code/branches/core5/src/orxonox/controllers/ArtificialController.cc	2009-10-02 18:58:27 UTC (rev 5861)
@@ -45,6 +45,8 @@
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
         this->targetPosition_ = Vector3::ZERO;
+        
+        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     }
 
     ArtificialController::~ArtificialController()
@@ -161,15 +163,18 @@
         return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
     }
 
-    void ArtificialController::destroyedPawn(Pawn* ship)
+    void ArtificialController::abandonTarget(Pawn* target)
     {
-        if (ship == this->target_)
-        {
-            this->forgetTarget();
-            this->searchRandomTargetPosition();
-        }
+        if (target == this->target_)
+            this->targetDied();
     }
 
+    void ArtificialController::targetDied()
+    {
+        this->forgetTarget();
+        this->searchRandomTargetPosition();
+    }
+
     bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     {
         if (entity1 == entity2)

Modified: code/branches/core5/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/core5/src/orxonox/controllers/ArtificialController.h	2009-10-02 18:41:33 UTC (rev 5860)
+++ code/branches/core5/src/orxonox/controllers/ArtificialController.h	2009-10-02 18:58:27 UTC (rev 5861)
@@ -32,20 +32,21 @@
 #include "OrxonoxPrereqs.h"
 
 #include "util/Math.h"
-#include "interfaces/PawnListener.h"
 #include "Controller.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport ArtificialController : public Controller, public PawnListener
+    class _OrxonoxExport ArtificialController : public Controller
     {
         public:
             ArtificialController(BaseObject* creator);
             virtual ~ArtificialController();
+            
+            void abandonTarget(Pawn* target);
 
-            virtual void destroyedPawn(Pawn* pawn);
+        protected:
+            void targetDied();
 
-        protected:
             void moveToPosition(const Vector3& target);
             void moveToTargetPosition();
 
@@ -64,7 +65,7 @@
 
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
-            Pawn* target_;
+            WeakPtr<Pawn> target_;
             bool bShooting_;
 
         private:

Modified: code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/UnderAttack.cc	2009-10-02 18:41:33 UTC (rev 5860)
+++ code/branches/core5/src/orxonox/gametypes/UnderAttack.cc	2009-10-02 18:58:27 UTC (rev 5861)
@@ -45,7 +45,7 @@
         this->gameTime_ = 180;
         this->teams_ = 2;
         this->destroyer_ = 0;
-        this->destroyer_.addCallback(createFunctor(&UnderAttack::killedDestroyer, this));
+        this->destroyer_.setCallback(createFunctor(&UnderAttack::killedDestroyer, this));
         this->gameEnded_ = false;
 
         this->setHUDTemplate("UnderAttackHUD");

Modified: code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc	2009-10-02 18:41:33 UTC (rev 5860)
+++ code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc	2009-10-02 18:58:27 UTC (rev 5861)
@@ -30,7 +30,7 @@
 #include "TeamBaseMatchBase.h"
 
 #include "core/CoreIncludes.h"
-#include "interfaces/PawnListener.h"
+#include "controllers/ArtificialController.h"
 #include "interfaces/TeamColourable.h"
 #include "gametypes/TeamBaseMatch.h"
 
@@ -91,8 +91,8 @@
         this->setRadarObjectColour(colour);
 
         // Call this so bots stop shooting at the base after they converted it
-        for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
-            it->destroyedPawn(this);
+        for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
+            it->abandonTarget(this);
     }
 }
 




More information about the Orxonox-commit mailing list