Restructured modes to be easier to inerhit from:

- cleanly split into constructor and init()
  phase
- added new isRaceFinished() function
Some minor code cleanup.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3900 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-08-21 13:05:52 +00:00
parent ef175e94d4
commit 6318008c87
12 changed files with 53 additions and 23 deletions

View File

@@ -29,7 +29,6 @@
FollowTheLeaderRace::FollowTheLeaderRace() : LinearWorld()
{
m_leader_intervals = stk_config->m_leader_intervals;
LinearWorld::init();
m_use_highscores = false; // disable high scores
TimedRace::setClockMode(COUNTDOWN, m_leader_intervals[0]);
}
@@ -85,14 +84,23 @@ void FollowTheLeaderRace::countdownReachedZero()
// The follow the leader race is over if there is only one kart left,
// or if all players have gone
if(getCurrentNumKarts()==2 || getCurrentNumPlayers()==0)
if(isRaceOver())
{
// Note: LinearWorld::terminateRace adds the scores for all remaining
// karts in the race.
TimedRace::enterRaceOverState();
enterRaceOverState();
return;
}
}
//-----------------------------------------------------------------------------
/** The follow the leader race is over if there is only one kart left,
* or if all players have gone.
*/
bool FollowTheLeaderRace::isRaceOver()
{
return getCurrentNumKarts()==2 || getCurrentNumPlayers()==0;
} // isRaceOver
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::onGo()
{

View File

@@ -40,6 +40,7 @@ public:
virtual bool useFastMusicNearEnd() const { return false; }
virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo();
virtual bool isRaceOver();
virtual bool raceHasLaps(){ return false; }
/** Called by the race result GUI at the end of the race to know the final order

View File

@@ -20,6 +20,16 @@
#include "modes/profile_world.hpp"
#include "robots/default_robot.hpp"
//-----------------------------------------------------------------------------
/** The constructor sets the number of (local) players to 0, since only AI
* karts are used.
*/
ProfileWorld::ProfileWorld()
{
race_manager->setNumPlayers(0);
race_manager->setNumLocalPlayers(0);
} // ProfileWorld
//-----------------------------------------------------------------------------
/** Prints the profile statistic and exits!!
*/

View File

@@ -26,11 +26,16 @@ class Kart;
class ProfileWorld : public StandardRace
{
private:
int m_frame_count;
protected:
virtual Kart *createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
const btTransform &init_pos);
public:
ProfileWorld();
virtual ~ProfileWorld();
/** Returns identifier for this world. */
virtual std::string getInternalCode() const {return "PROFILE"; }

View File

@@ -84,10 +84,18 @@ void StandardRace::update(float delta)
{
// Set delay mode to have time for camera animation, and
// to give the AI some time to get non-estimated timings
TimedRace::enterRaceOverState(true /* delay */);
enterRaceOverState(true /* delay */);
}
} // update
//-----------------------------------------------------------------------------
/** Returns tru if the race is finished, i.e. all player karts are finished.
*/
bool StandardRace::isRaceOver()
{
return race_manager->allPlayerFinished();
} // isRaceOver
//-----------------------------------------------------------------------------
void StandardRace::getDefaultCollectibles(int& collectible_type, int& amount)
{

View File

@@ -27,11 +27,12 @@
class StandardRace : public LinearWorld
{
public:
StandardRace();
StandardRace();
virtual ~StandardRace();
// clock events
virtual void onGo();
virtual bool isRaceOver();
virtual void terminateRace();
// overriding World methods

View File

@@ -176,7 +176,7 @@ void ThreeStrikesBattle::update(float delta)
World::update(delta);
// check if over
if(getCurrentNumKarts()==1 || getCurrentNumPlayers()==0)
if(isRaceOver())
{
// Add the results for the remaining kart
for(int i=0; i<(int)race_manager->getNumKarts(); i++)
@@ -189,6 +189,14 @@ void ThreeStrikesBattle::update(float delta)
}
} // update
//-----------------------------------------------------------------------------
/** The battle is over if only one kart is left, or no player kart.
*/
bool ThreeStrikesBattle::isRaceOver()
{
return getCurrentNumKarts()==1 || getCurrentNumPlayers()==0;
} // isRaceOver
//-----------------------------------------------------------------------------
void ThreeStrikesBattle::restartRace()
{

View File

@@ -44,6 +44,7 @@ public:
// clock events
virtual void onGo();
virtual bool isRaceOver();
virtual void terminateRace();
// overriding World methods

View File

@@ -61,6 +61,7 @@ World::World() : TimedRace()
{
m_physics = NULL;
m_race_gui = NULL;
TimedRace::setClockMode( CHRONO );
} // World
// ----------------------------------------------------------------------------
@@ -78,7 +79,6 @@ void World::init()
m_eliminated_karts = 0;
m_eliminated_players = 0;
TimedRace::setClockMode( CHRONO );
m_use_highscores = true;
// Create the race gui before anything else is attached to the scene node

View File

@@ -108,7 +108,7 @@ protected:
Kart* loadRobot (const std::string& kart_name, int position,
const btTransform& init_pos);
void estimateFinishTimes();
public:
virtual Kart *createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
const btTransform &init_pos);
@@ -120,9 +120,6 @@ protected:
RaceGUI *m_race_gui;
public:
/** debug text that will be overlaid to the screen */
core::stringw m_debug_text[10];
World();
/** call just after instanciating. can't be moved to the contructor as child
classes must be instanciated, otherwise polymorphism will fail and the
@@ -132,6 +129,8 @@ public:
virtual ~World();
virtual void update(float delta);
virtual void render();
/** Returns true if the race is over. Must be defined by all modes. */
virtual bool isRaceOver() = 0;
virtual void restartRace();
void disableRace(); // Put race into limbo phase
/** Returns a pointer to the race gui. */

View File

@@ -215,7 +215,7 @@ public:
KartType getKartType(int kart) const { return m_kart_status[kart].m_kart_type;}
int getCoinTarget() const { return m_coin_target; }
int getPositionScore(int p) const { return m_score_for_position[p-1]; }
int allPlayerFinished() const {return
bool allPlayerFinished() const {return
m_num_finished_players==m_player_karts.size();}
int raceIsActive() const { return m_active_race; }
const std::vector<std::string>&

View File

@@ -682,17 +682,6 @@ void RaceGUI::drawStatusText()
break;
} // switch
for(int i = 0; i < 10; ++i)
{
if(RaceManager::getWorld()->m_debug_text[i] != "")
{
static video::SColor color = video::SColor(255, 100, 209, 100);
core::rect<s32> pos(20, i*20, 20, (i+1)*20);
gui::IGUIFont* font = irr_driver->getRaceFont();
font->draw(RaceManager::getWorld()->m_debug_text[i].c_str(), pos, color);
}
}
float split_screen_ratio_x, split_screen_ratio_y;
split_screen_ratio_x = split_screen_ratio_y = 1.0;
if(race_manager->getNumLocalPlayers() >= 2)