Skip to content

Commit

Permalink
take no more chances with terror.
Browse files Browse the repository at this point in the history
if the city's longitude and latitude doesn't match the city's longitude and latitude
notify the local authorities, as all logic and reason has just gone out the window.
  • Loading branch information
Warboy1982 committed May 14, 2014
1 parent 9c1847f commit ab2f6a4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Savegame/AlienMission.cpp
Expand Up @@ -31,6 +31,7 @@
#include "../Ruleset/RuleCountry.h"
#include "../Ruleset/Ruleset.h"
#include "../Ruleset/RuleUfo.h"
#include "../Ruleset/City.h"
#include "../Ruleset/UfoTrajectory.h"
#include "SavedGame.h"
#include "TerrorSite.h"
Expand Down Expand Up @@ -392,6 +393,24 @@ void AlienMission::ufoReachedWaypoint(Ufo &ufo, Game &engine, const Globe &globe
ufo.setAltitude(trajectory.getAltitude(nextWaypoint));
ufo.setTrajectoryPoint(nextWaypoint);
std::pair<double, double> pos = getWaypoint(trajectory, nextWaypoint, globe, *rules.getRegion(_region));

// screw it, we're not taking any chances, use the city's lon/lat info instead of the region's
// TODO: find out why there is a discrepency between generated city mission zones and the cities that generated them.
// honolulu: 3.6141230952747376, -0.37332941766009109
// UFO: lon: 3.61412 lat: -0.373329
// Zone: Longitudes: 3.61412 to 3.61412 Lattitudes: -0.373329 to -0.373329
// http://openxcom.org/bugs/openxcom/issues/615#comment_3292
if (ufo.getRules()->getType() == "STR_TERROR_SHIP" && _rule.getType() == "STR_ALIEN_TERROR" && trajectory.getZone(nextWaypoint) == RuleRegion::CITY_MISSION_ZONE)
{
while(!rules.locateCity(pos.first, pos.second))
{
Log(LOG_DEBUG) << "Longitude: " << pos.first << "Lattitude: " << pos.second << " invalid";
size_t city = RNG::generate(0, rules.getRegion(_region)->getCities()->size() - 1);
pos.first = rules.getRegion(_region)->getCities()->at(city)->getLongitude();
pos.second = rules.getRegion(_region)->getCities()->at(city)->getLatitude();
}
}

Waypoint *wp = new Waypoint();
wp->setLongitude(pos.first);
wp->setLatitude(pos.second);
Expand Down Expand Up @@ -426,13 +445,19 @@ void AlienMission::ufoReachedWaypoint(Ufo &ufo, Game &engine, const Globe &globe
std::stringstream error;
error << "Mission number: " << getId() << " in region: " << getRegion() << " trying to land at lon: " << ufo.getLongitude() << " lat: " << ufo.getLatitude() << " ufo is on flightpath: " << ufo.getTrajectory().getID() << " at point: " << ufo.getTrajectoryPoint() << ", no city found.";
Log(LOG_FATAL) << error.str();
std::vector<MissionArea> cityZones = engine.getRuleset()->getRegion(getRegion())->getMissionZones().at(RuleRegion::CITY_MISSION_ZONE).areas;
std::vector<MissionArea> cityZones = rules.getRegion(getRegion())->getMissionZones().at(RuleRegion::CITY_MISSION_ZONE).areas;
for (int i = 0; i != cityZones.size(); ++i)
{
error.str("");
error << "Zone " << i << ": Longitudes: " << cityZones.at(i).lonMin * M_PI / 180 << " to " << cityZones.at(i).lonMax * M_PI / 180 << " Lattitudes: " << cityZones.at(i).latMin * M_PI / 180 << " to " << cityZones.at(i).latMax * M_PI / 180;
Log(LOG_INFO) << error.str();
}
for (std::vector<City*>::const_iterator i = rules.getRegion(getRegion())->getCities()->begin(); i != rules.getRegion(getRegion())->getCities()->end(); ++i)
{
error.str("");
error << "City: " << (*i)->getName() << " Longitude: " << (*i)->getLongitude() << " Latitude: " << (*i)->getLatitude();
Log(LOG_INFO) << error.str();
}
assert(0 && "Terror Mission failed to find a city, please check your log file for more details");
}
game.getTerrorSites()->push_back(terrorSite);
Expand Down

0 comments on commit ab2f6a4

Please sign in to comment.