Make flag deactivated time configurable

This commit is contained in:
Benau 2019-03-13 15:42:59 +08:00
parent 92460d8823
commit 9cbd2abe5d
9 changed files with 59 additions and 22 deletions

View File

@ -276,7 +276,7 @@ void CaptureTheFlag::update(int ticks)
m_red_scores, new_blue_scores); m_red_scores, new_blue_scores);
} }
m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart(); m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart();
m_red_flag->resetToBase(360/*deactivated_ticks*/); m_red_flag->resetToBase(race_manager->getFlagDeactivatedTicks());
} }
else if (m_blue_flag->getHolder() != -1 && m_red_flag->isInBase() && else if (m_blue_flag->getHolder() != -1 && m_red_flag->isInBase() &&
m_red_flag->isActivated() && m_red_flag->isActivated() &&
@ -307,7 +307,7 @@ void CaptureTheFlag::update(int ticks)
new_red_scores, m_blue_scores); new_red_scores, m_blue_scores);
} }
m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart(); m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart();
m_blue_flag->resetToBase(360/*deactivated_ticks*/); m_blue_flag->resetToBase(race_manager->getFlagDeactivatedTicks());
} }
// Test if red or blue flag is touched // Test if red or blue flag is touched
@ -326,7 +326,8 @@ void CaptureTheFlag::update(int ticks)
if (!m_red_flag->isInBase()) if (!m_red_flag->isInBase())
{ {
// Return the flag // Return the flag
m_red_flag->resetToBase(360/*deactivated_ticks*/); m_red_flag->resetToBase(
race_manager->getFlagDeactivatedTicks());
} }
} }
else else
@ -345,7 +346,8 @@ void CaptureTheFlag::update(int ticks)
if (!m_blue_flag->isInBase()) if (!m_blue_flag->isInBase())
{ {
// Return the flag // Return the flag
m_blue_flag->resetToBase(360/*deactivated_ticks*/); m_blue_flag->resetToBase(
race_manager->getFlagDeactivatedTicks());
} }
} }
else else
@ -489,14 +491,20 @@ void CaptureTheFlag::loseFlagForKart(int kart_id)
if (succeed) if (succeed)
m_red_flag->dropFlagAt(dropped_trans); m_red_flag->dropFlagAt(dropped_trans);
else else
m_red_flag->resetToBase(360/*deactivated_ticks*/); {
m_red_flag->resetToBase(
race_manager->getFlagDeactivatedTicks());
}
} }
else else
{ {
if (succeed) if (succeed)
m_blue_flag->dropFlagAt(dropped_trans); m_blue_flag->dropFlagAt(dropped_trans);
else else
m_blue_flag->resetToBase(360/*deactivated_ticks*/); {
m_blue_flag->resetToBase(
race_manager->getFlagDeactivatedTicks());
}
} }
} // loseFlagForKart } // loseFlagForKart

View File

