123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #pragma once
- #include "lib/IGameCallback.h"
- /*
- * CCallback.h, 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
- *
- */
- class CGHeroInstance;
- class CGameState;
- struct CPath;
- class CGObjectInstance;
- class CArmedInstance;
- struct BattleAction;
- class CGTownInstance;
- struct lua_State;
- class CClient;
- class IShipyard;
- struct CGPathNode;
- struct CGPath;
- struct CPathsInfo;
- struct CPack;
- class IBattleCallback
- {
- public:
- bool waitTillRealize; //if true, request functions will return after they are realized by server
- bool unlockGsWhenWaiting;//if true after sending each request, gs mutex will be unlocked so the changes can be applied; NOTICE caller must have gs mx locked prior to any call to actiob callback!
- //battle
- virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
- virtual bool battleMakeTacticAction(BattleAction * action) =0; // performs tactic phase actions
- };
- class IGameActionCallback
- {
- public:
- //hero
- virtual bool moveHero(const CGHeroInstance *h, int3 dst) =0; //dst must be free, neighbouring tile (this function can move hero only by one tile)
- virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses given hero; true - successfuly, false - not successfuly
- virtual void dig(const CGObjectInstance *hero)=0;
- virtual void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1))=0; //cast adventure map spell
- //town
- virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)=0;
- virtual bool buildBuilding(const CGTownInstance *town, BuildingID buildingID)=0;
- virtual void recruitCreatures(const CGObjectInstance *obj, CreatureID ID, ui32 amount, si32 level=-1)=0;
- virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made
- virtual void swapGarrisonHero(const CGTownInstance *town)=0;
- virtual void trade(const CGObjectInstance *market, EMarketMode::EMarketMode mode, int id1, int id2, int val1, const CGHeroInstance *hero = NULL)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
- virtual int selectionMade(int selection, int queryID) =0;
- virtual int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)=0;//swaps creatures between two possibly different garrisons // TODO: AI-unsafe code - fix it!
- virtual int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)=0;//joins first stack to the second (creatures must be same type)
- virtual int mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) =0; //first goes to the second
- virtual int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)=0;//split creatures from the first stack
- //virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
- virtual bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)=0;
- virtual bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)=0;
- virtual bool dismissCreature(const CArmedInstance *obj, SlotID stackPos)=0;
- virtual void endTurn()=0;
- virtual void buyArtifact(const CGHeroInstance *hero, ArtifactID aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
- virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
- virtual void setSelection(const CArmedInstance * obj)=0;
- virtual void save(const std::string &fname) = 0;
- virtual void sendMessage(const std::string &mess) = 0;
- virtual void buildBoat(const IShipyard *obj) = 0;
- };
- struct CPack;
- class CBattleCallback : public IBattleCallback, public CPlayerBattleCallback
- {
- protected:
- int sendRequest(const CPack *request); //returns requestID (that'll be matched to requestID in PackageApplied)
- CClient *cl;
- //virtual bool hasAccess(int playerId) const;
- public:
- CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C);
- int battleMakeAction(BattleAction* action) OVERRIDE;//for casting spells by hero - DO NOT use it for moving active stack
- bool battleMakeTacticAction(BattleAction * action) OVERRIDE; // performs tactic phase actions
- friend class CCallback;
- friend class CClient;
- };
- class CCallback : public CPlayerSpecificInfoCallback, public IGameActionCallback, public CBattleCallback
- {
- private:
- void validatePaths(); //recalcualte paths if necessary
- public:
- CCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient *C);
- virtual ~CCallback();
- //client-specific functionalities (pathfinding)
- virtual const CGPathNode *getPathInfo(int3 tile); //uses main, client pathfinder info
- virtual bool getPath2(int3 dest, CGPath &ret); //uses main, client pathfinder info
- virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1);
- virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
- void unregisterMyInterface(); //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
- //commands
- bool moveHero(const CGHeroInstance *h, int3 dst); //dst must be free, neighbouring tile (this function can move hero only by one tile)
- bool teleportHero(const CGHeroInstance *who, const CGTownInstance *where);
- int selectionMade(int selection, int queryID);
- int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2);
- int mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2); //first goes to the second
- int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2); //first goes to the second
- int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val);
- bool dismissHero(const CGHeroInstance * hero);
- //bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
- bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2);
- //bool moveArtifact(const CGHeroInstance * hero, ui16 src, const CStackInstance * stack, ui16 dest); // TODO: unify classes
- //bool moveArtifact(const CStackInstance * stack, ui16 src , const CGHeroInstance * hero, ui16 dest); // TODO: unify classes
- bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo);
- bool buildBuilding(const CGTownInstance *town, BuildingID buildingID) OVERRIDE;
- void recruitCreatures(const CGObjectInstance *obj, CreatureID ID, ui32 amount, si32 level=-1);
- bool dismissCreature(const CArmedInstance *obj, SlotID stackPos);
- bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE) OVERRIDE;
- void endTurn();
- void swapGarrisonHero(const CGTownInstance *town);
- void buyArtifact(const CGHeroInstance *hero, ArtifactID aid) OVERRIDE;
- void trade(const CGObjectInstance *market, EMarketMode::EMarketMode mode, int id1, int id2, int val1, const CGHeroInstance *hero = NULL);
- void setFormation(const CGHeroInstance * hero, bool tight);
- void setSelection(const CArmedInstance * obj);
- void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero);
- void save(const std::string &fname);
- void sendMessage(const std::string &mess);
- void buildBoat(const IShipyard *obj);
- void dig(const CGObjectInstance *hero);
- void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1));
- //friends
- friend class CClient;
- };
|