From: <geo...@us...> - 2009-09-06 07:10:03
|
Revision: 3145 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3145&view=rev Author: geoffthemedio Date: 2009-09-06 07:09:55 +0000 (Sun, 06 Sep 2009) Log Message: ----------- Re-re-wrote Or and And condition evaluation functions, and semi-rewrote Not condition evaluation function to be clearer Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2009-09-06 05:23:58 UTC (rev 3144) +++ trunk/FreeOrion/universe/Condition.cpp 2009-09-06 07:09:55 UTC (rev 3145) @@ -1494,17 +1494,34 @@ void Condition::And::Eval(const UniverseObject* source, ObjectSet& targets, ObjectSet& non_targets, SearchDomain search_domain/* = NON_TARGETS*/) const { - // if search domain is non targets, evalucate first operand condition on non targets, to assemble an - // initial targets set. if search domain is targets, evaluate first (and all other) operand condition - // on existing targets set - m_operands[0]->Eval(source, targets, non_targets, search_domain); + if (search_domain == NON_TARGETS) { + ObjectSet partly_checked_non_targets; - // regardless of whether search domain is TARGET or NON_TARGETS, evaluate remaining operand conditions - // on targets set, removing any targets that don't meet additional conditions, and stopping early if all - // targets are removed - for (unsigned int i = 1; i < m_operands.size(); ++i) { - if (targets.empty()) break; - m_operands[i]->Eval(source, targets, non_targets, TARGETS); + // move items in non_targets set that pass first operand condition into + // partly_checked_non_targets set + m_operands[0]->Eval(source, partly_checked_non_targets, non_targets, NON_TARGETS); + + // move items that don't pass one of the other conditions back to non_targets + for (unsigned int i = 1; i < m_operands.size(); ++i) { + if (partly_checked_non_targets.empty()) break; + m_operands[i]->Eval(source, partly_checked_non_targets, non_targets, TARGETS); + } + + // merge items that passed all operand conditions into targets + targets.insert(partly_checked_non_targets.begin(), partly_checked_non_targets.end()); + partly_checked_non_targets.clear(); + + // items already in targets set are not checked/ and remain in targets set even if + // they don't match one of the operand conditions + + } else { + // check all operand conditions on all objects in the targets set, moving those + // that don't pass a condition to the non-targets set + + for (unsigned int i = 0; i < m_operands.size(); ++i) { + if (targets.empty()) break; + m_operands[i]->Eval(source, targets, non_targets, TARGETS); + } } } @@ -1556,8 +1573,9 @@ void Condition::Or::Eval(const UniverseObject* source, ObjectSet& targets, ObjectSet& non_targets, SearchDomain search_domain/* = NON_TARGETS*/) const { if (search_domain == NON_TARGETS) { - // if search domain is non targets, evalucate with search domain non_targets on each operand condition, using - // the remaining non_targets from the previous operand condition as the non_targets for the next operand condition + // check each item in the non-targets set against each of the operand conditions + // if a non-target item matches an operand condition, move the item to the + // targets set. for (unsigned int i = 0; i < m_operands.size(); ++i) { if (non_targets.empty()) break; @@ -1565,20 +1583,24 @@ } } else { - // if search domain is targets, create a temporary empty new_targets set, and use the targets set as the - // effective non_targets set while evaluating each condition on the effective non_targets set. this way, - // if a target set object matches any conditions, it will be added to the new_targets set. after evaluating - // all conditions on the effective non_targets set, add the remaining objects to the real non_targets set, - // and set the real targets set equal to the new_targets set + ObjectSet partly_checked_targets; - ObjectSet new_targets; // new empty targets set - ObjectSet& temp_non_targets = targets; - for (unsigned int i = 0; i < m_operands.size(); ++i) { - if (temp_non_targets.empty()) break; - m_operands[i]->Eval(source, new_targets, temp_non_targets, NON_TARGETS); + // move items in targets set the fail the first operand condition into + // partly_checked_targets set + m_operands[0]->Eval(source, targets, partly_checked_targets, TARGETS); + + // move items that pass any of the other conditions back into targets + for (unsigned int i = 1; i < m_operands.size(); ++i) { + if (partly_checked_targets.empty()) break; + m_operands[i]->Eval(source, targets, partly_checked_targets, NON_TARGETS); } - non_targets.insert(temp_non_targets.begin(), temp_non_targets.end()); // move targets set object that didn't match any conditions to non_targets set - targets = new_targets; // set targets set equal to set of objects that matched at least one condition + + // merge items that failed all operand conditions into non_targets + non_targets.insert(partly_checked_targets.begin(), partly_checked_targets.end()); + partly_checked_targets.clear(); + + // items already in non_targets set are not checked and remain in + // non_targets set even if they pass one or more of the conditions } } @@ -1627,7 +1649,15 @@ void Condition::Not::Eval(const UniverseObject* source, ObjectSet& targets, ObjectSet& non_targets, SearchDomain search_domain/* = NON_TARGETS*/) const { - m_operand->Eval(source, non_targets, targets, search_domain == TARGETS ? NON_TARGETS : TARGETS); + if (search_domain == NON_TARGETS) { + // search non_targets set for items that don't meet the operand + // condition, and move those to the targets set + m_operand->Eval(source, non_targets, targets, TARGETS); // swapping order of targets and non_targets set parameters and TARGETS / NON_TARGETS search domain effects NOT on requested search domain + } else { + // search targets set for items that meet the operand condition + // condition, and move those to the non_targets set + m_operand->Eval(source, non_targets, targets, NON_TARGETS); + } } std::string Condition::Not::Description(bool negated/* = false*/) const |
From: <geo...@us...> - 2009-09-07 18:52:11
|
Revision: 3149 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3149&view=rev Author: geoffthemedio Date: 2009-09-07 18:52:01 +0000 (Mon, 07 Sep 2009) Log Message: ----------- Implemented enemy affiliation condition, and rewrote self affiliation condition to be a bit more readable and have comments explaining itself. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2009-09-07 11:13:09 UTC (rev 3148) +++ trunk/FreeOrion/universe/Condition.cpp 2009-09-07 18:52:01 UTC (rev 3149) @@ -376,12 +376,28 @@ bool Condition::EmpireAffiliation::Match(const UniverseObject* source, const UniverseObject* target) const { + int empire_id = m_empire_id->Eval(source, target); + switch (m_affiliation) { case AFFIL_SELF: - return m_exclusive ? target->WhollyOwnedBy(m_empire_id->Eval(source, target)) : target->OwnedBy(m_empire_id->Eval(source, target)); - break; + if (m_exclusive) { + // target object owned only by specified empire + return target->WhollyOwnedBy(empire_id); + } else { + // target object owned by specified empire, and possibly others + return target->OwnedBy(empire_id); + } + break; case AFFIL_ENEMY: - // TODO + if (m_exclusive) { + // target has an owner, but isn't owned by specified empire + return (!target->Owners().empty() && !target->OwnedBy(empire_id)); + } else { + // at least one of target's owners is not specified empire, but specified empire may also own target + return (target->Owners().size() > 1 || + (!target->Owners().empty() && !target->OwnedBy(empire_id)) + ); + } break; case AFFIL_ALLY: // TODO |
From: <geo...@us...> - 2011-07-27 02:18:46
|
Revision: 4072 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4072&view=rev Author: geoffthemedio Date: 2011-07-27 02:18:39 +0000 (Wed, 27 Jul 2011) Log Message: ----------- GCC compile fix from sourceforge bug report. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-07-26 08:32:15 UTC (rev 4071) +++ trunk/FreeOrion/universe/Condition.cpp 2011-07-27 02:18:39 UTC (rev 4072) @@ -1609,9 +1609,8 @@ /////////////////////////////////////////////////////////// // PlanetType // /////////////////////////////////////////////////////////// -Condition::PlanetType::PlanetType(const std::vector<const ValueRef::ValueRefBase<::PlanetType>*>& types) : - m_types(types) -{} +Condition::PlanetType::PlanetType(const std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>& types) : + m_types(types){} Condition::PlanetType::~PlanetType() { @@ -1621,7 +1620,7 @@ } namespace { - bool PlanetTypeSimpleMatch(const UniverseObject* candidate, const std::vector<::PlanetType>& types) + bool PlanetTypeSimpleMatch(const UniverseObject* candidate, const std::vector< ::PlanetType>& types) { if (!candidate) return false; @@ -1648,7 +1647,7 @@ bool simple_eval_safe = parent_context.condition_root_candidate || RootCandidateInvariant(); if (simple_eval_safe) { // check each valueref for invariance to local candidate - for (std::vector<const ValueRef::ValueRefBase<::PlanetType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->LocalCandidateInvariant()) { @@ -1659,9 +1658,9 @@ } if (simple_eval_safe) { // evaluate types once, and use to check all candidate objects - std::vector<::PlanetType> types; + std::vector< ::PlanetType> types; // get all types from valuerefs - for (std::vector<const ValueRef::ValueRefBase<::PlanetType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { types.push_back((*it)->Eval(parent_context)); @@ -1688,7 +1687,7 @@ bool Condition::PlanetType::RootCandidateInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->RootCandidateInvariant()) @@ -1699,7 +1698,7 @@ bool Condition::PlanetType::TargetInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->TargetInvariant()) @@ -1760,7 +1759,7 @@ planet = objects.Object<Planet>(building->PlanetID()); } if (planet) { - for (std::vector<const ValueRef::ValueRefBase<::PlanetType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if ((*it)->Eval(ScriptingContext(local_context)) == planet->Type()) @@ -1773,7 +1772,7 @@ /////////////////////////////////////////////////////////// // PlanetSize // /////////////////////////////////////////////////////////// -Condition::PlanetSize::PlanetSize(const std::vector<const ValueRef::ValueRefBase<::PlanetSize>*>& sizes) : +Condition::PlanetSize::PlanetSize(const std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*>& sizes) : m_sizes(sizes) {} @@ -1785,7 +1784,7 @@ } namespace { - bool PlanetSizeSimpleMatch(const UniverseObject* candidate, const std::vector<::PlanetSize>& sizes) + bool PlanetSizeSimpleMatch(const UniverseObject* candidate, const std::vector< ::PlanetSize>& sizes) { if (!candidate) return false; @@ -1800,7 +1799,7 @@ } if (planet) { // is it one of the specified building types? - for (std::vector<::PlanetSize>::const_iterator it = sizes.begin(); + for (std::vector< ::PlanetSize>::const_iterator it = sizes.begin(); it != sizes.end(); ++it) { if (planet->Size() == *it) @@ -1817,7 +1816,7 @@ bool simple_eval_safe = parent_context.condition_root_candidate || RootCandidateInvariant(); if (simple_eval_safe) { // check each valueref for invariance to local candidate - for (std::vector<const ValueRef::ValueRefBase<::PlanetSize>*>::const_iterator it = m_sizes.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*>::const_iterator it = m_sizes.begin(); it != m_sizes.end(); ++it) { if (!(*it)->LocalCandidateInvariant()) { @@ -1828,9 +1827,9 @@ } if (simple_eval_safe) { // evaluate types once, and use to check all candidate objects - std::vector<::PlanetSize> sizes; + std::vector< ::PlanetSize> sizes; // get all types from valuerefs - for (std::vector<const ValueRef::ValueRefBase<::PlanetSize>*>::const_iterator it = m_sizes.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*>::const_iterator it = m_sizes.begin(); it != m_sizes.end(); ++it) { sizes.push_back((*it)->Eval(parent_context)); @@ -1857,7 +1856,7 @@ bool Condition::PlanetSize::RootCandidateInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetSize>*>::const_iterator it = m_sizes.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*>::const_iterator it = m_sizes.begin(); it != m_sizes.end(); ++it) { if (!(*it)->RootCandidateInvariant()) @@ -1868,7 +1867,7 @@ bool Condition::PlanetSize::TargetInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetSize>*>::const_iterator it = m_sizes.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*>::const_iterator it = m_sizes.begin(); it != m_sizes.end(); ++it) { if (!(*it)->TargetInvariant()) @@ -1940,7 +1939,7 @@ /////////////////////////////////////////////////////////// // PlanetEnvironment // /////////////////////////////////////////////////////////// -Condition::PlanetEnvironment::PlanetEnvironment(const std::vector<const ValueRef::ValueRefBase<::PlanetEnvironment>*>& environments) : +Condition::PlanetEnvironment::PlanetEnvironment(const std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*>& environments) : m_environments(environments) {} @@ -1952,7 +1951,7 @@ } namespace { - bool PlanetEnvironmentSimpleMatch(const UniverseObject* candidate, const std::vector<::PlanetEnvironment>& environments) + bool PlanetEnvironmentSimpleMatch(const UniverseObject* candidate, const std::vector< ::PlanetEnvironment>& environments) { if (!candidate) return false; @@ -1967,7 +1966,7 @@ } if (planet) { // is it one of the specified building types? - for (std::vector<::PlanetEnvironment>::const_iterator it = environments.begin(); + for (std::vector< ::PlanetEnvironment>::const_iterator it = environments.begin(); it != environments.end(); ++it) { if (planet->EnvironmentForSpecies() == *it) @@ -1984,7 +1983,7 @@ bool simple_eval_safe = parent_context.condition_root_candidate || RootCandidateInvariant(); if (simple_eval_safe) { // check each valueref for invariance to local candidate - for (std::vector<const ValueRef::ValueRefBase<::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); it != m_environments.end(); ++it) { if (!(*it)->LocalCandidateInvariant()) { @@ -1995,9 +1994,9 @@ } if (simple_eval_safe) { // evaluate types once, and use to check all candidate objects - std::vector<::PlanetEnvironment> environments; + std::vector< ::PlanetEnvironment> environments; // get all types from valuerefs - for (std::vector<const ValueRef::ValueRefBase<::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); it != m_environments.end(); ++it) { environments.push_back((*it)->Eval(parent_context)); @@ -2024,7 +2023,7 @@ bool Condition::PlanetEnvironment::RootCandidateInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); it != m_environments.end(); ++it) { if (!(*it)->RootCandidateInvariant()) @@ -2035,7 +2034,7 @@ bool Condition::PlanetEnvironment::TargetInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*>::const_iterator it = m_environments.begin(); it != m_environments.end(); ++it) { if (!(*it)->TargetInvariant()) @@ -2465,7 +2464,7 @@ /////////////////////////////////////////////////////////// // StarType // /////////////////////////////////////////////////////////// -Condition::StarType::StarType(const std::vector<const ValueRef::ValueRefBase<::StarType>*>& types) : +Condition::StarType::StarType(const std::vector<const ValueRef::ValueRefBase< ::StarType>*>& types) : m_types(types) {} @@ -2477,7 +2476,7 @@ } namespace { - bool StarTypeSimpleMatch(const UniverseObject* candidate, const std::vector<::StarType>& types) + bool StarTypeSimpleMatch(const UniverseObject* candidate, const std::vector< ::StarType>& types) { if (!candidate) return false; @@ -2497,7 +2496,7 @@ bool simple_eval_safe = parent_context.condition_root_candidate || RootCandidateInvariant(); if (simple_eval_safe) { // check each valueref for invariance to local candidate - for (std::vector<const ValueRef::ValueRefBase<::StarType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::StarType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->LocalCandidateInvariant()) { @@ -2508,9 +2507,9 @@ } if (simple_eval_safe) { // evaluate types once, and use to check all candidate objects - std::vector<::StarType> types; + std::vector< ::StarType> types; // get all types from valuerefs - for (std::vector<const ValueRef::ValueRefBase<::StarType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::StarType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { types.push_back((*it)->Eval(parent_context)); @@ -2537,7 +2536,7 @@ bool Condition::StarType::RootCandidateInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::StarType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::StarType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->RootCandidateInvariant()) @@ -2548,7 +2547,7 @@ bool Condition::StarType::TargetInvariant() const { - for (std::vector<const ValueRef::ValueRefBase<::StarType>*>::const_iterator it = m_types.begin(); + for (std::vector<const ValueRef::ValueRefBase< ::StarType>*>::const_iterator it = m_types.begin(); it != m_types.end(); ++it) { if (!(*it)->TargetInvariant()) @@ -3765,7 +3764,7 @@ // assemble all systems that are or that contain subcondition matches Condition::ObjectSet destination_systems; for (Condition::ObjectSet::iterator it = destination_objects.begin(); it != destination_objects.end(); ++it) - if (const System* system = objects.Object<::System>((*it)->SystemID())) + if (const System* system = objects.Object< ::System>((*it)->SystemID())) destination_systems.insert(system); if (destination_systems.empty()) |
From: <geo...@us...> - 2011-08-07 00:42:37
|
Revision: 4101 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4101&view=rev Author: geoffthemedio Date: 2011-08-07 00:42:31 +0000 (Sun, 07 Aug 2011) Log Message: ----------- Fixed bug with WithinStarlaneJumps condition in cases where it was checking the number of jumps between two systems, which would return one more than the actual number of jumps. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-08-06 21:09:34 UTC (rev 4100) +++ trunk/FreeOrion/universe/Condition.cpp 2011-08-07 00:42:31 UTC (rev 4101) @@ -3554,7 +3554,7 @@ // can just find the shortest path between the two systems 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()); + return static_cast<int>(path.first.size() - 1); } else if (system_one) { // just object one is / in a system. |
From: <geo...@us...> - 2011-09-01 21:50:44
|
Revision: 4217 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4217&view=rev Author: geoffthemedio Date: 2011-09-01 21:50:37 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Tweaked layout of And and Or condition Dump output. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-09-01 21:49:40 UTC (rev 4216) +++ trunk/FreeOrion/universe/Condition.cpp 2011-09-01 21:50:37 UTC (rev 4217) @@ -4765,7 +4765,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += DumpIndent() + "]\n"; + retval += "\n" + DumpIndent() + "]\n"; return retval; } @@ -4865,7 +4865,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += DumpIndent() + "]\n"; + retval += "\n" + DumpIndent() + "]\n"; return retval; } |
From: <geo...@us...> - 2011-09-02 05:57:12
|
Revision: 4220 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4220&view=rev Author: geoffthemedio Date: 2011-09-02 05:57:06 +0000 (Fri, 02 Sep 2011) Log Message: ----------- Tweaked Or and And condition Dump functions to remove extra newlines. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-09-01 23:31:00 UTC (rev 4219) +++ trunk/FreeOrion/universe/Condition.cpp 2011-09-02 05:57:06 UTC (rev 4220) @@ -4765,7 +4765,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += "\n" + DumpIndent() + "]\n"; + retval += "\n" + DumpIndent() + "]"; return retval; } @@ -4865,7 +4865,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += "\n" + DumpIndent() + "]\n"; + retval += "\n" + DumpIndent() + "]"; return retval; } |
From: <geo...@us...> - 2011-09-16 02:31:07
|
Revision: 4271 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4271&view=rev Author: geoffthemedio Date: 2011-09-16 02:31:00 +0000 (Fri, 16 Sep 2011) Log Message: ----------- Fixed some crashes when created autogenerated descriptions of conditions with an optional empire id parameter. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-09-16 01:52:43 UTC (rev 4270) +++ trunk/FreeOrion/universe/Condition.cpp 2011-09-16 02:31:00 UTC (rev 4271) @@ -723,13 +723,15 @@ std::string Condition::EmpireAffiliation::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } if (m_affiliation == AFFIL_SELF) { std::string description_str = "DESC_EMPIRE_AFFILIATION_SELF"; @@ -3523,13 +3525,15 @@ std::string Condition::ProducedByEmpire::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } std::string description_str = "DESC_PRODUCED_BY_EMPIRE"; if (negated) @@ -3979,13 +3983,15 @@ std::string Condition::VisibleToEmpire::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } std::string description_str = "DESC_VISIBLE_TO_EMPIRE"; if (negated) @@ -4755,13 +4761,15 @@ std::string Condition::ExploredByEmpire::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } std::string description_str = "DESC_EXPLORED_BY_EMPIRE"; if (negated) @@ -4902,13 +4910,15 @@ std::string Condition::FleetSupplyableByEmpire::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } std::string description_str = "DESC_SUPPLY_CONNECTED_FLEET"; if (negated) @@ -5055,13 +5065,15 @@ std::string Condition::ResourceSupplyConnectedByEmpire::Description(bool negated/* = false*/) const { std::string empire_str; - int empire_id = ALL_EMPIRES; - if (ValueRef::ConstantExpr(m_empire_id)) - empire_id = m_empire_id->Eval(); - if (const Empire* empire = Empires().Lookup(empire_id)) - empire_str = empire->Name(); - else - empire_str = m_empire_id->Description(); + if (m_empire_id) { + int empire_id = ALL_EMPIRES; + if (ValueRef::ConstantExpr(m_empire_id)) + empire_id = m_empire_id->Eval(); + if (const Empire* empire = Empires().Lookup(empire_id)) + empire_str = empire->Name(); + else + empire_str = m_empire_id->Description(); + } std::string description_str = "DESC_SUPPLY_CONNECTED_RESOURCE"; if (negated) |
From: <geo...@us...> - 2011-10-01 22:29:08
|
Revision: 4318 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4318&view=rev Author: geoffthemedio Date: 2011-10-01 22:29:02 +0000 (Sat, 01 Oct 2011) Log Message: ----------- Made various conditions with low and high parameters match objects with whatever value applies equal to the low or high value, instead not matching if equal to the high value. I think this range rule is more obvious / intuitive / clear / consistent, particularly for integer-valued tests. For real-valued tests, this may necessitate using RangeMaxValueRef - 0.001 or similar to exclude the upper end of the range (eg. when a meter equals its associated max meter), but I think this is an acceptable tradeoff. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-10-01 22:28:16 UTC (rev 4317) +++ trunk/FreeOrion/universe/Condition.cpp 2011-10-01 22:29:02 UTC (rev 4318) @@ -150,7 +150,7 @@ int matched = condition_targets.size(); int low = (m_low ? m_low->Eval(local_context) : 0); int high = (m_high ? m_high->Eval(local_context) : INT_MAX); - in_range = (low <= matched && matched < high); + in_range = (low <= matched && matched <= high); } // transfer objects to or from candidate set, according to whether number of matches was within @@ -207,7 +207,7 @@ int low = (m_low ? std::max(0, m_low->Eval(local_context)) : 0); int high = (m_high ? std::min(m_high->Eval(local_context), IMPOSSIBLY_LARGE_TURN) : IMPOSSIBLY_LARGE_TURN); int turn = CurrentTurn(); - bool match = (low <= turn && turn < high); + bool match = (low <= turn && turn <= high); if (match && search_domain == NON_MATCHES) { // move all objects from non_matches to matches @@ -264,7 +264,7 @@ double low = (m_low ? std::max(0, m_low->Eval(local_context)) : 0); double high = (m_high ? std::min(m_high->Eval(local_context), IMPOSSIBLY_LARGE_TURN) : IMPOSSIBLY_LARGE_TURN); int turn = CurrentTurn(); - return (low <= turn && turn < high); + return (low <= turn && turn <= high); } /////////////////////////////////////////////////////////// @@ -777,7 +777,7 @@ case AFFIL_ENEMY: retval += "EnemyOf"; break; case AFFIL_ALLY: retval += "AllyOf"; break; case AFFIL_ANY: retval += "AnyEmpire"; break; - default: retval += "?"; break; + default: retval += "?"; break; } if (m_empire_id) retval += " empire = " + m_empire_id->Dump() + "\n"; @@ -1508,7 +1508,7 @@ int special_since_turn = it->second; - return low_turn <= special_since_turn && special_since_turn < high_turn; + return low_turn <= special_since_turn && special_since_turn <= high_turn; } } @@ -1624,9 +1624,10 @@ namespace { bool CreatedOnTurnSimpleMatch(const UniverseObject* candidate, int low, int high) { - return candidate && - low <= candidate->CreationTurn() && - candidate->CreationTurn() < high; + if (!candidate) + return false; + int turn = candidate->CreationTurn(); + return low <= turn && turn <= high; } } @@ -3173,7 +3174,7 @@ for (std::vector<std::string>::const_iterator it = parts.begin(); it != parts.end(); ++it) if (*it == name || (name.empty() && !(*it).empty())) // # of copies of specified part, or total number of parts if no part name specified ++count; - return (low <= count && count < high); + return (low <= count && count <= high); } } @@ -3288,7 +3289,7 @@ ++count; } } - return (low <= count && count < high); + return (low <= count && count <= high); } } @@ -3694,7 +3695,7 @@ if (const Meter* meter = candidate->GetMeter(meter_type)) { double value = meter->Initial(); // match Initial rather than Current to make results reproducible in a given turn, until back propegation happens - return low <= value && value < high; + return low <= value && value <= high; } return false; |
From: <geo...@us...> - 2011-10-09 21:05:44
|
Revision: 4368 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4368&view=rev Author: geoffthemedio Date: 2011-10-09 21:05:37 +0000 (Sun, 09 Oct 2011) Log Message: ----------- Renamed some containers from "targets" to "matches" in Number and SortedNumberOf conditions. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-10-09 20:59:22 UTC (rev 4367) +++ trunk/FreeOrion/universe/Condition.cpp 2011-10-09 21:05:37 UTC (rev 4368) @@ -136,16 +136,16 @@ Logger().errorStream() << "Condition::Number::Eval has root candidate-dependent ValueRefs, but expects local candidate to be the root candidate, and has no valid local candidate!"; } else { // get set of all UniverseObjects that satisfy m_condition - ObjectSet condition_targets; - ObjectSet condition_non_targets; + ObjectSet condition_matches; + ObjectSet condition_non_matches; ObjectMap& objects = GetUniverse().Objects(); for (ObjectMap::iterator uit = objects.begin(); uit != objects.end(); ++uit) { - condition_non_targets.insert(uit->second); + condition_non_matches.insert(uit->second); } - m_condition->Eval(local_context, condition_targets, condition_non_targets, NON_MATCHES); + m_condition->Eval(local_context, condition_matches, condition_non_matches, NON_MATCHES); // compare number of objects that satisfy m_condition to the acceptable range of such objects - int matched = condition_targets.size(); + int matched = condition_matches.size(); int low = (m_low ? m_low->Eval(local_context) : 0); int high = (m_high ? m_high->Eval(local_context) : INT_MAX); in_range = (low <= matched && matched <= high); @@ -488,24 +488,24 @@ ScriptingContext local_context(parent_context, no_object); // which input matches match the subcondition? - ObjectSet subcondition_matching_targets; - m_condition->Eval(local_context, subcondition_matching_targets, matches, NON_MATCHES); + ObjectSet subcondition_matching_matches; + m_condition->Eval(local_context, subcondition_matching_matches, matches, NON_MATCHES); // remaining input matches don't match the subcondition... - ObjectSet subcondition_non_matching_targets = matches; + ObjectSet subcondition_non_matching_matches = matches; matches.clear(); // to be refilled later // which input non_matches match the subcondition? - ObjectSet subcondition_matching_non_targets; - m_condition->Eval(local_context, subcondition_matching_non_targets, non_matches, NON_MATCHES); + ObjectSet subcondition_matching_non_matches; + m_condition->Eval(local_context, subcondition_matching_non_matches, non_matches, NON_MATCHES); // remaining input non_matches don't match the subcondition... - ObjectSet subcondition_non_matching_non_targets = non_matches; + ObjectSet subcondition_non_matching_non_matches = non_matches; non_matches.clear(); // to be refilled later // assemble single set of subcondition matching objects - ObjectSet all_subcondition_matches = subcondition_matching_targets; - all_subcondition_matches.insert(subcondition_matching_non_targets.begin(), subcondition_matching_non_targets.end()); + ObjectSet all_subcondition_matches = subcondition_matching_matches; + all_subcondition_matches.insert(subcondition_matching_non_matches.begin(), subcondition_matching_non_matches.end()); // how many subcondition matches to select as matches to this condition int number = m_number->Eval(local_context); @@ -519,50 +519,50 @@ // put objects back into matches and non_target sets as output... if (search_domain == NON_MATCHES) { - // put matched objects that are in subcondition_matching_non_targets into matches + // put matched objects that are in subcondition_matching_non_matches into matches for (ObjectSet::const_iterator match_it = matched_objects.begin(); match_it != matched_objects.end(); ++match_it) { const UniverseObject* matched_object = *match_it; - // is this matched object in subcondition_matching_non_targets? - ObjectSet::iterator smnt_it = subcondition_matching_non_targets.find(matched_object); - if (smnt_it != subcondition_matching_non_targets.end()) { + // is this matched object in subcondition_matching_non_matches? + ObjectSet::iterator smnt_it = subcondition_matching_non_matches.find(matched_object); + if (smnt_it != subcondition_matching_non_matches.end()) { // yes; move object to matches - subcondition_matching_non_targets.erase(smnt_it); + subcondition_matching_non_matches.erase(smnt_it); matches.insert(matched_object); } } - // put remaining (non-matched) objects in subcondition_matching_non_targets back into non_matches - non_matches.insert( subcondition_matching_non_targets.begin(), subcondition_matching_non_targets.end()); - // put objects in subcondition_non_matching_non_targets back into non_matches - non_matches.insert( subcondition_non_matching_non_targets.begin(), subcondition_non_matching_non_targets.end()); - // put objects in subcondition_matching_targets and subcondition_non_matching_targets back into matches - matches.insert( subcondition_matching_targets.begin(), subcondition_matching_targets.end()); - matches.insert( subcondition_non_matching_targets.begin(), subcondition_non_matching_targets.end()); + // put remaining (non-matched) objects in subcondition_matching_non_matches back into non_matches + non_matches.insert( subcondition_matching_non_matches.begin(), subcondition_matching_non_matches.end()); + // put objects in subcondition_non_matching_non_matches back into non_matches + non_matches.insert( subcondition_non_matching_non_matches.begin(), subcondition_non_matching_non_matches.end()); + // put objects in subcondition_matching_matches and subcondition_non_matching_matches back into matches + matches.insert( subcondition_matching_matches.begin(), subcondition_matching_matches.end()); + matches.insert( subcondition_non_matching_matches.begin(), subcondition_non_matching_matches.end()); // this leaves the original contents of matches unchanged, other than // possibly having transferred some objects into matches from non_matches } else { /*(search_domain == MATCHES)*/ - // put matched objecs that are in subcondition_matching_targets back into matches + // put matched objecs that are in subcondition_matching_matches back into matches for (ObjectSet::const_iterator match_it = matched_objects.begin(); match_it != matched_objects.end(); ++match_it) { const UniverseObject* matched_object = *match_it; - // is this matched object in subcondition_matching_targets? - ObjectSet::iterator smt_it = subcondition_matching_targets.find(matched_object); - if (smt_it != subcondition_matching_targets.end()) { + // is this matched object in subcondition_matching_matches? + ObjectSet::iterator smt_it = subcondition_matching_matches.find(matched_object); + if (smt_it != subcondition_matching_matches.end()) { // yes; move back into matches - subcondition_matching_targets.erase(smt_it); + subcondition_matching_matches.erase(smt_it); matches.insert(matched_object); } } - // put remaining (non-matched) objects in subcondition_matching_targets) into non_matches - non_matches.insert( subcondition_matching_targets.begin(), subcondition_matching_targets.end()); - // put objects in subcondition_non_matching_targets into non_matches - non_matches.insert( subcondition_non_matching_targets.begin(), subcondition_non_matching_targets.end()); - // put objects in subcondition_matching_non_targets and subcondition_non_matching_non_targets back into non_matches - non_matches.insert( subcondition_matching_non_targets.begin(), subcondition_matching_non_targets.end()); - non_matches.insert( subcondition_non_matching_non_targets.begin(), subcondition_non_matching_non_targets.end()); + // put remaining (non-matched) objects in subcondition_matching_matches) into non_matches + non_matches.insert( subcondition_matching_matches.begin(), subcondition_matching_matches.end()); + // put objects in subcondition_non_matching_matches into non_matches + non_matches.insert( subcondition_non_matching_matches.begin(), subcondition_non_matching_matches.end()); + // put objects in subcondition_matching_non_matches and subcondition_non_matching_non_matches back into non_matches + non_matches.insert( subcondition_matching_non_matches.begin(), subcondition_matching_non_matches.end()); + non_matches.insert( subcondition_non_matching_non_matches.begin(), subcondition_non_matching_non_matches.end()); // this leaves the original contents of non_matches unchanged, other than // possibly having transferred some objects into non_matches from matches } @@ -5185,7 +5185,7 @@ ObjectSet partly_checked_non_matches; // move items in non_matches set that pass first operand condition into - // partly_checked_non_targets set + // partly_checked_non_matches set m_operands[0]->Eval(local_context, partly_checked_non_matches, non_matches, NON_MATCHES); // move items that don't pass one of the other conditions back to non_matches @@ -5294,7 +5294,7 @@ ObjectSet partly_checked_matches; // move items in matches set the fail the first operand condition into - // partly_checked_targets set + // partly_checked_matches set m_operands[0]->Eval(local_context, matches, partly_checked_matches, MATCHES); // move items that pass any of the other conditions back into matches |
From: <tz...@us...> - 2011-10-16 03:55:26
|
Revision: 4394 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4394&view=rev Author: tzlaine Date: 2011-10-16 03:55:20 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Removed a needless change to EvalImpl()'s main loop, added during bughunting. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-10-16 03:52:09 UTC (rev 4393) +++ trunk/FreeOrion/universe/Condition.cpp 2011-10-16 03:55:20 UTC (rev 4394) @@ -43,10 +43,7 @@ if ((search_domain == Condition::MATCHES && !match) || (search_domain == Condition::NON_MATCHES && match)) { to_set.push_back(*it); *it = from_set.back(); - bool break_ = it + 1 == from_set.end(); from_set.pop_back(); - if (break_) - break; } else { ++it; } |
From: <geo...@us...> - 2012-01-14 05:06:14
|
Revision: 4585 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4585&view=rev Author: geoffthemedio Date: 2012-01-14 05:06:07 +0000 (Sat, 14 Jan 2012) Log Message: ----------- Fix for GCC compile error due to "and" being sort-of a C++ keyword. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2012-01-14 04:41:31 UTC (rev 4584) +++ trunk/FreeOrion/universe/Condition.cpp 2012-01-14 05:06:07 UTC (rev 4585) @@ -57,9 +57,9 @@ for (std::vector<const Condition::ConditionBase*>::const_iterator it = input_conditions.begin(); it != input_conditions.end(); ++it) { - if (const Condition::And* and = dynamic_cast<const Condition::And*>(*it)) { + if (const Condition::And* and_condition = dynamic_cast<const Condition::And*>(*it)) { std::vector<const Condition::ConditionBase*> flattened_operands = - FlattenAndNestedConditions(and->Operands()); + FlattenAndNestedConditions(and_condition->Operands()); std::copy(flattened_operands.begin(), flattened_operands.end(), std::back_inserter(retval)); } else { retval.push_back(*it); |
From: <geo...@us...> - 2012-01-26 20:18:38
|
Revision: 4620 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4620&view=rev Author: geoffthemedio Date: 2012-01-26 20:18:31 +0000 (Thu, 26 Jan 2012) Log Message: ----------- -Fixed issue where a single non-And condition was being treated as no conditions when flattening potentially-nested-and conditions. -Added some newlines to And and Or condition dump output. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2012-01-26 19:28:16 UTC (rev 4619) +++ trunk/FreeOrion/universe/Condition.cpp 2012-01-26 20:18:31 UTC (rev 4620) @@ -84,8 +84,8 @@ flattened_conditions = FlattenAndNestedConditions(conditions); //else if (dynamic_cast<const Condition::Or*>(*conditions.begin())) // flattened_conditions = FlattenOrNestedConditions(conditions); - //else - // std::cout << ""; + else + flattened_conditions = conditions; for (std::vector<const Condition::ConditionBase*>::const_iterator it = flattened_conditions.begin(); it != flattened_conditions.end(); ++it) @@ -5118,7 +5118,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += "\n" + DumpIndent() + "]"; + retval += "\n" + DumpIndent() + "]\n"; return retval; } @@ -5213,7 +5213,7 @@ retval += m_operands[i]->Dump(); } --g_indent; - retval += "\n" + DumpIndent() + "]"; + retval += "\n" + DumpIndent() + "]\n"; return retval; } |
From: <geo...@us...> - 2012-07-28 19:57:03
|
Revision: 5075 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=5075&view=rev Author: geoffthemedio Date: 2012-07-28 19:56:57 +0000 (Sat, 28 Jul 2012) Log Message: ----------- Implemented ALLY empire affiliation in condition, which presently means empires at peace with the specified empire. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2012-07-26 10:28:28 UTC (rev 5074) +++ trunk/FreeOrion/universe/Condition.cpp 2012-07-28 19:56:57 UTC (rev 5075) @@ -837,7 +837,7 @@ {} bool operator()(const UniverseObject* candidate) const { - if (!candidate) + if (!candidate || candidate->Unowned()) return false; switch (m_affiliation) { @@ -847,8 +847,15 @@ case AFFIL_ENEMY: return m_empire_id != ALL_EMPIRES && !candidate->Unowned() && !candidate->OwnedBy(m_empire_id); break; + case AFFIL_ALLY: { + if (m_empire_id == ALL_EMPIRES) + return false; + DiplomaticStatus status = Empires().GetDiplomaticStatus(m_empire_id, candidate->Owner()); + return (status == DIPLO_PEACE); + } case AFFIL_ANY: - return !candidate->Unowned(); + return true; + //return !candidate->Unowned(); break; default: return false; |
From: <geo...@us...> - 2013-03-08 13:54:08
|
Revision: 5845 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=5845&view=rev Author: geoffthemedio Date: 2013-03-08 13:53:59 +0000 (Fri, 08 Mar 2013) Log Message: ----------- Implemented condition operator== functions. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-03-07 21:47:36 UTC (rev 5844) +++ trunk/FreeOrion/universe/Condition.cpp 2013-03-08 13:53:59 UTC (rev 5845) @@ -133,6 +133,15 @@ return retval; } +#define CHECK_COND_VREF_MEMBER(m_ptr) { if (m_ptr == rhs_.m_ptr) { \ + /* check next member */ \ + } else if (!m_ptr || !rhs_.m_ptr) { \ + return false; \ + } else { \ + if (*m_ptr != *(rhs_.m_ptr)) \ + return false; \ + } } + /////////////////////////////////////////////////////////// // Condition::ConditionBase // /////////////////////////////////////////////////////////// @@ -235,38 +244,14 @@ const Condition::Number& rhs_ = static_cast<const Condition::Number&>(rhs); - if (m_low == rhs_.m_low) { - // check next member - } else if (!m_low || !rhs_.m_low) { - return false; - } else { - if (*m_low != *(rhs_.m_low)) - return false; - } + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + CHECK_COND_VREF_MEMBER(m_condition) - if (m_high == rhs_.m_high) { - // check next member - } else if (!m_high || !rhs_.m_high) { - return false; - } else { - if (*m_high != *(rhs_.m_high)) - return false; - } - - if (m_condition == rhs_.m_condition) { - // check next member - } else if (!m_condition || !rhs_.m_condition) { - return false; - } else { - if (*m_condition != *(rhs_.m_condition)) - return false; - } - return true; } -std::string Condition::Number::Description(bool negated/* = false*/) const -{ +std::string Condition::Number::Description(bool negated/* = false*/) const { std::string low_str = (m_low ? (ValueRef::ConstantExpr(m_low) ? boost::lexical_cast<std::string>(m_low->Eval()) : m_low->Description()) @@ -284,8 +269,7 @@ % m_condition->Description()); } -std::string Condition::Number::Dump() const -{ +std::string Condition::Number::Dump() const { std::string retval = DumpIndent() + "Number"; if (m_low) retval += " low = " + m_low->Dump(); @@ -375,11 +359,17 @@ m_condition->RootCandidateInvariant(); } -bool Condition::Number::TargetInvariant() const -{ return (!m_low || m_low->TargetInvariant()) && (!m_high || m_high->TargetInvariant()) && m_condition->TargetInvariant(); } +bool Condition::Number::TargetInvariant() const { + return (!m_low || m_low->TargetInvariant()) && + (!m_high || m_high->TargetInvariant()) && + m_condition->TargetInvariant(); +} -bool Condition::Number::SourceInvariant() const -{ return (!m_low || m_low->SourceInvariant()) && (!m_high || m_high->SourceInvariant()) && m_condition->SourceInvariant(); } +bool Condition::Number::SourceInvariant() const { + return (!m_low || m_low->SourceInvariant()) && + (!m_high || m_high->SourceInvariant()) && + m_condition->SourceInvariant(); +} bool Condition::Number::Match(const ScriptingContext& local_context) const { // get acceptable range of subcondition matches for candidate @@ -407,7 +397,6 @@ return in_range; } - /////////////////////////////////////////////////////////// // Turn // /////////////////////////////////////////////////////////// @@ -416,9 +405,20 @@ delete m_high; } -bool Condition::Turn::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Turn::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Turn& rhs_ = static_cast<const Condition::Turn&>(rhs); + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + void Condition::Turn::Eval(const ScriptingContext& parent_context, ObjectSet& matches, ObjectSet& non_matches, SearchDomain search_domain/* = NON_MATCHES*/) const { // if ValueRef for low or high range limits depend on local candidate, then // they must be evaluated per-candidate. @@ -529,9 +529,24 @@ delete m_condition; } -bool Condition::SortedNumberOf::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::SortedNumberOf::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::SortedNumberOf& rhs_ = static_cast<const Condition::SortedNumberOf&>(rhs); + + if (m_sorting_method != rhs_.m_sorting_method) + return false; + + CHECK_COND_VREF_MEMBER(m_number) + CHECK_COND_VREF_MEMBER(m_sort_key) + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { /** Random number genrator function to use with random_shuffle */ int CustomRandInt(int max_plus_one) { @@ -924,9 +939,22 @@ delete m_empire_id; } -bool Condition::EmpireAffiliation::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::EmpireAffiliation::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::EmpireAffiliation& rhs_ = static_cast<const Condition::EmpireAffiliation&>(rhs); + + if (m_affiliation != rhs_.m_affiliation) + return false; + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { struct EmpireAffiliationSimpleMatch { EmpireAffiliationSimpleMatch(int empire_id, EmpireAffiliationType affiliation) : @@ -1126,9 +1154,23 @@ delete m_names[i]; } -bool Condition::Homeworld::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Homeworld::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Homeworld& rhs_ = static_cast<const Condition::Homeworld&>(rhs); + + if (m_names.size() != rhs_.m_names.size()) + return false; + for (unsigned int i = 0; i < m_names.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_names.at(i)) + } + + return true; +} + namespace { struct HomeworldSimpleMatch { HomeworldSimpleMatch(const std::vector<std::string>& names) : @@ -1419,9 +1461,19 @@ Condition::Type::~Type() { delete m_type; } -bool Condition::Type::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Type::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Type& rhs_ = static_cast<const Condition::Type&>(rhs); + + CHECK_COND_VREF_MEMBER(m_type) + + return true; +} + namespace { struct TypeSimpleMatch { TypeSimpleMatch(UniverseObjectType type) : @@ -1528,12 +1580,25 @@ } } -bool Condition::Building::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Building::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Building& rhs_ = static_cast<const Condition::Building&>(rhs); + + if (m_names.size() != rhs_.m_names.size()) + return false; + for (unsigned int i = 0; i < m_names.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_names.at(i)) + } + + return true; +} + namespace { - struct BuildingSimpleMatch - { + struct BuildingSimpleMatch { BuildingSimpleMatch(const std::vector<std::string>& names) : m_names(names) {} @@ -1688,9 +1753,23 @@ delete m_since_turn_high; } -bool Condition::HasSpecial::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::HasSpecial::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::HasSpecial& rhs_ = static_cast<const Condition::HasSpecial&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + CHECK_COND_VREF_MEMBER(m_since_turn_low) + CHECK_COND_VREF_MEMBER(m_since_turn_high) + + return true; +} + namespace { struct HasSpecialSimpleMatch { HasSpecialSimpleMatch(const std::string& name, int low_turn, int high_turn) : @@ -1807,9 +1886,20 @@ /////////////////////////////////////////////////////////// // HasTag // /////////////////////////////////////////////////////////// -bool Condition::HasTag::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::HasTag::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::HasTag& rhs_ = static_cast<const Condition::HasTag&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + return true; +} + std::string Condition::HasTag::Description(bool negated/* = false*/) const { std::string description_str = "DESC_HAS_TAG"; if (negated) @@ -1838,9 +1928,20 @@ delete m_high; } -bool Condition::CreatedOnTurn::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::CreatedOnTurn::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::CreatedOnTurn& rhs_ = static_cast<const Condition::CreatedOnTurn&>(rhs); + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct CreatedOnTurnSimpleMatch { CreatedOnTurnSimpleMatch(int low, int high) : @@ -1931,9 +2032,19 @@ Condition::Contains::~Contains() { delete m_condition; } -bool Condition::Contains::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Contains::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Contains& rhs_ = static_cast<const Condition::Contains&>(rhs); + + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { struct ContainsSimpleMatch { ContainsSimpleMatch(const Condition::ObjectSet& subcondition_matches) : @@ -2043,9 +2154,19 @@ Condition::ContainedBy::~ContainedBy() { delete m_condition; } -bool Condition::ContainedBy::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ContainedBy::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ContainedBy& rhs_ = static_cast<const Condition::ContainedBy&>(rhs); + + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { struct ContainedBySimpleMatch { ContainedBySimpleMatch(const Condition::ObjectSet& subcondition_matches) : @@ -2155,9 +2276,19 @@ Condition::InSystem::~InSystem() { delete m_system_id; } -bool Condition::InSystem::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::InSystem::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::InSystem& rhs_ = static_cast<const Condition::InSystem&>(rhs); + + CHECK_COND_VREF_MEMBER(m_system_id) + + return true; +} + namespace { struct InSystemSimpleMatch { InSystemSimpleMatch(int system_id) : @@ -2245,9 +2376,19 @@ Condition::ObjectID::~ObjectID() { delete m_object_id; } -bool Condition::ObjectID::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ObjectID::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ObjectID& rhs_ = static_cast<const Condition::ObjectID&>(rhs); + + CHECK_COND_VREF_MEMBER(m_object_id) + + return true; +} + namespace { struct ObjectIDSimpleMatch { ObjectIDSimpleMatch(int object_id) : @@ -2332,9 +2473,23 @@ } } -bool Condition::PlanetType::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::PlanetType::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::PlanetType& rhs_ = static_cast<const Condition::PlanetType&>(rhs); + + if (m_types.size() != rhs_.m_types.size()) + return false; + for (unsigned int i = 0; i < m_types.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_types.at(i)) + } + + return true; +} + namespace { struct PlanetTypeSimpleMatch { PlanetTypeSimpleMatch(const std::vector< ::PlanetType>& types) : @@ -2490,9 +2645,23 @@ } } -bool Condition::PlanetSize::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::PlanetSize::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::PlanetSize& rhs_ = static_cast<const Condition::PlanetSize&>(rhs); + + if (m_sizes.size() != rhs_.m_sizes.size()) + return false; + for (unsigned int i = 0; i < m_sizes.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_sizes.at(i)) + } + + return true; +} + namespace { struct PlanetSizeSimpleMatch { PlanetSizeSimpleMatch(const std::vector< ::PlanetSize>& sizes) : @@ -2651,9 +2820,23 @@ } } -bool Condition::PlanetEnvironment::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::PlanetEnvironment::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::PlanetEnvironment& rhs_ = static_cast<const Condition::PlanetEnvironment&>(rhs); + + if (m_environments.size() != rhs_.m_environments.size()) + return false; + for (unsigned int i = 0; i < m_environments.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_environments.at(i)) + } + + return true; +} + namespace { struct PlanetEnvironmentSimpleMatch { PlanetEnvironmentSimpleMatch(const std::vector< ::PlanetEnvironment>& environments) : @@ -2813,9 +2996,23 @@ } } -bool Condition::Species::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Species::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Species& rhs_ = static_cast<const Condition::Species&>(rhs); + + if (m_names.size() != rhs_.m_names.size()) + return false; + for (unsigned int i = 0; i < m_names.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_names.at(i)) + } + + return true; +} + namespace { struct SpeciesSimpleMatch { SpeciesSimpleMatch(const std::vector<std::string>& names) : @@ -2995,9 +3192,28 @@ delete m_high; } -bool Condition::Enqueued::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Enqueued::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Enqueued& rhs_ = static_cast<const Condition::Enqueued&>(rhs); + + if (m_build_type != rhs_.m_build_type) + return false; + + if (m_name != rhs_.m_name) + return false; + + CHECK_COND_VREF_MEMBER(m_design_id) + CHECK_COND_VREF_MEMBER(m_empire_id) + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { int NumberOnQueue(const ProductionQueue& queue, BuildType build_type, int location_id, const std::string& name = "", int design_id = ShipDesign::INVALID_DESIGN_ID) @@ -3221,9 +3437,23 @@ } } -bool Condition::FocusType::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::FocusType::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::FocusType& rhs_ = static_cast<const Condition::FocusType&>(rhs); + + if (m_names.size() != rhs_.m_names.size()) + return false; + for (unsigned int i = 0; i < m_names.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_names.at(i)) + } + + return true; +} + namespace { struct FocusTypeSimpleMatch { FocusTypeSimpleMatch(const std::vector<std::string>& names) : @@ -3380,9 +3610,23 @@ } } -bool Condition::StarType::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::StarType::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::StarType& rhs_ = static_cast<const Condition::StarType&>(rhs); + + if (m_types.size() != rhs_.m_types.size()) + return false; + for (unsigned int i = 0; i < m_types.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_types.at(i)) + } + + return true; +} + namespace { struct StarTypeSimpleMatch { StarTypeSimpleMatch(const std::vector< ::StarType>& types) : @@ -3517,9 +3761,20 @@ /////////////////////////////////////////////////////////// // DesignHasHull // /////////////////////////////////////////////////////////// -bool Condition::DesignHasHull::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::DesignHasHull::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::DesignHasHull& rhs_ = static_cast<const Condition::DesignHasHull&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + return true; +} + std::string Condition::DesignHasHull::Description(bool negated/* = false*/) const { std::string description_str = "DESC_DESIGN_HAS_HULL"; if (negated) @@ -3551,9 +3806,23 @@ delete m_high; } -bool Condition::DesignHasPart::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::DesignHasPart::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::DesignHasPart& rhs_ = static_cast<const Condition::DesignHasPart&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct DesignHasPartSimpleMatch { DesignHasPartSimpleMatch(int low, int high, const std::string& name) : @@ -3662,9 +3931,23 @@ delete m_high; } -bool Condition::DesignHasPartClass::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::DesignHasPartClass::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::DesignHasPartClass& rhs_ = static_cast<const Condition::DesignHasPartClass&>(rhs); + + if (m_class != rhs_.m_class) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct DesignHasPartClassSimpleMatch { DesignHasPartClassSimpleMatch(int low, int high, ShipPartClass part_class) : @@ -3772,9 +4055,20 @@ /////////////////////////////////////////////////////////// // PredefinedShipDesign // /////////////////////////////////////////////////////////// -bool Condition::PredefinedShipDesign::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::PredefinedShipDesign::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::PredefinedShipDesign& rhs_ = static_cast<const Condition::PredefinedShipDesign&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + return true; +} + std::string Condition::PredefinedShipDesign::Description(bool negated/* = false*/) const { std::string description_str = "DESC_PREDEFINED_SHIP_DESIGN"; if (negated) @@ -3815,9 +4109,19 @@ Condition::NumberedShipDesign::~NumberedShipDesign() { delete m_design_id; } -bool Condition::NumberedShipDesign::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::NumberedShipDesign::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::NumberedShipDesign& rhs_ = static_cast<const Condition::NumberedShipDesign&>(rhs); + + CHECK_COND_VREF_MEMBER(m_design_id) + + return true; +} + namespace { struct NumberedShipDesignSimpleMatch { NumberedShipDesignSimpleMatch(int design_id) : @@ -3896,9 +4200,19 @@ Condition::ProducedByEmpire::~ProducedByEmpire() { delete m_empire_id; } -bool Condition::ProducedByEmpire::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ProducedByEmpire::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ProducedByEmpire& rhs_ = static_cast<const Condition::ProducedByEmpire&>(rhs); + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { struct ProducedByEmpireSimpleMatch { ProducedByEmpireSimpleMatch(int empire_id) : @@ -3985,9 +4299,19 @@ Condition::Chance::~Chance() { delete m_chance; } -bool Condition::Chance::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Chance::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Chance& rhs_ = static_cast<const Condition::Chance&>(rhs); + + CHECK_COND_VREF_MEMBER(m_chance) + + return true; +} + namespace { struct ChanceSimpleMatch { ChanceSimpleMatch(double chance) : @@ -4059,9 +4383,23 @@ delete m_high; } -bool Condition::MeterValue::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::MeterValue::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::MeterValue& rhs_ = static_cast<const Condition::MeterValue&>(rhs); + + if (m_meter != rhs_.m_meter) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct MeterValueSimpleMatch { MeterValueSimpleMatch(double low, double high, MeterType meter_type) : @@ -4203,9 +4541,26 @@ delete m_high; } -bool Condition::ShipPartMeterValue::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ShipPartMeterValue::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ShipPartMeterValue& rhs_ = static_cast<const Condition::ShipPartMeterValue&>(rhs); + + if (m_meter != rhs_.m_meter) + return false; + + if (m_part_name != rhs_.m_part_name) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct ShipPartMeterValueSimpleMatch { ShipPartMeterValueSimpleMatch(const std::string& ship_part_name, @@ -4322,9 +4677,26 @@ delete m_high; } -bool Condition::EmpireMeterValue::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::EmpireMeterValue::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::EmpireMeterValue& rhs_ = static_cast<const Condition::EmpireMeterValue&>(rhs); + + if (m_empire_id != rhs_.m_empire_id) + return false; + + if (m_meter != rhs_.m_meter) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct EmpireMeterValueSimpleMatch { EmpireMeterValueSimpleMatch(int empire_id, double low, double high, const std::string& meter) : @@ -4457,9 +4829,23 @@ delete m_high; } -bool Condition::EmpireStockpileValue::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::EmpireStockpileValue::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::EmpireStockpileValue& rhs_ = static_cast<const Condition::EmpireStockpileValue&>(rhs); + + if (m_stockpile != rhs_.m_stockpile) + return false; + + CHECK_COND_VREF_MEMBER(m_low) + CHECK_COND_VREF_MEMBER(m_high) + + return true; +} + namespace { struct EmpireStockpileValueSimpleMatch { EmpireStockpileValueSimpleMatch(double low, double high, ResourceType stockpile) : @@ -4563,9 +4949,20 @@ /////////////////////////////////////////////////////////// // OwnerHasTech // /////////////////////////////////////////////////////////// -bool Condition::OwnerHasTech::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::OwnerHasTech::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::OwnerHasTech& rhs_ = static_cast<const Condition::OwnerHasTech&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + return true; +} + std::string Condition::OwnerHasTech::Description(bool negated/* = false*/) const { std::string description_str = "DESC_OWNER_HAS_TECH"; if (negated) @@ -4595,9 +4992,20 @@ /////////////////////////////////////////////////////////// // OwnerHasBuildingTypeAvailable // /////////////////////////////////////////////////////////// -bool Condition::OwnerHasBuildingTypeAvailable::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::OwnerHasBuildingTypeAvailable::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::OwnerHasBuildingTypeAvailable& rhs_ = static_cast<const Condition::OwnerHasBuildingTypeAvailable&>(rhs); + + if (m_name != rhs_.m_name) + return false; + + return true; +} + std::string Condition::OwnerHasBuildingTypeAvailable::Description(bool negated/* = false*/) const { std::string description_str = "DESC_OWNER_HAS_BUILDING_TYPE"; if (negated) @@ -4627,9 +5035,20 @@ /////////////////////////////////////////////////////////// // OwnerHasShipDesignAvailable // /////////////////////////////////////////////////////////// -bool Condition::OwnerHasShipDesignAvailable::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::OwnerHasShipDesignAvailable::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::OwnerHasShipDesignAvailable& rhs_ = static_cast<const Condition::OwnerHasShipDesignAvailable&>(rhs); + + if (m_id != rhs_.m_id) + return false; + + return true; +} + std::string Condition::OwnerHasShipDesignAvailable::Description(bool negated/* = false*/) const { std::string description_str = "DESC_OWNER_HAS_SHIP_DESIGN"; if (negated) @@ -4662,12 +5081,21 @@ Condition::VisibleToEmpire::~VisibleToEmpire() { delete m_empire_id; } -bool Condition::VisibleToEmpire::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::VisibleToEmpire::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::VisibleToEmpire& rhs_ = static_cast<const Condition::VisibleToEmpire&>(rhs); + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { - struct VisibleToEmpireSimpleMatch - { + struct VisibleToEmpireSimpleMatch { VisibleToEmpireSimpleMatch(int empire_id) : m_empire_id(empire_id) {} @@ -4749,9 +5177,20 @@ delete m_condition; } -bool Condition::WithinDistance::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::WithinDistance::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::WithinDistance& rhs_ = static_cast<const Condition::WithinDistance&>(rhs); + + CHECK_COND_VREF_MEMBER(m_distance) + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { struct WithinDistanceSimpleMatch { WithinDistanceSimpleMatch(const Condition::ObjectSet& from_objects, double distance) : @@ -4873,9 +5312,20 @@ delete m_condition; } -bool Condition::WithinStarlaneJumps::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::WithinStarlaneJumps::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::WithinStarlaneJumps& rhs_ = static_cast<const Condition::WithinStarlaneJumps&>(rhs); + + CHECK_COND_VREF_MEMBER(m_jumps) + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { const int MANY_JUMPS(999999); @@ -5086,9 +5536,19 @@ Condition::CanAddStarlaneConnection::~CanAddStarlaneConnection() { delete m_condition; } -bool Condition::CanAddStarlaneConnection::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::CanAddStarlaneConnection::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::CanAddStarlaneConnection& rhs_ = static_cast<const Condition::CanAddStarlaneConnection&>(rhs); + + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + namespace { struct CanAddStarlaneConnectionSimpleMatch { CanAddStarlaneConnectionSimpleMatch(const Condition::ObjectSet& destination_objects) : @@ -5304,9 +5764,19 @@ Condition::CanRemoveStarlaneConnection::~CanRemoveStarlaneConnection() { delete m_condition; } -bool Condition::CanRemoveStarlaneConnection::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::CanRemoveStarlaneConnection::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::CanRemoveStarlaneConnection& rhs_ = static_cast<const Condition::CanRemoveStarlaneConnection&>(rhs); + + CHECK_COND_VREF_MEMBER(m_condition) + + return true; +} + bool Condition::CanRemoveStarlaneConnection::RootCandidateInvariant() const { return m_condition->RootCandidateInvariant(); } @@ -5415,9 +5885,19 @@ Condition::ExploredByEmpire::~ExploredByEmpire() { delete m_empire_id; } -bool Condition::ExploredByEmpire::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ExploredByEmpire::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ExploredByEmpire& rhs_ = static_cast<const Condition::ExploredByEmpire&>(rhs); + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { struct ExploredByEmpireSimpleMatch { ExploredByEmpireSimpleMatch(int empire_id) : @@ -5548,9 +6028,19 @@ Condition::FleetSupplyableByEmpire::~FleetSupplyableByEmpire() { delete m_empire_id; } -bool Condition::FleetSupplyableByEmpire::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::FleetSupplyableByEmpire::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::FleetSupplyableByEmpire& rhs_ = static_cast<const Condition::FleetSupplyableByEmpire&>(rhs); + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { struct FleetSupplyableSimpleMatch { FleetSupplyableSimpleMatch(int empire_id) : @@ -5643,9 +6133,19 @@ delete m_condition; } -bool Condition::ResourceSupplyConnectedByEmpire::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::ResourceSupplyConnectedByEmpire::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::ResourceSupplyConnectedByEmpire& rhs_ = static_cast<const Condition::ResourceSupplyConnectedByEmpire&>(rhs); + + CHECK_COND_VREF_MEMBER(m_empire_id) + + return true; +} + namespace { struct ResourceSupplySimpleMatch { ResourceSupplySimpleMatch(int empire_id, const Condition::ObjectSet& from_objects) : @@ -5920,9 +6420,23 @@ delete m_operands[i]; } -bool Condition::And::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::And::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::And& rhs_ = static_cast<const Condition::And&>(rhs); + + if (m_operands.size() != rhs_.m_operands.size()) + return false; + for (unsigned int i = 0; i < m_operands.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_operands.at(i)) + } + + return true; +} + void Condition::And::Eval(const ScriptingContext& parent_context, ObjectSet& matches, ObjectSet& non_matches, SearchDomain search_domain/* = NON_MATCHES*/) const { @@ -6019,9 +6533,23 @@ delete m_operands[i]; } -bool Condition::Or::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Or::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Or& rhs_ = static_cast<const Condition::Or&>(rhs); + + if (m_operands.size() != rhs_.m_operands.size()) + return false; + for (unsigned int i = 0; i < m_operands.size(); ++i) { + CHECK_COND_VREF_MEMBER(m_operands.at(i)) + } + + return true; +} + void Condition::Or::Eval(const ScriptingContext& parent_context, ObjectSet& matches, ObjectSet& non_matches, SearchDomain search_domain/* = NON_MATCHES*/) const { @@ -6118,9 +6646,19 @@ Condition::Not::~Not() { delete m_operand; } -bool Condition::Not::operator==(const Condition::ConditionBase& rhs) const -{ return Condition::ConditionBase::operator==(rhs); } +bool Condition::Not::operator==(const Condition::ConditionBase& rhs) const { + if (this == &rhs) + return true; + if (typeid(*this) != typeid(rhs)) + return false; + const Condition::Not& rhs_ = static_cast<const Condition::Not&>(rhs); + + CHECK_COND_VREF_MEMBER(m_operand) + + return true; +} + void Condition::Not::Eval(const ScriptingContext& parent_context, ObjectSet& matches, ObjectSet& non_matches, SearchDomain search_domain/* = NON_MATCHES*/) const { |
From: <geo...@us...> - 2013-05-10 06:02:03
|
Revision: 6018 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=6018&view=rev Author: geoffthemedio Date: 2013-05-10 06:01:56 +0000 (Fri, 10 May 2013) Log Message: ----------- Patch by adrian_broher with another UserString call tweak. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-05-10 05:52:04 UTC (rev 6017) +++ trunk/FreeOrion/universe/Condition.cpp 2013-05-10 06:01:56 UTC (rev 6018) @@ -6272,10 +6272,9 @@ { return Condition::ConditionBase::operator==(rhs); } std::string Condition::CanColonize::Description(bool negated/* = false*/) const { - std::string description_str = "DESC_CAN_COLONIZE"; - if (negated) - description_str += "_NOT"; - return UserString(description_str); + return str(FlexibleFormat((!negated) + ? UserString("DESC_CAN_COLONIZE") + : UserString("DESC_CAN_COLONIZE_NOT"))); } std::string Condition::CanColonize::Dump() const @@ -6337,10 +6336,9 @@ { return Condition::ConditionBase::operator==(rhs); } std::string Condition::CanProduceShips::Description(bool negated/* = false*/) const { - std::string description_str = "DESC_CAN_PRODUCE_SHIPS"; - if (negated) - description_str += "_NOT"; - return UserString(description_str); + return str(FlexibleFormat((!negated) + ? UserString("DESC_CAN_PRODUCE_SHIPS") + : UserString("DESC_CAN_PRODUCE_SHIPS_NOT"))); } std::string Condition::CanProduceShips::Dump() const |
From: <geo...@us...> - 2013-08-15 03:51:59
|
Revision: 6337 http://sourceforge.net/p/freeorion/code/6337 Author: geoffthemedio Date: 2013-08-15 03:51:56 +0000 (Thu, 15 Aug 2013) Log Message: ----------- Modified EmpireAffiliation evaluation to consider diplomatic status when matching objects that are owned by enemies. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-08-14 22:46:53 UTC (rev 6336) +++ trunk/FreeOrion/universe/Condition.cpp 2013-08-15 03:51:56 UTC (rev 6337) @@ -977,14 +977,19 @@ case AFFIL_SELF: return m_empire_id != ALL_EMPIRES && candidate->OwnedBy(m_empire_id); break; - case AFFIL_ENEMY: - return m_empire_id != ALL_EMPIRES && !candidate->Unowned() && !candidate->OwnedBy(m_empire_id); + case AFFIL_ENEMY: { + if (m_empire_id == ALL_EMPIRES) + return true; + DiplomaticStatus status = Empires().GetDiplomaticStatus(m_empire_id, candidate->Owner()); + return (status == DIPLO_WAR); break; + } case AFFIL_ALLY: { if (m_empire_id == ALL_EMPIRES) return false; DiplomaticStatus status = Empires().GetDiplomaticStatus(m_empire_id, candidate->Owner()); return (status == DIPLO_PEACE); + break; } case AFFIL_ANY: return true; |
From: <geo...@us...> - 2013-11-03 02:16:14
|
Revision: 6495 http://sourceforge.net/p/freeorion/code/6495 Author: geoffthemedio Date: 2013-11-03 02:16:10 +0000 (Sun, 03 Nov 2013) Log Message: ----------- Tweaked WithinDistance to match when distance between objects is <= the specified distance, instead of just < Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-11-01 09:37:45 UTC (rev 6494) +++ trunk/FreeOrion/universe/Condition.cpp 2013-11-03 02:16:10 UTC (rev 6495) @@ -2316,7 +2316,7 @@ if (m_system_id == INVALID_OBJECT_ID) return candidate->SystemID() != INVALID_OBJECT_ID; // match objects in any system else - return candidate->SystemID() == m_system_id; // match objects in specified system + return candidate->SystemID() == m_system_id; // match objects in specified system } int m_system_id; @@ -5229,20 +5229,20 @@ struct WithinDistanceSimpleMatch { WithinDistanceSimpleMatch(const Condition::ObjectSet& from_objects, double distance) : m_from_objects(from_objects), - m_distance(distance) + m_distance2(distance*distance) {} bool operator()(TemporaryPtr<const UniverseObject> candidate) const { if (!candidate) return false; - double distance2 = m_distance*m_distance; - // is candidate object close enough to any of the passed-in objects? - for (Condition::ObjectSet::const_iterator it = m_from_objects.begin(); it != m_from_objects.end(); ++it) { + for (Condition::ObjectSet::const_iterator it = m_from_objects.begin(); + it != m_from_objects.end(); ++it) + { double delta_x = candidate->X() - (*it)->X(); double delta_y = candidate->Y() - (*it)->Y(); - if (delta_x*delta_x + delta_y*delta_y < distance2) + if (delta_x*delta_x + delta_y*delta_y <= m_distance2) return true; } @@ -5250,7 +5250,7 @@ } const Condition::ObjectSet& m_from_objects; - double m_distance; + double m_distance2; }; } |
From: <dil...@us...> - 2013-11-04 21:12:39
|
Revision: 6498 http://sourceforge.net/p/freeorion/code/6498 Author: dilvish-fo Date: 2013-11-04 21:12:36 +0000 (Mon, 04 Nov 2013) Log Message: ----------- updated the the Enqueued condition to take into account element blocksize when making its tally. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-11-04 02:23:39 UTC (rev 6497) +++ trunk/FreeOrion/universe/Condition.cpp 2013-11-04 21:12:36 UTC (rev 6498) @@ -3267,7 +3267,7 @@ } } // else: looking for any production item - retval += 1; + retval += it->blocksize; } return retval; } |
From: <dil...@us...> - 2013-12-20 18:18:49
|
Revision: 6573 http://sourceforge.net/p/freeorion/code/6573 Author: dilvish-fo Date: 2013-12-20 18:18:46 +0000 (Fri, 20 Dec 2013) Log Message: ----------- eliminated spurious Universe::JumpDistance error reporting originating from JumpsBetweenObjects Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2013-12-19 13:56:56 UTC (rev 6572) +++ trunk/FreeOrion/universe/Condition.cpp 2013-12-20 18:18:46 UTC (rev 6573) @@ -5492,14 +5492,20 @@ // need to check shortest path from systems on either side of starlane fleet is on short jumps1 = -1, jumps2 = -1; try { - jumps1 = GetUniverse().JumpDistance(system_one->ID(), fleet->PreviousSystemID()); - jumps2 = GetUniverse().JumpDistance(system_one->ID(), fleet->NextSystemID()); + if (fleet->PreviousSystemID() != -1) + jumps1 = GetUniverse().JumpDistance(system_one->ID(), fleet->PreviousSystemID()); + if (fleet->NextSystemID() != -1) + jumps2 = GetUniverse().JumpDistance(system_one->ID(), fleet->NextSystemID()); } catch (...) { Logger().errorStream() << "JumpsBetweenObjects caught exception when calling JumpDistance"; } int jumps = static_cast<int>(std::max(jumps1, jumps2)); - if (jumps != -1) + if (jumps != -1) { return jumps - 1; + } else { + Logger().errorStream() << "JumpsBetweenObjects called with only obj 1 insytem but object 2 fleet having invalid prev_system and next_system"; + } + } } else if (system_two) { @@ -5509,14 +5515,19 @@ // need to check shortest path from systems on either side of starlane fleet is on short jumps1 = -1, jumps2 = -1; try { - jumps1 = GetUniverse().JumpDistance(system_two->ID(), fleet->PreviousSystemID()); - jumps2 = GetUniverse().JumpDistance(system_two->ID(), fleet->NextSystemID()); + if (fleet->PreviousSystemID() != -1) + jumps1 = GetUniverse().JumpDistance(system_two->ID(), fleet->PreviousSystemID()); + if (fleet->NextSystemID() != -1) + jumps2 = GetUniverse().JumpDistance(system_two->ID(), fleet->NextSystemID()); } catch (...) { Logger().errorStream() << "JumpsBetweenObjects caught exception when calling JumpDistance"; } int jumps = static_cast<int>(std::max(jumps1, jumps2)); - if (jumps != -1) + if (jumps != -1) { return jumps - 1; + } else { + Logger().errorStream() << "JumpsBetweenObjects called with only obj 2 insystem but object 1 fleet having invalid prev_system and next_system"; + } } } else { // neither object is / in a system @@ -5534,16 +5545,27 @@ int fleet_two_next_system_id = fleet_two->NextSystemID(); short jumps1 = -1, jumps2 = -1, jumps3 = -1, jumps4 = -1; try { - jumps1 = GetUniverse().JumpDistance(fleet_one_prev_system_id, fleet_two_prev_system_id); - jumps2 = GetUniverse().JumpDistance(fleet_one_prev_system_id, fleet_two_next_system_id); - jumps3 = GetUniverse().JumpDistance(fleet_one_next_system_id, fleet_two_prev_system_id); - jumps4 = GetUniverse().JumpDistance(fleet_one_next_system_id, fleet_two_next_system_id); + if (fleet_one_prev_system_id != -1 && fleet_two_prev_system_id != -1) + jumps1 = GetUniverse().JumpDistance(fleet_one_prev_system_id, fleet_two_prev_system_id); + if (fleet_one_prev_system_id != -1 && fleet_two_next_system_id != -1) + jumps2 = GetUniverse().JumpDistance(fleet_one_prev_system_id, fleet_two_next_system_id); + if (fleet_one_next_system_id != -1 && fleet_two_prev_system_id != -1) + jumps3 = GetUniverse().JumpDistance(fleet_one_next_system_id, fleet_two_prev_system_id); + if (fleet_one_next_system_id != -1 && fleet_two_next_system_id != -1) + jumps4 = GetUniverse().JumpDistance(fleet_one_next_system_id, fleet_two_next_system_id); } catch (...) { Logger().errorStream() << "JumpsBetweenObjects caught exception when calling JumpDistance"; } int jumps = static_cast<int>(std::max(jumps1, std::max(jumps2, std::max(jumps3, jumps4)))); - if (jumps != -1) + if (jumps != -1) { return jumps - 1; + } else { + Logger().errorStream() << "JumpsBetweenObjects called with neither obj1 nor obj2 insystem" + << "; fleet 1 prev_system " << fleet_one_prev_system_id + << " and next_system " << fleet_one_next_system_id + << "; fleet 2 prev_system " << fleet_two_prev_system_id + << " and next_system " << fleet_two_next_system_id; + } } } return MANY_JUMPS; |
From: <geo...@us...> - 2014-01-25 21:49:07
|
Revision: 6705 http://sourceforge.net/p/freeorion/code/6705 Author: geoffthemedio Date: 2014-01-25 21:49:05 +0000 (Sat, 25 Jan 2014) Log Message: ----------- Contains and ContainedBy optimization by cami. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2014-01-25 21:36:55 UTC (rev 6704) +++ trunk/FreeOrion/universe/Condition.cpp 2014-01-25 21:49:05 UTC (rev 6705) @@ -2207,24 +2207,62 @@ namespace { struct ContainsSimpleMatch { ContainsSimpleMatch(const Condition::ObjectSet& subcondition_matches) : - m_subcondition_matches(subcondition_matches) - {} + m_subcondition_matches_ids() + { + // We need a sorted container for efficiently intersecting + // subcondition_matches with the set of objects contained in some + // candidate object. + // We only need ids, not objects, so we can do that conversion + // here as well, simplifying later code. + // Note that this constructor is called only once per + // Contains::Eval(), its work cannot help performance when executed + // for each candidate. + m_subcondition_matches_ids.reserve(subcondition_matches.size()); + // gather the ids + for (Condition::ObjectSet::const_iterator it = subcondition_matches.begin(); it != subcondition_matches.end(); ++it) { + TemporaryPtr<const UniverseObject> obj = *it; + if (obj) + { m_subcondition_matches_ids.push_back(obj->ID()); } + } + // sort them + std::sort(m_subcondition_matches_ids.begin(), m_subcondition_matches_ids.end()); + } bool operator()(TemporaryPtr<const UniverseObject> candidate) const { if (!candidate) return false; bool match = false; - for (Condition::ObjectSet::const_iterator it = m_subcondition_matches.begin(); it != m_subcondition_matches.end(); ++it) { - if (candidate->Contains((*it)->ID())) { - match = true; - break; + const std::set<int>& candidate_elements = candidate->ContainedObjectIDs(); // guaranteed O(1) + + // We need to test whether candidate_elements and m_subcondition_matches_ids have a common element. + // We choose the strategy that is more efficient by comparing the sizes of both sets. + if (candidate_elements.size() < m_subcondition_matches_ids.size()) { + // candidate_elements is smaller, so we iterate it and look up each candidate element in m_subcondition_matches_ids + for (std::set<int>::const_iterator it = candidate_elements.begin(), end_it = candidate_elements.end(); it != end_it; ++it) { + // std::lower_bound requires m_subcondition_matches_ids to be sorted + std::vector<int>::const_iterator matching_it = std::lower_bound(m_subcondition_matches_ids.begin(), m_subcondition_matches_ids.end(), *it); + + if (matching_it != m_subcondition_matches_ids.end() && *matching_it == *it) { + match = true; + break; + } } + } else { + // m_subcondition_matches_ids is smaller, so we iterate it and look up each subcondition match in the set of candidate's elements + for (std::vector<int>::const_iterator it = m_subcondition_matches_ids.begin(); it != m_subcondition_matches_ids.end(); ++it) { + // candidate->Contains() may have a faster implementation than candidate_elements->find() + if (candidate->Contains(*it)) { + match = true; + break; + } + } } + return match; } - const Condition::ObjectSet& m_subcondition_matches; + std::vector<int> m_subcondition_matches_ids; }; } @@ -2323,26 +2361,69 @@ namespace { struct ContainedBySimpleMatch { ContainedBySimpleMatch(const Condition::ObjectSet& subcondition_matches) : - m_subcondition_matches(subcondition_matches) - {} + m_subcondition_matches_ids() + { + // We need a sorted container for efficiently intersecting + // subcondition_matches with the set of objects containing some + // candidate object. + // We only need ids, not objects, so we can do that conversion + // here as well, simplifying later code. + // Note that this constructor is called only once per + // ContainedBy::Eval(), its work cannot help performance when + // executed for each candidate. + m_subcondition_matches_ids.reserve(subcondition_matches.size()); + // gather the ids + for (Condition::ObjectSet::const_iterator it = subcondition_matches.begin(); it != subcondition_matches.end(); ++it) { + TemporaryPtr<const UniverseObject> obj = *it; + if (obj) + { m_subcondition_matches_ids.push_back(obj->ID()); } + } + // sort them + std::sort(m_subcondition_matches_ids.begin(), m_subcondition_matches_ids.end()); + } bool operator()(TemporaryPtr<const UniverseObject> candidate) const { if (!candidate) return false; bool match = false; - for (Condition::ObjectSet::const_iterator it = m_subcondition_matches.begin(); - it != m_subcondition_matches.end(); ++it) - { - if (candidate->ContainedBy((*it)->ID())) { - match = true; - break; + // gather the objects containing candidate + std::vector<int> candidate_containers; + const int candidate_id = candidate->ID(); + const int system_id = candidate->SystemID(); + const int container_id = candidate->ContainerObjectID(); + if ( system_id != INVALID_OBJECT_ID && system_id != candidate_id) candidate_containers.push_back( system_id); + if (container_id != INVALID_OBJECT_ID && container_id != system_id) candidate_containers.push_back(container_id); + // FIXME: currently, direct container and system will do. In the future, we might need a way to retrieve containers of containers + + // We need to test whether candidate_containers and m_subcondition_matches_ids have a common element. + // We choose the strategy that is more efficient by comparing the sizes of both sets. + if (candidate_containers.size() < m_subcondition_matches_ids.size()) { + // candidate_containers is smaller, so we iterate it and look up each candidate container in m_subcondition_matches_ids + for (std::vector<int>::const_iterator it = candidate_containers.begin(), end_it = candidate_containers.end(); it != end_it; ++it) { + // std::lower_bound requires m_subcondition_matches_ids to be sorted + std::vector<int>::const_iterator matching_it = std::lower_bound(m_subcondition_matches_ids.begin(), m_subcondition_matches_ids.end(), *it); + + if (matching_it != m_subcondition_matches_ids.end() && *matching_it == *it) { + match = true; + break; + } } + } else { + // m_subcondition_matches_ids is smaller, so we iterate it and look up each subcondition match in the set of candidate's containers + for (std::vector<int>::const_iterator it = m_subcondition_matches_ids.begin(); it != m_subcondition_matches_ids.end(); ++it) { + // candidate->ContainedBy() may have a faster implementation than candidate_containers->find() + if (candidate->ContainedBy(*it)) { + match = true; + break; + } + } } + return match; } - const Condition::ObjectSet& m_subcondition_matches; + std::vector<int> m_subcondition_matches_ids; }; } |
From: <geo...@us...> - 2014-01-25 22:44:02
|
Revision: 6708 http://sourceforge.net/p/freeorion/code/6708 Author: geoffthemedio Date: 2014-01-25 22:43:59 +0000 (Sat, 25 Jan 2014) Log Message: ----------- Tweaked ObjectID::GetDefaultInitialCandidateObjects to handle non-constant id specifications in safe cases (when id parameter is local candidate invariant). Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2014-01-25 22:12:24 UTC (rev 6707) +++ trunk/FreeOrion/universe/Condition.cpp 2014-01-25 22:43:59 UTC (rev 6708) @@ -2691,17 +2691,22 @@ if (!m_object_id) return; - if (!ValueRef::ConstantExpr(m_object_id)) { + bool simple_eval_safe = ValueRef::ConstantExpr(m_object_id) || + (m_object_id->LocalCandidateInvariant() && + (parent_context.condition_root_candidate || RootCandidateInvariant())); + + if (!simple_eval_safe) { AddAllObjectsSet(condition_non_targets); return; } // simple case of a single specified id; can add just that object - int obj_id = m_object_id->Eval(); - if (obj_id == INVALID_OBJECT_ID) + TemporaryPtr<const UniverseObject> no_object; + int object_id = m_object_id->Eval(ScriptingContext(parent_context, no_object)); + if (object_id == INVALID_OBJECT_ID) return; - TemporaryPtr<UniverseObject> obj = Objects().ExistingObject(obj_id); + TemporaryPtr<UniverseObject> obj = Objects().ExistingObject(object_id); if (obj) condition_non_targets.push_back(obj); } |
From: <geo...@us...> - 2014-06-23 19:50:30
|
Revision: 7189 http://sourceforge.net/p/freeorion/code/7189 Author: geoffthemedio Date: 2014-06-23 19:50:26 +0000 (Mon, 23 Jun 2014) Log Message: ----------- Added special case to Enqueued condition evaluation, so that if no low or high range limits are specified, it defaults to a low = 1. Previously, it would default to low = 0 whenever no low was specified, meaning if no low or high are specified, it matches locations regardless of whether anything is enqueued there. This is counter-intuitive, as I'd expect an Enqueued condition with no ranges specified to match places that have any number (ie. low = 1) items of the specified type enqueued. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2014-06-23 18:06:00 UTC (rev 7188) +++ trunk/FreeOrion/universe/Condition.cpp 2014-06-23 19:50:26 UTC (rev 7189) @@ -3593,6 +3593,14 @@ int empire_id = (m_empire_id ? m_empire_id->Eval(parent_context) : ALL_EMPIRES); int low = (m_low ? m_low->Eval(parent_context) : 0); int high = (m_high ? m_high->Eval(parent_context) : INT_MAX); + // special case: if neither low nor high is specified, default to a + // minimum of 1, so that just matching "Enqueued (type) (name/id)" will + // match places where at least one of the specified item is enqueued. + // if a max or other minimum are specified, then default to 0 low, so + // that just specifying a max will include anything below that max, + // including 0. + if (!m_low && !m_high) + low = 1; EvalImpl(matches, non_matches, search_domain, EnqueuedSimpleMatch(m_build_type, m_name, design_id, empire_id, low, high)); |
From: <ve...@us...> - 2015-01-08 16:54:23
|
Revision: 7823 http://sourceforge.net/p/freeorion/code/7823 Author: vezzra Date: 2015-01-08 16:54:20 +0000 (Thu, 08 Jan 2015) Log Message: ----------- Fixed bug in ResourceSupplyConnectedByEmpire condition Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2015-01-07 12:36:12 UTC (rev 7822) +++ trunk/FreeOrion/universe/Condition.cpp 2015-01-08 16:54:20 UTC (rev 7823) @@ -6216,7 +6216,9 @@ if (group.find(candidate->SystemID()) != group.end()) return true; // test object and candidate object are in same resourse sharing group else - return false; // test object is not in resource sharing group with candidate (each object can be in only one group) + // test object is not in resource sharing group with candidate + // as each object can be in only one group, no need to check the remaining groups + break; } // current subcondition-matching object is not in this resource sharing group } |
From: <geo...@us...> - 2015-01-15 02:31:28
|
Revision: 7842 http://sourceforge.net/p/freeorion/code/7842 Author: geoffthemedio Date: 2015-01-15 02:31:26 +0000 (Thu, 15 Jan 2015) Log Message: ----------- Safety checks in And, Or, and Not::Eval to ensure subconditions are non-null, due to some crashes I was getting due to missing subconditions, probably due to parser adjustment complications. At least it doesn't crash when doing first turn effects updates, now. Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2015-01-15 01:01:51 UTC (rev 7841) +++ trunk/FreeOrion/universe/Condition.cpp 2015-01-15 02:31:26 UTC (rev 7842) @@ -6933,6 +6933,17 @@ TemporaryPtr<const UniverseObject> no_object; ScriptingContext local_context(parent_context, no_object); + if (m_operands.empty()) { + Logger().errorStream() << "Condition::And::Eval given no operands!"; + return; + } + for (unsigned int i = 0; i < m_operands.size(); ++i) { + if (!m_operands[i]) { + Logger().errorStream() << "Condition::And::Eval given null operand!"; + return; + } + } + if (search_domain == NON_MATCHES) { ObjectSet partly_checked_non_matches; partly_checked_non_matches.reserve(non_matches.size()); @@ -7081,6 +7092,17 @@ TemporaryPtr<const UniverseObject> no_object; ScriptingContext local_context(parent_context, no_object); + if (m_operands.empty()) { + Logger().errorStream() << "Condition::Or::Eval given no operands!"; + return; + } + for (unsigned int i = 0; i < m_operands.size(); ++i) { + if (!m_operands[i]) { + Logger().errorStream() << "Condition::Or::Eval given null operand!"; + return; + } + } + if (search_domain == NON_MATCHES) { // check each item in the non-matches set against each of the operand conditions // if a non-candidate item matches an operand condition, move the item to the @@ -7217,6 +7239,11 @@ TemporaryPtr<const UniverseObject> no_object; ScriptingContext local_context(parent_context, no_object); + if (!m_operand) { + Logger().errorStream() << "Condition::Not::Eval found no subcondition to evaluate!"; + return; + } + if (search_domain == NON_MATCHES) { // search non_matches set for items that don't meet the operand // condition, and move those to the matches set |
From: <dil...@us...> - 2015-01-20 20:10:34
|
Revision: 7853 http://sourceforge.net/p/freeorion/code/7853 Author: dilvish-fo Date: 2015-01-20 20:10:32 +0000 (Tue, 20 Jan 2015) Log Message: ----------- fix by Geoff for recent problem with EmpireAffiliation condition Modified Paths: -------------- trunk/FreeOrion/universe/Condition.cpp Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2015-01-19 22:04:17 UTC (rev 7852) +++ trunk/FreeOrion/universe/Condition.cpp 2015-01-20 20:10:32 UTC (rev 7853) @@ -1045,7 +1045,7 @@ {} bool operator()(TemporaryPtr<const UniverseObject> candidate) const { - if (!candidate || candidate->Unowned()) + if (!candidate) return false; switch (m_affiliation) { |