Allow scripts to get the Valued.Cost value of an actor type

This commit is contained in:
Taryn Hill
2016-08-13 18:46:48 -05:00
parent 6d742efbf4
commit 9089012a79

View File

@@ -84,5 +84,18 @@ namespace OpenRA.Mods.Common.Scripting
var pi = ai.TraitInfoOrDefault<ICruiseAltitudeInfo>();
return pi != null ? pi.GetCruiseAltitude().Length : 0;
}
public int Cost(string type)
{
ActorInfo ai;
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
throw new LuaException("Unknown actor type '{0}'".F(type));
var vi = ai.TraitInfoOrDefault<ValuedInfo>();
if (vi == null)
throw new LuaException("Actor type '{0}' does not have the Valued trait required to get the Cost.".F(type));
return vi.Cost;
}
}
}