Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 31, 2015, 12:20:00 PM (9 years ago)
Author:
gania
Message:

move functions were added, everyone stays in formations

Location:
code/branches/AI_HS15
Files:
11 edited

Legend:

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

    r10725 r10729  
    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     <SpawnPoint team=0 position="1000,1000,-1000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <SpawnPoint team=0 position="1000,1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535    <!-->
    3636
     
    8080      </controller>
    8181    </SpaceShip>
    82     <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
     82    <SpaceShip position="1000, 1500, -1300 ?>" lookat="0,0,0">
    8383      <templates>
    8484        <Template link=spaceshipassff />
     
    8989      </controller>
    9090    </SpaceShip>
    91     <SpaceShip position="1000, 1000, -1700 ?>" lookat="0,0,0">
     91    <SpaceShip position="1000, 1500, -1700 ?>" lookat="0,0,0">
    9292      <templates>
    9393        <Template link=spaceshipassff />
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10725 r10729  
    3232
    3333    RegisterClass(CommonController);
     34    static const float SPEED = 0.6f;
     35    static const float ROTATEFACTOR = 0.2f;
    3436
     37    /*static const float SPEED_FREE = 0.8f;
     38    static const float ROTATEFACTOR_FREE = 0.8f;*/
    3539   
    3640    bool CommonController::setWingman (CommonController* wingman)
     
    5155
    5256        RegisterObject(CommonController);
    53         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
    5457    }
    5558
     
    5861    {
    5962    }
     63    //copy the Roll orientation of given Quaternion.
     64    void CommonController::copyOrientation(const Quaternion& orient)
     65    {
     66        //roll angle difference in radian
     67        float diff=orient.getRoll(false).valueRadians()-(this->getControllableEntity()->getOrientation().getRoll(false).valueRadians());
     68        while(diff>math::twoPi) diff-=math::twoPi;
     69        while(diff<-math::twoPi) diff+=math::twoPi;
     70        this->getControllableEntity()->rotateRoll(-diff);
     71
     72
     73
     74    }
     75    void CommonController::setTargetPosition(const Vector3& target)
     76    {
     77        this->targetPosition_ = target;
     78        this->bHasTargetPosition_ = true;
     79    }
     80
     81    void CommonController::copyTargetOrientation()
     82    {
     83        if (bHasTargetOrientation_)
     84        {   
     85            copyOrientation(targetOrientation_);
     86        }
     87    }
     88    void CommonController::setTargetOrientation(const Quaternion& orient)
     89    {
     90        this->targetOrientation_=orient;
     91        this->bHasTargetOrientation_=true;
     92    }
     93    void CommonController::setTargetOrientation(ControllableEntity* target)
     94    {
     95        if (target)
     96            setTargetOrientation(target->getOrientation());
     97    }
     98
    6099
    61100    void CommonController::moveToPosition(const Vector3& target)
     
    63102        if (!this->getControllableEntity())
    64103            return;
     104       
     105        //100 is (so far) the smallest tolerance (empirically found) that can be reached,
     106        //with smaller distance spaceships can't reach position and go circles around it instead
     107        int tolerance = 100;
    65108
    66         Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     109        ControllableEntity* entity = this->getControllableEntity();
     110        Vector2 coord = get2DViewCoordinates
     111            (entity->getPosition(),
     112            entity->getOrientation() * WorldEntity::FRONT,
     113            entity->getOrientation() * WorldEntity::UP,
     114            target);
     115
    67116        float distance = (target - this->getControllableEntity()->getPosition()).length();
     117
     118        //rotates should be in range [-1,+1], clamp cuts off all that is not
    68119        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
    69120        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
    70121
    71122       
    72         if (this->target_ || distance > 10)
     123        if (distance > tolerance)
    73124        {
    74             this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX);
    75             this->getControllableEntity()->rotatePitch(0.8f * rotateY);
     125            //Yaw and Pitch are enough to start facing the target
     126            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX);
     127            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY);
     128
     129            //300 works, maybe less is better
     130            if (distance < 300)
     131            {
     132                //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
     133                //It's important that roll is not changed in the process of changing yaw and pitch
     134                //Wingmen won't face same direction as Leaders, but when Leaders start moving
     135                //Yaw and Pitch will adapt.
     136                if (bHasTargetOrientation_)
     137                {
     138                    copyTargetOrientation();
     139                }
     140            }
     141            this->getControllableEntity()->moveFrontBack(1.2f*SPEED);
     142        }
     143        else
     144        {     
     145            bHasTargetPosition_ = false;
     146            bHasTargetOrientation_ = false;
    76147        }
    77148
    78         if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    79         {
    80             this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
    81         }
    82         else if (distance > 100)
    83             this->getControllableEntity()->moveFrontBack(0.8f);
    84        
    85 
    86 
    87         if (distance < 100)
    88         {
    89             this->positionReached();
    90             bHasTargetOrientation_=false;
    91         }
     149     
     150    }
     151    void CommonController::moveToTargetPosition()
     152    {
     153        this->moveToPosition(this->targetPosition_);
    92154    }
    93155 
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10725 r10729  
    3939    {
    4040        public:
     41            static const float ACTION_INTERVAL = 1.0f;
     42
    4143            enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
    4244            virtual void setFormationMode(FormationMode val)
     
    5052            virtual bool setWingman(CommonController* wingman);
    5153            virtual bool hasWingman();
    52             Vector3* desiredRelativePosition_;
    5354
     55
     56            void setTargetOrientation(const Quaternion& orient);
     57            void setTargetOrientation(ControllableEntity* target);
     58            void setTargetPosition(const Vector3& target);
    5459
    5560        protected:
     
    5762            virtual void positionReached() {}
    5863
    59         /*    void moveToTargetPosition();
    60             void absoluteMoveToPosition(const Vector3& target);
     64       
     65            void moveToTargetPosition();
    6166            void copyOrientation(const Quaternion& orient);
    6267            void copyTargetOrientation();
    6368
    64             void spin();
    65             void turn180();
    66             void follow();
    67             void setTargetPosition(const Vector3& target);
    6869
    69             void setTargetOrientation(const Quaternion& orient);
    70             void setTargetOrientation(Pawn* target);
    71 
    72 
    73 
    74             void setTarget(Pawn* target);
    75 
    76             void searchNewTarget();
    77             void forgetTarget();
    78 
    79             void targetDied();
    80 */
    8170            bool bHasTargetPosition_;
    8271            Vector3 targetPosition_;
     
    9180
    9281
    93             //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.   
    9482         
    9583        private:
    9684           
    97             //Timer actionTimer_; //<! Regularly calls action().
    9885               
    9986    };
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10725 r10729  
    3434
    3535    RegisterClass(DivisionController);
    36     static const float ACTION_INTERVAL = 1.0f;
    3736
    3837    DivisionController::DivisionController(Context* context) : LeaderController(context)
     
    4544        this->myWingman_ = 0;
    4645        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
     46       
     47        /*Vector3* pos = new Vector3(500,500,-500);
     48        this->setTargetPosition(*pos);*/
    4749
    4850    }
     
    5456    void DivisionController::tick(float dt)
    5557    {
     58        if (this->bHasTargetPosition_)
     59        {
     60            this->moveToTargetPosition();
     61        }
     62
    5663        SUPER(DivisionController, tick, dt);
    5764
     
    5966    void DivisionController::action()
    6067    {
    61 /*        setDesiredPositionOfFollower();
    62         setDesiredPositionOfWingman();*/
     68        setTargetPositionOfFollower();
     69        setTargetPositionOfWingman();
    6370    }
    6471
     
    7683    }
    7784
    78    /* void DivisionController::setDesiredPositionOfWingman()
     85    void DivisionController::setTargetPositionOfWingman()
    7986    {
    8087        if (!this->myWingman_)
    8188            return;
    82 
     89        Vector3* targetRelativePositionOfWingman;
    8390        switch (this->formationMode_){
    8491            case WALL:
    8592            {
    86                 myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0);  
     93                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
    8794                break;
    8895            }
     
    100107            }
    101108        }
     109        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
     110       
     111        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) +
     112        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
     113       
     114        myWingman_->setTargetOrientation(orient);
     115        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
    102116       
    103117    }
    104     void DivisionController::setDesiredPositionOfFollower()
     118    void DivisionController::setTargetPositionOfFollower()
    105119    {
    106120        if (!this->myFollower_)
    107121            return;
    108 
     122        Vector3* targetRelativePositionOfFollower;
    109123        switch (this->formationMode_){
    110124            case WALL:
    111125            {
    112                 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
     126                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
    113127                break;
    114128            }
     
    126140            }
    127141        }
     142        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
     143       
     144        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) +
     145        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
     146       
     147        myFollower_->setTargetOrientation(orient);
     148        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
    128149       
    129     }*/
     150    }
    130151    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    131152    {
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10725 r10729  
    5151               
    5252                        virtual bool setFollower(LeaderController* myFollower);
    53                         virtual bool setWingman(CommonController* wingman)
     53                        virtual bool setWingman(CommonController* cwingman)
    5454            {
     55                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
    5556                if (!this->myWingman_)
    5657                {
     
    8384
    8485        protected:
    85             void setDesiredPositionOfWingman();
    86             void setDesiredPositionOfFollower();
     86            void setTargetPositionOfWingman();
     87            void setTargetPositionOfFollower();
    8788            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    88 
    89                 //Target enemy, set by fleet controller.
    90                
    91                        
    92                        
    93                
    94 
    9589           
    9690        private:
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc

    r10719 r10729  
    4747        RegisterObject(LeaderController);
    4848
    49         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
    5049    }
    5150
    52 
     51   
    5352    LeaderController::~LeaderController()
    5453    {
    5554    }
    5655
    57    
    58 //**********************************************NEW
    59    /* void LeaderController::defaultBehaviour(float maxrand)
    60     { 
    61        
    62     }*/
    6356
    6457}
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10725 r10729  
    4242    {
    4343        public:
    44                static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
    4544
    4645            LeaderController(Context* context);
     
    6362                return true;
    6463            };
    65             WeakPtr<CommonController> myWingman_;
     64            WeakPtr<WingmanController> myWingman_;
    6665
    6766            WeakPtr<LeaderController> myFollower_;
     
    7069
    7170        protected:
    72            
    73 
    74 
    75             //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.   
    7671         
    7772        private:
    7873           
    79            
    80            
    81             //Timer actionTimer_; //<! Regularly calls action().
    82                
    8374    };
    8475}
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10725 r10729  
    3333
    3434    RegisterClass(SectionController);
    35     static const float ACTION_INTERVAL = 1.0f;
    3635
    3736    SectionController::SectionController(Context* context) : LeaderController(context)
    3837    {
    3938        RegisterObject(SectionController);
    40                 this->setFormationMode(WALL);
     39        this->setFormationMode(WALL);
    4140
    4241        bIsDivisionLeader_ = false;
     
    4443        this->myWingman_ = 0;
    4544        this->myDivisionLeader_ = 0;
    46         this->desiredRelativePosition_ = 0;
    4745
    4846        orxout(internal_error) << this << "Was created" << endl;
     
    5452       
    5553    }
    56     /*void SectionController::setDesiredPositionOfWingman()
     54    void SectionController::setTargetPositionOfWingman()
    5755    {
    5856        if (!this->myWingman_)
    5957            return;
    60 
     58        Vector3* targetRelativePositionOfWingman;
    6159        switch (this->formationMode_){
    6260            case WALL:
    6361            {
    64                 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);  
     62                targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 
    6563                break;
    6664            }
     
    7876            }
    7977        }
     78        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
     79       
     80        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) +
     81        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
     82       
     83        myWingman_->setTargetOrientation(orient);
     84        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
    8085       
    8186    }
    82 */
     87
    8388    LeaderController* SectionController::findNewDivisionLeader()
    8489    {
     
    104109
    105110
    106            
    107            
    108 
    109111            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    110112           
     
    114116                minDistance = distance;
    115117            }
    116            /* // is pawn in range?
    117             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    118             {
    119 
    120                 if ((it)->setFollower(this))
    121                     return (*it);
    122             }*/
     118         
    123119        }
    124120        if (closestLeader)
     
    142138
    143139        }
    144 /*        setDesiredPositionOfWingman();
    145 */    }
     140        setTargetPositionOfWingman();
     141
     142    }
    146143    /*
    147144    Wingmen and Leaders attack target_, which is a member variable of their classes.
     
    158155
    159156    */
    160    /* void SectionController::keepDivisionTick()
    161     {
    162 
    163 
    164         if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_)
    165         {
    166 
    167             Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) +
    168                 (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    169             this->moveToPosition (desiredAbsolutePosition);
    170         }
    171     }*/
     157   
    172158    void SectionController::tick(float dt)
    173159    {
    174        
    175 
    176        /*
    177160        if (!this->isActive())
    178161            return;
    179162       
    180         //--------------------------Stay in division--------------------------
    181         this->keepDivisionTick();
    182         */
    183         //If ordered to move -> move to a target Point
    184        
    185         //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
    186         //(Section shoots same target, Boss's section shoots another target)
    187        
     163        if (this->bHasTargetPosition_)
     164        {
     165            this->moveToTargetPosition();
     166        }
    188167
    189         //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
    190168       
    191169        SUPER(SectionController, tick, dt);
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.h

    r10725 r10729  
    4242            SectionController(Context* context);
    4343            virtual ~SectionController();
    44             virtual bool setWingman(CommonController* wingman)
     44            virtual bool setWingman(CommonController* cwingman)
    4545            {
     46                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
     47
    4648                if (!this->myWingman_)
    4749                {
     
    5456                }
    5557            }
     58
    5659
    5760            virtual bool hasWingman()
     
    6972
    7073        protected:
    71             void setDesiredPositionOfWingman();
    72             void keepDivisionTick();
     74            void setTargetPositionOfWingman();
    7375            //A division is the biggest block of spaceships.
    7476            //In division one section is leading, the other one always stays on the same position
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10725 r10729  
    3434
    3535    RegisterClass(WingmanController);
    36     static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;
    37     static const float ACTION_INTERVAL = 1.0f;
     36   
     37
    3838    WingmanController::WingmanController(Context* context) : CommonController(context)
    3939    {
     
    4141        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4242        this->myLeader_ = 0;
    43         this->desiredRelativePosition_ = 0;
    4443    }
    4544
     
    8887    void WingmanController::action()
    8988    {
    90         //this->target_ = this->sectionTarget_;
    9189        if (!this->myLeader_)
    9290        {
     
    145143
    146144     
    147     /*void WingmanController::keepSectionTick()
    148     {
    149         if (this->myLeader_ && this->myLeader_->getControllableEntity())
    150                             //orxout(internal_error) << "MOVING" << endl;
    151 
    152         if (this->myLeader_ && this->myLeader_->getControllableEntity() && desiredRelativePosition_)
    153         {
    154             Vector3 desiredAbsolutePosition = ((this->myLeader_->getControllableEntity()->getWorldPosition()) +
    155                 (this->myLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    156             this->moveToPosition (desiredAbsolutePosition);
    157         }
    158     }*/
     145   
    159146    void WingmanController::tick(float dt)
    160147    {   
    161        /* //-------------------------------------------------------
     148        //-------------------------------------------------------
    162149           
    163150       
     
    165152            return;
    166153        //--------------------------Stay in formation--------------------------
    167         this->keepSectionTick();*/
    168            
     154        if (this->bHasTargetPosition_)
     155        {
     156            //targetPosition_ and targetOrientation_ are set by the Leader in its action()
     157            this->moveToTargetPosition();
     158        }
    169159       
    170160        //--------------------------Attack same target as the Leader--------------------------
     
    175165            this->doFire();
    176166        }
    177 */
     167        */
    178168       
    179169        //orxout(internal_error) << "I am " << this << endl;
     
    190180    }
    191181
    192 //**********************************************NEW
    193     /*void WingmanController::defaultBehaviour(float maxrand)
    194     { 
    195        
    196     }*/
     182
    197183
    198184}
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10725 r10729  
    6060
    6161            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    62             //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
    6362
    6463
    6564                     
    6665        private:
    67             //const float ACTION_INTERVAL;
    68             void keepSectionTick();
    6966
    70             //LeaderController* leader_;
    7167
    7268            Timer actionTimer_; //<! Regularly calls action().
Note: See TracChangeset for help on using the changeset viewer.