[Orxonox-commit 4294] r8965 - code/branches/formation/src/orxonox/controllers

willis at orxonox.net willis at orxonox.net
Wed Dec 7 16:00:38 CET 2011


Author: willis
Date: 2011-12-07 16:00:37 +0100 (Wed, 07 Dec 2011)
New Revision: 8965

Modified:
   code/branches/formation/src/orxonox/controllers/AIController.cc
   code/branches/formation/src/orxonox/controllers/HumanController.cc
   code/branches/formation/src/orxonox/controllers/HumanController.h
   code/branches/formation/src/orxonox/controllers/Masterable.cc
   code/branches/formation/src/orxonox/controllers/Masterable.h
   code/branches/formation/src/orxonox/controllers/NewHumanController.cc
Log:
added some Mode features, fixed a speed issue

Modified: code/branches/formation/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/AIController.cc	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/AIController.cc	2011-12-07 15:00:37 UTC (rev 8965)
@@ -122,6 +122,11 @@
                this->searchNewTarget();
             }
 
+            // next enemy
+            random = rnd(maxrand);
+            if (random < 10 && (this->target_))
+                this->searchNewTarget();
+
             // shoot
             random = rnd(maxrand);
             if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))

Modified: code/branches/formation/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.cc	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/HumanController.cc	2011-12-07 15:00:37 UTC (rev 8965)
@@ -173,7 +173,14 @@
     void HumanController::doFire(unsigned int firemode)
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+        {
             HumanController::localController_s->controllableEntity_->fire(firemode);
+            //if human fires, set slaves free. See Masterable::forceFreeSlaves()
+            if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->mode_==NORMAL)
+            {
+                HumanController::localController_s->forceFreeSlaves();
+            }
+        }
     }
 
     void HumanController::reload()
@@ -323,15 +330,17 @@
                 orxout(message) <<"Mode: NORMAL "<< endl;
                 break;
             }
-            changedMode();
         }
     }
 
-    void HumanController::changedMode()
+
+    //used, when slaves are in DEFEND mode.
+    void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     {
+        if (!this->formationFlight_ || this->state_!=MASTER || this->mode_!=DEFEND) return;
+            this->masterAttacked(originator);
+    }
 
-    }
-    
     void HumanController::addBots(unsigned int amount)
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())

Modified: code/branches/formation/src/orxonox/controllers/HumanController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.h	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/HumanController.h	2011-12-07 15:00:37 UTC (rev 8965)
@@ -87,8 +87,9 @@
 
             static void toggleFormationFlight();
             static void FFChangeMode();
-            static void changedMode();
+            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
 
+
             static void addBots(unsigned int amount);
             static void killBots(unsigned int amount = 0);
 

Modified: code/branches/formation/src/orxonox/controllers/Masterable.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.cc	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/Masterable.cc	2011-12-07 15:00:37 UTC (rev 8965)
@@ -318,9 +318,9 @@
 		    {
 			copyTargetOrientation();
 		    }
-                if (distance < 40)
-                {
-                    this->getControllableEntity()->moveFrontBack(0.2f*SPEED_MASTER);
+                if (distance < 100)
+                {   //linear speed reduction
+                    this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
 		   
                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
 
@@ -450,9 +450,7 @@
         {
             this->state_ = MASTER;
             this->myMaster_ = 0;
-            orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl;
-        } else if (this->state_ != SLAVE)
-            orxout(debug_output) << "search new master: no master found, no teammates..."<< endl;
+        }
     }
  /**
         @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
@@ -619,18 +617,24 @@
             {
                  (*it)->myMaster_=this;
             }
+            this->myMaster_=0;
             this->state_=MASTER;
         }
-        //debug
+        /*/debug
         if (this->state_==SLAVE)
            {orxout(debug_output) << this << " is slave "<< endl;}
         else if (this->state_==MASTER)
            {orxout(debug_output) << this << " is now a master of "<<this->slaves_.size()<<" slaves."<< endl;}
         if (this->state_==FREE)
-           {orxout(debug_output) << this << " is free "<< endl;}
+           {orxout(debug_output) << this << " is free "<< endl;}*/
     }
 
+    void Masterable::masterAttacked(Pawn* originator)
+    {
+       orxout(debug_output)<<"slaves, attack!"<<endl;
+    }     
 
+
     /**
       @brief Sets the new mode. If master, set it for all slaves.
     */
@@ -903,109 +907,6 @@
         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)
@@ -1045,7 +946,6 @@
 
             if (entity2->getPlayer())
                 team2 = tdm->getTeam(entity2->getPlayer());
-            return (team1 == team2 && team1 != -1); //temp solution
         }
 
         TeamBaseMatchBase* base = 0;

Modified: code/branches/formation/src/orxonox/controllers/Masterable.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.h	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/Masterable.h	2011-12-07 15:00:37 UTC (rev 8965)
@@ -77,7 +77,7 @@
 
       inline void setTeam(int team)
            { this->team_ = team; 
-             orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;}
+             orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;} 
       inline int getTeam() const
            { return this->team_; }
 
@@ -133,6 +133,7 @@
       bool forcedFree();
 
       void takeLeadOfFormation();
+      void masterAttacked(Pawn* originator);      
 
       void specificMasterActionHold();
       void turn180Init();

Modified: code/branches/formation/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/NewHumanController.cc	2011-12-07 14:22:46 UTC (rev 8964)
+++ code/branches/formation/src/orxonox/controllers/NewHumanController.cc	2011-12-07 15:00:37 UTC (rev 8965)
@@ -296,6 +296,9 @@
 
     void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     {
+        //Used in HumanController for formationFlight
+        HumanController::hit(originator,contactpoint,damage);
+        
         if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
         {
             Vector3 posA;




More information about the Orxonox-commit mailing list