From: <geo...@us...> - 2011-07-16 20:06:04
|
Revision: 4048 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4048&view=rev Author: geoffthemedio Date: 2011-07-16 20:05:58 +0000 (Sat, 16 Jul 2011) Log Message: ----------- -Fixed bug with JumpsBetweenObjects in Condition.cpp that was passed non-system object ids to Universe::LeastJumpsPath which could lead to crashes when finding the jumps between non-system objects. -Added a no-parameter constructor to the Homeworld condition. The condition already deals with the case where no species names are passed in, and this allows it to be used more easily. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp trunk/FreeOrion/universe/Condition.h Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-07-16 16:37:21 UTC (rev 4047) +++ trunk/FreeOrion/universe/Condition.cpp 2011-07-16 20:05:58 UTC (rev 4048) @@ -733,6 +733,10 @@ /////////////////////////////////////////////////////////// // Homeworld // /////////////////////////////////////////////////////////// +Condition::Homeworld::Homeworld() : + m_names() +{} + Condition::Homeworld::Homeworld(const std::vector<const ValueRef::ValueRefBase<std::string>*>& names) : m_names(names) {} @@ -2204,7 +2208,7 @@ if (system_one && system_two) { // both condition-matching object and candidate are / in systems. // can just find the shortest path between the two systems - std::pair<std::list<int>, double> path = GetUniverse().LeastJumpsPath(one->ID(), two->ID()); + std::pair<std::list<int>, double> path = GetUniverse().LeastJumpsPath(system_one->ID(), system_two->ID()); if (!path.first.empty()) // if path.first is empty, no path exists between the systems return static_cast<int>(path.first.size()); @@ -2213,8 +2217,8 @@ if (const Fleet* fleet = FleetFromObject(two)) { // other object is a fleet that is between systems // need to check shortest path from systems on either side of starlane fleet is on - std::pair<std::list<int>, double> path1 = GetUniverse().LeastJumpsPath(one->ID(), fleet->PreviousSystemID()); - std::pair<std::list<int>, double> path2 = GetUniverse().LeastJumpsPath(one->ID(), fleet->NextSystemID()); + std::pair<std::list<int>, double> path1 = GetUniverse().LeastJumpsPath(system_one->ID(), fleet->PreviousSystemID()); + std::pair<std::list<int>, double> path2 = GetUniverse().LeastJumpsPath(system_one->ID(), fleet->NextSystemID()); if (int jumps = static_cast<int>(std::max(path1.first.size(), path2.first.size()))) return jumps - 1; } @@ -2224,8 +2228,8 @@ if (const Fleet* fleet = FleetFromObject(two)) { // other object is a fleet that is between systems // need to check shortest path from systems on either side of starlane fleet is on - std::pair<std::list<int>, double> path1 = GetUniverse().LeastJumpsPath(two->ID(), fleet->PreviousSystemID()); - std::pair<std::list<int>, double> path2 = GetUniverse().LeastJumpsPath(two->ID(), fleet->NextSystemID()); + std::pair<std::list<int>, double> path1 = GetUniverse().LeastJumpsPath(system_two->ID(), fleet->PreviousSystemID()); + std::pair<std::list<int>, double> path2 = GetUniverse().LeastJumpsPath(system_two->ID(), fleet->NextSystemID()); if (int jumps = static_cast<int>(std::max(path1.first.size(), path2.first.size()))) return jumps - 1; } Modified: trunk/FreeOrion/universe/Condition.h =================================================================== --- trunk/FreeOrion/universe/Condition.h 2011-07-16 16:37:21 UTC (rev 4047) +++ trunk/FreeOrion/universe/Condition.h 2011-07-16 20:05:58 UTC (rev 4048) @@ -248,6 +248,7 @@ * any species in the current game Universe. */ struct Condition::Homeworld : Condition::ConditionBase { + Homeworld(); Homeworld(const std::vector<const ValueRef::ValueRefBase<std::string>*>& names); virtual ~Homeworld(); virtual std::string Description(bool negated = false) const; |