Skip to content

Commit dbbbcb3

Browse files
committed
Fix crafts not targeting custom alien bases correctly
1 parent f779159 commit dbbbcb3

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎src/Savegame/AlienMission.cpp‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ class matchById: public std::unary_function<const AlienBase *, bool>
6161
{
6262
public:
6363
/// Remember ID.
64-
matchById(int id) : _id(id) { /* Empty by design. */ }
64+
matchById(int id, std::string type) : _id(id), _type(type) { /* Empty by design. */ }
6565
/// Match with stored ID.
66-
bool operator()(const AlienBase *ab) const { return ab->getId() == _id; }
66+
bool operator()(const AlienBase *ab) const { return ab->getId() == _id && ab->getDeployment()->getMarkerName() == _type; }
6767
private:
6868
int _id;
69+
std::string _type;
6970
};
7071

7172
/**
@@ -84,8 +85,15 @@ void AlienMission::load(const YAML::Node& node, SavedGame &game)
8485
_uniqueID = node["uniqueID"].as<int>(_uniqueID);
8586
if (const YAML::Node &base = node["alienBase"])
8687
{
87-
int id = base.as<int>();
88-
std::vector<AlienBase*>::const_iterator found = std::find_if (game.getAlienBases()->begin(), game.getAlienBases()->end(), matchById(id));
88+
int id = base.as<int>(-1);
89+
std::string type = "STR_ALIEN_BASE";
90+
// New format
91+
if (id == -1)
92+
{
93+
id = base["id"].as<int>();
94+
type = base["type"].as<std::string>();
95+
}
96+
std::vector<AlienBase*>::const_iterator found = std::find_if(game.getAlienBases()->begin(), game.getAlienBases()->end(), matchById(id, type));
8997
if (found == game.getAlienBases()->end())
9098
{
9199
throw Exception("Corrupted save: Invalid base for mission.");
@@ -112,7 +120,7 @@ YAML::Node AlienMission::save() const
112120
node["uniqueID"] = _uniqueID;
113121
if (_base)
114122
{
115-
node["alienBase"] = _base->getId();
123+
node["alienBase"] = _base->saveId();
116124
}
117125
node["missionSiteZone"] = _missionSiteZone;
118126
return node;

‎src/Savegame/Craft.cpp‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,26 @@ void Craft::load(const YAML::Node &node, const Mod *mod, SavedGame *save)
179179
}
180180
}
181181
}
182-
else if (type == "STR_ALIEN_BASE")
182+
else
183183
{
184-
for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i)
184+
// Backwards compatibility
185+
if (type == "STR_ALIEN_TERROR")
186+
type = "STR_TERROR_SITE";
187+
bool found = false;
188+
for (std::vector<MissionSite*>::iterator i = save->getMissionSites()->begin(); i != save->getMissionSites()->end() && !found; ++i)
185189
{
186-
if ((*i)->getId() == id)
190+
if ((*i)->getId() == id && (*i)->getDeployment()->getMarkerName() == type)
187191
{
188192
setDestination(*i);
189-
break;
193+
found = true;
190194
}
191195
}
192-
}
193-
else
194-
{
195-
// Backwards compatibility
196-
if (type == "STR_ALIEN_TERROR")
197-
type = "STR_TERROR_SITE";
198-
for (std::vector<MissionSite*>::iterator i = save->getMissionSites()->begin(); i != save->getMissionSites()->end(); ++i)
196+
for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end() && !found; ++i)
199197
{
200198
if ((*i)->getId() == id && (*i)->getDeployment()->getMarkerName() == type)
201199
{
202200
setDestination(*i);
203-
break;
201+
found = true;
204202
}
205203
}
206204
}

0 commit comments

Comments
 (0)