2011-12-13 21:23:17 +00:00
# pragma once
2009-04-16 11:14:13 +00:00
2010-12-19 14:39:56 +00:00
# include "../lib/ConstTransitivePtr.h"
2011-12-13 21:23:17 +00:00
# include "int3.h"
# include "GameConstants.h"
2013-01-15 14:20:48 +00:00
# include "HeroBonus.h"
2009-05-14 04:49:04 +00:00
2009-04-15 14:03:31 +00: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 11:14:13 +00:00
*/
2012-08-25 08:44:51 +00:00
class CLegacyConfigParser ;
2012-05-18 20:50:16 +00:00
struct BattleHex ;
2011-12-13 21:23:17 +00:00
class DLL_LINKAGE CSpell
2009-04-16 11:14:13 +00:00
{
public :
2011-02-21 16:53:23 +00:00
enum ETargetType { NO_TARGET , CREATURE , CREATURE_EXPERT_MASSIVE , OBSTACLE } ;
2012-02-16 21:19:07 +00:00
enum ESpellPositiveness { NEGATIVE = - 1 , NEUTRAL = 0 , POSITIVE = 1 } ;
2012-08-26 09:07:48 +00:00
TSpell id ;
2012-12-18 10:32:11 +00:00
std : : string identifier ;
2009-04-16 11:14:13 +00: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 10:32:11 +00:00
std : : map < TFaction , si32 > probabilities ; //% chance to gain for castles
2009-04-16 11:14:13 +00:00
std : : vector < si32 > AIVals ; //AI values: per skill level: 0 - none, 1 - basic, etc
std : : string attributes ; //reference only attributes
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
2012-09-13 23:41:03 +00:00
std : : vector < TSpell > counteredSpells ; //spells that are removed when effect of this spell is placed on creature (for bless-curse, haste-slow, and similar pairs)
2013-01-15 14:20:48 +00:00
CSpell ( ) ;
2012-05-18 20:50:16 +00: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 10:03:13 +00:00
si16 mainEffectAnim ; //main spell effect animation, in AC format (or -1 when none)
2011-02-21 16:53:23 +00:00
ETargetType getTargetType ( ) const ;
2009-04-16 11:14:13 +00:00
2013-02-02 17:20:31 +00: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 isMindSpell ( ) const ; //TODO: deprecated - remove, refactor
inline bool isOffensiveSpell ( ) const ;
inline bool hasEffects ( ) const ;
2013-01-16 11:19:04 +00:00
void getEffects ( std : : vector < Bonus > & lst , const int level ) const ;
2013-01-15 14:20:48 +00:00
2013-01-16 11:19:04 +00:00
bool isImmuneBy ( const IBonusBearer * obj ) const ;
2012-02-16 21:19:07 +00:00
2009-04-16 11:14:13 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-12-18 10:32:11 +00:00
h & identifier & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
2012-09-13 23:41:03 +00:00
& powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range & counteredSpells & mainEffectAnim ;
2013-01-16 11:19:04 +00:00
h & isRising & isDamage & isMind ;
h & effects & immunities & limiters ;
2009-04-16 11:14:13 +00:00
}
2013-01-15 14:20:48 +00:00
friend class CSpellHandler ;
private :
2013-01-16 11:19:04 +00:00
bool isRising ;
bool isDamage ;
bool isMind ;
bool isOffensive ;
2013-01-15 14:20:48 +00:00
2013-01-16 11:19:04 +00:00
std : : vector < Bonus > effects [ 4 ] ;
std : : vector < Bonus : : BonusType > immunities ; //any of these hrants immunity
std : : vector < Bonus : : BonusType > limiters ; //all of them are required
2013-02-02 17:20:31 +00:00
2013-01-15 14:20:48 +00:00
2009-04-16 11:14:13 +00:00
} ;
2013-02-02 17:20:31 +00: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 : : isMindSpell ( ) const
{
return isMind ;
}
bool CSpell : : isOffensiveSpell ( ) const
{
return isOffensive ;
}
bool CSpell : : hasEffects ( ) const
{
return ! effects [ 0 ] . empty ( ) ;
}
2011-12-13 21:23:17 +00:00
bool DLL_LINKAGE isInScreenRange ( const int3 & center , const int3 & pos ) ; //for spells like Dimension Door
2010-03-20 22:17:19 +00:00
2011-12-13 21:23:17 +00:00
class DLL_LINKAGE CSpellHandler
2009-04-16 11:14:13 +00:00
{
2012-08-25 08:44:51 +00:00
CSpell * loadSpell ( CLegacyConfigParser & parser ) ;
2009-04-16 11:14:13 +00:00
public :
2009-09-25 03:21:56 +00:00
CSpellHandler ( ) ;
2010-12-19 14:39:56 +00:00
std : : vector < ConstTransitivePtr < CSpell > > spells ;
2013-01-15 14:20:48 +00:00
2009-04-16 11:14:13 +00:00
void loadSpells ( ) ;
2013-01-06 19:30:12 +00: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-02-04 21:58:42 +00:00
std : : vector < bool > getDefaultAllowedSpells ( ) const ;
2013-01-06 19:30:12 +00:00
2009-04-16 11:14:13 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2013-01-15 14:20:48 +00:00
h & spells ;
2009-04-16 11:14:13 +00:00
}
} ;