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

Implemented spell range overlay for Dimension Door and Scuttle Boat

This commit is contained in:
Ivan Savenko 2023-04-20 14:15:08 +03:00
parent 4dc16b9ff7
commit 5c9ae8aafc
10 changed files with 55 additions and 19 deletions

View File

@ -1,6 +1,7 @@
# 1.2.0 -> 1.2.1 # 1.2.0 -> 1.2.1
### GENERAL: ### GENERAL:
* Implemented spell range overlay for Dimension Door and Scuttle Boat
* Fixed movement cost penalty from terrain * Fixed movement cost penalty from terrain
* Fixed empty Black Market on game start * Fixed empty Black Market on game start
* Fixed bad morale happening after waiting * Fixed bad morale happening after waiting

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

View File

@ -1076,8 +1076,11 @@ void CAdvMapInt::onTileLeftClicked(const int3 &mapPos)
const CGObjectInstance *topBlocking = getActiveObject(mapPos); const CGObjectInstance *topBlocking = getActiveObject(mapPos);
int3 selPos = selection->getSightCenter(); int3 selPos = selection->getSightCenter();
if(spellBeingCasted && isInScreenRange(selPos, mapPos)) if(spellBeingCasted)
{ {
if (!isInScreenRange(selPos, mapPos))
return;
const TerrainTile *heroTile = LOCPLINT->cb->getTile(selPos); const TerrainTile *heroTile = LOCPLINT->cb->getTile(selPos);
switch(spellBeingCasted->id) switch(spellBeingCasted->id)
@ -1179,11 +1182,15 @@ void CAdvMapInt::onTileHovered(const int3 &mapPos)
switch(spellBeingCasted->id) switch(spellBeingCasted->id)
{ {
case SpellID::SCUTTLE_BOAT: case SpellID::SCUTTLE_BOAT:
if(objAtTile && objAtTile->ID == Obj::BOAT) {
int3 hpos = selection->getSightCenter();
if(objAtTile && objAtTile->ID == Obj::BOAT && isInScreenRange(hpos, mapPos))
CCS->curh->set(Cursor::Map::SCUTTLE_BOAT); CCS->curh->set(Cursor::Map::SCUTTLE_BOAT);
else else
CCS->curh->set(Cursor::Map::POINTER); CCS->curh->set(Cursor::Map::POINTER);
return; return;
}
case SpellID::DIMENSION_DOOR: case SpellID::DIMENSION_DOOR:
{ {
const TerrainTile * t = LOCPLINT->cb->getTile(mapPos, false); const TerrainTile * t = LOCPLINT->cb->getTile(mapPos, false);
@ -1342,6 +1349,8 @@ void CAdvMapInt::enterCastingMode(const CSpell * sp)
{ {
assert(sp->id == SpellID::SCUTTLE_BOAT || sp->id == SpellID::DIMENSION_DOOR); assert(sp->id == SpellID::SCUTTLE_BOAT || sp->id == SpellID::DIMENSION_DOOR);
spellBeingCasted = sp; spellBeingCasted = sp;
Settings config = settings.write["session"]["showSpellRange"];
config->Bool() = true;
deactivate(); deactivate();
terrain->activate(); terrain->activate();
@ -1356,6 +1365,9 @@ void CAdvMapInt::leaveCastingMode(bool cast, int3 dest)
terrain->deactivate(); terrain->deactivate();
activate(); activate();
Settings config = settings.write["session"]["showSpellRange"];
config->Bool() = false;
if(cast) if(cast)
LOCPLINT->cb->castSpell(curHero(), id, dest); LOCPLINT->cb->castSpell(curHero(), id, dest);
else else

View File

@ -86,4 +86,8 @@ public:
virtual bool showGrid() const = 0; virtual bool showGrid() const = 0;
virtual bool showVisitable() const = 0; virtual bool showVisitable() const = 0;
virtual bool showBlocked() const = 0; virtual bool showBlocked() const = 0;
/// if true, spell range for teleport / scuttle boat will be visible
virtual bool showSpellRange(const int3 & position) const = 0;
}; };

View File

@ -584,15 +584,16 @@ uint8_t MapRendererObjects::checksum(IMapRendererContext & context, const int3 &
return 0xff-1; return 0xff-1;
} }
MapRendererDebug::MapRendererDebug() MapRendererOverlay::MapRendererOverlay()
: imageGrid(IImage::createFromFile("debug/grid", EImageBlitMode::ALPHA)) : imageGrid(IImage::createFromFile("debug/grid", EImageBlitMode::ALPHA))
, imageBlocked(IImage::createFromFile("debug/blocked", EImageBlitMode::ALPHA)) , imageBlocked(IImage::createFromFile("debug/blocked", EImageBlitMode::ALPHA))
, imageVisitable(IImage::createFromFile("debug/visitable", EImageBlitMode::ALPHA)) , imageVisitable(IImage::createFromFile("debug/visitable", EImageBlitMode::ALPHA))
, imageSpellRange(IImage::createFromFile("debug/spellRange", EImageBlitMode::ALPHA))
{ {
} }
void MapRendererDebug::renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates) void MapRendererOverlay::renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates)
{ {
if(context.showGrid()) if(context.showGrid())
target.draw(imageGrid, Point(0,0)); target.draw(imageGrid, Point(0,0));
@ -618,9 +619,12 @@ void MapRendererDebug::renderTile(IMapRendererContext & context, Canvas & target
if (context.showVisitable() && visitable) if (context.showVisitable() && visitable)
target.draw(imageVisitable, Point(0,0)); target.draw(imageVisitable, Point(0,0));
} }
if (context.showSpellRange(coordinates))
target.draw(imageSpellRange, Point(0,0));
} }
uint8_t MapRendererDebug::checksum(IMapRendererContext & context, const int3 & coordinates) uint8_t MapRendererOverlay::checksum(IMapRendererContext & context, const int3 & coordinates)
{ {
uint8_t result = 0; uint8_t result = 0;
@ -633,6 +637,9 @@ uint8_t MapRendererDebug::checksum(IMapRendererContext & context, const int3 & c
if (context.showGrid()) if (context.showGrid())
result += 4; result += 4;
if (context.showSpellRange(coordinates))
result += 8;
return result; return result;
} }
@ -766,7 +773,7 @@ MapRenderer::TileChecksum MapRenderer::getTileChecksum(IMapRendererContext & con
result[3] = rendererRoad.checksum(context, coordinates); result[3] = rendererRoad.checksum(context, coordinates);
result[4] = rendererObjects.checksum(context, coordinates); result[4] = rendererObjects.checksum(context, coordinates);
result[5] = rendererPath.checksum(context, coordinates); result[5] = rendererPath.checksum(context, coordinates);
result[6] = rendererDebug.checksum(context, coordinates); result[6] = rendererOverlay.checksum(context, coordinates);
if(!context.isVisible(coordinates)) if(!context.isVisible(coordinates))
result[7] = rendererFow.checksum(context, coordinates); result[7] = rendererFow.checksum(context, coordinates);
@ -800,7 +807,7 @@ void MapRenderer::renderTile(IMapRendererContext & context, Canvas & target, con
rendererObjects.renderTile(context, target, coordinates); rendererObjects.renderTile(context, target, coordinates);
rendererPath.renderTile(context, target, coordinates); rendererPath.renderTile(context, target, coordinates);
rendererDebug.renderTile(context, target, coordinates); rendererOverlay.renderTile(context, target, coordinates);
if(!context.isVisible(coordinates)) if(!context.isVisible(coordinates))
rendererFow.renderTile(context, target, coordinates); rendererFow.renderTile(context, target, coordinates);

View File

@ -129,21 +129,12 @@ public:
void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates); void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
}; };
class MapRendererDebug class MapRendererOverlay
{ {
std::shared_ptr<IImage> imageGrid; std::shared_ptr<IImage> imageGrid;
std::shared_ptr<IImage> imageVisitable; std::shared_ptr<IImage> imageVisitable;
std::shared_ptr<IImage> imageBlocked; std::shared_ptr<IImage> imageBlocked;
public: std::shared_ptr<IImage> imageSpellRange;
MapRendererDebug();
uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
};
class MapRendererOverlay
{
std::unique_ptr<CAnimation> iconsStorage;
public: public:
MapRendererOverlay(); MapRendererOverlay();
@ -160,7 +151,7 @@ class MapRenderer
MapRendererFow rendererFow; MapRendererFow rendererFow;
MapRendererObjects rendererObjects; MapRendererObjects rendererObjects;
MapRendererPath rendererPath; MapRendererPath rendererPath;
MapRendererDebug rendererDebug; MapRendererOverlay rendererOverlay;
public: public:
using TileChecksum = std::array<uint8_t, 8>; using TileChecksum = std::array<uint8_t, 8>;

View File

@ -22,6 +22,7 @@
#include "../../lib/CPathfinder.h" #include "../../lib/CPathfinder.h"
#include "../../lib/Point.h" #include "../../lib/Point.h"
#include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/mapping/CMap.h" #include "../../lib/mapping/CMap.h"
MapRendererBaseContext::MapRendererBaseContext(const MapRendererContextState & viewState) MapRendererBaseContext::MapRendererBaseContext(const MapRendererContextState & viewState)
@ -199,6 +200,11 @@ bool MapRendererBaseContext::showBlocked() const
return false; return false;
} }
bool MapRendererBaseContext::showSpellRange(const int3 & position) const
{
return false;
}
MapRendererAdventureContext::MapRendererAdventureContext(const MapRendererContextState & viewState) MapRendererAdventureContext::MapRendererAdventureContext(const MapRendererContextState & viewState)
: MapRendererBaseContext(viewState) : MapRendererBaseContext(viewState)
{ {
@ -266,6 +272,16 @@ bool MapRendererAdventureContext::showBlocked() const
return settingShowBlocked; return settingShowBlocked;
} }
bool MapRendererAdventureContext::showSpellRange(const int3 & position) const
{
if (!settingSpellRange)
return false;
auto hero = adventureInt->curHero();
return !isInScreenRange(hero->getSightCenter(), position);
}
MapRendererAdventureTransitionContext::MapRendererAdventureTransitionContext(const MapRendererContextState & viewState) MapRendererAdventureTransitionContext::MapRendererAdventureTransitionContext(const MapRendererContextState & viewState)
: MapRendererAdventureContext(viewState) : MapRendererAdventureContext(viewState)
{ {

View File

@ -58,6 +58,7 @@ public:
bool showGrid() const override; bool showGrid() const override;
bool showVisitable() const override; bool showVisitable() const override;
bool showBlocked() const override; bool showBlocked() const override;
bool showSpellRange(const int3 & position) const override;
}; };
class MapRendererAdventureContext : public MapRendererBaseContext class MapRendererAdventureContext : public MapRendererBaseContext
@ -67,6 +68,7 @@ public:
bool settingShowGrid = false; bool settingShowGrid = false;
bool settingShowVisitable = false; bool settingShowVisitable = false;
bool settingShowBlocked = false; bool settingShowBlocked = false;
bool settingSpellRange= false;
bool settingsAdventureObjectAnimation = true; bool settingsAdventureObjectAnimation = true;
bool settingsAdventureTerrainAnimation = true; bool settingsAdventureTerrainAnimation = true;
@ -80,6 +82,8 @@ public:
bool showGrid() const override; bool showGrid() const override;
bool showVisitable() const override; bool showVisitable() const override;
bool showBlocked() const override; bool showBlocked() const override;
bool showSpellRange(const int3 & position) const override;
}; };
class MapRendererAdventureTransitionContext : public MapRendererAdventureContext class MapRendererAdventureTransitionContext : public MapRendererAdventureContext

View File

@ -154,6 +154,7 @@ void MapViewController::updateBefore(uint32_t timeDelta)
adventureContext->settingShowGrid = settings["gameTweaks"]["showGrid"].Bool(); adventureContext->settingShowGrid = settings["gameTweaks"]["showGrid"].Bool();
adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool(); adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool();
adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool(); adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool();
adventureContext->settingSpellRange = settings["session"]["showSpellRange"].Bool();
} }
} }