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

First version that compiles

This commit is contained in:
Tomasz Zieliński 2022-09-21 11:34:23 +02:00
parent b20f649521
commit 494b0f0226
93 changed files with 431 additions and 359 deletions

View File

@ -89,10 +89,10 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
for(pos.y = 0; pos.y < sizes.y; ++pos.y)
{
const TerrainTile* tile = &gs->map->getTile(pos);
if (!tile->terType.isPassable())
if (!tile->terType->isPassable())
continue;
if (tile->terType.isWater())
if (tile->terType->isWater())
{
resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, tile, fow, player, gs));
if (useFlying)

View File

@ -44,10 +44,10 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
for(pos.y=0; pos.y < sizes.y; ++pos.y)
{
const TerrainTile * tile = &gs->map->getTile(pos);
if(!tile->terType.isPassable())
if(!tile->terType->isPassable())
continue;
if(tile->terType.isWater())
if(tile->terType->isWater())
{
resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, tile, fow, player, gs));
if(useFlying)

View File

@ -37,6 +37,7 @@ void CGameInfo::setFromLib()
spellh = VLC->spellh;
skillh = VLC->skillh;
objtypeh = VLC->objtypeh;
terrainTypeHandler = VLC->terrainTypeHandler;
battleFieldHandler = VLC->battlefieldsHandler;
obstacleHandler = VLC->obstacleHandler;
}

View File

@ -33,6 +33,7 @@ class IMainVideoPlayer;
class CServerHandler;
class BattleFieldHandler;
class ObstacleHandler;
class TerrainTypeHandler;
class CMap;
@ -78,6 +79,7 @@ public:
ConstTransitivePtr<CSpellHandler> spellh;
ConstTransitivePtr<CSkillHandler> skillh;
ConstTransitivePtr<CObjectHandler> objh;
ConstTransitivePtr<TerrainTypeHandler> terrainTypeHandler;
ConstTransitivePtr<CObjectClassesHandler> objtypeh;
ConstTransitivePtr<ObstacleHandler> obstacleHandler;
CGeneralTextHandler * generaltexth;

View File

@ -102,24 +102,28 @@ CSoundHandler::CSoundHandler():
//predefine terrain set
//TODO: need refactoring - support custom sounds for new terrains and load from json
int h3mTerrId = 0;
for(auto snd :
horseSounds =
{
soundBase::horseDirt, soundBase::horseSand, soundBase::horseGrass,
soundBase::horseSnow, soundBase::horseSwamp, soundBase::horseRough,
soundBase::horseSubterranean, soundBase::horseLava,
soundBase::horseWater, soundBase::horseRock
})
{
horseSounds[Terrain::createTerrainTypeH3M(h3mTerrId++)] = snd;
}
for(auto & terrain : VLC->terrainTypeHandler::terrains())
{Terrain::DIRT, soundBase::horseDirt},
{Terrain::SAND, soundBase::horseSand},
{Terrain::GRASS, soundBase::horseGrass},
{Terrain::SNOW, soundBase::horseSnow},
{Terrain::SWAMP, soundBase::horseSwamp},
{Terrain::ROUGH, soundBase::horseRough},
{Terrain::SUBTERRANEAN, soundBase::horseSubterranean},
{Terrain::LAVA, soundBase::horseLava},
{Terrain::WATER, soundBase::horseWater},
{Terrain::ROCK, soundBase::horseRock}
};
auto terrains = CGI->terrainTypeHandler->terrains();
for(const auto * terrain : terrains)
{
//since all sounds are hardcoded, let's keep it
if(vstd::contains(horseSounds, terrain))
if(vstd::contains(horseSounds, terrain->id))
continue;
horseSounds[terrain] = horseSounds.at(Terrain::createTerrainTypeH3M(Terrain::Manager::getInfo(terrain).horseSoundId));
//Use already existing horse sound
horseSounds[terrain->id] = horseSounds.at(terrains[terrain->id]->horseSoundId);
}
};
@ -364,10 +368,9 @@ CMusicHandler::CMusicHandler():
addEntryToSet("enemy-turn", file.getName(), file.getName());
}
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : CGI->terrainTypeHandler->terrains())
{
auto & entry = Terrain::Manager::getInfo(terrain);
addEntryToSet("terrain", terrain, "Music/" + entry.musicFilename);
addEntryToSet("terrain", terrain->name, "Music/" + terrain->musicFilename);
}
}

View File

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

View File

@ -274,7 +274,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, true);
CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->name, true);
if(details.result == TryMoveHero::TELEPORTATION)
{
@ -2742,8 +2742,8 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
{
path.convert(0);
Terrain currentTerrain = Terrain("BORDER"); // not init yet
Terrain newTerrain;
TTerrain currentTerrain = Terrain::BORDER; // not init yet
TTerrain newTerrain;
int sh = -1;
auto canStop = [&](CGPathNode * node) -> bool
@ -2798,7 +2798,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
#endif
{
newTerrain = cb->getTile(CGHeroInstance::convertPosition(currentCoord, false))->terType;
newTerrain = cb->getTile(CGHeroInstance::convertPosition(currentCoord, false))->terType->id;
if(newTerrain != currentTerrain)
{
CCS->soundh->stopSound(sh);

View File

@ -456,8 +456,8 @@ CBattleInterface::~CBattleInterface()
if (adventureInt && adventureInt->selection)
{
auto & terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->terType;
CCS->musich->playMusicFromSet("terrain", terrain, true);
const auto * terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->terType;
CCS->musich->playMusicFromSet("terrain", terrain->name, true);
}
animsAreDisplayed.setn(false);
}

View File

@ -188,10 +188,11 @@ void CMapHandler::initTerrainGraphics()
}
};
//TODO: use if as a key
std::map<std::string, std::string> terrainFiles;
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
terrainFiles[terrain] = Terrain::Manager::getInfo(terrain).tilesFilename;
terrainFiles[terrain->name] = terrain->tilesFilename;
}
loadFlipped(terrainAnimations, terrainImages, terrainFiles);
@ -609,10 +610,13 @@ void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const T
ui8 rotation = tinfo.extTileFlags % 4;
if(parent->terrainImages[tinfo.terType].size()<=tinfo.terView)
//TODO: use ui8 instead of string key
auto terrainName = tinfo.terType->name;
if(parent->terrainImages[terrainName].size()<=tinfo.terView)
return;
drawElement(EMapCacheType::TERRAIN, parent->terrainImages[tinfo.terType][tinfo.terView][rotation], nullptr, targetSurf, &destRect);
drawElement(EMapCacheType::TERRAIN, parent->terrainImages[terrainName][tinfo.terView][rotation], nullptr, targetSurf, &destRect);
}
void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo)
@ -1390,7 +1394,7 @@ void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRM
}
}
if(!isTile2Terrain || out.empty())
out = CGI->generaltexth->terrainNames[t.terType];
out = CGI->generaltexth->terrainNames[t.terType->id];
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
{

View File

@ -391,10 +391,11 @@ const SDL_Color & CMinimapInstance::getTileColor(const int3 & pos)
}
// else - use terrain color (blocked version or normal)
auto colorPair = parent->colors.find(tile->terType->id)->second;
if (tile->blocked && (!tile->visitable))
return parent->colors.find(tile->terType)->second.second;
return colorPair.second;
else
return parent->colors.find(tile->terType)->second.first;
return colorPair.first;
}
void CMinimapInstance::tileToPixels (const int3 &tile, int &x, int &y, int toX, int toY)
{
@ -495,30 +496,29 @@ void CMinimapInstance::showAll(SDL_Surface * to)
}
}
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
{
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > ret;
std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > ret;
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
auto & m = Terrain::Manager::getInfo(terrain);
SDL_Color normal =
{
ui8(m.minimapUnblocked[0]),
ui8(m.minimapUnblocked[1]),
ui8(m.minimapUnblocked[2]),
ui8(terrain->minimapUnblocked[0]),
ui8(terrain->minimapUnblocked[1]),
ui8(terrain->minimapUnblocked[2]),
ui8(255)
};
SDL_Color blocked =
{
ui8(m.minimapBlocked[0]),
ui8(m.minimapBlocked[1]),
ui8(m.minimapBlocked[2]),
ui8(terrain->minimapBlocked[0]),
ui8(terrain->minimapBlocked[1]),
ui8(terrain->minimapBlocked[2]),
ui8(255)
};
ret[terrain] = std::make_pair(normal, blocked);
ret[terrain->id] = std::make_pair(normal, blocked);
}
return ret;
}

View File

@ -217,7 +217,7 @@ protected:
int level;
//to initialize colors
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > loadColors();
std::map<TTerrain, 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<Terrain, std::pair<SDL_Color, SDL_Color> > colors;
const std::map<TTerrain, std::pair<SDL_Color, SDL_Color> > colors;
CMinimap(const Rect & position);

View File

@ -1413,7 +1413,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, true);
CCS->musich->playMusicFromSet("terrain", tile->terType->name, true);
}
if(centerView)
centerOn(sel);

View File

