From: <tz...@us...> - 2006-03-11 00:13:34
|
Revision: 1809 Author: tzlaine Date: 2006-03-10 16:13:23 -0800 (Fri, 10 Mar 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1809&view=rev Log Message: ----------- Removed the RefineBuildingType Effect subclass and added a new Condition subclass OwnerHasTech. This is to replace the kludgey way that refinement techs were expected to operate, in favor of a more natural system. Now, EffectsGroups' activation conditions can be based on whether a certain tech is known to the source's owner, effectively allowing the enabling or disabling each EffectsGroup based on the existence of one or more refinement techs. Modified Paths: -------------- trunk/FreeOrion/Empire/Empire.cpp trunk/FreeOrion/Empire/Empire.h trunk/FreeOrion/universe/Condition.cpp trunk/FreeOrion/universe/Condition.h trunk/FreeOrion/universe/Effect.cpp trunk/FreeOrion/universe/Effect.h trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/Empire/Empire.cpp =================================================================== --- trunk/FreeOrion/Empire/Empire.cpp 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/Empire/Empire.cpp 2006-03-11 00:13:23 UTC (rev 1809) @@ -922,22 +922,6 @@ m_building_types.insert(name); } -void Empire::RefineBuildingType(const std::string& name, const std::vector<boost::shared_ptr<const Effect::EffectsGroup> >& effects) -{ - BuildingType*& building = m_modified_building_types[name]; - if (!building) - building = new BuildingType(*::GetBuildingType(name)); - building->AddEffects(effects); -} - -void Empire::ClearRefinements() -{ - for (std::map<std::string, BuildingType*>::iterator it = m_modified_building_types.begin(); it != m_modified_building_types.end(); ++it) { - delete it->second; - } - m_modified_building_types.clear(); -} - void Empire::AddExploredSystem(int ID) { m_explored_systems.insert(ID); Modified: trunk/FreeOrion/Empire/Empire.h =================================================================== --- trunk/FreeOrion/Empire/Empire.h 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/Empire/Empire.h 2006-03-11 00:13:23 UTC (rev 1809) @@ -324,7 +324,7 @@ /// Returns the set of all available techs. const std::set<std::string>& AvailableTechs() const; - /// progress of partially-researched techs; fully researched techs cannot be found in this container + /// Returns true iff this tech has been completely resarched. bool TechAvailable(const std::string& name) const; /// Returns the set of all available building types. @@ -416,12 +416,6 @@ /// Inserts the given BuildingType into the Empire's list of available BuldingTypes. void AddBuildingType(const std::string& name); - /** Adds EffectsGroups \a effects to the empire-specific version of BuildingType \a name. */ - void RefineBuildingType(const std::string& name, const std::vector<boost::shared_ptr<const Effect::EffectsGroup> >& effects); - - /** Removes all refinements to Buildings, ShipComponents, etc., that are caused by Tech effects. */ - void ClearRefinements(); - /// Inserts the given ID into the Empire's list of explored systems. void AddExploredSystem(int ID); @@ -436,7 +430,7 @@ * references to SitRepEntries lying around when this happens. * You \a must pass in a dynamically allocated sitrep entry */ - void AddSitRepEntry( SitRepEntry* entry); + void AddSitRepEntry(SitRepEntry* entry); /// Removes the given Tech from the empire's list void RemoveTech(const std::string& name); Modified: trunk/FreeOrion/universe/Condition.cpp =================================================================== --- trunk/FreeOrion/universe/Condition.cpp 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/universe/Condition.cpp 2006-03-11 00:13:23 UTC (rev 1809) @@ -29,6 +29,7 @@ Condition::ConditionBase* NewChance(const XMLElement& elem) {return new Condition::Chance(elem);} Condition::ConditionBase* NewMeterValue(const XMLElement& elem) {return new Condition::MeterValue(elem);} Condition::ConditionBase* NewEmpireStockpileValue(const XMLElement& elem) {return new Condition::EmpireStockpileValue(elem);} + Condition::ConditionBase* NewOwnerHasTech(const XMLElement& elem) {return new Condition::OwnerHasTech(elem);} Condition::ConditionBase* NewVisibleToEmpire(const XMLElement& elem) {return new Condition::VisibleToEmpire(elem);} Condition::ConditionBase* NewWithinDistance(const XMLElement& elem) {return new Condition::WithinDistance(elem);} Condition::ConditionBase* NewWithinStarlaneJumps(const XMLElement& elem) {return new Condition::WithinStarlaneJumps(elem);} @@ -89,6 +90,7 @@ factory.AddGenerator("Condition::Chance", &NewChance); factory.AddGenerator("Condition::MeterValue", &NewMeterValue); factory.AddGenerator("Condition::EmpireStockpileValue", &NewEmpireStockpileValue); + factory.AddGenerator("Condition::OwnerHasTech", &NewOwnerHasTech); factory.AddGenerator("Condition::VisibleToEmpire", &NewVisibleToEmpire); factory.AddGenerator("Condition::WithinDistance", &NewWithinDistance); factory.AddGenerator("Condition::WithinStarlaneJumps", &NewWithinStarlaneJumps); @@ -980,7 +982,7 @@ } /////////////////////////////////////////////////////////// -// EmpireStockpileValue // +// EmpireStockpileValue // /////////////////////////////////////////////////////////// Condition::EmpireStockpileValue::EmpireStockpileValue(StockpileType stockpile, const ValueRef::ValueRefBase<double>* low, const ValueRef::ValueRefBase<double>* high) : m_stockpile(stockpile), @@ -1036,6 +1038,37 @@ } /////////////////////////////////////////////////////////// +// OwnerHasTech // +/////////////////////////////////////////////////////////// +Condition::OwnerHasTech::OwnerHasTech(const std::string& name) : + m_name(name) +{} + +Condition::OwnerHasTech::OwnerHasTech(const XMLElement& elem) +{ + if (elem.Tag() != "Condition::OwnerHasTech") + throw std::runtime_error("Condition::OwnerHasTech : Attempted to create a OwnerHasTech condition from an XML element with a tag other than \"Condition::OwnerHasTech\"."); + + m_name = elem.Text(); +} + +std::string Condition::OwnerHasTech::Description(bool negated/* = false*/) const +{ + std::string description_str = "DESC_OWNER_HAS_TECH"; + if (negated) + description_str += "_NOT"; + return str(format(UserString(description_str)) % UserString(m_name)); +} + +bool Condition::OwnerHasTech::Match(const UniverseObject* source, const UniverseObject* target) const +{ + if (target->Owners().size() != 1) + return false; + Empire* empire = Empires().Lookup(*target->Owners().begin()); + return empire->TechAvailable(m_name); +} + +/////////////////////////////////////////////////////////// // VisibleToEmpire // /////////////////////////////////////////////////////////// Condition::VisibleToEmpire::VisibleToEmpire(const std::vector<const ValueRef::ValueRefBase<int>*>& empire_ids) : Modified: trunk/FreeOrion/universe/Condition.h =================================================================== --- trunk/FreeOrion/universe/Condition.h 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/universe/Condition.h 2006-03-11 00:13:23 UTC (rev 1809) @@ -29,6 +29,7 @@ struct Chance; struct MeterValue; struct EmpireStockpileValue; + struct OwnerHasTech; struct VisibleToEmpire; struct WithinDistance; struct WithinStarlaneJumps; @@ -305,6 +306,18 @@ const ValueRef::ValueRefBase<double>* m_high; }; +/** Matches all objects that have a single owner who has tech \a tech_name. */ +struct Condition::OwnerHasTech : Condition::ConditionBase +{ + OwnerHasTech(const std::string& name); + OwnerHasTech(const XMLElement& elem); + virtual std::string Description(bool negated = false) const; + +private: + virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; + std::string m_name; +}; + /** Matches all objects that are visible to at least one Empire in \a empire_ids. */ struct Condition::VisibleToEmpire : Condition::ConditionBase { Modified: trunk/FreeOrion/universe/Effect.cpp =================================================================== --- trunk/FreeOrion/universe/Effect.cpp 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/universe/Effect.cpp 2006-03-11 00:13:23 UTC (rev 1809) @@ -685,66 +685,6 @@ /////////////////////////////////////////////////////////// -// RefineBuildingType // -/////////////////////////////////////////////////////////// -RefineBuildingType::RefineBuildingType(const std::string& building_type_name, - const ValueRef::ValueRefBase<int>* empire_id, - const std::vector<boost::shared_ptr<const Effect::EffectsGroup> >& effects) : - m_building_type_name(building_type_name), - m_empire_id(empire_id), - m_effects(effects) -{ -} - -RefineBuildingType::RefineBuildingType(const XMLElement& elem) -{ - if (elem.Tag() != "Effect::RefineBuildingType") - throw std::invalid_argument("Attempted to construct a Effect::RefineBuildingType from an XMLElement that had a tag other than \"Effect::RefineBuildingType\""); - - m_building_type_name = elem.Child("building_type").Text(); - m_empire_id = ParseArithmeticExpression<int>(elem.Child("empire_id").Text()); - for (XMLElement::const_child_iterator it = elem.Child("effects").child_begin(); it != elem.Child("effects").child_end(); ++it) { - m_effects.push_back(boost::shared_ptr<const Effect::EffectsGroup>(new Effect::EffectsGroup(*it))); - } -} - -RefineBuildingType::~RefineBuildingType() -{ - delete m_empire_id; -} - -void RefineBuildingType::Execute(const UniverseObject* source, UniverseObject* target) const -{ - int empire_id = m_empire_id->Eval(source, target); - Empire* empire = Empires().Lookup(empire_id); - empire->RefineBuildingType(m_building_type_name, m_effects); -} - -std::string RefineBuildingType::Description() const -{ - std::string retval; - std::string empire_str = ValueRef::ConstantExpr(m_empire_id) ? Empires().Lookup(m_empire_id->Eval(0, 0))->Name() : m_empire_id->Description(); -#if 0 - retval = str(format(UserString("DESC_REFINE_BUILDING_TYPE")) - % m_building_type_name - % empire_str); - for (unsigned int i = 0; i < m_effects.size(); ++i) { - EffectsGroup::Description description = m_effects.GetDescription(); - retval += str(format(UserString("DESC_EFFECTS_GROUP")) - % description.scope_description - % description.activation_description); - for (unsigned int j = 0; j < description.effect_descriptions.size(); ++j) { - retval += str(format(UserString("DESC_EFFECT")) - % lexical_cast<std::string>(j) - % description.effect_descriptions[i]); - } - } -#endif - return retval; -} - - -/////////////////////////////////////////////////////////// // SetEffectTarget // /////////////////////////////////////////////////////////// SetEffectTarget::SetEffectTarget(const ValueRef::ValueRefBase<int>* effect_target_id) : Modified: trunk/FreeOrion/universe/Effect.h =================================================================== --- trunk/FreeOrion/universe/Effect.h 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/universe/Effect.h 2006-03-11 00:13:23 UTC (rev 1809) @@ -19,7 +19,6 @@ class RemoveSpecial; class SetStarType; class SetTechAvailability; - class RefineBuildingType; class SetEffectTarget; XMLObjectFactory<EffectBase> EffectFactory(); ///< an XML factory that creates the right subclass of EffectBase from a given XML element } @@ -265,25 +264,6 @@ bool m_include_tech; }; -/** Adds additional EffectsGroups \a effects to the \a building_type_name BuildingType definition for Empire \a empire_id. This is intended to be used - for Refinement Techs and special events. */ -class Effect::RefineBuildingType : public Effect::EffectBase -{ -public: - RefineBuildingType(const std::string& building_type_name, const ValueRef::ValueRefBase<int>* empire_id, - const std::vector<boost::shared_ptr<const Effect::EffectsGroup> >& effects); - RefineBuildingType(const XMLElement& elem); - virtual ~RefineBuildingType(); - - virtual void Execute(const UniverseObject* source, UniverseObject* target) const; - virtual std::string Description() const; - -private: - std::string m_building_type_name; - const ValueRef::ValueRefBase<int>* m_empire_id; - std::vector<boost::shared_ptr<const Effect::EffectsGroup> > m_effects; -}; - class Effect::SetEffectTarget : public Effect::EffectBase { public: Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2006-03-07 00:15:43 UTC (rev 1808) +++ trunk/FreeOrion/universe/Universe.cpp 2006-03-11 00:13:23 UTC (rev 1809) @@ -1176,7 +1176,6 @@ } } for (EmpireManager::iterator it = Empires().begin(); it != Empires().end(); ++it) { - it->second->ClearRefinements(); for (Empire::TechItr tech_it = it->second->TechBegin(); tech_it != it->second->TechEnd(); ++tech_it) { const Tech* tech = GetTech(*tech_it); assert(tech); |