Add ISingleInstanceInit interface.
Inits that are logically singletons (e.g. actor location or owner) should implement this interface to avoid runtime inconsistencies. Duplicate instances are rejected at init-time, allowing simpler queries when they are used.
This commit is contained in:
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
MaxHP = hp = info.HP > 0 ? info.HP : 1;
|
||||
|
||||
// Cast to long to avoid overflow when multiplying by the health
|
||||
var healthInit = init.GetOrDefault<HealthInit>(info);
|
||||
var healthInit = init.GetOrDefault<HealthInit>();
|
||||
if (healthInit != null)
|
||||
hp = (int)(healthInit.Value * (long)MaxHP / 100);
|
||||
|
||||
@@ -233,13 +233,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class HealthInit : ValueActorInit<int>
|
||||
public class HealthInit : ValueActorInit<int>, ISingleInstanceInit
|
||||
{
|
||||
readonly bool allowZero;
|
||||
|
||||
public HealthInit(TraitInfo info, int value, bool allowZero = false)
|
||||
: base(info, value) { this.allowZero = allowZero; }
|
||||
|
||||
public HealthInit(int value, bool allowZero = false)
|
||||
: base(value) { this.allowZero = allowZero; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user