Răsfoiți Sursa

* fixed 1085
* fixed starting hero is granted in normal scenarios
* introduced TArtifactInstanceID

mateuszb 13 ani în urmă
părinte
comite
f3f4a7633d

+ 4 - 4
lib/CArtHandler.cpp

@@ -448,7 +448,7 @@ void CArtHandler::sortArts()
  	//	}
  	//}
 }
-void CArtHandler::erasePickedArt (TArtifactID id)
+void CArtHandler::erasePickedArt( TArtifactInstanceID id )
 {
 	std::vector<CArtifact*>* ptr;
 	CArtifact *art = artifacts[id];
@@ -566,7 +566,7 @@ void CArtHandler::giveArtBonus(TArtifactID aid, Bonus *bonus)
 	artifacts[aid]->addNewBonus(bonus);
 }
 
-void CArtHandler::makeItCreatureArt (TArtifactID aid, bool onlyCreature /*=true*/)
+void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/)
 {
 	CArtifact *a = artifacts[aid];
 	if (onlyCreature)
@@ -577,7 +577,7 @@ void CArtHandler::makeItCreatureArt (TArtifactID aid, bool onlyCreature /*=true*
 	a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
 }
 
-void CArtHandler::makeItCommanderArt (TArtifactID aid, bool onlyCommander /*=true*/)
+void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ )
 {
 	CArtifact *a = artifacts[aid];
 	if (onlyCommander)
@@ -1456,7 +1456,7 @@ si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
 	return -1;
 }
 
-const CArtifactInstance * CArtifactSet::getArtByInstanceId( TArtifactID artInstId ) const
+const CArtifactInstance * CArtifactSet::getArtByInstanceId( TArtifactInstanceID artInstId ) const
 {
 	for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
 		if(i->second.artifact->id == artInstId)

+ 17 - 8
lib/CArtHandler.h

@@ -34,11 +34,20 @@ namespace ArtifactPosition
 	};
 }
 
-namespace ArtifactPos
+namespace ArtifactID
 {
-	enum ArtifactPos
+	enum ArtifactID
 	{
-		SPELLBOOK = 17
+		SPELLBOOK = 0,
+		SPELL_SCROLL = 1,
+		GRAIL = 2,
+		CATAPULT = 3,
+		BALLISTA = 4,
+		AMMO_CART = 5,
+		FIRST_AID_TENT = 6,
+		CENTAUR_AXE = 7,
+		BLACKSHARD_OF_THE_DEAD_KNIGHT = 8,
+		CORNUCOPIA = 140
 	};
 }
 
@@ -110,7 +119,7 @@ public:
 	CArtifactInstance();
 
 	ConstTransitivePtr<CArtifact> artType; 
-	TArtifactID id; //id of the instance
+	TArtifactInstanceID id;
 
 	//CArtifactInstance(int aid);
 
@@ -208,14 +217,14 @@ public:
 	ui16 getArtSync (ui32 rand, int flags);
 	void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag);
 	void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
-	void erasePickedArt (TArtifactID id);
+	void erasePickedArt (TArtifactInstanceID id);
 	bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
 // 	void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const;
 // 	void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const;
 	void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
 	static int convertMachineID(int id, bool creToArt);
-	void makeItCreatureArt (TArtifactID aid, bool onlyCreature = true);
-	void makeItCommanderArt (TArtifactID aid, bool onlyCommander = true);
+	void makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature = true);
+	void makeItCommanderArt (TArtifactInstanceID aid, bool onlyCommander = true);
 	CArtHandler();
 	~CArtHandler();
 
@@ -257,7 +266,7 @@ public:
 	CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true); //NULL - no artifact
 	si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
 	si32 getArtPos(const CArtifactInstance *art) const;
-	const CArtifactInstance *getArtByInstanceId(TArtifactID artInstId) const;
+	const CArtifactInstance *getArtByInstanceId(TArtifactInstanceID artInstId) const;
 	bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
 	bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const;
 	si32 getArtTypeId(ui16 pos) const;

+ 26 - 23
lib/CGameState.cpp

