2011-12-14 00:23:17 +03:00
# pragma once
2009-04-16 14:14:13 +03:00
2010-12-19 16:39:56 +02:00
# include "../lib/ConstTransitivePtr.h"
2011-12-14 00:23:17 +03:00
# include "int3.h"
# include "GameConstants.h"
2013-01-15 17:20:48 +03:00
# include "HeroBonus.h"
2009-05-14 07:49:04 +03:00
2009-04-15 17:03:31 +03:00
/*
* CSpellHandler . 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 14:14:13 +03:00
*/
2012-08-25 11:44:51 +03:00
class CLegacyConfigParser ;
2012-05-18 23:50:16 +03:00
struct BattleHex ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CSpell
2009-04-16 14:14:13 +03:00
{
public :
2011-02-21 18:53:23 +02:00
enum ETargetType { NO_TARGET , CREATURE , CREATURE_EXPERT_MASSIVE , OBSTACLE } ;
2012-02-17 00:19:07 +03:00
enum ESpellPositiveness { NEGATIVE = - 1 , NEUTRAL = 0 , POSITIVE = 1 } ;
2013-02-11 02:24:57 +03:00
SpellID id ;
2012-12-18 13:32:11 +03:00
std : : string identifier ;
2009-04-16 14:14:13 +03:00
std : : string name ;
std : : string abbName ; //abbreviated name
std : : vector < std : : string > descriptions ; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc
si32 level ;
bool earth ;
bool water ;
bool fire ;
bool air ;
si32 power ; //spell's power
std : : vector < si32 > costs ; //per skill level: 0 - none, 1 - basic, etc
std : : vector < si32 > powers ; //[er skill level: 0 - none, 1 - basic, etc
2012-12-18 13:32:11 +03:00
std : : map < TFaction , si32 > probabilities ; //% chance to gain for castles
2009-04-16 14:14:13 +03:00
std : : vector < si32 > AIVals ; //AI values: per skill level: 0 - none, 1 - basic, etc
2013-02-13 22:35:43 +03:00
2009-04-16 14:14:13 +03:00
bool combatSpell ; //is this spell combat (true) or adventure (false)
bool creatureAbility ; //if true, only creatures can use this spell
si8 positiveness ; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
std : : vector < std : : string > range ; //description of spell's range in SRSL by magic school level
2013-02-11 02:24:57 +03:00
std : : vector < SpellID > counteredSpells ; //spells that are removed when effect of this spell is placed on creature (for bless-curse, haste-slow, and similar pairs)
2012-09-14 02:41:03 +03:00
2013-01-15 17:20:48 +03:00
CSpell ( ) ;
2013-04-21 19:38:31 +03:00
~ CSpell ( ) ;
2013-01-15 17:20:48 +03:00
2012-05-18 23:50:16 +03:00
std : : vector < BattleHex > rangeInHexes ( BattleHex centralHex , ui8 schoolLvl , ui8 side , bool * outDroppedHexes = NULL ) const ; //convert range to specific hexes; last optional out parameter is set to true, if spell would cover unavailable hexes (that are not included in ret)
2009-04-22 13:03:13 +03:00
si16 mainEffectAnim ; //main spell effect animation, in AC format (or -1 when none)
2011-02-21 18:53:23 +02:00
ETargetType getTargetType ( ) const ;
2009-04-16 14:14:13 +03:00
2013-02-02 20:20:31 +03:00
inline bool isCombatSpell ( ) const ;
inline bool isAdventureSpell ( ) const ;
inline bool isCreatureAbility ( ) const ;
inline bool isPositive ( ) const ;
inline bool isNegative ( ) const ;
inline bool isRisingSpell ( ) const ;
inline bool isDamageSpell ( ) const ;
inline bool isOffensiveSpell ( ) const ;
inline bool hasEffects ( ) const ;
2013-01-16 14:19:04 +03:00
void getEffects ( std : : vector < Bonus > & lst , const int level ) const ;
2013-01-15 17:20:48 +03:00
2013-01-16 14:19:04 +03:00
bool isImmuneBy ( const IBonusBearer * obj ) const ;
2012-02-17 00:19:07 +03:00
2013-02-13 22:35:43 +03:00
/**
* Returns resource name of icon for SPELL_IMMUNITY bonus
*/
inline const std : : string & getIconImmune ( ) const ;
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-12-18 13:32:11 +03:00
h & identifier & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
2012-09-14 02:41:03 +03:00
& powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range & counteredSpells & mainEffectAnim ;
2013-02-13 22:35:43 +03:00
h & isRising & isDamage & isOffensive ;
h & targetType ;
2013-01-16 14:19:04 +03:00
h & effects & immunities & limiters ;
2013-02-13 22:35:43 +03:00
h & iconImmune ;
2009-04-16 14:14:13 +03:00
}
2013-01-15 17:20:48 +03:00
friend class CSpellHandler ;
private :
2013-02-13 22:35:43 +03:00
2013-01-16 14:19:04 +03:00
bool isRising ;
bool isDamage ;
bool isOffensive ;
2013-01-15 17:20:48 +03:00
2013-02-13 22:35:43 +03:00
std : : string attributes ; //reference only attributes
void setAttributes ( const std : : string & newValue ) ;
ETargetType targetType ;
2013-04-21 19:38:31 +03:00
std : : vector < std : : vector < Bonus * > > effects ; // [level 0-3][list of effects]
2013-02-13 22:35:43 +03:00
std : : vector < Bonus : : BonusType > immunities ; //any of these grants immunity
std : : vector < Bonus : : BonusType > limiters ; //all of them are required to be affected
2013-02-02 20:20:31 +03:00
2013-02-13 22:35:43 +03:00
///graphics related stuff
2013-01-15 17:20:48 +03:00
2013-02-13 22:35:43 +03:00
std : : string iconImmune ;
2009-04-16 14:14:13 +03:00
} ;
2013-02-02 20:20:31 +03:00
///CSpell inlines
bool CSpell : : isCombatSpell ( ) const
{
return combatSpell ;
}
bool CSpell : : isAdventureSpell ( ) const
{
return ! combatSpell ;
}
bool CSpell : : isCreatureAbility ( ) const
{
return creatureAbility ;
}
bool CSpell : : isPositive ( ) const
{
return positiveness = = POSITIVE ;
}
bool CSpell : : isNegative ( ) const
{
return positiveness = = NEGATIVE ;
}
bool CSpell : : isRisingSpell ( ) const
{
return isRising ;
}
bool CSpell : : isDamageSpell ( ) const
{
return isDamage ;
}
bool CSpell : : isOffensiveSpell ( ) const
{
return isOffensive ;
}
bool CSpell : : hasEffects ( ) const
{
2013-04-23 12:54:57 +03:00
return effects . size ( ) ;
2013-02-02 20:20:31 +03:00
}
2013-02-13 22:35:43 +03:00
const std : : string & CSpell : : getIconImmune ( ) const
{
return iconImmune ;
}
2011-12-14 00:23:17 +03:00
bool DLL_LINKAGE isInScreenRange ( const int3 & center , const int3 & pos ) ; //for spells like Dimension Door
2010-03-21 00:17:19 +02:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CSpellHandler
2009-04-16 14:14:13 +03:00
{
2013-02-13 22:35:43 +03:00
CSpell * loadSpell ( CLegacyConfigParser & parser , const SpellID id ) ;
2012-08-25 11:44:51 +03:00
2009-04-16 14:14:13 +03:00
public :
2009-09-25 06:21:56 +03:00
CSpellHandler ( ) ;
2013-04-21 19:38:31 +03:00
~ CSpellHandler ( ) ;
2010-12-19 16:39:56 +02:00
std : : vector < ConstTransitivePtr < CSpell > > spells ;
2013-01-15 17:20:48 +03:00
2013-01-06 22:30:12 +03:00
/**
* Gets a list of default allowed spells . OH3 spells are all allowed by default .
*
* @ return a list of allowed spells , the index is the spell id and the value either 0 for not allowed or 1 for allowed
*/
2013-04-21 15:49:26 +03:00
std : : vector < bool > getDefaultAllowed ( ) const ;
2013-01-06 22:30:12 +03:00
2009-04-16 14:14:13 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2013-01-15 17:20:48 +03:00
h & spells ;
2009-04-16 14:14:13 +03:00
}
} ;