1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/lib/mapObjects/IObjectInterface.cpp

160 lines
3.7 KiB
C++
Raw Normal View History

/*
* IObjectInterface.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
*
*/
#include "StdInc.h"
#include "IObjectInterface.h"
#include "CGTownInstance.h"
#include "MiscObjects.h"
#include "../IGameCallback.h"
#include "../TerrainHandler.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../networkPacks/PacksForClient.h"
VCMI_LIB_NAMESPACE_BEGIN
void IObjectInterface::showInfoDialog(const ui32 txtID, const ui16 soundID, EInfoWindowMode mode) const
{
InfoWindow iw;
iw.soundID = soundID;
iw.player = getOwner();
iw.type = mode;
iw.text.appendLocalString(EMetaText::ADVOB_TXT,txtID);
2024-01-01 16:37:48 +02:00
cb->sendAndApply(&iw);
}
///IObjectInterface
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{}
void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
{}
void IObjectInterface::newTurn(CRandomGenerator & rand) const
{}
void IObjectInterface::initObj(CRandomGenerator & rand)
{}
2023-10-25 20:56:00 +02:00
void IObjectInterface::pickRandomObject(CRandomGenerator & rand)
{}
void IObjectInterface::setProperty(ObjProperty what, ObjPropertyID identifier)
{}
bool IObjectInterface::wasVisited (PlayerColor player) const
{
return false;
}
bool IObjectInterface::wasVisited (const CGHeroInstance * h) const
{
return false;
}
void IObjectInterface::postInit()
{}
void IObjectInterface::preInit()
{}
void IObjectInterface::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
{}
void IObjectInterface::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
{}
void IObjectInterface::garrisonDialogClosed(const CGHeroInstance *hero) const
{}
void IObjectInterface::heroLevelUpDone(const CGHeroInstance *hero) const
{}
int3 IBoatGenerator::bestLocation() const
{
std::vector<int3> offsets;
getOutOffsets(offsets);
for (auto & offset : offsets)
{
2023-06-20 22:09:11 +02:00
int3 targetTile = getObject()->visitablePos() + offset;
const TerrainTile *tile = getObject()->cb->getTile(targetTile, false);
if(!tile)
continue; // tile not visible / outside the map
if(!tile->terType->isWater())
continue;
if (tile->blocked)
{
bool hasBoat = false;
for (auto const * object : tile->blockingObjects)
if (object->ID == Obj::BOAT || object->ID == Obj::HERO)
hasBoat = true;
if (!hasBoat)
continue; // tile is blocked, but not by boat -> check next potential position
}
return targetTile;
}
return int3 (-1,-1,-1);
}
IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const
{
int3 tile = bestLocation();
if(!tile.valid())
return TILE_BLOCKED; //no available water
2024-01-01 16:37:48 +02:00
const TerrainTile *t = getObject()->cb->getTile(tile);
if(!t)
return TILE_BLOCKED; //no available water
2023-06-07 00:55:21 +02:00
if(t->blockingObjects.empty())
return GOOD; //OK
if(t->blockingObjects.front()->ID == Obj::BOAT || t->blockingObjects.front()->ID == Obj::HERO)
2023-06-07 00:55:21 +02:00
return BOAT_ALREADY_BUILT; //blocked with boat
2023-06-07 00:55:21 +02:00
return TILE_BLOCKED; //blocked
}
void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visitor) const
{
switch(shipyardStatus())
{
case BOAT_ALREADY_BUILT:
out.appendLocalString(EMetaText::GENERAL_TXT, 51);
break;
case TILE_BLOCKED:
if(visitor)
{
out.appendLocalString(EMetaText::GENERAL_TXT, 134);
out.replaceRawString(visitor->getNameTranslated());
}
else
out.appendLocalString(EMetaText::ADVOB_TXT, 189);
break;
case NO_WATER:
2023-06-07 00:55:21 +02:00
logGlobal->error("Shipyard without water at tile %s! ", getObject()->getPosition().toString());
return;
}
}
void IShipyard::getBoatCost(TResources & cost) const
{
cost[EGameResID::WOOD] = 10;
cost[EGameResID::GOLD] = 1000;
}
VCMI_LIB_NAMESPACE_END