Add difficulty to karts

This commit is contained in:
Flakebi 2014-07-29 22:54:42 +02:00
parent bcf7690809
commit a84094e55e
8 changed files with 199 additions and 52 deletions

View File

@ -336,22 +336,92 @@
</ai>
<!-- The per-player difficulties in multiplayer games.
These values are multiplied with the current values of a car. (except ai) -->
These values are multiplied with the current values of a car. -->
<difficulties>
<easiest>
<engine power="4.0" max-speed="4.0"/>
<mass value="1.0"/>
<engine brake-factor="2.5" max-speed-reverse-ratio="1.0" power="1.5" max-speed="1.5"/>
<nitro consumption="0.7" max-speed-increase="1.3" duration="1.0" fade-out-time="1.0"/>
<bubblegum time="0.5" speed-fraction="0.5" torque="0.5" fade-in-time="1.0"/>
<rescue time="0.5"/>
<explosion time="0.5" invulnerability-time="1.5"/>
<slipstream length="1.5" width="1.5" collect-time="0.5" use-time="2.0"
add-power="1.5" min-speed="1.5" max-speed-increase="1.5" duration="1.5"
fade-out-time="1.0"/>
<plunger band-max-length="1.5" band-force="1.0" band-duration="1.0"
band-speed-increase="1.5" band-fade-out-time="1.0" in-face-time="0.5"/>
<zipper time="1.3" force="1.3" speed-gain="1.3" max-speed-increase="1.3"
fade-out-time="1.0"/>
<swatter duration="1.5" squash-duration="0.7" squash-slowdown="0.5"/>
<startup time="2.0 2.0" boost="1.5 1.5"/>
</easiest>
<easy>
<engine power="2.0" max-speed="2.0"/>
<mass value="1.0"/>
<engine brake-factor="1.7" max-speed-reverse-ratio="1.0" power="1.2" max-speed="1.2"/>
<nitro consumption="0.9" max-speed-increase="1.1" duration="1.0" fade-out-time="1.0"/>
<bubblegum time="0.7" speed-fraction="0.7" torque="0.7" fade-in-time="1.0"/>
<rescue time="0.7"/>
<explosion time="0.7" invulnerability-time="1.2"/>
<slipstream length="1.2" width="1.2" collect-time="0.7" use-time="1.5"
add-power="1.3" min-speed="1.3" max-speed-increase="1.3" duration="1.3"
fade-out-time="1.0"/>
<plunger band-max-length="1.2" band-force="1.0" band-duration="1.0"
band-speed-increase="1.2" band-fade-out-time="1.0" in-face-time="0.7"/>
<zipper time="1.2" force="1.1" speed-gain="1.1" max-speed-increase="1.1"
fade-out-time="1.0"/>
<swatter duration="1.2" squash-duration="0.8" squash-slowdown="0.7"/>
<startup time="1.5 1.5" boost="1.2 1.2"/>
</easy>
<normal>
<engine power="1.0" max-speed="1.0"/>
<mass value="1.0"/>
<engine brake-factor="1.0" max-speed-reverse-ratio="1.0" power="1.0" max-speed="1.0"/>
<nitro consumption="1.0" max-speed-increase="1.0" duration="1.0" fade-out-time="1.0"/>
<bubblegum time="1.0" speed-fraction="1.0" torque="1.0" fade-in-time="1.0"/>
<rescue time="1.0"/>
<explosion time="1.0" radius="1.0" invulnerability-time="1.0"/>
<slipstream length="1.0" width="1.0" collect-time="1.0" use-time="1.0"
add-power="1.0" min-speed="1.0" max-speed-increase="1.0" duration="1.0"
fade-out-time="1.0"/>
<plunger band-max-length="1.0" band-force="1.0" band-duration="1.0"
band-speed-increase="1.0" band-fade-out-time="1.0" in-face-time="1.0"/>
<zipper time="1.0" force="1.0" speed-gain="1.0" max-speed-increase="1.0"
fade-out-time="1.0"/>
<swatter duration="1.0" squash-duration="1.0" squash-slowdown="1.0"/>
<startup time="1.0 1.0" boost="1.0 1.0"/>
</normal>
<hard>
<engine power="0.5" max-speed="0.5"/>
<mass value="1.0"/>
<engine brake-factor="0.8" max-speed-reverse-ratio="0.8" power="0.8" max-speed="0.8"/>
<nitro consumption="1.1" max-speed-increase="0.9" duration="1.0" fade-out-time="1.0"/>
<bubblegum time="1.5" speed-fraction="1.5" torque="1.5" fade-in-time="1.0"/>
<rescue time="1.5"/>
<explosion time="1.3" invulnerability-time="0.7"/>
<slipstream length="0.8" width="0.8" collect-time="1.5" use-time="0.8"
add-power="0.8" min-speed="0.8" max-speed-increase="0.9" duration="0.8"
fade-out-time="1.0"/>
<plunger band-max-length="0.8" band-force="1.0" band-duration="1.0"
band-speed-increase="0.8" band-fade-out-time="1.0" in-face-time="1.3"/>
<zipper time="0.8" force="0.8" speed-gain="0.8" max-speed-increase="0.8"
fade-out-time="1.0"/>
<swatter duration="0.8" squash-duration="1.5" squash-slowdown="1.8"/>
<startup time="0.8 0.8" boost="0.8 0.8"/>
</hard>
<hardest>
<engine power="0.25" max-speed="0.25"/>
<mass value="1.0"/>
<engine brake-factor="0.5" max-speed-reverse-ratio="0.6" power="0.6" max-speed="0.6"/>
<nitro consumption="1.2" max-speed-increase="0.8" duration="1.0" fade-out-time="1.0"/>
<bubblegum time="2.0" speed-fraction="2.0" torque="2.0" fade-in-time="1.0"/>
<rescue time="2.0"/>
<explosion time="1.5" invulnerability-time="0.5"/>
<slipstream length="0.6" width="0.6" collect-time="1.5" use-time="0.6"
add-power="0.6" min-speed="0.6" max-speed-increase="0.8" duration="0.6"
fade-out-time="1.0"/>
<plunger band-max-length="0.6" band-force="1.0" band-duration="1.0"
band-speed-increase="0.6" band-fade-out-time="1.0" in-face-time="1.5"/>
<zipper time="0.6" force="0.6" speed-gain="0.6" max-speed-increase="0.6"
fade-out-time="1.0"/>
<swatter duration="0.6" squash-duration="1.5" squash-slowdown="1.8"/>
<startup time="0.6 0.6" boost="0.6 0.6"/>
</hardets>
</difficulties>

