OpenXcom
1.0
Open-source clone of the original X-Com
|
Holds pairs of relative weights and IDs. More...
#include <WeightedOptions.h>
Public Member Functions | |
WeightedOptions () | |
Create an empty set. | |
const std::string | choose () const |
Select from among the items. More... | |
const std::string | top () const |
Select the top item. More... | |
void | set (const std::string &id, size_t weight) |
Set an option's weight. More... | |
bool | empty () const |
Is this empty? | |
void | clear () |
Remove all entries. | |
void | load (const YAML::Node &node) |
Update our list with data from YAML. More... | |
YAML::Node | save () const |
Store our list in YAML. More... | |
Holds pairs of relative weights and IDs.
It is used to store options and make a random choice between them.
const std::string OpenXcom::WeightedOptions::choose | ( | ) | const |
Select from among the items.
Select a random choice from among the contents.
This MUST be called on non-empty objects. Each time this is called, the returned value can be different.
void OpenXcom::WeightedOptions::load | ( | const YAML::Node & | nd | ) |
Update our list with data from YAML.
Add the weighted options from a YAML::Node to a WeightedOptions.
The weight option list is not replaced, only values in nd will be added / changed.
nd | The YAML node (containing a map) with the new values. |
YAML::Node OpenXcom::WeightedOptions::save | ( | ) | const |
Store our list in YAML.
Send the WeightedOption contents to a YAML::Emitter.
void OpenXcom::WeightedOptions::set | ( | const std::string & | id, |
size_t | weight | ||
) |
Set an option's weight.
If weight is set to 0, the option is removed from the list of choices. If id already exists, the new weight replaces the old one, otherwise id is added to the list of choices, with weight as the weight.
id | The option name. |
weight | The option's new weight. |
const std::string OpenXcom::WeightedOptions::top | ( | ) | const |
Select the top item.
Select the most likely option.
This MUST be called on non-empty objects.