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/SectionController.cc

    r10719 r10722  
    4848        if (this->isInitialized())
    4949        {
    50            
     50            if (this->myDivisionLeader_)
     51                this->myDivisionLeader_->myFollower_ = 0;
     52            if(this->myWingman_)
     53                this->myWingman_->myLeader_ = 0;
    5154        }
    5255    }
    53      LeaderController* SectionController::findNewDivisionLeader()
     56   
     57    LeaderController* SectionController::findNewDivisionLeader()
    5458    {
    5559
    5660        if (!this->getControllableEntity())
    57             return NULL;
     61            return 0;
    5862
    59        
     63        LeaderController* closestLeader = 0;
     64        float minDistance =  std::numeric_limits<float>::infinity();
    6065        //go through all pawns
    6166        for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
    6267        {
    63 
     68            //0ptr or not DivisionController?
     69            if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
     70                continue;
    6471            //same team?
    6572            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     
    7279
    7380           
    74             //nullptr or not DivisionController?
    75             if (!(it) || !(it)->bIsDivisionLeader_)
    76                 continue;
     81           
    7782
    7883            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    79 
    80             // is pawn in range?
     84           
     85            if (distance < minDistance && !(it->hasFollower()))
     86            {
     87                closestLeader = *it;
     88                minDistance = distance;
     89            }
     90           /* // is pawn in range?
    8191            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    8292            {
     
    8494                if ((it)->setFollower(this))
    8595                    return (*it);
    86             }
     96            }*/
    8797        }
    88                 return NULL;
     98        if (closestLeader)
     99        {
     100            if (closestLeader->setFollower(this))
     101                return closestLeader;
     102        }
     103        return 0;
    89104
    90105    }
     
    96111        {
    97112            LeaderController* newDivisionLeader = findNewDivisionLeader();
    98             myDivisionLeader_ = newDivisionLeader;
    99            /* if (newDivisionLeader)
     113            this->myDivisionLeader_ = newDivisionLeader;
     114            /*if (newDivisionLeader)
    100115                orxout(internal_error) << "new DivisionLeader set" << endl;
    101116            else
    102                 orxout(internal_error) << "null division leader" << endl;*/
     117                orxout(internal_error) << "0 division leader" << endl;*/
    103118        }
    104119    }
Note: See TracChangeset for help on using the changeset viewer.