@@ -980,34 +980,37 @@ void CGameState::init(StartInfo * si)
 	/*********give starting hero****************************************/
 	tlog4 << "\tGiving starting hero";
 	{
+		bool campaignGiveHero = false;
 		if(scenarioOps->campState)
 		{
 			auto bonus = scenarioOps->campState->getBonusForCurrentMap();
 			if(bonus.is_initialized())
 			{
-				for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end(); ++it)
-				{
-					const PlayerInfo &p = map->players[it->first];
-					bool campaignGiveHero = it->second.human && scenarioOps->mode == StartInfo::CAMPAIGN &&
-						bonus.get().type == CScenarioTravel::STravelBonus::HERO;
-					bool generateHero = (p.generateHeroAtMainTown || campaignGiveHero) && p.hasMainTown;
-					if(generateHero && vstd::contains(scenarioOps->playerInfos, it->first))
-					{
-						int3 hpos = p.posOfMainTown;
-						hpos.x+=1;
-
-						int h = pickHero(it->first);
-						if(it->second.hero == -1)
-							it->second.hero = h;
-
-						CGHeroInstance * nnn =  static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,it->first));
-						nnn->id = map->objects.size();
-						nnn->initHero();
-						map->heroes.push_back(nnn);
-						map->objects.push_back(nnn);
-						map->addBlockVisTiles(nnn);
-					}
-				}
+				campaignGiveHero =  scenarioOps->mode == StartInfo::CAMPAIGN &&
+					bonus.get().type == CScenarioTravel::STravelBonus::HERO;
+			}
+		}
+
+
+		for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end(); ++it)
+		{
+			const PlayerInfo &p = map->players[it->first];
+			bool generateHero = (p.generateHeroAtMainTown || (it->second.human && campaignGiveHero)) && p.hasMainTown;
+			if(generateHero && vstd::contains(scenarioOps->playerInfos, it->first))
+			{
+				int3 hpos = p.posOfMainTown;
+				hpos.x+=1;
+
+				int h = pickHero(it->first);
+				if(it->second.hero == -1)
+					it->second.hero = h;
+
+				CGHeroInstance * nnn =  static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,it->first));
+				nnn->id = map->objects.size();
+				nnn->initHero();
+				map->heroes.push_back(nnn);
+				map->objects.push_back(nnn);
+				map->addBlockVisTiles(nnn);
 			}
 		}
 	}

+ 1 - 1
lib/CObjectHandler.cpp

@@ -5438,7 +5438,7 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const
 	iw.text.addTxt(MetaString::SPELL_NAME,spell);
 	iw.text << ".";
 
-	if(!h->getArt(ArtifactPos::SPELLBOOK))
+	if(!h->getArt(ArtifactPosition::SPELLBOOK))
 	{
 		iw.text.addTxt(MetaString::ADVOB_TXT,131);
 	}

+ 2 - 1
lib/GameConstants.h

@@ -405,5 +405,6 @@ typedef si32 TBonusSubtype;
 typedef si32 TSlot;
 typedef si32 TQuantity;
 typedef si32 TArtifactID;
+typedef si32 TArtifactInstanceID;
 typedef ui32 TCreature; //creature id
-typedef si8 TPlayerColor;
+typedef ui8 TPlayerColor;

+ 1 - 1
lib/NetPacks.h

@@ -1323,7 +1323,7 @@ struct BattleResult : public CPackForClient//3003
 	ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
 	std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
 	TExpType exp[2]; //exp for attacker and defender
-	std::set<TArtifactID> artifacts; //artifacts taken from loser to winner - currently unused
+	std::set<TArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 1 - 1
server/CGameHandler.cpp

@@ -2967,7 +2967,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, int ri
 	return true;
 }
 
-bool CGameHandler::sellArtifact(const IMarket *m, const CGHeroInstance *h, TArtifactID aid, int rid)
+bool CGameHandler::sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactInstanceID aid, TResource rid )
 {
 	const CArtifactInstance *art = h->getArtByInstanceId(aid);
 	if(!art)

+ 1 - 1
server/CGameHandler.h

@@ -216,7 +216,7 @@ public:
 	bool assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assemble, ui32 assembleTo);
 	bool buyArtifact( ui32 hid, TArtifactID aid ); //for blacksmith and mage guild only -> buying for gold in common buildings
 	bool buyArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactID rid, TArtifactID aid); //for artifact merchant and black market -> buying for any resource in special building / advobject
-	bool sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactID aid, TArtifactID rid); //for artifact merchant selling
+	bool sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactInstanceID aid, TResource rid); //for artifact merchant selling
 	//void lootArtifacts (TArtHolder source, TArtHolder dest, std::vector<ui32> &arts); //after battle - move al arts to winer
 	bool buySecSkill( const IMarket *m, const CGHeroInstance *h, int skill);
 	bool garrisonSwap(si32 tid);