fix a bunch of suspicious assignment warnings

master
Maikel de Vries 2018-04-09 11:53:55 +02:00
parent d9f9a2a9a3
commit c00a8cf3c3
30 changed files with 132 additions and 108 deletions

View File

@ -337,11 +337,13 @@ private func GainTechnology(proplist entry)
// Technology gain callback.
Call(Format("~Gain%s", entry.tech), entry, tier);
// Update any related techs that may become available
var n = GetLength(base_material), req;
var n = GetLength(base_material);
for (var i=0; i<n; ++i)
if (req = base_material[i].requirements)
if (GetIndexOf(req, entry.tech) >= 0)
UpdateIndexedItem(i);
{
var req = base_material[i].requirements;
if (req && GetIndexOf(req, entry.tech) >= 0)
UpdateIndexedItem(i);
}
return true;
}

View File

@ -522,9 +522,14 @@ func UpdateEnemy()
func UpdateFood()
{
// Need food?
if (GetEnergy() >= MaxEnergy/1000) return food = nil;
if (GetEnergy() >= MaxEnergy/1000)
{
food = nil;
return;
}
// Last one too far away now?
if (food && ObjectDistance(this, food) > 150) food = nil;
if (food && ObjectDistance(this, food) > 150)
food = nil;
// Slid in water?
if (food && food->GBackLiquid()) food = nil;

View File

@ -271,15 +271,17 @@ public func PlayAnimation(string animation, int index, array position, array wei
public func GetAnimationLength(string animation)
{
var replacement;
if(PropAnimations != nil)
if(replacement = GetProperty(animation, PropAnimations))
if (PropAnimations != nil)
{
var replacement = GetProperty(animation, PropAnimations);
if (replacement)
{
if(GetType(replacement) == C4V_Array)
animation = replacement[0];
else
animation = replacement;
}
}
return inherited(animation, ...);
}
@ -420,8 +422,9 @@ func GetWalkAnimationPosition(string new_anim, int current_pos, string current_a
if(PropAnimations != nil)
if(GetProperty(Format("%s_Position", new_anim), PropAnimations))
{
var length = GetAnimationLength(new_anim), replacement;
if(replacement = GetProperty(new_anim, PropAnimations))
var length = GetAnimationLength(new_anim);
var replacement = GetProperty(new_anim, PropAnimations);
if (replacement)
{
// at this point /replacement/ may contain an array of two animations that signal a merge
// in that case, just take the first one..

View File

@ -95,9 +95,11 @@ public func Reset()
var plr;
for (var i=0; i<GetPlayerCount(C4PT_User); ++i)
{
var plr = GetPlayerByIndex(i, C4PT_User), cursor;
var plr = GetPlayerByIndex(i, C4PT_User);
var controller = CreateObject(GetGUIControllerID(), 0, 0, plr);
if (cursor = GetCursor(plr)) controller->~OnCrewSelection(cursor);
var cursor = GetCursor(plr);
if (cursor)
controller->~OnCrewSelection(cursor);
}
}
return true;

View File

@ -85,8 +85,8 @@ func Update()
{
var p = (current * 100) / maximum;
var charge = (255 * p) / 100;
var clr;
if(clr = image->~GetBarColor(p))
var clr = image->~GetBarColor(p);
if (clr)
{
lr = clr.r;
lg = clr.g;

View File

@ -217,7 +217,7 @@ func Departure_WeaponRespawn(object container, ...)
// Remove this weapon after a while
// (This function should be save to be called in foreign context)
ScheduleCall(this, Rule_ObjectFade.FadeOutObject, 120, 1, this);
// Revert to previou sdeparture call. No double-respawn in case it gets collected
// Revert to previous departure call. No double-respawn in case it gets collected
if ((this.Departure = this.WeaponRespawn_Departure))
{
return Call(this.Departure, container, ...);

View File

@ -180,7 +180,8 @@ public func ExecuteAttackPath(effect fx)
{
alive_check = Find_OCF(OCF_Alive);
}
if ((fx.target = FindObject(Find_AtPoint(next_pt.X, next_pt.Y), Find_Func("IsStructure"), alive_check)))
fx.target = FindObject(Find_AtPoint(next_pt.X, next_pt.Y), Find_Func("IsStructure"), alive_check);
if (fx.target)
{
// Do not advance on path unless target(s) destroyed.
return true;

View File

@ -115,10 +115,8 @@ private func ExecuteRanged(effect fx)
if (fx.is_aggressive && d > 40)
fx.Target->SetCommand("MoveTo", nil, fx.target->GetX(), fx.target->GetY());
// Might also change target if current is unreachable.
var new_target;
if (!Random(3))
if (new_target = this->FindTarget(fx))
fx.target = new_target;
fx.target = this->FindTarget(fx) ?? fx.target;
return true;
}

View File

@ -105,17 +105,18 @@ public func Execute(effect fx, int time)
// Wake up nearby allies.
if (fx.ally_alert_range)
{
var ally_fx;
for (var ally in fx.Target->FindObjects(Find_Distance(fx.ally_alert_range), Find_Exclude(fx.Target), Find_OCF(OCF_CrewMember), Find_Owner(fx.Target->GetOwner())))
if (ally_fx = this->GetAI(ally))
if (!ally_fx.target)
{
ally_fx.target = fx.target;
ally_fx.alert = ally_fx.time;
if (ally_fx.encounter_cb)
if (GameCall(ally_fx.encounter_cb, ally, fx.target))
ally_fx.encounter_cb = nil;
}
{
var ally_fx = this->GetAI(ally);
if (ally_fx && !ally_fx.target)
{
ally_fx.target = fx.target;
ally_fx.alert = ally_fx.time;
if (ally_fx.encounter_cb)
if (GameCall(ally_fx.encounter_cb, ally, fx.target))
ally_fx.encounter_cb = nil;
}
}
// Do some messages.
this->ExecuteIntruderMessage(fx);
// Waking up works only once. after that, AI might have moved and wake up clonks it shouldn't.

View File

@ -71,8 +71,8 @@ func FxSproutCheckTimer(target, effect, time)
}
// already a bush here?
var b;
if(b = FindObject(Find_Distance(20 + Random(10)), Find_ID(SproutBerryBush)))
var b = FindObject(Find_Distance(20 + Random(10)), Find_ID(SproutBerryBush));
if (b)
{
// extra fertilizer
b.saved_water += SproutBerryBush_water_per_berry * 2;

View File

@ -42,11 +42,14 @@ public func MergeWithStacksIn(object to_building, ...)
{
if (to_building && to_building->~IsProducer() && !to_building->~IsCollectionAllowed(this))
{
var i = ContentsCount(), contents, num_collected = 0;
var i = ContentsCount(), num_collected = 0;
while (i--)
if (contents = Contents(i))
{
var contents = Contents(i);
if (contents)
if (to_building->Collect(contents))
++num_collected;
}
// Return if contents transfer was successful.
if (num_collected > 0) return true;
}

View File

@ -44,11 +44,12 @@ public func GetConnectedItem(object source)
public func StartFusing(object controller)
{
var effect;
if (effect = GetEffect("IntFusing", this))
var fx = GetEffect("IntFusing", this);
if (fx)
{
// Double fuse start scheduled? Ignore.
if (effect.fuse_source == controller) return false;
if (fx.fuse_source == controller)
return false;
// Fuse from both sides not supported
return RemoveObject();
}
@ -71,13 +72,13 @@ public func StartFusing(object controller)
fuse_call = GetActionTarget(0);
fuse_vertex = GetVertexNum()-1;
}
effect = AddEffect("IntFusing", this, 100, 1, this);
effect.fuse_dir = fuse_dir;
effect.fuse_source = controller;
effect.fuse_call = fuse_call;
effect.fuse_vertex = fuse_vertex;
effect.fuse_x = GetVertex(fuse_vertex, VTX_X) * 10;
effect.fuse_y = GetVertex(fuse_vertex, VTX_Y) * 10;
fx = AddEffect("IntFusing", this, 100, 1, this);
fx.fuse_dir = fuse_dir;
fx.fuse_source = controller;
fx.fuse_call = fuse_call;
fx.fuse_vertex = fuse_vertex;
fx.fuse_x = GetVertex(fuse_vertex, VTX_X) * 10;
fx.fuse_y = GetVertex(fuse_vertex, VTX_Y) * 10;
return true;
}

View File

@ -8,7 +8,7 @@
local radius; //actual effect radius to grab objects
local radiusparticle; //radius of particles around object
local aiming;
local is_aiming;
local anim_spin;
local iAngle;
@ -74,10 +74,10 @@ public func ControlUseStart(object clonk, ix, iy)
public func ControlUseHolding(object clonk, ix, iy)
{
if(!clonk->HasHandAction() || !aiming || (!clonk->IsWalking() && !clonk->IsJumping()))
if (!clonk->HasHandAction() || !is_aiming || (!clonk->IsWalking() && !clonk->IsJumping()))
{
CancelUse(clonk);
return 1;
return true;
}
UpdateGloveAngle(clonk, ix, iy);
@ -184,7 +184,7 @@ func StartUsage(object clonk)
hand = "AimArmsGeneric.L";
}
aiming = 1;
is_aiming = true;
aim_anim = clonk->PlayAnimation(hand, CLONK_ANIM_SLOT_Arms, Anim_Const(clonk->GetAnimationLength(hand)/2), Anim_Const(1000));
clonk->UpdateAttach();
@ -260,9 +260,10 @@ protected func CancelUse(object clonk)
{
EndUsage(clonk);
Sound("Objects::Electrical",nil,nil,nil,-1);
if(aiming = 1) PlayAnimation("Closing", -5, Anim_Linear(0,0,GetAnimationLength("Closing"), 10, ANIM_Hold));
if (is_aiming)
PlayAnimation("Closing", -5, Anim_Linear(0,0,GetAnimationLength("Closing"), 10, ANIM_Hold));
StopAnimation(anim_spin);
aiming = 0;
is_aiming = false;
if(target_object) LostTargetObject(target_object);
target_object = nil;
return true;

View File

@ -107,8 +107,8 @@ public func ControlUseStart(object clonk, int x, int y)
if (!Contents(0))
{
// Put some bullets into the blunderbuss.
var obj;
if (obj = FindObject(Find_Container(clonk), Find_Func("IsBullet")))
var obj = FindObject(Find_Container(clonk), Find_Func("IsBullet"));
if (obj)
obj->Enter(this);
}

View File

@ -121,8 +121,8 @@ public func ControlUseStart(object clonk, int x, int y)
if(!Contents(0))
{
// reload
var obj;
if(obj = FindObject(Find_Container(clonk), Find_Func("IsArrow")))
var obj = FindObject(Find_Container(clonk), Find_Func("IsArrow"));
if (obj)
{
obj->Enter(this);
}

View File

@ -106,8 +106,8 @@ public func ControlUseStart(object clonk, int x, int y)
if(!Contents(0))
{
// put something inside
var obj;
if(obj = FindObject(Find_Container(clonk), Find_Func("IsGrenadeLauncherAmmo")))
var obj = FindObject(Find_Container(clonk), Find_Func("IsGrenadeLauncherAmmo"));
if (obj)
{
obj->Enter(this);
}

View File

@ -117,11 +117,11 @@ public func GetExtraInteractions()
var functions = _inherited(...) ?? [];
// flipping construction-preview
var effect;
if(effect = GetEffect("ControlConstructionPreview", this))
var fx = GetEffect("ControlConstructionPreview", this);
if (fx)
{
if(effect.flipable)
PushBack(functions, {Fn = "Flip", Description=ConstructionPreviewer->GetFlipDescription(), Object=effect.preview, IconID=ConstructionPreviewer_IconFlip, Priority=0});
if (fx.flipable)
PushBack(functions, {Fn = "Flip", Description=ConstructionPreviewer->GetFlipDescription(), Object=fx.preview, IconID=ConstructionPreviewer_IconFlip, Priority=0});
}
// call elevator cases
var elevators = FindObjects(Find_ID(ElevatorCase), Find_InRect(-ELEVATOR_CALL_DISTANCE, AbsY(0), ELEVATOR_CALL_DISTANCE * 2, GetY() + AbsY(LandscapeHeight())), Find_Func("Ready", this));

View File

@ -378,8 +378,8 @@ func GetInteractableObjects(array sort)
// Make sure that the Clonk's action target is always shown.
// You can push a lorry out of your bounding box and would, otherwise, then be unable to release it.
var main_criterion = Find_AtRect(-5, -10, 10, 20);
var action_target = nil;
if (action_target = GetActionTarget())
var action_target = GetActionTarget();
if (action_target)
{
main_criterion = Find_Or(main_criterion, Find_InArray([action_target]));
}

View File

@ -150,8 +150,8 @@ public func SetHandItemPos(int hand, int inv)
old_object->~Deselection(this, hand);
// notify new hand2 item (which should be old hand-item) that it has been selected
var hand_item;
if (hand_item = GetHandItem(hand2))
var hand_item = GetHandItem(hand2);
if (hand_item)
{
this->~OnSlotFull(hand2);
// OnSlotFull might have done something to the item
@ -171,8 +171,8 @@ public func SetHandItemPos(int hand, int inv)
}
// notify the new item that it was selected
var item;
if(item = GetItem(inv))
var item = GetItem(inv);
if (item)
{
this->~OnSlotFull(hand);
// OnSlotFull might have done something to the item

View File

@ -156,9 +156,11 @@ private func BaseIntersection_IsPointContained(int x, int y)
private func BaseIntersection_GetBoundingRectangle()
{
// Bounding rectangle of intersection
var result, rt;
var result;
for (var area in this.areas)
if (rt = area->GetBoundingRectangle())
{
var rt = area->GetBoundingRectangle();
if (rt)
{
// first bounds determine area
if (!result)
@ -182,6 +184,7 @@ private func BaseIntersection_GetBoundingRectangle()
}
}
}
}
return result;
}
@ -242,9 +245,11 @@ private func BaseCombination_IsPointContained(int x, int y)
private func BaseCombination_GetBoundingRectangle()
{
// Bounding rectangle of combination
var result, rt;
var result;
for (var area in this.areas)
if (rt = area->GetBoundingRectangle())
{
var rt = area->GetBoundingRectangle();
if (rt)
{
// first bounds determine area
if (!result)
@ -268,6 +273,7 @@ private func BaseCombination_GetBoundingRectangle()
}
}
}
}
return result;
}

View File

@ -274,11 +274,9 @@ public func OnBuyMenuSelection(id def, extra_data, object clonk)
private func EjectAllContents()
{
var i = ContentsCount();
var obj;
while (i--)
if (obj = Contents(i))
EjectContents(obj);
while (obj = Contents())
EjectContents(obj);
}
private func EjectContents(object contents)

View File

@ -261,10 +261,11 @@ private func TransferInventory(object from, object to)
{
if (!from || !to) return;
// 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))
var contents = from->Contents(i);
if (contents)
{
if (contents->~IsDroppedOnDeath(from))
{

View File

@ -80,8 +80,9 @@ func IsNeutral() { return neutral; }
func SetNeutral(bool to_val)
{
neutral = to_val;
// Neutral flagpoles: A bit smaller and different texture. No marker Radius.
if (neutral = to_val)
if (neutral)
{
SetMeshMaterial("NeutralFlagBanner",0);
//SetMeshMaterial("NeutralFlagPole",1);

View File

@ -62,8 +62,8 @@ public func Collection(object obj, bool put)
public func ContentsCheck()
{
// Ejects non fuel items immediately
var fuel;
if (fuel = FindObject(Find_Container(this), Find_Not(Find_Func("IsFuel"))))
var fuel = FindObject(Find_Container(this), Find_Not(Find_Func("IsFuel")));
if (fuel)
{
fuel->Exit(-45, 21, -20, -1, -1, -30);
Sound("Chuff");

View File

@ -243,10 +243,10 @@ public func SaveScenarioObject(proplist props)
if (Contained())
if (Contained()->GetID() == Cotton)
return false;
var effect;
if (effect = GetEffect("IntFlight", this))
var fx = GetEffect("IntFlight", this);
if (fx)
{
props->AddCall("Flight", this, "ResumeFlight", effect.time, effect.random);
props->AddCall("Flight", this, "ResumeFlight", fx.time, fx.random);
}
return true;
}

View File

@ -295,7 +295,7 @@ func IsFullyGrown()
func Remove()
{
var t = GetActionTarget();
if(t)
if (t)
{
// not natural cause?
if(this.isDead)
@ -307,8 +307,8 @@ func Remove()
t->LoseSprout(this);
}
if(t = Contents())
t->RemoveObject();
if (Contents()) // TODO: Is this needed at all? Contents are removed on destruction.
t = Contents()->RemoveObject();
return RemoveObject();
}

View File

@ -53,8 +53,9 @@ public func Sprout()
// No duplicate sprout
if (GetEffect("IntGerminate", this)) return false;
// Try to sprout a coconut tree.
var d = 8, tree;
if (tree = PlaceVegetation(Tree_Coconut, -d/2, -d/2, d, d, 100))
var d = 8;
var tree = PlaceVegetation(Tree_Coconut, -d/2, -d/2, d, d, 100);
if (tree)
{
tree->InitChild(this);
this.Collectible = 0;

View File

@ -367,8 +367,8 @@ global func FxFireTimer(object target, proplist effect, int time)
if (time % (20 + effect.FreqReduction) == 0)
{
// Extinguish when in water-like materials.
var mat;
if (mat = GetMaterial())
var mat = GetMaterial();
if (mat)
{
if (GetMaterialVal("Extinguisher", "Material", mat))
{

View File

@ -300,27 +300,27 @@ global func SaveScen_SetContainers(array obj_data)
}
}
// Concatenate multiple contents creations
var cont;
for (var obj in obj_data) if ((cont = obj.o->Contained())) if (obj.props->HasProp(SAVEOBJ_ContentsCreationEx))
{
var num_contents_concat = 1;
if ((!obj.o.StaticSaveVar || save_scenario_dup_objects) && !obj.write_label)
for (var obj in obj_data)
if (obj.o->Contained() && obj.props->HasProp(SAVEOBJ_ContentsCreationEx))
{
for (var obj2 in obj_data) if (obj2 != obj && obj2.o->Contained() == cont && obj.o->GetID() == obj2.o->GetID() && obj2.props->HasProp(SAVEOBJ_ContentsCreationEx))
var num_contents_concat = 1;
if ((!obj.o.StaticSaveVar || save_scenario_dup_objects) && !obj.write_label)
{
++num_contents_concat;
obj2.props->Clear();
for (var obj2 in obj_data) if (obj2 != obj && obj2.o->Contained() == obj.o->Contained() && obj.o->GetID() == obj2.o->GetID() && obj2.props->HasProp(SAVEOBJ_ContentsCreationEx))
{
++num_contents_concat;
obj2.props->Clear();
}
}
if (num_contents_concat > 1)
{
obj.props->Remove(SAVEOBJ_ContentsCreation);
var creation_prop = obj.props->HasProp(SAVEOBJ_ContentsCreationEx);
creation_prop.s = Format(creation_prop.s, num_contents_concat);
}
else
obj.props->Remove(SAVEOBJ_ContentsCreationEx);
}
if (num_contents_concat > 1)
{
obj.props->Remove(SAVEOBJ_ContentsCreation);
var creation_prop = obj.props->HasProp(SAVEOBJ_ContentsCreationEx);
creation_prop.s = Format(creation_prop.s, num_contents_concat);
}
else
obj.props->Remove(SAVEOBJ_ContentsCreationEx);
}
return obj_data;
}

View File

@ -91,8 +91,8 @@ global func HalfVehicleFadeJumpStop()
{
if (!this)
return FatalError("this function requires object context");
var fx;
if (fx = GetEffect("IntHalfVehicleFadeJump", this))
var fx = GetEffect("IntHalfVehicleFadeJump", this);
if (fx)
fx.Interval = 1;
}