- added a new validation for faction validation report AND game load for attack-var since a negative value will segfault the game

This commit is contained in:
Mark Vejvoda
2011-01-10 05:44:45 +00:00
parent 18a0a93a8e
commit b201cebf3b
2 changed files with 53 additions and 27 deletions

View File

@@ -275,7 +275,7 @@ std::vector<std::string> FactionType::validateFactionType() {
results.push_back(szBuf); results.push_back(szBuf);
} }
} }
} }
} }
} }
@@ -360,7 +360,23 @@ std::vector<std::string> FactionType::validateFactionType() {
char szBuf[4096]=""; char szBuf[4096]="";
sprintf(szBuf,"The Unit [%s] in Faction [%s] has no other units that can produce, build or morph into it in this faction!",unitType.getName().c_str(),this->getName().c_str()); sprintf(szBuf,"The Unit [%s] in Faction [%s] has no other units that can produce, build or morph into it in this faction!",unitType.getName().c_str(),this->getName().c_str());
results.push_back(szBuf); results.push_back(szBuf);
} }
// Ensure that all attack skill types have valid values
if(unitType.hasSkillClass(scAttack) == true) {
for(int j = 0; j < unitType.getSkillTypeCount(); ++j) {
const SkillType *st = unitType.getSkillType(j);
if(st != NULL && dynamic_cast<const AttackSkillType *>(st) != NULL) {
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(st);
if(ast->getAttackVar() < 0) {
char szBuf[4096]="";
sprintf(szBuf,"The Unit [%s] in Faction [%s] has the skill [%s] with an INVALID attack var value which is < 0 [%d]!",unitType.getName().c_str(),this->getName().c_str(),ast->getName().c_str(),ast->getAttackVar());
results.push_back(szBuf);
}
}
}
}
// end
} }
return results; return results;

View File

