[Orxonox-commit 6266] r10923 - in code/branches/campaignHS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Mon Dec 7 08:34:20 CET 2015


Author: gania
Date: 2015-12-07 08:34:20 +0100 (Mon, 07 Dec 2015)
New Revision: 10923

Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
check in

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-12-07 07:34:20 UTC (rev 10923)
@@ -91,7 +91,7 @@
 
 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 
 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
-      <!--  
+       
     <Model mesh="cube.mesh" scale=8 position="0,0,0" />
 
     <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
@@ -152,11 +152,11 @@
         <Template link=spaceshipassff />
       </templates>
     </SpaceShip> 
-  -->
+ 
    
 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
 <!-- HERE STARTS DEMO FOR FIGHTING -->
-    
+    <!-- 
 
     <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="d1sd1">
       <templates>
@@ -195,44 +195,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="-5000, 1500, -1000" lookat="0,0,0" team=0 name="d1s1d1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=0 formationMode="WALL">
 
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-5000, 1900, -1000" lookat="0,0,0" team=0 name="d1s1s1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=0>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-5000, 2100, -1000" lookat="0,0,0" team=0 name="d1s1w1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=0>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-5000, 2400, -1000" lookat="0,0,0" team=0 name="d1s1w2">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=0>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-
     <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1  name="d2sd1">
       <templates>
         <Template link=spaceshipassff />
@@ -270,44 +233,7 @@
         </WingmanController>
       </controller>
     </SpaceShip> 
