Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 16, 2011, 5:02:12 PM (13 years ago)
Author:
jo
Message:

Object colouring added - according to current team implementation. Doesn't totally work as intended.

Location:
code/branches/gamecontent/src/orxonox/gametypes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamecontent/src/orxonox/gametypes/Mission.cc

    r8923 r8941  
    3030//#include "TeamGametype.h"
    3131#include "items/Engine.h"
     32#include "controllers/ArtificialController.h"
    3233
    3334#include "core/CoreIncludes.h"
     
    7071    {
    7172        Gametype::start();
    72 
     73        this->setTeams();
    7374        /*for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it != ObjectList<Engine>::end(); ++it)
    7475            it->setActive(false); // works -> @sr :*/
     
    8788         * */
    8889    }
     90
     91    void Mission::setTeams()
     92    {
     93        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     94            this->setObjectColour(*it);
     95    }
     96
     97
     98
    8999}
  • code/branches/gamecontent/src/orxonox/gametypes/Mission.h

    r8923 r8941  
    4646            virtual void start();
    4747            virtual void end();
     48            virtual void setTeams();
    4849            virtual void addBots(unsigned int amount){} //<! overwrite function in order to bypass the addbots command
    4950            inline void setLives(unsigned int amount)
  • code/branches/gamecontent/src/orxonox/gametypes/TeamGametype.cc

    r8930 r8941  
    3535#include "worldentities/TeamSpawnPoint.h"
    3636#include "worldentities/pawns/Pawn.h"
     37#include "controllers/ArtificialController.h"
    3738
    3839namespace orxonox
     
    7071    {
    7172        Gametype::playerEntered(player);
     73        if(player == NULL) return;
    7274        this->findAndSetTeam(player);
     75        if( getNumberOfPlayers() < maxPlayers_ || maxPlayers_  ==  0)
     76            this->allowedInGame_[player]= true;
     77        else
     78            this->allowedInGame_[player]= false;
    7379    }
    7480
     
    108114    void TeamGametype::spawnDeadPlayersIfRequested()
    109115    {
    110         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end();
    111 ++it)
    112         if (it->second.state_ == PlayerState::Dead)
    113         {
    114          if ((it->first->isReadyToSpawn() || this->bForceSpawn_))
    115             {
    116                this->spawnPlayer(it->first);
     116        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)\
     117        {
     118            if(true)//check if dead player is allowed to enter -> if maximum nr of players is exceeded & player was not in game before: disallow
     119                continue;
     120            if (it->second.state_ == PlayerState::Dead)
     121            {
     122                if ((it->first->isReadyToSpawn() || this->bForceSpawn_))
     123                {
     124                   this->spawnPlayer(it->first);
     125                }
    117126            }
    118127        }
     
    209218            return;
    210219
     220        this->setTeamColour(player,pawn);
     221    }
     222
     223    bool TeamGametype::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
     224    {
     225        if (pawn1 && pawn2)
     226        {
     227            std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
     228            std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
     229
     230            if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
     231                return (it1->second == it2->second);
     232        }
     233        return false;
     234    }
     235
     236    int TeamGametype::getTeam(PlayerInfo* player)
     237    {
     238        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
     239        if (it_player != this->teamnumbers_.end())
     240            return it_player->second;
     241        else
     242            return -1;
     243    }
     244
     245    void TeamGametype::setTeamColour(PlayerInfo* player, Pawn* pawn)
     246    {
    211247        // Set the team colour
    212248        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
     
    230266    }
    231267
    232     bool TeamGametype::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
    233     {
    234         if (pawn1 && pawn2)
    235         {
    236             std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
    237             std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
    238 
    239             if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
    240                 return (it1->second == it2->second);
    241         }
    242         return false;
    243     }
    244 
    245     int TeamGametype::getTeam(PlayerInfo* player)
    246     {
    247         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    248         if (it_player != this->teamnumbers_.end())
    249             return it_player->second;
    250         else
    251             return -1;
    252     }
     268    void TeamGametype::setObjectColour(Pawn* pawn)
     269    {
     270        if(pawn == NULL)
     271            return;
     272        //get Pawn's controller
     273        ArtificialController* controller = orxonox_cast<ArtificialController*>(pawn);
     274        if(controller == NULL)
     275            return;
     276        //get Teamnumber - get the data
     277        int teamnumber= controller->getTeam();
     278        if(teamnumber < 0)
     279            return;
     280        //set ObjectColour
     281        pawn->setRadarObjectColour(this->teamcolours_[teamnumber]);
     282
     283        std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
     284        for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
     285        {
     286            if ((*it)->isA(Class(TeamColourable)))
     287            {
     288                TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
     289                tc->setTeamColour(this->teamcolours_[teamnumber]);
     290            }
     291         }
     292    }
     293
     294
    253295}
  • code/branches/gamecontent/src/orxonox/gametypes/TeamGametype.h

    r8930 r8941  
    7373            //unsigned int playersPerTeam_; //<! Defines Maximum for players per team. Value 0: no maximum!
    7474            unsigned int maxPlayers_;  //<! Defines Maximum for number of players. Value 0 : no maximum!
     75            std::map<PlayerInfo*, bool> allowedInGame_; //!< Only those players are allowed to spawn which are listed here as 'true'.
     76            void setTeamColour(PlayerInfo* player, Pawn* pawn);
     77            void setObjectColour(Pawn* pawn);
    7578    };
    7679}
Note: See TracChangeset for help on using the changeset viewer.