1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

Initial implementation of VIEW_AIR & VIEW_EARTH

This commit is contained in:
AlexVinS
2015-02-02 15:02:27 +03:00
parent 1333f8e410
commit f6e83685e7
8 changed files with 145 additions and 24 deletions

View File

@ -2189,6 +2189,27 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI
} }
const CSpell * spell = CGI->spellh->objects[spellID]; const CSpell * spell = CGI->spellh->objects[spellID];
if(spellID == SpellID::VIEW_AIR)
{
int level = caster->getSpellSchoolLevel(spell);
adventureInt->worldViewOptions.showAllArtifacts = true;
adventureInt->worldViewOptions.showAllHeroes = (level>1);
adventureInt->worldViewOptions.showAllTowns = (level>2);
viewWorldMap();
}
else if(spellID == SpellID::VIEW_EARTH)
{
int level = caster->getSpellSchoolLevel(spell);
adventureInt->worldViewOptions.showAllResources = true;
adventureInt->worldViewOptions.showAllMines = (level>1);
adventureInt->worldViewOptions.showAllTerrain = (level>2);
viewWorldMap();
}
auto castSoundPath = spell->getCastSound(); auto castSoundPath = spell->getCastSound();
if (!castSoundPath.empty()) if (!castSoundPath.empty())
CCS->soundh->playSound(castSoundPath); CCS->soundh->playSound(castSoundPath);

View File

@ -616,8 +616,7 @@ void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf
if (obj->pos.z != pos.z) if (obj->pos.z != pos.z)
continue; continue;
if (!(*info->visibilityMap)[pos.x][pos.y][pos.z]) const bool isVisible = (*info->visibilityMap)[pos.x][pos.y][pos.z];
continue; // TODO needs to skip this check if we have view-air-like spell cast
if (!obj->visitableAt(pos.x, pos.y)) if (!obj->visitableAt(pos.x, pos.y))
continue; continue;
@ -640,24 +639,31 @@ void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf
case Obj::MONOLITH_ONE_WAY_ENTRANCE: case Obj::MONOLITH_ONE_WAY_ENTRANCE:
case Obj::MONOLITH_ONE_WAY_EXIT: case Obj::MONOLITH_ONE_WAY_EXIT:
case Obj::MONOLITH_TWO_WAY: case Obj::MONOLITH_TWO_WAY:
if(isVisible)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap;
break; break;
case Obj::SUBTERRANEAN_GATE: case Obj::SUBTERRANEAN_GATE:
if(isVisible)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap;
break; break;
case Obj::ARTIFACT: case Obj::ARTIFACT:
if(isVisible || info->showAllArtifacts)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap;
break; break;
case Obj::TOWN: case Obj::TOWN:
if(isVisible || info->showAllTowns)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap;
break; break;
case Obj::HERO: case Obj::HERO:
if(isVisible || info->showAllHeroes)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap;
break; break;
case Obj::MINE: case Obj::MINE:
if(isVisible || info->showAllMines)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + obj->subID + ownerIndex].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + obj->subID + ownerIndex].bitmap;
break; break;
case Obj::RESOURCE: case Obj::RESOURCE:
if(isVisible || info->showAllResources)
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + obj->subID + ownerIndex].bitmap; wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + obj->subID + ownerIndex].bitmap;
break; break;
} }
@ -905,8 +911,7 @@ void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingIn
if (pos.y < 0 || pos.y >= parent->sizes.y) if (pos.y < 0 || pos.y >= parent->sizes.y)
continue; continue;
if (!canDrawCurrentTile()) const bool isVisible = canDrawCurrentTile();
continue;
realTileRect.x = realPos.x; realTileRect.x = realPos.x;
realTileRect.y = realPos.y; realTileRect.y = realPos.y;
@ -915,11 +920,15 @@ void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingIn
const TerrainTile & tinfo = parent->map->getTile(pos); const TerrainTile & tinfo = parent->map->getTile(pos);
const TerrainTile * tinfoUpper = pos.y > 0 ? &parent->map->getTile(int3(pos.x, pos.y - 1, pos.z)) : nullptr; const TerrainTile * tinfoUpper = pos.y > 0 ? &parent->map->getTile(int3(pos.x, pos.y - 1, pos.z)) : nullptr;
if(isVisible || info->showAllTerrain)
{
drawTileTerrain(targetSurf, tinfo, tile); drawTileTerrain(targetSurf, tinfo, tile);
if (tinfo.riverType) if (tinfo.riverType)
drawRiver(targetSurf, tinfo); drawRiver(targetSurf, tinfo);
drawRoad(targetSurf, tinfo, tinfoUpper); drawRoad(targetSurf, tinfo, tinfoUpper);
}
if(isVisible)
drawObjects(targetSurf, tile); drawObjects(targetSurf, tile);
} }
} }
@ -940,7 +949,7 @@ void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingIn
{ {
const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z]; const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z];
if (!(*info->visibilityMap)[pos.x][pos.y][topTile.z]) if (!(*info->visibilityMap)[pos.x][pos.y][topTile.z] && !info->showAllTerrain)
drawFow(targetSurf); drawFow(targetSurf);
// overlay needs to be drawn over fow, because of artifacts-aura-like spells // overlay needs to be drawn over fow, because of artifacts-aura-like spells