View File

@ -97,6 +97,17 @@ void PlayerDifficulty::load(const std::string &filename, const std::string &node
*/
void PlayerDifficulty::getAllData(const XMLNode * root)
{
if(const XMLNode *mass_node = root->getNode("mass"))
mass_node->get("value", &m_mass);
if(const XMLNode *engine_node = root->getNode("engine"))
{
engine_node->get("brake-factor", &m_brake_factor);
engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio);
engine_node->get("power", &m_engine_power);
engine_node->get("max-speed", &m_max_speed);
}
if(const XMLNode *nitro_node = root->getNode("nitro"))
{
nitro_node->get("consumption", &m_nitro_consumption );
@ -110,14 +121,12 @@ void PlayerDifficulty::getAllData(const XMLNode * root)
{
bubble_node->get("time", &m_bubblegum_time );
bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction);
bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time );
bubble_node->get("torque", &m_bubblegum_torque );
bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time );
}
if(const XMLNode *rescue_node = root->getNode("rescue"))
{
rescue_node->get("time", &m_rescue_time);
}
if(const XMLNode *explosion_node = root->getNode("explosion"))
{
@ -140,14 +149,6 @@ void PlayerDifficulty::getAllData(const XMLNode * root)
slipstream_node->get("fade-out-time", &m_slipstream_fade_out_time );
}
if(const XMLNode *engine_node = root->getNode("engine"))
{
engine_node->get("brake-factor", &m_brake_factor);
engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio);
engine_node->get("power", &m_engine_power);
engine_node->get("max-speed", &m_max_speed);
} // if getNode("engine")
if(const XMLNode *plunger_node= root->getNode("plunger"))
{
plunger_node->get("band-max-length", &m_rubber_band_max_length );

View File

@ -23,6 +23,7 @@
#define GAME_SETUP_HPP
#include "network/race_config.hpp"
#include "network/remote_kart_info.hpp"
#include <vector>
#include <string>
@ -43,6 +44,7 @@ class NetworkPlayerProfile
std::string kart_name; //!< The selected kart.
Online::OnlineProfile* user_profile; //!< Pointer to the lobby profile
uint8_t world_kart_id; //!< the kart id in the World class (pointer to AbstractKart)
PerPlayerDifficulty difficulty;
};
/*! \class GameSetup

View File

@ -112,6 +112,7 @@ void StartGameProtocol::update()
NetworkPlayerProfile* profile = players[i];
RemoteKartInfo rki(profile->race_id, profile->kart_name,
profile->user_profile->getUserName(), profile->race_id, !is_me);
rki.setDifficulty(profile->difficulty);
rki.setGlobalPlayerId(profile->race_id);
rki.setLocalPlayerId(is_me?0:1);
rki.setHostId(profile->race_id);
@ -140,6 +141,7 @@ void StartGameProtocol::update()
NetworkPlayerProfile* profile = players[i];
RemoteKartInfo rki(profile->race_id, profile->kart_name,
profile->user_profile->getUserName(), profile->race_id, !is_me);
rki.setDifficulty(profile->difficulty);
rki.setGlobalPlayerId(profile->race_id);
// on the server, the race id must be the local one.
rki.setLocalPlayerId(m_listener->isServer()?profile->race_id:(is_me?0:1));

View File

@ -161,6 +161,16 @@ void RaceManager::setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team
m_local_player_karts[player_id].setSoccerTeam(team);
}
//-----------------------------------------------------------------------------
/** Sets the per-player difficulty for a player.
*/
void RaceManager::setPlayerDifficulty(unsigned int player_id, PerPlayerDifficulty difficulty)
{
assert(player_id < m_local_player_karts.size());
m_local_player_karts[player_id].setDifficulty(difficulty);
}
//-----------------------------------------------------------------------------
/** Returns a pointer to the kart which has a given GP rank.
* \param n The rank (1 to number of karts) to look for.

View File

@ -374,6 +374,10 @@ public:
*/
void setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team);
/** Sets the per-player difficulty for a player.
*/
void setPlayerDifficulty(unsigned int player_id, PerPlayerDifficulty difficulty);
/** Sets the number of local players playing on this computer (including
* split screen).
* \param n Number of local players.

View File

@ -146,7 +146,41 @@ EventPropagation FocusDispatcher::focused(const int playerID)
return GUIEngine::EVENT_LET;
} // focused
FocusDispatcher2::FocusDispatcher2(KartSelectionScreen *parent) :
FocusDispatcher(parent)
{
}
GUIEngine::EventPropagation FocusDispatcher2::focused(const int playerID)
{
if (!m_is_initialised) return EVENT_LET;
if(UserConfigParams::logGUI())
Log::info("KartSelectionScreen", "FocusDispatcher2 focused by player %u",
playerID);
// since this screen is multiplayer, redirect focus to the right widget
const int amount = m_parent->m_kart_widgets.size();
for (int n=0; n<amount; n++)
{
if (m_parent->m_kart_widgets[n].getPlayerID() == playerID)
{
// If player is done, don't do anything with focus
if (m_parent->m_kart_widgets[n].isReady())
return GUIEngine::EVENT_BLOCK;
m_parent->m_kart_widgets[n].m_difficulty
->setFocusForPlayer(playerID);
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
} // focused
static FocusDispatcher *g_dispatcher = NULL;
static FocusDispatcher2 *g_dispatcher2 = NULL;
#if 0
#pragma mark -
@ -235,6 +269,7 @@ KartSelectionScreen* KartSelectionScreen::getRunningInstance()
void KartSelectionScreen::loadedFromFile()
{
g_dispatcher = new FocusDispatcher(this);
g_dispatcher2 = new FocusDispatcher2(this);
m_first_widget = g_dispatcher;
m_game_master_confirmed = false;
m_multiplayer_message = NULL;
@ -307,6 +342,7 @@ void KartSelectionScreen::init()
// FIXME : The reserved id value is -1 when we switch from KSS to NKSS and vice-versa
g_dispatcher->setRootID(placeholder->m_reserved_id);
g_dispatcher2->setRootID(placeholder->m_reserved_id);
g_root_id = placeholder->m_reserved_id;
if (!m_widgets.contains(g_dispatcher))
@ -318,6 +354,15 @@ void KartSelectionScreen::init()
// other widgets.
g_dispatcher->add();
}
if (!m_widgets.contains(g_dispatcher2))
{
m_widgets.push_back(g_dispatcher2);
// this is only needed if the dispatcher wasn't already in
// the list of widgets. If it already was, it was added along
// other widgets.
g_dispatcher2->add();
}
m_game_master_confirmed = false;
@ -417,6 +462,7 @@ void KartSelectionScreen::unloaded()
{
// these pointers are no more valid (have been deleted along other widgets)
g_dispatcher = NULL;
g_dispatcher2 = NULL;
}
// ----------------------------------------------------------------------------
@ -428,6 +474,7 @@ bool KartSelectionScreen::joinPlayer(InputDevice* device, bool first_player)
if (!m_multiplayer && !first_player) return false;
assert (g_dispatcher != NULL);
assert (g_dispatcher2 != NULL);
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
if (w == NULL)
@ -1179,6 +1226,8 @@ void KartSelectionScreen::allPlayersDone()
// std::cout << "selection=" << selection.c_str() << std::endl;
race_manager->setLocalKartInfo(n, selected_kart);
race_manager->setPlayerDifficulty(n,
(PerPlayerDifficulty) m_kart_widgets[n].m_difficulty->getValue());
}
// ---- Switch to assign mode

View File

@ -48,6 +48,7 @@ class KartSelectionScreen : public GUIEngine::Screen
friend class KartHoverListener;
friend class PlayerNameSpinner;
friend class FocusDispatcher;
friend class FocusDispatcher2;
protected:
/** Contains the custom widget shown for every player. (ref only since
* we're adding them to a Screen, and the Screen will take ownership
@ -172,6 +173,7 @@ public:
way?) */
class FocusDispatcher : public GUIEngine::Widget
{
protected:
KartSelectionScreen* m_parent;
int m_reserved_id;
@ -194,6 +196,13 @@ public:
virtual GUIEngine::EventPropagation focused(const int playerID);
}; // FocusDispatcher
class FocusDispatcher2 : public FocusDispatcher
{
public:
FocusDispatcher2(KartSelectionScreen *parent);
virtual GUIEngine::EventPropagation focused(const int playerID);
};
//!----------------------------------------------------------------------------
//! KartHoverListener :