Move TrackSector to WorldWithRank

This commit is contained in:
Benau 2016-09-28 13:48:32 +08:00
parent 3d89d5adc6
commit 100c23b3c0
15 changed files with 127 additions and 189 deletions

View File

@ -544,8 +544,7 @@ void ArenaAI::handleArenaItems(const float dt)
// Compensate the distance because this distance is straight to straight
// in graph node, so if kart to kart are not facing like so as, their real
// distance maybe smaller
const float dist_to_kart =
getKartDistance(m_closest_kart->getWorldKartId()) * 0.8f;
const float dist_to_kart = getKartDistance(m_closest_kart) * 0.8f;
switch(m_kart->getPowerup()->getType())
{

View File

@ -131,7 +131,7 @@ private:
virtual void findTarget() = 0;
virtual bool forceBraking() { return m_avoiding_item; }
virtual int getCurrentNode() const = 0;
virtual float getKartDistance(int to_id) const = 0;
virtual float getKartDistance(const AbstractKart* kart) const = 0;
virtual bool ignorePathFinding() { return false; }
virtual bool isWaiting() const = 0;
virtual bool isKartOnRoad() const = 0;

View File

@ -114,7 +114,7 @@ void BattleAI::findClosestKart(bool use_difficulty)
}
float dist_to_kart = m_graph->getDistance(getCurrentNode(),
m_world->getKartNode(kart->getWorldKartId()));
m_world->getSectorForKart(kart));
if (dist_to_kart <= distance)
{
distance = dist_to_kart;
@ -123,7 +123,7 @@ void BattleAI::findClosestKart(bool use_difficulty)
}
m_closest_kart = m_world->getKart(closest_kart_num);
m_closest_kart_node = m_world->getKartNode(closest_kart_num);
m_closest_kart_node = m_world->getSectorForKart(m_closest_kart);
m_closest_kart_point = m_closest_kart->getXYZ();
} // findClosestKart
@ -145,7 +145,7 @@ void BattleAI::findTarget()
//-----------------------------------------------------------------------------
int BattleAI::getCurrentNode() const
{
return m_world->getKartNode(m_kart->getWorldKartId());
return m_world->getSectorForKart(m_kart);
} // getCurrentNode
//-----------------------------------------------------------------------------
@ -155,9 +155,10 @@ bool BattleAI::isWaiting() const
} // isWaiting
//-----------------------------------------------------------------------------
float BattleAI::getKartDistance(int to_id) const
float BattleAI::getKartDistance(const AbstractKart* kart) const
{
return m_graph->getDistance(getCurrentNode(), m_world->getKartNode(to_id));
return m_graph->getDistance(getCurrentNode(),
m_world->getSectorForKart(kart));
} // getKartDistance
//-----------------------------------------------------------------------------

View File

@ -37,7 +37,7 @@ private:
virtual void findClosestKart(bool use_difficulty) OVERRIDE;
virtual void findTarget() OVERRIDE;
virtual int getCurrentNode() const OVERRIDE;
virtual float getKartDistance(int to_id) const OVERRIDE;
virtual float getKartDistance(const AbstractKart* kart) const OVERRIDE;
virtual bool isKartOnRoad() const OVERRIDE;
virtual bool isWaiting() const OVERRIDE;
public:

View File

@ -157,7 +157,7 @@ void SoccerAI::findClosestKart(bool use_difficulty)
}
m_closest_kart = m_world->getKart(closest_kart_num);
m_closest_kart_node = m_world->getKartNode(closest_kart_num);
m_closest_kart_node = m_world->getSectorForKart(m_closest_kart);
m_closest_kart_point = m_closest_kart->getXYZ();
} // findClosestKart
@ -187,8 +187,9 @@ void SoccerAI::findTarget()
{
// This AI will attack the other team ball chaser
int id = m_world->getBallChaser(m_opp_team);
m_target_point = m_world->getKart(id)->getXYZ();
m_target_node = m_world->getKartNode(id);
const AbstractKart* kart = m_world->getKart(id);
m_target_point = kart->getXYZ();
m_target_node = m_world->getSectorForKart(kart);
}
else
{
@ -453,7 +454,7 @@ float SoccerAI::rotateSlope(float old_slope, bool rotate_up)
//-----------------------------------------------------------------------------
int SoccerAI::getCurrentNode() const
{
return m_world->getKartNode(m_kart->getWorldKartId());
return m_world->getSectorForKart(m_kart);
} // getCurrentNode
//-----------------------------------------------------------------------------
@ -463,9 +464,10 @@ bool SoccerAI::isWaiting() const
} // isWaiting
//-----------------------------------------------------------------------------
float SoccerAI::getKartDistance(int to_id) const
float SoccerAI::getKartDistance(const AbstractKart* kart) const
{
return m_graph->getDistance(getCurrentNode(), m_world->getKartNode(to_id));
return m_graph->getDistance(getCurrentNode(),
m_world->getSectorForKart(kart));
} // getKartDistance
//-----------------------------------------------------------------------------

