Cleaned up world.hpp:

- sorted declarations so that all virtual functions
  are together.
- Renamed *_IDENT variables to IDENT_* so that the
  naming is consistent
- Using std::string& for IDENT_* instead of char*
- Use pointer for out variables in getDefaultCollectibles.
- Moved m_fastest_lap variable from world to LinearWorld.
- Many many cosmetic changes to follow our style guide.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9852 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2011-09-16 01:49:38 +00:00
parent 9f4bce73a3
commit 3185c5fcc9
18 changed files with 275 additions and 206 deletions

View File

@@ -201,6 +201,8 @@ void InputManager::handleStaticAction(int key, int value)
10000);
else
kart->setPowerup(PowerupManager::POWERUP_SWATTER, 10000);
kart = world->getLocalPlayerKart(1);
kart->getAttachment()->set(Attachment::ATTACH_BOMB, 30, NULL);
}
break;

View File

@@ -113,7 +113,7 @@ void Powerup::reset()
m_number = 0;
int type, number;
World::getWorld()->getDefaultCollectibles( type, number );
World::getWorld()->getDefaultCollectibles( &type, &number );
set( (PowerupManager::PowerupType)type, number );
} // reset

View File

@@ -1029,6 +1029,11 @@ void Kart::showZipperFire()
*/
void Kart::setSquash(float time, float slowdown)
{
if(m_attachment->getType()==Attachment::ATTACH_BOMB)
{
this->handleExplosion(getXYZ(), /*direct hit*/true);
return;
}
m_node->setScale(core::vector3df(1.0f, 0.5f, 1.0f));
MaxSpeed::setSlowdown(MaxSpeed::MS_DECREASE_SQUASH, slowdown, 0.1f);
m_squash_time = time;

View File

@@ -186,9 +186,9 @@ void FollowTheLeaderRace::restartRace()
//-----------------------------------------------------------------------------
/** Returns the internal identifier for this kind of race.
*/
std::string FollowTheLeaderRace::getIdent() const
const std::string& FollowTheLeaderRace::getIdent() const
{
return FTL_IDENT;
return IDENT_FTL;
} // getIdent
//-----------------------------------------------------------------------------

View File

@@ -40,7 +40,7 @@ public:
// overriding World methods
virtual void restartRace();
virtual std::string getIdent() const;
virtual const std::string& getIdent() const;
float getClockStartTime();
virtual bool useFastMusicNearEnd() const { return false; }
virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo();
@@ -48,7 +48,7 @@ public:
virtual bool isRaceOver();
virtual bool raceHasLaps(){ return false; }
};
}; // FollowTheLeader
#endif

View File

