1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-06 23:26:26 +02:00

Map/Road/River identifiers are now private members

This commit is contained in:
Ivan Savenko 2023-01-01 17:10:47 +02:00
parent f3985d205b
commit 7c7ae26e67
31 changed files with 92 additions and 82 deletions

View File

@ -340,7 +340,7 @@ void CMusicHandler::loadTerrainMusicThemes()
{ {
for (const auto & terrain : CGI->terrainTypeHandler->objects) for (const auto & terrain : CGI->terrainTypeHandler->objects)
{ {
addEntryToSet("terrain_" + terrain->identifier, "Music/" + terrain->musicFilename); addEntryToSet("terrain_" + terrain->getName(), "Music/" + terrain->musicFilename);
} }
} }

View File

@ -259,7 +259,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
{ {
updateAmbientSounds(); updateAmbientSounds();
//We may need to change music - select new track, music handler will change it if needed //We may need to change music - select new track, music handler will change it if needed
CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->identifier, true, false); CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->getName(), true, false);
if(details.result == TryMoveHero::TELEPORTATION) if(details.result == TryMoveHero::TELEPORTATION)
{ {
@ -2436,7 +2436,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
sh = CCS->soundh->playSound(soundBase::horseFlying, -1); sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
#endif #endif
{ {
newTerrain = cb->getTile(h->convertToVisitablePos(prevCoord))->terType->id; newTerrain = cb->getTile(h->convertToVisitablePos(prevCoord))->terType->getId();
if(newTerrain != currentTerrain || wasOnRoad != movingOnRoad) if(newTerrain != currentTerrain || wasOnRoad != movingOnRoad)
{ {
CCS->soundh->stopSound(sh); CCS->soundh->stopSound(sh);

View File

@ -136,8 +136,8 @@ BattleInterface::~BattleInterface()
if (adventureInt && adventureInt->selection) if (adventureInt && adventureInt->selection)
{ {
//FIXME: this should be moved to adventureInt which should restore correct track based on selection/active player //FIXME: this should be moved to adventureInt which should restore correct track based on selection/active player
const auto & terrain = *(LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->terType); const auto * terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->terType;
CCS->musich->playMusicFromSet("terrain", terrain.name, true, false); CCS->musich->playMusicFromSet("terrain", terrain->getName(), true, false);
} }
// may happen if user decided to close game while in battle // may happen if user decided to close game while in battle

View File

@ -177,7 +177,7 @@ void CMapHandler::initTerrainGraphics()
std::map<std::string, std::string> roadFiles; std::map<std::string, std::string> roadFiles;
for(const auto & terrain : VLC->terrainTypeHandler->objects) for(const auto & terrain : VLC->terrainTypeHandler->objects)
{ {
terrainFiles[terrain->identifier] = terrain->tilesFilename; terrainFiles[terrain->getName()] = terrain->tilesFilename;
} }
for(const auto & river : VLC->riverTypeHandler->objects) for(const auto & river : VLC->riverTypeHandler->objects)
{ {
@ -606,7 +606,7 @@ void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const T
ui8 rotation = tinfo.extTileFlags % 4; ui8 rotation = tinfo.extTileFlags % 4;
//TODO: use ui8 instead of string key //TODO: use ui8 instead of string key
auto terrainName = tinfo.terType->identifier; auto terrainName = tinfo.terType->getName();
if(parent->terrainImages[terrainName].size()<=tinfo.terView) if(parent->terrainImages[terrainName].size()<=tinfo.terView)
return; return;
@ -786,7 +786,7 @@ void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const Terra
void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const
{ {
if (tinfoUpper && tinfoUpper->roadType->id != Road::NO_ROAD) if (tinfoUpper && tinfoUpper->roadType->getId() != Road::NO_ROAD)
{ {
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4; ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
Rect source(0, tileSize / 2, tileSize, tileSize / 2); Rect source(0, tileSize / 2, tileSize, tileSize / 2);
@ -795,7 +795,7 @@ void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainT
&source, targetSurf, &dest); &source, targetSurf, &dest);
} }
if(tinfo.roadType->id != Road::NO_ROAD) //print road from this tile if(tinfo.roadType->getId() != Road::NO_ROAD) //print road from this tile
{ {
ui8 rotation = (tinfo.extTileFlags >> 4) % 4; ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
Rect source(0, 0, tileSize, halfTileSizeCeil); Rect source(0, 0, tileSize, halfTileSizeCeil);
@ -860,7 +860,7 @@ void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingIn
if(isVisible || info->showAllTerrain) if(isVisible || info->showAllTerrain)
{ {
drawTileTerrain(targetSurf, tinfo, tile); drawTileTerrain(targetSurf, tinfo, tile);
if(tinfo.riverType->id != River::NO_RIVER) if(tinfo.riverType->getId() != River::NO_RIVER)
drawRiver(targetSurf, tinfo); drawRiver(targetSurf, tinfo);
drawRoad(targetSurf, tinfo, tinfoUpper); drawRoad(targetSurf, tinfo, tinfoUpper);
} }
@ -1390,7 +1390,7 @@ void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRM
} }
if(!isTile2Terrain || out.empty()) if(!isTile2Terrain || out.empty())
out = VLC->terrainTypeHandler->getById(t.terType->id)->nameTranslated; out = t.terType->getName();
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG) if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
{ {

View File

@ -390,7 +390,7 @@ const SDL_Color & CMinimapInstance::getTileColor(const int3 & pos)
} }
// else - use terrain color (blocked version or normal) // else - use terrain color (blocked version or normal)
const auto & colorPair = parent->colors.find(tile->terType->id)->second; const auto & colorPair = parent->colors.find(tile->terType->getId())->second;
if (tile->blocked && (!tile->visitable)) if (tile->blocked && (!tile->visitable))
return colorPair.second; return colorPair.second;
else else
@ -517,7 +517,7 @@ std::map<TerrainId, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
ui8(255) ui8(255)
}; };
ret[terrain->id] = std::make_pair(normal, blocked); ret[terrain->getId()] = std::make_pair(normal, blocked);
} }
return ret; return ret;
} }

View File

@ -1414,7 +1414,7 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)
auto pos = sel->visitablePos(); auto pos = sel->visitablePos();
auto tile = LOCPLINT->cb->getTile(pos); auto tile = LOCPLINT->cb->getTile(pos);
if(tile) if(tile)
CCS->musich->playMusicFromSet("terrain", tile->terType->identifier, true, false); CCS->musich->playMusicFromSet("terrain", tile->terType->getName(), true, false);
} }
if(centerView) if(centerView)
centerOn(sel); centerOn(sel);

