Set the world kart id in the constructor of karts, and not

later in a separate call.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10788 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-02-02 05:21:14 +00:00
parent 8dd5b8461c
commit 613173ff3d
8 changed files with 27 additions and 14 deletions

View File

@ -70,7 +70,8 @@
* \param is_first_kart Indicates whether this is the first *player* kart
* \param init_transform The initial position and rotation for this kart.
*/
Kart::Kart (const std::string& ident, Track* track, int position, bool is_first_kart,
Kart::Kart (const std::string& ident, unsigned int world_kart_id,
Track* track, int position, bool is_first_kart,
const btTransform& init_transform, RaceManager::KartType type)
: TerrainInfo(1),
Moveable(), EmergencyAnimation(this), MaxSpeed(this), m_powerup(this)
@ -92,6 +93,7 @@ Kart::Kart (const std::string& ident, Track* track, int position, bool is_first_
m_kart_model = m_kart_properties->getKartModelCopy();
m_initial_position = position;
m_race_position = position;
m_world_kart_id = world_kart_id;
m_collected_energy = 0;
m_finished_race = false;
m_finish_time = 0.0f;

View File

@ -215,11 +215,10 @@ protected:
KartModel* m_kart_model;
public:
Kart(const std::string& ident, Track* track, int position, bool is_first_kart,
Kart(const std::string& ident, unsigned int world_kart_id,
Track* track, int position, bool is_first_kart,
const btTransform& init_transform, RaceManager::KartType type);
virtual ~Kart();
unsigned int getWorldKartId() const { return m_world_kart_id; }
void setWorldKartId(unsigned int n) { m_world_kart_id=n; }
void loadData(RaceManager::KartType type, bool is_first_kart, Track* track,
bool animatedModel);
virtual void updateGraphics(float dt, const Vec3& off_xyz,
@ -253,6 +252,9 @@ public:
bool playCustomSFX (unsigned int type);
void setController(Controller *controller);
// ------------------------------------------------------------------------
/** Returns the index of this kart in world. */
unsigned int getWorldKartId() const { return m_world_kart_id; }
// ------------------------------------------------------------------------
/** Returns this kart's kart model. */
KartModel* getKartModel() { return m_kart_model; }
// ------------------------------------------------------------------------

View File

@ -20,11 +20,12 @@
#include "items/item.hpp"
KartWithStats::KartWithStats(const std::string& ident, Track* track,
KartWithStats::KartWithStats(const std::string& ident,
unsigned int world_kart_id, Track* track,
int position, bool is_first_kart,
const btTransform& init_transform,
RaceManager::KartType type)
: Kart(ident, track, position, is_first_kart,
: Kart(ident, world_kart_id, track, position, is_first_kart,
init_transform, type)
{
reset();

View File

@ -65,7 +65,8 @@ private:
float m_skidding_time;
public:
KartWithStats(const std::string& ident, Track* track,
KartWithStats(const std::string& ident,
unsigned int world_kart_id, Track* track,
int position, bool is_first_kart,
const btTransform& init_transform,
RaceManager::KartType type);

View File

@ -91,8 +91,12 @@ Kart *ProfileWorld::createKart(const std::string &kart_ident, int index,
{
btTransform init_pos = m_track->getStartTransform(index);
Kart *new_kart = new KartWithStats(kart_ident, m_track, index+1,
false, init_pos,
Kart *new_kart = new KartWithStats(kart_ident,
/*world kart id*/ index,
m_track,
/*position*/ index+1,
/*is_first_kart*/false,
init_pos,
RaceManager::KT_AI);
Controller *controller = loadAIController(new_kart);

View File

@ -144,7 +144,6 @@ void World::init()
Kart* newkart = createKart(kart_ident, i, local_player_id,
global_player_id);
m_karts.push_back(newkart);
newkart->setWorldKartId(m_karts.size()-1);
m_track->adjustForFog(newkart->getNode());
} // for i
@ -190,7 +189,7 @@ Kart *World::createKart(const std::string &kart_ident, int index,
{
int position = index+1;
btTransform init_pos = m_track->getStartTransform(index);
Kart *new_kart = new Kart(kart_ident, m_track, position,
Kart *new_kart = new Kart(kart_ident, index,m_track, position,
(local_player_id == 0), init_pos,
race_manager->getKartType(index));
Controller *controller = NULL;

View File

@ -23,10 +23,13 @@
/** A network kart. On the server, it receives its control information (steering etc)
from the network manager.
*/
NetworkKart::NetworkKart(const std::string &kart_name, Track* track, int position,
NetworkKart::NetworkKart(const std::string &kart_name,
unsigned int world_kart_id, Track* track,
int position,
const btTransform &init_transform, int global_player_id,
RaceManager::KartType type)
: Kart(kart_name, track, position, false, init_transform, type)
: Kart(kart_name, world_kart_id, track, position,
/*is_first_kart*/false, init_transform, type)
{
m_global_player_id = global_player_id;
} // NetworkKart

View File

@ -28,7 +28,8 @@ class NetworkKart : public Kart
private:
int m_global_player_id; // to identify this kart to the network manager
public:
NetworkKart(const std::string& kart_name, Track* track, int position,
NetworkKart(const std::string& kart_name, unsigned int world_kart_id,
Track* track, int position,
const btTransform& init_transform,
int global_player_id, RaceManager::KartType type);
void setControl(const KartControl& kc);