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

gania at orxonox.net gania at orxonox.net
Sun Nov 29 12:14:43 CET 2015


Author: gania
Date: 2015-11-29 12:14:43 +0100 (Sun, 29 Nov 2015)
New Revision: 10886

Removed:
   code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
   code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
   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/SectionController.h
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
Log:
improved dodging

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-29 11:14:43 UTC (rev 10886)
@@ -31,7 +31,7 @@
   >
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <TeamSpawnPoint team=0 position="-5000, 3000, -2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=0 position="3000, -1500, 1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     
 <!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
       <!-- 
@@ -61,7 +61,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">
@@ -122,11 +122,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="ss2">
       <templates>
         <Template link=spaceshipassff />
@@ -241,7 +241,7 @@
         </SectionController>
       </controller>
     </SpaceShip>
-
+ -->
     
 <!-- HERE ENDS DEMO FOR FIGHTING -->
 <!-- HERE STARTS DEMO FOR FORMATIONS -->
@@ -296,19 +296,60 @@
     </SpaceShip> 
     -->
 <!-- HERE ENDS DEMO FOR FORMATIONS -->
-    <!-- 
-    <SpaceShip position="-2000, 3000, -2000" lookat="0,0,0" team=1 name="ss2">
+    <!-- 1 division is roughly equal to 6 AIControllers--!>
+<!-- 
+    <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 >
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1 formationMode="finger4">
-          
+        <DivisionController team=1 formationMode="WALL">
+
         </DivisionController>
       </controller>
     </SpaceShip>
- -->
+    <SpaceShip position="2000, -1900, 1000" lookat="0,0,0" team=1>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=1>
+        </SectionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="2000, -2100, 1000" lookat="0,0,0" team=1>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="2000, -2400, 1000" lookat="0,0,0" team=1>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip> 
 
+    <?lua
+      for i = 0, 5, 1 do
+        ?>
+      <SpaceShip position="<?lua print(7000) ?>,<?lua print(i*500) ?>,<?lua print(0) ?>" team=2>
+        <templates>
+          <Template link=spaceshipassff />
+        </templates>
+        <controller>
+          <AIController team=2 />
+        </controller>
+      </SpaceShip>
+    <?lua end ?> -->
+    
+
   </Scene>
 </Level>
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -58,8 +58,15 @@
         SUPER( ActionpointController, XMLPort, xmlelement, mode );
         XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
     }
