allow modes to disallow some types of powerups, for instance no anvil should be collected in battle mode...

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2423 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2008-11-08 02:52:29 +00:00
parent 576d1c3265
commit bb56beb7f9
6 changed files with 32 additions and 2 deletions

View File

@ -252,7 +252,13 @@ void Powerup::hitBonusBox(int n, const Item &item, int add_info)
//exclude the anvil and the parachute, but later we have to add 1 to prevent
//having a value of 0 since that isn't a valid powerup.
PowerupType newC;
newC = (PowerupType)(m_random.get(POWERUP_MAX - 1 - 2) + 1);
while(true)
{
newC = (PowerupType)(m_random.get(POWERUP_MAX - 1 - 2) + 1);
// allow the game mode to allow or disallow this type of powerup
if(race_manager->getWorld()->acceptPowerup(newC)) break;
}
// Save the information about the powerup in the race state
// so that the clients can be updated.
if(network_manager->getMode()==NetworkManager::NW_SERVER)

View File

@ -21,6 +21,7 @@
#include "user_config.hpp"
#include "translation.hpp"
#include "audio/sound_manager.hpp"
#include "items/powerup_manager.hpp"
//-----------------------------------------------------------------------------
FollowTheLeaderRace::FollowTheLeaderRace() : LinearWorld()
@ -136,7 +137,6 @@ KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo(const RaceGUI* cal
return m_kart_display_info;
}
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::raceResultOrder( int* order )
{
const unsigned int NUM_KARTS = race_manager->getNumKarts();
@ -177,3 +177,12 @@ void FollowTheLeaderRace::raceResultOrder( int* order )
delete []scores;
delete []race_time;
}
//-----------------------------------------------------------------------------
bool FollowTheLeaderRace::acceptPowerup(const int type) const
{
// anvil makes no sense in FTL, the leader is supposed to stay first,
// you don't want to stop him
if(type == POWERUP_ANVIL) return false;
return true;
}

View File

@ -38,6 +38,7 @@ public:
virtual std::string getInternalCode() const;
virtual bool useFastMusicNearEnd() const { return false; }
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
virtual bool acceptPowerup(const int type) const;
virtual bool raceHasLaps(){ return false; }

View File

@ -294,3 +294,11 @@ void ThreeStrikesBattle::raceResultOrder( int* order )
order[pos] = kart_id;
}
}
//-----------------------------------------------------------------------------
bool ThreeStrikesBattle::acceptPowerup(const int type) const
{
// these powerups don't make much sense in battle mode
if(type == POWERUP_PARACHUTE || type == POWERUP_ANVIL || type == POWERUP_ZIPPER) return false;
return true;
}

View File

@ -55,6 +55,7 @@ public:
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
virtual bool raceHasLaps(){ return false; }
virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body);
virtual bool acceptPowerup(const int type) const;
virtual std::string getInternalCode() const;

View File

@ -180,6 +180,11 @@ public:
bool shouldDrawTimer() const { return TimedRace::isRacePhase() &&
TimedRace::getClockMode() != CLOCK_NONE; }
/** called when a bonus box is hit, to determine which types of powerups are allowed
in each game mode. By default all are accepted, override in child classes to get
a different behaviour */
virtual bool acceptPowerup(const int type) const { return true; }
/** 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
*/