2010-05-25 20:06:42 +02:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-12-14 08:40:48 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-05-25 20:06:42 +02:00
//
2011-01-10 06:44:45 +01:00
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
2010-05-25 20:06:42 +02:00
// License, or (at your option) any later version
// ==============================================================
# include "skill_type.h"
# include <cassert>
2014-09-29 02:55:15 +02:00
# include <iterator>
2010-05-25 20:06:42 +02:00
# include "sound.h"
# include "util.h"
# include "lang.h"
# include "renderer.h"
# include "particle_type.h"
# include "unit_particle_type.h"
2014-07-18 01:04:36 +02:00
# include "projectile_type.h"
2010-05-25 20:06:42 +02:00
# include "tech_tree.h"
# include "faction_type.h"
# include "leak_dumper.h"
using namespace Shared : : Util ;
using namespace Shared : : Graphics ;
namespace Glest { namespace Game {
2011-11-11 05:17:55 +01:00
int SkillType : : nextAttackBoostId = 0 ;
2011-06-25 10:53:53 +02:00
2013-05-17 05:59:34 +02:00
AttackBoost : : AttackBoost ( ) : boostUpgrade ( ) {
2011-06-25 22:44:46 +02:00
enabled = false ;
allowMultipleBoosts = false ;
radius = 0 ;
targetType = abtFaction ;
unitParticleSystemTypeForSourceUnit = NULL ;
unitParticleSystemTypeForAffectedUnit = NULL ;
2011-11-04 05:51:12 +01:00
includeSelf = false ;
2011-06-25 10:53:53 +02:00
}
2011-06-25 22:44:46 +02:00
AttackBoost : : ~ AttackBoost ( ) {
delete unitParticleSystemTypeForSourceUnit ;
unitParticleSystemTypeForSourceUnit = NULL ;
delete unitParticleSystemTypeForAffectedUnit ;
unitParticleSystemTypeForAffectedUnit = NULL ;
}
2011-06-25 10:53:53 +02:00
bool AttackBoost : : isAffected ( const Unit * source , const Unit * dest ) const {
bool result = false ;
2011-11-04 05:51:12 +01:00
if ( enabled = = true & &
source ! = NULL & & dest ! = NULL & &
( includeSelf = = true | | source ! = dest ) ) {
2011-06-25 22:44:46 +02:00
bool destUnitMightApply = false ;
2011-11-04 05:51:12 +01:00
if ( source = = dest & & includeSelf = = true ) {
destUnitMightApply = true ;
2011-06-25 10:53:53 +02:00
}
2011-11-04 05:51:12 +01:00
else {
// All units are affected (including enemies)
if ( targetType = = abtAll ) {
2014-12-19 19:40:34 +01:00
destUnitMightApply = ( boostUnitList . empty ( ) & & tags . empty ( ) ) | | isInUnitListOrTags ( dest - > getType ( ) ) ; ;
2011-06-25 22:44:46 +02:00
}
2011-11-04 05:51:12 +01:00
// Only same faction units are affected
else if ( targetType = = abtFaction ) {
if ( source - > getFactionIndex ( ) = = dest - > getFactionIndex ( ) ) {
2014-12-19 19:40:34 +01:00
destUnitMightApply = ( boostUnitList . empty ( ) & & tags . empty ( ) ) | | isInUnitListOrTags ( dest - > getType ( ) ) ;
2011-11-04 05:51:12 +01:00
}
}
// Only ally units are affected
else if ( targetType = = abtAlly ) {
if ( source - > isAlly ( dest ) = = true ) {
2014-12-19 19:40:34 +01:00
destUnitMightApply = ( boostUnitList . empty ( ) & & tags . empty ( ) ) | | isInUnitListOrTags ( dest - > getType ( ) ) ;
2011-06-25 22:44:46 +02:00
}
}
2011-11-04 05:51:12 +01:00
// Only foe units are affected
else if ( targetType = = abtFoe ) {
if ( source - > isAlly ( dest ) = = false ) {
2014-12-19 19:40:34 +01:00
destUnitMightApply = ( boostUnitList . empty ( ) & & tags . empty ( ) ) | | isInUnitListOrTags ( dest - > getType ( ) ) ;
2011-11-04 05:51:12 +01:00
}
}
else if ( targetType = = abtUnitTypes ) {
2014-09-29 02:23:36 +02:00
destUnitMightApply = isInUnitListOrTags ( dest - > getType ( ) ) ;
2011-06-25 10:53:53 +02:00
}
}
2011-06-25 22:44:46 +02:00
if ( destUnitMightApply = = true ) {
2013-10-03 02:17:51 +02:00
float distance = source - > getCenteredPos ( ) . dist ( dest - > getCenteredPos ( ) ) ;
2011-06-25 22:44:46 +02:00
if ( distance < = radius ) {
result = true ;
}
}
2011-06-25 10:53:53 +02:00
}
return result ;
}
2014-09-29 02:23:36 +02:00
bool AttackBoost : : isInUnitListOrTags ( const UnitType * unitType ) const {
// Specify which units are affected
std : : set < const UnitType * > : : iterator it ;
for ( it = boostUnitList . begin ( ) ; it ! = boostUnitList . end ( ) ; + + it ) {
const UnitType * boostUnit = * it ;
if ( unitType - > getId ( ) = = boostUnit - > getId ( ) ) {
return true ;
}
}
set < string > unitTags = unitType - > getTags ( ) ;
set < string > intersect ;
set_intersection ( tags . begin ( ) , tags . end ( ) , unitTags . begin ( ) , unitTags . end ( ) ,
std : : inserter ( intersect , intersect . begin ( ) ) ) ;
if ( ! intersect . empty ( ) ) return true ;
// Otherwise no match
return false ;
}
string AttackBoost : : getTagName ( string tag , bool translatedValue ) const {
if ( translatedValue = = false ) return tag ;
Lang & lang = Lang : : getInstance ( ) ;
return lang . getTechTreeString ( " TagName_ " + tag , tag . c_str ( ) ) ;
}
2013-06-13 10:55:48 +02:00
string AttackBoost : : getDesc ( bool translatedValue ) const {
2012-02-19 03:40:13 +01:00
Lang & lang = Lang : : getInstance ( ) ;
string str = " " ;
string indent = " " ;
2012-03-28 08:25:57 +02:00
if ( enabled ) {
if ( boostUnitList . empty ( ) = = false ) {
2013-10-29 07:13:38 +01:00
str + = " \n " + lang . getString ( " Effects " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
2013-10-29 07:13:38 +01:00
str + = indent + lang . getString ( " effectRadius " ) + " : " + intToStr ( radius ) + " \n " ;
2012-02-19 03:40:13 +01:00
if ( allowMultipleBoosts = = false ) {
2013-10-29 07:13:38 +01:00
string allowIt = lang . getString ( " No " ) ;
2012-02-19 03:40:13 +01:00
if ( allowMultipleBoosts = = true )
2013-10-29 07:13:38 +01:00
allowIt = lang . getString ( " False " ) ;
str + = indent + lang . getString ( " allowMultiBoost " ) + " : " + allowIt + " \n " ;
2012-02-19 03:40:13 +01:00
}
2013-06-13 10:55:48 +02:00
str + = boostUpgrade . getDesc ( translatedValue ) ;
2012-02-19 03:40:13 +01:00
if ( targetType = = abtAlly )
{
2013-10-29 07:13:38 +01:00
str + = lang . getString ( " AffectedUnitsFromTeam " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
else if ( targetType = = abtFoe )
{
2013-10-29 07:13:38 +01:00
str + = lang . getString ( " AffectedUnitsFromFoe " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
else if ( targetType = = abtFaction )
{
2013-10-29 07:13:38 +01:00
str + = lang . getString ( " AffectedUnitsFromYourFaction " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
else if ( targetType = = abtUnitTypes )
{
2013-10-29 07:13:38 +01:00
str + = lang . getString ( " AffectedUnitsFromAll " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
else if ( targetType = = abtAll )
{
2013-10-29 07:13:38 +01:00
str + = lang . getString ( " AffectedUnitsFromAll " ) + " : \n " ;
2012-02-19 03:40:13 +01:00
}
2014-09-29 02:23:36 +02:00
if ( boostUnitList . empty ( ) & & tags . empty ( ) ) {
str + = lang . getString ( " All " ) + " \n " ;
2012-02-19 03:40:13 +01:00
}
else
{
2014-09-29 02:23:36 +02:00
// We want the output to be sorted, so convert the set to a vector and sort that
std : : vector < const UnitType * > outputUnits ( boostUnitList . begin ( ) , boostUnitList . end ( ) ) ;
std : : sort ( outputUnits . begin ( ) , outputUnits . end ( ) , UnitTypeSorter ( ) ) ;
vector < const UnitType * > : : iterator unitIter ;
for ( unitIter = outputUnits . begin ( ) ; unitIter ! = outputUnits . end ( ) ; + + unitIter ) {
const UnitType * unit = * unitIter ;
str + = indent + unit - > getName ( translatedValue ) + " \n " ;
}
// Do the same for tags
std : : vector < string > outputTags ( tags . begin ( ) , tags . end ( ) ) ;
std : : sort ( outputTags . begin ( ) , outputTags . end ( ) ) ;
vector < string > : : iterator tagIter ;
for ( tagIter = outputTags . begin ( ) ; tagIter ! = outputTags . end ( ) ; + + tagIter ) {
string tag = * tagIter ;
str + = indent + lang . getString ( " TagDesc " , ( translatedValue = = true ? " " : " english " ) ) +
" " + getTagName ( tag , translatedValue ) + " \n " ;
}
2012-02-19 03:40:13 +01:00
}
return str ;
}
else
return " " ;
}
2011-06-25 10:53:53 +02:00
2013-12-22 06:53:27 +01:00
void AttackBoost : : loadGame ( const XmlNode * rootNode , Faction * faction , const SkillType * skillType ) {
const XmlNode * attackBoostNode = rootNode - > getChild ( " AttackBoost " ) ;
2013-12-23 06:03:40 +01:00
enabled = ( attackBoostNode - > getAttribute ( " enabled " ) - > getIntValue ( ) ! = 0 ) ;
allowMultipleBoosts = ( attackBoostNode - > getAttribute ( " allowMultipleBoosts " ) - > getIntValue ( ) ! = 0 ) ;
2013-12-22 06:53:27 +01:00
radius = attackBoostNode - > getAttribute ( " radius " ) - > getIntValue ( ) ;
targetType = static_cast < AttackBoostTargetType > ( attackBoostNode - > getAttribute ( " targetType " ) - > getIntValue ( ) ) ;
if ( attackBoostNode - > hasChild ( " UnitType " ) = = true ) {
vector < XmlNode * > attackBoostNodeList = attackBoostNode - > getChildList ( " UnitType " ) ;
for ( unsigned int i = 0 ; i < attackBoostNodeList . size ( ) ; + + i ) {
XmlNode * node = attackBoostNodeList [ i ] ;
string unitTypeName = node - > getAttribute ( " name " ) - > getValue ( ) ;
const UnitType * unitType = faction - > getType ( ) - > getUnitType ( unitTypeName ) ;
if ( unitType ! = NULL ) {
2014-09-29 02:23:36 +02:00
boostUnitList . insert ( unitType ) ;
2013-12-22 06:53:27 +01:00
}
}
}
2014-09-29 02:23:36 +02:00
if ( attackBoostNode - > hasChild ( " tag " ) ) {
vector < XmlNode * > tagNodeList = attackBoostNode - > getChildList ( " tag " ) ;
for ( unsigned int i = 0 ; i < tagNodeList . size ( ) ; + + i ) {
XmlNode * node = tagNodeList [ i ] ;
string tagName = node - > getAttribute ( " name " ) - > getValue ( ) ;
tags . insert ( tagName ) ;
}
}
2013-12-22 06:53:27 +01:00
//boostUpgrade.loadGame(attackBoostNode,faction);
boostUpgrade = skillType - > getAttackBoost ( ) - > boostUpgrade ;
unitParticleSystemTypeForSourceUnit = new UnitParticleSystemType ( ) ;
unitParticleSystemTypeForSourceUnit - > loadGame ( attackBoostNode ) ;
unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType ( ) ;
unitParticleSystemTypeForAffectedUnit - > loadGame ( attackBoostNode ) ;
2013-12-23 06:03:40 +01:00
includeSelf = ( attackBoostNode - > getAttribute ( " includeSelf " ) - > getIntValue ( ) ! = 0 ) ;
2013-12-22 06:53:27 +01:00
name = attackBoostNode - > getAttribute ( " name " ) - > getValue ( ) ;
}
2012-03-10 04:27:25 +01:00
void AttackBoost : : saveGame ( XmlNode * rootNode ) const {
std : : map < string , string > mapTagReplacements ;
XmlNode * attackBoostNode = rootNode - > addChild ( " AttackBoost " ) ;
// bool enabled;
attackBoostNode - > addAttribute ( " enabled " , intToStr ( enabled ) , mapTagReplacements ) ;
// bool allowMultipleBoosts;
attackBoostNode - > addAttribute ( " allowMultipleBoosts " , intToStr ( allowMultipleBoosts ) , mapTagReplacements ) ;
// int radius;
attackBoostNode - > addAttribute ( " radius " , intToStr ( radius ) , mapTagReplacements ) ;
// AttackBoostTargetType targetType;
attackBoostNode - > addAttribute ( " targetType " , intToStr ( targetType ) , mapTagReplacements ) ;
// vector<const UnitType *> boostUnitList;
2014-09-29 02:23:36 +02:00
std : : set < const UnitType * > : : iterator unitIter ;
for ( unitIter = boostUnitList . begin ( ) ; unitIter ! = boostUnitList . end ( ) ; + + unitIter ) {
const UnitType * unit = * unitIter ;
2012-03-10 04:27:25 +01:00
XmlNode * unitTypeNode = attackBoostNode - > addChild ( " UnitType " ) ;
2014-09-29 02:23:36 +02:00
unitTypeNode - > addAttribute ( " name " , unit - > getName ( false ) , mapTagReplacements ) ;
}
std : : set < string > : : iterator tagIter ;
for ( tagIter = tags . begin ( ) ; tagIter ! = tags . end ( ) ; + + tagIter ) {
string tag = * tagIter ;
XmlNode * unitTypeNode = attackBoostNode - > addChild ( " tag " ) ;
unitTypeNode - > addAttribute ( " name " , tag , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
}
// UpgradeTypeBase boostUpgrade;
boostUpgrade . saveGame ( attackBoostNode ) ;
// UnitParticleSystemType *unitParticleSystemTypeForSourceUnit;
if ( unitParticleSystemTypeForSourceUnit ! = NULL ) {
unitParticleSystemTypeForSourceUnit - > saveGame ( attackBoostNode ) ;
}
// UnitParticleSystemType *unitParticleSystemTypeForAffectedUnit;
if ( unitParticleSystemTypeForAffectedUnit ! = NULL ) {
unitParticleSystemTypeForAffectedUnit - > saveGame ( attackBoostNode ) ;
}
// bool includeSelf;
attackBoostNode - > addAttribute ( " includeSelf " , intToStr ( includeSelf ) , mapTagReplacements ) ;
// string name;
attackBoostNode - > addAttribute ( " name " , name , mapTagReplacements ) ;
}
2014-07-20 03:28:03 +02:00
// =====================================================
// class SkillSound
// =====================================================
SkillSound : : SkillSound ( ) {
startTime = 0.0f ;
}
SkillSound : : ~ SkillSound ( )
{
deleteValues ( soundContainer . getSounds ( ) . begin ( ) , soundContainer . getSounds ( ) . end ( ) ) ;
startTime = 0.0f ;
//soundContainer
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class SkillType
// =====================================================
2011-03-15 16:30:28 +01:00
SkillType : : ~ SkillType ( ) {
2014-07-20 03:28:03 +02:00
while ( ! skillSoundList . empty ( ) ) {
delete skillSoundList . back ( ) ;
skillSoundList . pop_back ( ) ;
}
2010-05-25 20:06:42 +02:00
//remove unitParticleSystemTypes
2011-03-15 16:30:28 +01:00
while ( ! unitParticleSystemTypes . empty ( ) ) {
2010-05-25 20:06:42 +02:00
delete unitParticleSystemTypes . back ( ) ;
unitParticleSystemTypes . pop_back ( ) ;
}
}
2011-11-11 05:17:55 +01:00
const XmlNode * SkillType : : findAttackBoostDetails ( string attackBoostName ,
const XmlNode * attackBoostsNode , const XmlNode * attackBoostNode ) {
const XmlNode * result = attackBoostNode ;
if ( attackBoostsNode ! = NULL & & attackBoostName ! = " " ) {
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) attackBoostsNode - > getChildCount ( ) ; + + i ) {
2011-11-11 05:17:55 +01:00
const XmlNode * abn = attackBoostsNode - > getChild ( " attack-boost " , i ) ;
string sharedName = abn - > getAttribute ( " name " ) - > getRestrictedValue ( ) ;
if ( sharedName = = attackBoostName ) {
result = abn ;
break ;
}
}
}
return result ;
}
void SkillType : : loadAttackBoost ( const XmlNode * attackBoostsNode , const XmlNode * attackBoostNode ,
const FactionType * ft , string parentLoader , const string & dir ,
string currentPath , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
const TechTree * tt ) {
attackBoost . enabled = true ;
if ( attackBoostNode - > hasAttribute ( " name " ) = = true ) {
attackBoost . name = attackBoostNode - > getAttribute ( " name " ) - > getRestrictedValue ( ) ;
attackBoostNode = findAttackBoostDetails ( attackBoost . name , attackBoostsNode , attackBoostNode ) ;
}
else {
attackBoost . name = " attack-boost-autoname- " + intToStr ( getNextAttackBoostId ( ) ) ;
}
string targetType = attackBoostNode - > getChild ( " target " ) - > getAttribute ( " value " ) - > getValue ( ) ;
2012-12-26 08:57:10 +01:00
attackBoost . allowMultipleBoosts = false ;
if ( attackBoostNode - > hasChild ( " allow-multiple-boosts " ) = = true ) {
attackBoost . allowMultipleBoosts = attackBoostNode - > getChild ( " allow-multiple-boosts " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
2011-11-11 05:17:55 +01:00
attackBoost . radius = attackBoostNode - > getChild ( " radius " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
2012-12-26 08:57:10 +01:00
attackBoost . includeSelf = false ;
2011-11-11 05:17:55 +01:00
if ( attackBoostNode - > getChild ( " target " ) - > hasAttribute ( " include-self " ) = = true ) {
attackBoost . includeSelf = attackBoostNode - > getChild ( " target " ) - > getAttribute ( " include-self " ) - > getBoolValue ( ) ;
}
2012-12-26 08:57:10 +01:00
2011-11-11 05:17:55 +01:00
if ( targetType = = " ally " ) {
attackBoost . targetType = abtAlly ;
}
else if ( targetType = = " foe " ) {
attackBoost . targetType = abtFoe ;
}
else if ( targetType = = " faction " ) {
attackBoost . targetType = abtFaction ;
}
else if ( targetType = = " unit-types " ) {
attackBoost . targetType = abtUnitTypes ;
}
else if ( targetType = = " all " ) {
attackBoost . targetType = abtAll ;
}
else {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Unsupported target [%s] specified for attack boost for skill [%s] in [%s] " , targetType . c_str ( ) , name . c_str ( ) , parentLoader . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-11-11 05:17:55 +01:00
}
2014-09-29 02:23:36 +02:00
// Load the regular targets
const XmlNode * targetNode = attackBoostNode - > getChild ( " target " ) ;
vector < XmlNode * > targetNodes = targetNode - > getChildList ( " unit-type " ) ;
for ( size_t i = 0 ; i < targetNodes . size ( ) ; + + i ) {
string unitName = targetNodes . at ( i ) - > getAttribute ( " name " ) - > getRestrictedValue ( ) ;
attackBoost . boostUnitList . insert ( ft - > getUnitType ( unitName ) ) ;
}
// Load tags
vector < XmlNode * > tagNodes = targetNode - > getChildList ( " tag " ) ;
for ( size_t i = 0 ; i < tagNodes . size ( ) ; + + i ) {
string unitName = tagNodes . at ( i ) - > getAttribute ( " name " ) - > getRestrictedValue ( ) ;
attackBoost . tags . insert ( unitName ) ;
}
2012-03-13 16:21:25 +01:00
attackBoost . boostUpgrade . load ( attackBoostNode , attackBoost . name ) ;
2011-11-11 05:17:55 +01:00
if ( attackBoostNode - > hasChild ( " particles " ) = = true ) {
const XmlNode * particleNode = attackBoostNode - > getChild ( " particles " ) ;
bool particleEnabled = particleNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
if ( particleEnabled = = true ) {
if ( particleNode - > hasChild ( " originator-particle-file " ) = = true ) {
const XmlNode * particleFileNode = particleNode - > getChild ( " originator-particle-file " ) ;
string path = particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
attackBoost . unitParticleSystemTypeForSourceUnit = new UnitParticleSystemType ( ) ;
attackBoost . unitParticleSystemTypeForSourceUnit - > load ( particleFileNode , dir , currentPath + path , & Renderer : : getInstance ( ) , loadedFileList , parentLoader , tt - > getPath ( ) ) ;
loadedFileList [ currentPath + path ] . push_back ( make_pair ( parentLoader , particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
}
if ( particleNode - > hasChild ( " affected-particle-file " ) = = true ) {
const XmlNode * particleFileNode = particleNode - > getChild ( " affected-particle-file " ) ;
string path = particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
attackBoost . unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType ( ) ;
attackBoost . unitParticleSystemTypeForAffectedUnit - > load ( particleFileNode , dir , currentPath + path , & Renderer : : getInstance ( ) , loadedFileList , parentLoader , tt - > getPath ( ) ) ;
loadedFileList [ currentPath + path ] . push_back ( make_pair ( parentLoader , particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
}
}
}
}
void SkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt , const FactionType * ft ,
std : : map < string , vector < pair < string , string > > > & loadedFileList ,
2011-05-05 22:18:38 +02:00
string parentLoader ) {
2010-05-25 20:06:42 +02:00
//name
name = sn - > getChild ( " name " ) - > getAttribute ( " value " ) - > getRestrictedValue ( ) ;
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//ep cost
2013-01-11 19:26:30 +01:00
if ( sn - > hasChild ( " ep-cost " ) = = true ) {
mpCost = sn - > getChild ( " ep-cost " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
else {
mpCost = 0 ;
}
if ( sn - > hasChild ( " hp-cost " ) = = true ) {
2011-02-06 19:33:49 +01:00
hpCost = sn - > getChild ( " hp-cost " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
2011-02-11 08:39:58 +01:00
}
else {
2011-02-06 19:33:49 +01:00
hpCost = 0 ;
}
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//speed
2013-01-11 19:26:30 +01:00
if ( sn - > hasChild ( " speed " ) = = true ) {
speed = sn - > getChild ( " speed " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
else {
speed = 0 ;
}
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//anim speed
2013-01-11 19:26:30 +01:00
if ( sn - > hasChild ( " anim-speed " ) = = true ) {
animSpeed = sn - > getChild ( " anim-speed " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
else {
animSpeed = 0 ;
}
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//model
2011-03-13 09:23:43 +01:00
string currentPath = dir ;
endPathWithSlash ( currentPath ) ;
2011-05-05 09:15:12 +02:00
2011-06-25 23:40:27 +02:00
animationRandomCycleMaxcount = - 1 ;
if ( sn - > hasChild ( " animation-random-cycle-maxcount " ) = = true ) {
const XmlNode * randomCycleCountNode = sn - > getChild ( " animation-random-cycle-maxcount " ) ;
animationRandomCycleMaxcount = randomCycleCountNode - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2013-01-11 19:26:30 +01:00
if ( sn - > hasChild ( " animation " ) = = true ) {
//string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath);
vector < XmlNode * > animationList = sn - > getChildList ( " animation " ) ;
for ( unsigned int i = 0 ; i < animationList . size ( ) ; + + i ) {
string path = animationList [ i ] - > getAttribute ( " path " ) - > getRestrictedValue ( currentPath ) ;
if ( fileExists ( path ) = = true ) {
2013-12-05 16:17:41 +01:00
Model * animation = Renderer : : getInstance ( ) . newModel ( rsGame , path , false , & loadedFileList , & parentLoader ) ;
2013-01-11 19:26:30 +01:00
loadedFileList [ path ] . push_back ( make_pair ( parentLoader , animationList [ i ] - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
2011-06-25 07:23:41 +02:00
2013-01-11 19:26:30 +01:00
animations . push_back ( animation ) ;
//printf("**FOUND ANIMATION [%s]\n",path.c_str());
2011-06-25 17:30:18 +02:00
2013-01-11 19:26:30 +01:00
AnimationAttributes animationAttributeList ;
if ( animationList [ i ] - > getAttribute ( " minHp " , false ) ! = NULL & & animationList [ i ] - > getAttribute ( " maxHp " , false ) ! = NULL ) {
animationAttributeList . fromHp = animationList [ i ] - > getAttribute ( " minHp " ) - > getIntValue ( ) ;
animationAttributeList . toHp = animationList [ i ] - > getAttribute ( " maxHp " ) - > getIntValue ( ) ;
}
animationAttributes . push_back ( animationAttributeList ) ;
}
else {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line %d] WARNING CANNOT LOAD MODEL [%s] for parentLoader [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , path . c_str ( ) , parentLoader . c_str ( ) ) ;
2011-06-25 17:30:18 +02:00
}
2011-06-25 07:23:41 +02:00
}
2013-01-11 19:26:30 +01:00
if ( animations . empty ( ) = = true ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Error no animations found for skill [%s] for parentLoader [%s] " , name . c_str ( ) , parentLoader . c_str ( ) ) ;
throw megaglest_runtime_error ( szBuf ) ;
2011-06-25 07:23:41 +02:00
}
}
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//particles
2011-03-15 16:30:28 +01:00
if ( sn - > hasChild ( " particles " ) ) {
2010-05-25 20:06:42 +02:00
const XmlNode * particleNode = sn - > getChild ( " particles " ) ;
bool particleEnabled = particleNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
2011-03-15 16:30:28 +01:00
if ( particleEnabled ) {
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) particleNode - > getChildCount ( ) ; + + i ) {
2010-05-25 20:06:42 +02:00
const XmlNode * particleFileNode = particleNode - > getChild ( " particle-file " , i ) ;
string path = particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
UnitParticleSystemType * unitParticleSystemType = new UnitParticleSystemType ( ) ;
2011-07-07 00:23:51 +02:00
unitParticleSystemType - > load ( particleFileNode , dir , currentPath + path , & Renderer : : getInstance ( ) ,
2011-05-07 00:12:16 +02:00
loadedFileList , parentLoader , tt - > getPath ( ) ) ;
2011-08-27 08:52:17 +02:00
2014-07-23 21:24:43 +02:00
if ( particleNode - > getChild ( i ) - > hasAttribute ( " start-time " ) ) {
//printf("*NOTE particle system type has start-time [%f]\n",particleNode->getAttribute("start-time")->getFloatValue());
unitParticleSystemType - > setStartTime ( particleNode - > getChild ( i ) - > getAttribute ( " start-time " ) - > getFloatValue ( ) ) ;
} else if ( particleNode - > hasAttribute ( " start-time " ) ) {
2011-08-27 08:52:17 +02:00
//printf("*NOTE particle system type has start-time [%f]\n",particleNode->getAttribute("start-time")->getFloatValue());
unitParticleSystemType - > setStartTime ( particleNode - > getAttribute ( " start-time " ) - > getFloatValue ( ) ) ;
}
2014-07-23 21:24:43 +02:00
if ( particleNode - > getChild ( i ) - > hasAttribute ( " end-time " ) ) {
//printf("*NOTE particle system type has start-time [%f]\n",particleNode->getAttribute("start-time")->getFloatValue());
unitParticleSystemType - > setEndTime ( particleNode - > getChild ( i ) - > getAttribute ( " end-time " ) - > getFloatValue ( ) ) ;
} else if ( particleNode - > hasAttribute ( " end-time " ) ) {
2011-08-27 08:52:17 +02:00
//printf("*NOTE particle system type has end-time [%f]\n",particleNode->getAttribute("end-time")->getFloatValue());
unitParticleSystemType - > setEndTime ( particleNode - > getAttribute ( " end-time " ) - > getFloatValue ( ) ) ;
}
2014-11-19 06:38:46 +01:00
if ( particleNode - > getChild ( i ) - > hasAttribute ( " minHp " ) & & particleNode - > getChild ( i ) - > hasAttribute ( " maxHp " ) ) {
unitParticleSystemType - > setMinmaxEnabled ( true ) ;
unitParticleSystemType - > setMinHp ( particleNode - > getChild ( i ) - > getAttribute ( " minHp " ) - > getIntValue ( ) ) ;
unitParticleSystemType - > setMaxHp ( particleNode - > getChild ( i ) - > getAttribute ( " maxHp " ) - > getIntValue ( ) ) ;
if ( particleNode - > getChild ( i ) - > hasAttribute ( " ispercentbased " ) ) {
unitParticleSystemType - > setMinmaxIsPercent ( particleNode - > getChild ( i ) - > getAttribute ( " ispercentbased " ) - > getBoolValue ( ) ) ;
}
}
2011-05-06 09:47:31 +02:00
loadedFileList [ currentPath + path ] . push_back ( make_pair ( parentLoader , particleFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
2010-05-25 20:06:42 +02:00
unitParticleSystemTypes . push_back ( unitParticleSystemType ) ;
}
2014-11-19 06:38:46 +01:00
//printf("Load skill particles line: %d size: %d\n",__LINE__,(int)unitParticleSystemTypes.size());
2010-05-25 20:06:42 +02:00
}
}
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
//sound
2014-07-20 03:28:03 +02:00
vector < XmlNode * > soundNodeList = sn - > getChildList ( " sound " ) ;
for ( unsigned int i = 0 ; i < soundNodeList . size ( ) ; + + i ) {
const XmlNode * soundNode = soundNodeList [ i ] ;
2013-01-11 19:26:30 +01:00
if ( soundNode - > getAttribute ( " enabled " ) - > getBoolValue ( ) ) {
2014-07-20 03:28:03 +02:00
float soundStartTime = soundNode - > getAttribute ( " start-time " ) - > getFloatValue ( ) ;
SkillSound * skillSound = new SkillSound ( ) ;
skillSound - > setStartTime ( soundStartTime ) ;
skillSound - > getSoundContainer ( ) - > resize ( ( int ) soundNode - > getChildCount ( ) ) ;
skillSoundList . push_back ( skillSound ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) soundNode - > getChildCount ( ) ; + + i ) {
2013-01-11 19:26:30 +01:00
const XmlNode * soundFileNode = soundNode - > getChild ( " sound-file " , i ) ;
string path = soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( currentPath , true ) ;
StaticSound * sound = new StaticSound ( ) ;
sound - > load ( path ) ;
loadedFileList [ path ] . push_back ( make_pair ( parentLoader , soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
2014-07-20 03:28:03 +02:00
( * skillSound - > getSoundContainer ( ) ) [ i ] = sound ;
2013-01-11 19:26:30 +01:00
}
2010-05-25 20:06:42 +02:00
}
}
2011-06-25 09:31:01 +02:00
// attack-boost
if ( sn - > hasChild ( " attack-boost " ) = = true ) {
//printf("$$FOUND ATTACK BOOST FOR [%s]\n",parentLoader.c_str());
const XmlNode * attackBoostNode = sn - > getChild ( " attack-boost " ) ;
2011-11-11 05:17:55 +01:00
loadAttackBoost ( attackBoostsNode , attackBoostNode , ft , parentLoader , dir , currentPath , loadedFileList , tt ) ;
2011-06-25 22:44:46 +02:00
}
2014-02-01 23:15:44 +01:00
shake = false ;
shakeIntensity = 50 ;
shakeDuration = 300 ;
shakeStartTime = 0.0f ;
shakeSelfEnabled = false ;
shakeSelfVisible = true ;
shakeSelfInCameraView = false ;
shakeSelfCameraAffected = false ;
shakeTeamEnabled = false ;
shakeTeamVisible = true ;
shakeTeamInCameraView = false ;
shakeTeamCameraAffected = false ;
shakeEnemyEnabled = false ;
shakeEnemyVisible = true ;
shakeEnemyInCameraView = false ;
shakeEnemyCameraAffected = false ;
if ( sn - > hasChild ( " shake " ) ) {
XmlNode * shakeNode = sn - > getChild ( " shake " ) ;
shake = shakeNode - > getAttribute ( " enabled " ) - > getBoolValue ( ) ;
shakeIntensity = shakeNode - > getAttribute ( " intensity " ) - > getIntValue ( ) ;
shakeDuration = shakeNode - > getAttribute ( " duration " ) - > getIntValue ( ) ;
if ( shakeNode - > hasAttribute ( " start-time " ) ) {
shakeStartTime = shakeNode - > getAttribute ( " start-time " ) - > getFloatValue ( ) ;
}
if ( shakeNode - > hasChild ( " self " ) ) {
shakeSelfEnabled = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " enabled " ) - > getBoolValue ( ) ;
shakeSelfVisible = shakeNode - > getChild ( " self " ) - > getAttribute ( " visible " ) - > getBoolValue ( ) ;
shakeSelfInCameraView = shakeNode - > getChild ( " self " ) - > getAttribute ( " in-camera-view " ) - > getBoolValue ( ) ;
shakeSelfCameraAffected = shakeNode - > getChild ( " self " ) - > getAttribute ( " camera-distance-affected " ) - > getBoolValue ( ) ;
}
if ( shakeNode - > hasChild ( " team " ) ) {
shakeTeamEnabled = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " enabled " ) - > getBoolValue ( ) ;
shakeTeamVisible = shakeNode - > getChild ( " team " ) - > getAttribute ( " visible " ) - > getBoolValue ( ) ;
shakeTeamInCameraView = shakeNode - > getChild ( " team " ) - > getAttribute ( " in-camera-view " ) - > getBoolValue ( ) ;
shakeTeamCameraAffected = shakeNode - > getChild ( " team " ) - > getAttribute ( " camera-distance-affected " ) - > getBoolValue ( ) ;
}
if ( shakeNode - > hasChild ( " enemy " ) ) {
shakeEnemyEnabled = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " enabled " ) - > getBoolValue ( ) ;
shakeEnemyVisible = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " visible " ) - > getBoolValue ( ) ;
shakeEnemyInCameraView = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " in-camera-view " ) - > getBoolValue ( ) ;
shakeEnemyCameraAffected = shakeNode - > getChild ( " enemy " ) - > getAttribute ( " camera-distance-affected " ) - > getBoolValue ( ) ;
}
//visible-for (team, self,all, team-and-visible, self-and-visible, all-and-visible )
}
2010-05-25 20:06:42 +02:00
}
2011-06-25 23:40:27 +02:00
bool SkillType : : CanCycleNextRandomAnimation ( const int * animationRandomCycleCount ) const {
bool result = true ;
if ( animations . size ( ) > 1 ) {
if ( animationRandomCycleMaxcount > = 0 & &
animationRandomCycleCount ! = NULL & &
* animationRandomCycleCount > = animationRandomCycleMaxcount ) {
result = false ;
}
}
return result ;
}
2012-03-24 19:30:49 +01:00
const AnimationAttributes SkillType : : getAnimationAttribute ( int index ) const {
return animationAttributes [ index ] ;
}
2013-10-03 02:17:51 +02:00
Model * SkillType : : getAnimation ( float animProgress , const Unit * unit ,
2011-06-25 23:40:27 +02:00
int * lastAnimationIndex , int * animationRandomCycleCount ) const {
2011-06-25 09:31:01 +02:00
int modelIndex = 0 ;
2012-03-24 19:30:49 +01:00
//printf("Count [%d] animProgress = [%f] for skill [%s] animationRandomCycleCount = %d\n",animations.size(),animProgress,name.c_str(),*animationRandomCycleCount);
2011-06-25 09:31:01 +02:00
if ( animations . size ( ) > 1 ) {
2012-03-24 19:30:49 +01:00
//printf("animProgress = [%f] for skill [%s] animationRandomCycleCount = %d\n",animProgress,name.c_str(),*animationRandomCycleCount);
2011-06-25 09:31:01 +02:00
if ( lastAnimationIndex ) {
modelIndex = * lastAnimationIndex ;
}
if ( modelIndex < 0 | | animProgress > 1.0f ) {
2011-06-25 23:40:27 +02:00
bool canCycle = CanCycleNextRandomAnimation ( animationRandomCycleCount ) ;
if ( canCycle = = true ) {
2011-07-01 23:47:54 +02:00
vector < int > filteredAnimations ;
2011-06-25 23:40:27 +02:00
bool foundSpecificAnimation = false ;
if ( unit ! = NULL ) {
for ( unsigned int i = 0 ; i < animationAttributes . size ( ) ; + + i ) {
const AnimationAttributes & attributes = animationAttributes [ i ] ;
if ( attributes . fromHp ! = 0 | | attributes . toHp ! = 0 ) {
if ( unit - > getHp ( ) > = attributes . fromHp & & unit - > getHp ( ) < = attributes . toHp ) {
2014-12-16 06:07:13 +01:00
//modelIndex = i;
2011-06-25 23:40:27 +02:00
foundSpecificAnimation = true ;
2011-07-01 23:47:54 +02:00
filteredAnimations . push_back ( i ) ;
2011-06-30 20:59:58 +02:00
//printf("SELECTING Model index = %d [%s] model attributes [%d to %d] for unit [%s - %d] with HP = %d\n",i,animations[modelIndex]->getFileName().c_str(),attributes.fromHp,attributes.toHp,unit->getType()->getName().c_str(),unit->getId(),unit->getHp());
2011-07-01 23:47:54 +02:00
//break;
2011-06-25 23:40:27 +02:00
}
2011-06-25 17:30:18 +02:00
}
}
2011-07-12 00:30:16 +02:00
// Need to make sure the filtered list does NOT include any
// models with min/max hp
if ( foundSpecificAnimation = = false ) {
for ( unsigned int i = 0 ; i < animationAttributes . size ( ) ; + + i ) {
const AnimationAttributes & attributes = animationAttributes [ i ] ;
if ( attributes . fromHp = = 0 & & attributes . toHp = = 0 ) {
2014-12-16 04:44:26 +01:00
//modelIndex = i;
2011-07-12 00:30:16 +02:00
foundSpecificAnimation = true ;
filteredAnimations . push_back ( i ) ;
//printf("SELECTING Model index = %d [%s] model attributes [%d to %d] for unit [%s - %d] with HP = %d\n",i,animations[modelIndex]->getFileName().c_str(),attributes.fromHp,attributes.toHp,unit->getType()->getName().c_str(),unit->getId(),unit->getHp());
//break;
}
}
}
2011-06-25 17:30:18 +02:00
}
2011-06-25 23:40:27 +02:00
if ( foundSpecificAnimation = = false ) {
//int modelIndex = random.randRange(0,animations.size()-1);
2012-09-27 08:42:57 +02:00
Chrono seed ( true ) ;
2013-02-04 09:30:43 +01:00
srand ( ( unsigned int ) seed . getCurTicks ( ) + ( unit ! = NULL ? unit - > getId ( ) : 0 ) ) ;
2012-09-27 08:42:57 +02:00
2011-06-25 23:40:27 +02:00
modelIndex = rand ( ) % animations . size ( ) ;
2011-06-30 20:59:58 +02:00
//const AnimationAttributes &attributes = animationAttributes[modelIndex];
//printf("SELECTING RANDOM Model index = %d [%s] model attributes [%d to %d] for unit [%s - %d] with HP = %d\n",modelIndex,animations[modelIndex]->getFileName().c_str(),attributes.fromHp,attributes.toHp,unit->getType()->getName().c_str(),unit->getId(),unit->getHp());
2011-06-25 23:40:27 +02:00
}
2011-07-01 23:47:54 +02:00
else {
2012-09-27 08:42:57 +02:00
Chrono seed ( true ) ;
2012-10-30 18:12:04 +01:00
srand ( ( unsigned int ) seed . getCurTicks ( ) + unit - > getId ( ) ) ;
2012-09-27 08:42:57 +02:00
2011-07-01 23:47:54 +02:00
int filteredModelIndex = rand ( ) % filteredAnimations . size ( ) ;
modelIndex = filteredAnimations [ filteredModelIndex ] ;
}
2011-06-25 17:30:18 +02:00
}
2011-06-25 09:31:01 +02:00
}
}
if ( lastAnimationIndex ) {
2012-03-24 19:30:49 +01:00
if ( * lastAnimationIndex ! = modelIndex ) {
//printf("Switching model from [%s] to [%s]\n",(*lastAnimationIndex >= 0 ? animations[*lastAnimationIndex]->getFileName().c_str() : "none"),animations[modelIndex]->getFileName().c_str());
}
2011-06-25 09:31:01 +02:00
* lastAnimationIndex = modelIndex ;
}
2011-06-25 07:23:41 +02:00
//printf("!!RETURN ANIMATION [%d / %d]\n",modelIndex,animations.size()-1);
return animations [ modelIndex ] ;
}
2011-03-15 16:30:28 +01:00
string SkillType : : skillClassToStr ( SkillClass skillClass ) {
2010-05-25 20:06:42 +02:00
switch ( skillClass ) {
case scStop : return " Stop " ;
case scMove : return " Move " ;
case scAttack : return " Attack " ;
case scHarvest : return " Harvest " ;
case scRepair : return " Repair " ;
case scBuild : return " Build " ;
case scDie : return " Die " ;
case scBeBuilt : return " Be Built " ;
case scProduce : return " Produce " ;
case scUpgrade : return " Upgrade " ;
2013-01-11 19:18:58 +01:00
case scFogOfWar : return " Fog Of War " ;
2010-05-25 20:06:42 +02:00
default :
assert ( false ) ;
2012-09-22 22:13:57 +02:00
break ;
}
return " " ;
2010-05-25 20:06:42 +02:00
}
2012-04-02 04:07:32 +02:00
string SkillType : : fieldToStr ( Field field ) {
Lang & lang = Lang : : getInstance ( ) ;
2012-05-11 07:49:47 +02:00
string fieldName = " " ;
2012-04-02 04:07:32 +02:00
switch ( field ) {
2012-05-11 07:49:47 +02:00
case fLand :
if ( lang . hasString ( " FieldLand " ) = = true ) {
2013-10-29 07:13:38 +01:00
fieldName = lang . getString ( " FieldLand " ) ;
2012-05-11 07:49:47 +02:00
}
else {
fieldName = " Land " ;
}
//return "Land";
return lang . getTilesetString ( " FieldLandName " , fieldName . c_str ( ) ) ;
case fAir :
if ( lang . hasString ( " FieldAir " ) = = true ) {
2013-10-29 07:13:38 +01:00
fieldName = lang . getString ( " FieldAir " ) ;
2012-05-11 07:49:47 +02:00
}
else {
fieldName = " Air " ;
}
//return "Air";
return lang . getTilesetString ( " FieldAirName " , fieldName . c_str ( ) ) ;
default :
assert ( false ) ;
2012-09-22 22:13:57 +02:00
break ;
}
return " " ;
2010-05-25 20:06:42 +02:00
}
2012-03-10 04:27:25 +01:00
void SkillType : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * skillTypeNode = rootNode - > addChild ( " SkillType " ) ;
// SkillClass skillClass;
skillTypeNode - > addAttribute ( " skillClass " , intToStr ( skillClass ) , mapTagReplacements ) ;
// string name;
skillTypeNode - > addAttribute ( " name " , name , mapTagReplacements ) ;
// int mpCost;
skillTypeNode - > addAttribute ( " mpCost " , intToStr ( mpCost ) , mapTagReplacements ) ;
// int hpCost;
skillTypeNode - > addAttribute ( " hpCost " , intToStr ( hpCost ) , mapTagReplacements ) ;
// int speed;
skillTypeNode - > addAttribute ( " speed " , intToStr ( speed ) , mapTagReplacements ) ;
// int animSpeed;
skillTypeNode - > addAttribute ( " animSpeed " , intToStr ( animSpeed ) , mapTagReplacements ) ;
// int animationRandomCycleMaxcount;
skillTypeNode - > addAttribute ( " animationRandomCycleMaxcount " , intToStr ( animationRandomCycleMaxcount ) , mapTagReplacements ) ;
// vector<Model *> animations;
// vector<AnimationAttributes> animationAttributes;
//
// SoundContainer sounds;
// float soundStartTime;
2014-07-20 03:28:03 +02:00
// skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements);
2012-03-10 04:27:25 +01:00
// RandomGen random;
skillTypeNode - > addAttribute ( " random " , intToStr ( random . getLastNumber ( ) ) , mapTagReplacements ) ;
// AttackBoost attackBoost;
attackBoost . saveGame ( skillTypeNode ) ;
// static int nextAttackBoostId;
skillTypeNode - > addAttribute ( " nextAttackBoostId " , intToStr ( nextAttackBoostId ) , mapTagReplacements ) ;
// UnitParticleSystemTypes unitParticleSystemTypes;
for ( UnitParticleSystemTypes : : iterator it = unitParticleSystemTypes . begin ( ) ; it ! = unitParticleSystemTypes . end ( ) ; + + it ) {
( * it ) - > saveGame ( skillTypeNode ) ;
}
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class StopSkillType
// =====================================================
StopSkillType : : StopSkillType ( ) {
skillClass = scStop ;
}
2013-09-21 22:50:58 +02:00
string StopSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Stop " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Stop " ) ;
2010-05-25 20:06:42 +02:00
}
// =====================================================
// class MoveSkillType
// =====================================================
MoveSkillType : : MoveSkillType ( ) {
skillClass = scMove ;
}
2013-09-21 22:50:58 +02:00
string MoveSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Move " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Move " ) ;
2010-05-25 20:06:42 +02:00
}
int MoveSkillType : : getTotalSpeed ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = speed + totalUpgrade - > getMoveSpeed ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
// =====================================================
// class AttackSkillType
// =====================================================
//varios
2011-01-10 06:44:45 +01:00
AttackSkillType : : AttackSkillType ( ) {
2010-05-25 20:06:42 +02:00
skillClass = scAttack ;
attackType = NULL ;
projectile = false ;
splash = false ;
splashRadius = 0 ;
2011-02-11 08:39:58 +01:00
spawnUnit = " " ;
spawnUnitcount = 0 ;
2014-07-27 12:54:25 +02:00
spawnUnitAtTarget = false ;
2010-05-25 20:06:42 +02:00
splashParticleSystemType = NULL ;
2011-01-10 06:44:45 +01:00
for ( int i = 0 ; i < fieldCount ; + + i ) {
2010-05-25 20:06:42 +02:00
attackFields [ i ] = false ;
}
2011-09-01 03:11:23 +02:00
attackStrength = 0 ;
attackVar = 0 ;
attackRange = 0 ;
attackStartTime = 0 ;
splashDamageAll = false ;
2010-05-25 20:06:42 +02:00
}
2011-01-10 06:44:45 +01:00
AttackSkillType : : ~ AttackSkillType ( ) {
2014-07-10 23:34:39 +02:00
2014-07-18 01:04:36 +02:00
deleteValues ( projectileTypes . begin ( ) , projectileTypes . end ( ) ) ;
2011-01-10 06:44:45 +01:00
2010-05-25 20:06:42 +02:00
delete splashParticleSystemType ;
2011-01-10 06:44:45 +01:00
splashParticleSystemType = NULL ;
2010-05-25 20:06:42 +02:00
deleteValues ( projSounds . getSounds ( ) . begin ( ) , projSounds . getSounds ( ) . end ( ) ) ;
2013-02-01 18:25:49 +01:00
projSounds . clearSounds ( ) ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void AttackSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-05-06 09:47:31 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
2011-05-05 22:18:38 +02:00
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2010-05-25 20:06:42 +02:00
2011-03-13 09:23:43 +01:00
string currentPath = dir ;
endPathWithSlash ( currentPath ) ;
2010-05-25 20:06:42 +02:00
//misc
2013-10-03 16:51:26 +02:00
std : : vector < string > attackStrengthXMLTags ;
attackStrengthXMLTags . push_back ( " attack-strenght " ) ;
attackStrengthXMLTags . push_back ( " attack-strength " ) ;
attackStrength = sn - > getChildWithAliases ( attackStrengthXMLTags ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
2010-05-25 20:06:42 +02:00
attackVar = sn - > getChild ( " attack-var " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
2011-01-10 06:44:45 +01:00
if ( attackVar < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " The attack skill has an INVALID attack var value which is < 0 [%d] in file [%s]! " , attackVar , dir . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-01-10 06:44:45 +01:00
}
2010-05-25 20:06:42 +02:00
attackRange = sn - > getChild ( " attack-range " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
string attackTypeName = sn - > getChild ( " attack-type " ) - > getAttribute ( " value " ) - > getRestrictedValue ( ) ;
attackType = tt - > getAttackType ( attackTypeName ) ;
attackStartTime = sn - > getChild ( " attack-start-time " ) - > getAttribute ( " value " ) - > getFloatValue ( ) ;
2011-02-06 19:33:49 +01:00
if ( sn - > hasChild ( " unit " ) ) {
spawnUnit = sn - > getChild ( " unit " ) - > getAttribute ( " value " ) - > getValue ( ) ;
2014-07-27 12:54:25 +02:00
spawnUnitcount = sn - > getChild ( " unit " ) - > getAttribute ( " amount " ) - > getIntValue ( ) ;
if ( sn - > getChild ( " unit " ) - > hasAttribute ( " spawnAtTarget " ) ) {
spawnUnitAtTarget = sn - > getChild ( " unit " ) - > getAttribute ( " spawnAtTarget " ) - > getBoolValue ( ) ;
} else {
spawnUnitAtTarget = false ;
}
2011-02-06 19:33:49 +01:00
} else {
spawnUnit = " " ;
spawnUnitcount = 0 ;
2014-07-27 12:54:25 +02:00
spawnUnitAtTarget = false ;
2011-02-06 19:33:49 +01:00
}
2010-05-25 20:06:42 +02:00
//attack fields
const XmlNode * attackFieldsNode = sn - > getChild ( " attack-fields " ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) attackFieldsNode - > getChildCount ( ) ; + + i ) {
2010-05-25 20:06:42 +02:00
const XmlNode * fieldNode = attackFieldsNode - > getChild ( " field " , i ) ;
string fieldName = fieldNode - > getAttribute ( " value " ) - > getRestrictedValue ( ) ;
if ( fieldName = = " land " ) {
attackFields [ fLand ] = true ;
2011-01-10 06:44:45 +01:00
}
2010-05-25 20:06:42 +02:00
else if ( fieldName = = " air " ) {
attackFields [ fAir ] = true ;
}
else {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Not a valid field: " + fieldName + " : " + dir ) ;
2010-05-25 20:06:42 +02:00
}
}
2014-07-19 18:50:47 +02:00
if ( sn - > hasChild ( " projectile " ) ) {
2014-07-18 01:04:36 +02:00
//projectile -- backward compatible old behaviour with only one projectile
const XmlNode * projectileNode = sn - > getChild ( " projectile " ) ;
projectile = projectileNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
if ( projectile ) {
// create new projectile
2014-12-01 00:30:02 +01:00
ProjectileType * projectileType = new ProjectileType ( ) ;
//only add this projectile if there is an enabled particlesystem
//projectileTypes.push_back(projectileType);
projectileType - > setAttackStartTime ( attackStartTime ) ;
projectileType - > setDamagePercentage ( 100 ) ;
2014-07-18 01:04:36 +02:00
//proj particle
if ( projectileNode - > hasChild ( " particle " ) ) {
const XmlNode * particleNode = projectileNode - > getChild ( " particle " ) ;
bool particleEnabled = particleNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
2014-12-01 00:30:02 +01:00
if ( particleEnabled ) {
2014-11-25 00:56:59 +01:00
projectileTypes . push_back ( projectileType ) ;
2014-07-18 01:04:36 +02:00
string path = particleNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
ParticleSystemTypeProjectile * projectileParticleSystemType = new ParticleSystemTypeProjectile ( ) ;
projectileParticleSystemType - > load ( particleNode , dir , currentPath + path ,
& Renderer : : getInstance ( ) , loadedFileList , parentLoader ,
tt - > getPath ( ) ) ;
loadedFileList [ currentPath + path ] . push_back ( make_pair ( parentLoader , particleNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
projectileType - > setProjectileParticleSystemType ( projectileParticleSystemType ) ;
2014-07-09 19:59:09 +02:00
}
2014-11-25 22:35:07 +01:00
else {
delete projectileType ;
}
2014-07-09 19:59:09 +02:00
}
2014-12-01 00:30:02 +01:00
else {
delete projectileType ;
}
2014-07-18 01:04:36 +02:00
//proj sounds
const XmlNode * soundNode = projectileNode - > getChild ( " sound " ) ;
if ( soundNode - > getAttribute ( " enabled " ) - > getBoolValue ( ) ) {
projSounds . resize ( ( int ) soundNode - > getChildCount ( ) ) ;
for ( int i = 0 ; i < ( int ) soundNode - > getChildCount ( ) ; + + i ) {
const XmlNode * soundFileNode = soundNode - > getChild ( " sound-file " , i ) ;
string path = soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( currentPath , true ) ;
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
StaticSound * sound = new StaticSound ( ) ;
sound - > load ( path ) ;
loadedFileList [ path ] . push_back ( make_pair ( parentLoader , soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
projSounds [ i ] = sound ;
}
2010-05-25 20:06:42 +02:00
}
}
}
2014-07-19 18:50:47 +02:00
else {
const XmlNode * projectilesNode = sn - > getChild ( " projectiles " ) ;
vector < XmlNode * > projectilesNodeList = projectilesNode - > getChildList ( " projectile " ) ;
2014-07-20 22:47:07 +02:00
int totalDamagePercentage = 0 ;
2014-07-19 18:50:47 +02:00
for ( unsigned int i = 0 ; i < projectilesNodeList . size ( ) ; + + i ) {
const XmlNode * projectileNode = projectilesNodeList [ i ] ;
ProjectileType * projectileType = new ProjectileType ( ) ;
projectileType - > load ( projectileNode , dir , tt - > getPath ( ) , loadedFileList , parentLoader ) ;
2014-07-20 22:47:07 +02:00
totalDamagePercentage + = projectileType - > getDamagePercentage ( ) ;
2014-07-19 18:50:47 +02:00
projectileTypes . push_back ( projectileType ) ;
projectile = true ;
}
2014-07-20 22:47:07 +02:00
if ( totalDamagePercentage ! = 100 ) {
throw megaglest_runtime_error ( " Damages percentages of projectiles don't sum up to 100 % " ) ;
}
2014-07-28 23:18:52 +02:00
if ( sn - > hasChild ( " hitsound " ) = = true ) {
//general hit sounds, individual ones can be set in projectiles
const XmlNode * soundNode = sn - > getChild ( " hitsound " ) ;
if ( soundNode - > getAttribute ( " enabled " ) - > getBoolValue ( ) ) {
2014-07-19 18:50:47 +02:00
2014-07-28 23:18:52 +02:00
projSounds . resize ( ( int ) soundNode - > getChildCount ( ) ) ;
for ( int i = 0 ; i < ( int ) soundNode - > getChildCount ( ) ; + + i ) {
const XmlNode * soundFileNode = soundNode - > getChild ( " sound-file " , i ) ;
string path = soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( currentPath , true ) ;
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
2014-07-19 18:50:47 +02:00
2014-07-28 23:18:52 +02:00
StaticSound * sound = new StaticSound ( ) ;
sound - > load ( path ) ;
loadedFileList [ path ] . push_back ( make_pair ( parentLoader , soundFileNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ) ) ;
projSounds [ i ] = sound ;
}
2014-07-19 18:50:47 +02:00
}
}
}
2010-05-25 20:06:42 +02:00
//splash
const XmlNode * splashNode = sn - > getChild ( " splash " ) ;
splash = splashNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
if ( splash ) {
splashRadius = splashNode - > getChild ( " radius " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
splashDamageAll = splashNode - > getChild ( " damage-all " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
//splash particle
const XmlNode * particleNode = splashNode - > getChild ( " particle " ) ;
bool particleEnabled = particleNode - > getAttribute ( " value " ) - > getBoolValue ( ) ;
if ( particleEnabled ) {
2011-01-10 06:44:45 +01:00
string path = particleNode - > getAttribute ( " path " ) - > getRestrictedValue ( ) ;
2010-05-25 20:06:42 +02:00
splashParticleSystemType = new ParticleSystemTypeSplash ( ) ;
2011-07-07 00:23:51 +02:00
splashParticleSystemType - > load ( particleNode , dir , currentPath + path ,
2011-05-07 00:12:16 +02:00
& Renderer : : getInstance ( ) , loadedFileList , parentLoader ,
tt - > getPath ( ) ) ;
2010-05-25 20:06:42 +02:00
}
}
}
2014-08-10 00:15:23 +02:00
int AttackSkillType : : getTotalSpeed ( const TotalUpgrade * totalUpgrade ) const {
int result = speed + totalUpgrade - > getAttackSpeed ( this ) ;
result = max ( 0 , result ) ;
return result ;
}
// Get the amount to boost the attack animation speed by (based on attack-speed upgrades)
int AttackSkillType : : getAnimSpeedBoost ( const TotalUpgrade * totalUpgrade ) const {
// Same calculation as in TotalUpgrade::sum, but bypassing the use of the value
// list (which is for the attack speed, not animation speed)
if ( totalUpgrade - > getAttackRangeIsMultiplier ( ) ) {
return animSpeed * ( totalUpgrade - > getAttackSpeed ( NULL ) / ( double ) 100 ) ;
}
else {
return totalUpgrade - > getAttackSpeed ( NULL ) ;
}
}
2013-09-21 22:50:58 +02:00
string AttackSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Attack " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Attack " ) ;
2010-05-25 20:06:42 +02:00
}
//get totals
int AttackSkillType : : getTotalAttackStrength ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = attackStrength + totalUpgrade - > getAttackStrength ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
int AttackSkillType : : getTotalAttackRange ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = attackRange + totalUpgrade - > getAttackRange ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
2012-03-10 04:27:25 +01:00
void AttackSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * attackSkillTypeNode = rootNode - > addChild ( " AttackSkillType " ) ;
// int attackStrength;
attackSkillTypeNode - > addAttribute ( " attackStrength " , intToStr ( attackStrength ) , mapTagReplacements ) ;
// int attackVar;
attackSkillTypeNode - > addAttribute ( " attackVar " , intToStr ( attackVar ) , mapTagReplacements ) ;
// int attackRange;
attackSkillTypeNode - > addAttribute ( " attackRange " , intToStr ( attackRange ) , mapTagReplacements ) ;
// const AttackType *attackType;
if ( attackType ! = NULL ) {
2013-06-13 10:55:48 +02:00
attackSkillTypeNode - > addAttribute ( " attackType " , attackType - > getName ( false ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
}
// bool attackFields[fieldCount];
for ( unsigned int i = 0 ; i < fieldCount ; + + i ) {
XmlNode * attackFieldsNode = attackSkillTypeNode - > addChild ( " attackFields " ) ;
attackFieldsNode - > addAttribute ( " key " , intToStr ( i ) , mapTagReplacements ) ;
attackFieldsNode - > addAttribute ( " value " , intToStr ( attackFields [ i ] ) , mapTagReplacements ) ;
}
// float attackStartTime;
2013-10-02 22:22:10 +02:00
attackSkillTypeNode - > addAttribute ( " attackStartTime " , floatToStr ( attackStartTime , 6 ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
// string spawnUnit;
attackSkillTypeNode - > addAttribute ( " spawnUnit " , spawnUnit , mapTagReplacements ) ;
// int spawnUnitcount;
attackSkillTypeNode - > addAttribute ( " spawnUnitcount " , intToStr ( spawnUnitcount ) , mapTagReplacements ) ;
2014-07-27 12:54:25 +02:00
// bool spawnUnitAtTarget;
attackSkillTypeNode - > addAttribute ( " spawnUnitAtTarget " , intToStr ( spawnUnitAtTarget ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
// bool projectile;
attackSkillTypeNode - > addAttribute ( " projectile " , intToStr ( projectile ) , mapTagReplacements ) ;
// ParticleSystemTypeProjectile* projectileParticleSystemType;
2014-07-10 23:34:39 +02:00
// save a skill_type ????
// if(projectileParticleSystemType != NULL) {
// projectileParticleSystemType->saveGame(attackSkillTypeNode);
// }
2012-03-10 04:27:25 +01:00
// SoundContainer projSounds;
//
// bool splash;
attackSkillTypeNode - > addAttribute ( " splash " , intToStr ( splash ) , mapTagReplacements ) ;
// int splashRadius;
attackSkillTypeNode - > addAttribute ( " splashRadius " , intToStr ( splashRadius ) , mapTagReplacements ) ;
// bool splashDamageAll;
attackSkillTypeNode - > addAttribute ( " splashDamageAll " , intToStr ( splashDamageAll ) , mapTagReplacements ) ;
// ParticleSystemTypeSplash* splashParticleSystemType;
if ( splashParticleSystemType ! = NULL ) {
splashParticleSystemType - > saveGame ( attackSkillTypeNode ) ;
}
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class BuildSkillType
// =====================================================
BuildSkillType : : BuildSkillType ( ) {
skillClass = scBuild ;
}
2013-09-21 22:50:58 +02:00
string BuildSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Build " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Build " ) ;
2010-05-25 20:06:42 +02:00
}
// =====================================================
// class HarvestSkillType
// =====================================================
HarvestSkillType : : HarvestSkillType ( ) {
skillClass = scHarvest ;
}
2013-09-21 22:50:58 +02:00
string HarvestSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Harvest " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Harvest " ) ;
2010-05-25 20:06:42 +02:00
}
// =====================================================
// class RepairSkillType
// =====================================================
RepairSkillType : : RepairSkillType ( ) {
skillClass = scRepair ;
}
2013-09-21 22:50:58 +02:00
string RepairSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Repair " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Repair " ) ;
2010-05-25 20:06:42 +02:00
}
// =====================================================
// class ProduceSkillType
// =====================================================
ProduceSkillType : : ProduceSkillType ( ) {
skillClass = scProduce ;
2011-09-01 03:11:23 +02:00
animProgressBound = false ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void ProduceSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-07-08 01:02:46 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2011-07-08 01:02:46 +02:00
if ( sn - > hasChild ( " anim-progress-bound " ) ) {
animProgressBound = sn - > getChild ( " anim-progress-bound " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
else {
animProgressBound = false ;
}
}
2013-09-21 22:50:58 +02:00
string ProduceSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Produce " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Produce " ) ;
2010-05-25 20:06:42 +02:00
}
int ProduceSkillType : : getTotalSpeed ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = speed + totalUpgrade - > getProdSpeed ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
2012-03-10 04:27:25 +01:00
void ProduceSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * produceSkillTypeNode = rootNode - > addChild ( " ProduceSkillType " ) ;
produceSkillTypeNode - > addAttribute ( " animProgressBound " , intToStr ( animProgressBound ) , mapTagReplacements ) ;
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class UpgradeSkillType
// =====================================================
UpgradeSkillType : : UpgradeSkillType ( ) {
skillClass = scUpgrade ;
2011-09-01 03:11:23 +02:00
animProgressBound = false ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void UpgradeSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-07-08 01:02:46 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2011-07-08 01:02:46 +02:00
if ( sn - > hasChild ( " anim-progress-bound " ) ) {
animProgressBound = sn - > getChild ( " anim-progress-bound " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
else {
animProgressBound = false ;
}
}
2013-09-21 22:50:58 +02:00
string UpgradeSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Upgrade " ;
}
2013-10-29 07:13:38 +01:00
return Lang : : getInstance ( ) . getString ( " Upgrade " ) ;
2010-05-25 20:06:42 +02:00
}
int UpgradeSkillType : : getTotalSpeed ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = speed + totalUpgrade - > getProdSpeed ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
2012-03-10 04:27:25 +01:00
void UpgradeSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * upgradeSkillTypeNode = rootNode - > addChild ( " UpgradeSkillType " ) ;
upgradeSkillTypeNode - > addAttribute ( " animProgressBound " , intToStr ( animProgressBound ) , mapTagReplacements ) ;
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class BeBuiltSkillType
// =====================================================
BeBuiltSkillType : : BeBuiltSkillType ( ) {
skillClass = scBeBuilt ;
2011-09-01 03:11:23 +02:00
animProgressBound = false ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void BeBuiltSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-07-02 18:07:04 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2011-07-02 18:07:04 +02:00
2011-07-08 01:02:46 +02:00
if ( sn - > hasChild ( " anim-progress-bound " ) ) {
animProgressBound = sn - > getChild ( " anim-progress-bound " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
else if ( sn - > hasChild ( " anim-hp-bound " ) ) { // deprecated!!!! remove it when you see it after 15th July 2011
animProgressBound = sn - > getChild ( " anim-hp-bound " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
2011-07-02 18:07:04 +02:00
}
else {
2011-07-08 01:02:46 +02:00
animProgressBound = false ;
2011-07-02 18:07:04 +02:00
}
}
2013-09-21 22:50:58 +02:00
string BeBuiltSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Be built " ;
}
2010-05-25 20:06:42 +02:00
return " Be built " ;
}
2012-03-10 04:27:25 +01:00
void BeBuiltSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * beBuiltSkillTypeNode = rootNode - > addChild ( " BeBuiltSkillType " ) ;
beBuiltSkillTypeNode - > addAttribute ( " animProgressBound " , intToStr ( animProgressBound ) , mapTagReplacements ) ;
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class MorphSkillType
// =====================================================
MorphSkillType : : MorphSkillType ( ) {
skillClass = scMorph ;
2011-09-01 03:11:23 +02:00
animProgressBound = false ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void MorphSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-07-08 01:02:46 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2011-07-08 01:02:46 +02:00
if ( sn - > hasChild ( " anim-progress-bound " ) ) {
animProgressBound = sn - > getChild ( " anim-progress-bound " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
else {
animProgressBound = false ;
}
}
2013-09-21 22:50:58 +02:00
string MorphSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Morph " ;
}
2010-05-25 20:06:42 +02:00
return " Morph " ;
}
int MorphSkillType : : getTotalSpeed ( const TotalUpgrade * totalUpgrade ) const {
2011-06-26 09:06:32 +02:00
int result = speed + totalUpgrade - > getProdSpeed ( this ) ;
2011-06-26 05:59:28 +02:00
result = max ( 0 , result ) ;
return result ;
2010-05-25 20:06:42 +02:00
}
2012-03-10 04:27:25 +01:00
void MorphSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * morphSkillTypeNode = rootNode - > addChild ( " MorphSkillType " ) ;
morphSkillTypeNode - > addAttribute ( " animProgressBound " , intToStr ( animProgressBound ) , mapTagReplacements ) ;
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class DieSkillType
// =====================================================
DieSkillType : : DieSkillType ( ) {
skillClass = scDie ;
2011-09-01 03:11:23 +02:00
fade = false ;
2010-05-25 20:06:42 +02:00
}
2011-11-11 05:17:55 +01:00
void DieSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
2011-05-06 09:47:31 +02:00
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
2011-05-05 22:18:38 +02:00
string parentLoader ) {
2011-11-11 05:17:55 +01:00
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
2010-05-25 20:06:42 +02:00
fade = sn - > getChild ( " fade " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
2013-09-21 22:50:58 +02:00
string DieSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " Die " ;
}
2010-05-25 20:06:42 +02:00
return " Die " ;
}
2012-03-10 04:27:25 +01:00
void DieSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * dieSkillTypeNode = rootNode - > addChild ( " DieSkillType " ) ;
dieSkillTypeNode - > addAttribute ( " fade " , intToStr ( fade ) , mapTagReplacements ) ;
}
2014-07-20 03:28:03 +02:00
StaticSound * DieSkillType : : getSound ( ) const {
if ( skillSoundList . size ( ) = = 0 ) {
return NULL ;
}
else {
return skillSoundList . front ( ) - > getSoundContainer ( ) - > getRandSound ( ) ;
}
}
2013-01-11 19:18:58 +01:00
// =====================================================
// class FogOfWarSkillType
// =====================================================
FogOfWarSkillType : : FogOfWarSkillType ( ) {
skillClass = scFogOfWar ;
fowEnable = false ;
applyToTeam = false ;
durationTime = 0 ;
}
void FogOfWarSkillType : : load ( const XmlNode * sn , const XmlNode * attackBoostsNode ,
const string & dir , const TechTree * tt ,
const FactionType * ft , std : : map < string , vector < pair < string , string > > > & loadedFileList ,
string parentLoader ) {
SkillType : : load ( sn , attackBoostsNode , dir , tt , ft , loadedFileList , parentLoader ) ;
fowEnable = sn - > getChild ( " enable-fog " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
applyToTeam = sn - > getChild ( " apply-team " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
durationTime = sn - > getChild ( " duration " ) - > getAttribute ( " value " ) - > getFloatValue ( ) ;
}
2013-09-21 22:50:58 +02:00
string FogOfWarSkillType : : toString ( bool translatedValue ) const {
if ( translatedValue = = false ) {
return " FogOfWar " ;
}
2013-01-11 19:18:58 +01:00
return " FogOfWar " ;
}
void FogOfWarSkillType : : saveGame ( XmlNode * rootNode ) {
SkillType : : saveGame ( rootNode ) ;
std : : map < string , string > mapTagReplacements ;
XmlNode * fogSkillTypeNode = rootNode - > addChild ( " FogOfWarSkillType " ) ;
fogSkillTypeNode - > addAttribute ( " enable-fog " , intToStr ( fowEnable ) , mapTagReplacements ) ;
fogSkillTypeNode - > addAttribute ( " apply-team " , intToStr ( applyToTeam ) , mapTagReplacements ) ;
2013-10-02 22:22:10 +02:00
fogSkillTypeNode - > addAttribute ( " duration " , floatToStr ( durationTime , 6 ) , mapTagReplacements ) ;
2013-01-11 19:18:58 +01:00
}
2010-05-25 20:06:42 +02:00
// =====================================================
// class SkillTypeFactory
// =====================================================
SkillTypeFactory : : SkillTypeFactory ( ) {
registerClass < StopSkillType > ( " stop " ) ;
registerClass < MoveSkillType > ( " move " ) ;
registerClass < AttackSkillType > ( " attack " ) ;
registerClass < BuildSkillType > ( " build " ) ;
registerClass < BeBuiltSkillType > ( " be_built " ) ;
registerClass < HarvestSkillType > ( " harvest " ) ;
registerClass < RepairSkillType > ( " repair " ) ;
registerClass < ProduceSkillType > ( " produce " ) ;
registerClass < UpgradeSkillType > ( " upgrade " ) ;
registerClass < MorphSkillType > ( " morph " ) ;
registerClass < DieSkillType > ( " die " ) ;
2013-01-11 19:18:58 +01:00
registerClass < FogOfWarSkillType > ( " fog_of_war " ) ;
2010-05-25 20:06:42 +02:00
}
SkillTypeFactory & SkillTypeFactory : : getInstance ( ) {
static SkillTypeFactory ctf ;
return ctf ;
}
2011-01-10 06:44:45 +01:00
} } //end namespace