Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10849


Ignore:
Timestamp:
Nov 24, 2015, 5:21:03 PM (8 years ago)
Author:
gania
Message:

major change: introduced Actionpoints, look AITest.oxw. Only FLY works for now

Location:
code/branches/campaignHS15
Files:
4 edited

Legend:

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

    r10847 r10849  
    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=1 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <TeamSpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535   
    3636<!--
     
    5353<!--                 <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" />
    5454 -->
    55     <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
     55<!--     <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
    5656      <templates>
    5757        <Template link=spaceshipassff />
     
    6161        </DivisionController>
    6262      </controller>
    63     </SpaceShip>
    64     <SpaceShip position="0, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
     63    </SpaceShip> -->
     64    <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=1 name="ss2">
    6565      <templates>
    6666        <Template link=spaceshipassff />
    6767      </templates>
    6868      <controller>
    69         <DivisionController team=12>
     69        <DivisionController team=1>
    7070          <actionpoints>
    71             <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />
    72             <Actionpoint position="12,34,56" action="FLY" />
     71            <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
     72            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
     73            <Actionpoint position="-1000,750,-500" action="FLY" />
     74            <Actionpoint position="0,0,0" action="FLY" />
    7375          </actionpoints>
    7476        </DivisionController>
    7577      </controller>
    7678    </SpaceShip>
    77    
     79    <SpaceShip position="0, 0, 0" lookat="0,0,0" team=2 name="ss4">
     80      <templates>
     81        <Template link=spaceshipassff />
     82      </templates>
     83    </SpaceShip>
     84    <SpaceShip position="1000, 300, 200" lookat="0,0,0" team=2 name="ss3">
     85      <templates>
     86        <Template link=spaceshipassff />
     87      </templates>
     88    </SpaceShip>
     89    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=1 name="fuck">
     90      <templates>
     91        <Template link=spaceshipassff />
     92      </templates>
     93    </SpaceShip>
    7894   <!--  <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
    7995      <templates>
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10848 r10849  
    5858    CommonController::CommonController( Context* context ): Controller( context )
    5959    {
    60         this->action_ = Action::FLY;
     60        this->squaredaccuracy_ = 500;
     61        this->action_ = Action::NONE;
    6162        this->stopLookingAtTarget();
    62         this->attackRange_ = 2500;
     63        this->attackRange_ = 800;
    6364        RegisterObject( CommonController );
    6465    }
     
    6970        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
    7071    }
    71     void CommonController::backupAction()
    72     {
    73         this->actionpoints_.push_back (this->currentActionpoint_);
    74     }
    75     void CommonController::restoreAction()
    76     {
    77         this->currentActionpoint_ = this->actionpoints_.back();
    78         this->actionpoints_.pop_back();
    79     }
    80     void CommonController::popAction()
    81     {
    82         this->currentActionpoint_ = actionpoints_.back();
    83         actionpoints_.pop_back();
    84     }
    85 
     72   
     73 
    8674    void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
    8775    {
     
    120108        if (!this->getProtect())
    121109            return "noProtectWasSet";
    122         return CommonController::getName (this->getProtect());
     110        return CommonController::getName (orxonox_cast<Pawn*>(this->getProtect()));
    123111    }
    124112    std::string CommonController::getName(Pawn* entity)
     
    256244    {
    257245        this->action_ = action;
    258         if (action == Action::FIGHT)
     246        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
    259247        {   
    260248            if (target)
     
    334322            }
    335323            else
    336                 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
     324                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
    337325            //this->setAction( value );
    338             parsedActionpoints_.push_back( std::make_tuple (value, targetName, position) );
    339         }
    340         else
    341         {
    342             parsedActionpoints_.push_back(
    343                 std::make_tuple (Action::FLY, "", actionpoint->getWorldPosition()) );
     326            Point p = { value, targetName, position };
     327            parsedActionpoints_.push_back(p);
     328            orxout(internal_error) << "Pushed " << p.action << endl;
     329        }
     330        else
     331        {
     332            Point p = { Action::FLY, "", actionpoint->getWorldPosition() };
     333            parsedActionpoints_.push_back(p);
    344334        }
    345335            this->actionpoints_.push_back(actionpoint);
     
    357347    void CommonController::setClosestTarget()
    358348    {
    359         this->setTarget (closestTarget());
    360     }
    361     ControllableEntity* CommonController::closestTarget()
     349        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) );
     350    }
     351    Pawn* CommonController::closestTarget()
    362352    {
    363353        if (!this->getControllableEntity())
     
    381371        if (closestTarget)
    382372        {
    383            return static_cast<ControllableEntity*>(closestTarget);
     373           return closestTarget;
    384374        }
    385375        return 0; 
     
    391381        if (!this->parsedActionpoints_.empty())
    392382        {
    393             this->action_ = std::get<0>( this->parsedActionpoints_.back() );
     383            this->action_ = this->parsedActionpoints_.back().action;
    394384
    395385            switch ( this->action_ )
     
    401391                case Action::FLY:
    402392                {
    403                     this->setTargetPosition(std::get<2>( this->parsedActionpoints_.back() ));
     393                    this->setTargetPosition( this->parsedActionpoints_.back().position );
    404394                    if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    405395                    {
     
    411401                case Action::PROTECT:
    412402                {
    413                     std::string protectName = std::get<1>( this->parsedActionpoints_.back() );
     403                    std::string protectName = this->parsedActionpoints_.back().name;
    414404
    415405                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     
    437427                case Action::ATTACK:
    438428                {
    439                     std::string targetName = std::get<1>( this->parsedActionpoints_.back() );
     429                    std::string targetName = this->parsedActionpoints_.back().name;
    440430
    441431                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     
    443433                        if (CommonController::getName(*itP) == targetName)
    444434                        {
     435                            orxout(internal_error) << "Attacking" << endl;
    445436                            this->setTarget (static_cast<ControllableEntity*>(*itP));
    446437                        }
     
    465456            this->action_ = Action::NONE;
    466457        }
     458        orxout(internal_error) << "Executing action " << this->getActionXML() << endl;
    467459    }
    468460    void CommonController::nextActionpoint()
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10848 r10849  
    6565            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
    6666        };
     67       
    6768    }
     69   
     70    struct Point {
     71        Action::Value action;
     72        std::string name;
     73        Vector3 position;
     74    } ;
     75
     76
     77   
    6878 
    6979
     
    171181                void doFire();
    172182                void setClosestTarget();
    173                 ControllableEntity* closestTarget();
     183                Pawn* closestTarget();
    174184
    175185                bool bShooting_;
     
    200210                std::vector<WeakPtr<WorldEntity> > actionpoints_;
    201211                float squaredaccuracy_;
    202                 <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_;
    203                 std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_;
     212                Point  currentActionpoint_;
     213                std::vector<Point > parsedActionpoints_;
     214                void executeActionpoint();
     215                void nextActionpoint();
    204216            //----[/Actionpoint information]----
    205217            //----["Private" variables]----
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10848 r10849  
    2828
    2929#include "DivisionController.h"
    30 
     30#include "infos/PlayerInfo.h"
    3131
    3232namespace orxonox
     
    9393        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    9494        {
    95             if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
    96              !this->target_)
    97             {
    98                 ControllableEntity* newTarget = this->closestTarget();
     95            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
     96                || !this->target_ )
     97            {
     98                Pawn* newTarget = this->closestTarget();
    9999                if ( newTarget &&
    100                     CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ )
     100                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
     101                        <= this->attackRange_ )
    101102                {
    102103                    // this->backupAction();
    103104                    // this->setAction (Action::FIGHT, newTarget);
    104                     this->parsedActionpoints_.push_back(
    105                         std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) );
     105                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
     106                    this->parsedActionpoints_.push_back(p);
     107                    this->executeActionpoint();
    106108                }
    107109            }
     
    113115        if (this->action_ == Action::NONE)
    114116        {
    115 
    116         }
    117 
    118         this->executeActionpoint();
     117            this->executeActionpoint();
     118        }
     119
    119120
    120121        //this->action_ is what I am actually executing, this->target_ is what I am
     
    142143                else if (this->action_ == Action::FIGHTALL)
    143144                {
    144                     if (newTarget)
     145                    if (newTarget && newTarget->getController())
    145146                    {
    146147                        this->setAction (Action::FIGHTALL, newTarget);
     
    158159                //----fly in formation if far enough----
    159160                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     161               
     162                   
    160163                if (diffVector.length() > this->attackRange_)
    161164                {
     
    198201        else if (this->action_ == Action::FLY)
    199202        {
     203
     204            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     205            {
     206                orxout(internal_error) << "arrived";
     207                this->nextActionpoint();
     208                return;
     209            }
    200210            this->setTargetPositionOfWingman();
    201211            this->setTargetPositionOfFollower();
     
    203213        else if (this->action_ == Action::PROTECT)
    204214        {
     215            if (!this->getProtect())
     216            {
     217                this->nextActionpoint();
     218                return;
     219            }
    205220           /* if (this->myWingman_)
    206221                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
     
    218233            this->setTargetPositionOfWingman();
    219234            this->setTargetPositionOfFollower();
     235
    220236        }
    221237        else if (this->action_ == Action::ATTACK)
    222238        {   
    223             if (this->hasTarget())
    224             {
    225                 //----fly in formation if far enough----
    226                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    227                 if (diffVector.length() > this->attackRange_)
    228                 {
    229                     this->setTargetPositionOfWingman();
    230                     this->setTargetPositionOfFollower();                   
    231                 }
    232                 else
    233                 {
    234                     //----wingmans shall support the fire of their leaders----
    235                     if (this->myWingman_)
    236                     {
    237                         this->myWingman_->setAction (this->action_, this->target_);     
    238                     }
    239                     if (this->myFollower_)
    240                     {
    241                         this->myFollower_->setAction (this->action_);                                   
    242                     }
    243 
    244                 }
    245                
    246             }
    247             if (this->hasTarget())
    248             {
    249                 //----choose where to go----
    250                 this->maneuver();
    251                 //----fire if you can----
    252                 this->bShooting_ = this->canFire();               
    253             }
     239            if (!this->hasTarget())
     240            {
     241                this->nextActionpoint();
     242                return;
     243            }
     244            //----fly in formation if far enough----
     245            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     246            if (diffVector.length() > this->attackRange_)
     247            {
     248                this->setTargetPositionOfWingman();
     249                this->setTargetPositionOfFollower();                   
     250            }
     251            else
     252            {
     253                //----wingmans shall support the fire of their leaders----
     254                if (this->myWingman_)
     255                {
     256                    this->myWingman_->setAction (this->action_, this->target_);     
     257                }
     258                if (this->myFollower_)
     259                {
     260                    this->myFollower_->setAction (this->action_);                                   
     261                }
     262
     263            }
     264           
     265            //----choose where to go----
     266            this->maneuver();
     267            //----fire if you can----
     268            this->bShooting_ = this->canFire();               
    254269        }
    255270
Note: See TracChangeset for help on using the changeset viewer.