View File

@ -70,7 +70,7 @@ private:
virtual bool forceBraking() OVERRIDE
{ return m_avoiding_item || m_force_brake; }
virtual int getCurrentNode() const OVERRIDE;
virtual float getKartDistance(int to_id) const OVERRIDE;
virtual float getKartDistance(const AbstractKart* kart) const OVERRIDE;
virtual bool ignorePathFinding() OVERRIDE
{ return m_overtake_ball || m_chasing_ball; }
virtual bool isKartOnRoad() const OVERRIDE;

View File

@ -68,6 +68,7 @@
#include "tracks/drive_node.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "tracks/track_sector.hpp"
#include "utils/constants.hpp"
#include "utils/log.hpp" //TODO: remove after debugging is done
#include "utils/vs.hpp"
@ -1306,7 +1307,7 @@ void Kart::update(float dt)
if (lw && DriveGraph::get())
{
const int sector =
lw->getTrackSector(getWorldKartId()).getCurrentGraphNode();
lw->getTrackSector(getWorldKartId())->getCurrentGraphNode();
dist_to_sector = getXYZ().distance
(DriveGraph::get()->getNode(sector)->getCenter());

View File

@ -94,7 +94,6 @@ void LinearWorld::reset()
for(unsigned int i=0; i<kart_amount; i++)
{
m_kart_info[i].reset();
m_kart_info[i].getTrackSector()->update(m_karts[i]->getXYZ());
m_karts[i]->setWrongwayCounter(0);
} // next kart
@ -181,12 +180,12 @@ void LinearWorld::update(float dt)
// in the position of the kart (e.g. while falling the kart
// might get too close to another part of the track, shortly
// jump to position one, then on reset fall back to last)
if ((!kart_info.getTrackSector()->isOnRoad() &&
if ((!getTrackSector(n)->isOnRoad() &&
(!kart->getMaterial() ||
kart->getMaterial()->isDriveReset())) &&
!kart->isGhostKart())
continue;
kart_info.getTrackSector()->update(kart->getFrontXYZ());
getTrackSector(n)->update(kart->getFrontXYZ());
kart_info.m_overall_distance = kart_info.m_race_lap
* m_track->getTrackLength()
+ getDistanceDownTrackForKart(kart->getWorldKartId());
@ -380,24 +379,6 @@ void LinearWorld::newLap(unsigned int kart_index)
kart->getController()->newLap(kart_info.m_race_lap);
} // newLap
//-----------------------------------------------------------------------------
/** Gets the sector a kart is on. This function returns UNKNOWN_SECTOR if the
* kart_id is larger than the current kart info. This is necessary in the case
* that a collision with the track happens during resetAllKarts: at this time
* m_kart_info is not initialised (and has size 0), so it would trigger this
* assert. While this normally does not happen, it is useful for track
* designers that STK does not crash.
* \param kart_id The world kart id of the kart for which to return
* the sector.
*/
int LinearWorld::getSectorForKart(const AbstractKart *kart) const
{
if(kart->getWorldKartId()>=m_kart_info.size())
return Graph::UNKNOWN_SECTOR;
return m_kart_info[kart->getWorldKartId()].getTrackSector()
->getCurrentGraphNode();
} // getSectorForKart
//-----------------------------------------------------------------------------
/** Returns the distance the kart has travelled along the track since
* crossing the start line..
@ -405,8 +386,7 @@ int LinearWorld::getSectorForKart(const AbstractKart *kart) const
*/
float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].getTrackSector()->getDistanceFromStart();
return getTrackSector(kart_id)->getDistanceFromStart();
} // getDistanceDownTrackForKart
//-----------------------------------------------------------------------------
@ -416,8 +396,7 @@ float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const
*/
float LinearWorld::getDistanceToCenterForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].getTrackSector()->getDistanceToCenter();
return getTrackSector(kart_id)->getDistanceToCenter();
} // getDistanceToCenterForKart
//-----------------------------------------------------------------------------
@ -635,13 +614,13 @@ unsigned int LinearWorld::getNumberOfRescuePositions() const
// ------------------------------------------------------------------------
unsigned int LinearWorld::getRescuePositionIndex(AbstractKart *kart)
{
KartInfo& info = m_kart_info[kart->getWorldKartId()];
const unsigned int kart_id = kart->getWorldKartId();
info.getTrackSector()->rescue();
getTrackSector(kart_id)->rescue();
// Setting XYZ for the kart is important since otherwise the kart
// will not detect the right material again when doing the next
// raycast to detect where it is driving on (--> potential rescue loop)
return info.getTrackSector()->getCurrentGraphNode();
return getTrackSector(kart_id)->getCurrentGraphNode();
} // getRescuePositionIndex
// ------------------------------------------------------------------------
@ -864,7 +843,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
// If the kart can go in more than one directions from the current track
// don't do any reverse message handling, since it is likely that there
// will be one direction in which it isn't going backwards anyway.
int sector = m_kart_info[i].getTrackSector()->getCurrentGraphNode();
int sector = getTrackSector(i)->getCurrentGraphNode();
if (DriveGraph::get()->getNumberOfSuccessors(sector) > 1)
return;
@ -915,3 +894,8 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
} // checkForWrongDirection
//-----------------------------------------------------------------------------
void LinearWorld::setLastTriggeredCheckline(unsigned int kart_index, int index)
{
if (m_kart_info.size() == 0) return;
getTrackSector(kart_index)->setLastTriggeredCheckline(index);
} // setLastTriggeredCheckline