View File

@ -132,7 +132,7 @@
"transitionRequired" : true, "transitionRequired" : true,
"terrainViewPatterns" : "water", "terrainViewPatterns" : "water",
"horseSound" : "horse08", "horseSound" : "horse08",
"horseSoundPenalty" : "horse28" "horseSoundPenalty" : "horse28",
"sounds": { "sounds": {
"ambient": ["LOOPOCEA"] "ambient": ["LOOPOCEA"]
} }

View File

@ -2134,7 +2134,7 @@ void CGameState::updateRumor()
rumorId = *RandomGeneratorUtil::nextItem(sRumorTypes, rand); rumorId = *RandomGeneratorUtil::nextItem(sRumorTypes, rand);
if(rumorId == RumorState::RUMOR_GRAIL) if(rumorId == RumorState::RUMOR_GRAIL)
{ {
rumorExtra = getTile(map->grailPos)->terType->id.getNum(); rumorExtra = getTile(map->grailPos)->terType->getIndex();
break; break;
} }

View File

@ -1003,7 +1003,7 @@ TurnInfo::BonusCache::BonusCache(TConstBonusListPtr bl)
for(const auto & terrain : VLC->terrainTypeHandler->objects) for(const auto & terrain : VLC->terrainTypeHandler->objects)
{ {
noTerrainPenalty.push_back(static_cast<bool>( noTerrainPenalty.push_back(static_cast<bool>(
bl->getFirst(Selector::type()(Bonus::NO_TERRAIN_PENALTY).And(Selector::subtype()(terrain->id.getNum()))))); bl->getFirst(Selector::type()(Bonus::NO_TERRAIN_PENALTY).And(Selector::subtype()(terrain->getIndex())))));
} }
freeShipBoarding = static_cast<bool>(bl->getFirst(Selector::type()(Bonus::FREE_SHIP_BOARDING))); freeShipBoarding = static_cast<bool>(bl->getFirst(Selector::type()(Bonus::FREE_SHIP_BOARDING)));

View File

@ -2136,7 +2136,7 @@ int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
std::string CreatureTerrainLimiter::toString() const std::string CreatureTerrainLimiter::toString() const
{ {
boost::format fmt("CreatureTerrainLimiter(terrainType=%s)"); boost::format fmt("CreatureTerrainLimiter(terrainType=%s)");
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->identifier; auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getName();
fmt % (terrainType == ETerrainId::NATIVE_TERRAIN ? "native" : terrainName); fmt % (terrainType == ETerrainId::NATIVE_TERRAIN ? "native" : terrainName);
return fmt.str(); return fmt.str();
} }
@ -2146,7 +2146,7 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
JsonNode root(JsonNode::JsonType::DATA_STRUCT); JsonNode root(JsonNode::JsonType::DATA_STRUCT);
root["type"].String() = "CREATURE_TERRAIN_LIMITER"; root["type"].String() = "CREATURE_TERRAIN_LIMITER";
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->identifier; auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getName();
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName)); root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName));
return root; return root;

