Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 29, 2015, 8:02:23 PM (10 years ago)
Author:
gania
Message:

All compiling, WingmanControllers actually find LeaderControllers and connect to them, SectionControllers find DivisionControllers and connect. TODO write tick functions, helper functions to CommonController

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10717 r10719  
    4141
    4242    RegisterClass(WingmanController);
    43     static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
    44 
     43    static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;
     44    static const float ACTION_INTERVAL = 1.0f;
    4545    WingmanController::WingmanController(Context* context) : CommonController(context)
    4646    {
    4747        RegisterObject(WingmanController);
    48         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
     48        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4949    }
    5050
     
    6868       
    6969        //go through all pawns
    70         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    71         {
    72 
     70        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
     71        {
    7372            //same team?
    74             if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
     73            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
    7574                continue;
    76 
    77             //Does it have a Controller?
    78             Controller* controller = 0;
    79 
    80             if (it->getController())
    81                 controller = it->getController();
    82             else if (it->getXMLController())
    83                 controller = it->getXMLController();
    84 
    85             if (!controller)
     75            //is equal to this?
     76            if (it->getControllableEntity() == this->getControllableEntity())
    8677                continue;
    8778
    88             //is equal to this?
    89             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     79
     80
     81            //nullptr?
     82            if (!it || !it->isLeader())
    9083                continue;
    9184
    92 
    93             CommonController* newLeader = orxonox_cast<CommonController*>(controller);
    94 
    95             //nullptr?
    96             if (!newLeader || !newLeader->isLeader())
    97                 continue;
    98 
    99             float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
     85            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    10086
    10187            // is pawn in range?
     
    10389            {
    10490
    105                 if (newLeader->setWingman(this))
    106                     return newLeader;
     91                if (it->setWingman(this))
     92                    return *it;
    10793            }
    10894        }
    10995        return NULL;
    110     }
    111     bool WingmanController::isLeader()
    112     {
    113         return false;
    11496    }
    11597    void WingmanController::action()
     
    120102            CommonController* newLeader = findNewLeader();
    121103            myLeader_ = newLeader;
    122             orxout(internal_error) << "new Leader set" << endl;
    123         }
    124     }
    125 
    126     void WingmanController::tick(float dt)
    127     {   
    128         //-------------------------------------------------------
    129             /*//collect data for AI behaviour
     104           /* if (newLeader)
     105                orxout(internal_error) << "new Leader set" << endl;
     106            else
     107                orxout(internal_error) << "null leader" << endl;
     108*/
     109        }
     110        else
     111        {
     112            //orxout(internal_error) << "already have a Leader" << endl;
     113
     114        }
     115    }
     116 /*//collect data for AI behaviour
    130117            Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
    131118            Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
     
    166153                orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
    167154            }*/
    168     /*
    169         if (!this->isActive())
    170             return;
    171         //--------------------------Stay in formation--------------------------
    172         if (bFollowLeader_)
    173         {
    174             this->keepSectionTick();*/
    175             /*keepSectionTick(){
    176                 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
    177                     Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
    178                         (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    179                     this->moveToPosition (desiredAbsolutePosition);
    180                 }
    181             }
    182             */
    183           /* 
    184             //--------------------------Attack same target as the Leader--------------------------
    185 
    186             if (this->target_)
    187             {
    188                 this->aimAtTarget();
    189                 this->doFire();
    190             }
    191         }*/
    192          //orxout(internal_error) << "I am " << this << endl;
    193 
    194        /* void FormationController::setDesiredPositionOfSlaves()
     155
     156      /*  void FormationController::setDesiredPositionOfSlaves()
    195157    {
    196158        if (this->state_ != MASTER)
     
    218180       
    219181    }*/
     182    void WingmanController::tick(float dt)
     183    {   
     184        //-------------------------------------------------------
     185           
     186        /*
     187        if (!this->isActive())
     188            return;
     189        //--------------------------Stay in formation--------------------------
     190        if (bFollowLeader_)
     191        {
     192            this->keepSectionTick();
     193           
     194            keepSectionTick(){
     195                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
     196                    Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
     197                        (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
     198                    this->moveToPosition (desiredAbsolutePosition);
     199                }
     200            }
     201           
     202           
     203            //--------------------------Attack same target as the Leader--------------------------
     204
     205            if (this->target_)
     206            {
     207                this->aimAtTarget();
     208                this->doFire();
     209            }
     210        }
     211        */
     212         //orxout(internal_error) << "I am " << this << endl;
     213
    220214       
    221215        SUPER(WingmanController, tick, dt);
    222216    }
     217
     218    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     219    {
     220        SUPER(WingmanController, XMLPort, xmlelement, mode);
     221
     222        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     223    }
     224
    223225//**********************************************NEW
    224226    /*void WingmanController::defaultBehaviour(float maxrand)
Note: See TracChangeset for help on using the changeset viewer.