@@ -37,10 +37,11 @@
*/
LinearWorld::LinearWorld() : WorldWithRank()
{
m_kart_display_info = NULL;
m_last_lap_sfx = sfx_manager->createSoundSource("last_lap_fanfare");
m_last_lap_sfx_played = false;
m_kart_display_info = NULL;
m_last_lap_sfx = sfx_manager->createSoundSource("last_lap_fanfare");
m_last_lap_sfx_played = false;
m_last_lap_sfx_playing = false;
m_fastest_lap = 9999999.9f;
} // LinearWorld
// ----------------------------------------------------------------------------
@@ -101,7 +102,8 @@ void LinearWorld::restartRace()
updateRacePosition();
#ifdef DEBUG
//FIXME: this could be defined somewhere in a central header so it can be used everywhere
//FIXME: this could be defined somewhere in a central header so it can
// be used everywhere
#define assertExpr( ARG1, OP, ARG2 ) if (!(ARG1 OP ARG2)) \
{ \
std::cerr << "Failed assert " << #ARG1 << #OP << #ARG2 << " @ " << __FILE__ << ":" << __LINE__ \
@@ -113,7 +115,8 @@ void LinearWorld::restartRace()
{
for (unsigned int j=i+1; j<kart_amount; j++)
{
assertExpr( m_karts[i]->getPosition(), !=, m_karts[j]->getPosition() );
assertExpr( m_karts[i]->getPosition(), !=,
m_karts[j]->getPosition() );
}
}
#endif
@@ -131,7 +134,8 @@ void LinearWorld::update(float dt)
// especially updates the kart positions.
WorldWithRank::update(dt);
if (m_last_lap_sfx_playing && m_last_lap_sfx->getStatus() != SFXManager::SFX_PLAYING)
if (m_last_lap_sfx_playing &&
m_last_lap_sfx->getStatus() != SFXManager::SFX_PLAYING)
{
music_manager->getCurrentMusic()->resetTemporaryVolume();
m_last_lap_sfx_playing = false;
@@ -146,7 +150,8 @@ void LinearWorld::update(float dt)
KartInfo& kart_info = m_kart_info[n];
Kart* kart = m_karts[n];
// Nothing to do for karts that are currently being rescued or eliminated
// Nothing to do for karts that are currently being
// rescued or eliminated
if(kart->playingEmergencyAnimation()) continue;
kart_info.getSector()->update(kart->getXYZ(), kart, m_track);
@@ -163,13 +168,15 @@ void LinearWorld::update(float dt)
for (unsigned int i=0; i<kart_amount; i++)
{
// ---------- update rank ------
if (m_karts[i]->hasFinishedRace() || m_karts[i]->isEliminated()) continue;
if (m_karts[i]->hasFinishedRace() ||
m_karts[i]->isEliminated() ) continue;
// During the last lap update the estimated finish time.
// This is used to play the faster music, and by the AI
if (m_kart_info[i].m_race_lap == race_manager->getNumLaps()-1)
{
m_kart_info[i].m_estimated_finish = estimateFinishTimeForKart(m_karts[i]);
m_kart_info[i].m_estimated_finish =
estimateFinishTimeForKart(m_karts[i]);
}
checkForWrongDirection(i);
}
@@ -184,12 +191,14 @@ void LinearWorld::update(float dt)
{
for(unsigned int j =0; j<kart_amount; j++)
{
printf("kart id=%d, position=%d, finished=%d, laps=%d, distanceDownTrack=%f %s\n",
printf("kart id=%d, position=%d, finished=%d, laps=%d, "
"distanceDownTrack=%f %s\n",
j, m_karts[j]->getPosition(),
m_karts[j]->hasFinishedRace(),
m_kart_info[j].m_race_lap,
getDistanceDownTrackForKart(m_karts[j]->getWorldKartId()),
(m_karts[j]->getPosition() == m_karts[i]->getPosition() ? "<--- !!!" : ""));
(m_karts[j]->getPosition() == m_karts[i]->getPosition()
? "<--- !!!" : "") );
}
}
pos_used[m_karts[i]->getPosition()]=i;
@@ -236,7 +245,8 @@ void LinearWorld::newLap(unsigned int kart_index)
m_last_lap_sfx_playing = true;
// In case that no music is defined
if(music_manager->getCurrentMusic() && music_manager->getMasterMusicVolume() > 0.2f)
if(music_manager->getCurrentMusic() &&
music_manager->getMasterMusicVolume() > 0.2f)
{
music_manager->getCurrentMusic()->setTemporaryVolume(0.2f);
}
@@ -251,11 +261,12 @@ void LinearWorld::newLap(unsigned int kart_index)
else if (kart_info.m_race_lap > 0 && kart_info.m_race_lap+1 < lap_count)
{
m_race_gui->addMessage(_("Lap %i", kart_info.m_race_lap+1),
kart, 3.0f, video::SColor(255, 210, 100, 50), true);
kart, 3.0f, video::SColor(255, 210, 100, 50),
true);
}
// The race positions must be updated here: consider the situation where
// the first kart does not cross the finish line in its last lap, instead
// the first kart does not cross the finish line in its last lap, instead
// it passes it, the kart reverses and crosses the finishing line
// backwards. Just before crossing the finishing line the kart will be on
// the last lap, but with a distance along the track close to zero.
@@ -297,16 +308,17 @@ void LinearWorld::newLap(unsigned int kart_index)
}
// if new fastest lap
if(time_per_lap < getFastestLapTime() && raceHasLaps() &&
if(time_per_lap < m_fastest_lap && raceHasLaps() &&
kart_info.m_race_lap>0)
{
setFastestLap(kart, time_per_lap);
m_fastest_lap = time_per_lap;
std::string s = StringUtils::timeToString(time_per_lap);
irr::core::stringw m_fastest_lap_message;
//I18N: as in "fastest lap: 60 seconds by Wilber"
m_fastest_lap_message += _("%s by %s", s.c_str(), core::stringw(kart->getName()));
m_fastest_lap_message += _("%s by %s", s.c_str(),
core::stringw(kart->getName()));
m_race_gui->addMessage(m_fastest_lap_message, NULL,
3.0f, video::SColor(255, 255, 255, 255), false);
@@ -401,7 +413,8 @@ RaceGUIBase::KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo()
if(current_lap > laps_of_leader)
{
// more laps than current leader --> new leader and new time computation
// more laps than current leader --> new leader and
// new time computation
laps_of_leader = current_lap;
time_of_leader = lap_time;
} else if(current_lap == laps_of_leader)
@@ -420,14 +433,17 @@ RaceGUIBase::KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo()
const int position = kart->getPosition();
if(laps_of_leader>0 && // Don't compare times when crossing the start line first
(getTime() - getTimeAtLapForKart(kart->getWorldKartId())<5.0f || rank_info.lap != laps_of_leader) &&
raceHasLaps())
// Don't compare times when crossing the start line first
if(laps_of_leader>0 &&
(getTime() - getTimeAtLapForKart(kart->getWorldKartId())<5.0f ||
rank_info.lap != laps_of_leader) &&
raceHasLaps())
{ // Display for 5 seconds
std::string str;
if(position == 1)
{
str = " " + StringUtils::timeToString( getTimeAtLapForKart(kart->getWorldKartId()) );
str = " " + StringUtils::timeToString(
getTimeAtLapForKart(kart->getWorldKartId()) );
}
else
{
@@ -453,7 +469,8 @@ RaceGUIBase::KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo()
}
else if(kart_info.m_race_lap>=0 && numLaps>1)
{
rank_info.g = rank_info.b = 1.0f-(float)kart_info.m_race_lap/((float)numLaps-1.0f);
rank_info.g = rank_info.b =
1.0f-(float)kart_info.m_race_lap/((float)numLaps-1.0f);
}
} // next kart
@@ -478,7 +495,8 @@ float LinearWorld::estimateFinishTimeForKart(Kart* kart)
// In case that a kart is rescued behind start line, or ...
if(distance_covered<0) distance_covered =1.0f;
const float full_distance = race_manager->getNumLaps()*m_track->getTrackLength();
const float full_distance = race_manager->getNumLaps()
* m_track->getTrackLength();
const float average_speed = distance_covered/getTime();
// Finish time is the time needed for the whole race with
@@ -521,7 +539,8 @@ void LinearWorld::moveKartAfterRescue(Kart* kart)
float epsilon = 0.5f * kart->getKartHeight();
btTransform pos;
pos.setOrigin(kart->getXYZ()+btVector3(0, kart->getKartHeight() + epsilon, 0));
pos.setOrigin(kart->getXYZ()+btVector3(0, kart->getKartHeight() + epsilon,
0));
pos.setRotation(btQuaternion(btVector3(0.0f, 1.0f, 0.0f),
m_track->getAngle(sector)));
@@ -533,13 +552,15 @@ void LinearWorld::moveKartAfterRescue(Kart* kart)
if (kart_over_ground)
{
//add vertical offset so that the kart starts off above the track
float vertical_offset = kart->getKartProperties()->getVertRescueOffset() *
kart->getKartHeight();
float vertical_offset =
kart->getKartProperties()->getVertRescueOffset()
* kart->getKartHeight();
kart->getBody()->translate(btVector3(0, vertical_offset, 0));
}
else
{
fprintf(stderr, "WARNING: invalid position after rescue for kart %s on track %s.\n",
fprintf(stderr, "WARNING: invalid position after rescue for kart %s "
"on track %s.\n",
(kart->getIdent().c_str()), m_track->getIdent().c_str());
}
@@ -584,13 +605,15 @@ void LinearWorld::updateRacePosition()
const int my_id = kart->getWorldKartId();
const int my_laps = getLapForKart(my_id);
const float my_progression = getDistanceDownTrackForKart(my_id);
// Count karts ahead of the current kart, i.e. kart that are already finished,
// have done more laps, or the same number of laps, but a greater distance.
// Count karts ahead of the current kart, i.e. kart that are
// already finished, have done more laps, or the same number of laps,
// but a greater distance.
for (unsigned int j = 0 ; j < kart_amount ; j++)
{
if(j == kart->getWorldKartId()) continue; // don't compare a kart with itself
if(m_karts[j]->isEliminated()) continue; // dismiss eliminated karts
// don't compare a kart with itself
if(j == kart->getWorldKartId()) continue;
// dismiss eliminated karts
if(m_karts[j]->isEliminated()) continue;
if(!kart->hasFinishedRace() && m_karts[j]->hasFinishedRace())
{
@@ -619,9 +642,11 @@ void LinearWorld::updateRacePosition()
{
p++;
#if _DEBUG_PRINTS_LIKE_MAD_
std::cout << " " << p << " : " << m_karts[j]->getIdent() <<
" because he has is further within the track (my progression is " <<
my_progression << ", his progression is " << other_progression << ")\n";
std::cout << " " << p << " : " << m_karts[j]->getIdent()
<< " because he has is further within the track"
"(my progression is "
<< my_progression << ", his progression is "
<< other_progression << ")\n";
#endif
}
} //next kart
@@ -637,18 +662,24 @@ void LinearWorld::updateRacePosition()
std::cerr << "Info used to decide ranking :\n";
for (unsigned int d=0; d<kart_amount; d++)
{
std::cerr << " kart " << m_karts[d]->getIdent() << " has finished(" << m_karts[d]->hasFinishedRace()
<< "), is at lap (" << getLapForKart(d) << "), is at distance("
<< getDistanceDownTrackForKart(d) << "), is eliminated(" << m_karts[d]->isEliminated() << ")" << std::endl;
std::cerr << " kart " << m_karts[d]->getIdent()
<< " has finished(" << m_karts[d]->hasFinishedRace()
<< "), is at lap (" << getLapForKart(d)
<< "), is at distance("
<< getDistanceDownTrackForKart(d)
<< "), is eliminated(" << m_karts[d]->isEliminated()
<< ")" << std::endl;
}
std::cerr << "Who has each ranking so far :\n";
for (unsigned int d=0; d<i; d++)
{
std::cerr << " " << m_karts[d]->getIdent() << " has rank " << m_karts[d]->getPosition() << std::endl;
std::cerr << " " << m_karts[d]->getIdent() << " has rank "
<< m_karts[d]->getPosition() << std::endl;
}
std::cerr << " --> And " << kart->getIdent() << " is being set at rank " << p << std::endl;
std::cerr << " --> And " << kart->getIdent()
<< " is being set at rank " << p << std::endl;
history->Save();
assert(false);
}
@@ -691,11 +722,13 @@ void LinearWorld::updateRacePosition()
<< my_progression<<").\n";
for (unsigned int j = 0 ; j < kart_amount ; j++)
{
if(j == kart->getWorldKartId()) continue; // don't compare a kart with itself
// don't compare a kart with itself
if(j == kart->getWorldKartId()) continue;
if(!kart->hasFinishedRace() && m_karts[j]->hasFinishedRace())
{
p++;
std::cout << " " << p << " : " << m_karts[j]->getIdent() << " because he has finished.\n";
std::cout << " " << p << " : " << m_karts[j]->getIdent()
<< " because he has finished.\n";
continue;
}
int other_laps = getLapForKart(j);
@@ -704,19 +737,24 @@ void LinearWorld::updateRacePosition()
if(other_laps > my_laps)
{
p++; // Other kart has more lapses
std::cout << " " << p << " : " << m_karts[j]->getIdent() << " because he has more laps than me.\n";
std::cout << " " << p << " : "
<< m_karts[j]->getIdent()
<< " because he has more laps than me.\n";
}
continue;
}
float other_progression = getDistanceDownTrackForKart(j);
if(other_progression > my_progression ||
(other_progression == my_progression &&
m_karts[j]->getInitialPosition() > kart->getInitialPosition()) )
m_karts[j]->getInitialPosition()
> kart->getInitialPosition()) )
{
p++;
std::cout << " " << p << " : " << m_karts[j]->getIdent() <<
" because he is further within the track (my progression is " <<
my_progression << ", his progression is " << other_progression << ")\n";
std::cout << " " << p << " : " << m_karts[j]->getIdent()
<< " because he is further within the track"
"(my progression is "
<< my_progression << ", his progression is "
<< other_progression << ")\n";
}
} //next kart
} // for i<kart_amount
@@ -759,9 +797,11 @@ void LinearWorld::checkForWrongDirection(unsigned int i)
kart->getVelocityLC().getY() > 0.0f &&
!kart->hasFinishedRace() )
{
m_race_gui->addMessage(_("WRONG WAY!"), kart, -1.0f /* time */,
video::SColor(255,255,255,255), true /* important */,
true /* big font */);
m_race_gui->addMessage(_("WRONG WAY!"), kart,
/* time */ -1.0f,
video::SColor(255,255,255,255),
/*important*/ true,
/*big font*/ true);
} // if angle is too big
} // checkForWrongDirection

