1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Better names for terrain parameters. Support for new movement sounds.

This commit is contained in:
Ivan Savenko
2022-12-21 00:45:35 +02:00
parent 4e4dae854f
commit 64885bdf6b
21 changed files with 121 additions and 150 deletions

View File

@@ -89,35 +89,6 @@ CSoundHandler::CSoundHandler():
soundBase::battle02, soundBase::battle03, soundBase::battle04,
soundBase::battle05, soundBase::battle06, soundBase::battle07
};
//predefine terrain set
//TODO: support custom sounds for new terrains and load from json
horseSounds =
{
{ETerrainId::DIRT, soundBase::horseDirt},
{ETerrainId::SAND, soundBase::horseSand},
{ETerrainId::GRASS, soundBase::horseGrass},
{ETerrainId::SNOW, soundBase::horseSnow},
{ETerrainId::SWAMP, soundBase::horseSwamp},
{ETerrainId::ROUGH, soundBase::horseRough},
{ETerrainId::SUBTERRANEAN, soundBase::horseSubterranean},
{ETerrainId::LAVA, soundBase::horseLava},
{ETerrainId::WATER, soundBase::horseWater},
{ETerrainId::ROCK, soundBase::horseRock}
};
}
void CSoundHandler::loadHorseSounds()
{
for(const auto & terrain : CGI->terrainTypeHandler->objects)
{
//since all sounds are hardcoded, let's keep it
if(vstd::contains(horseSounds, terrain->id))
continue;
//Use already existing horse sound
horseSounds[terrain->id] = horseSounds.at(static_cast<TerrainId>(CGI->terrainTypeHandler->getById(terrain->id)->horseSoundId));
}
}
void CSoundHandler::init()
@@ -369,7 +340,7 @@ void CMusicHandler::loadTerrainMusicThemes()
{
for (const auto & terrain : CGI->terrainTypeHandler->objects)
{
addEntryToSet("terrain_" + terrain->name, "Music/" + terrain->musicFilename);
addEntryToSet("terrain_" + terrain->identifier, "Music/" + terrain->musicFilename);
}
}

View File

@@ -61,7 +61,6 @@ public:
CSoundHandler();
void init() override;
void loadHorseSounds();
void release() override;
void setVolume(ui32 percent) override;
@@ -84,7 +83,6 @@ public:
// Sets
std::vector<soundBase::soundID> pickupSounds;
std::vector<soundBase::soundID> battleIntroSounds;
std::map<TerrainId, soundBase::soundID> horseSounds;
};
// Helper //now it looks somewhat useless

View File

@@ -156,7 +156,6 @@ void CPlayerInterface::initGameInterface(std::shared_ptr<Environment> ENV, std::
cb = CB;
env = ENV;
CCS->soundh->loadHorseSounds();
CCS->musich->loadTerrainMusicThemes();
initializeHeroTownList();
@@ -260,7 +259,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
{
updateAmbientSounds();
//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->name, true, false);
CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->identifier, true, false);
if(details.result == TryMoveHero::TELEPORTATION)
{
@@ -2410,7 +2409,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
}
if(i != path.nodes.size() - 1)
{
sh = CCS->soundh->playSound(CCS->soundh->horseSounds[currentTerrain], -1);
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(currentTerrain)->horseSound, -1);
}
continue;
}
@@ -2432,7 +2431,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
if(newTerrain != currentTerrain)
{
CCS->soundh->stopSound(sh);
sh = CCS->soundh->playSound(CCS->soundh->horseSounds[newTerrain], -1);
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(newTerrain)->horseSound, -1);
currentTerrain = newTerrain;
}
}

View File

