Allow any addon karts in online with tux hitbox in physics

Live join and spectate are now possible too
This commit is contained in:
Benau 2020-07-18 10:04:07 +08:00
parent 846b77541f
commit 32cc160630
11 changed files with 68 additions and 32 deletions

View File

@ -116,8 +116,8 @@ The current server configuration xml looks like this:
<!-- If true, the server owner can config the difficulty and game mode in the GUI of lobby. This option cannot be used with owner-less or grand prix server, and will be automatically turned on if the server was created using the in-game GUI. The changed difficulty and game mode will not be saved in this config file. -->
<server-configurable value="false" />
<!-- If true, players can live join or spectate the in-progress game. Currently live joining is only available if the current game mode used in server is FFA, CTF or soccer, also no addon karts will be available for players to choose, and official-karts-threshold will be made 1.0. -->
<live-players value="true" />
<!-- If true, players can live join or spectate the in-progress game. Currently live joining is only available if the current game mode used in server is FFA, CTF or soccer, also official-karts-threshold will be made 1.0. -->
<live-spectate value="true" />
<!-- Time in seconds when a flag is dropped a by player in CTF returning to its own base. -->
<flag-return-timeout value="20" />

View File

@ -41,7 +41,7 @@
<spacer width="3%" height="100%"/>
<bubble proportion="1" height="100%"
I18N="In the help menu"
text="Once in a server, a race will begin once its owner (symbolized with the crown) decides so. Official servers may auto-start races only when there are enough players. Then, you can choose your kart and vote for the next track to race on. An addon kart or track is allowed only if it exists on all joined players and the server."/>
text="Once in a server, a race will begin once its owner (symbolized with the crown) decides so. Official servers may auto-start races only when there are enough players. Then, you can choose your kart and vote for the next track to race on. An addon track is allowed only if it exists on all joined players and the server."/>
</div>
<label align="center" I18N="In the help menu" text="... or on the same device:"/>

View File

@ -25,6 +25,7 @@
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "network/network_config.hpp"
#include "physics/physics.hpp"
#include "utils/log.hpp"
@ -78,13 +79,26 @@ void AbstractKart::loadKartProperties(const std::string& new_ident,
{
m_kart_properties.reset(new KartProperties());
const KartProperties* kp = kart_properties_manager->getKart(new_ident);
const KartProperties* kp_addon = NULL;
if (NetworkConfig::get()->isNetworking() && kp && kp->isAddon())
{
// For addon kart in network we use the same hitbox (tux) so anyone
// can use any addon karts with different graphical kart model
kp_addon = kp;
kp = kart_properties_manager->getKart(std::string("tux"));
}
if (kp == NULL)
{
Log::warn("Abstract_Kart", "Unknown kart %s, fallback to tux",
new_ident.c_str());
if (!NetworkConfig::get()->isNetworking())
{
Log::warn("Abstract_Kart", "Unknown kart %s, fallback to tux",
new_ident.c_str());
}
kp = kart_properties_manager->getKart(std::string("tux"));
}
m_kart_properties->copyForPlayer(kp, handicap);
if (kp_addon)
m_kart_properties->adjustForOnlineAddonKart(kp_addon);
m_name = m_kart_properties->getName();
m_handicap = handicap;
m_kart_animation = NULL;
@ -97,10 +111,13 @@ void AbstractKart::loadKartProperties(const std::string& new_ident,
// released when the kart is deleted, but since the original
// kart_model is stored in the kart_properties all the time,
// there is no risk of a mesh being deleted too early.
m_kart_model.reset(m_kart_properties->getKartModelCopy(ri));
m_kart_width = m_kart_model->getWidth();
m_kart_height = m_kart_model->getHeight();
m_kart_length = m_kart_model->getLength();
if (kp_addon)
m_kart_model.reset(kp_addon->getKartModelCopy(ri));
else
m_kart_model.reset(m_kart_properties->getKartModelCopy(ri));
m_kart_width = kp->getMasterKartModel().getWidth();
m_kart_height = kp->getMasterKartModel().getHeight();
m_kart_length = kp->getMasterKartModel().getLength();
m_kart_highest_point = m_kart_model->getHighestPoint();
m_wheel_graphics_position = m_kart_model->getWheelsGraphicsPosition();
} // loadKartProperties

View File

@ -144,7 +144,7 @@ void CannonAnimation::init(Ipo *ipo, const Vec3 &start_left,
Vec3 direction = my_start_right - my_start_left;
direction.normalize();
float kw = m_kart ? m_kart->getKartModel()->getWidth()
float kw = m_kart ? m_kart->getKartWidth()
: m_flyable->getExtend().getX();
Vec3 adj_start_left = my_start_left + (0.5f*kw) * direction;
Vec3 adj_start_right = my_start_right - (0.5f*kw) * direction;

View File

@ -345,6 +345,22 @@ void KartProperties::setHatMeshName(const std::string &hat_name)
m_kart_model->setHatMeshName(hat_name);
} // setHatMeshName
// ----------------------------------------------------------------------------
/** Change the graphical properties (icon, shadow..) for addon kart using in
* online mode.
* \param source The source kart properties from which to copy this objects'
* values.
*/
void KartProperties::adjustForOnlineAddonKart(const KartProperties* source)
{
m_ident = source->m_ident;
m_shadow_material = source->m_shadow_material;
m_icon_material = source->m_icon_material;
m_minimap_icon = source->m_minimap_icon;
m_engine_sfx_type = source->m_engine_sfx_type;
m_color = source->m_color;
} // adjustForOnlineAddonKart
//-----------------------------------------------------------------------------
void KartProperties::combineCharacteristics(HandicapLevel handicap)
{

View File

@ -214,6 +214,7 @@ public:
~KartProperties ();
void copyForPlayer (const KartProperties *source,
HandicapLevel h = HANDICAP_NONE);
void adjustForOnlineAddonKart(const KartProperties* source);
void copyFrom (const KartProperties *source);
void getAllData (const XMLNode * root);
void checkAllSet (const std::string &filename);

View File

@ -578,10 +578,7 @@ void ServerLobby::updateAddons()
auto all_k = kart_properties_manager->getAllAvailableKarts();
if (all_k.size() >= 65536)
all_k.resize(65535);
if (ServerConfig::m_live_players)
m_available_kts.first = m_official_kts.first;
else
m_available_kts.first = { all_k.begin(), all_k.end() };
m_available_kts.first = m_official_kts.first;
} // updateAddons
//-----------------------------------------------------------------------------
@ -699,10 +696,7 @@ void ServerLobby::setup()
auto all_k = kart_properties_manager->getAllAvailableKarts();
if (all_k.size() >= 65536)
all_k.resize(65535);
if (ServerConfig::m_live_players)
m_available_kts.first = m_official_kts.first;
else
m_available_kts.first = { all_k.begin(), all_k.end() };
m_available_kts.first = m_official_kts.first;
updateTracksForMode();
m_server_has_loaded_world.store(false);
@ -5114,9 +5108,16 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
{
std::string kart;
ns.decodeString(&kart);
if (m_available_kts.first.find(kart) == m_available_kts.first.end())
if (kart.find("randomkart") != std::string::npos ||
(kart.find("addon_") == std::string::npos &&
m_available_kts.first.find(kart) == m_available_kts.first.end()))
{
continue;
RandomGenerator rg;
std::set<std::string>::iterator it =
m_available_kts.first.begin();
std::advance(it,
rg.get((int)m_available_kts.first.size()));
peer->getPlayerProfiles()[i]->setKartName(*it);
}
else
{

View File

@ -143,12 +143,6 @@ void loadServerConfigXML(const XMLNode* root, bool default_config)
"A new file will be created.", g_server_config_path.c_str());
if (root)
delete root;
if (default_config)
{
// Below option will have different default value when writing
// to server_config.xml in config directory
m_live_players = false;
}
writeServerConfigToDisk();
return;
}

View File

@ -259,12 +259,11 @@ namespace ServerConfig
"mode will not be saved in this config file."));
SERVER_CFG_PREFIX BoolServerConfigParam m_live_players
SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "live-players",
SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "live-spectate",
"If true, players can live join or spectate the in-progress game. "
"Currently live joining is only available if the current game mode "
"used in server is FFA, CTF or soccer, also no addon karts will be "
"available for players to choose, and official-karts-threshold will "
"be made 1.0."));
"used in server is FFA, CTF or soccer, also official-karts-threshold "
"will be made 1.0."));
SERVER_CFG_PREFIX FloatServerConfigParam m_flag_return_timeout
SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "flag-return-timeout",

View File

@ -868,7 +868,9 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id,
const KartProperties *kp =
kart_properties_manager->getKart(selection);
// Adjust for online addon karts
if (kp && kp->isAddon() && NetworkConfig::get()->isNetworking())
kp = kart_properties_manager->getKart("tux");
if (kp != NULL)
{
w->setValues(kp, m_kart_widgets[widget_id].getHandicap());

View File

@ -61,7 +61,13 @@ private:
// ------------------------------------------------------------------------
virtual bool isIgnored(const std::string& ident) const OVERRIDE
{ return m_available_karts.find(ident) == m_available_karts.end(); }
{
// Online addon kart use tux for hitbox in server so we can allow any
// addon kart graphically
if (ident.find("addon_") != std::string::npos)
return false;
return m_available_karts.find(ident) == m_available_karts.end();
}
// ------------------------------------------------------------------------
void updateProgressBarText();
// ------------------------------------------------------------------------