@ -1,6 +1,7 @@
{
"dirt" :
{
"originalTerrainId": 0,
"moveCost" : 100,
"minimapUnblocked" : [ 82, 56, 8 ],
"minimapBlocked" : [ 57, 40, 8 ],
@ -14,6 +15,7 @@
},
"sand" :
{
"originalTerrainId": 1,
"moveCost" : 150,
"minimapUnblocked" : [ 222, 207, 140 ],
"minimapBlocked" : [ 165, 158, 107 ],
@ -28,6 +30,7 @@
},
"grass" :
{
"originalTerrainId": 2,
"moveCost" : 100,
"minimapUnblocked" : [ 0, 65, 0 ],
"minimapBlocked" : [ 0, 48, 0 ],
@ -40,6 +43,7 @@
},
"snow" :
{
"originalTerrainId": 3,
"moveCost" : 150,
"minimapUnblocked" : [ 181, 199, 198 ],
"minimapBlocked" : [ 140, 158, 156 ],
@ -52,6 +56,7 @@
},
"swamp" :
{
"originalTerrainId": 4,
"moveCost" : 175,
"minimapUnblocked" : [ 74, 134, 107 ],
"minimapBlocked" : [ 33, 89, 66 ],
@ -64,6 +69,7 @@
},
"rough" :
{
"originalTerrainId": 5,
"moveCost" : 125,
"minimapUnblocked" : [ 132, 113, 49 ],
"minimapBlocked" : [ 99, 81, 33 ],
@ -76,6 +82,7 @@
},
"subterra" :
{
"originalTerrainId": 6,
"moveCost" : 100,
"minimapUnblocked" : [ 132, 48, 0 ],
"minimapBlocked" : [ 90, 8, 0 ],
@ -90,6 +97,7 @@
},
"lava" :
{
"originalTerrainId": 7,
"moveCost" : 100,
"minimapUnblocked" : [ 74, 73, 74 ],
"minimapBlocked" : [ 41, 40, 41 ],
@ -103,6 +111,7 @@
},
"water" :
{
"originalTerrainId": 8,
"moveCost" : 100,
"minimapUnblocked" : [ 8, 81, 148 ],
"minimapBlocked" : [ 8, 81, 148 ],
@ -120,6 +129,7 @@
},
"rock" :
{
"originalTerrainId": 9,
"moveCost" : -1,
"minimapUnblocked" : [ 0, 0, 0 ],
"minimapBlocked" : [ 0, 0, 0 ],

View File

@ -283,22 +283,22 @@ std::string CCreature::nodeName() const
return "\"" + namePl + "\"";
}
bool CCreature::isItNativeTerrain(const Terrain & terrain) const
bool CCreature::isItNativeTerrain(TTerrain terrain) const
{
auto native = getNativeTerrain();
return native == terrain || native == Terrain::ANY;
return native == terrain || native == Terrain::ANY_TERRAIN;
}
Terrain CCreature::getNativeTerrain() const
TTerrain CCreature::getNativeTerrain() const
{
const std::string cachingStringBlocksRetaliation = "type_NO_TERRAIN_PENALTY";
static const auto selectorBlocksRetaliation = Selector::type()(Bonus::NO_TERRAIN_PENALTY);
const std::string cachingStringNoTerrainPenalty = "type_NO_TERRAIN_PENALTY";
static const auto selectorNoTerrainPenalty = Selector::type()(Bonus::NO_TERRAIN_PENALTY);
//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
//and in the CGHeroInstance::getNativeTerrain() to setup mevement bonuses or/and penalties.
return hasBonus(selectorBlocksRetaliation, selectorBlocksRetaliation)
? Terrain::ANY
: (Terrain)(*VLC->townh)[faction]->nativeTerrain;
return hasBonus(selectorNoTerrainPenalty, selectorNoTerrainPenalty)
? Terrain::ANY_TERRAIN
: (*VLC->townh)[faction]->nativeTerrain;
}
void CCreature::updateFrom(const JsonNode & data)

View File

@ -119,14 +119,14 @@ public:
ArtifactID warMachine;
bool isItNativeTerrain(const Terrain & terrain) const;
bool isItNativeTerrain(TTerrain 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.
*/
Terrain getNativeTerrain() const;
TTerrain getNativeTerrain() const;
int32_t getIndex() const override;
int32_t getIconIndex() const override;
const std::string & getName() const override;

View File

@ -575,7 +575,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
{
const TerrainTile *tile = getTile(t->bestLocation(), false);
if(!tile || tile->terType.isLand())
if(!tile || tile->terType->isLand())
return EBuildingState::NO_WATER; //lack of water
}

View File

@ -964,8 +964,8 @@ void CGameState::initGrailPosition()
const TerrainTile &t = map->getTile(int3(x, y, z));
if(!t.blocked
&& !t.visitable
&& t.terType.isLand()
&& t.terType.isPassable()
&& t.terType->isLand()
&& t.terType->isPassable()
&& (int)map->grailPos.dist2dSQ(int3(x, y, z)) <= (map->grailRadius * map->grailRadius))
allowedPos.push_back(int3(x,y,z));
}
@ -1919,7 +1919,7 @@ BattleField CGameState::battleGetBattlefieldType(int3 tile, CRandomGenerator & r
return BattleField::fromString("sand_shore");
return BattleField::fromString(
*RandomGeneratorUtil::nextItem(Terrain::Manager::getInfo(t.terType).battleFields, rand));
*RandomGeneratorUtil::nextItem(t.terType->battleFields, rand));
}
UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack)
@ -2101,7 +2101,7 @@ void CGameState::updateRumor()
rumorId = *RandomGeneratorUtil::nextItem(sRumorTypes, rand);
if(rumorId == RumorState::RUMOR_GRAIL)
{
rumorExtra = getTile(map->grailPos)->terType.id();
rumorExtra = getTile(map->grailPos)->terType->id;
break;
}

View File

@ -336,12 +336,12 @@ CGeneralTextHandler::CGeneralTextHandler()
for(int i = 0; i < h3mTerrainNames.size(); ++i)
{
terrainNames[Terrain::createTerrainTypeH3M(i)] = h3mTerrainNames[i];
terrainNames[i] = h3mTerrainNames[i];
}
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
if(!Terrain::Manager::getInfo(terrain).terrainText.empty())
terrainNames[terrain] = Terrain::Manager::getInfo(terrain).terrainText;
if(!terrain->terrainText.empty())
terrainNames[terrain->id] = terrain->terrainText;
}

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<std::string, std::string> terrainNames;
std::map<TTerrain, 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