@ -115,7 +115,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
const btTransform& getBaseTrans() const { return m_flag_base_trans; } const btTransform& getBaseTrans() const { return m_flag_base_trans; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void resetToBase(uint16_t deactivated_ticks = 0) void resetToBase(unsigned deactivated_ticks = 0)
{ {
// 11 bit for deactivated_ticks saved with flag status (5 bits) // 11 bit for deactivated_ticks saved with flag status (5 bits)
if (deactivated_ticks > 2047) if (deactivated_ticks > 2047)

View File

@ -285,6 +285,8 @@ void ClientLobby::addAllPlayers(Event* event)
m_game_setup->setHitCaptureTime(hit_capture_limit, time_limit); m_game_setup->setHitCaptureTime(hit_capture_limit, time_limit);
uint16_t flag_return_timeout = data.getUInt16(); uint16_t flag_return_timeout = data.getUInt16();
race_manager->setFlagReturnTicks(flag_return_timeout); race_manager->setFlagReturnTicks(flag_return_timeout);
unsigned flag_deactivated_time = data.getUInt16();
race_manager->setFlagDeactivatedTicks(flag_deactivated_time);
} }
configRemoteKart(players, isSpectator() ? 1 : configRemoteKart(players, isSpectator() ? 1 :
(int)NetworkConfig::get()->getNetworkPlayers().size()); (int)NetworkConfig::get()->getNetworkPlayers().size());

View File

@ -596,16 +596,20 @@ void ServerLobby::asynchronousUpdate()
if (peer) if (peer)
peer->addAvailableKartID(i); peer->addAvailableKartID(i);
} }
float real_players_count = (float)players.size(); getHitCaptureLimit();
getHitCaptureLimit(real_players_count);
// Add placeholder players for live join // Add placeholder players for live join
addLiveJoinPlaceholder(players); addLiveJoinPlaceholder(players);
NetworkString* load_world_message = getLoadWorldMessage(players); NetworkString* load_world_message = getLoadWorldMessage(players);
m_game_setup->setHitCaptureTime(m_battle_hit_capture_limit,
m_battle_time_limit);
uint16_t flag_return_time = (uint16_t)stk_config->time2Ticks( uint16_t flag_return_time = (uint16_t)stk_config->time2Ticks(
ServerConfig::m_flag_return_timemout); ServerConfig::m_flag_return_timeout);
race_manager->setFlagReturnTicks(flag_return_time); race_manager->setFlagReturnTicks(flag_return_time);
uint16_t flag_deactivated_time = (uint16_t)stk_config->time2Ticks(
ServerConfig::m_flag_deactivated_time);
race_manager->setFlagDeactivatedTicks(flag_deactivated_time);
configRemoteKart(players, 0); configRemoteKart(players, 0);
// Reset for next state usage // Reset for next state usage
@ -658,11 +662,12 @@ NetworkString* ServerLobby::getLoadWorldMessage(
{ {
load_world_message->addUInt32(m_battle_hit_capture_limit) load_world_message->addUInt32(m_battle_hit_capture_limit)
.addFloat(m_battle_time_limit); .addFloat(m_battle_time_limit);
m_game_setup->setHitCaptureTime(m_battle_hit_capture_limit,
m_battle_time_limit);
uint16_t flag_return_time = (uint16_t)stk_config->time2Ticks( uint16_t flag_return_time = (uint16_t)stk_config->time2Ticks(
ServerConfig::m_flag_return_timemout); ServerConfig::m_flag_return_timeout);
load_world_message->addUInt16(flag_return_time); load_world_message->addUInt16(flag_return_time);
uint16_t flag_deactivated_time = (uint16_t)stk_config->time2Ticks(
ServerConfig::m_flag_deactivated_time);
load_world_message->addUInt16(flag_deactivated_time);
} }
return load_world_message; return load_world_message;
} // getLoadWorldMessage } // getLoadWorldMessage
@ -2726,9 +2731,8 @@ bool ServerLobby::handleAllVotes(PeerVote* winner_vote,
} // handleAllVotes } // handleAllVotes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void ServerLobby::getHitCaptureLimit(float num_karts) void ServerLobby::getHitCaptureLimit()
{ {
// Read user_config.hpp for formula
int hit_capture_limit = std::numeric_limits<int>::max(); int hit_capture_limit = std::numeric_limits<int>::max();
float time_limit = 0.0f; float time_limit = 0.0f;
if (race_manager->getMinorMode() == if (race_manager->getMinorMode() ==

View File

@ -272,7 +272,7 @@ private:
double getUncertaintySpread(uint32_t online_id); double getUncertaintySpread(uint32_t online_id);
double scalingValueForTime(double time); double scalingValueForTime(double time);
void checkRaceFinished(); void checkRaceFinished();
void getHitCaptureLimit(float num_karts); void getHitCaptureLimit();
void configPeersStartTime(); void configPeersStartTime();
void resetServer(); void resetServer();
void addWaitingPlayersToGame(); void addWaitingPlayersToGame();

View File

@ -277,14 +277,24 @@ void loadServerLobbyFromConfig()
if (unsupportedGameMode()) if (unsupportedGameMode())
Log::fatal("ServerConfig", "Unsupported game mode"); Log::fatal("ServerConfig", "Unsupported game mode");
if (stk_config->time2Ticks(m_flag_return_timemout) > 65535 || if (stk_config->time2Ticks(m_flag_return_timeout) > 65535 ||
m_flag_return_timemout <= 0.0f) m_flag_return_timeout <= 0.0f)
{ {
float timeout = m_flag_return_timemout; float timeout = m_flag_return_timeout;
// in CTFFlag it uses 16bit unsigned integer for timeout // in CTFFlag it uses 16bit unsigned integer for timeout
Log::warn("ServerConfig", "Invalid %f m_flag_return_timemout which " Log::warn("ServerConfig", "Invalid %f m_flag_return_timemout which "
"is invalid, use default value.", timeout); "is invalid, use default value.", timeout);
m_flag_return_timemout.revertToDefaults(); m_flag_return_timeout.revertToDefaults();
}
if (stk_config->time2Ticks(m_flag_deactivated_time) > 2047 ||
m_flag_deactivated_time < 0.0f)
{
float timeout = m_flag_deactivated_time;
// in CTFFlag it uses 11bit unsigned integer for timeout
Log::warn("ServerConfig", "Invalid %f m_flag_return_timemout which "
"is invalid, use default value.", timeout);
m_flag_deactivated_time.revertToDefaults();
} }
int frequency_in_config = m_state_frequency; int frequency_in_config = m_state_frequency;

View File

@ -238,11 +238,16 @@ namespace ServerConfig
"available for players to choose, and official-karts-threshold will " "available for players to choose, and official-karts-threshold will "
"be made 1.0.")); "be made 1.0."));
SERVER_CFG_PREFIX FloatServerConfigParam m_flag_return_timemout SERVER_CFG_PREFIX FloatServerConfigParam m_flag_return_timeout
SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "flag-return-timemout", SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "flag-return-timeout",
"Time in seconds when a flag is dropped a by player in CTF " "Time in seconds when a flag is dropped a by player in CTF "
"returning to its own base.")); "returning to its own base."));
SERVER_CFG_PREFIX FloatServerConfigParam m_flag_deactivated_time
SERVER_CFG_DEFAULT(FloatServerConfigParam(3.0f, "flag-deactivated-time",
"Time in seconds to deactivate a flag when it's captured or returned "
"to own base by players."));
SERVER_CFG_PREFIX IntServerConfigParam m_hit_limit SERVER_CFG_PREFIX IntServerConfigParam m_hit_limit
SERVER_CFG_DEFAULT(IntServerConfigParam(20, "hit-limit", SERVER_CFG_DEFAULT(IntServerConfigParam(20, "hit-limit",
"Hit limit of free for all, zero to disable hit limit.")); "Hit limit of free for all, zero to disable hit limit."));