-   	void ActionpointController::tick(float dt)
-   	{
+    ActionpointController::~ActionpointController()
+    {
+        loopActionpoints_.clear();
+        parsedActionpoints_.clear();
+        actionpoints_.clear();
+    }
+    void ActionpointController::tick(float dt)
+    {
+
         if (this->timeout_ > 0 && this->bFiredRocket_)
         {
             this->timeout_ -= dt;
@@ -67,7 +74,7 @@
         if (timeout_ <= 0)
             this->bFiredRocket_ = false;
 
-   		if (this->bHasTargetPosition_)
+        if (this->bHasTargetPosition_)
         {
             this->moveToTargetPosition(dt);
         }
@@ -89,21 +96,129 @@
             }
         }
         if (this->bFirstTick_)
-        {
-            // this->getControllableEntity()->setOrientation(1,0,0,0);
-            // this->getControllableEntity()->rotateRoll(-this->getControllableEntity()->getOrientation().getRoll(true).valueRadians());
-            // this->getControllableEntity()->rotateYaw(-this->getControllableEntity()->getOrientation().getYaw(true).valueRadians());
-            // this->getControllableEntity()->rotatePitch(-this->getControllableEntity()->getOrientation().getPitch(true).valueRadians());            
+        {            
             this->bFirstTick_ = false;
+        }
 
+        SUPER(ActionpointController, tick, dt);
+    }
+    void ActionpointController::action()
+    {
+        if (!this || !this->getControllableEntity())
+            return;
+        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
+            return;
+        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
+        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
+        if (this->actionCounter_ % 2 == 0)
+            this->startAttackingEnemiesThatAreClose();
+        //No action -> pop one from stack
+        if (this->action_ == Action::NONE || this->bTakenOver_)
+        {
+            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
+            {
+                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
+                this->parsedActionpoints_.push_back (p);
+            }
+            this->executeActionpoint();
+            this->bTakenOver_ = false;
+            this->action();
         }
-   		SUPER(ActionpointController, tick, dt);
-   	}
-    ActionpointController::~ActionpointController()
-    {
-        loopActionpoints_.clear();
-        parsedActionpoints_.clear();
-        actionpoints_.clear();
+        //Action fightall -> fight till nobody alive
+        if (this->action_ == Action::FIGHTALL)
+        {
+            if (!this->hasTarget())
+            {
+                ControllableEntity* newTarget = this->closestTarget();    
+                if (newTarget)
+                {
+                    this->setAction (Action::FIGHTALL, newTarget);
+                    this->action();
+                }
+                else
+                {
+                    this->nextActionpoint();
+                    if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
+                    {
+                        this->action();
+                    }       
+                }
+            }
+        }
+        //Action fight -> fight as long as enemies in range
+        else if (this->action_ == Action::FIGHT)
+        {
+            if (!this->hasTarget())
+            {
+                //----find a target----
+                ControllableEntity* newTarget = this->closestTarget();    
+                if (newTarget && 
+                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                {
+                    this->setAction (Action::FIGHT, newTarget);
+                    this->action();
+                }
+                else
+                {
+                    this->nextActionpoint();
+                    this->action();
+                }
+            }
+            else if (this->hasTarget())
+            {
+                //----fly in formation if far enough----
+                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                    
+                if (diffVector.length() > this->attackRange_)
+                {
+                    ControllableEntity* newTarget = this->closestTarget();
+                    
+                    if (newTarget && 
+                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                    {
+                        this->setAction (Action::FIGHT, newTarget);
+                    }
+                    else
+                    {
+                        this->nextActionpoint();
+                        this->action();
+                    }
+                }
+            }
+        }
+        else if (this->action_ == Action::FLY)
+        {
+            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+            {
+                this->nextActionpoint();   
+                this->action();
+            }
+        }
+        else if (this->action_ == Action::PROTECT)
+        {
+            if (!this->getProtect())
+            {
+                this->nextActionpoint();
+                this->action(); 
+            }
+            this->stayNearProtect();
+        }
+        else if (this->action_ == Action::ATTACK)
+        {   
+            if (!this->hasTarget())
+            {
+                this->nextActionpoint();
+                this->action();
+            }
+        }
+        if (this->hasTarget())
+        {
+            //----choose where to go----
+            this->maneuver();
+            //----fire if you can----
+            this->bShooting_ = this->canFire();                
+        }
+        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     }
     void ActionpointController::setProtect (ControllableEntity* protect)
     {
@@ -272,23 +387,21 @@
             executeActionpoint();
             return;
         }
-        this->action_ = p.action;
-        switch ( this->action_ )
+        this->setAction (p.action);
+        switch (this->action_)
         {
             case Action::FIGHT:
             {
                 std::string targetName = p.name;
                 if (targetName == "")
-                {
                     break;
-                }
                 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
                 {
                     if (CommonController::getName(*itP) == targetName)
                     {
                         this->setTarget (static_cast<ControllableEntity*>(*itP));
                     }
-                }          
+                }
                 break;
             }
             case Action::FLY:
@@ -360,17 +473,26 @@
             }
             default:
                 break;
-        }
-        
+        }   
     }
 
     
     void ActionpointController::stayNearProtect()
     {
-        Vector3 targetRelativePosition(0, 300, 300);  
+        Vector3 targetRelativePosition(0, 300, 300);
+        if (!this->getProtect())
+        {
+            this->nextActionpoint();
+            return;
+        }  
         Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
             (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
         this->setTargetPosition(targetAbsolutePosition);
+        if (!this->getProtect())
+        {
+            this->nextActionpoint();
+            return;
+        }  
         if (this->actionCounter_ % 3 == 0)
             this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     }
@@ -421,135 +543,13 @@
             fillLoopReversed();
         }
     }
