Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9508 for code


Ignore:
Timestamp:
Dec 11, 2012, 6:13:18 PM (12 years ago)
Author:
purgham
Message:

still not working!

Location:
code/branches/Racingbot/src/modules/gametypes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc

    r9470 r9508  
    6565        //orxout(user_status) << "test" << std::endl;
    6666
     67
    6768    }
    6869
     
    104105            ChatManager::message(message);
    105106        }
     107    }
     108
     109    //Must not be called before setNextCheckpointsAsVector3 at least once has been called
     110    void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){
     111        std::set<int> lastcheckpoints=this->nextCheckpoints_;
     112        nextCheckpoints_.clear();
     113        std::set<int>::iterator it = lastcheckpoints.begin();
     114        if(checkpoints.x<-1){
     115            virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it)));
     116            it++;
     117        }
     118        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
     119
     120        if(checkpoints.y<-1){
     121                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it)));
     122                    it++;
     123        }
     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        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
    106131    }
    107132
     
    148173    }
    149174
    150     Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
     175    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
     176    {
     177        Vector3 checkpoints = getVirtualNextCheckpointsAsVector3();
     178        int j[3];
     179        j[0]=changeVirtualToRealCheckPoint(checkpoints.x);
     180        j[1]=changeVirtualToRealCheckPoint(checkpoints.y);
     181        j[2]=changeVirtualToRealCheckPoint(checkpoints.z);
     182
     183
     184        return Vector3(j[0],j[1],j[2]);
     185
     186
     187    }
     188
     189    int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) {
     190        int temp=checkpointID;
     191        while(temp<-1){
     192            temp = this->virtualToRealCheckPoints_[temp];
     193        }
     194        return temp;
     195    }
     196
     197
     198    Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const
    151199    {
    152200        Vector3 checkpoints = Vector3(-1, -1, -1);
  • code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h

    r9441 r9508  
    6060
    6161            void setNextCheckpointsAsVector3(const Vector3& checkpoints);
    62             Vector3 getNextCheckpointsAsVector3() const;
    63             const std::set<int>& getNextCheckpoints() const
     62            Vector3 getNextCheckpointsAsVector3();
     63            Vector3 getVirtualNextCheckpointsAsVector3() const;
     64            void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints);
     65            int changeVirtualToRealCheckPoint(int);
     66
     67            const std::set<int>& getVirtualNextCheckpoints() const
    6468            {
    6569                return this->nextCheckpoints_;
    6670            }
    67 
     71            std::set<int> getNextCheckpoints()
     72            {
     73                std::set<int> temp;
     74                std::set<int> temp2=getVirtualNextCheckpoints();
     75                for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){
     76                    temp.insert(changeVirtualToRealCheckPoint((*it)));
     77                }
     78                return temp;
     79            }
    6880            inline void setLast(bool isLast)
    6981            {
     
    91103
    92104        protected:
     105
    93106            virtual void fire(bool bIsTriggered, BaseObject* originator);
    94107
     
    99112
    100113        private:
     114
    101115            int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0
    102116            std::set<int> nextCheckpoints_; ///< the indexes of the next check points
     
    105119            std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint
    106120            Vector3 myPosition_;
     121            std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed
    107122    };
    108123}
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc

    r9507 r9508  
    5454        ArtificialController(creator)
    5555    {
    56         RegisterObject(SpaceRaceController)
    57 ;        std::vector<RaceCheckPoint*> checkpoints;
     56        RegisterObject(SpaceRaceController);
     57        std::vector<RaceCheckPoint*> checkpoints;
     58
     59        virtualCheckPointIndex=-2;
    5860        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
    5961        {
     
    6466        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
    6567        checkpoints_=checkpoints;
     68
    6669        for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it)
    6770        {
    6871            std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
    6972            if(!nextCheckPoints.empty()) {
    70                 orxout() << "yay" << endl;
    7173                for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++) {
    7274                    RaceCheckPoint* point2 = findCheckpoint((*numb));
     
    8082        // initialisation of currentRaceCheckpoint_
    8183        currentRaceCheckpoint_ = NULL;
    82         /*
    83          // find first Checkpoint
    84          for (int i=0; true; i++){
    85          if(checkpoints_[i]->getCheckpointIndex()==0){
    86          nextRaceCheckpoint_=checkpoints_[i];
    87          break;
    88          }
    89          }*/
    90 
    91         virtualCheckPointIndex=-2;
     84
     85        int i;
     86        for (i=-2; findCheckpoint(i)!= NULL; i--){
     87            continue;
     88        }
     89        orxout()<<"Die ANzahl der virtuellen CP betraegt: "<< (-i)-2<<endl;
     90
    9291    }
    9392
     
    109108    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints)
    110109    {
    111         std::map<RaceCheckPoint*, int> * zaehler = new std::map<
    112         RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached (for simulation)
     110        std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached (for simulation)
    113111        for (unsigned int i = 0; i < allCheckpoints.size(); i++)
    114112        {
     
    140138        if (currentCheckpoint->isLast())
    141139        {// last point reached
    142             orxout() << "last one" << endl;
     140
    143141            (*zaehler)[currentCheckpoint] += 1;
    144142            return 1; // 1 Way form the last point to this one
     
    147145        {
    148146            int numberOfWays = 0; // counts number of ways from this Point to the last point
    149             for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
     147            for (std::set<int>::iterator it = currentCheckpoint->getVirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it)
    150148            {
    151149                if(currentCheckpoint==findCheckpoint(*it)){
     
    153151                    continue;
    154152                }
    155                 for (std::set<int>::iterator a = currentCheckpoint->getNextCheckpoints().begin(); a!= currentCheckpoint->getNextCheckpoints().end(); ++a){
    156                     orxout() << "Nextcheckpoints: "<<(*a) << endl;
    157                 }
    158                 orxout() << "currentCheck; " << currentCheckpoint->getCheckpointIndex() << "findCheck; " << findCheckpoint(*it)->getCheckpointIndex() << endl;
    159                 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
     153               numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
    160154            }
    161155            (*zaehler)[currentCheckpoint] += numberOfWays;
     
    185179        {   -1, -1, -1};
    186180        int temp_i = 0;
    187         for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it)
     181        for (std::set<int>::iterator it =raceCheckpoint->getVirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it)
    188182        {
    189183            distances[temp_i] = recCalculateDistance(findCheckpoint(*it), this->getControllableEntity()->getPosition());
     
    194188            if (distances[2] < distances[1] && distances[2] != -1)
    195189            {
    196                 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]
     190                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]
    197191            }
    198192            else
    199193            {
    200                 std::set<int>::iterator temp = raceCheckpoint->getNextCheckpoints().begin();
     194                std::set<int>::iterator temp = raceCheckpoint->getVirtualNextCheckpoints().begin();
    201195                return findCheckpoint(*(++temp)); // return [1]
    202196            }
     
    206200            if (distances[2] < distances[0] && distances[2] != -1)
    207201            {
    208                 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return [2]
     202                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return [2]
    209203            }
    210204            else
    211205            {
    212                 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().begin()); // return [0]
     206                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().begin()); // return [0]
    213207            }
    214208        }
     
    229223        {
    230224            int minimum = std::numeric_limits<int>::max();
    231             for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it)
     225            for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it!= currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)
    232226            {
    233227                int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
     
    250244            return nextRaceCheckpoint_;
    251245        }
    252         if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible
     246        if ((currentRaceCheckpoint_->getVirtualNextCheckpoints()).size() == 1) // no Adjust possible
    253247
    254248        {
     
    275269            newTempRaceCheckPoint = new RaceCheckPoint((*it));
    276270        }
     271        newTempRaceCheckPoint->setVisible(false);
    277272        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
    278273        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
    279274        newTempRaceCheckPoint->setLast(false);
    280         newTempRaceCheckPoint->setNextCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
    281 
    282         Vector3 temp = previousCheckpoint->getNextCheckpointsAsVector3();
     275        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
     276
     277        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
    283278        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
    284279        int positionInNextCheckPoint;
    285280        for (int i = 0; i <3; i++)
    286281        {
    287             if(previousCheckpoint->getNextCheckpointsAsVector3()[i]==indexFollowingCheckPoint)
    288             positionInNextCheckPoint=i;
     282            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
     283                positionInNextCheckPoint=i;
    289284        }
    290285        switch(positionInNextCheckPoint)
     
    294289            case 2: temp.z=virtualCheckPointIndex; break;
    295290        }
    296         previousCheckpoint->setNextCheckpointsAsVector3(temp);
     291        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
    297292        virtualCheckPointIndex--;
    298         OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
     293        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
     294        /*orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
     295        temp=previousCheckpoint->getNextCheckpointsAsVector3();
     296        orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
     297        orxout()<<endl;*/
    299298        return newTempRaceCheckPoint;
    300299    }
     
    315314        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
    316315        {
    317             if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30)
     316            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
    318317            {
    319318                currentRaceCheckpoint_=nextRaceCheckpoint_;
    320319                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
    321320                lastPositionSpaceship=this->getControllableEntity()->getPosition();
     321                orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
    322322            }
    323323        }
     
    325325        if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
    326326        {//Checkpoint erreicht
     327
    327328            currentRaceCheckpoint_=nextRaceCheckpoint_;
    328329            OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
    329330            nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
    330331            lastPositionSpaceship=this->getControllableEntity()->getPosition();
     332            orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
    331333        }
    332334        else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
     
    335337            lastPositionSpaceship=this->getControllableEntity()->getPosition();
    336338        }
    337         //TODO: korrigieren!
    338 
     339
     340        // Abmessung fuer MINDISTANCE gut;
    339341        else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE )
    340342        {
Note: See TracChangeset for help on using the changeset viewer.