Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2015, 12:08:30 PM (9 years ago)
Author:
gania
Message:

created destructor functions and improved findNewLeader and findNewDivisionLeader

File:
1 edited

Legend:

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

    r10719 r10722  
    2929#include "WingmanController.h"
    3030
    31 #include "core/CoreIncludes.h"
    32 
    33 #include "core/XMLPort.h"
    34 #include "core/command/ConsoleCommandIncludes.h"
    35 
    36 #include "worldentities/ControllableEntity.h"
    37 #include "worldentities/pawns/Pawn.h"
    3831
    3932namespace orxonox
     
    5144    WingmanController::~WingmanController()
    5245    {
    53     }
    54 
    55    /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    56     {
    57         SUPER(WingmanController, XMLPort, xmlelement, mode);
    58 
    59         XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
    60         XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
    61     }*/
     46        if (this->myLeader_)
     47            this->myLeader_->myWingman_ = 0;
     48    }
     49
    6250    CommonController* WingmanController::findNewLeader()
    6351    {
    6452
    6553        if (!this->getControllableEntity())
    66             return NULL;
    67 
    68        
    69         //go through all pawns
     54            return 0;
     55
     56        CommonController* closestLeader = 0;
     57        float minDistance =  std::numeric_limits<float>::infinity();
     58
    7059        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    7160        {
     61            //0ptr?
     62            if (!it || !it->isLeader() || !(it->getControllableEntity()))
     63                continue;
    7264            //same team?
    73             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     65            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
    7466                continue;
    7567            //is equal to this?
     
    7971
    8072
    81             //nullptr?
    82             if (!it || !it->isLeader())
    83                 continue;
     73         
    8474
    8575            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    86 
    87             // is pawn in range?
     76            if (distance < minDistance && !(it->hasWingman()))
     77            {
     78                closestLeader = *it;
     79                minDistance = distance;
     80            }
     81            /*// is pawn in range?
    8882            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    8983            {
     
    9185                if (it->setWingman(this))
    9286                    return *it;
    93             }
    94         }
    95         return NULL;
    96     }
     87            }*/
     88        }
     89        if (closestLeader)
     90        {
     91            if (closestLeader->setWingman(this))
     92                return closestLeader;
     93        }
     94        return 0;
     95    }
     96   
    9797    void WingmanController::action()
    9898    {
    9999        //this->target_ = this->sectionTarget_;
    100         if (!myLeader_)
     100        if (!this->myLeader_)
    101101        {
    102102            CommonController* newLeader = findNewLeader();
    103             myLeader_ = newLeader;
    104            /* if (newLeader)
     103            this->myLeader_ = newLeader;
     104            if (newLeader)
    105105                orxout(internal_error) << "new Leader set" << endl;
    106106            else
    107                 orxout(internal_error) << "null leader" << endl;
    108 */
     107                orxout(internal_error) << "0 leader" << endl;
     108
    109109        }
    110110        else
    111111        {
     112
    112113            //orxout(internal_error) << "already have a Leader" << endl;
    113114
Note: See TracChangeset for help on using the changeset viewer.