MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / genLook

Method genLook

src/Ruleset/SoldierNamePool.cpp:127–155  ·  view source on GitHub ↗

* Generates an int representing the index of the soldier's look, when passed the maximum index value. * @param numLooks The maximum index. * @return The index of the soldier's look. */

Source from the content-addressed store, hash-verified

125 * @return The index of the soldier's look.
126 */
127size_t SoldierNamePool::genLook(size_t numLooks)
128{
129 int look = 0;
130 const int minimumChance = 2; // minimum chance of a look being selected if it isn't enumerated. This ensures that looks MUST be zeroed to not appear.
131
132 while (_lookWeights.size() < numLooks)
133 {
134 _lookWeights.push_back(minimumChance);
135 _totalWeight += minimumChance;
136 }
137 while (_lookWeights.size() > numLooks)
138 {
139 _totalWeight -= _lookWeights.back();
140 _lookWeights.pop_back();
141 }
142
143 int random = RNG::generate(0, _totalWeight);
144 for (std::vector<int>::iterator i = _lookWeights.begin(); i != _lookWeights.end(); ++i)
145 {
146 if (random <= *i)
147 {
148 return look;
149 }
150 random -= *i;
151 ++look;
152 }
153
154 return RNG::generate(0, numLooks - 1);
155}
156
157}

Callers 1

SoldierMethod · 0.80

Calls 1

generateFunction · 0.85

Tested by

no test coverage detected