Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2008, 4:05:25 AM (16 years ago)
Author:
rgrieder
Message:

Added stats overlay. "OverlayGroup toggleVisibility Stats" will do what it says.

Location:
code/branches/presentation/src/orxonox/objects/gametypes
Files:
2 edited

Legend:

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

    r2494 r2495  
    3535#include "core/CoreIncludes.h"
    3636#include "core/ConfigValueIncludes.h"
    37 #include "core/Loader.h"
    38 #include "core/XMLFile.h"
     37#include "core/Template.h"
     38#include "core/Core.h"
     39#include "overlays/OverlayGroup.h"
    3940#include "objects/infos/PlayerInfo.h"
    4041#include "objects/infos/Bot.h"
     
    6869        this->addBots(this->numberOfBots_);
    6970
    70         this->statsOverlay_ = 0;
    71 
    7271        setConfigValues();
    7372
    7473        // load the corresponding score board
    75         //this->statsOverlay_ = new XMLFile(Settings::getDataPath() + "overlay/" + this->statsOverlayName_);
    76         //Loader::open(statsOverlay_);
    77         //this->setGametype(this);
     74        if (Core::showsGraphics() && this->scoreboardTemplate_ != "")
     75        {
     76            this->scoreboard_ = new OverlayGroup(this);
     77            this->scoreboard_->addTemplate(this->scoreboardTemplate_);
     78            this->scoreboard_->setGametype(this);
     79        }
     80        else
     81            this->scoreboard_ = 0;
    7882    }
    7983
     
    8488        SetConfigValue(bForceSpawn_, false);
    8589        SetConfigValue(numberOfBots_, 0);
    86         SetConfigValue(statsOverlayName_, "stats.oxo");
     90        SetConfigValue(scoreboardTemplate_, "defaultScoreboard");
    8791    }
    8892
     
    118122    void Gametype::playerEntered(PlayerInfo* player)
    119123    {
    120         this->players_[player] = PlayerState::Joined;
     124        this->players_[player].state_ = PlayerState::Joined;
    121125
    122126        std::string message = player->getName() + " entered the game";
     
    127131    void Gametype::playerLeft(PlayerInfo* player)
    128132    {
    129         std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(player);
     133        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
    130134        if (it != this->players_.end())
    131135        {
     
    188192        if (victim && victim->getPlayer())
    189193        {
    190             std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(victim->getPlayer());
     194            std::map<PlayerInfo*, Player>::iterator it = this->players_.find(victim->getPlayer());
    191195            if (it != this->players_.end())
    192196            {
    193                 it->second = PlayerState::Dead;
     197                it->second.state_ = PlayerState::Dead;
     198                it->second.killed_++;
     199
     200                // Reward killer
     201                if (killer)
     202                {
     203                    std::map<PlayerInfo*, Player>::iterator itKiller = this->players_.find(killer->getPlayer());
     204                    if (itKiller != this->players_.end())
     205                    {
     206                        this->playerScored(itKiller->second);
     207                    }
     208                    else
     209                        COUT(2) << "Warning: Killing Pawn was not in the playerlist" << std::endl;
     210                }
    194211
    195212                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
     
    211228    }
    212229
    213     void Gametype::playerScored(PlayerInfo* player)
    214     {
     230    void Gametype::playerScored(Player& player)
     231    {
     232        player.frags_++;
    215233    }
    216234
     
    234252    void Gametype::assignDefaultPawnsIfNeeded()
    235253    {
    236         for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     254        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    237255        {
    238256            if (!it->first->getControllableEntity())
    239257            {
    240                 it->second = PlayerState::Dead;
     258                it->second.state_ = PlayerState::Dead;
    241259
    242260                if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
     
    249267                        spawn->spawn(entity);
    250268                        it->first->startControl(entity);
    251                         it->second = PlayerState::Dead;
     269                        it->second.state_ = PlayerState::Dead;
    252270                    }
    253271                    else
     
    284302                    bool allplayersready = true;
    285303                    bool hashumanplayers = false;
    286                     for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     304                    for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    287305                    {
    288306                        if (!it->first->isReadyToSpawn())
     
    303321    void Gametype::spawnPlayersIfRequested()
    304322    {
    305         for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     323        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    306324            if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    307325                this->spawnPlayer(it->first);
     
    310328    void Gametype::spawnDeadPlayersIfRequested()
    311329    {
    312         for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    313             if (it->second == PlayerState::Dead)
     330        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     331            if (it->second.state_ == PlayerState::Dead)
    314332                if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    315333                    this->spawnPlayer(it->first);
     
    322340        {
    323341            player->startControl(spawnpoint->spawn());
    324             this->players_[player] = PlayerState::Alive;
     342            this->players_[player].state_ = PlayerState::Alive;
    325343        }
    326344        else
  • code/branches/presentation/src/orxonox/objects/gametypes/Gametype.h

    r2492 r2495  
    5353    }
    5454
     55    struct Player
     56    {
     57        PlayerInfo* info_;
     58        PlayerState::Enum state_;
     59        int frags_;
     60        int killed_;
     61    };
     62
    5563    class _OrxonoxExport Gametype : public BaseObject, public Tickable
    5664    {
    5765        friend class PlayerInfo;
    58         friend class ClassIdentifier<Gametype>;
    5966
    6067        public:
     
    8289            virtual void playerChangedName(PlayerInfo* player);
    8390
    84             virtual void playerScored(PlayerInfo* player);
     91            virtual void playerScored(Player& player);
    8592
    8693            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
     
    8895            virtual void pawnPostSpawn(Pawn* pawn);
    8996
    90             inline const std::map<PlayerInfo*, PlayerState::Enum>& getPlayers() const
     97            inline const std::map<PlayerInfo*, Player>& getPlayers() const
    9198                { return this->players_; }
    9299
     
    104111            inline unsigned int getNumberOfPlayers() const
    105112                { return this->players_.size(); }
    106 
    107             inline std::string getPlayersName() const
    108                 { return "StatsBot77"; }
    109 
    110             inline unsigned int getPlayersFrags() const
    111                 { return 123; }
    112113
    113114        private:
     
    131132            unsigned int numberOfBots_;
    132133
    133             std::map<PlayerInfo*, PlayerState::Enum> players_;
     134            std::map<PlayerInfo*, Player> players_;
    134135            std::set<SpawnPoint*> spawnpoints_;
    135136            SubclassIdentifier<ControllableEntity> defaultControllableEntity_;
    136137
    137             XMLFile* statsOverlay_;
     138            OverlayGroup* scoreboard_;
    138139
    139140            // Config Values
    140             std::string statsOverlayName_;
     141            std::string scoreboardTemplate_;
    141142    };
    142143}
Note: See TracChangeset for help on using the changeset viewer.