From 9089012a79c06b26bd7f97867999e812c84ec138 Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Sat, 13 Aug 2016 18:46:48 -0500 Subject: [PATCH] Allow scripts to get the Valued.Cost value of an actor type --- OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs index 38d7b73647..5e87dcf2d5 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs @@ -84,5 +84,18 @@ namespace OpenRA.Mods.Common.Scripting var pi = ai.TraitInfoOrDefault(); 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(); + 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; + } } }