Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 28, 2008, 3:05:17 AM (16 years ago)
Author:
landauf
Message:

added spaceship

File:
1 edited

Legend:

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

    r2020 r2024  
    4848        RegisterObject(Gametype);
    4949
    50         this->defaultPawn_ = Class(Spectator);
     50        this->defaultControllableEntity_ = Class(Spectator);
     51
    5152        this->bStarted_ = false;
    5253        this->bEnded_ = false;
    5354        this->bAutoStart_ = false;
     55        this->bForceSpawn_ = false;
     56
     57        this->initialStartCountdown_ = 3;
     58        this->startCountdown_ = 0;
     59        this->bStartCountdownRunning_ = false;
    5460
    5561        COUT(0) << "created Gametype" << std::endl;
     
    5864    void Gametype::tick(float dt)
    5965    {
     66        if (this->bStartCountdownRunning_ && !this->bStarted_)
     67            this->startCountdown_ -= dt;
     68
    6069        if (!this->bStarted_)
    6170            this->checkStart();
    6271
    6372        this->assignDefaultPawnsIfNeeded();
     73        this->spawnDeadPlayersIfRequested();
    6474    }
    6575
     
    6979        this->bStarted_ = true;
    7080
    71         for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    72             this->spawnPlayer(*it);
     81        this->spawnPlayersIfRequested();
    7382    }
    7483
     
    122131    }
    123132
    124     void Gametype::playerSpawned(PlayerInfo* player)
    125     {
    126     }
    127 
    128     void Gametype::playerDied(PlayerInfo* player)
     133    void Gametype::pawnPreSpawn(Pawn* pawn)
     134    {
     135    }
     136
     137    void Gametype::pawnPostSpawn(Pawn* pawn)
     138    {
     139    }
     140
     141    void Gametype::pawnKilled(Pawn* victim, Pawn* killer)
    129142    {
    130143    }
     
    164177                {
    165178                    // force spawn at spawnpoint with default pawn
    166                     ControllableEntity* newpawn = this->defaultPawn_.fabricate(spawn);
    167                     spawn->spawn(newpawn);
    168                     (*it)->startControl(newpawn);
     179                    ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
     180                    spawn->spawn(entity);
     181                    (*it)->startControl(entity);
    169182                }
    170183                else
     
    181194        if (!this->bStarted_)
    182195        {
    183             if (this->players_.size() > 0)
     196            if (this->bStartCountdownRunning_)
     197            {
     198                if (this->startCountdown_ <= 0)
     199                {
     200                    this->bStartCountdownRunning_ = false;
     201                    this->startCountdown_ = 0;
     202                    this->start();
     203                }
     204            }
     205            else if (this->players_.size() > 0)
    184206            {
    185207                if (this->bAutoStart_)
     
    196218                    }
    197219                    if (allplayersready)
    198                         this->start();
    199                 }
    200             }
    201         }
     220                    {
     221                        this->startCountdown_ = this->initialStartCountdown_;
     222                        this->bStartCountdownRunning_ = true;
     223                    }
     224                }
     225            }
     226        }
     227    }
     228
     229    void Gametype::spawnPlayersIfRequested()
     230    {
     231        for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     232            if ((*it)->isReadyToSpawn() || this->bForceSpawn_)
     233                this->spawnPlayer(*it);
     234    }
     235
     236    void Gametype::spawnDeadPlayersIfRequested()
     237    {
     238        for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     239            if (!(*it)->getControllableEntity())
     240                if ((*it)->isReadyToSpawn() || this->bForceSpawn_)
     241                    this->spawnPlayer(*it);
    202242    }
    203243
    204244    void Gametype::spawnPlayer(PlayerInfo* player)
    205245    {
    206         if (player->isReadyToSpawn())
    207         {
    208             SpawnPoint* spawnpoint = this->getBestSpawnPoint(player);
    209             if (spawnpoint)
    210             {
    211                 player->startControl(spawnpoint->spawn());
    212             }
    213             else
    214             {
    215                 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
    216                 abort();
    217             }
     246        SpawnPoint* spawnpoint = this->getBestSpawnPoint(player);
     247        if (spawnpoint)
     248        {
     249            player->startControl(spawnpoint->spawn());
     250        }
     251        else
     252        {
     253            COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
     254            abort();
    218255        }
    219256    }
Note: See TracChangeset for help on using the changeset viewer.