From: <geo...@us...> - 2011-09-01 20:23:32
|
Revision: 4215 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4215&view=rev Author: geoffthemedio Date: 2011-09-01 20:23:25 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Added Armed and Monster conditions, with parsing, that match ships that have weapons and that are space monsters, respectively. Modified Paths: -------------- trunk/FreeOrion/default/eng_stringtable.txt trunk/FreeOrion/universe/Condition.cpp trunk/FreeOrion/universe/Condition.h trunk/FreeOrion/universe/ConditionParser1.cpp Modified: trunk/FreeOrion/default/eng_stringtable.txt =================================================================== --- trunk/FreeOrion/default/eng_stringtable.txt 2011-09-01 18:28:10 UTC (rev 4214) +++ trunk/FreeOrion/default/eng_stringtable.txt 2011-09-01 20:23:25 UTC (rev 4215) @@ -2102,7 +2102,7 @@ Empire EMPIRE_CAPITAL -Capital: +Capital: NO_CAPITAL No Known Capital @@ -3462,6 +3462,18 @@ DESC_CAPITAL_NOT that is not an empire's capital planet +DESC_MONSTER + this is a space monster + +DESC_MONSTER_NOT + that is not a space monster + +DESC_ARMED + that is an armed ship + +DESC_ARMED_NOT + that is not an armed ship + DESC_TYPE that is a %1% Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2011-09-01 18:28:10 UTC (rev 4214) +++ trunk/FreeOrion/universe/Condition.cpp 2011-09-01 20:23:25 UTC (rev 4215) @@ -1074,6 +1074,74 @@ } /////////////////////////////////////////////////////////// +// Monster // +/////////////////////////////////////////////////////////// +Condition::Monster::Monster() +{} + +std::string Condition::Monster::Description(bool negated/* = false*/) const +{ + std::string description_str = "DESC_MONSTER"; + if (negated) + description_str += "_NOT"; + return UserString(description_str); +} + +std::string Condition::Monster::Dump() const +{ + return DumpIndent() + "Monster\n"; +} + +bool Condition::Monster::Match(const ScriptingContext& local_context) const +{ + const UniverseObject* candidate = local_context.condition_local_candidate; + if (!candidate) { + Logger().errorStream() << "Monster::Match passed no candidate object"; + return false; + } + + if (const Ship* ship = universe_object_cast<const Ship*>(candidate)) + if (ship->IsMonster()) + return true; + + return false; +} + +/////////////////////////////////////////////////////////// +// Armed // +/////////////////////////////////////////////////////////// +Condition::Armed::Armed() +{} + +std::string Condition::Armed::Description(bool negated/* = false*/) const +{ + std::string description_str = "DESC_ARMED"; + if (negated) + description_str += "_NOT"; + return UserString(description_str); +} + +std::string Condition::Armed::Dump() const +{ + return DumpIndent() + "Armed\n"; +} + +bool Condition::Armed::Match(const ScriptingContext& local_context) const +{ + const UniverseObject* candidate = local_context.condition_local_candidate; + if (!candidate) { + Logger().errorStream() << "Armed::Match passed no candidate object"; + return false; + } + + if (const Ship* ship = universe_object_cast<const Ship*>(candidate)) + if (ship->IsArmed()) + return true; + + return false; +} + +/////////////////////////////////////////////////////////// // Type // /////////////////////////////////////////////////////////// Condition::Type::Type(const ValueRef::ValueRefBase<UniverseObjectType>* type) : Modified: trunk/FreeOrion/universe/Condition.h =================================================================== --- trunk/FreeOrion/universe/Condition.h 2011-09-01 18:28:10 UTC (rev 4214) +++ trunk/FreeOrion/universe/Condition.h 2011-09-01 20:23:25 UTC (rev 4215) @@ -40,6 +40,8 @@ struct Target; struct Homeworld; struct Capital; + struct Monster; + struct Armed; struct Type; struct Building; struct HasSpecial; @@ -333,6 +335,40 @@ void serialize(Archive& ar, const unsigned int version); }; +/** Matches space monsters. */ +struct Condition::Monster : public Condition::ConditionBase +{ + Monster(); + virtual bool RootCandidateInvariant() const { return true; } + virtual bool TargetInvariant() const { return true; } + virtual std::string Description(bool negated = false) const; + virtual std::string Dump() const; + +private: + virtual bool Match(const ScriptingContext& local_context) const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + +/** Matches armed ships and monsters. */ +struct Condition::Armed : public Condition::ConditionBase +{ + Armed(); + virtual bool RootCandidateInvariant() const { return true; } + virtual bool TargetInvariant() const { return true; } + virtual std::string Description(bool negated = false) const; + virtual std::string Dump() const; + +private: + virtual bool Match(const ScriptingContext& local_context) const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + /** Matches all objects that are of UniverseObjectType \a type. */ struct Condition::Type : public Condition::ConditionBase { @@ -1213,6 +1249,18 @@ } template <class Archive> +void Condition::Monster::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase); +} + +template <class Archive> +void Condition::Armed::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase); +} + +template <class Archive> void Condition::Type::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) Modified: trunk/FreeOrion/universe/ConditionParser1.cpp =================================================================== --- trunk/FreeOrion/universe/ConditionParser1.cpp 2011-09-01 18:28:10 UTC (rev 4214) +++ trunk/FreeOrion/universe/ConditionParser1.cpp 2011-09-01 20:23:25 UTC (rev 4215) @@ -120,6 +120,8 @@ Rule target; Rule stationary; Rule capital; + Rule monster; + Rule armed; OwnedByRule owned_by; StringRefVecRule homeworld; StringRefVecRule building; @@ -177,6 +179,14 @@ str_p("capital") [capital.this_ = new_<Condition::Capital>()]; + monster = + str_p("monster") + [monster.this_ = new_<Condition::Monster>()]; + + armed = + str_p("armed") + [armed.this_ = new_<Condition::Armed>()]; + building = str_p("building") >> (name_label >> string_ref_vector[building.names = arg1]) @@ -276,7 +286,11 @@ all[condition1_p.this_ = arg1] | source[condition1_p.this_ = arg1] | focus_type[condition1_p.this_ = arg1] + | stationary[condition1_p.this_ = arg1] | homeworld[condition1_p.this_ = arg1] + | capital[condition1_p.this_ = arg1] + | monster[condition1_p.this_ = arg1] + | armed[condition1_p.this_ = arg1] | building[condition1_p.this_ = arg1] | species[condition1_p.this_ = arg1] | planet_type[condition1_p.this_ = arg1] @@ -286,7 +300,6 @@ | meter_value[condition1_p.this_ = arg1] | owned_by[condition1_p.this_ = arg1] | target[condition1_p.this_ = arg1] - | stationary[condition1_p.this_ = arg1] | and_[condition1_p.this_ = arg1] | or_[condition1_p.this_ = arg1] | not_[condition1_p.this_ = arg1]; |