-    void ActionpointController::action()
-    {
-        if (!this || !this->getControllableEntity())
-            return;
-        // orxout (internal_error) << "Size of actions is " << this->parsedActionpoints_.size() << endl;
-        if (this->actionCounter_ % 2 == 0)
-            this->startAttackingEnemiesThatAreClose();
-        //No action -> pop one from stack
-        if (this->action_ == Action::NONE || this->bTakenOver_)
-        {
-            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
-            {
-                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
-                this->parsedActionpoints_.push_back (p);
-
-            }
-            this->executeActionpoint();
-            this->bTakenOver_ = false;
-            this->action();
-        }
-        //Action fightall -> fight till nobody alive
-        if (this->action_ == Action::FIGHTALL)
-        {
-            if (!this->hasTarget())
-            {
-                //----find a target----
-                ControllableEntity* newTarget = this->closestTarget();    
-                if (newTarget)
-                {
-                    this->setAction (Action::FIGHTALL, newTarget);
-                }
-                else
-                {
-                    this->nextActionpoint();
-
-                    if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
-                    {
-                        this->action();
-                    }
-                    
-                }
-            }
-            else if (this->hasTarget())
-            {
-
-            }
-        }
-        //Action fight -> fight as long as enemies in range
-        else if (this->action_ == Action::FIGHT)
-        {
-            if (!this->hasTarget())
-            {
-                //----find a target----
-                ControllableEntity* newTarget = this->closestTarget();    
-                if (newTarget && 
-                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
-                {
-                    this->setAction (Action::FIGHT, newTarget);
-                }
-                else
-                {
-                    this->nextActionpoint();
-                    this->action();
-                }
-            }
-            else if (this->hasTarget())
-            {
-                //----fly in formation if far enough----
-                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                    
-                if (diffVector.length() > this->attackRange_)
-                {
-                    ControllableEntity* newTarget = this->closestTarget();
-                    
-                    if (newTarget && 
-                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
-                    {
-                        this->setAction (Action::FIGHT, newTarget);
-                    }
-                    else
-                    {
-                        this->nextActionpoint();
-                        this->action();
-                    }
-                }
-            }
-        }
-        else if (this->action_ == Action::FLY)
-        {
-            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
-            {
-                this->nextActionpoint();   
-                this->action();
-            }
-        }
-        else if (this->action_ == Action::PROTECT)
-        {
-            if (!this->getProtect())
-            {
-                this->nextActionpoint();
-                this->action(); 
-            }
-            this->stayNearProtect();
-        }
-        else if (this->action_ == Action::ATTACK)
-        {   
-            if (!this->hasTarget())
-            {
-                this->nextActionpoint();
-                this->action();
-            }
-        }
-        if (this->hasTarget())
-        {
-            //----choose where to go----
-            this->maneuver();
-            //----fire if you can----
-            this->bShooting_ = this->canFire();                
-        }
-        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
-
-    }
+    
     void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
     {
       this->parsedActionpoints_ = vector;
       this->loopActionpoints_ = loop;
       this->bLoop_ = b;
       this->bTakenOver_ = true;
-      // orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;
     }
     void ActionpointController::setClosestTarget()
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt	2015-11-29 11:14:43 UTC (rev 10886)
@@ -11,7 +11,6 @@
   FormationController.cc
   ControllerDirector.cc
   DivisionController.cc
-  LeaderController.cc
   WingmanController.cc
   SectionController.cc
   CommonController.cc

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -35,7 +35,7 @@
     RegisterClass(DivisionController);
 
     //Leaders share the fact that they have Wingmans
-    DivisionController::DivisionController(Context* context) : LeaderController(context)
+    DivisionController::DivisionController(Context* context) : ActionpointController(context)
     {
         RegisterObject(DivisionController);
         this->setFormationMode(FormationMode::DIAMOND);

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -29,13 +29,13 @@
 #ifndef _DivisionController_H__
 #define _DivisionController_H__
 
-#include "controllers/LeaderController.h"
+#include "controllers/ActionpointController.h"
 
 
 
 namespace orxonox
 {
-    class _OrxonoxExport DivisionController : public LeaderController
+    class _OrxonoxExport DivisionController : public ActionpointController
     {
         public:
             //----[language demanded functions]----            

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -44,7 +44,7 @@
     
     FightingController::FightingController( Context* context ): FlyingController( context )
     {
-    	this->attackRange_ = 3000;
+    	this->attackRange_ = 2500;
         this->stopLookingAtTarget();
         this->bSetupWorked = false;
         this->timeout_ = 0;
@@ -125,38 +125,39 @@
         Vector3 diffVector = this->positionOfTarget_ - thisPosition;
         float diffLength = diffVector.length();
         Vector3 diffUnit = diffVector/diffLength;
-        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f);
-        
+        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/15.0f)
+            || this->deltaHp < 0;
+
         //too far? well, come closer then
         if (diffLength > this->attackRange_)
         {
-            this->spread_ = 300;
-            this->formationMode_ = FormationMode::WALL;
+            this->spread_ = 400;
+            this->formationMode_ = FormationMode::DIAMOND;
             this->bKeepFormation_ = true;
             
-            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
+            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
         }
         //too close? How do u expect to dodge anything? Just attack!
-        else if (diffLength < 500)
+        else if (diffLength < 400)
         {   
             this->bKeepFormation_ = false;
 
             //at this point, just look and shoot
-            if (diffLength < 250)
+            if (diffLength < 200)
             {
                 this->stopMoving();
                 this->startLookingAtTarget();
             }
             else
             {
-                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
+                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.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 * 200.0f);
+            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
         }
         //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
         else 
@@ -164,7 +165,7 @@
             this->bKeepFormation_ = false;
             if (maneuverCounter_ == 0)
             {
-                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);   
+                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 50.0f);   
                 return;
             }
             dodge(thisPosition, diffUnit);
@@ -175,10 +176,10 @@
     {
         //d.x*x + d.y*y + d.z*z == 0
         //z = 1/d.z * (-d.y*y - d.x * x)
-        float x = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
-        float y = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
+        float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
+        float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
         float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
-        this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);
+        this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f));
         this->boostControl();
 
     }