View File

@@ -43,6 +43,9 @@ private:
bool m_last_lap_sfx_playing;
/** The fastest lap time. */
float m_fastest_lap;
// ------------------------------------------------------------------------
/** Some additional info that needs to be kept for each kart
* in this kind of race.

View File

@@ -37,13 +37,13 @@ bool StandardRace::isRaceOver()
} // isRaceOver
//-----------------------------------------------------------------------------
void StandardRace::getDefaultCollectibles(int& collectible_type, int& amount)
void StandardRace::getDefaultCollectibles(int *collectible_type, int *amount)
{
// in time trial mode, give zippers
if(race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL)
{
collectible_type = PowerupManager::POWERUP_ZIPPER;
amount = race_manager->getNumLaps();
*collectible_type = PowerupManager::POWERUP_ZIPPER;
*amount = race_manager->getNumLaps();
}
else World::getDefaultCollectibles(collectible_type, amount);
} // getDefaultCollectibles
@@ -60,7 +60,7 @@ bool StandardRace::haveBonusBoxes()
//-----------------------------------------------------------------------------
/** Returns an identifier for this race.
*/
std::string StandardRace::getIdent() const
const std::string& StandardRace::getIdent() const
{
if(race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL)
return IDENT_TTRIAL;

View File

@@ -36,10 +36,9 @@ public:
virtual ~StandardRace() {};
// overriding World methods
virtual void getDefaultCollectibles(int& collectible_type, int& amount);
virtual void getDefaultCollectibles(int *collectible_type, int *amount);
virtual bool haveBonusBoxes();
virtual std::string
getIdent() const;
virtual const std::string& getIdent() const;
};
#endif

