1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-01 23:12:49 +02:00

Terrain/Road/River handler are now in compileable state

This commit is contained in:
Ivan Savenko
2022-12-20 18:35:40 +02:00
parent 1468f6aded
commit e1799379dd
35 changed files with 303 additions and 205 deletions

View File

@@ -338,12 +338,12 @@ std::string CDrawRiversOperation::getLabel() const
void CDrawRoadsOperation::executeTile(TerrainTile & tile)
{
tile.roadType = const_cast<RoadType*>(VLC->roadTypeHandler->getByIndex(roadType));
tile.roadType = const_cast<RoadType*>(VLC->roadTypeHandler->getByIndex(roadType.getNum()));
}
void CDrawRiversOperation::executeTile(TerrainTile & tile)
{
tile.riverType = const_cast<RiverType*>(VLC->riverTypeHandler->getByIndex(riverType));
tile.riverType = const_cast<RiverType*>(VLC->riverTypeHandler->getByIndex(riverType.getNum()));
}
bool CDrawRoadsOperation::canApplyPattern(const LinePattern & pattern) const

View File

@@ -80,7 +80,7 @@ private:
class CDrawRiversOperation : public CDrawLinesOperation
{
public:
CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RoadId roadType, CRandomGenerator * gen);
CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RiverId roadType, CRandomGenerator * gen);
std::string getLabel() const override;
protected:

View File

@@ -422,14 +422,14 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
bool nativeTestOk, nativeTestStrongOk;
nativeTestOk = nativeTestStrongOk = (rule.isNativeStrong() || rule.isNativeRule()) && !isAlien;
if(centerTerType->id == TerrainId::DIRT)
if(centerTerType->id == ETerrainId::DIRT)
{
nativeTestOk = rule.isNativeRule() && !terType->isTransitionRequired();
bool sandTestOk = (rule.isSandRule() || rule.isTransition())
&& terType->isTransitionRequired();
applyValidationRslt(rule.isAnyRule() || sandTestOk || nativeTestOk || nativeTestStrongOk);
}
else if(centerTerType->id == TerrainId::SAND)
else if(centerTerType->id == ETerrainId::SAND)
{
applyValidationRslt(true);
}
@@ -551,12 +551,12 @@ CClearTerrainOperation::CClearTerrainOperation(CMap* map, CRandomGenerator* gen)
{
CTerrainSelection terrainSel(map);
terrainSel.selectRange(MapRect(int3(0, 0, 0), map->width, map->height));
addOperation(std::make_unique<CDrawTerrainOperation>(map, terrainSel, TerrainId::WATER, gen));
addOperation(std::make_unique<CDrawTerrainOperation>(map, terrainSel, ETerrainId::WATER, gen));
if(map->twoLevel)
{
terrainSel.clearSelection();
terrainSel.selectRange(MapRect(int3(0, 0, 1), map->width, map->height));
addOperation(std::make_unique<CDrawTerrainOperation>(map, terrainSel, TerrainId::ROCK, gen));
addOperation(std::make_unique<CDrawTerrainOperation>(map, terrainSel, ETerrainId::ROCK, gen));
}
}

View File

@@ -941,7 +941,7 @@ void CMapLoaderH3M::readTerrain()
tile.roadType = const_cast<RoadType*>(VLC->roadTypeHandler->getByIndex(reader.readUInt8()));
tile.roadDir = reader.readUInt8();
tile.extTileFlags = reader.readUInt8();
tile.blocked = ((!tile.terType->isPassable() || tile.terType->id == TerrainId::BORDER ) ? true : false); //underground tiles are always blocked
tile.blocked = ((!tile.terType->isPassable() || tile.terType->id == ETerrainId::BORDER ) ? true : false); //underground tiles are always blocked
tile.visitable = 0;
}
}

View File

@@ -346,6 +346,37 @@ CMapFormatJson::CMapFormatJson():
}
TerrainType * CMapFormatJson::getTerrainByCode( std::string code)
{
for ( auto const & object : VLC->terrainTypeHandler->objects)
{
if (object->typeCode == code)
return const_cast<TerrainType *>(object.get());
}
return nullptr;
}
RiverType * CMapFormatJson::getRiverByCode( std::string code)
{
for ( auto const & object : VLC->riverTypeHandler->objects)
{
if (object->code == code)
return const_cast<RiverType *>(object.get());
}
return nullptr;
}
RoadType * CMapFormatJson::getRoadByCode( std::string code)
{
for ( auto const & object : VLC->roadTypeHandler->objects)
{
if (object->code == code)
return const_cast<RoadType *>(object.get());
}
return nullptr;
}
void CMapFormatJson::serializeAllowedFactions(JsonSerializeFormat & handler, std::set<TFaction> & value)
{
//TODO: unify allowed factions with others - make them std::vector<bool>
@@ -949,7 +980,7 @@ void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile
using namespace TerrainDetail;
{//terrain type
const std::string typeCode = src.substr(0, 2);
tile.terType = const_cast<TerrainType*>(VLC->terrainTypeHandler->getInfoByCode(typeCode));
tile.terType = getTerrainByCode(typeCode);
}
int startPos = 2; //0+typeCode fixed length
{//terrain view
@@ -979,13 +1010,13 @@ void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile
startPos += 2;
try
{
tile.roadType = const_cast<RoadType*>(VLC->roadTypeHandler->getInfoByCode(typeCode));
tile.roadType = getRoadByCode(typeCode);
}
catch (const std::exception&) //it's not a road, it's a river
{
try
{
tile.riverType = const_cast<RiverType*>(VLC->riverTypeHandler->getInfoByCode(typeCode));
tile.riverType = getRiverByCode(typeCode);
hasRoad = false;
}
catch (const std::exception&)
@@ -1021,7 +1052,7 @@ void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile
{//river type
const std::string typeCode = src.substr(startPos, 2);
startPos += 2;
tile.riverType = const_cast<RiverType*>(VLC->riverTypeHandler->getInfoByCode(typeCode));
tile.riverType = getRiverByCode(typeCode);
}
{//river dir
int pos = startPos;

View File

@@ -26,6 +26,9 @@ struct TerrainTile;
struct PlayerInfo;
class CGObjectInstance;
class AObjectTypeHandler;
class TerrainType;
class RoadType;
class RiverType;
class JsonSerializeFormat;
class JsonDeserializer;
@@ -57,6 +60,10 @@ protected:
CMapFormatJson();
static TerrainType * getTerrainByCode( std::string code);
static RiverType * getRiverByCode( std::string code);
static RoadType * getRoadByCode( std::string code);
void serializeAllowedFactions(JsonSerializeFormat & handler, std::set<TFaction> & value);
///common part of header saving/loading