Skip to content

Commit

Permalink
Fix suspicious_assignment warnings in Defense
Browse files Browse the repository at this point in the history
  • Loading branch information
isilkor committed Jul 23, 2018
1 parent 808a90e commit 806357e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
19 changes: 12 additions & 7 deletions planet/Defense.ocf/FightForGidl.ocs/Script.c
Expand Up @@ -74,11 +74,13 @@ func RemovePlayer(int plr)
private func TransferInventory(object from, object to)
{
// Drop some items that cannot be transferred (such as connected pipes and dynamite igniters)
var i = from->ContentsCount(), contents;
var i = from->ContentsCount();
while (i--)
if (contents = from->Contents(i))
if (contents->~IsDroppedOnDeath(from))
contents->Exit();
{
var contents = from->Contents(i);
if (contents && contents->~IsDroppedOnDeath(from))
contents->Exit();
}
return to->GrabContents(from);
}

Expand Down Expand Up @@ -303,10 +305,13 @@ func OnClonkDeath(clonk, killed_by)
{
// Enemy clonk death
// Remove inventory
var i = clonk->ContentsCount(), obj;
while (i--) if (obj=clonk->Contents(i))
if (!obj->~OnContainerDeath())
var i = clonk->ContentsCount();
while (i--)
{
var obj = clonk->Contents(i);
if (obj && !obj->~OnContainerDeath())
obj->RemoveObject();
}
// Clear enemies from list
i = GetIndexOf(g_spawned_enemies, clonk);
if (i>=0)
Expand Down
10 changes: 7 additions & 3 deletions planet/Defense.ocf/Windmill.ocs/CustomAI.ocd/Script.c
Expand Up @@ -20,7 +20,7 @@ public func FindTarget(effect fx, bool parent)
private func FindInventoryWeapon(effect fx)
{
// Extra weapons
if (fx.weapon = fx.Target->FindContents(Axe))
if (FindInventoryWeaponBase(fx, Axe))
{
fx.strategy = this.ExecuteMelee;
return true;
Expand Down Expand Up @@ -357,8 +357,12 @@ private func ExecuteRanged(effect fx)
// Path not free or out of range. Just wait for enemy to come...
fx.aim_weapon->ControlUseHolding(fx.Target,tx-x,ty-y);
// Might also change target if current is unreachable
var new_target;
if (!Random(3)) if (new_target = this->FindTarget(fx)) fx.target = new_target;
if (!Random(3))
{
var new_target = this->FindTarget(fx);
if (new_target)
fx.target = new_target;
}
return true;
}

Expand Down
21 changes: 13 additions & 8 deletions planet/Defense.ocf/Windmill.ocs/Script.c
Expand Up @@ -74,11 +74,13 @@ func RemovePlayer(int plr)
private func TransferInventory(object from, object to)
{
// Drop some items that cannot be transferred (such as connected pipes and dynamite igniters)
var i = from->ContentsCount(), contents;
var i = from->ContentsCount();
while (i--)
if (contents = from->Contents(i))
if (contents->~IsDroppedOnDeath(from))
contents->Exit();
{
var contents = from->Contents(i);
if (contents && contents->~IsDroppedOnDeath(from))
contents->Exit();
}
return to->GrabContents(from);
}

Expand Down Expand Up @@ -169,10 +171,13 @@ func OnClonkDeath(clonk, killed_by)
{
// Enemy clonk death
// Remove inventory
var i = clonk->ContentsCount(), obj;
while (i--) if (obj=clonk->Contents(i))
if (!obj->~OnContainerDeath())
var i = clonk->ContentsCount();
while (i--)
{
var obj = clonk->Contents(i);
if (obj && !obj->~OnContainerDeath())
obj->RemoveObject();
}
// Clear enemies from list
i = GetIndexOf(g_spawned_enemies, clonk);
if (i>=0)
Expand Down Expand Up @@ -516,4 +521,4 @@ func InitWaveData()
Arrows = [{ X = 0, Y = 0 },{ X = 2000, Y = 0 },{ X = 0, Y = 300 },{ X = 2000, Y = 300 },{ X = 1000, Y = 0 },{ X = 0, Y = 1250 },{ X = 2000, Y = 1250 },{ X = 200, Y = 2000 },{ X = 1800, Y = 2000 },{ X = 880, Y = 2000 },{ X = 1120, Y = 2000 }]
}];
return true;
}
}

0 comments on commit 806357e

Please sign in to comment.