|
@@ -31,120 +31,33 @@ CTownHandler::~CTownHandler()
|
|
|
for( std::map<int, Structure*>::iterator j = i->begin(); j!=i->end(); j++)
|
|
|
delete j->second;
|
|
|
}
|
|
|
-void CTownHandler::loadNames()
|
|
|
+void CTownHandler::loadStructures()
|
|
|
{
|
|
|
int si, itr;
|
|
|
char bufname[75];
|
|
|
- for (si=0; si<F_NUMBER; si++)
|
|
|
+ int townID;
|
|
|
+
|
|
|
+ for (townID=0; townID<F_NUMBER; townID++)
|
|
|
{
|
|
|
CTown town;
|
|
|
- town.typeID=si;
|
|
|
+ town.typeID=townID;
|
|
|
town.bonus=towns.size();
|
|
|
if (town.bonus==8) town.bonus=3;
|
|
|
towns.push_back(town);
|
|
|
}
|
|
|
|
|
|
- loadStructures();
|
|
|
-
|
|
|
-
|
|
|
- std::ifstream of;
|
|
|
- for(int x=0;x<towns.size();x++)
|
|
|
- towns[x].basicCreatures.resize(7);
|
|
|
-
|
|
|
- of.open(DATA_DIR "/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();
|
|
|
-
|
|
|
- for(int x=0;x<towns.size();x++)
|
|
|
- towns[x].upgradedCreatures.resize(7);
|
|
|
-
|
|
|
- of.open(DATA_DIR "/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();
|
|
|
-
|
|
|
- of.open(DATA_DIR "/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();
|
|
|
-
|
|
|
- of.open(DATA_DIR "/config/mageLevel.txt");
|
|
|
- of >> si;
|
|
|
- for(itr=0; itr<si; itr++)
|
|
|
- {
|
|
|
- of >> towns[itr].mageLevel >> towns[itr].primaryRes >> towns[itr].warMachine;
|
|
|
- }
|
|
|
- of.close();
|
|
|
- of.clear();
|
|
|
-
|
|
|
- of.open(DATA_DIR "/config/requirements.txt");
|
|
|
- requirements.resize(F_NUMBER);
|
|
|
- while(!of.eof())
|
|
|
- {
|
|
|
- int ile, town, build, pom;
|
|
|
- of >> ile;
|
|
|
- for(int i=0;i<ile;i++)
|
|
|
- {
|
|
|
- of >> town;
|
|
|
- while(true)
|
|
|
- {
|
|
|
- of.getline(bufname,75);
|
|
|
- if(!bufname[0] || bufname[0] == '\n' || bufname[0] == '\r')
|
|
|
- of.getline(bufname,75);
|
|
|
- std::istringstream ifs(bufname);
|
|
|
- ifs >> build;
|
|
|
- if(build<0)
|
|
|
- break;
|
|
|
- while(!ifs.eof())
|
|
|
- {
|
|
|
- ifs >> pom;
|
|
|
- requirements[town][build].insert(pom);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- of.close();
|
|
|
- of.clear();
|
|
|
-}
|
|
|
-
|
|
|
-void CTownHandler::loadStructures()
|
|
|
-{
|
|
|
- std::ifstream of;
|
|
|
-
|
|
|
structures.resize(F_NUMBER);
|
|
|
|
|
|
// read city properties
|
|
|
const JsonNode config(DATA_DIR "/config/buildings.json");
|
|
|
- const JsonVector &town_type_vec = config["town_type"].Vector();
|
|
|
- int townID=0;
|
|
|
|
|
|
// Iterate for each city type
|
|
|
- for (JsonVector::const_iterator it = town_type_vec.begin(); it!=town_type_vec.end(); ++it, ++townID) {
|
|
|
+ townID = 0;
|
|
|
+ BOOST_FOREACH(const JsonNode &town_node, config["town_type"].Vector()) {
|
|
|
std::map<int, Structure*> &town = structures[townID];
|
|
|
- const JsonNode &town_node = *it;
|
|
|
- const JsonVector &defnames_vec = town_node["defnames"].Vector();
|
|
|
|
|
|
// Read buildings coordinates for that city
|
|
|
- for (JsonVector::const_iterator it2 = defnames_vec.begin(); it2!=defnames_vec.end(); ++it2) {
|
|
|
- const JsonNode &node = *it2;
|
|
|
+ BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) {
|
|
|
Structure *vinya = new Structure;
|
|
|
const JsonNode *value;
|
|
|
|
|
@@ -183,6 +96,8 @@ void CTownHandler::loadStructures()
|
|
|
else
|
|
|
tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl;
|
|
|
}
|
|
|
+
|
|
|
+ townID ++;
|
|
|
}
|
|
|
|
|
|
int group_num=0;
|
|
@@ -226,6 +141,83 @@ void CTownHandler::loadStructures()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ std::ifstream of;
|
|
|
+ for(int x=0;x<towns.size();x++)
|
|
|
+ towns[x].basicCreatures.resize(7);
|
|
|
+
|
|
|
+ of.open(DATA_DIR "/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();
|
|
|
+
|
|
|
+ for(int x=0;x<towns.size();x++)
|
|
|
+ towns[x].upgradedCreatures.resize(7);
|
|
|
+
|
|
|
+ of.open(DATA_DIR "/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();
|
|
|
+
|
|
|
+ of.open(DATA_DIR "/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();
|
|
|
+
|
|
|
+ of.open(DATA_DIR "/config/mageLevel.txt");
|
|
|
+ of >> si;
|
|
|
+ for(itr=0; itr<si; itr++)
|
|
|
+ {
|
|
|
+ of >> towns[itr].mageLevel >> towns[itr].primaryRes >> towns[itr].warMachine;
|
|
|
+ }
|
|
|
+ of.close();
|
|
|
+ of.clear();
|
|
|
+
|
|
|
+ of.open(DATA_DIR "/config/requirements.txt");
|
|
|
+ requirements.resize(F_NUMBER);
|
|
|
+ while(!of.eof())
|
|
|
+ {
|
|
|
+ int ile, town, build, pom;
|
|
|
+ of >> ile;
|
|
|
+ for(int i=0;i<ile;i++)
|
|
|
+ {
|
|
|
+ of >> town;
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ of.getline(bufname,75);
|
|
|
+ if(!bufname[0] || bufname[0] == '\n' || bufname[0] == '\r')
|
|
|
+ of.getline(bufname,75);
|
|
|
+ std::istringstream ifs(bufname);
|
|
|
+ ifs >> build;
|
|
|
+ if(build<0)
|
|
|
+ break;
|
|
|
+ while(!ifs.eof())
|
|
|
+ {
|
|
|
+ ifs >> pom;
|
|
|
+ requirements[town][build].insert(pom);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ of.close();
|
|
|
+ of.clear();
|
|
|
}
|
|
|
|
|
|
const std::string & CTown::Name() const
|