@@ -3,9 +3,9 @@
// //
// Copyright (C) 2001-2008 Marti<74>o Figueroa // Copyright (C) 2001-2008 Marti<74>o Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the // by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version // License, or (at your option) any later version
// ============================================================== // ==============================================================
@@ -44,21 +44,21 @@ SkillType::~SkillType(){
void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){
//name //name
name= sn->getChild("name")->getAttribute("value")->getRestrictedValue(); name= sn->getChild("name")->getAttribute("value")->getRestrictedValue();
//ep cost //ep cost
mpCost= sn->getChild("ep-cost")->getAttribute("value")->getIntValue(); mpCost= sn->getChild("ep-cost")->getAttribute("value")->getIntValue();
//speed //speed
speed= sn->getChild("speed")->getAttribute("value")->getIntValue(); speed= sn->getChild("speed")->getAttribute("value")->getIntValue();
//anim speed //anim speed
animSpeed= sn->getChild("anim-speed")->getAttribute("value")->getIntValue(); animSpeed= sn->getChild("anim-speed")->getAttribute("value")->getIntValue();
//model //model
string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(); string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue();
animation= Renderer::getInstance().newModel(rsGame); animation= Renderer::getInstance().newModel(rsGame);
animation->load(dir + "/" + path); animation->load(dir + "/" + path);
//particles //particles
if(sn->hasChild("particles")){ if(sn->hasChild("particles")){
const XmlNode *particleNode= sn->getChild("particles"); const XmlNode *particleNode= sn->getChild("particles");
@@ -73,15 +73,15 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
} }
} }
} }
//sound //sound
const XmlNode *soundNode= sn->getChild("sound"); const XmlNode *soundNode= sn->getChild("sound");
if(soundNode->getAttribute("enabled")->getBoolValue()){ if(soundNode->getAttribute("enabled")->getBoolValue()){
soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); soundStartTime= soundNode->getAttribute("start-time")->getFloatValue();
sounds.resize(soundNode->getChildCount()); sounds.resize(soundNode->getChildCount());
for(int i=0; i<soundNode->getChildCount(); ++i){ for(int i=0; i<soundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
@@ -155,7 +155,7 @@ int MoveSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{
// ===================================================== // =====================================================
//varios //varios
AttackSkillType::AttackSkillType(){ AttackSkillType::AttackSkillType() {
skillClass= scAttack; skillClass= scAttack;
attackType= NULL; attackType= NULL;
projectile= false; projectile= false;
@@ -163,24 +163,34 @@ AttackSkillType::AttackSkillType(){
splashRadius= 0; splashRadius= 0;
projectileParticleSystemType= NULL; projectileParticleSystemType= NULL;
splashParticleSystemType= NULL; splashParticleSystemType= NULL;
for(int i=0; i<fieldCount; ++i){
for(int i = 0; i < fieldCount; ++i) {
attackFields[i]= false; attackFields[i]= false;
} }
} }
AttackSkillType::~AttackSkillType(){ AttackSkillType::~AttackSkillType() {
delete projectileParticleSystemType; delete projectileParticleSystemType;
projectileParticleSystemType = NULL;
delete splashParticleSystemType; delete splashParticleSystemType;
splashParticleSystemType = NULL;
deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end()); deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end());
} }
void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft) {
SkillType::load(sn, dir, tt, ft);
SkillType::load(sn, dir, tt, ft);
//misc //misc
attackStrength= sn->getChild("attack-strenght")->getAttribute("value")->getIntValue(); attackStrength= sn->getChild("attack-strenght")->getAttribute("value")->getIntValue();
attackVar= sn->getChild("attack-var")->getAttribute("value")->getIntValue(); attackVar= sn->getChild("attack-var")->getAttribute("value")->getIntValue();
if(attackVar < 0) {
char szBuf[4096]="";
sprintf(szBuf,"The attack skill has an INVALID attack var value which is < 0 [%d] in file [%s]!",attackVar,dir.c_str());
throw runtime_error(szBuf);
}
attackRange= sn->getChild("attack-range")->getAttribute("value")->getIntValue(); attackRange= sn->getChild("attack-range")->getAttribute("value")->getIntValue();
string attackTypeName= sn->getChild("attack-type")->getAttribute("value")->getRestrictedValue(); string attackTypeName= sn->getChild("attack-type")->getAttribute("value")->getRestrictedValue();
attackType= tt->getAttackType(attackTypeName); attackType= tt->getAttackType(attackTypeName);
@@ -193,7 +203,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
string fieldName= fieldNode->getAttribute("value")->getRestrictedValue(); string fieldName= fieldNode->getAttribute("value")->getRestrictedValue();
if(fieldName=="land"){ if(fieldName=="land"){
attackFields[fLand]= true; attackFields[fLand]= true;
} }
else if(fieldName=="air"){ else if(fieldName=="air"){
attackFields[fAir]= true; attackFields[fAir]= true;
} }
@@ -206,12 +216,12 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
const XmlNode *projectileNode= sn->getChild("projectile"); const XmlNode *projectileNode= sn->getChild("projectile");
projectile= projectileNode->getAttribute("value")->getBoolValue(); projectile= projectileNode->getAttribute("value")->getBoolValue();
if(projectile){ if(projectile){
//proj particle //proj particle
const XmlNode *particleNode= projectileNode->getChild("particle"); const XmlNode *particleNode= projectileNode->getChild("particle");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); projectileParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
} }
@@ -219,7 +229,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
//proj sounds //proj sounds
const XmlNode *soundNode= projectileNode->getChild("sound"); const XmlNode *soundNode= projectileNode->getChild("sound");
if(soundNode->getAttribute("enabled")->getBoolValue()){ if(soundNode->getAttribute("enabled")->getBoolValue()){
projSounds.resize(soundNode->getChildCount()); projSounds.resize(soundNode->getChildCount());
for(int i=0; i<soundNode->getChildCount(); ++i){ for(int i=0; i<soundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
@@ -242,7 +252,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
const XmlNode *particleNode= splashNode->getChild("particle"); const XmlNode *particleNode= splashNode->getChild("particle");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
splashParticleSystemType= new ParticleSystemTypeSplash(); splashParticleSystemType= new ParticleSystemTypeSplash();
splashParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); splashParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
} }
@@ -399,4 +409,4 @@ SkillTypeFactory &SkillTypeFactory::getInstance(){
return ctf; return ctf;
} }
}} //end namespace }} //end namespace