Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var pi = ai.Traits.GetOrDefault<ICruiseAltitudeInfo>();
|
||||
var pi = ai.TraitInfoOrDefault<ICruiseAltitudeInfo>();
|
||||
return pi != null ? pi.GetCruiseAltitude().Length : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
if (entryLocation.HasValue)
|
||||
{
|
||||
var pi = ai.Traits.GetOrDefault<AircraftInfo>();
|
||||
var pi = ai.TraitInfoOrDefault<AircraftInfo>();
|
||||
initDict.Add(new CenterPositionInit(owner.World.Map.CenterOfCell(entryLocation.Value) + new WVec(0, 0, pi != null ? pi.CruiseAltitude.Length : 0)));
|
||||
initDict.Add(new LocationInit(entryLocation.Value));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
else
|
||||
{
|
||||
var heli = transport.Info.Traits.GetOrDefault<HelicopterInfo>();
|
||||
var heli = transport.Info.TraitInfoOrDefault<HelicopterInfo>();
|
||||
if (heli != null)
|
||||
{
|
||||
transport.QueueActivity(new Turn(transport, heli.InitialFacing));
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public CaptureProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
normalInfo = Self.Info.Traits.GetOrDefault<CapturesInfo>();
|
||||
externalInfo = Self.Info.Traits.GetOrDefault<ExternalCapturesInfo>();
|
||||
normalInfo = Self.Info.TraitInfoOrDefault<CapturesInfo>();
|
||||
externalInfo = Self.Info.TraitInfoOrDefault<ExternalCapturesInfo>();
|
||||
}
|
||||
|
||||
[Desc("Captures the target actor.")]
|
||||
public void Capture(Actor target)
|
||||
{
|
||||
var normalCapturable = target.Info.Traits.GetOrDefault<CapturableInfo>();
|
||||
var externalCapturable = target.Info.Traits.GetOrDefault<ExternalCapturableInfo>();
|
||||
var normalCapturable = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
var externalCapturable = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
|
||||
|
||||
if (normalInfo != null && normalCapturable != null && normalInfo.CaptureTypes.Contains(normalCapturable.Type))
|
||||
Self.QueueActivity(new CaptureActor(Self, target));
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public DemolitionProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
info = Self.Info.Traits.Get<C4DemolitionInfo>();
|
||||
info = Self.Info.TraitInfo<C4DemolitionInfo>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Self.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
@@ -267,7 +267,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Player.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
|
||||
Reference in New Issue
Block a user