Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2011, 4:09:25 PM (14 years ago)
Author:
willis
Message:

added different Modes, debugging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/formation/src/orxonox/controllers/Masterable.cc

    r8948 r8953  
    5757
    5858
    59   static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
    60   static const int RADIUS_TO_SEARCH_FOR_MASTERS = 20000;
     59  static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
     60  static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
    6161  static const int FORMATION_LENGTH =  110;
    6262  static const int FORMATION_WIDTH =  110;
     
    7979
    8080        this->state_ = FREE;
     81        this->mode_ = NORMAL;
    8182        this->specificMasterAction_ = NONE;
    8283        this->specificMasterActionHoldCount_  = 0;
     
    444445            this->state_ = MASTER;
    445446            this->myMaster_ = 0;
    446             orxout(debug_output) << "search new master: no master found, but teammates"<< endl;
    447         }
     447            orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl;
     448        } else if (this->state_ != SLAVE)
     449            orxout(debug_output) << "search new master: no master found, no teammates..."<< endl;
    448450    }
    449451 /**
     
    589591        if (this->state_==FREE)
    590592        {
    591           /*
    592             float minDistance=(float)RADIUS_TO_SEARCH_FOR_MASTERS;
    593             Masterable* bestMaster=NULL;
    594 
    595             //search nearest Master, store in bestMaster
    596             for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    597             {
    598            
    599                 //same team?  (doesnt work with a HumanPlayer??!?) TODO
    600                 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
    601                     continue;
    602 
    603                 //get Controller
    604                 Controller* controller = 0;
    605 
    606                 if (it->getController())
    607                     controller = it->getController();
    608                 else if (it->getXMLController())
    609                     controller = it->getXMLController();
    610 
    611                 if (!controller)
    612                     continue;
    613 
    614                 //myself?
    615                 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
    616                     continue;
    617 
    618                 Masterable *newMaster = orxonox_cast<Masterable*>(controller);
    619                 if (!newMaster || newMaster->state_!=MASTER) continue;
    620                
    621                 float distance= (it->getPosition() - this->getControllableEntity()->getPosition()).length();
    622                
    623                 if (distance<minDistance)
    624                 {
    625                     minDistance=distance;
    626                     bestMaster=newMaster;
    627                 }
    628             }
    629 
    630             if (bestMaster!=NULL)
    631             {
    632                 //becom slave of formation
    633                 bestMaster->slaves_.push_back(this);
    634                 this->state_=SLAVE;
    635                 this->myMaster_=bestMaster;
    636             }
    637             else
    638             {
    639               //no formation found to lead, become master of empty formation
    640               this->state_=MASTER;
    641               this->slaves_.clear();
    642               this->myMaster_=0;
    643               orxout(debug_output) << this << "no formation found!, empty formation"<< endl;
    644               return;
    645             }
    646          */
    647593          searchNewMaster();
    648594        }
     
    681627
    682628    /**
     629      @brief Sets the new mode. If master, set it for all slaves.
     630    */
     631    void Masterable::setMode(Mode val)
     632    {
     633        this->mode_=val;
     634        if (this->state_==MASTER)
     635        {
     636            for(std::vector<Masterable*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     637            {
     638                 (*it)->mode_=val;
     639                 if (val==ATTACK)
     640                     (*it)->forgetTarget();
     641            }
     642        }
     643    }
     644
     645    /**
    683646        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
    684647    */
     
    935898    }
    936899
    937 
    938 
    939 
    940 
    941   void Masterable::setMode(Mode mode)
    942   {
    943      for (std::vector<Masterable*>::iterator it=slaves_.begin(); it != slaves_.end(); it++)
    944      {
    945         //(*it)->myMode_=mode;
    946      }
    947   }
    948 
    949   Masterable::Mode Masterable::getMode()
    950   {
    951     return Masterable::NORMAL;
    952   }
    953 
    954 
    955900  bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    956901    {
     
    992937            if (entity2->getPlayer())
    993938                team2 = tdm->getTeam(entity2->getPlayer());
     939            return (team1 == team2 && team1 != -1); //temp solution
    994940        }
    995941
Note: See TracChangeset for help on using the changeset viewer.