From c2cbd8da27dda3e2b364f935b4e0f722ef1f5755 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Mon, 6 Jan 2014 14:17:56 +0000 Subject: [PATCH] Un-abstracted AbstractGoal to allow serialization. --- AI/VCAI/Goals.h | 29 +++++++++++++++-------------- AI/VCAI/VCAI.h | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/AI/VCAI/Goals.h b/AI/VCAI/Goals.h index 329f3ac3f..d5dcf637e 100644 --- a/AI/VCAI/Goals.h +++ b/AI/VCAI/Goals.h @@ -53,7 +53,7 @@ namespace Goals }; //method chaining + clone pattern -#define VSETTER(type, field) virtual AbstractGoal & set ## field(const type &rhs) = 0; +#define VSETTER(type, field) virtual AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;}; #define OSETTER(type, field) CGoal & set ## field(const type &rhs) override { field = rhs; return *this; }; #if 0 @@ -62,6 +62,8 @@ namespace Goals enum {LOW_PR = -1}; +TSubgoal sptr(const AbstractGoal & tmp); + class AbstractGoal { public: @@ -89,7 +91,10 @@ public: town = nullptr; } virtual ~AbstractGoal(){}; - virtual AbstractGoal * clone() const = 0; + //FIXME: abstract goal should be abstract, but serializer fails to instantiate subgoals in such case + virtual AbstractGoal * clone() const {return const_cast(this);}; + virtual TGoalVec getAllPossibleSubgoals() {TGoalVec vec; return vec;}; + virtual TSubgoal whatToDoToAchieve() {return sptr(AbstractGoal());}; EGoals goalType; @@ -102,9 +107,6 @@ public: static TSubgoal lookForArtSmart(int aid); //checks non-standard ways of obtaining art (merchants, quests, etc.) static TSubgoal tryRecruitHero(); - virtual TGoalVec getAllPossibleSubgoals() = 0; - virtual TSubgoal whatToDoToAchieve() = 0; - ///Visitor pattern //TODO: make accept work for shared_ptr... somehow virtual void accept (VCAI * ai); //unhandled goal will report standard error @@ -119,11 +121,11 @@ public: return false; } - //template void serialize(Handler &h, const int version) - //{ - // h & goalType & isElementar & isAbstract & priority; - // h & value & resID & objid & aid & tile & hero & town & bid; - //} + template void serialize(Handler &h, const int version) + { + h & goalType & isElementar & isAbstract & priority; + h & value & resID & objid & aid & tile & hero & town & bid; + } }; template class CGoal : public AbstractGoal @@ -171,13 +173,12 @@ public: } template void serialize(Handler &h, const int version) { - h & goalType & isElementar & isAbstract & priority; - h & value & resID & objid & aid & tile & hero & town & bid; + h & static_cast (*this); + //h & goalType & isElementar & isAbstract & priority; + //h & value & resID & objid & aid & tile & hero & town & bid; } }; -TSubgoal sptr(const AbstractGoal & tmp); - class Invalid : public CGoal { public: diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index 014d53f00..c512fe369 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -311,7 +311,7 @@ public: template void serializeInternal(Handler &h, const int version) { - h & knownSubterraneanGates & townVisitsThisWeek;// & lockedHeroes & reservedHeroesMap; //FIXME: cannot instantiate abstract class + h & knownSubterraneanGates & townVisitsThisWeek & lockedHeroes & reservedHeroesMap; //FIXME: cannot instantiate abstract class h & visitableObjs & alreadyVisited & reservedObjs; h & saving & status & battlename;