- added numerous guards around spawn code because we had a number of crashes from this code somehow tonight

This commit is contained in:
Mark Vejvoda 2011-02-11 07:39:58 +00:00
parent 2d0912ae19
commit b5e4eb53d8
5 changed files with 68 additions and 48 deletions

View File

@ -527,7 +527,7 @@ const UnitType *FactionType::getUnitType(const string &name) const{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,unitTypes[i].getName().c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,unitTypes[i].getName().c_str());
} }
throw runtime_error("Unit not found: "+name); throw runtime_error("Unit not found: [" + name + "]");
} }
const UpgradeType *FactionType::getUpgradeType(const string &name) const{ const UpgradeType *FactionType::getUpgradeType(const string &name) const{

View File

@ -49,7 +49,8 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
mpCost= sn->getChild("ep-cost")->getAttribute("value")->getIntValue(); mpCost= sn->getChild("ep-cost")->getAttribute("value")->getIntValue();
if (sn->hasChild("hp-cost")) { if (sn->hasChild("hp-cost")) {
hpCost = sn->getChild("hp-cost")->getAttribute("value")->getIntValue(); hpCost = sn->getChild("hp-cost")->getAttribute("value")->getIntValue();
} else { }
else {
hpCost = 0; hpCost = 0;
} }
@ -166,6 +167,8 @@ AttackSkillType::AttackSkillType() {
projectile= false; projectile= false;
splash= false; splash= false;
splashRadius= 0; splashRadius= 0;
spawnUnit="";
spawnUnitcount=0;
projectileParticleSystemType= NULL; projectileParticleSystemType= NULL;
splashParticleSystemType= NULL; splashParticleSystemType= NULL;

View File

@ -434,6 +434,12 @@ bool Map::isFreeCells(const Vec2i & pos, int size, Field field) const {
bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field,
const Unit *unit, const UnitType *munit) const { const Unit *unit, const UnitType *munit) const {
if(unit == NULL) {
throw runtime_error("unit == NULL");
}
if(munit == NULL) {
throw runtime_error("munit == NULL");
}
for (int i = 1; i <= munit->getSize(); ++i) { for (int i = 1; i <= munit->getSize(); ++i) {
for (int j = 1; j <= munit->getSize(); ++j) { for (int j = 1; j <= munit->getSize(); ++j) {
if (munit->hasCellMap() == true) { if (munit->hasCellMap() == true) {
@ -443,10 +449,6 @@ bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field,
Vec2i(pos.x + i - 1, pos.y + j - 1), field, unit) == false) { Vec2i(pos.x + i - 1, pos.y + j - 1), field, unit) == false) {
return false; return false;
} }
else {
}
}
else {
} }
} }
else { else {

View File

@ -148,15 +148,20 @@ void UnitUpdater::updateUnit(Unit *unit) {
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
unit->cancelCommand(); unit->cancelCommand();
} }
if(unit->getCurrSkill()->getClass() != scAttack){ if(unit->getCurrSkill() != NULL && unit->getCurrSkill()->getClass() != scAttack) {
unit->computeHp(); unit->computeHp();
} }
else{ else if(unit->getCommandSize() > 0) {
Command *command= unit->getCurrCommand(); Command *command= unit->getCurrCommand();
if(command != NULL) {
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType()); const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
if(act->getAttackSkillType()->getSpawnUnit() != ""){ if( act != NULL && act->getAttackSkillType() != NULL &&
for (int y=0; y < act->getAttackSkillType()->getSpawnUnitCount(); ++y) { act->getAttackSkillType()->getSpawnUnit() != "" && act->getAttackSkillType()->getSpawnUnitCount() > 0) {
Unit *spawned;
const FactionType *ft= unit->getFaction()->getType();
const UnitType *spawnUnitType = ft->getUnitType(act->getAttackSkillType()->getSpawnUnit());
int spawnCount = act->getAttackSkillType()->getSpawnUnitCount();
for (int y=0; y < spawnCount; ++y) {
UnitPathInterface *newpath = NULL; UnitPathInterface *newpath = NULL;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic:
@ -168,13 +173,17 @@ unit->computeHp();
default: default:
throw runtime_error("detected unsupported pathfinder type!"); throw runtime_error("detected unsupported pathfinder type!");
} }
const FactionType *ft= unit->getFaction()->getType();
spawned= new Unit(world->getNextUnitId(unit->getFaction()), newpath, Vec2i(0),ft->getUnitType(act->getAttackSkillType()->getSpawnUnit()), unit->getFaction(), world->getMap(),CardinalDir::NORTH); Unit *spawned= new Unit(world->getNextUnitId(unit->getFaction()), newpath,
Vec2i(0), spawnUnitType, unit->getFaction(),
world->getMap(), CardinalDir::NORTH);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] about to place unit for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,spawned->toString().c_str()); SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] about to place unit for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,spawned->toString().c_str());
if(!world->placeUnit(unit->getCenteredPos(), 10, spawned)) { if(!world->placeUnit(unit->getCenteredPos(), 10, spawned)) {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] COULD NOT PLACE UNIT for unitID [%d]\n",__FILE__,__FUNCTION__,__LINE__,spawned->getId()); SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] COULD NOT PLACE UNIT for unitID [%d]\n",__FILE__,__FUNCTION__,__LINE__,spawned->getId());
// This will also cleanup newPath
delete spawned; delete spawned;
spawned = NULL;
} }
else { else {
spawned->create(); spawned->create();
@ -190,8 +199,7 @@ unit->computeHp();
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
} }
} }
}
} }
} }
@ -1641,6 +1649,13 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
} }
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance){ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance){
if(attacker == NULL) {
throw runtime_error("attacker == NULL");
}
if(ast == NULL) {
throw runtime_error("ast == NULL");
}
//get vars //get vars
float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade()); float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
int var= ast->getAttackVar(); int var= ast->getAttackVar();