2014-05-16 19:22:21 +02:00
|
|
|
/*
|
|
|
|
* mapHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-12-13 21:23:17 +00:00
|
|
|
#include "StdInc.h"
|
2009-02-02 13:05:19 +00:00
|
|
|
#include "mapHandler.h"
|
2023-02-20 22:16:50 +02:00
|
|
|
#include "IMapRendererObserver.h"
|
2011-12-13 21:23:17 +00:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../CGameInfo.h"
|
2023-02-14 23:49:12 +02:00
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
|
2023-02-18 17:37:09 +02:00
|
|
|
#include "../../lib/UnlockGuard.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
#include "../../lib/mapObjects/CObjectClassesHandler.h"
|
|
|
|
#include "../../lib/mapping/CMap.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/TerrainHandler.h"
|
2009-04-15 14:03:31 +00:00
|
|
|
|
2023-02-16 21:35:15 +02:00
|
|
|
/*
|
2023-02-10 16:50:05 +02:00
|
|
|
void CMapPuzzleViewBlitter::drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
|
2015-01-19 20:08:19 +01:00
|
|
|
{
|
|
|
|
CMapBlitter::drawObjects(targetSurf, tile);
|
|
|
|
|
|
|
|
// grail X mark
|
|
|
|
if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
|
|
|
|
{
|
2018-03-30 14:02:04 +03:00
|
|
|
const auto mark = graphics->heroMoveArrows->getImage(0);
|
2016-10-18 10:31:31 +03:00
|
|
|
mark->draw(targetSurf,realTileRect.x,realTileRect.y);
|
2015-01-19 20:08:19 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 21:35:15 +02:00
|
|
|
*/
|
|
|
|
/*
|
2023-02-10 16:50:05 +02:00
|
|
|
void CMapPuzzleViewBlitter::postProcessing(SDL_Surface * targetSurf) const
|
2015-01-19 20:08:19 +01:00
|
|
|
{
|
|
|
|
CSDL_Ext::applyEffect(targetSurf, info->drawBounds, static_cast<int>(!ADVOPT.puzzleSepia));
|
|
|
|
}
|
2023-02-16 21:35:15 +02:00
|
|
|
*/
|
|
|
|
/*
|
2023-02-10 16:50:05 +02:00
|
|
|
bool CMapPuzzleViewBlitter::canDrawObject(const CGObjectInstance * obj) const
|
2015-01-19 20:08:19 +01:00
|
|
|
{
|
|
|
|
if (!CMapBlitter::canDrawObject(obj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//don't print flaggable objects in puzzle mode
|
|
|
|
if (obj->isVisitable())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(std::find(unblittableObjects.begin(), unblittableObjects.end(), obj->ID) != unblittableObjects.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-02-16 21:35:15 +02:00
|
|
|
*/
|
|
|
|
/*
|
2023-02-10 16:50:05 +02:00
|
|
|
CMapPuzzleViewBlitter::CMapPuzzleViewBlitter(CMapHandler * parent)
|
2015-01-19 20:08:19 +01:00
|
|
|
: CMapNormalBlitter(parent)
|
|
|
|
{
|
|
|
|
unblittableObjects.push_back(Obj::HOLE);
|
|
|
|
}
|
2023-02-16 21:35:15 +02:00
|
|
|
*/
|
2015-01-19 20:08:19 +01:00
|
|
|
|
2023-02-18 17:37:09 +02:00
|
|
|
bool CMapHandler::hasOngoingAnimations()
|
2016-11-08 00:15:46 +03:00
|
|
|
{
|
2023-02-18 17:37:09 +02:00
|
|
|
for (auto * observer : observers)
|
|
|
|
if (observer->hasOngoingAnimations())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::waitForOngoingAnimations()
|
|
|
|
{
|
|
|
|
while (CGI->mh->hasOngoingAnimations())
|
|
|
|
{
|
|
|
|
auto unlockPim = vstd::makeUnlockGuard(*CPlayerInterface::pim);
|
|
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
|
|
|
}
|
2016-11-08 00:15:46 +03:00
|
|
|
}
|
2023-02-18 17:37:09 +02:00
|
|
|
|
2021-11-06 00:08:48 +03:00
|
|
|
bool CMapHandler::hasObjectHole(const int3 & pos) const
|
2010-02-21 15:03:30 +00:00
|
|
|
{
|
2023-02-16 21:35:15 +02:00
|
|
|
//const TerrainTile2 & tt = ttiles[pos.z][pos.x][pos.y];
|
2021-11-06 00:08:48 +03:00
|
|
|
|
2023-02-16 21:35:15 +02:00
|
|
|
//for(auto & elem : tt.objects)
|
|
|
|
//{
|
|
|
|
// if(elem.obj && elem.obj->ID == Obj::HOLE)
|
|
|
|
// return true;
|
|
|
|
//}
|
2021-11-06 00:08:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const
|
|
|
|
{
|
|
|
|
const TerrainTile & t = map->getTile(pos);
|
2010-02-21 15:03:30 +00:00
|
|
|
|
2015-12-06 02:23:41 +03:00
|
|
|
if(t.hasFavorableWinds())
|
2021-11-06 00:08:48 +03:00
|
|
|
{
|
2022-12-31 15:01:19 +02:00
|
|
|
out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS, 0);
|
2021-11-06 00:08:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2023-02-16 21:35:15 +02:00
|
|
|
//const TerrainTile2 & tt = ttiles[pos.z][pos.x][pos.y];
|
2021-11-06 00:08:48 +03:00
|
|
|
bool isTile2Terrain = false;
|
|
|
|
out.clear();
|
|
|
|
|
2023-02-16 21:35:15 +02:00
|
|
|
//for(auto & elem : tt.objects)
|
|
|
|
//{
|
|
|
|
// if(elem.obj)
|
|
|
|
// {
|
|
|
|
// out = elem.obj->getObjectName();
|
|
|
|
// if(elem.obj->ID == Obj::HOLE)
|
|
|
|
// return;
|
2021-11-06 00:08:48 +03:00
|
|
|
|
2023-02-16 21:35:15 +02:00
|
|
|
// isTile2Terrain = elem.obj->isTile2Terrain();
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//}
|
2022-12-20 16:14:06 +02:00
|
|
|
|
2022-12-20 18:35:40 +02:00
|
|
|
if(!isTile2Terrain || out.empty())
|
2023-01-01 18:05:09 +02:00
|
|
|
out = t.terType->getNameTranslated();
|
2021-11-06 00:08:48 +03:00
|
|
|
|
|
|
|
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
|
|
|
|
{
|
|
|
|
out = boost::str(boost::format(isRMB ? "%s\r\n%s" : "%s %s") // New line for the Message Box, space for the Status Bar
|
|
|
|
% out
|
|
|
|
% CGI->generaltexth->allTexts[330]); // 'digging ok'
|
|
|
|
}
|
2010-02-21 15:03:30 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 02:26:36 +03:00
|
|
|
bool CMapHandler::compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b)
|
|
|
|
{
|
2015-02-20 23:19:16 +01:00
|
|
|
if (!a)
|
|
|
|
return true;
|
|
|
|
if (!b)
|
|
|
|
return false;
|
2022-09-11 15:12:35 +02:00
|
|
|
if (a->appearance->printPriority != b->appearance->printPriority)
|
|
|
|
return a->appearance->printPriority > b->appearance->printPriority;
|
2014-06-24 02:26:36 +03:00
|
|
|
|
|
|
|
if(a->pos.y != b->pos.y)
|
|
|
|
return a->pos.y < b->pos.y;
|
|
|
|
|
|
|
|
if(b->ID==Obj::HERO && a->ID!=Obj::HERO)
|
|
|
|
return true;
|
|
|
|
if(b->ID!=Obj::HERO && a->ID==Obj::HERO)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!a->isVisitable() && b->isVisitable())
|
|
|
|
return true;
|
|
|
|
if(!b->isVisitable() && a->isVisitable())
|
|
|
|
return false;
|
|
|
|
if(a->pos.x < b->pos.x)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-19 20:08:19 +01:00
|
|
|
|
2023-02-16 21:35:15 +02:00
|
|
|
CMapHandler::CMapHandler(const CMap * map)
|
|
|
|
: map(map)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const CMap * CMapHandler::getMap()
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapHandler::isInMap( const int3 & tile)
|
|
|
|
{
|
|
|
|
return map->isInTheMap(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> CMapHandler::getAmbientSounds(const int3 & tile)
|
|
|
|
{
|
|
|
|
std::vector<std::string> result;
|
|
|
|
|
|
|
|
//for(auto & ttObj : ttiles[tile.z][tile.x][tile.y].objects)
|
|
|
|
//{
|
|
|
|
// if(ttObj.ambientSound)
|
|
|
|
// result.push_back(ttObj.ambientSound.get());
|
|
|
|
//}
|
|
|
|
if(map->isCoastalTile(tile))
|
|
|
|
result.emplace_back("LOOPOCEA");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onObjectFadeIn(const CGObjectInstance * obj)
|
|
|
|
{
|
2023-02-18 17:37:09 +02:00
|
|
|
for (auto * observer : observers)
|
|
|
|
observer->onObjectFadeIn(obj);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onObjectFadeOut(const CGObjectInstance * obj)
|
|
|
|
{
|
2023-02-18 17:37:09 +02:00
|
|
|
for (auto * observer : observers)
|
|
|
|
observer->onObjectFadeOut(obj);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onObjectInstantAdd(const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
for (auto * observer : observers)
|
2023-02-18 17:37:09 +02:00
|
|
|
observer->onObjectInstantAdd(obj);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onObjectInstantRemove(const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
for (auto * observer : observers)
|
2023-02-18 17:37:09 +02:00
|
|
|
observer->onObjectInstantRemove(obj);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
|
|
|
|
{
|
|
|
|
assert(obj->pos == dest);
|
2023-02-18 17:37:09 +02:00
|
|
|
for (auto * observer : observers)
|
|
|
|
observer->onHeroTeleported(obj, from, dest);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
|
|
|
|
{
|
|
|
|
assert(obj->pos == dest);
|
2023-02-18 17:37:09 +02:00
|
|
|
for (auto * observer : observers)
|
|
|
|
observer->onHeroMoved(obj, from, dest);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::onHeroRotated(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
|
|
|
|
{
|
2023-02-18 17:37:09 +02:00
|
|
|
assert(obj->pos == from);
|
|
|
|
for (auto * observer : observers)
|
|
|
|
observer->onHeroRotated(obj, from, dest);
|
2023-02-16 21:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::addMapObserver(IMapObjectObserver * object)
|
|
|
|
{
|
|
|
|
observers.push_back(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::removeMapObserver(IMapObjectObserver * object)
|
|
|
|
{
|
|
|
|
vstd::erase(observers, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMapObjectObserver::IMapObjectObserver()
|
|
|
|
{
|
|
|
|
CGI->mh->addMapObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMapObjectObserver::~IMapObjectObserver()
|
|
|
|
{
|
|
|
|
CGI->mh->removeMapObserver(this);
|
|
|
|
}
|