Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10725


Ignore:
Timestamp:
Oct 30, 2015, 11:07:34 PM (8 years ago)
Author:
gania
Message:

fixed pointers

Location:
code/branches/AI_HS15
Files:
11 edited

Legend:

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

    r10722 r10725  
    7171    </StaticEntity>
    7272   
    73    
    7473    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
    7574      <templates>
     
    7776      </templates>
    7877      <controller>
    79         <SectionController team=1>
    80         </SectionController>
     78        <DivisionController team=1>
     79        </DivisionController>
    8180      </controller>
    8281    </SpaceShip>
    83     <SpaceShip position="1000, 1000, -1600 ?>" lookat="0,0,0">
     82    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
     83      <templates>
     84        <Template link=spaceshipassff />
     85      </templates>
     86      <controller>
     87        <WingmanController team=1>
     88        </WingmanController>
     89      </controller>
     90    </SpaceShip>
     91    <SpaceShip position="1000, 1000, -1700 ?>" lookat="0,0,0">
    8492      <templates>
    8593        <Template link=spaceshipassff />
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10722 r10725  
    5151
    5252        RegisterObject(CommonController);
    53 
    5453        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
    5554    }
     
    6059    }
    6160
     61    void CommonController::moveToPosition(const Vector3& target)
     62    {
     63        if (!this->getControllableEntity())
     64            return;
     65
     66        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     67        float distance = (target - this->getControllableEntity()->getPosition()).length();
     68        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     69        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
     70
     71       
     72        if (this->target_ || distance > 10)
     73        {
     74            this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX);
     75            this->getControllableEntity()->rotatePitch(0.8f * rotateY);
     76        }
     77
     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        }
     92    }
    6293 
    6394
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10722 r10725  
    3939    {
    4040        public:
    41            
     41            enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
     42            virtual void setFormationMode(FormationMode val)
     43                { this->formationMode_ = val; }
     44            inline FormationMode getFormationMode() const
     45                { return this->formationMode_; }
     46
    4247            CommonController(Context* context);
    4348            virtual ~CommonController();
     
    4550            virtual bool setWingman(CommonController* wingman);
    4651            virtual bool hasWingman();
    47             CommonController* myWingman_;
     52            Vector3* desiredRelativePosition_;
    4853
    49             CommonController* myLeader_;
    5054
    5155        protected:
     56            void moveToPosition(const Vector3& target);
     57            virtual void positionReached() {}
     58
     59        /*    void moveToTargetPosition();
     60            void absoluteMoveToPosition(const Vector3& target);
     61            void copyOrientation(const Quaternion& orient);
     62            void copyTargetOrientation();
     63
     64            void spin();
     65            void turn180();
     66            void follow();
     67            void setTargetPosition(const Vector3& target);
     68
     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*/
     81            bool bHasTargetPosition_;
     82            Vector3 targetPosition_;
     83            bool bHasTargetOrientation_;
     84            Quaternion targetOrientation_;
     85
     86            WeakPtr<ControllableEntity> target_;
     87            bool bShooting_;
     88
     89            FormationMode formationMode_;
     90
     91
    5292
    5393            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.   
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10722 r10725  
    3434
    3535    RegisterClass(DivisionController);
     36    static const float ACTION_INTERVAL = 1.0f;
    3637
    3738    DivisionController::DivisionController(Context* context) : LeaderController(context)
    3839    {
    3940        RegisterObject(DivisionController);
     41        this->setFormationMode(WALL);
     42
    4043        bIsDivisionLeader_ = true;
     44        this->myFollower_ = 0;
     45        this->myWingman_ = 0;
     46        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
     47
    4148    }
    4249
    4350    DivisionController::~DivisionController()
    4451    {
    45         if (this->isInitialized())
    46         {
    47             if (this->myFollower_)
    48                 this->myFollower_->myDivisionLeader_ = 0;
    49             if (this->myWingman_)
    50                 this->myWingman_->myLeader_ = 0;
    51         }
    52     } void DivisionController::tick(float dt)
     52     
     53    }
     54    void DivisionController::tick(float dt)
    5355    {
    5456        SUPER(DivisionController, tick, dt);
    5557
    5658    }
     59    void DivisionController::action()
     60    {
     61/*        setDesiredPositionOfFollower();
     62        setDesiredPositionOfWingman();*/
     63    }
     64
    5765    bool DivisionController::setFollower(LeaderController* myFollower)
    5866    {
     
    6775        }
    6876    }
     77
     78   /* void DivisionController::setDesiredPositionOfWingman()
     79    {
     80        if (!this->myWingman_)
     81            return;
     82
     83        switch (this->formationMode_){
     84            case WALL:
     85            {
     86                myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0);   
     87                break;
     88            }
     89            case FINGER4:
     90            {
     91                break;
     92            }
     93            case VEE:
     94            {
     95                break;
     96            }
     97            case DIAMOND:
     98            {
     99                break;
     100            }
     101        }
     102       
     103    }
     104    void DivisionController::setDesiredPositionOfFollower()
     105    {
     106        if (!this->myFollower_)
     107            return;
     108
     109        switch (this->formationMode_){
     110            case WALL:
     111            {
     112                myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
     113                break;
     114            }
     115            case FINGER4:
     116            {
     117                break;
     118            }
     119            case VEE:
     120            {
     121                break;
     122            }
     123            case DIAMOND:
     124            {
     125                break;
     126            }
     127        }
     128       
     129    }*/
    69130    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    70131    {
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10722 r10725  
    4848
    4949                //Using british military aircraft formations
    50                 enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
    51                 void setFormationMode(FormationMode val);
    52                 inline FormationMode getFormationMode() const
    53                         { return this->formationMode_; }
     50               
     51               
    5452                        virtual bool setFollower(LeaderController* myFollower);
    5553                        virtual bool setWingman(CommonController* wingman)
     
    8583
    8684        protected:
     85            void setDesiredPositionOfWingman();
     86            void setDesiredPositionOfFollower();
     87            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    8788
    8889                //Target enemy, set by fleet controller.
    89                 WeakPtr<Pawn> target_;
    90                 bool bHasTargetPosition_;
    91                         Vector3 targetPosition_;
    92                         bool bHasTargetOrientation_;
    93                         Quaternion targetOrientation_;
    94                         FormationMode formationMode_;
     90               
    9591                       
    9692                       
     
    9995           
    10096        private:
     97            Timer actionTimer_; //<! Regularly calls action().
     98
    10199    };
    102100}
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10722 r10725  
    6363                return true;
    6464            };
    65             LeaderController* myFollower_;
    66             LeaderController* myDivisionLeader_;
     65            WeakPtr<CommonController> myWingman_;
     66
     67            WeakPtr<LeaderController> myFollower_;
     68            WeakPtr<LeaderController> myDivisionLeader_;
    6769
    6870
     
    7577        private:
    7678           
    77             WeakPtr<Pawn> target_;
    7879           
    7980           
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10722 r10725  
    3838    {
    3939        RegisterObject(SectionController);
     40                this->setFormationMode(WALL);
     41
    4042        bIsDivisionLeader_ = false;
    4143        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
    42 
     44        this->myWingman_ = 0;
     45        this->myDivisionLeader_ = 0;
     46        this->desiredRelativePosition_ = 0;
     47
     48        orxout(internal_error) << this << "Was created" << endl;
    4349
    4450    }
     
    4652    SectionController::~SectionController()
    4753    {
    48         if (this->isInitialized())
    49         {
    50             if (this->myDivisionLeader_)
    51                 this->myDivisionLeader_->myFollower_ = 0;
    52             if(this->myWingman_)
    53                 this->myWingman_->myLeader_ = 0;
    54         }
    55     }
    56    
     54       
     55    }
     56    /*void SectionController::setDesiredPositionOfWingman()
     57    {
     58        if (!this->myWingman_)
     59            return;
     60
     61        switch (this->formationMode_){
     62            case WALL:
     63            {
     64                myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
     65                break;
     66            }
     67            case FINGER4:
     68            {
     69                break;
     70            }
     71            case VEE:
     72            {
     73                break;
     74            }
     75            case DIAMOND:
     76            {
     77                break;
     78            }
     79        }
     80       
     81    }
     82*/
    5783    LeaderController* SectionController::findNewDivisionLeader()
    5884    {
     
    112138            LeaderController* newDivisionLeader = findNewDivisionLeader();
    113139            this->myDivisionLeader_ = newDivisionLeader;
    114             /*if (newDivisionLeader)
     140            if (newDivisionLeader)
    115141                orxout(internal_error) << "new DivisionLeader set" << endl;
    116             else
    117                 orxout(internal_error) << "0 division leader" << endl;*/
    118         }
    119     }
     142
     143        }
     144/*        setDesiredPositionOfWingman();
     145*/    }
    120146    /*
    121147    Wingmen and Leaders attack target_, which is a member variable of their classes.
     
    132158
    133159    */
     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    }*/
    134172    void SectionController::tick(float dt)
    135     {/*
     173    {
     174       
     175
     176       /*
    136177        if (!this->isActive())
    137178            return;
    138179       
    139180        //--------------------------Stay in division--------------------------
    140         this->keepDivisionTick();*/
    141         /*keepDivisionTick(){
    142             if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
    143                 Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
    144                     (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    145                 this->moveToPosition (desiredAbsolutePosition);
    146             }
    147         }
     181        this->keepDivisionTick();
    148182        */
    149         /*//If ordered to attack -> follow target and shoot
    150         if (this->bAttackOrder_)
    151         {
    152  
    153         }
    154183        //If ordered to move -> move to a target Point
    155184       
    156185        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
    157186        //(Section shoots same target, Boss's section shoots another target)
    158         {
    159 
    160         }*/
     187       
    161188
    162189        //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.h

    r10722 r10725  
    5353                    return false;
    5454                }
    55             };
     55            }
     56
    5657            virtual bool hasWingman()
    5758            {
     
    6869
    6970        protected:
    70 
     71            void setDesiredPositionOfWingman();
     72            void keepDivisionTick();
    7173            //A division is the biggest block of spaceships.
    7274            //In division one section is leading, the other one always stays on the same position
     
    8385            Timer actionTimer_; //<! Regularly calls action().
    8486           
    85             Vector3* desiredRelativePosition_;
    8687
    8788    };
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10722 r10725  
    4040        RegisterObject(WingmanController);
    4141        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
     42        this->myLeader_ = 0;
     43        this->desiredRelativePosition_ = 0;
    4244    }
    4345
    4446    WingmanController::~WingmanController()
    4547    {
    46         if (this->myLeader_)
    47             this->myLeader_->myWingman_ = 0;
     48
    4849    }
    4950
     
    6970                continue;
    7071
    71 
    72 
    73          
    74 
    7572            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    7673            if (distance < minDistance && !(it->hasWingman()))
     
    7976                minDistance = distance;
    8077            }
    81             /*// is pawn in range?
    82             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    83             {
    84 
    85                 if (it->setWingman(this))
    86                     return *it;
    87             }*/
     78           
    8879        }
    8980        if (closestLeader)
     
    110101        else
    111102        {
    112 
    113             //orxout(internal_error) << "already have a Leader" << endl;
    114103
    115104        }
     
    155144            }*/
    156145
    157       /*  void FormationController::setDesiredPositionOfSlaves()
     146     
     147    /*void WingmanController::keepSectionTick()
    158148    {
    159         if (this->state_ != MASTER)
    160             return;
    161         switch (this->formationMode_){
    162             case ATTACK:
    163             {
    164                 float i = 0;
    165                 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    166                 {
    167                     (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
    168                     i++;
    169                 }
    170                 break;
    171             }
    172             case NORMAL:
    173             {
    174                 break;
    175             }
    176             case DEFEND:
    177             {
    178                 break;
    179             }
     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);
    180157        }
    181        
    182158    }*/
    183159    void WingmanController::tick(float dt)
    184160    {   
    185         //-------------------------------------------------------
     161       /* //-------------------------------------------------------
    186162           
    187         /*
     163       
    188164        if (!this->isActive())
    189165            return;
    190166        //--------------------------Stay in formation--------------------------
    191         if (bFollowLeader_)
     167        this->keepSectionTick();*/
     168           
     169       
     170        //--------------------------Attack same target as the Leader--------------------------
     171
     172        /*if (this->target_)
    192173        {
    193             this->keepSectionTick();
    194            
    195             keepSectionTick(){
    196                 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
    197                     Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
    198                         (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    199                     this->moveToPosition (desiredAbsolutePosition);
    200                 }
    201             }
    202            
    203            
    204             //--------------------------Attack same target as the Leader--------------------------
    205 
    206             if (this->target_)
    207             {
    208                 this->aimAtTarget();
    209                 this->doFire();
    210             }
     174            this->aimAtTarget();
     175            this->doFire();
    211176        }
    212         */
    213          //orxout(internal_error) << "I am " << this << endl;
     177*/
     178       
     179        //orxout(internal_error) << "I am " << this << endl;
    214180
    215181       
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10722 r10725  
    5757
    5858        protected:
     59            WeakPtr<CommonController> myLeader_;
    5960
    6061            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     
    6566        private:
    6667            //const float ACTION_INTERVAL;
    67            
    68             WeakPtr<Pawn> target_;
     68            void keepSectionTick();
     69
    6970            //LeaderController* leader_;
    7071
  • code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc

    r10624 r10725  
    320320    }
    321321
    322 
    323322    void Pawn::death()
    324323    {
Note: See TracChangeset for help on using the changeset viewer.