[Orxonox-commit 4668] r9339 - code/branches/presentation2012merge/src/orxonox/gametypes
jo at orxonox.net
jo at orxonox.net
Mon Jul 30 22:41:04 CEST 2012
Author: jo
Date: 2012-07-30 22:41:03 +0200 (Mon, 30 Jul 2012)
New Revision: 9339
Modified:
code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc
code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.cc
code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.h
Log:
Found reason why players are not always detected correctly: numberOfPlayers only count players that have been added before the gametype started.
Modified: code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc 2012-07-30 19:25:47 UTC (rev 9338)
+++ code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc 2012-07-30 20:41:03 UTC (rev 9339)
@@ -275,13 +275,9 @@
//Case: friendly fire
else if (friendlyfire && (source == target))
{
- std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
- if (it != this->players_.end())
- {
- it->second.frags_--;
- }
+ this->playerScored(originator->getPlayer(), -1);
}
- }// from far far away not to be removed!
+ }
return false; //default: no damage
}
@@ -295,13 +291,9 @@
{
if (playerParty_[originator->getPlayer()] == killer) //reward the killer
{
- std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
- if (it != this->players_.end())
- {
- it->second.frags_+=20; //value must be tested
- }
+ this->playerScored(originator->getPlayer(), 25);
}
- return true;
+ return true;
}
else return false;
}
@@ -341,6 +333,8 @@
playerParty_[player]=chaser; //Set playerparty
numberOf[chaser]++;
Gametype::playerEntered(player);
+ orxout() << "# Players(2) : " << this->getNumberOfPlayers() <<endl;
+ orxout() << "# Players(3): " << this->getPlayerCount() <<endl;
const std::string& message = player->getName() + " entered the game";
ChatManager::message(message);
}
@@ -360,6 +354,8 @@
ChatManager::message(message);
//remove player from map
playerParty_.erase (player);
+ orxout() << "# Players(2) : " << this->getNumberOfPlayers() <<endl;
+ orxout() << "# Players(3): " << this->getPlayerCount() <<endl;
//adjust player parties
evaluatePlayerParties();
}
@@ -374,9 +370,6 @@
if (this->hasStarted() && !gameEnded_)
{
-orxout() << " number of chasers: " << numberOf[chaser] << endl;
-orxout() << " number of killers: " << numberOf[killer] << endl;
-orxout() << " number of victims: " << numberOf[piggy] << endl;
pointsPerTime = pointsPerTime + dt; //increase points
gameTime_ = gameTime_ - dt; // decrease game time
if (pointsPerTime > 2.0f) //hard coded points for victim! should be changed
@@ -418,14 +411,9 @@
{
for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden
{
- if (it->second==piggy)
+ if (it->second==piggy)//Spieler mit der Pig-party frags++
{
- //Spieler mit der Pig-party frags++
- std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);
- if (it2 != this->players_.end())
- {
- it2->second.frags_++;
- }
+ this->playerScored(it->first);
}
}
}
@@ -501,7 +489,7 @@
}
}
//killers: every 4th player is a killer
- if (getPlayerCount()/4 > numberOf[killer])
+ if (getPlayerCount()/4 > (int)numberOf[killer])
{
notEnoughKillers=true;
if (tutorial) // Announce selectionphase
Modified: code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.cc 2012-07-30 19:25:47 UTC (rev 9338)
+++ code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.cc 2012-07-30 20:41:03 UTC (rev 9339)
@@ -182,6 +182,7 @@
{
this->players_[player].state_ = PlayerState::Joined;
this->gtinfo_->playerEntered(player);
+ orxout() << "# Players: " << this->getNumberOfPlayers() <<endl;
}
bool Gametype::playerLeft(PlayerInfo* player)
@@ -190,6 +191,7 @@
if (it != this->players_.end())
{
this->players_.erase(it);
+ orxout() << "# Players: " << this->getNumberOfPlayers() <<endl;
return true;
}
return false;
@@ -300,11 +302,11 @@
}
}
- void Gametype::playerScored(PlayerInfo* player)
+ void Gametype::playerScored(PlayerInfo* player, int score)
{
std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
if (it != this->players_.end())
- it->second.frags_++;
+ it->second.frags_ += score;
}
int Gametype::getScore(PlayerInfo* player) const
Modified: code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.h 2012-07-30 19:25:47 UTC (rev 9338)
+++ code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.h 2012-07-30 20:41:03 UTC (rev 9339)
@@ -89,7 +89,7 @@
virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype);
virtual bool playerChangedName(PlayerInfo* player);
- virtual void playerScored(PlayerInfo* player);
+ virtual void playerScored(PlayerInfo* player, int score = 1);
virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
@@ -152,6 +152,10 @@
virtual void resetTimer();
virtual void resetTimer(float t);
+ /**
+ @brief Get number of Players.
+ Note that only those players are counted that were added before the game started.
+ */
inline unsigned int getNumberOfPlayers() const
{ return this->gtinfo_->getNumberOfPlayers(); }
More information about the Orxonox-commit
mailing list