View File

@ -101,6 +101,15 @@ struct MapDrawingInfo
bool puzzleMode; bool puzzleMode;
int3 grailPos; // location of grail for puzzle mode [in tiles] int3 grailPos; // location of grail for puzzle mode [in tiles]
bool showAllArtifacts; //for basic viewAir
bool showAllHeroes; //for advanced viewAir
bool showAllTowns; //for expert viewAir
bool showAllResources; //for basic viewEarth
bool showAllMines; //for advanced viewEarth
bool showAllTerrain; //for expert viewEarth
MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, CDefHandler * iconsDef_ = nullptr) MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, CDefHandler * iconsDef_ = nullptr)
: scaled(false), : scaled(false),
topTile(topTile_), topTile(topTile_),
@ -113,7 +122,13 @@ struct MapDrawingInfo
heroAnim(0u), heroAnim(0u),
movement(int3()), movement(int3()),
puzzleMode(false), puzzleMode(false),
grailPos(int3()) grailPos(int3()),
showAllArtifacts(false),
showAllHeroes(false),
showAllTowns(false),
showAllResources(false),
showAllMines(false),
showAllTerrain(false)
{} {}
ui8 getHeroAnim() const { return otherheroAnim ? anim : heroAnim; } ui8 getHeroAnim() const { return otherheroAnim ? anim : heroAnim; }

View File

@ -310,7 +310,7 @@ void CTerrainRect::showAll(SDL_Surface * to)
MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIconsDef); MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIconsDef);
info.scaled = true; info.scaled = true;
info.scale = adventureInt->worldViewScale; info.scale = adventureInt->worldViewScale;
adventureInt->worldViewOptions.adjustDrawingInfo(info);
CGI->mh->drawTerrainRectNew(to, &info); CGI->mh->drawTerrainRectNew(to, &info);
} }
} }
@ -1783,6 +1783,9 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale /* = 0.4f */)
townList.activate(); townList.activate();
heroList.activate(); heroList.activate();
infoBar.activate(); infoBar.activate();
worldViewOptions.clear();
break; break;
case EAdvMapMode::WORLD_VIEW: case EAdvMapMode::WORLD_VIEW:
panelMain->deactivate(); panelMain->deactivate();
@ -1843,3 +1846,24 @@ void CAdventureOptions::showScenarioInfo()
GH.pushInt(new CScenarioInfo(LOCPLINT->cb->getMapHeader(), LOCPLINT->cb->getStartInfo())); GH.pushInt(new CScenarioInfo(LOCPLINT->cb->getMapHeader(), LOCPLINT->cb->getStartInfo()));
} }
} }
CAdvMapInt::WorldViewOptions::WorldViewOptions()
{
clear();
}
void CAdvMapInt::WorldViewOptions::clear()
{
showAllArtifacts = showAllHeroes = showAllTowns = showAllResources = showAllMines = showAllTerrain = false;
}
void CAdvMapInt::WorldViewOptions::adjustDrawingInfo(MapDrawingInfo& info)
{
info.showAllArtifacts = showAllArtifacts;
info.showAllHeroes = showAllHeroes;
info.showAllTowns = showAllTowns;
info.showAllResources = showAllResources;
info.showAllMines = showAllMines;
info.showAllTerrain = showAllTerrain;
}

