2014-04-19 20:44:21 +03:00
|
|
|
/*
|
2014-04-20 11:58:58 +03:00
|
|
|
* CGameInfoCallback.cpp, part of VCMI engine
|
2014-04-19 20:44:21 +03:00
|
|
|
*
|
|
|
|
* 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"
|
2014-04-20 11:58:58 +03:00
|
|
|
#include "CGameInfoCallback.h"
|
2014-04-19 20:44:21 +03:00
|
|
|
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "gameState/CGameState.h"
|
|
|
|
#include "gameState/InfoAboutArmy.h"
|
2023-06-26 16:25:29 +02:00
|
|
|
#include "gameState/SThievesGuildInfo.h"
|
2023-07-11 14:16:02 +02:00
|
|
|
#include "gameState/TavernHeroesPool.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "gameState/QuestInfo.h"
|
|
|
|
#include "mapObjects/CGHeroInstance.h"
|
2024-01-09 16:43:36 +02:00
|
|
|
#include "mapObjects/CGTownInstance.h"
|
|
|
|
#include "mapObjects/MiscObjects.h"
|
2023-10-24 16:32:09 +02:00
|
|
|
#include "networkPacks/ArtifactLocation.h"
|
2015-11-30 19:52:15 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2014-04-20 10:13:37 +03:00
|
|
|
#include "StartInfo.h" // for StartInfo
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "battle/BattleInfo.h" // for BattleInfo
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "GameSettings.h"
|
2023-01-09 01:17:37 +02:00
|
|
|
#include "TerrainHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "spells/CSpellHandler.h"
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "mapping/CMap.h"
|
2015-12-02 21:39:53 +02:00
|
|
|
#include "CPlayerState.h"
|
2014-04-19 20:44:21 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
//TODO make clean
|
2017-08-11 19:03:05 +02:00
|
|
|
#define ERROR_VERBOSE_OR_NOT_RET_VAL_IF(cond, verbose, txt, retVal) do {if(cond){if(verbose)logGlobal->error("%s: %s",BOOST_CURRENT_FUNCTION, txt); return retVal;}} while(0)
|
|
|
|
#define ERROR_RET_IF(cond, txt) do {if(cond){logGlobal->error("%s: %s", BOOST_CURRENT_FUNCTION, txt); return;}} while(0)
|
|
|
|
#define ERROR_RET_VAL_IF(cond, txt, retVal) do {if(cond){logGlobal->error("%s: %s", BOOST_CURRENT_FUNCTION, txt); return retVal;}} while(0)
|
2014-04-19 20:44:21 +03:00
|
|
|
|
|
|
|
PlayerColor CGameInfoCallback::getOwner(ObjectInstanceID heroID) const
|
|
|
|
{
|
|
|
|
const CGObjectInstance *obj = getObj(heroID);
|
|
|
|
ERROR_RET_VAL_IF(!obj, "No such object!", PlayerColor::CANNOT_DETERMINE);
|
|
|
|
return obj->tempOwner;
|
|
|
|
}
|
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
int CGameInfoCallback::getResource(PlayerColor Player, GameResID which) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const PlayerState *p = getPlayerState(Player);
|
2014-04-19 20:44:21 +03:00
|
|
|
ERROR_RET_VAL_IF(!p, "No player info!", -1);
|
2023-08-18 12:38:19 +02:00
|
|
|
ERROR_RET_VAL_IF(p->resources.size() <= which.getNum() || which.getNum() < 0, "No such resource!", -1);
|
2014-04-19 20:44:21 +03:00
|
|
|
return p->resources[which];
|
|
|
|
}
|
|
|
|
|
|
|
|
const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) const
|
|
|
|
{
|
|
|
|
return &gs->scenarioOps->getIthPlayersSettings(color);
|
|
|
|
}
|
|
|
|
|
2023-11-05 15:24:26 +02:00
|
|
|
bool CGameInfoCallback::isAllowed(SpellID id) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-11-05 15:24:26 +02:00
|
|
|
return gs->map->allowedSpells.count(id) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isAllowed(ArtifactID id) const
|
|
|
|
{
|
|
|
|
return gs->map->allowedArtifact.count(id) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isAllowed(SecondarySkill id) const
|
|
|
|
{
|
|
|
|
return gs->map->allowedAbilities.count(id) != 0;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
std::optional<PlayerColor> CGameInfoCallback::getPlayerID() const
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const Player * CGameInfoCallback::getPlayer(PlayerColor color) const
|
|
|
|
{
|
|
|
|
return getPlayerState(color, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PlayerState * CGameInfoCallback::getPlayerState(PlayerColor color, bool verbose) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2015-08-30 20:51:22 +02:00
|
|
|
//funtion written from scratch since it's accessed A LOT by AI
|
|
|
|
|
2016-01-27 12:47:42 +02:00
|
|
|
if(!color.isValidPlayer())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-08-30 20:51:22 +02:00
|
|
|
auto player = gs->players.find(color);
|
|
|
|
if (player != gs->players.end())
|
|
|
|
{
|
|
|
|
if (hasAccess(color))
|
|
|
|
return &player->second;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (verbose)
|
2016-08-12 18:20:57 +02:00
|
|
|
logGlobal->error("Cannot access player %d info!", color);
|
2015-08-30 20:51:22 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (verbose)
|
2016-08-12 18:20:57 +02:00
|
|
|
logGlobal->error("Cannot find player %d info!", color);
|
2015-08-30 20:51:22 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-08-14 00:16:25 +02:00
|
|
|
TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
|
2023-08-13 12:06:35 +02:00
|
|
|
{
|
|
|
|
if(!color.isValidPlayer())
|
|
|
|
{
|
2023-08-14 00:16:25 +02:00
|
|
|
return TurnTimerInfo{};
|
2023-08-13 12:06:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto player = gs->players.find(color);
|
|
|
|
if(player != gs->players.end())
|
|
|
|
{
|
2023-08-14 00:16:25 +02:00
|
|
|
return player->second.turnTimer;
|
2023-08-13 12:06:35 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 00:16:25 +02:00
|
|
|
return TurnTimerInfo{};
|
2023-08-13 12:06:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
/************************************************************************/
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
const CGObjectInstance* CGameInfoCallback::getObj(ObjectInstanceID objid, bool verbose) const
|
|
|
|
{
|
|
|
|
si32 oid = objid.num;
|
|
|
|
if(oid < 0 || oid >= gs->map->objects.size())
|
|
|
|
{
|
|
|
|
if(verbose)
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("Cannot get object with id %d", oid);
|
2014-04-19 20:44:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGObjectInstance *ret = gs->map->objects[oid];
|
|
|
|
if(!ret)
|
|
|
|
{
|
|
|
|
if(verbose)
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("Cannot get object with id %d. Object was removed", oid);
|
2014-04-19 20:44:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
if(!isVisible(ret, getPlayerID()) && ret->tempOwner != getPlayerID())
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
if(verbose)
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("Cannot get object with id %d. Object is not visible.", oid);
|
2014-04-19 20:44:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance* CGameInfoCallback::getHero(ObjectInstanceID objid) const
|
|
|
|
{
|
|
|
|
const CGObjectInstance *obj = getObj(objid, false);
|
|
|
|
if(obj)
|
|
|
|
return dynamic_cast<const CGHeroInstance*>(obj);
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const CGTownInstance* CGameInfoCallback::getTown(ObjectInstanceID objid) const
|
|
|
|
{
|
|
|
|
const CGObjectInstance *obj = getObj(objid, false);
|
|
|
|
if(obj)
|
|
|
|
return dynamic_cast<const CGTownInstance*>(obj);
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-12-25 14:03:43 +02:00
|
|
|
void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
|
|
|
|
ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
|
2022-12-25 14:03:43 +02:00
|
|
|
gs->fillUpgradeInfo(obj, stackPos, out);
|
|
|
|
//return gs->fillUpgradeInfo(obj->getStack(stackPos));
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
if(beforeRandomization)
|
|
|
|
return gs->initialOpts;
|
|
|
|
else
|
|
|
|
return gs->scenarioOps;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
|
|
|
|
//if there is a battle
|
2023-08-25 17:23:15 +02:00
|
|
|
auto casterBattle = gs->getBattle(caster->getOwner());
|
|
|
|
|
|
|
|
if(casterBattle)
|
|
|
|
return casterBattle->battleGetSpellCost(sp, caster);
|
2014-04-19 20:44:21 +03:00
|
|
|
|
|
|
|
//if there is no battle
|
|
|
|
return caster->getSpellCost(sp);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
|
|
|
|
ERROR_RET_VAL_IF(hero && !canGetFullInfo(hero), "Cannot get info about caster!", -1);
|
2014-11-13 14:16:27 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(hero) //we see hero's spellbook
|
|
|
|
return sp->calculateDamage(hero);
|
2014-11-13 14:16:27 +02:00
|
|
|
else
|
|
|
|
return 0; //mage guild
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
ERROR_RET_IF(!obj, "No guild object!");
|
|
|
|
ERROR_RET_IF(obj->ID == Obj::TOWN && !canGetFullInfo(obj), "Cannot get info about town guild object!");
|
|
|
|
//TODO: advmap object -> check if they're visited by our hero
|
|
|
|
|
|
|
|
if(obj->ID == Obj::TOWN || obj->ID == Obj::TAVERN)
|
|
|
|
{
|
2015-12-04 17:38:57 +02:00
|
|
|
int taverns = 0;
|
2023-08-30 21:07:02 +02:00
|
|
|
for(auto town : gs->players[*getPlayerID()].towns)
|
2015-12-04 17:38:57 +02:00
|
|
|
{
|
|
|
|
if(town->hasBuilt(BuildingID::TAVERN))
|
|
|
|
taverns++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gs->obtainPlayersStats(thi, taverns);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
else if(obj->ID == Obj::DEN_OF_THIEVES)
|
|
|
|
{
|
|
|
|
gs->obtainPlayersStats(thi, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CGameInfoCallback::howManyTowns(PlayerColor Player) const
|
|
|
|
{
|
|
|
|
ERROR_RET_VAL_IF(!hasAccess(Player), "Access forbidden!", -1);
|
2020-10-01 10:38:06 +02:00
|
|
|
return static_cast<int>(gs->players[Player].towns.size());
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
ERROR_RET_VAL_IF(!isVisible(town, getPlayerID()), "Town is not visible!", false); //it's not a town or it's not visible for layer
|
2014-04-19 20:44:21 +03:00
|
|
|
bool detailed = hasAccess(town->tempOwner);
|
|
|
|
|
|
|
|
if(town->ID == Obj::TOWN)
|
2015-02-06 16:36:09 +02:00
|
|
|
{
|
|
|
|
if(!detailed && nullptr != selectedObject)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
2015-02-06 16:36:09 +02:00
|
|
|
if(nullptr != selectedHero)
|
2023-10-21 13:50:42 +02:00
|
|
|
detailed = selectedHero->hasVisions(town, BonusCustomSubtype::visionsTowns);
|
2015-02-06 16:36:09 +02:00
|
|
|
}
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
dest.initFromTown(dynamic_cast<const CGTownInstance *>(town), detailed);
|
2016-01-27 12:47:42 +02:00
|
|
|
}
|
2014-04-19 20:44:21 +03:00
|
|
|
else if(town->ID == Obj::GARRISON || town->ID == Obj::GARRISON2)
|
2023-03-13 23:26:44 +02:00
|
|
|
dest.initFromArmy(dynamic_cast<const CArmedInstance *>(town), detailed);
|
2014-04-19 20:44:21 +03:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const //FIXME: redundant?
|
|
|
|
{
|
|
|
|
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", int3(-1,-1,-1));
|
|
|
|
return gs->guardingCreaturePosition(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (int3 pos) const
|
|
|
|
{
|
|
|
|
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", std::vector<const CGObjectInstance*>());
|
|
|
|
std::vector<const CGObjectInstance*> ret;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(auto * cr : gs->guardingCreatures(pos))
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ret.push_back(cr);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool CGameInfoCallback::isTileGuardedUnchecked(int3 tile) const
|
2024-04-01 20:18:35 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
return !gs->guardingCreatures(tile).empty();
|
2024-04-01 20:18:35 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * h = dynamic_cast<const CGHeroInstance *>(hero);
|
2014-04-19 20:44:21 +03:00
|
|
|
|
|
|
|
ERROR_RET_VAL_IF(!h, "That's not a hero!", false);
|
|
|
|
|
2016-09-28 13:22:33 +02:00
|
|
|
InfoAboutHero::EInfoLevel infoLevel = InfoAboutHero::EInfoLevel::BASIC;
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2016-09-28 13:22:33 +02:00
|
|
|
if(hasAccess(h->tempOwner))
|
|
|
|
infoLevel = InfoAboutHero::EInfoLevel::DETAILED;
|
|
|
|
|
2016-12-10 14:34:58 +02:00
|
|
|
if (infoLevel == InfoAboutHero::EInfoLevel::BASIC)
|
2016-09-27 13:48:04 +02:00
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
auto ourBattle = gs->getBattle(*getPlayerID());
|
2023-08-25 17:23:15 +02:00
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
if(ourBattle && ourBattle->playerHasAccessToHeroInfo(*getPlayerID(), h)) //if it's battle we can get enemy hero full data
|
2016-09-28 13:22:33 +02:00
|
|
|
infoLevel = InfoAboutHero::EInfoLevel::INBATTLE;
|
2016-12-10 14:34:58 +02:00
|
|
|
else
|
2022-12-07 22:10:08 +02:00
|
|
|
ERROR_RET_VAL_IF(!isVisible(h->visitablePos()), "That hero is not visible!", false);
|
2017-08-11 19:03:05 +02:00
|
|
|
}
|
2016-09-27 13:48:04 +02:00
|
|
|
|
2016-09-28 13:22:33 +02:00
|
|
|
if( (infoLevel == InfoAboutHero::EInfoLevel::BASIC) && nullptr != selectedObject)
|
2015-02-06 16:36:09 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
2015-02-06 16:36:09 +02:00
|
|
|
if(nullptr != selectedHero)
|
2023-10-21 13:50:42 +02:00
|
|
|
if(selectedHero->hasVisions(hero, BonusCustomSubtype::visionsHeroes))
|
2016-09-28 13:22:33 +02:00
|
|
|
infoLevel = InfoAboutHero::EInfoLevel::DETAILED;
|
2015-02-06 16:36:09 +02:00
|
|
|
}
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2016-09-28 13:22:33 +02:00
|
|
|
dest.initFromHero(h, infoLevel);
|
2016-09-28 00:20:45 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
//DISGUISED bonus implementation
|
2023-08-30 21:07:02 +02:00
|
|
|
if(getPlayerRelations(*getPlayerID(), hero->tempOwner) == PlayerRelations::ENEMIES)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
2016-01-27 12:47:42 +02:00
|
|
|
//todo: bonus cashing
|
2023-10-05 15:13:52 +02:00
|
|
|
int disguiseLevel = h->valOfBonuses(BonusType::DISGUISED);
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2019-01-19 12:52:02 +02:00
|
|
|
auto doBasicDisguise = [](InfoAboutHero & info)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
|
|
|
int maxAIValue = 0;
|
|
|
|
const CCreature * mostStrong = nullptr;
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
for(auto & elem : info.army)
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
if(static_cast<int>(elem.second.type->getAIValue()) > maxAIValue)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
maxAIValue = elem.second.type->getAIValue();
|
2015-02-07 17:12:29 +02:00
|
|
|
mostStrong = elem.second.type;
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
if(nullptr == mostStrong)//just in case
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("CGameInfoCallback::getHeroInfo: Unable to select most strong stack");
|
2015-02-07 17:12:29 +02:00
|
|
|
else
|
|
|
|
for(auto & elem : info.army)
|
|
|
|
{
|
|
|
|
elem.second.type = mostStrong;
|
|
|
|
}
|
|
|
|
};
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2019-01-19 12:52:02 +02:00
|
|
|
auto doAdvancedDisguise = [&doBasicDisguise](InfoAboutHero & info)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
|
|
|
doBasicDisguise(info);
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
for(auto & elem : info.army)
|
|
|
|
elem.second.count = 0;
|
|
|
|
};
|
2016-01-27 12:47:42 +02:00
|
|
|
|
|
|
|
auto doExpertDisguise = [this,h](InfoAboutHero & info)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
|
|
|
for(auto & elem : info.army)
|
|
|
|
elem.second.count = 0;
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
const auto factionIndex = getStartInfo(false)->playerInfos.at(h->tempOwner).castle;
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
int maxAIValue = 0;
|
|
|
|
const CCreature * mostStrong = nullptr;
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2024-05-17 00:05:51 +02:00
|
|
|
for(const auto & creature : VLC->creh->objects)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
2023-04-09 17:26:32 +02:00
|
|
|
if(creature->getFaction() == factionIndex && static_cast<int>(creature->getAIValue()) > maxAIValue)
|
2015-02-07 17:12:29 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
maxAIValue = creature->getAIValue();
|
2023-12-31 23:43:35 +02:00
|
|
|
mostStrong = creature.get();
|
2015-02-07 17:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-27 12:47:42 +02:00
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
if(nullptr != mostStrong) //possible, faction may have no creatures at all
|
|
|
|
for(auto & elem : info.army)
|
|
|
|
elem.second.type = mostStrong;
|
2016-01-27 12:47:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-07 17:12:29 +02:00
|
|
|
switch (disguiseLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
//no bonus at all - do nothing
|
2016-01-27 12:47:42 +02:00
|
|
|
break;
|
2015-02-07 17:12:29 +02:00
|
|
|
case 1:
|
|
|
|
doBasicDisguise(dest);
|
2016-01-27 12:47:42 +02:00
|
|
|
break;
|
2015-02-07 17:12:29 +02:00
|
|
|
case 2:
|
|
|
|
doAdvancedDisguise(dest);
|
2016-01-27 12:47:42 +02:00
|
|
|
break;
|
2015-02-07 17:12:29 +02:00
|
|
|
case 3:
|
|
|
|
doExpertDisguise(dest);
|
2016-01-27 12:47:42 +02:00
|
|
|
break;
|
2015-02-07 17:12:29 +02:00
|
|
|
default:
|
|
|
|
//invalid value
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("CGameInfoCallback::getHeroInfo: Invalid DISGUISED bonus value %d", disguiseLevel);
|
2015-02-07 17:12:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-19 20:44:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-19 21:35:44 +02:00
|
|
|
int CGameInfoCallback::getDate(Date mode) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
return gs->getDate(mode);
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2022-12-30 00:11:21 +02:00
|
|
|
return gs->isVisible(pos, Player);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(int3 pos) const
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
return isVisible(pos, getPlayerID());
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
bool CGameInfoCallback::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
return gs->isVisible(obj, Player);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
return isVisible(obj, getPlayerID());
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
// const CCreatureSet* CInfoCallback::getGarrison(const CGObjectInstance *obj) const
|
|
|
|
// {
|
|
|
|
// //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
// if()
|
|
|
|
// const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
|
|
|
|
// if(!armi)
|
|
|
|
// return nullptr;
|
|
|
|
// else
|
|
|
|
// return armi;
|
|
|
|
// }
|
|
|
|
|
2024-03-27 23:06:31 +02:00
|
|
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getBlockingObjs( int3 pos ) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance *> ret;
|
|
|
|
const TerrainTile *t = getTile(pos);
|
|
|
|
ERROR_RET_VAL_IF(!t, "Not a valid tile requested!", ret);
|
|
|
|
|
|
|
|
for(const CGObjectInstance * obj : t->blockingObjects)
|
|
|
|
ret.push_back(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-27 23:06:31 +02:00
|
|
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getVisitableObjs(int3 pos, bool verbose) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance *> ret;
|
|
|
|
const TerrainTile *t = getTile(pos, verbose);
|
2017-08-11 19:03:05 +02:00
|
|
|
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!t, verbose, pos.toString() + " is not visible!", ret);
|
2014-04-19 20:44:21 +03:00
|
|
|
|
|
|
|
for(const CGObjectInstance * obj : t->visitableObjects)
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
if(getPlayerID() || obj->ID != Obj::EVENT) //hide events from players
|
2014-04-19 20:44:21 +03:00
|
|
|
ret.push_back(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
const CGObjectInstance * CGameInfoCallback::getTopObj (int3 pos) const
|
|
|
|
{
|
|
|
|
return vstd::backOrNull(getVisitableObjs(pos));
|
|
|
|
}
|
|
|
|
|
2024-03-27 23:06:31 +02:00
|
|
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getFlaggableObjects(int3 pos) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance *> ret;
|
|
|
|
const TerrainTile *t = getTile(pos);
|
|
|
|
ERROR_RET_VAL_IF(!t, "Not a valid tile requested!", ret);
|
|
|
|
for(const CGObjectInstance *obj : t->blockingObjects)
|
|
|
|
if(obj->tempOwner != PlayerColor::UNFLAGGABLE)
|
|
|
|
ret.push_back(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int3 CGameInfoCallback::getMapSize() const
|
|
|
|
{
|
|
|
|
return int3(gs->map->width, gs->map->height, gs->map->twoLevel ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const CGObjectInstance * townOrTavern) const
|
|
|
|
{
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
|
|
|
std::vector<const CGHeroInstance *> ret;
|
|
|
|
//ERROR_RET_VAL_IF(!isOwnedOrVisited(townOrTavern), "Town or tavern must be owned or visited!", ret);
|
|
|
|
//TODO: town needs to be owned, advmap tavern needs to be visited; to be reimplemented when visit tracking is done
|
2018-03-22 13:14:43 +02:00
|
|
|
const CGTownInstance * town = getTown(townOrTavern->id);
|
2023-07-11 14:16:02 +02:00
|
|
|
|
2018-03-22 13:14:43 +02:00
|
|
|
if(townOrTavern->ID == Obj::TAVERN || (town && town->hasBuilt(BuildingID::TAVERN)))
|
2023-08-30 21:07:02 +02:00
|
|
|
return gs->heroesPool->getHeroesFor(*getPlayerID());
|
2023-07-11 14:16:02 +02:00
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-25 00:58:04 +02:00
|
|
|
const TerrainTile * CGameInfoCallback::getTile(int3 tile, bool verbose) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2022-01-25 13:19:48 +02:00
|
|
|
if(isVisible(tile))
|
|
|
|
return &gs->map->getTile(tile);
|
2014-04-19 20:44:21 +03:00
|
|
|
|
2022-01-25 13:19:48 +02:00
|
|
|
if(verbose)
|
|
|
|
logGlobal->error("\r\n%s: %s\r\n", BOOST_CURRENT_FUNCTION, tile.toString() + " is not visible!");
|
|
|
|
return nullptr;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const TerrainTile * CGameInfoCallback::getTileUnchecked(int3 tile) const
|
2024-03-25 00:58:04 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
if (isInTheMap(tile))
|
|
|
|
return &gs->map->getTile(tile);
|
2024-03-25 00:58:04 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
return nullptr;
|
2024-03-25 00:58:04 +02:00
|
|
|
}
|
|
|
|
|
2023-02-22 17:24:42 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-08-31 07:39:03 +02:00
|
|
|
//TODO: typedef?
|
2022-09-18 16:39:10 +02:00
|
|
|
std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const
|
2015-08-31 07:39:03 +02:00
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
assert(getPlayerID().has_value());
|
|
|
|
const auto * team = getPlayerTeam(getPlayerID().value());
|
2015-08-31 07:39:03 +02:00
|
|
|
|
|
|
|
size_t width = gs->map->width;
|
|
|
|
size_t height = gs->map->height;
|
2022-09-18 16:39:10 +02:00
|
|
|
size_t levels = gs->map->levels();
|
2015-08-31 07:39:03 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * ptr = new boost::multi_array<TerrainTile *, 3>(boost::extents[levels][width][height]);
|
2015-08-31 07:39:03 +02:00
|
|
|
|
2022-09-18 16:39:10 +02:00
|
|
|
int3 tile;
|
|
|
|
for(tile.z = 0; tile.z < levels; tile.z++)
|
|
|
|
for(tile.x = 0; tile.x < width; tile.x++)
|
|
|
|
for(tile.y = 0; tile.y < height; tile.y++)
|
2015-08-31 07:39:03 +02:00
|
|
|
{
|
2024-05-07 21:17:05 +02:00
|
|
|
if (team->fogOfWarMap[tile.z][tile.x][tile.y])
|
2022-09-18 16:39:10 +02:00
|
|
|
(*ptr)[tile.z][tile.x][tile.y] = &gs->map->getTile(tile);
|
2015-08-31 07:39:03 +02:00
|
|
|
else
|
2022-09-18 16:39:10 +02:00
|
|
|
(*ptr)[tile.z][tile.x][tile.y] = nullptr;
|
2015-08-31 07:39:03 +02:00
|
|
|
}
|
2022-09-18 16:39:10 +02:00
|
|
|
|
|
|
|
return std::shared_ptr<const boost::multi_array<TerrainTile*, 3>>(ptr);
|
2015-08-31 07:39:03 +02:00
|
|
|
}
|
|
|
|
|
2023-08-19 21:35:44 +02:00
|
|
|
EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, BuildingID ID )
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED);
|
|
|
|
|
|
|
|
if(!t->town->buildings.count(ID))
|
|
|
|
return EBuildingState::BUILDING_ERROR;
|
|
|
|
|
|
|
|
const CBuilding * building = t->town->buildings.at(ID);
|
|
|
|
|
|
|
|
|
|
|
|
if(t->hasBuilt(ID)) //already built
|
|
|
|
return EBuildingState::ALREADY_PRESENT;
|
|
|
|
|
|
|
|
//can we build it?
|
|
|
|
if(vstd::contains(t->forbiddenBuildings, ID))
|
|
|
|
return EBuildingState::FORBIDDEN; //forbidden
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto possiblyNotBuiltTest = [&](const BuildingID & id) -> bool
|
2016-09-12 22:28:11 +02:00
|
|
|
{
|
|
|
|
return ((id == BuildingID::CAPITOL) ? true : !t->hasBuilt(id));
|
|
|
|
};
|
2016-09-10 19:38:49 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::function<bool(BuildingID id)> allowedTest = [&](const BuildingID & id) -> bool
|
2016-09-10 19:38:49 +02:00
|
|
|
{
|
2016-10-15 03:19:47 +02:00
|
|
|
return !vstd::contains(t->forbiddenBuildings, id);
|
2016-09-10 19:38:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!t->genBuildingRequirements(ID, true).satisfiable(allowedTest, possiblyNotBuiltTest))
|
|
|
|
return EBuildingState::FORBIDDEN;
|
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
if(ID == BuildingID::CAPITOL)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const PlayerState *ps = getPlayerState(t->tempOwner, false);
|
2014-04-19 20:44:21 +03:00
|
|
|
if(ps)
|
|
|
|
{
|
2018-10-29 17:56:14 +02:00
|
|
|
for(const CGTownInstance *town : ps->towns)
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2018-10-29 17:56:14 +02:00
|
|
|
if(town->hasBuilt(BuildingID::CAPITOL))
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
return EBuildingState::HAVE_CAPITAL; //no more than one capitol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(ID == BuildingID::SHIPYARD)
|
|
|
|
{
|
|
|
|
const TerrainTile *tile = getTile(t->bestLocation(), false);
|
|
|
|
|
2023-10-04 13:11:13 +02:00
|
|
|
if(!tile || !tile->terType->isWater())
|
2014-04-19 20:44:21 +03:00
|
|
|
return EBuildingState::NO_WATER; //lack of water
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto buildTest = [&](const BuildingID & id) -> bool
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2014-08-07 19:40:22 +03:00
|
|
|
return t->hasBuilt(id);
|
2014-04-19 20:44:21 +03:00
|
|
|
};
|
|
|
|
|
2014-08-07 19:40:22 +03:00
|
|
|
if (!t->genBuildingRequirements(ID).test(buildTest))
|
2014-04-19 20:44:21 +03:00
|
|
|
return EBuildingState::PREREQUIRES;
|
|
|
|
|
2023-03-15 23:47:26 +02:00
|
|
|
if(t->builded >= VLC->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP))
|
2014-07-29 10:49:50 +03:00
|
|
|
return EBuildingState::CANT_BUILD_TODAY; //building limit
|
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
//checking resources
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(!building->resources.canBeAfforded(getPlayerState(t->tempOwner)->resources))
|
2014-04-19 20:44:21 +03:00
|
|
|
return EBuildingState::NO_RESOURCES; //lack of res
|
|
|
|
|
|
|
|
return EBuildingState::ALLOWED;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CMapHeader * CGameInfoCallback::getMapHeader() const
|
|
|
|
{
|
|
|
|
return gs->map;
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
bool CGameInfoCallback::hasAccess(std::optional<PlayerColor> playerId) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
return !getPlayerID() || getPlayerID()->isSpectator() || gs->getPlayerRelations(*playerId, *getPlayerID()) != PlayerRelations::ENEMIES;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-08-19 20:43:50 +02:00
|
|
|
EPlayerStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const PlayerState *ps = gs->getPlayerState(player, verbose);
|
2014-04-19 20:44:21 +03:00
|
|
|
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!ps, verbose, "No such player!", EPlayerStatus::WRONG);
|
|
|
|
|
|
|
|
return ps->status;
|
|
|
|
}
|
|
|
|
|
2015-11-30 16:51:28 +02:00
|
|
|
std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTavern) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-09-27 23:22:45 +02:00
|
|
|
MetaString text;
|
|
|
|
text.appendLocalString(EMetaText::GENERAL_TXT, 216);
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::string extraText;
|
2015-12-06 01:51:54 +02:00
|
|
|
if(gs->rumor.type == RumorState::TYPE_NONE)
|
2023-09-27 23:22:45 +02:00
|
|
|
return text.toString();
|
2015-11-30 19:52:15 +02:00
|
|
|
|
2015-11-30 23:44:58 +02:00
|
|
|
auto rumor = gs->rumor.last[gs->rumor.type];
|
|
|
|
switch(gs->rumor.type)
|
2015-11-30 19:52:15 +02:00
|
|
|
{
|
2015-12-04 21:58:14 +02:00
|
|
|
case RumorState::TYPE_SPECIAL:
|
2023-09-27 23:22:45 +02:00
|
|
|
text.replaceLocalString(EMetaText::GENERAL_TXT, rumor.first);
|
2015-12-04 21:58:14 +02:00
|
|
|
if(rumor.first == RumorState::RUMOR_GRAIL)
|
2023-10-11 00:58:32 +02:00
|
|
|
text.replaceTextID(TextIdentifier("core", "arraytxt", 158 + rumor.second).get());
|
2015-12-01 03:57:52 +02:00
|
|
|
else
|
2023-10-11 00:58:32 +02:00
|
|
|
text.replaceTextID(TextIdentifier("core", "plcolors", rumor.second).get());
|
2015-12-01 03:57:52 +02:00
|
|
|
|
|
|
|
break;
|
2015-12-04 21:58:14 +02:00
|
|
|
case RumorState::TYPE_MAP:
|
2023-09-27 23:22:45 +02:00
|
|
|
text.replaceRawString(gs->map->rumors[rumor.first].text.toString());
|
2015-11-30 23:44:58 +02:00
|
|
|
break;
|
2015-11-30 19:52:15 +02:00
|
|
|
|
2015-12-04 21:58:14 +02:00
|
|
|
case RumorState::TYPE_RAND:
|
2023-10-11 00:58:32 +02:00
|
|
|
text.replaceTextID(TextIdentifier("core", "randtvrn", rumor.first).get());
|
2015-11-30 19:52:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-27 23:22:45 +02:00
|
|
|
return text.toString();
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-08-19 20:43:50 +02:00
|
|
|
PlayerRelations CGameInfoCallback::getPlayerRelations( PlayerColor color1, PlayerColor color2 ) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
return gs->getPlayerRelations(color1, color2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const
|
|
|
|
{
|
|
|
|
return !obj || hasAccess(obj->tempOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CGameInfoCallback::getHeroCount( PlayerColor player, bool includeGarrisoned ) const
|
|
|
|
{
|
|
|
|
int ret = 0;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const PlayerState *p = gs->getPlayerState(player);
|
2014-04-19 20:44:21 +03:00
|
|
|
ERROR_RET_VAL_IF(!p, "No such player!", -1);
|
|
|
|
|
|
|
|
if(includeGarrisoned)
|
2020-10-01 10:38:06 +02:00
|
|
|
return static_cast<int>(p->heroes.size());
|
2014-04-19 20:44:21 +03:00
|
|
|
else
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : p->heroes)
|
2014-04-19 20:44:21 +03:00
|
|
|
if(!elem->inTownGarrison)
|
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isOwnedOrVisited(const CGObjectInstance *obj) const
|
|
|
|
{
|
|
|
|
if(canGetFullInfo(obj))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const TerrainTile *t = getTile(obj->visitablePos()); //get entrance tile
|
|
|
|
const CGObjectInstance *visitor = t->visitableObjects.back(); //visitong hero if present or the obejct itself at last
|
|
|
|
return visitor->ID == Obj::HERO && canGetFullInfo(visitor); //owned or allied hero is a visitor
|
|
|
|
}
|
|
|
|
|
2023-08-25 00:08:48 +02:00
|
|
|
bool CGameInfoCallback::isPlayerMakingTurn(PlayerColor player) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
return gs->actingPlayers.count(player);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
2023-12-17 19:31:32 +02:00
|
|
|
CGameInfoCallback::CGameInfoCallback():
|
|
|
|
gs(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
CGameInfoCallback::CGameInfoCallback(CGameState * GS):
|
2023-03-13 23:26:44 +02:00
|
|
|
gs(GS)
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::howManyTowns() const
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2023-08-30 21:07:02 +02:00
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
|
return CGameInfoCallback::howManyTowns(*getPlayerID());
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(bool onlyOur) const
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2024-01-17 15:59:41 +02:00
|
|
|
auto ret = std::vector < const CGTownInstance *>();
|
2014-04-19 20:44:21 +03:00
|
|
|
for(const auto & i : gs->players)
|
|
|
|
{
|
|
|
|
for(const auto & town : i.second.towns)
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
if(i.first == getPlayerID() || (!onlyOur && isVisible(town, getPlayerID())))
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ret.push_back(town);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo(bool onlyOur) const
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
std::vector < const CGHeroInstance *> ret;
|
|
|
|
for(auto hero : gs->map->heroesOnMap)
|
|
|
|
{
|
2014-12-21 14:56:32 +02:00
|
|
|
// !player || // - why would we even get access to hero not owned by any player?
|
2023-08-30 21:07:02 +02:00
|
|
|
if((hero->tempOwner == *getPlayerID()) ||
|
|
|
|
(isVisible(hero->visitablePos(), getPlayerID()) && !onlyOur) )
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ret.push_back(hero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned) const
|
|
|
|
{
|
|
|
|
if (hero->inTownGarrison && !includeGarrisoned)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
size_t index = 0;
|
2023-08-30 21:07:02 +02:00
|
|
|
auto & heroes = gs->players[*getPlayerID()].heroes;
|
2014-04-19 20:44:21 +03:00
|
|
|
|
|
|
|
for (auto & heroe : heroes)
|
|
|
|
{
|
|
|
|
if (includeGarrisoned || !(heroe)->inTownGarrison)
|
|
|
|
index++;
|
|
|
|
|
|
|
|
if (heroe == hero)
|
2020-10-01 10:38:06 +02:00
|
|
|
return static_cast<int>(index);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-01-20 09:44:13 +02:00
|
|
|
int3 CPlayerSpecificInfoCallback::getGrailPos( double *outKnownRatio )
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2024-01-09 16:43:36 +02:00
|
|
|
if (!getPlayerID() || gs->map->obeliskCount == 0)
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
2016-01-20 09:44:13 +02:00
|
|
|
*outKnownRatio = 0.0;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
TeamID t = gs->getPlayerTeam(*getPlayerID())->id;
|
2016-08-29 22:07:52 +02:00
|
|
|
double visited = 0.0;
|
2024-01-09 16:43:36 +02:00
|
|
|
if(gs->map->obelisksVisited.count(t))
|
|
|
|
visited = static_cast<double>(gs->map->obelisksVisited[t]);
|
2016-08-29 22:07:52 +02:00
|
|
|
|
2024-01-09 16:43:36 +02:00
|
|
|
*outKnownRatio = visited / gs->map->obeliskCount;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
return gs->map->grailPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector < const CGObjectInstance * > CPlayerSpecificInfoCallback::getMyObjects() const
|
|
|
|
{
|
|
|
|
std::vector < const CGObjectInstance * > ret;
|
|
|
|
for(const CGObjectInstance * obj : gs->map->objects)
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
if(obj && obj->tempOwner == getPlayerID())
|
2014-04-19 20:44:21 +03:00
|
|
|
ret.push_back(obj);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings() const
|
|
|
|
{
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
|
|
|
std::vector < const CGDwelling * > ret;
|
2023-08-30 21:07:02 +02:00
|
|
|
for(CGDwelling * dw : gs->getPlayerState(*getPlayerID())->dwellings)
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ret.push_back(dw);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
|
|
|
|
{
|
|
|
|
std::vector <QuestInfo> ret;
|
2023-08-30 21:07:02 +02:00
|
|
|
for(const auto & quest : gs->getPlayerState(*getPlayerID())->quests)
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
ret.push_back (quest);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2023-08-30 21:07:02 +02:00
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
|
return getHeroCount(*getPlayerID(), includeGarrisoned);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId, bool includeGarrisoned) const
|
|
|
|
{
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2023-08-30 21:07:02 +02:00
|
|
|
const PlayerState *p = getPlayerState(*getPlayerID());
|
2014-04-19 20:44:21 +03:00
|
|
|
ERROR_RET_VAL_IF(!p, "No player info", nullptr);
|
|
|
|
|
|
|
|
if (!includeGarrisoned)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(ui32 i = 0; i < p->heroes.size() && static_cast<int>(i) <= serialId; i++)
|
2014-04-19 20:44:21 +03:00
|
|
|
if(p->heroes[i]->inTownGarrison)
|
|
|
|
serialId++;
|
|
|
|
}
|
|
|
|
ERROR_RET_VAL_IF(serialId < 0 || serialId >= p->heroes.size(), "No player info", nullptr);
|
|
|
|
return p->heroes[serialId];
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId) const
|
|
|
|
{
|
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2023-08-30 21:07:02 +02:00
|
|
|
const PlayerState *p = getPlayerState(*getPlayerID());
|
2014-04-19 20:44:21 +03:00
|
|
|
ERROR_RET_VAL_IF(!p, "No player info", nullptr);
|
|
|
|
ERROR_RET_VAL_IF(serialId < 0 || serialId >= p->towns.size(), "No player info", nullptr);
|
|
|
|
return p->towns[serialId];
|
|
|
|
}
|
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
int CPlayerSpecificInfoCallback::getResourceAmount(GameResID type) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2023-08-30 21:07:02 +02:00
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
|
return getResource(*getPlayerID(), type);
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TResources CPlayerSpecificInfoCallback::getResourceAmount() const
|
|
|
|
{
|
|
|
|
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2023-08-30 21:07:02 +02:00
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", TResources());
|
|
|
|
return gs->players[*getPlayerID()].resources;
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
|
|
|
|
{
|
2015-08-30 21:42:19 +02:00
|
|
|
//rewritten by hand, AI calls this function a lot
|
|
|
|
|
|
|
|
auto team = gs->teams.find(teamID);
|
|
|
|
if (team != gs->teams.end())
|
|
|
|
{
|
|
|
|
const TeamState *ret = &team->second;
|
2023-08-30 21:07:02 +02:00
|
|
|
if(!getPlayerID().has_value()) //neutral (or invalid) player
|
2015-08-30 21:42:19 +02:00
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
{
|
2023-08-30 21:07:02 +02:00
|
|
|
if (vstd::contains(ret->players, *getPlayerID())) //specific player
|
2015-08-30 21:42:19 +02:00
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 10:36:24 +02:00
|
|
|
logGlobal->error("Illegal attempt to access team data!");
|
2015-08-30 21:42:19 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 18:20:57 +02:00
|
|
|
logGlobal->error("Cannot find info for team %d", teamID);
|
2015-08-30 21:42:19 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const TeamState * CGameInfoCallback::getPlayerTeam( PlayerColor color ) const
|
|
|
|
{
|
2015-08-30 21:42:19 +02:00
|
|
|
auto player = gs->players.find(color);
|
|
|
|
if (player != gs->players.end())
|
|
|
|
{
|
|
|
|
return getTeam (player->second.team);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const CGHeroInstance * CGameInfoCallback::getHeroWithSubid( int subid ) const
|
2014-04-19 20:44:21 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(subid<0)
|
|
|
|
return nullptr;
|
|
|
|
if(subid>= gs->map->allHeroes.size())
|
|
|
|
return nullptr;
|
2014-04-19 20:44:21 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return gs->map->allHeroes.at(subid).get();
|
2014-04-19 20:44:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isInTheMap(const int3 &pos) const
|
|
|
|
{
|
|
|
|
return gs->map->isInTheMap(pos);
|
|
|
|
}
|
|
|
|
|
2023-04-16 00:48:49 +02:00
|
|
|
void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const
|
2017-09-13 02:35:58 +02:00
|
|
|
{
|
2023-10-04 14:31:42 +02:00
|
|
|
gs->getTilesInRange(tiles, pos, radious, ETileVisibility::REVEALED, *getPlayerID(), distanceFormula);
|
2017-09-13 02:35:58 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CGameInfoCallback::calculatePaths(const std::shared_ptr<PathfinderConfig> & config)
|
2018-08-12 13:31:31 +02:00
|
|
|
{
|
2021-05-16 19:53:11 +02:00
|
|
|
gs->calculatePaths(config);
|
2018-08-12 13:31:31 +02:00
|
|
|
}
|
|
|
|
|
2022-12-07 21:50:45 +02:00
|
|
|
void CGameInfoCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &out)
|
|
|
|
{
|
|
|
|
gs->calculatePaths(hero, out);
|
|
|
|
}
|
|
|
|
|
2014-04-19 20:44:21 +03:00
|
|
|
const CArtifactInstance * CGameInfoCallback::getArtInstance( ArtifactInstanceID aid ) const
|
|
|
|
{
|
|
|
|
return gs->map->artInstances[aid.num];
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid ) const
|
|
|
|
{
|
|
|
|
return gs->map->objects[oid.num];
|
|
|
|
}
|
|
|
|
|
2024-02-01 10:43:16 +02:00
|
|
|
const CArtifactSet * CGameInfoCallback::getArtSet(const ArtifactLocation & loc) const
|
2023-10-23 18:37:18 +02:00
|
|
|
{
|
2024-02-01 10:43:16 +02:00
|
|
|
return gs->getArtSet(loc);
|
2023-10-23 18:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 04:10:31 +02:00
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
vstd::erase_if(ids, [&](const ObjectInstanceID & id) -> bool
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * obj = getObj(id, false);
|
2015-03-09 04:10:31 +02:00
|
|
|
return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisible(obj->pos, player));
|
|
|
|
});
|
|
|
|
return ids;
|
2015-03-08 15:21:14 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 13:20:34 +02:00
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelEntraces(TeleportChannelID id, PlayerColor player) const
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
2015-03-09 04:10:31 +02:00
|
|
|
return getVisibleTeleportObjects(gs->map->teleportChannels[id]->entrances, player);
|
|
|
|
}
|
2015-03-08 15:21:14 +02:00
|
|
|
|
2015-03-09 13:20:34 +02:00
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelExits(TeleportChannelID id, PlayerColor player) const
|
2015-03-09 04:10:31 +02:00
|
|
|
{
|
|
|
|
return getVisibleTeleportObjects(gs->map->teleportChannels[id]->exits, player);
|
2015-03-08 15:21:14 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 01:01:24 +02:00
|
|
|
ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID id, PlayerColor player) const
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
2015-03-09 13:20:34 +02:00
|
|
|
std::vector<ObjectInstanceID> entrances = getTeleportChannelEntraces(id, player);
|
|
|
|
std::vector<ObjectInstanceID> exits = getTeleportChannelExits(id, player);
|
2023-03-13 23:26:44 +02:00
|
|
|
if((entrances.empty() || exits.empty()) // impassable if exits or entrances list are empty
|
|
|
|
|| (entrances.size() == 1 && entrances == exits)) // impassable if only entrance and only exit is same object. e.g bidirectional monolith
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
|
|
|
return ETeleportChannelType::IMPASSABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto intersection = vstd::intersection(entrances, exits);
|
|
|
|
if(intersection.size() == entrances.size() && intersection.size() == exits.size())
|
|
|
|
return ETeleportChannelType::BIDIRECTIONAL;
|
2023-03-13 23:26:44 +02:00
|
|
|
else if(intersection.empty())
|
2015-03-08 15:21:14 +02:00
|
|
|
return ETeleportChannelType::UNIDIRECTIONAL;
|
|
|
|
else
|
|
|
|
return ETeleportChannelType::MIXED;
|
|
|
|
}
|
|
|
|
|
2015-03-09 01:01:24 +02:00
|
|
|
bool CGameInfoCallback::isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player) const
|
2015-03-08 15:21:14 +02:00
|
|
|
{
|
2015-03-09 01:01:24 +02:00
|
|
|
return ETeleportChannelType::IMPASSABLE == getTeleportChannelType(id, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player) const
|
|
|
|
{
|
|
|
|
return ETeleportChannelType::BIDIRECTIONAL == getTeleportChannelType(id, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player) const
|
|
|
|
{
|
|
|
|
return ETeleportChannelType::UNIDIRECTIONAL == getTeleportChannelType(id, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameInfoCallback::isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const
|
|
|
|
{
|
|
|
|
return obj && obj->isEntrance() && !isTeleportChannelImpassable(obj->channel, player);
|
2015-03-08 15:21:14 +02:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|