Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/gametypes/Gametype.cc

    r2171 r2485  
    3434
    3535#include "core/CoreIncludes.h"
     36#include "core/ConfigValueIncludes.h"
    3637#include "objects/infos/PlayerInfo.h"
     38#include "objects/infos/Bot.h"
    3739#include "objects/worldentities/pawns/Spectator.h"
    3840#include "objects/worldentities/SpawnPoint.h"
     41#include "objects/worldentities/Camera.h"
    3942
    4043#include "network/Host.h"
     
    4447    CreateUnloadableFactory(Gametype);
    4548
    46     Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
     49    Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator)
    4750    {
    4851        RegisterObject(Gametype);
    4952
     53        this->setGametype(this);
     54
    5055        this->defaultControllableEntity_ = Class(Spectator);
    5156
    52         this->bStarted_ = false;
    53         this->bEnded_ = false;
    5457        this->bAutoStart_ = false;
    5558        this->bForceSpawn_ = false;
     59        this->numberOfBots_ = 0;
    5660
    5761        this->initialStartCountdown_ = 3;
    58         this->startCountdown_ = 0;
    59         this->bStartCountdownRunning_ = false;
     62
     63        this->setConfigValues();
     64
     65        this->addBots(this->numberOfBots_);
     66    }
     67
     68    void Gametype::setConfigValues()
     69    {
     70        SetConfigValue(initialStartCountdown_, 3.0f);
     71        SetConfigValue(bAutoStart_, false);
     72        SetConfigValue(bForceSpawn_, false);
     73        SetConfigValue(numberOfBots_, 0);
    6074    }
    6175
    6276    void Gametype::tick(float dt)
    6377    {
    64         if (this->bStartCountdownRunning_ && !this->bStarted_)
    65             this->startCountdown_ -= dt;
    66 
    67         if (!this->bStarted_)
     78        SUPER(Gametype, tick, dt);
     79
     80        if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
     81            this->gtinfo_.startCountdown_ -= dt;
     82
     83        if (!this->gtinfo_.bStarted_)
    6884            this->checkStart();
    6985        else
     
    7692    {
    7793        COUT(0) << "game started" << std::endl;
    78         this->bStarted_ = true;
     94        this->gtinfo_.bStarted_ = true;
    7995
    8096        this->spawnPlayersIfRequested();
     
    84100    {
    85101        COUT(0) << "game ended" << std::endl;
    86         this->bEnded_ = true;
     102        this->gtinfo_.bEnded_ = true;
    87103    }
    88104
     
    140156    void Gametype::pawnKilled(Pawn* victim, Pawn* killer)
    141157    {
     158        if (victim && victim->getPlayer())
     159        {
     160            std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(victim->getPlayer());
     161            if (it != this->players_.end())
     162            {
     163                it->second = PlayerState::Dead;
     164
     165                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
     166                if (victim->getCamera())
     167                {
     168                    entity->setPosition(victim->getCamera()->getWorldPosition());
     169                    entity->setOrientation(victim->getCamera()->getWorldOrientation());
     170                }
     171                else
     172                {
     173                    entity->setPosition(victim->getWorldPosition());
     174                    entity->setOrientation(victim->getWorldOrientation());
     175                }
     176                it->first->startControl(entity);
     177            }
     178            else
     179                COUT(2) << "Warning: Killed Pawn was not in the playerlist" << std::endl;
     180        }
    142181    }
    143182
     
    150189        if (this->spawnpoints_.size() > 0)
    151190        {
    152             srand(time(0));
    153             rnd();
    154 
    155191            unsigned int randomspawn = (unsigned int)rnd(this->spawnpoints_.size());
    156192            unsigned int index = 0;
     
    170206        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    171207        {
    172             if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_))
    173             {
    174                 SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
    175                 if (spawn)
    176                 {
    177                     // force spawn at spawnpoint with default pawn
    178                     ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
    179                     spawn->spawn(entity);
    180                     it->first->startControl(entity);
    181                     it->second = PlayerState::Dead;
     208            if (!it->first->getControllableEntity())
     209            {
     210                it->second = PlayerState::Dead;
     211
     212                if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
     213                {
     214                    SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
     215                    if (spawn)
     216                    {
     217                        // force spawn at spawnpoint with default pawn
     218                        ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
     219                        spawn->spawn(entity);
     220                        it->first->startControl(entity);
     221                        it->second = PlayerState::Dead;
     222                    }
     223                    else
     224                    {
     225                        COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
     226                        abort();
     227                    }
     228                }
     229            }
     230        }
     231    }
     232
     233    void Gametype::checkStart()
     234    {
     235        if (!this->gtinfo_.bStarted_)
     236        {
     237            if (this->gtinfo_.bStartCountdownRunning_)
     238            {
     239                if (this->gtinfo_.startCountdown_ <= 0)
     240                {
     241                    this->gtinfo_.bStartCountdownRunning_ = false;
     242                    this->gtinfo_.startCountdown_ = 0;
     243                    this->start();
     244                }
     245            }
     246            else if (this->players_.size() > 0)
     247            {
     248                if (this->bAutoStart_)
     249                {
     250                    this->start();
    182251                }
    183252                else
    184253                {
    185                     COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
    186                     abort();
    187                 }
    188             }
    189         }
    190     }
    191 
    192     void Gametype::checkStart()
    193     {
    194         if (!this->bStarted_)
    195         {
    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)
    206             {
    207                 if (this->bAutoStart_)
    208                 {
    209                     this->start();
    210                 }
    211                 else
    212                 {
    213254                    bool allplayersready = true;
     255                    bool hashumanplayers = false;
    214256                    for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    215257                    {
    216258                        if (!it->first->isReadyToSpawn())
    217259                            allplayersready = false;
     260                        if (it->first->isHumanPlayer())
     261                            hashumanplayers = true;
    218262                    }
    219                     if (allplayersready)
     263                    if (allplayersready && hashumanplayers)
    220264                    {
    221                         this->startCountdown_ = this->initialStartCountdown_;
    222                         this->bStartCountdownRunning_ = true;
     265                        this->gtinfo_.startCountdown_ = this->initialStartCountdown_;
     266                        this->gtinfo_.bStartCountdownRunning_ = true;
    223267                    }
    224268                }
     
    256300        }
    257301    }
     302
     303    void Gametype::addBots(unsigned int amount)
     304    {
     305        for (unsigned int i = 0; i < amount; ++i)
     306            new Bot(this);
     307    }
     308
     309    void Gametype::killBots(unsigned int amount)
     310    {
     311        unsigned int i = 0;
     312        for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); )
     313        {
     314            if (it->getGametype() == this)
     315            {
     316                delete (*(it++));
     317                ++i;
     318            }
     319        }
     320    }
    258321}
  • code/branches/presentation/src/orxonox/objects/gametypes/Gametype.h

    r2171 r2485  
    3838#include "objects/worldentities/ControllableEntity.h"
    3939#include "objects/Tickable.h"
     40#include "objects/infos/GametypeInfo.h"
    4041
    4142namespace orxonox
     
    6061            virtual ~Gametype() {}
    6162
     63            void setConfigValues();
     64
    6265            virtual void tick(float dt);
    6366
     67            inline const GametypeInfo* getGametypeInfo() const
     68                { return &this->gtinfo_; }
     69
    6470            inline bool hasStarted() const
    65                 { return this->bStarted_; }
     71                { return this->gtinfo_.bStarted_; }
    6672            inline bool hasEnded() const
    67                 { return this->bEnded_; }
     73                { return this->gtinfo_.bEnded_; }
    6874
    6975            virtual void start();
     
    8894
    8995            inline bool isStartCountdownRunning() const
    90                 { return this->bStartCountdownRunning_; }
     96                { return this->gtinfo_.bStartCountdownRunning_; }
    9197            inline float getStartCountdown() const
    92                 { return this->startCountdown_; }
     98                { return this->gtinfo_.startCountdown_; }
     99
     100            void addBots(unsigned int amount);
     101            void killBots(unsigned int amount = 0);
    93102
    94103        private:
     
    104113            void spawnDeadPlayersIfRequested();
    105114
    106             bool bStarted_;
    107             bool bEnded_;
     115            GametypeInfo gtinfo_;
     116
    108117            bool bAutoStart_;
    109118            bool bForceSpawn_;
    110119
    111120            float initialStartCountdown_;
    112             float startCountdown_;
    113             bool bStartCountdownRunning_;
     121            unsigned int numberOfBots_;
    114122
    115123            std::map<PlayerInfo*, PlayerState::Enum> players_;
Note: See TracChangeset for help on using the changeset viewer.