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

Fixed game startup

This commit is contained in:
Ivan Savenko 2022-12-20 20:26:54 +02:00
parent e1799379dd
commit 2de3178158
9 changed files with 50 additions and 42 deletions

View File

@ -10,6 +10,9 @@
"hero" : 156,
"spell" : 81,
"object" : 256,
"terrain" : 10,
"river" : 5,
"road" : 4,
"mapVersion" : 28 // max supported version, SoD
},

View File

@ -1,28 +1,28 @@
{
"waterRiver":
{
"originalRiverId": 1,
"index": 1,
"code": "rw", //must be 2 characters
"animation": "clrrvr",
"delta": "clrdelt"
},
"iceRiver":
{
"originalRiverId": 2,
"index": 2,
"code": "ri",
"animation": "icyrvr",
"delta": "icedelt"
},
"mudRiver":
{
"originalRiverId": 3,
"index": 3,
"code": "rm",
"animation": "mudrvr",
"delta": "muddelt"
},
"lavaRiver":
{
"originalRiverId": 4,
"index": 4,
"code": "rl",
"animation": "lavrvr",
"delta": "lavdelt"

View File

@ -1,21 +1,21 @@
{
"dirtRoad":
{
"originalRoadId": 1,
"index": 1,
"code": "pd", //must be 2 characters
"animation": "dirtrd",
"moveCost": 75
},
"gravelRoad":
{
"originalRoadId": 2,
"index": 2,
"code": "pg",
"animation": "gravrd",
"moveCost": 65
},
"cobblestoneRoad":
{
"originalRoadId": 3,
"index": 3,
"code": "pc",
"animation": "cobbrd",
"moveCost": 50

View File

@ -88,7 +88,7 @@
"minimapBlocked" : [ 90, 8, 0 ],
"music" : "Underground.mp3",
"tiles" : "SUBBTL",
"type" : "SUB",
"type" : [ "SUB" ],
"code" : "sb",
"river" : "rw",
"battleFields" : ["subterranean"],
@ -118,7 +118,7 @@
"minimapBlocked" : [ 8, 81, 148 ],
"music" : "Water.mp3",
"tiles" : "WATRTL",
"type" : "WATER",
"type" : [ "WATER" ],
"code" : "wt",
"battleFields" : ["ship"],
"transitionRequired" : true,
@ -136,7 +136,7 @@
"minimapBlocked" : [ 0, 0, 0 ],
"music" : "Underground.mp3", // Impossible in H3
"tiles" : "ROCKTL",
"type" : "ROCK",
"type" : [ "ROCK" ],
"code" : "rc",
"battleFields" : ["rocklands"],
"transitionRequired" : true,

View File

@ -1226,7 +1226,7 @@ enum class ETerrainId {
WRONG = -2,
BORDER = -1,
FIRST_REGULAR_TERRAIN = 0,
DIRT,
DIRT = 0,
SAND,
GRASS,
SNOW,

View File

@ -12,6 +12,7 @@
#include "Terrain.h"
#include "VCMI_Lib.h"
#include "CModHandler.h"
#include "CGeneralTextHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -99,8 +100,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
if(!json["rockTerrain"].isNull())
{
auto rockTerrainName = json["rockTerrain"].String();
VLC->modh->identifiers.requestIdentifier("terrain", rockTerrainName, [info](int32_t identifier)
VLC->modh->identifiers.requestIdentifier("terrain", json["rockTerrain"], [info](int32_t identifier)
{
info->rockTerrain = TerrainId(identifier);
});
@ -117,7 +117,20 @@ const std::vector<std::string> & TerrainTypeHandler::getTypeNames() const
std::vector<JsonNode> TerrainTypeHandler::loadLegacyData(size_t dataSize)
{
return {};
objects.resize(dataSize);
CLegacyConfigParser terrainParser("DATA/TERRNAME.TXT");
std::vector<JsonNode> result;
do
{
JsonNode terrain;
terrain["text"].String() = terrainParser.readString();
result.push_back(terrain);
}
while (terrainParser.endLine());
return result;
}
std::vector<bool> TerrainTypeHandler::getDefaultAllowed() const

View File

@ -165,14 +165,7 @@ void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
}
//assuming that object can be placed on other land terrains
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER))
{
for(const auto & terrain : VLC->terrainTypeHandler->objects)
{
if(terrain->isLand() && terrain->isPassable())
allowedTerrains.insert(terrain->id);
}
}
anyTerrain = allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER);
id = Obj(boost::lexical_cast<int>(strings[5]));
subid = boost::lexical_cast<int>(strings[6]);
@ -238,14 +231,7 @@ void ObjectTemplate::readMap(CBinaryReader & reader)
}
//assuming that object can be placed on other land terrains
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER))
{
for(const auto & terrain : VLC->terrainTypeHandler->objects)
{
if(terrain->isLand() && terrain->isPassable())
allowedTerrains.insert(terrain->id);
}
}
anyTerrain = allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER);
id = Obj(reader.readUInt32());
subid = reader.readUInt32();
@ -292,15 +278,11 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain)
allowedTerrains.insert(TerrainId(identifier));
});
}
anyTerrain = false;
}
else
{
for(const auto & terrain : VLC->terrainTypeHandler->objects)
{
if(!terrain->isPassable() || terrain->isWater())
continue;
allowedTerrains.insert(terrain->id);
}
anyTerrain = true;
}
if(withTerrain && allowedTerrains.empty())
@ -561,9 +543,14 @@ void ObjectTemplate::calculateVisitableOffset()
visitableOffset = int3(0, 0, 0);
}
bool ObjectTemplate::canBePlacedAt(TerrainId terrain) const
bool ObjectTemplate::canBePlacedAt(TerrainId terrainID) const
{
return vstd::contains(allowedTerrains, terrain);
if (anyTerrain)
{
auto const & terrain = VLC->terrainTypeHandler->getById(terrainID);
return terrain->isLand() && terrain->isPassable();
}
return vstd::contains(allowedTerrains, terrainID);
}
void ObjectTemplate::recalculate()

View File

@ -35,6 +35,9 @@ class DLL_LINKAGE ObjectTemplate
/// list of terrains on which this object can be placed
std::set<TerrainId> allowedTerrains;
/// or, allow placing object on any terrain
bool anyTerrain;
void afterLoadFixup();
public:

View File

@ -377,8 +377,10 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
terrainTypes.clear();
for(auto ttype : node.Vector())
{
auto identifier = VLC->modh->identifiers.getIdentifier("terrain", ttype);
terrainTypes.emplace(*identifier);
VLC->modh->identifiers.requestIdentifier("terrain", ttype, [this](int32_t identifier)
{
terrainTypes.emplace(identifier);
});
}
}
}