Jelajahi Sumber

- minor mechanics fixes, corrected handling of 2nd upgrades (like pirates from hota)

Ivan Savenko 13 tahun lalu
induk
melakukan
3fcf8b6f4b
4 mengubah file dengan 18 tambahan dan 11 penghapusan
  1. 8 6
      lib/CGameState.cpp
  2. 2 2
      lib/CObjectHandler.cpp
  3. 3 1
      lib/CObjectHandler.h
  4. 5 2
      server/CGameHandler.cpp

+ 8 - 6
lib/CGameState.cpp

@@ -1683,15 +1683,17 @@ UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack)
 	}
 	if(t)
 	{
-		BOOST_FOREACH(si32 bid, t->builtBuildings)
+		BOOST_FOREACH(const CGTownInstance::TCreaturesSet::value_type & dwelling, t->creatures)
 		{
-			if( bid >= 37   &&   bid < 44 ) //upgraded creature dwelling
+			if (vstd::contains(dwelling.second, base->idNumber)) //Dwelling with our creature
 			{
-				int nid = t->town->upgradedCreatures[bid-37]; //upgrade offered by that building
-				if(vstd::contains(base->upgrades, nid)) //possible upgrade
+				BOOST_FOREACH(ui32 upgrID, dwelling.second)
 				{
-					ret.newID.push_back(nid);
-					ret.cost.push_back(VLC->creh->creatures[nid]->cost - base->cost);
+					if(vstd::contains(base->upgrades, upgrID)) //possible upgrade
+					{
+						ret.newID.push_back(upgrID);
+						ret.cost.push_back(VLC->creh->creatures[upgrID]->cost - base->cost);
+					}
 				}
 			}
 		}

+ 2 - 2
lib/CObjectHandler.cpp

@@ -1873,7 +1873,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
 	if (!vstd::contains(builtBuildings, EBuilding::DWELL_FIRST+level))
 		return ret; //no dwelling
 
-	const CCreature *creature = VLC->creh->creatures[town->basicCreatures[level]];
+	const CCreature *creature = VLC->creh->creatures[creatures[level].second.back()];
 	const int base = creature->growth;
 	int castleBonus = 0;
 
@@ -1896,7 +1896,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
 	if(const PlayerState *p = cb->getPlayer(tempOwner, false))
 	{
 		BOOST_FOREACH(const CGDwelling *dwelling, p->dwellings)
-			if(creature->idNumber == dwelling->creatures[0].second[0])
+			if(vstd::contains(creatures[level].second, dwelling->creatures[0].second[0]))
 				dwellingBonus++;
 	}
 

+ 3 - 1
lib/CObjectHandler.h

@@ -433,8 +433,10 @@ public:
 class DLL_LINKAGE CGDwelling : public CArmedInstance
 {
 public:
+	typedef std::vector<std::pair<ui32, std::vector<ui32> > > TCreaturesSet;
+
 	CSpecObjInfo * info; //h3m info about dewlling
-	std::vector<std::pair<ui32, std::vector<ui32> > > creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
+	TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 5 - 2
server/CGameHandler.cpp

@@ -1020,7 +1020,7 @@ void CGameHandler::newTurn()
 				if(t->creatureDwelling(k))//there is dwelling (k-level)
 				{
 					ui32 &availableCount = sac.creatures[k].first;
-					const CCreature *cre = VLC->creh->creatures[t->creatureDwelling(k, true) ? t->town->upgradedCreatures[k] : t->town->basicCreatures[k]];
+					const CCreature *cre = VLC->creh->creatures[t->creatures[k].second.back()];
 
 					if (n.specialWeek == NewTurn::PLAGUE)
 						availableCount = t->creatures[k].first / 2; //halve their number, no growth
@@ -1031,7 +1031,7 @@ void CGameHandler::newTurn()
 						else
 							availableCount += t->creatureGrowth(k);
 
-						if(n.creatureid == cre->idNumber 
+						if( vstd::contains(t->creatures[k].second, n.creatureid)
 							|| (n.specialWeek == NewTurn::DEITYOFFIRE && (cre->idNumber == 42 || cre->idNumber == 43)))
 						{
 							if(n.specialWeek == NewTurn::DOUBLE_GROWTH)
@@ -2182,6 +2182,9 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ )
 		ssi.tid = tid;
 		ssi.creatures = t->creatures;
 		ssi.creatures[bid-37].second.push_back(t->town->upgradedCreatures[bid-37]);
+		//Test for 2nd upgrade - add sharpshooters if grand elves dwelling was constructed
+		//if (t->subID == 1 && bid == 39)
+		//	ssi.creatures[bid-37].second.push_back(137);
 		sendAndApply(&ssi);
 	}
 	else if(bid >= 30) //bas. dwelling