Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2015, 4:04:16 PM (9 years ago)
Author:
gania
Message:

commented some stuff

Location:
code/branches/campaignHS15
Files:
7 edited

Legend:

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

    r10888 r10898  
    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=1 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     38    <TeamSpawnPoint team=0 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3939   
    4040<!--     
     
    102102          <actionpoints>
    103103            <Actionpoint position="0,0,0" action="FLY" />
    104             <Actionpoint position="-1000,750,-500" action="ATTACK" attack="ss3" />
     104            <Actionpoint position="-1000,750,-500" action="ATTACK" attack="attack" />
    105105            <Actionpoint position="-1000,750,-500" action="PROTECt" protectMe=true />
    106             <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
     106            <Actionpoint position="-1000,750,-500" action="PROTECt" protect="protect" />
    107107            <Actionpoint position="-1000,750,-500" action="FIGHTALL" />
    108108           </actionpoints>
     
    142142      </templates>
    143143    </SpaceShip>
    144     <SpaceShip position="3000, 1000, 2000" lookat="0,0,0" team=2 name="ss3">
    145       <templates>
    146         <Template link=spaceshipassff />
    147       </templates>
    148     </SpaceShip>
    149     <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name="fuck">
    150       <templates>
    151         <Template link=spaceshipassff />
    152       </templates>
    153     </SpaceShip>
    154  
    155     -->
     144    <SpaceShip position="3000, 1000, 2000" lookat="0,0,0" team=2 name="attack">
     145      <templates>
     146        <Template link=spaceshipassff />
     147      </templates>
     148    </SpaceShip>
     149    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name="protect">
     150      <templates>
     151        <Template link=spaceshipassff />
     152      </templates>
     153    </SpaceShip>
     154  -->
     155   
    156156<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
    157157<!-- HERE STARTS DEMO FOR FIGHTING -->
     
    253253      </controller>
    254254    </SpaceShip>
    255     <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>
     255   <!-- <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>
    256256      <templates>
    257257        <Template link=spaceshipassff />
     
    272272      </controller>
    273273    </SpaceShip>
    274 
     274 -->
    275275   
    276276<!-- HERE ENDS DEMO FOR FIGHTING -->
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10888 r10898  
    122122        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    123123        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
    124         if (this->actionCounter_ % 2 == 0)
    125             this->startAttackingEnemiesThatAreClose();
     124        // if (this->actionCounter_ % 2 == 0)
    126125        //No action -> pop one from stack
    127126        if (this->action_ == Action::NONE || this->bTakenOver_)
     
    133132            //     this->parsedActionpoints_.push_back(point);
    134133            // }
     134            this->startAttackingEnemiesThatAreClose();
     135
    135136            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
    136137            {
     
    209210        else if (this->action_ == Action::FLY)
    210211        {
     212            this->startAttackingEnemiesThatAreClose();           
    211213            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    212214            {
     
    217219        else if (this->action_ == Action::PROTECT)
    218220        {
     221            this->startAttackingEnemiesThatAreClose();           
    219222            if (!this->getProtect())
    220223            {
     
    226229        else if (this->action_ == Action::ATTACK)
    227230        {   
     231            this->startAttackingEnemiesThatAreClose();           
    228232            if (!this->hasTarget())
    229233            {
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10888 r10898  
    3838namespace orxonox
    3939{
     40    /**
     41    @brief
     42        ActionpointController is a state machine with states:
     43            1) NONE
     44            2) FLY: fly towards a point
     45            3) FIGHT: fight enemies that are in attackRange_ (see FightingController)
     46            4) PROTECT: follow this->protect_
     47            5) FIGHTALL: fight all enemies on the map
     48            6) ATTACK: fight a specific spaceship
     49        This controller always executes an action that is in the back of the vector being used.
     50        After current this->action_ is completed, next action becomes the top action (one that will
     51        be returned by someVector.back()), and current action either will be removed (if not looping),
     52        or moved to the top (if looping).
     53
     54        Every second action(), which is once in two seconds, this searches the area for enemies that are in attack range, if finds anyone,
     55        pushes Action::FIGHT to the stack. That makes spaceship fight enemies inside of a sphere, and when all enemies in range are dead,
     56        Action::FIGHT is removed from the stack, and spaceship resumes doing whatever action was being executed before.
     57
     58        In XML one has to attack Actionpoints in order to achieve any complex behaviour, but in Controller all actionpoints are effectively
     59        being stored in an array of type Point::Value.
     60    */
    4061    namespace Action
    4162    { 
     
    6990               
    7091            virtual void tick(float dt);
    71 
    72             void addActionpoint(WorldEntity* waypoint);
     92            /**
     93            @brief
     94                XML method, example XML usage:
     95                <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
     96                  <templates>
     97                    <Template link=spaceshipassff />
     98                  </templates>
     99                  <controller>
     100                    <DivisionController team=0 formationMode="finger4">
     101                      <actionpoints>
     102                        <Actionpoint position="0,0,0" action="FLY" />
     103                        <Actionpoint position="-1000,750,-500" action="ATTACK" attack="attack" />
     104                        <Actionpoint position="-1000,750,-500" action="PROTECt" protectMe=true />
     105                        <Actionpoint position="-1000,750,-500" action="PROTECt" protect="protect" />
     106                        <Actionpoint position="-1000,750,-500" action="FIGHTALL" />
     107                       </actionpoints>
     108                    </DivisionController>
     109                  </controller>
     110                </SpaceShip>
     111               
     112                Full description:
     113                Adds an Actionpoint to this->actionpoints_. Actionpoint can take arguments like action="attack" attack="name".
     114                For documentation on Actionpoint XML arguments, check out Actionpoint.h class
     115                If any WorldEntity that is not Actionpoint or its child being sent to actionpoints through XML,
     116                action would be assumed to be Action::FLY and target position to be position of the entity. Also, if not Actionpoint
     117                is passed, it is assumed to be in a loop. How it works is: in <actionpoints> first all Actionpoints between
     118                first Actionpoint with loopStart=true and first following Actionpoint with loopEnd=true are included in a single loop.
     119                If they are adjacent (in the input array) with WorldEntity, then WorldEntity is also in a loop.
     120                All the Worldentities are assumed to be in loop.
     121               
     122                Loop example:
     123                <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
     124                  <templates>
     125                    <Template link=spaceshipassff />
     126                  </templates>
     127                  <controller>
     128                    <DivisionController team=0 formationMode="wall">
     129                      <actionpoints>
     130                        <Actionpoint position="  0,2000,-600" action="FLY" loopStart=true/>
     131                        <Actionpoint position="  0,2000,-1000" action="FLY"  />
     132                        <Actionpoint position="400,2000,-1000" action="FLY" />
     133                        <Actionpoint position="400,2000,-600" action="FLY" loopEnd=true />
     134                      </actionpoints>
     135                    </DivisionController>
     136                  </controller>
     137                </SpaceShip>
     138               
     139                other loop example:
     140                <SpaceShip position="-1500, -1500, -1500" lookat="0,0,0" team=0 name="ss1">
     141                  <templates>
     142                    <Template link=spaceshipassff />
     143                  </templates>
     144                  <controller>
     145                    <DivisionController team=0 formationMode="diamond">
     146                      <actionpoints>
     147                        <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
     148                        <Model mesh="cube.mesh" scale=8 position="  0,2000,-1000" />
     149                        <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" />
     150                        <Model mesh="cube.mesh" scale=8 position="400,2000,-600" />
     151                      </actionpoints>
     152                    </DivisionController>
     153                  </controller>
     154                </SpaceShip>
     155
     156            @note
     157                Don't use several loops, and don't use WorldEntities as input to <actionpoints> as I didn't test it well, but you
     158                can try if feeling lucky. 
     159            */
     160            void addActionpoint(WorldEntity* actionpoint);
    73161            WorldEntity* getActionpoint(unsigned int index) const;           
    74162            virtual void stayNearProtect();
     
    92180            virtual bool hasFollower()
    93181                { return true; }
    94                
     182
    95183        protected:
    96184                void startAttackingEnemiesThatAreClose();
     
    104192                std::vector<WeakPtr<WorldEntity> > actionpoints_;
    105193                float squaredaccuracy_;
    106                 std::vector<Point > parsedActionpoints_;
    107                 std::vector<Point > loopActionpoints_;
     194                std::vector<Point > parsedActionpoints_;//<! actionpoints as they are stored here after being parsed from XML
     195                std::vector<Point > loopActionpoints_;  //<! actionpoints that are to be looped
    108196                bool bInLoop_;
    109                 bool bLoop_;   
    110                 bool bEndLoop_; 
    111                 bool bTakenOver_; 
     197                bool bLoop_;                            //<! is state machine looping?
     198                bool bEndLoop_;                   
     199                bool bTakenOver_;                       //<! are actionpoints taken over from the leader when he died? if yes, top actionpoint
     200                                                        //<! is to be executed for the state machine to start working
    112201            //----[/Actionpoint information]----
    113202                void setProtect (ControllableEntity* protect);
    114203                ControllableEntity* getProtect ();
    115                 WeakPtr<ControllableEntity> protect_;    
    116                 void fillLoop();
     204                WeakPtr<ControllableEntity> protect_;   //<! entity that is to be protected if this->action_ == Action::PROTECT
     205                void fillLoop();                        //<! moves actionpoints that are should be in loop from parsedActionpoints_ to loopActionpoints_
    117206                void fillLoopReversed();
    118                 void moveBackToTop();
     207                void moveBackToTop();                   //<! analog of removing back actionpoint for loopActionpoints_: instead of removing it,
     208                                                        //<! move it to the top, so that it will be executed later on.
    119209                void setClosestTarget();
    120210                Pawn* closestTarget();
    121211            //----[Actionpoint methods]----
    122                 void executeActionpoint();
    123                 void nextActionpoint();
    124                 void pushAction(Point& p);
    125                 void popAction();
     212                /**
     213                @brief
     214                    Sets this->target_, this->targetPosition_, this->protect_ and this->action_ depending
     215                    on the current actionpoint in the vector parsedActionpoints_ if not looping or
     216                    loopActionpoints_ if looping.
     217                @note
     218                */
     219                void executeActionpoint(); 
     220                /**
     221                @brief
     222                    If this->bLoop_, move back action to top (back is the current one, top is the last),
     223                    otherwise remove back actionpoint.
     224                @note
     225                    actionpoints_ is only used for XML, real state stacks are parsedActionpoints_ and loopActionpoints_
     226                */           
     227                void nextActionpoint();                 
    126228            //----[Actionpoint methods]----         
    127229                bool bFirstTick_;
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10891 r10898  
    224224        return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
    225225    }
    226     // void FightingController::doFire()
    227     // {
    228     //     if ( !this->target_ || !this->getControllableEntity() )
    229     //     {
    230     //         return;
    231     //     }
    232      
    233     //     Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
    234 
    235     //     if ( pawn )
    236     //         pawn->setAimPosition( this->positionOfTarget_ );
    237     //     float distance = CommonController::distance (this->getControllableEntity(), this->target_);
    238     //     this->getControllableEntity() ->fire(distance < 1500 ? (distance < 1000 && distance > 700 ? 3 : 0) : (1));
    239     // }
    240226
    241227
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10888 r10898  
    3535namespace orxonox
    3636{
     37    /**
     38    @brief
     39        FightingController stores all the fighting methods and member variables of AI.
     40        Main methods here are maneuver() and dodge().
     41    */
    3742    class _OrxonoxExport FightingController : public FlyingController
    3843    {
     
    4954            ControllableEntity* getTarget() const
    5055                { return this->target_; }
    51             bool bKeepFormation_;
     56            bool bKeepFormation_;   //even if action_ == FIGHT, you might still want to keep formation if far enough form the target
    5257           
    5358        protected:
    54             void setTarget(ControllableEntity* target);
     59            void setTarget(ControllableEntity* target); //set a target to shoot at
    5560
    56             void setPositionOfTarget(const Vector3& target);
    57             void setOrientationOfTarget(const Quaternion& orient);
    58             void stopLookingAtTarget();
    59             void startLookingAtTarget();
    60             void lookAtTarget(float dt);
     61            void setPositionOfTarget(const Vector3& target);    //good to know where target is
     62            void setOrientationOfTarget(const Quaternion& orient);  //I don't really use that
     63            void stopLookingAtTarget();     //<! target dead -> you need to be able to fly
     64            void startLookingAtTarget();    //<! if close to target, no need to fly, just rotate yourself
     65            void lookAtTarget(float dt);    //<! rotate yourself towards target
    6166
    62             void maneuver();
    63             void dodge(const Vector3& thisPosition, Vector3& diffUnit);
    64             void dodgeTowards (Vector3& position);
    65             bool canFire();
    66             void doFire();
     67            void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
     68                             //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
     69            void dodge(const Vector3& thisPosition, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between
     70                                                                        //<! this and target_ plus or minus some amount in difference vector direction,
     71                                                                        //<! depending on whether it is better to close up or survive.
     72            void dodgeTowards (Vector3& position);  //fly towards position and awoid being hit
     73            bool canFire(); //<! check if target_ is in radius and if this is looking at target_
     74            void doFire();  //<! choose weapon, set aim at target_ and fire
    6775            WeakPtr<ControllableEntity> target_;
    6876            void setClosestTarget();
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10886 r10898  
    3535namespace orxonox
    3636{   
     37    /**
     38    @brief
     39        FlyingController stores all the flying methods and member variables of AI.
     40    */
    3741    namespace FormationMode
    3842    {
  • code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h

    r10888 r10898  
    2626 *
    2727 */
    28 
    29 /**
    30     @file Attacher.h
    31     @brief Definition of the Attacher class.
    32     @ingroup Objects
    33 */
    3428
    3529#ifndef _Actionpoint_H__
Note: See TracChangeset for help on using the changeset viewer.