2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* NetPacksServer.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"
|
2009-03-09 12:37:49 +02:00
|
|
|
#include "../lib/NetPacks.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2009-03-09 12:37:49 +02:00
|
|
|
#include "CGameHandler.h"
|
2010-05-18 10:01:54 +03:00
|
|
|
#include "../lib/IGameCallback.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../lib/mapping/CMap.h"
|
2010-12-25 21:23:30 +02:00
|
|
|
#include "../lib/CGameState.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "../lib/battle/BattleInfo.h"
|
|
|
|
#include "../lib/battle/BattleAction.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../lib/battle/Unit.h"
|
2016-09-10 02:32:40 +02:00
|
|
|
#include "../lib/serializer/Connection.h"
|
2017-07-03 20:09:27 +02:00
|
|
|
#include "../lib/spells/CSpellHandler.h"
|
|
|
|
#include "../lib/spells/ISpellMechanics.h"
|
2018-08-13 23:48:00 +02:00
|
|
|
#include "../lib/serializer/Cast.h"
|
2009-03-09 12:37:49 +02:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool CPackForServer::isPlayerOwns(CGameHandler * gh, ObjectInstanceID id)
|
|
|
|
{
|
|
|
|
return gh->getPlayerAt(c) == gh->getOwner(id);
|
|
|
|
}
|
2009-03-09 12:37:49 +02:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
void CPackForServer::throwNotAllowedAction()
|
|
|
|
{
|
|
|
|
if(c)
|
|
|
|
{
|
|
|
|
SystemMessage temp_message("You are not allowed to perform this action!");
|
2018-01-05 19:21:07 +02:00
|
|
|
c->sendPack(&temp_message);
|
2018-01-25 19:21:34 +02:00
|
|
|
}
|
|
|
|
logNetwork->error("Player is not allowed to perform this action!");
|
|
|
|
throw ExceptionNotAllowedAction();
|
|
|
|
}
|
2011-05-28 04:02:28 +03:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
void CPackForServer::wrongPlayerMessage(CGameHandler * gh, PlayerColor expectedplayer)
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "You were identified as player " << gh->getPlayerAt(c) << " while expecting " << expectedplayer;
|
|
|
|
logNetwork->error(oss.str());
|
|
|
|
if(c)
|
|
|
|
{
|
|
|
|
SystemMessage temp_message(oss.str());
|
2018-01-05 19:21:07 +02:00
|
|
|
c->sendPack(&temp_message);
|
2018-01-25 19:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-28 04:02:28 +03:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
void CPackForServer::throwOnWrongOwner(CGameHandler * gh, ObjectInstanceID id)
|
|
|
|
{
|
|
|
|
if(!isPlayerOwns(gh, id))
|
|
|
|
{
|
|
|
|
wrongPlayerMessage(gh, gh->getOwner(id));
|
|
|
|
throwNotAllowedAction();
|
|
|
|
}
|
|
|
|
}
|
2009-03-09 12:37:49 +02:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
void CPackForServer::throwOnWrongPlayer(CGameHandler * gh, PlayerColor player)
|
|
|
|
{
|
|
|
|
if(player != gh->getPlayerAt(c))
|
|
|
|
{
|
|
|
|
wrongPlayerMessage(gh, player);
|
|
|
|
throwNotAllowedAction();
|
|
|
|
}
|
|
|
|
}
|
2010-11-27 22:17:28 +02:00
|
|
|
|
2018-11-17 21:56:51 +02:00
|
|
|
void CPackForServer::throwAndComplain(CGameHandler * gh, std::string txt)
|
2018-01-25 19:21:34 +02:00
|
|
|
{
|
|
|
|
gh->complain(txt);
|
|
|
|
throwNotAllowedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CGameState * CPackForServer::GS(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
|
|
|
return gh->gs;
|
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool SaveGame::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
|
|
|
gh->save(fname);
|
2016-08-30 00:11:54 +02:00
|
|
|
logGlobal->info("Game has been saved as %s", fname);
|
2009-04-16 03:28:54 +03:00
|
|
|
return true;
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool EndTurn::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
PlayerColor player = GS(gh)->currentPlayer;
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongPlayer(gh, player);
|
2013-04-20 14:34:01 +03:00
|
|
|
if(gh->queries.topQuery(player))
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Cannot end turn before resolving queries!");
|
2011-07-17 21:49:05 +03:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
gh->states.setFlag(GS(gh)->currentPlayer, &PlayerStatus::makingTurn, false);
|
2009-04-16 03:28:54 +03:00
|
|
|
return true;
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool DismissHero::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
2013-02-09 00:17:39 +03:00
|
|
|
return gh->removeObject(gh->getObj(hid));
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool MoveHero::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
|
|
|
return gh->moveHero(hid, dest, 0, transit, gh->getPlayerAt(c));
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool CastleTeleportHero::applyGh(CGameHandler * gh)
|
2010-06-30 22:27:35 +03:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
2015-10-31 17:04:06 +02:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
return gh->teleportHero(hid, dest, source, gh->getPlayerAt(c));
|
2010-06-30 22:27:35 +03:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool ArrangeStacks::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2009-04-16 03:28:54 +03:00
|
|
|
//checks for owning in the gh func
|
2018-01-25 19:21:34 +02:00
|
|
|
return gh->arrangeStacks(id1, id2, what, p1, p2, val, gh->getPlayerAt(c));
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
bool BulkMoveArmy::applyGh(CGameHandler * gh)
|
|
|
|
{
|
|
|
|
return gh->bulkMoveArmy(srcArmy, destArmy, srcSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BulkSplitStack::applyGh(CGameHandler * gh)
|
|
|
|
{
|
|
|
|
return gh->bulkSplitStack(src, srcOwner, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BulkMergeStacks::applyGh(CGameHandler* gh)
|
|
|
|
{
|
|
|
|
return gh->bulkMergeStacks(src, srcOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BulkSmartSplitStack::applyGh(CGameHandler * gh)
|
|
|
|
{
|
|
|
|
return gh->bulkSmartSplitStack(src, srcOwner);
|
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool DisbandCreature::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, id);
|
|
|
|
return gh->disbandCreature(id, pos);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool BuildStructure::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, tid);
|
|
|
|
return gh->buildStructure(tid, bid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool RecruitCreatures::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
return gh->recruitCreatures(tid, dst, crid, amount, level);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool UpgradeCreature::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, id);
|
|
|
|
return gh->upgradeCreature(id, pos, cid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool GarrisonHeroSwap::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2010-08-12 18:54:25 +03:00
|
|
|
const CGTownInstance * town = gh->getTown(tid);
|
2018-01-25 19:21:34 +02:00
|
|
|
if(!isPlayerOwns(gh, tid) && !(town->garrisonHero && isPlayerOwns(gh, town->garrisonHero->id)))
|
|
|
|
throwNotAllowedAction(); //neither town nor garrisoned hero (if present) is ours
|
2009-04-16 03:28:54 +03:00
|
|
|
return gh->garrisonSwap(tid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool ExchangeArtifacts::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongPlayer(gh, src.owningPlayer()); //second hero can be ally
|
2012-04-14 05:20:22 +03:00
|
|
|
return gh->moveArtifact(src, dst);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool AssembleArtifacts::applyGh(CGameHandler * gh)
|
2010-02-16 16:39:56 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, heroID);
|
2010-02-16 16:39:56 +02:00
|
|
|
return gh->assembleArtifacts(heroID, artifactSlot, assemble, assembleTo);
|
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool BuyArtifact::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
|
|
|
return gh->buyArtifact(hid, aid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool TradeOnMarketplace::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-03-10 21:19:55 +02:00
|
|
|
const CGObjectInstance * market = gh->getObj(marketId);
|
|
|
|
if(!market)
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Invalid market object");
|
2018-03-10 21:19:55 +02:00
|
|
|
const CGHeroInstance * hero = gh->getHero(heroId);
|
|
|
|
|
2010-05-18 10:01:54 +03:00
|
|
|
//market must be owned or visited
|
2018-01-25 19:21:34 +02:00
|
|
|
const IMarket * m = IMarket::castFrom(market);
|
2010-05-18 10:01:54 +03:00
|
|
|
|
|
|
|
if(!m)
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "market is not-a-market! :/");
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
PlayerColor player = market->tempOwner;
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
if(player >= PlayerColor::PLAYER_LIMIT)
|
2010-05-18 10:01:54 +03:00
|
|
|
player = gh->getTile(market->visitablePos())->visitableObjects.back()->tempOwner;
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
if(player >= PlayerColor::PLAYER_LIMIT)
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "No player can use this market!");
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2019-03-24 20:20:08 +02:00
|
|
|
bool allyTownSkillTrade = (mode == EMarketMode::RESOURCE_SKILL && gh->getPlayerRelations(player, hero->tempOwner) == PlayerRelations::ALLIES);
|
|
|
|
|
|
|
|
if(hero && (!(player == hero->tempOwner || allyTownSkillTrade)
|
|
|
|
|| hero->visitablePos() != market->visitablePos()))
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "This hero can't use this marketplace!");
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2019-03-24 20:20:08 +02:00
|
|
|
if(!allyTownSkillTrade)
|
|
|
|
throwOnWrongPlayer(gh, player);
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2017-10-14 21:30:56 +02:00
|
|
|
bool result = true;
|
|
|
|
|
2010-05-08 01:10:32 +03:00
|
|
|
switch(mode)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_RESOURCE:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->tradeResources(m, val[i], player, r1[i], r2[i]);
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_PLAYER:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->sendResources(val[i], player, static_cast<Res::ERes>(r1[i]), PlayerColor(r2[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_RESOURCE:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->sellCreatures(val[i], m, hero, SlotID(r1[i]), static_cast<Res::ERes>(r2[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_ARTIFACT:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->buyArtifact(m, hero, static_cast<Res::ERes>(r1[i]), ArtifactID(r2[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::ARTIFACT_RESOURCE:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->sellArtifact(m, hero, ArtifactInstanceID(r1[i]), static_cast<Res::ERes>(r2[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_UNDEAD:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r1.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->transformInUndead(m, hero, SlotID(r1[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_SKILL:
|
2017-10-28 11:04:55 +02:00
|
|
|
for(int i = 0; i < r2.size(); ++i)
|
2017-10-14 21:30:56 +02:00
|
|
|
result &= gh->buySecSkill(m, hero, SecondarySkill(r2[i]));
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_EXP:
|
2017-10-14 21:30:56 +02:00
|
|
|
{
|
|
|
|
std::vector<SlotID> slotIDs(r1.begin(), r1.end());
|
|
|
|
std::vector<ui32> count(val.begin(), val.end());
|
|
|
|
return gh->sacrificeCreatures(m, hero, slotIDs, count);
|
|
|
|
}
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::ARTIFACT_EXP:
|
2017-10-14 21:30:56 +02:00
|
|
|
{
|
|
|
|
std::vector<ArtifactPosition> positions(r1.begin(), r1.end());
|
|
|
|
return gh->sacrificeArtifact(m, hero, positions);
|
|
|
|
}
|
2010-05-08 01:10:32 +03:00
|
|
|
default:
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Unknown exchange mode!");
|
2010-05-08 01:10:32 +03:00
|
|
|
}
|
2017-10-14 21:30:56 +02:00
|
|
|
|
|
|
|
return result;
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool SetFormation::applyGh(CGameHandler * gh)
|
2015-10-31 17:04:06 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
|
|
|
return gh->setFormation(hid, formation);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool HireHero::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
const CGObjectInstance * obj = gh->getObj(tid);
|
|
|
|
const CGTownInstance * town = dynamic_ptr_cast<CGTownInstance>(obj);
|
2015-10-15 03:00:21 +02:00
|
|
|
if(town && PlayerRelations::ENEMIES == gh->getPlayerRelations(obj->tempOwner, gh->getPlayerAt(c)))
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Can't buy hero in enemy town!");
|
2010-07-09 02:03:27 +03:00
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
return gh->hireHero(obj, hid, player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool BuildBoat::applyGh(CGameHandler * gh)
|
2009-07-26 06:33:13 +03:00
|
|
|
{
|
2018-11-17 15:02:47 +02:00
|
|
|
if(gh->getPlayerRelations(gh->getOwner(objid), gh->getPlayerAt(c)) == PlayerRelations::ENEMIES)
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Can't build boat at enemy shipyard");
|
2018-11-17 15:02:47 +02:00
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
return gh->buildBoat(objid);
|
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool QueryReply::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2012-07-15 18:34:00 +03:00
|
|
|
auto playerToConnection = gh->connections.find(player);
|
|
|
|
if(playerToConnection == gh->connections.end())
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "No such player!");
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!vstd::contains(playerToConnection->second, c))
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Message came from wrong connection!");
|
2013-05-27 13:53:28 +03:00
|
|
|
if(qid == QueryID(-1))
|
2018-11-17 21:56:51 +02:00
|
|
|
throwAndComplain(gh, "Cannot answer the query with id -1!");
|
2012-07-15 18:34:00 +03:00
|
|
|
|
2011-09-06 09:00:32 +03:00
|
|
|
assert(vstd::contains(gh->states.players, player));
|
2017-06-06 06:53:51 +02:00
|
|
|
return gh->queryReply(qid, reply, player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool MakeAction::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
const BattleInfo * b = GS(gh)->curB;
|
|
|
|
if(!b)
|
|
|
|
throwNotAllowedAction();
|
2015-10-31 17:04:06 +02:00
|
|
|
|
2011-02-14 00:46:04 +02:00
|
|
|
if(b->tacticDistance)
|
2011-02-12 18:12:48 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(ba.actionType != EActionType::WALK && ba.actionType != EActionType::END_TACTIC_PHASE
|
|
|
|
&& ba.actionType != EActionType::RETREAT && ba.actionType != EActionType::SURRENDER)
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!vstd::contains(gh->connections[b->sides[b->tacticsSide].color], c))
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2011-02-12 18:12:48 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto active = b->battleActiveUnit();
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!active)
|
|
|
|
throwNotAllowedAction();
|
2017-07-20 06:08:49 +02:00
|
|
|
auto unitOwner = b->battleGetOwner(active);
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!vstd::contains(gh->connections[unitOwner], c))
|
|
|
|
throwNotAllowedAction();
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2009-04-16 03:28:54 +03:00
|
|
|
return gh->makeBattleAction(ba);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool MakeCustomAction::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
const BattleInfo * b = GS(gh)->curB;
|
|
|
|
if(!b)
|
|
|
|
throwNotAllowedAction();
|
|
|
|
if(b->tacticDistance)
|
|
|
|
throwNotAllowedAction();
|
2017-07-20 06:08:49 +02:00
|
|
|
auto active = b->battleActiveUnit();
|
2018-01-25 19:21:34 +02:00
|
|
|
if(!active)
|
|
|
|
throwNotAllowedAction();
|
2017-07-20 06:08:49 +02:00
|
|
|
auto unitOwner = b->battleGetOwner(active);
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!vstd::contains(gh->connections[unitOwner], c))
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2017-07-20 06:08:49 +02:00
|
|
|
if(ba.actionType != EActionType::HERO_SPELL)
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2009-04-16 03:28:54 +03:00
|
|
|
return gh->makeCustomAction(ba);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool DigWithHero::applyGh(CGameHandler * gh)
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, id);
|
2010-02-21 17:03:30 +02:00
|
|
|
return gh->dig(gh->getHero(id));
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
bool CastAdvSpell::applyGh(CGameHandler * gh)
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongOwner(gh, hid);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
|
|
|
const CSpell * s = sid.toSpell();
|
|
|
|
if(!s)
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2017-06-06 06:53:51 +02:00
|
|
|
const CGHeroInstance * h = gh->getHero(hid);
|
|
|
|
if(!h)
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
AdventureSpellCastParameters p;
|
|
|
|
p.caster = h;
|
|
|
|
p.pos = pos;
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
return s->adventureCast(gh->spellEnv, p);
|
2010-03-11 01:16:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 19:21:34 +02:00
|
|
|
bool PlayerMessage::applyGh(CGameHandler * gh)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2017-06-03 07:25:10 +02:00
|
|
|
if(!player.isSpectator()) // TODO: clearly not a great way to verify permissions
|
|
|
|
{
|
2018-01-25 19:21:34 +02:00
|
|
|
throwOnWrongPlayer(gh, player);
|
2018-01-05 19:21:07 +02:00
|
|
|
if(gh->getPlayerAt(this->c) != player)
|
2018-01-25 19:21:34 +02:00
|
|
|
throwNotAllowedAction();
|
2017-06-03 07:25:10 +02:00
|
|
|
}
|
2018-01-25 19:21:34 +02:00
|
|
|
gh->playerMessage(player, text, currObj);
|
2009-04-16 03:28:54 +03:00
|
|
|
return true;
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|