2008-06-19 09:08:05 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-06-10 21:04:15 +03:00
|
|
|
#include "CBuildingHandler.h"
|
2008-12-22 19:48:41 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-12-22 19:48:41 +02:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2008-03-02 20:16:08 +02:00
|
|
|
#include <sstream>
|
2008-03-10 01:06:35 +02:00
|
|
|
#include <fstream>
|
2008-06-19 09:08:05 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
2009-01-06 20:42:20 +02:00
|
|
|
unsigned int readNr(std::string &in, int &it)
|
2008-03-02 20:16:08 +02:00
|
|
|
{
|
|
|
|
int last=it;
|
|
|
|
for(;last<in.size();last++)
|
|
|
|
if(in[last]=='\t' || in[last]=='\n' || in[last]==' ' || in[last]=='\r' || in[last]=='\n')
|
|
|
|
break;
|
|
|
|
if(last==in.size())
|
2009-01-11 00:08:18 +02:00
|
|
|
throw std::string("Cannot read number...");
|
|
|
|
|
2008-03-02 20:16:08 +02:00
|
|
|
std::stringstream ss(in.substr(it,last-it));
|
|
|
|
it+=(1+last-it);
|
|
|
|
ss >> last;
|
|
|
|
return last;
|
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
CBuilding * readBg(std::string &buf, int& it)
|
2008-03-02 20:16:08 +02:00
|
|
|
{
|
|
|
|
CBuilding * nb = new CBuilding();
|
2008-08-01 14:21:15 +03:00
|
|
|
nb->resources.resize(RESOURCE_QUANTITY);
|
2008-03-02 20:16:08 +02:00
|
|
|
for(int res=0;res<7;res++)
|
|
|
|
nb->resources[res] = readNr(buf,it);
|
2008-12-22 19:48:41 +02:00
|
|
|
/*nb->refName = */readTo(buf,it,'\n');
|
|
|
|
//reference name is ommitted, it's seems to be useless
|
2008-03-02 20:16:08 +02:00
|
|
|
return nb;
|
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
void CBuildingHandler::loadBuildings()
|
|
|
|
{
|
2008-06-19 09:08:05 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("BUILDING.TXT"), temp;
|
2009-01-06 20:42:20 +02:00
|
|
|
unsigned int andame = buf.size();
|
|
|
|
int it=0; //buf iterator
|
2007-06-10 21:04:15 +03:00
|
|
|
|
2008-03-02 20:16:08 +02:00
|
|
|
temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//read 2 lines of file info
|
2007-06-10 21:04:15 +03:00
|
|
|
|
2008-03-02 20:16:08 +02:00
|
|
|
//read 9 special buildings for every faction
|
|
|
|
for(int i=0;i<F_NUMBER;i++)
|
2007-06-10 21:04:15 +03:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
temp = readTo(buf,it,'\n');//read blank line and faction name
|
|
|
|
temp = readTo(buf,it,'\n');
|
|
|
|
for(int bg = 0; bg<9; bg++)
|
2007-06-10 21:04:15 +03:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
CBuilding *nb = readBg(buf,it);
|
2008-12-22 19:48:41 +02:00
|
|
|
nb->tid = i;
|
|
|
|
nb->bid = bg+17;
|
2008-03-02 20:16:08 +02:00
|
|
|
buildings[i][bg+17] = nb;
|
2007-06-10 21:04:15 +03:00
|
|
|
}
|
|
|
|
}
|
2007-06-10 23:14:37 +03:00
|
|
|
|
2008-03-02 20:16:08 +02:00
|
|
|
//reading 17 neutral (common) buildings
|
|
|
|
temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//neutral buildings - skip 3 lines
|
|
|
|
for(int bg = 0; bg<17; bg++)
|
2007-06-10 23:14:37 +03:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
CBuilding *nb = readBg(buf,it);
|
|
|
|
for(int f=0;f<F_NUMBER;f++)
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
buildings[f][bg] = new CBuilding(*nb);
|
2008-12-22 19:48:41 +02:00
|
|
|
buildings[f][bg]->tid = f;
|
|
|
|
buildings[f][bg]->bid = bg;
|
|
|
|
}
|
2008-03-02 20:16:08 +02:00
|
|
|
delete nb;
|
2007-06-10 23:14:37 +03:00
|
|
|
}
|
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
//reading 14 per faction dwellings
|
2008-03-02 20:16:08 +02:00
|
|
|
temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//dwellings - skip 2 lines
|
|
|
|
for(int i=0;i<F_NUMBER;i++)
|
2007-06-10 23:14:37 +03:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
temp = readTo(buf,it,'\n');//read blank line
|
|
|
|
temp = readTo(buf,it,'\n');// and faction name
|
|
|
|
for(int bg = 0; bg<14; bg++)
|
2007-06-10 23:14:37 +03:00
|
|
|
{
|
2008-03-02 20:16:08 +02:00
|
|
|
CBuilding *nb = readBg(buf,it);
|
2008-12-22 19:48:41 +02:00
|
|
|
nb->tid = i;
|
|
|
|
nb->bid = bg+30;
|
2008-03-02 20:16:08 +02:00
|
|
|
buildings[i][bg+30] = nb;
|
2007-06-10 23:14:37 +03:00
|
|
|
}
|
|
|
|
}
|
2008-03-02 20:16:08 +02:00
|
|
|
/////done reading BUILDING.TXT*****************************
|
2007-06-10 23:14:37 +03:00
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
char line[100]; //bufor
|
2008-03-10 01:06:35 +02:00
|
|
|
std::ifstream ofs("config/hall.txt");
|
|
|
|
int castles;
|
|
|
|
ofs>>castles;
|
|
|
|
for(int i=0;i<castles;i++)
|
|
|
|
{
|
|
|
|
int tid;
|
|
|
|
unsigned int it, box=0;
|
|
|
|
std::string pom;
|
|
|
|
ofs >> tid >> pom;
|
|
|
|
hall[tid].first = pom;
|
|
|
|
(hall[tid].second).resize(5); //rows
|
|
|
|
for(int j=0;j<5;j++)
|
|
|
|
{
|
|
|
|
box = it = 0;
|
|
|
|
ofs.getline(line,100);
|
2009-03-24 23:28:17 +02:00
|
|
|
if(!line[0] || line[0] == '\n' || line[0] == '\r')
|
2008-03-10 01:06:35 +02:00
|
|
|
ofs.getline(line,100);
|
|
|
|
std::string linia(line);
|
|
|
|
bool areboxes=true;
|
|
|
|
while(areboxes) //read all boxes
|
|
|
|
{
|
|
|
|
(hall[tid].second)[j].push_back(std::vector<int>()); //push new box
|
|
|
|
int seppos = linia.find_first_of('|',it); //position of end of this box data
|
|
|
|
if(seppos<0)
|
|
|
|
seppos = linia.length();
|
|
|
|
while(it<seppos)
|
|
|
|
{
|
|
|
|
int last = linia.find_first_of(' ',it);
|
|
|
|
std::stringstream ss(linia.substr(it,last-it));
|
|
|
|
it = last + 1;
|
|
|
|
ss >> last;
|
|
|
|
(hall[tid].second)[j][box].push_back(last);
|
2008-03-21 02:03:31 +02:00
|
|
|
areboxes = it; //wyzeruje jak nie znajdzie kolejnej spacji = koniec linii
|
2008-03-10 01:06:35 +02:00
|
|
|
if(!it)
|
2008-08-02 18:08:03 +03:00
|
|
|
it = seppos+1;
|
2008-03-10 01:06:35 +02:00
|
|
|
}
|
|
|
|
box++;
|
|
|
|
it+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-02 18:08:03 +03:00
|
|
|
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
CBuildingHandler::~CBuildingHandler()
|
|
|
|
{
|
|
|
|
for(std::map<int, std::map<int, CBuilding*> >::iterator i=buildings.begin(); i!=buildings.end(); i++)
|
|
|
|
for(std::map<int, CBuilding*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
|
|
|
|
delete j->second;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
const std::string & CBuilding::Name()
|
|
|
|
{
|
|
|
|
if(name.length())
|
|
|
|
return name;
|
|
|
|
else if(vstd::contains(VLC->generaltexth->buildings,tid) && vstd::contains(VLC->generaltexth->buildings[tid],bid))
|
|
|
|
return VLC->generaltexth->buildings[tid][bid].first;
|
|
|
|
tlog2 << "Warning: Cannot find name text for building " << bid << "for " << tid << "town.\n";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CBuilding::Description()
|
|
|
|
{
|
|
|
|
if(description.length())
|
|
|
|
return description;
|
|
|
|
else if(vstd::contains(VLC->generaltexth->buildings,tid) && vstd::contains(VLC->generaltexth->buildings[tid],bid))
|
|
|
|
return VLC->generaltexth->buildings[tid][bid].second;
|
|
|
|
tlog2 << "Warning: Cannot find description text for building " << bid << "for " << tid << "town.\n";
|
|
|
|
return "";
|
|
|
|
}
|