Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10912


Ignore:
Timestamp:
Dec 1, 2015, 7:03:32 PM (8 years ago)
Author:
gania
Message:

defaultPatrol and defaultFightAll XML commands

Location:
code/branches/campaignHS15
Files:
5 edited

Legend:

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

    r10909 r10912  
    3636    ?>
    3737    <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"/>
    38     <TeamSpawnPoint team=0 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     38    <TeamSpawnPoint team=0 position="2000, 2000, 2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3939   
    4040<!--     
     
    5353      </templates>
    5454      <controller>
    55         <DivisionController team=0 formationMode="finger4">
     55        <DivisionController team=1 formationMode="finger4">
    5656          <actionpoints>
    5757            <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
     
    307307      </controller>
    308308    </SpaceShip>
    309    <!--  <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>
    310       <templates>
    311         <Template link=spaceshipassff />
    312       </templates>
    313       <controller>
    314         <DivisionController team=1 formationMode="WALL">
    315 
    316         </DivisionController>
    317       </controller>
    318     </SpaceShip>
    319     <SpaceShip position="2000, -1900, 3000" lookat="0,0,0" team=1>
    320       <templates>
    321         <Template link=spaceshipassff />
    322       </templates>
    323       <controller>
    324         <SectionController team=1>
    325         </SectionController>
    326       </controller>
    327     </SpaceShip>
    328  -->
    329    
     309
    330310<!-- HERE ENDS DEMO FOR FIGHTING -->
    331311<!-- HERE STARTS DEMO FOR FORMATIONS -->
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10910 r10912  
    3232#include <algorithm>
    3333#include "worldentities/Actionpoint.h"
     34
    3435namespace orxonox
    3536{
     
    5556        this->bStartedDodging_ = false;
    5657        this->timeDodged_ = 0;
     58        this->bDefaultPatrol_ = true;
     59        this->bDefaultFightAll_ = true;
     60        this->stop_ = false;
    5761        RegisterObject(ActionpointController);
    5862
     
    6165    {
    6266        SUPER( ActionpointController, XMLPort, xmlelement, mode );
     67        // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
     68        // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
     69
    6370        XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
    64     }
     71        XMLPortParam(ActionpointController, "defaultFightAll", setDefaultFightAll, getDefaultFightAll, xmlelement, mode).defaultValues(true);
     72        XMLPortParam(ActionpointController, "defaultPatrol", setDefaultPatrol, getDefaultPatrol, xmlelement, mode).defaultValues(true);
     73    }
     74    // void ActionpointController::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
     75    // {
     76    //     SUPER(ActionpointController, XMLEventPort, xmlelement, mode);
     77    //     XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
     78    //     XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
     79
     80    // }
     81    // bool ActionpointController::stop(bool bTriggered, BaseObject* trigger)
     82    // {
     83    //     this->stop_ = true;
     84    //     return true;
     85    // }
     86    // bool ActionpointController::go(bool bTriggered, BaseObject* trigger)
     87    // {
     88    //     this->stop_ = false;
     89    //     return true;
     90    // }
    6591    ActionpointController::~ActionpointController()
    6692    {
     
    74100    void ActionpointController::tick(float dt)
    75101    {
    76 
     102        if (stop_)
     103            return;
    77104        if (this->timeout_ > 0 && this->bFiredRocket_)
    78105        {
     
    143170        SUPER(ActionpointController, tick, dt);
    144171    }
    145     std::pair <ControllableEntity*, ControllableEntity*> ActionpointController::closestTargets()
    146     {
    147         WeakPtr<ControllableEntity> firstTarget, secondTarget, tempTarget;
    148         float firstDistance = std::numeric_limits<float>::infinity(), secondDistance = std::numeric_limits<float>::infinity(), tempDistance = 0;
    149         Gametype* gt = this->getGametype();
    150         for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    151         {
    152             tempTarget = static_cast<ControllableEntity*>(*itP);
    153             if (CommonController::sameTeam (this->getControllableEntity(), tempTarget, gt))
    154                 continue;
    155 
    156             tempDistance = CommonController::distance (*itP, this->getControllableEntity());
    157             if (tempDistance < firstDistance)
    158             {
    159                 secondDistance = firstDistance;
    160                 secondTarget = firstTarget;
    161 
    162                 firstDistance = tempDistance;
    163                 firstTarget = tempTarget;
    164             }
    165             else if (tempDistance < secondDistance)
    166             {
    167                 secondDistance = tempDistance;
    168                 secondTarget = tempTarget;
    169             }
    170         }
    171         return std::make_pair (firstTarget, secondTarget); 
    172     }
    173 
    174     //patrol can only be called by divisionController or others if they don't have a leader
    175     //searches for closest enemy and sets target to it. If wasn't fighting, pushes Action::FIGHT on a stack.
    176     //patrol gets called constantly either if this is fighting or if this->bDefaultPatrol_ is set to true via XML
    177     bool ActionpointController::patrol()
    178     {
    179         std::pair <ControllableEntity*, ControllableEntity*> newTargets = this->closestTargets();
    180         if (!newTargets.first)
    181             return false;
    182         ControllableEntity* newTarget = newTargets.first;
    183 
    184         float distance = CommonController::distance (this->getControllableEntity(), newTarget);
    185         if (distance < this->attackRange_ && distance < CommonController::distance(this->getControllableEntity(), this->target_))
    186         {
    187             this->setTarget (newTarget);
    188 
    189             if (this->getIdentifier()->getName() == "DivisionController")
    190             {
    191                 if (!newTargets.second)
    192                 {
    193                     if (this->myFollower_)
    194                         this->myFollower_->setTarget(newTargets.first);
    195                 }
    196                 else
    197                 {
    198                     if (this->myFollower_ && CommonController::distance(this->getControllableEntity(), newTargets.second) < this->attackRange_ + 600.0f)
    199                         this->myFollower_->setTarget(newTargets.second);
    200                     else if (this->myFollower_)
    201                         this->myFollower_->setTarget(newTargets.first);
    202                 }
    203             }
    204             if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    205             {
    206                 this->bPatrolling_ = true;
    207                 if (this->bLoop_)
    208                 {
    209                     Point p = { Action::FIGHT, "", Vector3::ZERO, true };
    210                     this->loopActionpoints_.push_back(p);
    211                     this->executeActionpoint();
    212                 }
    213                 else
    214                 {
    215                     Point p = { Action::FIGHT, "", Vector3::ZERO, false };
    216                     this->parsedActionpoints_.push_back(p);
    217                     this->executeActionpoint();   
    218                 }                   
    219             }
    220             return true;
    221         }
    222         else
    223         {
    224             return false;
    225         }
    226     }
    227     //checks if state is still to be executed and makes a transition otherwise.
    228     //if this->bDefaultPatrol_ == true, patrols area for enemies and, if not fighting, pushes a state with action = FIGHT
    229     void ActionpointController::stateMachine()
    230     {
    231         //Check if calculations needed
    232         if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()) || !this->isActive())
    233             return;
    234 
    235         //state NONE means that either previous state finished executing and next state is to be fetched or no states are left to execute
    236         //NONE is never on a stack -> it is only a transition state saved in a variable
    237         if (this->action_ == Action::NONE || this->bTakenOver_)
    238         {
    239             //no actionpoints a.k.a. states left to execute
    240             if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
    241             {
    242                 //default action is fighting
    243                 if (this->bDefaultFightAll_)
    244                 {
    245                     //make state
    246                     Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
    247                     //push it on the stack
    248                     this->parsedActionpoints_.push_back (p);
    249                 }
    250                 //default action is nothing
    251                 else
    252                 {
    253                     this->bActive_ = false;
    254                     return;
    255                 }     
    256             }
    257             //switch to the new state
    258             this->executeActionpoint();
    259             this->bTakenOver_ = false;
    260         }
    261         if (this->action_ == Action::FIGHTALL)
    262         {
    263             if (!this->hasTarget())
    264             {
    265                 ControllableEntity* newTarget = this->closestTarget();   
    266                 if (newTarget)
    267                 {
    268                     this->setTarget (newTarget);
    269                 }
    270                 else
    271                 {
    272                     this->nextActionpoint();
    273                     this->executeActionpoint();
    274                 }
    275             }
    276             else
    277             {
    278                 bool b = this->patrol();
    279             }
    280 
    281         }
    282         if (this->action_ == Action::FIGHT)
    283         {
    284             if (!this->hasTarget() )
    285             {
    286                 if (!this->patrol())
    287                 {
    288                     if (this->bPatrolling_)
    289                     {
    290                         if (this->bLoop_)
    291                         {
    292                             if (!this->loopActionpoints_.empty())
    293                             {
    294                                 this->loopActionpoints_.pop_back();
    295                             }
    296                         }
    297                         else
    298                         {
    299                             if (!this->parsedActionpoints_.empty())
    300                             {
    301                                 this->parsedActionpoints_.pop_back();
    302                             }           
    303                         }
    304                         this->setAction(Action::NONE);
    305                         this->bHasTargetPosition_ = false;
    306                         this->bPatrolling_ = false;
    307                     }
    308                     else
    309                     {
    310                         this->nextActionpoint();
    311                     }
    312                     this->executeActionpoint();
    313                 }
    314             }
    315             else if (this->hasTarget())
    316             {
    317                 if (CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
    318                 {
    319                     this->setTarget(0);
    320                     this->stateMachine();
    321                 }
    322             }
    323         }
    324         if (this->action_ == Action::FLY)
    325         {
    326             if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    327             {
    328                 this->nextActionpoint();   
    329                 this->executeActionpoint();
    330             }
    331             else if (this->bDefaultPatrol_)
    332             {
    333                 bool b = this->patrol();
    334             }
    335         }
    336         if (this->action_ == Action::PROTECT)
    337         {
    338             if (!this->getProtect())
    339             {
    340                 this->nextActionpoint();
    341                 this->executeActionpoint();
    342             }
    343             else
    344             {
    345                 this->stayNearProtect();
    346             }
    347             if (this->bDefaultPatrol_)
    348             {
    349                 bool b = this->patrol();
    350             }
    351         }
    352         if (this->action_ == Action::ATTACK)
    353         {   
    354             if (!this->hasTarget())
    355             {
    356                 this->nextActionpoint();
    357                 this->executeActionpoint();
    358             }
    359             if (this->bDefaultPatrol_)
    360             {
    361                 bool b = this->patrol();
    362             }
    363         }
    364     }
    365 
     172     
    366173
    367174
     
    372179        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
    373180            return;
    374         this->startAttackingEnemiesThatAreClose();
     181        if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
     182        {
     183            this->startAttackingEnemiesThatAreClose();
     184        }
    375185
    376186        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
     
    388198            // }
    389199
    390             if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
     200            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
    391201            {
    392202                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
     
    395205            this->executeActionpoint();
    396206            this->bTakenOver_ = false;
    397             this->action();
     207            // this->action();
    398208        }
    399209        //Action fightall -> fight till nobody alive
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10910 r10912  
    3535#include "../modules/pickup/PickupSpawner.h"
    3636#include <map>
     37
     38
    3739
    3840namespace orxonox
     
    159161            */
    160162            void addActionpoint(WorldEntity* actionpoint);
    161             WorldEntity* getActionpoint(unsigned int index) const;           
     163            WorldEntity* getActionpoint(unsigned int index) const;   
     164            void setDefaultFightAll(bool value)
     165                { this->bDefaultFightAll_ = value; }
     166            bool getDefaultFightAll ()
     167                { return this->bDefaultFightAll_; }
     168            void setDefaultPatrol(bool value)
     169                { this->bDefaultPatrol_ = value; }
     170            bool getDefaultPatrol ()
     171                { return this->bDefaultPatrol_; }
     172                 // Trigger interface
     173            // bool stop(bool bTriggered, BaseObject* trigger);
     174            // bool go(bool bTriggered, BaseObject* trigger);
     175            // virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     176
    162177            virtual void stayNearProtect();
    163178            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
     
    180195            virtual bool hasFollower()
    181196                { return true; }
    182             void stateMachine();
    183             bool patrol();
    184             std::pair <ControllableEntity*, ControllableEntity*> closestTargets();
     197
    185198
    186199        protected:
     
    243256                bool bManeuverCalled_;
    244257                bool bDefaultFightAll_;
     258
    245259                bool bActive_;
    246260                bool bPatrolling_;
    247261                bool bDefaultPatrol_;
     262                bool stop_;
    248263
    249264        private:
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10909 r10912  
    6060    {
    6161        SUPER(DivisionController, XMLPort, xmlelement, mode);
    62 
     62       
    6363        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    6464    }
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10909 r10912  
    125125            {
    126126                this->keepFormation();
     127                //orxout (internal_error) << "Keeping formation" << endl;
     128
    127129            }
    128130            else if (!this->myDivisionLeader_->bKeepFormation_)
     
    130132                if (!this->hasTarget())
    131133                {
    132                     this->chooseTarget();
     134                    //this->chooseTarget();
     135                    //orxout (internal_error) << "Section ain't got no target" << endl;
    133136                }
    134137                if (this->hasTarget())
Note: See TracChangeset for help on using the changeset viewer.