mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
Store TerrainType by havlue and handle by reference
This commit is contained in:
parent
cd3a1a02c2
commit
2bd30556a3
@ -120,14 +120,14 @@ CSoundHandler::CSoundHandler():
|
||||
void CSoundHandler::loadHorseSounds()
|
||||
{
|
||||
const auto & terrains = CGI->terrainTypeHandler->terrains();
|
||||
for(const auto * terrain : terrains)
|
||||
for(const auto & terrain : terrains)
|
||||
{
|
||||
//since all sounds are hardcoded, let's keep it
|
||||
if(vstd::contains(horseSounds, terrain->id))
|
||||
if(vstd::contains(horseSounds, terrain.id))
|
||||
continue;
|
||||
|
||||
//Use already existing horse sound
|
||||
horseSounds[terrain->id] = horseSounds.at(terrains[terrain->id]->horseSoundId);
|
||||
horseSounds[terrain.id] = horseSounds.at(terrains[terrain.id].horseSoundId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,9 +376,9 @@ CMusicHandler::CMusicHandler():
|
||||
|
||||
void CMusicHandler::loadTerrainSounds()
|
||||
{
|
||||
for (const auto * terrain : CGI->terrainTypeHandler->terrains())
|
||||
for (const auto & terrain : CGI->terrainTypeHandler->terrains())
|
||||
{
|
||||
addEntryToSet("terrain", terrain->name, "Music/" + terrain->musicFilename);
|
||||
addEntryToSet("terrain", terrain.name, "Music/" + terrain.musicFilename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,9 +176,9 @@ void CMapHandler::initTerrainGraphics()
|
||||
std::map<std::string, std::string> terrainFiles;
|
||||
std::map<std::string, std::string> riverFiles;
|
||||
std::map<std::string, std::string> roadFiles;
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
terrainFiles[terrain->name] = terrain->tilesFilename;
|
||||
terrainFiles[terrain.name] = terrain.tilesFilename;
|
||||
}
|
||||
for(const auto * river : VLC->terrainTypeHandler->rivers())
|
||||
{
|
||||
|
@ -499,25 +499,25 @@ std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
|
||||
{
|
||||
std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > ret;
|
||||
|
||||
for(const auto * terrain : CGI->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : CGI->terrainTypeHandler->terrains())
|
||||
{
|
||||
SDL_Color normal =
|
||||
{
|
||||
ui8(terrain->minimapUnblocked[0]),
|
||||
ui8(terrain->minimapUnblocked[1]),
|
||||
ui8(terrain->minimapUnblocked[2]),
|
||||
ui8(terrain.minimapUnblocked[0]),
|
||||
ui8(terrain.minimapUnblocked[1]),
|
||||
ui8(terrain.minimapUnblocked[2]),
|
||||
ui8(255)
|
||||
};
|
||||
|
||||
SDL_Color blocked =
|
||||
{
|
||||
ui8(terrain->minimapBlocked[0]),
|
||||
ui8(terrain->minimapBlocked[1]),
|
||||
ui8(terrain->minimapBlocked[2]),
|
||||
ui8(terrain.minimapBlocked[0]),
|
||||
ui8(terrain.minimapBlocked[1]),
|
||||
ui8(terrain.minimapBlocked[2]),
|
||||
ui8(255)
|
||||
};
|
||||
|
||||
ret[terrain->id] = std::make_pair(normal, blocked);
|
||||
ret[terrain.id] = std::make_pair(normal, blocked);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -338,10 +338,10 @@ CGeneralTextHandler::CGeneralTextHandler()
|
||||
{
|
||||
terrainNames[i] = h3mTerrainNames[i];
|
||||
}
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
if(!terrain->terrainText.empty())
|
||||
terrainNames[terrain->id] = terrain->terrainText;
|
||||
if(!terrain.terrainText.empty())
|
||||
terrainNames[terrain.id] = terrain.terrainText;
|
||||
}
|
||||
|
||||
|
||||
|
@ -346,7 +346,7 @@ CHeroHandler::CHeroHandler()
|
||||
loadTerrains();
|
||||
for(int i = 0; i < VLC->terrainTypeHandler->terrains().size(); ++i)
|
||||
{
|
||||
VLC->modh->identifiers.registerObject("core", "terrain", VLC->terrainTypeHandler->terrains()[i]->name, i);
|
||||
VLC->modh->identifiers.registerObject("core", "terrain", VLC->terrainTypeHandler->terrains()[i].name, i);
|
||||
}
|
||||
loadBallistics();
|
||||
loadExperience();
|
||||
@ -972,9 +972,9 @@ ui64 CHeroHandler::reqExp (ui32 level) const
|
||||
|
||||
void CHeroHandler::loadTerrains()
|
||||
{
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
terrCosts[terrain->id] = terrain->moveCost;
|
||||
terrCosts[terrain.id] = terrain.moveCost;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1008,10 +1008,10 @@ bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
|
||||
|
||||
TurnInfo::BonusCache::BonusCache(TConstBonusListPtr bl)
|
||||
{
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
noTerrainPenalty.push_back(static_cast<bool>(
|
||||
bl->getFirst(Selector::type()(Bonus::NO_TERRAIN_PENALTY).And(Selector::subtype()(terrain->id)))));
|
||||
bl->getFirst(Selector::type()(Bonus::NO_TERRAIN_PENALTY).And(Selector::subtype()(terrain.id)))));
|
||||
}
|
||||
|
||||
freeShipBoarding = static_cast<bool>(bl->getFirst(Selector::type()(Bonus::FREE_SHIP_BOARDING)));
|
||||
|
@ -2137,7 +2137,7 @@ int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
|
||||
std::string CreatureTerrainLimiter::toString() const
|
||||
{
|
||||
boost::format fmt("CreatureTerrainLimiter(terrainType=%s)");
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType]->name;
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType].name;
|
||||
fmt % (terrainType == Terrain::NATIVE_TERRAIN ? "native" : terrainName);
|
||||
return fmt.str();
|
||||
}
|
||||
@ -2147,7 +2147,7 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
|
||||
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
root["type"].String() = "CREATURE_TERRAIN_LIMITER";
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType]->name;
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType].name;
|
||||
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName));
|
||||
|
||||
return root;
|
||||
|
175
lib/Terrain.cpp
175
lib/Terrain.cpp
@ -31,10 +31,6 @@ TerrainTypeHandler::TerrainTypeHandler()
|
||||
|
||||
TerrainTypeHandler::~TerrainTypeHandler()
|
||||
{
|
||||
for (const auto * terrain : objects)
|
||||
{
|
||||
delete terrain;
|
||||
}
|
||||
for (const auto * river : riverTypes)
|
||||
{
|
||||
delete river;
|
||||
@ -49,7 +45,7 @@ void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfig
|
||||
{
|
||||
std::vector<std::function<void()>> resolveLater;
|
||||
|
||||
objects.resize(Terrain::ORIGINAL_TERRAIN_COUNT, nullptr); //make space for original terrains
|
||||
objects.resize(Terrain::ORIGINAL_TERRAIN_COUNT); //make space for original terrains
|
||||
|
||||
for(auto & mod : allConfigs)
|
||||
{
|
||||
@ -59,11 +55,11 @@ void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfig
|
||||
JsonNode terrs(mod, ResourceID("config/terrains.json"));
|
||||
for(auto & terr : terrs.Struct())
|
||||
{
|
||||
auto * info = new TerrainType(terr.first); //set name
|
||||
TerrainType info(terr.first); //set name
|
||||
|
||||
info->moveCost = terr.second["moveCost"].Integer();
|
||||
info.moveCost = static_cast<int>(terr.second["moveCost"].Integer());
|
||||
const JsonVector &unblockedVec = terr.second["minimapUnblocked"].Vector();
|
||||
info->minimapUnblocked =
|
||||
info.minimapUnblocked =
|
||||
{
|
||||
ui8(unblockedVec[0].Float()),
|
||||
ui8(unblockedVec[1].Float()),
|
||||
@ -71,18 +67,18 @@ void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfig
|
||||
};
|
||||
|
||||
const JsonVector &blockedVec = terr.second["minimapBlocked"].Vector();
|
||||
info->minimapBlocked =
|
||||
info.minimapBlocked =
|
||||
{
|
||||
ui8(blockedVec[0].Float()),
|
||||
ui8(blockedVec[1].Float()),
|
||||
ui8(blockedVec[2].Float())
|
||||
};
|
||||
info->musicFilename = terr.second["music"].String();
|
||||
info->tilesFilename = terr.second["tiles"].String();
|
||||
info.musicFilename = terr.second["music"].String();
|
||||
info.tilesFilename = terr.second["tiles"].String();
|
||||
|
||||
if(terr.second["type"].isNull())
|
||||
{
|
||||
info->passabilityType = TerrainType::PassabilityType::LAND | TerrainType::PassabilityType::SURFACE;
|
||||
info.passabilityType = TerrainType::PassabilityType::LAND | TerrainType::PassabilityType::SURFACE;
|
||||
}
|
||||
else if (terr.second["type"].getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
@ -90,122 +86,125 @@ void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfig
|
||||
{
|
||||
//Set bits
|
||||
auto s = node.String();
|
||||
if (s == "LAND") info->passabilityType |= TerrainType::PassabilityType::LAND;
|
||||
if (s == "WATER") info->passabilityType |= TerrainType::PassabilityType::WATER;
|
||||
if (s == "ROCK") info->passabilityType |= TerrainType::PassabilityType::ROCK;
|
||||
if (s == "SURFACE") info->passabilityType |= TerrainType::PassabilityType::SURFACE;
|
||||
if (s == "SUB") info->passabilityType |= TerrainType::PassabilityType::SUBTERRANEAN;
|
||||
if (s == "LAND") info.passabilityType |= TerrainType::PassabilityType::LAND;
|
||||
if (s == "WATER") info.passabilityType |= TerrainType::PassabilityType::WATER;
|
||||
if (s == "ROCK") info.passabilityType |= TerrainType::PassabilityType::ROCK;
|
||||
if (s == "SURFACE") info.passabilityType |= TerrainType::PassabilityType::SURFACE;
|
||||
if (s == "SUB") info.passabilityType |= TerrainType::PassabilityType::SUBTERRANEAN;
|
||||
}
|
||||
}
|
||||
else //should be string - one option only
|
||||
{
|
||||
auto s = terr.second["type"].String();
|
||||
if (s == "LAND") info->passabilityType = TerrainType::PassabilityType::LAND;
|
||||
if (s == "WATER") info->passabilityType = TerrainType::PassabilityType::WATER;
|
||||
if (s == "ROCK") info->passabilityType = TerrainType::PassabilityType::ROCK;
|
||||
if (s == "SURFACE") info->passabilityType = TerrainType::PassabilityType::SURFACE;
|
||||
if (s == "SUB") info->passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
|
||||
}
|
||||
|
||||
if(terr.second["rockTerrain"].isNull())
|
||||
{
|
||||
info->rockTerrain = Terrain::ROCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto rockTerrainName = terr.second["rockTerrain"].String();
|
||||
resolveLater.push_back([this, rockTerrainName, info]()
|
||||
{
|
||||
info->rockTerrain = getInfoByName(rockTerrainName)->id;
|
||||
});
|
||||
if (s == "LAND") info.passabilityType = TerrainType::PassabilityType::LAND;
|
||||
if (s == "WATER") info.passabilityType = TerrainType::PassabilityType::WATER;
|
||||
if (s == "ROCK") info.passabilityType = TerrainType::PassabilityType::ROCK;
|
||||
if (s == "SURFACE") info.passabilityType = TerrainType::PassabilityType::SURFACE;
|
||||
if (s == "SUB") info.passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
|
||||
}
|
||||
|
||||
if(terr.second["river"].isNull())
|
||||
{
|
||||
info->river = River::NO_RIVER;
|
||||
info.river = River::NO_RIVER;
|
||||
}
|
||||
else
|
||||
{
|
||||
info->river = getRiverByCode(terr.second["river"].String())->id;
|
||||
info.river = getRiverByCode(terr.second["river"].String())->id;
|
||||
}
|
||||
|
||||
if(terr.second["horseSoundId"].isNull())
|
||||
{
|
||||
info->horseSoundId = Terrain::ROCK; //rock sound as default
|
||||
info.horseSoundId = Terrain::ROCK; //rock sound as default
|
||||
}
|
||||
else
|
||||
{
|
||||
info->horseSoundId = terr.second["horseSoundId"].Float();
|
||||
info.horseSoundId = static_cast<int>(terr.second["horseSoundId"].Float());
|
||||
}
|
||||
|
||||
if(!terr.second["text"].isNull())
|
||||
{
|
||||
info->terrainText = terr.second["text"].String();
|
||||
info.terrainText = terr.second["text"].String();
|
||||
}
|
||||
|
||||
if(terr.second["code"].isNull())
|
||||
{
|
||||
info->typeCode = terr.first.substr(0, 2);
|
||||
info.typeCode = terr.first.substr(0, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
info->typeCode = terr.second["code"].String();
|
||||
assert(info->typeCode.length() == 2);
|
||||
info.typeCode = terr.second["code"].String();
|
||||
assert(info.typeCode.length() == 2);
|
||||
}
|
||||
|
||||
if(!terr.second["battleFields"].isNull())
|
||||
{
|
||||
for(auto & t : terr.second["battleFields"].Vector())
|
||||
{
|
||||
info->battleFields.emplace_back(t.String());
|
||||
info.battleFields.emplace_back(t.String());
|
||||
}
|
||||
}
|
||||
|
||||
info.transitionRequired = false;
|
||||
if(!terr.second["transitionRequired"].isNull())
|
||||
{
|
||||
info.transitionRequired = terr.second["transitionRequired"].Bool();
|
||||
}
|
||||
|
||||
info.terrainViewPatterns = "normal";
|
||||
if(!terr.second["terrainViewPatterns"].isNull())
|
||||
{
|
||||
info.terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
||||
}
|
||||
|
||||
if(!terr.second["originalTerrainId"].isNull())
|
||||
{
|
||||
//place in reserved slot
|
||||
info.id = (TTerrainId)(terr.second["originalTerrainId"].Float());
|
||||
objects[info.id] = info;
|
||||
}
|
||||
else
|
||||
{
|
||||
//append at the end
|
||||
info.id = static_cast<TTerrainId>(objects.size());
|
||||
objects.push_back(info);
|
||||
}
|
||||
TTerrainId id = info.id;
|
||||
|
||||
//Update terrain with this id in the future, after all terrain types are populated
|
||||
|
||||
if(!terr.second["prohibitTransitions"].isNull())
|
||||
{
|
||||
for(auto & t : terr.second["prohibitTransitions"].Vector())
|
||||
{
|
||||
std::string prohibitedTerrainName = t.String();
|
||||
resolveLater.push_back([this, prohibitedTerrainName, info]()
|
||||
resolveLater.push_back([this, prohibitedTerrainName, id]()
|
||||
{
|
||||
info->prohibitTransitions.emplace_back(getInfoByName(prohibitedTerrainName)->id);
|
||||
//FIXME: is that reference to the element in vector?
|
||||
objects[id].prohibitTransitions.emplace_back(getInfoByName(prohibitedTerrainName)->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
info->transitionRequired = false;
|
||||
if(!terr.second["transitionRequired"].isNull())
|
||||
{
|
||||
info->transitionRequired = terr.second["transitionRequired"].Bool();
|
||||
}
|
||||
|
||||
info->terrainViewPatterns = "normal";
|
||||
if(!terr.second["terrainViewPatterns"].isNull())
|
||||
{
|
||||
info->terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
||||
}
|
||||
|
||||
TTerrainId id = Terrain::WRONG;
|
||||
if(!terr.second["originalTerrainId"].isNull())
|
||||
if(terr.second["rockTerrain"].isNull())
|
||||
{
|
||||
//place in reserved slot
|
||||
id = (TTerrainId)(terr.second["originalTerrainId"].Float());
|
||||
objects[id] = info;
|
||||
objects[id].rockTerrain = Terrain::ROCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
//append at the end
|
||||
id = objects.size();
|
||||
objects.push_back(info);
|
||||
auto rockTerrainName = terr.second["rockTerrain"].String();
|
||||
resolveLater.push_back([this, rockTerrainName, id]()
|
||||
{
|
||||
//FIXME: is that reference to the element in vector?
|
||||
objects[id].rockTerrain = getInfoByName(rockTerrainName)->id;
|
||||
});
|
||||
}
|
||||
info->id = id;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ORIGINAL_TERRAIN_COUNT; i++)
|
||||
{
|
||||
//Make sure that original terrains are loaded
|
||||
assert(objects(i));
|
||||
assert(objects(i).id != Terrain::WRONG);
|
||||
}
|
||||
|
||||
recreateTerrainMaps();
|
||||
@ -243,7 +242,7 @@ void TerrainTypeHandler::initRivers(const std::vector<std::string> & allConfigs)
|
||||
}
|
||||
else
|
||||
{
|
||||
info->id = riverTypes.size();
|
||||
info->id = static_cast<TRiverId>(riverTypes.size());
|
||||
riverTypes.push_back(info);
|
||||
}
|
||||
}
|
||||
@ -278,7 +277,7 @@ void TerrainTypeHandler::initRoads(const std::vector<std::string> & allConfigs)
|
||||
}
|
||||
else
|
||||
{
|
||||
info->id = roadTypes.size();
|
||||
info->id = static_cast<TRoadId>(roadTypes.size());
|
||||
roadTypes.push_back(info);
|
||||
}
|
||||
}
|
||||
@ -289,8 +288,12 @@ void TerrainTypeHandler::initRoads(const std::vector<std::string> & allConfigs)
|
||||
|
||||
void TerrainTypeHandler::recreateTerrainMaps()
|
||||
{
|
||||
for (const TerrainType * terrainInfo : objects)
|
||||
//This assumes the vector will never be updated or reallocated in the future
|
||||
|
||||
for (size_t i = 0; i < objects.size(); i++)
|
||||
{
|
||||
const auto * terrainInfo = &objects[i];
|
||||
|
||||
terrainInfoByName[terrainInfo->name] = terrainInfo;
|
||||
terrainInfoByCode[terrainInfo->typeCode] = terrainInfo;
|
||||
terrainInfoById[terrainInfo->id] = terrainInfo;
|
||||
@ -323,8 +326,9 @@ void TerrainTypeHandler::recreateRoadMaps()
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<TerrainType *> & TerrainTypeHandler::terrains() const
|
||||
const std::vector<TerrainType> & TerrainTypeHandler::terrains() const
|
||||
{
|
||||
//FIXME: somehow make it non-copyable? Pointers must point t original data and not its copy
|
||||
return objects;
|
||||
}
|
||||
|
||||
@ -394,10 +398,13 @@ TerrainType::operator std::string() const
|
||||
}
|
||||
|
||||
TerrainType::TerrainType(const std::string& _name):
|
||||
minimapBlocked({0,0,0}), //black
|
||||
minimapUnblocked({ 128,128,128 }), //grey
|
||||
name(_name),
|
||||
river(River::NO_RIVER),
|
||||
id(Terrain::WRONG),
|
||||
rockTerrain(Terrain::ROCK),
|
||||
moveCost(100),
|
||||
moveCost(GameConstants::BASE_MOVEMENT_COST),
|
||||
horseSoundId(0),
|
||||
passabilityType(0),
|
||||
transitionRequired(false)
|
||||
@ -406,8 +413,25 @@ TerrainType::TerrainType(const std::string& _name):
|
||||
|
||||
TerrainType& TerrainType::operator=(const TerrainType & other)
|
||||
{
|
||||
//TODO
|
||||
battleFields = other.battleFields;
|
||||
prohibitTransitions = other.prohibitTransitions;
|
||||
minimapBlocked = other.minimapBlocked;
|
||||
minimapUnblocked = other.minimapUnblocked;
|
||||
name = other.name;
|
||||
musicFilename = other.musicFilename;
|
||||
tilesFilename = other.tilesFilename;
|
||||
terrainText = other.terrainText;
|
||||
typeCode = other.typeCode;
|
||||
terrainViewPatterns = other.terrainViewPatterns;
|
||||
rockTerrain = other.rockTerrain;
|
||||
river = other.river;
|
||||
|
||||
id = other.id;
|
||||
moveCost = other.moveCost;
|
||||
horseSoundId = other.horseSoundId;
|
||||
passabilityType = other.passabilityType;
|
||||
transitionRequired = other.transitionRequired;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -466,6 +490,7 @@ RiverType::RiverType(const std::string & fileName, const std::string & code, TRi
|
||||
RoadType::RoadType(const std::string& fileName, const std::string& code, TRoadId id):
|
||||
fileName(fileName),
|
||||
code(code),
|
||||
id(id)
|
||||
id(id),
|
||||
movementCost(GameConstants::BASE_MOVEMENT_COST)
|
||||
{
|
||||
}
|
@ -135,7 +135,7 @@ public:
|
||||
TerrainTypeHandler();
|
||||
~TerrainTypeHandler();
|
||||
|
||||
const std::vector<TerrainType *> & terrains() const;
|
||||
const std::vector<TerrainType> & terrains() const;
|
||||
const TerrainType * getInfoByName(const std::string & terrainName) const;
|
||||
const TerrainType * getInfoByCode(const std::string & terrainCode) const;
|
||||
const TerrainType * getInfoById(TTerrainId id) const;
|
||||
@ -166,7 +166,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
std::vector<TerrainType *> objects;
|
||||
std::vector<TerrainType> objects;
|
||||
std::vector<RiverType *> riverTypes;
|
||||
std::vector<RoadType *> roadTypes;
|
||||
|
||||
|
@ -165,10 +165,10 @@ void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
|
||||
//assuming that object can be placed on other land terrains
|
||||
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain::WATER))
|
||||
{
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
if(terrain->isLand() && terrain->isPassable())
|
||||
allowedTerrains.insert(terrain->id);
|
||||
if(terrain.isLand() && terrain.isPassable())
|
||||
allowedTerrains.insert(terrain.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,10 +238,10 @@ void ObjectTemplate::readMap(CBinaryReader & reader)
|
||||
//assuming that object can be placed on other land terrains
|
||||
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain::WATER))
|
||||
{
|
||||
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
if(terrain->isLand() && terrain->isPassable())
|
||||
allowedTerrains.insert(terrain->id);
|
||||
if(terrain.isLand() && terrain.isPassable())
|
||||
allowedTerrains.insert(terrain.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,11 +289,11 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain)
|
||||
}
|
||||
else
|
||||
{
|
||||
for(const auto* terrain : VLC->terrainTypeHandler->terrains())
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
{
|
||||
if(!terrain->isPassable() || terrain->isWater())
|
||||
if(!terrain.isPassable() || terrain.isWater())
|
||||
continue;
|
||||
allowedTerrains.insert(terrain->id);
|
||||
allowedTerrains.insert(terrain.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ void CDrawTerrainOperation::execute()
|
||||
for(const auto & pos : terrainSel.getSelectedItems())
|
||||
{
|
||||
auto & tile = map->getTile(pos);
|
||||
tile.terType = VLC->terrainTypeHandler->terrains()[terType];
|
||||
tile.terType = const_cast<TerrainType*>(&VLC->terrainTypeHandler->terrains()[terType]);
|
||||
invalidateTerrainViews(pos);
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ CTerrainViewPatternConfig::~CTerrainViewPatternConfig()
|
||||
|
||||
const std::vector<CTerrainViewPatternConfig::TVPVector> & CTerrainViewPatternConfig::getTerrainViewPatterns(TTerrainId terrain) const
|
||||
{
|
||||
auto iter = terrainViewPatterns.find(VLC->terrainTypeHandler->terrains()[terrain]->terrainViewPatterns);
|
||||
auto iter = terrainViewPatterns.find(VLC->terrainTypeHandler->terrains()[terrain].terrainViewPatterns);
|
||||
if (iter == terrainViewPatterns.end())
|
||||
return terrainViewPatterns.at("normal");
|
||||
return iter->second;
|
||||
|
@ -921,9 +921,9 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
|
||||
void CMapLoaderH3M::readTerrain()
|
||||
{
|
||||
map->initTerrain();
|
||||
const auto terrains = VLC->terrainTypeHandler->terrains();
|
||||
const auto rivers = VLC->terrainTypeHandler->rivers();
|
||||
const auto roads = VLC->terrainTypeHandler->roads();
|
||||
const auto & terrains = VLC->terrainTypeHandler->terrains();
|
||||
const auto & rivers = VLC->terrainTypeHandler->rivers();
|
||||
const auto & roads = VLC->terrainTypeHandler->roads();
|
||||
|
||||
// Read terrain
|
||||
int3 pos;
|
||||
@ -935,7 +935,7 @@ void CMapLoaderH3M::readTerrain()
|
||||
for(pos.x = 0; pos.x < map->width; pos.x++)
|
||||
{
|
||||
auto & tile = map->getTile(pos);
|
||||
tile.terType = terrains[reader.readUInt8()];
|
||||
tile.terType = const_cast<TerrainType*>(&terrains[reader.readUInt8()]);
|
||||
tile.terView = reader.readUInt8();
|
||||
tile.riverType = rivers[reader.readUInt8()];
|
||||
tile.riverDir = reader.readUInt8();
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
static std::string encode(const si32 index)
|
||||
{
|
||||
const auto& terrains = VLC->terrainTypeHandler->terrains();
|
||||
return (index >=0 && index < terrains.size()) ? terrains[index]->name : "<INVALID TERRAIN>";
|
||||
return (index >=0 && index < terrains.size()) ? terrains[index].name : "<INVALID TERRAIN>";
|
||||
}
|
||||
};
|
||||
|
||||
@ -150,9 +150,9 @@ ZoneOptions::ZoneOptions()
|
||||
terrainTypeLikeZone(NO_ZONE),
|
||||
treasureLikeZone(NO_ZONE)
|
||||
{
|
||||
for(const auto * terr : VLC->terrainTypeHandler->terrains())
|
||||
if(terr->isLand() && terr->isPassable())
|
||||
terrainTypes.insert(terr->id);
|
||||
for(const auto & terr : VLC->terrainTypeHandler->terrains())
|
||||
if(terr.isLand() && terr.isPassable())
|
||||
terrainTypes.insert(terr.id);
|
||||
}
|
||||
|
||||
ZoneOptions & ZoneOptions::operator=(const ZoneOptions & other)
|
||||
|
@ -198,8 +198,8 @@ void CZonePlacer::prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto * terrainType = VLC->terrainTypeHandler->terrains()[tt];
|
||||
if(terrainType->isUnderground() && !terrainType->isSurface())
|
||||
const auto & terrainType = VLC->terrainTypeHandler->terrains()[tt];
|
||||
if(terrainType.isUnderground() && !terrainType.isSurface())
|
||||
{
|
||||
//underground only
|
||||
zonesOnLevel[1]++;
|
||||
|
@ -83,8 +83,8 @@ void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & con
|
||||
//1. Try to make direct connection
|
||||
//Do if it's not prohibited by terrain settings
|
||||
const auto& terrains = VLC->terrainTypeHandler->terrains();
|
||||
bool directProhibited = vstd::contains(terrains[zone.getTerrainType()]->prohibitTransitions, otherZone->getTerrainType())
|
||||
|| vstd::contains(terrains[otherZone->getTerrainType()]->prohibitTransitions, zone.getTerrainType());
|
||||
bool directProhibited = vstd::contains(terrains[zone.getTerrainType()].prohibitTransitions, otherZone->getTerrainType())
|
||||
|| vstd::contains(terrains[otherZone->getTerrainType()].prohibitTransitions, zone.getTerrainType());
|
||||
auto directConnectionIterator = dNeighbourZones.find(otherZoneId);
|
||||
if(!directProhibited && directConnectionIterator != dNeighbourZones.end())
|
||||
{
|
||||
|
@ -117,9 +117,9 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
|
||||
{
|
||||
//collect all water terrain types
|
||||
std::vector<TTerrainId> waterTerrains;
|
||||
for(auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
if(terrain->isWater())
|
||||
waterTerrains.push_back(terrain->id);
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->terrains())
|
||||
if(terrain.isWater())
|
||||
waterTerrains.push_back(terrain.id);
|
||||
|
||||
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, gen.rand));
|
||||
}
|
||||
@ -135,18 +135,18 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
|
||||
}
|
||||
|
||||
//Now, replace disallowed terrains on surface and in the underground
|
||||
const auto* terrainType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()];
|
||||
const auto & terrainType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()];
|
||||
|
||||
if(zone.isUnderground())
|
||||
{
|
||||
if(!terrainType->isUnderground())
|
||||
if(!terrainType.isUnderground())
|
||||
{
|
||||
zone.setTerrainType(Terrain::SUBTERRANEAN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!terrainType->isSurface())
|
||||
if (!terrainType.isSurface())
|
||||
{
|
||||
zone.setTerrainType(Terrain::DIRT);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ void RiverPlacer::init()
|
||||
void RiverPlacer::drawRivers()
|
||||
{
|
||||
map.getEditManager()->getTerrainSelection().setSelection(rivers.getTilesVector());
|
||||
map.getEditManager()->drawRiver(VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->river, &generator.rand);
|
||||
map.getEditManager()->drawRiver(VLC->terrainTypeHandler->terrains()[zone.getTerrainType()].river, &generator.rand);
|
||||
}
|
||||
|
||||
char RiverPlacer::dump(const int3 & t)
|
||||
@ -194,7 +194,7 @@ void RiverPlacer::preprocess()
|
||||
//calculate delta positions
|
||||
if(connectedToWaterZoneId > -1)
|
||||
{
|
||||
auto river = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->river;
|
||||
auto river = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()].river;
|
||||
auto & a = neighbourZonesTiles[connectedToWaterZoneId];
|
||||
auto availableArea = zone.areaPossible() + zone.freePaths();
|
||||
for(auto & tileToProcess : availableArea.getTilesVector())
|
||||
@ -320,7 +320,7 @@ void RiverPlacer::preprocess()
|
||||
|
||||
void RiverPlacer::connectRiver(const int3 & tile)
|
||||
{
|
||||
auto riverType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->river;
|
||||
auto riverType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()].river;
|
||||
auto river = VLC->terrainTypeHandler->rivers()[riverType];
|
||||
if(river->id == River::NO_RIVER)
|
||||
return;
|
||||
|
@ -108,7 +108,7 @@ void Object::Instance::setTemplate(const TTerrainId & terrain)
|
||||
if(dObject.appearance->id == Obj::NO_OBJ)
|
||||
{
|
||||
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain);
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrain]->name;
|
||||
auto terrainName = VLC->terrainTypeHandler->terrains()[terrain].name;
|
||||
if (templates.empty())
|
||||
{
|
||||
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") %
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
void RockPlacer::process()
|
||||
{
|
||||
rockTerrain = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->rockTerrain;
|
||||
assert(!VLC->terrainTypeHandler->terrains()[rockTerrain]->isPassable());
|
||||
rockTerrain = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()].rockTerrain;
|
||||
assert(!VLC->terrainTypeHandler->terrains()[rockTerrain].isPassable());
|
||||
|
||||
accessibleArea = zone.freePaths() + zone.areaUsed();
|
||||
if(auto * m = zone.getModificator<ObjectManager>())
|
||||
|
Loading…
x
Reference in New Issue
Block a user