View File

@ -21,7 +21,6 @@
#include <vector>
#include "modes/world_with_rank.hpp"
#include "tracks/track_sector.hpp"
#include "utils/aligned_array.hpp"
class SFXBase;
@ -78,9 +77,6 @@ private:
* track-length plus distance-along-track). */
float m_overall_distance;
/** Stores the current graph node and track coordinates etc. */
TrackSector m_track_sector;
/** Initialises all fields. */
KartInfo() { reset(); }
// --------------------------------------------------------------------
@ -92,14 +88,7 @@ private:
m_time_at_last_lap = 99999.9f;
m_estimated_finish = -1.0f;
m_overall_distance = 0.0f;
m_track_sector.reset();
} // reset
// --------------------------------------------------------------------
/** Returns a pointer to the current node object. */
TrackSector *getTrackSector() {return &m_track_sector; }
// --------------------------------------------------------------------
/** Returns a pointer to the current node object. */
const TrackSector *getTrackSector() const {return &m_track_sector; }
};
// ------------------------------------------------------------------------
@ -124,7 +113,6 @@ public:
virtual ~LinearWorld();
virtual void update(float delta) OVERRIDE;
int getSectorForKart(const AbstractKart *kart) const;
float getDistanceDownTrackForKart(const int kart_id) const;
float getDistanceToCenterForKart(const int kart_id) const;
float getEstimatedFinishTime(const int kart_id) const;
@ -149,14 +137,6 @@ public:
// ------------------------------------------------------------------------
/** Override settings from base class */
virtual bool useChecklineRequirements() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
/** Returns true if the kart is on a valid driveline quad.
* \param kart_index Index of the kart. */
bool isOnRoad(unsigned int kart_index) const
{
return m_kart_info[kart_index].getTrackSector()->isOnRoad();
} // isOnRoad
// ------------------------------------------------------------------------
/** Returns the number of laps a kart has completed.
* \param kart_index World index of the kart. */
@ -165,21 +145,8 @@ public:
assert(kart_index < m_kart_info.size());
return m_kart_info[kart_index].m_race_lap;
} // getkartLap
// ------------------------------------------------------------------------
/** Returns the track_sector object for the specified kart.
* \param kart_index World index of the kart. */
TrackSector& getTrackSector(unsigned int kart_index)
{
return m_kart_info[kart_index].m_track_sector;
} // getTrackSector
// ------------------------------------------------------------------------
void setLastTriggeredCheckline(unsigned int kart_index, int index)
{
if (m_kart_info.size() == 0)
return;
m_kart_info[kart_index].m_track_sector.setLastTriggeredCheckline(index);
}
void setLastTriggeredCheckline(unsigned int kart_index, int index);
// ------------------------------------------------------------------------
/** Returns how far the kart has driven so far (i.e.
* number-of-laps-finished times track-length plus distance-on-track.

View File

@ -71,12 +71,6 @@ SoccerWorld::~SoccerWorld()
delete m_ball_track_sector;
m_ball_track_sector = NULL;
for (unsigned int i = 0; i < m_kart_track_sector.size(); i++)
{
delete m_kart_track_sector[i];
}
m_kart_track_sector.clear();
} // ~SoccerWorld
//-----------------------------------------------------------------------------
@ -98,10 +92,8 @@ void SoccerWorld::init()
if (m_track->hasNavMesh())
{
// Init track sector if navmesh is found
// Init track sector for ball if navmesh is found
m_ball_track_sector = new TrackSector();
for (unsigned int i = 0; i < m_karts.size(); i++)
m_kart_track_sector.push_back(new TrackSector());
}
TrackObjectManager* tom = getTrack()->getTrackObjectManager();
@ -160,8 +152,6 @@ void SoccerWorld::reset()
if (m_track->hasNavMesh())
{
m_ball_track_sector->reset();
for (unsigned int i = 0; i < m_karts.size(); i++)
m_kart_track_sector[i]->reset();
}
initKartList();
@ -192,7 +182,7 @@ void SoccerWorld::update(float dt)
updateBallPosition(dt);
if (m_track->hasNavMesh())
{
updateKartNodes();
updateSectorForKarts();
updateAIData();
}
@ -450,22 +440,6 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
return new_kart;
} // createKart
//-----------------------------------------------------------------------------
/** Updates the m_kart_on_node value of each kart to localize it
* on the navigation mesh.
*/
void SoccerWorld::updateKartNodes()
{
if (isRaceOver()) return;
const unsigned int n = getNumKarts();
for (unsigned int i = 0; i < n; i++)
{
if (m_karts[i]->isEliminated()) continue;
m_kart_track_sector[i]->update(m_karts[i]->getXYZ());
}
} // updateKartNodes
//-----------------------------------------------------------------------------
/** Localize the ball on the navigation mesh.
*/
@ -504,13 +478,6 @@ void SoccerWorld::updateBallPosition(float dt)
} // updateBallPosition
//-----------------------------------------------------------------------------
int SoccerWorld::getKartNode(unsigned int kart_id) const
{
assert(kart_id < m_kart_track_sector.size());
return m_kart_track_sector[kart_id]->getCurrentGraphNode();
} // getKartNode
//-----------------------------------------------------------------------------
int SoccerWorld::getBallNode() const
{
@ -756,10 +723,3 @@ void SoccerWorld::setAITeam()
Log::debug("SoccerWorld","blue AI: %d red AI: %d", m_blue_ai, m_red_ai);
} // setAITeam
//-----------------------------------------------------------------------------
bool SoccerWorld::isOnRoad(unsigned int kart_id) const
{
assert(m_kart_track_sector.size() > kart_id);
return m_kart_track_sector[kart_id]->isOnRoad();
} // isOnRoad

View File

@ -280,7 +280,6 @@ private:
std::map<int, unsigned int> m_kart_position_map;
/** Data generated from navmesh */
std::vector<TrackSector*> m_kart_track_sector;
TrackSector* m_ball_track_sector;
int m_red_ai;
@ -290,8 +289,6 @@ private:
/** Set the team for the karts */
void initKartList();
/** Function to update the locations of all karts on the polygon map */
void updateKartNodes();
/** Function to update the location the ball on the polygon map */
void updateBallPosition(float dt);
/** Function to update data for AI usage. */
@ -356,10 +353,6 @@ public:
m_blue_score_times : m_red_score_times);
}
// ------------------------------------------------------------------------
int getKartNode(unsigned int kart_id) const;
// ------------------------------------------------------------------------
bool isOnRoad(unsigned int kart_id) const;
// ------------------------------------------------------------------------
int getBallNode() const;
// ------------------------------------------------------------------------
const Vec3& getBallPosition() const

View File

@ -30,7 +30,6 @@
#include "states_screens/race_gui_base.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
#include "tracks/track_sector.hpp"
#include "utils/constants.hpp"
#include <string>
@ -65,12 +64,6 @@ void ThreeStrikesBattle::init()
WorldWithRank::init();
m_display_rank = false;
m_kart_info.resize(m_karts.size());
if (m_track->hasNavMesh())
{
// Init track sector if navmesh is found
for (unsigned int i = 0; i < m_karts.size(); i++)
m_kart_track_sector.push_back(new TrackSector());
}
} // ThreeStrikesBattle
//-----------------------------------------------------------------------------
@ -86,12 +79,6 @@ ThreeStrikesBattle::~ThreeStrikesBattle()
// freed once all refernces to it (which will happen once all
// karts are being freed, which would have a pointer to this mesh)
irr_driver->removeMeshFromCache(m_tire);
for (unsigned int i = 0; i < m_kart_track_sector.size(); i++)
{
delete m_kart_track_sector[i];
}
m_kart_track_sector.clear();
} // ~ThreeStrikesBattle
//-----------------------------------------------------------------------------
@ -145,12 +132,6 @@ void ThreeStrikesBattle::reset()
m_track->getTrackObjectManager()->removeObject(obj);
}
m_tires.clearWithoutDeleting();
if (m_track->hasNavMesh())
{
for (unsigned int i = 0; i < kart_amount; i++)
m_kart_track_sector[i]->reset();
}
} // reset
//-----------------------------------------------------------------------------
@ -325,7 +306,7 @@ void ThreeStrikesBattle::update(float dt)
WorldWithRank::updateTrack(dt);
if (m_track->hasNavMesh())
updateKartNodes();
updateSectorForKarts();
// insert blown away tire(s) now if was requested
while (m_insert_tire > 0)
@ -475,31 +456,6 @@ bool ThreeStrikesBattle::isRaceOver()
return getCurrentNumKarts()==1 || getCurrentNumPlayers()==0;
} // isRaceOver
//-----------------------------------------------------------------------------
/** Updates the m_on_node value of each kart to localize it
* on the navigation mesh.
*/
void ThreeStrikesBattle::updateKartNodes()
{
if (isRaceOver()) return;
const unsigned int n = getNumKarts();
for (unsigned int i = 0; i < n; i++)
{
if (m_karts[i]->isEliminated()) continue;
m_kart_track_sector[i]->update(m_karts[i]->getXYZ());
}
} // updateKartNodes
//-----------------------------------------------------------------------------
/** Get the which node the kart located in navigation mesh.
*/
int ThreeStrikesBattle::getKartNode(unsigned int kart_id) const
{
assert(kart_id < m_kart_track_sector.size());
return m_kart_track_sector[kart_id]->getCurrentGraphNode();
} // getKartNode
//-----------------------------------------------------------------------------
/** Called when the race finishes, i.e. after playing (if necessary) an
* end of race animation. It updates the time for all karts still racing,
@ -565,10 +521,3 @@ void ThreeStrikesBattle::enterRaceOverState()
}
} // enterRaceOverState
//-----------------------------------------------------------------------------
bool ThreeStrikesBattle::isOnRoad(unsigned int kart_id) const
{
assert(m_kart_track_sector.size() > kart_id);
return m_kart_track_sector[kart_id]->isOnRoad();
} // isOnRoad

View File

@ -29,7 +29,6 @@
#include <string>
class PhysicalObject;
class TrackSector;
/**
* \brief An implementation of World, to provide the 3 strikes battle game mode
@ -71,11 +70,6 @@ private:
PtrVector<TrackObject, REF> m_tires;
std::vector<TrackSector*> m_kart_track_sector;
/** Function to update the locations of all karts on the navigation map */
void updateKartNodes();
/** Profiling usage */
int m_total_rescue;
int m_frame_count;
@ -118,8 +112,6 @@ public:
virtual void kartAdded(AbstractKart* kart, scene::ISceneNode* node) OVERRIDE;
virtual void enterRaceOverState() OVERRIDE;
int getKartNode(unsigned int kart_id) const;
bool isOnRoad(unsigned int kart_id) const;
void updateKartRanks();
void increaseRescueCount() { m_total_rescue++; }
}; // ThreeStrikesBattles

