This object stores all the weights for one particular number of karts.
More...
|
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.
|
|
|
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.
|
|
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.
◆ 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
-
rank | Rank that is to be interpolated. |
prev | On return contains the index of the closest weight field smaller than the given rank. |
next | On return contains the index of the closest weight field bigger than the given rank. |
weight | On 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
-
rank | The rank for which an item needs to be picked (between 0 and number_of_karts-1). |
random_number | A random number used to 'randomly' select the item that was picked. |
◆ interpolate()
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
-
prev | The WeightsData object for less karts. |
next | The WeightData object for more karts. |
num_karts | Number 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_karts | Number of karts for this set of data. |
node | The XML node with the data to read. |
◆ 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: