void Server::sendChatMessage(ChatMessage &msg) { // check if sender is a player name DOPE_ASSERT(msg.sender.size()); DOPE_ASSERT(!msg.global); const std::vector<std::string> &pn(m_game.getPlayerNames()); PlayerID pid=m_game.getPlayerID(msg.sender); TeamID tid=~0U; if (pid<pn.size()) { // yes => find team of player tid=m_game.getTeamIDofPlayer(pid); DOPE_ASSERT(tid!=~0U); }else{ // no => check if sender is a team name tid=m_game.getTeamID(msg.sender); } DOPE_ASSERT(tid!=TeamID(~0U)); // now we have the team id we want to send messages to // => send message to every client which has a member of this team Connections::iterator it(connections.begin()); while (it!=connections.end()) { const std::vector<PlayerID> &pids(it->second->getPlayerIDs()); for (unsigned p=0;p<pids.size();++p) { if (m_game.getTeamIDofPlayer(pids[p])==tid) { it->second->emit(msg); break; } } ++it; } }
bool CGameTeamMaster::TeamMatch( const CBaseEntity* const pActivator ) const { if( m_teamIndex < 0 && AnyTeam() ) return true; if( !pActivator ) return false; return UTIL_TeamsMatch( pActivator->TeamID(), TeamID() ); }
BOOL CGameTeamMaster::TeamMatch(CBaseEntity *pActivator) { if (m_teamIndex < 0 && AnyTeam()) return TRUE; if (!pActivator) return FALSE; return UTIL_TeamsMatch(pActivator->TeamID(), TeamID()); }
std::vector<TeamID> Server::getTeamIDs(const Connection *c) const { DOPE_ASSERT(c); std::vector<TeamID> res; const std::vector<PlayerID> &pids(c->getPlayerIDs()); for (unsigned p=0;p<pids.size();++p) { TeamID tid=m_game.getTeamIDofPlayer(pids[p]); DOPE_ASSERT(tid!=TeamID(~0U)); if (std::find(res.begin(),res.end(),tid)==res.end()) res.push_back(tid); } return res; }
#define INSTANTIATE_BASE_FOR_ID_HERE #include "StdInc.h" #include "VCMI_Lib.h" #include "mapObjects/CObjectClassesHandler.h" #include "CArtHandler.h" #include "CCreatureHandler.h" #include "spells/CSpellHandler.h" const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2); const PlayerColor PlayerColor::CANNOT_DETERMINE = PlayerColor(253); const PlayerColor PlayerColor::UNFLAGGABLE = PlayerColor(254); const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255); const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I); const TeamID TeamID::NO_TEAM = TeamID(255); #define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \ bool operator==(const A & a, const B & b) \ { \ return AN == BN ; \ } \ bool operator!=(const A & a, const B & b) \ { \ return AN != BN ; \ } \ bool operator<(const A & a, const B & b) \ { \ return AN < BN ; \ } \ bool operator<=(const A & a, const B & b) \
void CMapGenerator::addPlayerInfo() { // Calculate which team numbers exist enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2}; std::array<std::list<int>, 2> teamNumbers; int teamOffset = 0; int playerCount = 0; int teamCount = 0; for (int i = CPHUMAN; i < AFTER_LAST; ++i) { if (i == CPHUMAN) { playerCount = mapGenOptions->getPlayerCount(); teamCount = mapGenOptions->getTeamCount(); } else { playerCount = mapGenOptions->getCompOnlyPlayerCount(); teamCount = mapGenOptions->getCompOnlyTeamCount(); } if(playerCount == 0) { continue; } int playersPerTeam = playerCount / (teamCount == 0 ? playerCount : teamCount); int teamCountNorm = teamCount; if(teamCountNorm == 0) { teamCountNorm = playerCount; } for(int j = 0; j < teamCountNorm; ++j) { for(int k = 0; k < playersPerTeam; ++k) { teamNumbers[i].push_back(j + teamOffset); } } for(int j = 0; j < playerCount - teamCountNorm * playersPerTeam; ++j) { teamNumbers[i].push_back(j + teamOffset); } teamOffset += teamCountNorm; } // Team numbers are assigned randomly to every player //TODO: allow customize teams in rmg template for(const auto & pair : mapGenOptions->getPlayersSettings()) { const auto & pSettings = pair.second; PlayerInfo player; player.canComputerPlay = true; int j = (pSettings.getPlayerType() == EPlayerType::COMP_ONLY) ? CPUONLY : CPHUMAN; if (j == CPHUMAN) { player.canHumanPlay = true; } if (teamNumbers[j].empty()) { logGlobal->errorStream() << boost::format("Not enough places in team for %s player") % ((j == CPUONLY) ? "CPU" : "CPU or human"); assert (teamNumbers[j].size()); } auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand); player.team = TeamID(*itTeam); teamNumbers[j].erase(itTeam); map->players[pSettings.getColor().getNum()] = player; } map->howManyTeams = (mapGenOptions->getTeamCount() == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getTeamCount()) + (mapGenOptions->getCompOnlyTeamCount() == 0 ? mapGenOptions->getCompOnlyPlayerCount() : mapGenOptions->getCompOnlyTeamCount()); }