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

A variety of suggested style tweaks

This commit is contained in:
Tomasz Zieliński 2022-09-25 09:33:56 +02:00
parent fd63cb6109
commit 4ea57ea7fc
66 changed files with 155 additions and 156 deletions

View File

@ -119,7 +119,7 @@ CSoundHandler::CSoundHandler():
void CSoundHandler::loadHorseSounds()
{
auto terrains = CGI->terrainTypeHandler->terrains();
const auto & terrains = CGI->terrainTypeHandler->terrains();
for(const auto * terrain : terrains)
{
//since all sounds are hardcoded, let's keep it
@ -376,7 +376,7 @@ 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);
}

View File

@ -84,7 +84,7 @@ public:
// Sets
std::vector<soundBase::soundID> pickupSounds;
std::vector<soundBase::soundID> battleIntroSounds;
std::map<TTerrain, soundBase::soundID> horseSounds;
std::map<TTerrainId, soundBase::soundID> horseSounds;
};
// Helper //now it looks somewhat useless

View File

@ -2746,8 +2746,8 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
{
path.convert(0);
TTerrain currentTerrain = Terrain::BORDER; // not init yet
TTerrain newTerrain;
TTerrainId currentTerrain = Terrain::BORDER; // not init yet
TTerrainId newTerrain;
int sh = -1;
auto canStop = [&](CGPathNode * node) -> bool

View File

@ -495,9 +495,9 @@ void CMinimapInstance::showAll(SDL_Surface * to)
}
}
std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
{
std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > ret;
std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > ret;
for(const auto * terrain : CGI->terrainTypeHandler->terrains())
{

View File

@ -217,7 +217,7 @@ protected:
int level;
//to initialize colors
std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > loadColors();
std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > loadColors();
void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override;
@ -228,7 +228,7 @@ protected:
public:
// terrainID -> (normal color, blocked color)
const std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > colors;
const std::map<TTerrainId, std::pair<SDL_Color, SDL_Color> > colors;
CMinimap(const Rect & position);

View File

@ -283,13 +283,13 @@ std::string CCreature::nodeName() const
return "\"" + namePl + "\"";
}
bool CCreature::isItNativeTerrain(TTerrain terrain) const
bool CCreature::isItNativeTerrain(TTerrainId terrain) const
{
auto native = getNativeTerrain();
return native == terrain || native == Terrain::ANY_TERRAIN;
}
TTerrain CCreature::getNativeTerrain() const
TTerrainId CCreature::getNativeTerrain() const
{
const std::string cachingStringNoTerrainPenalty = "type_NO_TERRAIN_PENALTY";
static const auto selectorNoTerrainPenalty = Selector::type()(Bonus::NO_TERRAIN_PENALTY);

View File

@ -119,14 +119,14 @@ public:
ArtifactID warMachine;
bool isItNativeTerrain(TTerrain terrain) const;
bool isItNativeTerrain(TTerrainId terrain) const;
/**
Returns creature native terrain considering some terrain bonuses.
@param considerBonus is used to avoid Dead Lock when this method is called inside getAllBonuses
considerBonus = true is called from Pathfinder and fills actual nativeTerrain considering bonus(es).
considerBonus = false is called on Battle init and returns already prepared nativeTerrain without Bonus system calling.
*/
TTerrain getNativeTerrain() const;
TTerrainId getNativeTerrain() const;
int32_t getIndex() const override;
int32_t getIconIndex() const override;
const std::string & getName() const override;

View File

@ -122,7 +122,7 @@ public:
std::vector<std::string> advobtxt;
std::vector<std::string> xtrainfo;
std::vector<std::string> restypes; //names of resources
std::map<TTerrain, std::string> terrainNames;
std::map<TTerrainId, std::string> terrainNames;
std::vector<std::string> randsign;
std::vector<std::pair<std::string,std::string>> mines; //first - name; second - event description
std::vector<std::string> seerEmpty;

View File

@ -265,7 +265,7 @@ public:
CHeroClassHandler classes;
//default costs of going through terrains. -1 means terrain is impassable
std::map<TTerrain, int> terrCosts;
std::map<TTerrainId, int> terrCosts;
struct SBallisticsLevelInfo
{

View File

@ -527,7 +527,7 @@ struct DLL_LINKAGE TurnInfo
TConstBonusListPtr bonuses;
mutable int maxMovePointsLand;
mutable int maxMovePointsWater;
TTerrain nativeTerrain;
TTerrainId nativeTerrain;
TurnInfo(const CGHeroInstance * Hero, const int Turn = 0);
bool isLayerAvailable(const EPathfindingLayer layer) const;

View File

@ -332,7 +332,7 @@ bool CStack::isOnNativeTerrain() const
return res;
}
bool CStack::isOnTerrain(TTerrain terrain) const
bool CStack::isOnTerrain(TTerrainId terrain) const
{
return battle->getTerrainType() == terrain;
}

View File

@ -29,7 +29,7 @@ public:
ui32 ID; //unique ID of stack
const CCreature * type;
TTerrain nativeTerrain; //tmp variable to save native terrain value on battle init
TTerrainId nativeTerrain; //tmp variable to save native terrain value on battle init
ui32 baseAmount;
PlayerColor owner; //owner - player color (255 for neutrals)
@ -51,7 +51,7 @@ public:
bool canBeHealed() const; //for first aid tent - only harmed stacks that are not war machines
bool isOnNativeTerrain() const;
bool isOnTerrain(TTerrain terrain) const;
bool isOnTerrain(TTerrainId terrain) const;
ui32 level() const;
si32 magicResistance() const override; //include aura of resistance

View File

@ -26,9 +26,9 @@
const int NAMES_PER_TOWN=16; // number of town names per faction in H3 files. Json can define any number
const TTerrain CTownHandler::defaultGoodTerrain(Terrain::GRASS);
const TTerrain CTownHandler::defaultEvilTerrain(Terrain::LAVA);
const TTerrain CTownHandler::defaultNeutralTerrain(Terrain::ROUGH);
const TTerrainId CTownHandler::defaultGoodTerrain(Terrain::GRASS);
const TTerrainId CTownHandler::defaultEvilTerrain(Terrain::LAVA);
const TTerrainId CTownHandler::defaultNeutralTerrain(Terrain::ROUGH);
const std::map<std::string, CBuilding::EBuildMode> CBuilding::MODES =
{
@ -942,9 +942,9 @@ void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source)
assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES);
}
TTerrain CTownHandler::getDefaultTerrainForAlignment(EAlignment::EAlignment alignment) const
TTerrainId CTownHandler::getDefaultTerrainForAlignment(EAlignment::EAlignment alignment) const
{
TTerrain terrain = defaultGoodTerrain;
TTerrainId terrain = defaultGoodTerrain;
switch(alignment)
{

View File

@ -185,7 +185,7 @@ public:
TFaction index;
TTerrain nativeTerrain;
TTerrainId nativeTerrain;
EAlignment::EAlignment alignment;
bool preferUndergroundPlacement;
@ -358,9 +358,9 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
std::vector<BuildingRequirementsHelper> requirementsToLoad;
std::vector<BuildingRequirementsHelper> overriddenBidsToLoad; //list of buildings, which bonuses should be overridden.
const static TTerrain defaultGoodTerrain;
const static TTerrain defaultEvilTerrain;
const static TTerrain defaultNeutralTerrain;
const static TTerrainId defaultGoodTerrain;
const static TTerrainId defaultEvilTerrain;
const static TTerrainId defaultNeutralTerrain;
static TPropagatorPtr & emptyPropagator();
@ -391,7 +391,7 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
void loadPuzzle(CFaction & faction, const JsonNode & source);
TTerrain getDefaultTerrainForAlignment(EAlignment::EAlignment aligment) const;
TTerrainId getDefaultTerrainForAlignment(EAlignment::EAlignment aligment) const;
void loadRandomFaction();

View File

@ -1230,9 +1230,9 @@ typedef si64 TExpType;
typedef std::pair<si64, si64> TDmgRange;
typedef si32 TBonusSubtype;
typedef si32 TQuantity;
typedef si8 TTerrain;
typedef si8 TRoad;
typedef si8 TRiver;
typedef si8 TTerrainId;
typedef si8 TRoadId;
typedef si8 TRiverId;
typedef int TRmgTemplateZoneId;

View File

@ -2111,7 +2111,7 @@ CreatureTerrainLimiter::CreatureTerrainLimiter()
{
}
CreatureTerrainLimiter::CreatureTerrainLimiter(TTerrain terrain):
CreatureTerrainLimiter::CreatureTerrainLimiter(TTerrainId terrain):
terrainType(terrain)
{
}

View File

@ -1060,9 +1060,9 @@ public:
class DLL_LINKAGE CreatureTerrainLimiter : public ILimiter //applies only to creatures that are on specified terrain, default native terrain
{
public:
TTerrain terrainType;
TTerrainId terrainType;
CreatureTerrainLimiter();
CreatureTerrainLimiter(TTerrain terrain);
CreatureTerrainLimiter(TTerrainId terrain);
int limit(const BonusLimitationContext &context) const override;
virtual std::string toString() const override;

View File

@ -701,7 +701,7 @@ DLL_LINKAGE void GiveHero::applyGs(CGameState *gs)
DLL_LINKAGE void NewObject::applyGs(CGameState *gs)
{
TTerrain terrainType = Terrain::BORDER;
TTerrainId terrainType = Terrain::BORDER;
if(ID == Obj::BOAT && !gs->isInTheMap(pos)) //special handling for bug #3060 - pos outside map but visitablePos is not
{

View File

@ -66,7 +66,7 @@ std::vector<BattleHex> ObstacleInfo::getBlocked(BattleHex hex) const
return ret;
}
bool ObstacleInfo::isAppropriate(const TTerrain terrainType, const BattleField & battlefield) const
bool ObstacleInfo::isAppropriate(const TTerrainId terrainType, const BattleField & battlefield) const
{
auto bgInfo = battlefield.getInfo();

View File

@ -31,7 +31,7 @@ public:
si32 iconIndex;
std::string identifier;
std::string appearAnimation, animation, dissapearAnimation;
std::vector<TTerrain> allowedTerrains;
std::vector<TTerrainId> allowedTerrains;
std::vector<std::string> allowedSpecialBfields;
//TODO: here is extra field to implement it's logic in the future but save backward compatibility
@ -50,7 +50,7 @@ public:
std::vector<BattleHex> getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
bool isAppropriate(const TTerrain terrainType, const BattleField & specialBattlefield) const;
bool isAppropriate(const TTerrainId terrainType, const BattleField & specialBattlefield) const;
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -169,11 +169,11 @@ void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfig
info->terrainViewPatterns = terr.second["terrainViewPatterns"].String();
}
TTerrain id = Terrain::WRONG;
TTerrainId id = Terrain::WRONG;
if(!terr.second["originalTerrainId"].isNull())
{
//place in reserved slot
id = (TTerrain)(terr.second["originalTerrainId"].Float());
id = (TTerrainId)(terr.second["originalTerrainId"].Float());
objects[id] = info;
}
else
@ -222,7 +222,7 @@ void TerrainTypeHandler::initRivers(const std::vector<std::string> & allConfigs)
if (!river.second["originalRiverId"].isNull())
{
info->id = static_cast<TRiver>(river.second["originalRiverId"].Float());
info->id = static_cast<TRiverId>(river.second["originalRiverId"].Float());
riverTypes[info->id] = info;
}
else
@ -257,7 +257,7 @@ void TerrainTypeHandler::initRoads(const std::vector<std::string> & allConfigs)
if (!road.second["originalRoadId"].isNull())
{
info->id = static_cast<TRoad>(road.second["originalRoadId"].Float());
info->id = static_cast<TRoadId>(road.second["originalRoadId"].Float());
roadTypes[info->id] = info;
}
else
@ -332,7 +332,7 @@ const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainC
return terrainInfoByCode.at(terrainCode);
}
const TerrainType* TerrainTypeHandler::getInfoById(TTerrain id) const
const TerrainType* TerrainTypeHandler::getInfoById(TTerrainId id) const
{
return terrainInfoById.at(id);
}
@ -347,7 +347,7 @@ const RiverType* TerrainTypeHandler::getRiverByCode(const std::string& riverCode
return riverInfoByCode.at(riverCode);
}
const RiverType* TerrainTypeHandler::getRiverById(TRiver id) const
const RiverType* TerrainTypeHandler::getRiverById(TRiverId id) const
{
return riverInfoById.at(id);
}
@ -362,7 +362,7 @@ const RoadType* TerrainTypeHandler::getRoadByCode(const std::string& roadCode) c
return roadInfoByCode.at(roadCode);
}
const RoadType* TerrainTypeHandler::getRoadById(TRoad id) const
const RoadType* TerrainTypeHandler::getRoadById(TRoadId id) const
{
return roadInfoById.at(id);
}
@ -440,17 +440,16 @@ bool TerrainType::isTransitionRequired() const
return transitionRequired;
}
RiverType::RiverType(const std::string & fileName, const std::string & code, TRiver id):
RiverType::RiverType(const std::string & fileName, const std::string & code, TRiverId id):
fileName(fileName),
code(code),
id(id)
{
}
RoadType::RoadType(const std::string& fileName, const std::string& code, TRoad id):
RoadType::RoadType(const std::string& fileName, const std::string& code, TRoadId id):
fileName(fileName),
code(code),
id(id),
movementCost(GameConstants::BASE_MOVEMENT_COST)
id(id)
{
}

View File

@ -29,7 +29,7 @@ public:
};
std::vector<std::string> battleFields;
std::vector<TTerrain> prohibitTransitions;
std::vector<TTerrainId> prohibitTransitions;
std::array<int, 3> minimapBlocked;
std::array<int, 3> minimapUnblocked;
std::string name;
@ -38,10 +38,10 @@ public:
std::string terrainText;
std::string typeCode;
std::string terrainViewPatterns;
TRiver river;
TRiverId river;
TTerrain id;
TTerrain rockTerrain;
TTerrainId id;
TTerrainId rockTerrain;
int moveCost;
int horseSoundId;
ui8 passabilityType;
@ -94,9 +94,9 @@ public:
std::string fileName;
std::string code;
std::string deltaName;
TRiver id;
TRiverId id;
RiverType(const std::string & fileName = "", const std::string& code = "", TRiver id = River::NO_RIVER);
RiverType(const std::string & fileName = "", const std::string & code = "", TRiverId id = River::NO_RIVER);
template <typename Handler> void serialize(Handler& h, const int version)
{
@ -112,10 +112,10 @@ class DLL_LINKAGE RoadType
public:
std::string fileName;
std::string code;
TRoad id;
TRoadId id;
ui8 movementCost;
RoadType(const std::string & fileName = "", const std::string& code = "", TRoad id = Road::NO_ROAD);
RoadType(const std::string & fileName = "", const std::string& code = "", TRoadId id = Road::NO_ROAD);
template <typename Handler> void serialize(Handler& h, const int version)
{
@ -133,24 +133,21 @@ class DLL_LINKAGE TerrainTypeHandler //TODO: public IHandlerBase ?
public:
TerrainTypeHandler();
void initTerrains(const std::vector<std::string> & allConfigs);
void initRivers(const std::vector<std::string> & allConfigs);
void initRoads(const std::vector<std::string> & allConfigs);
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(TTerrain id) const;
const TerrainType * getInfoById(TTerrainId id) const;
const std::vector<RiverType *> & rivers() const;
const RiverType * getRiverByName(const std::string & riverName) const;
const RiverType * getRiverByCode(const std::string & riverCode) const;
const RiverType * getRiverById(TRiver id) const;
const RiverType * getRiverById(TRiverId id) const;
const std::vector<RoadType *> & roads() const;
const RoadType * getRoadByName(const std::string & roadName) const;
const RoadType * getRoadByCode(const std::string & roadCode) const;
const RoadType * getRoadById(TRoad id) const;
const RoadType * getRoadById(TRoadId id) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -174,16 +171,19 @@ private:
std::unordered_map<std::string, const TerrainType*> terrainInfoByName;
std::unordered_map<std::string, const TerrainType*> terrainInfoByCode;
std::unordered_map<TTerrain, const TerrainType*> terrainInfoById;
std::unordered_map<TTerrainId, const TerrainType*> terrainInfoById;
std::unordered_map<std::string, const RiverType*> riverInfoByName;
std::unordered_map<std::string, const RiverType*> riverInfoByCode;
std::unordered_map<TRiver, const RiverType*> riverInfoById;
std::unordered_map<TRiverId, const RiverType*> riverInfoById;
std::unordered_map<std::string, const RoadType*> roadInfoByName;
std::unordered_map<std::string, const RoadType*> roadInfoByCode;
std::unordered_map<TRoad, const RoadType*> roadInfoById;
std::unordered_map<TRoadId, const RoadType*> roadInfoById;
void initTerrains(const std::vector<std::string> & allConfigs);
void initRivers(const std::vector<std::string> & allConfigs);
void initRoads(const std::vector<std::string> & allConfigs);
void recreateTerrainMaps();
void recreateRiverMaps();
void recreateRoadMaps();

View File

@ -189,7 +189,7 @@ struct RangeGenerator
std::function<int()> myRand;
};
BattleInfo * BattleInfo::setupBattle(const int3 & tile, TTerrain terrain, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town)
BattleInfo * BattleInfo::setupBattle(const int3 & tile, TTerrainId terrain, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town)
{
CMP_stack cmpst;
auto curB = new BattleInfo();
@ -563,7 +563,7 @@ BattleField BattleInfo::getBattlefieldType() const
return battlefieldType;
}
TTerrain BattleInfo::getTerrainType() const
TTerrainId BattleInfo::getTerrainType() const
{
return terrainType;
}

View File

@ -37,7 +37,7 @@ public:
SiegeInfo si;
BattleField battlefieldType; //like !!BA:B
TTerrain terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
TTerrainId terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
ui8 tacticsSide; //which side is requested to play tactics phase
ui8 tacticDistance; //how many hexes we can go forward (1 = only hexes adjacent to margin line)
@ -73,7 +73,7 @@ public:
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
BattleField getBattlefieldType() const override;
TTerrain getTerrainType() const override;
TTerrainId getTerrainType() const override;
ObstacleCList getAllObstacles() const override;
@ -138,7 +138,7 @@ public:
const CGHeroInstance * getHero(PlayerColor player) const; //returns fighting hero that belongs to given player
void localInit();
static BattleInfo * setupBattle(const int3 & tile, TTerrain, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town);
static BattleInfo * setupBattle(const int3 & tile, TTerrainId, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town);
ui8 whatSide(PlayerColor player) const;

View File

@ -47,7 +47,7 @@ BattleField BattleProxy::getBattlefieldType() const
return subject->battleGetBattlefieldType();
}
TTerrain BattleProxy::getTerrainType() const
TTerrainId BattleProxy::getTerrainType() const
{
return subject->battleTerrainType();
}

