Browse Source

* correctly calculated growths (including castles and horde structures)
* giving daily income

Michał W. Urbańczyk 17 years ago
parent
commit
fb5c26437c
5 changed files with 49 additions and 12 deletions
  1. 4 8
      CCallback.cpp
  2. 18 0
      config/building_horde.txt
  3. 17 4
      hch/CObjectHandler.cpp
  4. 9 0
      hch/CTownHandler.cpp
  5. 1 0
      hch/CTownHandler.h

+ 4 - 8
CCallback.cpp

@@ -61,16 +61,12 @@ void CCallback::newTurn()
 			{
 				for(int k=0;k<CREATURES_PER_TOWN;k++)
 				{
-					int growth;
-					if(i->second.towns[j]->creatureDwelling(k))//basic growth
-						  growth=CGI->creh->creatures[i->second.towns[j]->town->basicCreatures[k]].growth;
-					if(i->second.towns[j]->builtBuildings.find(9)!=i->second.towns[j]->builtBuildings.end()) //castle +100%
-						growth*=2;
-					else if(i->second.towns[j]->builtBuildings.find(9)!=i->second.towns[j]->builtBuildings.end()) //castle +100%
-						growth*=1.5;
-					i->second.towns[j]->strInfo.creatures[k]+=growth;
+					if(i->second.towns[j]->creatureDwelling(k))//there is dwelling
+						i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k);
 				}
 			}
+			if((gs->day>1) && i->first<PLAYER_LIMIT)
+				i->second.resources[6]+=i->second.towns[j]->dailyIncome();
 		}
 	}
 }

+ 18 - 0
config/building_horde.txt

@@ -0,0 +1,18 @@
+0	1	2
+0	2	-1
+1	1	1
+1	2	4
+2	1	1
+2	2	-1
+3	1	0
+3	2	2
+4	1	0
+4	2	-1
+5	1	0
+5	2	-1
+6	1	0
+6	2	-1
+7	1	0
+7	2	-1
+8	1	0
+8	2	-1

+ 17 - 4
hch/CObjectHandler.cpp

@@ -9,6 +9,7 @@
 #include "../CLua.h"
 #include "CHeroHandler.h"
 #include <boost/algorithm/string/replace.hpp>
+#include "CTownHandler.h"
 void CObjectHandler::loadObjects()
 {
 	int ID=0;
@@ -272,13 +273,25 @@ bool CGTownInstance::creatureDwelling(int level, bool upgraded) const
 }
 int CGTownInstance::getHordeLevel(int HID)  const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present
 {
-	//TODO: write
-	return -1;
+	return town->hordeLvl[HID];
 }
 int CGTownInstance::creatureGrowth(int level) const
 {
-	//TODO: write 
-	return -1;
+	int ret = CGI->creh->creatures[town->basicCreatures[level]].growth;
+	switch(fortLevel())
+	{
+	case 3:
+		ret*=2;break;
+	case 2:
+		ret*=(1.5); break;
+	}
+	if(getHordeLevel(0)==level)
+		if((builtBuildings.find(18)!=builtBuildings.end()) || (builtBuildings.find(19)!=builtBuildings.end()))
+			ret+=CGI->creh->creatures[town->basicCreatures[level]].hordeGrowth;
+	if(getHordeLevel(1)==level)
+		if((builtBuildings.find(24)!=builtBuildings.end()) || (builtBuildings.find(25)!=builtBuildings.end()))
+			ret+=CGI->creh->creatures[town->basicCreatures[level]].hordeGrowth;
+	return ret;
 }
 int CGTownInstance::dailyIncome() const
 {

+ 9 - 0
hch/CTownHandler.cpp

@@ -240,6 +240,15 @@ void CTownHandler::loadNames()
 		of.close();
 		of.clear();
 
+		of.open("config/building_horde.txt");
+		while(!of.eof())
+		{
+			int tid, lid, cid; //town,horde serial,creature level
+			of >> tid >> lid >> cid;
+			towns[tid].hordeLvl[--lid] = cid;
+		}
+		of.close();
+		of.clear();
 		
 		of.open("config/requirements.txt");
 		while(!of.eof())

+ 1 - 0
hch/CTownHandler.h

@@ -19,6 +19,7 @@ public:
 	std::vector<std::string> names; //names of the town instances
 	std::vector<int> basicCreatures; //level (from 0) -> ID
 	std::vector<int> upgradedCreatures; //level (from 0) -> ID
+	std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
 	int bonus; //pic number
 	int typeID;
 };