[Orxonox-commit 4286] r8957 - code/branches/formation/src/orxonox/controllers

willis at orxonox.net willis at orxonox.net
Wed Dec 7 13:50:41 CET 2011


Author: willis
Date: 2011-12-07 13:50:40 +0100 (Wed, 07 Dec 2011)
New Revision: 8957

Modified:
   code/branches/formation/src/orxonox/controllers/Masterable.cc
   code/branches/formation/src/orxonox/controllers/Masterable.h
Log:
fixed a bug in searchnewMaster

Modified: code/branches/formation/src/orxonox/controllers/Masterable.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.cc	2011-11-30 16:12:00 UTC (rev 8956)
+++ code/branches/formation/src/orxonox/controllers/Masterable.cc	2011-12-07 12:50:40 UTC (rev 8957)
@@ -39,6 +39,7 @@
 #include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
 #include "gametypes/Dynamicmatch.h"
+#include "gametypes/Gametype.h"
 #include "controllers/WaypointPatrolController.h"
 #include "controllers/NewHumanController.h"
 #include "controllers/DroneController.h"
@@ -392,7 +393,12 @@
         {
            
             //same team?
-            if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+            Gametype* gt=this->getGametype();
+            if (!gt)
+            {
+                gt=it->getGametype();
+            }
+            if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it),gt))
                 continue;
 
             //has it an Masterable?
@@ -897,6 +903,109 @@
         this->searchRandomTargetPosition();
     }
 
+/*
+    bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    {
+        if (!entity1 || !entity2) return false;
+        if (entity1 == entity2) return true;
+
+        if (!gametype)
+            orxout(debug_output) << "gametype NULL"<< endl;
+
+        int team1 = -1;
+        int team2 = -1;
+
+        TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
+        if (tdm)
+        {
+            if (entity1->getPlayer())
+                team1 = tdm->getTeam(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = tdm->getTeam(entity2->getPlayer());
+             orxout(debug_output) << "teamdeath okay"<< endl;
+        }
+
+        if (team1!=-1 && team2!=-1)
+        {
+            orxout(debug_output) << "Sameteam: decided in TeamDeathmatch. return "<<(team1 == team2 && team1 != -1)<< endl;
+            return (team1 == team2 && team1 != -1); 
+        }
+        team1=team2=-1;
+        orxout(debug_output) << "Sameteam: not in teamdeathmatch."<< endl;
+        TeamBaseMatchBase* base = 0;
+        base = orxonox_cast<TeamBaseMatchBase*>(entity1);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team1 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team1 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team1 = -1;
+            }
+        }
+        base = orxonox_cast<TeamBaseMatchBase*>(entity2);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team2 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team2 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team2 = -1;
+            }
+        }
+
+        if (team1!=-1 && team2!=-1)
+            return (team1 == team2 && team1 != -1); 
+        team1=team2=-1;
+
+
+        DroneController* droneController = 0;
+        droneController = orxonox_cast<DroneController*>(entity1->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+            return true;
+        droneController = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+            return true;
+        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+            return true;
+
+        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+
+            if (team1 ==-1 ||team2 ==-1 ) {return false;}
+            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+            else return true;
+        }
+
+        return (team1 == team2 && team1 != -1);
+
+    }*/
+
   bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     {
         if (entity1 == entity2)

Modified: code/branches/formation/src/orxonox/controllers/Masterable.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.h	2011-11-30 16:12:00 UTC (rev 8956)
+++ code/branches/formation/src/orxonox/controllers/Masterable.h	2011-12-07 12:50:40 UTC (rev 8957)
@@ -76,7 +76,8 @@
            { return this->passive_; }
 
       inline void setTeam(int team)
-           { this->team_ = team; }
+           { this->team_ = team; 
+             orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;}
       inline int getTeam() const
            { return this->team_; }
 




More information about the Orxonox-commit mailing list