Applied Unitraxx's patch to save GP. At this stage no GUI support
was added. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12782 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
7ac899ade7
commit
b3e7a7ebbf
@ -22,6 +22,7 @@ src/challenges/game_slot.cpp
|
||||
src/challenges/unlock_manager.cpp
|
||||
src/config/device_config.cpp
|
||||
src/config/player.cpp
|
||||
src/config/saved_grand_prix.cpp
|
||||
src/config/stk_config.cpp
|
||||
src/config/user_config.cpp
|
||||
src/graphics/camera.cpp
|
||||
@ -267,6 +268,7 @@ src/challenges/game_slot.hpp
|
||||
src/challenges/unlock_manager.hpp
|
||||
src/config/device_config.hpp
|
||||
src/config/player.hpp
|
||||
src/config/saved_grand_prix.hpp
|
||||
src/config/stk_config.hpp
|
||||
src/config/user_config.hpp
|
||||
src/graphics/camera.hpp
|
||||
|
@ -35,7 +35,10 @@ class PlayerProfile : public NoCopy
|
||||
{
|
||||
protected:
|
||||
|
||||
/** For saving to config file. */
|
||||
/**
|
||||
* For saving to config file.
|
||||
* WARNING : m_player_group has to be declared before the other userconfigparams!
|
||||
*/
|
||||
GroupUserConfigParam m_player_group;
|
||||
|
||||
WStringUserConfigParam m_name;
|
||||
|
170
src/config/saved_grand_prix.cpp
Normal file
170
src/config/saved_grand_prix.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#include "config/saved_grand_prix.hpp"
|
||||
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SavedGrandPrix::SavedGPKart::SavedGPKart(GroupUserConfigParam * group,
|
||||
const std::string &ident,
|
||||
int score,
|
||||
int local_player_id,
|
||||
int global_player_id,
|
||||
float overall_time)
|
||||
: m_group("Kart", group, "Saved state of a kart") ,
|
||||
m_ident(ident.c_str(),"ident", &m_group),
|
||||
m_score(score,"score",&m_group),
|
||||
m_local_player_id(local_player_id,"local_player_id",&m_group),
|
||||
m_global_player_id(global_player_id,"global_player_id",&m_group),
|
||||
m_overall_time(overall_time,"overall_time",&m_group)
|
||||
{
|
||||
|
||||
} // SavedGPKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SavedGrandPrix::SavedGPKart::SavedGPKart(GroupUserConfigParam * group,
|
||||
const XMLNode* node)
|
||||
: m_group("Kart", group, "Saved state of a kart"),
|
||||
m_ident("-","ident", &m_group),
|
||||
m_score(0,"score",&m_group),
|
||||
m_local_player_id(0,"local_player_id",&m_group),
|
||||
m_global_player_id(0,"global_player_id",&m_group),
|
||||
m_overall_time(0.0f,"overall_time",&m_group)
|
||||
{
|
||||
m_ident.findYourDataInAnAttributeOf(node);
|
||||
m_score.findYourDataInAnAttributeOf(node);
|
||||
m_local_player_id.findYourDataInAnAttributeOf(node);
|
||||
m_global_player_id.findYourDataInAnAttributeOf(node);
|
||||
m_overall_time.findYourDataInAnAttributeOf(node);
|
||||
} // SavedGPKart
|
||||
|
||||
// ============================================================================
|
||||
SavedGrandPrix::SavedGrandPrix(const std::string &player_id,
|
||||
const std::string &gp_id,
|
||||
RaceManager::Difficulty difficulty,
|
||||
int player_karts,
|
||||
int last_track,
|
||||
const std::vector<RaceManager::KartStatus> &kart_list)
|
||||
: m_savedgp_group("SavedGP",
|
||||
"Represents the saved state of a GP"),
|
||||
m_player_id(player_id.c_str(), "player_id", &m_savedgp_group),
|
||||
m_gp_id(gp_id.c_str(), "gp_id", &m_savedgp_group),
|
||||
m_difficulty((int)difficulty,"difficulty", &m_savedgp_group),
|
||||
m_player_karts(player_karts,"player_karts", &m_savedgp_group),
|
||||
m_next_track(last_track,"last_track", &m_savedgp_group)
|
||||
{
|
||||
for(unsigned int i =0; i < kart_list.size(); i++)
|
||||
{
|
||||
SavedGPKart * newKart = new SavedGPKart(&m_savedgp_group,
|
||||
kart_list[i].m_ident,
|
||||
kart_list[i].m_score,
|
||||
kart_list[i].m_local_player_id,
|
||||
kart_list[i].m_global_player_id,
|
||||
kart_list[i].m_overall_time
|
||||
);
|
||||
m_karts.push_back(newKart);
|
||||
}
|
||||
} // SavedGrandPrix
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SavedGrandPrix::SavedGrandPrix(const XMLNode* node)
|
||||
: m_savedgp_group("SavedGP",
|
||||
"Represents the saved state of a GP"),
|
||||
m_player_id("-", "player_id", &m_savedgp_group),
|
||||
m_gp_id("-", "gp_id", &m_savedgp_group),
|
||||
m_difficulty(0,"difficulty", &m_savedgp_group),
|
||||
m_player_karts(0,"player_karts", &m_savedgp_group),
|
||||
m_next_track(0,"last_track", &m_savedgp_group)
|
||||
{
|
||||
//m_player_group.findYourDataInAChildOf(node);
|
||||
m_player_id.findYourDataInAnAttributeOf(node);
|
||||
m_gp_id.findYourDataInAnAttributeOf(node);
|
||||
m_difficulty.findYourDataInAnAttributeOf(node);
|
||||
m_player_karts.findYourDataInAnAttributeOf(node);
|
||||
m_next_track.findYourDataInAnAttributeOf(node);
|
||||
|
||||
std::vector<XMLNode*> karts;
|
||||
node->getNodes("Kart", karts);
|
||||
for(unsigned int i =0; i < karts.size(); i++)
|
||||
{
|
||||
SavedGPKart * newKart = new SavedGPKart(&m_savedgp_group,karts[i]);
|
||||
m_karts.push_back(newKart);
|
||||
}
|
||||
} // SavedGrandPrix
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SavedGrandPrix::clearKarts()
|
||||
{
|
||||
m_savedgp_group.clearChildren();
|
||||
m_karts.clearAndDeleteAll();
|
||||
} // clearKarts
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SavedGrandPrix::setKarts(const std::vector<RaceManager::KartStatus> &kart_list)
|
||||
{
|
||||
clearKarts();
|
||||
for(unsigned int i =0; i < kart_list.size(); i++)
|
||||
{
|
||||
SavedGPKart * newKart = new SavedGPKart(&m_savedgp_group,
|
||||
kart_list[i].m_ident,
|
||||
kart_list[i].m_score,
|
||||
kart_list[i].m_local_player_id,
|
||||
kart_list[i].m_global_player_id,
|
||||
kart_list[i].m_overall_time
|
||||
);
|
||||
m_karts.push_back(newKart);
|
||||
}
|
||||
} // setKarts
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SavedGrandPrix::loadKarts(std::vector<RaceManager::KartStatus> & kart_list)
|
||||
{
|
||||
//Fix aikarts
|
||||
int aikarts = 0;
|
||||
for(int i = 0; i < m_karts.size(); i++)
|
||||
{
|
||||
if(m_karts[i].m_local_player_id == -1)
|
||||
{
|
||||
//AI kart found
|
||||
kart_list[aikarts].m_ident = m_karts[i].m_ident;
|
||||
kart_list[aikarts].m_score = m_karts[i].m_score;
|
||||
kart_list[aikarts].m_overall_time = m_karts[i].m_overall_time;
|
||||
aikarts++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get correct player
|
||||
for(unsigned int x = kart_list.size()-m_player_karts;
|
||||
x < kart_list.size(); x++)
|
||||
{
|
||||
if(kart_list[x].m_local_player_id == m_karts[i].m_local_player_id)
|
||||
{
|
||||
kart_list[x].m_score = m_karts[i].m_score;
|
||||
kart_list[x].m_overall_time = m_karts[i].m_overall_time;
|
||||
} // if kart_list[x].m_local_player_id == m_karts[i].,_local
|
||||
} // for x
|
||||
} // if m_local_player_id == -1
|
||||
} // for i
|
||||
} // loadKarts
|
164
src/config/saved_grand_prix.hpp
Normal file
164
src/config/saved_grand_prix.hpp
Normal file
@ -0,0 +1,164 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2010 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SAVED_GRAND_PRIX_HPP
|
||||
#define HEADER_SAVED_GRAND_PRIX_HPP
|
||||
|
||||
#include <string>
|
||||
#include "config/user_config.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
class RaceManager;
|
||||
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* \brief Class for managing saved Grand-Prix's
|
||||
* A list of all possible resumable GP's is stored in the user config.
|
||||
* \ingroup config
|
||||
*/
|
||||
class SavedGrandPrix
|
||||
{
|
||||
private:
|
||||
class SavedGPKart
|
||||
{
|
||||
friend class SavedGrandPrix;
|
||||
GroupUserConfigParam m_group;
|
||||
StringUserConfigParam m_ident;
|
||||
IntUserConfigParam m_score, m_local_player_id, m_global_player_id;
|
||||
FloatUserConfigParam m_overall_time;
|
||||
public:
|
||||
SavedGPKart(GroupUserConfigParam * group, const XMLNode* node);
|
||||
SavedGPKart(GroupUserConfigParam * group,
|
||||
const std::string &ident,
|
||||
int score,
|
||||
int local_player_id,
|
||||
int global_player_id,
|
||||
float overall_time);
|
||||
}; // SavedGPKart
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* For saving to config file.
|
||||
* WARNING : m_savedgp_group has to be declared before the other userconfigparams!
|
||||
*/
|
||||
GroupUserConfigParam m_savedgp_group;
|
||||
StringUserConfigParam m_player_id;
|
||||
|
||||
/** Identifier of this GP. */
|
||||
StringUserConfigParam m_gp_id;
|
||||
|
||||
/** Difficulty at which this GP was run. */
|
||||
IntUserConfigParam m_difficulty;
|
||||
|
||||
/** Number of player karts used in this GP. */
|
||||
IntUserConfigParam m_player_karts;
|
||||
|
||||
/** Index of the next to run track. */
|
||||
IntUserConfigParam m_next_track;
|
||||
|
||||
PtrVector<SavedGPKart> m_karts;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor to create a new entry.
|
||||
*/
|
||||
SavedGrandPrix(const std::string &player_id,
|
||||
const std::string &gp_id,
|
||||
RaceManager::Difficulty difficulty,
|
||||
int player_karts,
|
||||
int last_track,
|
||||
const std::vector<RaceManager::KartStatus> &kart_list);
|
||||
|
||||
/**
|
||||
* Constructor to deserialize a entry that was saved to a XML file
|
||||
*/
|
||||
SavedGrandPrix(const XMLNode* node);
|
||||
void setKarts(const std::vector<RaceManager::KartStatus> &kart_list);
|
||||
void clearKarts();
|
||||
void loadKarts(std::vector<RaceManager::KartStatus> & kart_list);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the player id for this saved GP. */
|
||||
const std::string getPlayerID() const { return m_player_id; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the grand prix id. */
|
||||
std::string getGPID() const { return m_gp_id; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the difficulty of this GP. */
|
||||
int getDifficulty() const { return m_difficulty; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the total number of karts of this GP. */
|
||||
int getTotalKarts() const { return m_karts.size(); }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of player karts in this GP. */
|
||||
int getPlayerKarts() const { return m_player_karts; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the index of the last track finished when this GP was saved. */
|
||||
int getNextTrack() const { return m_next_track; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the index of the last track finished. */
|
||||
void setNextTrack(int next_track) { m_next_track = next_track; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Removed this SavedGrandPrix from the list of all SavedGrandPrix, and
|
||||
* deletes it. */
|
||||
void remove()
|
||||
{
|
||||
UserConfigParams::m_saved_grand_prix_list.remove(this);
|
||||
delete this;
|
||||
} // remove
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Finds the right SavedGrandPrix given the specified data, or
|
||||
* NULL if no matching GP was found.
|
||||
*/
|
||||
static SavedGrandPrix* getSavedGP(const std::string &player,
|
||||
const std::string &gpid,
|
||||
int difficulty, int total_karts,
|
||||
int player_karts)
|
||||
{
|
||||
for (int n=0; n<UserConfigParams::m_saved_grand_prix_list.size(); n++)
|
||||
{
|
||||
SavedGrandPrix* gp = &UserConfigParams::m_saved_grand_prix_list[n];
|
||||
if ((gp->getGPID() == gpid) &&
|
||||
(gp->getPlayerID() == player) &&
|
||||
(gp->getDifficulty() == difficulty) &&
|
||||
(gp->getTotalKarts() == total_karts) &&
|
||||
(gp->getPlayerKarts() == player_karts)){
|
||||
return gp;
|
||||
} // if
|
||||
} // for n
|
||||
return NULL;
|
||||
} // getSavedGP
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}; // class SavedGrandPrix
|
||||
|
||||
#endif
|
||||
|
||||
/*EOF*/
|
@ -35,6 +35,7 @@ static PtrVector<UserConfigParam, REF> all_params;
|
||||
#define PARAM_DEFAULT(X) = X
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
#include "config/saved_grand_prix.hpp"
|
||||
#include "config/player.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
@ -51,6 +52,18 @@ UserConfigParam::~UserConfigParam()
|
||||
all_params.remove(this);
|
||||
} // ~UserConfigParam
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Writes an inner node.
|
||||
* \param stream the xml writer.
|
||||
* \param level determines indentation level.
|
||||
*/
|
||||
void UserConfigParam::writeInner(XMLWriter& stream, int level) const
|
||||
{
|
||||
std::string tab(level * 4,' ');
|
||||
stream << L" " << tab.c_str() << m_param_name.c_str() << L"=\""
|
||||
<< toString() << L"\"\n";
|
||||
} // writeInner
|
||||
|
||||
// ============================================================================
|
||||
GroupUserConfigParam::GroupUserConfigParam(const char* group_name,
|
||||
const char* comment)
|
||||
@ -60,31 +73,63 @@ GroupUserConfigParam::GroupUserConfigParam(const char* group_name,
|
||||
if(comment != NULL) m_comment = comment;
|
||||
} // GroupUserConfigParam
|
||||
|
||||
// ============================================================================
|
||||
GroupUserConfigParam::GroupUserConfigParam(const char* group_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment)
|
||||
{
|
||||
m_param_name = group_name;
|
||||
group->addChild(this);
|
||||
if(comment != NULL) m_comment = comment;
|
||||
} // GroupUserConfigParam
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::write(XMLWriter& stream) const
|
||||
{
|
||||
const int children_amount = m_children.size();
|
||||
const int attr_amount = m_attributes.size();
|
||||
|
||||
// comments
|
||||
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str();
|
||||
for(int n=0; n<children_amount; n++)
|
||||
for(int n=0; n<attr_amount; n++)
|
||||
{
|
||||
if(m_children[n]->m_comment.size() > 0)
|
||||
stream << L"\n " << m_children[n]->m_param_name.c_str()
|
||||
<< L" : " << m_children[n]->m_comment.c_str();
|
||||
if(m_attributes[n]->m_comment.size() > 0)
|
||||
stream << L"\n " << m_attributes[n]->m_param_name.c_str()
|
||||
<< L" : " << m_attributes[n]->m_comment.c_str();
|
||||
}
|
||||
|
||||
stream << L" -->\n <" << m_param_name.c_str() << "\n";
|
||||
|
||||
// actual values
|
||||
for (int n=0; n<attr_amount; n++)
|
||||
{
|
||||
m_attributes[n]->writeInner(stream, 1);
|
||||
}
|
||||
stream << L" >\n";
|
||||
const int children_amount = m_children.size();
|
||||
for (int n=0; n<children_amount; n++)
|
||||
{
|
||||
stream << L" " << m_children[n]->m_param_name.c_str() << L"=\""
|
||||
<< m_children[n]->toString() << L"\"\n";
|
||||
m_children[n]->writeInner(stream, 1);
|
||||
}
|
||||
stream << L" />\n\n";
|
||||
stream << L" </" << m_param_name.c_str() << ">\n\n";
|
||||
} // write
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::writeInner(XMLWriter& stream, int level) const
|
||||
{
|
||||
std::string tab(level * 4,' ');
|
||||
for(int i = 0; i < level; i++) tab =+ " ";
|
||||
const int children_amount = m_attributes.size();
|
||||
|
||||
stream << L" " << tab.c_str() << "<" << m_param_name.c_str() << "\n";
|
||||
|
||||
// actual values
|
||||
for (int n=0; n<children_amount; n++)
|
||||
{
|
||||
m_attributes[n]->writeInner(stream, level+1);
|
||||
}
|
||||
stream << L" " << tab.c_str() << "/>\n";
|
||||
} // writeInner
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::findYourDataInAChildOf(const XMLNode* node)
|
||||
{
|
||||
@ -96,10 +141,10 @@ void GroupUserConfigParam::findYourDataInAChildOf(const XMLNode* node)
|
||||
return;
|
||||
}
|
||||
|
||||
const int children_amount = m_children.size();
|
||||
for (int n=0; n<children_amount; n++)
|
||||
const int attributes_amount = m_attributes.size();
|
||||
for (int n=0; n<attributes_amount; n++)
|
||||
{
|
||||
m_children[n]->findYourDataInAnAttributeOf(child);
|
||||
m_attributes[n]->findYourDataInAnAttributeOf(child);
|
||||
}
|
||||
|
||||
} // findYourDataInAChildOf
|
||||
@ -116,11 +161,24 @@ irr::core::stringw GroupUserConfigParam::toString() const
|
||||
} // toString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::addChild(UserConfigParam* child)
|
||||
void GroupUserConfigParam::clearChildren()
|
||||
{
|
||||
m_children.clear();
|
||||
} // clearChildren
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::addChild(GroupUserConfigParam* child)
|
||||
{
|
||||
m_children.push_back(child);
|
||||
} // addChild
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GroupUserConfigParam::addChild(UserConfigParam* child)
|
||||
{
|
||||
m_attributes.push_back(child);
|
||||
} // addChild
|
||||
|
||||
|
||||
// ============================================================================
|
||||
IntUserConfigParam::IntUserConfigParam(int default_value,
|
||||
const char* param_name,
|
||||
@ -524,6 +582,7 @@ UserConfig::UserConfig()
|
||||
UserConfig::~UserConfig()
|
||||
{
|
||||
UserConfigParams::m_all_players.clearAndDeleteAll();
|
||||
UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll();
|
||||
} // ~UserConfig
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -553,7 +612,8 @@ void UserConfig::addDefaultPlayer()
|
||||
UserConfigParams::m_all_players.push_back( new GuestPlayerProfile() );
|
||||
|
||||
// Set the name as the default name for all players.
|
||||
UserConfigParams::m_all_players.push_back( new PlayerProfile(username.c_str()) );
|
||||
UserConfigParams::m_all_players.push_back(
|
||||
new PlayerProfile(username.c_str()) );
|
||||
|
||||
} // addDefaultPlayer
|
||||
|
||||
@ -584,7 +644,7 @@ bool UserConfig::loadConfig()
|
||||
XMLNode* root = file_manager->createXMLTree(filename);
|
||||
if(!root || root->getName() != "stkconfig")
|
||||
{
|
||||
std::cerr << "Could not read user config file file " << filename.c_str() << std::endl;
|
||||
std::cerr << "Could not read user config file file " << filename << std::endl;
|
||||
if(root) delete root;
|
||||
return false;
|
||||
}
|
||||
@ -631,12 +691,24 @@ bool UserConfig::loadConfig()
|
||||
{
|
||||
//std::string name;
|
||||
//players[i]->get("name", &name);
|
||||
UserConfigParams::m_all_players.push_back( new PlayerProfile(players[i]) );
|
||||
UserConfigParams::m_all_players.push_back(
|
||||
new PlayerProfile(players[i]) );
|
||||
}
|
||||
|
||||
// sort players by frequency of use
|
||||
UserConfigParams::m_all_players.insertionSort();
|
||||
|
||||
|
||||
// ---- Read Saved GP's
|
||||
UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll();
|
||||
std::vector<XMLNode*> saved_gps;
|
||||
root->getNodes("SavedGP", saved_gps);
|
||||
const int gp_amount = saved_gps.size();
|
||||
for (int i=0; i<gp_amount; i++)
|
||||
{
|
||||
UserConfigParams::m_saved_grand_prix_list.push_back(
|
||||
new SavedGrandPrix( saved_gps[i]) );
|
||||
}
|
||||
delete root;
|
||||
|
||||
return true;
|
||||
|
@ -49,14 +49,16 @@ using irr::core::stringc;
|
||||
using irr::core::stringw;
|
||||
|
||||
#include "graphics/camera.hpp"
|
||||
#include "io/xml_writer.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
class PlayerProfile;
|
||||
class SavedGrandPrix;
|
||||
class XMLNode;
|
||||
class XMLWriter;
|
||||
class PlayerProfile;
|
||||
|
||||
/**
|
||||
* The base of a set of small utilities to enable quickly adding/removing
|
||||
@ -71,6 +73,7 @@ protected:
|
||||
public:
|
||||
virtual ~UserConfigParam();
|
||||
virtual void write(XMLWriter& stream) const = 0;
|
||||
virtual void writeInner(XMLWriter& stream, int level = 0) const;
|
||||
virtual void findYourDataInAChildOf(const XMLNode* node) = 0;
|
||||
virtual void findYourDataInAnAttributeOf(const XMLNode* node) = 0;
|
||||
virtual irr::core::stringw toString() const = 0;
|
||||
@ -79,14 +82,22 @@ public:
|
||||
// ============================================================================
|
||||
class GroupUserConfigParam : public UserConfigParam
|
||||
{
|
||||
std::vector<UserConfigParam*> m_children;
|
||||
std::vector<UserConfigParam*> m_attributes;
|
||||
std::vector<GroupUserConfigParam*> m_children;
|
||||
public:
|
||||
GroupUserConfigParam(const char* name, const char* comment=NULL);
|
||||
GroupUserConfigParam(const char* param_name,
|
||||
GroupUserConfigParam* group,
|
||||
const char* comment = NULL);
|
||||
void write(XMLWriter& stream) const;
|
||||
void writeInner(XMLWriter& stream, int level = 0) const;
|
||||
void findYourDataInAChildOf(const XMLNode* node);
|
||||
void findYourDataInAnAttributeOf(const XMLNode* node);
|
||||
|
||||
void addChild(UserConfigParam* child);
|
||||
void addChild(GroupUserConfigParam* child);
|
||||
void clearChildren();
|
||||
|
||||
irr::core::stringw toString() const;
|
||||
}; // GroupUserConfigParam
|
||||
|
||||
@ -655,6 +666,9 @@ namespace UserConfigParams
|
||||
|
||||
PARAM_PREFIX PtrVector<PlayerProfile> m_all_players;
|
||||
|
||||
/** List of all saved GPs. */
|
||||
PARAM_PREFIX PtrVector<SavedGrandPrix> m_saved_grand_prix_list;
|
||||
|
||||
/** Some constants to bitmask to enable various messages to be printed. */
|
||||
enum { LOG_MEMORY = 0x0001,
|
||||
LOG_GUI = 0x0002,
|
||||
|
@ -1333,6 +1333,10 @@
|
||||
RelativePath="..\..\config\player.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\config\saved_grand_prix.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\config\stk_config.cpp"
|
||||
>
|
||||
@ -2531,6 +2535,10 @@
|
||||
RelativePath="..\..\config\player.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\config\saved_grand_prix.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\config\stk_config.hpp"
|
||||
>
|
||||
|
@ -183,7 +183,8 @@ GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id)
|
||||
* irrLicht, If no, create one. Returns true if new configuration was created,
|
||||
* otherwise false.
|
||||
*/
|
||||
bool DeviceManager::getConfigForGamepad(const int irr_id, const core::stringc& name,
|
||||
bool DeviceManager::getConfigForGamepad(const int irr_id,
|
||||
const core::stringc& name,
|
||||
GamepadConfig **config)
|
||||
{
|
||||
bool found = false;
|
||||
|
@ -22,8 +22,9 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "config/saved_grand_prix.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
@ -293,7 +294,7 @@ void RaceManager::startNew(bool from_overworld)
|
||||
// ==========================================================================
|
||||
m_kart_status.clear();
|
||||
|
||||
// Before thi
|
||||
|
||||
assert((unsigned int)m_num_karts == m_ai_kart_list.size()+m_player_karts.size());
|
||||
// First add the AI karts (randomly chosen)
|
||||
// ----------------------------------------
|
||||
@ -335,9 +336,25 @@ void RaceManager::startNew(bool from_overworld)
|
||||
init_gp_rank ++;
|
||||
}
|
||||
|
||||
// Then start the race with the first track
|
||||
// ========================================
|
||||
m_track_number = 0;
|
||||
|
||||
//We look if Player 1 has a saved version of this GP.
|
||||
SavedGrandPrix* gp = SavedGrandPrix::getSavedGP( StateManager::get()
|
||||
->getActivePlayerProfile(0)
|
||||
->getUniqueID(),
|
||||
m_grand_prix.getId(),
|
||||
m_difficulty,
|
||||
m_num_karts,
|
||||
m_player_karts.size());
|
||||
|
||||
// Start the race with the appropriate track
|
||||
// =========================================
|
||||
if(gp != NULL)
|
||||
{
|
||||
m_track_number = gp->getNextTrack();
|
||||
gp->loadKarts(m_kart_status);
|
||||
}
|
||||
else
|
||||
m_track_number = 0;
|
||||
|
||||
startNextRace();
|
||||
} // startNew
|
||||
@ -456,6 +473,42 @@ void RaceManager::next()
|
||||
m_track_number++;
|
||||
if(m_track_number<(int)m_tracks.size())
|
||||
{
|
||||
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
||||
{
|
||||
//Saving GP state
|
||||
//We look if Player 1 has already saved this GP.
|
||||
SavedGrandPrix* gp =
|
||||
SavedGrandPrix::getSavedGP(StateManager::get()
|
||||
->getActivePlayerProfile(0)
|
||||
->getUniqueID(),
|
||||
m_grand_prix.getId(),
|
||||
m_difficulty,
|
||||
m_num_karts,
|
||||
m_player_karts.size());
|
||||
if(gp != NULL)
|
||||
{
|
||||
//if so addept it
|
||||
gp->setKarts(m_kart_status);
|
||||
gp->setNextTrack(m_track_number);
|
||||
}
|
||||
else
|
||||
{
|
||||
//create a new entry
|
||||
UserConfigParams::m_saved_grand_prix_list.push_back(
|
||||
new SavedGrandPrix(
|
||||
StateManager::get()->getActivePlayerProfile(0)
|
||||
->getUniqueID(),
|
||||
m_grand_prix.getId(),
|
||||
m_difficulty,
|
||||
m_player_karts.size(),
|
||||
m_track_number,
|
||||
m_kart_status
|
||||
)
|
||||
);
|
||||
}
|
||||
user_config->saveConfig();
|
||||
}
|
||||
|
||||
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
||||
network_manager->beginReadySetGoBarrier();
|
||||
else
|
||||
@ -575,7 +628,19 @@ void RaceManager::exitRace(bool delete_world)
|
||||
if (m_major_mode==MAJOR_MODE_GRAND_PRIX && m_track_number==(int)m_tracks.size())
|
||||
{
|
||||
unlock_manager->getCurrentSlot()->grandPrixFinished();
|
||||
|
||||
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
||||
{
|
||||
//Delete saved GP
|
||||
SavedGrandPrix* gp =
|
||||
SavedGrandPrix::getSavedGP(StateManager::get()
|
||||
->getActivePlayerProfile(0)
|
||||
->getUniqueID(),
|
||||
m_grand_prix.getId(),
|
||||
m_difficulty,
|
||||
m_num_karts,
|
||||
m_player_karts.size());
|
||||
if(gp != NULL) gp->remove();
|
||||
}
|
||||
StateManager::get()->resetAndGoToScreen( MainMenuScreen::getInstance() );
|
||||
|
||||
bool someHumanPlayerWon = false;
|
||||
|
@ -242,6 +242,8 @@ private:
|
||||
|
||||
bool m_started_from_overworld;
|
||||
|
||||
public:
|
||||
|
||||
/** This data structure accumulates kart data and race result data from
|
||||
* each race. */
|
||||
struct KartStatus
|
||||
@ -282,6 +284,7 @@ private:
|
||||
{}
|
||||
|
||||
}; // KartStatus
|
||||
private:
|
||||
|
||||
/** The kart status data for each kart. */
|
||||
std::vector<KartStatus> m_kart_status;
|
||||
|
Loading…
Reference in New Issue
Block a user