[-] Fixed crash when handlind action for unit killed by TTL

[-] Fixed crash for pience missiles which are gone outside of map
[-] Fixed crash when saving invalid order
[-] Fixed crash when changing owner for dead unit
[-] Don't help to summoned units for AI
This commit is contained in:
cybermind 2013-03-17 12:02:27 +06:00
parent ed541eb8ed
commit 542cb5a5d4
4 changed files with 27 additions and 7 deletions

View file

@ -470,6 +470,10 @@ static void UnitActionsEachCycle(UNITP_ITERATOR begin, UNITP_ITERATOR end)
// Handle each cycle buffs
HandleBuffsEachCycle(unit);
// Unit could be dead after TTL kill
if (unit.Destroyed) {
continue;
}
try {
HandleUnitAction(unit);

View file

@ -655,7 +655,7 @@ void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type)
*/
void AiHelpMe(const CUnit *attacker, CUnit &defender)
{
/* Freandly Fire - typical splash */
/* Friendly Fire - typical splash */
if (!attacker || attacker->Player->Index == defender.Player->Index) {
//FIXME - try react somehow
return;
@ -669,11 +669,14 @@ void AiHelpMe(const CUnit *attacker, CUnit &defender)
if (!defender.Type->CanAttack && defender.Type->UnitType == UnitTypeFly) {
return;
}
// Summoned unit, don't help
if (defender.GroupId == -1) {
return;
}
PlayerAi &pai = *defender.Player->Ai;
AiPlayer = &pai;
// If unit belongs to an attacking force, check if force members can help.
if (defender.GroupId) {
AiForce &aiForce = pai.Force[defender.GroupId - 1];

View file

@ -647,10 +647,18 @@ bool MissileInitMove(Missile &missile)
void MissileHandlePierce(Missile &missile, const Vec2i &pos)
{
CUnit *unit = UnitOnMapTile(pos, -1);
if (unit && unit->IsAliveOnMap()
&& (missile.Type->FriendlyFire || unit->IsEnemy(*missile.SourceUnit->Player))) {
missile.MissileHit(unit);
if (Map.Info.IsPointOnMap(pos) == false) {
return;
}
std::vector<CUnit *> units;
Select(pos, pos, units);
for (std::vector<CUnit *>::iterator it = units.begin(); it != units.end(); ++it) {
CUnit &unit = **it;
if (unit.IsAliveOnMap()
&& (missile.Type->FriendlyFire || unit.IsEnemy(*missile.SourceUnit->Player))) {
missile.MissileHit(&unit);
}
}
}

View file

@ -665,7 +665,7 @@ bool CUnit::CanStoreOrder(COrder *order)
{
Assert(order);
if (order && order->Finished == true && order->IsValid() == false) {
if ((order && order->Finished == true) || order->IsValid() == false) {
return false;
}
if (this->SavedOrder != NULL) {
@ -1664,6 +1664,11 @@ void CUnit::ChangeOwner(CPlayer &newplayer)
return;
}
// Can't change owner for dead units
if (this->IsAlive() == false) {
return;
}
// Rescue all units in buildings/transporters.
CUnit *uins = UnitInside;
for (int i = InsideCount; i; --i, uins = uins->NextContained) {