1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Revert "Game runs without crash"

This reverts commit 9bb8f2a971.
This commit is contained in:
nordsoft 2022-09-04 15:47:58 +04:00
parent 1a78df69f2
commit 3cc8afc046
11 changed files with 297 additions and 460 deletions

View File

@ -38,7 +38,6 @@ void CGameInfo::setFromLib()
skillh = VLC->skillh; skillh = VLC->skillh;
objtypeh = VLC->objtypeh; objtypeh = VLC->objtypeh;
battleFieldHandler = VLC->battlefieldsHandler; battleFieldHandler = VLC->battlefieldsHandler;
obstacleHandler = VLC->obstacleHandler;
} }
const ArtifactService * CGameInfo::artifacts() const const ArtifactService * CGameInfo::artifacts() const
@ -86,11 +85,6 @@ const SkillService * CGameInfo::skills() const
return globalServices->skills(); return globalServices->skills();
} }
const ObstacleService * CGameInfo::obstacles() const
{
return globalServices->obstacles();
}
void CGameInfo::updateEntity(Metatype metatype, int32_t index, const JsonNode & data) void CGameInfo::updateEntity(Metatype metatype, int32_t index, const JsonNode & data)
{ {
logGlobal->error("CGameInfo::updateEntity call is not expected."); logGlobal->error("CGameInfo::updateEntity call is not expected.");

View File

@ -32,7 +32,6 @@ class CGameState;
class IMainVideoPlayer; class IMainVideoPlayer;
class CServerHandler; class CServerHandler;
class BattleFieldHandler; class BattleFieldHandler;
class ObstacleHandler;
class CMap; class CMap;
@ -63,7 +62,6 @@ public:
const spells::Service * spells() const override; const spells::Service * spells() const override;
const SkillService * skills() const override; const SkillService * skills() const override;
const BattleFieldService * battlefields() const override; const BattleFieldService * battlefields() const override;
const ObstacleService * obstacles() const override;
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override; void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
@ -79,7 +77,6 @@ public:
ConstTransitivePtr<CSkillHandler> skillh; ConstTransitivePtr<CSkillHandler> skillh;
ConstTransitivePtr<CObjectHandler> objh; ConstTransitivePtr<CObjectHandler> objh;
ConstTransitivePtr<CObjectClassesHandler> objtypeh; ConstTransitivePtr<CObjectClassesHandler> objtypeh;
ConstTransitivePtr<ObstacleHandler> obstacleHandler;
CGeneralTextHandler * generaltexth; CGeneralTextHandler * generaltexth;
CMapHandler * mh; CMapHandler * mh;
CTownHandler * townh; CTownHandler * townh;

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@
#include "CSkillHandler.h" #include "CSkillHandler.h"
#include "ScriptHandler.h" #include "ScriptHandler.h"
#include "BattleFieldHandler.h" #include "BattleFieldHandler.h"
#include "ObstacleHandler.h"
#include <vstd/StringUtils.h> #include <vstd/StringUtils.h>
@ -436,7 +435,6 @@ void CContentHandler::init()
handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template"))); 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("scripts", ContentTypeHandler(VLC->scriptHandler, "script")));
handlers.insert(std::make_pair("battlefields", ContentTypeHandler(VLC->battlefieldsHandler, "battlefield"))); 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? //TODO: any other types of moddables?
} }

View File

@ -294,15 +294,10 @@ BattleField BattleField::fromString(std::string identifier)
else else
return BattleField::NONE; return BattleField::NONE;
} }
const ObstacleInfo * Obstacle::getInfo() const
{
return VLC->obstacles()->getById(*this);
}
Obstacle::operator std::string() const Obstacle::operator std::string() const
{ {
return getInfo()->identifier; return VLC->obstacles()->getById(*this)->identifier;
} }
Obstacle Obstacle::fromString(std::string identifier) Obstacle Obstacle::fromString(std::string identifier)

View File