View File

@ -735,7 +735,7 @@ DLL_LINKAGE void NewObject::applyGs(CGameState *gs)
else else
{ {
const TerrainTile & t = gs->map->getTile(pos); const TerrainTile & t = gs->map->getTile(pos);
terrainType = t.terType->id; terrainType = t.terType->getId();
} }
CGObjectInstance *o = nullptr; CGObjectInstance *o = nullptr;

View File

@ -47,7 +47,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
info->horseSoundPenalty = json["horseSoundPenalty"].String(); info->horseSoundPenalty = json["horseSoundPenalty"].String();
info->transitionRequired = json["transitionRequired"].Bool(); info->transitionRequired = json["transitionRequired"].Bool();
info->terrainViewPatterns = json["terrainViewPatterns"].String(); info->terrainViewPatterns = json["terrainViewPatterns"].String();
info->nameTranslated = json["nameTranslated"].String(); //info->nameTranslated = json["nameTranslated"].String();
const JsonVector & unblockedVec = json["minimapUnblocked"].Vector(); const JsonVector & unblockedVec = json["minimapUnblocked"].Vector();
info->minimapUnblocked = info->minimapUnblocked =

View File

@ -21,6 +21,11 @@ VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE TerrainType : public EntityT<TerrainId> class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
{ {
friend class TerrainTypeHandler;
std::string identifier;
TerrainId id;
ui8 passabilityType;
public: public:
int32_t getIndex() const override { return id.getNum(); } int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; } int32_t getIconIndex() const override { return 0; }
@ -29,6 +34,9 @@ public:
void registerIcons(const IconRegistar & cb) const override {} void registerIcons(const IconRegistar & cb) const override {}
TerrainId getId() const override { return id;} TerrainId getId() const override { return id;}
std::string getNameTextID() const;
std::string getNameTranslated() const;
enum PassabilityType : ui8 enum PassabilityType : ui8
{ {
LAND = 1, LAND = 1,
@ -42,20 +50,16 @@ public:
std::vector<TerrainId> prohibitTransitions; std::vector<TerrainId> prohibitTransitions;
std::array<int, 3> minimapBlocked; std::array<int, 3> minimapBlocked;
std::array<int, 3> minimapUnblocked; std::array<int, 3> minimapUnblocked;
std::string identifier;
std::string shortIdentifier; std::string shortIdentifier;
std::string musicFilename; std::string musicFilename;
std::string tilesFilename; std::string tilesFilename;
std::string nameTranslated;
std::string terrainViewPatterns; std::string terrainViewPatterns;
std::string horseSound; std::string horseSound;
std::string horseSoundPenalty; std::string horseSoundPenalty;
TerrainId id;
TerrainId rockTerrain; TerrainId rockTerrain;
RiverId river; RiverId river;
int moveCost; int moveCost;
ui8 passabilityType;
bool transitionRequired; bool transitionRequired;
TerrainType(); TerrainType();
@ -78,7 +82,6 @@ public:
h & identifier; h & identifier;
h & musicFilename; h & musicFilename;
h & tilesFilename; h & tilesFilename;
h & nameTranslated;
h & shortIdentifier; h & shortIdentifier;
h & terrainViewPatterns; h & terrainViewPatterns;
h & rockTerrain; h & rockTerrain;
@ -95,6 +98,10 @@ public:
class DLL_LINKAGE RiverType : public EntityT<RiverId> class DLL_LINKAGE RiverType : public EntityT<RiverId>
{ {
friend class RiverTypeHandler;
std::string identifier;
RiverId id;
public: public:
int32_t getIndex() const override { return id.getNum(); } int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; } int32_t getIconIndex() const override { return 0; }
@ -103,11 +110,12 @@ public:
void registerIcons(const IconRegistar & cb) const override {} void registerIcons(const IconRegistar & cb) const override {}
RiverId getId() const override { return id;} RiverId getId() const override { return id;}
std::string getNameTextID() const;
std::string getNameTranslated() const;
std::string tilesFilename; std::string tilesFilename;
std::string identifier;
std::string shortIdentifier; std::string shortIdentifier;
std::string deltaName; std::string deltaName;
RiverId id;
RiverType(); RiverType();
@ -122,6 +130,10 @@ public:
class DLL_LINKAGE RoadType : public EntityT<RoadId> class DLL_LINKAGE RoadType : public EntityT<RoadId>
{ {
friend class RoadTypeHandler;
std::string identifier;
RoadId id;
public: public:
int32_t getIndex() const override { return id.getNum(); } int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; } int32_t getIconIndex() const override { return 0; }
@ -131,9 +143,7 @@ public:
RoadId getId() const override { return id;} RoadId getId() const override { return id;}
std::string tilesFilename; std::string tilesFilename;
std::string identifier;
std::string shortIdentifier; std::string shortIdentifier;
RoadId id;
ui8 movementCost; ui8 movementCost;
RoadType(); RoadType();

View File

@ -81,16 +81,16 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile & dest, const TerrainTile & f
int64_t ret = GameConstants::BASE_MOVEMENT_COST; int64_t ret = GameConstants::BASE_MOVEMENT_COST;
//if there is road both on dest and src tiles - use road movement cost //if there is road both on dest and src tiles - use road movement cost
if(dest.roadType->id != Road::NO_ROAD && from.roadType->id != Road::NO_ROAD) if(dest.roadType->getId() != Road::NO_ROAD && from.roadType->getId() != Road::NO_ROAD)
{ {
ret = std::max(dest.roadType->movementCost, from.roadType->movementCost); ret = std::max(dest.roadType->movementCost, from.roadType->movementCost);
} }
else if(ti->nativeTerrain != from.terType->id &&//the terrain is not native else if(ti->nativeTerrain != from.terType->getId() &&//the terrain is not native
ti->nativeTerrain != ETerrainId::ANY_TERRAIN && //no special creature bonus ti->nativeTerrain != ETerrainId::ANY_TERRAIN && //no special creature bonus
!ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType->id.getNum())) //no special movement bonus !ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType->getId().getNum())) //no special movement bonus
{ {
ret = VLC->heroh->terrCosts[from.terType->id]; ret = VLC->heroh->terrCosts[from.terType->getId()];
ret -= ti->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING); ret -= ti->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING);
if(ret < GameConstants::BASE_MOVEMENT_COST) if(ret < GameConstants::BASE_MOVEMENT_COST)
ret = GameConstants::BASE_MOVEMENT_COST; ret = GameConstants::BASE_MOVEMENT_COST;
@ -519,7 +519,7 @@ void CGHeroInstance::initObj(CRandomGenerator & rand)
if (ID != Obj::PRISON) if (ID != Obj::PRISON)
{ {
auto terrain = cb->gameState()->getTile(visitablePos())->terType->id; auto terrain = cb->gameState()->getTile(visitablePos())->terType->getId();
auto customApp = VLC->objtypeh->getHandlerFor(ID, type->heroClass->getIndex())->getOverride(terrain, this); auto customApp = VLC->objtypeh->getHandlerFor(ID, type->heroClass->getIndex())->getOverride(terrain, this);
if (customApp) if (customApp)
appearance = customApp; appearance = customApp;

View File

@ -1132,7 +1132,7 @@ void CGTownInstance::setType(si32 ID, si32 subID)
void CGTownInstance::updateAppearance() void CGTownInstance::updateAppearance()
{ {
auto terrain = cb->gameState()->getTile(visitablePos())->terType->id; auto terrain = cb->gameState()->getTile(visitablePos())->terType->getId();
//FIXME: not the best way to do this //FIXME: not the best way to do this
auto app = VLC->objtypeh->getHandlerFor(ID, subID)->getOverride(terrain, this); auto app = VLC->objtypeh->getHandlerFor(ID, subID)->getOverride(terrain, this);
if (app) if (app)

View File

@ -207,13 +207,13 @@ void CGObjectInstance::setType(si32 ID, si32 subID)
logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString()); logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString());
return; return;
} }
if(!handler->getTemplates(tile.terType->id).empty()) if(!handler->getTemplates(tile.terType->getId()).empty())
{ {
appearance = handler->getTemplates(tile.terType->id)[0]; appearance = handler->getTemplates(tile.terType->getId())[0];
} }
else else
{ {
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->identifier); logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->getName());
appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash
} }

View File

@ -84,7 +84,7 @@ CGObjectInstance * CTownInstanceConstructor::create(std::shared_ptr<const Object
void CTownInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const void CTownInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
{ {
auto templ = getOverride(object->cb->getTile(object->pos)->terType->id, object); auto templ = getOverride(object->cb->getTile(object->pos)->terType->getId(), object);
if(templ) if(templ)
object->appearance = templ; object->appearance = templ;
} }

View File

@ -360,7 +360,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
for(auto type : allowedTerrains) for(auto type : allowedTerrains)
{ {
JsonNode value(JsonNode::JsonType::DATA_STRING); JsonNode value(JsonNode::JsonType::DATA_STRING);
value.String() = VLC->terrainTypeHandler->getById(type)->identifier; value.String() = VLC->terrainTypeHandler->getById(type)->getName();
data.push_back(value); data.push_back(value);
} }
} }

View File

@ -358,22 +358,22 @@ bool CDrawRiversOperation::canApplyPattern(const LinePattern & pattern) const
bool CDrawRoadsOperation::needUpdateTile(const TerrainTile & tile) const bool CDrawRoadsOperation::needUpdateTile(const TerrainTile & tile) const
{ {
return tile.roadType->id != Road::NO_ROAD; return tile.roadType->getId() != Road::NO_ROAD;
} }
bool CDrawRiversOperation::needUpdateTile(const TerrainTile & tile) const bool CDrawRiversOperation::needUpdateTile(const TerrainTile & tile) const
{ {
return tile.riverType->id != River::NO_RIVER; return tile.riverType->getId() != River::NO_RIVER;
} }
bool CDrawRoadsOperation::tileHasSomething(const int3& pos) const bool CDrawRoadsOperation::tileHasSomething(const int3& pos) const
{ {
return map->getTile(pos).roadType->id != Road::NO_ROAD; return map->getTile(pos).roadType->getId() != Road::NO_ROAD;
} }
bool CDrawRiversOperation::tileHasSomething(const int3& pos) const bool CDrawRiversOperation::tileHasSomething(const int3& pos) const
{ {
return map->getTile(pos).riverType->id != River::NO_RIVER; return map->getTile(pos).riverType->getId() != River::NO_RIVER;
} }
void CDrawRoadsOperation::updateTile(TerrainTile & tile, const LinePattern & pattern, const int flip) void CDrawRoadsOperation::updateTile(TerrainTile & tile, const LinePattern & pattern, const int flip)

View File

@ -154,7 +154,7 @@ void CDrawTerrainOperation::updateTerrainTypes()
rect.forEach([&](const int3& posToTest) rect.forEach([&](const int3& posToTest)
{ {
auto & terrainTile = map->getTile(posToTest); auto & terrainTile = map->getTile(posToTest);
if(centerTile.terType->id != terrainTile.terType->id) if(centerTile.terType->getId() != terrainTile.terType->getId())
{ {
auto formerTerType = terrainTile.terType; auto formerTerType = terrainTile.terType;
terrainTile.terType = centerTile.terType; terrainTile.terType = centerTile.terType;
@ -257,7 +257,7 @@ void CDrawTerrainOperation::updateTerrainViews()
{ {
for(const auto & pos : invalidatedTerViews) for(const auto & pos : invalidatedTerViews)
{ {
const auto & patterns = VLC->terviewh->getTerrainViewPatterns(map->getTile(pos).terType->id); const auto & patterns = VLC->terviewh->getTerrainViewPatterns(map->getTile(pos).terType->getId());
// Detect a pattern which fits best // Detect a pattern which fits best
int bestPattern = -1; int bestPattern = -1;
@ -393,9 +393,9 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
{ {
if(recDepth == 0 && map->isInTheMap(currentPos)) if(recDepth == 0 && map->isInTheMap(currentPos))
{ {
if(terType->id == centerTerType->id) if(terType->getId() == centerTerType->getId())
{ {
const auto & patternForRule = VLC->terviewh->getTerrainViewPatternsById(centerTerType->id, rule.name); const auto & patternForRule = VLC->terviewh->getTerrainViewPatternsById(centerTerType->getId(), rule.name);
if(auto p = patternForRule) if(auto p = patternForRule)
{ {
auto rslt = validateTerrainView(currentPos, &(*p), 1); auto rslt = validateTerrainView(currentPos, &(*p), 1);
@ -422,14 +422,14 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
bool nativeTestOk, nativeTestStrongOk; bool nativeTestOk, nativeTestStrongOk;
nativeTestOk = nativeTestStrongOk = (rule.isNativeStrong() || rule.isNativeRule()) && !isAlien; nativeTestOk = nativeTestStrongOk = (rule.isNativeStrong() || rule.isNativeRule()) && !isAlien;
if(centerTerType->id == ETerrainId::DIRT) if(centerTerType->getId() == ETerrainId::DIRT)
{ {
nativeTestOk = rule.isNativeRule() && !terType->isTransitionRequired(); nativeTestOk = rule.isNativeRule() && !terType->isTransitionRequired();
bool sandTestOk = (rule.isSandRule() || rule.isTransition()) bool sandTestOk = (rule.isSandRule() || rule.isTransition())
&& terType->isTransitionRequired(); && terType->isTransitionRequired();
applyValidationRslt(rule.isAnyRule() || sandTestOk || nativeTestOk || nativeTestStrongOk); applyValidationRslt(rule.isAnyRule() || sandTestOk || nativeTestOk || nativeTestStrongOk);
} }
else if(centerTerType->id == ETerrainId::SAND) else if(centerTerType->getId() == ETerrainId::SAND)
{ {
applyValidationRslt(true); applyValidationRslt(true);
} }

View File

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

View File

@ -1322,10 +1322,10 @@ std::string CMapSaverJson::writeTerrainTile(const TerrainTile & tile)
out << tile.terType->shortIdentifier << (int)tile.terView << flipCodes[tile.extTileFlags % 4]; out << tile.terType->shortIdentifier << (int)tile.terView << flipCodes[tile.extTileFlags % 4];
if(tile.roadType->id != Road::NO_ROAD) if(tile.roadType->getId() != Road::NO_ROAD)
out << tile.roadType << (int)tile.roadDir << flipCodes[(tile.extTileFlags >> 4) % 4]; out << tile.roadType << (int)tile.roadDir << flipCodes[(tile.extTileFlags >> 4) % 4];
if(tile.riverType->id != River::NO_RIVER) if(tile.riverType->getId() != River::NO_RIVER)
out << tile.riverType << (int)tile.riverDir << flipCodes[(tile.extTileFlags >> 2) % 4]; out << tile.riverType << (int)tile.riverDir << flipCodes[(tile.extTileFlags >> 2) % 4];
return out.str(); return out.str();

View File

@ -75,7 +75,7 @@ public:
static std::string encode(const si32 index) static std::string encode(const si32 index)
{ {
return VLC->terrainTypeHandler->getByIndex(index)->identifier; return VLC->terrainTypeHandler->getByIndex(index)->getName();
} }
}; };
@ -154,7 +154,7 @@ ZoneOptions::ZoneOptions()
{ {
for(const auto & terr : VLC->terrainTypeHandler->objects) for(const auto & terr : VLC->terrainTypeHandler->objects)
if(terr->isLand() && terr->isPassable()) if(terr->isLand() && terr->isPassable())
terrainTypes.insert(terr->id); terrainTypes.insert(terr->getId());
} }
ZoneOptions & ZoneOptions::operator=(const ZoneOptions & other) ZoneOptions & ZoneOptions::operator=(const ZoneOptions & other)
@ -365,7 +365,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
for(auto & ttype : terrainTypes) for(auto & ttype : terrainTypes)
{ {
JsonNode n; JsonNode n;
n.String() = VLC->terrainTypeHandler->getById(ttype)->identifier; n.String() = VLC->terrainTypeHandler->getById(ttype)->getName();
node.Vector().push_back(n); node.Vector().push_back(n);
} }
} }

View File

@ -121,7 +121,7 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
std::vector<TerrainId> waterTerrains; std::vector<TerrainId> waterTerrains;
for(const auto & terrain : VLC->terrainTypeHandler->objects) for(const auto & terrain : VLC->terrainTypeHandler->objects)
if(terrain->isWater()) if(terrain->isWater())
waterTerrains.push_back(terrain->id); waterTerrains.push_back(terrain->getId());
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, gen.rand)); zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, gen.rand));
} }

View File

@ -323,7 +323,7 @@ void RiverPlacer::connectRiver(const int3 & tile)
{ {
auto riverType = VLC->terrainTypeHandler->getById(zone.getTerrainType())->river; auto riverType = VLC->terrainTypeHandler->getById(zone.getTerrainType())->river;
const auto * river = VLC->riverTypeHandler->getById(riverType); const auto * river = VLC->riverTypeHandler->getById(riverType);
if(river->id == River::NO_RIVER) if(river->getId() == River::NO_RIVER)
return; return;
rmg::Area roads; rmg::Area roads;

View File

@ -121,7 +121,7 @@ void Object::Instance::setTemplate(TerrainId terrain)
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain); auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain);
if (templates.empty()) if (templates.empty())
{ {
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->identifier; auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getName();
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName)); throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName));
} }
dObject.appearance = templates.front(); dObject.appearance = templates.front();
@ -293,14 +293,14 @@ void Object::Instance::finalize(RmgMap & map)
if (!dObject.appearance) if (!dObject.appearance)
{ {
auto terrainType = map.map().getTile(getPosition(true)).terType; auto terrainType = map.map().getTile(getPosition(true)).terType;
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType->id); auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType->getId());
if (templates.empty()) if (templates.empty())
{ {
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") % dObject.ID % dObject.subID % getPosition(true).toString() % terrainType)); throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") % dObject.ID % dObject.subID % getPosition(true).toString() % terrainType));
} }
else else
{ {
setTemplate(terrainType->id); setTemplate(terrainType->getId());
} }
} }

