diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index dcebf3c29..86684ce0a 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -374,7 +374,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldTyp else { curB->town = NULL; - curB->siege = 0; + curB->siege = CGTownInstance::NONE; curB->terrainType = terrain; } @@ -566,13 +566,13 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int battlefieldTyp } - if (curB->siege == 2 || curB->siege == 3) + if (curB->siege == CGTownInstance::CITADEL || curB->siege == CGTownInstance::CASTLE) { // keep tower CStack * stack = curB->generateNewStack(CStackBasicDescriptor(149, 1), false, 255, -2); stacks.push_back(stack); - if (curB->siege == 3) + if (curB->siege == CGTownInstance::CASTLE) { // lower tower + upper tower CStack * stack = curB->generateNewStack(CStackBasicDescriptor(149, 1), false, 255, -4); diff --git a/lib/BattleState.h b/lib/BattleState.h index 8a6b4dcb3..4d5cd1403 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -47,7 +47,7 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb { ui8 sides[2]; //sides[0] - attacker, sides[1] - defender si32 round, activeStack, selectedStack; - ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle + CGTownInstance::EFortLevel siege; const CGTownInstance * town; //used during town siege - id of attacked town; -1 if not town defence int3 tile; //for background and bonuses CGHeroInstance* heroes[2]; @@ -60,7 +60,7 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb SiegeInfo si; si32 battlefieldType; //like !!BA:B - ui8 terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy) + int terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy) ui8 tacticsSide; //which side is requested to play tactics phase ui8 tacticDistance; //how many hexes we can go forward (1 = only hexes adjacent to margin line) diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 411eb1adb..e7e789210 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -405,7 +405,7 @@ bool CBattleInfoEssentials::battleHasHero(ui8 side) const ui8 CBattleInfoEssentials::battleGetWallState(int partOfWall) const { RETURN_IF_NOT_BATTLE(0); - if(getBattle()->siege == 0) + if(getBattle()->siege == CGTownInstance::NONE) return 0; assert(partOfWall >= 0 && partOfWall < EWallParts::PARTS_COUNT); diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index a346d5584..14a3f1709 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -1020,7 +1020,7 @@ void CCommanderInstance::init() type = NULL; idRand = -1; _armyObj = NULL; - setNodeType (Bonus::COMMANDER); + setNodeType (CBonusSystemNode::COMMANDER); secondarySkills.resize (ECommander::SPELL_POWER + 1); } diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 31a42130a..362788f08 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -131,7 +131,7 @@ void CPlayersVisited::setPropertyDer( ui8 what, ui32 val ) players.insert((ui8)val); } -bool CPlayersVisited::wasVisited( ui8 player ) const +bool CPlayersVisited::wasVisited( TPlayerColor player ) const { return vstd::contains(players,player); } @@ -3552,7 +3552,7 @@ void CGVisitableOPW::newTurn() const cb->setHoverName(id,&ms); } } -bool CGVisitableOPW::wasVisited(ui8 player) const +bool CGVisitableOPW::wasVisited(TPlayerColor player) const { return visited; //TODO: other players should see object as unvisited } @@ -6268,7 +6268,7 @@ void CGKeys::setPropertyDer (ui8 what, ui32 val) //101-108 - enable key for play playerKeyMap.find(what-101)->second.insert((ui8)val); } -bool CGKeys::wasMyColorVisited (int player) const +bool CGKeys::wasMyColorVisited (TPlayerColor player) const { if (vstd::contains(playerKeyMap[player], subID)) //creates set if it's not there return true; @@ -6291,7 +6291,7 @@ const std::string CGKeys::getName() const return name; } -bool CGKeymasterTent::wasVisited (ui8 player) const +bool CGKeymasterTent::wasVisited (TPlayerColor player) const { return wasMyColorVisited (player); } diff --git a/lib/CObjectHandler.h b/lib/CObjectHandler.h index e0aebad85..25b98011c 100644 --- a/lib/CObjectHandler.h +++ b/lib/CObjectHandler.h @@ -55,7 +55,7 @@ public: MISSION_ART = 5, MISSION_ARMY = 6, MISSION_RESOURCES = 7, MISSION_HERO = 8, MISSION_PLAYER = 9, MISSION_KEYMASTER = 10}; enum Eprogress {NOT_ACTIVE, IN_PROGRESS, COMPLETE}; - si32 qid; //unique quets id for serialization / identification + si32 qid; //unique quest id for serialization / identification Emission missionType; Eprogress progress; @@ -172,8 +172,8 @@ public: CGDefInfo * defInfo; ui8 animPhaseShift; - ui8 tempOwner; - ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile + TPlayerColor tempOwner; + bool blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile virtual ui8 getPassableness() const; //bitmap - if the bit is set the corresponding player can pass through the visitable tiles of object, even if it's blockvis; if not set - default properties from definfo are used virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated @@ -234,9 +234,9 @@ public: class DLL_LINKAGE CPlayersVisited: public CGObjectInstance { public: - std::set players; //players that visited this object + std::set players; //players that visited this object - bool wasVisited(ui8 player) const; + bool wasVisited(TPlayerColor player) const; void setPropertyDer(ui8 what, ui32 val) override; template void serialize(Handler &h, const int version) @@ -305,7 +305,7 @@ public: std::vector > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities ui32 movement; //remaining movement points ui8 sex; - ui8 inTownGarrison; // if hero is in town garrison + bool inTownGarrison; // if hero is in town garrison ConstTransitivePtr visitedTown; //set if hero is visiting town or in the town garrison ConstTransitivePtr commander; const CGBoat *boat; //set to CGBoat when sailing @@ -319,7 +319,7 @@ public: struct DLL_LINKAGE Patrol { Patrol(){patrolling=false;patrolRadious=-1;}; - ui8 patrolling; + bool patrolling; ui32 patrolRadious; template void serialize(Handler &h, const int version) { @@ -329,7 +329,7 @@ public: struct DLL_LINKAGE HeroSpecial : CBonusSystemNode { - ui8 growsWithLevel; + bool growsWithLevel; HeroSpecial(){growsWithLevel = false;}; @@ -714,10 +714,10 @@ private: class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects { public: - ui8 removeAfterVisit; //true if event is removed after occurring + bool removeAfterVisit; //true if event is removed after occurring ui8 availableFor; //players whom this event is available for - ui8 computerActivate; //true if computre player can activate this event - ui8 humanActivate; //true if human player can activate this event + bool computerActivate; //true if computer player can activate this event + bool humanActivate; //true if human player can activate this event template void serialize(Handler &h, const int version) { @@ -738,8 +738,8 @@ public: std::string message; //message printed for attacking hero std::vector resources; //[res_id], resources given to hero that has won with monsters TArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none - ui8 neverFlees; //if true, the troops will never flee - ui8 notGrowingTeam; //if true, number of units won't grow + bool neverFlees; //if true, the troops will never flee + bool notGrowingTeam; //if true, number of units won't grow ui64 temppower; //used to handle fractional stack growth for tiny stacks @@ -891,7 +891,7 @@ public: class DLL_LINKAGE CGGarrison : public CArmedInstance { public: - ui8 removableUnits; + bool removableUnits; ui8 getPassableness() const; void onHeroVisit(const CGHeroInstance * h) const override; @@ -1002,7 +1002,7 @@ class DLL_LINKAGE CGVisitableOPW : public CGObjectInstance //objects visitable O public: ui8 visited; //true if object has been visited this week - bool wasVisited(ui8 player) const; + bool wasVisited(TPlayerColor player) const; void onHeroVisit(const CGHeroInstance * h) const override; void newTurn() const override; @@ -1046,7 +1046,7 @@ public: }; class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW -{///unfortunatelly, this one is quite different than others +{///unfortunately, this one is quite different than others public: void onHeroVisit(const CGHeroInstance * h) const override; const std::string & getHoverText() const override; @@ -1098,11 +1098,11 @@ public: class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards { public: - static std::map > playerKeyMap; //[players][keysowned] + static std::map > playerKeyMap; //[players][keysowned] //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black const std::string getName() const; //depending on color - bool wasMyColorVisited (int player) const; + bool wasMyColorVisited (TPlayerColor player) const; const std::string & getHoverText() const override; @@ -1117,7 +1117,7 @@ protected: class DLL_LINKAGE CGKeymasterTent : public CGKeys { public: - bool wasVisited (ui8 player) const; + bool wasVisited (TPlayerColor player) const; void onHeroVisit(const CGHeroInstance * h) const override; template void serialize(Handler &h, const int version) diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 4344a6502..98d26b288 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -530,7 +530,7 @@ void CTownHandler::load(const JsonNode &source) if (alignment == -1) faction.alignment = EAlignment::NEUTRAL; else - faction.alignment = alignment; + faction.alignment = static_cast(alignment); if (!node.second["town"].isNull()) { diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index ef91eb391..1a263364c 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -174,7 +174,7 @@ public: TFaction factionID; ui8 nativeTerrain; - ui8 alignment; // uses EAlignment enum + EAlignment::EAlignment alignment; TCreature commander; diff --git a/lib/Connection.h b/lib/Connection.h index 32fb0ebac..03c1b4e46 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -34,7 +34,7 @@ #include "CObjectHandler.h" //for CArmedInstance #include "Mapping/CCampaignHandler.h" //for CCampaignState -const ui32 version = 734; +const ui32 version = 735; const TSlot COMMANDER_SLOT_PLACEHOLDER = -2; class CConnection; @@ -72,6 +72,7 @@ namespace boost enum SerializationLvl { Wrong=0, + Boolean, Primitive, Array, Pointer, @@ -118,6 +119,23 @@ public: extern DLL_LINKAGE CTypeList typeList; + +template +struct SaveBoolean +{ + static void invoke(Ser &s, const bool &data) + { + s.saveBoolean(data); + } +}; +template +struct LoadBoolean +{ + static void invoke(Ser &s, bool &data) + { + s.loadBoolean(data); + } +}; template struct SavePrimitive { @@ -222,6 +240,10 @@ struct SerializationLevel { typedef mpl::integral_c_tag tag; typedef + typename mpl::eval_if< + boost::is_same, + mpl::int_, + //else typename mpl::eval_if< boost::is_fundamental, mpl::int_, @@ -252,6 +274,7 @@ struct SerializationLevel > > > + > >::type type; static const int value = SerializationLevel::type::value; }; @@ -406,7 +429,7 @@ struct SaveIfStackInstance assert(data->armyObj); TSlot slot = -1; - if(data->getNodeType() == Bonus::COMMANDER) + if(data->getNodeType() == CBonusSystemNode::COMMANDER) slot = COMMANDER_SLOT_PLACEHOLDER; else slot = data->armyObj->findStack(data); @@ -582,6 +605,9 @@ public: { typedef //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if typename mpl::eval_if< mpl::equal_to,mpl::int_ >, mpl::identity >, //else if @@ -602,6 +628,7 @@ public: > > > + > >::type typex; typex::invoke(* this->This(), data); } @@ -689,6 +716,11 @@ public: si32 writ = static_cast(data); *this << writ; } + void saveBoolean(const bool & data) + { + ui8 writ = static_cast(data); + *this << writ; + } }; @@ -778,6 +810,9 @@ public: { typedef //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if typename mpl::eval_if< mpl::equal_to,mpl::int_ >, mpl::identity >, //else if @@ -798,6 +833,7 @@ public: > > > + > >::type typex; typex::invoke(* this->This(), data); } @@ -1049,6 +1085,12 @@ public: *this >> read; data = static_cast(read); } + void loadBoolean(bool &data) + { + ui8 read; + *this >> read; + data = static_cast(read); + } }; class DLL_LINKAGE CSaveFile diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 4ebb0820b..7ae2616c0 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -970,7 +970,7 @@ void CBonusSystemNode::exportBonuses() exportBonus(b); } -ui8 CBonusSystemNode::getNodeType() const +CBonusSystemNode::ENodeTypes CBonusSystemNode::getNodeType() const { return nodeType; } @@ -995,7 +995,7 @@ const TNodesVector& CBonusSystemNode::getChildrenNodes() const return children; } -void CBonusSystemNode::setNodeType(ui8 type) +void CBonusSystemNode::setNodeType(CBonusSystemNode::ENodeTypes type) { nodeType = type; } @@ -1345,7 +1345,7 @@ int CCreatureTypeLimiter::limit(const BonusLimitationContext &context) const //drop bonus if it's not our creature and (we dont check upgrades or its not our upgrade) } -CCreatureTypeLimiter::CCreatureTypeLimiter(const CCreature &Creature, ui8 IncludeUpgrades /*= true*/) +CCreatureTypeLimiter::CCreatureTypeLimiter(const CCreature &Creature, bool IncludeUpgrades /*= true*/) :creature(&Creature), includeUpgrades(IncludeUpgrades) { } @@ -1411,7 +1411,7 @@ CPropagatorNodeType::CPropagatorNodeType() } -CPropagatorNodeType::CPropagatorNodeType(ui8 NodeType) +CPropagatorNodeType::CPropagatorNodeType(int NodeType) : nodeType(NodeType) { } diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index a4931c605..57222e5fd 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -467,10 +467,10 @@ public: class DLL_LINKAGE CPropagatorNodeType : public IPropagator { - ui8 nodeType; + int nodeType; //CBonusSystemNode::ENodeTypes public: CPropagatorNodeType(); - CPropagatorNodeType(ui8 NodeType); + CPropagatorNodeType(int NodeType); bool shouldBeAttached(CBonusSystemNode *dest); //CBonusSystemNode *getDestNode(CBonusSystemNode *source, CBonusSystemNode *redParent, CBonusSystemNode *redChild) OVERRIDE; @@ -547,6 +547,12 @@ public: class DLL_LINKAGE CBonusSystemNode : public IBonusBearer { +public: + enum ENodeTypes + { + UNKNOWN, STACK_INSTANCE, STACK_BATTLE, specialty, ARTIFACT, CREATURE, ARTIFACT_INSTANCE, HERO, PLAYER, TEAM, + TOWN_AND_VISITOR, BATTLE, COMMANDER + }; private: BonusList bonuses; //wielded bonuses (local or up-propagated here) BonusList exportedBonuses; //bonuses coming from this node (wielded or propagated away) @@ -554,7 +560,7 @@ private: TNodesVector parents; //parents -> we inherit bonuses from them, we may attach our bonuses to them TNodesVector children; - ui8 nodeType; + ENodeTypes nodeType; std::string description; static const bool cachingEnabled; @@ -622,8 +628,8 @@ public: BonusList &getBonusList(); const BonusList &getBonusList() const; BonusList &getExportedBonusList(); - ui8 getNodeType() const; - void setNodeType(ui8 type); + CBonusSystemNode::ENodeTypes getNodeType() const; + void setNodeType(CBonusSystemNode::ENodeTypes type); const TNodesVector &getParentNodes() const; const TNodesVector &getChildrenNodes() const; const std::string &getDescription() const; @@ -639,11 +645,6 @@ public: BONUS_TREE_DESERIALIZATION_FIX //h & parents & children; } - enum ENodeTypes - { - UNKNOWN, STACK_INSTANCE, STACK_BATTLE, specialty, ARTIFACT, CREATURE, ARTIFACT_INSTANCE, HERO, PLAYER, TEAM, - TOWN_AND_VISITOR, BATTLE - }; }; namespace NBonus @@ -761,10 +762,10 @@ class DLL_LINKAGE CCreatureTypeLimiter : public ILimiter //affect only stacks of { public: const CCreature *creature; - ui8 includeUpgrades; + bool includeUpgrades; CCreatureTypeLimiter(); - CCreatureTypeLimiter(const CCreature &Creature, ui8 IncludeUpgrades = true); + CCreatureTypeLimiter(const CCreature &Creature, bool IncludeUpgrades = true); void setCreature (TCreature id); int limit(const BonusLimitationContext &context) const OVERRIDE; @@ -781,7 +782,7 @@ class DLL_LINKAGE HasAnotherBonusLimiter : public ILimiter //applies only to nod public: TBonusType type; TBonusSubtype subtype; - ui8 isSubtypeRelevant; //check for subtype only if this is true + bool isSubtypeRelevant; //check for subtype only if this is true HasAnotherBonusLimiter(TBonusType bonus = Bonus::NONE); HasAnotherBonusLimiter(TBonusType bonus, TBonusSubtype _subtype); @@ -798,7 +799,7 @@ public: class DLL_LINKAGE CreatureNativeTerrainLimiter : public ILimiter //applies only to creatures that are on their native terrain { public: - si8 terrainType; + int terrainType; CreatureNativeTerrainLimiter(); CreatureNativeTerrainLimiter(int TerrainType); diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 505ff53b3..8aefe7000 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1420,7 +1420,7 @@ DLL_LINKAGE void ObstaclesRemoved::applyGs( CGameState *gs ) DLL_LINKAGE void CatapultAttack::applyGs( CGameState *gs ) { - if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege + if(gs->curB && gs->curB->siege != CGTownInstance::NONE) //if there is a battle and it's a siege { BOOST_FOREACH(const auto &it,attackedParts) {