Add auto end network game (implicitly on for ranked server)
This commit is contained in:
parent
53156a3a07
commit
785aaf7647
@ -599,6 +599,8 @@ void cmdLineHelp()
|
||||
" --auto-connect Automatically connect to fist server and start race\n"
|
||||
" --max-players=n Maximum number of clients (server only).\n"
|
||||
" --motd Message showing in all lobby of clients, can specify a .txt file.\n"
|
||||
" --auto-end Automatically end network game after 1st player finished\n"
|
||||
" for some time (currently his finished time * 1.25 + 15.0). \n"
|
||||
" --no-validation Allow non validated and unencrypted connection in wan.\n"
|
||||
" --ranked Server will submit ranking to stk addons server.\n"
|
||||
" You require permission for that.\n"
|
||||
@ -1088,6 +1090,11 @@ int handleCmdLine()
|
||||
NetworkConfig::get()->setValidatedPlayers(true);
|
||||
NetworkConfig::get()->setRankedServer(true);
|
||||
NetworkConfig::get()->setOwnerLess(true);
|
||||
NetworkConfig::get()->setAutoEnd(true);
|
||||
}
|
||||
if (CommandLine::has("--auto-end"))
|
||||
{
|
||||
NetworkConfig::get()->setAutoEnd(true);
|
||||
}
|
||||
if (CommandLine::has("--owner-less"))
|
||||
{
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "graphics/material.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "race/history.hpp"
|
||||
#include "states_screens/race_gui_base.hpp"
|
||||
#include "tracks/drive_graph.hpp"
|
||||
@ -92,6 +93,7 @@ LinearWorld::~LinearWorld()
|
||||
void LinearWorld::reset()
|
||||
{
|
||||
WorldWithRank::reset();
|
||||
m_finish_timeout = std::numeric_limits<float>::max();
|
||||
m_last_lap_sfx_played = false;
|
||||
m_last_lap_sfx_playing = false;
|
||||
m_fastest_lap_ticks = INT_MAX;
|
||||
@ -157,6 +159,16 @@ void LinearWorld::reset()
|
||||
*/
|
||||
void LinearWorld::update(int ticks)
|
||||
{
|
||||
if (getPhase() == RACE_PHASE &&
|
||||
m_finish_timeout != std::numeric_limits<float>::max())
|
||||
{
|
||||
m_finish_timeout -= stk_config->ticks2Time(ticks);
|
||||
if (m_finish_timeout < 0.0f)
|
||||
{
|
||||
endRaceEarly();
|
||||
m_finish_timeout = std::numeric_limits<float>::max();
|
||||
}
|
||||
}
|
||||
const unsigned int kart_amount = getNumKarts();
|
||||
|
||||
// Do stuff specific to this subtype of race.
|
||||
@ -439,6 +451,13 @@ void LinearWorld::newLap(unsigned int kart_index)
|
||||
|
||||
float prev_time = kart->getRecentPreviousXYZTime();
|
||||
float finish_time = prev_time*finish_proportion + getTime()*(1.0f-finish_proportion);
|
||||
|
||||
if (NetworkConfig::get()->isServer() &&
|
||||
NetworkConfig::get()->isAutoEnd() &&
|
||||
m_finish_timeout == std::numeric_limits<float>::max())
|
||||
{
|
||||
m_finish_timeout = finish_time * 1.25f + 15.0f;
|
||||
}
|
||||
kart->finishedRace(finish_time);
|
||||
}
|
||||
}
|
||||
|
@ -58,12 +58,14 @@ private:
|
||||
/** This stores the live time difference between a ghost kart
|
||||
* and a second kart racing against it (normal or ghost).
|
||||
*/
|
||||
|
||||
float m_live_time_difference;
|
||||
|
||||
/** True if the live_time_difference is invalid */
|
||||
bool m_valid_reference_time;
|
||||
|
||||
/* if set then the game will auto end after this time for networking */
|
||||
float m_finish_timeout;
|
||||
|
||||
/** This calculate the time difference between the second kart in the race
|
||||
* (there must be at least two) and the first kart in the race
|
||||
* (who must be a ghost).
|
||||
|
@ -51,6 +51,7 @@ NetworkConfig::NetworkConfig()
|
||||
m_is_public_server = false;
|
||||
m_is_ranked_server = false;
|
||||
m_validated_players = false;
|
||||
m_auto_end = false;
|
||||
m_owner_less = false;
|
||||
m_done_adding_network_players = false;
|
||||
m_max_players = 4;
|
||||
|
@ -70,6 +70,9 @@ private:
|
||||
/** True if this is a ranked server */
|
||||
bool m_is_ranked_server;
|
||||
|
||||
/* True if automatically end after 1st player finished for some time. */
|
||||
bool m_auto_end;
|
||||
|
||||
/** The password for a server (or to authenticate to a server). */
|
||||
std::string m_password;
|
||||
|
||||
@ -317,6 +320,10 @@ public:
|
||||
void setOwnerLess(bool val) { m_owner_less = val; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isOwnerLess() const { return m_owner_less; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setAutoEnd(bool val) { m_auto_end = val; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isAutoEnd() const { return m_auto_end; }
|
||||
|
||||
}; // class NetworkConfig
|
||||
|
||||
|
@ -811,6 +811,8 @@ void ServerLobby::checkRaceFinished()
|
||||
assert(World::getWorld());
|
||||
if (!RaceEventManager::getInstance()->isRaceOver()) return;
|
||||
|
||||
Log::info("ServerLobby", "The game is considered finish.");
|
||||
|
||||
// Reset for next state usage
|
||||
resetPeersReady();
|
||||
NetworkString* total = getNetworkString();
|
||||
|
@ -33,15 +33,6 @@ void RaceEventManager::update(int ticks)
|
||||
&ticks);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
World::getWorld()->updateWorld(ticks);
|
||||
|
||||
// if the race is over
|
||||
if (World::getWorld()->getPhase() >= WorldStatus::RESULT_DISPLAY_PHASE &&
|
||||
World::getWorld()->getPhase() != WorldStatus::IN_GAME_MENU_PHASE)
|
||||
{
|
||||
// consider the world finished.
|
||||
stop();
|
||||
Log::info("RaceEventManager", "The game is considered finish.");
|
||||
}
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user