From 1bb728b04728746d0ea99181bf0e2bc639bfe5bc Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Mon, 23 Jul 2018 12:08:09 +0200 Subject: [PATCH] Fix variable_out_of_scope warnings in Objects --- .../Animals.ocd/Butterfly.ocd/Script.c | 14 ++++++------- .../Objects.ocd/Animals.ocd/Mooq.ocd/Script.c | 20 ++++++++++--------- .../Environment.ocd/Cloud.ocd/Script.c | 12 +++++------ .../Defense.ocd/DefenseEnemy.ocd/Script.c | 1 + .../Goals.ocd/Parkour.ocd/Script.c | 7 ++++--- .../HUD.ocd/Scoreboard.ocd/Script.c | 14 +++++++------ .../Helpers.ocd/ObjectRestorer.ocd/Script.c | 9 +++++---- .../ConstructionPreviewer.ocd/Script.c | 8 ++++---- .../Vegetation.ocd/Cotton.ocd/Script.c | 7 ++++--- .../LargeCaveMushroom.ocd/Script.c | 4 ++-- 10 files changed, 51 insertions(+), 45 deletions(-) diff --git a/planet/Objects.ocd/Animals.ocd/Butterfly.ocd/Script.c b/planet/Objects.ocd/Animals.ocd/Butterfly.ocd/Script.c index e838f4f23..1a6d0dca6 100644 --- a/planet/Objects.ocd/Animals.ocd/Butterfly.ocd/Script.c +++ b/planet/Objects.ocd/Animals.ocd/Butterfly.ocd/Script.c @@ -93,14 +93,12 @@ private func GetRestingPlace(proplist coordinates) // Try to rest in nearby grass for (var grass in FindObjects(Find_Distance(150), Find_ID(Grass), Sort_Distance())) { - if (!Random(2)) continue; - break; - } - if (grass) - { - coordinates.x = grass->GetX() + Random(4) - 2; - coordinates.y = grass->GetY() + 2; - return true; + if (!Random(2)) + { + coordinates.x = grass->GetX() + Random(4) - 2; + coordinates.y = grass->GetY() + 2; + return true; + } } return false; } diff --git a/planet/Objects.ocd/Animals.ocd/Mooq.ocd/Script.c b/planet/Objects.ocd/Animals.ocd/Mooq.ocd/Script.c index 836adb58a..85545af78 100644 --- a/planet/Objects.ocd/Animals.ocd/Mooq.ocd/Script.c +++ b/planet/Objects.ocd/Animals.ocd/Mooq.ocd/Script.c @@ -327,16 +327,17 @@ func TaskWalkTo(spot) { var iX = GetX(); var iY = GetY(); + var sX, sY; if (GetType(spot) == C4V_C4Object) { - var sX = spot->GetX(); - var sY = spot->GetY(); + sX = spot->GetX(); + sY = spot->GetY(); } else if (GetType(spot) == C4V_PropList) { - var sX = spot.x; - var sY = spot.y; + sX = spot.x; + sY = spot.y; } else return; @@ -361,16 +362,17 @@ func TaskSwimTo(spot) { var iX = GetX(); var iY = GetY(); + var sX, sY; if (GetType(spot) == C4V_C4Object) { - var sX = spot->GetX(); - var sY = spot->GetY(); + sX = spot->GetX(); + sY = spot->GetY(); } else if (GetType(spot) == C4V_PropList) { - var sX = spot.x; - var sY = spot.y; + sX = spot.x; + sY = spot.y; } else return; @@ -934,4 +936,4 @@ local ContactCalls = true; public func Definition(proplist def) { def.PictureTransformation = Trans_Mul(Trans_Translate(2000, 3000, 0), Trans_Scale(1400), Trans_Rotate(20, 1, 0, 0), Trans_Rotate(60, 0, 1, 0)); -} \ No newline at end of file +} diff --git a/planet/Objects.ocd/Environment.ocd/Cloud.ocd/Script.c b/planet/Objects.ocd/Environment.ocd/Cloud.ocd/Script.c index 12715226e..bba23714d 100644 --- a/planet/Objects.ocd/Environment.ocd/Cloud.ocd/Script.c +++ b/planet/Objects.ocd/Environment.ocd/Cloud.ocd/Script.c @@ -104,17 +104,17 @@ public func Place(int count) { if (this != Cloud) return; - var max_tries = count * 500; - for (var i = 0; i < count && max_tries > 0; max_tries--) + var created = 0; + for (var max_tries = count * 500; created < count && max_tries > 0; max_tries--) { - var pos; - if ((pos = FindPosInMat("Sky", 0, 0, LandscapeWidth(), LandscapeHeight())) && MaterialDepthCheck(pos[0], pos[1], "Sky", 200)) + var pos = FindPosInMat("Sky", 0, 0, LandscapeWidth(), LandscapeHeight()); + if (pos && MaterialDepthCheck(pos[0], pos[1], "Sky", 200)) { CreateObjectAbove(Cloud, pos[0], pos[1], NO_OWNER); - i++; + created++; } } - return i; + return created; } // Changes the precipitation type of this cloud. diff --git a/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseEnemy.ocd/Script.c b/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseEnemy.ocd/Script.c index 31f3669ce..8341fbe77 100644 --- a/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseEnemy.ocd/Script.c +++ b/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseEnemy.ocd/Script.c @@ -159,6 +159,7 @@ private func LaunchEnemyAt(proplist prop_enemy, int wave_nr, int enemy_plr, prop for (var inv in ForceToInventoryArray(prop_enemy.Inventory)) { // Special way to pick up carry heavy objects instantly. + var inv_obj; if (inv->~IsCarryHeavy() && (enemy->GetOCF() & OCF_CrewMember)) inv_obj = enemy->CreateCarryHeavyContents(inv); else diff --git a/planet/Objects.ocd/Goals.ocd/Parkour.ocd/Script.c b/planet/Objects.ocd/Goals.ocd/Parkour.ocd/Script.c index 37ad392e7..2fa61f99a 100644 --- a/planet/Objects.ocd/Goals.ocd/Parkour.ocd/Script.c +++ b/planet/Objects.ocd/Goals.ocd/Parkour.ocd/Script.c @@ -517,10 +517,11 @@ static const SBRD_BestTime = 1; private func UpdateScoreboardTitle() { + var caption; if (cp_count > 0) - var caption = Format("$MsgCaptionX$", cp_count); + caption = Format("$MsgCaptionX$", cp_count); else - var caption = "$MsgCaptionNone$"; + caption = "$MsgCaptionNone$"; return Scoreboard->SetTitle(caption); } @@ -581,7 +582,7 @@ protected func FxIntDirNextCPTimer(object target, effect fx) var green = BoundBy(510 - dist, 0, 255); var blue = 0; // Arrow is colored a little different for the finish. - if (cp->GetCPMode() & PARKOUR_CP_Finish) + if (nextcp->GetCPMode() & PARKOUR_CP_Finish) blue = 128; var color = RGBa(red, green, blue, 128); // Draw arrow. diff --git a/planet/Objects.ocd/HUD.ocd/Scoreboard.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Scoreboard.ocd/Script.c index 985561c9b..bb1055f28 100644 --- a/planet/Objects.ocd/HUD.ocd/Scoreboard.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Scoreboard.ocd/Script.c @@ -98,15 +98,17 @@ public func SetData( var index = -1; for(var i = 0; i < GetLength(Scoreboard_data); ++i) { - if(Scoreboard_data[i].ID != ID) continue; - index = i; - break; + if(Scoreboard_data[i].ID == ID) + { + index = i; + break; + } } if(index == -1) return; - Scoreboard_data[i][key] = to; + Scoreboard_data[index][key] = to; if(sort_parameter) - Scoreboard_data[i][Format("%s_", key)] = sort_parameter; + Scoreboard_data[index][Format("%s_", key)] = sort_parameter; Scoreboard->Update(ID); } @@ -322,4 +324,4 @@ public func SetTitle(string title) { SetScoreboardData(SBRD_Caption, SBRD_Caption, title); Scoreboard_title_set = true; -} \ No newline at end of file +} diff --git a/planet/Objects.ocd/Helpers.ocd/ObjectRestorer.ocd/Script.c b/planet/Objects.ocd/Helpers.ocd/ObjectRestorer.ocd/Script.c index f3d00e3e3..d005366d7 100644 --- a/planet/Objects.ocd/Helpers.ocd/ObjectRestorer.ocd/Script.c +++ b/planet/Objects.ocd/Helpers.ocd/ObjectRestorer.ocd/Script.c @@ -56,15 +56,16 @@ protected func FxRestoreTimer(object target, effect, int time) var init_x = effect.init_x; var init_y = effect.init_y; var to_container = effect.to_container; + var to_x, to_y; if (to_container) { - var to_x = to_container->GetX(); - var to_y = to_container->GetY(); + to_x = to_container->GetX(); + to_y = to_container->GetY(); } else { - var to_x = effect.to_x; - var to_y = effect.to_y; + to_x = effect.to_x; + to_y = effect.to_y; } // Are the coordinates specified now, if not remove effect. if (to_x == nil || to_y == nil) diff --git a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c index 756e19460..4a4aa1bc2 100644 --- a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c @@ -117,6 +117,9 @@ func Reposition(int x, int y) y = BoundBy(y, -dimension_y - clonk_height/2, dimension_y + clonk_height/2); // Try to combine the structure with other structures. var found = false; + // Hopefully, in the end this contains a single sticking direction. + var single_stick_to = 0; + if (structure->~ConstructionCombineWith()) { // There is no use in doing all the other checks if no sticking direction is defined at all @@ -153,9 +156,6 @@ func Reposition(int x, int y) // // Whichever part is howered on is checked first for stick direction - // Hopefully, in the end this contains a single sticking direction. - var single_stick_to = 0; - // Left if (other_offset_x < other_width / -6) { @@ -314,4 +314,4 @@ func Flip() // UI not saved. func SaveScenarioObject() { return false; } -local Plane = 210; \ No newline at end of file +local Plane = 210; diff --git a/planet/Objects.ocd/Vegetation.ocd/Cotton.ocd/Script.c b/planet/Objects.ocd/Vegetation.ocd/Cotton.ocd/Script.c index de95d2d70..e15937bdc 100644 --- a/planet/Objects.ocd/Vegetation.ocd/Cotton.ocd/Script.c +++ b/planet/Objects.ocd/Vegetation.ocd/Cotton.ocd/Script.c @@ -93,10 +93,11 @@ private func Perish() // If fullgrown is true, the branch will be fully grown but not bear a fruit! public func GrowBranch(bool fullgrown, int branch) { + var next_to_grow; if (branch != nil) - var next_to_grow = branch; + next_to_grow = branch; else - var next_to_grow = GetNextGrowableBranch(fullgrown); + next_to_grow = GetNextGrowableBranch(fullgrown); if (next_to_grow == -1) return false; if (branches[next_to_grow].grow_animation != branch_proto.grow_animation) // Already growing, fullgrown must be true @@ -352,4 +353,4 @@ local Description = "$Description$"; local Collectible = 0; local growth = 3; local degrowth = -6; -local fastgrowth = 9; \ No newline at end of file +local fastgrowth = 9; diff --git a/planet/Objects.ocd/Vegetation.ocd/LargeCaveMushroom.ocd/Script.c b/planet/Objects.ocd/Vegetation.ocd/LargeCaveMushroom.ocd/Script.c index 45f27f0a5..3b2bc120c 100644 --- a/planet/Objects.ocd/Vegetation.ocd/LargeCaveMushroom.ocd/Script.c +++ b/planet/Objects.ocd/Vegetation.ocd/LargeCaveMushroom.ocd/Script.c @@ -197,8 +197,8 @@ private func Seed() if (this.Confinement) plant->KeepArea(this.Confinement); } + return plant; } - return plant; } local Name = "$Name$"; @@ -206,4 +206,4 @@ local Touchable = 0; local BlastIncinerate = 2; local ContactIncinerate = 6; local NoBurnDecay = true; -local Components = {Wood = 4}; \ No newline at end of file +local Components = {Wood = 4};