From 9bb8f2a9718a0fcbe6c8ab5921926ed61a5043d1 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sun, 28 Aug 2022 04:27:08 +0400 Subject: [PATCH] Game runs without crash --- client/CGameInfo.cpp | 6 + client/CGameInfo.h | 3 + config/obstacles.json | 633 ++++++++++++++++++------------- lib/CModHandler.cpp | 2 + lib/GameConstants.cpp | 7 +- lib/GameConstants.h | 4 +- lib/ObstacleHandler.cpp | 63 +-- lib/ObstacleHandler.h | 25 +- lib/VCMI_Lib.cpp | 2 + lib/battle/BattleInfo.cpp | 8 +- lib/battle/CObstacleInstance.cpp | 4 +- 11 files changed, 460 insertions(+), 297 deletions(-) diff --git a/client/CGameInfo.cpp b/client/CGameInfo.cpp index 3c8eb86fb..d8c58296a 100644 --- a/client/CGameInfo.cpp +++ b/client/CGameInfo.cpp @@ -38,6 +38,7 @@ void CGameInfo::setFromLib() skillh = VLC->skillh; objtypeh = VLC->objtypeh; battleFieldHandler = VLC->battlefieldsHandler; + obstacleHandler = VLC->obstacleHandler; } const ArtifactService * CGameInfo::artifacts() const @@ -85,6 +86,11 @@ const SkillService * CGameInfo::skills() const return globalServices->skills(); } +const ObstacleService * CGameInfo::obstacles() const +{ + return globalServices->obstacles(); +} + void CGameInfo::updateEntity(Metatype metatype, int32_t index, const JsonNode & data) { logGlobal->error("CGameInfo::updateEntity call is not expected."); diff --git a/client/CGameInfo.h b/client/CGameInfo.h index b93924873..70b56905c 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -32,6 +32,7 @@ class CGameState; class IMainVideoPlayer; class CServerHandler; class BattleFieldHandler; +class ObstacleHandler; class CMap; @@ -62,6 +63,7 @@ public: const spells::Service * spells() const override; const SkillService * skills() const override; const BattleFieldService * battlefields() const override; + const ObstacleService * obstacles() const override; void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override; @@ -77,6 +79,7 @@ public: ConstTransitivePtr skillh; ConstTransitivePtr objh; ConstTransitivePtr objtypeh; + ConstTransitivePtr obstacleHandler; CGeneralTextHandler * generaltexth; CMapHandler * mh; CTownHandler * townh; diff --git a/config/obstacles.json b/config/obstacles.json index 22a944f3c..d2a7116c6 100644 --- a/config/obstacles.json +++ b/config/obstacles.json @@ -11,1225 +11,1346 @@ // * "defname" is name of the graphics. It's def file for usual obstacles and bitmap for the absolute ones. { -"obstacles" : [ + "0": { - "id" : 0, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObDino1.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "1": { - "id" : 1, "allowedTerrain" : ["dirt", "sand", "rough", "subterra"], "specialBattlefields" : ["sand_shore"], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObDino2.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "2": { - "id" : 2, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 4, "height" : 2, "blockedTiles" : [0, 1, -14, -15, -16], "defname" : "ObDino3.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "3": { - "id" : 3, "allowedTerrain" : ["dirt", "rough"], "specialBattlefields" : ["cursed_ground"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObSkel1.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "4": { - "id" : 4, "allowedTerrain" : ["dirt", "rough", "subterra"], "specialBattlefields" : ["sand_shore", "cursed_ground"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObSkel2.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "5": { - "id" : 5, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 4, "height" : 2, "blockedTiles" : [1, 2, 3], "defname" : "ObBDT01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "6": { - "id" : 6, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [-15, -16], "defname" : "ObDRk01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "7": { - "id" : 7, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 2, "blockedTiles" : [0, 1], "defname" : "ObDRk02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "8": { - "id" : 8, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 2, "blockedTiles" : [-16], "defname" : "ObDRk03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "9": { - "id" : 9, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 2, "blockedTiles" : [0, 1], "defname" : "ObDRk04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "10": { - "id" : 10, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 2, "blockedTiles" : [0, 1], "defname" : "ObDSh01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "11": { - "id" : 11, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObDTF03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "12": { - "id" : 12, "allowedTerrain" : ["dirt", "rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 3, "blockedTiles" : [0, 1, 2, 3], "defname" : "ObDtS03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "13": { - "id" : 13, "allowedTerrain" : ["dirt", "rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 2, "blockedTiles" : [1, 2, -15], "defname" : "ObDtS04.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "14": { - "id" : 14, "allowedTerrain" : ["dirt", "rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 2, "blockedTiles" : [2, -15, -16], "defname" : "ObDtS14.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "15": { - "id" : 15, "allowedTerrain" : ["dirt", "rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 3, "blockedTiles" : [1, -16, -33], "defname" : "ObDtS15.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "16": { - "id" : 16, "allowedTerrain" : ["sand"], "specialBattlefields" : [], "width" : 4, "height" : 4, "blockedTiles" : [-15, -16, -32, -33, -48, -49], "defname" : "ObDsM01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "17": { - "id" : 17, "allowedTerrain" : ["sand"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [1, -15, -16], "defname" : "ObDsS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "18": { - "id" : 18, "allowedTerrain" : ["sand"], "specialBattlefields" : [], "width" : 4, "height" : 2, "blockedTiles" : [1, 2, 3, -15, -16], "defname" : "ObDsS17.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "19": { - "id" : 19, "allowedTerrain" : ["grass", "swamp"], "specialBattlefields" : [], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObGLg01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "20": { - "id" : 20, "allowedTerrain" : ["grass", "swamp"], "specialBattlefields" : ["magic_plains"], "width" : 2, "height" : 2, "blockedTiles" : [0, 1], "defname" : "ObGRk01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "21": { - "id" : 21, "allowedTerrain" : ["grass", "swamp"], "specialBattlefields" : [], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObGSt01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "22": { - "id" : 22, "allowedTerrain" : ["grass"], "specialBattlefields" : ["magic_plains"], "width" : 6, "height" : 2, "blockedTiles" : [1, 2, 3, 4, -13, -14, -15, -16], "defname" : "ObGrS01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "23": { - "id" : 23, "allowedTerrain" : ["grass"], "specialBattlefields" : [], "width" : 7, "height" : 1, "blockedTiles" : [1, 2], "defname" : "OBGrS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "24": { - "id" : 24, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 1, "blockedTiles" : [0, 1, 2], "defname" : "ObSnS01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "25": { - "id" : 25, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 5, "height" : 1, "blockedTiles" : [1, 2, 3, 4], "defname" : "ObSnS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "26": { - "id" : 26, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 3, "blockedTiles" : [0, -16, -33], "defname" : "ObSnS03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "27": { - "id" : 27, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 1, "blockedTiles" : [0, 1, 2], "defname" : "ObSnS04.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "28": { - "id" : 28, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 1, "blockedTiles" : [1], "defname" : "ObSnS05.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "29": { - "id" : 29, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [1, 2], "defname" : "ObSnS06.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "30": { - "id" : 30, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObSnS07.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "31": { - "id" : 31, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObSnS08.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "32": { - "id" : 32, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 7, "height" : 2, "blockedTiles" : [2, 3, 4, 5, -13, -14, -15, -16], "defname" : "ObSnS09.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "33": { - "id" : 33, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 5, "height" : 5, "blockedTiles" : [3, -13, -14, -15, -33, -49, -66], "defname" : "ObSnS10.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "34": { - "id" : 34, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 2, "height" : 2, "blockedTiles" : [0], "defname" : "ObSwS01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "35": { - "id" : 35, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 8, "height" : 3, "blockedTiles" : [-10, -11, -12, -13, -14, -15, -16], "defname" : "ObSwS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "36": { - "id" : 36, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObSwS03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "37": { - "id" : 37, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 3, "height" : 1, "blockedTiles" : [0, 1, 2], "defname" : "ObSwS04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "38": { - "id" : 38, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 5, "height" : 4, "blockedTiles" : [-13, -14, -15, -16, -30, -31, -32, -33], "defname" : "ObSwS11b.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "39": { - "id" : 39, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 4, "height" : 3, "blockedTiles" : [-16, -17, -31, -32, -33, -34], "defname" : "ObSwS13a.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "40": { - "id" : 40, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 2, "height" : 2, "blockedTiles" : [0, 1, -16], "defname" : "ObRgS01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "41": { - "id" : 41, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 4, "height" : 3, "blockedTiles" : [-14, -15, -16, -32, -33], "defname" : "ObRgS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "42": { - "id" : 42, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 2, "blockedTiles" : [1, 2, -15, -16], "defname" : "ObRgS03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "43": { - "id" : 43, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 3, "blockedTiles" : [-16, -32, -33], "defname" : "ObRgS04.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "44": { - "id" : 44, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 3, "height" : 3, "blockedTiles" : [-15, -16, -32], "defname" : "ObRgS05.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "45": { - "id" : 45, "allowedTerrain" : ["subterra"], "specialBattlefields" : [], "width" : 3, "height" : 3, "blockedTiles" : [0, 1, 2, -15, -16], "defname" : "ObSuS01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "46": { - "id" : 46, "allowedTerrain" : ["subterra"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObSuS02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "47": { - "id" : 47, "allowedTerrain" : ["subterra"], "specialBattlefields" : [], "width" : 4, "height" : 3, "blockedTiles" : [0, 1, 2, 3, -14, -15, -16], "defname" : "ObSuS11b.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "48": { - "id" : 48, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 4, "height" : 3, "blockedTiles" : [-14, -32, -33], "defname" : "ObLvS01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "49": { - "id" : 49, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 4, "height" : 2, "blockedTiles" : [0, 1, 2, -14, -15, -16], "defname" : "ObLvS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "50": { - "id" : 50, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 5, "height" : 3, "blockedTiles" : [-13, -14, -15, -30, -31, -32, -33], "defname" : "ObLvS03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "51": { - "id" : 51, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObLvS04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "52": { - "id" : 52, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 4, "height" : 4, "blockedTiles" : [-14, -15, -32, -33, -49, -50], "defname" : "ObLvS09.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "53": { - "id" : 53, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 5, "height" : 3, "blockedTiles" : [-13, -14, -15, -16, -30, -31], "defname" : "ObLvS17.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "54": { - "id" : 54, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 5, "height" : 3, "blockedTiles" : [-13, -14, -15, -16, -31, -32, -33], "defname" : "ObLvS22.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "55": { - "id" : 55, "allowedTerrain" : ["water"], "specialBattlefields" : [], "width" : 3, "height" : 3, "blockedTiles" : [-15, -16, -33], "defname" : "ObBtS04.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "56": { - "id" : 56, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 3, "height" : 2, "blockedTiles" : [1, -15, -16], "defname" : "ObBhS02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "57": { - "id" : 57, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObBhS03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "58": { - "id" : 58, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 5, "height" : 2, "blockedTiles" : [1, 2, 3, -14, -15, -16], "defname" : "ObBhS11a.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "59": { - "id" : 59, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 4, "height" : 2, "blockedTiles" : [1, 2, -14, -15], "defname" : "ObBhS12b.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "60": { - "id" : 60, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 2, "height" : 2, "blockedTiles" : [0, 1, -16], "defname" : "ObBhS14b.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "61": { - "id" : 61, "allowedTerrain" : [], "specialBattlefields" : ["holy_ground"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObHGs00.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "62": { - "id" : 62, "allowedTerrain" : [], "specialBattlefields" : ["holy_ground"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObHGs01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "63": { - "id" : 63, "allowedTerrain" : [], "specialBattlefields" : ["holy_ground"], "width" : 3, "height" : 3, "blockedTiles" : [1], "defname" : "ObHGs02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "64": { - "id" : 64, "allowedTerrain" : [], "specialBattlefields" : ["holy_ground"], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObHGs03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "65": { - "id" : 65, "allowedTerrain" : [], "specialBattlefields" : ["holy_ground"], "width" : 4, "height" : 3, "blockedTiles" : [0, 1, 2, 3], "defname" : "ObHGs04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "66": { - "id" : 66, "allowedTerrain" : [], "specialBattlefields" : ["evil_fog"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObEFs00.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "67": { - "id" : 67, "allowedTerrain" : [], "specialBattlefields" : ["evil_fog"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObEFs01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "68": { - "id" : 68, "allowedTerrain" : [], "specialBattlefields" : ["evil_fog"], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2], "defname" : "ObEFs02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "69": { - "id" : 69, "allowedTerrain" : [], "specialBattlefields" : ["evil_fog"], "width" : 4, "height" : 2, "blockedTiles" : [1, 2], "defname" : "ObEFs03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "70": { - "id" : 70, "allowedTerrain" : [], "specialBattlefields" : ["evil_fog"], "width" : 6, "height" : 2, "blockedTiles" : [1, 2, 3, -12, -13], "defname" : "ObEFs04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "71": { - "id" : 71, "allowedTerrain" : [], "specialBattlefields" : ["clover_field"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObCFs00.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "72": { - "id" : 72, "allowedTerrain" : [], "specialBattlefields" : ["clover_field"], "width" : 3, "height" : 1, "blockedTiles" : [0, 1, 2], "defname" : "ObCFs01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "73": { - "id" : 73, "allowedTerrain" : [], "specialBattlefields" : ["clover_field"], "width" : 3, "height" : 2, "blockedTiles" : [1, 2, -15, -16], "defname" : "ObCFs02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "74": { - "id" : 74, "allowedTerrain" : [], "specialBattlefields" : ["clover_field"], "width" : 4, "height" : 2, "blockedTiles" : [0, 1, 2, -14, -15, -16], "defname" : "ObCFs03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "75": { - "id" : 75, "allowedTerrain" : [], "specialBattlefields" : ["lucid_pools"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObLPs00.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "76": { - "id" : 76, "allowedTerrain" : [], "specialBattlefields" : ["lucid_pools"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObLPs01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "77": { - "id" : 77, "allowedTerrain" : [], "specialBattlefields" : ["lucid_pools"], "width" : 3, "height" : 2, "blockedTiles" : [0, -15, -16], "defname" : "ObLPs02.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "78": { - "id" : 78, "allowedTerrain" : [], "specialBattlefields" : ["lucid_pools"], "width" : 5, "height" : 2, "blockedTiles" : [1, 2, 3, -13, -14, -15, -16], "defname" : "ObLPs03.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "79": { - "id" : 79, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObFFs00.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "80": { - "id" : 80, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObFFs01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "81": { - "id" : 81, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 3, "height" : 2, "blockedTiles" : [0, 1, 2, -15], "defname" : "ObFFs02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "82": { - "id" : 82, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 4, "height" : 2, "blockedTiles" : [1, 2, 3, -15, -16], "defname" : "ObFFs03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "83": { - "id" : 83, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 3, "height" : 3, "blockedTiles" : [0, 1, 2, 3, -14, -15, -16], "defname" : "ObFFs04.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "84": { - "id" : 84, "allowedTerrain" : [], "specialBattlefields" : ["rocklands"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObRLs00.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "85": { - "id" : 85, "allowedTerrain" : [], "specialBattlefields" : ["rocklands"], "width" : 2, "height" : 1, "blockedTiles" : [0, 1], "defname" : "ObRLs01.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "86": { - "id" : 86, "allowedTerrain" : [], "specialBattlefields" : ["rocklands"], "width" : 3, "height" : 1, "blockedTiles" : [0, 1, 2], "defname" : "ObRLs02.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "87": { - "id" : 87, "allowedTerrain" : [], "specialBattlefields" : ["rocklands"], "width" : 4, "height" : 2, "blockedTiles" : [1, 2, 3, -15, -16], "defname" : "ObRLs03.def", - "unknown" : 0 + "unknown" : 0, + "absolute" : false }, + "88": { - "id" : 88, "allowedTerrain" : [], "specialBattlefields" : ["magic_clouds"], "width" : 1, "height" : 1, "blockedTiles" : [0], "defname" : "ObMCs00.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "89": { - "id" : 89, "allowedTerrain" : [], "specialBattlefields" : ["magic_clouds"], "width" : 2, "height" : 2, "blockedTiles" : [1, -16], "defname" : "ObMCs01.def", - "unknown" : 1 + "unknown" : 1, + "absolute" : false }, + "90": { - "id" : 90, "allowedTerrain" : [], "specialBattlefields" : ["magic_clouds"], "width" : 4, "height" : 2, "blockedTiles" : [0, 1, -14, -15], "defname" : "ObMCs02.def", - "unknown" : 1 - } -], -"absoluteObstacles" : [ + "unknown" : 1, + "absolute" : false + }, + + "100": { - "id" : 0, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 124, "height" : 254, "blockedTiles" : [80, 94, 95, 96, 97, 105, 106, 107, 108, 109, 110], - "defname" : "ObDtL04.pcx" + "defname" : "ObDtL04.pcx", + "absolute" : true }, + "101": { - "id" : 1, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 256, "height" : 254, "blockedTiles" : [73, 91, 108, 109, 110, 111, 112, 113], - "defname" : "ObDtL06.pcx" + "defname" : "ObDtL06.pcx", + "absolute" : true }, + "102": { - "id" : 2, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 168, "height" : 212, "blockedTiles" : [60, 61, 62, 63, 64, 72, 73, 74, 75, 76, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149], - "defname" : "ObDtL10.pcx" + "defname" : "ObDtL10.pcx", + "absolute" : true }, + "103": { - "id" : 3, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 124, "height" : 254, "blockedTiles" : [88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98], - "defname" : "ObDtL02.pcx" + "defname" : "ObDtL02.pcx", + "absolute" : true }, + "104": { - "id" : 4, "allowedTerrain" : ["dirt"], "specialBattlefields" : [], "width" : 146, "height" : 254, "blockedTiles" : [76, 77, 78, 79, 80, 89, 90, 91, 92, 93], - "defname" : "ObDtL03.pcx" + "defname" : "ObDtL03.pcx", + "absolute" : true }, + "105": { - "id" : 5, "allowedTerrain" : ["grass"], "specialBattlefields" : [], "width" : 173, "height" : 221, "blockedTiles" : [55, 56, 57, 58, 75, 76, 77, 95, 112, 113, 131], - "defname" : "ObGrL01.pcx" + "defname" : "ObGrL01.pcx", + "absolute" : true }, + "106": { - "id" : 6, "allowedTerrain" : ["grass"], "specialBattlefields" : [], "width" : 180, "height" : 264, "blockedTiles" : [81, 91, 92, 93, 94, 95, 96, 97, 98, 106, 107, 123], - "defname" : "ObGrL02.pcx" + "defname" : "ObGrL02.pcx", + "absolute" : true }, + "107": { - "id" : 7, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 166, "height" : 255, "blockedTiles" : [76, 77, 78, 79, 91, 92, 93, 97, 98, 106, 107, 108], - "defname" : "ObSnL01.pcx" + "defname" : "ObSnL01.pcx", + "absolute" : true }, + "108": { - "id" : 8, "allowedTerrain" : ["snow"], "specialBattlefields" : [], "width" : 302, "height" : 172, "blockedTiles" : [41, 42, 43, 58, 75, 92, 108, 126, 143], - "defname" : "ObSnL14.pcx" + "defname" : "ObSnL14.pcx", + "absolute" : true }, + "109": { - "id" : 9, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 300, "height" : 170, "blockedTiles" : [40, 41, 58, 59, 74, 75, 92, 93, 109, 110, 111, 127, 128, 129, 130], - "defname" : "ObSwL15.pcx" + "defname" : "ObSwL15.pcx", + "absolute" : true }, + "110": { - "id" : 10, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 278, "height" : 171, "blockedTiles" : [43, 60, 61, 77, 93, 94, 95, 109, 110, 126, 127], - "defname" : "ObSwL14.pcx" + "defname" : "ObSwL14.pcx", + "absolute" : true }, + "111": { - "id" : 11, "allowedTerrain" : ["swamp"], "specialBattlefields" : [], "width" : 256, "height" : 254, "blockedTiles" : [74, 75, 76, 77, 91, 92, 93, 94, 95, 109, 110, 111, 112], - "defname" : "ObSwL22.pcx" + "defname" : "ObSwL22.pcx", + "absolute" : true }, + "112": { - "id" : 12, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 124, "height" : 254, "blockedTiles" : [77, 78, 79, 80, 81, 91, 92, 93, 94, 105, 106, 107], - "defname" : "ObLvL01.pcx" + "defname" : "ObLvL01.pcx", + "absolute" : true }, + "113": { - "id" : 13, "allowedTerrain" : ["lava"], "specialBattlefields" : [], "width" : 256, "height" : 128, "blockedTiles" : [43, 60, 61, 76, 77, 93, 109, 126, 127, 142, 143], - "defname" : "OBLvL02.pcx" + "defname" : "OBLvL02.pcx", + "absolute" : true }, + "114": { - "id" : 14, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 186, "height" : 212, "blockedTiles" : [55, 72, 90, 107, 125, 126, 127, 128, 129, 130, 131, 132], - "defname" : "ObRgL01.pcx" + "defname" : "ObRgL01.pcx", + "absolute" : true }, + "115": { - "id" : 15, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 347, "height" : 174, "blockedTiles" : [41, 59, 76, 94, 111, 129, 143, 144, 145], - "defname" : "ObRgL02.pcx" + "defname" : "ObRgL02.pcx", + "absolute" : true }, + "116": { - "id" : 16, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 294, "height" : 169, "blockedTiles" : [40, 41, 42, 43, 58, 75, 93, 110, 128, 145], - "defname" : "ObRgL03.pcx" + "defname" : "ObRgL03.pcx", + "absolute" : true }, + "117": { - "id" : 17, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 165, "height" : 257, "blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 89, 105], - "defname" : "ObRgL04.pcx" + "defname" : "ObRgL04.pcx", + "absolute" : true }, + "118": { - "id" : 18, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 208, "height" : 268, "blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 90, 91, 92, 93, 94, 95, 96, 97], - "defname" : "ObRgL05.pcx" + "defname" : "ObRgL05.pcx", + "absolute" : true }, + "119": { - "id" : 19, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 252, "height" : 254, "blockedTiles" : [73, 74, 75, 76, 77, 78, 91, 92, 93, 94], - "defname" : "ObRgL06.pcx" + "defname" : "ObRgL06.pcx", + "absolute" : true }, + "120": { - "id" : 20, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 278, "height" : 128, "blockedTiles" : [23, 40, 58, 75, 93, 110, 128, 145, 163], - "defname" : "ObRgL15.pcx" + "defname" : "ObRgL15.pcx", + "absolute" : true }, + "121": { - "id" : 21, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 208, "height" : 268, "blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 90, 91, 92, 93, 94, 95, 96, 97], - "defname" : "ObRgL05.pcx" + "defname" : "ObRgL05.pcx", + "absolute" : true }, + "122": { - "id" : 22, "allowedTerrain" : ["rough"], "specialBattlefields" : ["cursed_ground"], "width" : 168, "height" : 212, "blockedTiles" : [73, 74, 75, 76, 77, 78, 79, 90, 91, 92, 93, 94, 95, 96, 97, 106, 107, 108, 109, 110, 111, 112], - "defname" : "ObRgL22.pcx" + "defname" : "ObRgL22.pcx", + "absolute" : true }, + "123": { - "id" : 23, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 147, "height" : 264, "blockedTiles" : [72, 73, 74, 75, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98], - "defname" : "ObBhL02.pcx" + "defname" : "ObBhL02.pcx", + "absolute" : true }, + "124": { - "id" : 24, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 178, "height" : 262, "blockedTiles" : [71, 72, 73, 74, 75, 76, 77, 78, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98], - "defname" : "ObBhL03.pcx" + "defname" : "ObBhL03.pcx", + "absolute" : true }, + "125": { - "id" : 25, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 173, "height" : 257, "blockedTiles" : [72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 89, 90, 105, 106], - "defname" : "ObBhL05.pcx" + "defname" : "ObBhL05.pcx", + "absolute" : true }, + "126": { - "id" : 26, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 241, "height" : 272, "blockedTiles" : [73, 91, 108, 109, 110, 111, 112, 113], - "defname" : "ObBhL06.pcx" + "defname" : "ObBhL06.pcx", + "absolute" : true }, + "127": { - "id" : 27, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 261, "height" : 129, "blockedTiles" : [27, 28, 43, 44, 60, 61, 76, 77, 93, 94, 109, 110, 126, 127, 142, 143, 159], - "defname" : "ObBhL14.pcx" + "defname" : "ObBhL14.pcx", + "absolute" : true }, + "128": { - "id" : 28, "allowedTerrain" : [], "specialBattlefields" : ["sand_shore"], "width" : 180, "height" : 154, "blockedTiles" : [22, 38, 39, 40, 44, 45, 46, 55, 56, 57, 62, 63, 123, 124, 125, 130, 131, 140, 141, 146, 147, 148], - "defname" : "ObBhL16.pcx" + "defname" : "ObBhL16.pcx", + "absolute" : true }, + "129": { - "id" : 29, "allowedTerrain" : [], "specialBattlefields" : ["clover_field"], "width" : 304, "height" : 264, "blockedTiles" : [76, 77, 92, 93, 94, 95, 109, 110, 111], - "defname" : "ObCFL00.pcx" + "defname" : "ObCFL00.pcx", + "absolute" : true }, + "130": { - "id" : 30, "allowedTerrain" : [], "specialBattlefields" : ["lucid_pools"], "width" : 256, "height" : 257, "blockedTiles" : [76, 77, 78, 92, 93, 94, 107, 108, 109], - "defname" : "ObLPL00.pcx" + "defname" : "ObLPL00.pcx", + "absolute" : true }, + "131": { - "id" : 31, "allowedTerrain" : [], "specialBattlefields" : ["fiery_fields"], "width" : 257, "height" : 255, "blockedTiles" : [76, 77, 91, 92, 93, 94, 95, 108, 109, 110, 111], - "defname" : "ObFFL00.pcx" + "defname" : "ObFFL00.pcx", + "absolute" : true }, + "132": { - "id" : 32, "allowedTerrain" : [], "specialBattlefields" : ["rocklands"], "width" : 277, "height" : 218, "blockedTiles" : [60, 61, 75, 76, 77, 91, 92, 93, 94, 95], - "defname" : "ObRLL00.pcx" + "defname" : "ObRLL00.pcx", + "absolute" : true }, + "133": { - "id" : 33, "allowedTerrain" : [], "specialBattlefields" : ["magic_clouds"], "width" : 300, "height" : 214, "blockedTiles" : [59, 60, 74, 75, 76, 93, 94, 95, 111, 112], - "defname" : "ObMCL00.pcx" + "defname" : "ObMCL00.pcx", + "absolute" : true } -] - } diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index a7b2ace73..1c30b1208 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -26,6 +26,7 @@ #include "CSkillHandler.h" #include "ScriptHandler.h" #include "BattleFieldHandler.h" +#include "ObstacleHandler.h" #include @@ -435,6 +436,7 @@ void CContentHandler::init() handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template"))); handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script"))); handlers.insert(std::make_pair("battlefields", ContentTypeHandler(VLC->battlefieldsHandler, "battlefield"))); + handlers.insert(std::make_pair("obstacles", ContentTypeHandler(VLC->obstacleHandler, "obstacle"))); //TODO: any other types of moddables? } diff --git a/lib/GameConstants.cpp b/lib/GameConstants.cpp index 609df9b88..e7137de75 100644 --- a/lib/GameConstants.cpp +++ b/lib/GameConstants.cpp @@ -294,10 +294,15 @@ BattleField BattleField::fromString(std::string identifier) else return BattleField::NONE; } + +const ObstacleInfo * Obstacle::getInfo() const +{ + return VLC->obstacles()->getById(*this); +} Obstacle::operator std::string() const { - return VLC->obstacles()->getById(*this)->identifier; + return getInfo()->identifier; } Obstacle Obstacle::fromString(std::string identifier) diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 18fb48ba4..d86c760ce 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -1126,13 +1126,13 @@ class BattleField : public BaseForID DLL_LINKAGE static BattleField fromString(std::string identifier); }; +class ObstacleInfo; class Obstacle : public BaseForID { INSTID_LIKE_CLASS_COMMON(Obstacle, si32) - ///json serialization helpers + DLL_LINKAGE const ObstacleInfo * getInfo() const; DLL_LINKAGE operator std::string() const; - DLL_LINKAGE static Obstacle fromString(std::string identifier); }; diff --git a/lib/ObstacleHandler.cpp b/lib/ObstacleHandler.cpp index 2490f3134..38b2b283b 100644 --- a/lib/ObstacleHandler.cpp +++ b/lib/ObstacleHandler.cpp @@ -76,35 +76,40 @@ bool ObstacleInfo::isAppropriate(const Terrain & terrainType, const BattleField return vstd::contains(allowedTerrains, terrainType); } -void ObstacleHandler::loadObstacles() +ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { - auto loadObstacles = [](const JsonNode & node, bool absolute, std::vector & out) - { - for(const JsonNode &obs : node.Vector()) - { - out.emplace_back(); - ObstacleInfo & obi = out.back(); - obi.defName = obs["defname"].String(); - obi.width = static_cast(obs["width"].Float()); - obi.height = static_cast(obs["height"].Float()); - for(auto & t : obs["allowedTerrain"].Vector()) - obi.allowedTerrains.emplace_back(t.String()); - for(auto & t : obs["specialBattlefields"].Vector()) - obi.allowedSpecialBfields.emplace_back(t.String()); - obi.blockedTiles = obs["blockedTiles"].convertTo >(); - obi.isAbsoluteObstacle = absolute; - } - }; + auto * info = new ObstacleInfo(Obstacle(index), identifier); - //auto allConfigs = VLC->modh->getActiveMods(); - //allConfigs.insert(allConfigs.begin(), "core"); - /*for(auto & mod : allConfigs) - { - if(!CResourceHandler::get(mod)->existsResource(ResourceID("config/obstacles.json"))) - continue; - - const JsonNode config(mod, ResourceID("config/obstacles.json")); - loadObstacles(config["obstacles"], false, obstacles); - loadObstacles(config["absoluteObstacles"], true, absoluteObstacles); - }*/ + info->defName = json["defname"].String(); + info->width = static_cast(json["width"].Float()); + info->height = static_cast(json["height"].Float()); + for(auto & t : json["allowedTerrain"].Vector()) + info->allowedTerrains.emplace_back(t.String()); + for(auto & t : json["specialBattlefields"].Vector()) + info->allowedSpecialBfields.emplace_back(t.String()); + info->blockedTiles = json["blockedTiles"].convertTo>(); + info->isAbsoluteObstacle = json["absolute"].Bool(); + if(info->isAbsoluteObstacle) + absoluteObstacles.push_back(info->getId()); + else + obstacles.push_back(info->getId()); + + return info; +} + +std::vector ObstacleHandler::loadLegacyData(size_t dataSize) +{ + return std::vector(); +} + +std::vector ObstacleHandler::getDefaultAllowed() const +{ + return std::vector(); +} + +const std::vector & ObstacleHandler::getTypeNames() const +{ + static const std::vector types = std::vector { "obstacle" }; + + return types; } diff --git a/lib/ObstacleHandler.h b/lib/ObstacleHandler.h index 04fb119eb..e4b6fc5f4 100644 --- a/lib/ObstacleHandler.h +++ b/lib/ObstacleHandler.h @@ -18,6 +18,14 @@ struct DLL_LINKAGE ObstacleInfo : public EntityT { + ObstacleInfo(): obstacle(-1), width(0), height(0), isAbsoluteObstacle(false), iconIndex(0) + {} + + ObstacleInfo(Obstacle obstacle, std::string identifier) + : obstacle(obstacle), identifier(identifier), iconIndex(obstacle.getNum()), name(identifier), width(0), height(0), isAbsoluteObstacle(false) + { + } + Obstacle obstacle; si32 iconIndex; std::string name; @@ -43,6 +51,10 @@ struct DLL_LINKAGE ObstacleInfo : public EntityT template void serialize(Handler &h, const int version) { + h & obstacle; + h & iconIndex; + h & name; + h & identifier; h & defName; h & allowedTerrains; h & allowedSpecialBfields; @@ -61,10 +73,17 @@ public: class ObstacleHandler: public CHandlerBase { public: - void loadObstacles(); + std::vector absoluteObstacles; + std::vector obstacles; - std::vector obstacles; //info about obstacles that may be placed on battlefield - std::vector absoluteObstacles; //info about obstacles that may be placed on battlefield + ObstacleInfo * loadFromJson(const std::string & scope, + const JsonNode & json, + const std::string & identifier, + size_t index) override; + + const std::vector & getTypeNames() const override; + std::vector loadLegacyData(size_t dataSize) override; + std::vector getDefaultAllowed() const override; template void serialize(Handler & h, const int version) { diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 1ebb22783..81fd2bd99 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -218,6 +218,8 @@ void LibClasses::init(bool onlyEssential) createHandler(scriptHandler, "Script", pomtime); createHandler(battlefieldsHandler, "Battlefields", pomtime); + + createHandler(obstacleHandler, "Obstacles", pomtime); logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff()); diff --git a/lib/battle/BattleInfo.cpp b/lib/battle/BattleInfo.cpp index d8930762e..43157bd65 100644 --- a/lib/battle/BattleInfo.cpp +++ b/lib/battle/BattleInfo.cpp @@ -254,11 +254,11 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain, auto appropriateAbsoluteObstacle = [&](int id) { - return VLC->obstacleHandler->absoluteObstacles[id].isAppropriate(curB->terrainType, battlefieldType); + return VLC->obstacleHandler->absoluteObstacles[id].getInfo()->isAppropriate(curB->terrainType, battlefieldType); }; auto appropriateUsualObstacle = [&](int id) -> bool { - return VLC->obstacleHandler->obstacles[id].isAppropriate(curB->terrainType, battlefieldType); + return VLC->obstacleHandler->obstacles[id].getInfo()->isAppropriate(curB->terrainType, battlefieldType); }; if(r.rand(1,100) <= 40) //put cliff-like obstacle @@ -275,7 +275,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain, for(BattleHex blocked : obstPtr->getBlockedTiles()) blockedTiles.push_back(blocked); - tilesToBlock -= (int)VLC->obstacleHandler->absoluteObstacles[obstPtr->ID].blockedTiles.size() / 2; + tilesToBlock -= (int)VLC->obstacleHandler->absoluteObstacles[obstPtr->ID].getInfo()->blockedTiles.size() / 2; } catch(RangeGenerator::ExhaustedPossibilities &) { @@ -291,7 +291,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain, { auto tileAccessibility = curB->getAccesibility(); const int obid = obidgen.getSuchNumber(appropriateUsualObstacle); - const ObstacleInfo &obi = VLC->obstacleHandler->obstacles[obid]; + const ObstacleInfo &obi = *VLC->obstacleHandler->obstacles[obid].getInfo(); auto validPosition = [&](BattleHex pos) -> bool { diff --git a/lib/battle/CObstacleInstance.cpp b/lib/battle/CObstacleInstance.cpp index d70a3e78e..4cc0f4b3b 100644 --- a/lib/battle/CObstacleInstance.cpp +++ b/lib/battle/CObstacleInstance.cpp @@ -35,9 +35,9 @@ const ObstacleInfo & CObstacleInstance::getInfo() const switch(obstacleType) { case ABSOLUTE_OBSTACLE: - return VLC->obstacleHandler->absoluteObstacles[ID]; + return *VLC->obstacleHandler->absoluteObstacles[ID].getInfo(); case USUAL: - return VLC->obstacleHandler->obstacles[ID]; + return *VLC->obstacleHandler->obstacles[ID].getInfo(); default: throw std::runtime_error("Unknown obstacle type in CObstacleInstance::getInfo()"); }