-    <SpaceShip position="1000, -1500, 1000" lookat="0,0,0" team=1  name="d2s1d1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=1 formationMode="WALL">
-
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="1000, -1900, 1000" lookat="0,0,0" team=1 name="d2s1s1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=1>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="1000, -2100, 1000" lookat="0,0,0" team=1 name="d2s1w1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="1000, -2400, 1000" lookat="0,0,0" team=1 name="d2s1w2">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip> 
-
+ -->
 <!-- HERE ENDS DEMO FOR FIGHTING -->
 <!-- HERE STARTS DEMO FOR FORMATIONS -->
     <!-- 

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -39,18 +39,16 @@
 
     ActionpointController::ActionpointController(Context* context) : FightingController(context)
     {
+        this->ticks_ = 0;
         this->bPatrolling_ = false;
-
-        this->actionCounter_ = 0;
+        this->maneuverCounter_ = 0;
         this->bInLoop_ = false;
         this->bLoop_ = false;
         this->bEndLoop_ = false;
         loopActionpoints_.clear();
         parsedActionpoints_.clear();
         actionpoints_.clear();
-        healthSpawners_.clear();
-        damageSpawners_.clear();
-        speedSpawners_.clear();
+
         this->bTakenOver_ = false;
         this->action_ = Action::NONE;
         this->squaredaccuracy_ = 2500;
@@ -95,38 +93,47 @@
         loopActionpoints_.clear();
         parsedActionpoints_.clear();
         actionpoints_.clear();
-        healthSpawners_.clear();
-        damageSpawners_.clear();
-        speedSpawners_.clear();
+        ActionpointController::nextActionpointControllerId_--;
+        if (ActionpointController::nextActionpointControllerId_ < 0)
+            ActionpointController::nextActionpointControllerId_ = 0;
     }
     void ActionpointController::tick(float dt)
     {
-        if (!this->getControllableEntity())
+        if (!this || !this->getControllableEntity())
             return;
-        if (stop_)
-            return;
-        if (this->timeout_ > 0 && this->bFiredRocket_)
+        ++this->ticks_;
+        // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl;
+        if (ActionpointController::sTicks_ < this->ticks_)
         {
-            this->timeout_ -= dt;
+            // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl;
+            ++ActionpointController::sTicks_;
         }
-        if (this->bStartedDodging_)
+
+        if (this->ticks_ == 1)
         {
-            this->timeDodged_ += dt;
-            if (this->timeDodged_ > 4.0f)
+
+            this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++;
+            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
+            std::reverse(actionpoints_.begin(), actionpoints_.end());
+            if (this->parsedActionpoints_.empty())
             {
-                this->bStartedDodging_ = false;
-                this->timeDodged_ = 0;
+                this->action_ = Action::FIGHTALL;
             }
         }
-        maneuverCounter_ += dt;
-        if (maneuverCounter_ > 6.0f)
-            maneuverCounter_ = 0;
-        this->timeOffset_ += dt;
-        if (this->timeOffset_ >= 2.4f)
+        if (this->ticks_ == 1)
+        {    
             this->timeOffset_ = 0.0f;
-        if (timeout_ <= 0)
-            this->bFiredRocket_ = false;
-
+            this->bActionCalled_ = false;
+            
+            this->bFirstTick_ = false;
+        }
+/*        if (ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_+1) != this->actionpointControllerId_)
+        {
+            return;
+        }*/
+        if (!this || !this->getControllableEntity())
+            return;
+        
         if (this->bHasTargetPosition_)
         {
             this->moveToTargetPosition(dt);
@@ -135,50 +142,68 @@
         {
             this->lookAtTarget(dt);
         }
-
-        if (!this->getControllableEntity())
-            return;
         if (this->bShooting_)
         {
             this->doFire();
         }
-        if (this->bFirstTick_)
+
+        if (!this || !this->getControllableEntity())
+            return;
+        
+        if (stop_)
+            return;
+        
+        this->timeOffset_ += dt;
+        if (this->timeOffset_ >= 2.4f)
+            this->timeOffset_ = 0.0f;
+        if (timeout_ <= 0)
+            this->bFiredRocket_ = false;
+        if (!this || !this->getControllableEntity())
+            return;
+
+        if (!this || !this->getControllableEntity())
+            return;
+        if (this->timeout_ > 0 && this->bFiredRocket_)
+            {
+                this->timeout_ -= dt;
+            }
+            if (this->bStartedDodging_)
+            {
+                this->timeDodged_ += dt;
+            }
+            maneuverCounter_ += dt;
+
+        //maneuver every 0.25 sec -> 
+        int step =  5;
+        if (this->hasTarget() && ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_) + 3)
         {
-            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
-            std::reverse(actionpoints_.begin(), actionpoints_.end());
-            if (this->parsedActionpoints_.empty())
+            if (maneuverCounter_ > 6.0f)
+                maneuverCounter_ = 0;
+            if (this->bStartedDodging_ &&  this->timeDodged_ > 4.0f)
             {
-                this->action_ = Action::FIGHTALL;
+                this->bStartedDodging_ = false;
+                this->timeDodged_ = 0;
             }
+            this->maneuver();
         }
-        if (this->bFirstTick_)
-        {    
-            this->timeOffset_ = 0.0f;
-            this->bActionCalled_ = false;
-            setSpawners();
-            // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() <<
-            // ", damage spawners size = " << this->damageSpawners_.size() <<
-            // ", speed spawners size = " << this->speedSpawners_.size() << endl;        
-            this->bFirstTick_ = false;
+        if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
+        {
+            this->action();
         }
-        if (!this->getControllableEntity())
+        if (!this || !this->getControllableEntity())
             return;
-        //maneuver every 0.25 sec -> 
-        if (this->hasTarget() && 
-            ((this->timeOffset_ >= 0.4f && this->timeOffset_ < 0.8f) || 
-             (this->timeOffset_ >= 1.2f && this->timeOffset_ < 1.6f) ||
-             (this->timeOffset_ >= 1.8f && this->timeOffset_ < 2.0f) ||
-             (this->timeOffset_ >= 2.2f && this->timeOffset_ < 2.4f)) && !this->bManeuverCalled_)
+
+        if (!this || !this->getControllableEntity())
+            return;
+        if (this->hasTarget() &&  ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_))
         {
-            this->bManeuverCalled_ = true;
-            this->maneuver();
             this->bShooting_ = this->canFire();
+            
         }
-        if ((this->timeOffset_ >= 0.0f && this->timeOffset_ < 0.4f) || 
-             (this->timeOffset_ >= 0.8f && this->timeOffset_ < 1.2f) ||
-             (this->timeOffset_ >= 1.6f && this->timeOffset_ < 1.8f) ||
-             (this->timeOffset_ >= 2.0f && this->timeOffset_ < 2.2f))
-            this->bManeuverCalled_ = false;
+        if (!this || !this->getControllableEntity())
+            return;
+        
+
         SUPER(ActionpointController, tick, dt);
     }
      
@@ -194,20 +219,18 @@
         {
             this->startAttackingEnemiesThatAreClose();
         }
+        if (!this || !this->getControllableEntity())
+            return;
+
         this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
         this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
+        if (!this || !this->getControllableEntity())
+            return;
 
         // if (this->actionCounter_ % 2 == 0)
         //No action -> pop one from stack
         if (this->action_ == Action::NONE || this->bTakenOver_)
         {
-            // Point point = closestPickup(PickupType::HEALTH);
-            // if (point.action != Action::NONE)
-            // {
-            //     orxout(internal_error) << "found health" << endl;
-            //     this->parsedActionpoints_.push_back(point);
-            // }
-
             if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
             {
                 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
@@ -217,6 +240,9 @@
             this->bTakenOver_ = false;
             // this->action();
         }
+        if (!this || !this->getControllableEntity())
+            return;
+
         //Action fightall -> fight till nobody alive
         if (this->action_ == Action::FIGHTALL)
         {
@@ -306,20 +332,6 @@
             }
         }
 
-            // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
-            // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
-            // {
-            //     //----choose where to go----
-            //     this->maneuver();
-            // }
-            // else
-            // {
-            //     this->dodgeTowards(healthPosition);
-            // }
-            // //----fire if you can----
-            // this->bShooting_ = this->canFire();  
-         
-        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
 
     }
     void ActionpointController::setProtect (ControllableEntity* protect)
@@ -401,17 +413,17 @@
         switch ( this->action_ )
         {
             case Action::FIGHT:
-            { return "FIGHT"; break; }
+            { return "FIGHT"; }
             case Action::FLY:
-            { return "FLY"; break; }
+            { return "FLY"; }
             case Action::PROTECT:
-            { return "PROTECT"; break; }
+            { return "PROTECT"; }
             case Action::NONE:
-            { return "NONE"; break; }
+            { return "NONE"; }
             case Action::FIGHTALL:
-            { return "FIGHTALL"; break; }
+            { return "FIGHTALL"; }
             case Action::ATTACK:
-            { return "ATTACK"; break; }
+            { return "ATTACK"; }
             default:
                 return "NONE";
                 break;
@@ -461,6 +473,9 @@
     //if last element was failed to be parsed, next element will be executed.
     void ActionpointController::executeActionpoint()
     {
+        if (!this || !this->getControllableEntity())
+            return;
+
         Point p;
         if (this->bLoop_ && !loopActionpoints_.empty())
         {
@@ -477,6 +492,9 @@
         }
         else
         {
+            if (!this || !this->getControllableEntity())
+                return;
+
             this->setTarget(0);
             this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
             this->action_ = Action::NONE;
@@ -519,7 +537,9 @@
             }
             case Action::PROTECT:
             {
-                
+                if (!this || !this->getControllableEntity())
+                    return;
+
                 std::string protectName = p.name;
                 if (protectName == "reservedKeyword:human")
                 {
@@ -582,6 +602,9 @@
     
     void ActionpointController::stayNearProtect()
     {
+        if (!this || !this->getControllableEntity())
+            return;
+
         Vector3 targetRelativePosition(0, 300, 300);
         if (!this->getProtect())
         {
@@ -664,7 +687,7 @@
     }
     Pawn* ActionpointController::closestTarget()
     {
-        if (!this->getControllableEntity())
+        if (!this || !this->getControllableEntity())
             return 0;
 
         Pawn* closestTarget = 0;
@@ -690,6 +713,9 @@
     }
     void ActionpointController::startAttackingEnemiesThatAreClose()
     {
+        if (!this || !this->getControllableEntity())
+            return;
+
         //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
         {
             if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
@@ -699,6 +725,8 @@
                     CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
                         <= this->attackRange_ )
                 {
+                    if (!this || !this->getControllableEntity())
+                        return;
                     this->setTarget(newTarget);
                     if (this->bLoop_ && !this->bPatrolling_)
                     {
@@ -717,125 +745,6 @@
             }
         }
     }
-    Vector3 ActionpointController::bestHealthPickup(float searchRadius)
-    {
-
-        //1000000/distance^2 * 1/index+1
-        float maxUse = 0;
-        float tempUse = -1;
-        int index = 0;
-        float distance = 0;
-        Vector3 bestPosition = this->getControllableEntity()->getWorldPosition();
-
-        for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it)
-        {
-            distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length();
-            if (distance < this->tolerance_ || !(*it).second.second)
-            {
-                (*it).second.second = false;
-                continue;
-            }
-            if (distance > searchRadius)
-                continue;
-            index = (*it).first;
-            tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1);
-            if (tempUse > maxUse)
-            {
-                bestPosition = (*it).second.first->getWorldPosition();
-                maxUse = tempUse;
-            }
-        }
-        //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index);
-        //P.S. check if it == ... .end()
-        //orxout (internal_error) << "best position = " << bestPosition << endl;
-        return  bestPosition;
-    }
-    void ActionpointController::setSpawners()
-    {
-        std::vector<std::string> damagePickups;
-        std::vector<std::string> healthPickups;
-        std::vector<std::string> speedPickups;       
-        int index = 0;
-
-
-        damagePickups.push_back("largedamageboostpickup");
-        damagePickups.push_back("dronepickup");            
-        damagePickups.push_back("mediumdamageboostpickup");
-        damagePickups.push_back("smalldamageboostpickup");
-
-        healthPickups.push_back("triplehealthspeedinvisibilitypickup");            
-        healthPickups.push_back("crazyhealthpickup");
-        healthPickups.push_back("hugehealthpickup");
-        healthPickups.push_back("hugeshieldpickup");
-        healthPickups.push_back("hugeinvisiblepickup");
-        healthPickups.push_back("hugeshrinkpickup");
-        healthPickups.push_back("mediumhealthpickup");
-        healthPickups.push_back("mediumshieldpickup");
-        healthPickups.push_back("mediuminvisiblepickup");
-        healthPickups.push_back("mediumshrinkpickup");  
-        healthPickups.push_back("smallhealthpickup");                   
-        healthPickups.push_back("smallshieldpickup");
-        healthPickups.push_back("smallinvisiblepickup");
-        healthPickups.push_back("smallshrinkpickup");
-
-        speedPickups.push_back("triplehealthspeedinvisibilitypickup");
-        speedPickups.push_back("hugespeedpickup");
-        speedPickups.push_back("smalljumppickup");
-        speedPickups.push_back("mediumspeedpickup");
-        speedPickups.push_back("smallspeedpickup");
-        
-
-
-        for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it)
-        {
-            if ((*it)->getIdentifier()->getName() != "PickupSpawner")
-                continue;
-            PickupSpawner* spawner = static_cast<PickupSpawner*>(*it);
-            std::string name = spawner->getPickupTemplateName();
-            //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length(); 
-            // if (distance < 50.0f)
-            //     continue;           
-            for (unsigned int i = 0; i < healthPickups.size(); ++i)
-            {
-                if (name == healthPickups.at(i))
-                {
-                    index = i;
-                    this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
-                    break;
-                }
-            }
-            for (unsigned int i = 0; i < damagePickups.size(); ++i)
-            {
-                if (name == damagePickups.at(i))
-                {
-                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
-                    index = i;
-                    this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
-                    break;
-                }
-            }
-            for (unsigned int i = 0; i < speedPickups.size(); ++i)
-            {
-                if (name == speedPickups.at(i))
-                {
-                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
-                    index = i;
-                    this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
-                    break;
-                }
-            }
-            // if (tempUse > maxUse)
-            // {
-            //     Point p = { Action::FLY, "", (*it)->getWorldPosition(), false };
-            //     maxUse = tempUse;
-            //     maxPoint = p;
-            // }
-            // else
-            // {
-            //     tempUse = -1;
-            //     continue;
-            // }
-            // orxout(internal_error) << "resp time  = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl;
-        }  
-    }
-}
+    int ActionpointController::nextActionpointControllerId_ = 0;
+    int ActionpointController::sTicks_ = 0;
+}   

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-07 07:34:20 UTC (rev 10923)
@@ -36,7 +36,6 @@
 #include <map>
 
 
-
 namespace orxonox
 {
     /**
@@ -245,13 +244,13 @@
             //----[Actionpoint methods]----          
                 bool bFirstTick_; 
 
-                void setSpawners();
+              /*  void setSpawners();
                 Vector3 bestHealthPickup (float searchRadius);
                 // Point closestPickup(PickupType::Value pickupType);
                 std::multimap <int, std::pair<PickupSpawner*, bool> > healthSpawners_; 
                 std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_; 
                 std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_; 
-
+*/
                 float timeOffset_;
                 bool bActionCalled_;
                 bool bManeuverCalled_;
@@ -261,7 +260,12 @@
                 bool bPatrolling_;
                 bool bDefaultPatrol_;
                 bool stop_;
+                static int sTicks_;
+                static int nextActionpointControllerId_;
+                int actionpointControllerId_;
+                int ticks_;
 
+
         private:
             
     };

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -67,7 +67,7 @@
         if (!this->isActive())
             return;   
         SUPER(DivisionController, tick, dt);
-        if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
+        /*if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
         {
             this->action();
             this->bActionCalled_ = true;
@@ -75,7 +75,7 @@
         if (this->timeOffset_ > 1.6f)
         {
             this->bActionCalled_ = false;
-        }
+        }*/
 
         
     }

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -62,6 +62,8 @@
     }
     void FightingController::lookAtTarget(float dt)
     {
+        if (!this || !this->getControllableEntity())
+            return;
         ControllableEntity* entity = this->getControllableEntity();
         if ( !entity )
             return;
@@ -125,9 +127,10 @@
         Vector3 diffVector = this->positionOfTarget_ - thisPosition;
         float diffLength = diffVector.length();
         Vector3 diffUnit = diffVector/diffLength;
-        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
-            || this->deltaHp < 0;
 
+        if (!this || !this->getControllableEntity())
+            return;
+
         //too far? well, come closer then
         if (diffLength > this->attackRange_)
         {
@@ -138,8 +141,13 @@
             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
         }
         else
-        {
+        {   
+            bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
+                || this->deltaHp < 0;
             this->bKeepFormation_ = false;
+
+            if (!this || !this->getControllableEntity())
+                return;
             // if (this->actionCounter_ % 3 == 0)
             if (maneuverCounter_ <= 1.2)
             {
@@ -172,67 +180,8 @@
                 }
             }
         }
-        /*//too close? How do u expect to dodge anything? Just attack!
-        else if (diffLength < 1000)
-        {   
-            this->bKeepFormation_ = false;
-
-            //at this point, just look and shoot
-            if (diffLength < 1000)
-            {
-                this->stopMoving();
-                this->startLookingAtTarget();
-
-            }
-            else
-            {
-                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f);
-            }
-        }
-        //Good distance? Check if target looks at us. It doesn't? Go hunt!
-        else if (!bTargetIsLookingAtThis)
-        {
-            this->bKeepFormation_ = false;
-            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);
-        }
-        //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
-        else 
-        {   
-            this->bKeepFormation_ = false;
-            if (maneuverCounter_ == 0)
-            {
-                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);   
-                return;
-            }
-            if (this->actionCounter_ % 3 == 0)
-                dodge(thisPosition, diffLength, diffUnit);
-        }*/
     }
-    void FightingController::dodgeTowards (Vector3& position)
-    {
-        Vector3 thisPosition = this->getControllableEntity()->getPosition();
-        Vector3 diff = (position - thisPosition);
-        float diffLength = diff.length();
-        Vector3 diffUnit = diff/diffLength;
-        float factor = 300.0f;
-        if (diffLength < 300)
-        {
-            this->setTargetPosition(position);
-            return;    
-        }
-        else if (diffLength < 600)
-            factor = 400.0f;
-        else if (diffLength < 1000)
-            factor = 700.0f;
-        else
-            factor = 1000.0f;
-        float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
-        float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
-        float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
-        this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor);
-        // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z)  << endl;
-        this->boostControl();
-    }
+    
     void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit)
     {
         //d.x*x + d.y*y + d.z*z == 0
@@ -256,7 +205,7 @@
     bool FightingController::canFire() 
     {
         //no target? why fire?
-        if (!this->target_)
+        if (!this->target_ || !this->getControllableEntity())
             return false;
         Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 
                                                            hardcoded_projectile_speed, this->target_->getWorldPosition(), 
@@ -273,7 +222,7 @@
 
     float FightingController::squaredDistanceToTarget()  const
     {
-        if (!this->getControllableEntity())
+        if (!this || !this->getControllableEntity())
             return 0;
         if (!this->target_ || !this->getControllableEntity())
             return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_));
@@ -293,7 +242,7 @@
     
     Pawn* FightingController::closestTarget() const
     {
-        if (!this->getControllableEntity())
+        if (!this || !this->getControllableEntity())
             return 0;
 
         Pawn* closestTarget = 0;

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -23,7 +23,7 @@
  *      Gani Aliguzhinov
 
  *   Co-authors:
- *      Dominik Solenicki
+ *   ...
  *
  */
 #include "controllers/FlyingController.h"
@@ -45,7 +45,6 @@
     }
     FlyingController::~FlyingController() 
     {
-
     }
 
     void FlyingController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -75,24 +74,26 @@
         switch ( this->formationMode_ )
         {
             case FormationMode::WALL:
-            { return "WALL"; break; }
+            { return "WALL"; }
             case FormationMode::FINGER4:
-            { return "FINGER4"; break; }
+            { return "FINGER4"; }
             case FormationMode::DIAMOND:
-            { return "DIAMOND"; break; }
+            { return "DIAMOND"; }
             default:
-                return "DIAMOND"; break;
+                return "DIAMOND";
         }
     }
     void FlyingController::stopMoving()
     {
         this->bHasTargetPosition_ = false;
     }
-    void FlyingController::moveToPosition(const Vector3& target, float dt)
+    void FlyingController::moveToPosition(const Vector3& targetPosition, float dt)
     {
+        if (!this->getControllableEntity())
+            return;
         ControllableEntity* entity = this->getControllableEntity();
 
-        float distance = ( target - entity->getPosition() ).length();
+        float distance = ( targetPosition - entity->getPosition() ).length();
 
         if ( distance >= this->tolerance_ )
         {
@@ -100,13 +101,13 @@
                 ( entity->getPosition() , 
                 entity->getOrientation()  * WorldEntity::FRONT, 
                 entity->getOrientation()  * WorldEntity::UP, 
-                target );
+                targetPosition );
             float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
             float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
             entity->rotateYaw( ROTATEFACTOR * rotateX * dt );
             entity->rotatePitch( ROTATEFACTOR * rotateY * dt );
           
-            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
+            if (distance > this->tolerance_*1.5f || (rotateX > -0.03 && rotateX < 0.03 && rotateY > -0.03 && rotateY < 0.03))
                 entity->moveFrontBack( SPEED * dt );
                 copyTargetOrientation(dt);
         }
@@ -122,10 +123,11 @@
     }
     void FlyingController::copyOrientation(const Quaternion& orient, float dt)
     {
-        //inspired by
+        //copied from
         //http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer&structure=Tutorials#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_
         //how can I make my objects rotate smoothly?
-       
+        if (!this->getControllableEntity())
+            return;
         Quaternion myOrient = this->getControllableEntity()->getOrientation();
         this->rotationProgress_ += dt;
 
@@ -136,37 +138,28 @@
         }
         else
         {
-
-            Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
+            Quaternion deltaOrientation = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
             
-            //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation.
-            //it is faster just to set orientation, plus that way there is no need in calculating the roll angle.
-            //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call 
-            //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much.
-            //If you don't like the code style, you are welcomed to uncomment the code below
-            //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower.
-            //P.S. apperantly it did affect ship's direction and did so way too much.
-            Matrix3 orientMatrix, myMatrix;
+            Matrix3 deltaMatrix, myMatrix;
 
-            delta.ToRotationMatrix(orientMatrix);
+            deltaOrientation.ToRotationMatrix(deltaMatrix);
             myOrient.ToRotationMatrix (myMatrix);
 
-            Radian yRad, pRad, rRad, yMy, pMy, rMy;
-            orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad);
-            myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy);
+            Radian yawDelta, pitchDelta, rollDelta, yawMy, pitchMy, rollMy;
+            deltaMatrix.ToEulerAnglesYXZ(yawDelta, pitchDelta, rollDelta);
+            myMatrix.ToEulerAnglesYXZ (yawMy, pitchMy, rollMy);
 
-            this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt);
-            // this->getControllableEntity()->setOrientation(delta);
+            if (!this->getControllableEntity())
+                return;
+            this->getControllableEntity()->rotateRoll ((rollDelta.valueRadians() - rollMy.valueRadians())*ROTATEFACTOR*dt);
         }
-        
-        
     }
-    //change log: increased precision, increased rotation speed
+
     void FlyingController::copyTargetOrientation(float dt)
     {
         if (bHasTargetOrientation_)
         {   
-            copyOrientation(targetOrientation_, dt);
+            this->copyOrientation(targetOrientation_, dt);
         }
     }
     