@ -344,9 +344,9 @@ CHeroHandler::~CHeroHandler() = default;
CHeroHandler::CHeroHandler()
{
loadTerrains();
for(int i = 0; i < VLC->terrainTypeHandler::terrains().size(); ++i)
for(int i = 0; i < VLC->terrainTypeHandler->terrains().size(); ++i)
{
VLC->modh->identifiers.registerObject("core", "terrain", VLC->terrainTypeHandler::terrains()[i], 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(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
terrCosts[terrain] = Terrain::Manager::getInfo(terrain).moveCost;
terrCosts[terrain->id] = terrain->moveCost;
}
}

View File

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

View File

@ -46,7 +46,7 @@ void NodeStorage::initialize(const PathfinderOptions & options, const CGameState
for(pos.y=0; pos.y < sizes.y; ++pos.y)
{
const TerrainTile * tile = &gs->map->getTile(pos);
if(tile->terType.isWater())
if(tile->terType->isWater())
{
resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, tile, fow, player, gs));
if(useFlying)
@ -54,7 +54,7 @@ void NodeStorage::initialize(const PathfinderOptions & options, const CGameState
if(useWaterWalking)
resetTile(pos, ELayer::WATER, PathfinderUtil::evaluateAccessibility<ELayer::WATER>(pos, tile, fow, player, gs));
}
if(tile->terType.isLand())
if(tile->terType->isLand())
{
resetTile(pos, ELayer::LAND, PathfinderUtil::evaluateAccessibility<ELayer::LAND>(pos, tile, fow, player, gs));
if(useFlying)
@ -1008,10 +1008,10 @@ bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
TurnInfo::BonusCache::BonusCache(TConstBonusListPtr bl)
{
for(int i = 0; i < VLC->terrainTypeHandler::terrains().size(); ++i)
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
noTerrainPenalty.push_back(static_cast<bool>(
bl->getFirst(Selector::type()(Bonus::NO_TERRAIN_PENALTY).And(Selector::subtype()(i)))));
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)));
@ -1027,7 +1027,7 @@ TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn)
{
bonuses = hero->getAllBonuses(Selector::days(turn), Selector::all, nullptr, "");
bonusCache = make_unique<BonusCache>(bonuses);
nativeTerrain = hero->getNativeTerrain();
nativeTerrain = VLC->terrainTypeHandler->terrains()[hero->getNativeTerrain()];
}
bool TurnInfo::isLayerAvailable(const EPathfindingLayer layer) const
@ -1178,7 +1178,7 @@ void CPathfinderHelper::getNeighbours(
continue;
const TerrainTile & hlpt = map->getTile(hlp);
if(!hlpt.terType.isPassable())
if(!hlpt.terType->isPassable())
continue;
// //we cannot visit things from blocked tiles
@ -1188,18 +1188,18 @@ void CPathfinderHelper::getNeighbours(
// }
/// Following condition let us avoid diagonal movement over coast when sailing
if(srct.terType.isWater() && limitCoastSailing && hlpt.terType.isWater() && dir.x && dir.y) //diagonal move through water
if(srct.terType->isWater() && limitCoastSailing && hlpt.terType->isWater() && dir.x && dir.y) //diagonal move through water
{
int3 hlp1 = tile,
hlp2 = tile;
hlp1.x += dir.x;
hlp2.y += dir.y;
if(map->getTile(hlp1).terType.isLand() || map->getTile(hlp2).terType.isLand())
if(map->getTile(hlp1).terType->isLand() || map->getTile(hlp2).terType->isLand())
continue;
}
if(indeterminate(onLand) || onLand == hlpt.terType.isLand())
if(indeterminate(onLand) || onLand == hlpt.terType->isLand())
{
vec.push_back(hlp);
}
@ -1237,7 +1237,7 @@ int CPathfinderHelper::getMovementCost(
{
ret = static_cast<int>(ret * (100.0 + ti->valOfBonuses(Bonus::FLYING_MOVEMENT)) / 100.0);
}
else if(dt->terType.isWater())
else if(dt->terType->isWater())
{
if(hero->boat && ct->hasFavorableWinds() && dt->hasFavorableWinds())
ret = static_cast<int>(ret * 0.666);
@ -1265,7 +1265,7 @@ int CPathfinderHelper::getMovementCost(
{
std::vector<int3> vec;
vec.reserve(8); //optimization
getNeighbours(*dt, dst, vec, ct->terType.isLand(), true);
getNeighbours(*dt, dst, vec, ct->terType->isLand(), true);
for(auto & elem : vec)
{
int fcost = getMovementCost(dst, elem, nullptr, nullptr, left, false);

View File

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

View File

@ -328,11 +328,11 @@ bool CStack::canBeHealed() const
bool CStack::isOnNativeTerrain() const
{
//this code is called from CreatureTerrainLimiter::limit on battle start
auto res = nativeTerrain == Terrain::ANY || nativeTerrain == battle->getTerrainType();
auto res = nativeTerrain == Terrain::ANY_TERRAIN || nativeTerrain == battle->getTerrainType();
return res;
}
bool CStack::isOnTerrain(const Terrain & terrain) const
bool CStack::isOnTerrain(TTerrain terrain) const
{
return battle->getTerrainType() == terrain;
}

View File

@ -29,7 +29,7 @@ public:
ui32 ID; //unique ID of stack
const CCreature * type;
Terrain nativeTerrain; //tmp variable to save native terrain value on battle init
TTerrain 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(const Terrain & terrain) const;
bool isOnTerrain(TTerrain 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 Terrain CTownHandler::defaultGoodTerrain{"grass"};
const Terrain CTownHandler::defaultEvilTerrain{"lava"};
const Terrain CTownHandler::defaultNeutralTerrain{"rough"};
const TTerrain CTownHandler::defaultGoodTerrain(Terrain::GRASS);
const TTerrain CTownHandler::defaultEvilTerrain(Terrain::LAVA);
const TTerrain 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);
}
Terrain CTownHandler::getDefaultTerrainForAlignment(EAlignment::EAlignment alignment) const
TTerrain CTownHandler::getDefaultTerrainForAlignment(EAlignment::EAlignment alignment) const
{
Terrain terrain = defaultGoodTerrain;
TTerrain terrain = defaultGoodTerrain;
switch(alignment)
{
@ -983,7 +983,7 @@ CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode
auto nativeTerrain = source["nativeTerrain"];
faction->nativeTerrain = nativeTerrain.isNull()
? getDefaultTerrainForAlignment(faction->alignment)
: Terrain(nativeTerrain.String());
: VLC->terrainTypeHandler->getInfoByName(nativeTerrain.String())->id;
if (!source["town"].isNull())
{

View File

@ -185,7 +185,7 @@ public:
TFaction index;
Terrain nativeTerrain;
TTerrain 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 Terrain defaultGoodTerrain;
const static Terrain defaultEvilTerrain;
const static Terrain defaultNeutralTerrain;
const static TTerrain defaultGoodTerrain;
const static TTerrain defaultEvilTerrain;
const static TTerrain defaultNeutralTerrain;
static TPropagatorPtr & emptyPropagator();
@ -391,7 +391,7 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
void loadPuzzle(CFaction & faction, const JsonNode & source);
Terrain getDefaultTerrainForAlignment(EAlignment::EAlignment aligment) const;
TTerrain getDefaultTerrainForAlignment(EAlignment::EAlignment aligment) const;
void loadRandomFaction();

View File

@ -834,8 +834,9 @@ ID_LIKE_OPERATORS(Obj, Obj::EObj)
namespace Terrain
{
enum ETerrain : TTerrain
enum ETerrain : si8
{
NATIVE_TERRAIN = -4,
ANY_TERRAIN = -3,
WRONG = -2,
BORDER = -1,
@ -1205,7 +1206,7 @@ typedef si64 TExpType;
typedef std::pair<si64, si64> TDmgRange;
typedef si32 TBonusSubtype;
typedef si32 TQuantity;
typedef ui8 TTerrain;
typedef si8 TTerrain;
typedef int TRmgTemplateZoneId;

View File

@ -2107,9 +2107,13 @@ bool CPropagatorNodeType::shouldBeAttached(CBonusSystemNode *dest)
}
CreatureTerrainLimiter::CreatureTerrainLimiter()
: terrainType()
: terrainType(Terrain::NATIVE_TERRAIN)
{
}
CreatureTerrainLimiter::CreatureTerrainLimiter(TTerrain terrain):
terrainType(terrain)
{
}
int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
@ -2117,9 +2121,14 @@ int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
const CStack *stack = retrieveStackBattle(&context.node);
if(stack)
{
if(terrainType.isNative())//terrainType not specified = native
if (terrainType == Terrain::NATIVE_TERRAIN)//terrainType not specified = native
{
return !stack->isOnNativeTerrain();
return !stack->isOnTerrain(terrainType);
}
else
{
return !stack->isOnTerrain(terrainType);
}
}
return true;
//TODO neutral creatues
@ -2128,7 +2137,8 @@ int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
std::string CreatureTerrainLimiter::toString() const
{
boost::format fmt("CreatureTerrainLimiter(terrainType=%s)");
fmt % (terrainType.isNative() ? "native" : static_cast<std::string>(terrainType));
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType]->name;
fmt % (terrainType == Terrain::NATIVE_TERRAIN ? "native" : terrainName);
return fmt.str();
}
@ -2137,8 +2147,8 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
root["type"].String() = "CREATURE_TERRAIN_LIMITER";
if(!terrainType.isNative())
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainType));
auto terrainName = VLC->terrainTypeHandler->terrains()[terrainType]->name;
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName));
return root;
}

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:
Terrain terrainType;
TTerrain terrainType;
CreatureTerrainLimiter();
CreatureTerrainLimiter(const Terrain& terrain);
CreatureTerrainLimiter(TTerrain terrain);
int limit(const BonusLimitationContext &context) const override;
virtual std::string toString() const override;

View File

@ -50,7 +50,7 @@ void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
for (int yd = 0; yd < gs->map->height; yd++)
{
tinfo = getTile(int3 (xd,yd,zd));
if (tinfo->terType.isLand() && tinfo->terType.isPassable() && !tinfo->blocked) //land and free
if (tinfo->terType->isLand() && tinfo->terType->isPassable() && !tinfo->blocked) //land and free
tiles.push_back (int3 (xd,yd,zd));
}
}
@ -117,8 +117,8 @@ void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3, ShashInt3> &
{
for (int yd = 0; yd < gs->map->height; yd++)
{
if ((getTile (int3 (xd,yd,zd))->terType.isWater() && water)
|| (getTile (int3 (xd,yd,zd))->terType.isLand() && land))
if ((getTile (int3 (xd,yd,zd))->terType->isWater() && water)
|| (getTile (int3 (xd,yd,zd))->terType->isLand() && land))
tiles.insert(int3(xd,yd,zd));
}
}

View File

@ -701,13 +701,13 @@ DLL_LINKAGE void GiveHero::applyGs(CGameState *gs)
DLL_LINKAGE void NewObject::applyGs(CGameState *gs)
{
Terrain terrainType;
TTerrain terrainType = Terrain::BORDER;
if(ID == Obj::BOAT && !gs->isInTheMap(pos)) //special handling for bug #3060 - pos outside map but visitablePos is not
{
CGObjectInstance testObject = CGObjectInstance();
testObject.pos = pos;
testObject.appearance = VLC->objtypeh->getHandlerFor(ID, subID)->getTemplates(Terrain("water")).front();
testObject.appearance = VLC->objtypeh->getHandlerFor(ID, subID)->getTemplates(Terrain::WATER).front();
const int3 previousXAxisTile = int3(pos.x - 1, pos.y, pos.z);
assert(gs->isInTheMap(previousXAxisTile) && (testObject.visitablePos() == previousXAxisTile));
@ -716,7 +716,7 @@ DLL_LINKAGE void NewObject::applyGs(CGameState *gs)
else
{
const TerrainTile & t = gs->map->getTile(pos);
terrainType = t.terType;
terrainType = t.terType->id;
}
CGObjectInstance *o = nullptr;
@ -724,7 +724,7 @@ DLL_LINKAGE void NewObject::applyGs(CGameState *gs)
{
case Obj::BOAT:
o = new CGBoat();
terrainType = Terrain("water"); //TODO: either boat should only spawn on water, or all water objects should be handled this way
terrainType = Terrain::WATER; //TODO: either boat should only spawn on water, or all water objects should be handled this way
break;
case Obj::MONSTER: //probably more options will be needed
o = new CGCreature();

View File

@ -66,7 +66,7 @@ std::vector<BattleHex> ObstacleInfo::getBlocked(BattleHex hex) const
return ret;
}
bool ObstacleInfo::isAppropriate(const Terrain & terrainType, const BattleField & battlefield) const
bool ObstacleInfo::isAppropriate(const TTerrain terrainType, const BattleField & battlefield) const
{
auto bgInfo = battlefield.getInfo();
@ -84,7 +84,7 @@ ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const Js
info->width = json["width"].Integer();
info->height = json["height"].Integer();
for(auto & t : json["allowedTerrain"].Vector())
info->allowedTerrains.emplace_back(t.String());
info->allowedTerrains.emplace_back(VLC->terrainTypeHandler->getInfoByName(t.String())->id);
for(auto & t : json["specialBattlefields"].Vector())
info->allowedSpecialBfields.emplace_back(t.String());
info->blockedTiles = json["blockedTiles"].convertTo<std::vector<si16>>();

View File

@ -31,7 +31,7 @@ public:
si32 iconIndex;
std::string identifier;
std::string appearAnimation, animation, dissapearAnimation;
std::vector<Terrain> allowedTerrains;
std::vector<TTerrain> 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 Terrain & terrainType, const BattleField & specialBattlefield) const;
bool isAppropriate(const TTerrain terrainType, const BattleField & specialBattlefield) const;
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -59,13 +59,13 @@ namespace PathfinderUtil
break;
case ELayer::WATER:
if(tinfo->blocked || tinfo->terType.isLand())
if(tinfo->blocked || tinfo->terType->isLand())
return CGPathNode::BLOCKED;
break;
case ELayer::AIR:
if(tinfo->blocked || tinfo->terType.isLand())
if(tinfo->blocked || tinfo->terType->isLand())
return CGPathNode::FLYABLE;
break;

View File

@ -34,7 +34,7 @@ TerrainTypeHandler::TerrainTypeHandler()
JsonNode terrs(mod, ResourceID("config/terrains.json"));
for(auto & terr : terrs.Struct())
{
auto * info = new TerrainType(terr.first);
auto * info = new TerrainType(terr.first); //set name
info->moveCost = terr.second["moveCost"].Integer();
const JsonVector &unblockedVec = terr.second["minimapUnblocked"].Vector();
@ -70,11 +70,15 @@ TerrainTypeHandler::TerrainTypeHandler()
if(terr.second["rockTerrain"].isNull())
{
info->rockTerrain = "rock";
info->rockTerrain = Terrain::ROCK;
}
else
{
info->rockTerrain = terr.second["rockTerrain"].String();
auto rockTerrainType = terr.second["rockTerrain"].String();
resolveLater.push_back([this, rockTerrainType, info]()
{
info->rockTerrain = getInfoByName(rockTerrainType)->id;
});
}
if(terr.second["river"].isNull())
@ -122,7 +126,11 @@ TerrainTypeHandler::TerrainTypeHandler()
{
for(auto & t : terr.second["prohibitTransitions"].Vector())
{
info->prohibitTransitions.emplace_back(t.String());
std::string prohibitedTerrainName = t.String();
resolveLater.push_back([this, prohibitedTerrainName, info]()
{
info->prohibitTransitions.emplace_back(getInfoByName(prohibitedTerrainName)->id);
});
}
}
@ -138,13 +146,7 @@ TerrainTypeHandler::TerrainTypeHandler()
info->terrainViewPatterns = terr.second["terrainViewPatterns"].String();
}
//TODO: handle 10 origina terrains
terrainInfoByName[terr.first] = info;
terrainInfoByCode[info->typeCode] = info;
terrainInfoById[info->id] = info;
TTerrain id;
TTerrain id = Terrain::WRONG;
if(!terr.second["originalTerrainId"].isNull())
{
//place in reserved slot
@ -173,24 +175,34 @@ TerrainTypeHandler::TerrainTypeHandler()
}
}
const std::vector<TerrainType *> & TerrainTypeHandler::terrains()
void TerrainTypeHandler::recreateTerrainMaps()
{
for (const TerrainType * terrainInfo : objects)
{
terrainInfoByName[terrainInfo->name] = terrainInfo;
terrainInfoByCode[terrainInfo->typeCode] = terrainInfo;
terrainInfoById[terrainInfo->id] = terrainInfo;
}
}
const std::vector<TerrainType *> & TerrainTypeHandler::terrains() const
{
return objects;
}
const TerrainType* TerrainTypeHandler::getInfoByName(const std::string& terrainName) const
{
return terrainInfoByName.at(terrainName);
}
const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainName) const
const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainCode) const
{
return terrainInfoByCode.at(terrainCode);
}
const TerrainType* TerrainTypeHandler::getInfoById(TTerrain id) const
{
return terrainInfoById.at(id);
}
std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType)
@ -202,10 +214,18 @@ TerrainType::operator std::string() const
{
return name;
}
TerrainType::TerrainType(const std::string & _name) : name(_name)
{}
TerrainType::TerrainType(const std::string& _name):
name(name),
id(Terrain::WRONG),
rockTerrain(Terrain::ROCK),
moveCost(100),
horseSoundId(0),
passabilityType(PassabilityType::LAND),
transitionRequired(false)
{
}
TerrainType& TerrainType::operator=(const TerrainType & other)
{
//TODO

View File

@ -37,17 +37,17 @@ public:
std::string terrainText;
std::string typeCode;
std::string terrainViewPatterns;
std::string rockTerrain;
std::string river;
TTerrain id;
TTerrain rockTerrain;
int moveCost;
int horseSoundId;
PassabilityType passabilityType;
bool transitionRequired;
TerrainType(const std::string & _type = "");
TerrainType(const std::string & name = "");
TerrainType& operator=(const TerrainType & _type);
bool operator==(const TerrainType & other);
@ -87,19 +87,29 @@ public:
DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType);
class DLL_LINKAGE TerrainTypeHandler //TODO: handlerBase
class DLL_LINKAGE TerrainTypeHandler //TODO: public IHandlerBase ?
{
public:
TerrainTypeHandler();
const std::vector<TerrainType *> & terrains();
const std::vector<TerrainType *> & terrains() const;
const TerrainType * getInfoByName(const std::string & terrainName) const;
const TerrainType * getInfoByCode(const std::string & terrainName) const;
const TerrainType * getInfoByCode(const std::string & terrainCode) const;
const TerrainType * getInfoById(TTerrain id) const;
//TODO: road, river types?
template <typename Handler> void serialize(Handler &h, const int version)
{
h & objects;
if (!h.saving)
{
recreateTerrainMaps();
}
}
private:
std::vector<TerrainType *> objects;
@ -108,18 +118,6 @@ private:
std::unordered_map<std::string, const TerrainType*> terrainInfoByCode;
std::unordered_map<TTerrain, const TerrainType*> terrainInfoById;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name;
void recreateTerrainMaps();
if (!saving)
{
//TODO: recreate at load
}
/*
h & terrainInfoByName;
h & terrainInfoByCode;
h & terrainInfoById;
*/
}
};

View File

@ -195,6 +195,8 @@ void LibClasses::init(bool onlyEssential)
createHandler(generaltexth, "General text", pomtime);
createHandler(terrainTypeHandler, "Terrain", pomtime);
createHandler(heroh, "Hero", pomtime);
createHandler(arth, "Artifact", pomtime);

View File

@ -27,6 +27,7 @@ class CContentHandler;
class BattleFieldHandler;
class IBonusTypeHandler;
class CBonusTypeHandler;
class TerrainTypeHandler;
class ObstacleHandler;
class CTerrainViewPatternConfig;
class CRmgTemplateStorage;
@ -78,6 +79,7 @@ public:
CTownHandler * townh;
CGeneralTextHandler * generaltexth;
CModHandler * modh;
TerrainTypeHandler * terrainTypeHandler;
CTerrainViewPatternConfig * terviewh;
CRmgTemplateStorage * tplh;
BattleFieldHandler * battlefieldsHandler;
@ -112,6 +114,7 @@ public:
h & skillh;
h & battlefieldsHandler;
h & obstacleHandler;
h & terrainTypeHandler;
if(!h.saving)
{

View File

@ -189,7 +189,7 @@ struct RangeGenerator
std::function<int()> myRand;
};
BattleInfo * BattleInfo::setupBattle(const int3 & tile, const Terrain & terrain, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town)
BattleInfo * BattleInfo::setupBattle(const int3 & tile, TTerrain 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;
}
Terrain BattleInfo::getTerrainType() const
TTerrain BattleInfo::getTerrainType() const
{
return terrainType;
}

View File

@ -18,7 +18,6 @@
class CStack;
class CStackInstance;
class CStackBasicDescriptor;
class Terrain;
class BattleField;
class DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallback, public IBattleState
@ -38,7 +37,7 @@ public:
SiegeInfo si;
BattleField battlefieldType; //like !!BA:B
Terrain terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
TTerrain 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)
@ -74,7 +73,7 @@ public:
battle::Units getUnitsIf(battle::UnitFilter predicate) const override;
BattleField getBattlefieldType() const override;
Terrain getTerrainType() const override;
TTerrain getTerrainType() const override;
ObstacleCList getAllObstacles() const override;
@ -139,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, const Terrain & terrain, const BattleField & battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town);
static BattleInfo * setupBattle(const int3 & tile, TTerrain, 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();
}
Terrain BattleProxy::getTerrainType() const
TTerrain 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;
Terrain getTerrainType() const override;
TTerrain getTerrainType() const override;
ObstacleCList getAllObstacles() const override;

View File

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

View File

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

View File

@ -10,11 +10,11 @@
#pragma once
#include "GameConstants.h"
#include "BattleHex.h"
struct CObstacleInstance;
class BattleField;
class Terrain;
namespace battle
{
@ -34,7 +34,7 @@ class DLL_LINKAGE IBattleInfoCallback
public:
virtual scripting::Pool * getContextPool() const = 0;
virtual Terrain battleTerrainType() const = 0;
virtual TTerrain 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 Terrain getTerrainType() const = 0;
virtual TTerrain getTerrainType() const = 0;
virtual ObstacleCList getAllObstacles() const = 0;

View File

@ -98,13 +98,13 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile & dest, const TerrainTile & f
break;
}
}
else if(ti->nativeTerrain != from.terType //the terrain is not native
&& ti->nativeTerrain != Terrain::ANY //no special creature bonus
&& !ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType.id()) //no special movement bonus
else if(ti->nativeTerrain->id != from.terType->id //the terrain is not native
&& ti->nativeTerrain != nullptr //no special creature bonus
&& !ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType->id) //no special movement bonus
)
{
ret = VLC->heroh->terrCosts[from.terType];
ret = VLC->heroh->terrCosts[from.terType->id];
ret -= ti->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING);
if(ret < GameConstants::BASE_MOVEMENT_COST)
ret = GameConstants::BASE_MOVEMENT_COST;
@ -112,7 +112,7 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile & dest, const TerrainTile & f
return (ui32)ret;
}
Terrain CGHeroInstance::getNativeTerrain() const
TTerrain 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.
@ -120,18 +120,18 @@ Terrain 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?
Terrain nativeTerrain("BORDER");
TTerrain nativeTerrain = Terrain::BORDER;
for(auto stack : stacks)
{
Terrain stackNativeTerrain = stack.second->type->getNativeTerrain(); //consider terrain bonuses e.g. Lodestar.
TTerrain stackNativeTerrain = stack.second->type->getNativeTerrain(); //consider terrain bonuses e.g. Lodestar.
if(stackNativeTerrain == Terrain("BORDER"))
if(stackNativeTerrain == Terrain::BORDER) //where does this value come from?
continue;
if(nativeTerrain == Terrain("BORDER"))
if(nativeTerrain == Terrain::BORDER) //FIXME: this statement is always true
nativeTerrain = stackNativeTerrain;
else if(nativeTerrain != stackNativeTerrain)
return Terrain("BORDER");
return Terrain::BORDER;
}
return nativeTerrain;
}
@ -529,7 +529,8 @@ void CGHeroInstance::initObj(CRandomGenerator & rand)
if (ID != Obj::PRISON)
{
auto customApp = VLC->objtypeh->getHandlerFor(ID, type->heroClass->getIndex())->getOverride(cb->gameState()->getTile(visitablePos())->terType, this);
auto terrain = cb->gameState()->getTile(visitablePos())->terType->id;
auto customApp = VLC->objtypeh->getHandlerFor(ID, type->heroClass->getIndex())->getOverride(terrain, this);
if (customApp)
appearance = customApp;
}

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
Terrain getNativeTerrain() const;
TTerrain 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

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

View File

@ -581,7 +581,7 @@ BattleField AObjectTypeHandler::getBattlefield() const
return battlefield ? BattleField::fromString(battlefield.get()) : BattleField::NONE;
}
std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplates(const Terrain & terrainType) const
std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplates(TTerrain terrainType) const
{
std::vector<std::shared_ptr<const ObjectTemplate>> templates = getTemplates();
std::vector<std::shared_ptr<const ObjectTemplate>> filtered;
@ -598,7 +598,7 @@ std::vector<std::shared_ptr<const ObjectTemplate>>AObjectTypeHandler::getTemplat
return filtered;
}
std::shared_ptr<const ObjectTemplate> AObjectTypeHandler::getOverride(const Terrain & terrainType, const CGObjectInstance * object) const
std::shared_ptr<const ObjectTemplate> AObjectTypeHandler::getOverride(TTerrain 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 Terrain & terrainType) const;
std::vector<std::shared_ptr<const ObjectTemplate>> getTemplates(const TTerrain 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(const Terrain & terrainType, const CGObjectInstance * object) const;
std::shared_ptr<const ObjectTemplate> getOverride(TTerrain terrainType, const CGObjectInstance * object) const;
BattleField getBattlefield() const;

View File

@ -206,8 +206,8 @@ void CGObjectInstance::setType(si32 ID, si32 subID)
logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString());
return;
}
if(!handler->getTemplates(tile.terType).empty())
appearance = handler->getTemplates(tile.terType)[0];
if(!handler->getTemplates(tile.terType->id).empty())
appearance = handler->getTemplates(tile.terType->id)[0];
else
appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash
if (ID == Obj::HERO)
@ -434,7 +434,7 @@ int3 IBoatGenerator::bestLocation() const
{
if(const TerrainTile *tile = IObjectInterface::cb->getTile(o->pos + offset, false)) //tile is in the map
{
if(tile->terType.isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat
if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat
return o->pos + offset;
}
}

View File

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

View File

@ -155,20 +155,20 @@ void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
// so these two fields can be interpreted as "strong affinity" and "weak affinity" towards terrains
std::string & terrStr = strings[4]; // allowed terrains, 1 = object can be placed on this terrain
assert(terrStr.size() == 9); // all terrains but rock
for(size_t i = 0; i < 9; i++)
assert(terrStr.size() == Terrain::ROCK - 1); // all terrains but rock
for(TTerrain i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ROCK; i++)
{
if (terrStr[8-i] == '1')
allowedTerrains.insert(Terrain::createTerrainTypeH3M(i));
allowedTerrains.insert(i);
}
//assuming that object can be placed on other land terrains
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain("water")))
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain::WATER))
{
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
if(terrain.isLand() && terrain.isPassable())
allowedTerrains.insert(terrain);
if(terrain->isLand() && terrain->isPassable())
allowedTerrains.insert(terrain->id);
}
}
@ -229,19 +229,19 @@ void ObjectTemplate::readMap(CBinaryReader & reader)
reader.readUInt16();
ui16 terrMask = reader.readUInt16();
for(size_t i = 0; i < 9; i++)
for(size_t i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ROCK; i++)
{
if (((terrMask >> i) & 1 ) != 0)
allowedTerrains.insert(Terrain::createTerrainTypeH3M(i));
allowedTerrains.insert(i);
}
//assuming that object can be placed on other land terrains
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain("water")))
if(allowedTerrains.size() >= 8 && !allowedTerrains.count(Terrain::WATER))
{
for(auto & terrain : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
if(terrain.isLand() && terrain.isPassable())
allowedTerrains.insert(terrain);
if(terrain->isLand() && terrain->isPassable())
allowedTerrains.insert(terrain->id);
}
}
@ -285,15 +285,15 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain)
if(withTerrain && !node["allowedTerrains"].isNull())
{
for (auto & entry : node["allowedTerrains"].Vector())
allowedTerrains.insert(entry.String());
allowedTerrains.insert(VLC->terrainTypeHandler->getInfoByName(entry.String())->id);
}
else
{
for(auto & i : VLC->terrainTypeHandler::terrains())
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
{
if(!i.isPassable() || i.isWater())
if(!terrain->isPassable() || terrain->isWater())
continue;
allowedTerrains.insert(i);
allowedTerrains.insert(terrain->id);
}
}
@ -369,7 +369,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
if(withTerrain)
{
//assumed that ROCK and WATER terrains are not included
if(allowedTerrains.size() < (VLC->terrainTypeHandler::terrains().size() - 2))
if(allowedTerrains.size() < (VLC->terrainTypeHandler->terrains().size() - 2))
{
JsonVector & data = node["allowedTerrains"].Vector();
@ -556,9 +556,9 @@ void ObjectTemplate::calculateVisitableOffset()
visitableOffset = int3(0, 0, 0);
}
bool ObjectTemplate::canBePlacedAt(Terrain terrain) const
bool ObjectTemplate::canBePlacedAt(TTerrain terrain) const
{
return allowedTerrains.count(terrain) != 0;
return vstd::contains(allowedTerrains, terrain);
}
void ObjectTemplate::recalculate()

View File

@ -16,7 +16,6 @@ class CBinaryReader;
class CLegacyConfigParser;
class JsonNode;
class int3;
class Terrain;
class DLL_LINKAGE ObjectTemplate
{
@ -32,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<Terrain> allowedTerrains;
std::set<TTerrain> allowedTerrains;
void afterLoadFixup();
@ -99,7 +98,7 @@ public:
};
// Checks if object can be placed on specific terrain
bool canBePlacedAt(Terrain terrain) const;
bool canBePlacedAt(TTerrain terrain) const;
ObjectTemplate();
//custom copy constructor is required

View File

@ -123,8 +123,15 @@ CCastleEvent::CCastleEvent() : town(nullptr)
}
TerrainTile::TerrainTile() : terType("BORDER"), terView(0), riverType(RIVER_NAMES[0]),
riverDir(0), roadType(ROAD_NAMES[0]), roadDir(0), extTileFlags(0), visitable(false),
TerrainTile::TerrainTile():
terType(nullptr),
terView(0),
riverType(RIVER_NAMES[0]),
riverDir(0),
roadType(ROAD_NAMES[0]),
roadDir(0),
extTileFlags(0),
visitable(false),
blocked(false)
{
@ -132,13 +139,13 @@ TerrainTile::TerrainTile() : terType("BORDER"), terView(0), riverType(RIVER_NAME
bool TerrainTile::entrableTerrain(const TerrainTile * from) const
{
return entrableTerrain(from ? from->terType.isLand() : true, from ? from->terType.isWater() : true);
return entrableTerrain(from ? from->terType->isLand() : true, from ? from->terType->isWater() : true);
}
bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const
{
return terType.isPassable()
&& ((allowSea && terType.isWater()) || (allowLand && terType.isLand()));
return terType->isPassable()
&& ((allowSea && terType->isWater()) || (allowLand && terType->isLand()));
}
bool TerrainTile::isClear(const TerrainTile * from) const
@ -164,7 +171,7 @@ CGObjectInstance * TerrainTile::topVisitableObj(bool excludeTop) const
EDiggingStatus TerrainTile::getDiggingStatus(const bool excludeTop) const
{
if(terType.isWater() || !terType.isPassable())
if(terType->isWater() || !terType->isPassable())
return EDiggingStatus::WRONG_TERRAIN;
int allowedBlocked = excludeTop ? 1 : 0;
@ -181,7 +188,7 @@ bool TerrainTile::hasFavorableWinds() const
bool TerrainTile::isWater() const
{
return terType.isWater();
return terType->isWater();
}
void CMapHeader::setupEvents()

View File

@ -80,7 +80,7 @@ struct DLL_LINKAGE TerrainTile
EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
bool hasFavorableWinds() const;
Terrain terType;
TerrainType * terType;
ui8 terView;
std::string riverType;
ui8 riverDir;

View File

@ -124,7 +124,7 @@ void CMapEditManager::clearTerrain(CRandomGenerator * gen)
execute(make_unique<CClearTerrainOperation>(map, gen ? gen : &(this->gen)));
}
void CMapEditManager::drawTerrain(Terrain terType, CRandomGenerator * gen)
void CMapEditManager::drawTerrain(TTerrain terType, CRandomGenerator * gen)
{
execute(make_unique<CDrawTerrainOperation>(map, terrainSel, terType, gen ? gen : &(this->gen)));
terrainSel.clearSelection();

View File

@ -70,7 +70,7 @@ public:
void clearTerrain(CRandomGenerator * gen = nullptr);
/// Draws terrain at the current terrain selection. The selection will be cleared automatically.
void drawTerrain(Terrain terType, CRandomGenerator * gen = nullptr);
void drawTerrain(TTerrain terType, CRandomGenerator * gen = nullptr);
/// Draws roads at the current terrain selection. The selection will be cleared automatically.
void drawRoad(const std::string & roadType, CRandomGenerator * gen = nullptr);

View File

@ -81,8 +81,11 @@ void CComposedOperation::addOperation(std::unique_ptr<CMapOperation>&& operation
operations.push_back(std::move(operation));
}
CDrawTerrainOperation::CDrawTerrainOperation(CMap* map, const CTerrainSelection& terrainSel, Terrain terType, CRandomGenerator* gen)
: CMapOperation(map), terrainSel(terrainSel), terType(terType), gen(gen)
CDrawTerrainOperation::CDrawTerrainOperation(CMap* map, const CTerrainSelection& terrainSel, TTerrain terType, CRandomGenerator* gen):
CMapOperation(map),
terrainSel(terrainSel),
terType(terType),
gen(gen)
{
}
@ -92,7 +95,7 @@ void CDrawTerrainOperation::execute()
for(const auto & pos : terrainSel.getSelectedItems())
{
auto & tile = map->getTile(pos);
tile.terType = terType;
tile.terType = VLC->terrainTypeHandler->terrains()[terType];
invalidateTerrainViews(pos);
}
@ -149,7 +152,7 @@ void CDrawTerrainOperation::updateTerrainTypes()
rect.forEach([&](const int3& posToTest)
{
auto & terrainTile = map->getTile(posToTest);
if(centerTile.terType != terrainTile.terType)
if(centerTile.terType->id != terrainTile.terType->id)
{
auto formerTerType = terrainTile.terType;
terrainTile.terType = centerTile.terType;
@ -252,7 +255,7 @@ void CDrawTerrainOperation::updateTerrainViews()
{
for(const auto & pos : invalidatedTerViews)
{
const auto & patterns = VLC->terviewh->getTerrainViewPatterns(map->getTile(pos).terType);
const auto & patterns = VLC->terviewh->getTerrainViewPatterns(map->getTile(pos).terType->id);
// Detect a pattern which fits best
int bestPattern = -1;
@ -340,7 +343,7 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
int cy = pos.y + (i / 3) - 1;
int3 currentPos(cx, cy, pos.z);
bool isAlien = false;
Terrain terType;
TerrainType * terType = nullptr;
if(!map->isInTheMap(currentPos))
{
// position is not in the map, so take the ter type from the neighbor tile
@ -373,7 +376,7 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
else
{
terType = map->getTile(currentPos).terType;
if(terType != centerTerType && (terType.isPassable() || centerTerType.isPassable()))
if(terType != centerTerType && (terType->isPassable() || centerTerType->isPassable()))
{
isAlien = true;
}
@ -388,9 +391,9 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
{
if(recDepth == 0 && map->isInTheMap(currentPos))
{
if(terType == centerTerType)
if(terType->id == centerTerType->id)
{
const auto & patternForRule = VLC->terviewh->getTerrainViewPatternsById(centerTerType, rule.name);
const auto & patternForRule = VLC->terviewh->getTerrainViewPatternsById(centerTerType->id, rule.name);
if(auto p = patternForRule)
{
auto rslt = validateTerrainView(currentPos, &(*p), 1);
@ -417,18 +420,18 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
bool nativeTestOk, nativeTestStrongOk;
nativeTestOk = nativeTestStrongOk = (rule.isNativeStrong() || rule.isNativeRule()) && !isAlien;
if(centerTerType == Terrain("dirt"))
if(centerTerType->id == Terrain::DIRT)
{
nativeTestOk = rule.isNativeRule() && !terType.isTransitionRequired();
nativeTestOk = rule.isNativeRule() && !terType->isTransitionRequired();
bool sandTestOk = (rule.isSandRule() || rule.isTransition())
&& terType.isTransitionRequired();
&& terType->isTransitionRequired();
applyValidationRslt(rule.isAnyRule() || sandTestOk || nativeTestOk || nativeTestStrongOk);
}
else if(centerTerType == Terrain("sand"))
else if(centerTerType->id == Terrain::SAND)
{
applyValidationRslt(true);
}
else if(centerTerType.isTransitionRequired()) //water, rock and some special terrains require sand transition
else if(centerTerType->isTransitionRequired()) //water, rock and some special terrains require sand transition
{
bool sandTestOk = (rule.isSandRule() || rule.isTransition())
&& isAlien;
@ -437,9 +440,9 @@ CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainVi
else
{
bool dirtTestOk = (rule.isDirtRule() || rule.isTransition())
&& isAlien && !terType.isTransitionRequired();
&& isAlien && !terType->isTransitionRequired();
bool sandTestOk = (rule.isSandRule() || rule.isTransition())
&& terType.isTransitionRequired();
&& terType->isTransitionRequired();
if(transitionReplacement.empty() && rule.isTransition()
&& (dirtTestOk || sandTestOk))
@ -502,7 +505,7 @@ CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const
auto valid = validateTerrainView(pos, ptrConfig->getTerrainTypePatternById("n1")).result;
// Special validity check for rock & water
if(valid && (terType.isWater() || !terType.isPassable()))
if(valid && (terType->isWater() || !terType->isPassable()))
{
static const std::string patternIds[] = { "s1", "s2" };
for(auto & patternId : patternIds)
@ -512,7 +515,7 @@ CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const
}
}
// Additional validity check for non rock OR water
else if(!valid && (terType.isLand() && terType.isPassable()))
else if(!valid && (terType->isLand() && terType->isPassable()))
{
static const std::string patternIds[] = { "n2", "n3" };
for (auto & patternId : patternIds)
@ -546,12 +549,12 @@ CClearTerrainOperation::CClearTerrainOperation(CMap* map, CRandomGenerator* gen)
{
CTerrainSelection terrainSel(map);
terrainSel.selectRange(MapRect(int3(0, 0, 0), map->width, map->height));
addOperation(make_unique<CDrawTerrainOperation>(map, terrainSel, Terrain("water"), gen));
addOperation(make_unique<CDrawTerrainOperation>(map, terrainSel, Terrain::WATER, gen));
if(map->twoLevel)
{
terrainSel.clearSelection();
terrainSel.selectRange(MapRect(int3(0, 0, 1), map->width, map->height));
addOperation(make_unique<CDrawTerrainOperation>(map, terrainSel, Terrain("rock"), gen));
addOperation(make_unique<CDrawTerrainOperation>(map, terrainSel, Terrain::ROCK, gen));
}
}

View File

@ -61,7 +61,7 @@ private:
class CDrawTerrainOperation : public CMapOperation
{
public:
CDrawTerrainOperation(CMap * map, const CTerrainSelection & terrainSel, Terrain terType, CRandomGenerator * gen);
CDrawTerrainOperation(CMap * map, const CTerrainSelection & terrainSel, TTerrain 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;
Terrain terType;
TTerrain terType;
CRandomGenerator* gen;
std::set<int3> invalidatedTerViews;
};

View File

@ -268,9 +268,9 @@ CTerrainViewPatternConfig::~CTerrainViewPatternConfig()
}
const std::vector<CTerrainViewPatternConfig::TVPVector> & CTerrainViewPatternConfig::getTerrainViewPatterns(const Terrain & terrain) const
const std::vector<CTerrainViewPatternConfig::TVPVector> & CTerrainViewPatternConfig::getTerrainViewPatterns(TTerrain terrain) const
{
auto iter = terrainViewPatterns.find(Terrain::Manager::getInfo(terrain).terrainViewPatterns);
auto iter = terrainViewPatterns.find(VLC->terrainTypeHandler->terrains()[terrain]->terrainViewPatterns);
if (iter == terrainViewPatterns.end())
return terrainViewPatterns.at("normal");
return iter->second;
@ -293,7 +293,7 @@ boost::optional<const TerrainViewPattern &> CTerrainViewPatternConfig::getTerrai
return boost::optional<const TerrainViewPattern&>();
}
boost::optional<const CTerrainViewPatternConfig::TVPVector &> CTerrainViewPatternConfig::getTerrainViewPatternsById(const Terrain & terrain, const std::string & id) const
boost::optional<const CTerrainViewPatternConfig::TVPVector &> CTerrainViewPatternConfig::getTerrainViewPatternsById(TTerrain terrain, const std::string & id) const
{
const std::vector<TVPVector> & groupPatterns = getTerrainViewPatterns(terrain);
for (const TVPVector & patternFlips : groupPatterns)
@ -355,7 +355,7 @@ void CTerrainViewPatternUtils::printDebuggingInfoAboutTile(const CMap * map, int
{
auto debugTile = map->getTile(debugPos);
std::string terType = static_cast<std::string>(debugTile.terType).substr(0, 6);
std::string terType = debugTile.terType->name.substr(0, 6);
line += terType;
line.insert(line.end(), PADDED_LENGTH - terType.size(), ' ');
}

View File

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

View File

@ -921,6 +921,7 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
void CMapLoaderH3M::readTerrain()
{
map->initTerrain();
const auto terrains = VLC->terrainTypeHandler->terrains();
// Read terrain
int3 pos;
@ -937,14 +938,14 @@ void CMapLoaderH3M::readTerrain()
for(pos.x = 0; pos.x < map->width; pos.x++)
{
auto & tile = map->getTile(pos);
tile.terType = Terrain::createTerrainTypeH3M(reader.readUInt8());
tile.terType = terrains[reader.readUInt8()];
tile.terView = reader.readUInt8();
tile.riverType = RIVER_NAMES[reader.readUInt8()];
tile.riverDir = reader.readUInt8();
tile.roadType = ROAD_NAMES[reader.readUInt8()];
tile.roadDir = reader.readUInt8();
tile.extTileFlags = reader.readUInt8();
tile.blocked = ((!tile.terType.isPassable() || tile.terType == Terrain("BORDER") ) ? true : false); //underground tiles are always blocked
tile.blocked = ((!tile.terType->isPassable() || tile.terType->id == Terrain::BORDER ) ? true : false); //underground tiles are always blocked
tile.visitable = 0;
}
}

View File

@ -945,7 +945,7 @@ void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile
using namespace TerrainDetail;
{//terrain type
const std::string typeCode = src.substr(0, 2);
tile.terType = Terrain::createTerrainByCode(typeCode);
tile.terType = const_cast<TerrainType *>(VLC->terrainTypeHandler->getInfoByCode(typeCode));
}
int startPos = 2; //0+typeCode fixed length
{//terrain view
@ -1276,7 +1276,7 @@ std::string CMapSaverJson::writeTerrainTile(const TerrainTile & tile)
out.setf(std::ios::dec, std::ios::basefield);
out.unsetf(std::ios::showbase);
out << Terrain::Manager::getInfo(tile.terType).typeCode << (int)tile.terView << flipCodes[tile.extTileFlags % 4];
out << tile.terType->typeCode << (int)tile.terView << flipCodes[tile.extTileFlags % 4];
if(tile.roadType != ROAD_NAMES[0])
out << tile.roadType << (int)tile.roadDir << flipCodes[(tile.extTileFlags >> 4) % 4];

View File

@ -49,12 +49,12 @@ void CMapGenerator::loadConfig()
for(auto& s : randomMapJson["terrain"]["undergroundAllow"].Vector())
{
if(!s.isNull())
config.terrainUndergroundAllowed.emplace_back(s.String());
config.terrainUndergroundAllowed.emplace_back(VLC->terrainTypeHandler->getInfoByName(s.String())->id);
}
for(auto& s : randomMapJson["terrain"]["groundProhibit"].Vector())
{
if(!s.isNull())
config.terrainGroundProhibit.emplace_back(s.String());
config.terrainGroundProhibit.emplace_back(VLC->terrainTypeHandler->getInfoByName(s.String())->id);
}
config.shipyardGuard = randomMapJson["waterZone"]["shipyard"]["value"].Integer();
for(auto & treasure : randomMapJson["waterZone"]["treasure"].Vector())

View File

@ -32,8 +32,8 @@ class DLL_LINKAGE CMapGenerator: public Load::Progress
public:
struct Config
{
std::vector<Terrain> terrainUndergroundAllowed;
std::vector<Terrain> terrainGroundProhibit;
std::vector<TTerrain> terrainUndergroundAllowed;
std::vector<TTerrain> terrainGroundProhibit;
std::vector<CTreasureInfo> waterTreasure;
int shipyardGuard;
int mineExtraResources;

View File

@ -67,12 +67,13 @@ class TerrainEncoder
public:
static si32 decode(const std::string & identifier)
{
return vstd::find_pos(VLC->terrainTypeHandler::terrains(), identifier);
return VLC->terrainTypeHandler->getInfoByCode(identifier)->id;
}
static std::string encode(const si32 index)
{
return (index >=0 && index < VLC->terrainTypeHandler::terrains().size()) ? static_cast<std::string>(VLC->terrainTypeHandler::terrains()[index]) : "<INVALID TERRAIN>";
const auto& terrains = VLC->terrainTypeHandler->terrains();
return (index >=0 && index < terrains.size()) ? terrains[index]->name : "<INVALID TERRAIN>";
}
};
@ -149,9 +150,9 @@ ZoneOptions::ZoneOptions()
terrainTypeLikeZone(NO_ZONE),
treasureLikeZone(NO_ZONE)
{
for(auto & terr : VLC->terrainTypeHandler::terrains())
if(terr.isLand() && terr.isPassable())
terrainTypes.insert(terr);
for(const auto * terr : VLC->terrainTypeHandler->terrains())
if(terr->isLand() && terr->isPassable())
terrainTypes.insert(terr->id);
}
ZoneOptions & ZoneOptions::operator=(const ZoneOptions & other)
@ -214,12 +215,12 @@ boost::optional<int> ZoneOptions::getOwner() const
return owner;
}
const std::set<Terrain> & ZoneOptions::getTerrainTypes() const
const std::set<TTerrain> & ZoneOptions::getTerrainTypes() const
{
return terrainTypes;
}
void ZoneOptions::setTerrainTypes(const std::set<Terrain> & value)
void ZoneOptions::setTerrainTypes(const std::set<TTerrain> & 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());
@ -374,7 +375,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
terrainTypes.clear();
for(auto ttype : node.Vector())
{
terrainTypes.emplace(ttype.String());
terrainTypes.emplace(VLC->terrainTypeHandler->getInfoByName(ttype.String())->id);
}
}
}

View File

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

View File

@ -191,14 +191,14 @@ void CZonePlacer::prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const
else
{
auto & tt = (*VLC->townh)[faction]->nativeTerrain;
if(tt == Terrain("dirt"))
if(tt == Terrain::DIRT)
{
//any / random
zonesToPlace.push_back(zone);
}
else
{
if(tt.isUnderground())
if(VLC->terrainTypeHandler->terrains()[tt]->isUnderground())
{
//underground
zonesOnLevel[1]++;
@ -571,7 +571,7 @@ void CZonePlacer::assignZones(CRandomGenerator * rand)
//make sure that terrain inside zone is not a rock
//FIXME: reorder actions?
paintZoneTerrain(*zone.second, *rand, map, Terrain("subterra"));
paintZoneTerrain(*zone.second, *rand, map, Terrain::SUBTERRANEAN);
}
}
logGlobal->info("Finished zone colouring");

View File

@ -82,8 +82,9 @@ void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & con
//1. Try to make direct connection
//Do if it's not prohibited by terrain settings
bool directProhibited = vstd::contains(Terrain::Manager::getInfo(zone.getTerrainType()).prohibitTransitions, otherZone->getTerrainType())
|| vstd::contains(Terrain::Manager::getInfo(otherZone->getTerrainType()).prohibitTransitions, zone.getTerrainType());
const auto& terrains = VLC->terrainTypeHandler->terrains();
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())
{

View File

@ -93,14 +93,14 @@ void createBorder(RmgMap & gen, Zone & zone)
}
}
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, const Terrain & terrainType)
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrain terrain)
{
auto v = zone.getArea().getTilesVector();
map.getEditManager()->getTerrainSelection().setSelection(v);
map.getEditManager()->drawTerrain(terrainType, &generator);
map.getEditManager()->drawTerrain(terrain, &generator);
}
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, const Terrain & terrain)
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrain terrain)
{
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
vstd::erase_if(factories, [ObjID, &terrain](si32 f)
@ -116,10 +116,10 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
if(zone.getType()==ETemplateZoneType::WATER)
{
//collect all water terrain types
std::vector<Terrain> waterTerrains;
for(auto & terrain : VLC->terrainTypeHandler::terrains())
if(terrain.isWater())
waterTerrains.push_back(terrain);
std::vector<TTerrain> waterTerrains;
for(auto & terrain : VLC->terrainTypeHandler->terrains())
if(terrain->isWater())
waterTerrains.push_back(terrain->id);
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, gen.rand));
}
@ -141,18 +141,19 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
if(!vstd::contains(gen.getConfig().terrainUndergroundAllowed, zone.getTerrainType()))
{
//collect all underground terrain types
std::vector<Terrain> undegroundTerrains;
for(auto & terrain : VLC->terrainTypeHandler::terrains())
if(terrain.isUnderground())
undegroundTerrains.push_back(terrain);
std::vector<TTerrain> undegroundTerrains;
for(const auto * terrain : VLC->terrainTypeHandler->terrains())
if(terrain->isUnderground())
undegroundTerrains.push_back(terrain->id);
zone.setTerrainType(*RandomGeneratorUtil::nextItem(undegroundTerrains, gen.rand));
}
}
else
{
if(vstd::contains(gen.getConfig().terrainGroundProhibit, zone.getTerrainType()) || zone.getTerrainType().isUnderground())
zone.setTerrainType(Terrain("dirt"));
const auto* terrainType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()];
if(vstd::contains(gen.getConfig().terrainGroundProhibit, zone.getTerrainType()) || terrainType->isUnderground())
zone.setTerrainType(Terrain::DIRT);
}
}
}
@ -168,7 +169,7 @@ void createObstaclesCommon2(RmgMap & map, CRandomGenerator & generator)
for(int y = 0; y < map.map().height; y++)
{
int3 tile(x, y, 1);
if(!map.map().getTile(tile).terType.isPassable())
if(!map.map().getTile(tile).terType->isPassable())
{
map.setOccupied(tile, ETileType::USED);
}

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, const Terrain & terrainType);
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, RmgMap & map, TTerrain terrainType);
void initTerrainType(Zone & zone, CMapGenerator & gen);
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, const Terrain & terrain);
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TTerrain terrain);

View File

@ -91,7 +91,7 @@ void RiverPlacer::init()
void RiverPlacer::drawRivers()
{
map.getEditManager()->getTerrainSelection().setSelection(rivers.getTilesVector());
map.getEditManager()->drawRiver(Terrain::Manager::getInfo(zone.getTerrainType()).river, &generator.rand);
map.getEditManager()->drawRiver(VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->river, &generator.rand);
}
char RiverPlacer::dump(const int3 & t)
@ -200,7 +200,7 @@ void RiverPlacer::preprocess()
//calculate delta positions
if(connectedToWaterZoneId > -1)
{
auto river = Terrain::Manager::getInfo(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())
@ -326,7 +326,7 @@ void RiverPlacer::preprocess()
void RiverPlacer::connectRiver(const int3 & tile)
{
auto river = Terrain::Manager::getInfo(zone.getTerrainType()).river;
auto river = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()]->river;
if(river.empty() || river == RIVER_NAMES[0])
return;

View File

@ -82,7 +82,7 @@ void RmgMap::initTiles(CMapGenerator & generator)
getEditManager()->clearTerrain(&generator.rand);
getEditManager()->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions.getWidth(), mapGenOptions.getHeight()));
getEditManager()->drawTerrain(Terrain("grass"), &generator.rand);
getEditManager()->drawTerrain(Terrain::GRASS, &generator.rand);
auto tmpl = mapGenOptions.getMapTemplate();
zones.clear();

View File

@ -103,13 +103,17 @@ void Object::Instance::setPositionRaw(const int3 & position)
dObject.pos = dPosition + dParent.getPosition();
}
void Object::Instance::setTemplate(const Terrain & terrain)
void Object::Instance::setTemplate(const TTerrain & terrain)
{
if(dObject.appearance->id == Obj::NO_OBJ)
{
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain);
if(templates.empty())
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % static_cast<std::string>(terrain)));
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") %
dObject.ID % dObject.subID % terrainName));
}
dObject.appearance = templates.front();
}
@ -253,7 +257,7 @@ void Object::setPosition(const int3 & position)
i.setPositionRaw(i.getPosition());
}
void Object::setTemplate(const Terrain & terrain)
void Object::setTemplate(const TTerrain & terrain)
{
for(auto& i : dInstances)
i.setTemplate(terrain);
@ -289,11 +293,12 @@ void Object::Instance::finalize(RmgMap & map)
if (dObject.appearance->id == Obj::NO_OBJ)
{
auto terrainType = map.map().getTile(getPosition(true)).terType;
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType);
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType->id);
if (templates.empty())
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") % dObject.ID % dObject.subID % getPosition(true).toString() % terrainType));
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") %
dObject.ID % dObject.subID % getPosition(true).toString() % terrainType->name));
setTemplate(terrainType);
setTemplate(terrainType->id);
}
for(auto & tile : getBlockedArea().getTilesVector())