View File

@ -20,11 +20,23 @@
#include "karts/abstract_kart.hpp"
#include "karts/kart_properties.hpp"
#include "race/history.hpp"
#include "tracks/graph.hpp"
#include "tracks/track.hpp"
#include "tracks/track_sector.hpp"
#include "utils/log.hpp"
#include <iostream>
//-----------------------------------------------------------------------------
WorldWithRank::~WorldWithRank()
{
for (unsigned int i = 0; i < m_kart_track_sector.size(); i++)
{
delete m_kart_track_sector[i];
}
m_kart_track_sector.clear();
} // ~WorldWithRank
//-----------------------------------------------------------------------------
void WorldWithRank::init()
{
@ -39,8 +51,23 @@ void WorldWithRank::init()
#endif
stk_config->getAllScores(&m_score_for_position, getNumKarts());
// Don't init track sector if navmesh is not found in arena
if ((m_track->isArena() || m_track->isSoccer()) && !m_track->hasNavMesh())
return;
for (unsigned int i = 0; i < m_karts.size(); i++)
m_kart_track_sector.push_back(new TrackSector());
} // init
//-----------------------------------------------------------------------------
void WorldWithRank::reset()
{
World::reset();
for (unsigned int i = 0; i < m_kart_track_sector.size(); i++)
getTrackSector(i)->update(m_karts[i]->getXYZ());
} // reset
//-----------------------------------------------------------------------------
/** Returns the kart with a given position.
* \param p The position of the kart, 1<=p<=num_karts).
@ -184,3 +211,45 @@ int WorldWithRank::getScoreForPosition(int p)
assert(p - 1 <(int) m_score_for_position.size());
return m_score_for_position[p - 1];
} // getScoreForPosition
//-----------------------------------------------------------------------------
/** Returns true if the kart is on a valid graph quad.
* \param kart_index Index of the kart.
*/
bool WorldWithRank::isOnRoad(unsigned int kart_index) const
{
return getTrackSector(kart_index)->isOnRoad();
} // isOnRoad
//-----------------------------------------------------------------------------
/** Gets the sector a kart is on. This function returns UNKNOWN_SECTOR if the
* kart_id is larger than the current kart sector. This is necessary in the
* case that a collision with the track happens during resetAllKarts: at this
* time m_kart_track_sector is not initialised (and has size 0), so it would
* trigger this assert. While this normally does not happen, it is useful for
* track designers that STK does not crash.
* \param kart_id The world kart id of the kart for which to return
* the sector.
*/
int WorldWithRank::getSectorForKart(const AbstractKart *kart) const
{
if (kart->getWorldKartId() >= m_kart_track_sector.size())
return Graph::UNKNOWN_SECTOR;
return getTrackSector(kart->getWorldKartId())->getCurrentGraphNode();
} // getSectorForKart
//-----------------------------------------------------------------------------
/** Localize each kart on the graph using its center xyz.
*/
void WorldWithRank::updateSectorForKarts()
{
if (isRaceOver()) return;
const unsigned int n = getNumKarts();
assert(n == m_kart_track_sector.size());
for (unsigned int i = 0; i < n; i++)
{
if (m_karts[i]->isEliminated()) continue;
getTrackSector(i)->update(m_karts[i]->getXYZ());
}
} // updateSectorForKarts

