浏览代码

few more refactorings

alexvins 12 年之前
父节点
当前提交
a9d458c8f4

+ 1 - 1
AI/EmptyAI/CEmptyAI.cpp

@@ -13,7 +13,7 @@ void CEmptyAI::yourTurn()
 	cb->endTurn();
 }
 
-void CEmptyAI::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, int queryID)
+void CEmptyAI::heroGotLevel(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill::SecondarySkill> &skills, int queryID)
 {
 	cb->selectionMade(rand() % skills.size(), queryID);
 }

+ 2 - 2
AI/EmptyAI/CEmptyAI.h

@@ -12,9 +12,9 @@ class CEmptyAI : public CGlobalAI
 public:
 	void init(CCallback * CB) override;
 	void yourTurn() override;
-	void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, int queryID) override; 
+	void heroGotLevel(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill::SecondarySkill> &skills, int queryID) override;
 	void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, int queryID) override;
-	void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) override; 
+	void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) override;
 	void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, int queryID) override;
 };
 

+ 10 - 10
lib/CArtHandler.cpp

@@ -25,7 +25,7 @@ using namespace boost::assign;
 
 extern boost::rand48 ran;
 
-const std::map<std::string, CArtifact::EartClass> artifactClassMap = boost::assign::map_list_of 
+const std::map<std::string, CArtifact::EartClass> artifactClassMap = boost::assign::map_list_of
 	("TREASURE", CArtifact::ART_TREASURE)
 	("MINOR", CArtifact::ART_MINOR)
 	("MAJOR", CArtifact::ART_MAJOR)
@@ -38,7 +38,7 @@ const std::map<std::string, CArtifact::EartClass> artifactClassMap = boost::assi
 
 #define ART_POS(x) ( #x, ArtifactPosition::x )
 
-const std::map<std::string, int> artifactPositionMap = boost::assign::map_list_of 
+const std::map<std::string, int> artifactPositionMap = boost::assign::map_list_of
 	ART_POS(HEAD)
 	ART_POS(SHOULDERS)
 	ART_POS(NECK)
@@ -424,7 +424,7 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
 			art->aClass = CArtifact::ART_SPECIAL;
 		}
 	}
-	
+
 	int bearerType = -1;
 	bool heroArt = false;
 
@@ -707,7 +707,7 @@ void CArtHandler::addBonuses()
 	BOOST_FOREACH (auto & artifact, config["artifacts"].Struct()) //pair <string, JsonNode> (id, properties)
 	{
 		auto ga = artifacts[artifact.second["id"].Float()].get();
-		
+
 		BOOST_FOREACH (auto b, artifact.second["bonuses"].Vector())
 		{
 			auto bonus = JsonUtils::parseBonus (b);
@@ -783,7 +783,7 @@ bool CArtHandler::legalArtifact(int id)
 			(artifacts[id]->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT);
 }
 
-void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
+void CArtHandler::initAllowedArtifactsList(const std::vector<bool> &allowed)
 {
 	allowedArtifacts.clear();
 	clearHlpLists();
@@ -812,12 +812,12 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
 	}
 }
 
-std::vector<ui8> CArtHandler::getDefaultAllowedArtifacts() const
+std::vector<bool> CArtHandler::getDefaultAllowedArtifacts() const
 {
-	std::vector<ui8> allowedArtifacts;
-	allowedArtifacts.resize(127, 1);
-	allowedArtifacts.resize(141, 0);
-	allowedArtifacts.resize(GameConstants::ARTIFACTS_QUANTITY, 1);
+	std::vector<bool> allowedArtifacts;
+	allowedArtifacts.resize(127, true);
+	allowedArtifacts.resize(141, false);
+	allowedArtifacts.resize(GameConstants::ARTIFACTS_QUANTITY, true);
 	return allowedArtifacts;
 }
 

+ 3 - 3
lib/CArtHandler.h

@@ -248,7 +248,7 @@ public:
 	void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
 	void erasePickedArt (TArtifactInstanceID id);
 	bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
-	void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
+	void initAllowedArtifactsList(const std::vector<bool> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
 	static int convertMachineID(int id, bool creToArt);
 	void makeItCreatureArt (CArtifact * a, bool onlyCreature = true);
 	void makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature = true);