View File

@ -30,7 +30,7 @@ public:
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
BattleField getBattlefieldType() const override;
TTerrain getTerrainType() const override;
TTerrainId getTerrainType() const override;
ObstacleCList getAllObstacles() const override;

View File

@ -14,9 +14,9 @@
#include "../NetPacks.h"
#include "../mapObjects/CGTownInstance.h"
TTerrain CBattleInfoEssentials::battleTerrainType() const
TTerrainId CBattleInfoEssentials::battleTerrainType() const
{
RETURN_IF_NOT_BATTLE(TTerrain());
RETURN_IF_NOT_BATTLE(TTerrainId());
return getBattle()->getTerrainType();
}

View File

@ -46,7 +46,7 @@ public:
BattlePerspective::BattlePerspective battleGetMySide() const;
const IBonusBearer * getBattleNode() const;
TTerrain battleTerrainType() const override;
TTerrainId battleTerrainType() const override;
BattleField battleGetBattlefieldType() const override;
int32_t battleGetEnchanterCounter(ui8 side) const;

View File

@ -38,7 +38,7 @@ public:
virtual scripting::Pool * getContextPool() const = 0;
#endif
virtual TTerrain battleTerrainType() const = 0;
virtual TTerrainId battleTerrainType() const = 0;
virtual BattleField battleGetBattlefieldType() const = 0;
///return none if battle is ongoing; otherwise the victorious side (0/1) or 2 if it is a draw

