Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 22, 2015, 5:06:38 PM (9 years ago)
Author:
gania
Message:

some comments added

File:
1 edited

Legend:

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

    r10805 r10826  
    3535    RegisterClass(WingmanController);
    3636   
    37 
     37    //CommonController contains all common functionality of AI Controllers
    3838    WingmanController::WingmanController(Context* context) : CommonController(context)
    3939    {
     
    4242        this->myLeader_ = 0;
    4343        this->rank_ = Rank::WINGMAN;
    44 
    4544    }
    4645
     
    4948
    5049    }
    51     // void WingmanController::chooseManeuver()
    52     // {
    53     //     if (this->maneuverType_ == ManeuverType::NONE)
    54     //     switch (this->maneuverType_ )
    55     //     {
    56     //         case ManeuverType::NONE:
    57     //         {
     50 
     51    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     52    {
     53        SUPER(WingmanController, XMLPort, xmlelement, mode);
    5854
    59     //             break;
    60     //         }
    61     //         case ManeuverType::NEUTRAL:
    62     //         {
    63 
    64     //             break;
    65     //         }
    66     //         case ManeuverType::OFFENSIVE:
    67     //         {
    68 
    69     //             break;
    70     //         }
    71     //         case ManeuverType::DEFENSIVE:
    72     //         {
    73 
    74     //             break;
    75     //         }
    76     //     }
    77     //     if (!this->myWingman_)
    78     //         return;
    79     //     Vector3* targetRelativePositionOfWingman;
    80     //     switch (this->formationMode_){
    81     //         case FormationMode::WALL:
    82     //         {
    83     //             targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 
    84     //             break;
    85     //         }
    86     //         case FormationMode::FINGER4:
    87     //         {
    88     //             targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 
    89     //             break;
    90     //         }
    91     //         case FormationMode::VEE:
    92     //         {
    93     //             break;
    94     //         }
    95     //         case FormationMode::DIAMOND:
    96     //         {
    97     //             targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                 
    98     //             break;
    99     //         }
    100     //     }
    101     //     Quaternion orient = this->getControllableEntity()->getWorldOrientation();
    102        
    103     //     Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) +
    104     //     (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
    105        
    106     //     myWingman_->setTargetOrientation(orient);
    107     //     myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
    108        
    109     // }
    110 
     55        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     56    }
     57   
     58    //----in tick, move (or look) and shoot----
    11159    void WingmanController::tick(float dt)
    11260    {   
     
    12977    }
    13078   
     79    //----action for hard calculations----
    13180    void WingmanController::action()
    13281    {
     82        //----If no leader, find one----
    13383        if (!this->myLeader_)
    13484        {
     
    13686            this->myLeader_ = newLeader;
    13787            if (newLeader)
    138                 orxout(internal_error) << "new Leader set" << endl;
     88            {
     89                //orxout(internal_error) << "new Leader set" << endl;
     90            }
     91            //----If no leader found, attack someone----
     92            //----TODO: find closest enemy----
    13993            else
    14094            {
    141                 if (!this->target_){
     95                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
     96                {
    14297                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    14398                    {
    144                         if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     99                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
    145100                            continue;   
    146101                        this->setAction(Action::FIGHT, (*itP));
     
    149104                }
    150105            }
    151 
    152106        }
     107        //----If have leader, he will deal with logic----
    153108        else
    154109        {
    155110
    156111        }
    157        
     112
     113
     114        //----action was set to fight----
    158115        if (this->action_ == Action::FIGHT)
    159116        {
     117            //----choose where to go----
    160118            this->maneuver();
     119            //----fire if you can----
    161120            this->bShooting_ = this->canFire();
    162             if (this->target_)
    163             {
    164                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    165                 if (diffVector.length() > 5000)
    166                 {
    167                  
    168                 }   
    169             }
    170121        }
     122        //----action was set to fly, leader handles the logic----
    171123        else if (this->action_ == Action::FLY)
    172124        {
    173125
    174126        }
     127        //----TODO: implement protect----
    175128        else if (this->action_ == Action::PROTECT)
    176129        {
     
    182135   
    183136   
    184 
     137    //----POST: closest leader that is ready to take a new wingman is returned----
    185138    CommonController* WingmanController::findNewLeader()
    186139    {
     
    189142            return 0;
    190143
     144        //----vars for finding the closest leader----
    191145        CommonController* closestLeader = 0;
    192146        float minDistance =  std::numeric_limits<float>::infinity();
     
    194148        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    195149        {
    196             //0ptr?
     150            //----0ptr or not a leader or dead?----
    197151            if (!it ||
    198152                (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) ||
    199153                !(it->getControllableEntity()))
    200154                continue;
    201             //same team?
    202             if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
     155           
     156            //----same team?----
     157            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) )
    203158                continue;
    204             //is equal to this?
    205             if (it->getControllableEntity() == this->getControllableEntity())
    206                 continue;
    207 
    208             float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
     159           
     160            //----check distance----
     161            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
    209162            if (distance < minDistance && !(it->hasWingman()))
    210163            {
     
    216169        if (closestLeader)
    217170        {
     171            //----Racing conditions----
    218172            if (closestLeader->setWingman(this))
    219173                return closestLeader;
     
    222176    }
    223177
    224     void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    225     {
    226         SUPER(WingmanController, XMLPort, xmlelement, mode);
    227 
    228         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    229     }
    230178
    231179
Note: See TracChangeset for help on using the changeset viewer.