Changeset 7605 for code/branches/lastmanstanding/src/orxonox
- Timestamp:
- Nov 2, 2010, 10:34:07 PM (14 years ago)
- Location:
- code/branches/lastmanstanding/src/orxonox/gametypes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/lastmanstanding/src/orxonox/gametypes/LastManStanding.cc
r7602 r7605 35 35 #include "core/ConfigValueIncludes.h" 36 36 #include "util/Convert.h" 37 //TODO: respawn delay 37 38 38 namespace orxonox 39 39 { … … 48 48 this->timeRemaining=15.0f; 49 49 this->respawnDelay=4.0f; 50 this->noPunishment=false; 51 this->hardPunishment=false; 52 this->punishDamageRate=0.4f; 50 53 this->setHUDTemplate("LastmanstandingHUD"); 51 54 } … … 84 87 SetConfigValue(timeRemaining, 15.0f); 85 88 SetConfigValue(respawnDelay, 4.0f); 89 SetConfigValue(noPunishment, false); 90 SetConfigValue(hardPunishment, false); 86 91 } 87 92 … … 91 96 { 92 97 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 } 93 107 } 94 108 return true; … … 111 125 } 112 126 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 113 140 void LastManStanding::end() 114 141 { … … 127 154 } 128 155 156 129 157 void LastManStanding::playerEntered(PlayerInfo* player) 130 158 { … … 132 160 return; 133 161 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 136 166 this->playersAlive++; 137 167 this->timeToAct_[player]=timeRemaining; … … 154 184 { 155 185 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); 157 189 //Update: EachPlayer's "Players in Game"-HUD 158 190 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) … … 207 239 } 208 240 209 void LastManStanding:: killPlayer(PlayerInfo* player)241 void LastManStanding::punishPlayer(PlayerInfo* player) 210 242 { 211 243 if(!player) 244 return; 245 if(noPunishment) 212 246 return; 213 247 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); … … 215 249 { 216 250 if(!player->getControllableEntity()) 217 {return;}251 return; 218 252 Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity()); 219 253 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 226 269 void LastManStanding::tick(float dt) 227 270 { … … 231 274 if ((this->hasStarted()&&(playersAlive<=1)))//last player remaining 232 275 { 233 this->end();276 this->end(); 234 277 } 235 278 for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it) … … 243 286 if (playerDelayTime_[it->first]<=0) 244 287 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()); 245 294 } 246 295 else if (it->second<0.0f) … … 248 297 it->second=timeRemaining+3.0f;//reset punishment-timer 249 298 if (playerGetLives(it->first)>0) 250 this-> killPlayer(it->first);251 } 252 else if (it->second<timeRemaining/ 6)//Warning message299 this->punishPlayer(it->first); 300 } 301 else if (it->second<timeRemaining/5)//Warning message 253 302 { 254 303 if (it->first->getClientID()== CLIENTID_UNKNOWN) -
code/branches/lastmanstanding/src/orxonox/gametypes/LastManStanding.h
r7596 r7605 58 58 std::map<PlayerInfo*, float> playerDelayTime_; //!< Stores each Player's delay time. 59 59 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; 61 65 62 66 public: … … 75 79 76 80 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". 78 82 void tick (float dt); //!< used to end the game 79 83 };
Note: See TracChangeset
for help on using the changeset viewer.