- added numerous guards around spawn code because we had a number of crashes from this code somehow tonight
This commit is contained in:
parent
2d0912ae19
commit
b5e4eb53d8
|
@ -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());
|
||||
}
|
||||
|
||||
throw runtime_error("Unit not found: "+name);
|
||||
throw runtime_error("Unit not found: [" + name + "]");
|
||||
}
|
||||
|
||||
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
|
||||
|
|
|
@ -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();
|
||||
if (sn->hasChild("hp-cost")) {
|
||||
hpCost = sn->getChild("hp-cost")->getAttribute("value")->getIntValue();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
hpCost = 0;
|
||||
}
|
||||
|
||||
|
@ -166,6 +167,8 @@ AttackSkillType::AttackSkillType() {
|
|||
projectile= false;
|
||||
splash= false;
|
||||
splashRadius= 0;
|
||||
spawnUnit="";
|
||||
spawnUnitcount=0;
|
||||
projectileParticleSystemType= NULL;
|
||||
splashParticleSystemType= NULL;
|
||||
|
||||
|
|
|
@ -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,
|
||||
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 j = 1; j <= munit->getSize(); ++j) {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -148,15 +148,20 @@ void UnitUpdater::updateUnit(Unit *unit) {
|
|||
unit->setCurrSkill(scStop);
|
||||
unit->cancelCommand();
|
||||
}
|
||||
if(unit->getCurrSkill()->getClass() != scAttack){
|
||||
unit->computeHp();
|
||||
if(unit->getCurrSkill() != NULL && unit->getCurrSkill()->getClass() != scAttack) {
|
||||
unit->computeHp();
|
||||
}
|
||||
else{
|
||||
else if(unit->getCommandSize() > 0) {
|
||||
Command *command= unit->getCurrCommand();
|
||||
if(command != NULL) {
|
||||
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
|
||||
if(act->getAttackSkillType()->getSpawnUnit() != ""){
|
||||
for (int y=0; y < act->getAttackSkillType()->getSpawnUnitCount(); ++y) {
|
||||
Unit *spawned;
|
||||
if( act != NULL && act->getAttackSkillType() != NULL &&
|
||||
act->getAttackSkillType()->getSpawnUnit() != "" && act->getAttackSkillType()->getSpawnUnitCount() > 0) {
|
||||
|
||||
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;
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
|
@ -168,20 +173,24 @@ unit->computeHp();
|
|||
default:
|
||||
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());
|
||||
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());
|
||||
|
||||
// This will also cleanup newPath
|
||||
delete spawned;
|
||||
spawned = NULL;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
spawned->create();
|
||||
spawned->born();
|
||||
world->getStats()->produce(unit->getFactionIndex());
|
||||
const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit());
|
||||
if(ct!=NULL){
|
||||
if(ct != NULL){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
spawned->giveCommand(new Command(ct, unit->getMeetingPos()));
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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){
|
||||
if(attacker == NULL) {
|
||||
throw runtime_error("attacker == NULL");
|
||||
}
|
||||
if(ast == NULL) {
|
||||
throw runtime_error("ast == NULL");
|
||||
}
|
||||
|
||||
//get vars
|
||||
float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
|
||||
int var= ast->getAttackVar();
|
||||
|
|
Loading…
Reference in New Issue