@@ -177,15 +177,15 @@ void CMapHandler::initTerrainGraphics()
std::map<std::string, std::string> roadFiles;
for(const auto & terrain : VLC->terrainTypeHandler->objects)
{
terrainFiles[terrain->name] = terrain->tilesFilename;
terrainFiles[terrain->identifier] = terrain->tilesFilename;
}
for(const auto & river : VLC->riverTypeHandler->objects)
{
riverFiles[river->fileName] = river->fileName;
riverFiles[river->tilesFilename] = river->tilesFilename;
}
for(const auto & road : VLC->roadTypeHandler->objects)
{
roadFiles[road->fileName] = road->fileName;
roadFiles[road->tilesFilename] = road->tilesFilename;
}
loadFlipped(terrainAnimations, terrainImages, terrainFiles);
@@ -606,7 +606,7 @@ void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const T
ui8 rotation = tinfo.extTileFlags % 4;
//TODO: use ui8 instead of string key
auto terrainName = tinfo.terType->name;
auto terrainName = tinfo.terType->identifier;
if(parent->terrainImages[terrainName].size()<=tinfo.terView)
return;
@@ -791,7 +791,7 @@ void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainT
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
Rect source(0, tileSize / 2, tileSize, tileSize / 2);
Rect dest(realPos.x, realPos.y, tileSize, tileSize / 2);
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfoUpper->roadType->fileName][tinfoUpper->roadDir][rotation],
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfoUpper->roadType->tilesFilename][tinfoUpper->roadDir][rotation],
&source, targetSurf, &dest);
}
@@ -800,7 +800,7 @@ void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainT
ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
Rect source(0, 0, tileSize, halfTileSizeCeil);
Rect dest(realPos.x, realPos.y + tileSize / 2, tileSize, tileSize / 2);
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfo.roadType->fileName][tinfo.roadDir][rotation],
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfo.roadType->tilesFilename][tinfo.roadDir][rotation],
&source, targetSurf, &dest);
}
}
@@ -809,7 +809,7 @@ void CMapHandler::CMapBlitter::drawRiver(SDL_Surface * targetSurf, const Terrain
{
Rect destRect(realTileRect);
ui8 rotation = (tinfo.extTileFlags >> 2) % 4;
drawElement(EMapCacheType::RIVERS, parent->riverImages[tinfo.riverType->fileName][tinfo.riverDir][rotation], nullptr, targetSurf, &destRect);
drawElement(EMapCacheType::RIVERS, parent->riverImages[tinfo.riverType->tilesFilename][tinfo.riverDir][rotation], nullptr, targetSurf, &destRect);
}
void CMapHandler::CMapBlitter::drawFow(SDL_Surface * targetSurf) const
@@ -1390,7 +1390,7 @@ void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRM
}
if(!isTile2Terrain || out.empty())
out = VLC->terrainTypeHandler->getById(t.terType->id)->terrainText;
out = VLC->terrainTypeHandler->getById(t.terType->id)->nameTranslated;
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
{

View File

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

View File

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

View File

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

View File

@@ -7,11 +7,11 @@
"minimapBlocked" : [ 57, 40, 8 ],
"music" : "Dirt.mp3",
"tiles" : "DIRTTL",
"code" : "dt",
"shortIdentifier" : "dt",
"river" : "mudRiver",
"battleFields" : ["dirt_birches", "dirt_hills", "dirt_pines"],
"terrainViewPatterns" : "dirt",
"horseSoundId" : 0
"horseSound" : "horseDirt"
},
"sand" :
{
@@ -21,12 +21,12 @@
"minimapBlocked" : [ 165, 158, 107 ],
"music" : "Sand.mp3",
"tiles" : "SANDTL",
"code" : "sa",
"shortIdentifier" : "sa",
"river" : "mudRiver",
"battleFields" : ["sand_mesas"],
"transitionRequired" : true,
"terrainViewPatterns" : "sand",
"horseSoundId" : 1
"horseSound" : "horseSand"
},
"grass" :
{
@@ -36,10 +36,10 @@
"minimapBlocked" : [ 0, 48, 0 ],
"music" : "Grass.mp3",
"tiles" : "GRASTL",
"code" : "gr",
"shortIdentifier" : "gr",
"river" : "waterRiver",
"battleFields" : ["grass_hills", "grass_pines"],
"horseSoundId" : 2
"horseSound" : "horseGrass"
},
"snow" :
{
@@ -49,10 +49,10 @@
"minimapBlocked" : [ 140, 158, 156 ],
"music" : "Snow.mp3",
"tiles" : "SNOWTL",
"code" : "sn",
"shortIdentifier" : "sn",
"river" : "iceRiver",
"battleFields" : ["snow_mountains", "snow_trees"],
"horseSoundId" : 3
"horseSound" : "horseSnow"
},
"swamp" :
{
@@ -62,10 +62,10 @@
"minimapBlocked" : [ 33, 89, 66 ],
"music" : "Swamp.mp3",
"tiles" : "SWMPTL",
"code" : "sw",
"shortIdentifier" : "sw",
"river" : "waterRiver",
"battleFields" : ["swamp_trees"],
"horseSoundId" : 4
"horseSound" : "horseSwamp"
},
"rough" :
{
@@ -75,10 +75,10 @@
"minimapBlocked" : [ 99, 81, 33 ],
"music" : "Rough.mp3",
"tiles" : "ROUGTL",
"code" : "rg",
"shortIdentifier" : "rg",
"river" : "mudRiver",
"battleFields" : ["rough"],
"horseSoundId" : 5
"horseSound" : "horseRough"
},
"subterra" :
{
@@ -89,11 +89,11 @@
"music" : "Underground.mp3",
"tiles" : "SUBBTL",
"type" : [ "SUB" ],
"code" : "sb",
"shortIdentifier" : "sb",
"river" : "waterRiver",
"battleFields" : ["subterranean"],
"rockTerrain" : "rock",
"horseSoundId" : 6
"horseSound" : "horseSubterranean"
},
"lava" :
{
@@ -104,11 +104,11 @@
"music" : "Lava.mp3",
"tiles" : "LAVATL",
"type" : ["SUB", "SURFACE"],
"code" : "lv",
"shortIdentifier" : "lv",
"river" : "lavaRiver",
"battleFields" : ["lava"],
"rockTerrain" : "rock",
"horseSoundId" : 7
"horseSound" : "horseLava"
},
"water" :
{
@@ -119,11 +119,11 @@
"music" : "Water.mp3",
"tiles" : "WATRTL",
"type" : [ "WATER" ],
"code" : "wt",
"shortIdentifier" : "wt",
"battleFields" : ["ship"],
"transitionRequired" : true,
"terrainViewPatterns" : "water",
"horseSoundId" : 8,
"horseSound" : "horseWater",
"sounds": {
"ambient": ["LOOPOCEA"]
}
@@ -137,10 +137,10 @@
"music" : "Underground.mp3", // Impossible in H3
"tiles" : "ROCKTL",
"type" : [ "ROCK" ],
"code" : "rc",
"shortIdentifier" : "rc",
"battleFields" : ["rocklands"],
"transitionRequired" : true,
"terrainViewPatterns" : "rock",
"horseSoundId" : 9
"horseSound" : "horseRock"
}
}

View File

@@ -1944,8 +1944,7 @@ BattleField CGameState::battleGetBattlefieldType(int3 tile, CRandomGenerator & r
if(map->isCoastalTile(tile)) //coastal tile is always ground
return BattleField::fromString("sand_shore");
return BattleField::fromString(
*RandomGeneratorUtil::nextItem(t.terType->battleFields, rand));
return BattleField(*RandomGeneratorUtil::nextItem(t.terType->battleFields, rand));
}

View File

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

View File

@@ -38,15 +38,15 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
TerrainType * info = new TerrainType;
info->id = TerrainId(index);
info->name = identifier;
info->identifier = identifier;
info->moveCost = static_cast<int>(json["moveCost"].Integer());
info->musicFilename = json["music"].String();
info->tilesFilename = json["tiles"].String();
info->horseSoundId = static_cast<int>(json["horseSoundId"].Float());
info->horseSound = json["horseSound"].String();
info->transitionRequired = json["transitionRequired"].Bool();
info->terrainViewPatterns = json["terrainViewPatterns"].String();
info->terrainText = json["text"].String();
info->nameTranslated = json["nameTranslated"].String();
const JsonVector & unblockedVec = json["minimapUnblocked"].Vector();
info->minimapUnblocked =
@@ -84,23 +84,24 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
{
info->river = RiverId(identifier);
});
}
info->typeCode = json["code"].String();
assert(info->typeCode.length() == 2);
info->shortIdentifier = json["shortIdentifier"].String();
assert(info->shortIdentifier.length() == 2);
for(auto & t : json["battleFields"].Vector())
info->battleFields.emplace_back(t.String());
//Update terrain with this id in the future, after all terrain types are populated
{
VLC->modh->identifiers.requestIdentifier("battlefield", t, [info](int32_t identifier)
{
info->battleFields.emplace_back(identifier);
});
}
for(auto & t : json["prohibitTransitions"].Vector())
{
VLC->modh->identifiers.requestIdentifier("terrain", t, [info](int32_t identifier)
{
info->prohibitTransitions.push_back(TerrainId(identifier));
info->prohibitTransitions.emplace_back(identifier);
});
}
@@ -159,10 +160,11 @@ RiverType * RiverTypeHandler::loadFromJson(
{
RiverType * info = new RiverType;
info->id = RiverId(index);
info->fileName = json["animation"].String();
info->code = json["code"].String();
info->deltaName = json["delta"].String();
info->id = RiverId(index);
info->identifier = identifier;
info->tilesFilename = json["tilesFilename"].String();
info->shortIdentifier = json["shortIdentifier"].String();
info->deltaName = json["delta"].String();
return info;
}
@@ -197,10 +199,11 @@ RoadType * RoadTypeHandler::loadFromJson(
{
RoadType * info = new RoadType;
info->id = RoadId(index);
info->fileName = json["animation"].String();
info->code = json["code"].String();
info->movementCost = json["moveCost"].Integer();
info->id = RoadId(index);
info->identifier = identifier;
info->tilesFilename = json["animation"].String();
info->shortIdentifier = json["code"].String();
info->movementCost = json["moveCost"].Integer();
return info;
}

View File

@@ -24,8 +24,8 @@ class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
const std::string & getName() const override { return name;}
const std::string & getJsonKey() const override { return name;}
const std::string & getName() const override { return identifier;}
const std::string & getJsonKey() const override { return identifier;}
void registerIcons(const IconRegistar & cb) const override {}
TerrainId getId() const override { return id;}
@@ -38,22 +38,22 @@ public:
ROCK = 16
};
std::vector<std::string> battleFields;
std::vector<BattleField> battleFields;
std::vector<TerrainId> prohibitTransitions;
std::array<int, 3> minimapBlocked;
std::array<int, 3> minimapUnblocked;
std::string name;
std::string identifier;
std::string shortIdentifier;
std::string musicFilename;
std::string tilesFilename;
std::string terrainText;
std::string typeCode;
std::string nameTranslated;
std::string terrainViewPatterns;
RiverId river;
std::string horseSound;
TerrainId id;
TerrainId rockTerrain;
RiverId river;
int moveCost;
int horseSoundId;
ui8 passabilityType;
bool transitionRequired;
@@ -74,18 +74,18 @@ public:
h & prohibitTransitions;
h & minimapBlocked;
h & minimapUnblocked;
h & name;
h & identifier;
h & musicFilename;
h & tilesFilename;
h & terrainText;
h & typeCode;
h & nameTranslated;
h & shortIdentifier;
h & terrainViewPatterns;
h & rockTerrain;
h & river;
h & id;
h & moveCost;
h & horseSoundId;
h & horseSound;
h & passabilityType;
h & transitionRequired;
}
@@ -96,13 +96,14 @@ class DLL_LINKAGE RiverType : public EntityT<RiverId>
public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
const std::string & getName() const override { return code;}
const std::string & getJsonKey() const override { return code;}
const std::string & getName() const override { return identifier;}
const std::string & getJsonKey() const override { return identifier;}
void registerIcons(const IconRegistar & cb) const override {}
RiverId getId() const override { return id;}
std::string fileName;
std::string code;
std::string tilesFilename;
std::string identifier;
std::string shortIdentifier;
std::string deltaName;
RiverId id;
@@ -110,8 +111,8 @@ public:
template <typename Handler> void serialize(Handler& h, const int version)
{
h & fileName;
h & code;
h & tilesFilename;
h & identifier;
h & deltaName;
h & id;
}
@@ -122,13 +123,14 @@ class DLL_LINKAGE RoadType : public EntityT<RoadId>
public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
const std::string & getName() const override { return code;}
const std::string & getJsonKey() const override { return code;}
const std::string & getName() const override { return identifier;}
const std::string & getJsonKey() const override { return identifier;}
void registerIcons(const IconRegistar & cb) const override {}
RoadId getId() const override { return id;}
std::string fileName;
std::string code;
std::string tilesFilename;
std::string identifier;
std::string shortIdentifier;
RoadId id;
ui8 movementCost;
@@ -136,8 +138,8 @@ public:
template <typename Handler> void serialize(Handler& h, const int version)
{
h & fileName;
h & code;
h & tilesFilename;
h & identifier;
h & id;
h & movementCost;
}

View File

@@ -213,7 +213,7 @@ void CGObjectInstance::setType(si32 ID, si32 subID)
}
else
{
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->name);
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->identifier);
appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash
}

View File

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

View File

@@ -357,7 +357,7 @@ void CTerrainViewPatternUtils::printDebuggingInfoAboutTile(const CMap * map, int
{
auto debugTile = map->getTile(debugPos);
std::string terType = debugTile.terType->name.substr(0, 6);
std::string terType = debugTile.terType->shortIdentifier;
line += terType;
line.insert(line.end(), PADDED_LENGTH - terType.size(), ' ');
}

View File

@@ -350,7 +350,7 @@ TerrainType * CMapFormatJson::getTerrainByCode( std::string code)
{
for ( auto const & object : VLC->terrainTypeHandler->objects)
{
if (object->typeCode == code)
if (object->shortIdentifier == code)
return const_cast<TerrainType *>(object.get());
}
return nullptr;
@@ -360,7 +360,7 @@ RiverType * CMapFormatJson::getRiverByCode( std::string code)
{
for ( auto const & object : VLC->riverTypeHandler->objects)
{
if (object->code == code)
if (object->shortIdentifier == code)
return const_cast<RiverType *>(object.get());
}
return nullptr;
@@ -370,7 +370,7 @@ RoadType * CMapFormatJson::getRoadByCode( std::string code)
{
for ( auto const & object : VLC->roadTypeHandler->objects)
{
if (object->code == code)
if (object->shortIdentifier == code)
return const_cast<RoadType *>(object.get());
}
return nullptr;
@@ -1320,7 +1320,7 @@ std::string CMapSaverJson::writeTerrainTile(const TerrainTile & tile)
out.setf(std::ios::dec, std::ios::basefield);
out.unsetf(std::ios::showbase);
out << tile.terType->typeCode << (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)
out << tile.roadType << (int)tile.roadDir << flipCodes[(tile.extTileFlags >> 4) % 4];

View File

@@ -75,7 +75,7 @@ public:
static std::string encode(const si32 index)
{
return VLC->terrainTypeHandler->getByIndex(index)->name;
return VLC->terrainTypeHandler->getByIndex(index)->identifier;
}
};
@@ -365,7 +365,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
for(auto & ttype : terrainTypes)
{
JsonNode n;
n.String() = VLC->terrainTypeHandler->getById(ttype)->name;
n.String() = VLC->terrainTypeHandler->getById(ttype)->identifier;
node.Vector().push_back(n);
}
}

View File

@@ -381,7 +381,7 @@ void RiverPlacer::connectRiver(const int3 & tile)
{
if(tmplates.size() % 4 != 0)
throw rmgException(boost::to_string(boost::format("River templates for (%d,%d) at terrain %s, river %s are incorrect") %
RIVER_DELTA_ID % RIVER_DELTA_SUBTYPE % zone.getTerrainType() % river->code));
RIVER_DELTA_ID % RIVER_DELTA_SUBTYPE % zone.getTerrainType() % river->shortIdentifier));
std::string targetTemplateName = river->deltaName + std::to_string(deltaOrientations[pos]) + ".def";
for(auto & templ : tmplates)

View File

@@ -121,7 +121,7 @@ void Object::Instance::setTemplate(TerrainId terrain)
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain);
if (templates.empty())
{
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->name;
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->identifier;
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();

View File

@@ -545,19 +545,19 @@ void MainWindow::loadObjectsTree()
//adding terrains
for(auto & terrain : VLC->terrainTypeHandler->objects)
{
QPushButton *b = new QPushButton(QString::fromStdString(terrain->name));
QPushButton *b = new QPushButton(QString::fromStdString(terrain->identifier));
ui->terrainLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, terrain]{ terrainButtonClicked(terrain->id); });
//filter
ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->name));
ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->identifier));
}
//add spacer to keep terrain button on the top
ui->terrainLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
//adding roads
for(auto & road : VLC->roadTypeHandler->objects)
{
QPushButton *b = new QPushButton(QString::fromStdString(road->fileName));
QPushButton *b = new QPushButton(QString::fromStdString(road->tilesFilename));
ui->roadLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, road]{ roadOrRiverButtonClicked(road->id.getNum(), true); });
}
@@ -566,7 +566,7 @@ void MainWindow::loadObjectsTree()
//adding rivers
for(auto & river : VLC->riverTypeHandler->objects)
{
QPushButton *b = new QPushButton(QString::fromStdString(river->fileName));
QPushButton *b = new QPushButton(QString::fromStdString(river->tilesFilename));
ui->riverLayout->addWidget(b);
connect(b, &QPushButton::clicked, this, [this, river]{ roadOrRiverButtonClicked(river->id.getNum(), false); });
}
@@ -919,7 +919,7 @@ void MainWindow::on_terrainFilterCombo_currentTextChanged(const QString &arg1)
if (!arg1.isEmpty())
{
for (auto const & terrain : VLC->terrainTypeHandler->objects)
if (terrain->name == arg1.toStdString())
if (terrain->identifier == arg1.toStdString())
objectBrowser->terrain = terrain->id;
}
objectBrowser->invalidate();