@@ -194,6 +195,7 @@
         {
             this->setPositionOfTarget(newPositionOfTarget);
         }
+
         return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
     }
     // void FightingController::doFire() 
@@ -269,10 +271,12 @@
         {
             return;
         }
+
         Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity());
         if (pawn)
             pawn->setAimPosition (this->positionOfTarget_);
-
+        // if (pawn->getHealth() < 100)
+        //     orxout(internal_error) << "not full, hp = " << pawn->getHealth() << endl;
         int firemode;
         float distance = CommonController::distance (this->getControllableEntity(), this->target_);
 
@@ -280,47 +284,48 @@
         //                             (this->rocketsLeft_ > 0 && !this->bFiredRocket_ ? getFiremode("RocketFire") : getFiremode ("HsW01"))
         //                                                      : getFiremode("HsW01")) : 
         //                                                      (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01"));
-        if (distance < 800)
+        if (distance < 1500)
         {
-            if (this->rocketsLeft_ > 0)
+            if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
             {
-                firemode = getFiremode ("SimpleRocketFire");
+                firemode = getFiremode ("RocketFire");
             }
             else
             {
-                if (distance > 450)
+                if (distance > 800)
+                    firemode = getFiremode ("HsW01");
+                else
                     firemode = getFiremode ("LightningGun");
-                else
-                    firemode = getFiremode ("HsW01");
             }
 
         } 
-        else if (distance < 1200)
+        // else if (distance < 1000)
+        // {
+        //     if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
+        //     {
+        //         firemode = getFiremode ("RocketFire");
+        //     }
+        //     else
+        //     {
+        //         firemode = getFiremode ("HsW01");
+        //     }
+        // }
+        else if (distance < 2000)
         {
-            if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
-            {
-                firemode = getFiremode ("RocketFire");
-            }
-            else
-            {
-                firemode = getFiremode ("HsW01");
-            }
+            firemode = getFiremode ("HsW01");
         }
-        else if (distance < 1500)
+        else
         {
             firemode = getFiremode ("LightningGun");
         }
-        else
-        {
-            firemode = getFiremode ("HsW01");
-        }
         if (firemode < 0)
         {
-            firemode = getFiremode ("HsW01");
+            //assuming there is always some weapon with index 0
+            firemode = 0;
         }
         if (firemode == getFiremode("RocketFire"))
         {
-            this->timeout_ = 1.0f;
+            this->timeout_ = 0.5f;
             this->rocketsLeft_--;
             this->bFiredRocket_ = true;
         }

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -76,7 +76,8 @@
             bool bShooting_;
             int maneuverCounter_;   
             bool bLookAtTarget_; 
-
+            float deltaHp;
+            float previousHp;
             //WEAPONSYSTEM DATA
             int rocketsLeft_;
             float timeout_;

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -200,4 +200,36 @@
            this->getControllableEntity()->boost(false);
         }
     }
+    void FlyingController::keepFormation(const ControllableEntity* leaderEntity, Vector3& targetRelativePosition)
+    {
+        ControllableEntity* myEntity = this->getControllableEntity();
+        Vector3 myPosition = myEntity->getWorldPosition();
+
+        if (!leaderEntity)
+        {
+            return;
+        }
+        Quaternion orient = leaderEntity->getWorldOrientation();
+        Vector3 leaderPosition = leaderEntity->getWorldPosition();
+
+        if (!leaderEntity)
+        {
+            return;
+        }
+        Vector3 targetAbsolutePosition = 
+            (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_)
+            this->setTargetOrientation (orient);
+        this->setTargetPosition (targetAbsolutePosition);
+        if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
+        {
+            this->boostControl();
+        }
+        else
+        {
+           this->getControllableEntity()->boost(false);
+        }
+    }
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -20,9 +20,9 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Gani Aliguzhinov
  *   Co-authors:
- *      ...
+ *      Dominik Solenicki
  *
  */
 
@@ -78,7 +78,8 @@
             void setTargetPosition(const Vector3& target);
             void setTargetOrientation(const Quaternion& orient);
             void setTargetOrientation(ControllableEntity* target);
-            virtual void boostControl();        
+            virtual void boostControl();  
+            void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition);      
             FormationMode::Value formationMode_;
           
             float rotationProgress_;

Deleted: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -1,56 +0,0 @@
-/*
- *   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 details.
- *
- *   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:
- *      Gani Aliguzhinov
- *   Co-authors:
- *      ...
- *
- */
-
-#include "LeaderController.h"
-
-
-namespace orxonox
-{
-
-    RegisterClass(LeaderController);
-
-    //CommonController contains all common functionality of AI Controllers
-    LeaderController::LeaderController(Context* context) : ActionpointController(context)
-    {
-
-        RegisterObject(LeaderController);
-
-    }
-
-   	void LeaderController::tick(float dt)
-   	{
-   		
-   		SUPER(LeaderController, tick, dt);
-   	}
-    LeaderController::~LeaderController()
-    {
-    }
-    
-    
-
-}

Deleted: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -1,60 +0,0 @@
-/*
- *   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 details.
- *
- *   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:
- *      Gani Aliguzhinov
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _LeaderController_H__
-#define _LeaderController_H__
-
-#include "controllers/ActionpointController.h"
-
-
-
-
-namespace orxonox
-{
-    class _OrxonoxExport LeaderController : public ActionpointController
-    {
-        public:
-            //----[language demanded functions]----            
-                LeaderController(Context* context);
-                virtual ~LeaderController();
-            //----[language demanded functions]----            
-                virtual void tick(float dt); 
-
-
-
-        protected:
-            //----private variables-----
-
-
-            
-        private:
-            
-    };
-}
-
-#endif /* _LeaderController_H__ */

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -38,7 +38,7 @@
     RegisterClass(SectionController);
 
     //Leaders share the fact that they have Wingmans
