From a84a95f0eee1b99feab48d831b4c95494b5e5f81 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Thu, 3 Feb 2011 12:58:46 +0000 Subject: [PATCH] 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. --- global.h | 3 +- hch/CCreatureHandler.cpp | 75 ++++++++++++++++++++++++++++++++++++++++ hch/CCreatureHandler.h | 3 +- lib/HeroBonus.h | 5 +-- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/global.h b/global.h index bfe0aebad..697ca20ca 100644 --- a/global.h +++ b/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; diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index eade32c1f..426b49501 100644 --- a/hch/CCreatureHandler.cpp +++ b/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::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() { } diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 44e6040cc..beeff2651 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -110,12 +110,13 @@ public: std::vector 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> stackBonuses; // bonus => name, description + std::vector 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; diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index ba7ab445a..4d2902f53 100644 --- a/lib/HeroBonus.h +++ b/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 expBonuses; // variations for levels 1-10, copied to val field; + std::vector expBonuses; // variations for levels 1-10, copied to val field; bool enable; //if true - turns ability on / off for zero value template void serialize(Handler &h, const int version)