Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.