2022-11-20 19:11:34 +02:00
/*
* CBattleStacksController . 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
*
*/
# pragma once
2022-11-27 02:26:02 +02:00
# include "../gui/Geometries.h"
2022-11-29 02:00:08 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2022-11-20 19:11:34 +02:00
struct BattleHex ;
2022-11-29 02:00:08 +02:00
class BattleAction ;
class CStack ;
class SpellID ;
VCMI_LIB_NAMESPACE_END
struct SDL_Surface ;
2022-11-20 19:11:34 +02:00
struct StackAttackedInfo ;
2022-11-26 23:12:20 +02:00
class CCanvas ;
2022-11-20 19:11:34 +02:00
class CBattleInterface ;
class CBattleAnimation ;
class CCreatureAnimation ;
class CBattleAnimation ;
2022-12-06 13:41:29 +02:00
class CBattleRenderer ;
2022-11-25 00:26:14 +02:00
class IImage ;
2022-11-20 19:11:34 +02:00
class CBattleStacksController
{
CBattleInterface * owner ;
2022-11-25 00:26:14 +02:00
std : : shared_ptr < IImage > amountNormal ;
std : : shared_ptr < IImage > amountNegative ;
std : : shared_ptr < IImage > amountPositive ;
std : : shared_ptr < IImage > amountEffNeutral ;
2022-11-20 19:11:34 +02:00
2022-11-28 16:02:46 +02:00
std : : vector < CBattleAnimation * > currentAnimations ; //currently displayed animations <anim, initialized>
std : : map < int32_t , std : : shared_ptr < CCreatureAnimation > > stackAnimation ; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
std : : map < int , bool > stackFacingRight ; // <creatureID, if false reverse creature's animation> //TODO: move it to battle callback
2022-11-20 19:11:34 +02:00
const CStack * activeStack ; //number of active stack; nullptr - no one
const CStack * mouseHoveredStack ; // stack below mouse pointer, used for border animation
const CStack * stackToActivate ; //when animation is playing, we should wait till the end to make the next stack active; nullptr of none
const CStack * selectedStack ; //for Teleport / Sacrifice
bool stackCanCastSpell ; //if true, active stack could possibly cast some target spell
si32 creatureSpellToCast ;
ui32 animIDhelper ; //for giving IDs for animations
2022-11-25 00:26:14 +02:00
bool stackNeedsAmountBox ( const CStack * stack ) ;
2022-11-26 23:12:20 +02:00
void showStackAmountBox ( std : : shared_ptr < CCanvas > canvas , const CStack * stack ) ;
2022-12-02 17:49:38 +02:00
BattleHex getStackCurrentPosition ( const CStack * stack ) ;
2022-11-26 23:12:20 +02:00
std : : shared_ptr < IImage > getStackAmountBox ( const CStack * stack ) ;
2022-11-25 00:26:14 +02:00
2022-11-20 19:11:34 +02:00
public :
CBattleStacksController ( CBattleInterface * owner ) ;
bool shouldRotate ( const CStack * stack , const BattleHex & oldPos , const BattleHex & nextHex ) ;
bool facingRight ( const CStack * stack ) ;
void stackReset ( const CStack * stack ) ;
void stackAdded ( const CStack * stack ) ; //new stack appeared on battlefield
void stackRemoved ( uint32_t stackID ) ; //stack disappeared from batlefiled
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
void stacksAreAttacked ( std : : vector < StackAttackedInfo > attackedInfos ) ; //called when a certain amount of stacks has been attacked
void stackAttacking ( const CStack * attacker , BattleHex dest , const CStack * attacked , bool shooting ) ; //called when stack with id ID is attacking something on hex dest
void startAction ( const BattleAction * action ) ;
void endAction ( const BattleAction * action ) ;
bool activeStackSpellcaster ( ) ;
SpellID activeStackSpellToCast ( ) ;
void activateStack ( ) ; //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
void setActiveStack ( const CStack * stack ) ;
void setHoveredStack ( const CStack * stack ) ;
void setSelectedStack ( const CStack * stack ) ;
2022-11-26 23:12:20 +02:00
void showAliveStack ( std : : shared_ptr < CCanvas > canvas , const CStack * stack ) ;
void showStack ( std : : shared_ptr < CCanvas > canvas , const CStack * stack ) ;
2022-11-25 00:26:14 +02:00
2022-12-06 13:41:29 +02:00
void collectRenderableObjects ( CBattleRenderer & renderer ) ;
2022-11-20 19:11:34 +02:00
void addNewAnim ( CBattleAnimation * anim ) ; //adds new anim to pendingAnims
void updateBattleAnimations ( ) ;
const CStack * getActiveStack ( ) ;
const CStack * getSelectedStack ( ) ;
2022-11-27 02:26:02 +02:00
/// returns position of animation needed to place stack in specific hex
Point getStackPositionAtHex ( BattleHex hexNum , const CStack * creature ) ;
2022-11-20 19:11:34 +02:00
friend class CBattleAnimation ; // for exposing pendingAnims/creAnims/creDir to animations
} ;