2008-06-13 00:08:04 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-06-08 22:56:35 +03:00
|
|
|
#include "CCreatureHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <sstream>
|
2008-08-30 00:41:32 +03:00
|
|
|
#include <boost/assign/std/set.hpp>
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <boost/assign/std/vector.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2008-04-14 21:24:46 +03:00
|
|
|
#include <boost/algorithm/string/find.hpp>
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2008-06-17 20:48:32 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2008-08-30 00:41:32 +03:00
|
|
|
using namespace boost::assign;
|
2008-06-13 00:08:04 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
2008-06-17 20:48:32 +03:00
|
|
|
CCreatureHandler::CCreatureHandler()
|
|
|
|
{
|
|
|
|
VLC->creh = this;
|
|
|
|
}
|
2008-09-24 19:25:14 +03:00
|
|
|
int CCreature::getQuantityID(const int & quantity)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
|
|
|
if (quantity<5)
|
|
|
|
return 0;
|
|
|
|
if (quantity<10)
|
|
|
|
return 1;
|
|
|
|
if (quantity<20)
|
|
|
|
return 2;
|
|
|
|
if (quantity<50)
|
|
|
|
return 3;
|
|
|
|
if (quantity<100)
|
|
|
|
return 4;
|
|
|
|
if (quantity<250)
|
|
|
|
return 5;
|
|
|
|
if (quantity<500)
|
|
|
|
return 5;
|
|
|
|
if (quantity<1000)
|
|
|
|
return 6;
|
|
|
|
if (quantity<4000)
|
|
|
|
return 7;
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isDoubleWide() const
|
2008-04-14 21:24:46 +03:00
|
|
|
{
|
2008-09-12 11:51:46 +03:00
|
|
|
return vstd::contains(abilities,DOUBLE_WIDE);
|
2008-04-14 21:24:46 +03:00
|
|
|
}
|
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isFlying() const
|
2008-04-14 21:24:46 +03:00
|
|
|
{
|
2008-09-12 11:51:46 +03:00
|
|
|
return vstd::contains(abilities,FLYING);
|
2008-04-14 21:24:46 +03:00
|
|
|
}
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isShooting() const
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2008-09-12 11:51:46 +03:00
|
|
|
return vstd::contains(abilities,SHOOTER);
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-08-01 14:21:15 +03:00
|
|
|
si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatures can be bought
|
2008-05-12 08:46:04 +03:00
|
|
|
{
|
|
|
|
int ret = 2147483645;
|
|
|
|
int resAmnt = std::min(res.size(),cost.size());
|
|
|
|
for(int i=0;i<resAmnt;i++)
|
|
|
|
if(cost[i])
|
2008-08-01 14:21:15 +03:00
|
|
|
ret = std::min(ret,(int)(res[i]/cost[i]));
|
2008-05-12 08:46:04 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2008-04-14 21:24:46 +03:00
|
|
|
|
2007-06-08 22:56:35 +03:00
|
|
|
void CCreatureHandler::loadCreatures()
|
|
|
|
{
|
2008-09-01 03:25:36 +03:00
|
|
|
notUsedMonsters += 122,124,126,128,145,146,147,148,149,160,161,162,163,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191;
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading ZCRTRAIT.TXT" << std::endl;
|
2008-06-12 09:45:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("ZCRTRAIT.TXT");
|
2007-07-16 17:42:44 +03:00
|
|
|
int andame = buf.size();
|
2007-06-10 21:04:15 +03:00
|
|
|
int i=0; //buf iterator
|
|
|
|
int hmcr=0;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\r')
|
|
|
|
++hmcr;
|
|
|
|
if(hmcr==2)
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
i+=2;
|
|
|
|
|
|
|
|
while(i<buf.size())
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
CCreature ncre;
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost.resize(RESOURCE_QUANTITY);
|
2008-02-05 05:56:45 +02:00
|
|
|
ncre.level=0;
|
2007-06-10 21:04:15 +03:00
|
|
|
int befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.nameSing = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.namePl = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[0] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[1] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[2] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[3] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[4] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[5] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost[6] = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.fightValue = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.AIValue = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.growth = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.hordeGrowth = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.hitPoints = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.speed = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.attack = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.defence = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-05-23 22:50:11 +03:00
|
|
|
ncre.damageMin = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-05-23 22:50:11 +03:00
|
|
|
ncre.damageMax = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.shots = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.spells = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-05-23 22:50:11 +03:00
|
|
|
ncre.ammMin = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2008-05-23 22:50:11 +03:00
|
|
|
ncre.ammMax = atoi(buf.substr(befi, i-befi).c_str());
|
2007-06-10 21:04:15 +03:00
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.abilityText = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\r')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.abilityRefs = buf.substr(befi, i-befi);
|
|
|
|
i+=2;
|
2008-09-12 11:51:46 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "DOUBLE_WIDE"))
|
|
|
|
ncre.abilities.insert(DOUBLE_WIDE);
|
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "FLYING_ARMY"))
|
|
|
|
ncre.abilities.insert(FLYING);
|
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
|
|
|
|
ncre.abilities.insert(SHOOTER);
|
2009-01-29 20:07:31 +02:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SIEGE_WEAPON"))
|
|
|
|
ncre.abilities.insert(SIEGE_WEAPON);
|
2008-09-14 10:11:07 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
|
|
|
|
ncre.abilities.insert(TWICE_ATTACK);
|
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))
|
|
|
|
ncre.abilities.insert(NO_ENEMY_RETALIATION);
|
2007-06-13 23:17:48 +03:00
|
|
|
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
|
|
|
|
{
|
|
|
|
ncre.idNumber = creatures.size();
|
|
|
|
creatures.push_back(ncre);
|
|
|
|
}
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
|
|
|
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading config/crerefnam.txt" << std::endl;
|
2007-10-17 01:39:11 +03:00
|
|
|
//loading reference names
|
2008-08-02 18:08:03 +03:00
|
|
|
std::ifstream ifs("config/crerefnam.txt");
|
2007-10-15 23:59:17 +03:00
|
|
|
int tempi;
|
|
|
|
std::string temps;
|
|
|
|
for (;;)
|
2007-06-18 13:49:06 +03:00
|
|
|
{
|
2007-10-15 23:59:17 +03:00
|
|
|
ifs >> tempi >> temps;
|
|
|
|
if (tempi>=creatures.size())
|
2007-06-18 13:49:06 +03:00
|
|
|
break;
|
2007-10-15 23:59:17 +03:00
|
|
|
boost::assign::insert(nameToID)(temps,tempi);
|
|
|
|
creatures[tempi].nameRef=temps;
|
2007-06-18 13:49:06 +03:00
|
|
|
}
|
2007-10-15 23:59:17 +03:00
|
|
|
ifs.close();
|
2008-02-05 05:56:45 +02:00
|
|
|
ifs.clear();
|
|
|
|
for(int i=1;i<=10;i++)
|
|
|
|
levelCreatures.insert(std::pair<int,std::vector<CCreature*> >(i,std::vector<CCreature*>()));
|
2008-11-01 00:41:22 +02:00
|
|
|
|
|
|
|
tlog5 << "\t\tReading config/monsters.txt" << std::endl;
|
2008-08-02 18:08:03 +03:00
|
|
|
ifs.open("config/monsters.txt");
|
2008-02-05 05:56:45 +02:00
|
|
|
{
|
|
|
|
while(!ifs.eof())
|
|
|
|
{
|
|
|
|
int id, lvl;
|
|
|
|
ifs >> id >> lvl;
|
|
|
|
if(lvl>0)
|
|
|
|
{
|
|
|
|
creatures[id].level = lvl;
|
|
|
|
levelCreatures[lvl].push_back(&(creatures[id]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-04 20:30:53 +03:00
|
|
|
ifs.close();
|
|
|
|
ifs.clear();
|
|
|
|
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading config/cr_factions.txt" << std::endl;
|
2008-08-02 18:08:03 +03:00
|
|
|
ifs.open("config/cr_factions.txt");
|
2008-04-04 20:30:53 +03:00
|
|
|
while(!ifs.eof())
|
|
|
|
{
|
|
|
|
int id, fact;
|
|
|
|
ifs >> id >> fact;
|
|
|
|
creatures[id].faction = fact;
|
|
|
|
}
|
|
|
|
ifs.close();
|
|
|
|
ifs.clear();
|
2007-10-17 01:39:11 +03:00
|
|
|
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading config/cr_upgrade_list.txt" << std::endl;
|
2008-08-02 18:08:03 +03:00
|
|
|
ifs.open("config/cr_upgrade_list.txt");
|
2008-05-31 23:37:54 +03:00
|
|
|
while(!ifs.eof())
|
|
|
|
{
|
|
|
|
int id, up;
|
|
|
|
ifs >> id >> up;
|
|
|
|
creatures[id].upgrades.insert(up);
|
|
|
|
}
|
|
|
|
ifs.close();
|
|
|
|
ifs.clear();
|
2008-08-02 18:08:03 +03:00
|
|
|
|
2008-03-05 19:01:41 +02:00
|
|
|
//loading unit animation def names
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading config/CREDEFS.TXT" << std::endl;
|
2008-03-05 19:01:41 +02:00
|
|
|
std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
|
|
|
|
inp.seekg(0,std::ios::end); // na koniec
|
|
|
|
int andame2 = inp.tellg(); // read length
|
|
|
|
inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
2008-08-02 18:08:03 +03:00
|
|
|
char * bufor = new char[andame2]; // allocate memory
|
2008-03-05 19:01:41 +02:00
|
|
|
inp.read((char*)bufor, andame2); // read map file to buffer
|
|
|
|
inp.close();
|
|
|
|
buf = std::string(bufor);
|
2008-08-02 18:08:03 +03:00
|
|
|
delete [] bufor;
|
2008-03-05 19:01:41 +02:00
|
|
|
|
|
|
|
i = 0; //buf iterator
|
|
|
|
hmcr = 0;
|
|
|
|
for(i; i<andame2; ++i) //omitting rubbish
|
|
|
|
{
|
|
|
|
if(buf[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "We have "<<creatures.size() << " creatures\n";
|
|
|
|
for(int s=0; s<creatures.size(); ++s)
|
2008-03-05 19:01:41 +02:00
|
|
|
{
|
2008-11-01 00:41:22 +02:00
|
|
|
//tlog5 <<"\t\t\t" << s <<". Reading defname. \n";
|
2008-03-05 19:01:41 +02:00
|
|
|
int befi=i;
|
|
|
|
std::string rub;
|
|
|
|
for(i; i<andame2; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]==' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rub = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame2; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string defName = buf.substr(befi, i-befi);
|
|
|
|
creatures[s].animDefName = defName;
|
|
|
|
}
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading CRANIM.TXT.txt" << std::endl;
|
2008-03-05 19:01:41 +02:00
|
|
|
loadAnimationInfo();
|
2008-08-02 18:08:03 +03:00
|
|
|
|
|
|
|
//loading id to projectile mapping
|
|
|
|
|
2008-11-01 00:41:22 +02:00
|
|
|
tlog5 << "\t\tReading config/cr_shots.txt" << std::endl;
|
2008-08-17 22:15:31 +03:00
|
|
|
std::ifstream inp2("config" PATHSEPARATOR "cr_shots.txt", std::ios::in | std::ios::binary); //this file is not in lod
|
2008-08-02 18:08:03 +03:00
|
|
|
char dump [200];
|
|
|
|
inp2.getline(dump, 200);
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
std::string name;
|
|
|
|
bool spin;
|
|
|
|
|
|
|
|
inp2>>id;
|
|
|
|
if(id == -1)
|
|
|
|
break;
|
|
|
|
inp2>>name;
|
|
|
|
idToProjectile[id] = name;
|
|
|
|
inp2>>spin;
|
|
|
|
idToProjectileSpin[id] = spin;
|
|
|
|
}
|
|
|
|
inp2.close();
|
2008-08-30 00:41:32 +03:00
|
|
|
|
2008-09-12 11:51:46 +03:00
|
|
|
|
|
|
|
|
2008-10-05 15:34:14 +03:00
|
|
|
creatures[115].abilities.insert(DOUBLE_WIDE);//water elemental should be treated as double-wide
|
2008-09-12 11:51:46 +03:00
|
|
|
creatures[123].abilities.insert(DOUBLE_WIDE);//ice elemental should be treated as double-wide
|
2008-09-14 10:11:07 +03:00
|
|
|
creatures[140].abilities.insert(DOUBLE_WIDE);//boar should be treated as double-wide
|
2009-02-21 17:43:28 +02:00
|
|
|
creatures[142].abilities.insert(DOUBLE_WIDE);//nomads should be treated as double-wide
|
2009-03-14 13:25:25 +02:00
|
|
|
|
|
|
|
creatures[46].abilities -= FLYING;
|
2007-10-15 23:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::loadAnimationInfo()
|
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("CRANIM.TXT");
|
2008-03-05 19:01:41 +02:00
|
|
|
int andame = buf.size();
|
|
|
|
int i=0; //buf iterator
|
|
|
|
int hmcr=0;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\r')
|
|
|
|
++hmcr;
|
|
|
|
if(hmcr==2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
2008-11-01 00:41:22 +02:00
|
|
|
for(int dd=0; dd<creatures.size(); ++dd)
|
2008-03-05 19:01:41 +02:00
|
|
|
{
|
2008-11-01 00:41:22 +02:00
|
|
|
//tlog5 << "\t\t\tReading animation info for creature " << dd << std::endl;
|
2008-03-05 19:01:41 +02:00
|
|
|
loadUnitAnimInfo(creatures[dd], buf, i);
|
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int & i)
|
|
|
|
{
|
|
|
|
int befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
while(unit.timeBetweenFidgets == 0.0)
|
|
|
|
{
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.walkAnimationTime = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.attackAnimationTime = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.flightAnimationDistance = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.upperRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.upperRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.rightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.rightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.lowerRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.lowerRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
for(int jjj=0; jjj<12; ++jjj)
|
|
|
|
{
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.missleFrameAngles[jjj] = atof(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.troopCountLocationOffset= atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unit.attackClimaxFrame = atoi(src.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
for(i; i<src.size(); ++i)
|
|
|
|
{
|
|
|
|
if(src[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
CCreatureHandler::~CCreatureHandler()
|
|
|
|
{
|
|
|
|
}
|