View File

@ -42,7 +42,7 @@ public:
virtual battle::Units getUnitsIf(battle::UnitFilter predicate) const = 0;
virtual BattleField getBattlefieldType() const = 0;
virtual TTerrain getTerrainType() const = 0;
virtual TTerrainId getTerrainType() const = 0;
virtual ObstacleCList getAllObstacles() const = 0;

View File

@ -96,7 +96,7 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile & dest, const TerrainTile & f
return (ui32)ret;
}
TTerrain CGHeroInstance::getNativeTerrain() const
TTerrainId CGHeroInstance::getNativeTerrain() const
{
// NOTE: in H3 neutral stacks will ignore terrain penalty only if placed as topmost stack(s) in hero army.
// This is clearly bug in H3 however intended behaviour is not clear.
@ -104,11 +104,11 @@ TTerrain CGHeroInstance::getNativeTerrain() const
// will always have best penalty without any influence from player-defined stacks order
// TODO: What should we do if all hero stacks are neutral creatures?
TTerrain nativeTerrain = Terrain::BORDER;
TTerrainId nativeTerrain = Terrain::BORDER;
for(auto stack : stacks)
{
TTerrain stackNativeTerrain = stack.second->type->getNativeTerrain(); //consider terrain bonuses e.g. Lodestar.
TTerrainId stackNativeTerrain = stack.second->type->getNativeTerrain(); //consider terrain bonuses e.g. Lodestar.
if(stackNativeTerrain == Terrain::BORDER) //where does this value come from?
continue;

View File

@ -155,7 +155,7 @@ public:
bool needsLastStack()const override;
ui32 getTileCost(const TerrainTile &dest, const TerrainTile &from, const TurnInfo * ti) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling
TTerrain getNativeTerrain() const;
TTerrainId getNativeTerrain() const;
ui32 getLowestCreatureSpeed() const;
int3 getPosition(bool h3m = false) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day

View File

@ -588,7 +588,7 @@ BattleField AObjectTypeHandler::getBattlefield() const
return battlefield ? BattleField::fromString(battlefield.get()) : BattleField::NONE;
}
std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplates(TTerrain terrainType) const
std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplates(TTerrainId terrainType) const
{
std::vector<std::shared_ptr<const ObjectTemplate>> templates = getTemplates();
std::vector<std::shared_ptr<const ObjectTemplate>> filtered;
@ -605,7 +605,7 @@ std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplat
return filtered;
}
std::shared_ptr<const ObjectTemplate> AObjectTypeHandler::getOverride(TTerrain terrainType, const CGObjectInstance * object) const
std::shared_ptr<const ObjectTemplate> AObjectTypeHandler::getOverride(TTerrainId terrainType, const CGObjectInstance * object) const
{
std::vector<std::shared_ptr<const ObjectTemplate>> ret = getTemplates(terrainType);
for (const auto & tmpl: ret)

View File

@ -182,11 +182,11 @@ public:
/// returns all templates matching parameters
std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates() const;
std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates(const TTerrain terrainType) const;
std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates(const TTerrainId terrainType) const;
/// returns preferred template for this object, if present (e.g. one of 3 possible templates for town - village, fort and castle)
/// note that appearance will not be changed - this must be done separately (either by assignment or via pack from server)
std::shared_ptr<const ObjectTemplate> getOverride(TTerrain terrainType, const CGObjectInstance * object) const;
std::shared_ptr<const ObjectTemplate> getOverride(TTerrainId terrainType, const CGObjectInstance * object) const;
BattleField getBattlefield() const;

View File

@ -156,7 +156,7 @@ void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
std::string & terrStr = strings[4]; // allowed terrains, 1 = object can be placed on this terrain
assert(terrStr.size() == Terrain::ROCK - 1); // all terrains but rock
for(TTerrain i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ROCK; i++)
for(TTerrainId i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ROCK; i++)
{
if (terrStr[8-i] == '1')
allowedTerrains.insert(i);
@ -282,22 +282,22 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain)
else
visitDir = 0x00;
if (withTerrain && !node["allowedTerrains"].isNull())
if(withTerrain && !node["allowedTerrains"].isNull())
{
for (auto& entry : node["allowedTerrains"].Vector())
for(auto& entry : node["allowedTerrains"].Vector())
allowedTerrains.insert(VLC->terrainTypeHandler->getInfoByName(entry.String())->id);
}
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);
}
}
if (withTerrain && allowedTerrains.empty())
if(withTerrain && allowedTerrains.empty())
logGlobal->warn("Loaded template without allowed terrains!");
auto charToTile = [&](const char & ch) -> ui8
@ -555,7 +555,7 @@ void ObjectTemplate::calculateVisitableOffset()
visitableOffset = int3(0, 0, 0);
}
bool ObjectTemplate::canBePlacedAt(TTerrain terrain) const
bool ObjectTemplate::canBePlacedAt(TTerrainId terrain) const
{
return vstd::contains(allowedTerrains, terrain);
}

View File

@ -31,7 +31,7 @@ class DLL_LINKAGE ObjectTemplate
/// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
ui8 visitDir;
/// list of terrains on which this object can be placed
std::set<TTerrain> allowedTerrains;
std::set<TTerrainId> allowedTerrains;
void afterLoadFixup();
@ -98,7 +98,7 @@ public:
};
// Checks if object can be placed on specific terrain
bool canBePlacedAt(TTerrain terrain) const;
bool canBePlacedAt(TTerrainId terrain) const;
ObjectTemplate();
//custom copy constructor is required

View File

@ -156,14 +156,14 @@ CDrawLinesOperation::CDrawLinesOperation(CMap * map, const CTerrainSelection & t
}
///CDrawRoadsOperation
CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, TRoad roadType, CRandomGenerator * gen):
CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, TRoadId roadType, CRandomGenerator * gen):
CDrawLinesOperation(map, terrainSel,gen),
roadType(roadType)
{
}
///CDrawRiversOperation
CDrawRiversOperation::CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, TRiver riverType, CRandomGenerator * gen):
CDrawRiversOperation::CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, TRiverId riverType, CRandomGenerator * gen):
CDrawLinesOperation(map, terrainSel, gen),
riverType(riverType)
{

View File

@ -61,7 +61,7 @@ protected:
class CDrawRoadsOperation : public CDrawLinesOperation
{
public:
CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, TRoad roadType, CRandomGenerator * gen);
CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, TRoadId roadType, CRandomGenerator * gen);
std::string getLabel() const override;
protected:
@ -72,13 +72,13 @@ protected:
void updateTile(TerrainTile & tile, const CDrawLinesOperation::LinePattern & pattern, const int flip) override;
private:
TRoad roadType;
TRoadId roadType;
};
class CDrawRiversOperation : public CDrawLinesOperation
{
public:
CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, TRoad roadType, CRandomGenerator * gen);
CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, TRoadId roadType, CRandomGenerator * gen);
std::string getLabel() const override;
protected:
@ -89,5 +89,5 @@ protected:
void updateTile(TerrainTile & tile, const CDrawLinesOperation::LinePattern & pattern, const int flip) override;
private:
TRiver riverType;
TRiverId riverType;
};

