- 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());
|
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{
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ public:
|
||||||
bool getAttackField(Field field) const {return attackFields[field];}
|
bool getAttackField(Field field) const {return attackFields[field];}
|
||||||
float getAttackStartTime() const {return attackStartTime;}
|
float getAttackStartTime() const {return attackStartTime;}
|
||||||
string getSpawnUnit() const {return spawnUnit;}
|
string getSpawnUnit() const {return spawnUnit;}
|
||||||
int getSpawnUnitCount() const {return spawnUnitcount;}
|
int getSpawnUnitCount() const {return spawnUnitcount;}
|
||||||
|
|
||||||
//get proj
|
//get proj
|
||||||
bool getProjectile() const {return projectile;}
|
bool getProjectile() const {return projectile;}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -148,52 +148,60 @@ 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();
|
||||||
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
|
if(command != NULL) {
|
||||||
if(act->getAttackSkillType()->getSpawnUnit() != ""){
|
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
|
||||||
for (int y=0; y < act->getAttackSkillType()->getSpawnUnitCount(); ++y) {
|
if( act != NULL && act->getAttackSkillType() != NULL &&
|
||||||
Unit *spawned;
|
act->getAttackSkillType()->getSpawnUnit() != "" && act->getAttackSkillType()->getSpawnUnitCount() > 0) {
|
||||||
UnitPathInterface *newpath = NULL;
|
|
||||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
|
||||||
case pfBasic:
|
|
||||||
newpath = new UnitPathBasic();
|
|
||||||
break;
|
|
||||||
case pfRoutePlanner:
|
|
||||||
newpath = new UnitPath();
|
|
||||||
break;
|
|
||||||
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);
|
|
||||||
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());
|
|
||||||
|
|
||||||
delete spawned;
|
const FactionType *ft= unit->getFaction()->getType();
|
||||||
}
|
const UnitType *spawnUnitType = ft->getUnitType(act->getAttackSkillType()->getSpawnUnit());
|
||||||
else{
|
int spawnCount = act->getAttackSkillType()->getSpawnUnitCount();
|
||||||
spawned->create();
|
for (int y=0; y < spawnCount; ++y) {
|
||||||
spawned->born();
|
UnitPathInterface *newpath = NULL;
|
||||||
world->getStats()->produce(unit->getFactionIndex());
|
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||||
const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit());
|
case pfBasic:
|
||||||
if(ct!=NULL){
|
newpath = new UnitPathBasic();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
break;
|
||||||
spawned->giveCommand(new Command(ct, unit->getMeetingPos()));
|
case pfRoutePlanner:
|
||||||
|
newpath = new UnitPath();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
spawned->create();
|
||||||
|
spawned->born();
|
||||||
|
world->getStats()->produce(unit->getFactionIndex());
|
||||||
|
const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit());
|
||||||
|
if(ct != NULL){
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
spawned->giveCommand(new Command(ct, unit->getMeetingPos()));
|
||||||
|
}
|
||||||
|
scriptManager->onUnitCreated(spawned);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scriptManager->onUnitCreated(spawned);
|
|
||||||
|
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//move unit in cells
|
//move unit in cells
|
||||||
if(unit->getCurrSkill()->getClass() == scMove) {
|
if(unit->getCurrSkill()->getClass() == scMove) {
|
||||||
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue