MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / chooseOption

Function chooseOption

source/game/StarDungeonGenerator.cpp:58–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 }
57
58 ConnectorConstPtr chooseOption(List<ConnectorConstPtr>& options, RandomSource& rnd) {
59 float distribution = 0;
60 for (size_t i = 0; i < options.size(); i++)
61 distribution += options[i]->part()->chance();
62 float pick = rnd.randf() * distribution;
63 for (size_t i = 0; i < options.size(); i++) {
64 pick -= options[i]->part()->chance();
65 if (pick <= 0)
66 return options.takeAt(i);
67 }
68 // float rounding is always fun
69 return options.takeAt(options.size() - 1);
70 }
71
72 List<RuleConstPtr> Rule::readRules(Json const& rules) {
73 List<RuleConstPtr> result;

Callers 1

buildDungeonMethod · 0.85

Calls 5

chanceMethod · 0.80
partMethod · 0.80
randfMethod · 0.80
takeAtMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected