Modified behaviour of startup boost: instead of giving it to the first

two karts, it is now given for all karts starting withint a certain
amount of time. These times and boost value are specified in
stk-config.xml.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5855 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-09-02 00:19:06 +00:00
parent adc99cc6b6
commit 0e84cdf091
9 changed files with 68 additions and 40 deletions

View File

@ -22,11 +22,9 @@
The last values applies for all remaining karts. -->
<follow-the-leader intervals="30 20 10"/>
<!-- Startup information. Boost: startup speed boost for
the first karts to press acceleration at start.
<!-- Startup information.
Penalty: Penalty time if a kart accelerates before GO. -->
<startup boost ="10 5"
penalty="1" />
<startup penalty="1" />
<!-- The title music. -->
<music title="main_theme.music"/>
@ -43,7 +41,7 @@
<near-ground distance="2"/>
<!-- How long the end animation will be shown. -->
<delay-finish time="14"/>
<delay-finish time="0.5"/>
<!-- How long the music credits are shown. -->
<credits music="10"/>
@ -105,6 +103,13 @@
<!-- Camera: Distance between kart and camera. -->
<camera distance="1.5"/>
<!-- If a kart starts within the specified time after 'go',
it receives the corresponding bonus from 'boost'. Those
fields must have the same size, and must be sorted by
increasing times. -->
<startup time = "0.3 0.5"
boost = "10 5" />
<!-- Rescue: time: How long it takes the kart to be raised.
height: how height the kart will be raised before it is
dropped back onto the track.

View File

@ -82,11 +82,7 @@ void STKConfig::load(const std::string &filename)
fprintf(stderr,"No follow leader interval(s) defined in stk_config");
exit(-1);
}
if(m_startup_boost.size()==0)
{
fprintf(stderr, "No startup speed boost defined in stk_config");
exit(-1);
}
if(m_switch_items.size()!=Item::ITEM_LAST-Item::ITEM_FIRST+1)
{
fprintf(stderr,"No item switches defined in stk_config");
@ -158,7 +154,6 @@ void STKConfig::init_defaults()
m_enable_networking = true;
m_scores.clear();
m_leader_intervals.clear();
m_startup_boost.clear();
m_switch_items.clear();
} // init_defaults
@ -198,7 +193,6 @@ void STKConfig::getAllData(const XMLNode * root)
if(const XMLNode *startup_node= root->getNode("startup"))
{
startup_node->get("boost", &m_startup_boost);
startup_node->get("penalty", &m_penalty_time );
}

View File

@ -94,9 +94,6 @@ public:
std::vector<float>
m_leader_intervals; /**<Interval in follow the leader till
last kart is reomved. */
std::vector<float>
m_startup_boost; /**< The speed boost the fastest players
pressing 'accel' at start get. */
std::vector<int> m_switch_items; /**< How to switch items. */
std::vector<int>
m_scores; /**<Scores depending on position. */

View File

