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

Method getRandomMapBlock

src/Ruleset/RuleTerrain.cpp:123–148  ·  view source on GitHub ↗

* Gets a random mapblock within the given constraints. * @param maxsize The maximum size of the mapblock (10 or 20 or 999 - don't care). * @param type Whether this must be a block of a certain type. * @param force Whether to enforce the max size. * @return Pointer to the mapblock. */

Source from the content-addressed store, hash-verified

121 * @return Pointer to the mapblock.
122 */
123MapBlock* RuleTerrain::getRandomMapBlock(int maxsize, MapBlockType type, bool force)
124{
125 std::vector<MapBlock*> compliantMapBlocks;
126
127 for (std::vector<MapBlock*>::const_iterator i = _mapBlocks.begin(); i != _mapBlocks.end(); ++i)
128 {
129 if (((force && (*i)->getSizeX() == maxsize) ||
130 (!force && (*i)->getSizeX() <= maxsize)) &&
131 ((*i)->getType() == type || (*i)->getSubType() == type))
132 {
133 for (int j = 0; j != (*i)->getRemainingUses(); ++j)
134 {
135 compliantMapBlocks.push_back((*i));
136 }
137 }
138 }
139
140 if (compliantMapBlocks.empty()) return 0;
141
142 size_t n = RNG::generate(0, compliantMapBlocks.size() - 1);
143
144 if (type == MT_DEFAULT)
145 compliantMapBlocks[n]->markUsed();
146
147 return compliantMapBlocks[n];
148}
149
150/**
151 * Gets a mapblock with a given name.

Callers 1

generateMapMethod · 0.80

Calls 7

generateFunction · 0.85
getSizeXMethod · 0.80
getSubTypeMethod · 0.80
getRemainingUsesMethod · 0.80
markUsedMethod · 0.80
getTypeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected