2009-04-15 14:03:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  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 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-13 11:26:03 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# pragma once 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "lib/CGameInfoCallback.h" 
  
						 
					
						
							
								
									
										
										
											
												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 17:58:30 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "lib/battle/CPlayerBattleCallback.h" 
  
						 
					
						
							
								
									
										
										
										
											2017-07-13 11:26:03 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "lib/int3.h" // for int3 
  
						 
					
						
							
								
									
										
										
										
											2009-08-05 00:21:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-26 16:07:42 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								VCMI_LIB_NAMESPACE_BEGIN  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CGHeroInstance ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  CGameState ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								struct  CPath ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  CGObjectInstance ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  CArmedInstance ;  
						 
					
						
							
								
									
										
										
										
											2017-07-20 07:08:49 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  BattleAction ;  
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CGTownInstance ;  
						 
					
						
							
								
									
										
										
										
											2009-07-26 03:33:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  IShipyard ;  
						 
					
						
							
								
									
										
										
										
											2009-08-30 12:47:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  CGPathNode ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								struct  CGPath ;  
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  CPathsInfo ;  
						 
					
						
							
								
									
										
										
										
											2018-10-07 14:51:27 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  PathfinderConfig ;  
						 
					
						
							
								
									
										
										
										
											2011-08-26 00:27:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  CPack ;  
						 
					
						
							
								
									
										
										
										
											2022-07-26 16:07:42 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  CPackForServer ;  
						 
					
						
							
								
									
										
										
										
											2013-06-23 16:09:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  IBattleEventsReceiver ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  IGameEventsReceiver ;  
						 
					
						
							
								
									
										
										
										
											2014-04-20 11:13:37 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  ArtifactLocation ;  
						 
					
						
							
								
									
										
										
										
											2022-10-14 11:24:29 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  BattleStateInfoForRetreat ;  
						 
					
						
							
								
									
										
										
										
											2023-04-28 05:14:27 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  IMarket ;  
						 
					
						
							
								
									
										
										
										
											2014-04-20 11:13:37 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-26 16:07:42 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								VCMI_LIB_NAMESPACE_END  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-26 12:18:24 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// in static AI build this file gets included into libvcmi
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef STATIC_AI 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								VCMI_LIB_USING_NAMESPACE  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-26 16:07:42 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CClient ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								struct  lua_State ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  IBattleCallback  
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2022-09-22 11:02:16 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  ~ IBattleCallback ( )  =  default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-18 19:55:59 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  waitTillRealize  =  false ;  //if true, request functions will return after they are realized by server
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  unlockGsWhenWaiting  =  false ; //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!
 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//battle
 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-18 19:55:59 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  battleMakeSpellAction ( const  BattleAction  &  action )  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  battleMakeUnitAction ( const  BattleAction  &  action )  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  battleMakeTacticAction ( const  BattleAction  &  action )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-16 20:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  std : : optional < BattleAction >  makeSurrenderRetreatDecision ( const  BattleStateInfoForRetreat  &  battleState )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  IGameActionCallback  
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2009-08-03 19:22:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//hero
 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-08 17:04:09 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  moveHero ( const  CGHeroInstance  * h ,  int3  dst ,  bool  transit )  = 0 ;  //dst must be free, neighbouring tile (this function can move hero only by one tile)
 
							 
						 
					
						
							
								
									
										
										
										
											2009-08-03 19:22:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  dismissHero ( const  CGHeroInstance  *  hero ) = 0 ;  //dismisses given hero; true - successfuly, false - not successfuly
 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-12 15:46:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  dig ( const  CGObjectInstance  * hero ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-10 23:24:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  castSpell ( const  CGHeroInstance  * hero ,  SpellID  spellID ,  const  int3  & pos  =  int3 ( - 1 ,  - 1 ,  - 1 ) ) = 0 ;  //cast adventure map spell
 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-08-03 19:22:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//town
 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-08 23:03:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  recruitHero ( const  CGObjectInstance  * townOrTavern ,  const  CGHeroInstance  * hero ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-11 19:11:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  buildBuilding ( const  CGTownInstance  * town ,  BuildingID  buildingID ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 00:18:49 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  recruitCreatures ( const  CGDwelling  * obj ,  const  CArmedInstance  *  dst ,  CreatureID  ID ,  ui32  amount ,  si32  level = - 1 ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-16 14:03:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  upgradeCreature ( const  CArmedInstance  * obj ,  SlotID  stackPos ,  CreatureID  newID = CreatureID : : NONE ) = 0 ;  //if newID==-1 then best possible upgrade will be made
 
							 
						 
					
						
							
								
									
										
										
										
											2009-08-03 19:22:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  swapGarrisonHero ( const  CGTownInstance  * town ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-19 21:43:50 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  trade ( const  IMarket  *  market ,  EMarketMode  mode ,  ui32  id1 ,  ui32  id2 ,  ui32  val1 ,  const  CGHeroInstance  *  hero  =  nullptr ) = 0 ;  //mode==0: sell val1 units of id1 resource for id2 resiurce
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  trade ( const  IMarket  *  market ,  EMarketMode  mode ,  const  std : : vector < ui32 >  &  id1 ,  const  std : : vector < ui32 >  &  id2 ,  const  std : : vector < ui32 >  &  val1 ,  const  CGHeroInstance  *  hero  =  nullptr ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 10:53:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  int  selectionMade ( int  selection ,  QueryID  queryID )  = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-06 07:53:51 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  int  sendQueryReply ( const  JsonNode  &  reply ,  QueryID  queryID )  = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-16 14:03:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									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
 
							 
						 
					
						
							
								
									
										
										
										
											2012-01-30 16:07:52 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
 
							 
						 
					
						
							
								
									
										
										
										
											2012-04-14 02:20:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  swapArtifacts ( const  ArtifactLocation  & l1 ,  const  ArtifactLocation  & l2 ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-16 14:03:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  assembleArtifacts ( const  CGHeroInstance  *  hero ,  ArtifactPosition  artifactSlot ,  bool  assemble ,  ArtifactID  assembleTo ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-08 00:41:55 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  eraseArtifactByClient ( const  ArtifactLocation  &  al ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-16 14:03:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  dismissCreature ( const  CArmedInstance  * obj ,  SlotID  stackPos ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  endTurn ( ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-10 23:24:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									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)
 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  setFormation ( const  CGHeroInstance  *  hero ,  bool  tight ) = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 03:14:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  save ( const  std : : string  & fname )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-21 20:35:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  sendMessage ( const  std : : string  & mess ,  const  CGObjectInstance  *  currentObject  =  nullptr )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-26 03:33:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  buildBoat ( const  IShipyard  * obj )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-28 15:57:38 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// To implement high-level army management bulk actions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  int  bulkMoveArmy ( ObjectInstanceID  srcArmy ,  ObjectInstanceID  destArmy ,  SlotID  srcSlot )  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  int  bulkSplitStack ( ObjectInstanceID  armyId ,  SlotID  srcSlot ,  int  howMany  =  1 )  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  int  bulkSmartSplitStack ( ObjectInstanceID  armyId ,  SlotID  srcSlot )  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  int  bulkMergeStacks ( ObjectInstanceID  armyId ,  SlotID  srcSlot )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-06 23:41:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Moves all artifacts from one hero to another
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-11 01:01:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  bulkMoveArtifacts ( ObjectInstanceID  srcHero ,  ObjectInstanceID  dstHero ,  bool  swap )  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-08-26 09:07:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CBattleCallback  :  public  IBattleCallback ,  public  CPlayerBattleCallback  
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								protected :  
						 
					
						
							
								
									
										
										
										
											2018-01-05 20:21:07 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  sendRequest ( const  CPackForServer  *  request ) ;  //returns requestID (that'll be matched to requestID in PackageApplied)
 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CClient  * cl ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2023-04-16 20:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CBattleCallback ( std : : optional < PlayerColor >  Player ,  CClient  *  C ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-18 19:55:59 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  battleMakeSpellAction ( const  BattleAction  &  action )  override ; //for casting spells by hero - DO NOT use it for moving active stack
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  battleMakeUnitAction ( const  BattleAction  &  action )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  battleMakeTacticAction ( const  BattleAction  &  action )  override ;  // performs tactic phase actions
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-16 20:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									std : : optional < BattleAction >  makeSurrenderRetreatDecision ( const  BattleStateInfoForRetreat  &  battleState )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-12 15:46:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 19:31:14 +03: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 17:58:30 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									scripting : : Pool  *  getContextPool ( )  const  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 19:31:14 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
											
												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 17:58:30 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-02-06 17:26:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									friend  class  CCallback ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									friend  class  CClient ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-28 15:57:38 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CCallback  :  public  CPlayerSpecificInfoCallback ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  IGameActionCallback , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  CBattleCallback 
							 
						 
					
						
							
								
									
										
										
										
											2010-12-22 20:14:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2023-04-16 20:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CCallback ( CGameState  *  GS ,  std : : optional < PlayerColor >  Player ,  CClient  *  C ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-02-12 15:46:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  ~ CCallback ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-03-06 16:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-05-29 23:49:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//client-specific functionalities (pathfinding)
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-15 19:39:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  canMoveBetween ( const  int3  & a ,  const  int3  & b ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-21 16:42:08 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  int3  getGuardingCreaturePosition ( int3  tile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-15 06:00:00 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  std : : shared_ptr < const  CPathsInfo >  getPathsInfo ( const  CGHeroInstance  *  h ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-02-26 18:31:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-22 18:22:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//Set of metrhods that allows adding more interfaces for this player that'll receive game event call-ins.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-29 05:43:33 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  registerBattleInterface ( std : : shared_ptr < IBattleEventsReceiver >  battleEvents ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  unregisterBattleInterface ( std : : shared_ptr < IBattleEventsReceiver >  battleEvents ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-07-15 15:34:00 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//commands
  
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  moveHero ( const  CGHeroInstance  * h ,  int3  dst ,  bool  transit  =  false )  override ;  //dst must be free, neighbouring tile (this function can move hero only by one tile)
 
							 
						 
					
						
							
								
									
										
										
										
											2010-06-30 19:27:35 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  teleportHero ( const  CGHeroInstance  * who ,  const  CGTownInstance  * where ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  selectionMade ( int  selection ,  QueryID  queryID )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-06 07:53:51 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  sendQueryReply ( const  JsonNode  &  reply ,  QueryID  queryID )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  swapCreatures ( const  CArmedInstance  * s1 ,  const  CArmedInstance  * s2 ,  SlotID  p1 ,  SlotID  p2 )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  mergeOrSwapStacks ( const  CArmedInstance  * s1 ,  const  CArmedInstance  * s2 ,  SlotID  p1 ,  SlotID  p2 )  override ;  //first goes to the second
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  mergeStacks ( const  CArmedInstance  * s1 ,  const  CArmedInstance  * s2 ,  SlotID  p1 ,  SlotID  p2 )  override ;  //first goes to the second
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  splitStack ( const  CArmedInstance  * s1 ,  const  CArmedInstance  * s2 ,  SlotID  p1 ,  SlotID  p2 ,  int  val )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-28 15:57:38 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  bulkMoveArmy ( ObjectInstanceID  srcArmy ,  ObjectInstanceID  destArmy ,  SlotID  srcSlot )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  bulkSplitStack ( ObjectInstanceID  armyId ,  SlotID  srcSlot ,  int  howMany  =  1 )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  bulkSmartSplitStack ( ObjectInstanceID  armyId ,  SlotID  srcSlot )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  bulkMergeStacks ( ObjectInstanceID  armyId ,  SlotID  srcSlot )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  dismissHero ( const  CGHeroInstance  *  hero )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  swapArtifacts ( const  ArtifactLocation  & l1 ,  const  ArtifactLocation  & l2 )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  assembleArtifacts ( const  CGHeroInstance  *  hero ,  ArtifactPosition  artifactSlot ,  bool  assemble ,  ArtifactID  assembleTo )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-11 01:01:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  bulkMoveArtifacts ( ObjectInstanceID  srcHero ,  ObjectInstanceID  dstHero ,  bool  swap )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-08 00:41:55 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  eraseArtifactByClient ( const  ArtifactLocation  &  al )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-26 11:18:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  buildBuilding ( const  CGTownInstance  * town ,  BuildingID  buildingID )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  recruitCreatures ( const  CGDwelling  *  obj ,  const  CArmedInstance  *  dst ,  CreatureID  ID ,  ui32  amount ,  si32  level = - 1 )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  dismissCreature ( const  CArmedInstance  * obj ,  SlotID  stackPos )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-26 11:18:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  upgradeCreature ( const  CArmedInstance  * obj ,  SlotID  stackPos ,  CreatureID  newID = CreatureID : : NONE )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  endTurn ( )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  swapGarrisonHero ( const  CGTownInstance  * town )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-26 11:18:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  buyArtifact ( const  CGHeroInstance  * hero ,  ArtifactID  aid )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-19 21:43:50 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  trade ( const  IMarket  *  market ,  EMarketMode  mode ,  ui32  id1 ,  ui32  id2 ,  ui32  val1 ,  const  CGHeroInstance  *  hero  =  nullptr )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  trade ( const  IMarket  *  market ,  EMarketMode  mode ,  const  std : : vector < ui32 >  &  id1 ,  const  std : : vector < ui32 >  &  id2 ,  const  std : : vector < ui32 >  &  val1 ,  const  CGHeroInstance  *  hero  =  nullptr )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-12 16:47:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  setFormation ( const  CGHeroInstance  *  hero ,  bool  tight )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  recruitHero ( const  CGObjectInstance  * townOrTavern ,  const  CGHeroInstance  * hero )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  save ( const  std : : string  & fname )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  sendMessage ( const  std : : string  & mess ,  const  CGObjectInstance  *  currentObject  =  nullptr )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  buildBoat ( const  IShipyard  * obj )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  dig ( const  CGObjectInstance  * hero )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  castSpell ( const  CGHeroInstance  * hero ,  SpellID  spellID ,  const  int3  & pos  =  int3 ( - 1 ,  - 1 ,  - 1 ) )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-16 11:14:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//friends
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									friend  class  CClient ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;