-    SectionController::SectionController(Context* context) : LeaderController(context)
+    SectionController::SectionController(Context* context) : ActionpointController(context)
     {
         RegisterObject(SectionController);
         this->setFormationMode(FormationMode::FINGER4);
@@ -53,10 +53,6 @@
    
     SectionController::~SectionController()
     {
-        // if (this->myWingman_)
-        // {
-        //     this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
-        // }
        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
         {
             if(this->actionpoints_[i])
@@ -68,8 +64,6 @@
     void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(SectionController, XMLPort, xmlelement, mode);
-
-        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     }
 
     //----in tick, move (or look) and shoot----
@@ -77,13 +71,7 @@
     {
         if (!this->isActive())
             return;
-
-    //this doesn't fight in formation flight, thus we can afford executing following code in tick: when nobody fights, tick is anyway stable.
-        if (this->myDivisionLeader_ && this->myDivisionLeader_->getAction() != Action::FIGHT && this->myDivisionLeader_->getAction() !=
-            Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK)
-        {
-            
-        }    
+   
         SUPER(SectionController, tick, dt);
     }
 
@@ -109,7 +97,6 @@
         }
         if (!myDivisionLeader_)
         {
-            
             ActionpointController::action();
             if (!this || !this->getControllableEntity())
                 return;
@@ -127,85 +114,22 @@
                 || this->myDivisionLeader_->getAction() == Action::FIGHTALL
                 || this->myDivisionLeader_->getAction() == Action::ATTACK))
             {
-                ControllableEntity* myEntity = this->getControllableEntity();
-                Vector3 myPosition = myEntity->getWorldPosition();
-                if (!this->myDivisionLeader_)
-                {
-                    return;
-                }
-                ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
-                Quaternion orient = leaderEntity->getWorldOrientation();
-                Vector3 leaderPosition = leaderEntity->getWorldPosition();
-
-                Vector3 targetRelativePosition = getFormationPosition();
-                if (!this->myDivisionLeader_)
-                {
-                    return;
-                }
-                Vector3 targetAbsolutePosition = 
-                    (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_)
-                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
-                else
-                    this->setAction (Action::FLY, targetAbsolutePosition);
-
-                if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
-                {
-                    this->boostControl();
-                }
-                else
-                {
-                   this->getControllableEntity()->boost(false);
-                }
+                this->keepFormation();
             }
-            else
+            else if (!this->myDivisionLeader_->bKeepFormation_)
             {
-                switch (myDivisionLeader_->getAction())
+                if (!this->hasTarget())
                 {
-                    case Action::FIGHT:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->chooseTarget();
-                        }
-                        break;
-                    }
-                    case Action::FIGHTALL:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->chooseTarget();
-                        }
-                        break;
-                    }
-                    case Action::ATTACK:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->chooseTarget();
-                        }
-                        break;
-                    }
-                    default:
-                    {
-                        //formation flight is executed in tick 
-                    }
+                    this->chooseTarget(); 
                 }
                 if (this->hasTarget())
                 {
-                    //----choose where to go----
                     this->maneuver();
-                    //----fire if you can----
                     this->bShooting_ = this->canFire();                
                 }
             }
-            
-            
         }
         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
-
     }
 
     
@@ -297,7 +221,15 @@
         return result;
     }
 
-    
+    void SectionController::keepFormation()
+    {
+        this->bKeepFormation_ = true;
+        ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
+        Vector3 targetRelativePosition = this->getFormationPosition();
+        if (!leaderEntity)
+            return;
+        FlyingController::keepFormation(leaderEntity, targetRelativePosition);
+    }
 
     ActionpointController* SectionController::findNewDivisionLeader()
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -29,12 +29,12 @@
 #ifndef _SectionController_H__
 #define _SectionController_H__
 
