Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7890


Ignore:
Timestamp:
Feb 14, 2011, 8:29:14 PM (14 years ago)
Author:
jo
Message:

trying to find a bug

Location:
code/branches/lastmanstanding2/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/lastmanstanding2/src/modules/overlays/hud/CMakeLists.txt

    r7697 r7890  
    1616  GametypeFadingMessage.cc
    1717  LastManStandingInfos.cc
    18   LastTeamStandingInfos.cc 
     18  LastTeamStandingInfos.cc
    1919)
  • code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.cc

    r7699 r7890  
    4343    LastTeamStanding::LastTeamStanding(BaseObject* creator) : TeamDeathmatch(creator)
    4444    {
    45         RegisterObject(LastTeamStanding);
    46         this->bForceSpawn_=true;
    47         this->lives=4;
    48         this->teamsAlive=0;
    49         this->timeRemaining=15.0f;
    50         this->respawnDelay=4.0f;
    51         this->bNoPunishment=false;
    52         this->bHardPunishment=false;
    53         this->punishDamageRate=0.4f;
    54         this->setHUDTemplate("LastTeamStandingHUD");//tolowercase:-)
    55         this->eachTeamsPlayers = new int[teams_];
    56         this->bMinPlayersReached = false;
     45        this->bForceSpawn_ = true;
     46        this->lives = 1;//4
     47        this->eachTeamsPlayers.reserve(teams_);
     48        this->teamsAlive = 0;
     49        this->bMinTeamsReached = false;
     50        this->bNoPunishment = false;
     51        this->bHardPunishment = false;
     52        this->punishDamageRate = 0.4f;
     53        this->timeRemaining = 15.0f;
     54        this->respawnDelay = 4.0f;
    5755    }
    5856   
    5957    LastTeamStanding::~LastTeamStanding()
    6058    {
    61         delete[] this->eachTeamsPlayers;
     59        this->playerLives_.clear();
     60        this->eachTeamsPlayers.clear();
     61        this->timeToAct_.clear();
     62        this->playerDelayTime_.clear();
     63        this->inGame_.clear();
    6264    }   
    63 
    64     void LastTeamStanding::spawnDeadPlayersIfRequested()
    65     {
    66         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    67             if (it->second.state_ == PlayerState::Dead)
    68             {
    69                 bool alive = (0<playerLives_[it->first]&&(inGame_[it->first]));
    70                 if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
    71                 {
    72                     this->spawnPlayer(it->first);
    73                 }
    74             }
    75     }
    76 
    77 
    78     void LastTeamStanding::setConfigValues()
    79     {
    80         SetConfigValue(lives, 4);
    81         SetConfigValue(timeRemaining, 15.0f);
    82         SetConfigValue(respawnDelay, 4.0f);
    83         SetConfigValue(bNoPunishment, false);
    84         SetConfigValue(bHardPunishment, false);
    85     }
    86 
    87     bool LastTeamStanding::allowPawnDamage(Pawn* victim, Pawn* originator)
    88     {
    89         bool allow = TeamDeathmatch::allowPawnDamage(victim, originator);
    90         if(!allow) {return allow;}
    91         if (originator && originator->getPlayer())// only for safety
    92         {
    93             this->timeToAct_[originator->getPlayer()]=timeRemaining;
    94 
    95             std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
    96             if (it != this->players_.end())
    97             {
    98                 if (it->first->getClientID()== CLIENTID_UNKNOWN)
    99                     return true;
    100                 const std::string& message = ""; // resets Camper-Warning-message
    101                 this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    102             }   
    103         }
    104         return allow;
    105     }
    106 
    107     bool LastTeamStanding::allowPawnDeath(Pawn* victim, Pawn* originator)
    108     {
    109         if (!victim||!victim->getPlayer())// only for safety
    110             return true;
    111         bool allow =TeamDeathmatch::allowPawnDeath(victim, originator);
    112         if(!allow) {return allow;}
    113         playerLives_[victim->getPlayer()]=playerLives_[victim->getPlayer()]-1;
    114         this->inGame_[victim->getPlayer()]=false;//if player dies he, isn't allowed to respawn immediately
    115         if (playerLives_[victim->getPlayer()]<=0)//if player lost all lives
    116         {
    117             this->eachTeamsPlayers[getTeam(victim->getPlayer())]--;
    118             if(eachTeamsPlayers[getTeam(victim->getPlayer())]==0)//last team member died
    119                 this->teamsAlive--;
    120             const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
    121             COUT(0) << message << std::endl;
    122             Host::Broadcast(message);
    123         }
    124 
    125         return allow;
    126     }
    127 
    128     int LastTeamStanding::getMinLives()
    129     {
    130         int min=lives;
    131         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    132         {
    133             if (it->second<=0)
    134                 continue;
    135             if (it->second<lives)
    136                 min=it->second;
    137         }
    138         return min;
    139     }
    140 
    141     void LastTeamStanding::end()//TODO!
    142     {
    143         Gametype::end();
    144        
    145         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    146         {
    147             if (it->first->getClientID() == CLIENTID_UNKNOWN)
    148                 continue;
    149 
    150             if (it->second > 0)
    151                 this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
    152             else
    153                 this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    154         }
    155     }
    156 
    157     int LastTeamStanding::playerGetLives(PlayerInfo* player)
    158     {
    159         if (player)
    160             return  playerLives_[player];
    161         else
    162             return 0;
    163     }
    164    
    165     int LastTeamStanding::getNumTeamsAlive() const
    166     {
    167         return this->teamsAlive;
    168     }
    16965
    17066    void LastTeamStanding::playerEntered(PlayerInfo* player)
     
    17773        else
    17874            playerLives_[player]=getMinLives();//new players only get minimum of lives
    179            
    180         if(this->eachTeamsPlayers[getTeam(player)]==0)
     75       
     76        if(this->eachTeamsPlayers[getTeam(player)]==0) //if a player is the first in his group, a new team is alive
    18177            this->teamsAlive++;
    182         this->eachTeamsPlayers[getTeam(player)]++;
     78        this->eachTeamsPlayers[getTeam(player)]++; //the number of player in this team is increased
     79
    18380        if (teamsAlive>1) // Now the game is allowed to end, since there are at least two teams.
    184             bMinPlayersReached=true;
    185         this->timeToAct_[player]=timeRemaining;
    186         this->playerDelayTime_[player]=respawnDelay;
    187         this->inGame_[player]=true;
     81            bMinTeamsReached = true; // since there are at least two teams, the game is allowed to end
     82        this->timeToAct_[player] = timeRemaining;
     83        this->playerDelayTime_[player] = respawnDelay;
     84        this->inGame_[player] = true;
    18885    }
    18986
     
    19390        if (valid_player)
    19491        {
    195             this->eachTeamsPlayers[getTeam(player)]--;
    196             if(this->eachTeamsPlayers[getTeam(player)]==0)
     92            this->eachTeamsPlayers[getTeam(player)]--;       // a player left the team
     93            if(this->eachTeamsPlayers[getTeam(player)] == 0) // if it was the last player a team died
    19794                 this->teamsAlive--;
    198             this->playerLives_.erase (player);
    199             this->playerDelayTime_.erase (player);
    200             this->inGame_.erase (player);
     95            this->playerLives_.erase(player);
     96            this->eachTeamsPlayers.clear();
    20197            this->timeToAct_.erase(player);
     98            this->playerDelayTime_.erase(player);
     99            this->inGame_.erase(player);
    202100        }
    203101
    204102        return valid_player;
     103    }
     104
     105    bool LastTeamStanding::allowPawnDeath(Pawn* victim, Pawn* originator)
     106    {
     107        if (!victim||!victim->getPlayer())// only for safety
     108            return true;
     109        bool allow = TeamDeathmatch::allowPawnDeath(victim, originator);
     110        if(!allow) {return allow;}
     111       
     112        playerLives_[victim->getPlayer()] = playerLives_[victim->getPlayer()] - 1; //player lost a live
     113        this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately
     114        if (playerLives_[victim->getPlayer()]<=0) //if player lost all lives
     115        {
     116            this->eachTeamsPlayers[getTeam(victim->getPlayer())]--;
     117            if(eachTeamsPlayers[getTeam(victim->getPlayer())] == 0) //last team member died
     118                this->teamsAlive--;
     119            const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
     120            COUT(0) << message << std::endl;
     121            Host::Broadcast(message);
     122        }
     123
     124        return allow;
     125    }
     126
     127    bool LastTeamStanding::allowPawnDamage(Pawn* victim, Pawn* originator)
     128    {
     129        bool allow = TeamDeathmatch::allowPawnDamage(victim, originator);
     130        if(!allow) {return allow;}
     131        if (originator && originator->getPlayer())// only for safety
     132        {
     133            this->timeToAct_[originator->getPlayer()] = timeRemaining;
     134
     135            std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
     136            if (it != this->players_.end())
     137            {
     138                if (it->first->getClientID()== CLIENTID_UNKNOWN)
     139                    return true;
     140                const std::string& message = ""; // resets Camper-Warning-message
     141                this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
     142            }   
     143        }
     144        return allow;
     145    }
     146
     147    void LastTeamStanding::spawnDeadPlayersIfRequested()
     148    {
     149        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     150            if (it->second.state_ == PlayerState::Dead)
     151            {
     152                bool alive = (0 < playerLives_[it->first]&&(inGame_[it->first]));
     153                if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
     154                {
     155                    this->spawnPlayer(it->first);
     156                }
     157            }
    205158    }
    206159
     
    211164        TeamDeathmatch::playerStartsControllingPawn(player,pawn);
    212165       
    213         this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
    214         this->playerDelayTime_[player]=respawnDelay;
     166        this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer
     167        this->playerDelayTime_[player] = respawnDelay;
    215168       
    216169        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
     
    222175            this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    223176        } 
     177    }
     178
     179    void LastTeamStanding::tick(float dt)
     180    {
     181        SUPER(LastTeamStanding, tick, dt);
     182        if(this->hasStarted()&&(!this->hasEnded()))
     183        {
     184            if (bMinTeamsReached &&(this->hasStarted()&&(teamsAlive<=1)))//last team remaining -> game will end
     185            {
     186                this->end();
     187            }
     188            for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
     189            {   
     190                if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time.
     191                    continue;     
     192                it->second -= dt;//Decreases punishment time.
     193                if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
     194                {
     195                    playerDelayTime_[it->first] -= dt;
     196                    if (playerDelayTime_[it->first] <= 0)
     197                    this->inGame_[it->first] = true;
     198
     199                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
     200                        continue;
     201                    int output = 1 + playerDelayTime_[it->first];
     202                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
     203                    this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
     204                }
     205                else if (it->second < 0.0f)
     206                {
     207                    it->second = timeRemaining + 3.0f;//reset punishment-timer
     208                    if (playerGetLives(it->first) > 0)
     209                    {
     210                        this->punishPlayer(it->first);
     211                        if (it->first->getClientID() == CLIENTID_UNKNOWN)
     212                            return;
     213                        const std::string& message = ""; // resets Camper-Warning-message
     214                        this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
     215                    }
     216                }
     217                else if (it->second < timeRemaining/5)//Warning message
     218                {
     219                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
     220                        continue;
     221                    const std::string& message = "Camper Warning! Don't forget to shoot.";
     222                    this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
     223                }
     224            }
     225        }
     226    }
     227
     228    void LastTeamStanding::end()//TODO: Send the message to the whole team
     229    {
     230        Gametype::end();
     231       
     232        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
     233        {
     234            if (it->first->getClientID() == CLIENTID_UNKNOWN)
     235                continue;
     236
     237            if (it->second > 0)
     238                this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
     239            else
     240                this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     241        /*//erase maps:
     242            this->playerLives_.erase(it->first);
     243            this->playerDelayTime_.erase (it->first);
     244            this->inGame_.erase (it->first);
     245            this->timeToAct_.erase(it->first);*/
     246        }
     247
     248    }
     249
     250
     251    int LastTeamStanding::getMinLives()
     252    {
     253        int min = lives;
     254        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
     255        {
     256            if (it->second <= 0)
     257                continue;
     258            if (it->second < lives)
     259                min = it->second;
     260        }
     261        return min;
    224262    }
    225263
     
    241279            {
    242280                pawn->kill();
    243                 this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
     281                this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer
    244282            }
    245283            else
    246284            {
    247                 float damage=pawn->getMaxHealth()*punishDamageRate*0.5;//TODO: Factor 0.5 is hard coded. Where is the ratio between MaxHealth actually defined?
     285                float damage = pawn->getMaxHealth()*punishDamageRate*0.5;//TODO: Factor 0.5 is hard coded. Where is the ratio between MaxHealth actually defined?
    248286                pawn->removeHealth(damage);
    249                 this->timeToAct_[player]=timeRemaining;//reset timer
    250             }
    251         }
    252     }
    253 
    254     void LastTeamStanding::tick(float dt)
    255     {
    256         SUPER(LastTeamStanding, tick, dt);
    257         if(this->hasStarted()&&(!this->hasEnded()))
    258         {
    259             if (bMinPlayersReached &&(this->hasStarted()&&(teamsAlive<=1)))//last team remaining
    260             {
    261                 this->end();
    262             }
    263             for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
    264             {   
    265                 if (playerGetLives(it->first)<=0)//Players without lives shouldn't be affected by time.
    266                     continue;     
    267                 it->second-=dt;//Decreases punishment time.
    268                 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
    269                 {
    270                     playerDelayTime_[it->first]-=dt;
    271                     if (playerDelayTime_[it->first]<=0)
    272                     this->inGame_[it->first]=true;
    273 
    274                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
    275                         continue;
    276                     int output=1+playerDelayTime_[it->first];
    277                     const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
    278                     this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    279                 }
    280                 else if (it->second<0.0f)
    281                 {
    282                     it->second=timeRemaining+3.0f;//reset punishment-timer
    283                     if (playerGetLives(it->first)>0)
    284                     {
    285                         this->punishPlayer(it->first);
    286                         if (it->first->getClientID()== CLIENTID_UNKNOWN)
    287                             return;
    288                         const std::string& message = ""; // resets Camper-Warning-message
    289                         this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    290                     }
    291                 }
    292                 else if (it->second<timeRemaining/5)//Warning message
    293                 {
    294                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
    295                         continue;
    296                     const std::string& message = "Camper Warning! Don't forget to shoot.";
    297                     this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    298                 }
    299             }
    300         }
    301     }
    302 
     287                this->timeToAct_[player] = timeRemaining;//reset timer
     288            }
     289        }
     290    }
     291
     292    int LastTeamStanding::playerGetLives(PlayerInfo* player)
     293    {
     294        if (player)
     295            return  playerLives_[player];
     296        else
     297            return 0;
     298    }
     299   
     300    void LastTeamStanding::setConfigValues()
     301    {
     302        SetConfigValue(lives, 4);
     303        SetConfigValue(timeRemaining, 15.0f);
     304        SetConfigValue(respawnDelay, 4.0f);
     305        SetConfigValue(bNoPunishment, false);
     306        SetConfigValue(bHardPunishment, false);
     307    }
    303308}
  • code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.h

    r7699 r7890  
    5454            int lives; //!< Standard amount of lives. Each player starts a game with so many lives.
    5555            std::map< PlayerInfo*, int > playerLives_; //!< Each player's lives are stored here.
     56            std::vector<int> eachTeamsPlayers; //!<Number of players in each team.
    5657            int teamsAlive; //!< Counter counting teams with more than one player remaining.
     58//Data for CamperPunishment
    5759            float timeRemaining; //!< Each player has a certain time where he or she has to hit an opponent or will be punished.
    5860            std::map<PlayerInfo*, float> timeToAct_; //!< Each player's time till she/he will be punished is stored here.
     61            bool bNoPunishment; //!< Config value to switch off Punishment function if it is set to true.
     62            bool bHardPunishment; //!< Switches between damage and death as punishment.
     63            float punishDamageRate; //!< Makes Damage adjustable.
     64//Data for RespawnDelay
    5965            float respawnDelay; //!<Time in seconds when a player will respawn after death.
    6066            std::map<PlayerInfo*, float> playerDelayTime_; //!< Stores each Player's delay time.
    6167            std::map<PlayerInfo*, bool> inGame_; //!< Indicates each Player's state.
    62             bool bNoPunishment; //!< Config value to switch off Punishment function if it is set to true.
    63             bool bHardPunishment; //!< Switches between damage and death as punishment.
    64             float punishDamageRate; //!< Makes Damage adjustable.
     68
     69            bool bMinTeamsReached; //!< Lock. Game shouldn't end right at the beginning.
     70
    6571            virtual void spawnDeadPlayersIfRequested(); //!< Prevents dead players to respawn.
    6672            virtual int getMinLives(); //!< Returns minimum of each player's lives; players with 0 lives are skipped;
    67             int * eachTeamsPlayers; //!<Each teams player's alive.
    68             bool bMinPlayersReached;
    6973
    7074        public:
    7175            LastTeamStanding(BaseObject* creator); //!< Default Constructor.
    7276            virtual ~LastTeamStanding(); //!< Default Destructor.
     77
     78            virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
     79            virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
     80
     81            virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //!< Manages each player's lost lives.
     82            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //!< If a player shoot's an opponent, his punishment countdown will be resetted.
     83            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn); //!< Resets punishment time and respawn delay.
     84            void tick (float dt); //!< used to end the game
     85            virtual void end(); //!< Sends an end message.
     86            void punishPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
     87            int playerGetLives(PlayerInfo* player); //!< getFunction for the map "playerLives_".
     88            inline int getNumTeamsAlive() const//!< Returns the number of players that are still alive.
     89            {return this->teamsAlive;}
    7390            void setConfigValues(); //!< Makes values configurable.
    7491
    75             virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //!< If a player shoot's an opponent, his punishment countdown will be resetted.
    76             virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //!< Manages each players lives.
    77 
    78             virtual void end(); //!< Sends an end message.
    79             int playerGetLives(PlayerInfo* player); //!< getFunction for the map "playerLives_".
    80             int getNumTeamsAlive() const; //!< Returns the number of players that are still alive.
    81             virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
    82             virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
    83             virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn); //!< Resets punishment time and respawn delay.
    84 
    85             void punishPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
    86             void tick (float dt); //!< used to end the game
    8792    };
    8893}
Note: See TracChangeset for help on using the changeset viewer.