View File

@ -16,7 +16,6 @@
class CGObjectInstance;
class RmgMap;
class Terrain;
namespace rmg {
class Object
@ -34,7 +33,7 @@ public:
int3 getVisitablePosition() const;
bool isVisitableFrom(const int3 & tile) const;
const Area & getAccessibleArea() const;
void setTemplate(const Terrain & terrain); //cache invalidation
void setTemplate(const TTerrain & terrain); //cache invalidation
int3 getPosition(bool isAbsolute = false) const;
void setPosition(const int3 & position); //cache invalidation
@ -70,7 +69,7 @@ public:
const int3 & getPosition() const;
void setPosition(const int3 & position);
void setTemplate(const Terrain & terrain);
void setTemplate(const TTerrain & terrain);
const Area & getArea() const; //lazy cache invalidation

View File

@ -22,8 +22,8 @@
void RockPlacer::process()
{
rockTerrain = Terrain::Manager::getInfo(zone.getTerrainType()).rockTerrain;
assert(!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>())
@ -76,7 +76,7 @@ void RockPlacer::postProcess()
//finally mark rock tiles as occupied, spawn no obstacles there
rockArea = zone.area().getSubarea([this](const int3 & t)
{
return !map.map().getTile(t).terType.isPassable();
return !map.map().getTile(t).terType->isPassable();
});
zone.areaUsed().unite(rockArea);
@ -95,7 +95,7 @@ void RockPlacer::init()
char RockPlacer::dump(const int3 & t)
{
if(!map.map().getTile(t).terType.isPassable())
if(!map.map().getTile(t).terType->isPassable())
{
return zone.area().contains(t) ? 'R' : 'E';
}

View File

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

View File

@ -61,14 +61,14 @@ ETileType::ETileType TileInfo::getTileType() const
return occupied;
}
Terrain TileInfo::getTerrainType() const
TTerrain TileInfo::getTerrainType() const
{
return terrain;
}
void TileInfo::setTerrainType(Terrain value)
void TileInfo::setTerrainType(TTerrain type)
{
terrain = value;
terrain = type;
}
void TileInfo::setRoadType(const std::string & value)

View File

@ -28,14 +28,14 @@ public:
bool isUsed() const;
bool isRoad() const;
void setOccupied(ETileType::ETileType value);
Terrain getTerrainType() const;
TTerrain getTerrainType() const;
ETileType::ETileType getTileType() const;
void setTerrainType(Terrain value);
void setTerrainType(TTerrain value);
void setRoadType(const std::string & value);
private:
float nearestObjectDistance;
ETileType::ETileType occupied;
Terrain terrain;
TTerrain terrain;
std::string roadType;
};

View File

@ -811,7 +811,7 @@ ObjectInfo::ObjectInfo()
}
void ObjectInfo::setTemplate(si32 type, si32 subtype, Terrain terrainType)
void ObjectInfo::setTemplate(si32 type, si32 subtype, TTerrain 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, Terrain terrain);
void setTemplate(si32 type, si32 subtype, TTerrain terrain);
ObjectInfo();

