1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Small refactoring of adventure map spell casting:

- Removed duplicated checks for DD possibility
- Moved most of spell-specific code from AdventureMapInterface to library
code
- AdventureSpellMechanics class now provides methods to check whether
spellcast is possible, similarly to battle spells
- If it is not possible to cast adventure map spell (e.g. no mana or no
move points) game will show infowindow immediately on clicking spellbook
instead of on cast attempt
- If hero does not have movement points for a DD, game will show correct
error message
- Added game settings 'dimensionDoorFailureSpendsPoints' due to
discovered H3 logic
This commit is contained in:
Ivan Savenko
2024-04-10 18:19:48 +03:00
parent bcd4a8c961
commit 8353bca34f
15 changed files with 285 additions and 289 deletions

View File

@@ -287,22 +287,9 @@ std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (in
return ret;
}
bool CGameInfoCallback::isTileGuardedAfterDimensionDoorUse(int3 tile, const CGHeroInstance * castingHero) const
bool CGameInfoCallback::isTileGuardedUnchecked(int3 tile) const
{
//for known tiles this is just potential convenience info, for tiles behind fog of war this info matches HotA but not H3 so make it accessible only with proper setting on
bool canAccessInfo = false;
if(isVisible(tile))
canAccessInfo = true;
else if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_TRIGGERS_GUARDS)
&& isInScreenRange(castingHero->getSightCenter(), tile)
&& castingHero->canCastThisSpell(static_cast<SpellID>(SpellID::DIMENSION_DOOR).toSpell()))
canAccessInfo = true; //TODO: check if available casts > 0, before adding that check make dimension door daily limit popup trigger on spell pick
if(canAccessInfo)
return !gs->guardingCreatures(tile).empty();
return false;
return !gs->guardingCreatures(tile).empty();
}
bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject) const
@@ -528,40 +515,12 @@ const TerrainTile * CGameInfoCallback::getTile(int3 tile, bool verbose) const
return nullptr;
}
const TerrainTile * CGameInfoCallback::getTileForDimensionDoor(int3 tile, const CGHeroInstance * castingHero) const
const TerrainTile * CGameInfoCallback::getTileUnchecked(int3 tile) const
{
auto outputTile = getTile(tile, false);
if (isInTheMap(tile))
return &gs->map->getTile(tile);
if(outputTile != nullptr)
return outputTile;
bool allowOnlyToUncoveredTiles = VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_ONLY_TO_UNCOVERED_TILES);
if(!allowOnlyToUncoveredTiles)
{
if(castingHero->canCastThisSpell(static_cast<SpellID>(SpellID::DIMENSION_DOOR).toSpell())
&& isInScreenRange(castingHero->getSightCenter(), tile))
{ //TODO: check if available casts > 0, before adding that check make dimension door daily limit popup trigger on spell pick
//we are allowed to get basic blocked/water invisible nearby tile date when casting DD spell
TerrainTile targetTile = gs->map->getTile(tile);
auto obfuscatedTile = std::make_shared<TerrainTile>();
obfuscatedTile->visitable = false;
obfuscatedTile->blocked = targetTile.blocked || targetTile.visitable;
if(targetTile.blocked || targetTile.visitable)
obfuscatedTile->terType = VLC->terrainTypeHandler->getById(TerrainId::ROCK);
else if(!VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_EXPOSES_TERRAIN_TYPE))
obfuscatedTile->terType = gs->map->getTile(castingHero->getSightCenter()).terType;
else
obfuscatedTile->terType = targetTile.isWater()
? VLC->terrainTypeHandler->getById(TerrainId::WATER)
: VLC->terrainTypeHandler->getById(TerrainId::GRASS);
outputTile = obfuscatedTile.get();
}
}
return outputTile;
return nullptr;
}
EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) const