View File

@ -44,7 +44,7 @@ void WaterProxy::process()
{ {
MAYBE_UNUSED(t); MAYBE_UNUSED(t);
assert(map.isOnMap(t)); assert(map.isOnMap(t));
assert(map.map().getTile(t).terType->id == zone.getTerrainType()); assert(map.map().getTile(t).terType->getId() == zone.getTerrainType());
} }
for(auto z : map.getZones()) for(auto z : map.getZones())
@ -54,7 +54,7 @@ void WaterProxy::process()
for(auto & t : z.second->area().getTilesVector()) for(auto & t : z.second->area().getTilesVector())
{ {
if(map.map().getTile(t).terType->id == zone.getTerrainType()) if(map.map().getTile(t).terType->getId() == zone.getTerrainType())
{ {
z.second->areaPossible().erase(t); z.second->areaPossible().erase(t);
z.second->area().erase(t); z.second->area().erase(t);

View File

@ -545,12 +545,12 @@ void MainWindow::loadObjectsTree()
//adding terrains //adding terrains
for(auto & terrain : VLC->terrainTypeHandler->objects) for(auto & terrain : VLC->terrainTypeHandler->objects)
{ {
QPushButton *b = new QPushButton(QString::fromStdString(terrain->identifier)); QPushButton *b = new QPushButton(QString::fromStdString(terrain->getName()));
ui->terrainLayout->addWidget(b); ui->terrainLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, terrain]{ terrainButtonClicked(terrain->id); }); connect(b, &QPushButton::clicked, this, [this, terrain]{ terrainButtonClicked(terrain->getId()); });
//filter //filter
ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->identifier)); ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->getName()));
} }
//add spacer to keep terrain button on the top //add spacer to keep terrain button on the top
ui->terrainLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); ui->terrainLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
@ -559,7 +559,7 @@ void MainWindow::loadObjectsTree()
{ {
QPushButton *b = new QPushButton(QString::fromStdString(road->tilesFilename)); QPushButton *b = new QPushButton(QString::fromStdString(road->tilesFilename));
ui->roadLayout->addWidget(b); ui->roadLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, road]{ roadOrRiverButtonClicked(road->id.getNum(), true); }); connect(b, &QPushButton::clicked, this, [this, road]{ roadOrRiverButtonClicked(road->getIndex(), true); });
} }
//add spacer to keep terrain button on the top //add spacer to keep terrain button on the top
ui->roadLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); ui->roadLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
@ -568,7 +568,7 @@ void MainWindow::loadObjectsTree()
{ {
QPushButton *b = new QPushButton(QString::fromStdString(river->tilesFilename)); QPushButton *b = new QPushButton(QString::fromStdString(river->tilesFilename));
ui->riverLayout->addWidget(b); ui->riverLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, river]{ roadOrRiverButtonClicked(river->id.getNum(), false); }); connect(b, &QPushButton::clicked, this, [this, river]{ roadOrRiverButtonClicked(river->getIndex(), false); });
} }
//add spacer to keep terrain button on the top //add spacer to keep terrain button on the top
ui->riverLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); ui->riverLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
@ -919,8 +919,8 @@ void MainWindow::on_terrainFilterCombo_currentTextChanged(const QString &arg1)
if (!arg1.isEmpty()) if (!arg1.isEmpty())
{ {
for (auto const & terrain : VLC->terrainTypeHandler->objects) for (auto const & terrain : VLC->terrainTypeHandler->objects)
if (terrain->identifier == arg1.toStdString()) if (terrain->getName() == arg1.toStdString())
objectBrowser->terrain = terrain->id; objectBrowser->terrain = terrain->getId();
} }
objectBrowser->invalidate(); objectBrowser->invalidate();
objectBrowser->sort(0); objectBrowser->sort(0);
@ -1113,7 +1113,7 @@ void MainWindow::on_actionUpdate_appearance_triggered()
if(handler->isStaticObject()) if(handler->isStaticObject())
{ {
staticObjects.insert(obj); staticObjects.insert(obj);
if(obj->appearance->canBePlacedAt(terrain->id)) if(obj->appearance->canBePlacedAt(terrain->getId()))
{ {
controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj); controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj);
continue; continue;
@ -1124,13 +1124,13 @@ void MainWindow::on_actionUpdate_appearance_triggered()
} }
else else
{ {
auto app = handler->getOverride(terrain->id, obj); auto app = handler->getOverride(terrain->getId(), obj);
if(!app) if(!app)
{ {
if(obj->appearance->canBePlacedAt(terrain->id)) if(obj->appearance->canBePlacedAt(terrain->getId()))
continue; continue;
auto templates = handler->getTemplates(terrain->id); auto templates = handler->getTemplates(terrain->getId());
if(templates.empty()) if(templates.empty())
{ {
++errors; ++errors;

View File

@ -408,7 +408,7 @@ void MapController::commitObstacleFill(int level)
if(tl.blocked || tl.visitable) if(tl.blocked || tl.visitable)
continue; continue;
terrainSelected[tl.terType->id].blockedArea.add(t); terrainSelected[tl.terType->getId()].blockedArea.add(t);
} }
for(auto & sel : terrainSelected) for(auto & sel : terrainSelected)

View File

@ -80,7 +80,7 @@ void MapHandler::initTerrainGraphics()
std::map<std::string, std::string> riverFiles; std::map<std::string, std::string> riverFiles;
for(const auto & terrain : VLC->terrainTypeHandler->objects) for(const auto & terrain : VLC->terrainTypeHandler->objects)
{ {
terrainFiles[terrain->identifier] = terrain->tilesFilename; terrainFiles[terrain->getName()] = terrain->tilesFilename;
} }
for(const auto & river : VLC->riverTypeHandler->objects) for(const auto & river : VLC->riverTypeHandler->objects)
{ {
@ -101,7 +101,7 @@ void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z)
auto & tinfo = map->getTile(int3(x, y, z)); auto & tinfo = map->getTile(int3(x, y, z));
ui8 rotation = tinfo.extTileFlags % 4; ui8 rotation = tinfo.extTileFlags % 4;
auto terrainName = tinfo.terType->identifier; auto terrainName = tinfo.terType->getName();
if(terrainImages.at(terrainName).size() <= tinfo.terView) if(terrainImages.at(terrainName).size() <= tinfo.terView)
return; return;
@ -115,7 +115,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
auto & tinfo = map->getTile(int3(x, y, z)); auto & tinfo = map->getTile(int3(x, y, z));
auto * tinfoUpper = map->isInTheMap(int3(x, y - 1, z)) ? &map->getTile(int3(x, y - 1, z)) : nullptr; auto * tinfoUpper = map->isInTheMap(int3(x, y - 1, z)) ? &map->getTile(int3(x, y - 1, z)) : nullptr;
if(tinfoUpper && tinfoUpper->roadType->id != Road::NO_ROAD) if(tinfoUpper && tinfoUpper->roadType->getId() != Road::NO_ROAD)
{ {
auto roadName = tinfoUpper->roadType->tilesFilename; auto roadName = tinfoUpper->roadType->tilesFilename;
QRect source(0, tileSize / 2, tileSize, tileSize / 2); QRect source(0, tileSize / 2, tileSize, tileSize / 2);
@ -127,7 +127,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
} }
} }
if(tinfo.roadType->id != Road::NO_ROAD) //print road from this tile if(tinfo.roadType->getId() != Road::NO_ROAD) //print road from this tile
{ {
auto roadName = tinfo.roadType->tilesFilename; auto roadName = tinfo.roadType->tilesFilename;
QRect source(0, 0, tileSize, tileSize / 2); QRect source(0, 0, tileSize, tileSize / 2);
@ -144,7 +144,7 @@ void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
{ {
auto & tinfo = map->getTile(int3(x, y, z)); auto & tinfo = map->getTile(int3(x, y, z));
if(tinfo.riverType->id == River::NO_RIVER) if(tinfo.riverType->getId() == River::NO_RIVER)
return; return;
//TODO: use ui8 instead of string key //TODO: use ui8 instead of string key

View File

@ -2242,7 +2242,7 @@ void CGameHandler::setupBattle(int3 tile, const CArmedInstance *armies[2], const
battleResult.set(nullptr); battleResult.set(nullptr);
const auto & t = *getTile(tile); const auto & t = *getTile(tile);
TerrainId terrain = t.terType->id; TerrainId terrain = t.terType->getId();
if (gs->map->isCoastalTile(tile)) //coastal tile is always ground if (gs->map->isCoastalTile(tile)) //coastal tile is always ground
terrain = ETerrainId::SAND; terrain = ETerrainId::SAND;