View File

@@ -215,9 +215,9 @@ void ThreeStrikesBattle::kartHit(const int kart_id)
//-----------------------------------------------------------------------------
/** Returns the internal identifier for this race.
*/
std::string ThreeStrikesBattle::getIdent() const
const std::string& ThreeStrikesBattle::getIdent() const
{
return STRIKES_IDENT;
return IDENT_STRIKES;
} // getIdent
//-----------------------------------------------------------------------------

View File

@@ -97,7 +97,7 @@ public:
virtual bool raceHasLaps(){ return false; }
virtual void moveKartAfterRescue(Kart* kart);
virtual std::string getIdent() const;
virtual const std::string& getIdent() const;
virtual void kartHit(const int kart_id);
virtual void update(float dt);

View File

@@ -177,9 +177,9 @@ void TutorialRace::restartRace()
//-----------------------------------------------------------------------------
/** Returns the internal identifier for this kind of race.
*/
std::string TutorialRace::getIdent() const
const std::string& TutorialRace::getIdent() const
{
return FTL_IDENT;
return IDENT_FTL;
} // getIdent
//-----------------------------------------------------------------------------

View File

@@ -41,7 +41,7 @@ public:
// overriding World methods
virtual void restartRace();
virtual std::string getIdent() const;
virtual const std::string& getIdent() const;
float getClockStartTime();
virtual bool useFastMusicNearEnd() const { return false; }
virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo();