View File

@ -23,6 +23,7 @@
#include "modes/world.hpp"
class AbstractKart;
class TrackSector;
/**
* A WorldWithRank is a world where the karts are ranked. This is the base
@ -60,12 +61,20 @@ protected:
unsigned int getClosestStartPoint(AbstractKart *kart);
/** Stores the current graph node and track coordinates for each kart. */
std::vector<TrackSector*> m_kart_track_sector;
// ------------------------------------------------------------------------
void updateSectorForKarts();
public:
WorldWithRank() : World() {}
virtual ~WorldWithRank();
/** call just after instanciating. can't be moved to the contructor as child
classes must be instanciated, otherwise polymorphism will fail and the
results will be incorrect */
virtual void init() OVERRIDE;
virtual void reset() OVERRIDE;
bool displayRank() const { return m_display_rank; }
@ -76,6 +85,18 @@ public:
AbstractKart* getKartAtPosition(unsigned int p) const;
virtual int getScoreForPosition(int p);
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
// ------------------------------------------------------------------------
/** Returns the track_sector object for the specified kart.
* \param kart_index World index of the kart. */
TrackSector* getTrackSector(unsigned int kart_index) const
{
assert(kart_index < m_kart_track_sector.size());
return m_kart_track_sector[kart_index];
} // getTrackSector
// ------------------------------------------------------------------------
bool isOnRoad(unsigned int kart_index) const;
// ------------------------------------------------------------------------
int getSectorForKart(const AbstractKart *kart) const;
}; // WorldWithRank