View File

@ -124,19 +124,19 @@ void CMapEditManager::clearTerrain(CRandomGenerator * gen)
execute(make_unique<CClearTerrainOperation>(map, gen ? gen : &(this->gen)));
}
void CMapEditManager::drawTerrain(TTerrain terType, CRandomGenerator * gen)
void CMapEditManager::drawTerrain(TTerrainId terType, CRandomGenerator * gen)
{
execute(make_unique<CDrawTerrainOperation>(map, terrainSel, terType, gen ? gen : &(this->gen)));
terrainSel.clearSelection();
}
void CMapEditManager::drawRoad(TRoad roadType, CRandomGenerator* gen)
void CMapEditManager::drawRoad(TRoadId roadType, CRandomGenerator* gen)
{
execute(make_unique<CDrawRoadsOperation>(map, terrainSel, roadType, gen ? gen : &(this->gen)));
terrainSel.clearSelection();
}
void CMapEditManager::drawRiver(TRiver riverType, CRandomGenerator* gen)
void CMapEditManager::drawRiver(TRiverId riverType, CRandomGenerator* gen)
{
execute(make_unique<CDrawRiversOperation>(map, terrainSel, riverType, gen ? gen : &(this->gen)));
terrainSel.clearSelection();

View File

@ -70,13 +70,13 @@ public:
void clearTerrain(CRandomGenerator * gen = nullptr);
/// Draws terrain at the current terrain selection. The selection will be cleared automatically.
void drawTerrain(TTerrain terType, CRandomGenerator * gen = nullptr);
void drawTerrain(TTerrainId terType, CRandomGenerator * gen = nullptr);
/// Draws roads at the current terrain selection. The selection will be cleared automatically.
void drawRoad(TRoad roadType, CRandomGenerator * gen = nullptr);
void drawRoad(TRoadId roadType, CRandomGenerator * gen = nullptr);
/// Draws rivers at the current terrain selection. The selection will be cleared automatically.
void drawRiver(TRiver riverType, CRandomGenerator * gen = nullptr);
void drawRiver(TRiverId riverType, CRandomGenerator * gen = nullptr);
void insertObject(CGObjectInstance * obj);
void insertObjects(std::set<CGObjectInstance *> & objects);

View File

@ -81,7 +81,7 @@ void CComposedOperation::addOperation(std::unique_ptr<CMapOperation>&& operation
operations.push_back(std::move(operation));
}
CDrawTerrainOperation::CDrawTerrainOperation(CMap* map, const CTerrainSelection& terrainSel, TTerrain terType, CRandomGenerator* gen):
CDrawTerrainOperation::CDrawTerrainOperation(CMap* map, const CTerrainSelection& terrainSel, TTerrainId terType, CRandomGenerator* gen):
CMapOperation(map),
terrainSel(terrainSel),
terType(terType),

View File

@ -61,7 +61,7 @@ private:
class CDrawTerrainOperation : public CMapOperation
{
public:
CDrawTerrainOperation(CMap * map, const CTerrainSelection & terrainSel, TTerrain terType, CRandomGenerator * gen);
CDrawTerrainOperation(CMap * map, const CTerrainSelection & terrainSel, TTerrainId terType, CRandomGenerator * gen);
void execute() override;
void undo() override;
@ -98,7 +98,7 @@ private:
ValidationResult validateTerrainViewInner(const int3 & pos, const TerrainViewPattern & pattern, int recDepth = 0) const;
CTerrainSelection terrainSel;
TTerrain terType;
TTerrainId terType;
CRandomGenerator* gen;
std::set<int3> invalidatedTerViews;
};

View File

@ -268,7 +268,7 @@ CTerrainViewPatternConfig::~CTerrainViewPatternConfig()
}
const std::vector<CTerrainViewPatternConfig::TVPVector> & CTerrainViewPatternConfig::getTerrainViewPatterns(TTerrain terrain) const
const std::vector<CTerrainViewPatternConfig::TVPVector> & CTerrainViewPatternConfig::getTerrainViewPatterns(TTerrainId terrain) const
{
auto iter = terrainViewPatterns.find(VLC->terrainTypeHandler->terrains()[terrain]->terrainViewPatterns);
if (iter == terrainViewPatterns.end())
@ -293,7 +293,7 @@ boost::optional<const TerrainViewPattern &> CTerrainViewPatternConfig::getTerrai
return boost::optional<const TerrainViewPattern&>();
}
boost::optional<const CTerrainViewPatternConfig::TVPVector &> CTerrainViewPatternConfig::getTerrainViewPatternsById(TTerrain terrain, const std::string & id) const
boost::optional<const CTerrainViewPatternConfig::TVPVector &> CTerrainViewPatternConfig::getTerrainViewPatternsById(TTerrainId terrain, const std::string & id) const
{
const std::vector<TVPVector> & groupPatterns = getTerrainViewPatterns(terrain);
for (const TVPVector & patternFlips : groupPatterns)

View File

@ -215,9 +215,9 @@ public:
CTerrainViewPatternConfig();
~CTerrainViewPatternConfig();
const std::vector<TVPVector> & getTerrainViewPatterns(TTerrain terrain) const;
const std::vector<TVPVector> & getTerrainViewPatterns(TTerrainId terrain) const;
boost::optional<const TerrainViewPattern &> getTerrainViewPatternById(std::string patternId, const std::string & id) const;
boost::optional<const TVPVector &> getTerrainViewPatternsById(TTerrain terrain, const std::string & id) const;
boost::optional<const TVPVector &> getTerrainViewPatternsById(TTerrainId terrain, const std::string & id) const;
const TVPVector * getTerrainTypePatternById(const std::string & id) const;
void flipPattern(TerrainViewPattern & pattern, int flip) const;

View File

@ -215,12 +215,12 @@ boost::optional<int> ZoneOptions::getOwner() const
return owner;
}
const std::set<TTerrain> & ZoneOptions::getTerrainTypes() const
const std::set<TTerrainId> & ZoneOptions::getTerrainTypes() const
{
return terrainTypes;
}
void ZoneOptions::setTerrainTypes(const std::set<TTerrain> & value)
void ZoneOptions::setTerrainTypes(const std::set<TTerrainId> & value)
{
//assert(value.find(ETerrainType::WRONG) == value.end() && value.find(ETerrainType::BORDER) == value.end() &&
// value.find(ETerrainType::WATER) == value.end() && value.find(ETerrainType::ROCK) == value.end());

View File

@ -103,8 +103,8 @@ public:
void setSize(int value);
boost::optional<int> getOwner() const;
const std::set<TTerrain> & getTerrainTypes() const;
void setTerrainTypes(const std::set<TTerrain> & value);
const std::set<TTerrainId> & getTerrainTypes() const;
void setTerrainTypes(const std::set<TTerrainId> & value);
const CTownInfo & getPlayerTowns() const;
const CTownInfo & getNeutralTowns() const;
@ -144,7 +144,7 @@ protected:
CTownInfo playerTowns;
CTownInfo neutralTowns;
bool matchTerrainToTown;
std::set<TTerrain> terrainTypes;
std::set<TTerrainId> terrainTypes;
bool townsAreSameType;
std::set<TFaction> townTypes;

View File

@ -93,14 +93,14 @@ void createBorder(RmgMap & gen, Zone & zone)
}
}
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrain terrain)
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrainId terrain)
{
auto v = zone.getArea().getTilesVector();
map.getEditManager()->getTerrainSelection().setSelection(v);
map.getEditManager()->drawTerrain(terrain, &generator);
}
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrain terrain)
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrainId terrain)
{
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
vstd::erase_if(factories, [ObjID, &terrain](si32 f)
@ -116,7 +116,7 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
if(zone.getType()==ETemplateZoneType::WATER)
{
//collect all water terrain types
std::vector<TTerrain> waterTerrains;
std::vector<TTerrainId> waterTerrains;
for(auto & terrain : VLC->terrainTypeHandler->terrains())
if(terrain->isWater())
waterTerrains.push_back(terrain->id);

View File

@ -40,9 +40,9 @@ rmg::Tileset collectDistantTiles(const Zone & zone, int distance);
void createBorder(RmgMap & gen, Zone & zone);
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrain terrainType);
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrainId terrainType);
void initTerrainType(Zone & zone, CMapGenerator & gen);
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrain terrain);
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrainId terrain);

View File

@ -24,7 +24,7 @@
#include "Functions.h"
#include "../mapping/CMapEditManager.h"
void ObstacleProxy::collectPossibleObstacles(TTerrain terrain)
void ObstacleProxy::collectPossibleObstacles(TTerrainId terrain)
{
//get all possible obstacles for this terrain
for(auto primaryID : VLC->objtypeh->knownObjects())

View File

@ -23,7 +23,7 @@ public:
rmg::Area blockedArea;
void collectPossibleObstacles(TTerrain terrain);
void collectPossibleObstacles(TTerrainId terrain);
void placeObstacles(CMap * map, CRandomGenerator & rand);

View File

@ -229,7 +229,7 @@ void RmgMap::setOccupied(const int3 &tile, ETileType::ETileType state)
tiles[tile.x][tile.y][tile.z].setOccupied(state);
}
void RmgMap::setRoad(const int3& tile, TRoad roadType)
void RmgMap::setRoad(const int3& tile, TRoadId roadType)
{
assertOnMap(tile);

View File

@ -44,7 +44,7 @@ public:
bool isOnMap(const int3 & tile) const;
void setOccupied(const int3 &tile, ETileType::ETileType state);
void setRoad(const int3 &tile, TRoad roadType);
void setRoad(const int3 &tile, TRoadId roadType);
TileInfo getTile(const int3 & tile) const;

View File

@ -103,7 +103,7 @@ void Object::Instance::setPositionRaw(const int3 & position)
dObject.pos = dPosition + dParent.getPosition();
}
void Object::Instance::setTemplate(const TTerrain & terrain)
void Object::Instance::setTemplate(const TTerrainId & terrain)
{
if(dObject.appearance->id == Obj::NO_OBJ)
{
@ -257,7 +257,7 @@ void Object::setPosition(const int3 & position)
i.setPositionRaw(i.getPosition());
}
void Object::setTemplate(const TTerrain & terrain)
void Object::setTemplate(const TTerrainId & terrain)
{
for(auto& i : dInstances)
i.setTemplate(terrain);

View File

@ -33,7 +33,7 @@ public:
int3 getVisitablePosition() const;
bool isVisitableFrom(const int3 & tile) const;
const Area & getAccessibleArea() const;
void setTemplate(const TTerrain & terrain); //cache invalidation
void setTemplate(const TTerrainId & terrain); //cache invalidation
int3 getPosition(bool isAbsolute = false) const;
void setPosition(const int3 & position); //cache invalidation
@ -69,7 +69,7 @@ public:
const int3 & getPosition() const;
void setPosition(const int3 & position);
void setTemplate(const TTerrain & terrain);
void setTemplate(const TTerrainId & terrain);
const Area & getArea() const; //lazy cache invalidation

View File

@ -70,7 +70,7 @@ void RoadPlacer::drawRoads(bool secondary)
zone.freePaths().unite(roads);
map.getEditManager()->getTerrainSelection().setSelection(roads.getTilesVector());
std::string roadCode = (secondary ? generator.getConfig().secondaryRoadType : generator.getConfig().defaultRoadType);
TRoad roadType = VLC->terrainTypeHandler->getRoadByCode(roadCode)->id;
TRoadId roadType = VLC->terrainTypeHandler->getRoadByCode(roadCode)->id;
map.getEditManager()->drawRoad(roadType, &generator.rand);
}

View File

@ -26,5 +26,5 @@ public:
protected:
rmg::Area rockArea, accessibleArea;
TTerrain rockTerrain;
TTerrainId rockTerrain;
};