@ -1126,13 +1126,13 @@ class BattleField : public BaseForID<BattleField, si32>
DLL_LINKAGE static BattleField fromString(std::string identifier); DLL_LINKAGE static BattleField fromString(std::string identifier);
}; };
class ObstacleInfo;
class Obstacle : public BaseForID<Obstacle, si32> class Obstacle : public BaseForID<Obstacle, si32>
{ {
INSTID_LIKE_CLASS_COMMON(Obstacle, si32) INSTID_LIKE_CLASS_COMMON(Obstacle, si32)
DLL_LINKAGE const ObstacleInfo * getInfo() const; ///json serialization helpers
DLL_LINKAGE operator std::string() const; DLL_LINKAGE operator std::string() const;
DLL_LINKAGE static Obstacle fromString(std::string identifier); DLL_LINKAGE static Obstacle fromString(std::string identifier);
}; };

View File

@ -76,40 +76,35 @@ bool ObstacleInfo::isAppropriate(const Terrain & terrainType, const BattleField
return vstd::contains(allowedTerrains, terrainType); return vstd::contains(allowedTerrains, terrainType);
} }
ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) void ObstacleHandler::loadObstacles()
{ {
auto * info = new ObstacleInfo(Obstacle(index), identifier); auto loadObstacles = [](const JsonNode & node, bool absolute, std::vector<ObstacleInfo> & out)
{
for(const JsonNode &obs : node.Vector())
{
out.emplace_back();
ObstacleInfo & obi = out.back();
obi.defName = obs["defname"].String();
obi.width = static_cast<si32>(obs["width"].Float());
obi.height = static_cast<si32>(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<std::vector<si16> >();
obi.isAbsoluteObstacle = absolute;
}
};
info->defName = json["defname"].String(); //auto allConfigs = VLC->modh->getActiveMods();
info->width = static_cast<si32>(json["width"].Float()); //allConfigs.insert(allConfigs.begin(), "core");
info->height = static_cast<si32>(json["height"].Float()); /*for(auto & mod : allConfigs)
for(auto & t : json["allowedTerrain"].Vector()) {
info->allowedTerrains.emplace_back(t.String()); if(!CResourceHandler::get(mod)->existsResource(ResourceID("config/obstacles.json")))
for(auto & t : json["specialBattlefields"].Vector()) continue;
info->allowedSpecialBfields.emplace_back(t.String());
info->blockedTiles = json["blockedTiles"].convertTo<std::vector<si16>>(); const JsonNode config(mod, ResourceID("config/obstacles.json"));
info->isAbsoluteObstacle = json["absolute"].Bool(); loadObstacles(config["obstacles"], false, obstacles);
if(info->isAbsoluteObstacle) loadObstacles(config["absoluteObstacles"], true, absoluteObstacles);
absoluteObstacles.push_back(info->getId()); }*/
else
obstacles.push_back(info->getId());
return info;
}
std::vector<JsonNode> ObstacleHandler::loadLegacyData(size_t dataSize)
{
return std::vector<JsonNode>();
}
std::vector<bool> ObstacleHandler::getDefaultAllowed() const
{
return std::vector<bool>();
}
const std::vector<std::string> & ObstacleHandler::getTypeNames() const
{
static const std::vector<std::string> types = std::vector<std::string> { "obstacle" };
return types;
} }

View File

@ -18,14 +18,6 @@
struct DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle> struct DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle>
{ {
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; Obstacle obstacle;
si32 iconIndex; si32 iconIndex;
std::string name; std::string name;
@ -51,10 +43,6 @@ struct DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle>
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & obstacle;
h & iconIndex;
h & name;
h & identifier;
h & defName; h & defName;
h & allowedTerrains; h & allowedTerrains;
h & allowedSpecialBfields; h & allowedSpecialBfields;
@ -73,17 +61,10 @@ public:
class ObstacleHandler: public CHandlerBase<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService> class ObstacleHandler: public CHandlerBase<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService>
{ {
public: public:
std::vector<Obstacle> absoluteObstacles; void loadObstacles();
std::vector<Obstacle> obstacles;
ObstacleInfo * loadFromJson(const std::string & scope, std::vector<ObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
const JsonNode & json, std::vector<ObstacleInfo> absoluteObstacles; //info about obstacles that may be placed on battlefield
const std::string & identifier,
size_t index) override;
const std::vector<std::string> & getTypeNames() const override;
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
std::vector<bool> getDefaultAllowed() const override;
template <typename Handler> void serialize(Handler & h, const int version) template <typename Handler> void serialize(Handler & h, const int version)
{ {

View File

@ -218,8 +218,6 @@ void LibClasses::init(bool onlyEssential)
createHandler(scriptHandler, "Script", pomtime); createHandler(scriptHandler, "Script", pomtime);
createHandler(battlefieldsHandler, "Battlefields", pomtime); createHandler(battlefieldsHandler, "Battlefields", pomtime);
createHandler(obstacleHandler, "Obstacles", pomtime);
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff()); logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());

View File

@ -254,11 +254,11 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain,
auto appropriateAbsoluteObstacle = [&](int id) auto appropriateAbsoluteObstacle = [&](int id)
{ {
return VLC->obstacleHandler->absoluteObstacles[id].getInfo()->isAppropriate(curB->terrainType, battlefieldType); return VLC->obstacleHandler->absoluteObstacles[id].isAppropriate(curB->terrainType, battlefieldType);
}; };
auto appropriateUsualObstacle = [&](int id) -> bool auto appropriateUsualObstacle = [&](int id) -> bool
{ {
return VLC->obstacleHandler->obstacles[id].getInfo()->isAppropriate(curB->terrainType, battlefieldType); return VLC->obstacleHandler->obstacles[id].isAppropriate(curB->terrainType, battlefieldType);
}; };
if(r.rand(1,100) <= 40) //put cliff-like obstacle 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()) for(BattleHex blocked : obstPtr->getBlockedTiles())
blockedTiles.push_back(blocked); blockedTiles.push_back(blocked);
tilesToBlock -= (int)VLC->obstacleHandler->absoluteObstacles[obstPtr->ID].getInfo()->blockedTiles.size() / 2; tilesToBlock -= (int)VLC->obstacleHandler->absoluteObstacles[obstPtr->ID].blockedTiles.size() / 2;
} }
catch(RangeGenerator::ExhaustedPossibilities &) catch(RangeGenerator::ExhaustedPossibilities &)
{ {
@ -291,7 +291,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain,
{ {
auto tileAccessibility = curB->getAccesibility(); auto tileAccessibility = curB->getAccesibility();
const int obid = obidgen.getSuchNumber(appropriateUsualObstacle); const int obid = obidgen.getSuchNumber(appropriateUsualObstacle);
const ObstacleInfo &obi = *VLC->obstacleHandler->obstacles[obid].getInfo(); const ObstacleInfo &obi = VLC->obstacleHandler->obstacles[obid];
auto validPosition = [&](BattleHex pos) -> bool auto validPosition = [&](BattleHex pos) -> bool
{ {

View File

@ -35,9 +35,9 @@ const ObstacleInfo & CObstacleInstance::getInfo() const
switch(obstacleType) switch(obstacleType)
{ {
case ABSOLUTE_OBSTACLE: case ABSOLUTE_OBSTACLE:
return *VLC->obstacleHandler->absoluteObstacles[ID].getInfo(); return VLC->obstacleHandler->absoluteObstacles[ID];
case USUAL: case USUAL:
return *VLC->obstacleHandler->obstacles[ID].getInfo(); return VLC->obstacleHandler->obstacles[ID];
default: default:
throw std::runtime_error("Unknown obstacle type in CObstacleInstance::getInfo()"); throw std::runtime_error("Unknown obstacle type in CObstacleInstance::getInfo()");
} }