Add country code and handicap to scorer data
This commit is contained in:
@@ -587,7 +587,7 @@
|
||||
-->
|
||||
<network-capabilities>
|
||||
<capabilities name="report_player"/>
|
||||
<capabilities name="color_emoji"/>
|
||||
<capabilities name="soccer_fixes"/>
|
||||
<capabilities name="ranking_changes"/>
|
||||
</network-capabilities>
|
||||
</config>
|
||||
|
||||
@@ -36,7 +36,7 @@ Controller::Controller(AbstractKart *kart)
|
||||
} // Controller
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
core::stringw Controller::getName() const
|
||||
core::stringw Controller::getName(bool include_handicap_string) const
|
||||
{
|
||||
return m_kart->getName();
|
||||
} // getName
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
/** Display name of the controller.
|
||||
* Defaults to kart name; overriden by controller classes
|
||||
* (such as player controllers) to display username. */
|
||||
virtual core::stringw getName() const;
|
||||
virtual core::stringw getName(bool include_handicap_string = true) const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the kart controlled by this controller. */
|
||||
AbstractKart *getKart() const { return m_kart; }
|
||||
|
||||
@@ -113,7 +113,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the previous controller (which has the right
|
||||
* player name associated). */
|
||||
core::stringw getName() const { return m_previous_controller->getName(); }
|
||||
core::stringw getName(bool include_handicap_string = true) const
|
||||
{ return m_previous_controller->getName(include_handicap_string); }
|
||||
|
||||
}; // EndKart
|
||||
|
||||
|
||||
@@ -90,9 +90,10 @@ public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Return the display name; if not set, use default display name (kart name) */
|
||||
core::stringw getName() const OVERRIDE
|
||||
core::stringw getName(bool include_handicap_string = true) const OVERRIDE
|
||||
{
|
||||
return m_display_name.empty() ? Controller::getName() : m_display_name;
|
||||
return m_display_name.empty() ?
|
||||
Controller::getName(include_handicap_string) : m_display_name;
|
||||
}
|
||||
}; // GhostController
|
||||
|
||||
|
||||
@@ -427,13 +427,13 @@ bool LocalPlayerController::canGetAchievements() const
|
||||
} // canGetAchievements
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
core::stringw LocalPlayerController::getName() const
|
||||
core::stringw LocalPlayerController::getName(bool include_handicap_string) const
|
||||
{
|
||||
if (NetworkConfig::get()->isNetworking())
|
||||
return PlayerController::getName();
|
||||
|
||||
core::stringw name = m_player->getProfile()->getName();
|
||||
if (m_handicap != HANDICAP_NONE)
|
||||
if (include_handicap_string && m_handicap != HANDICAP_NONE)
|
||||
name = _("%s (handicapped)", name);
|
||||
|
||||
return name;
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
virtual bool isLocalPlayerController() const OVERRIDE {return true;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the player profile. */
|
||||
core::stringw getName() const OVERRIDE;
|
||||
core::stringw getName(bool include_handicap_string = true) const OVERRIDE;
|
||||
|
||||
}; // LocalPlayerController
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ void PlayerController::rewindTo(BareNetworkString *buffer)
|
||||
} // rewindTo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
core::stringw PlayerController::getName() const
|
||||
core::stringw PlayerController::getName(bool include_handicap_string) const
|
||||
{
|
||||
core::stringw name = m_kart->getName();
|
||||
if (NetworkConfig::get()->isNetworking())
|
||||
@@ -405,7 +405,7 @@ core::stringw PlayerController::getName() const
|
||||
const RemoteKartInfo& rki = race_manager->getKartInfo(
|
||||
m_kart->getWorldKartId());
|
||||
name = rki.getPlayerName();
|
||||
if (rki.getHandicap() == HANDICAP_MEDIUM)
|
||||
if (include_handicap_string && rki.getHandicap() == HANDICAP_MEDIUM)
|
||||
{
|
||||
#ifdef SERVER_ONLY
|
||||
name += L" (handicapped)";
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
} // finishedRace
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the player profile. */
|
||||
core::stringw getName() const OVERRIDE;
|
||||
core::stringw getName(bool include_handicap_string = true) const OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called when this kart started too early and got a start penalty. */
|
||||
virtual void displayPenaltyWarning();
|
||||
|
||||
@@ -276,11 +276,13 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
|
||||
sd.m_id = m_ball_hitter;
|
||||
sd.m_correct_goal = isCorrectGoal(m_ball_hitter, first_goal);
|
||||
sd.m_kart = getKart(m_ball_hitter)->getIdent();
|
||||
sd.m_player = getKart(m_ball_hitter)->getController()->getName();
|
||||
sd.m_player = getKart(m_ball_hitter)->getController()
|
||||
->getName(false/*include_handicap_string*/);
|
||||
sd.m_handicap_level = getKart(m_ball_hitter)->getHandicap();
|
||||
if (race_manager->getKartGlobalPlayerId(m_ball_hitter) > -1)
|
||||
{
|
||||
sd.m_country_flag = StringUtils::getCountryFlag(
|
||||
race_manager->getKartInfo(m_ball_hitter).getCountryCode());
|
||||
sd.m_country_code =
|
||||
race_manager->getKartInfo(m_ball_hitter).getCountryCode();
|
||||
}
|
||||
if (sd.m_correct_goal)
|
||||
{
|
||||
@@ -325,25 +327,20 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
|
||||
.addUInt8((uint8_t)sd.m_id).addUInt8(sd.m_correct_goal)
|
||||
.addUInt8(first_goal).addFloat(sd.m_time)
|
||||
.addTime(m_ticks_back_to_own_goal)
|
||||
.encodeString(sd.m_kart);
|
||||
core::stringw player_name = sd.m_player;
|
||||
NetworkString p_with_flag = p;
|
||||
p.encodeString(player_name);
|
||||
if (!sd.m_country_flag.empty())
|
||||
{
|
||||
player_name += L" ";
|
||||
player_name += sd.m_country_flag;
|
||||
}
|
||||
p_with_flag.encodeString(player_name);
|
||||
.encodeString(sd.m_kart).encodeString(sd.m_player);
|
||||
// Added in 1.1, add missing handicap info and country code
|
||||
NetworkString p_1_1 = p;
|
||||
p_1_1.encodeString(sd.m_country_code)
|
||||
.addUInt8(sd.m_handicap_level);
|
||||
auto peers = STKHost::get()->getPeers();
|
||||
for (auto& peer : peers)
|
||||
{
|
||||
if (peer->isValidated() && !peer->isWaitingForGame())
|
||||
{
|
||||
if (peer->getClientCapabilities().find("color_emoji") !=
|
||||
if (peer->getClientCapabilities().find("soccer_fixes") !=
|
||||
peer->getClientCapabilities().end())
|
||||
{
|
||||
peer->sendPacket(&p_with_flag, true/*reliable*/);
|
||||
peer->sendPacket(&p_1_1, true/*reliable*/);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -388,6 +385,13 @@ void SoccerWorld::handlePlayerGoalFromServer(const NetworkString& ns)
|
||||
int ticks_back_to_own_goal = ns.getTime();
|
||||
ns.decodeString(&sd.m_kart);
|
||||
ns.decodeStringW(&sd.m_player);
|
||||
// Added in 1.1, add missing handicap info and country code
|
||||
if (NetworkConfig::get()->getServerCapabilities().find("soccer_fixes")
|
||||
!= NetworkConfig::get()->getServerCapabilities().end())
|
||||
{
|
||||
ns.decodeString(&sd.m_country_code);
|
||||
sd.m_handicap_level = (HandicapLevel)ns.getUInt8();
|
||||
}
|
||||
|
||||
if (first_goal)
|
||||
{
|
||||
@@ -778,15 +782,14 @@ void SoccerWorld::saveCompleteState(BareNetworkString* bns, STKPeer* peer)
|
||||
bns->addUInt8((uint8_t)m_red_scorers[i].m_id)
|
||||
.addUInt8(m_red_scorers[i].m_correct_goal)
|
||||
.addFloat(m_red_scorers[i].m_time)
|
||||
.encodeString(m_red_scorers[i].m_kart);
|
||||
core::stringw player_name = m_red_scorers[i].m_player;
|
||||
if (peer->getClientCapabilities().find("color_emoji") !=
|
||||
.encodeString(m_red_scorers[i].m_kart)
|
||||
.encodeString(m_red_scorers[i].m_player);
|
||||
if (peer->getClientCapabilities().find("soccer_fixes") !=
|
||||
peer->getClientCapabilities().end())
|
||||
{
|
||||
player_name += L" ";
|
||||
player_name += m_red_scorers[i].m_country_flag;
|
||||
bns->encodeString(m_red_scorers[i].m_country_code)
|
||||
.addUInt8(m_red_scorers[i].m_handicap_level);
|
||||
}
|
||||
bns->encodeString(player_name);
|
||||
}
|
||||
|
||||
const unsigned blue_scorers = (unsigned)m_blue_scorers.size();
|
||||
@@ -796,15 +799,14 @@ void SoccerWorld::saveCompleteState(BareNetworkString* bns, STKPeer* peer)
|
||||
bns->addUInt8((uint8_t)m_blue_scorers[i].m_id)
|
||||
.addUInt8(m_blue_scorers[i].m_correct_goal)
|
||||
.addFloat(m_blue_scorers[i].m_time)
|
||||
.encodeString(m_blue_scorers[i].m_kart);
|
||||
core::stringw player_name = m_blue_scorers[i].m_player;
|
||||
if (peer->getClientCapabilities().find("color_emoji") !=
|
||||
.encodeString(m_blue_scorers[i].m_kart)
|
||||
.encodeString(m_blue_scorers[i].m_player);
|
||||
if (peer->getClientCapabilities().find("soccer_fixes") !=
|
||||
peer->getClientCapabilities().end())
|
||||
{
|
||||
player_name += L" ";
|
||||
player_name += m_blue_scorers[i].m_country_flag;
|
||||
bns->encodeString(m_blue_scorers[i].m_country_code)
|
||||
.addUInt8(m_blue_scorers[i].m_handicap_level);
|
||||
}
|
||||
bns->encodeString(player_name);
|
||||
}
|
||||
bns->addTime(m_reset_ball_ticks).addTime(m_ticks_back_to_own_goal);
|
||||
} // saveCompleteState
|
||||
@@ -824,6 +826,12 @@ void SoccerWorld::restoreCompleteState(const BareNetworkString& b)
|
||||
sd.m_time = b.getFloat();
|
||||
b.decodeString(&sd.m_kart);
|
||||
b.decodeStringW(&sd.m_player);
|
||||
if (NetworkConfig::get()->getServerCapabilities().find("soccer_fixes")
|
||||
!= NetworkConfig::get()->getServerCapabilities().end())
|
||||
{
|
||||
b.decodeString(&sd.m_country_code);
|
||||
sd.m_handicap_level = (HandicapLevel)b.getUInt8();
|
||||
}
|
||||
m_red_scorers.push_back(sd);
|
||||
}
|
||||
|
||||
@@ -836,6 +844,12 @@ void SoccerWorld::restoreCompleteState(const BareNetworkString& b)
|
||||
sd.m_time = b.getFloat();
|
||||
b.decodeString(&sd.m_kart);
|
||||
b.decodeStringW(&sd.m_player);
|
||||
if (NetworkConfig::get()->getServerCapabilities().find("soccer_fixes")
|
||||
!= NetworkConfig::get()->getServerCapabilities().end())
|
||||
{
|
||||
b.decodeString(&sd.m_country_code);
|
||||
sd.m_handicap_level = (HandicapLevel)b.getUInt8();
|
||||
}
|
||||
m_blue_scorers.push_back(sd);
|
||||
}
|
||||
m_reset_ball_ticks = b.getTime();
|
||||
|
||||
@@ -53,8 +53,10 @@ public:
|
||||
std::string m_kart;
|
||||
/** Player name which scores. */
|
||||
core::stringw m_player;
|
||||
/** Country flag of player (used in server only). */
|
||||
core::stringw m_country_flag;
|
||||
/** Country code of player. */
|
||||
std::string m_country_code;
|
||||
/** Handicap of player. */
|
||||
HandicapLevel m_handicap_level;
|
||||
}; // ScorerData
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user