mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	ArtifactLocation now use ID for artHolder identification part1
This commit is contained in:
		| @@ -9,6 +9,7 @@ | ||||
|  */ | ||||
| #include "StdInc.h" | ||||
|  | ||||
| #include "../../lib/ArtifactUtils.h" | ||||
| #include "../../lib/UnlockGuard.h" | ||||
| #include "../../lib/mapObjects/MapObjects.h" | ||||
| #include "../../lib/mapObjects/ObjectTemplate.h" | ||||
| @@ -1021,7 +1022,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance | ||||
|  | ||||
| 			for(auto location : allArtifacts) | ||||
| 			{ | ||||
| 				if(location.relatedObj() == target && location.slot < ArtifactPosition::AFTER_LAST) | ||||
| 				if(location.relatedObj() == target && ArtifactUtils::isSlotEquipment(location.slot)) | ||||
| 					continue; //don't reequip artifact we already wear | ||||
|  | ||||
| 				if(location.slot == ArtifactPosition::MACH4) // don't attempt to move catapult | ||||
|   | ||||
| @@ -14,6 +14,7 @@ | ||||
| #include "BuildingManager.h" | ||||
| #include "Goals/Goals.h" | ||||
|  | ||||
| #include "../../lib/ArtifactUtils.h" | ||||
| #include "../../lib/UnlockGuard.h" | ||||
| #include "../../lib/mapObjects/MapObjects.h" | ||||
| #include "../../lib/mapObjects/ObjectTemplate.h" | ||||
| @@ -1195,7 +1196,7 @@ void VCAI::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance * ot | ||||
| 				if(location.slot == ArtifactPosition::MACH4 || location.slot == ArtifactPosition::SPELLBOOK) | ||||
| 					continue; // don't attempt to move catapult and spellbook | ||||
|  | ||||
| 				if(location.relatedObj() == target && location.slot < ArtifactPosition::AFTER_LAST) | ||||
| 				if(location.relatedObj() == target && ArtifactUtils::isSlotEquipment(location.slot)) | ||||
| 					continue; //don't reequip artifact we already wear | ||||
|  | ||||
| 				auto s = location.getSlot(); | ||||
|   | ||||
| @@ -334,7 +334,7 @@ void CHeroWindow::commanderWindow() | ||||
| 	if(pickedArtInst) | ||||
| 	{ | ||||
| 		const auto freeSlot = ArtifactUtils::getArtAnyPosition(curHero->commander, pickedArtInst->getTypeId()); | ||||
| 		if(freeSlot < ArtifactPosition::COMMANDER_AFTER_LAST) //we don't want to put it in commander's backpack! | ||||
| 		if(vstd::contains(ArtifactUtils::commanderSlots(), freeSlot)) // We don't want to put it in commander's backpack! | ||||
| 		{ | ||||
| 			ArtifactLocation src(hero, ArtifactPosition::TRANSITION_POS); | ||||
| 			ArtifactLocation dst(curHero->commander.get(), freeSlot); | ||||
|   | ||||
| @@ -74,6 +74,49 @@ DLL_LINKAGE const std::vector<ArtifactPosition> & ArtifactUtils::constituentWorn | ||||
| 	return positions; | ||||
| } | ||||
|  | ||||
| DLL_LINKAGE const std::vector<ArtifactPosition> & ArtifactUtils::allWornSlots() | ||||
| { | ||||
| 	static const std::vector<ArtifactPosition> positions = | ||||
| 	{ | ||||
| 		ArtifactPosition::HEAD, | ||||
| 		ArtifactPosition::SHOULDERS, | ||||
| 		ArtifactPosition::NECK, | ||||
| 		ArtifactPosition::RIGHT_HAND, | ||||
| 		ArtifactPosition::LEFT_HAND, | ||||
| 		ArtifactPosition::TORSO, | ||||
| 		ArtifactPosition::RIGHT_RING, | ||||
| 		ArtifactPosition::LEFT_RING, | ||||
| 		ArtifactPosition::FEET, | ||||
| 		ArtifactPosition::MISC1, | ||||
| 		ArtifactPosition::MISC2, | ||||
| 		ArtifactPosition::MISC3, | ||||
| 		ArtifactPosition::MISC4, | ||||
| 		ArtifactPosition::MISC5, | ||||
| 		ArtifactPosition::MACH1, | ||||
| 		ArtifactPosition::MACH2, | ||||
| 		ArtifactPosition::MACH3, | ||||
| 		ArtifactPosition::MACH4, | ||||
| 		ArtifactPosition::SPELLBOOK | ||||
| 	}; | ||||
|  | ||||
| 	return positions; | ||||
| } | ||||
|  | ||||
| DLL_LINKAGE const std::vector<ArtifactPosition> & ArtifactUtils::commanderSlots() | ||||
| { | ||||
| 	static const std::vector<ArtifactPosition> positions = | ||||
| 	{ | ||||
| 		ArtifactPosition::COMMANDER1, | ||||
| 		ArtifactPosition::COMMANDER2, | ||||
| 		ArtifactPosition::COMMANDER3, | ||||
| 		ArtifactPosition::COMMANDER4, | ||||
| 		ArtifactPosition::COMMANDER5, | ||||
| 		ArtifactPosition::COMMANDER6 | ||||
| 	}; | ||||
|  | ||||
| 	return positions; | ||||
| } | ||||
|  | ||||
| DLL_LINKAGE bool ArtifactUtils::isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot) | ||||
| { | ||||
| 	return slot.second.artifact | ||||
|   | ||||
| @@ -31,6 +31,8 @@ namespace ArtifactUtils | ||||
| 	// TODO: Make this constexpr when the toolset is upgraded | ||||
| 	DLL_LINKAGE const std::vector<ArtifactPosition> & unmovableSlots(); | ||||
| 	DLL_LINKAGE const std::vector<ArtifactPosition> & constituentWornSlots(); | ||||
| 	DLL_LINKAGE const std::vector<ArtifactPosition> & allWornSlots(); | ||||
| 	DLL_LINKAGE const std::vector<ArtifactPosition> & commanderSlots(); | ||||
| 	DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot); | ||||
| 	DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, const ArtifactID & artID, const ArtifactPosition & slot); | ||||
| 	DLL_LINKAGE bool isSlotBackpack(const ArtifactPosition & slot); | ||||
|   | ||||
| @@ -693,8 +693,8 @@ void CArtHandler::makeItCommanderArt(CArtifact * a, bool onlyCommander) | ||||
| 		a->possibleSlots[ArtBearer::HERO].clear(); | ||||
| 		a->possibleSlots[ArtBearer::CREATURE].clear(); | ||||
| 	} | ||||
| 	for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i) | ||||
| 		a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(i)); | ||||
| 	for(auto & slot : ArtifactUtils::commanderSlots()) | ||||
| 		a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(slot)); | ||||
| } | ||||
|  | ||||
| bool CArtHandler::legalArtifact(const ArtifactID & id) | ||||
| @@ -975,9 +975,9 @@ const ArtSlotInfo * CArtifactSet::getSlot(const ArtifactPosition & pos) const | ||||
| 	} | ||||
| 	if(vstd::contains(artifactsWorn, pos)) | ||||
| 		return &artifactsWorn.at(pos); | ||||
| 	if(pos >= ArtifactPosition::AFTER_LAST ) | ||||
| 	if(ArtifactUtils::isSlotBackpack(pos)) | ||||
| 	{ | ||||
| 		int backpackPos = (int)pos - ArtifactPosition::BACKPACK_START; | ||||
| 		auto backpackPos = pos - ArtifactPosition::BACKPACK_START; | ||||
| 		if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size()) | ||||
| 			return nullptr; | ||||
| 		else | ||||
| @@ -1080,9 +1080,9 @@ void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const s | ||||
|  | ||||
| void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map) | ||||
| { | ||||
| 	for(ArtifactPosition ap = ArtifactPosition::HEAD; ap < ArtifactPosition::AFTER_LAST; ap.advance(1)) | ||||
| 	for(auto & slot : ArtifactUtils::allWornSlots()) | ||||
| 	{ | ||||
| 		serializeJsonSlot(handler, ap, map); | ||||
| 		serializeJsonSlot(handler, slot, map); | ||||
| 	} | ||||
|  | ||||
| 	std::vector<ArtifactID> backpackTemp; | ||||
|   | ||||
| @@ -607,20 +607,23 @@ public: | ||||
| 		TRANSITION_POS = -3, | ||||
| 		FIRST_AVAILABLE = -2, | ||||
| 		PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack | ||||
| 		 | ||||
| 		// Hero | ||||
| 		HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5 | ||||
| 		RIGHT_RING, LEFT_RING, FEET, //8 | ||||
| 		MISC1, MISC2, MISC3, MISC4, //12 | ||||
| 		MACH1, MACH2, MACH3, MACH4, //16 | ||||
| 		SPELLBOOK, MISC5, //18 | ||||
| 		AFTER_LAST, | ||||
| 		//cres | ||||
| 		BACKPACK_START = 19, | ||||
| 		 | ||||
| 		// Creatures | ||||
| 		CREATURE_SLOT = 0, | ||||
| 		COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6, COMMANDER_AFTER_LAST, | ||||
|  | ||||
| 		BACKPACK_START = 19 | ||||
| 		 | ||||
| 		// Commander | ||||
| 		COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6 | ||||
| 	}; | ||||
|  | ||||
| 	static_assert (AFTER_LAST == BACKPACK_START, "incorrect number of artifact slots"); | ||||
| 	static_assert(MISC5 < BACKPACK_START, "incorrect number of artifact slots"); | ||||
|  | ||||
| 	DLL_LINKAGE static si32 decode(const std::string & identifier); | ||||
| 	DLL_LINKAGE static std::string encode(const si32 index); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user