forked from Mirrors/openclonk
Fix suspicious_assignment warnings in Objects, System
parent
81dff1b92a
commit
e024bef54b
|
@ -278,7 +278,9 @@ private func Env_AddAction(achance, afn, par0, par1, par2, par3, par4)
|
|||
{
|
||||
// Make sure to not write into prototype proplist.
|
||||
if (this.actions == this.Prototype.actions) this.actions = [];
|
||||
return this.actions[GetLength(this.actions)] = { chance=achance, fn=afn, par=[par0, par1, par2, par3, par4] };
|
||||
var action = { chance=achance, fn=afn, par=[par0, par1, par2, par3, par4] };
|
||||
this.actions[GetLength(this.actions)] = action;
|
||||
return action;
|
||||
}
|
||||
|
||||
/* Default environment checks */
|
||||
|
|
|
@ -251,11 +251,14 @@ protected func Hit(int dx, int dy)
|
|||
|
||||
private func SplitRock()
|
||||
{
|
||||
var con = GetCon(), erock;
|
||||
var con = GetCon();
|
||||
// Explosive rocks do some damage
|
||||
if (is_explosive)
|
||||
if (erock = CreateObjectAbove(Rock, 0, 4, GetController()))
|
||||
if (is_explosive)
|
||||
{
|
||||
var erock = CreateObjectAbove(Rock, 0, 4, GetController());
|
||||
if (erock)
|
||||
erock->Explode(Max(15 * con / 100, 3));
|
||||
}
|
||||
// Split the rock into smaller ones if it is big enough.
|
||||
if (con > 40)
|
||||
{
|
||||
|
|
|
@ -295,29 +295,40 @@ private func ApplyCrewSettings(object crew)
|
|||
private func InitializeCrew(int plr)
|
||||
{
|
||||
// Collect IDs of crew to create
|
||||
var requested_crew = [], n=0, i, obj, idx, def;
|
||||
var requested_crew = [], n=0;
|
||||
for (var idlist_entry in starting_crew)
|
||||
for (i=0; i<idlist_entry.count; ++i)
|
||||
for (var i = 0; i < idlist_entry.count; ++i)
|
||||
requested_crew[n++] = idlist_entry.id;
|
||||
// Match them to existing crew
|
||||
for (i = GetCrewCount(plr)-1; i>=0; --i)
|
||||
if (obj = GetCrew(plr, i))
|
||||
if ((idx = GetIndexOf(requested_crew, obj->GetID())) >= 0)
|
||||
for (var i = GetCrewCount(plr)-1; i>=0; --i)
|
||||
{
|
||||
var obj = GetCrew(plr, i);
|
||||
if (obj) {
|
||||
var idx = GetIndexOf(requested_crew, obj->GetID());
|
||||
if (idx >= 0)
|
||||
{
|
||||
obj->SetPosition(GetX(), GetY() + GetDefHeight()/2 - obj->GetDefHeight()/2);
|
||||
requested_crew[idx] = nil;
|
||||
}
|
||||
else
|
||||
obj->RemoveObject(); // not in list: Kill
|
||||
}
|
||||
}
|
||||
// Create any missing crew
|
||||
for (def in requested_crew)
|
||||
for (var def in requested_crew)
|
||||
if (def)
|
||||
if (obj = CreateObjectAbove(def, 0, GetDefHeight()/2, plr))
|
||||
{
|
||||
var obj = CreateObjectAbove(def, 0, GetDefHeight()/2, plr);
|
||||
if (obj)
|
||||
obj->MakeCrewMember(plr);
|
||||
}
|
||||
// Apply crew settings
|
||||
for (i = GetCrewCount(plr)-1; i>=0; --i)
|
||||
if (obj = GetCrew(plr, i))
|
||||
for (var i = GetCrewCount(plr)-1; i>=0; --i)
|
||||
{
|
||||
var obj = GetCrew(plr, i);
|
||||
if (obj)
|
||||
ApplyCrewSettings(obj);
|
||||
}
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
|
@ -346,11 +357,13 @@ private func InitializeMaterial(int plr)
|
|||
for (var idlist_entry in starting_material)
|
||||
{
|
||||
var best_target = nil, target_score, clonk;
|
||||
var obj = EditorBase->CreateItemPlusParameter(idlist_entry, GetX(),GetY()+GetDefHeight()/2, plr);
|
||||
var obj = EditorBase->CreateItemPlusParameter(idlist_entry, GetX(), GetY() + GetDefHeight() / 2, plr);
|
||||
if (!obj || !obj.Collectible) continue;
|
||||
var id = idlist_entry.id;
|
||||
for (var j=0; j<GetCrewCount(plr); ++j)
|
||||
if (clonk = GetCrew(plr, j))
|
||||
for (var j=0; j < GetCrewCount(plr); ++j)
|
||||
{
|
||||
var clonk = GetCrew(plr, j);
|
||||
if (clonk)
|
||||
{
|
||||
var clonk_score = 0;
|
||||
// High penalty: Already has item of same type
|
||||
|
@ -363,6 +376,7 @@ private func InitializeMaterial(int plr)
|
|||
target_score = clonk_score;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (best_target) best_target->Collect(obj); // May fail due to contents full
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -72,8 +72,10 @@ public func FindInventoryWeapon(effect fx)
|
|||
return true;
|
||||
}
|
||||
// Make a bomber out of those who carry the powderkeg.
|
||||
if (fx.weapon = fx.Target->FindContents(PowderKeg))
|
||||
var keg = fx.Target->FindContents(PowderKeg);
|
||||
if (keg)
|
||||
{
|
||||
fx.weapon = keg;
|
||||
fx.is_siege = true;
|
||||
fx.strategy = this.ExecuteBomber;
|
||||
return true;
|
||||
|
|
|
@ -519,9 +519,8 @@ public func SaveScenarioObject(props)
|
|||
// Checkpoints without a goal? Use regular saving.
|
||||
if (!cp_con)
|
||||
{
|
||||
|
||||
if (v = GetCPMode()) props->AddCall("Checkpoint", this, "SetCPMode", GetBitmaskNameByValue(v, "PARKOUR_CP_"));
|
||||
if (v = GetCPNumber()) props->AddCall("Checkpoint", this, "SetCPNumber", v);
|
||||
if (GetCPMode()) props->AddCall("Checkpoint", this, "SetCPMode", GetBitmaskNameByValue(GetCPMode(), "PARKOUR_CP_"));
|
||||
if (GetCPNumber()) props->AddCall("Checkpoint", this, "SetCPNumber", GetCPNumber());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -218,7 +218,8 @@ func Departure_WeaponRespawn(object container, ...)
|
|||
// (This function should be save to be called in foreign context)
|
||||
ScheduleCall(this, Rule_ObjectFade.FadeOutObject, 120, 1, this);
|
||||
// Revert to previous departure call. No double-respawn in case it gets collected
|
||||
if ((this.Departure = this.WeaponRespawn_Departure))
|
||||
this.Departure = this.WeaponRespawn_Departure;
|
||||
if (this.Departure)
|
||||
{
|
||||
return Call(this.Departure, container, ...);
|
||||
}
|
||||
|
@ -252,24 +253,24 @@ public func FindInventoryWeapon(effect fx)
|
|||
if (FindInventoryWeaponBow(fx)) return true;
|
||||
if (FindInventoryWeaponJavelin(fx)) return true;
|
||||
// Throwing weapons.
|
||||
if ((fx.weapon = fx.Target->FindContents(Firestone)) || (fx.weapon = fx.Target->FindContents(Rock)) || (fx.weapon = fx.Target->FindContents(Lantern)))
|
||||
if (FindInventoryWeaponBase(fx, Firestone) || FindInventoryWeaponBase(fx, Rock) || FindInventoryWeaponBase(fx, Lantern))
|
||||
{
|
||||
fx.can_attack_structures = fx.weapon->~HasExplosionOnImpact();
|
||||
fx.strategy = this.ExecuteThrow;
|
||||
return true;
|
||||
}
|
||||
// Melee weapons.
|
||||
if ((fx.weapon = fx.Target->FindContents(Sword)) || (fx.weapon = fx.Target->FindContents(Axe))) // Sword attacks aren't 100% correct for Axe, but work well enough
|
||||
if (FindInventoryWeaponBase(fx, Sword) || FindInventoryWeaponBase(fx, Axe)) // Sword attacks aren't 100% correct for Axe, but work well enough
|
||||
{
|
||||
fx.strategy = this.ExecuteMelee;
|
||||
return true;
|
||||
}
|
||||
if ((fx.weapon = fx.Target->FindContents(PowderKeg)))
|
||||
if (FindInventoryWeaponBase(fx, PowderKeg))
|
||||
{
|
||||
fx.strategy = this.ExecuteBomber;
|
||||
return true;
|
||||
}
|
||||
if ((fx.weapon = fx.Target->FindContents(Club)))
|
||||
if (FindInventoryWeaponBase(fx, Club))
|
||||
{
|
||||
fx.strategy = this.ExecuteClub;
|
||||
return true;
|
||||
|
@ -278,73 +279,80 @@ public func FindInventoryWeapon(effect fx)
|
|||
return false;
|
||||
}
|
||||
|
||||
private func FindInventoryWeaponBase(effect fx, id type)
|
||||
{
|
||||
var weapon = fx.Target->FindContents(type);
|
||||
if (weapon)
|
||||
{
|
||||
fx.weapon = weapon;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private func FindInventoryWeaponGrenadeLauncher(effect fx)
|
||||
{
|
||||
if (fx.weapon = fx.Target->FindContents(GrenadeLauncher))
|
||||
var weapon = fx.Target->FindContents(GrenadeLauncher);
|
||||
if (weapon && this->HasBombs(fx, weapon))
|
||||
{
|
||||
if (this->HasBombs(fx, fx.weapon))
|
||||
{
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 75;
|
||||
fx.ammo_check = this.HasBombs;
|
||||
fx.ranged = true;
|
||||
fx.can_attack_structures = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
fx.weapon = nil;
|
||||
fx.weapon = weapon;
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 75;
|
||||
fx.ammo_check = this.HasBombs;
|
||||
fx.ranged = true;
|
||||
fx.can_attack_structures = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private func FindInventoryWeaponBlunderbuss(effect fx)
|
||||
{
|
||||
if (fx.weapon = fx.Target->FindContents(Blunderbuss))
|
||||
var weapon = fx.Target->FindContents(Blunderbuss);
|
||||
if (weapon && this->HasAmmo(fx, weapon))
|
||||
{
|
||||
if (this->HasAmmo(fx, fx.weapon))
|
||||
{
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 200;
|
||||
fx.ammo_check = this.HasAmmo;
|
||||
fx.ranged = true;
|
||||
fx.ranged_direct = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
fx.weapon = nil;
|
||||
fx.weapon = weapon;
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 200;
|
||||
fx.ammo_check = this.HasAmmo;
|
||||
fx.ranged = true;
|
||||
fx.ranged_direct = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private func FindInventoryWeaponBow(effect fx)
|
||||
{
|
||||
if (fx.weapon = fx.Target->FindContents(Bow))
|
||||
var weapon = fx.Target->FindContents(Bow);
|
||||
if (weapon && this->HasArrows(fx, weapon))
|
||||
{
|
||||
if (this->HasArrows(fx, fx.weapon))
|
||||
{
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 100;
|
||||
fx.ammo_check = this.HasArrows;
|
||||
fx.ranged = true;
|
||||
var arrow = fx.weapon->Contents(0) ?? FindObject(Find_Container(fx.Target), Find_Func("IsArrow"));
|
||||
fx.can_attack_structures = arrow && arrow->~IsExplosive();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
fx.weapon = nil;
|
||||
fx.weapon = weapon;
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = 100;
|
||||
fx.ammo_check = this.HasArrows;
|
||||
fx.ranged = true;
|
||||
var arrow = weapon->Contents(0) ?? FindObject(Find_Container(fx.Target), Find_Func("IsArrow"));
|
||||
fx.can_attack_structures = arrow && arrow->~IsExplosive();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private func FindInventoryWeaponJavelin(effect fx)
|
||||
{
|
||||
if (fx.weapon = fx.Target->FindContents(Javelin))
|
||||
var weapon = fx.Target->FindContents(Javelin);
|
||||
if (weapon)
|
||||
{
|
||||
fx.weapon = weapon;
|
||||
fx.strategy = this.ExecuteRanged;
|
||||
fx.projectile_speed = fx.Target.ThrowSpeed * fx.weapon.shooting_strength / 100;
|
||||
fx.ranged=true;
|
||||
fx.projectile_speed = fx.Target.ThrowSpeed * weapon.shooting_strength / 100;
|
||||
fx.ranged = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ public func ExecuteArm(effect fx)
|
|||
// Find shield.
|
||||
fx.shield = fx.Target->FindContents(Shield);
|
||||
// Vehicle control overrides all other weapons
|
||||
if (fx.weapon = fx.vehicle)
|
||||
if ((fx.weapon = fx.vehicle) != nil)
|
||||
{
|
||||
if (this->CheckVehicleAmmo(fx, fx.weapon))
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ func Definition(def)
|
|||
// Item plus extra stuff (contents, stack, etc.)
|
||||
ItemPlusParameterOptionMap = {};
|
||||
ItemPlusParameter = { Name="$Item", Type="enum", Sorted=true, Options = [ { Name="$Nothing$", Priority=50 } ] };
|
||||
var itemdef, i = 0, n = 0, option, contents_def, j, n2, contents_defs, mat;
|
||||
var itemdef, i = 0, n = 0, option, contents_def, j, n2, contents_defs;
|
||||
while ((itemdef = GetDefinition(i++)))
|
||||
if (itemdef.Collectible || itemdef->~GetLiquidType())
|
||||
{
|
||||
|
@ -67,9 +67,12 @@ func Definition(def)
|
|||
j = 0; n2 = 0;
|
||||
contents_defs = [{Name="$Nothing$"}];
|
||||
while ((contents_def = GetDefinition(j++)))
|
||||
if ((mat = contents_def->~GetLiquidType()))
|
||||
{
|
||||
var mat = contents_def->~GetLiquidType();
|
||||
if (mat)
|
||||
if (itemdef->IsLiquidContainerForMaterial(mat))
|
||||
contents_defs[++n2] = contents_def;
|
||||
}
|
||||
if (n2)
|
||||
{
|
||||
option.Value = { ItemPlusParameter="liquid", ID=itemdef };
|
||||
|
|
|
@ -138,7 +138,8 @@ public func ReactivatePlayerControls(int plr)
|
|||
// Ensure proper cursor.
|
||||
if (!GetCursor(plr))
|
||||
SetCursor(plr, GetCrew(plr));
|
||||
if (crew = GetCursor(plr))
|
||||
crew = GetCursor(plr);
|
||||
if (crew)
|
||||
SetPlrView(plr, crew);
|
||||
return true;
|
||||
}
|
||||
|
@ -277,13 +278,15 @@ public func LoadScenarioSection(name, ...)
|
|||
// Store objects: All clonks and sequence object
|
||||
this.save_objs = [];
|
||||
AddSectSaveObj(this);
|
||||
var iplr, plr;
|
||||
for (iplr = 0; iplr < GetPlayerCount(C4PT_User); ++iplr)
|
||||
for (var iplr = 0; iplr < GetPlayerCount(C4PT_User); ++iplr)
|
||||
{
|
||||
plr = GetPlayerByIndex(iplr, C4PT_User);
|
||||
for (var icrew = 0, crew; icrew < GetCrewCount(iplr); ++icrew)
|
||||
if (crew = GetCrew(plr, icrew))
|
||||
var plr = GetPlayerByIndex(iplr, C4PT_User);
|
||||
for (var icrew = 0; icrew < GetCrewCount(iplr); ++icrew)
|
||||
{
|
||||
var crew = GetCrew(plr, icrew);
|
||||
if (crew)
|
||||
AddSectSaveObj(crew);
|
||||
}
|
||||
}
|
||||
var save_objs = this.save_objs;
|
||||
// Load new section
|
||||
|
@ -295,9 +298,9 @@ public func LoadScenarioSection(name, ...)
|
|||
if (this)
|
||||
this.save_objs = nil;
|
||||
// Recover HUD
|
||||
for (iplr = 0; iplr < GetPlayerCount(C4PT_User); ++iplr)
|
||||
for (var iplr = 0; iplr < GetPlayerCount(C4PT_User); ++iplr)
|
||||
{
|
||||
plr = GetPlayerByIndex(iplr, C4PT_User);
|
||||
var plr = GetPlayerByIndex(iplr, C4PT_User);
|
||||
var controllerDef = Library_HUDController->GetGUIControllerID();
|
||||
var HUDcontroller = FindObject(Find_ID(controllerDef), Find_Owner(plr));
|
||||
if (!HUDcontroller) HUDcontroller = CreateObjectAbove(controllerDef, 10, 10, plr);
|
||||
|
|
|
@ -78,10 +78,20 @@ public func GetDynamiteCount()
|
|||
public func SetDynamiteCount(int new_count)
|
||||
{
|
||||
// Adjust dynamite counts to given amount
|
||||
var dyna;
|
||||
var change = new_count - GetDynamiteCount();
|
||||
if (change > 0) while (change--) CreateContents(Dynamite);
|
||||
if (change < 0) while (change++) if ((dyna = FindObject(Find_ID(Dynamite), Find_Container(this)))) dyna->RemoveObject();
|
||||
if (change > 0)
|
||||
{
|
||||
while (change--)
|
||||
CreateContents(Dynamite);
|
||||
} else if (change < 0)
|
||||
{
|
||||
while (change++)
|
||||
{
|
||||
var dynamite = FindObject(Find_ID(Dynamite), Find_Container(this));
|
||||
if (dynamite)
|
||||
dynamite->RemoveObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Empty this box and turn it into an igniter
|
||||
|
|
|
@ -451,7 +451,7 @@ global func SaveScenarioObject(props)
|
|||
var all_prop_names = GetProperties(this.EditorProps), prop_name, prop;
|
||||
for (prop_name in all_prop_names)
|
||||
{
|
||||
if ((prop=this.EditorProps[prop_name]))
|
||||
if ((prop = this.EditorProps[prop_name]) != nil)
|
||||
{
|
||||
if (GetType(prop) == C4V_PropList)
|
||||
{
|
||||
|
@ -497,9 +497,10 @@ global func SaveScenarioObject(props)
|
|||
global func SaveScenarioObjectAction(props)
|
||||
{
|
||||
// Helper function to store action properties
|
||||
var v;
|
||||
props->AddCall("Action", this, "SetAction", Format("%v", GetAction() ?? "Idle"), GetActionTarget(), GetActionTarget(1));
|
||||
if (v = GetPhase()) props->AddCall("Phase", this, "SetPhase", v);
|
||||
var v = GetPhase();
|
||||
if (v)
|
||||
props->AddCall("Phase", this, "SetPhase", v);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,15 +102,15 @@ global func FxIntScheduleCallTimer(object obj, effect fx)
|
|||
// documented in /docs/sdk/script/fn
|
||||
global func ClearScheduleCall(object obj, call_function)
|
||||
{
|
||||
var i, fx;
|
||||
var i;
|
||||
// Count downwards from effectnumber, to remove effects.
|
||||
i = GetEffectCount("IntScheduleCall", obj);
|
||||
while (i--)
|
||||
while (i--) {
|
||||
// Check All ScheduleCall-Effects.
|
||||
if (fx = GetEffect("IntScheduleCall", obj, i))
|
||||
// Found right function.
|
||||
if (fx.Function == call_function)
|
||||
// Remove effect.
|
||||
RemoveEffect(nil, obj, fx);
|
||||
var fx = GetEffect("IntScheduleCall", obj, i);
|
||||
if (fx && fx.Function == call_function)
|
||||
// Found right function. Remove effect.
|
||||
RemoveEffect(nil, obj, fx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue