diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index b0fe6c67..e8d554e2 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -660,16 +660,21 @@ void Ai::unblockUnits() { iterMap2 != iterMap->second.end(); iterMap2++) { int idx = iterMap2->first; const Unit *adjacentUnit = iterMap2->second; + if(adjacentUnit != NULL && adjacentUnit->getType()->getFirstCtOfClass(ccMove) != NULL) { + const CommandType *ct = adjacentUnit->getType()->getFirstCtOfClass(ccMove); - for(int moveAttempt = 1; moveAttempt <= villageRadius; ++moveAttempt) { - Vec2i pos= Vec2i( - random.randRange(-villageRadius*2, villageRadius*2), random.randRange(-villageRadius*2, villageRadius*2)) + - adjacentUnit->getPos(); + for(int moveAttempt = 1; moveAttempt <= villageRadius; ++moveAttempt) { + Vec2i pos= Vec2i( + random.randRange(-villageRadius*2, villageRadius*2), random.randRange(-villageRadius*2, villageRadius*2)) + + adjacentUnit->getPos(); - bool canUnitMoveToCell = map->aproxCanMove(adjacentUnit, adjacentUnit->getPos(), pos); - if(canUnitMoveToCell == true) { - const CommandType *ct = adjacentUnit->getType()->getFirstCtOfClass(ccMove); - CommandResult r = aiInterface->giveCommand(adjacentUnit,ct, pos); + bool canUnitMoveToCell = map->aproxCanMove(adjacentUnit, adjacentUnit->getPos(), pos); + if(canUnitMoveToCell == true) { + + if(ct != NULL) { + CommandResult r = aiInterface->giveCommand(adjacentUnit,ct, pos); + } + } } } } diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 1c6d8e45..817e0f31 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -146,6 +146,11 @@ CommandResult AiInterface::giveCommand(const Unit *unit, const CommandType *comm sprintf(szBuf,"In [%s::%s Line: %d] Can not find AI unittype with unit id: %d, AI factionIndex = %d. Game out of synch.",__FILE__,__FUNCTION__,__LINE__,unit->getId(),factionIndex); throw runtime_error(szBuf); } + if(commandType == NULL) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s Line: %d] commandType == NULL, unit id: %d, AI factionIndex = %d. Game out of synch.",__FILE__,__FUNCTION__,__LINE__,unit->getId(),factionIndex); + throw runtime_error(szBuf); + } const CommandType* ct= unit->getType()->findCommandTypeById(commandType->getId()); if(ct == NULL) { char szBuf[4096]="";