Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9339 for code


Ignore:
Timestamp:
Jul 30, 2012, 10:41:03 PM (12 years ago)
Author:
jo
Message:

Found reason why players are not always detected correctly: numberOfPlayers only count players that have been added before the gametype started.

Location:
code/branches/presentation2012merge/src/orxonox/gametypes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc

    r9338 r9339  
    276276            else if (friendlyfire && (source == target))
    277277            {
    278                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
    279                 if (it != this->players_.end())
    280                     {
    281                         it->second.frags_--;
    282                     }
    283             }
    284         }// from far far away not to be removed!
     278                    this->playerScored(originator->getPlayer(), -1);
     279            }
     280        }
    285281        return false; //default: no damage
    286282    }
     
    296292            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
    297293            {
    298                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
    299                 if (it != this->players_.end())
    300                 {
    301                     it->second.frags_+=20; //value must be tested
    302                 }
    303             }
    304         return true;
     294                    this->playerScored(originator->getPlayer(), 25);
     295            }
     296            return true;
    305297        }
    306298        else return false;
     
    342334        numberOf[chaser]++;
    343335        Gametype::playerEntered(player);
     336        orxout() << "# Players(2) : " << this->getNumberOfPlayers() <<endl;
     337        orxout() << "# Players(3): " << this->getPlayerCount() <<endl;
    344338        const std::string& message = player->getName() + " entered the game";
    345339        ChatManager::message(message);
     
    361355            //remove player from map
    362356            playerParty_.erase (player);
     357            orxout() << "# Players(2) : " << this->getNumberOfPlayers() <<endl;
     358            orxout() << "# Players(3): " << this->getPlayerCount() <<endl;
    363359            //adjust player parties
    364360            evaluatePlayerParties();
     
    375371        if (this->hasStarted() && !gameEnded_)
    376372        {
    377 orxout() << " number of chasers:  " << numberOf[chaser] << endl;
    378 orxout() << " number of killers:  " << numberOf[killer] << endl;
    379 orxout() << " number of victims:  " << numberOf[piggy] << endl;
    380373            pointsPerTime = pointsPerTime + dt; //increase points
    381374            gameTime_ = gameTime_ - dt; // decrease game time
     
    419412        for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden
    420413        {
    421             if (it->second==piggy)
    422             {
    423                  //Spieler mit der Pig-party frags++
    424                  std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);
    425                  if (it2 != this->players_.end())
    426                  {
    427                      it2->second.frags_++;
    428                  }
     414            if (it->second==piggy)//Spieler mit der Pig-party frags++
     415            {
     416                 this->playerScored(it->first);
    429417            }
    430418        }
     
    502490        }
    503491        //killers: every 4th player is a killer
    504         if (getPlayerCount()/4 > numberOf[killer])
     492        if (getPlayerCount()/4 > (int)numberOf[killer])
    505493        {
    506494            notEnoughKillers=true;
  • code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.cc

    r9261 r9339  
    183183        this->players_[player].state_ = PlayerState::Joined;
    184184        this->gtinfo_->playerEntered(player);
     185        orxout() << "# Players: " << this->getNumberOfPlayers() <<endl;
    185186    }
    186187
     
    191192        {
    192193            this->players_.erase(it);
     194            orxout() << "# Players: " << this->getNumberOfPlayers() <<endl;
    193195            return true;
    194196        }
     
    301303    }
    302304
    303     void Gametype::playerScored(PlayerInfo* player)
     305    void Gametype::playerScored(PlayerInfo* player, int score)
    304306    {
    305307        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
    306308        if (it != this->players_.end())
    307             it->second.frags_++;
     309            it->second.frags_ += score;
    308310    }
    309311
  • code/branches/presentation2012merge/src/orxonox/gametypes/Gametype.h

    r9260 r9339  
    9090            virtual bool playerChangedName(PlayerInfo* player);
    9191
    92             virtual void playerScored(PlayerInfo* player);
     92            virtual void playerScored(PlayerInfo* player, int score = 1);
    9393
    9494            virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
     
    153153            virtual void resetTimer(float t);
    154154
     155            /**
     156            @brief Get number of Players.
     157            Note that only those players are counted that were added before the game started.
     158            */
    155159            inline unsigned int getNumberOfPlayers() const
    156160                { return this->gtinfo_->getNumberOfPlayers(); }
Note: See TracChangeset for help on using the changeset viewer.