Merge branch 'KartPerGamemode'
# Conflicts: # src/states_screens/gp_info_screen.cpp
This commit is contained in:
commit
c59af9136c
@ -47,7 +47,7 @@ ChallengeData::ChallengeData(const std::string& filename)
|
||||
|
||||
for (int d=0; d<RaceManager::DIFFICULTY_COUNT; d++)
|
||||
{
|
||||
m_num_karts[d] = -1;
|
||||
m_default_num_karts[d] = -1;
|
||||
m_position[d] = -1;
|
||||
m_time[d] = -1.0f;
|
||||
m_energy[d] = -1;
|
||||
@ -176,7 +176,7 @@ ChallengeData::ChallengeData(const std::string& filename)
|
||||
|
||||
int num_karts = -1;
|
||||
if (!karts_node->get("number", &num_karts)) error("karts");
|
||||
m_num_karts[d] = num_karts;
|
||||
m_default_num_karts[d] = num_karts;
|
||||
|
||||
std::string replay_file;
|
||||
if (karts_node->get("replay_file", &replay_file))
|
||||
@ -385,7 +385,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const
|
||||
race_manager->setMinorMode(m_minor);
|
||||
race_manager->setTrack(m_track_id);
|
||||
race_manager->setNumLaps(m_num_laps);
|
||||
race_manager->setNumKarts(m_num_karts[d]);
|
||||
race_manager->setNumKarts(m_default_num_karts[d]);
|
||||
race_manager->setNumPlayers(1);
|
||||
race_manager->setCoinTarget(m_energy[d]);
|
||||
race_manager->setDifficulty(d);
|
||||
@ -404,7 +404,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const
|
||||
race_manager->setMinorMode(m_minor);
|
||||
race_manager->setGrandPrix(*grand_prix_manager->getGrandPrix(m_gp_id));
|
||||
race_manager->setDifficulty(d);
|
||||
race_manager->setNumKarts(m_num_karts[d]);
|
||||
race_manager->setNumKarts(m_default_num_karts[d]);
|
||||
race_manager->setNumPlayers(1);
|
||||
}
|
||||
|
||||
@ -448,7 +448,7 @@ bool ChallengeData::isChallengeFulfilled() const
|
||||
|
||||
if (kart->isEliminated() ) return false;
|
||||
if (track_name != m_track_id ) return false;
|
||||
if ((int)world->getNumKarts() < m_num_karts[d] ) return false;
|
||||
if ((int)world->getNumKarts() < m_default_num_karts[d] ) return false;
|
||||
if (m_energy[d] > 0 && kart->getEnergy() < m_energy[d] ) return false;
|
||||
if (m_position[d] > 0 && kart->getPosition() > m_position[d]) return false;
|
||||
|
||||
@ -495,7 +495,7 @@ bool ChallengeData::isGPFulfilled() const
|
||||
if (race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX ||
|
||||
race_manager->getMinorMode() != m_minor ||
|
||||
race_manager->getGrandPrix().getId() != m_gp_id ||
|
||||
race_manager->getNumberOfKarts() < (unsigned int)m_num_karts[d] ||
|
||||
race_manager->getNumberOfKarts() < (unsigned int)m_default_num_karts[d] ||
|
||||
race_manager->getNumPlayers() > 1) return false;
|
||||
|
||||
// check if the player came first.
|
||||
|
@ -84,7 +84,7 @@ private:
|
||||
|
||||
int m_num_laps;
|
||||
int m_position[RaceManager::DIFFICULTY_COUNT];
|
||||
int m_num_karts[RaceManager::DIFFICULTY_COUNT];
|
||||
int m_default_num_karts[RaceManager::DIFFICULTY_COUNT];
|
||||
std::string m_ai_kart_ident[RaceManager::DIFFICULTY_COUNT];
|
||||
std::string m_replay_files[RaceManager::DIFFICULTY_COUNT];
|
||||
float m_time[RaceManager::DIFFICULTY_COUNT];
|
||||
@ -208,7 +208,7 @@ public:
|
||||
*/
|
||||
int getNumKarts(RaceManager::Difficulty difficulty) const
|
||||
{
|
||||
return m_num_karts[difficulty];
|
||||
return m_default_num_karts[difficulty];
|
||||
} // getNumKarts
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the maximum time in which the kart must finish.
|
||||
|
@ -321,7 +321,158 @@ core::stringc ListUserConfigParam<T, U>::toString() const
|
||||
return "";
|
||||
} // toString
|
||||
|
||||
// ============================================================================
|
||||
template<typename T, typename U>
|
||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||
const char* comment)
|
||||
{
|
||||
m_param_name = param_name;
|
||||
all_params.push_back(this);
|
||||
if (comment != NULL) m_comment = comment;
|
||||
} // MapUserConfigParam
|
||||
|
||||
// ============================================================================
|
||||
template<typename T, typename U>
|
||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||
const char* comment,
|
||||
int nb_elements,
|
||||
...)
|
||||
{
|
||||
m_param_name = param_name;
|
||||
all_params.push_back(this);
|
||||
if (comment != NULL) m_comment = comment;
|
||||
|
||||
// add the default list
|
||||
va_list arguments;
|
||||
va_start(arguments, nb_elements);
|
||||
|
||||
struct pair_type { T key; U value; };
|
||||
|
||||
for (int i = 0; i < nb_elements; i++)
|
||||
{
|
||||
pair_type key_value_pair = va_arg(arguments, pair_type);
|
||||
m_elements.insert(std::pair<T, U>(key_value_pair.key, key_value_pair.value));
|
||||
}
|
||||
va_end(arguments); // Cleans up the list
|
||||
} // MapUserConfigParam
|
||||
|
||||
// ============================================================================
|
||||
template<typename T, typename U>
|
||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment)
|
||||
{
|
||||
m_param_name = param_name;
|
||||
group->addChild(this);
|
||||
if (comment != NULL) m_comment = comment;
|
||||
} // MapUserConfigParam
|
||||
|
||||
// ============================================================================
|
||||
template<typename T, typename U>
|
||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment,
|
||||
int nb_elements,
|
||||
...)
|
||||
{
|
||||
m_param_name = param_name;
|
||||
group->addChild(this);
|
||||
if (comment != NULL) m_comment = comment;
|
||||
|
||||
// add the default list
|
||||
va_list arguments;
|
||||
va_start(arguments, nb_elements);
|
||||
|
||||
struct pair_type { T key; U value; };
|
||||
|
||||
for (int i = 0; i < nb_elements; i++) {
|
||||
pair_type key_value_pair = va_arg(arguments, pair_type);
|
||||
m_elements.insert(std::pair<T, U>(key_value_pair.key, key_value_pair.value));
|
||||
}
|
||||
va_end(arguments); // Cleans up the list
|
||||
} // MapUserConfigParam
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T, typename U>
|
||||
void MapUserConfigParam<T, U>::write(std::ofstream& stream) const
|
||||
{
|
||||
const int elts_amount = m_elements.size();
|
||||
|
||||
// comment
|
||||
if (m_comment.size() > 0) stream << " <!-- " << m_comment.c_str();
|
||||
stream << " -->\n <" << m_param_name.c_str() << "\n";
|
||||
|
||||
stream << " Size=\"" << elts_amount << "\"\n";
|
||||
// actual elements
|
||||
//for (int n = 0; n<elts_amount; n++)
|
||||
|
||||
for (const auto& kv : m_elements)
|
||||
{
|
||||
stream << " " << kv.first << "=\"" << kv.second << "\"\n";
|
||||
}
|
||||
stream << " >\n";
|
||||
stream << " </" << m_param_name.c_str() << ">\n\n";
|
||||
} // write
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
template<typename T, typename U>
|
||||
void MapUserConfigParam<T, U>::findYourDataInAChildOf(const XMLNode* node)
|
||||
{
|
||||
const XMLNode* child = node->getNode(m_param_name);
|
||||
if (child == NULL)
|
||||
{
|
||||
//Log::error("User Config", "Couldn't find parameter group %s", m_param_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
int attr_count = 0;
|
||||
child->get("Size", &attr_count);
|
||||
|
||||
for (const auto& kv : m_elements)
|
||||
{
|
||||
std::pair<T,U> elt;
|
||||
elt.first = kv.first;
|
||||
elt.second = kv.second;
|
||||
|
||||
|
||||
bool there = false;
|
||||
|
||||
for (const auto& kvRHS : m_elements)
|
||||
{
|
||||
if (elt.second == kvRHS.second)
|
||||
{
|
||||
there = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (!there)
|
||||
{
|
||||
m_elements.insert(elt);
|
||||
}
|
||||
}
|
||||
} // findYourDataInAChildOf
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T, typename U>
|
||||
void MapUserConfigParam<T, U>::findYourDataInAnAttributeOf(const XMLNode* node)
|
||||
{
|
||||
} // findYourDataInAnAttributeOf
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T, typename U>
|
||||
void MapUserConfigParam<T, U>::addElement(T element, U value)
|
||||
{
|
||||
m_elements[element] = value;
|
||||
} // findYourDataInAnAttributeOf
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T, typename U>
|
||||
core::stringc MapUserConfigParam<T, U>::toString() const
|
||||
{
|
||||
return "";
|
||||
} // toString
|
||||
|
||||
// ============================================================================
|
||||
IntUserConfigParam::IntUserConfigParam(int default_value,
|
||||
|
@ -136,6 +136,55 @@ public:
|
||||
}; // ListUserConfigParam
|
||||
typedef ListUserConfigParam<std::string, const char*> StringListUserConfigParam;
|
||||
|
||||
template<typename T, typename U>
|
||||
class MapUserConfigParam : public UserConfigParam
|
||||
{
|
||||
std::map<T, U> m_elements;
|
||||
|
||||
public:
|
||||
MapUserConfigParam(const char* param_name,
|
||||
const char* comment = NULL);
|
||||
MapUserConfigParam(const char* param_name,
|
||||
const char* comment,
|
||||
int nb_elts,
|
||||
...);
|
||||
MapUserConfigParam(const char* param_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment = NULL);
|
||||
MapUserConfigParam(const char* param_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment,
|
||||
int nb_elts,
|
||||
...);
|
||||
|
||||
void write(std::ofstream& stream) const;
|
||||
void findYourDataInAChildOf(const XMLNode* node);
|
||||
void findYourDataInAnAttributeOf(const XMLNode* node);
|
||||
|
||||
void addElement(T element, U value);
|
||||
|
||||
irr::core::stringc toString() const;
|
||||
|
||||
operator std::map<T,U>() const
|
||||
{
|
||||
return m_elements;
|
||||
}
|
||||
std::map<T, U>& operator=(const std::map<T,U>& v)
|
||||
{
|
||||
m_elements = std::map<T, U>(v);
|
||||
return m_elements;
|
||||
}
|
||||
std::map<T, U>& operator=(const MapUserConfigParam& v)
|
||||
{
|
||||
m_elements = std::map<T,U>(v);
|
||||
return m_elements;
|
||||
}
|
||||
U& operator[] (const T key)
|
||||
{
|
||||
return m_elements[key];
|
||||
}
|
||||
}; // ListUserConfigParam
|
||||
typedef MapUserConfigParam<int, int> IntToIntUserConfigParam;
|
||||
// ============================================================================
|
||||
class IntUserConfigParam : public UserConfigParam
|
||||
{
|
||||
@ -335,7 +384,7 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( GroupUserConfigParam("RaceSetup",
|
||||
"Race Setup Settings") );
|
||||
|
||||
PARAM_PREFIX IntUserConfigParam m_num_karts
|
||||
PARAM_PREFIX IntUserConfigParam m_default_num_karts
|
||||
PARAM_DEFAULT( IntUserConfigParam(4, "numkarts",
|
||||
&m_race_setup_group,
|
||||
"Default number of karts. -1 means use all") );
|
||||
@ -706,6 +755,14 @@ namespace UserConfigParams
|
||||
"stun.voxgratia.org",
|
||||
"stun.xten.com") );
|
||||
|
||||
// ---- Gamemode setup
|
||||
PARAM_PREFIX IntToIntUserConfigParam m_num_karts_per_gamemode
|
||||
PARAM_DEFAULT(IntToIntUserConfigParam("num_karts_per_gamemode",
|
||||
"The Number of karts per gamemode.",
|
||||
1,
|
||||
std::make_pair(1100, 4)
|
||||
));
|
||||
|
||||
PARAM_PREFIX BoolUserConfigParam m_log_packets
|
||||
PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets",
|
||||
"If all network packets should be logged") );
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -1189,16 +1189,16 @@ int handleCmdLine()
|
||||
|
||||
if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n))
|
||||
{
|
||||
UserConfigParams::m_num_karts = n;
|
||||
if(UserConfigParams::m_num_karts > stk_config->m_max_karts)
|
||||
UserConfigParams::m_default_num_karts = n;
|
||||
if(UserConfigParams::m_default_num_karts > stk_config->m_max_karts)
|
||||
{
|
||||
Log::warn("main", "Number of karts reset to maximum number %d.",
|
||||
stk_config->m_max_karts);
|
||||
UserConfigParams::m_num_karts = stk_config->m_max_karts;
|
||||
UserConfigParams::m_default_num_karts = stk_config->m_max_karts;
|
||||
}
|
||||
race_manager->setNumKarts( UserConfigParams::m_num_karts );
|
||||
race_manager->setNumKarts( UserConfigParams::m_default_num_karts );
|
||||
Log::verbose("main", "%d karts will be used.",
|
||||
(int)UserConfigParams::m_num_karts);
|
||||
(int)UserConfigParams::m_default_num_karts);
|
||||
} // --numkarts
|
||||
|
||||
if(CommandLine::has( "--no-start-screen") ||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "tracks/track_manager.hpp"
|
||||
|
||||
std::vector<std::string> DemoWorld::m_demo_tracks;
|
||||
int DemoWorld::m_num_karts = 2;
|
||||
int DemoWorld::m_default_num_karts = 2;
|
||||
float DemoWorld::m_max_idle_time = 99999.0f;
|
||||
float DemoWorld::m_current_idle_time = 0;
|
||||
bool DemoWorld::m_do_demo = false;
|
||||
@ -49,7 +49,7 @@ DemoWorld::DemoWorld()
|
||||
race_manager->setReverseTrack(false);
|
||||
race_manager->setMinorMode (RaceManager::MINOR_MODE_NORMAL_RACE);
|
||||
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
|
||||
race_manager->setNumKarts(m_num_karts);
|
||||
race_manager->setNumKarts(m_default_num_karts);
|
||||
race_manager->setNumPlayers(1);
|
||||
race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
|
||||
|
||||
@ -149,7 +149,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt)
|
||||
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
|
||||
|
||||
m_do_demo = true;
|
||||
race_manager->setNumKarts(m_num_karts);
|
||||
race_manager->setNumKarts(m_default_num_karts);
|
||||
race_manager->setPlayerKart(0, "tux");
|
||||
race_manager->setupPlayerKartInfo();
|
||||
race_manager->startSingleRace(m_demo_tracks[0], m_num_laps, false);
|
||||
|
@ -40,7 +40,7 @@ private:
|
||||
static std::vector<std::string> m_demo_tracks;
|
||||
|
||||
/** Number of karts to use in demo mode. */
|
||||
static int m_num_karts;
|
||||
static int m_default_num_karts;
|
||||
|
||||
/** Idle time after which demo mode should be started. */
|
||||
static float m_max_idle_time;
|
||||
@ -66,7 +66,7 @@ public:
|
||||
static void setNumLaps(unsigned int num_laps) { m_num_laps = num_laps; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the number of karts to use in demo mode. */
|
||||
static void setNumKarts(unsigned int num_karts) { m_num_karts = num_karts;}
|
||||
static void setNumKarts(unsigned int num_karts) { m_default_num_karts = num_karts;}
|
||||
// ------------------------------------------------------------------------
|
||||
static void setTracks(const std::vector<std::string> &tracks);
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -66,7 +66,7 @@ RaceManager::RaceManager()
|
||||
{
|
||||
// Several code depends on this, e.g. kart_properties
|
||||
assert(DIFFICULTY_FIRST == 0);
|
||||
m_num_karts = UserConfigParams::m_num_karts;
|
||||
m_num_karts = UserConfigParams::m_default_num_karts;
|
||||
m_difficulty = DIFFICULTY_HARD;
|
||||
m_major_mode = MAJOR_MODE_SINGLE;
|
||||
m_minor_mode = MINOR_MODE_NORMAL_RACE;
|
||||
|
@ -234,7 +234,8 @@ void GPInfoScreen::init()
|
||||
{
|
||||
const int local_players = race_manager->getNumLocalPlayers();
|
||||
int min_ai = 0;
|
||||
int num_ai = UserConfigParams::m_num_karts - local_players;
|
||||
int num_ai = UserConfigParams::m_num_karts_per_gamemode[RaceManager::MAJOR_MODE_GRAND_PRIX]
|
||||
- local_players;
|
||||
|
||||
// A ftl reace needs at least three karts to make any sense
|
||||
if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
|
||||
@ -321,7 +322,7 @@ void GPInfoScreen::eventCallback(Widget *, const std::string &name,
|
||||
const int num_ai = has_AI ? m_ai_kart_spinner->getValue() : 0;
|
||||
|
||||
race_manager->setNumKarts(local_players + num_ai);
|
||||
UserConfigParams::m_num_karts = local_players + num_ai;
|
||||
UserConfigParams::m_num_karts_per_gamemode[RaceManager::MAJOR_MODE_GRAND_PRIX] = local_players + num_ai;
|
||||
|
||||
m_gp.changeReverse(getReverse());
|
||||
race_manager->startGP(m_gp, false, false);
|
||||
@ -358,7 +359,7 @@ void GPInfoScreen::eventCallback(Widget *, const std::string &name,
|
||||
{
|
||||
const int num_ai = m_ai_kart_spinner->getValue();
|
||||
race_manager->setNumKarts( race_manager->getNumLocalPlayers() + num_ai );
|
||||
UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers() + num_ai;
|
||||
UserConfigParams::m_num_karts_per_gamemode[RaceManager::MAJOR_MODE_GRAND_PRIX] = race_manager->getNumLocalPlayers() + num_ai;
|
||||
}
|
||||
else if(name=="back")
|
||||
{
|
||||
|
@ -163,15 +163,19 @@ void TrackInfoScreen::init()
|
||||
race_manager->hasAI());
|
||||
m_ai_kart_spinner->setVisible(has_AI);
|
||||
getWidget<LabelWidget>("ai-text")->setVisible(has_AI);
|
||||
|
||||
if (has_AI)
|
||||
{
|
||||
m_ai_kart_spinner->setActive(true);
|
||||
|
||||
int num_ai = UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] - local_players;
|
||||
|
||||
// Avoid negative numbers (which can happen if e.g. the number of karts
|
||||
// in a previous race was lower than the number of players now.
|
||||
int num_ai = UserConfigParams::m_num_karts - local_players;
|
||||
|
||||
if (num_ai < 0) num_ai = 0;
|
||||
m_ai_kart_spinner->setValue(num_ai);
|
||||
|
||||
race_manager->setNumKarts(num_ai + local_players);
|
||||
// Set the max karts supported based on the battle arena selected
|
||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
|
||||
@ -240,7 +244,8 @@ void TrackInfoScreen::init()
|
||||
m_ai_kart_spinner->setValue(0);
|
||||
m_ai_kart_spinner->setActive(false);
|
||||
race_manager->setNumKarts(race_manager->getNumLocalPlayers());
|
||||
UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers();
|
||||
|
||||
UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers();
|
||||
}
|
||||
else if (record_available)
|
||||
{
|
||||
@ -367,10 +372,11 @@ void TrackInfoScreen::onEnterPressedInternal()
|
||||
if (has_AI)
|
||||
num_ai = m_ai_kart_spinner->getValue();
|
||||
|
||||
if (UserConfigParams::m_num_karts != (local_players + num_ai))
|
||||
|
||||
if (UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] != (local_players + num_ai))
|
||||
{
|
||||
race_manager->setNumKarts(local_players + num_ai);
|
||||
UserConfigParams::m_num_karts = local_players + num_ai;
|
||||
UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = local_players + num_ai;
|
||||
}
|
||||
|
||||
// Disable accidentally unlocking of a challenge
|
||||
@ -420,7 +426,7 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
m_ai_kart_spinner->setActive(false);
|
||||
race_manager->setNumKarts(race_manager->getNumLocalPlayers());
|
||||
UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers();
|
||||
UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -439,7 +445,7 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
const int num_ai = m_ai_kart_spinner->getValue();
|
||||
race_manager->setNumKarts( race_manager->getNumLocalPlayers() + num_ai );
|
||||
UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers() + num_ai;
|
||||
UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers() + num_ai;
|
||||
updateHighScores();
|
||||
}
|
||||
} // eventCallback
|
||||
|
Loading…
Reference in New Issue
Block a user