Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2012, 6:07:37 PM (11 years ago)
Author:
jo
Message:

Merging the Racingbot branch into the presentationHS12 branch.

Location:
code/branches/presentationHS12
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS12

  • code/branches/presentationHS12/src/modules/gametypes/RaceCheckPoint.cc

    r9348 r9523  
    4343    CreateFactory(RaceCheckPoint);
    4444
    45     RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
     45    RaceCheckPoint::RaceCheckPoint(BaseObject* creator) : DistanceMultiTrigger(creator),
     46            RadarViewable(creator, static_cast<WorldEntity*> (this))
    4647    {
    4748        RegisterObject(RaceCheckPoint);
    48 
    4949        this->setDistance(100);
    5050        this->setBeaconMode("off");
     
    6060        this->bIsLast_ = false;
    6161        this->timeLimit_ = 0;
    62         this->player_ = NULL;
    63     }
    64 
    65 
    66    RaceCheckPoint::~RaceCheckPoint()
    67    {
    68    }
     62        //this->players_ = vector<PlayerInfo*>();
     63
     64        myPosition_= this->getPosition(); //eingefuegt
     65        //orxout(user_status) << "test" << std::endl;
     66    }
     67
     68    RaceCheckPoint::~RaceCheckPoint()
     69    {
     70
     71    }
    6972
    7073    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    8689            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
    8790            if (entity)
    88                 this->player_ = entity->getPlayer();
     91                this->players_.push_back(entity->getPlayer());
    8992        }
    9093    }
     
    9598        if (this->timeLimit_ != 0)
    9699        {
    97             std::string message =  "You have " + multi_cast<std::string>(this->timeLimit_)
    98                         + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
     100            std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
     101            + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
    99102            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
    100103            ChatManager::message(message);
     
    102105    }
    103106
     107    //Must not be called before setNextCheckpointsAsVector3 at least once has been called
     108    void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){
     109        /*std::set<int> lastcheckpoints=this->nextCheckpoints_;
     110        nextCheckpoints_.clear();
     111        std::set<int>::iterator it = lastcheckpoints.begin();
     112        if(checkpoints.x<-1){
     113            virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it)));
     114            it++;
     115        }
     116        if(checkpoints.x!=-1)
     117            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
     118
     119        if(checkpoints.y<-1){
     120                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it)));
     121                    it++;
     122        }
     123        if(checkpoints.y!=-1)
     124            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     125
     126        if(checkpoints.z<-1){
     127                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it)));
     128                    it++;
     129        }
     130        if(checkpoints.z!=-1)
     131            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));*/
     132        nextCheckpointsVirtual_.clear();
     133        if(checkpoints.x!=-1)
     134            nextCheckpointsVirtual_.insert(checkpoints.x);
     135        if(checkpoints.y!=-1)
     136                nextCheckpointsVirtual_.insert(checkpoints.y);
     137        if(checkpoints.z!=-1)
     138                nextCheckpointsVirtual_.insert(checkpoints.z);
     139    }
     140
    104141    void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
    105142    {
     
    107144
    108145        if (checkpoints.x > -1)
    109             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
     146        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
    110147        if (checkpoints.y > -1)
    111             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     148        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
    112149        if (checkpoints.z > -1)
    113             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
    114     }
    115 
    116     Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
     150        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     151
     152        this->nextCheckpointsVirtual_=nextCheckpoints_;
     153    }
     154
     155    PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
     156    {
     157        if (players_.size() > 0)
     158        {
     159            for (int i = 0; i < players_.size(); i++)
     160            {
     161                if (this->players_[i]->getClientID() == clientID)
     162                {
     163                    return players_[i];
     164                }
     165            }
     166        }
     167        return NULL;
     168    }
     169
     170    bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
     171    {
     172        if (players_.size() > 0)
     173        {
     174            for (int i = 0; i < players_.size(); i++)
     175            {
     176                if (this->players_[i] == player)
     177                {
     178                    return true;
     179                }
     180            }
     181        }
     182        return false;
     183    }
     184
     185    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
     186    {
     187        Vector3 checkpoints(-1,-1,-1); int count=0;
     188        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){
     189            switch (count)
     190                        {
     191                            case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
     192                            case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
     193                            case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
     194                        }
     195                        ++count;
     196        }
     197        return checkpoints;
     198        //= getVirtualNextCheckpointsAsVector3();
     199        int j[3];
     200        j[0]=changeVirtualToRealCheckPoint(checkpoints.x);
     201        j[1]=changeVirtualToRealCheckPoint(checkpoints.y);
     202        j[2]=changeVirtualToRealCheckPoint(checkpoints.z);
     203
     204
     205        return Vector3(j[0],j[1],j[2]);
     206
     207
     208    }
     209
     210    int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) {
     211        int temp=checkpointID;
     212        while(temp<-1){
     213            temp = this->virtualToRealCheckPoints_[temp];
     214        }
     215        return temp;
     216    }
     217
     218
     219    Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const
    117220    {
    118221        Vector3 checkpoints = Vector3(-1, -1, -1);
    119222
    120223        size_t count = 0;
    121         for (std::set<int>::iterator it = this->nextCheckpoints_.begin(); it != this->nextCheckpoints_.end(); ++it)
     224        for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it)
    122225        {
    123226            switch (count)
Note: See TracChangeset for help on using the changeset viewer.