Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Don't go out of bounds when picking a race for a mission
- Loading branch information
Showing
with
9 additions
and
3 deletions.
-
+5
−0
src/Geoscape/GeoscapeState.cpp
-
+4
−3
src/Mod/RuleAlienMission.cpp
|
@@ -2643,6 +2643,11 @@ bool GeoscapeState::processCommand(RuleMissionScript *command) |
|
|
missionRace = command->generate(month, GEN_RACE); |
|
|
} |
|
|
|
|
|
if (missionRace.empty()) |
|
|
{ |
|
|
throw Exception("Error proccessing mission script named: " + command->getType() + ", mission type: " + missionType + " has no available races"); |
|
|
} |
|
|
|
|
|
// we're bound to end up with typos, so let's throw an exception instead of simply returning false |
|
|
// that way, the modder can fix their mistake |
|
|
if (mod->getAlienRace(missionRace) == 0) |
|
|
|
@@ -142,9 +142,10 @@ void RuleAlienMission::load(const YAML::Node &node) |
|
|
*/ |
|
|
std::string RuleAlienMission::generateRace(const size_t monthsPassed) const |
|
|
{ |
|
|
std::vector<std::pair<size_t, WeightedOptions*> >::const_reverse_iterator rc = _raceDistribution.rbegin(); |
|
|
while (monthsPassed < rc->first) |
|
|
++rc; |
|
|
std::vector<std::pair<size_t, WeightedOptions*> >::const_reverse_iterator rc; |
|
|
for (rc = _raceDistribution.rbegin(); rc != _raceDistribution.rend() && monthsPassed < rc->first; ++rc); |
|
|
if (rc == _raceDistribution.rend()) |
|
|
return ""; |
|
|
return rc->second->choose(); |
|
|
} |
|
|
|
|
|