Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10885


Ignore:
Timestamp:
Nov 28, 2015, 10:30:56 PM (8 years ago)
Author:
gania
Message:

added other weapons

Location:
code/branches/campaignHS15
Files:
19 edited

Legend:

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

    r10883 r10885  
    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="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <TeamSpawnPoint team=0 position="-5000, 3000, -2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535   
    3636<!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
     
    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>
     
    134134      <controller>
    135135        <DivisionController team=0 formationMode="WALL">
    136           <actionpoints>
    137             <Actionpoint position="0,0,0" action="ATTACK" attack="ss3" />
    138           </actionpoints>
     136
    139137        </DivisionController>
    140138      </controller>
     
    167165      </controller>
    168166    </SpaceShip>
    169 
    170     <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 name="ss3">
     167    <SpaceShip position="-4000, 1500, -3000" lookat="0,0,0" team=0>
     168      <templates>
     169        <Template link=spaceshipassff />
     170      </templates>
     171      <controller>
     172        <DivisionController team=0 formationMode="WALL">
     173
     174        </DivisionController>
     175      </controller>
     176    </SpaceShip>
     177    <SpaceShip position="-4000, 1900, -3000" lookat="0,0,0" team=0>
     178      <templates>
     179        <Template link=spaceshipassff />
     180      </templates>
     181      <controller>
     182        <SectionController team=0>
     183        </SectionController>
     184      </controller>
     185    </SpaceShip>
     186
     187
     188    <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 >
    171189      <templates>
    172190        <Template link=spaceshipassff />
     
    174192      <controller>
    175193        <DivisionController team=1 formationMode="WALL">
    176           <actionpoints>
    177             <Actionpoint position="0,0,0" action="ATTACk" attack="ss2" />
    178           </actionpoints>
     194
    179195        </DivisionController>
    180196      </controller>
     
    207223      </controller>
    208224    </SpaceShip>
    209      -->
     225    <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>
     226      <templates>
     227        <Template link=spaceshipassff />
     228      </templates>
     229      <controller>
     230        <DivisionController team=1 formationMode="WALL">
     231
     232        </DivisionController>
     233      </controller>
     234    </SpaceShip>
     235    <SpaceShip position="2000, -1900, 3000" lookat="0,0,0" team=1>
     236      <templates>
     237        <Template link=spaceshipassff />
     238      </templates>
     239      <controller>
     240        <SectionController team=1>
     241        </SectionController>
     242      </controller>
     243    </SpaceShip>
     244
     245   
    210246<!-- HERE ENDS DEMO FOR FIGHTING -->
    211247<!-- HERE STARTS DEMO FOR FORMATIONS -->
    212    
     248    <!--
    213249    <Model mesh="cube.mesh" scale=8 position="   0,2000,    0" />
    214250    <Model mesh="cube.mesh" scale=8 position="   0,2000,-2000" />
     
    259295      </controller>
    260296    </SpaceShip>
    261    
     297    -->
    262298<!-- HERE ENDS DEMO FOR FORMATIONS -->
    263299    <!--
    264     <SpaceShip position="2000, 2000, 2000" lookat="0,0,0" team=1 name="ss2">
     300    <SpaceShip position="-2000, 3000, -2000" lookat="0,0,0" team=1 name="ss2">
    265301      <templates>
    266302        <Template link=spaceshipassff />
     
    272308      </controller>
    273309    </SpaceShip>
    274    
    275310 -->
     311
    276312  </Scene>
    277313</Level>
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    6161        void ActionpointController::tick(float dt)
    6262        {
     63        if (this->timeout_ > 0 && this->bFiredRocket_)
     64        {
     65            this->timeout_ -= dt;
     66        }
     67        if (timeout_ <= 0)
     68            this->bFiredRocket_ = false;
     69
    6370                if (this->bHasTargetPosition_)
    6471        {
     
    6976            this->lookAtTarget(dt);
    7077        }
    71         if (bShooting_)
     78        if (this->bShooting_)
    7279        {
    7380            this->doFire();
     
    537544
    538545    }
    539     void ActionpointController::takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b)
     546    void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
    540547    {
    541548      this->parsedActionpoints_ = vector;
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      ...
     
    5555    {
    5656        public:
    57             //----[language demanded functions]----           
    58                 ActionpointController(Context* context);
    59                 virtual ~ActionpointController();
    60             //----[language demanded functions]----           
    61                 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
     57            ActionpointController(Context* context);
     58            virtual ~ActionpointController();
     59            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
    6260               
    63             virtual void tick(float dt);
     61            virtual void tick(float dt);
     62
    6463            void addActionpoint(WorldEntity* waypoint);
    6564            WorldEntity* getActionpoint(unsigned int index) const;           
    6665            virtual void stayNearProtect();
    6766            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    68             virtual void takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b);
    69             Action::Value getAction ();
    70             std::string getActionName();
     67            virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b);
     68
     69            virtual Action::Value getAction ();
     70            virtual std::string getActionName();
    7171
    7272            void setAction (Action::Value action);
     
    8383            virtual bool hasFollower()
    8484                { return true; }
    85 
     85               
    8686        protected:
    87             void startAttackingEnemiesThatAreClose();
    88 
     87                void startAttackingEnemiesThatAreClose();
     88                WeakPtr<ActionpointController> myWingman_;
     89                WeakPtr<ActionpointController> myFollower_;
     90                WeakPtr<ActionpointController> myDivisionLeader_;
    8991            //----[Actionpoint information]----
    9092                Action::Value action_;
     
    103105                ControllableEntity* getProtect ();
    104106                WeakPtr<ControllableEntity> protect_;     
    105 
     107                void fillLoop();
     108                void fillLoopReversed();
     109                void moveBackToTop();
    106110                void setClosestTarget();
    107111                Pawn* closestTarget();
     
    109113                void executeActionpoint();
    110114                void nextActionpoint();
    111                 void fillLoop();
    112                 void fillLoopReversed();
    113                 void moveBackToTop();
     115                void pushAction(Point& p);
     116                void popAction();
    114117            //----[Actionpoint methods]----         
    115118                bool bFirstTick_;
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      Dominik Solenicki
     
    5252    float CommonController::randomInRange( float a, float b )
    5353    {
    54         float random = rnd( 1.0f );
    55         float diff = b - a;
    56         float r = random * diff;
    57         return a + r;
     54        return a + rnd(1.0f) * (b - a);
    5855    }
    5956    float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
     
    193190        return name;
    194191    }
    195  
    196 
    197192}
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    9696    }
    9797   
    98     bool DivisionController::setWingman(ActionpointController* wingman)
     98    bool DivisionController::setWingman(ActionpointController* newWingman)
    9999    {
    100 
    101         WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
    102100        if (!this->myWingman_)
    103101        {
    104102            this->myWingman_ = newWingman;
     103            if (!this->hasFollower())
     104                newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
    105105            return true;
    106106        }
     
    110110        }
    111111    }
    112     bool DivisionController::setFollower(ActionpointController* myFollower)
     112    bool DivisionController::setFollower(ActionpointController* newFollower)
    113113    {
    114         LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower);
    115114        if (!this->myFollower_)
    116115        {
     
    120119                this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false);
    121120            }
     121
     122            newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
     123           
    122124            return true;
    123125        }
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    5252
    5353            //----[own functions]----
    54                 virtual bool setFollower(ActionpointController* myFollower);
    55                 virtual bool setWingman(ActionpointController* wingman);
     54                virtual bool setFollower(ActionpointController* newFollower);
     55                virtual bool setWingman(ActionpointController* newWingman);
    5656                virtual bool hasWingman();
    5757                virtual bool hasFollower();
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      Fabian 'x3n' Landau, Dominik Solenicki
    2626 *
    2727 */
     
    3131
    3232
     33#include "worldentities/pawns/SpaceShip.h"
     34
     35#include "weaponsystem/WeaponMode.h"
     36#include "weaponsystem/WeaponPack.h"
     37#include "weaponsystem/Weapon.h"
     38#include "weaponsystem/WeaponSlot.h"
     39#include "weaponsystem/WeaponSlot.h"
    3340namespace orxonox
    3441{
     
    3845    FightingController::FightingController( Context* context ): FlyingController( context )
    3946    {
    40         this->attackRange_ = 2000;
     47        this->attackRange_ = 3000;
    4148        this->stopLookingAtTarget();
    42 
     49        this->bSetupWorked = false;
     50        this->timeout_ = 0;
    4351        RegisterObject( FightingController );
    4452    }
     
    7886        this->bLookAtTarget_ = true;
    7987    }
    80     bool FightingController::hasTarget()
     88    bool FightingController::hasTarget() const
    8189    {
    8290        if ( this->target_ )
     
    106114    void FightingController::maneuver()
    107115    {
     116        if ( !this->target_ || !this->getControllableEntity())
     117            return;
    108118        maneuverCounter_++;
    109119        if (maneuverCounter_ > 5)
    110120            maneuverCounter_ = 0;
    111121
    112         if ( !this->target_ || !this->getControllableEntity())
    113             return;
    114        
    115122        Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
    116         this->setPositionOfTarget( getPredictedPosition(
    117             thisPosition,
    118             hardcoded_projectile_speed,
    119             this->target_->getWorldPosition() ,
    120             this->target_->getVelocity() 
    121             )  );
    122         this->setOrientationOfTarget( this->target_->getOrientation() );
    123 
     123        this->setPositionOfTarget(this->target_->getWorldPosition());
     124        //this->setOrientationOfTarget(this->target_->getOrientation());
    124125        Vector3 diffVector = this->positionOfTarget_ - thisPosition;
    125126        float diffLength = diffVector.length();
    126127        Vector3 diffUnit = diffVector/diffLength;
    127 
    128         bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/20.0f );
     128        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f);
    129129       
    130130        //too far? well, come closer then
     
    135135            this->bKeepFormation_ = true;
    136136           
    137             this->setTargetPosition( this->positionOfTarget_ );
     137            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
    138138        }
    139139        //too close? How do u expect to dodge anything? Just attack!
    140         else if ( diffLength < 500 )
     140        else if (diffLength < 500)
    141141        {   
    142142            this->bKeepFormation_ = false;
    143143
    144144            //at this point, just look and shoot
    145             if ( diffLength < 250 )
     145            if (diffLength < 250)
    146146            {
    147147                this->stopMoving();
     
    150150            else
    151151            {
    152                 this->setTargetPosition( this->positionOfTarget_ );
     152                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
    153153            }
    154154        }
    155155        //Good distance? Check if target looks at us. It doesn't? Go hunt!
    156         else if ( !bTargetIsLookingAtThis )
     156        else if (!bTargetIsLookingAtThis)
    157157        {
    158158            this->bKeepFormation_ = false;
    159             this->setTargetPosition( this->positionOfTarget_ );
     159            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
    160160        }
    161161        //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
     
    165165            if (maneuverCounter_ == 0)
    166166            {
    167                 this->setTargetPosition( this->positionOfTarget_ );   
     167                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);   
    168168                return;
    169169            }
    170             dodge( thisPosition, diffUnit );
     170            dodge(thisPosition, diffUnit);
    171171        }
    172172    }
    173173   
    174     void FightingController::dodge(Vector3& thisPosition, Vector3& diffUnit)
    175     {
    176         float factorX = 0, factorY = 0, factorZ = 0;
    177         float rand = CommonController::randomInRange (0, 1);
    178    
    179         if (rand <= 0.5)
    180         { factorX = 1; }
     174    void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)
     175    {
     176        //d.x*x + d.y*y + d.z*z == 0
     177        //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);
     180        float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
     181        this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);
     182        this->boostControl();
     183
     184    }
     185    bool FightingController::canFire()
     186    {
     187        //no target? why fire?
     188        if (!this->target_)
     189            return false;
     190        Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
     191                                                           hardcoded_projectile_speed, this->target_->getWorldPosition(),
     192                                                           this->target_->getVelocity());
     193        if (!newPositionOfTarget.isNaN())
     194        {
     195            this->setPositionOfTarget(newPositionOfTarget);
     196        }
     197        return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
     198    }
     199    // void FightingController::doFire()
     200    // {
     201    //     if ( !this->target_ || !this->getControllableEntity() )
     202    //     {
     203    //         return;
     204    //     }
     205     
     206    //     Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
     207
     208    //     if ( pawn )
     209    //         pawn->setAimPosition( this->positionOfTarget_ );
     210    //     float distance = CommonController::distance (this->getControllableEntity(), this->target_);
     211    //     this->getControllableEntity() ->fire(distance < 1500 ? (distance < 1000 && distance > 700 ? 3 : 0) : (1));
     212    // }
     213
     214
     215    float FightingController::squaredDistanceToTarget()  const
     216    {
     217        if (!this->getControllableEntity())
     218            return 0;
     219        if (!this->target_ || !this->getControllableEntity())
     220            return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_));
    181221        else
    182         { factorX = -1; }
    183         rand = CommonController::randomInRange (0, 1);
    184         if (rand <= 0.5)
    185         { factorY = 1; }
    186         else
    187         { factorY = -1; }
    188         rand = CommonController::randomInRange (0, 1);
    189         if (rand <= 0.5)
    190         { factorZ = 1; }
    191         else
    192         { factorZ = -1; }
    193 
    194         Vector3 target = ( diffUnit )* 8000.0f;
    195         Vector3* randVector = new Vector3(
    196             factorX * CommonController::randomInRange( 10000, 40000 ),
    197             factorY * CommonController::randomInRange( 10000, 40000 ),
    198             factorZ * CommonController::randomInRange( 10000, 40000 )
    199         );
    200         Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
    201         Vector3 randV = *randVector;
    202         delete randVector;
    203         randV -= projection;
    204         target += randV;
    205         this->setTargetPosition( thisPosition + target );
    206     }
    207     bool FightingController::canFire()
    208     {
    209         //no target? why fire?
    210         if ( !this->target_ )
    211             return false;
    212 
    213         Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() ,
    214             hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
    215         if ( newPositionOfTarget != Vector3::ZERO )
    216         {
    217             this->setPositionOfTarget( newPositionOfTarget );
    218         }
    219 
    220         float squaredDistance = squaredDistanceToTarget();
    221 
    222         if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f))
    223         {
    224             return true;
    225         }
    226         else
    227         {
    228             return false;
    229         }
    230     }
    231     void FightingController::doFire()
    232     {
    233         if ( !this->target_ || !this->getControllableEntity() )
    234         {
    235             return;
    236         }
    237      
    238         Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
    239 
    240         if ( pawn )
    241             pawn->setAimPosition( this->positionOfTarget_ );
    242         this->getControllableEntity() ->fire( 0 );
    243     }
    244     float FightingController::squaredDistanceToTarget()  const
    245     {
    246         if ( !this->getControllableEntity()  )
    247             return 0;
    248         if ( !this->target_ || !this->getControllableEntity() )
    249             return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
    250         else
    251             return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
    252     }
    253     bool FightingController::isLookingAtTarget( float angle )
     222            return (this->getControllableEntity()->getPosition().squaredDistance(this->positionOfTarget_));
     223    }
     224    bool FightingController::isLookingAtTarget( float angle ) const
    254225    {
    255226        if ( !this->getControllableEntity()  || !this->target_ )
     
    257228        return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle);
    258229    }
    259         void FightingController::setClosestTarget()
     230    void FightingController::setClosestTarget()
    260231    {
    261232        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) );
    262233    }
    263234   
    264     Pawn* FightingController::closestTarget()
     235    Pawn* FightingController::closestTarget() const
    265236    {
    266237        if (!this->getControllableEntity())
     
    288259        return 0; 
    289260    }
     261    //I checked it out, rockets DO NOT cause any problems! this->getControllableEntity() is always a SpaceShip
     262    void FightingController::doFire()
     263    {
     264        if (!this->bSetupWorked)
     265        {
     266            this->setupWeapons();
     267        }
     268        if (!this->target_ || !this->getControllableEntity())
     269        {
     270            return;
     271        }
     272        Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity());
     273        if (pawn)
     274            pawn->setAimPosition (this->positionOfTarget_);
     275
     276        int firemode;
     277        float distance = CommonController::distance (this->getControllableEntity(), this->target_);
     278
     279        // firemode = distance < 1500 ? (distance > 800 && distance < 1200 ?
     280        //                             (this->rocketsLeft_ > 0 && !this->bFiredRocket_ ? getFiremode("RocketFire") : getFiremode ("HsW01"))
     281        //                                                      : getFiremode("HsW01")) :
     282        //                                                      (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01"));
     283        if (distance < 800)
     284        {
     285            if (this->rocketsLeft_ > 0)
     286            {
     287                firemode = getFiremode ("SimpleRocketFire");
     288            }
     289            else
     290            {
     291                if (distance > 450)
     292                    firemode = getFiremode ("LightningGun");
     293                else
     294                    firemode = getFiremode ("HsW01");
     295            }
     296
     297        }
     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)
     310        {
     311            firemode = getFiremode ("LightningGun");
     312        }
     313        else
     314        {
     315            firemode = getFiremode ("HsW01");
     316        }
     317        if (firemode < 0)
     318        {
     319            firemode = getFiremode ("HsW01");
     320        }
     321        if (firemode == getFiremode("RocketFire"))
     322        {
     323            this->timeout_ = 1.0f;
     324            this->rocketsLeft_--;
     325            this->bFiredRocket_ = true;
     326        }
     327        if (firemode == getFiremode("SimpleRocketFire"))
     328        {
     329            this->rocketsLeft_--;
     330        }
     331             
     332        this->getControllableEntity()->fire(firemode);
     333       
     334    }
     335    void FightingController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
     336    {
     337        this->bSetupWorked = false;
     338        if(this->getControllableEntity())
     339        {
     340            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     341            if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
     342            {
     343                this->weaponModes_.clear(); // reset previous weapon information
     344                WeaponSlot* wSlot = 0;
     345                for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
     346                {
     347                    WeaponMode* wMode = 0;
     348                    for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
     349                    {
     350                        std::string wName = wMode->getIdentifier()->getName();
     351                        if (wName == "RocketFire")
     352                            this->rocketsLeft_ = 10;
     353                        if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
     354                            weaponModes_[wName] = wMode->getMode();
     355                    }
     356                }
     357                if(weaponModes_.size())//at least one weapon detected
     358                    this->bSetupWorked = true;
     359            }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
     360        }
     361    }
     362
     363    int FightingController::getFiremode(std::string name)
     364    {
     365        for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
     366        {
     367            if (it->first == name)
     368                return it->second;
     369        }
     370        return -1;
     371    }
    290372}
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau, Dominik Solenicki
    2626 *
    2727 */
     
    4545       
    4646            float squaredDistanceToTarget() const;
    47             bool isLookingAtTarget(float angle);
    48             bool hasTarget();
    49             ControllableEntity* getTarget()
     47            bool isLookingAtTarget(float angle) const;
     48            bool hasTarget() const;
     49            ControllableEntity* getTarget() const
    5050                { return this->target_; }
    5151            bool bKeepFormation_;
     
    6161
    6262            void maneuver();
    63             void dodge(Vector3& thisPosition, Vector3& diffUnit);
     63            void dodge(const Vector3& thisPosition, Vector3& diffUnit);
    6464            bool canFire();
    6565            void doFire();
     
    7171            bool bHasOrientationOfTarget_;
    7272            Quaternion orientationOfTarget_;
    73             Pawn* closestTarget();
     73            Pawn* closestTarget() const;
    7474
    7575            int attackRange_;
    7676            bool bShooting_;
    7777            int maneuverCounter_;   
    78             bool bLookAtTarget_;           
     78            bool bLookAtTarget_;
     79
     80            //WEAPONSYSTEM DATA
     81            int rocketsLeft_;
     82            float timeout_;
     83            bool bFiredRocket_;
     84            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
     85            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
     86            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
     87            bool bSetupWorked; //<! If false, setupWeapons() is called.
     88            int getFiremode(std::string name);
     89         
    7990    };
    8091}
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10882 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
     24
    2425 *   Co-authors:
    2526 *      Dominik Solenicki
     
    3132#include "util/Math.h"
    3233#include <OgreMatrix3.h>
     34
    3335namespace orxonox
    3436{   
    3537    RegisterClass (FlyingController);
    3638   
    37     FlyingController::FlyingController( Context* context ): CommonController( context )
    38     {
     39    FlyingController::FlyingController(Context* context): CommonController(context)
     40    {
     41        RegisterObject(FlyingController);       
    3942        this->rotationProgress_ = 0;
    4043        this->spread_ = 200;
    41         this->tolerance_ = 60;
    42         RegisterObject( FlyingController );
     44        this->tolerance_ = 100;
    4345    }
    4446    FlyingController::~FlyingController()
     
    4749    }
    4850
    49     void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
    50     {
    51         XMLPortParam( FlyingController, "spread", setSpread, getSpread,  xmlelement, mode );
    52         XMLPortParam( FlyingController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
    53         SUPER( FlyingController, XMLPort, xmlelement, mode );
     51    void FlyingController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     52    {
     53        XMLPortParam(FlyingController, "spread", setSpread, getSpread,  xmlelement, mode);
     54        XMLPortParam(FlyingController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode);
     55        SUPER(FlyingController, XMLPort, xmlelement, mode);
    5456    }
    5557   
    56     void FlyingController::setFormationModeXML( std::string val )
    57     {
    58         const std::string valUpper = getUppercase( val );
     58    void FlyingController::setFormationModeXML(std::string val)
     59    {
     60        const std::string valUpper = getUppercase(val);
    5961        FormationMode::Value value;
    6062       
     
    6668            value = FormationMode::DIAMOND;
    6769        else
    68             ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
    69         this->setFormationMode( value );
    70     }
    71     std::string FlyingController::getFormationModeXML()
     70            ThrowException(ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'.");
     71        this->setFormationMode(value);
     72    }
     73    std::string FlyingController::getFormationModeXML() const
    7274    {
    7375        switch ( this->formationMode_ )
     
    8385        }
    8486    }
    85 
    86    
    87 
    8887    void FlyingController::stopMoving()
    8988    {
    9089        this->bHasTargetPosition_ = false;
    9190    }
    92 
    93     void FlyingController::moveToPosition( const Vector3& target, float dt )
     91    void FlyingController::moveToPosition(const Vector3& target, float dt)
    9492    {
    9593        ControllableEntity* entity = this->getControllableEntity();
    9694
    97         float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
    98 
     95        float distance = ( target - entity->getPosition() ).length();
    9996
    10097        if ( distance >= this->tolerance_ )
     
    107104            float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
    108105            float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
    109             this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
    110             this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
    111 
     106            entity->rotateYaw( ROTATEFACTOR * rotateX * dt );
     107            entity->rotatePitch( ROTATEFACTOR * rotateY * dt );
    112108         
    113109            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
    114                 this->getControllableEntity() ->moveFrontBack( SPEED * dt );
     110                entity->moveFrontBack( SPEED * dt );
     111                copyTargetOrientation(dt);
    115112        }
    116113        else
     
    118115            bHasTargetPosition_ = false;
    119116        }
    120         copyTargetOrientation(dt);
    121117    }
    122118   
     
    125121        this->moveToPosition (this->targetPosition_, dt);
    126122    }
    127     void FlyingController::copyOrientation( const Quaternion& orient, float dt )
     123    void FlyingController::copyOrientation(const Quaternion& orient, float dt)
    128124    {
    129125        //inspired by
     
    167163    }
    168164    //change log: increased precision, increased rotation speed
    169     void FlyingController::copyTargetOrientation( float dt )
    170     {
    171         if ( bHasTargetOrientation_ )
     165    void FlyingController::copyTargetOrientation(float dt)
     166    {
     167        if (bHasTargetOrientation_)
    172168        {   
    173             copyOrientation( targetOrientation_, dt );
     169            copyOrientation(targetOrientation_, dt);
    174170        }
    175171    }
    176172   
    177     void FlyingController::setTargetPosition( const Vector3& target )
     173    void FlyingController::setTargetPosition(const Vector3& target)
    178174    {
    179175        this->targetPosition_ = target;
     
    181177    }
    182178
    183     void FlyingController::setTargetOrientation( const Quaternion& orient )
     179    void FlyingController::setTargetOrientation(const Quaternion& orient)
    184180    {
    185181        this->targetOrientation_=orient;
     
    187183    }
    188184
    189     void FlyingController::setTargetOrientation( ControllableEntity* target )
    190     {
    191         if ( target )
    192             setTargetOrientation( target->getOrientation() );
     185    void FlyingController::setTargetOrientation(ControllableEntity* target)
     186    {
     187        if (target)
     188            setTargetOrientation(target->getOrientation());
    193189    }
    194190    void FlyingController::boostControl()
     
    198194        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
    199195        {
    200 
    201196            this->getControllableEntity()->boost(true);
    202197        }
     
    206201        }
    207202    }
    208    
    209203}
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10881 r10885  
    5656            void setSpread (int spread)
    5757                { this->spread_ = spread; }
    58             int getSpread ()
     58            int getSpread () const
    5959                { return this->spread_; }
    6060
    6161            void setFormationModeXML(std::string val);
    62             std::string getFormationModeXML();
     62            std::string getFormationModeXML() const;
    6363
    6464            void setFormationMode(FormationMode::Value val)
  • code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc

    r10864 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
  • code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      ...
     
    3131
    3232#include "controllers/ActionpointController.h"
    33 #include "controllers/WingmanController.h"
    3433
    3534
     
    5150        protected:
    5251            //----private variables-----
    53                 WeakPtr<WingmanController> myWingman_;
    54                 WeakPtr<LeaderController> myFollower_;
    55                 WeakPtr<LeaderController> myDivisionLeader_;
     52
    5653
    5754           
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    9696        if (!myDivisionLeader_)
    9797        {
    98             LeaderController* newDivisionLeader = findNewDivisionLeader();
     98            ActionpointController* newDivisionLeader = findNewDivisionLeader();
    9999            this->myDivisionLeader_ = newDivisionLeader;
    100100            //spread copyOrientation called equally among the division
    101101            if (this->myDivisionLeader_)
    102102            {
    103                 this->actionCounter_ = 8;
     103                this->actionCounter_ = 5;
    104104            }
    105105        }
     
    147147                     + (orient* (targetRelativePosition)));
    148148                //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    149                 if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
     149                if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
    150150                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
    151151                else
     
    300300   
    301301
    302     LeaderController* SectionController::findNewDivisionLeader()
     302    ActionpointController* SectionController::findNewDivisionLeader()
    303303    {
    304304
     
    306306            return 0;
    307307
    308         LeaderController* closestLeader = 0;
     308        ActionpointController* closestLeader = 0;
    309309        float minDistance =  std::numeric_limits<float>::infinity();
    310310        //go through all pawns
    311         for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
     311        for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
    312312        {
    313313            //0ptr or not DivisionController?
     
    338338        return 0;
    339339    }
    340     bool SectionController::setWingman(ActionpointController* wingman)
    341     {
    342         WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
     340    bool SectionController::setWingman(ActionpointController* newWingman)
     341    {
    343342
    344343        if (!this->myWingman_)
    345344        {
    346345            this->myWingman_ = newWingman;
     346            newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
    347347            return true;
    348348        }
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    5151           
    5252            //----[own functions]----
    53                 LeaderController* findNewDivisionLeader();
     53                ActionpointController* findNewDivisionLeader();
    5454
    55                 virtual bool setWingman(ActionpointController* wingman);
     55                virtual bool setWingman(ActionpointController* newWingman);
    5656                virtual bool hasWingman();
    57 
     57                virtual bool hasFollower()
     58                    { return false; }
    5859                void chooseTarget();
    5960            //----[/own functions]----
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10883 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    8989                //spread copyOrientation called equally among the division
    9090                if (this->myLeader_->getIdentifier()->getName() == "SectionController")
    91                     this->actionCounter_ = 2;
     91                    this->actionCounter_ = 1;
    9292                else
    93                     this->actionCounter_ = 5;
     93                    this->actionCounter_ = 4;
    9494            }
    9595        }
     
    126126                     + (orient* (targetRelativePosition)));
    127127                //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    128                 if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
     128                if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
    129129                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
    130130                else
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h

    r10877 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      ...
     
    4949
    5050                virtual void tick(float dt);
     51                virtual bool hasWingman()
     52                    { return false; }
     53                virtual bool hasFollower()
     54                    { return false; }
    5155            //----[/orxonox demanded functions]----
    5256
  • code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.cc

    r10868 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      ...
  • code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h

    r10868 r10885  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Gani Aliguzhinov
    2424 *   Co-authors:
    2525 *      ...
Note: See TracChangeset for help on using the changeset viewer.