mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Replace static_cast's of Identifiers with getNum call
This commit is contained in:
		| @@ -209,7 +209,7 @@ CHeroClass::CHeroClass(): | ||||
|  | ||||
| void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill pSkill) const | ||||
| { | ||||
| 	const auto & skillName = NPrimarySkill::names[static_cast<int>(pSkill)]; | ||||
| 	const auto & skillName = NPrimarySkill::names[pSkill.getNum()]; | ||||
| 	auto currentPrimarySkillValue = static_cast<int>(node["primarySkills"][skillName].Integer()); | ||||
| 	//minimal value is 0 for attack and defense and 1 for spell power and knowledge | ||||
| 	auto primarySkillLegalMinimum = (pSkill == PrimarySkill::ATTACK || pSkill == PrimarySkill::DEFENSE) ? 0 : 1; | ||||
|   | ||||
| @@ -113,7 +113,7 @@ namespace JsonRandom | ||||
| 		if (value.empty() || value[0] != '@') | ||||
| 			return PrimarySkill(*VLC->identifiers()->getIdentifier(modScope, "primarySkill", value)); | ||||
| 		else | ||||
| 			return PrimarySkill(loadVariable("primarySkill", value, variables, static_cast<int>(PrimarySkill::NONE))); | ||||
| 			return PrimarySkill(loadVariable("primarySkill", value, variables, PrimarySkill::NONE.getNum())); | ||||
| 	} | ||||
|  | ||||
| 	/// Method that allows type-specific object filtering | ||||
| @@ -322,7 +322,7 @@ namespace JsonRandom | ||||
| 			for(const auto & pair : value.Struct()) | ||||
| 			{ | ||||
| 				PrimarySkill id = decodeKey<PrimarySkill>(pair.second.meta, pair.first, variables); | ||||
| 				ret[static_cast<int>(id)] += loadValue(pair.second, rng, variables); | ||||
| 				ret[id.getNum()] += loadValue(pair.second, rng, variables); | ||||
| 			} | ||||
| 		} | ||||
| 		if(value.isVector()) | ||||
| @@ -333,7 +333,7 @@ namespace JsonRandom | ||||
| 				PrimarySkill skillID = *RandomGeneratorUtil::nextItem(potentialPicks, rng); | ||||
|  | ||||
| 				defaultSkills.erase(skillID); | ||||
| 				ret[static_cast<int>(skillID)] += loadValue(element, rng, variables); | ||||
| 				ret[skillID.getNum()] += loadValue(element, rng, variables); | ||||
| 			} | ||||
| 		} | ||||
| 		return ret; | ||||
|   | ||||
| @@ -1155,7 +1155,7 @@ std::pair<const battle::Unit *, BattleHex> CBattleInfoCallback::getNearestStack( | ||||
|  | ||||
| BattleHex CBattleInfoCallback::getAvaliableHex(const CreatureID & creID, ui8 side, int initialPos) const | ||||
| { | ||||
| 	bool twoHex = VLC->creh->objects[creID]->isDoubleWide(); | ||||
| 	bool twoHex = VLC->creatures()->getById(creID)->isDoubleWide(); | ||||
|  | ||||
| 	int pos; | ||||
| 	if (initialPos > -1) | ||||
|   | ||||
| @@ -317,7 +317,7 @@ ILimiter::EDecision FactionLimiter::limit(const BonusLimitationContext &context) | ||||
| std::string FactionLimiter::toString() const | ||||
| { | ||||
| 	boost::format fmt("FactionLimiter(faction=%s)"); | ||||
| 	fmt % VLC->factions()->getByIndex(faction)->getJsonKey(); | ||||
| 	fmt % VLC->factions()->getById(faction)->getJsonKey(); | ||||
| 	return fmt.str(); | ||||
| } | ||||
|  | ||||
| @@ -326,7 +326,7 @@ JsonNode FactionLimiter::toJsonNode() const | ||||
| 	JsonNode root(JsonNode::JsonType::DATA_STRUCT); | ||||
|  | ||||
| 	root["type"].String() = "FACTION_LIMITER"; | ||||
| 	root["parameters"].Vector().push_back(JsonUtils::stringNode(VLC->factions()->getByIndex(faction)->getJsonKey())); | ||||
| 	root["parameters"].Vector().push_back(JsonUtils::stringNode(VLC->factions()->getById(faction)->getJsonKey())); | ||||
|  | ||||
| 	return root; | ||||
| } | ||||
|   | ||||
| @@ -73,13 +73,13 @@ ImagePath CampaignRegions::getBackgroundName() const | ||||
|  | ||||
| Point CampaignRegions::getPosition(CampaignScenarioID which) const | ||||
| { | ||||
| 	auto const & region = regions[static_cast<int>(which)]; | ||||
| 	auto const & region = regions[which.getNum()]; | ||||
| 	return Point(region.xpos, region.ypos); | ||||
| } | ||||
|  | ||||
| ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, std::string type) const | ||||
| { | ||||
| 	auto const & region = regions[static_cast<int>(which)]; | ||||
| 	auto const & region = regions[which.getNum()]; | ||||
|  | ||||
| 	static const std::string colors[2][8] = | ||||
| 	{ | ||||
| @@ -267,7 +267,7 @@ void CampaignState::setCurrentMapAsConquered(std::vector<CGHeroInstance *> heroe | ||||
| 		return a->getHeroStrength() > b->getHeroStrength(); | ||||
| 	}); | ||||
|  | ||||
| 	logGlobal->info("Scenario %d of campaign %s (%s) has been completed", static_cast<int>(*currentMap), getFilename(), getNameTranslated()); | ||||
| 	logGlobal->info("Scenario %d of campaign %s (%s) has been completed", currentMap->getNum(), getFilename(), getNameTranslated()); | ||||
|  | ||||
| 	mapsConquered.push_back(*currentMap); | ||||
| 	auto reservedHeroes = getReservedHeroes(); | ||||
| @@ -320,7 +320,7 @@ std::unique_ptr<CMap> CampaignState::getMap(CampaignScenarioID scenarioId) const | ||||
| 	CMapService mapService; | ||||
| 	std::string scenarioName = getFilename().substr(0, getFilename().find('.')); | ||||
| 	boost::to_lower(scenarioName); | ||||
| 	scenarioName += ':' + std::to_string(static_cast<int>(scenarioId)); | ||||
| 	scenarioName += ':' + std::to_string(scenarioId.getNum()); | ||||
| 	const auto & mapContent = mapPieces.find(scenarioId)->second; | ||||
| 	return mapService.loadMap(mapContent.data(), mapContent.size(), scenarioName, getModName(), getEncoding()); | ||||
| } | ||||
| @@ -333,7 +333,7 @@ std::unique_ptr<CMapHeader> CampaignState::getMapHeader(CampaignScenarioID scena | ||||
| 	CMapService mapService; | ||||
| 	std::string scenarioName = getFilename().substr(0, getFilename().find('.')); | ||||
| 	boost::to_lower(scenarioName); | ||||
| 	scenarioName += ':' + std::to_string(static_cast<int>(scenarioId)); | ||||
| 	scenarioName += ':' + std::to_string(scenarioId.getNum()); | ||||
| 	const auto & mapContent = mapPieces.find(scenarioId)->second; | ||||
| 	return mapService.loadMapHeader(mapContent.data(), mapContent.size(), scenarioName, getModName(), getEncoding()); | ||||
| } | ||||
|   | ||||
| @@ -369,7 +369,7 @@ si32 FactionID::decode(const std::string & identifier) | ||||
| 	if(rawId) | ||||
| 		return rawId.value(); | ||||
| 	else | ||||
| 		return FactionID::DEFAULT; | ||||
| 		return FactionID::DEFAULT.getNum(); | ||||
| } | ||||
|  | ||||
| std::string FactionID::encode(const si32 index) | ||||
|   | ||||
| @@ -52,11 +52,6 @@ public: | ||||
| 		num += change; | ||||
| 	} | ||||
|  | ||||
| 	constexpr operator int32_t () const | ||||
| 	{ | ||||
| 		return num; | ||||
| 	} | ||||
|  | ||||
| 	friend std::ostream& operator<<(std::ostream& os, const IdentifierBase& dt) | ||||
| 	{ | ||||
| 		return os << dt.num; | ||||
|   | ||||
| @@ -90,7 +90,7 @@ void CGameStateCampaign::trimCrossoverHeroesParameters(std::vector<CampaignHeroR | ||||
| 					.And(Selector::subtype()(BonusSubtypeID(g))) | ||||
| 					.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL)); | ||||
|  | ||||
| 				cgh->getBonusLocalFirst(sel)->val = cgh->type->heroClass->primarySkillInitial[g]; | ||||
| 				cgh->getBonusLocalFirst(sel)->val = cgh->type->heroClass->primarySkillInitial[g.getNum()]; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -375,7 +375,7 @@ std::vector<CampaignHeroReplacement> CGameStateCampaign::generateCampaignHeroesT | ||||
| 		auto * heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get()); | ||||
|  | ||||
| 		// only 1 field must be set | ||||
| 		assert(heroPlaceholder->powerRank != heroPlaceholder->heroType); | ||||
| 		assert(heroPlaceholder->powerRank.has_value() != heroPlaceholder->heroType.has_value()); | ||||
|  | ||||
| 		if(heroPlaceholder->powerRank) | ||||
| 			placeholdersByPower.push_back(heroPlaceholder); | ||||
| @@ -498,7 +498,7 @@ void CGameStateCampaign::initStartingResources() | ||||
| 		std::vector<const PlayerSettings *> people = getHumanPlayerInfo(); //players we will give resource bonus | ||||
| 		for(const PlayerSettings *ps : people) | ||||
| 		{ | ||||
| 			std::vector<int> res; //resources we will give | ||||
| 			std::vector<GameResID> res; //resources we will give | ||||
| 			switch (chosenBonus->info1) | ||||
| 			{ | ||||
| 				case 0: case 1: case 2: case 3: case 4: case 5: case 6: | ||||
|   | ||||
| @@ -92,7 +92,7 @@ void CArmedInstance::updateMoraleBonusFromArmy() | ||||
|  | ||||
| 		for(auto f : factions) | ||||
| 		{ | ||||
| 			if (VLC->factions()->getByIndex(f)->getAlignment() != EAlignment::EVIL) | ||||
| 			if (VLC->factions()->getById(f)->getAlignment() != EAlignment::EVIL) | ||||
| 				mixableFactions++; | ||||
| 		} | ||||
| 		if (mixableFactions > 0) | ||||
|   | ||||
| @@ -71,16 +71,8 @@ void CMapEvent::serializeJson(JsonSerializeFormat & handler) | ||||
| void CCastleEvent::serializeJson(JsonSerializeFormat & handler) | ||||
| { | ||||
| 	CMapEvent::serializeJson(handler); | ||||
| 	{ | ||||
| 		std::vector<BuildingID> temp(buildings.begin(), buildings.end()); | ||||
| 		auto a = handler.enterArray("buildings"); | ||||
| 		a.syncSize(temp); | ||||
| 		for(int i = 0; i < temp.size(); ++i) | ||||
| 		{ | ||||
| 			a.serializeInt(i, temp[i]); | ||||
| 			buildings.insert(temp[i]); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	handler.serializeIdArray("buildings", buildings); | ||||
| 	{ | ||||
| 		auto a = handler.enterArray("creatures"); | ||||
| 		a.syncSize(creatures); | ||||
| @@ -393,7 +385,7 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type | ||||
| 	// There is weird bug because of which sometimes heroes will not be found properly despite having correct position | ||||
| 	// Try to workaround that and find closest object that we can use | ||||
|  | ||||
| 	logGlobal->error("Failed to find object of type %d at %s", static_cast<int>(type), pos.toString()); | ||||
| 	logGlobal->error("Failed to find object of type %d at %s", type.getNum(), pos.toString()); | ||||
| 	logGlobal->error("Will try to find closest matching object"); | ||||
|  | ||||
| 	CGObjectInstance * bestMatch = nullptr; | ||||
|   | ||||
| @@ -2113,7 +2113,7 @@ void BattleStart::applyGs(CGameState * gs) const | ||||
| 	info->battleID = gs->nextBattleID; | ||||
| 	info->localInit(); | ||||
|  | ||||
| 	gs->nextBattleID = vstd::next(gs->nextBattleID, 1); | ||||
| 	gs->nextBattleID = BattleID(gs->nextBattleID.getNum() + 1); | ||||
| } | ||||
|  | ||||
| void BattleNextRound::applyGs(CGameState * gs) const | ||||
|   | ||||
| @@ -197,7 +197,7 @@ struct DLL_LINKAGE CPathsInfo | ||||
| 	STRONG_INLINE | ||||
| 	CGPathNode * getNode(const int3 & coord, const ELayer layer) | ||||
| 	{ | ||||
| 		return &nodes[layer][coord.z][coord.x][coord.y]; | ||||
| 		return &nodes[layer.getNum()][coord.z][coord.x][coord.y]; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -234,7 +234,7 @@ void Rewardable::Info::configureVariables(Rewardable::Configuration & object, CR | ||||
| 				value = JsonRandom::loadSpell(input, rng, object.variables.values).getNum(); | ||||
|  | ||||
| 			if (category.first == "primarySkill") | ||||
| 				value = static_cast<int>(JsonRandom::loadPrimary(input, rng, object.variables.values)); | ||||
| 				value = JsonRandom::loadPrimary(input, rng, object.variables.values).getNum(); | ||||
|  | ||||
| 			if (category.first == "secondarySkill") | ||||
| 				value = JsonRandom::loadSecondary(input, rng, object.variables.values).getNum(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user