#define VCMI_DLL #include "../stdafx.h" #include "CTownHandler.h" #include "CLodHandler.h" #include #include "../lib/VCMI_Lib.h" #include "CGeneralTextHandler.h" #include "../lib/JsonNode.h" #include extern CLodHandler * bitmaph; void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); /* * CTownHandler.cpp, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ CTownHandler::CTownHandler() { VLC->townh = this; } CTownHandler::~CTownHandler() { for( std::vector >::iterator i= structures.begin(); i!=structures.end(); i++) for( std::map::iterator j = i->begin(); j!=i->end(); j++) delete j->second; } void CTownHandler::loadStructures() { char bufname[75]; int townID; for (townID=0; townID &town = structures[townID]; // Read buildings coordinates for that city BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) { Structure *vinya = new Structure; const JsonNode *value; vinya->group = -1; vinya->townID = townID; vinya->ID = node["id"].Float(); vinya->defName = node["defname"].String(); vinya->name = vinya->defName; //TODO - use normal names vinya->pos.x = node["x"].Float(); vinya->pos.y = node["y"].Float(); vinya->pos.z = 0; value = &node["border"]; if (!value->isNull()) vinya->borderName = value->String(); value = &node["area"]; if (!value->isNull()) vinya->areaName = value->String(); town[vinya->ID] = vinya; } // Read buildings blit order for that city int itr = 1; BOOST_FOREACH(const JsonNode &node, town_node["blit_order"].Vector()) { int buildingID = node.Float(); /* Find the building and set its order. */ std::map::iterator i2 = town.find(buildingID); if (i2 != (town.end())) i2->second->pos.z = itr++; else tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl; } // Read basic creatures belonging to that city level = 0; BOOST_FOREACH(const JsonNode &node, town_node["creatures_basic"].Vector()) { // This if ignores the 8th field (WoG creature) if (level < towns[townID].basicCreatures.size()) towns[townID].basicCreatures[level] = node.Float(); level ++; } // Read upgraded creatures belonging to that city level = 0; BOOST_FOREACH(const JsonNode &node, town_node["creatures_upgraded"].Vector()) { towns[townID].upgradedCreatures[level] = node.Float(); level ++; } // Horde building creature level level = 0; BOOST_FOREACH(const JsonNode &node, town_node["horde"].Vector()) { towns[townID].hordeLvl[level] = node.Float(); level ++; } // Misc. towns[townID].mageLevel = town_node["mage_guild"].Float(); towns[townID].primaryRes = town_node["primary_ressource"].Float(); towns[townID].warMachine = town_node["war_machine"].Float(); townID ++; } int group_num=0; // Iterate for each city BOOST_FOREACH(const JsonNode &town_node, config["town_groups"].Vector()) { townID = town_node["id"].Float(); // Iterate for each group for that city BOOST_FOREACH(const JsonNode &group, town_node["groups"].Vector()) { group_num ++; // Iterate for each bulding value in the group BOOST_FOREACH(const JsonNode &value, group.Vector()) { int buildingID = value.Float(); std::vector >::iterator i; std::map::iterator i2; if (townID >= 0) { if ((i = structures.begin() + townID) != structures.end()) { if ((i2=(i->find(buildingID)))!=(i->end())) i2->second->group = group_num; else tlog3 << "Warning3: No building "<begin(); i2!=i->end(); i2++) { if(i2->first == buildingID) { i2->second->group = group_num; break; } } } } } } } std::ifstream of; 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> 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 { if(name.length()) return name; else return VLC->generaltexth->townTypes[typeID]; } const std::vector & CTown::Names() const { if(names.size()) return names; else return VLC->generaltexth->townNames[typeID]; }