Tidy up Mobile yaml / loading
This commit is contained in:
@@ -14,33 +14,49 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
using OpenRA.Traits.Activities;
|
using OpenRA.Traits.Activities;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
public class MobileInfo : ITraitInfo
|
public class MobileInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly string[] TerrainTypes;
|
[FieldLoader.LoadUsing( "LoadSpeeds" )]
|
||||||
public readonly float[] TerrainSpeeds;
|
public readonly Dictionary<string, TerrainInfo> TerrainSpeeds;
|
||||||
public readonly string[] TerrainCostOverrides;
|
[FieldLoader.Load] public readonly string[] Crushes;
|
||||||
public readonly float[] TerrainCosts;
|
[FieldLoader.Load] public readonly int WaitAverage = 60;
|
||||||
public readonly string[] Crushes;
|
[FieldLoader.Load] public readonly int WaitSpread = 20;
|
||||||
public readonly int WaitAverage = 60;
|
[FieldLoader.Load] public readonly int InitialFacing = 128;
|
||||||
public readonly int WaitSpread = 20;
|
[FieldLoader.Load] public readonly int ROT = 255;
|
||||||
public readonly int InitialFacing = 128;
|
[FieldLoader.Load] public readonly int Speed = 1;
|
||||||
public readonly int ROT = 255;
|
[FieldLoader.Load] public readonly bool OnRails = false;
|
||||||
public readonly int Speed = 1;
|
|
||||||
public readonly bool OnRails = false;
|
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
|
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||||
|
|
||||||
|
static object LoadSpeeds( MiniYaml y )
|
||||||
|
{
|
||||||
|
Dictionary<string,TerrainInfo> ret = new Dictionary<string, TerrainInfo>();
|
||||||
|
foreach (var t in y.NodesDict["TerrainSpeeds"].Nodes)
|
||||||
|
{
|
||||||
|
var speed = (float)FieldLoader.GetValue("speed", typeof(float),t.Value.Value);
|
||||||
|
var cost = t.Value.NodesDict.ContainsKey("PathingCost") ? (float)FieldLoader.GetValue("cost", typeof(float), t.Value.NodesDict["PathingCost"].Value) : 1f/speed;
|
||||||
|
ret.Add(t.Key, new TerrainInfo{Speed = speed, Cost = cost});
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TerrainInfo
|
||||||
|
{
|
||||||
|
public float Cost = float.PositiveInfinity;
|
||||||
|
public float Speed = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
|
public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
|
||||||
{
|
{
|
||||||
public readonly Actor self;
|
public readonly Actor self;
|
||||||
public readonly MobileInfo Info;
|
public readonly MobileInfo Info;
|
||||||
public readonly Dictionary<string,float> TerrainCost;
|
|
||||||
public readonly Dictionary<string,float> TerrainSpeed;
|
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Facing { get; set; }
|
public int Facing { get; set; }
|
||||||
[Sync]
|
[Sync]
|
||||||
@@ -93,26 +109,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
||||||
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
||||||
|
|
||||||
TerrainCost = new Dictionary<string, float>();
|
|
||||||
TerrainSpeed = new Dictionary<string, float>();
|
|
||||||
|
|
||||||
if (info.TerrainTypes.Count() != info.TerrainSpeeds.Count())
|
|
||||||
throw new InvalidOperationException("Mobile TerrainType/TerrainSpeed length mismatch");
|
|
||||||
|
|
||||||
if (info.TerrainCostOverrides != null)
|
|
||||||
for (int i = 0; i < info.TerrainCostOverrides.Count(); i++)
|
|
||||||
{
|
|
||||||
TerrainCost.Add(info.TerrainCostOverrides[i], info.TerrainCosts[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < info.TerrainTypes.Count(); i++)
|
|
||||||
{
|
|
||||||
if (!TerrainCost.ContainsKey(info.TerrainTypes[i]))
|
|
||||||
TerrainCost.Add(info.TerrainTypes[i], 1f/info.TerrainSpeeds[i]);
|
|
||||||
|
|
||||||
TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Actor self, int2 cell)
|
public void SetPosition(Actor self, int2 cell)
|
||||||
@@ -259,18 +255,24 @@ namespace OpenRA.Traits
|
|||||||
return float.PositiveInfinity;
|
return float.PositiveInfinity;
|
||||||
|
|
||||||
var type = self.World.GetTerrainType(cell);
|
var type = self.World.GetTerrainType(cell);
|
||||||
return TerrainCost[type];
|
if (!Info.TerrainSpeeds.ContainsKey(type))
|
||||||
|
return float.PositiveInfinity;
|
||||||
|
|
||||||
|
return Info.TerrainSpeeds[type].Cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual float MovementSpeedForCell(Actor self, int2 cell)
|
public virtual float MovementSpeedForCell(Actor self, int2 cell)
|
||||||
{
|
{
|
||||||
var type = self.World.GetTerrainType(cell);
|
var type = self.World.GetTerrainType(cell);
|
||||||
|
|
||||||
|
if (!Info.TerrainSpeeds.ContainsKey(type))
|
||||||
|
return 0;
|
||||||
|
|
||||||
var modifier = self
|
var modifier = self
|
||||||
.TraitsImplementing<ISpeedModifier>()
|
.TraitsImplementing<ISpeedModifier>()
|
||||||
.Select(t => t.GetSpeedModifier())
|
.Select(t => t.GetSpeedModifier())
|
||||||
.Product();
|
.Product();
|
||||||
return Info.Speed * TerrainSpeed[type] * modifier;
|
return Info.Speed * Info.TerrainSpeeds[type].Speed * modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<float2> GetCurrentPath(Actor self)
|
public IEnumerable<float2> GetCurrentPath(Actor self)
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 60%, 40%, 100%, 0%, 0%, 0%, 0%, 50%, 40%, 0%
|
Clear: 60%
|
||||||
|
Rough: 40%
|
||||||
|
Road: 100%
|
||||||
|
Ore: 70%
|
||||||
|
Beach: 40%
|
||||||
ROT: 5
|
ROT: 5
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
@@ -27,8 +31,12 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: wall, crate
|
Crushes: wall, crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 80%, 70%, 100%, 0%, 0%, 0%, 0%, 70%, 70%, 0%
|
Clear: 80%
|
||||||
|
Rough: 70%
|
||||||
|
Road: 100%
|
||||||
|
Ore: 90%
|
||||||
|
Beach: 70%
|
||||||
ROT: 5
|
ROT: 5
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
@@ -75,10 +83,13 @@
|
|||||||
Range: 4
|
Range: 4
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 90%, 80%, 100%, 0%, 0%, 0%, 0%, 90%, 80%, 0%
|
Clear: 90%
|
||||||
TerrainCostOverrides: Ore
|
Rough: 80%
|
||||||
TerrainCosts: 200
|
Road: 100%
|
||||||
|
Ore: 90%
|
||||||
|
PathingCost: 200
|
||||||
|
Beach: 80%
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
Targetable:
|
Targetable:
|
||||||
@@ -138,8 +149,8 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 0%, 0%, 0%, 0%, 100%, 0%, 0%, 0%, 0%, 0%
|
Water: 100%
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
Targetable:
|
Targetable:
|
||||||
|
|||||||
@@ -594,8 +594,17 @@ LST:
|
|||||||
Name: Landing Craft
|
Name: Landing Craft
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%
|
Clear: 100%
|
||||||
|
Rough: 100%
|
||||||
|
Road: 100%
|
||||||
|
Tree: 100%
|
||||||
|
Water: 100%
|
||||||
|
Rock: 100%
|
||||||
|
Wall: 100%
|
||||||
|
Ore: 100%
|
||||||
|
Beach: 100%
|
||||||
|
River: 100%
|
||||||
InitialFacing:0
|
InitialFacing:0
|
||||||
ROT: 4
|
ROT: 4
|
||||||
Speed: 10
|
Speed: 10
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: atmine, crate
|
Crushes: atmine, crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 60%, 40%, 100%, 0%, 0%, 0%, 0%, 90%, 40%, 0%
|
Clear: 60%
|
||||||
|
Rough: 40%
|
||||||
|
Road: 100%
|
||||||
|
Ore: 90%
|
||||||
|
Beach: 40%
|
||||||
ROT: 5
|
ROT: 5
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
@@ -25,8 +29,12 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: wall, atmine, crate
|
Crushes: wall, atmine, crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 80%, 70%, 100%, 0%, 0%, 0%, 0%, 90%, 70%, 0%
|
Clear: 80%
|
||||||
|
Rough: 70%
|
||||||
|
Road: 100%
|
||||||
|
Ore: 70%
|
||||||
|
Beach: 70%
|
||||||
ROT: 5
|
ROT: 5
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
@@ -52,8 +60,12 @@
|
|||||||
Range: 4
|
Range: 4
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: apmine, crate
|
Crushes: apmine, crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 90%, 80%, 100%, 0%, 0%, 0%, 0%, 100%, 80%, 0%
|
Clear: 90%
|
||||||
|
Rough: 80%
|
||||||
|
Road: 100%
|
||||||
|
Ore: 100%
|
||||||
|
Beach: 80%
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
Targetable:
|
Targetable:
|
||||||
@@ -74,8 +86,8 @@
|
|||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Mobile:
|
Mobile:
|
||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
TerrainSpeeds:
|
||||||
TerrainSpeeds: 0%, 0%, 0%, 0%, 100%, 0%, 0%, 0%, 0%, 0%
|
Water: 100%
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: ShipVoice
|
Voice: ShipVoice
|
||||||
Targetable:
|
Targetable:
|
||||||
|
|||||||
Reference in New Issue
Block a user