View File

@ -51,7 +51,7 @@ void WaterProxy::process()
for(auto & t : z.second->area().getTilesVector())
{
if(map.map().getTile(t).terType == zone.getTerrainType())
if(map.map().getTile(t).terType->id == zone.getTerrainType())
{
z.second->areaPossible().erase(t);
z.second->area().erase(t);

View File

@ -26,7 +26,7 @@ std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t)
Zone::Zone(RmgMap & map, CMapGenerator & generator)
: ZoneOptions(),
townType(ETownType::NEUTRAL),
terrainType(Terrain("grass")),
terrainType(Terrain::GRASS),
map(map),
generator(generator)
{
@ -132,12 +132,12 @@ void Zone::setTownType(si32 town)
townType = town;
}
const Terrain & Zone::getTerrainType() const
TTerrain Zone::getTerrainType() const
{
return terrainType;
}
void Zone::setTerrainType(const Terrain & terrain)
void Zone::setTerrainType(TTerrain terrain)
{
terrainType = terrain;
}

View File

@ -98,8 +98,8 @@ public:
si32 getTownType() const;
void setTownType(si32 town);
const Terrain & getTerrainType() const;
void setTerrainType(const Terrain & terrain);
TTerrain getTerrainType() const;
void setTerrainType(TTerrain 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;
Terrain terrainType;
TTerrain terrainType;
};

View File

@ -86,7 +86,7 @@ int BattleCbProxy::getTerrainType(lua_State * L)
if(!S.tryGet(1, object))
return S.retVoid();
return LuaStack::quickRetStr(L, object->battleTerrainType());
return LuaStack::quickRetInt(L, object->battleTerrainType());
}
int BattleCbProxy::getUnitByPos(lua_State * L)

