Rewrite ActorInit queries.

This commit is contained in:
Paul Chote
2020-05-24 22:28:16 +01:00
committed by teinarss
parent 626b40f31b
commit 7c6ec577dc
66 changed files with 332 additions and 265 deletions

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
actor =>
{
var init = actor.Init<HealthInit>();
return init != null ? init.Value(world) : 100;
return init != null ? init.Value : 100;
},
(actor, value) => actor.ReplaceInit(new HealthInit((int)value)));
}
@@ -68,10 +68,12 @@ namespace OpenRA.Mods.Common.Traits
public Health(ActorInitializer init, HealthInfo info)
{
Info = info;
MaxHP = info.HP > 0 ? info.HP : 1;
MaxHP = hp = info.HP > 0 ? info.HP : 1;
// Cast to long to avoid overflow when multiplying by the health
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, int>() * (long)MaxHP / 100) : MaxHP;
var healthInit = init.GetOrDefault<HealthInit>(info);
if (healthInit != null)
hp = (int)(healthInit.Value * (long)MaxHP / 100);
DisplayHP = hp;
}
@@ -247,12 +249,15 @@ namespace OpenRA.Mods.Common.Traits
value = init;
}
public int Value(World world)
public int Value
{
if (value < 0 || (value == 0 && !allowZero))
return 1;
get
{
if (value < 0 || (value == 0 && !allowZero))
return 1;
return value;
return value;
}
}
}
}