@@ -260,9 +260,9 @@ public:
 	/**
 	 * Gets a list of default allowed artifacts.
 	 *
-	 * @return a list of allowed artifacts, the index is the artifact id and the value either 0 for not allowed or 1 for allowed
+	 * @return a list of allowed artifacts, the index is the artifact id
 	 */
-	std::vector<ui8> getDefaultAllowedArtifacts() const;
+	std::vector<bool> getDefaultAllowedArtifacts() const;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 6 - 6
lib/CHeroHandler.cpp

@@ -359,7 +359,7 @@ void CHeroHandler::loadObstacles()
 {
 	auto loadObstacles = [](const JsonNode &node, bool absolute, std::map<int, CObstacleInfo> &out)
 	{
-		BOOST_FOREACH(const JsonNode &obs, node.Vector()) 
+		BOOST_FOREACH(const JsonNode &obs, node.Vector())
 		{
 			int ID = obs["id"].Float();
 			CObstacleInfo & obi = out[ID];
@@ -500,10 +500,10 @@ void CHeroHandler::loadTerrains()
 		terrCosts.push_back(config[name]["moveCost"].Float());
 }
 
-std::vector<ui8> CHeroHandler::getDefaultAllowedHeroes() const
+std::vector<bool> CHeroHandler::getDefaultAllowedHeroes() const
 {
 	// Look Data/HOTRAITS.txt for reference
-	std::vector<ui8> allowedHeroes;
+	std::vector<bool> allowedHeroes;
 	allowedHeroes.reserve(heroes.size());
 
 	BOOST_FOREACH(const CHero * hero, heroes)
@@ -514,9 +514,9 @@ std::vector<ui8> CHeroHandler::getDefaultAllowedHeroes() const
 	return allowedHeroes;
 }
 
-std::vector<ui8> CHeroHandler::getDefaultAllowedAbilities() const
+std::vector<bool> CHeroHandler::getDefaultAllowedAbilities() const
 {
-	std::vector<ui8> allowedAbilities;
-	allowedAbilities.resize(GameConstants::SKILL_QUANTITY, 1);
+	std::vector<bool> allowedAbilities;
+	allowedAbilities.resize(GameConstants::SKILL_QUANTITY, true);
 	return allowedAbilities;
 }

+ 4 - 4
lib/CHeroHandler.h

@@ -185,7 +185,7 @@ public:
 
 	//default costs of going through terrains. -1 means terrain is impassable
 	std::vector<int> terrCosts;
-	
+
 	struct SBallisticsLevelInfo
 	{
 		ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
@@ -233,14 +233,14 @@ public:
 	 *
 	 * @return a list of allowed heroes, the index is the hero id and the value either 0 for not allowed or 1 for allowed
 	 */
-	std::vector<ui8> getDefaultAllowedHeroes() const;
+	std::vector<bool> getDefaultAllowedHeroes() const;
 
 	/**
 	 * Gets a list of default allowed abilities. OH3 abilities/skills are all allowed by default.
 	 *
-	 * @return a list of allowed abilities, the index is the ability id and the value either 0 for not allowed or 1 for allowed
+	 * @return a list of allowed abilities, the index is the ability id
 	 */
-	std::vector<ui8> getDefaultAllowedAbilities() const;
+	std::vector<bool> getDefaultAllowedAbilities() const;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 2 - 2
lib/CObjectHandler.h

@@ -679,7 +679,7 @@ public:
 	si32 manaDiff; //amount of gained / lost mana
 	si32 moraleDiff; //morale modifier
 	si32 luckDiff; //luck modifier
-	std::vector<si32> resources;//gained / lost resources
+	TResources resources;//gained / lost resources
 	std::vector<si32> primskills;//gained / lost prim skills
 	std::vector<SecondarySkill::SecondarySkill> abilities; //gained abilities
 	std::vector<si32> abilityLevels; //levels of gained abilities
@@ -730,7 +730,7 @@ public:
 	ui32 identifier; //unique code for this monster (used in missions)
 	si8 character; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage)
 	std::string message; //message printed for attacking hero
-	std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
+	TResources resources; // resources given to hero that has won with monsters
 	TArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none
 	bool neverFlees; //if true, the troops will never flee
 	bool notGrowingTeam; //if true, number of units won't grow

+ 3 - 3
lib/CSpellHandler.cpp

@@ -527,9 +527,9 @@ void CSpellHandler::loadSpells()
 	boost::replace_first(spells[Spells::FORGETFULNESS]->attributes, "CREATURE_TARGET", "CREATURE_TARGET_2"); //TODO: use flags instead?
 }
 
-std::vector<ui8> CSpellHandler::getDefaultAllowedSpells() const
+std::vector<bool> CSpellHandler::getDefaultAllowedSpells() const
 {
-	std::vector<ui8> allowedSpells;
-	allowedSpells.resize(GameConstants::SPELLS_QUANTITY, 1);
+	std::vector<bool> allowedSpells;
+	allowedSpells.resize(GameConstants::SPELLS_QUANTITY, true);
 	return allowedSpells;
 }

+ 1 - 1
lib/CSpellHandler.h

@@ -187,7 +187,7 @@ public:
 	 *
 	 * @return a list of allowed spells, the index is the spell id and the value either 0 for not allowed or 1 for allowed
 	 */
-	std::vector<ui8> getDefaultAllowedSpells() const;
+	std::vector<bool> getDefaultAllowedSpells() const;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 5 - 5
lib/Mapping/CMap.h

@@ -580,10 +580,10 @@ public:
 	ui8 howManyTeams;
 
 	/**
-	 * A list of allowed heroes. The index is the hero id and the value is either 0 for not allowed or 1 for allowed.
+	 * A list of allowed heroes. The index is the hero id and the value = hero allowed.
 	 * The default value is a list of default allowed heroes. See CHeroHandler::getDefaultAllowedHeroes for more info.
 	 */
-	std::vector<ui8> allowedHeroes;
+	std::vector<bool> allowedHeroes;
 
 	/** A list of placeholded heroes. The index is the id of a hero type. */
 	std::vector<ui16> placeholdedHeroes;
@@ -734,13 +734,13 @@ public:
 	std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
 
 	/** list of allowed spells, index is the spell id */
-	std::vector<ui8> allowedSpell;
+	std::vector<bool> allowedSpell;
 
 	/** list of allowed artifacts, index is the artifact id */
-	std::vector<ui8> allowedArtifact;
+	std::vector<bool> allowedArtifact;
 
 	/** list of allowed abilities, index is the ability id */
-	std::vector<ui8> allowedAbilities;
+	std::vector<bool> allowedAbilities;
 
 	/** list of map events */
 	std::list<ConstTransitivePtr<CMapEvent> > events;

+ 80 - 132
lib/Mapping/MapFormatH3M.cpp

@@ -405,24 +405,11 @@ void CMapLoaderH3M::readTeamInfo()
 
 void CMapLoaderH3M::readAllowedHeroes()
 {
-	int lim = mapHeader->version == EMapFormat::ROE ? 16 : 20;
-
 	mapHeader->allowedHeroes.resize(VLC->heroh->heroes.size(), true);
 
-	for(int i = 0; i<lim; ++i)
-	{
-		ui8 c = readUI8();
-		for(int yy = 0; yy < 8; ++yy)
-		{
-			if(i * 8 + yy < GameConstants::HEROES_QUANTITY)
-			{
-				if(c != (c | static_cast<ui8>(std::pow(2., yy))))
-				{
-					mapHeader->allowedHeroes[i * 8 + yy] = false;
-				}
-			}
-		}
-	}
+	const int bytes = mapHeader->version == EMapFormat::ROE ? 16 : 20;
+
+	readBitmask(mapHeader->allowedHeroes,bytes,GameConstants::HEROES_QUANTITY, false);
 
 	// Probably reserved for further heroes
 	if(mapHeader->version > EMapFormat::ROE)
@@ -457,31 +444,15 @@ void CMapLoaderH3M::readDisposedHeroes()
 
 void CMapLoaderH3M::readAllowedArtifacts()
 {
-	map->allowedArtifact.resize (VLC->arth->artifacts.size()); //handle new artifacts, make them allowed by default
-	for (ui32 x = 0; x < map->allowedArtifact.size(); ++x)
-	{
-		map->allowedArtifact[x] = true;
-	}
+	map->allowedArtifact.resize (VLC->arth->artifacts.size(),true); //handle new artifacts, make them allowed by default
 
 	// Reading allowed artifacts:  17 or 18 bytes
 	if(map->version != EMapFormat::ROE)
 	{
-		int lim = map->version == EMapFormat::AB ? 17 : 18;
+		const int bytes = map->version == EMapFormat::AB ? 17 : 18;
+
+		readBitmask(map->allowedArtifact,bytes,GameConstants::ARTIFACTS_QUANTITY);
 
-		for(int i = 0; i < lim; ++i)
-		{
-			ui8 c = readUI8();
-			for(int yy = 0; yy < 8; ++yy)
-			{
-				if(i * 8 + yy < GameConstants::ARTIFACTS_QUANTITY)
-				{
-					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-					{
-						map->allowedArtifact[i * 8 + yy] = false;
-					}
-				}
-			}
-		}
 	}
 
 	// ban combo artifacts
@@ -513,53 +484,20 @@ void CMapLoaderH3M::readAllowedArtifacts()
 void CMapLoaderH3M::readAllowedSpellsAbilities()
 {
 	// Read allowed spells
-	map->allowedSpell.resize(GameConstants::SPELLS_QUANTITY);
-	for(ui32 x = 0; x < map->allowedSpell.size(); x++)
-	{
-		map->allowedSpell[x] = true;
-	}
+	map->allowedSpell.resize(GameConstants::SPELLS_QUANTITY, true);
 
 	// Read allowed abilities
-	map->allowedAbilities.resize(GameConstants::SKILL_QUANTITY);
-	for(ui32 x = 0; x < map->allowedAbilities.size(); x++)
-	{
-		map->allowedAbilities[x] = true;
-	}
+	map->allowedAbilities.resize(GameConstants::SKILL_QUANTITY, true);
 
 	if(map->version >= EMapFormat::SOD)
 	{
 		// Reading allowed spells (9 bytes)
-		for(int i = 0; i < 9; ++i)
-		{
-			ui8 c = readUI8();
-			for(int yy = 0; yy < 8; ++yy)
-			{
-				if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
-				{
-					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-					{
-						map->allowedSpell[i* 8 + yy] = false;
-					}
-				}
-			}
-		}
-
+		const int spell_bytes = 9;
+		readBitmask(map->allowedSpell, spell_bytes, GameConstants::SPELLS_QUANTITY);
 
 		// Allowed hero's abilities (4 bytes)
-		for(int i = 0; i < 4; ++i)
-		{
-			ui8 c = readUI8();
-			for(int yy = 0; yy < 8; ++yy)
-			{
-				if(i * 8 + yy < GameConstants::SKILL_QUANTITY)
-				{
-					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-					{
-						map->allowedAbilities[i * 8 + yy] = false;
-					}
-				}
-			}
-		}
+		const int abil_bytes = 4;
+		readBitmask(map->allowedAbilities, abil_bytes, GameConstants::SKILL_QUANTITY);
 	}
 }
 
@@ -629,20 +567,7 @@ void CMapLoaderH3M::readPredefinedHeroes()
 				// are spells
 				if(readBool())
 				{
-					for(int i = 0; i < 9; ++i)
-					{
-						ui8 c = readUI8();
-						for(int yy = 0; yy < 8; ++yy)
-						{
-							if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
-							{
-								if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-								{
-									hero->spells.insert(i * 8 + yy);
-								}
-							}
-						}
-					}
+					readSpells(hero->spells);
 				}
 
 				// customPrimSkills
@@ -914,7 +839,7 @@ void CMapLoaderH3M::readObjects()
 
 					if(readBool())
 					{
-						readCreatureSet(evnt, 7, map->version > EMapFormat::ROE);
+						readCreatureSet(evnt, 7);
 					}
 					skip(4);
 				}
@@ -923,11 +848,7 @@ void CMapLoaderH3M::readObjects()
 				evnt->moraleDiff = readSI8();
 				evnt->luckDiff = readSI8();
 
-				evnt->resources.resize(GameConstants::RESOURCE_QUANTITY);
-				for(int x = 0; x < 7; ++x)
-				{
-					evnt->resources[x] = readUI32();
-				}
+				readResourses(evnt->resources);
 
 				evnt->primskills.resize(GameConstants::PRIMARY_SKILLS);
 				for(int x = 0; x < 4; ++x)
@@ -962,7 +883,7 @@ void CMapLoaderH3M::readObjects()
 				}
 
 				int gcre = readUI8(); //number of gained creatures
-				readCreatureSet(&evnt->creatures, gcre, map->version > EMapFormat::ROE);
+				readCreatureSet(&evnt->creatures, gcre);
 
 				skip(8);
 				evnt->availableFor = readUI8();
@@ -1059,11 +980,7 @@ void CMapLoaderH3M::readObjects()
 				if(readBool()) //true if there is message or treasury
 				{
 					cre->message = readString();
-					cre->resources.resize(GameConstants::RESOURCE_QUANTITY);
-					for(int j = 0; j < 7; ++j)
-					{
-						cre->resources[j] = readUI32();
-					}
+					readResourses(cre->resources);
 
 					int artID;
 					if (map->version == EMapFormat::ROE)
@@ -1167,7 +1084,7 @@ void CMapLoaderH3M::readObjects()
 				nobj = gar;
 				nobj->setOwner(readUI8());
 				skip(3);
-				readCreatureSet(gar, 7, map->version > EMapFormat::ROE);
+				readCreatureSet(gar, 7);
 				if(map->version > EMapFormat::ROE)
 				{
 					gar->removableUnits = readBool();
@@ -1197,7 +1114,7 @@ void CMapLoaderH3M::readObjects()
 					art->message = readString();
 					if(readBool())
 					{
-						readCreatureSet(art, 7, map->version > EMapFormat::ROE);
+						readCreatureSet(art, 7);
 					}
 					skip(4);
 				}
@@ -1227,7 +1144,7 @@ void CMapLoaderH3M::readObjects()
 					res->message = readString();
 					if(readBool())
 					{
-						readCreatureSet(res, 7, map->version > EMapFormat::ROE);
+						readCreatureSet(res, 7);
 					}
 					skip(4);
 				}
@@ -1289,7 +1206,7 @@ void CMapLoaderH3M::readObjects()
 					box->message = readString();
 					if(readBool())
 					{
-						readCreatureSet(box, 7, map->version > EMapFormat::ROE);
+						readCreatureSet(box, 7);
 					}
 					skip(4);
 				}