View File

@ -1911,7 +1911,7 @@ void CGameHandler::newTurn()
hth.id = h->id;
auto ti = make_unique<TurnInfo>(h, 1);
// TODO: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356
hth.move = h->maxMovePointsCached(gs->map->getTile(h->getPosition(false)).terType.isLand(), ti.get());
hth.move = h->maxMovePointsCached(gs->map->getTile(h->getPosition(false)).terType->isLand(), ti.get());
hth.mana = h->getManaNewTurn();
n.heroes.insert(hth);
@ -2217,9 +2217,9 @@ void CGameHandler::setupBattle(int3 tile, const CArmedInstance *armies[2], const
battleResult.set(nullptr);
const auto t = getTile(tile);
Terrain terrain = t->terType;
TTerrain terrain = t->terType->id;
if (gs->map->isCoastalTile(tile)) //coastal tile is always ground
terrain = Terrain("sand");
terrain = Terrain::SAND;
BattleField terType = gs->battleGetBattlefieldType(tile, getRandomGenerator());
if (heroes[0] && heroes[0]->boat && heroes[1] && heroes[1]->boat)
@ -2316,7 +2316,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
const int3 guardPos = gs->guardingCreaturePosition(hmpos);
const bool embarking = !h->boat && !t.visitableObjects.empty() && t.visitableObjects.back()->ID == Obj::BOAT;
const bool disembarking = h->boat && t.terType.isLand() && !t.blocked;
const bool disembarking = h->boat && t.terType->isLand() && !t.blocked;
//result structure for start - movement failed, no move points used
TryMoveHero tmh;
@ -2338,11 +2338,11 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
//it's a rock or blocked and not visitable tile
//OR hero is on land and dest is water and (there is not present only one object - boat)
if (((!t.terType.isPassable() || (t.blocked && !t.visitable && !canFly))
if (((!t.terType->isPassable() || (t.blocked && !t.visitable && !canFly))
&& complain("Cannot move hero, destination tile is blocked!"))
|| ((!h->boat && !canWalkOnSea && !canFly && t.terType.isWater() && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != Obj::BOAT && t.visitableObjects.back()->ID != Obj::HERO))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276)
|| ((!h->boat && !canWalkOnSea && !canFly && t.terType->isWater() && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != Obj::BOAT && t.visitableObjects.back()->ID != Obj::HERO))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276)
&& complain("Cannot move hero, destination tile is on water!"))
|| ((h->boat && t.terType.isLand() && t.blocked)
|| ((h->boat && t.terType->isLand() && t.blocked)
&& complain("Cannot disembark hero, tile is blocked!"))
|| ((distance(h->pos, dst) >= 1.5 && !teleporting)
&& complain("Tiles are not neighboring!"))

View File

@ -193,7 +193,7 @@ public:
const auto t = gameCallback->getTile(tile);
Terrain terrain = t->terType;
TTerrain terrain = t->terType->id;
BattleField terType = BattleField::fromString("grass_hills");
//send info about battles

View File

@ -33,30 +33,30 @@ TEST(MapManager, DrawTerrain_Type)
// 1x1 Blow up
editManager->getTerrainSelection().select(int3(5, 5, 0));
editManager->drawTerrain(Terrain("grass"));
editManager->drawTerrain(Terrain::GRASS);
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
for(int i = 0; i < ARRAY_COUNT(squareCheck); ++i)
{
EXPECT_EQ(map->getTile(squareCheck[i]).terType, Terrain("grass"));
EXPECT_EQ(map->getTile(squareCheck[i]).terType->id, Terrain::GRASS);
}
// Concat to square
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType, Terrain("grass"));
editManager->drawTerrain(Terrain::GRASS);
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType->id, Terrain::GRASS);
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(Terrain("lava"));
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType, Terrain("grass"));
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType, Terrain("lava"));
editManager->drawTerrain(Terrain::LAVA);
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType->id, Terrain::GRASS);
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType->id, Terrain::LAVA);
// Special case water,rock
editManager->getTerrainSelection().selectRange(MapRect(int3(10, 10, 0), 10, 5));
editManager->drawTerrain(Terrain("grass"));
editManager->drawTerrain(Terrain::GRASS);
editManager->getTerrainSelection().selectRange(MapRect(int3(15, 17, 0), 10, 5));
editManager->drawTerrain(Terrain("grass"));
editManager->drawTerrain(Terrain::GRASS);
editManager->getTerrainSelection().select(int3(21, 16, 0));
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType, Terrain("grass"));
editManager->drawTerrain(Terrain::GRASS);
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType->id, Terrain::GRASS);
// Special case non water,rock
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
@ -66,17 +66,17 @@ TEST(MapManager, DrawTerrain_Type)
{
editManager->getTerrainSelection().select(diagonalCheck[i]);
}
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType, Terrain("water"));
editManager->drawTerrain(Terrain::GRASS);
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType->id, Terrain::WATER);
// Rock case
editManager->getTerrainSelection().selectRange(MapRect(int3(1, 1, 1), 15, 15));
editManager->drawTerrain(Terrain("subterra"));
editManager->drawTerrain(Terrain::SUBTERRANEAN);
std::vector<int3> vec({ int3(6, 6, 1), int3(7, 6, 1), int3(8, 6, 1), int3(5, 7, 1), int3(6, 7, 1), int3(7, 7, 1),
int3(8, 7, 1), int3(4, 8, 1), int3(5, 8, 1), int3(6, 8, 1)});
editManager->getTerrainSelection().setSelection(vec);
editManager->drawTerrain(Terrain("rock"));
EXPECT_TRUE(!map->getTile(int3(5, 6, 1)).terType.isPassable() || !map->getTile(int3(7, 8, 1)).terType.isPassable());
editManager->drawTerrain(Terrain::ROCK);
EXPECT_TRUE(!map->getTile(int3(5, 6, 1)).terType->isPassable() || !map->getTile(int3(7, 8, 1)).terType->isPassable());
//todo: add checks here and enable, also use smaller size
#if 0
@ -143,7 +143,7 @@ TEST(MapManager, DrawTerrain_View)
int3 pos((si32)posVector[0].Float(), (si32)posVector[1].Float(), (si32)posVector[2].Float());
const auto & originalTile = originalMap->getTile(pos);
editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1));
editManager->drawTerrain(originalTile.terType, &gen);
editManager->drawTerrain(originalTile.terType->id, &gen);
const auto & tile = map->getTile(pos);
bool isInRange = false;
for(const auto & range : mapping)

View File

@ -17,7 +17,7 @@ class IBattleInfoCallbackMock : public IBattleInfoCallback
{
public:
MOCK_CONST_METHOD0(getContextPool, scripting::Pool *());
MOCK_CONST_METHOD0(battleTerrainType, Terrain());
MOCK_CONST_METHOD0(battleTerrainType, TTerrain());
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, Terrain());
MOCK_CONST_METHOD0(getTerrainType, TTerrain());
MOCK_CONST_METHOD0(getAllObstacles, IBattleInfo::ObstacleCList());
MOCK_CONST_METHOD0(getDefendedTown, const CGTownInstance *());
MOCK_CONST_METHOD1(getWallState, si8(int));