mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
parent
1a78df69f2
commit
3cc8afc046
@ -38,7 +38,6 @@ void CGameInfo::setFromLib()
|
||||
skillh = VLC->skillh;
|
||||
objtypeh = VLC->objtypeh;
|
||||
battleFieldHandler = VLC->battlefieldsHandler;
|
||||
obstacleHandler = VLC->obstacleHandler;
|
||||
}
|
||||
|
||||
const ArtifactService * CGameInfo::artifacts() const
|
||||
@ -86,11 +85,6 @@ 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,7 +32,6 @@ class CGameState;
|
||||
class IMainVideoPlayer;
|
||||
class CServerHandler;
|
||||
class BattleFieldHandler;
|
||||
class ObstacleHandler;
|
||||
|
||||
class CMap;
|
||||
|
||||
@ -63,7 +62,6 @@ 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;
|
||||
|
||||
@ -79,7 +77,6 @@ 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,7 +26,6 @@
|
||||
#include "CSkillHandler.h"
|
||||
#include "ScriptHandler.h"
|
||||
#include "BattleFieldHandler.h"
|
||||
#include "ObstacleHandler.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("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?
|
||||
}
|
||||
|
||||
|
@ -294,15 +294,10 @@ 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 getInfo()->identifier;
|
||||
return VLC->obstacles()->getById(*this)->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)
|
||||
|
||||
DLL_LINKAGE const ObstacleInfo * getInfo() const;
|
||||
///json serialization helpers
|
||||
DLL_LINKAGE operator std::string() const;
|
||||
|
||||
DLL_LINKAGE static Obstacle fromString(std::string identifier);
|
||||
};
|
||||
|
||||
|
@ -76,40 +76,35 @@ bool ObstacleInfo::isAppropriate(const Terrain & terrainType, const BattleField
|
||||
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();
|
||||
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());
|
||||
|
||||
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;
|
||||
//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);
|
||||
}*/
|
||||
}
|
||||
|
@ -18,14 +18,6 @@
|
||||
|
||||
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;
|
||||
@ -51,10 +43,6 @@ 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;
|
||||
@ -73,17 +61,10 @@ public:
|
||||
class ObstacleHandler: public CHandlerBase<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService>
|
||||
{
|
||||
public:
|
||||
std::vector<Obstacle> absoluteObstacles;
|
||||
std::vector<Obstacle> obstacles;
|
||||
void loadObstacles();
|
||||
|
||||
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;
|
||||
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
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
|
@ -218,8 +218,6 @@ 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());
|
||||
|
||||
|
@ -254,11 +254,11 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain,
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
@ -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].getInfo()->blockedTiles.size() / 2;
|
||||
tilesToBlock -= (int)VLC->obstacleHandler->absoluteObstacles[obstPtr->ID].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].getInfo();
|
||||
const ObstacleInfo &obi = VLC->obstacleHandler->obstacles[obid];
|
||||
|
||||
auto validPosition = [&](BattleHex pos) -> bool
|
||||
{
|
||||
|
@ -35,9 +35,9 @@ const ObstacleInfo & CObstacleInstance::getInfo() const
|
||||
switch(obstacleType)
|
||||
{
|
||||
case ABSOLUTE_OBSTACLE:
|
||||
return *VLC->obstacleHandler->absoluteObstacles[ID].getInfo();
|
||||
return VLC->obstacleHandler->absoluteObstacles[ID];
|
||||
case USUAL:
|
||||
return *VLC->obstacleHandler->obstacles[ID].getInfo();
|
||||
return VLC->obstacleHandler->obstacles[ID];
|
||||
default:
|
||||
throw std::runtime_error("Unknown obstacle type in CObstacleInstance::getInfo()");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user