@@ -1299,11 +1216,7 @@ void CMapLoaderH3M::readObjects()
 				box->moraleDiff = readSI8();
 				box->luckDiff = readSI8();
 
-				box->resources.resize(GameConstants::RESOURCE_QUANTITY);
-				for(int x = 0; x < 7; ++x)
-				{
-					box->resources[x] = readUI32();
-				}
+				readResourses(box->resources);
 
 				box->primskills.resize(GameConstants::PRIMARY_SKILLS);
 				for(int x = 0; x < 4; ++x)
@@ -1335,7 +1248,7 @@ void CMapLoaderH3M::readObjects()
 					box->spells.push_back(readUI8());
 				}
 				int gcre = readUI8(); //number of gained creatures
-				readCreatureSet(&box->creatures, gcre, map->version > EMapFormat::ROE);
+				readCreatureSet(&box->creatures, gcre);
 				skip(8);
 				break;
 			}
@@ -1591,8 +1504,9 @@ void CMapLoaderH3M::readObjects()
 	});
 }
 
-void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number, bool version)
+void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number)
 {
+	const bool version = (map->version > EMapFormat::ROE);
 	const int maxID = version ? 0xffff : 0xff;
 
 	for(int ir = 0; ir < number; ++ir)
@@ -1720,7 +1634,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven)
 	// True if hero has nonstandard garrison
 	if(readBool())
 	{
-		readCreatureSet(nhi, 7, map->version > EMapFormat::ROE);
+		readCreatureSet(nhi, 7);
 	}
 
 	nhi->formation = readUI8();