@@ -185,10 +178,12 @@
     void FlyingController::setTargetOrientation(ControllableEntity* target)
     {
         if (target)
-            setTargetOrientation(target->getOrientation());
+            this->setTargetOrientation(target->getOrientation());
     }
     void FlyingController::boostControl()
     {
+        if (!this->getControllableEntity())
+            return;
         SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
         if(ship == NULL) return;
         if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
@@ -220,7 +215,7 @@
             (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
              + (orient* (targetRelativePosition)));
         //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
-        if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
+        if (static_cast<int>(rnd(1.0f) * 100) % 3 == 0)
             this->setTargetOrientation (orient);
         this->setTargetPosition (targetAbsolutePosition);
         if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-12-07 07:34:20 UTC (rev 10923)
@@ -84,10 +84,10 @@
             void setTargetOrientation(ControllableEntity* target);
             virtual void boostControl();  
             void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition);      
+            
             FormationMode::Value formationMode_;
           
-            float rotationProgress_;
-            int actionCounter_;
+            float rotationProgress_;    //<! for slerp
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
             bool bHasTargetOrientation_;

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -73,7 +73,7 @@
             return;
    
         SUPER(SectionController, tick, dt);
-        if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_)
+        /*if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_)
         {
             this->action();
             this->bActionCalled_ = true;
@@ -81,7 +81,7 @@
         if (this->timeOffset_ > 2.0f)
         {
             this->bActionCalled_ = false;
-        }
+        }*/
 
     }
 
@@ -96,10 +96,7 @@
             ActionpointController* newDivisionLeader = findNewDivisionLeader();
             this->myDivisionLeader_ = newDivisionLeader;
             //spread copyOrientation called equally among the division
-            if (this->myDivisionLeader_)
-            {
-                this->actionCounter_ = 5;
-            }
+
         }
         //----If have leader----
         else
@@ -155,7 +152,6 @@
             }
         }
 
-        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     }
 
     
@@ -165,10 +161,10 @@
     {
         //----If division leader fights, cover him by fighting emenies close to his target----
         Action::Value action = this->myDivisionLeader_->getAction();
-        
-        Pawn* target;
+
         if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
         {
+            Pawn* target;
             //----if he has a target----
             if (this->myDivisionLeader_->hasTarget())
             {
@@ -176,7 +172,6 @@
                 if ( this->myDivisionLeader_->hasWingman() && 
                     !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) )
                 {
-
                     bool foundTarget = false;
                     //----new target should be close to division's target----
                     Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-12-06 17:06:39 UTC (rev 10922)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-12-07 07:34:20 UTC (rev 10923)
@@ -69,7 +69,7 @@
         SUPER(WingmanController, tick, dt);
         if (!this->myLeader_)
         {
-            if (this->actionTime_ == 2.0f)
+            /*if (this->actionTime_ == 2.0f)
             {
                 if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
                 {
@@ -92,11 +92,11 @@
                 {
                     this->bActionCalled_ = false;
                 }
-            }
+            }*/
         }
         else
         {
-            if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_)
+           /* if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_)
             {
                 this->action();
                 this->bActionCalled_ = true;
@@ -104,7 +104,7 @@
             if (this->timeOffset_ <= 0.5f)
             {
                 this->bActionCalled_ = false;
-            }
+            }*/
         }
        
 
@@ -113,7 +113,8 @@
     //----action for hard calculations----
     void WingmanController::action()
     {
-
+        if (!this || !this->getControllableEntity())
+            return;
         //----If no leader, find one----
         if (!this->myLeader_)
         {
@@ -121,11 +122,7 @@
             this->myLeader_ = newLeader;
             if (this->myLeader_)
             {
-                //spread copyOrientation called equally among the division
-                if (this->myLeader_->getIdentifier()->getName() == "SectionController")
-                    this->actionCounter_ = 1;
-                else
-                    this->actionCounter_ = 4;
+               
             }
         }
         //----If have leader, he will deal with logic----
@@ -136,6 +133,9 @@
         if (!this->myLeader_)
         {
            ActionpointController::action();
+            if (!this || !this->getControllableEntity())
+                return;
+
         }
         else if (this->myLeader_)
         {
@@ -169,7 +169,6 @@
                 }
             }
         }
-        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     }
      
    




More information about the Orxonox-commit mailing list