Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: <geoffthemedio@us...> - 2013-02-09 10:55:16
|
Revision: 5739 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=5739&view=rev Author: geoffthemedio Date: 2013-02-09 10:55:09 +0000 (Sat, 09 Feb 2013) Log Message: ----------- -Modified server-side selection of human player species and empire names when first setting up a lobby to use the same generators as subsequent AI player additions. This gives player empires default names from the stock list rather than using the player's name, and prevents a bug where a non-playable species was being used as the default, which was being rejected client-side and lead to an error message in the client log file. -More fixing of minor issue related to the previous commit about generating empire names and returning a temporary variable by reference. Modified Paths: -------------- trunk/FreeOrion/server/ServerFSM.cpp Modified: trunk/FreeOrion/server/ServerFSM.cpp =================================================================== --- trunk/FreeOrion/server/ServerFSM.cpp 2013-02-09 10:17:47 UTC (rev 5738) +++ trunk/FreeOrion/server/ServerFSM.cpp 2013-02-09 10:55:09 UTC (rev 5739) @@ -89,6 +89,53 @@ } return ""; } + + void LogPlayerSetupData(const std::list<std::pair<int, PlayerSetupData> >& psd) { + Logger().debugStream() << "PlayerSetupData:"; + for (std::list<std::pair<int, PlayerSetupData> >::const_iterator it = psd.begin(); it != psd.end(); ++it) + Logger().debugStream() << boost::lexical_cast<std::string>(it->first) << " : " + << it->second.m_player_name << ", " + << it->second.m_client_type << ", " + << it->second.m_starting_species_name; + } + + void LoadEmpireNames(std::list<std::string>& names) { + boost::filesystem::ifstream ifs(GetResourceDir() / "empire_names.txt"); + while (ifs) { + std::string latest_name; + std::getline(ifs, latest_name); + if (!latest_name.empty()) + names.push_back(latest_name.substr(0, latest_name.find_last_not_of(" \t") + 1)); // strip off trailing whitespace + } + } + + std::string GenerateEmpireName(std::list<std::pair<int, PlayerSetupData> > &players) { + // load default empire names + static std::list<std::string> empire_names; + if (empire_names.empty()) + LoadEmpireNames(empire_names); + std::set<std::string> validNames(empire_names.begin(), empire_names.end()); + for (std::list<std::pair<int, PlayerSetupData> >::iterator player_setup_it = players.begin(); player_setup_it != players.end(); player_setup_it++) { + std::set<std::string>::iterator name_it = validNames.find(player_setup_it->second.m_empire_name); + if (name_it != validNames.end()) + validNames.erase(name_it); + } + if (!validNames.empty()) { + // pick a name from the list of empire names + int empire_name_idx = RandSmallInt(0, static_cast<int>(validNames.size()) - 1); + std::set<std::string>::iterator it = validNames.begin(); + std::advance(it, empire_name_idx); + return *it; + } else { + // use a generic name + return UserString("EMPIRE"); + } + } + + std::string GenerateEmpireName() { + std::list<std::pair<int, PlayerSetupData> > empty_data; + return GenerateEmpireName(empty_data); + } } @@ -276,10 +323,9 @@ PlayerSetupData& player_setup_data = m_lobby_data->m_players.begin()->second; player_setup_data.m_player_name = player_connection->PlayerName(); - player_setup_data.m_empire_name = player_connection->PlayerName(); // default empire name to same as player name, for lack of a better choice + player_setup_data.m_empire_name = GenerateEmpireName(m_lobby_data->m_players); player_setup_data.m_empire_color = EmpireColors().at(0); // since the host is the first joined player, it can be assumed that no other player is using this colour (unlike subsequent join game message responses) - if (!sm.empty()) - player_setup_data.m_starting_species_name = sm.begin()->first; + player_setup_data.m_starting_species_name = sm.RandomPlayableSpeciesName(); // leaving save game empire id as default player_setup_data.m_client_type = player_connection->GetClientType(); @@ -421,55 +467,6 @@ return discard_event(); } -namespace { - void LogPlayerSetupData(const std::list<std::pair<int, PlayerSetupData> >& psd) { - Logger().debugStream() << "PlayerSetupData:"; - for (std::list<std::pair<int, PlayerSetupData> >::const_iterator it = psd.begin(); it != psd.end(); ++it) - Logger().debugStream() << boost::lexical_cast<std::string>(it->first) << " : " - << it->second.m_player_name << ", " - << it->second.m_client_type << ", " - << it->second.m_starting_species_name; - } - - void LoadEmpireNames(std::list<std::string>& names) { - boost::filesystem::ifstream ifs(GetResourceDir() / "empire_names.txt"); - while (ifs) { - std::string latest_name; - std::getline(ifs, latest_name); - if (!latest_name.empty()) - names.push_back(latest_name.substr(0, latest_name.find_last_not_of(" \t") + 1)); // strip off trailing whitespace - } - } - - std::string GenerateEmpireName(std::list<std::pair<int, PlayerSetupData> > &players) { - // load default empire names - static std::list<std::string> empire_names; - if (empire_names.empty()) - LoadEmpireNames(empire_names); - std::set<std::string> validNames(empire_names.begin(), empire_names.end()); - for (std::list<std::pair<int, PlayerSetupData> >::iterator player_setup_it = players.begin(); player_setup_it != players.end(); player_setup_it++) { - std::set<std::string>::iterator name_it = validNames.find(player_setup_it->second.m_empire_name); - if (name_it != validNames.end()) - validNames.erase(name_it); - } - if (!validNames.empty()) { - // pick a name from the list of empire names - int empire_name_idx = RandSmallInt(0, static_cast<int>(validNames.size()) - 1); - std::set<std::string>::iterator it = validNames.begin(); - std::advance(it, empire_name_idx); - return *it; - } else { - // use a generic name - return UserString("EMPIRE"); - } - } -} - -const std::string& GenerateEmpireName() { - std::list<std::pair<int, PlayerSetupData> > empty_data; - return GenerateEmpireName(empty_data); -} - sc::result MPLobby::react(const LobbyUpdate& msg) { if (TRACE_EXECUTION) Logger().debugStream() << "(ServerFSM) MPLobby.LobbyUpdate"; ServerApp& server = Server(); |