From c605e2d10c2f133fc98c0e273c4a2f6569b85e06 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 22 Jun 2014 17:26:08 +0300 Subject: [PATCH 1/7] Gcc compile & warning fixes --- lib/mapObjects/CGTownInstance.cpp | 2 +- lib/rmg/CMapGenerator.cpp | 2 +- lib/rmg/CRmgTemplateZone.cpp | 22 ++++++++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index ed7d51c84..db903cbb9 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -10,10 +10,10 @@ #include "StdInc.h" #include "CGTownInstance.h" +#include "CObjectClassesHandler.h" #include "../NetPacks.h" #include "../CGeneralTextHandler.h" -#include "../mapObjects/CObjectClassesHandler.h" using namespace boost::assign; diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index bbf040013..79324a684 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -237,7 +237,7 @@ void CMapGenerator::createConnections() int3 guardPos(-1,-1,-1); auto otherZoneTiles = zoneB->getTileInfo(); - auto otherZoneCenter = zoneB->getPos(); + //auto otherZoneCenter = zoneB->getPos(); for (auto tile : tiles) { diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index a4e97d7c3..2a1a8a6ae 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -20,6 +20,8 @@ #include "../CSpellHandler.h" //for choosing random spells #include "../mapObjects/CObjectClassesHandler.h" +#include "../mapObjects/CGPandoraBox.h" +#include "../mapObjects/CRewardableObject.h" class CMap; class CMapEditManager; @@ -122,9 +124,16 @@ void CTileInfo::setTerrainType(ETerrainType value) terrain = value; } -CRmgTemplateZone::CRmgTemplateZone() : id(0), type(ETemplateZoneType::PLAYER_START), size(1), - terrainType (ETerrainType::GRASS), townType(0), townsAreSameType(false), matchTerrainToTown(true), totalDensity(0), - zoneMonsterStrength(EMonsterStrength::ZONE_NORMAL) +CRmgTemplateZone::CRmgTemplateZone() : + id(0), + type(ETemplateZoneType::PLAYER_START), + size(1), + townsAreSameType(false), + matchTerrainToTown(true), + townType(0), + terrainType (ETerrainType::GRASS), + zoneMonsterStrength(EMonsterStrength::ZONE_NORMAL), + totalDensity(0) { townTypes = getDefaultTownTypes(); terrainTypes = getDefaultTerrainTypes(); @@ -370,7 +379,7 @@ void CRmgTemplateZone::fractalize(CMapGenerator* gen) { if (gen->isFree(tile)) clearedTiles.push_back(tile); - else if (gen->isPossible(tile)); + else if (gen->isPossible(tile)) possibleTiles.insert(tile); } if (clearedTiles.empty()) //this should come from zone connections @@ -1032,8 +1041,8 @@ bool CRmgTemplateZone::findPlaceForObject(CMapGenerator* gen, CGObjectInstance* //si32 min_dist = sqrt(tileinfo.size()/density); int best_distance = 0; bool result = false; - si32 w = gen->map->width; - si32 h = gen->map->height; + //si32 w = gen->map->width; + //si32 h = gen->map->height; //logGlobal->infoStream() << boost::format("Min dist for density %f is %d") % density % min_dist; @@ -1265,6 +1274,7 @@ ObjectInfo CRmgTemplateZone::getRandomObject (CMapGenerator* gen, ui32 value) if (r <= t.first) return t.second; } + //FIXME: control reaches end of non-void function. Missing return? } void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen) From 1921bd22d6d10f66e5a6b3428512818d0eb73d8e Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 22 Jun 2014 17:39:56 +0300 Subject: [PATCH 2/7] Fixed banks config --- config/objects/creatureBanks.json | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/config/objects/creatureBanks.json b/config/objects/creatureBanks.json index b0d0c7218..6cba397be 100644 --- a/config/objects/creatureBanks.json +++ b/config/objects/creatureBanks.json @@ -68,7 +68,7 @@ ], "combat_value": 1013, "reward" : { - "value": 20000 + "value": 20000, "resources": { "wood" : 8, @@ -664,7 +664,7 @@ ] } } - } + }, "derelictShip" : { "index" :24, "handler": "bank", @@ -863,9 +863,9 @@ "gold" : 20000 }, "artifacts": [ - { "class" : "TREASURE" } - { "class" : "MINOR" } - { "class" : "MAJOR" } + { "class" : "TREASURE" }, + { "class" : "MINOR" }, + { "class" : "MAJOR" }, { "class" : "RELIC" } ] } @@ -886,9 +886,9 @@ "gold" : 30000 }, "artifacts": [ - { "class" : "MINOR" } - { "class" : "MAJOR" } - { "class" : "RELIC" } + { "class" : "MINOR" }, + { "class" : "MAJOR" }, + { "class" : "RELIC" }, { "class" : "RELIC" } ] } @@ -908,11 +908,10 @@ { "gold" : 40000 }, - "artifacts": [ 0, 0, 1, 3 ] "artifacts": [ - { "class" : "MAJOR" } - { "class" : "RELIC" } - { "class" : "RELIC" } + { "class" : "MAJOR" }, + { "class" : "RELIC" }, + { "class" : "RELIC" }, { "class" : "RELIC" } ] } @@ -932,11 +931,10 @@ { "gold" : 50000 }, - "artifacts": [ 0, 0, 0, 4 ] "artifacts": [ - { "class" : "RELIC" } - { "class" : "RELIC" } - { "class" : "RELIC" } + { "class" : "RELIC" }, + { "class" : "RELIC" }, + { "class" : "RELIC" }, { "class" : "RELIC" } ] } From 46d92f11cb0cc874df5bce59fb2194443c88c832 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Mon, 23 Jun 2014 10:24:49 +0400 Subject: [PATCH 3/7] Project update, fix build (!) register types as usual too huge --- lib/CMakeLists.txt | 1 + lib/VCMI_lib.cbp | 36 +++++++++++++++++++++++--- lib/mapObjects/CObjectClassesHandler.h | 2 +- lib/registerTypes/TypesMapObjects1.cpp | 9 ------- lib/registerTypes/TypesMapObjects3.cpp | 28 ++++++++++++++++++++ 5 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 lib/registerTypes/TypesMapObjects3.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 89ae588cb..f426a13a6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -94,6 +94,7 @@ set(lib_SRCS registerTypes/TypesClientPacks2.cpp registerTypes/TypesMapObjects1.cpp registerTypes/TypesMapObjects2.cpp + registerTypes/TypesMapObjects3.cpp registerTypes/TypesPregamePacks.cpp registerTypes/TypesServerPacks.cpp ) diff --git a/lib/VCMI_lib.cbp b/lib/VCMI_lib.cbp index 0bf21859e..aaff61c72 100644 --- a/lib/VCMI_lib.cbp +++ b/lib/VCMI_lib.cbp @@ -91,8 +91,6 @@ - - @@ -105,8 +103,6 @@ - - @@ -185,6 +181,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -205,6 +232,7 @@ + diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index 413deea9e..95b32fc49 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/lib/mapObjects/CObjectClassesHandler.h @@ -93,7 +93,7 @@ public: class CGObjectInstance; -class AObjectTypeHandler : public boost::noncopyable +class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable { RandomMapInfo rmgInfo; diff --git a/lib/registerTypes/TypesMapObjects1.cpp b/lib/registerTypes/TypesMapObjects1.cpp index 0a12c1fd8..961a16136 100644 --- a/lib/registerTypes/TypesMapObjects1.cpp +++ b/lib/registerTypes/TypesMapObjects1.cpp @@ -18,15 +18,6 @@ #include "../NetPacks.h" #include "../mapObjects/CObjectClassesHandler.h" -template void registerTypesMapObjectTypes>(CISer& s); -template void registerTypesMapObjectTypes>(COSer& s); -template void registerTypesMapObjectTypes>(CISer& s); -template void registerTypesMapObjectTypes>(COSer& s); -template void registerTypesMapObjectTypes(CSaveFile & s); -template void registerTypesMapObjectTypes(CLoadFile & s); -template void registerTypesMapObjectTypes(CTypeList & s); -template void registerTypesMapObjectTypes(CLoadIntegrityValidator & s); - template void registerTypesMapObjects1>(CISer& s); template void registerTypesMapObjects1>(COSer& s); template void registerTypesMapObjects1>(CISer& s); diff --git a/lib/registerTypes/TypesMapObjects3.cpp b/lib/registerTypes/TypesMapObjects3.cpp new file mode 100644 index 000000000..83cd20827 --- /dev/null +++ b/lib/registerTypes/TypesMapObjects3.cpp @@ -0,0 +1,28 @@ +#include "StdInc.h" +#include "RegisterTypes.h" + +#include "../mapping/CMapInfo.h" +#include "../StartInfo.h" +#include "../BattleState.h" +#include "../CGameState.h" +#include "../mapping/CMap.h" +#include "../CModHandler.h" +#include "../mapObjects/CObjectHandler.h" +#include "../CCreatureHandler.h" +#include "../VCMI_Lib.h" +#include "../CArtHandler.h" +#include "../CHeroHandler.h" +#include "../CSpellHandler.h" +#include "../CTownHandler.h" +#include "../mapping/CCampaignHandler.h" +#include "../NetPacks.h" +#include "../mapObjects/CObjectClassesHandler.h" + +template void registerTypesMapObjectTypes>(CISer& s); +template void registerTypesMapObjectTypes>(COSer& s); +template void registerTypesMapObjectTypes>(CISer& s); +template void registerTypesMapObjectTypes>(COSer& s); +template void registerTypesMapObjectTypes(CSaveFile & s); +template void registerTypesMapObjectTypes(CLoadFile & s); +template void registerTypesMapObjectTypes(CTypeList & s); +template void registerTypesMapObjectTypes(CLoadIntegrityValidator & s); From 47639832b14d8a78a19c8465d45df885c007cb20 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 23 Jun 2014 19:31:17 +0300 Subject: [PATCH 4/7] Probably fixed bug with map border rendering in rectangular maps --- client/mapHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 9e89e7504..84496ea4b 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -207,7 +207,7 @@ void CMapHandler::borderAndTerrainBitmapInit() terBitmapNum = 17; else if(i==(sizes.x) && j==(sizes.y)) terBitmapNum = 18; - else if(j == -1 && i > -1 && i < sizes.y) + else if(j == -1 && i > -1 && i < sizes.x) terBitmapNum = rand.nextInt(22, 23); else if(i == -1 && j > -1 && j < sizes.y) terBitmapNum = rand.nextInt(33, 34); From 06d17f709dd5c09abd78389d19a2bff98d6f96b0 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 23 Jun 2014 19:37:26 +0300 Subject: [PATCH 5/7] fixed compatibility code for resource-granting buildings --- lib/CTownHandler.cpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 10c9bc2cd..84ccec8c2 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -308,33 +308,32 @@ void CTownHandler::loadBuilding(CTown &town, const std::string & stringID, const ret->resources = TResources(source["cost"]); ret->produce = TResources(source["produce"]); - //for compatibility with older town mods + //MODS COMPATIBILITY FOR 0.96 if(!ret->produce.nonZero()) { - if (ret->bid == BuildingID::VILLAGE_HALL) ret->produce[Res::GOLD] = 500; - - if (ret->bid == BuildingID::TOWN_HALL) ret->produce[Res::GOLD] = 1000; - - if (ret->bid == BuildingID::CITY_HALL) ret->produce[Res::GOLD] = 2000; - - if (ret->bid == BuildingID::CAPITOL) ret->produce[Res::GOLD] = 4000; - - if (ret->bid == BuildingID::GRAIL) ret->produce[Res::GOLD] = 5000; - // - if (ret->bid == BuildingID::RESOURCE_SILO) - { - if ((ret->town->primaryRes != Res::WOOD) && (ret->town->primaryRes != Res::ORE) && (ret->town->primaryRes != Res::GOLD)) - ret->produce[ret->town->primaryRes] = 1; - else - { - if (ret->town->primaryRes == Res::GOLD) ret->produce[ret->town->primaryRes] = 500; - else + switch (ret->bid) { + break; case BuildingID::VILLAGE_HALL: ret->produce[Res::GOLD] = 500; + break; case BuildingID::TOWN_HALL : ret->produce[Res::GOLD] = 1000; + break; case BuildingID::CITY_HALL : ret->produce[Res::GOLD] = 2000; + break; case BuildingID::CAPITOL : ret->produce[Res::GOLD] = 4000; + break; case BuildingID::GRAIL : ret->produce[Res::GOLD] = 5000; + break; case BuildingID::RESOURCE_SILO : { - ret->produce[Res::WOOD] = 1; - ret->produce[Res::ORE] = 1; + switch (ret->town->primaryRes) + { + case Res::GOLD: + ret->produce[ret->town->primaryRes] = 500; + break; + case Res::WOOD_AND_ORE: + ret->produce[Res::WOOD] = 1; + ret->produce[Res::ORE] = 1; + break; + default: + ret->produce[ret->town->primaryRes] = 1; + break; + } } } - } } loadBuildingRequirements(town, *ret, source["requires"]); From 7c52db923a42269c3b01c9c16fca6dca5c66b6a5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 23 Jun 2014 20:10:08 +0300 Subject: [PATCH 6/7] Removed mods compatibility code from 0.95 --- lib/CHeroHandler.cpp | 14 +++----- lib/CTownHandler.cpp | 86 +++++++++++--------------------------------- 2 files changed, 24 insertions(+), 76 deletions(-) diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index b24aba25c..1a8414dbd 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -110,8 +110,6 @@ CHeroClass *CHeroClassHandler::loadFromJson(const JsonNode & node) heroClass->name = node["name"].String(); heroClass->affinity = vstd::find_pos(affinityStr, node["affinity"].String()); - if (heroClass->affinity >= 2) //FIXME: MODS COMPATIBILITY - heroClass->affinity = 0; for(const std::string & pSkill : PrimarySkill::names) { @@ -125,15 +123,11 @@ CHeroClass *CHeroClassHandler::loadFromJson(const JsonNode & node) heroClass->secSkillProbability.push_back(node["secondarySkills"][secSkill].Float()); } - //FIXME: MODS COMPATIBILITY - if (!node["commander"].isNull()) + VLC->modh->identifiers.requestIdentifier ("creature", node["commander"], + [=](si32 commanderID) { - VLC->modh->identifiers.requestIdentifier ("creature", node["commander"], - [=](si32 commanderID) - { - heroClass->commander = VLC->creh->creatures[commanderID]; - }); - } + heroClass->commander = VLC->creh->creatures[commanderID]; + }); heroClass->defaultTavernChance = node["defaultTavern"].Float(); for(auto & tavern : node["tavern"].Struct()) diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 84ccec8c2..a31d0a65e 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -272,24 +272,12 @@ void CTownHandler::loadBuildingRequirements(CTown &town, CBuilding & building, c { if (source.isNull()) return; - if (source.Vector()[0].getType() == JsonNode::DATA_FLOAT) - { - // MODS COMPATIBILITY - CBuilding::TRequired::OperatorAll required; - for(const JsonNode &building : source.Vector()) - required.expressions.push_back(BuildingID(building.Float())); - - building.requirements = CBuilding::TRequired(required); - } - else - { - BuildingRequirementsHelper hlp; - hlp.building = &building; - hlp.faction = town.faction; - hlp.json = source; - requirementsToLoad.push_back(hlp); - } + BuildingRequirementsHelper hlp; + hlp.building = &building; + hlp.faction = town.faction; + hlp.json = source; + requirementsToLoad.push_back(hlp); } void CTownHandler::loadBuilding(CTown &town, const std::string & stringID, const JsonNode & source) @@ -340,23 +328,17 @@ void CTownHandler::loadBuilding(CTown &town, const std::string & stringID, const if (!source["upgrades"].isNull()) { - //MODS COMPATIBILITY - if (source["upgrades"].getType() == JsonNode::DATA_FLOAT) - ret->upgrade = BuildingID(source["upgrades"].Float()); - else + // building id and upgrades can't be the same + if(stringID == source["upgrades"].String()) { - // building id and upgrades can't be the same - if(stringID == source["upgrades"].String()) - { - throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") % - stringID % town.faction->name)); - } - - VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["upgrades"], [=](si32 identifier) - { - ret->upgrade = BuildingID(identifier); - }); + throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") % + stringID % town.faction->name)); } + + VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["upgrades"], [=](si32 identifier) + { + ret->upgrade = BuildingID(identifier); + }); } else ret->upgrade = BuildingID::NONE; @@ -380,7 +362,6 @@ void CTownHandler::loadStructure(CTown &town, const std::string & stringID, cons { auto ret = new CStructure; - //Note: MODS COMPATIBILITY CODE ret->building = nullptr; ret->buildable = nullptr; @@ -398,17 +379,10 @@ void CTownHandler::loadStructure(CTown &town, const std::string & stringID, cons } else { - if (source["builds"].getType() == JsonNode::DATA_FLOAT) + VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["builds"], [=, &town](si32 identifier) mutable { - ret->buildable = town.buildings[BuildingID(source["builds"].Float())]; - } - else - { - VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["builds"], [=, &town](si32 identifier) mutable - { - ret->buildable = town.buildings[BuildingID(identifier)]; - }); - } + ret->buildable = town.buildings[BuildingID(identifier)]; + }); } ret->identifier = stringID; @@ -456,16 +430,10 @@ void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) auto & dst = dstBox[k]; auto & src = srcBox[k]; - //MODS COMPATIBILITY - if (src.getType() == JsonNode::DATA_FLOAT) - dst = BuildingID(src.Float()); - else + VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, src, [&](si32 identifier) { - VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, src, [&](si32 identifier) - { - dst = BuildingID(identifier); - }); - } + dst = BuildingID(identifier); + }); } } } @@ -672,20 +640,6 @@ CFaction * CTownHandler::loadFromJson(const JsonNode &source, std::string identi faction->name = source["name"].String(); faction->identifier = identifier; - //FIXME: MODS COMPATIBILITY - if (!source["commander"].isNull()) - { - VLC->modh->identifiers.requestIdentifier ("creature", source["commander"], - [=](si32 commanderID) - { - for (auto ptr : VLC->heroh->classes.heroClasses) - { - if (ptr->commander == nullptr && ptr->faction == faction->index) - ptr->commander = VLC->creh->creatures[commanderID]; - } - }); - } - faction->creatureBg120 = source["creatureBackground"]["120px"].String(); faction->creatureBg130 = source["creatureBackground"]["130px"].String(); From db49798b4d5f29d5cdd8df6a2a91309cb743cd42 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 23 Jun 2014 20:10:35 +0300 Subject: [PATCH 7/7] Fixed random artifact selection --- lib/mapObjects/JsonRandom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/JsonRandom.cpp b/lib/mapObjects/JsonRandom.cpp index ac001a589..e57b2483e 100644 --- a/lib/mapObjects/JsonRandom.cpp +++ b/lib/mapObjects/JsonRandom.cpp @@ -90,8 +90,8 @@ namespace JsonRandom for (auto & entry : value["slot"].Vector()) allowedPositions.insert(VLC->arth->stringToSlot(entry.String())); - if (value["minValue"].isNull()) minValue = value["minValue"].Float(); - if (value["maxValue"].isNull()) maxValue = value["maxValue"].Float(); + if (!value["minValue"].isNull()) minValue = value["minValue"].Float(); + if (!value["maxValue"].isNull()) maxValue = value["maxValue"].Float(); return VLC->arth->pickRandomArtifact(rng, [=](ArtifactID artID) -> bool {