SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | List of all members
PowerupManager::WeightsData Class Reference

This object stores all the weights for one particular number of karts. More...

Public Member Functions

void reset ()
 Deletes all data stored in a WeightsData objects.
 
void readData (int num_karts, const XMLNode *node)
 Reads in all weights for a given category and number of karts.
 
void interpolate (WeightsData *prev, WeightsData *next, int num_karts)
 Defines the weights for this WeightsData object based on a linear interpolation between the previous and next WeightsData class (depending on the number of karts in this race and in previous and next).
 
void convertRankToSection (int rank, int *prev, int *next, float *weight)
 For a given rank in the current race this computes the previous and next entry in the weight list, and the weight necessary to interpolate between these two values.
 
void precomputeWeights ()
 This function computes the item distribution for each possible rank in the race.
 
int getRandomItem (int rank, uint64_t random_number)
 Computes a random item dependent on the rank of the kart and a given random number.
 
void setNumKarts (int num_karts)
 Sets the number of karts.
 
int getNumKarts () const
 Returns for how many karts this entry is meant for.
 

Public Attributes

friend PowerupManager
 

Private Attributes

unsigned int m_num_karts
 The number of karts for which this entry is to be used.
 
std::vector< std::vector< int > > m_weights_for_section
 Stores for each of the sections the weights from the XML file.
 
std::vector< std::vector< unsigned > > m_summed_weights_for_rank
 This field is only populated for the WeightData class that is used during a race.
 

Detailed Description

This object stores all the weights for one particular number of karts.

I.e. it has a list of all the weights within the number of karts.

Member Function Documentation

◆ convertRankToSection()

void PowerupManager::WeightsData::convertRankToSection ( int  rank,
int *  prev,
int *  next,
float *  weight 
)

For a given rank in the current race this computes the previous and next entry in the weight list, and the weight necessary to interpolate between these two values.

If the requested rank should exactly match one entries, previous and next entry will be identical, and weight set to 1.0.

Parameters
rankRank that is to be interpolated.
prevOn return contains the index of the closest weight field smaller than the given rank.
nextOn return contains the index of the closest weight field bigger than the given rank.
weightOn return contains the weight to use to interpolate between next and previous. The weight is for 'next', so (1-weight) is the weight that needs to be applied to the previous data.

◆ getRandomItem()

int PowerupManager::WeightsData::getRandomItem ( int  rank,
uint64_t  random_number 
)

Computes a random item dependent on the rank of the kart and a given random number.

The value returned matches the enum value of the random item if single. In case of triple-item, the value will be the enum value plus the number of existing powerups (= POWERUP_LAST-POWERUP_FIRST+1)

Parameters
rankThe rank for which an item needs to be picked (between 0 and number_of_karts-1).
random_numberA random number used to 'randomly' select the item that was picked.

◆ interpolate()

void PowerupManager::WeightsData::interpolate ( WeightsData prev,
WeightsData next,
int  num_karts 
)

Defines the weights for this WeightsData object based on a linear interpolation between the previous and next WeightsData class (depending on the number of karts in this race and in previous and next).

Parameters
prevThe WeightsData object for less karts.
nextThe WeightData object for more karts.
num_kartsNumber of karts to extrapolate for.

◆ precomputeWeights()

void PowerupManager::WeightsData::precomputeWeights ( )

This function computes the item distribution for each possible rank in the race.

It creates a list which sums for each item the weights of all previous items. E.g. if the weight list starts with 20, 30, 0, 10, the summed array will contains 20, 50, 50, 60. This allows for a quick look up based on a single random number.

◆ readData()

void PowerupManager::WeightsData::readData ( int  num_karts,
const XMLNode node 
)

Reads in all weights for a given category and number of karts.

Parameters
num_kartsNumber of karts for this set of data.
nodeThe XML node with the data to read.

Member Data Documentation

◆ m_summed_weights_for_rank

std::vector< std::vector<unsigned> > PowerupManager::WeightsData::m_summed_weights_for_rank
private

This field is only populated for the WeightData class that is used during a race.

It contains for each rank the summed weights for easy lookup during a race.


The documentation for this class was generated from the following files: