2008-06-13 11:16:51 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-07-26 15:00:18 +03:00
|
|
|
#include "CTownHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-08-02 18:08:03 +03:00
|
|
|
#include <sstream>
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2008-06-13 11:16:51 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
|
|
|
void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
2007-07-26 15:00:18 +03:00
|
|
|
CTownHandler::CTownHandler()
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
|
|
|
VLC->townh = this;
|
|
|
|
}
|
2007-07-26 15:00:18 +03:00
|
|
|
CTownHandler::~CTownHandler()
|
2008-06-13 11:16:51 +03:00
|
|
|
{}
|
2007-07-26 15:00:18 +03:00
|
|
|
void CTownHandler::loadNames()
|
|
|
|
{
|
2007-09-16 20:21:23 +03:00
|
|
|
std::istringstream ins, names;
|
2008-06-13 11:16:51 +03:00
|
|
|
ins.str(bitmaph->getTextFile("TOWNTYPE.TXT"));
|
|
|
|
names.str(bitmaph->getTextFile("TOWNNAME.TXT"));
|
2007-10-14 15:11:18 +03:00
|
|
|
int si=0;
|
2008-03-16 02:09:43 +02:00
|
|
|
char bufname[75];
|
2007-07-26 15:00:18 +03:00
|
|
|
while (!ins.eof())
|
|
|
|
{
|
|
|
|
CTown town;
|
2008-02-07 20:45:22 +02:00
|
|
|
ins.getline(bufname,50);
|
|
|
|
town.name = std::string(bufname);
|
2008-02-22 17:47:01 +02:00
|
|
|
town.name = town.name.substr(0,town.name.size()-1);
|
2007-09-16 20:21:23 +03:00
|
|
|
for (int i=0; i<NAMES_PER_TOWN; i++)
|
|
|
|
{
|
|
|
|
names.getline(bufname,50);
|
2008-02-02 02:41:00 +02:00
|
|
|
std::string pom(bufname);
|
|
|
|
town.names.push_back(pom.substr(0,pom.length()-1));
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2007-10-14 15:11:18 +03:00
|
|
|
town.typeID=si++;
|
2007-07-26 15:00:18 +03:00
|
|
|
town.bonus=towns.size();
|
2008-08-02 18:08:03 +03:00
|
|
|
if (town.bonus==8) town.bonus=3;
|
2007-07-26 15:00:18 +03:00
|
|
|
if (town.name.length())
|
|
|
|
towns.push_back(town);
|
|
|
|
}
|
2008-01-09 19:21:31 +02:00
|
|
|
|
2008-06-13 11:16:51 +03:00
|
|
|
std::string strs = bitmaph->getTextFile("TCOMMAND.TXT");
|
2008-01-09 19:21:31 +02:00
|
|
|
int itr=0;
|
|
|
|
while(itr<strs.length()-1)
|
|
|
|
{
|
|
|
|
std::string tmp;
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(tmp, strs, itr, 3);
|
2008-01-09 19:21:31 +02:00
|
|
|
tcommands.push_back(tmp);
|
2008-01-15 23:38:01 +02:00
|
|
|
}
|
2008-01-09 19:21:31 +02:00
|
|
|
|
2008-06-13 11:16:51 +03:00
|
|
|
strs = bitmaph->getTextFile("HALLINFO.TXT");
|
2008-03-11 23:36:59 +02:00
|
|
|
itr=0;
|
|
|
|
while(itr<strs.length()-1)
|
|
|
|
{
|
|
|
|
std::string tmp;
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(tmp, strs, itr, 3);
|
2008-03-11 23:36:59 +02:00
|
|
|
hcommands.push_back(tmp);
|
|
|
|
}
|
|
|
|
|
2008-01-19 13:55:04 +02:00
|
|
|
//read buildings coords
|
2008-01-15 23:38:01 +02:00
|
|
|
std::ifstream of("config/buildings.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
Structure *vinya = new Structure;
|
2008-01-27 15:18:18 +02:00
|
|
|
vinya->group = -1;
|
2008-01-15 23:38:01 +02:00
|
|
|
of >> vinya->townID;
|
|
|
|
of >> vinya->ID;
|
|
|
|
of >> vinya->defName;
|
2008-01-27 22:37:10 +02:00
|
|
|
vinya->name = vinya->defName; //TODO - use normal names
|
2008-01-19 13:55:04 +02:00
|
|
|
of >> vinya->pos.x;
|
|
|
|
of >> vinya->pos.y;
|
|
|
|
vinya->pos.z = 0;
|
2008-01-15 23:38:01 +02:00
|
|
|
structures[vinya->townID][vinya->ID] = vinya;
|
2008-01-09 19:21:31 +02:00
|
|
|
}
|
2008-01-19 13:55:04 +02:00
|
|
|
of.close();
|
|
|
|
of.clear();
|
|
|
|
|
|
|
|
//read building priorities
|
|
|
|
of.open("config/buildings2.txt");
|
|
|
|
int format, idt;
|
|
|
|
std::string s;
|
|
|
|
of >> format >> idt;
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
std::map<int,std::map<int, Structure*> >::iterator i;
|
|
|
|
std::map<int, Structure*>::iterator i2;
|
|
|
|
int itr=1, buildingID;
|
|
|
|
int castleID;
|
|
|
|
of >> s;
|
|
|
|
if (s != "CASTLE")
|
|
|
|
break;
|
|
|
|
of >> castleID;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
of >> s;
|
|
|
|
if (s == "END")
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
if((i=structures.find(castleID))!=structures.end())
|
|
|
|
if((i2=(i->second.find(buildingID=atoi(s.c_str()))))!=(i->second.end()))
|
|
|
|
i2->second->pos.z=itr++;
|
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning1: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
|
2008-01-19 13:55:04 +02:00
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning1: Castle "<<castleID<<" not defined."<<std::endl;
|
2008-01-19 13:55:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
of.close();
|
2008-01-20 18:24:03 +02:00
|
|
|
of.clear();
|
|
|
|
|
2008-01-27 15:18:18 +02:00
|
|
|
//read borders and areas names
|
2008-01-20 18:24:03 +02:00
|
|
|
of.open("config/buildings3.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
std::map<int,std::map<int, Structure*> >::iterator i;
|
|
|
|
std::map<int, Structure*>::iterator i2;
|
|
|
|
int town, id;
|
|
|
|
std::string border, area;
|
|
|
|
of >> town >> id >> border >> border >> area;
|
|
|
|
|
|
|
|
if((i=structures.find(town))!=structures.end())
|
|
|
|
if((i2=(i->second.find(id)))!=(i->second.end()))
|
|
|
|
{
|
|
|
|
i2->second->borderName = border;
|
|
|
|
i2->second->areaName = area;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-01-20 18:24:03 +02:00
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning2: No building "<<id<<" in the castle "<<town<<std::endl;
|
2008-01-20 18:24:03 +02:00
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning2: Castle "<<town<<" not defined."<<std::endl;
|
2008-01-20 18:24:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
|
|
|
|
2008-01-27 15:18:18 +02:00
|
|
|
//read groups
|
|
|
|
itr = 0;
|
|
|
|
of.open("config/buildings4.txt");
|
|
|
|
of >> format;
|
|
|
|
if(format!=1)
|
|
|
|
{
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog1 << "Unhandled format of buildings4.txt \n";
|
2008-01-27 15:18:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-29 17:08:41 +02:00
|
|
|
of >> s;
|
|
|
|
int itr=1;
|
2008-01-27 15:18:18 +02:00
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
std::map<int,std::map<int, Structure*> >::iterator i;
|
|
|
|
std::map<int, Structure*>::iterator i2;
|
2008-01-29 17:08:41 +02:00
|
|
|
int buildingID;
|
2008-01-27 15:18:18 +02:00
|
|
|
int castleID;
|
2008-01-29 17:08:41 +02:00
|
|
|
itr++;
|
2008-01-27 15:18:18 +02:00
|
|
|
if (s == "CASTLE")
|
|
|
|
{
|
|
|
|
of >> castleID;
|
|
|
|
}
|
|
|
|
else if(s == "ALL")
|
|
|
|
{
|
|
|
|
castleID = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
of >> s;
|
|
|
|
while(1) //read groups for castle
|
|
|
|
{
|
|
|
|
if (s == "GROUP")
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
of >> s;
|
2008-01-29 17:08:41 +02:00
|
|
|
if((s == "GROUP") || (s == "EOD") || (s == "CASTLE")) //
|
2008-01-27 15:18:18 +02:00
|
|
|
break;
|
|
|
|
buildingID = atoi(s.c_str());
|
|
|
|
if(castleID>=0)
|
|
|
|
{
|
|
|
|
if((i=structures.find(castleID))!=structures.end())
|
|
|
|
if((i2=(i->second.find(buildingID)))!=(i->second.end()))
|
|
|
|
i2->second->group = itr;
|
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning3: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
|
2008-01-27 15:18:18 +02:00
|
|
|
else
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3 << "Warning3: Castle "<<castleID<<" not defined."<<std::endl;
|
2008-01-27 15:18:18 +02:00
|
|
|
}
|
|
|
|
else //set group for selected building in ALL castles
|
|
|
|
{
|
|
|
|
for(i=structures.begin();i!=structures.end();i++)
|
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
for(i2=i->second.begin(); i2!=i->second.end(); i2++)
|
2008-01-27 15:18:18 +02:00
|
|
|
{
|
|
|
|
if(i2->first == buildingID)
|
|
|
|
{
|
|
|
|
i2->second->group = itr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-29 17:08:41 +02:00
|
|
|
if(s == "CASTLE")
|
|
|
|
break;
|
2008-01-27 15:18:18 +02:00
|
|
|
itr++;
|
|
|
|
}//if (s == "GROUP")
|
|
|
|
else if(s == "EOD")
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
2008-02-05 05:56:45 +02:00
|
|
|
|
|
|
|
for(int x=0;x<towns.size();x++)
|
|
|
|
towns[x].basicCreatures.resize(7);
|
|
|
|
|
|
|
|
of.open("config/basicCres.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
int tid, lid, cid; //town,level,creature
|
|
|
|
of >> tid >> lid >> cid;
|
|
|
|
if(lid < towns[tid].basicCreatures.size())
|
|
|
|
towns[tid].basicCreatures[lid]=cid;
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
2008-03-16 02:09:43 +02:00
|
|
|
|
2008-04-04 20:30:53 +03:00
|
|
|
for(int x=0;x<towns.size();x++)
|
|
|
|
towns[x].upgradedCreatures.resize(7);
|
|
|
|
|
|
|
|
of.open("config/creatures_upgr.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
int tid, lid, cid; //town,level,creature
|
|
|
|
of >> tid >> lid >> cid;
|
|
|
|
if(lid < towns[tid].upgradedCreatures.size())
|
|
|
|
towns[tid].upgradedCreatures[lid]=cid;
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
|
|
|
|
2008-04-14 20:45:01 +03:00
|
|
|
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();
|
2008-08-02 18:08:03 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
of.open("config/mageLevel.txt");
|
2008-08-26 00:14:00 +03:00
|
|
|
of >> si;
|
|
|
|
for(itr=0; itr<si; itr++)
|
2008-08-20 09:57:53 +03:00
|
|
|
{
|
2008-08-27 13:19:18 +03:00
|
|
|
of >> towns[itr].mageLevel >> towns[itr].primaryRes >> towns[itr].warMachine;
|
2008-08-20 09:57:53 +03:00
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
|
|
|
|
2008-03-16 02:09:43 +02:00
|
|
|
of.open("config/requirements.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
int ile, town, build, pom;
|
|
|
|
of >> ile;
|
|
|
|
for(int i=0;i<ile;i++)
|
|
|
|
{
|
|
|
|
of >> town;
|
|
|
|
while(true)
|
|
|
|
{
|
2008-03-21 02:03:31 +02:00
|
|
|
of.getline(bufname,75);if(!(*bufname))of.getline(bufname,75);
|
2008-03-16 02:09:43 +02:00
|
|
|
std::istringstream ifs(bufname);
|
|
|
|
ifs >> build;
|
|
|
|
if(build<0)
|
|
|
|
break;
|
|
|
|
while(!ifs.eof())
|
|
|
|
{
|
|
|
|
ifs >> pom;
|
|
|
|
requirements[town][build].insert(pom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
of.clear();
|
2008-01-27 15:18:18 +02:00
|
|
|
}
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|