[Orxonox-commit 3484] r8170 - code/branches/lastmanstanding3/src/orxonox/gametypes
jo at orxonox.net
jo at orxonox.net
Sun Apr 3 13:01:28 CEST 2011
Author: jo
Date: 2011-04-03 13:01:28 +0200 (Sun, 03 Apr 2011)
New Revision: 8170
Modified:
code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.cc
code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.h
Log:
Removed lock that triggered a bug. (the game didn't end) Implemented win/loose message. Somehow the loose message isn't send though.
Modified: code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.cc
===================================================================
--- code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.cc 2011-04-03 10:52:54 UTC (rev 8169)
+++ code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.cc 2011-04-03 11:01:28 UTC (rev 8170)
@@ -46,7 +46,6 @@
this->lives = 1;//4
this->eachTeamsPlayers.resize(teams_,0);
this->teamsAlive = 0;
- this->bMinTeamsReached = false;
this->bNoPunishment = false;
this->bHardPunishment = false;
this->punishDamageRate = 0.4f;
@@ -74,12 +73,10 @@
else
playerLives_[player]=getMinLives();//new players only get minimum of lives */
- if (teamsAlive>1) // Now the game is allowed to end, since there are at least two teams.
- bMinTeamsReached = true; // since there are at least two teams, the game is allowed to end
this->timeToAct_[player] = timeRemaining;
this->playerDelayTime_[player] = respawnDelay;
this->inGame_[player] = true;
- int team = getTeam(player);
+ unsigned int team = getTeam(player);
if( team < 0|| team > teams_) // make sure getTeam returns a regular value
return;
if(this->eachTeamsPlayers[team]==0) //if a player is the first in his group, a new team is alive
@@ -96,7 +93,7 @@
this->timeToAct_.erase(player);
this->playerDelayTime_.erase(player);
this->inGame_.erase(player);
- int team = getTeam(player);
+ unsigned int team = getTeam(player);
if( team < 0|| team > teams_) // make sure getTeam returns a regular value
return valid_player;
this->eachTeamsPlayers[team]--; // a player left the team
@@ -118,7 +115,7 @@
this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately
if (playerLives_[victim->getPlayer()]<=0) //if player lost all lives
{
- int team = getTeam(victim->getPlayer());
+ unsigned int team = getTeam(victim->getPlayer());
if(team < 0|| team > teams_) // make sure getTeam returns a regular value
return allow;
this->eachTeamsPlayers[team]--;
@@ -188,7 +185,7 @@
SUPER(LastTeamStanding, tick, dt);
if(this->hasStarted()&&(!this->hasEnded()))
{
- if (bMinTeamsReached &&(this->hasStarted()&&(teamsAlive<=1)))//last team remaining -> game will end
+ if ( this->hasStarted()&&(teamsAlive<=1) )//last team remaining -> game will end
{
this->end();
}
@@ -235,18 +232,35 @@
void LastTeamStanding::end()//TODO: Send the message to the whole team
{
Gametype::end();
-
+ int party = -1;
+ //find a player who survived
for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
{
if (it->first->getClientID() == CLIENTID_UNKNOWN)
continue;
if (it->second > 0)
- this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
- else
- this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+ {
+ //which party has survived?
+ std::map<PlayerInfo*, int>::iterator it2 = this->teamnumbers_.find(it->first);
+ if (it2 != this->teamnumbers_.end())
+ {
+ party = it2->second;
+ }
+ //if (party < 0) return; //if search failed
+ //victory message to all team members
+ for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
+ {
+ if (it3->first->getClientID() == CLIENTID_UNKNOWN)
+ continue;
+ if (it3->second == party)
+ this->gtinfo_->sendAnnounceMessage("You have won the match!", it3->first->getClientID());
+ else
+ this->gtinfo_->sendAnnounceMessage("You have lost the match!", it3->first->getClientID());
+ }
+ return;
+ }
}
-
}
Modified: code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.h
===================================================================
--- code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.h 2011-04-03 10:52:54 UTC (rev 8169)
+++ code/branches/lastmanstanding3/src/orxonox/gametypes/LastTeamStanding.h 2011-04-03 11:01:28 UTC (rev 8170)
@@ -66,8 +66,6 @@
std::map<PlayerInfo*, float> playerDelayTime_; //!< Stores each Player's delay time.
std::map<PlayerInfo*, bool> inGame_; //!< Indicates each Player's state.
- bool bMinTeamsReached; //!< Lock. Game shouldn't end right at the beginning.
-
virtual void spawnDeadPlayersIfRequested(); //!< Prevents dead players to respawn.
virtual int getMinLives(); //!< Returns minimum of each player's lives; players with 0 lives are skipped;
More information about the Orxonox-commit
mailing list