View File

@@ -80,15 +80,15 @@ void MapHandler::initTerrainGraphics()
std::map<std::string, std::string> riverFiles;
for(const auto & terrain : VLC->terrainTypeHandler->objects)
{
terrainFiles[terrain->name] = terrain->tilesFilename;
terrainFiles[terrain->identifier] = terrain->tilesFilename;
}
for(const auto & river : VLC->riverTypeHandler->objects)
{
riverFiles[river->fileName] = river->fileName;
riverFiles[river->tilesFilename] = river->tilesFilename;
}
for(const auto & road : VLC->roadTypeHandler->objects)
{
roadFiles[road->fileName] = road->fileName;
roadFiles[road->tilesFilename] = road->tilesFilename;
}
loadFlipped(terrainAnimations, terrainImages, terrainFiles);
@@ -101,8 +101,7 @@ void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z)
auto & tinfo = map->getTile(int3(x, y, z));
ui8 rotation = tinfo.extTileFlags % 4;
//TODO: use ui8 instead of string key
auto terrainName = tinfo.terType->name;
auto terrainName = tinfo.terType->identifier;
if(terrainImages.at(terrainName).size() <= tinfo.terView)
return;
@@ -118,7 +117,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
if(tinfoUpper && tinfoUpper->roadType->id != Road::NO_ROAD)
{
auto roadName = tinfoUpper->roadType->fileName;
auto roadName = tinfoUpper->roadType->tilesFilename;
QRect source(0, tileSize / 2, tileSize, tileSize / 2);
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3);
@@ -130,7 +129,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
if(tinfo.roadType->id != Road::NO_ROAD) //print road from this tile
{
auto roadName = tinfo.roadType->fileName;
auto roadName = tinfo.roadType->tilesFilename;
QRect source(0, 0, tileSize, tileSize / 2);
ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3);
@@ -149,7 +148,7 @@ void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
return;
//TODO: use ui8 instead of string key
auto riverName = tinfo.riverType->fileName;
auto riverName = tinfo.riverType->tilesFilename;
if(riverImages.at(riverName).size() <= tinfo.riverDir)
return;