1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Grail digging check is now in library

This commit is contained in:
Ivan Savenko
2023-02-22 17:24:42 +02:00
parent d21c41e436
commit 5905dd6111
11 changed files with 41 additions and 33 deletions

View File

@@ -1901,11 +1901,8 @@ void CPlayerInterface::acceptTurn()
void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
{
int msgToShow = -1;
const bool isBlocked = CGI->mh->hasObjectHole(h->visitablePos()); // Don't dig in the pit.
const auto diggingStatus = isBlocked
? EDiggingStatus::TILE_OCCUPIED
: h->diggingStatus().num;
const auto diggingStatus = h->diggingStatus();
switch(diggingStatus)
{

View File

@@ -67,8 +67,8 @@ public:
/// returns animation frame for terrain
virtual size_t terrainImageIndex(size_t groupSize) const = 0;
// /// returns size of ouput tile, in pixels. 32x32 for "standard" map, may be smaller for world view mode
// virtual Point getTileSize() const = 0;
/// if true, rendered images will be converted to grayscale
virtual bool filterGrayscale() const = 0;
/// if true, world view overlay will be shown
virtual bool showOverlay() const = 0;

View File

@@ -83,18 +83,6 @@ void CMapHandler::waitForOngoingAnimations()
}
}
bool CMapHandler::hasObjectHole(const int3 & pos) const
{
//const TerrainTile2 & tt = ttiles[pos.z][pos.x][pos.y];
//for(auto & elem : tt.objects)
//{
// if(elem.obj && elem.obj->ID == Obj::HOLE)
// return true;
//}
return false;
}
void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const
{
const TerrainTile & t = map->getTile(pos);

View File

@@ -73,9 +73,6 @@ public:
/// returns list of ambient sounds for specified tile
std::vector<std::string> getAmbientSounds(const int3 & tile);
/// returns true if tile has hole from grail digging attempt
bool hasObjectHole(const int3 & pos) const;
/// determines if the map is ready to handle new hero movement (not available during fading animations)
bool hasOngoingAnimations();

View File

@@ -11,6 +11,7 @@
#include "Canvas.h"
#include "../renderSDL/SDL_Extensions.h"
#include "Colors.h"
#include "IImage.h"
#include "Graphics.h"
@@ -40,9 +41,23 @@ Canvas::Canvas(const Point & size):
renderArea(Point(0,0), size),
surface(CSDL_Ext::newSurface(size.x, size.y))
{
CSDL_Ext::fillSurface(surface, Colors::TRANSPARENCY );
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
}
void Canvas::applyTransparency(bool on)
{
if (on)
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
else
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
}
void Canvas::applyGrayscale()
{
CSDL_Ext::convertToGrayscale(surface, renderArea);
}
Canvas::~Canvas()
{
SDL_FreeSurface(surface);

View File

@@ -44,6 +44,12 @@ public:
~Canvas();
/// if set to true, drawing this canvas onto another canvas will use alpha channel information
void applyTransparency(bool on);
/// applies grayscale filter onto current image
void applyGrayscale();
/// renders image onto this canvas at specified position
void draw(const std::shared_ptr<IImage>& image, const Point & pos);

View File

@@ -631,8 +631,8 @@ void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect )
for(int yp = rect.top(); yp < rect.bottom(); ++yp)
{
uint8_t * pixel_from = pixels + rect.top() * surf->pitch + rect.left() * surf->format->BytesPerPixel;
uint8_t * pixel_dest = pixels + rect.top() * surf->pitch + rect.right() * surf->format->BytesPerPixel;
uint8_t * pixel_from = pixels + yp * surf->pitch + rect.left() * surf->format->BytesPerPixel;
uint8_t * pixel_dest = pixels + yp * surf->pitch + rect.right() * surf->format->BytesPerPixel;
for (uint8_t * pixel = pixel_from; pixel < pixel_dest; pixel += surf->format->BytesPerPixel)
{

View File

@@ -504,6 +504,19 @@ const TerrainTile * CGameInfoCallback::getTile( int3 tile, bool verbose) const
return nullptr;
}
EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) const
{
if(!isVisible(tile))
return EDiggingStatus::UNKNOWN;
for(const auto & object : gs->map->objects)
{
if(object && object->ID == Obj::HOLE && object->pos == tile)
return EDiggingStatus::TILE_OCCUPIED;
}
return getTile(tile)->getDiggingStatus();
}
//TODO: typedef?
std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const
{

View File

@@ -197,6 +197,7 @@ public:
virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
virtual void calculatePaths(std::shared_ptr<PathfinderConfig> config);
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out);
virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;
//town
virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;

View File

@@ -1135,7 +1135,7 @@ EDiggingStatus CGHeroInstance::diggingStatus() const
if(static_cast<int>(movement) < maxMovePoints(true))
return EDiggingStatus::LACK_OF_MOVEMENT;
return cb->getTile(visitablePos())->getDiggingStatus();
return cb->getTileDigStatus(visitablePos());
}
ArtBearer::ArtBearer CGHeroInstance::bearerType() const

View File

@@ -6032,15 +6032,6 @@ void CGameHandler::getVictoryLossMessage(PlayerColor player, const EVictoryLossC
bool CGameHandler::dig(const CGHeroInstance *h)
{
for (auto i = gs->map->objects.cbegin(); i != gs->map->objects.cend(); i++) //unflag objs
{
if (*i && (*i)->ID == Obj::HOLE && (*i)->pos == h->visitablePos())
{
complain("Cannot dig - there is already a hole under the hero!");
return false;
}
}
if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement
COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus());