mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Game runs without crash
This commit is contained in:
parent
756793992f
commit
9bb8f2a971
@ -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.");
|
||||
|
@ -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<CSkillHandler> skillh;
|
||||
ConstTransitivePtr<CObjectHandler> objh;
|
||||
ConstTransitivePtr<CObjectClassesHandler> objtypeh;
|
||||
ConstTransitivePtr<ObstacleHandler> obstacleHandler;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CMapHandler * mh;
|
||||
CTownHandler * townh;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,6 +26,7 @@
|
||||
#include "CSkillHandler.h"
|
||||
#include "ScriptHandler.h"
|
||||
#include "BattleFieldHandler.h"
|
||||
#include "ObstacleHandler.h"
|
||||
|
||||
#include <vstd/StringUtils.h>
|
||||
|
||||
@ -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?
|
||||
}
|
||||
|
||||
|
@ -295,9 +295,14 @@ BattleField BattleField::fromString(std::string identifier)
|
||||
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)
|
||||
|
@ -1126,13 +1126,13 @@ class BattleField : public BaseForID<BattleField, si32>
|
||||
DLL_LINKAGE static BattleField fromString(std::string identifier);
|
||||
};
|
||||
|
||||
class ObstacleInfo;
|
||||
class Obstacle : public BaseForID<Obstacle, si32>
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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<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;
|
||||
}
|
||||
};
|
||||
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;
|
||||
info->defName = json["defname"].String();
|
||||
info->width = static_cast<si32>(json["width"].Float());
|
||||
info->height = static_cast<si32>(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<std::vector<si16>>();
|
||||
info->isAbsoluteObstacle = json["absolute"].Bool();
|
||||
if(info->isAbsoluteObstacle)
|
||||
absoluteObstacles.push_back(info->getId());
|
||||
else
|
||||
obstacles.push_back(info->getId());
|
||||
|
||||
const JsonNode config(mod, ResourceID("config/obstacles.json"));
|
||||
loadObstacles(config["obstacles"], false, obstacles);
|
||||
loadObstacles(config["absoluteObstacles"], true, absoluteObstacles);
|
||||
}*/
|
||||
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;
|
||||
}
|
||||
|
@ -18,6 +18,14 @@
|
||||
|
||||
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;
|
||||
si32 iconIndex;
|
||||
std::string name;
|
||||
@ -43,6 +51,10 @@ struct DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle>
|
||||
|
||||
template <typename Handler> 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<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService>
|
||||
{
|
||||
public:
|
||||
void loadObstacles();
|
||||
std::vector<Obstacle> absoluteObstacles;
|
||||
std::vector<Obstacle> obstacles;
|
||||
|
||||
std::vector<ObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
|
||||
std::vector<ObstacleInfo> 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<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)
|
||||
{
|
||||
|
@ -219,6 +219,8 @@ void LibClasses::init(bool onlyEssential)
|
||||
|
||||
createHandler(battlefieldsHandler, "Battlefields", pomtime);
|
||||
|
||||
createHandler(obstacleHandler, "Obstacles", pomtime);
|
||||
|
||||
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());
|
||||
|
||||
modh->load();
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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()");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user