View File

@ -61,17 +61,17 @@ ETileType::ETileType TileInfo::getTileType() const
return occupied;
}
TTerrain TileInfo::getTerrainType() const
TTerrainId TileInfo::getTerrainType() const
{
return terrain;
}
void TileInfo::setTerrainType(TTerrain type)
void TileInfo::setTerrainType(TTerrainId type)
{
terrain = type;
}
void TileInfo::setRoadType(TRoad type)
void TileInfo::setRoadType(TRoadId type)
{
roadType = type;
// setOccupied(ETileType::FREE);

View File

@ -28,14 +28,14 @@ public:
bool isUsed() const;
bool isRoad() const;
void setOccupied(ETileType::ETileType value);
TTerrain getTerrainType() const;
TTerrainId getTerrainType() const;
ETileType::ETileType getTileType() const;
void setTerrainType(TTerrain value);
void setTerrainType(TTerrainId value);
void setRoadType(TRoad type);
void setRoadType(TRoadId type);
private:
float nearestObjectDistance;
ETileType::ETileType occupied;
TTerrain terrain;
TRoad roadType;
TTerrainId terrain;
TRoadId roadType;
};

View File

@ -811,7 +811,7 @@ ObjectInfo::ObjectInfo()
}
void ObjectInfo::setTemplate(si32 type, si32 subtype, TTerrain terrainType)
void ObjectInfo::setTemplate(si32 type, si32 subtype, TTerrainId terrainType)
{
auto templHandler = VLC->objtypeh->getHandlerFor(type, subtype);
if(!templHandler)

View File

@ -26,7 +26,7 @@ struct ObjectInfo
//ui32 maxPerMap; //unused
std::function<CGObjectInstance *()> generateObject;
void setTemplate(si32 type, si32 subtype, TTerrain terrain);
void setTemplate(si32 type, si32 subtype, TTerrainId terrain);
ObjectInfo();

View File

@ -132,12 +132,12 @@ void Zone::setTownType(si32 town)
townType = town;
}
TTerrain Zone::getTerrainType() const
TTerrainId Zone::getTerrainType() const
{
return terrainType;
}
void Zone::setTerrainType(TTerrain terrain)
void Zone::setTerrainType(TTerrainId terrain)
{
terrainType = terrain;
}

