2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-07-26 15:00:18 +03:00
|
|
|
#include "CTownHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
#include "VCMI_Lib.h"
|
2008-12-22 19:48:41 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2012-08-02 14:03:26 +03:00
|
|
|
#include "JsonNode.h"
|
2012-12-14 18:32:53 +03:00
|
|
|
#include "StringConstants.h"
|
2012-12-03 19:00:17 +03:00
|
|
|
#include "CModHandler.h"
|
2012-12-15 11:47:02 +03:00
|
|
|
#include "CArtHandler.h"
|
2012-08-02 14:03:26 +03:00
|
|
|
#include "Filesystem/CResourceLoader.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
const std::string & CBuilding::Name() const
|
|
|
|
{
|
2012-09-05 15:49:23 +03:00
|
|
|
return name;
|
2012-09-02 13:33:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CBuilding::Description() const
|
|
|
|
{
|
2012-09-05 15:49:23 +03:00
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBuilding::BuildingType CBuilding::getBase() const
|
|
|
|
{
|
|
|
|
const CBuilding * build = this;
|
|
|
|
while (build->upgrade >= 0)
|
|
|
|
build = VLC->townh->towns[build->tid].buildings[build->upgrade];
|
|
|
|
|
|
|
|
return build->bid;
|
|
|
|
}
|
|
|
|
|
|
|
|
si32 CBuilding::getDistance(CBuilding::BuildingType buildID) const
|
|
|
|
{
|
|
|
|
const CBuilding * build = VLC->townh->towns[tid].buildings[buildID];
|
|
|
|
int distance = 0;
|
|
|
|
while (build->upgrade >= 0 && build != this)
|
|
|
|
{
|
|
|
|
build = VLC->townh->towns[build->tid].buildings[build->upgrade];
|
|
|
|
distance++;
|
|
|
|
}
|
|
|
|
if (build == this)
|
|
|
|
return distance;
|
|
|
|
return -1;
|
2012-09-02 13:33:41 +03:00
|
|
|
}
|
|
|
|
|
2007-07-26 15:00:18 +03:00
|
|
|
CTownHandler::CTownHandler()
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
|
|
|
VLC->townh = this;
|
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
JsonNode readBuilding(CLegacyConfigParser & parser)
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-09-02 13:33:41 +03:00
|
|
|
JsonNode ret;
|
|
|
|
JsonNode & cost = ret["cost"];
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
//note: this code will try to parse mithril as well but wil always return 0 for it
|
|
|
|
BOOST_FOREACH(const std::string & resID, GameConstants::RESOURCE_NAMES)
|
2012-09-02 13:33:41 +03:00
|
|
|
cost[resID].Float() = parser.readNumber();
|
|
|
|
|
|
|
|
parser.endLine();
|
|
|
|
return ret;
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
void CTownHandler::loadLegacyData(JsonNode & dest)
|
2007-07-26 15:00:18 +03:00
|
|
|
{
|
2012-09-02 13:33:41 +03:00
|
|
|
CLegacyConfigParser parser("DATA/BUILDING.TXT");
|
|
|
|
dest.Vector().resize(GameConstants::F_NUMBER);
|
|
|
|
|
|
|
|
parser.endLine(); // header
|
|
|
|
parser.endLine();
|
2011-08-26 06:10:56 +03:00
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
//Unique buildings
|
|
|
|
for (size_t town=0; town<GameConstants::F_NUMBER; town++)
|
2007-07-26 15:00:18 +03:00
|
|
|
{
|
2012-10-05 16:11:26 +03:00
|
|
|
JsonVector & buildList = dest.Vector()[town]["buildings"].Vector();
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
buildList.resize( 30 ); //prepare vector for first set of buildings
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
parser.endLine(); //header
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
int buildID = 17;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
buildList[buildID] = readBuilding(parser);
|
|
|
|
buildID++;
|
2011-08-20 07:48:23 +03:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
while (!parser.isNextEntryEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Common buildings
|
|
|
|
parser.endLine(); // header
|
|
|
|
parser.endLine();
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
int buildID = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
JsonNode building = readBuilding(parser);
|
2011-08-20 09:08:48 +03:00
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
for (size_t town=0; town<GameConstants::F_NUMBER; town++)
|
2012-10-05 16:11:26 +03:00
|
|
|
dest.Vector()[town]["buildings"].Vector()[buildID] = building;
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
buildID++;
|
|
|
|
}
|
|
|
|
while (!parser.isNextEntryEmpty());
|
|
|
|
|
|
|
|
parser.endLine(); //header
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
//Dwellings
|
|
|
|
for (size_t town=0; town<GameConstants::F_NUMBER; town++)
|
|
|
|
{
|
|
|
|
parser.endLine(); //header
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-10-05 16:11:26 +03:00
|
|
|
dest.Vector()[town]["buildings"].Vector().push_back(readBuilding(parser));
|
2008-01-19 13:55:04 +02:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
while (!parser.isNextEntryEmpty());
|
|
|
|
}
|
2012-10-05 16:11:26 +03:00
|
|
|
{
|
|
|
|
CLegacyConfigParser parser("DATA/BLDGNEUT.TXT");
|
|
|
|
|
|
|
|
for(int building=0; building<15; building++)
|
|
|
|
{
|
|
|
|
std::string name = parser.readString();
|
|
|
|
std::string descr = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
for(int j=0; j<GameConstants::F_NUMBER; j++)
|
|
|
|
{
|
|
|
|
JsonVector & buildings = dest.Vector()[j]["buildings"].Vector();
|
|
|
|
buildings[building]["name"].String() = name;
|
|
|
|
buildings[building]["description"].String() = descr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parser.endLine(); // silo
|
|
|
|
parser.endLine(); // blacksmith //unused entries
|
|
|
|
parser.endLine(); // moat
|
|
|
|
|
|
|
|
//shipyard with the ship
|
|
|
|
std::string name = parser.readString();
|
|
|
|
std::string descr = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
for(int town=0; town<GameConstants::F_NUMBER; town++)
|
|
|
|
{
|
|
|
|
JsonVector & buildings = dest.Vector()[town]["buildings"].Vector();
|
|
|
|
buildings[20]["name"].String() = name;
|
|
|
|
buildings[20]["description"].String() = descr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//blacksmith
|
|
|
|
for(int town=0; town<GameConstants::F_NUMBER; town++)
|
|
|
|
{
|
|
|
|
JsonVector & buildings = dest.Vector()[town]["buildings"].Vector();
|
|
|
|
buildings[16]["name"].String() = parser.readString();
|
|
|
|
buildings[16]["description"].String() = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
CLegacyConfigParser parser("DATA/BLDGSPEC.TXT");
|
|
|
|
|
|
|
|
for(int town=0; town<GameConstants::F_NUMBER; town++)
|
|
|
|
{
|
|
|
|
JsonVector & buildings = dest.Vector()[town]["buildings"].Vector();
|
|
|
|
for(int build=0; build<9; build++)
|
|
|
|
{
|
|
|
|
buildings[17+build]["name"].String() = parser.readString();
|
|
|
|
buildings[17+build]["description"].String() = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
}
|
|
|
|
buildings[26]["name"].String() = parser.readString(); // Grail
|
|
|
|
buildings[26]["description"].String() = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
|
|
|
|
buildings[15]["name"].String() = parser.readString(); // Resource silo
|
|
|
|
buildings[15]["description"].String() = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
CLegacyConfigParser parser("DATA/DWELLING.TXT");
|
|
|
|
|
|
|
|
for(int town=0; town<GameConstants::F_NUMBER; town++)
|
|
|
|
{
|
|
|
|
JsonVector & buildings = dest.Vector()[town]["buildings"].Vector();
|
|
|
|
for(int build=0; build<14; build++)
|
|
|
|
{
|
|
|
|
buildings[30+build]["name"].String() = parser.readString();
|
|
|
|
buildings[30+build]["description"].String() = parser.readString();
|
|
|
|
parser.endLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT");
|
|
|
|
CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT");
|
|
|
|
size_t townID=0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
JsonNode & town = dest.Vector()[townID];
|
|
|
|
|
|
|
|
town["name"].String() = typeParser.readString();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<GameConstants::NAMES_PER_TOWN; i++)
|
|
|
|
{
|
|
|
|
JsonNode name;
|
|
|
|
name.String() = nameParser.readString();
|
|
|
|
town["names"].Vector().push_back(name);
|
|
|
|
nameParser.endLine();
|
|
|
|
}
|
|
|
|
townID++;
|
|
|
|
}
|
|
|
|
while (typeParser.endLine());
|
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTownHandler::loadBuilding(CTown &town, const JsonNode & source)
|
|
|
|
{
|
|
|
|
CBuilding * ret = new CBuilding;
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
static const std::string modes [] = {"normal", "auto", "special", "grail"};
|
|
|
|
|
|
|
|
ret->mode = boost::find(modes, source["mode"].String()) - modes;
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
ret->tid = town.typeID;
|
|
|
|
ret->bid = source["id"].Float();
|
2012-09-05 15:49:23 +03:00
|
|
|
ret->name = source["name"].String();
|
|
|
|
ret->description = source["description"].String();
|
2012-09-02 13:33:41 +03:00
|
|
|
ret->resources = TResources(source["cost"]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const JsonNode &building, source["requires"].Vector())
|
|
|
|
ret->requirements.insert(building.Float());
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
if (!source["upgrades"].isNull())
|
|
|
|
{
|
|
|
|
ret->requirements.insert(source["upgrades"].Float());
|
|
|
|
ret->upgrade = source["upgrades"].Float();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret->upgrade = -1;
|
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
town.buildings[ret->bid] = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTownHandler::loadBuildings(CTown &town, const JsonNode & source)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(const JsonNode &node, source.Vector())
|
|
|
|
{
|
|
|
|
loadBuilding(town, node);
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 06:10:56 +03:00
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
void CTownHandler::loadStructure(CTown &town, const JsonNode & source)
|
|
|
|
{
|
|
|
|
CStructure * ret = new CStructure;
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
if (source["id"].isNull())
|
|
|
|
{
|
|
|
|
ret->building = nullptr;
|
|
|
|
ret->buildable = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret->building = town.buildings[source["id"].Float()];
|
|
|
|
|
|
|
|
if (source["builds"].isNull())
|
|
|
|
ret->buildable = ret->building;
|
|
|
|
else
|
|
|
|
ret->buildable = town.buildings[source["builds"].Float()];
|
|
|
|
}
|
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
ret->pos.x = source["x"].Float();
|
|
|
|
ret->pos.y = source["y"].Float();
|
2012-09-05 15:49:23 +03:00
|
|
|
ret->pos.z = source["z"].Float();
|
2012-09-02 13:33:41 +03:00
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
ret->hiddenUpgrade = source["hidden"].Bool();
|
|
|
|
ret->defName = source["animation"].String();
|
2012-09-02 13:33:41 +03:00
|
|
|
ret->borderName = source["border"].String();
|
|
|
|
ret->areaName = source["area"].String();
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
town.clientInfo.structures.push_back(ret);
|
2012-09-02 13:33:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTownHandler::loadStructures(CTown &town, const JsonNode & source)
|
|
|
|
{
|
2012-09-05 15:49:23 +03:00
|
|
|
BOOST_FOREACH(const JsonNode &node, source.Vector())
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
|
|
|
loadStructure(town, node);
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 06:43:43 +03:00
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
void CTownHandler::loadTownHall(CTown &town, const JsonNode & source)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(const JsonNode &row, source.Vector())
|
|
|
|
{
|
|
|
|
std::vector< std::vector<int> > hallRow;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const JsonNode &box, row.Vector())
|
|
|
|
{
|
|
|
|
std::vector<int> hallBox;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const JsonNode &value, box.Vector())
|
|
|
|
{
|
|
|
|
hallBox.push_back(value.Float());
|
|
|
|
}
|
|
|
|
hallRow.push_back(hallBox);
|
2011-08-26 06:58:07 +03:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
town.clientInfo.hallSlots.push_back(hallRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 21:03:49 +03:00
|
|
|
CTown::ClientInfo::Point JsonToPoint(const JsonNode & node)
|
|
|
|
{
|
|
|
|
CTown::ClientInfo::Point ret;
|
|
|
|
ret.x = node["x"].Float();
|
|
|
|
ret.y = node["y"].Float();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source)
|
|
|
|
{
|
|
|
|
town.clientInfo.siegePrefix = source["imagePrefix"].String();
|
2012-12-10 23:08:00 +03:00
|
|
|
VLC->modh->identifiers.requestIdentifier(std::string("creature.") + source["shooter"].String(), [&town](si32 creature)
|
|
|
|
{
|
|
|
|
town.clientInfo.siegeShooter = creature;
|
|
|
|
});
|
|
|
|
|
2012-10-05 21:03:49 +03:00
|
|
|
town.clientInfo.siegeShooterCropHeight = source["shooterHeight"].Float();
|
|
|
|
|
|
|
|
auto & pos = town.clientInfo.siegePositions;
|
|
|
|
pos.resize(21);
|
|
|
|
|
|
|
|
pos[8] = JsonToPoint(source["towers"]["top"]["tower"]);
|
|
|
|
pos[17] = JsonToPoint(source["towers"]["top"]["battlement"]);
|
|
|
|
pos[20] = JsonToPoint(source["towers"]["top"]["creature"]);
|
|
|
|
|
|
|
|
pos[2] = JsonToPoint(source["towers"]["keep"]["tower"]);
|
|
|
|
pos[15] = JsonToPoint(source["towers"]["keep"]["battlement"]);
|
|
|
|
pos[18] = JsonToPoint(source["towers"]["keep"]["creature"]);
|
|
|
|
|
|
|
|
pos[3] = JsonToPoint(source["towers"]["bottom"]["tower"]);
|
|
|
|
pos[16] = JsonToPoint(source["towers"]["bottom"]["battlement"]);
|
|
|
|
pos[19] = JsonToPoint(source["towers"]["bottom"]["creature"]);
|
|
|
|
|
|
|
|
pos[9] = JsonToPoint(source["gate"]["gate"]);
|
|
|
|
pos[10] = JsonToPoint(source["gate"]["arch"]);
|
|
|
|
|
|
|
|
pos[7] = JsonToPoint(source["walls"]["upper"]);
|
|
|
|
pos[6] = JsonToPoint(source["walls"]["upperMid"]);
|
|
|
|
pos[5] = JsonToPoint(source["walls"]["bottomMid"]);
|
|
|
|
pos[4] = JsonToPoint(source["walls"]["bottom"]);
|
|
|
|
|
|
|
|
pos[13] = JsonToPoint(source["moat"]["moat"]);
|
|
|
|
pos[14] = JsonToPoint(source["moat"]["bank"]);
|
|
|
|
|
|
|
|
pos[11] = JsonToPoint(source["static"]["bottom"]);
|
|
|
|
pos[12] = JsonToPoint(source["static"]["top"]);
|
|
|
|
pos[1] = JsonToPoint(source["static"]["background"]);
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
void CTownHandler::loadClientData(CTown &town, const JsonNode & source)
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-09-22 18:10:15 +03:00
|
|
|
town.clientInfo.icons[0][0] = source["icons"]["village"]["normal"].Float();
|
|
|
|
town.clientInfo.icons[0][1] = source["icons"]["village"]["built"].Float();
|
|
|
|
town.clientInfo.icons[1][0] = source["icons"]["fort"]["normal"].Float();
|
|
|
|
town.clientInfo.icons[1][1] = source["icons"]["fort"]["built"].Float();
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
town.clientInfo.hallBackground = source["hallBackground"].String();
|
|
|
|
town.clientInfo.musicTheme = source["musicTheme"].String();
|
|
|
|
town.clientInfo.townBackground = source["townBackground"].String();
|
|
|
|
town.clientInfo.guildWindow = source["guildWindow"].String();
|
|
|
|
town.clientInfo.buildingsIcons = source["buildingsIcons"].String();
|
2011-08-26 07:12:46 +03:00
|
|
|
|
2012-10-05 22:57:28 +03:00
|
|
|
town.clientInfo.advMapVillage = source["adventureMap"]["village"].String();
|
|
|
|
town.clientInfo.advMapCastle = source["adventureMap"]["castle"].String();
|
|
|
|
town.clientInfo.advMapCapitol = source["adventureMap"]["capitol"].String();
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
loadTownHall(town, source["hallSlots"]);
|
|
|
|
loadStructures(town, source["structures"]);
|
2012-10-05 21:03:49 +03:00
|
|
|
loadSiegeScreen(town, source["siege"]);
|
2012-09-05 15:49:23 +03:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
void CTownHandler::loadTown(CTown &town, const JsonNode & source)
|
|
|
|
{
|
2012-12-11 15:12:46 +03:00
|
|
|
auto resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String());
|
|
|
|
if (resIter == boost::end(GameConstants::RESOURCE_NAMES))
|
|
|
|
town.primaryRes = 127; //Wood + Ore
|
|
|
|
else
|
|
|
|
town.primaryRes = resIter - boost::begin(GameConstants::RESOURCE_NAMES);
|
|
|
|
|
|
|
|
VLC->modh->identifiers.requestIdentifier(std::string("creature." + source["warMachine"].String()),
|
|
|
|
[&town](si32 creature)
|
|
|
|
{
|
|
|
|
town.warMachine = CArtHandler::convertMachineID(creature, true);
|
|
|
|
});
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
town.mageLevel = source["mageGuild"].Float();
|
2012-12-02 15:21:44 +03:00
|
|
|
town.names = source["names"].convertTo<std::vector<std::string> >();
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
// Horde building creature level
|
|
|
|
BOOST_FOREACH(const JsonNode &node, source["horde"].Vector())
|
|
|
|
{
|
|
|
|
town.hordeLvl[town.hordeLvl.size()] = node.Float();
|
2008-01-19 13:55:04 +02:00
|
|
|
}
|
2008-01-20 18:24:03 +02:00
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
const JsonVector & creatures = source["creatures"].Vector();
|
|
|
|
|
|
|
|
town.creatures.resize(creatures.size());
|
|
|
|
|
|
|
|
for (size_t i=0; i< creatures.size(); i++)
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-12-03 19:00:17 +03:00
|
|
|
const JsonVector & level = creatures[i].Vector();
|
|
|
|
|
|
|
|
town.creatures[i].resize(level.size());
|
|
|
|
|
|
|
|
for (size_t j=0; j<level.size(); j++)
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-12-03 19:00:17 +03:00
|
|
|
VLC->modh->identifiers.requestIdentifier(std::string("creature.") + level[j].String(), [=, &town](si32 creature)
|
|
|
|
{
|
|
|
|
town.creatures[i][j] = creature;
|
|
|
|
});
|
2008-01-27 15:18:18 +02:00
|
|
|
}
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2008-01-27 15:18:18 +02:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
loadBuildings(town, source["buildings"]);
|
|
|
|
loadClientData(town,source);
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2011-08-26 05:39:58 +03:00
|
|
|
|
2012-09-21 00:28:18 +03:00
|
|
|
void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source)
|
|
|
|
{
|
|
|
|
faction.puzzleMap.reserve(GameConstants::PUZZLE_MAP_PIECES);
|
|
|
|
|
|
|
|
std::string prefix = source["prefix"].String();
|
|
|
|
BOOST_FOREACH(const JsonNode &piece, source["pieces"].Vector())
|
|
|
|
{
|
|
|
|
size_t index = faction.puzzleMap.size();
|
|
|
|
SPuzzleInfo spi;
|
|
|
|
|
|
|
|
spi.x = piece["x"].Float();
|
|
|
|
spi.y = piece["y"].Float();
|
|
|
|
spi.whenUncovered = piece["index"].Float();
|
|
|
|
spi.number = index;
|
|
|
|
|
|
|
|
// filename calculation
|
|
|
|
std::ostringstream suffix;
|
|
|
|
suffix << std::setfill('0') << std::setw(2) << index;
|
|
|
|
|
|
|
|
spi.filename = prefix + suffix.str();
|
|
|
|
|
|
|
|
faction.puzzleMap.push_back(spi);
|
|
|
|
}
|
|
|
|
assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES);
|
|
|
|
}
|
|
|
|
|
2012-11-13 14:52:23 +03:00
|
|
|
void CTownHandler::load(const JsonNode &source)
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-09-05 15:49:23 +03:00
|
|
|
BOOST_FOREACH(auto & node, source.Struct())
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-12-16 16:47:53 +03:00
|
|
|
int id;
|
|
|
|
|
|
|
|
if (node.second["index"].isNull())
|
|
|
|
id = factions.rbegin()->first + 1;
|
|
|
|
else
|
|
|
|
id = node.second["index"].Float();
|
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
CFaction & faction = factions[id];
|
2012-09-02 13:33:41 +03:00
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
faction.factionID = id;
|
2012-10-05 16:11:26 +03:00
|
|
|
faction.name = node.second["name"].String();
|
2012-09-05 15:49:23 +03:00
|
|
|
|
|
|
|
faction.creatureBg120 = node.second["creatureBackground"]["120px"].String();
|
|
|
|
faction.creatureBg130 = node.second["creatureBackground"]["130px"].String();
|
|
|
|
|
2012-10-05 16:11:26 +03:00
|
|
|
faction.nativeTerrain = vstd::find_pos(GameConstants::TERRAIN_NAMES, node.second["nativeTerrain"].String());
|
|
|
|
int alignment = vstd::find_pos(EAlignment::names, node.second["alignment"].String());
|
|
|
|
if (alignment == -1)
|
|
|
|
faction.alignment = EAlignment::NEUTRAL;
|
2012-09-05 15:49:23 +03:00
|
|
|
else
|
2012-10-05 16:11:26 +03:00
|
|
|
faction.alignment = alignment;
|
2012-09-05 15:49:23 +03:00
|
|
|
|
|
|
|
if (!node.second["town"].isNull())
|
|
|
|
{
|
|
|
|
towns[id].typeID = id;
|
|
|
|
loadTown(towns[id], node.second["town"]);
|
|
|
|
}
|
2012-09-21 00:28:18 +03:00
|
|
|
if (!node.second["puzzleMap"].isNull())
|
|
|
|
loadPuzzle(faction, node.second["puzzleMap"]);
|
2012-11-13 14:52:23 +03:00
|
|
|
|
|
|
|
tlog3 << "Added faction: " << node.first << "\n";
|
2012-12-03 19:00:17 +03:00
|
|
|
VLC->modh->identifiers.registerObject(std::string("faction.") + node.first, faction.factionID);
|
2012-09-05 15:49:23 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
}
|
|
|
|
|
2012-09-02 13:33:41 +03:00
|
|
|
void CTownHandler::load()
|
2008-12-22 19:48:41 +02:00
|
|
|
{
|
2012-12-12 14:13:57 +03:00
|
|
|
JsonNode gameConf(ResourceID("config/gameConfig.json"));
|
|
|
|
JsonNode buildingsConf = JsonUtils::assembleFromFiles(gameConf["factions"].convertTo<std::vector<std::string> >());
|
2012-09-02 13:33:41 +03:00
|
|
|
|
|
|
|
JsonNode legacyConfig;
|
|
|
|
loadLegacyData(legacyConfig);
|
|
|
|
|
|
|
|
// semi-manually merge legacy config with towns json
|
2012-09-05 15:49:23 +03:00
|
|
|
|
|
|
|
for (size_t i=0; i< legacyConfig.Vector().size(); i++)
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-10-05 16:11:26 +03:00
|
|
|
JsonNode & legacyFaction = legacyConfig.Vector()[i];
|
2012-12-14 18:32:53 +03:00
|
|
|
JsonNode & outputFaction = buildingsConf[ETownType::names[i]];
|
2012-10-05 16:11:26 +03:00
|
|
|
|
|
|
|
if (outputFaction["name"].isNull())
|
|
|
|
outputFaction["name"] = legacyFaction["name"];
|
|
|
|
|
|
|
|
if (!outputFaction["town"].isNull())
|
2012-09-02 13:33:41 +03:00
|
|
|
{
|
2012-10-05 16:11:26 +03:00
|
|
|
if (outputFaction["town"]["names"].isNull())
|
|
|
|
outputFaction["town"]["names"] = legacyFaction["names"];
|
2012-09-02 13:33:41 +03:00
|
|
|
|
2012-10-05 16:11:26 +03:00
|
|
|
JsonNode & outputBuildings = outputFaction["town"]["buildings"];
|
|
|
|
JsonVector & legacyBuildings = legacyFaction["buildings"].Vector();
|
|
|
|
BOOST_FOREACH(JsonNode & building, outputBuildings.Vector())
|
|
|
|
{
|
|
|
|
if (vstd::contains(building.Struct(), "id") &&
|
|
|
|
legacyBuildings.size() > building["id"].Float() )
|
|
|
|
{
|
|
|
|
//find same buildings in legacy and json configs
|
|
|
|
JsonNode & legacyBuilding = legacyBuildings[building["id"].Float()];
|
|
|
|
|
|
|
|
if (!legacyBuilding.isNull()) //merge if h3 config was found for this building
|
2012-12-02 15:21:44 +03:00
|
|
|
JsonUtils::merge(building, legacyBuilding);
|
2012-10-05 16:11:26 +03:00
|
|
|
}
|
2012-09-02 13:33:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 14:52:23 +03:00
|
|
|
load(buildingsConf);
|
2009-10-04 05:02:45 +03:00
|
|
|
}
|
2012-11-20 20:53:45 +03:00
|
|
|
|
2012-12-02 15:21:44 +03:00
|
|
|
std::set<TFaction> CTownHandler::getDefaultAllowedFactions() const
|
2012-11-20 20:53:45 +03:00
|
|
|
{
|
2012-12-02 15:21:44 +03:00
|
|
|
std::set<TFaction> allowedFactions;
|
|
|
|
BOOST_FOREACH(auto town, towns)
|
2012-11-20 20:53:45 +03:00
|
|
|
{
|
2012-12-02 15:21:44 +03:00
|
|
|
allowedFactions.insert(town.first);
|
2012-11-20 20:53:45 +03:00
|
|
|
}
|
|
|
|
return allowedFactions;
|
|
|
|
}
|