1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Merged Warmonger's changes from trunk

This commit is contained in:
Michał W. Urbańczyk
2011-02-06 08:32:05 +00:00
12 changed files with 325 additions and 39 deletions

View File

@@ -12,6 +12,7 @@
#include <boost/algorithm/string/replace.hpp>
#include "../lib/VCMI_Lib.h"
#include "../lib/CGameState.h"
#include <boost/foreach.hpp>
using namespace boost::assign;
extern CLodHandler * bitmaph;
@@ -590,6 +591,69 @@ void CCreatureHandler::loadCreatures()
inp3 >> factionToTurretCreature[g];
}
inp3.close();
//reading creature ability names
ifs.open(DATA_DIR "/config/bonusnames.txt");
{
std::string buf2, buf3, line;
int i;
std::map<std::string,int>::const_iterator it;
getline(ifs, line); //skip 1st line
while(!ifs.eof())
{
getline(ifs, buf, '\t');
getline(ifs, buf2, '\t');
getline(ifs, buf3);
it = bonusNameMap.find(buf);
if (it != bonusNameMap.end())
stackBonuses[it->second] = std::pair<std::string, std::string>(buf2,buf3);
else
tlog2 << "Bonus " << buf << " not recognized, ingoring\n";
}
}
ifs.close();
if (STACK_EXP) //reading default stack experience bonuses
{
buf = bitmaph->getTextFile("CREXPBON.TXT");
int it = 0;
si32 creid = -1;
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(new stackExperience(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(new stackExperience(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(new stackExperience(b)); //experience list is common for creatures of that type
loadToIt (dump2, buf, it, 3); //crop comment
} while (it < buf.size());
BOOST_FOREACH(CCreature *c, creatures)
{
if (it = c->level < 7)
std::copy(commonBonuses[it-1].begin(), commonBonuses[it-1].end(), c->bonuses.begin());
else
std::copy(commonBonuses[7].begin(), commonBonuses[7].end(), c->bonuses.begin()); //common for tiers 8+
}
} //end of stack experience
}
void CCreatureHandler::loadAnimationInfo()
@@ -662,6 +726,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()
{
}