View File

@ -18,6 +18,8 @@ class IShipyard;
enum class EMapAnimRedrawStatus; enum class EMapAnimRedrawStatus;
class CFadeAnimation; class CFadeAnimation;
struct MapDrawingInfo;
/*****************************/ /*****************************/
/* /*
@ -127,6 +129,25 @@ public:
EAdvMapMode mode; EAdvMapMode mode;
float worldViewScale; float worldViewScale;
struct WorldViewOptions
{
bool showAllArtifacts; //for basic viewAir
bool showAllHeroes; //for advanced viewAir
bool showAllTowns; //for expert viewAir
bool showAllResources; //for basic viewEarth
bool showAllMines; //for advanced viewEarth
bool showAllTerrain; //for expert viewEarth
WorldViewOptions();
void clear();
void adjustDrawingInfo(MapDrawingInfo & info);
};
WorldViewOptions worldViewOptions;
SDL_Surface * bg; SDL_Surface * bg;
SDL_Surface * bgWorldView; SDL_Surface * bgWorldView;
std::vector<CDefHandler *> gems; std::vector<CDefHandler *> gems;

View File

@ -253,3 +253,14 @@ bool TownPortalMechanics::applyAdventureEffects(const SpellCastEnvironment * env
env->moveHero(parameters.caster->id, town->visitablePos() + parameters.caster->getVisitableOffset() ,1); env->moveHero(parameters.caster->id, town->visitablePos() + parameters.caster->getVisitableOffset() ,1);
return true; return true;
} }
bool ViewAirMechanics::applyAdventureEffects(const SpellCastEnvironment* env, AdventureSpellCastParameters& parameters) const
{
return true; //implemented on client side
}
bool ViewEarthMechanics::applyAdventureEffects(const SpellCastEnvironment* env, AdventureSpellCastParameters& parameters) const
{
return true; //implemented on client side
}

View File

@ -55,3 +55,21 @@ public:
protected: protected:
bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const override; bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const override;
}; };
class ViewAirMechanics: public DefaultSpellMechanics
{
public:
ViewAirMechanics(CSpell * s): DefaultSpellMechanics(s){};
protected:
bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const override;
};
class ViewEarthMechanics: public DefaultSpellMechanics
{
public:
ViewEarthMechanics(CSpell * s): DefaultSpellMechanics(s){};
protected:
bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const override;
};

View File

@ -74,10 +74,12 @@ ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
return new AdventureBonusingMechanics(s, Bonus::WATER_WALKING); return new AdventureBonusingMechanics(s, Bonus::WATER_WALKING);
case SpellID::TOWN_PORTAL: case SpellID::TOWN_PORTAL:
return new TownPortalMechanics(s); return new TownPortalMechanics(s);
case SpellID::VISIONS:
case SpellID::VIEW_EARTH: case SpellID::VIEW_EARTH:
case SpellID::DISGUISE: return new ViewEarthMechanics(s);
case SpellID::VIEW_AIR: case SpellID::VIEW_AIR:
return new ViewAirMechanics(s);
case SpellID::VISIONS:
case SpellID::DISGUISE:
default: default:
if(s->isRisingSpell()) if(s->isRisingSpell())
return new SpecialRisingSpellMechanics(s); return new SpecialRisingSpellMechanics(s);