Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 2, 2010, 10:34:07 PM (14 years ago)
Author:
jo
Message:

Various successful changes. But the part I commented out in punishPlayer(PlayerInfo* player) causes crashes.

Location:
code/branches/lastmanstanding/src/orxonox/gametypes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/lastmanstanding/src/orxonox/gametypes/LastManStanding.cc

    r7602 r7605  
    3535#include "core/ConfigValueIncludes.h"
    3636#include "util/Convert.h"
    37 //TODO: respawn delay
     37
    3838namespace orxonox
    3939{
     
    4848        this->timeRemaining=15.0f;
    4949        this->respawnDelay=4.0f;
     50        this->noPunishment=false;
     51        this->hardPunishment=false;
     52        this->punishDamageRate=0.4f;
    5053        this->setHUDTemplate("LastmanstandingHUD");
    5154    }
     
    8487        SetConfigValue(timeRemaining, 15.0f);
    8588        SetConfigValue(respawnDelay, 4.0f);
     89        SetConfigValue(noPunishment, false);
     90        SetConfigValue(hardPunishment, false);
    8691    }
    8792
     
    9196        {
    9297            this->timeToAct_[originator->getPlayer()]=timeRemaining;
     98
     99            std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
     100            if (it != this->players_.end())
     101            {
     102                if (it->first->getClientID()== CLIENTID_UNKNOWN)
     103                    return true;
     104                const std::string& message = ""; // set blank - erases Camper-Warning-message
     105                this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
     106            }   
    93107        }
    94108        return true;
     
    111125    }
    112126
     127    int LastManStanding::getMinLives()
     128    {
     129        int min=lives;
     130        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
     131        {
     132            if (it->second<=0)
     133                continue;
     134            if (it->second<lives)
     135                min=it->second;
     136        }
     137        return min;
     138    }
     139
    113140    void LastManStanding::end()
    114141    {
     
    127154    }
    128155
     156
    129157    void LastManStanding::playerEntered(PlayerInfo* player)
    130158    {
     
    132160            return;
    133161        Deathmatch::playerEntered(player);
    134 
    135         playerLives_[player]=lives;
     162        if (playersAlive<=1)
     163            playerLives_[player]=lives;
     164        else
     165            playerLives_[player]=getMinLives();//new players only get minimum of lives
    136166        this->playersAlive++;
    137167        this->timeToAct_[player]=timeRemaining;
     
    154184        {
    155185            this->playersAlive--;
    156             //this->playerLives_[player].erase (player); not necessary?
     186            this->playerLives_.erase (player);
     187            this->playerDelayTime_.erase (player);
     188            this->inGame_.erase (player);
    157189            //Update: EachPlayer's "Players in Game"-HUD
    158190            for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     
    207239    }
    208240
    209     void LastManStanding::killPlayer(PlayerInfo* player)
     241    void LastManStanding::punishPlayer(PlayerInfo* player)
    210242    {
    211243        if(!player)
     244            return;
     245        if(noPunishment)
    212246            return;
    213247        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
     
    215249        {
    216250            if(!player->getControllableEntity())
    217                 {return;}
     251                return;
    218252            Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
    219253            if(!pawn)
    220                 {return;}
    221             pawn->kill();
    222             this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
    223         }
    224     }
    225    
     254                return;
     255            if(hardPunishment)
     256            {
     257                pawn->kill();
     258                this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
     259            }
     260            /*else
     261            {
     262                float damage=pawn->getMaxHealth()*punishDamageRate*0.5;
     263                pawn->removeHealth(damage);
     264                this->timeToAct_[player]=timeRemaining;//reset timer
     265            }*/
     266        }
     267    }
     268
    226269    void LastManStanding::tick(float dt)
    227270    {
     
    231274            if ((this->hasStarted()&&(playersAlive<=1)))//last player remaining
    232275            {
    233             this->end();
     276                this->end();
    234277            }
    235278            for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
     
    243286                    if (playerDelayTime_[it->first]<=0)
    244287                    this->inGame_[it->first]=true;
     288
     289                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
     290                        continue;
     291                    int output=1+playerDelayTime_[it->first];
     292                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
     293                    this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    245294                }
    246295                else if (it->second<0.0f)
     
    248297                    it->second=timeRemaining+3.0f;//reset punishment-timer
    249298                    if (playerGetLives(it->first)>0)
    250                         this->killPlayer(it->first);
    251                 }
    252                 else if (it->second<timeRemaining/6)//Warning message
     299                        this->punishPlayer(it->first);
     300                }
     301                else if (it->second<timeRemaining/5)//Warning message
    253302                {
    254303                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
  • code/branches/lastmanstanding/src/orxonox/gametypes/LastManStanding.h

    r7596 r7605  
    5858            std::map<PlayerInfo*, float> playerDelayTime_; //!< Stores each Player's delay time.
    5959            std::map<PlayerInfo*, bool> inGame_; //!< Indicates each Player's state.
    60             virtual void spawnDeadPlayersIfRequested(); //!< Prevents dead players to respawn
     60            bool noPunishment;
     61            bool hardPunishment;
     62            float punishDamageRate;
     63            virtual void spawnDeadPlayersIfRequested(); //!< Prevents dead players to respawn.
     64            virtual int getMinLives(); //!< Returns minimum of each player's lives; players with 0 lives are skipped;
    6165
    6266        public:
     
    7579
    7680            const int playerGetLives(PlayerInfo* player); //!< getFunction for the map "playerLives_".
    77             void killPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
     81            void punishPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
    7882            void tick (float dt); //!< used to end the game
    7983    };
Note: See TracChangeset for help on using the changeset viewer.