@@ -1761,20 +1675,8 @@ CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven)
 		if(readBool())
 		{
 			nhi->spells.insert(0xffffffff); //placeholder "preset spells"
-			for(int i = 0; i < 9; ++i)
-			{
-				ui8 c = readUI8();
-				for(int yy = 0; yy < 8; ++yy)
-				{
-					if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
-					{
-						if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-						{
-							nhi->spells.insert(i * 8 + yy);
-						}
-					}
-				}
-			}
+
+			readSpells(nhi->spells);
 		}
 	}
 	else if(map->version == EMapFormat::AB)
@@ -2017,7 +1919,7 @@ CGTownInstance * CMapLoaderH3M::readTown(int castleID)
 	// True if garrison isn't empty
 	if(readBool())
 	{
-		readCreatureSet(nt, 7, map->version > EMapFormat::ROE);
+		readCreatureSet(nt, 7);
 	}
 	nt->formation = readUI8();
 
@@ -2107,6 +2009,9 @@ CGTownInstance * CMapLoaderH3M::readTown(int castleID)
 		nce->town = nt;
 		nce->name = readString();
 		nce->message = readString();
+
+		readResourses(nce->resources);
+
 		for(int x = 0; x < 7; ++x)
 		{
 			nce->resources[x] = readUI32();
@@ -2230,10 +2135,7 @@ void CMapLoaderH3M::readEvents()
 		ne->name = readString();
 		ne->message = readString();
 
-		for(int k = 0; k < 7; ++k)
-		{
-			ne->resources[k] = readUI32();
-		}
+		readResourses(ne->resources);
 		ne->players = readUI8();
 		if(map->version > EMapFormat::AB)
 		{
@@ -2253,6 +2155,52 @@ void CMapLoaderH3M::readEvents()
 	}
 }
 
