Integrated HitShapes

Integrated hit shapes with field loader and warhead calculations.
This commit is contained in:
Huw Pascoe
2015-10-29 16:58:07 +00:00
parent 5ef6d86f66
commit a8299221db
6 changed files with 40 additions and 15 deletions

View File

@@ -8,7 +8,9 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.Mods.Common.HitShapes;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -17,13 +19,39 @@ namespace OpenRA.Mods.Common.Traits
{
[Desc("HitPoints")]
public readonly int HP = 0;
[Desc("Physical size of the unit used for damage calculations. Impacts within this radius apply full damage.")]
public readonly WDist Radius = new WDist(426);
[Desc("Trigger interfaces such as AnnounceOnKill?")]
public readonly bool NotifyAppliedDamage = true;
[FieldLoader.LoadUsing("LoadShape")]
public readonly IHitShape Shape;
static object LoadShape(MiniYaml yaml)
{
IHitShape ret;
var shapeNode = yaml.Nodes.Find(n => n.Key == "Shape");
var shape = shapeNode != null ? shapeNode.Value.Value : string.Empty;
if (!string.IsNullOrEmpty(shape))
{
ret = Game.CreateObject<IHitShape>(shape + "Shape");
try
{
FieldLoader.Load(ret, shapeNode.Value);
}
catch (YamlException e)
{
throw new YamlException("HitShape {0}: {1}".F(shape, e.Message));
}
}
else
ret = new CircleShape();
ret.Initialize();
return ret;
}
public virtual object Create(ActorInitializer init) { return new Health(init, this); }
}