Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10886


Ignore:
Timestamp:
Nov 29, 2015, 12:14:43 PM (8 years ago)
Author:
gania
Message:

improved dodging

Location:
code/branches/campaignHS15
Files:
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/data/levels/AITest.oxw

    r10885 r10886  
    3232
    3333    <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"/>
    34     <TeamSpawnPoint team=0 position="-5000, 3000, -2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <TeamSpawnPoint team=0 position="3000, -1500, 1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535   
    3636<!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
     
    6262<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
    6363P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
    64        <!--
     64       
    6565    <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    6666
     
    123123      </templates>
    124124    </SpaceShip>
    125   -->
     125 
    126126   
    127127<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
    128128<!-- HERE STARTS DEMO FOR FIGHTING -->
    129    
     129    <!--
    130130    <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
    131131      <templates>
     
    242242      </controller>
    243243    </SpaceShip>
    244 
     244 -->
    245245   
    246246<!-- HERE ENDS DEMO FOR FIGHTING -->
     
    297297    -->
    298298<!-- HERE ENDS DEMO FOR FORMATIONS -->
    299     <!--
    300     <SpaceShip position="-2000, 3000, -2000" lookat="0,0,0" team=1 name="ss2">
    301       <templates>
    302         <Template link=spaceshipassff />
    303       </templates>
    304       <controller>
    305         <DivisionController team=1 formationMode="finger4">
    306          
    307         </DivisionController>
    308       </controller>
    309     </SpaceShip>
    310  -->
     299    <!-- 1 division is roughly equal to 6 AIControllers--!>
     300<!--
     301    <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 >
     302      <templates>
     303        <Template link=spaceshipassff />
     304      </templates>
     305      <controller>
     306        <DivisionController team=1 formationMode="WALL">
     307
     308        </DivisionController>
     309      </controller>
     310    </SpaceShip>
     311    <SpaceShip position="2000, -1900, 1000" lookat="0,0,0" team=1>
     312      <templates>
     313        <Template link=spaceshipassff />
     314      </templates>
     315      <controller>
     316        <SectionController team=1>
     317        </SectionController>
     318      </controller>
     319    </SpaceShip>
     320    <SpaceShip position="2000, -2100, 1000" lookat="0,0,0" team=1>
     321      <templates>
     322        <Template link=spaceshipassff />
     323      </templates>
     324      <controller>
     325        <WingmanController team=1>
     326        </WingmanController>
     327      </controller>
     328    </SpaceShip>
     329    <SpaceShip position="2000, -2400, 1000" lookat="0,0,0" team=1>
     330      <templates>
     331        <Template link=spaceshipassff />
     332      </templates>
     333      <controller>
     334        <WingmanController team=1>
     335        </WingmanController>
     336      </controller>
     337    </SpaceShip>
     338
     339    <?lua
     340      for i = 0, 5, 1 do
     341        ?>
     342      <SpaceShip position="<?lua print(7000) ?>,<?lua print(i*500) ?>,<?lua print(0) ?>" team=2>
     343        <templates>
     344          <Template link=spaceshipassff />
     345        </templates>
     346        <controller>
     347          <AIController team=2 />
     348        </controller>
     349      </SpaceShip>
     350    <?lua end ?> -->
     351   
    311352
    312353  </Scene>
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10885 r10886  
    5959        XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
    6060    }
    61         void ActionpointController::tick(float dt)
    62         {
     61    ActionpointController::~ActionpointController()
     62    {
     63        loopActionpoints_.clear();
     64        parsedActionpoints_.clear();
     65        actionpoints_.clear();
     66    }
     67    void ActionpointController::tick(float dt)
     68    {
     69
    6370        if (this->timeout_ > 0 && this->bFiredRocket_)
    6471        {
     
    6875            this->bFiredRocket_ = false;
    6976
    70                 if (this->bHasTargetPosition_)
     77        if (this->bHasTargetPosition_)
    7178        {
    7279            this->moveToTargetPosition(dt);
     
    9097        }
    9198        if (this->bFirstTick_)
    92         {
    93             // this->getControllableEntity()->setOrientation(1,0,0,0);
    94             // this->getControllableEntity()->rotateRoll(-this->getControllableEntity()->getOrientation().getRoll(true).valueRadians());
    95             // this->getControllableEntity()->rotateYaw(-this->getControllableEntity()->getOrientation().getYaw(true).valueRadians());
    96             // this->getControllableEntity()->rotatePitch(-this->getControllableEntity()->getOrientation().getPitch(true).valueRadians());           
     99        {           
    97100            this->bFirstTick_ = false;
    98 
    99         }
    100                 SUPER(ActionpointController, tick, dt);
    101         }
    102     ActionpointController::~ActionpointController()
    103     {
    104         loopActionpoints_.clear();
    105         parsedActionpoints_.clear();
    106         actionpoints_.clear();
     101        }
     102
     103        SUPER(ActionpointController, tick, dt);
     104    }
     105    void ActionpointController::action()
     106    {
     107        if (!this || !this->getControllableEntity())
     108            return;
     109        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
     110            return;
     111        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
     112        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     113        if (this->actionCounter_ % 2 == 0)
     114            this->startAttackingEnemiesThatAreClose();
     115        //No action -> pop one from stack
     116        if (this->action_ == Action::NONE || this->bTakenOver_)
     117        {
     118            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
     119            {
     120                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
     121                this->parsedActionpoints_.push_back (p);
     122            }
     123            this->executeActionpoint();
     124            this->bTakenOver_ = false;
     125            this->action();
     126        }
     127        //Action fightall -> fight till nobody alive
     128        if (this->action_ == Action::FIGHTALL)
     129        {
     130            if (!this->hasTarget())
     131            {
     132                ControllableEntity* newTarget = this->closestTarget();   
     133                if (newTarget)
     134                {
     135                    this->setAction (Action::FIGHTALL, newTarget);
     136                    this->action();
     137                }
     138                else
     139                {
     140                    this->nextActionpoint();
     141                    if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
     142                    {
     143                        this->action();
     144                    }       
     145                }
     146            }
     147        }
     148        //Action fight -> fight as long as enemies in range
     149        else if (this->action_ == Action::FIGHT)
     150        {
     151            if (!this->hasTarget())
     152            {
     153                //----find a target----
     154                ControllableEntity* newTarget = this->closestTarget();   
     155                if (newTarget &&
     156                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     157                {
     158                    this->setAction (Action::FIGHT, newTarget);
     159                    this->action();
     160                }
     161                else
     162                {
     163                    this->nextActionpoint();
     164                    this->action();
     165                }
     166            }
     167            else if (this->hasTarget())
     168            {
     169                //----fly in formation if far enough----
     170                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     171                   
     172                if (diffVector.length() > this->attackRange_)
     173                {
     174                    ControllableEntity* newTarget = this->closestTarget();
     175                   
     176                    if (newTarget &&
     177                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     178                    {
     179                        this->setAction (Action::FIGHT, newTarget);
     180                    }
     181                    else
     182                    {
     183                        this->nextActionpoint();
     184                        this->action();
     185                    }
     186                }
     187            }
     188        }
     189        else if (this->action_ == Action::FLY)
     190        {
     191            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     192            {
     193                this->nextActionpoint();   
     194                this->action();
     195            }
     196        }
     197        else if (this->action_ == Action::PROTECT)
     198        {
     199            if (!this->getProtect())
     200            {
     201                this->nextActionpoint();
     202                this->action();
     203            }
     204            this->stayNearProtect();
     205        }
     206        else if (this->action_ == Action::ATTACK)
     207        {   
     208            if (!this->hasTarget())
     209            {
     210                this->nextActionpoint();
     211                this->action();
     212            }
     213        }
     214        if (this->hasTarget())
     215        {
     216            //----choose where to go----
     217            this->maneuver();
     218            //----fire if you can----
     219            this->bShooting_ = this->canFire();               
     220        }
     221        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    107222    }
    108223    void ActionpointController::setProtect (ControllableEntity* protect)
     
    273388            return;
    274389        }
    275         this->action_ = p.action;
    276         switch ( this->action_ )
     390        this->setAction (p.action);
     391        switch (this->action_)
    277392        {
    278393            case Action::FIGHT:
     
    280395                std::string targetName = p.name;
    281396                if (targetName == "")
    282                 {
    283397                    break;
    284                 }
    285398                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    286399                {
     
    289402                        this->setTarget (static_cast<ControllableEntity*>(*itP));
    290403                    }
    291                 }         
     404                }
    292405                break;
    293406            }
     
    361474            default:
    362475                break;
    363         }
    364        
     476        }   
    365477    }
    366478
     
    368480    void ActionpointController::stayNearProtect()
    369481    {
    370         Vector3 targetRelativePosition(0, 300, 300); 
     482        Vector3 targetRelativePosition(0, 300, 300);
     483        if (!this->getProtect())
     484        {
     485            this->nextActionpoint();
     486            return;
     487        } 
    371488        Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
    372489            (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
    373490        this->setTargetPosition(targetAbsolutePosition);
     491        if (!this->getProtect())
     492        {
     493            this->nextActionpoint();
     494            return;
     495        } 
    374496        if (this->actionCounter_ % 3 == 0)
    375497            this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     
    422544        }
    423545    }
    424     void ActionpointController::action()
    425     {
    426         if (!this || !this->getControllableEntity())
    427             return;
    428         // orxout (internal_error) << "Size of actions is " << this->parsedActionpoints_.size() << endl;
    429         if (this->actionCounter_ % 2 == 0)
    430             this->startAttackingEnemiesThatAreClose();
    431         //No action -> pop one from stack
    432         if (this->action_ == Action::NONE || this->bTakenOver_)
    433         {
    434             if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
    435             {
    436                 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
    437                 this->parsedActionpoints_.push_back (p);
    438 
    439             }
    440             this->executeActionpoint();
    441             this->bTakenOver_ = false;
    442             this->action();
    443         }
    444         //Action fightall -> fight till nobody alive
    445         if (this->action_ == Action::FIGHTALL)
    446         {
    447             if (!this->hasTarget())
    448             {
    449                 //----find a target----
    450                 ControllableEntity* newTarget = this->closestTarget();   
    451                 if (newTarget)
    452                 {
    453                     this->setAction (Action::FIGHTALL, newTarget);
    454                 }
    455                 else
    456                 {
    457                     this->nextActionpoint();
    458 
    459                     if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
    460                     {
    461                         this->action();
    462                     }
    463                    
    464                 }
    465             }
    466             else if (this->hasTarget())
    467             {
    468 
    469             }
    470         }
    471         //Action fight -> fight as long as enemies in range
    472         else if (this->action_ == Action::FIGHT)
    473         {
    474             if (!this->hasTarget())
    475             {
    476                 //----find a target----
    477                 ControllableEntity* newTarget = this->closestTarget();   
    478                 if (newTarget &&
    479                         CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    480                 {
    481                     this->setAction (Action::FIGHT, newTarget);
    482                 }
    483                 else
    484                 {
    485                     this->nextActionpoint();
    486                     this->action();
    487                 }
    488             }
    489             else if (this->hasTarget())
    490             {
    491                 //----fly in formation if far enough----
    492                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    493                    
    494                 if (diffVector.length() > this->attackRange_)
    495                 {
    496                     ControllableEntity* newTarget = this->closestTarget();
    497                    
    498                     if (newTarget &&
    499                         CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    500                     {
    501                         this->setAction (Action::FIGHT, newTarget);
    502                     }
    503                     else
    504                     {
    505                         this->nextActionpoint();
    506                         this->action();
    507                     }
    508                 }
    509             }
    510         }
    511         else if (this->action_ == Action::FLY)
    512         {
    513             if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    514             {
    515                 this->nextActionpoint();   
    516                 this->action();
    517             }
    518         }
    519         else if (this->action_ == Action::PROTECT)
    520         {
    521             if (!this->getProtect())
    522             {
    523                 this->nextActionpoint();
    524                 this->action();
    525             }
    526             this->stayNearProtect();
    527         }
    528         else if (this->action_ == Action::ATTACK)
    529         {   
    530             if (!this->hasTarget())
    531             {
    532                 this->nextActionpoint();
    533                 this->action();
    534             }
    535         }
    536         if (this->hasTarget())
    537         {
    538             //----choose where to go----
    539             this->maneuver();
    540             //----fire if you can----
    541             this->bShooting_ = this->canFire();               
    542         }
    543         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    544 
    545     }
     546   
    546547    void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
    547548    {
     
    550551      this->bLoop_ = b;
    551552      this->bTakenOver_ = true;
    552       // orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;
    553553    }
    554554    void ActionpointController::setClosestTarget()
  • code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt

    r10871 r10886  
    1212  ControllerDirector.cc
    1313  DivisionController.cc
    14   LeaderController.cc
    1514  WingmanController.cc
    1615  SectionController.cc
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10885 r10886  
    3636
    3737    //Leaders share the fact that they have Wingmans
    38     DivisionController::DivisionController(Context* context) : LeaderController(context)
     38    DivisionController::DivisionController(Context* context) : ActionpointController(context)
    3939    {
    4040        RegisterObject(DivisionController);
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h

    r10885 r10886  
    3030#define _DivisionController_H__
    3131
    32 #include "controllers/LeaderController.h"
     32#include "controllers/ActionpointController.h"
    3333
    3434
     
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport DivisionController : public LeaderController
     38    class _OrxonoxExport DivisionController : public ActionpointController
    3939    {
    4040        public:
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10885 r10886  
    4545    FightingController::FightingController( Context* context ): FlyingController( context )
    4646    {
    47         this->attackRange_ = 3000;
     47        this->attackRange_ = 2500;
    4848        this->stopLookingAtTarget();
    4949        this->bSetupWorked = false;
     
    126126        float diffLength = diffVector.length();
    127127        Vector3 diffUnit = diffVector/diffLength;
    128         bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f);
    129        
     128        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/15.0f)
     129            || this->deltaHp < 0;
     130
    130131        //too far? well, come closer then
    131132        if (diffLength > this->attackRange_)
    132133        {
    133             this->spread_ = 300;
    134             this->formationMode_ = FormationMode::WALL;
     134            this->spread_ = 400;
     135            this->formationMode_ = FormationMode::DIAMOND;
    135136            this->bKeepFormation_ = true;
    136137           
    137             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     138            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    138139        }
    139140        //too close? How do u expect to dodge anything? Just attack!
    140         else if (diffLength < 500)
     141        else if (diffLength < 400)
    141142        {   
    142143            this->bKeepFormation_ = false;
    143144
    144145            //at this point, just look and shoot
    145             if (diffLength < 250)
     146            if (diffLength < 200)
    146147            {
    147148                this->stopMoving();
     
    150151            else
    151152            {
    152                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     153                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    153154            }
    154155        }
     
    157158        {
    158159            this->bKeepFormation_ = false;
    159             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
     160            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    160161        }
    161162        //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
     
    165166            if (maneuverCounter_ == 0)
    166167            {
    167                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);   
     168                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 50.0f);   
    168169                return;
    169170            }
     
    176177        //d.x*x + d.y*y + d.z*z == 0
    177178        //z = 1/d.z * (-d.y*y - d.x * x)
    178         float x = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    179         float y = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     179        float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     180        float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    180181        float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    181         this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);
     182        this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f));
    182183        this->boostControl();
    183184
     
    195196            this->setPositionOfTarget(newPositionOfTarget);
    196197        }
     198
    197199        return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
    198200    }
     
    270272            return;
    271273        }
     274
    272275        Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity());
    273276        if (pawn)
    274277            pawn->setAimPosition (this->positionOfTarget_);
    275 
     278        // if (pawn->getHealth() < 100)
     279        //     orxout(internal_error) << "not full, hp = " << pawn->getHealth() << endl;
    276280        int firemode;
    277281        float distance = CommonController::distance (this->getControllableEntity(), this->target_);
     
    281285        //                                                      : getFiremode("HsW01")) :
    282286        //                                                      (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01"));
    283         if (distance < 800)
    284         {
    285             if (this->rocketsLeft_ > 0)
    286             {
    287                 firemode = getFiremode ("SimpleRocketFire");
     287        if (distance < 1500)
     288        {
     289            if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
     290            {
     291                firemode = getFiremode ("RocketFire");
    288292            }
    289293            else
    290294            {
    291                 if (distance > 450)
     295                if (distance > 800)
     296                    firemode = getFiremode ("HsW01");
     297                else
    292298                    firemode = getFiremode ("LightningGun");
    293                 else
    294                     firemode = getFiremode ("HsW01");
    295299            }
    296300
    297301        }
    298         else if (distance < 1200)
    299         {
    300             if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
    301             {
    302                 firemode = getFiremode ("RocketFire");
    303             }
    304             else
    305             {
    306                 firemode = getFiremode ("HsW01");
    307             }
    308         }
    309         else if (distance < 1500)
     302        // else if (distance < 1000)
     303        // {
     304        //     if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
     305        //     {
     306        //         firemode = getFiremode ("RocketFire");
     307        //     }
     308        //     else
     309        //     {
     310        //         firemode = getFiremode ("HsW01");
     311        //     }
     312        // }
     313        else if (distance < 2000)
     314        {
     315            firemode = getFiremode ("HsW01");
     316        }
     317        else
    310318        {
    311319            firemode = getFiremode ("LightningGun");
    312320        }
    313         else
    314         {
    315             firemode = getFiremode ("HsW01");
    316         }
    317321        if (firemode < 0)
    318322        {
    319             firemode = getFiremode ("HsW01");
     323            //assuming there is always some weapon with index 0
     324            firemode = 0;
    320325        }
    321326        if (firemode == getFiremode("RocketFire"))
    322327        {
    323             this->timeout_ = 1.0f;
     328            this->timeout_ = 0.5f;
    324329            this->rocketsLeft_--;
    325330            this->bFiredRocket_ = true;
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10885 r10886  
    7777            int maneuverCounter_;   
    7878            bool bLookAtTarget_;
    79 
     79            float deltaHp;
     80            float previousHp;
    8081            //WEAPONSYSTEM DATA
    8182            int rocketsLeft_;
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10885 r10886  
    201201        }
    202202    }
     203    void FlyingController::keepFormation(const ControllableEntity* leaderEntity, Vector3& targetRelativePosition)
     204    {
     205        ControllableEntity* myEntity = this->getControllableEntity();
     206        Vector3 myPosition = myEntity->getWorldPosition();
     207
     208        if (!leaderEntity)
     209        {
     210            return;
     211        }
     212        Quaternion orient = leaderEntity->getWorldOrientation();
     213        Vector3 leaderPosition = leaderEntity->getWorldPosition();
     214
     215        if (!leaderEntity)
     216        {
     217            return;
     218        }
     219        Vector3 targetAbsolutePosition =
     220            (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
     221             + (orient* (targetRelativePosition)));
     222        //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
     223        if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
     224            this->setTargetOrientation (orient);
     225        this->setTargetPosition (targetAbsolutePosition);
     226        if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
     227        {
     228            this->boostControl();
     229        }
     230        else
     231        {
     232           this->getControllableEntity()->boost(false);
     233        }
     234    }
    203235}
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10885 r10886  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    7979            void setTargetOrientation(const Quaternion& orient);
    8080            void setTargetOrientation(ControllableEntity* target);
    81             virtual void boostControl();       
     81            virtual void boostControl(); 
     82            void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition);     
    8283            FormationMode::Value formationMode_;
    8384         
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10885 r10886  
    3939
    4040    //Leaders share the fact that they have Wingmans
    41     SectionController::SectionController(Context* context) : LeaderController(context)
     41    SectionController::SectionController(Context* context) : ActionpointController(context)
    4242    {
    4343        RegisterObject(SectionController);
     
    5454    SectionController::~SectionController()
    5555    {
    56         // if (this->myWingman_)
    57         // {
    58         //     this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
    59         // }
    6056       for (size_t i = 0; i < this->actionpoints_.size(); ++i)
    6157        {
     
    6965    {
    7066        SUPER(SectionController, XMLPort, xmlelement, mode);
    71 
    72         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    7367    }
    7468
     
    7872        if (!this->isActive())
    7973            return;
    80 
    81     //this doesn't fight in formation flight, thus we can afford executing following code in tick: when nobody fights, tick is anyway stable.
    82         if (this->myDivisionLeader_ && this->myDivisionLeader_->getAction() != Action::FIGHT && this->myDivisionLeader_->getAction() !=
    83             Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK)
    84         {
    85            
    86         }   
     74   
    8775        SUPER(SectionController, tick, dt);
    8876    }
     
    11098        if (!myDivisionLeader_)
    11199        {
    112            
    113100            ActionpointController::action();
    114101            if (!this || !this->getControllableEntity())
     
    128115                || this->myDivisionLeader_->getAction() == Action::ATTACK))
    129116            {
    130                 ControllableEntity* myEntity = this->getControllableEntity();
    131                 Vector3 myPosition = myEntity->getWorldPosition();
    132                 if (!this->myDivisionLeader_)
    133                 {
    134                     return;
    135                 }
    136                 ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
    137                 Quaternion orient = leaderEntity->getWorldOrientation();
    138                 Vector3 leaderPosition = leaderEntity->getWorldPosition();
    139 
    140                 Vector3 targetRelativePosition = getFormationPosition();
    141                 if (!this->myDivisionLeader_)
    142                 {
    143                     return;
    144                 }
    145                 Vector3 targetAbsolutePosition =
    146                     (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    147                      + (orient* (targetRelativePosition)));
    148                 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    149                 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
    150                     this->setAction (Action::FLY, targetAbsolutePosition, orient);
    151                 else
    152                     this->setAction (Action::FLY, targetAbsolutePosition);
    153 
    154                 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    155                 {
    156                     this->boostControl();
    157                 }
    158                 else
    159                 {
    160                    this->getControllableEntity()->boost(false);
    161                 }
    162             }
    163             else
    164             {
    165                 switch (myDivisionLeader_->getAction())
    166                 {
    167                     case Action::FIGHT:
    168                     {
    169                         if (!this->hasTarget())
    170                         {
    171                             this->chooseTarget();
    172                         }
    173                         break;
    174                     }
    175                     case Action::FIGHTALL:
    176                     {
    177                         if (!this->hasTarget())
    178                         {
    179                             this->chooseTarget();
    180                         }
    181                         break;
    182                     }
    183                     case Action::ATTACK:
    184                     {
    185                         if (!this->hasTarget())
    186                         {
    187                             this->chooseTarget();
    188                         }
    189                         break;
    190                     }
    191                     default:
    192                     {
    193                         //formation flight is executed in tick
    194                     }
     117                this->keepFormation();
     118            }
     119            else if (!this->myDivisionLeader_->bKeepFormation_)
     120            {
     121                if (!this->hasTarget())
     122                {
     123                    this->chooseTarget();
    195124                }
    196125                if (this->hasTarget())
    197126                {
    198                     //----choose where to go----
    199127                    this->maneuver();
    200                     //----fire if you can----
    201128                    this->bShooting_ = this->canFire();               
    202129                }
    203130            }
    204            
    205            
    206131        }
    207132        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    208 
    209133    }
    210134
     
    298222    }
    299223
    300    
     224    void SectionController::keepFormation()
     225    {
     226        this->bKeepFormation_ = true;
     227        ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
     228        Vector3 targetRelativePosition = this->getFormationPosition();
     229        if (!leaderEntity)
     230            return;
     231        FlyingController::keepFormation(leaderEntity, targetRelativePosition);
     232    }
    301233
    302234    ActionpointController* SectionController::findNewDivisionLeader()
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10885 r10886  
    3030#define _SectionController_H__
    3131
    32 #include "controllers/LeaderController.h"
     32#include "controllers/ActionpointController.h"
    3333
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport SectionController : public LeaderController
     37    class _OrxonoxExport SectionController : public ActionpointController
    3838    {
    3939        public:
     
    6464                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    6565                Vector3 getFormationPosition ();
     66                void keepFormation();
    6667        private:
    6768            //----private variables-----
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10885 r10886  
    5959    {
    6060        SUPER(WingmanController, XMLPort, xmlelement, mode);
    61 
    62         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    6361    }
    6462   
     
    6765    {   
    6866        if (!this->isActive())
    69             return;
    70         if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() !=
    71             Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK)
    72         {
    73         }   
     67            return;
    7468       
    7569        SUPER(WingmanController, tick, dt);
     
    108102                || this->myLeader_->getAction() == Action::ATTACK))
    109103            {
    110                 ControllableEntity* myEntity = this->getControllableEntity();
    111                 Vector3 myPosition = myEntity->getWorldPosition();
    112                 if (!this->myLeader_)
    113                 {
    114                     return;
    115                 }
    116                 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
    117                 Quaternion orient = leaderEntity->getWorldOrientation();
    118                 Vector3 leaderPosition = leaderEntity->getWorldPosition();
    119                 Vector3 targetRelativePosition = getFormationPosition();
    120                 if (!this->myLeader_)
    121                 {
    122                     return;
    123                 }
    124                 Vector3 targetAbsolutePosition =
    125                     (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    126                      + (orient* (targetRelativePosition)));
    127                 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    128                 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
    129                     this->setAction (Action::FLY, targetAbsolutePosition, orient);
    130                 else
    131                     this->setAction (Action::FLY, targetAbsolutePosition);
    132                 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    133                 {
    134                     this->boostControl();
    135                 }
    136                 else
    137                 {
    138                    this->getControllableEntity()->boost(false);
    139                 }
    140             }
    141             else
    142             {
    143                 switch (this->myLeader_->getAction())
    144                 {
    145                     case Action::FIGHT:
    146                     {
    147                         if (!this->hasTarget())
    148                         {
    149                             this->setTarget(this->myLeader_->getTarget());
    150                         }
    151                         break;
    152                     }
    153                     case Action::FIGHTALL:
    154                     {
    155                         if (!this->hasTarget())
    156                         {
    157                             this->setTarget(this->myLeader_->getTarget());
    158                         }
    159                         break;
    160                     }
    161                     case Action::ATTACK:
    162                     {
    163                         if (!this->hasTarget())
    164                         {
    165                             this->setTarget(this->myLeader_->getTarget());
    166                         }
    167                         break;
    168                     }
    169                     default:
    170                     {
    171                    
    172                     }
     104                this->keepFormation();
     105            }
     106            else if (!this->myLeader_->bKeepFormation_)
     107            {
     108                if (!this->hasTarget())
     109                {
     110                    this->setTarget(this->myLeader_->getTarget());
    173111                }
    174112                if (this->hasTarget())
     
    180118                }
    181119            }
    182            
    183            
    184120        }
    185121        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     
    236172        delete targetRelativePosition;
    237173        return result;
     174    }
     175    void WingmanController::keepFormation()
     176    {
     177        this->bKeepFormation_ = true;
     178        ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity();
     179        Vector3 targetRelativePosition = this->getFormationPosition();
     180        if (!leaderEntity)
     181            return;
     182        FlyingController::keepFormation (leaderEntity, targetRelativePosition);
    238183    }
    239184    //----POST: closest leader that is ready to take a new wingman is returned----
     
    268213                minDistance = distance;
    269214            }
    270            
    271215        }
    272216        if (closestLeader)
     
    277221                return closestLeader;
    278222            }
    279 
    280         }
    281 
     223        }
    282224        return 0;
    283225    }
    284226
    285 
    286 
    287 
    288227}
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h

    r10885 r10886  
    6363                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    6464                Vector3 getFormationPosition ();
    65 
     65                void keepFormation();
     66               
    6667        private:
    6768            //----private variables-----
Note: See TracChangeset for help on using the changeset viewer.