@ -403,6 +403,7 @@ void Kart::reset()
m_finish_time = 0.0f;
m_zipper_time_left = 0.0f;
m_collected_energy = 0;
m_has_started = false;
m_wheel_rotation = 0;
m_bounce_back_time = 0.0f;
m_skidding = 1.0f;
@ -1100,14 +1101,16 @@ bool Kart::playCustomSFX(unsigned int type)
*/
void Kart::updatePhysics(float dt)
{
// Checks for startup speed boost.
unsigned int num_started = World::getWorld()->getNumStartedKarts();
if(m_controls.m_accel>0 && num_started<stk_config->m_startup_boost.size())
// Check if accel is pressed for the first time.
if(!m_has_started && m_controls.m_accel)
{
m_zipper_time_left = 5.0f;
m_vehicle->activateZipper(stk_config->m_startup_boost[num_started]);
World::getWorld()->incNumStartedKarts();
m_has_started = true;
m_zipper_time_left = 5.0f;
float f = m_kart_properties->getStartupBoost();
m_vehicle->activateZipper(f);
}
m_bounce_back_time-=dt;
float engine_power = getActualWheelForce() + handleNitro(dt)
+ handleSlipstream(dt);

View File

@ -93,14 +93,19 @@ protected: // Used by the AI atm
KartControl m_controls; // The kart controls (e.g. steering, fire, ...)
Powerup m_powerup;
float m_zipper_time_left; /**<Zipper time left. */
Attachment *m_attachment;
Attachment *m_attachment;
/** Easier access for player_kart. */
Camera *m_camera;
Camera *m_camera;
private:
float m_max_speed; // maximum speed of the kart, computed from
/** Maximum speed of the kart. */
float m_max_speed;
/** Depending on terrain a certain reduction to the maximum speed applies.
* This reduction is accumulated in m_max_speed_reduction. */
float m_max_speed_reduction;
/** True if the kart hasn't moved since 'ready-set-go' - used to
* determine startup boost. */
bool m_has_started;
float m_power_reduction;
float m_max_gear_rpm; /**<Maximum engine rpm's for the current gear*/
float m_max_speed_reverse_ratio;

View File

@ -29,6 +29,7 @@
#include "graphics/material_manager.hpp"
#include "io/file_manager.hpp"
#include "karts/kart_model.hpp"
#include "modes/world.hpp"
#include "io/xml_node.hpp"
#include "utils/constants.hpp"
#include "utils/string_utils.hpp"
@ -380,6 +381,12 @@ void KartProperties::getAllData(const XMLNode * root)
if(const XMLNode *camera_node= root->getNode("camera"))
camera_node->get("distance", &m_camera_distance);
if(const XMLNode *startup_node= root->getNode("startup"))
{
startup_node->get("time", &m_startup_times);
startup_node->get("boost", &m_startup_boost);
}
if(const XMLNode *sounds_node= root->getNode("sounds"))
{
std::string s;
@ -435,10 +442,16 @@ void KartProperties::checkAllSet(const std::string &filename)
exit(-1);
}
if(m_gear_switch_ratio.size()!=m_gear_power_increase.size()) {
fprintf(stderr,"Number of entries for 'gear-switch-ratio' and 'gear-power-increase");
fprintf(stderr,"Number of entries for 'gear-switch-ratio' and 'gear-power-increase\n");
fprintf(stderr,"in '%s' must be equal.\n", filename.c_str());
exit(-1);
}
if(m_startup_boost.size()!=m_startup_times.size())
{
fprintf(stderr, "Number of entried for 'startup times' and 'startup-boost\n");
fprintf(stderr, "must be identical.\n");
exit(-1);
}
#define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \
fprintf(stderr,"Missing default value for '%s' in '%s'.\n", \
strA,filename.c_str());exit(-1); \
@ -506,5 +519,20 @@ float KartProperties::getMaxSteerAngle(float speed) const
return m_angle_at_min - (speed-m_min_speed_turn)*m_speed_angle_increase;
} // getMaxSteerAngle
// ----------------------------------------------------------------------------
/** Called the first time a kart accelerates after 'ready-set-go'. It searches
* through m_startup_times to find the appropriate slot, and returns the
* speed-boost from the corresponding entry in m_startup_boost.
* If the kart started too slow (i.e. slower than the longest time in
* m_startup_times, it returns 0.
*/
float KartProperties::getStartupBoost() const
{
float t = World::getWorld()->getTime();
for(unsigned int i=0; i<m_startup_times.size(); i++)
{
if(t<=m_startup_times[i]) return m_startup_boost[i];
}
return 0;
} // getStartupBoost
/* EOF */

View File

@ -199,6 +199,14 @@ private:
std::vector<float> m_gear_switch_ratio,
m_gear_power_increase;
/** If the kart starts within the specified time at index I after 'go',
* it receives the speed boost from m_startup_boost[I]. */
std::vector<float> m_startup_times;
/** The startup boost is the kart starts fast enough. */
std::vector<float> m_startup_boost;
void load (const std::string &filename,
const std::string &node);
@ -412,6 +420,7 @@ public:
/** Returns the full path where the files for this kart are stored. */
const std::string& getKartDir () const {return m_root; }
float getStartupBoost() const;
};
#endif

View File

@ -83,7 +83,6 @@ World::World() : WorldStatus(), m_clear_color(255,100,101,140)
m_use_highscores = true;
m_track = NULL;
m_clear_back_buffer = false;
m_num_started_karts = 0;
WorldStatus::setClockMode(CLOCK_CHRONO);
} // World
@ -668,8 +667,7 @@ void World::restartRace()
m_faster_music_active = false;
m_eliminated_karts = 0;
m_eliminated_players = 0;
m_num_started_karts = 0;
for ( KartList::iterator i = m_karts.begin(); i != m_karts.end() ; ++i )
{
(*i)->reset();

View File

@ -86,10 +86,6 @@ private:
/** A pointer to the global world object for a race. */
static World *m_world;
/** Counts the karts that have 'started', i.e. pressed acceleration
* after 'ready-set-go'. The first two karts will get a speed boost. */
unsigned int m_num_started_karts;
protected:
/** The list of all karts. */
KartList m_karts;
@ -258,13 +254,6 @@ public:
* Array dimension must be the number of karts.
*/
virtual void raceResultOrder(std::vector<int> *order ) = 0;
/** Returns the number of started karts, used to determine which karts
* receive a speed boost. */
unsigned int getNumStartedKarts() const { return m_num_started_karts; }
/** Increases the number of karts that have accelerated. */
void incNumStartedKarts() { m_num_started_karts++; }
bool clearBackBuffer() const { return m_clear_back_buffer; }
const irr::video::SColor& getClearColor() const { return m_clear_color; }