123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #include "../lib/NetPacks.h"
- #include "CGameHandler.h"
- #define PLAYER_OWNS(id) (gh->getPlayerAt(c)==gh->getOwner(id))
- #define ERROR_AND_RETURN {if(c) *c << &SystemMessage("You are not allowed to perform this action!"); \
- tlog1<<"Player is not allowed to perform this action!\n"; \
- return;}
- #define ERROR_IF_NOT_OWNS(id) if(!PLAYER_OWNS(id)) ERROR_AND_RETURN
- /*
- * 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
- *
- */
- CGameState* CPackForServer::GS(CGameHandler *gh)
- {
- return gh->gs;
- }
- void SaveGame::applyGh( CGameHandler *gh )
- {
- gh->sendMessageTo(*c,"Saving...");
- gh->save(fname);
- gh->sendMessageTo(*c,"Game has been succesfully saved!");
- }
- void CloseServer::applyGh( CGameHandler *gh )
- {
- gh->close();
- }
- void EndTurn::applyGh( CGameHandler *gh )
- {
- gh->states.setFlag(GS(gh)->currentPlayer,&PlayerStatus::makingTurn,false);
- }
- void DismissHero::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(hid);
- gh->removeObject(hid);
- }
- void MoveHero::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(hid);
- gh->moveHero(hid,dest,0,gh->getPlayerAt(c));
- }
- void ArrangeStacks::applyGh( CGameHandler *gh )
- {
- //ERROR_IF_NOT_OWNS(id1);
- //ERROR_IF_NOT_OWNS(id2);
- gh->arrangeStacks(id1,id2,what,p1,p2,val);
- }
- void DisbandCreature::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(id);
- gh->disbandCreature(id,pos);
- }
- void BuildStructure::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(tid);
- gh->buildStructure(tid,bid);
- }
- void RecruitCreatures::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(tid);
- gh->recruitCreatures(tid,crid,amount);
- }
- void UpgradeCreature::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(id);
- gh->upgradeCreature(id,pos,cid);
- }
- void GarrisonHeroSwap::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(tid);
- gh->garrisonSwap(tid);
- }
- void ExchangeArtifacts::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(hid1);
- ERROR_IF_NOT_OWNS(hid2);
- gh->swapArtifacts(hid1,hid2,slot1,slot2);
- }
- void BuyArtifact::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(hid);
- gh->buyArtifact(hid,aid);
- }
- void TradeOnMarketplace::applyGh( CGameHandler *gh )
- {
- if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
- gh->tradeResources(val,player,r1,r2);
- }
- void SetFormation::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(hid);
- gh->setFormation(hid,formation);
- }
- void HireHero::applyGh( CGameHandler *gh )
- {
- ERROR_IF_NOT_OWNS(tid);
- gh->hireHero(tid,hid);
- }
- void QueryReply::applyGh( CGameHandler *gh )
- {
- gh->queryReply(qid,answer);
- }
- void MakeAction::applyGh( CGameHandler *gh )
- {
- if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
- gh->makeBattleAction(ba);
- }
- void MakeCustomAction::applyGh( CGameHandler *gh )
- {
- if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
- gh->makeCustomAction(ba);
- }
- void PlayerMessage::applyGh( CGameHandler *gh )
- {
- if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
- gh->playerMessage(player,text);
- }
- void SetSelection::applyGh( CGameHandler *gh )
- {
- if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
- gh->sendAndApply(this);
- }
|