View File

@@ -94,15 +94,15 @@ World::World() : WorldStatus(), m_clear_color(255,100,101,140)
} // World
// ----------------------------------------------------------------------------
/** This function is called after the World constructor. In init() functions
* can be called that use World::getWorld(). The init function is
* called immediately after the constructor.
/** This function is called after instanciating. This can't be moved to the
* contructor as child classes must be instanciated, otherwise polymorphism
* will fail and the results will be incorrect . Also in init() functions
* can be called that use World::getWorld().
*/
void World::init()
{
race_state = new RaceState();
m_faster_music_active = false;
m_fastest_lap = 9999999.9f;
m_fastest_kart = 0;
m_eliminated_karts = 0;
m_eliminated_players = 0;
@@ -821,11 +821,17 @@ void World::eliminateKart(int kart_number, bool notifyOfElimination, bool remove
} // removeKart
//-----------------------------------------------------------------------------
void World::getDefaultCollectibles(int& collectible_type, int& amount )
/** Called to determine the default collectibles to give each player at the
* start for this kind of race. Both parameters are of 'out' type.
* \param collectible_type The type of collectible each kart.
* \param amount The number of collectibles.
*/
void World::getDefaultCollectibles(int *collectible_type, int *amount )
{
collectible_type = PowerupManager::POWERUP_NOTHING;
amount = 0;
}
*collectible_type = PowerupManager::POWERUP_NOTHING;
*amount = 0;
} // getDefaultCollectibles
//-----------------------------------------------------------------------------
void World::restartRace()
{

View File

@@ -67,7 +67,6 @@ protected:
RandomGenerator m_random;
Physics* m_physics;
float m_fastest_lap;
Kart* m_fastest_kart;
/** Number of eliminated karts. */
int m_eliminated_karts;
@@ -83,10 +82,12 @@ protected:
*/
bool m_use_highscores;
void updateHighscores (int* best_highscore_rank, int* best_finish_time, std::string* highscore_who,
void updateHighscores (int* best_highscore_rank, int* best_finish_time,
std::string* highscore_who,
StateManager::ActivePlayer** best_player);
void resetAllKarts ();
void eliminateKart (int kart_number, bool notifyOfElimination=true, bool remove=true);
void eliminateKart (int kart_number, bool notifyOfElimination=true,
bool remove=true);
Controller*
loadAIController (Kart *kart);
@@ -123,18 +124,18 @@ protected:
*/
virtual float estimateFinishTimeForKart(Kart* kart) {return getTime(); }
/** Pausing/unpausing are not done immediately, but at next udpdate. The use of
this is when switching between screens : if we leave a screen that paused the
game, only to go to another screen that pauses back the game, this mechanism
prevents the game from moving on between the switch
*/
/** Pausing/unpausing are not done immediately, but at next udpdate. The
* use of this is when switching between screens : if we leave a screen
* that paused the game, only to go to another screen that pauses back
* the game, this mechanism prevents the game from moving on between
* the switch. */
bool m_schedule_pause;
/** Pausing/unpausing are not done immediately, but at next udpdate. The use of
this is when switching between screens : if we leave a screen that paused the
game, only to go to another screen that pauses back the game, this mechanism
prevents the game from moving on between the switch
*/
/** Pausing/unpausing are not done immediately, but at next udpdate. The
* use of this is when switching between screens : if we leave a screen
* that paused the game, only to go to another screen that pauses back
* the game, this mechanism prevents the game from moving on between the
* switch. */
bool m_schedule_unpause;
Phase m_scheduled_pause_phase;
@@ -142,120 +143,133 @@ protected:
public:
World();
virtual ~World();
// Static functions to access world:
// =================================
// ------------------------------------------------------------------------
/** Returns a pointer to the (singleton) world object. */
static World* getWorld() { return m_world; }
/** Delete the )singleton) world object, if it exists, and sets the singleton pointer to NULL.
* It's harmless to call this if the world has been deleted already. */
// ------------------------------------------------------------------------
/** Delete the )singleton) world object, if it exists, and sets the
* singleton pointer to NULL. It's harmless to call this if the world
* has been deleted already. */
static void deleteWorld() { delete m_world; m_world = NULL; }
// ------------------------------------------------------------------------
/** Sets the pointer to the world object. This is only used by
* the race_manager.*/
static void setWorld(World *world) {m_world = world; }
/** 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();
void updateWorld(float dt);
virtual void restartRace();
/** Put race into limbo phase */
void disableRace();
Kart *getPlayerKart(unsigned int player) const;
Kart *getLocalPlayerKart(unsigned int n) const;
/** Returns a pointer to the race gui. */
RaceGUIBase *getRaceGUI() const { return m_race_gui; }
unsigned int getNumKarts() const { return m_karts.size(); }
Kart *getKart(int kartId) const { assert(kartId >= 0 &&
kartId < int(m_karts.size()));
return m_karts[kartId]; }
/** Returns the number of currently active (i.e.non-elikminated) karts. */
unsigned int getCurrentNumKarts() const { return (int)m_karts.size() -
m_eliminated_karts; }
/** Returns the number of currently active (i.e. non-eliminated) players. */
unsigned int getCurrentNumPlayers() const { return m_num_players -
m_eliminated_players; }
Physics *getPhysics() const { return m_physics; }
Track *getTrack() const { return m_track; }
Kart *getFastestKart() const { return m_fastest_kart; }
float getFastestLapTime() const { return m_fastest_lap; }
void setFastestLap(Kart *k, float time){ m_fastest_kart = k;
m_fastest_lap = time; }
Highscores *getHighscores() const;
// ------------------------------------------------------------------------
// Pure virtual functions
// ======================
virtual void terminateRace();
/** Called to determine the default collectibles to give each player for this
* kind of race. Both parameters are of 'out' type.
*/
virtual void getDefaultCollectibles(int& collectible_type, int& amount );
/** Called to determine whether this race mode uses bonus boxes.
*/
virtual bool haveBonusBoxes(){ return true; }
/** Each game mode should have a unique identifier. Override
* this method in child classes to provide it.
*/
virtual std::string getIdent() const = 0;
virtual bool useFastMusicNearEnd() const { return true; }
virtual void pause(Phase phase);
virtual void unpause();
void schedulePause(Phase phase);
void scheduleUnpause();
/**
* The code that draws the timer should call this first to know
* whether the game mode wants a timer drawn
*/
bool shouldDrawTimer() const { return isRacePhase() &&
getClockMode() != CLOCK_NONE; }
/**
* If you want to do something to karts or their graphics at the start of the race, override this
*/
virtual void kartAdded(Kart* kart, scene::ISceneNode* node) {}
/** \return whether this world can generate/have highscores */
bool useHighScores() const { return m_use_highscores; }
/** Called by the code that draws the list of karts on the race GUI
* to know what needs to be drawn in the current mode
*/
virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo() = 0;
* this method in child classes to provide it. */
virtual const std::string&
getIdent() const = 0;
// ------------------------------------------------------------------------
/** Since each mode will have a different way of deciding where a rescued
* kart is dropped, this method will be called and each mode can implement it.
*/
virtual void moveKartAfterRescue(Kart* kart) = 0;
/** Called when it is needed to know whether this kind of race involves counting laps.
*/
* kart is dropped, this method will be called and each mode can implement
* it. */
virtual void moveKartAfterRescue(Kart* kart) = 0;
// ------------------------------------------------------------------------
/** Called when it is needed to know whether this kind of race involves
* counting laps. */
virtual bool raceHasLaps() = 0;
// ------------------------------------------------------------------------
/** Called by the code that draws the list of karts on the race GUI
* to know what needs to be drawn in the current mode. */
virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo() = 0;
// ------------------------------------------------------------------------
// Virtual functions
// =================
virtual void init();
virtual void terminateRace();
virtual void restartRace();
virtual void pause(Phase phase);
virtual void unpause();
virtual void getDefaultCollectibles(int *collectible_type,
int *amount );
// ------------------------------------------------------------------------
/** Called to determine whether this race mode uses bonus boxes. */
virtual bool haveBonusBoxes(){ return true; }
// ------------------------------------------------------------------------
/** Returns if this mode should use fast music (if available). */
virtual bool useFastMusicNearEnd() const { return true; }
// ------------------------------------------------------------------------
/** If you want to do something to karts or their graphics at the start
* of the race, override this. */
virtual void kartAdded(Kart* kart, scene::ISceneNode* node) {}
// ------------------------------------------------------------------------
/** Called whenever a kart starts a new lap. Meaningless (and won't be
* called) in non-laped races.
*/
virtual void newLap(unsigned int kart_index) {}
/** Called when a kart was hit by a projectile
*/
// ------------------------------------------------------------------------
/** Called when a kart was hit by a projectile. */
virtual void kartHit(const int kart_id) {};
bool clearBackBuffer() const { return m_clear_back_buffer; }
// Other functions
// ===============
Highscores *getHighscores() const;
void schedulePause(Phase phase);
void scheduleUnpause();
void updateWorld(float dt);
void handleExplosion(const Vec3 &xyz, Kart *kart_hit,
PhysicalObject *object);
Kart *getPlayerKart(unsigned int player) const;
Kart *getLocalPlayerKart(unsigned int n) const;
// ------------------------------------------------------------------------
/** Returns a pointer to the race gui. */
RaceGUIBase *getRaceGUI() const { return m_race_gui;}
// ------------------------------------------------------------------------
/** Returns the number of karts in the race. */
unsigned int getNumKarts() const { return m_karts.size(); }
// ------------------------------------------------------------------------
/** Returns the kart with a given world id. */
Kart *getKart(int kartId) const {
assert(kartId >= 0 && kartId < int(m_karts.size()));
return m_karts[kartId]; }
// ------------------------------------------------------------------------
/** Returns the number of currently active (i.e.non-elikminated) karts. */
unsigned int getCurrentNumKarts() const { return (int)m_karts.size() -
m_eliminated_karts; }
// ------------------------------------------------------------------------
/** Returns the number of currently active (i.e. non-eliminated) players.*/
unsigned int getCurrentNumPlayers() const { return m_num_players -
m_eliminated_players;}
// ------------------------------------------------------------------------
/** Returns a pointer to the physics. */
Physics *getPhysics() const { return m_physics; }
// ------------------------------------------------------------------------
/** Returns a pointer to the track. */
Track *getTrack() const { return m_track; }
// ------------------------------------------------------------------------
/** The code that draws the timer should call this first to know
* whether the game mode wants a timer drawn. */
bool shouldDrawTimer() const { return isRacePhase() &&
getClockMode() != CLOCK_NONE; }
// ------------------------------------------------------------------------
/** \return whether this world can generate/have highscores */
bool useHighScores() const { return m_use_highscores; }
// ------------------------------------------------------------------------
/** Returns if this mode needs to clear the back buffer. */
bool clearBackBuffer() const { return m_clear_back_buffer; }
// ------------------------------------------------------------------------
/** Returns the color to clear the back buffer. */
const irr::video::SColor& getClearColor() const { return m_clear_color; }
void setClearBackBuffer(bool enabled) { m_clear_back_buffer = enabled; }
void setClearbackBufferColor(irr::video::SColor color) { m_clear_color = color; }
// ------------------------------------------------------------------------
/** Forces clearing of the back buffer. */
void setClearBackBuffer(bool enabled) { m_clear_back_buffer = enabled; }
// ------------------------------------------------------------------------
/** Sets the color to use when clearing the back buffer. */
void setClearbackBufferColor(irr::video::SColor color)
{ m_clear_color = color; }
// ------------------------------------------------------------------------
};
}; // World
#endif