-#include "controllers/LeaderController.h"
+#include "controllers/ActionpointController.h"
 
 
 namespace orxonox
 {
-    class _OrxonoxExport SectionController : public LeaderController
+    class _OrxonoxExport SectionController : public ActionpointController
     {
         public:
             //----[language demanded functions]----            
@@ -63,6 +63,7 @@
             //----action must only be managed by this----     
                 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
                 Vector3 getFormationPosition ();
+                void keepFormation();
         private:
             //----private variables-----
                 Timer actionTimer_; //<! Regularly calls action().

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-29 11:14:43 UTC (rev 10886)
@@ -58,19 +58,13 @@
     void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(WingmanController, XMLPort, xmlelement, mode);
-
-        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     }
     
     //----in tick, move (or look) and shoot----
     void WingmanController::tick(float dt)
     {   
         if (!this->isActive())
-            return;
-        if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() !=
-            Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK)
-        {
-        }   
+            return; 
         
         SUPER(WingmanController, tick, dt);
     }
@@ -107,69 +101,13 @@
             if (this->myLeader_->bKeepFormation_ || !(this->myLeader_->getAction() == Action::FIGHT || this->myLeader_->getAction() == Action::FIGHTALL
                 || this->myLeader_->getAction() == Action::ATTACK))
             {
-                ControllableEntity* myEntity = this->getControllableEntity();
-                Vector3 myPosition = myEntity->getWorldPosition();
-                if (!this->myLeader_)
-                {
-                    return;
-                }
-                ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
-                Quaternion orient = leaderEntity->getWorldOrientation();
-                Vector3 leaderPosition = leaderEntity->getWorldPosition();
-                Vector3 targetRelativePosition = getFormationPosition();
-                if (!this->myLeader_)
-                {
-                    return;
-                }
-                Vector3 targetAbsolutePosition = 
-                    (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_)
-                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
-                else
-                    this->setAction (Action::FLY, targetAbsolutePosition);
-                if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
-                {
-                    this->boostControl();
-                }
-                else
-                {
-                   this->getControllableEntity()->boost(false);
-                }
+                this->keepFormation();
             }
-            else
+            else if (!this->myLeader_->bKeepFormation_)
             {
-                switch (this->myLeader_->getAction())
+                if (!this->hasTarget())
                 {
-                    case Action::FIGHT:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->setTarget(this->myLeader_->getTarget());
-                        }
-                        break;
-                    }
-                    case Action::FIGHTALL:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->setTarget(this->myLeader_->getTarget());
-                        }
-                        break;
-                    }
-                    case Action::ATTACK:
-                    {
-                        if (!this->hasTarget())
-                        {
-                            this->setTarget(this->myLeader_->getTarget());
-                        }
-                        break;
-                    }
-                    default:
-                    {
-                    
-                    }
+                    this->setTarget(this->myLeader_->getTarget());
                 }
                 if (this->hasTarget())
                 {
@@ -179,8 +117,6 @@
                     this->bShooting_ = this->canFire();                
                 }
             }
-            
-            
         }
         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     }
@@ -236,6 +172,15 @@
         delete targetRelativePosition;
         return result;
     }
+    void WingmanController::keepFormation()
+    {
+        this->bKeepFormation_ = true;
+        ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
+        Vector3 targetRelativePosition = this->getFormationPosition();
+        if (!leaderEntity)
+            return;
+        FlyingController::keepFormation (leaderEntity, targetRelativePosition);
+    }
     //----POST: closest leader that is ready to take a new wingman is returned----
     ActionpointController* WingmanController::findNewLeader()
     {
@@ -267,7 +212,6 @@
                 closestLeader = *it;
                 minDistance = distance;
             }
-           
         }
         if (closestLeader)
         {
@@ -276,13 +220,8 @@
             {
                 return closestLeader;
             }
-
         }
-
         return 0;
     }
 
-
-
-
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-28 21:30:56 UTC (rev 10885)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-29 11:14:43 UTC (rev 10886)
@@ -62,7 +62,8 @@
             //----action must only be managed by this----
                 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
                 Vector3 getFormationPosition ();
-
+                void keepFormation();
+                
         private:
             //----private variables-----
                 WeakPtr<ActionpointController> myLeader_;




More information about the Orxonox-commit mailing list