فهرست منبع

Partial parsing for CREXPBON.txt table - only basic bonuses are supported

Bonuses will be stored in Creature node and used when Bonus System is ready.
DjWarmonger 14 سال پیش
والد
کامیت
a84a95f0ee
4فایلهای تغییر یافته به همراه82 افزوده شده و 4 حذف شده
  1. 2 1
      global.h
  2. 75 0
      hch/CCreatureHandler.cpp
  3. 2 1
      hch/CCreatureHandler.h
  4. 3 2
      lib/HeroBonus.h

+ 2 - 1
global.h

@@ -105,11 +105,12 @@ const int NAMES_PER_TOWN=16;
 const int CREATURES_PER_TOWN = 7; //without upgrades
 const int MAX_BUILDING_PER_TURN = 1;
 const int SPELL_LEVELS = 5;
-//const int CREEP_SIZE = 4000; // neutral stacks won't grow beyon this number
+//const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number
 const int CREEP_SIZE = 2000000000;
 const int WEEKLY_GROWTH = 10; //percent
 const int AVAILABLE_HEROES_PER_PLAYER = 2;
 const bool DWELLINGS_ACCUMULATE_CREATURES = true;
+const bool STACK_EXP = true;
 
 const int BFIELD_WIDTH = 17;
 const int BFIELD_HEIGHT = 11;

+ 75 - 0
hch/CCreatureHandler.cpp

@@ -600,6 +600,47 @@ void CCreatureHandler::loadCreatures()
 		}
 	}
 	ifs.close();
+
+	if (STACK_EXP) 	//reading default stack experience bonuses
+	{
+		buf = bitmaph->getTextFile("CREXPBON.TXT");
+		int it = 0, creid;
+		commonBonuses.resize(8); //8 tiers
+		stackExperience b;
+		b.expBonuses.resize(10);
+		b.source = Bonus::STACK_EXPERIENCE;
+
+		loadToIt (dump2, buf, it, 3); //ignore first line
+		loadToIt (dump2, buf, it, 4); //ignore index
+		loadStackExp(b, buf, it);
+		loadToIt (dump2, buf, it, 4); //crop comment
+		for (i = 0; i < 8; ++i)
+		{
+			commonBonuses[i].push_back(b);//health bonus common for all
+			for (int j = 0; j < 4; ++j) //four modifiers common for tiers
+			{
+				loadToIt (dump2, buf, it, 4); //ignore index
+				loadStackExp(b, buf, it);
+				commonBonuses[i].push_back(b);
+				loadToIt (dump2, buf, it, 3); //crop comment
+			}
+		}
+		do //parse everything that's left
+		{
+			loadToIt(creid, buf, it, 4); //get index
+			loadStackExp(b, buf, it);
+			creatures[creid]->bonuses.push_back(b); //experience list is common for creatures of that type
+			loadToIt (dump2, buf, it, 3); //crop comment
+		}
+		while (it < buf.size());
+		for (std::vector<CCreature*>::iterator i = creatures.begin(); i != creatures.end(); i++)
+		{
+			if (it = (*i)->level < 7)
+				std::copy(commonBonuses[it-1].begin(), commonBonuses[it-1].end(), (*i)->bonuses.begin());
+			else
+				std::copy(commonBonuses[7].begin(), commonBonuses[7].end(), (*i)->bonuses.begin()); //common for tiers 8+
+		}
+	} //end of stack experience
 }
 
 void CCreatureHandler::loadAnimationInfo()
@@ -672,6 +713,40 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int
 	i+=2;
 }
 
+void CCreatureHandler::loadStackExp(stackExperience & b, std::string & src, int & it) //help function for parsing CREXPBON.txt, assuming all its details are already defined
+{
+	std::string buf, mod;
+	loadToIt(buf, src, it, 4);
+	loadToIt(mod, src, it, 4);
+	switch (buf[0])
+	{
+		case 'H':
+			b.type = Bonus::STACK_HEALTH;
+			break;
+		case 'A':
+			b.type = Bonus::PRIMARY_SKILL;
+			b.subtype = PrimarySkill::ATTACK;
+			break;
+		case 'D':
+			b.type = Bonus::PRIMARY_SKILL;
+			b.subtype = PrimarySkill::DEFENSE;
+			break;
+		case 'M': //Max damage
+			b.type = Bonus::CREATURE_DAMAGE;
+			b.subtype = 2;
+			break;
+		case 'm': //Min damage
+			b.type = Bonus::CREATURE_DAMAGE;
+			b.subtype = 1;
+			break;
+	}
+	loadToIt (b.val, src, it, 4); //basic value, not particularly useful but existent
+	for (int i = 0; i < 10; ++i)
+	{
+		loadToIt (b.expBonuses[i], src, it, 4); //vector must have length 10
+	}
+}
+
 CCreatureHandler::~CCreatureHandler()
 {
 }

+ 2 - 1
hch/CCreatureHandler.h

@@ -110,12 +110,13 @@ public:
 	std::vector<si8> factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index
 	int factionToTurretCreature[F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege
 
-	//bonus names and descriptions
 	std::map<TBonusType, std::pair<std::string, std::string>> stackBonuses; // bonus => name, description
+	std::vector<BonusList> commonBonuses; // levels 1-8 from CREXPBON.txt
 
 	void loadCreatures();
 	void loadAnimationInfo();
 	void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
+	void loadStackExp(stackExperience & b, std::string & src, int & it);
 
 	bool isGood (si8 faction) const;
 	bool isEvil (si8 faction) const;

+ 3 - 2
lib/HeroBonus.h

@@ -189,7 +189,8 @@ struct DLL_EXPORT Bonus
 		HERO_SPECIAL,
 		ARMY,
 		CAMPAIGN_BONUS,
-		SPECIAL_WEEK
+		SPECIAL_WEEK,
+		STACK_EXPERIENCE
 	};
 
 	enum LimitEffect
@@ -292,7 +293,7 @@ struct DLL_EXPORT Bonus
 
 struct DLL_EXPORT stackExperience : public Bonus
 {
-	std::vector<ui32> expBonuses; // variations for levels 1-10, copied to val field;
+	std::vector<si32> expBonuses; // variations for levels 1-10, copied to val field;
 	bool enable; //if true - turns ability on / off for zero value
 
 	template <typename Handler> void serialize(Handler &h, const int version)