2011-12-13 21:35:28 +00:00
/*
* CBattleInterface . 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
*
*/
2017-07-13 11:26:03 +03:00
# pragma once
2022-11-24 16:30:04 +02:00
# include "../gui/CIntObject.h"
2017-07-13 11:26:03 +03:00
# include "../../lib/spells/CSpellHandler.h" //CSpell::TAnimation
2011-12-13 21:35:28 +00:00
2022-07-26 16:07:42 +03:00
VCMI_LIB_NAMESPACE_BEGIN
2011-12-13 21:35:28 +00:00
class CCreatureSet ;
class CGHeroInstance ;
class CStack ;
struct BattleResult ;
struct BattleSpellCast ;
struct CObstacleInstance ;
template < typename T > struct CondSh ;
2012-09-15 19:16:16 +00:00
struct SetStackEffect ;
2017-07-20 07:08:49 +03:00
class BattleAction ;
2011-12-13 21:35:28 +00:00
class CGTownInstance ;
struct CatapultAttack ;
struct BattleTriggerEffect ;
2022-07-26 16:07:42 +03:00
struct BattleHex ;
struct InfoAboutHero ;
struct CustomEffectInfo ;
VCMI_LIB_NAMESPACE_END
2011-12-13 21:35:28 +00:00
class CBattleHero ;
2022-11-26 23:12:20 +02:00
class CCanvas ;
2011-12-13 21:35:28 +00:00
class CBattleResultWindow ;
class CStackQueue ;
2011-12-17 18:59:59 +00:00
class CPlayerInterface ;
2011-12-22 13:05:19 +00:00
class CClickableHex ;
2017-09-05 17:21:44 +03:00
class CAnimation ;
2022-11-24 16:30:04 +02:00
struct BattleEffect ;
2017-07-20 07:08:49 +03:00
class IImage ;
2022-11-29 14:59:50 +02:00
class CStackQueue ;
2011-12-13 21:35:28 +00:00
2022-11-17 13:21:03 +02:00
class CBattleProjectileController ;
2022-11-17 18:50:12 +02:00
class CBattleSiegeController ;
2022-11-17 19:36:25 +02:00
class CBattleObstacleController ;
2022-11-17 23:57:51 +02:00
class CBattleFieldController ;
2022-11-18 17:54:10 +02:00
class CBattleControlPanel ;
2022-11-20 19:11:34 +02:00
class CBattleStacksController ;
2022-11-20 22:56:42 +02:00
class CBattleActionsController ;
2022-11-24 16:30:04 +02:00
class CBattleEffectsController ;
2022-11-17 13:21:03 +02:00
2011-12-22 13:05:19 +00:00
/// Small struct which contains information about the id of the attacked stack, the damage dealt,...
struct StackAttackedInfo
{
2016-10-28 23:37:20 +02:00
const CStack * defender ; //attacked stack
2017-07-20 07:08:49 +03:00
int64_t dmg ; //damage dealt
2012-04-08 10:34:23 +00:00
unsigned int amountKilled ; //how many creatures in stack has been killed
2016-10-28 23:37:20 +02:00
const CStack * attacker ; //attacking stack
2013-08-09 17:37:41 +00:00
bool indirectAttack ; //if true, stack was attacked indirectly - spell or ranged attack
2011-12-22 13:05:19 +00:00
bool killed ; //if true, stack has been killed
bool rebirth ; //if true, play rebirth animation after all
2012-02-18 17:39:47 +00:00
bool cloneKilled ;
2011-12-22 13:05:19 +00:00
} ;
2011-12-13 21:35:28 +00:00
/// Big class which handles the overall battle interface actions and it is also responsible for
/// drawing everything correctly.
2018-07-25 01:36:48 +03:00
class CBattleInterface : public WindowBase
2011-12-13 21:35:28 +00:00
{
private :
2018-07-25 01:36:48 +03:00
std : : shared_ptr < CBattleHero > attackingHero ;
std : : shared_ptr < CBattleHero > defendingHero ;
std : : shared_ptr < CStackQueue > queue ;
2022-11-18 17:54:10 +02:00
std : : shared_ptr < CBattleControlPanel > controlPanel ;
2018-07-25 01:36:48 +03:00
2022-11-20 19:11:34 +02:00
std : : shared_ptr < CPlayerInterface > tacticianInterface ; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players
std : : shared_ptr < CPlayerInterface > attackerInt , defenderInt ; //because LOCPLINT is not enough in hotSeat
std : : shared_ptr < CPlayerInterface > curInt ; //current player interface
2011-12-13 21:35:28 +00:00
const CCreatureSet * army1 , * army2 ; //copy of initial armies (for result window)
2016-10-28 23:37:20 +02:00
const CGHeroInstance * attackingHeroInstance , * defendingHeroInstance ;
2017-09-05 20:04:17 +03:00
2011-12-13 21:35:28 +00:00
ui8 animCount ;
bool tacticsMode ;
2019-03-22 21:39:53 +01:00
bool battleActionsStarted ; //used for delaying battle actions until intro sound stops
2019-03-23 12:12:25 +01:00
int battleIntroSoundChannel ; //required as variable for disabling it via ESC key
2012-04-04 08:03:52 +00:00
2022-11-20 19:11:34 +02:00
void trySetActivePlayer ( PlayerColor player ) ; // if in hotseat, will activate interface of chosen player
void activateStack ( ) ; //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
2013-06-22 21:47:51 +00:00
void requestAutofightingAIToTakeAction ( ) ;
2013-06-22 14:47:20 +00:00
2017-07-20 07:08:49 +03:00
void giveCommand ( EActionType action , BattleHex tile = BattleHex ( ) , si32 additional = - 1 ) ;
void sendCommand ( BattleAction * & command , const CStack * actor = nullptr ) ;
2016-10-28 23:37:20 +02:00
const CGHeroInstance * getActiveHero ( ) ; //returns hero that can currently cast a spell
2013-07-19 16:35:16 +00:00
2022-11-27 02:26:02 +02:00
void showInterface ( std : : shared_ptr < CCanvas > canvas ) ;
2013-07-19 16:35:16 +00:00
2022-11-27 02:26:02 +02:00
void showBattlefieldObjects ( std : : shared_ptr < CCanvas > canvas ) ;
2022-11-26 23:12:20 +02:00
void showBattlefieldObjects ( std : : shared_ptr < CCanvas > canvas , const BattleHex & location ) ;
2013-07-19 16:35:16 +00:00
2017-09-27 17:35:30 +03:00
void setHeroAnimation ( ui8 side , int phase ) ;
2011-12-13 21:35:28 +00:00
public :
2022-11-17 13:21:03 +02:00
std : : unique_ptr < CBattleProjectileController > projectilesController ;
2022-11-17 18:50:12 +02:00
std : : unique_ptr < CBattleSiegeController > siegeController ;
2022-11-17 19:36:25 +02:00
std : : unique_ptr < CBattleObstacleController > obstacleController ;
2022-11-17 23:57:51 +02:00
std : : unique_ptr < CBattleFieldController > fieldController ;
2022-11-20 19:11:34 +02:00
std : : unique_ptr < CBattleStacksController > stacksController ;
2022-11-20 22:56:42 +02:00
std : : unique_ptr < CBattleActionsController > actionsController ;
2022-11-24 16:30:04 +02:00
std : : unique_ptr < CBattleEffectsController > effectsController ;
2022-11-17 13:21:03 +02:00
2017-06-14 04:53:26 +03:00
static CondSh < bool > animsAreDisplayed ; //for waiting with the end of battle for end of anims
static CondSh < BattleAction * > givenCommand ; //data != nullptr if we have i.e. moved current unit
2022-11-20 19:11:34 +02:00
bool myTurn ; //if true, interface is active (commands can be ordered)
bool moveStarted ; //if true, the creature that is already moving is going to make its first step
int moveSoundHander ; // sound handler used when moving a unit
const BattleResult * bresult ; //result of a battle; if non-zero then display when all animations end
2011-12-13 21:35:28 +00:00
2017-07-18 00:04:00 +03:00
CBattleInterface ( const CCreatureSet * army1 , const CCreatureSet * army2 , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , const SDL_Rect & myRect , std : : shared_ptr < CPlayerInterface > att , std : : shared_ptr < CPlayerInterface > defen , std : : shared_ptr < CPlayerInterface > spectatorInt = nullptr ) ;
virtual ~ CBattleInterface ( ) ;
2011-12-13 21:35:28 +00:00
void setPrintCellBorders ( bool set ) ; //if true, cell borders will be printed
void setPrintStackRange ( bool set ) ; //if true,range of active stack will be printed
void setPrintMouseShadow ( bool set ) ; //if true, hex under mouse will be shaded
2013-07-06 16:10:20 +00:00
void setAnimSpeed ( int set ) ; //speed of animation; range 1..100
int getAnimSpeed ( ) const ; //speed of animation; range 1..100
2016-10-28 23:37:20 +02:00
CPlayerInterface * getCurrentPlayerInterface ( ) const ;
2013-06-23 19:35:54 +00:00
2022-11-18 17:54:10 +02:00
void tacticNextStack ( const CStack * current ) ;
void tacticPhaseEnd ( ) ;
2022-11-20 19:11:34 +02:00
void waitForAnims ( ) ;
2022-11-18 17:54:10 +02:00
2011-12-13 21:35:28 +00:00
//napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
2015-10-12 16:47:10 +03:00
void activate ( ) override ;
void deactivate ( ) override ;
void keyPressed ( const SDL_KeyboardEvent & key ) override ;
void mouseMoved ( const SDL_MouseMotionEvent & sEvent ) override ;
void clickRight ( tribool down , bool previousState ) override ;
void show ( SDL_Surface * to ) override ;
void showAll ( SDL_Surface * to ) override ;
2013-07-19 16:35:16 +00:00
2011-12-13 21:35:28 +00:00
//call-ins
void startAction ( const BattleAction * action ) ;
2022-11-20 19:11:34 +02:00
void stackReset ( const CStack * stack ) ;
void stackAdded ( const CStack * stack ) ; //new stack appeared on battlefield
2017-07-20 07:08:49 +03:00
void stackRemoved ( uint32_t stackID ) ; //stack disappeared from batlefiled
2016-10-28 23:37:20 +02:00
void stackActivated ( const CStack * stack ) ; //active stack has been changed
void stackMoved ( const CStack * stack , std : : vector < BattleHex > destHex , int distance ) ; //stack with id number moved to destHex
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
void stacksAreAttacked ( std : : vector < StackAttackedInfo > attackedInfos ) ; //called when a certain amount of stacks has been attacked
2016-10-28 23:37:20 +02:00
void stackAttacking ( const CStack * attacker , BattleHex dest , const CStack * attacked , bool shooting ) ; //called when stack with id ID is attacking something on hex dest
2011-12-13 21:35:28 +00:00
void newRoundFirst ( int round ) ;
void newRound ( int number ) ; //caled when round is ended; number is the number of round
void hexLclicked ( int whichOne ) ; //hex only call-in
void stackIsCatapulting ( const CatapultAttack & ca ) ; //called when a stack is attacking walls
void battleFinished ( const BattleResult & br ) ; //called when battle is finished - battleresult window should be printed
void displayBattleFinished ( ) ; //displays battle result
2016-10-28 23:37:20 +02:00
void spellCast ( const BattleSpellCast * sc ) ; //called when a hero casts a spell
2011-12-13 21:35:28 +00:00
void battleStacksEffectsSet ( const SetStackEffect & sse ) ; //called when a specific effect is set to stacks
2015-01-30 09:39:36 +03:00
void castThisSpell ( SpellID spellID ) ; //called when player has chosen a spell from spellbook
2017-07-20 07:08:49 +03:00
void displayBattleLog ( const std : : vector < MetaString > & battleLog ) ;
2016-03-01 08:16:02 +03:00
2021-02-20 04:57:50 +03:00
void displaySpellAnimationQueue ( const CSpell : : TAnimationQueue & q , BattleHex destinationTile ) ;
2016-09-10 18:56:38 +03:00
void displaySpellCast ( SpellID spellID , BattleHex destinationTile ) ; //displays spell`s cast animation
void displaySpellEffect ( SpellID spellID , BattleHex destinationTile ) ; //displays spell`s affected animation
void displaySpellHit ( SpellID spellID , BattleHex destinationTile ) ; //displays spell`s affected animation
2016-03-01 08:16:02 +03:00
2011-12-13 21:35:28 +00:00
void endAction ( const BattleAction * action ) ;
void hideQueue ( ) ;
void showQueue ( ) ;
2016-03-04 17:53:09 +03:00
2022-12-01 22:06:42 +02:00
void obstaclePlaced ( const std : : vector < std : : shared_ptr < const CObstacleInstance > > oi ) ;
2012-05-04 21:16:39 +00:00
2016-02-13 17:40:31 +03:00
void gateStateChanged ( const EGateState state ) ;
2016-02-10 07:10:32 +03:00
2016-10-28 23:37:20 +02:00
const CGHeroInstance * currentHero ( ) const ;
2012-08-26 09:07:48 +00:00
InfoAboutHero enemyHero ( ) const ;
2011-12-13 21:35:28 +00:00
friend class CPlayerInterface ;
friend class CInGameConsole ;
2022-11-29 14:59:50 +02:00
friend class CStackQueue ;
2011-12-13 21:35:28 +00:00
friend class CBattleResultWindow ;
friend class CBattleHero ;
friend class CBattleStackAnimation ;
friend class CReverseAnimation ;
friend class CDefenceAnimation ;
friend class CMovementAnimation ;
friend class CMovementStartAnimation ;
friend class CAttackAnimation ;
friend class CMeleeAttackAnimation ;
friend class CShootingAnimation ;
2017-09-08 14:25:12 +03:00
friend class CCastAnimation ;
2011-12-17 18:59:59 +00:00
friend class CClickableHex ;
2022-11-17 13:21:03 +02:00
friend class CBattleProjectileController ;
2022-11-17 18:50:12 +02:00
friend class CBattleSiegeController ;
2022-11-17 19:36:25 +02:00
friend class CBattleObstacleController ;
2022-11-17 23:57:51 +02:00
friend class CBattleFieldController ;
2022-11-18 17:54:10 +02:00
friend class CBattleControlPanel ;
2022-11-20 19:11:34 +02:00
friend class CBattleStacksController ;
2022-11-20 22:56:42 +02:00
friend class CBattleActionsController ;
2022-11-24 16:30:04 +02:00
friend class CBattleEffectsController ;
2011-12-13 21:35:28 +00:00
} ;