Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8571


Ignore:
Timestamp:
May 25, 2011, 6:07:35 PM (13 years ago)
Author:
dafrick
Message:

Fixing possible bug in Gametype.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spacerace/src/orxonox/gametypes/Gametype.cc

    r8079 r8571  
    306306    SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const
    307307    {
     308        // If there is at least one SpawnPoint.
    308309        if (this->spawnpoints_.size() > 0)
    309310        {
     311            // Fallback spawn point if there is no active one, choose a random one.
    310312            SpawnPoint* fallbackSpawnPoint = NULL;
    311313            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    312314            unsigned int index = 0;
    313             std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;
     315            std::vector<SpawnPoint*> activeSpawnPoints;
    314316            for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
    315317            {
     
    317319                    fallbackSpawnPoint = (*it);
    318320
    319                 if (!(*it)->isActive())
    320                     activeSpawnPoints.erase(*it);
     321                if (*it != NULL && (*it)->isActive())
     322                    activeSpawnPoints.push_back(*it);
    321323
    322324                ++index;
    323325            }
    324326
    325             randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    326             index = 0;
    327             for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it)
    328             {
    329                 if (index == randomspawn)
    330                     return (*it);
    331 
    332                 ++index;
    333             }
    334 
     327            if(activeSpawnPoints.size() > 0)
     328            {
     329                randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size())));
     330                return activeSpawnPoints[randomspawn];
     331            }
     332
     333            COUT(2) << "Warning: Fallback SpawnPoint was used, because there were no active SpawnPoints." << endl;
    335334            return fallbackSpawnPoint;
    336335        }
Note: See TracChangeset for help on using the changeset viewer.