Fix variable_out_of_scope warnings in Objects

master
Nicolas Hake 2018-07-23 12:08:09 +02:00
parent 4c43ebf58c
commit 1bb728b047
10 changed files with 51 additions and 45 deletions

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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;
local Plane = 210;

View File

@ -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;
local fastgrowth = 9;

View File

@ -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};
local Components = {Wood = 4};