View File

@ -82,6 +82,7 @@ RaceManager::RaceManager()
m_num_local_players = 0; m_num_local_players = 0;
m_hit_capture_limit = 0; m_hit_capture_limit = 0;
m_flag_return_ticks = stk_config->time2Ticks(20.0f); m_flag_return_ticks = stk_config->time2Ticks(20.0f);
m_flag_deactivated_ticks = stk_config->time2Ticks(3.0f);
setMaxGoal(0); setMaxGoal(0);
setTimeTarget(0.0f); setTimeTarget(0.0f);
setReverseTrack(false); setReverseTrack(false);

View File

@ -357,6 +357,7 @@ private:
unsigned int m_num_finished_karts; unsigned int m_num_finished_karts;
unsigned int m_num_finished_players; unsigned int m_num_finished_players;
unsigned m_flag_return_ticks; unsigned m_flag_return_ticks;
unsigned m_flag_deactivated_ticks;
int m_coin_target; int m_coin_target;
float m_time_target; float m_time_target;
int m_goal_target; int m_goal_target;
@ -902,6 +903,12 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
unsigned getFlagReturnTicks() const { return m_flag_return_ticks; } unsigned getFlagReturnTicks() const { return m_flag_return_ticks; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setFlagDeactivatedTicks(unsigned ticks)
{ m_flag_deactivated_ticks = ticks; }
// ------------------------------------------------------------------------
unsigned getFlagDeactivatedTicks() const
{ return m_flag_deactivated_ticks; }
// ------------------------------------------------------------------------
/** Whether the current game mode allow live joining even the current game /** Whether the current game mode allow live joining even the current game
*. started in network*/ *. started in network*/
bool supportsLiveJoining() const bool supportsLiveJoining() const