2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CCallback.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-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-08-27 17:15:03 +03:00
|
|
|
#include "CCallback.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CCreatureHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "lib/CGameState.h"
|
|
|
|
#include "client/CPlayerInterface.h"
|
2008-08-30 00:41:32 +03:00
|
|
|
#include "client/Client.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "lib/mapping/CMap.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CBuildingHandler.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
#include "lib/mapObjects/CObjectClassesHandler.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CGeneralTextHandler.h"
|
|
|
|
#include "lib/CHeroHandler.h"
|
2008-07-28 15:44:08 +03:00
|
|
|
#include "lib/NetPacks.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CArtHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "lib/GameConstants.h"
|
2015-12-02 21:39:53 +02:00
|
|
|
#include "lib/CPlayerState.h"
|
2012-02-20 00:03:43 +03:00
|
|
|
#include "lib/UnlockGuard.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "lib/battle/BattleInfo.h"
|
2008-03-14 20:24:37 +02:00
|
|
|
|
2010-06-30 22:27:35 +03:00
|
|
|
bool CCallback::teleportHero(const CGHeroInstance *who, const CGTownInstance *where)
|
|
|
|
{
|
|
|
|
CastleTeleportHero pack(who->id, where->id, 1);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-08 16:04:09 +02:00
|
|
|
bool CCallback::moveHero(const CGHeroInstance *h, int3 dst, bool transit)
|
2009-03-12 20:50:36 +02:00
|
|
|
{
|
2015-03-08 16:04:09 +02:00
|
|
|
MoveHero pack(dst,h->id,transit);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2007-08-30 13:11:53 +03:00
|
|
|
return true;
|
2007-08-29 15:18:31 +03:00
|
|
|
}
|
2012-07-15 18:34:00 +03:00
|
|
|
|
2013-05-27 13:53:28 +03:00
|
|
|
int CCallback::selectionMade(int selection, QueryID queryID)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2017-11-26 23:18:18 +02:00
|
|
|
JsonNode reply(JsonNode::JsonType::DATA_INTEGER);
|
2017-06-06 06:53:51 +02:00
|
|
|
reply.Integer() = selection;
|
|
|
|
return sendQueryReply(reply, queryID);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::sendQueryReply(const JsonNode & reply, QueryID queryID)
|
2007-12-25 18:25:53 +02:00
|
|
|
{
|
2013-02-11 17:42:09 +03:00
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2013-05-27 13:53:28 +03:00
|
|
|
if(queryID == QueryID(-1))
|
2012-07-15 18:34:00 +03:00
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->error("Cannot answer the query -1!");
|
2017-06-06 06:53:51 +02:00
|
|
|
return -1;
|
2012-07-15 18:34:00 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 00:32:40 +02:00
|
|
|
QueryReply pack(queryID, reply);
|
2013-02-11 17:42:09 +03:00
|
|
|
pack.player = *player;
|
2012-07-15 18:34:00 +03:00
|
|
|
return sendRequest(&pack);
|
2007-12-25 18:25:53 +02:00
|
|
|
}
|
2012-07-15 18:34:00 +03:00
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
void CCallback::recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level)
|
2008-04-11 20:41:02 +03:00
|
|
|
{
|
2016-03-13 08:02:08 +02:00
|
|
|
// TODO exception for neutral dwellings shouldn't be hardcoded
|
|
|
|
if(player != obj->tempOwner && obj->ID != Obj::WAR_MACHINE_FACTORY && obj->ID != Obj::REFUGEE_CAMP)
|
2010-05-15 11:33:32 +03:00
|
|
|
return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
2014-09-19 00:18:49 +03:00
|
|
|
RecruitCreatures pack(obj->id, dst->id, ID, amount, level);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-11 20:41:02 +03:00
|
|
|
}
|
2007-09-14 16:11:10 +03:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCallback::dismissCreature(const CArmedInstance *obj, SlotID stackPos)
|
2008-05-23 22:50:11 +03:00
|
|
|
{
|
2015-05-07 02:16:51 +02:00
|
|
|
if((player && obj->tempOwner != player) || (obj->stacksCount()<2 && obj->needsLastStack()))
|
2008-05-31 23:37:54 +03:00
|
|
|
return false;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
DisbandCreature pack(stackPos,obj->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-05-31 23:37:54 +03:00
|
|
|
return true;
|
2008-05-23 22:50:11 +03:00
|
|
|
}
|
2011-05-03 06:14:18 +03:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCallback::upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID)
|
2008-05-23 22:50:11 +03:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
UpgradeCreature pack(stackPos,obj->id,newID);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-05-23 22:50:11 +03:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-03 06:14:18 +03:00
|
|
|
|
2008-07-27 20:07:37 +03:00
|
|
|
void CCallback::endTurn()
|
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logGlobal->trace("Player %d ended his turn.", player.get().getNum());
|
2009-03-20 20:51:48 +02:00
|
|
|
EndTurn pack;
|
2018-01-05 19:21:07 +02:00
|
|
|
sendRequest(&pack);
|
2008-07-27 20:07:37 +03:00
|
|
|
}
|
2013-02-16 17:03:47 +03:00
|
|
|
int CCallback::swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(1,p1,p2,s1->id,s2->id,0);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-13 14:05:39 +03:00
|
|
|
return 0;
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
int CCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
2009-04-12 03:58:41 +03:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(2,p1,p2,s1->id,s2->id,0);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-13 14:05:39 +03:00
|
|
|
return 0;
|
2008-01-30 00:47:43 +02:00
|
|
|
}
|
2021-11-28 14:57:38 +02:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
int CCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)
|
2008-01-30 00:47:43 +02:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(3,p1,p2,s1->id,s2->id,val);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-19 19:15:04 +03:00
|
|
|
return 0;
|
2008-01-30 00:47:43 +02:00
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
int CCallback::bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot)
|
|
|
|
{
|
|
|
|
BulkMoveArmy pack(srcArmy, destArmy, srcSlot);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany)
|
|
|
|
{
|
|
|
|
BulkSplitStack pack(armyId, srcSlot, howMany);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::bulkSmartSplitStack(ObjectInstanceID armyId, SlotID srcSlot)
|
|
|
|
{
|
|
|
|
BulkSmartSplitStack pack(armyId, srcSlot);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot)
|
|
|
|
{
|
|
|
|
BulkMergeStacks pack(armyId, srcSlot);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-27 18:07:27 +02:00
|
|
|
bool CCallback::dismissHero(const CGHeroInstance *hero)
|
|
|
|
{
|
2008-08-02 00:41:38 +03:00
|
|
|
if(player!=hero->tempOwner) return false;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
DismissHero pack(hero->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-08-02 00:41:38 +03:00
|
|
|
return true;
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 05:20:22 +03:00
|
|
|
bool CCallback::swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)
|
2008-01-30 12:55:43 +02:00
|
|
|
{
|
2012-04-14 05:20:22 +03:00
|
|
|
ExchangeArtifacts ea;
|
|
|
|
ea.src = l1;
|
|
|
|
ea.dst = l2;
|
|
|
|
sendRequest(&ea);
|
|
|
|
return true;
|
2008-01-30 12:55:43 +02:00
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2010-02-16 16:39:56 +02:00
|
|
|
/**
|
|
|
|
* Assembles or disassembles a combination artifact.
|
|
|
|
* @param hero Hero holding the artifact(s).
|
|
|
|
* @param artifactSlot The worn slot ID of the combination- or constituent artifact.
|
|
|
|
* @param assemble True for assembly operation, false for disassembly.
|
|
|
|
* @param assembleTo If assemble is true, this represents the artifact ID of the combination
|
|
|
|
* artifact to assemble to. Otherwise it's not used.
|
|
|
|
*/
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCallback::assembleArtifacts (const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)
|
2010-02-16 16:39:56 +02:00
|
|
|
{
|
|
|
|
if (player != hero->tempOwner)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AssembleArtifacts aa(hero->id, artifactSlot, assemble, assembleTo);
|
|
|
|
sendRequest(&aa);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-11 01:01:55 +02:00
|
|
|
void CCallback::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap)
|
2022-11-06 23:41:29 +02:00
|
|
|
{
|
2022-11-10 23:24:41 +02:00
|
|
|
BulkExchangeArtifacts bma(srcHero, dstHero, swap);
|
2022-11-06 23:41:29 +02:00
|
|
|
sendRequest(&bma);
|
|
|
|
}
|
|
|
|
|
2023-04-07 23:41:55 +02:00
|
|
|
void CCallback::eraseArtifactByClient(const ArtifactLocation & al)
|
|
|
|
{
|
|
|
|
EraseArtifactByClient ea(al);
|
|
|
|
sendRequest(&ea);
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:11:34 +03:00
|
|
|
bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
2008-03-21 02:03:31 +02:00
|
|
|
{
|
2008-08-01 14:21:15 +03:00
|
|
|
if(town->tempOwner!=player)
|
2008-03-23 03:01:17 +02:00
|
|
|
return false;
|
2011-07-05 09:14:07 +03:00
|
|
|
|
|
|
|
if(!canBuildStructure(town, buildingID))
|
|
|
|
return false;
|
2008-08-01 14:21:15 +03:00
|
|
|
|
2009-03-20 20:51:48 +02:00
|
|
|
BuildStructure pack(town->id,buildingID);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-03-21 02:03:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
int CBattleCallback::battleMakeAction(const BattleAction * action)
|
2008-09-29 00:01:49 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
assert(action->actionType == EActionType::HERO_SPELL);
|
2009-03-20 20:51:48 +02:00
|
|
|
MakeCustomAction mca(*action);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&mca);
|
2008-09-29 00:01:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
int CBattleCallback::sendRequest(const CPackForServer * request)
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2013-02-11 17:42:09 +03:00
|
|
|
int requestID = cl->sendRequest(request, *player);
|
2010-12-22 22:14:40 +02:00
|
|
|
if(waitTillRealize)
|
2011-07-05 22:05:41 +03:00
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->trace("We'll wait till request %d is answered.\n", requestID);
|
2017-06-14 06:59:41 +02:00
|
|
|
auto gsUnlocker = vstd::makeUnlockSharedGuardIf(CGameState::mutex, unlockGsWhenWaiting);
|
2017-07-12 16:02:25 +02:00
|
|
|
CClient::waitingRequest.waitWhileContains(requestID);
|
2011-07-05 22:05:41 +03:00
|
|
|
}
|
2012-07-15 18:34:00 +03:00
|
|
|
|
2014-02-02 00:34:14 +03:00
|
|
|
boost::this_thread::interruption_point();
|
2012-07-15 18:34:00 +03:00
|
|
|
return requestID;
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
2008-08-16 11:47:41 +03:00
|
|
|
void CCallback::swapGarrisonHero( const CGTownInstance *town )
|
|
|
|
{
|
2013-02-23 15:22:23 +03:00
|
|
|
if(town->tempOwner == *player
|
|
|
|
|| (town->garrisonHero && town->garrisonHero->tempOwner == *player ))
|
|
|
|
{
|
|
|
|
GarrisonHeroSwap pack(town->id);
|
|
|
|
sendRequest(&pack);
|
|
|
|
}
|
2008-08-25 13:25:16 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void CCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid)
|
2008-08-25 13:25:16 +03:00
|
|
|
{
|
|
|
|
if(hero->tempOwner != player) return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
BuyArtifact pack(hero->id,aid);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 11:04:55 +02:00
|
|
|
void CCallback::trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero)
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2018-04-06 04:48:28 +02:00
|
|
|
trade(market, mode, std::vector<ui32>(1, id1), std::vector<ui32>(1, id2), std::vector<ui32>(1, val1), hero);
|
2017-10-14 21:30:56 +02:00
|
|
|
}
|
|
|
|
|
2017-10-28 11:04:55 +02:00
|
|
|
void CCallback::trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero)
|
2017-10-14 21:30:56 +02:00
|
|
|
{
|
|
|
|
TradeOnMarketplace pack;
|
2018-03-10 21:19:55 +02:00
|
|
|
pack.marketId = market->id;
|
2018-04-06 04:48:28 +02:00
|
|
|
pack.heroId = hero ? hero->id : ObjectInstanceID();
|
2017-10-14 21:30:56 +02:00
|
|
|
pack.mode = mode;
|
2017-10-18 21:02:23 +02:00
|
|
|
pack.r1 = id1;
|
|
|
|
pack.r2 = id2;
|
|
|
|
pack.val = val1;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-09-18 16:54:54 +03:00
|
|
|
}
|
|
|
|
|
2008-09-19 11:16:19 +03:00
|
|
|
void CCallback::setFormation(const CGHeroInstance * hero, bool tight)
|
2008-09-18 16:54:54 +03:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
SetFormation pack(hero->id,tight);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-10-19 02:20:48 +03:00
|
|
|
}
|
|
|
|
|
2010-07-09 02:03:27 +03:00
|
|
|
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2013-02-09 20:37:38 +03:00
|
|
|
assert(townOrTavern);
|
|
|
|
assert(hero);
|
2008-10-26 22:58:34 +02:00
|
|
|
ui8 i=0;
|
2013-02-11 17:42:09 +03:00
|
|
|
for(; i<gs->players[*player].availableHeroes.size(); i++)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2013-02-11 17:42:09 +03:00
|
|
|
if(gs->players[*player].availableHeroes[i] == hero)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2013-02-14 02:55:42 +03:00
|
|
|
HireHero pack(i, townOrTavern->id);
|
2013-02-11 17:42:09 +03:00
|
|
|
pack.player = *player;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2009-03-09 12:37:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 02:38:48 +02:00
|
|
|
void CCallback::save( const std::string &fname )
|
|
|
|
{
|
|
|
|
cl->save(fname);
|
2009-04-04 22:26:41 +03:00
|
|
|
}
|
|
|
|
|
2009-04-05 17:37:14 +03:00
|
|
|
|
2014-09-21 20:35:53 +03:00
|
|
|
void CCallback::sendMessage(const std::string &mess, const CGObjectInstance * currentObject)
|
2009-04-05 17:37:14 +03:00
|
|
|
{
|
2013-02-11 17:42:09 +03:00
|
|
|
ASSERT_IF_CALLED_WITH_PLAYER
|
2018-01-05 19:21:07 +02:00
|
|
|
PlayerMessage pm(mess, currentObject? currentObject->id : ObjectInstanceID(-1));
|
2022-10-05 17:04:51 +02:00
|
|
|
if(player)
|
|
|
|
pm.player = *player;
|
2018-01-05 19:21:07 +02:00
|
|
|
sendRequest(&pm);
|
2009-05-12 06:35:51 +03:00
|
|
|
}
|
2009-07-20 04:47:49 +03:00
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
void CCallback::buildBoat( const IShipyard *obj )
|
|
|
|
{
|
|
|
|
BuildBoat bb;
|
|
|
|
bb.objid = obj->o->id;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&bb);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
CCallback::CCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient * C)
|
|
|
|
: CBattleCallback(Player, C)
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
gs = GS;
|
|
|
|
|
2009-08-04 02:53:18 +03:00
|
|
|
waitTillRealize = false;
|
2012-02-17 00:46:28 +03:00
|
|
|
unlockGsWhenWaiting = false;
|
2009-07-26 06:33:13 +03:00
|
|
|
}
|
|
|
|
|
2013-02-12 18:46:43 +03:00
|
|
|
CCallback::~CCallback()
|
|
|
|
{
|
|
|
|
//trivial, but required. Don`t remove.
|
|
|
|
}
|
|
|
|
|
2014-02-15 22:39:03 +03:00
|
|
|
bool CCallback::canMoveBetween(const int3 &a, const int3 &b)
|
|
|
|
{
|
2016-12-21 11:10:37 +02:00
|
|
|
//bidirectional
|
|
|
|
return gs->map->canMoveBetween(a, b);
|
2014-02-15 22:39:03 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 05:00:00 +02:00
|
|
|
std::shared_ptr<const CPathsInfo> CCallback::getPathsInfo(const CGHeroInstance * h)
|
2014-02-07 11:23:31 +03:00
|
|
|
{
|
2014-09-21 16:42:08 +03:00
|
|
|
return cl->getPathsInfo(h);
|
2014-02-07 11:23:31 +03:00
|
|
|
}
|
|
|
|
|
2014-04-01 14:53:28 +03:00
|
|
|
int3 CCallback::getGuardingCreaturePosition(int3 tile)
|
|
|
|
{
|
|
|
|
if (!gs->map->isInTheMap(tile))
|
|
|
|
return int3(-1,-1,-1);
|
|
|
|
|
2022-09-18 16:39:10 +02:00
|
|
|
return gs->map->guardingCreaturePositions[tile.z][tile.x][tile.y];
|
2014-04-01 14:53:28 +03:00
|
|
|
}
|
|
|
|
|
2010-02-21 17:03:30 +02:00
|
|
|
void CCallback::dig( const CGObjectInstance *hero )
|
|
|
|
{
|
|
|
|
DigWithHero dwh;
|
|
|
|
dwh.id = hero->id;
|
|
|
|
sendRequest(&dwh);
|
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void CCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos)
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
|
|
|
CastAdvSpell cas;
|
|
|
|
cas.hid = hero->id;
|
|
|
|
cas.sid = spellID;
|
|
|
|
cas.pos = pos;
|
|
|
|
sendRequest(&cas);
|
|
|
|
}
|
2011-05-30 02:49:25 +03:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
int CCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
2012-03-11 04:26:11 +03:00
|
|
|
{
|
|
|
|
if(s1->getCreature(p1) == s2->getCreature(p2))
|
|
|
|
return mergeStacks(s1, s2, p1, p2);
|
|
|
|
else
|
|
|
|
return swapCreatures(s1, s2, p1, p2);
|
|
|
|
}
|
|
|
|
|
2015-12-29 04:43:33 +02:00
|
|
|
void CCallback::registerBattleInterface(std::shared_ptr<IBattleEventsReceiver> battleEvents)
|
2013-06-22 21:22:44 +03:00
|
|
|
{
|
2013-06-23 19:09:15 +03:00
|
|
|
cl->additionalBattleInts[*player].push_back(battleEvents);
|
2013-06-22 21:22:44 +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
|
|
|
void CCallback::unregisterBattleInterface(std::shared_ptr<IBattleEventsReceiver> battleEvents)
|
2013-06-22 21:22:44 +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
|
|
|
cl->additionalBattleInts[*player] -= battleEvents;
|
2013-06-22 21:22:44 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 18:31:14 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
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
|
|
|
scripting::Pool * CBattleCallback::getContextPool() const
|
2013-06-22 21:22:44 +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 cl->getGlobalContextPool();
|
2013-06-22 21:22:44 +03:00
|
|
|
}
|
2022-09-21 18:31:14 +02:00
|
|
|
#endif
|
2013-06-22 21:22:44 +03:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
CBattleCallback::CBattleCallback(boost::optional<PlayerColor> Player, CClient *C )
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
|
|
|
player = Player;
|
|
|
|
cl = C;
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
2011-02-12 18:12:48 +02:00
|
|
|
bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
|
|
|
|
{
|
2011-08-25 23:02:38 +03:00
|
|
|
assert(cl->gs->curB->tacticDistance);
|
2011-02-12 18:12:48 +02:00
|
|
|
MakeAction ma;
|
|
|
|
ma.ba = *action;
|
|
|
|
sendRequest(&ma);
|
|
|
|
return true;
|
2013-04-09 17:31:36 +03:00
|
|
|
}
|
2022-10-14 10:24:29 +02:00
|
|
|
|
|
|
|
boost::optional<BattleAction> CBattleCallback::makeSurrenderRetreatDecision(
|
|
|
|
const BattleStateInfoForRetreat & battleState)
|
|
|
|
{
|
|
|
|
return cl->playerint[getPlayerID().get()]->makeSurrenderRetreatDecision(battleState);
|
2022-12-07 21:50:45 +02:00
|
|
|
}
|