View File

@@ -33,11 +33,10 @@
class Kart;
class Track;
static const char* IDENT_STD = "STANDARD";
static const char* IDENT_TTRIAL = "STD_TIMETRIAL";
static const char* FTL_IDENT = "FOLLOW_LEADER";
static const char* STRIKES_IDENT = "BATTLE_3_STRIKES";
static const std::string IDENT_STD ("STANDARD" );
static const std::string IDENT_TTRIAL ("STD_TIMETRIAL" );
static const std::string IDENT_FTL ("FOLLOW_LEADER" );
static const std::string IDENT_STRIKES("BATTLE_3_STRIKES");
/**
* The race manager has two functions:
@@ -103,15 +102,16 @@ public:
/** Returns a string identifier for each minor race mode.
* \param mode Minor race mode.
*/
static const char* getIdentOf(const MinorRaceModeType mode)
static const std::string& getIdentOf(const MinorRaceModeType mode)
{
switch (mode)
{
case MINOR_MODE_NORMAL_RACE: return IDENT_STD;
case MINOR_MODE_TIME_TRIAL: return IDENT_TTRIAL;
case MINOR_MODE_FOLLOW_LEADER: return FTL_IDENT;
case MINOR_MODE_3_STRIKES: return STRIKES_IDENT;
default: assert(false); return NULL;
case MINOR_MODE_FOLLOW_LEADER: return IDENT_FTL;
case MINOR_MODE_3_STRIKES: return IDENT_STRIKES;
default: assert(false);
return IDENT_STD; // stop compiler warning
}
} // getIdentOf
@@ -173,8 +173,8 @@ public:
{
if (name==IDENT_STD ) return MINOR_MODE_NORMAL_RACE;
else if (name==IDENT_TTRIAL ) return MINOR_MODE_TIME_TRIAL;
else if (name==FTL_IDENT ) return MINOR_MODE_FOLLOW_LEADER;
else if (name==STRIKES_IDENT) return MINOR_MODE_3_STRIKES;
else if (name==IDENT_FTL ) return MINOR_MODE_FOLLOW_LEADER;
else if (name==IDENT_STRIKES) return MINOR_MODE_3_STRIKES;
assert(0);
return MINOR_MODE_NONE;

View File

@@ -185,7 +185,7 @@ void MinimalRaceGUI::renderGlobal(float dt)
drawGlobalMiniMap();
// in 3 strikes mode we need to see the lives
if (world->getIdent() == STRIKES_IDENT)
if (world->getIdent() == IDENT_STRIKES)
{
KartIconDisplayInfo* info = world->getKartsDisplayInfo();
drawGlobalPlayerIcons(info, m_map_height);

View File

@@ -95,7 +95,7 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
else if (name == "gamemode")
{
DynamicRibbonWidget* w = dynamic_cast<DynamicRibbonWidget*>(widget);
const std::string selectedMode = w->getSelectionIDString(PLAYER_ID_GAME_MASTER);
const std::string& selectedMode = w->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selectedMode == IDENT_STD)
{
@@ -109,7 +109,7 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
UserConfigParams::m_game_mode = CONFIG_CODE_TIMETRIAL;
StateManager::get()->pushScreen( TracksScreen::getInstance() );
}
else if (selectedMode == FTL_IDENT)
else if (selectedMode == IDENT_FTL)
{
// Make sure there are at least three karts, otherwise FTL doesn't
if(race_manager->getNumberOfKarts()<3)
@@ -119,7 +119,7 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con
UserConfigParams::m_game_mode = CONFIG_CODE_FTL;
StateManager::get()->pushScreen( TracksScreen::getInstance() );
}
else if (selectedMode == STRIKES_IDENT)
else if (selectedMode == IDENT_STRIKES)
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
UserConfigParams::m_game_mode = CONFIG_CODE_3STRIKES;
@@ -205,7 +205,7 @@ void RaceSetupScreen::init()
name2 += _("Contains no powerups, so only your driving skills matter!");
w2->addItem( name2, IDENT_TTRIAL, RaceManager::getIconOf(RaceManager::MINOR_MODE_TIME_TRIAL));
if (unlock_manager->isLocked(FTL_IDENT))
if (unlock_manager->isLocked(IDENT_FTL))
{
w2->addItem( _("Locked : solve active challenges to gain access to more!"),
"locked", RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), true);
@@ -216,7 +216,7 @@ void RaceSetupScreen::init()
RaceManager::getNameOf(RaceManager::MINOR_MODE_FOLLOW_LEADER)) + L"\n";
//I18N: short definition for follow-the-leader game mode
name3 += _("Keep up with the leader kart but don't overtake it!");
w2->addItem(name3, FTL_IDENT, RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), false);
w2->addItem(name3, IDENT_FTL, RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), false);
}
if (race_manager->getNumLocalPlayers() > 1 || UserConfigParams::m_artist_debug_mode)
@@ -225,7 +225,7 @@ void RaceSetupScreen::init()
RaceManager::getNameOf(RaceManager::MINOR_MODE_3_STRIKES)) + L"\n";
//FIXME: avoid duplicating descriptions from the help menu!
name4 += _("Hit others with weapons until they lose all their lives. (Only in multiplayer games)");
w2->addItem( name4, STRIKES_IDENT, RaceManager::getIconOf(RaceManager::MINOR_MODE_3_STRIKES));
w2->addItem( name4, IDENT_STRIKES, RaceManager::getIconOf(RaceManager::MINOR_MODE_3_STRIKES));
}
@@ -241,10 +241,10 @@ void RaceSetupScreen::init()
w2->setSelection(IDENT_TTRIAL, PLAYER_ID_GAME_MASTER, true);
break;
case CONFIG_CODE_FTL :
w2->setSelection(FTL_IDENT, PLAYER_ID_GAME_MASTER, true);
w2->setSelection(IDENT_FTL, PLAYER_ID_GAME_MASTER, true);
break;
case CONFIG_CODE_3STRIKES :
w2->setSelection(STRIKES_IDENT, PLAYER_ID_GAME_MASTER, true);
w2->setSelection(IDENT_STRIKES, PLAYER_ID_GAME_MASTER, true);
break;
}