+void CMapLoaderH3M::readSpells(std::set<TSpell>& dest)
+{
+	for(int byte  = 0; byte < 9; ++byte)
+	{
+		ui8 c = readUI8();
+		for(int bit = 0; bit < 8; ++bit)
+		{
+			if(byte * 8 + bit < GameConstants::SPELLS_QUANTITY)
+			{
+				if(c & (1 << bit))
+				{
+					dest.insert(byte * 8 + bit);
+				}
+			}
+		}
+	}
+}
+
+void CMapLoaderH3M::readResourses(TResources& resources)
+{
+	resources.resize(GameConstants::RESOURCE_QUANTITY); //needed?
+	for(int x = 0; x < 7; ++x)
+	{
+		resources[x] = readUI32();
+	}
+}
+
+
+void CMapLoaderH3M::readBitmask(std::vector<bool>& dest, const int byteCount, const int limit, bool negate)
+{
+	for(int byte = 0; byte < byteCount; ++byte)
+	{
+		const ui8 mask = readUI8();
+		for(int bit = 0; bit < 8; ++bit)
+		{
+			if(byte * 8 + bit < limit)
+			{
+				const bool flag = mask & (1 << bit);
+				if((negate && flag) || (!negate && !flag))
+					dest[byte * 8 + bit] = false;
+			}
+		}
+	}
+}
+
+
 ui8 CMapLoaderH3M::reverse(ui8 arg)
 {
 	ui8 ret = 0;

+ 15 - 4
lib/Mapping/MapFormatH3M.h

@@ -12,6 +12,8 @@
 #pragma once
 
 #include "CMapService.h"
+#include "../GameConstants.h"
+#include "../ResourceSet.h"
 
 #include "../vcmi_endian.h"
 #include "../int3.h"
@@ -159,9 +161,8 @@ private:
 	 *
 	 * @param out the loaded creature set
 	 * @param number the count of creatures to read
-	 * @param version true for > ROE maps
 	 */
-	void readCreatureSet(CCreatureSet * out, int number, bool version);
+	void readCreatureSet(CCreatureSet * out, int number);
 
 	/**
 	 * Reads a hero.
@@ -208,6 +209,18 @@ private:
 	 */
 	void readEvents();
 
+	void readSpells(std::set<TSpell> & dest);
+
+	void readResourses(TResources& resources);
+
+	/** Reads bitmask to boolean vector
+	* @param dest destination vector, shall be filed with "true" values
+	* @param byteCount size in bytes of bimask
+	* @param limit max count of vector elements to alter
+	* @param negate if true then set bit in mask means clear flag in vertor
+	*/
+	void readBitmask(std::vector<bool> & dest, const int byteCount, const int limit, bool negate = true);
+
 	/**
 	 * Reverses the input argument.
 	 *
@@ -216,8 +229,6 @@ private:
 	 */
 	ui8 reverse(ui8 arg);
 
-
-
 	/**
 	* Helper to read ui8 from buffer
 	*/