made section handling and lap counting a little more modular (nothing definitive, just an incremental step)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2302 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2008-09-25 00:31:21 +00:00
parent e48907a1cf
commit 3477a7f7e2
6 changed files with 65 additions and 25 deletions

View File

@@ -388,7 +388,7 @@ void Kart::reset()
}
RaceManager::getTrack()->spatialToTrack(m_curr_track_coords, getXYZ(),
m_track_sector );
m_track_sector );
m_vehicle->applyEngineForce (0.0f, 2);
m_vehicle->applyEngineForce (0.0f, 3);
@@ -409,9 +409,33 @@ void Kart::reset()
TerrainInfo::update(getXYZ());
} // reset
//-----------------------------------------------------------------------------
int Kart::getSector() const
{
// this method only makes sense for linear races
assert(RaceManager::getWorld()->isLinearRace());
return m_track_sector;
}
//-----------------------------------------------------------------------------
float Kart::getDistanceDownTrack() const
{
// this method only makes sense for linear races
assert(RaceManager::getWorld()->isLinearRace());
return m_curr_track_coords.getY();
}
//-----------------------------------------------------------------------------
float Kart::getDistanceToCenter () const
{
// this method only makes sense for linear races
assert(RaceManager::getWorld()->isLinearRace());
return m_curr_track_coords.getX();
}
//-----------------------------------------------------------------------------
void Kart::doLapCounting ()
{
// this method only makes sense for linear races
assert(RaceManager::getWorld()->isLinearRace());
bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords.getY() < 20.0f;
if ( newLap )
{
@@ -695,7 +719,17 @@ void Kart::update(float dt)
// Check if any herring was hit.
herring_manager->hitHerring(this);
if(RaceManager::getWorld()->isLinearRace()) updateSectorProgression();
if(!m_finished_race && RaceManager::getWorld()->isLinearRace()) doLapCounting();
processSkidMarks();
}
void Kart::updateSectorProgression()
{
// this method only makes sense for linear races
assert(RaceManager::getWorld()->isLinearRace());
// Save the last valid sector for forced rescue on shortcuts
if(m_track_sector != Track::UNKNOWN_SECTOR &&
!m_rescue )
@@ -737,11 +771,8 @@ void Kart::update(float dt)
}
RaceManager::getTrack()->spatialToTrack( m_curr_track_coords,
getXYZ(),
m_track_sector );
if(!m_finished_race) doLapCounting();
processSkidMarks();
getXYZ(),
m_track_sector );
} // update
//-----------------------------------------------------------------------------

View File

@@ -112,6 +112,8 @@ protected:
/** Search the given branch of objects that match the wheel names
and if so assign them to wheel_* variables */
void load_wheels (ssgBranch* obj);
virtual void doLapCounting ();
public:
Kart(const std::string& kart_name, int position,
@@ -131,9 +133,12 @@ public:
{ m_collectable.set(t, n); }
virtual void setPosition (int p)
{ m_race_position = p; }
int getSector () const { return m_track_sector; }
float getDistanceDownTrack() const { return m_curr_track_coords.getY(); }
float getDistanceToCenter () const { return m_curr_track_coords.getX(); }
// these methods only makes sense for linear races
int getSector () const;
float getDistanceDownTrack() const;
float getDistanceToCenter () const;
Attachment *getAttachment () { return &m_attachment; }
void setAttachmentType (attachmentType t, float time_left=0.0f,
Kart*k=NULL)
@@ -226,8 +231,9 @@ public:
virtual void reset ();
virtual void handleZipper ();
virtual void crashed (Kart *k);
virtual void doLapCounting ();
virtual void update (float dt);
void updateSectorProgression();
virtual void raceFinished (float time);
};

View File

@@ -68,8 +68,7 @@ World::World()
m_clock.setMode( CHRONO );
// FIXME - not really used yet, only a placeholder to be implemented fully later
m_order_karts = true;
m_linear_race = true;
m_use_highscores = true;

View File

@@ -98,9 +98,16 @@ protected:
bool m_faster_music_active; // true if faster music was activated
/** whether this kind of race orders karts from first to last
/** whether this kind of race orders karts from first to last, whether
* you can count laps, have some sort of progression record, whether
* sectors and drivelines are used, etc. This will be off for e.g. battle mode.
*/
bool m_linear_race;
/** Whether highscores should be used for this kind of race.
* True by default, change to false in a child class to disable.
*/
bool m_order_karts;
bool m_use_highscores;
void updateRacePosition(int k);
void updateHighscores ();
@@ -114,10 +121,6 @@ protected:
Track* m_track;
/** Whether highscores should be used for this kind of race.
* True by default, change to false in a child class to disable.
*/
bool m_use_highscores;
public:
/** debug text that will be overlaid to the screen */
@@ -129,10 +132,6 @@ public:
virtual void restartRace();
void disableRace(); // Put race into limbo phase
/** whether this kind of race orders karts from first to last
*/
bool areKartsOrdered();
PlayerKart *getPlayerKart(int player) const { return m_player_karts[player]; }
unsigned int getCurrentNumLocalPlayers() const { return m_local_player_karts.size(); }
PlayerKart *getLocalPlayerKart(int n) const { return m_local_player_karts[n]; }
@@ -187,6 +186,11 @@ public:
m_clock.getMode() != CLOCK_NONE); }
/** whether this kind of race orders karts from first to last, whether
* you can count laps, have some sort of progression record, whether
* sectors and drivelines are used, etc. This will be off for e.g. battle mode.
*/
bool isLinearRace() const { return m_linear_race; }
};
#endif

View File

@@ -462,7 +462,7 @@ bool DefaultRobot::do_wheelie ( const int STEPS )
step_coord = getXYZ()+vel_normal* m_kart_properties->getKartLength() * float(i);
RaceManager::getTrack()->spatialToTrack(step_track_coord, step_coord,
m_future_sector );
m_future_sector );
distance = step_track_coord[0] > 0.0f ? step_track_coord[0]
: -step_track_coord[0];

View File

@@ -360,7 +360,7 @@ int Track::findOutOfRoadSector
*/
int Track::spatialToTrack
(
Vec3& dst,
Vec3& dst, /* out */
const Vec3& POS,
const int SECTOR
) const