View File

@ -98,8 +98,8 @@ public:
si32 getTownType() const;
void setTownType(si32 town);
TTerrain getTerrainType() const;
void setTerrainType(TTerrain terrain);
TTerrainId getTerrainType() const;
void setTerrainType(TTerrainId terrain);
void connectPath(const rmg::Path & path);
rmg::Path searchPath(const rmg::Area & src, bool onlyStraight, std::function<bool(const int3 &)> areafilter = AREA_NO_FILTER) const;
@ -138,6 +138,6 @@ protected:
//template info
si32 townType;
TTerrain terrainType;
TTerrainId terrainType;
};

View File

@ -2238,8 +2238,8 @@ void CGameHandler::setupBattle(int3 tile, const CArmedInstance *armies[2], const
{
battleResult.set(nullptr);
const auto t = getTile(tile);
TTerrain terrain = t->terType->id;
const auto & t = *getTile(tile);
TTerrainId terrain = t.terType->id;
if (gs->map->isCoastalTile(tile)) //coastal tile is always ground
terrain = Terrain::SAND;

View File

@ -191,9 +191,9 @@ public:
int3 tile(4,4,0);
const auto t = gameCallback->getTile(tile);
const auto & t = *gameCallback->getTile(tile);
TTerrain terrain = t->terType->id;
TTerrainId terrain = t.terType->id;
BattleField terType = BattleField::fromString("grass_hills");
//send info about battles

View File

@ -17,7 +17,7 @@ class IBattleInfoCallbackMock : public IBattleInfoCallback
{
public:
MOCK_CONST_METHOD0(getContextPool, scripting::Pool *());
MOCK_CONST_METHOD0(battleTerrainType, TTerrain());
MOCK_CONST_METHOD0(battleTerrainType, TTerrainId());
MOCK_CONST_METHOD0(battleGetBattlefieldType, BattleField());
MOCK_CONST_METHOD0(battleIsFinished, boost::optional<int>());

View File

@ -19,7 +19,7 @@ public:
MOCK_CONST_METHOD1(getStacksIf, TStacks(TStackFilter));
MOCK_CONST_METHOD1(getUnitsIf, battle::Units(battle::UnitFilter));
MOCK_CONST_METHOD0(getBattlefieldType, BattleField());
MOCK_CONST_METHOD0(getTerrainType, TTerrain());
MOCK_CONST_METHOD0(getTerrainType, TTerrainId());
MOCK_CONST_METHOD0(getAllObstacles, IBattleInfo::ObstacleCList());
MOCK_CONST_METHOD0(getDefendedTown, const CGTownInstance *());
MOCK_CONST_METHOD1(getWallState, si8(int));