2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-07-26 15:00:18 +03:00
|
|
|
#include "CTownHandler.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "../CGameInfo.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-01-15 23:38:01 +02:00
|
|
|
#include <sstream>
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2007-07-26 15:00:18 +03:00
|
|
|
CTownHandler::CTownHandler()
|
|
|
|
{
|
|
|
|
smallIcons = CGI->spriteh->giveDef("ITPA.DEF");
|
|
|
|
}
|
|
|
|
CTownHandler::~CTownHandler()
|
|
|
|
{
|
|
|
|
delete smallIcons;
|
2008-01-15 23:38:01 +02:00
|
|
|
//todo - delete structures info
|
2007-07-26 15:00:18 +03:00
|
|
|
}
|
|
|
|
void CTownHandler::loadNames()
|
|
|
|
{
|
2007-09-16 20:21:23 +03:00
|
|
|
std::istringstream ins, names;
|
2007-07-26 15:00:18 +03:00
|
|
|
ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
|
2007-09-16 20:21:23 +03:00
|
|
|
names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
|
2007-10-14 15:11:18 +03:00
|
|
|
int si=0;
|
2007-07-26 15:00:18 +03:00
|
|
|
while (!ins.eof())
|
|
|
|
{
|
|
|
|
CTown town;
|
|
|
|
ins >> town.name;
|
2007-09-16 20:21:23 +03:00
|
|
|
char bufname[50];
|
|
|
|
for (int i=0; i<NAMES_PER_TOWN; i++)
|
|
|
|
{
|
|
|
|
names.getline(bufname,50);
|
|
|
|
town.names.push_back(std::string(bufname));
|
|
|
|
}
|
2007-10-14 15:11:18 +03:00
|
|
|
town.typeID=si++;
|
2007-07-26 15:00:18 +03:00
|
|
|
town.bonus=towns.size();
|
|
|
|
if (town.bonus==8) town.bonus=3;
|
|
|
|
if (town.name.length())
|
|
|
|
towns.push_back(town);
|
|
|
|
}
|
2008-01-09 19:21:31 +02:00
|
|
|
|
|
|
|
std::string strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT");
|
|
|
|
int itr=0;
|
|
|
|
while(itr<strs.length()-1)
|
|
|
|
{
|
|
|
|
std::string tmp;
|
|
|
|
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
|
|
|
|
tcommands.push_back(tmp);
|
2008-01-15 23:38:01 +02:00
|
|
|
}
|
2008-01-09 19:21:31 +02:00
|
|
|
|
2008-01-15 23:38:01 +02:00
|
|
|
|
|
|
|
std::ifstream of("config/buildings.txt");
|
|
|
|
while(!of.eof())
|
|
|
|
{
|
|
|
|
Structure *vinya = new Structure;
|
|
|
|
of >> vinya->townID;
|
|
|
|
of >> vinya->ID;
|
|
|
|
of >> vinya->defName;
|
|
|
|
of >> vinya->x;
|
|
|
|
of >> vinya->y;
|
|
|
|
structures[vinya->townID][vinya->ID] = vinya;
|
2008-01-09 19:21:31 +02:00
|
|
|
}
|
2008-01-15 23:38:01 +02:00
|
|
|
|
2007-07-26 15:00:18 +03:00
|
|
|
}
|
|
|
|
SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
|
|
|
|
{
|
|
|
|
if (ID==-1)
|
|
|
|
return smallIcons->ourImages[0].bitmap;
|
|
|
|
else if (ID==-2)
|
|
|
|
return smallIcons->ourImages[1].bitmap;
|
|
|
|
else if (ID==-3)
|
|
|
|
return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
|
|
|
|
else if (ID>F_NUMBER || ID<-3)
|
|
|
|
throw new std::exception("Invalid ID");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pom = 3;
|
|
|
|
if(!fort)
|
|
|
|
pom+=F_NUMBER*2;
|
|
|
|
pom += ID*2;
|
|
|
|
if (!builded)
|
|
|
|
pom--;
|
|
|
|
return smallIcons->ourImages[pom].bitmap;
|
|
|
|
}
|
2007-09-05 18:56:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTownHandler::getTypeByDefName(std::string name)
|
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-14 15:11:18 +03:00
|
|
|
|
|
|
|
CTownInstance::CTownInstance()
|
|
|
|
:pos(-1,-1,-1)
|
|
|
|
{
|
|
|
|
builded=-1;
|
|
|
|
destroyed=-1;
|
|
|
|
garrisonHero=NULL;
|
|
|
|
town=NULL;
|
2007-10-17 23:05:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTownInstance::getSightDistance() const //TODO: finish
|
|
|
|
{
|
|
|
|
return 10;
|
|
|
|
}
|