From 7b7b9d3319305766ecc54ef173e48f8b04ce2d43 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 26 Aug 2010 22:12:08 +1200 Subject: [PATCH] make WeaponInfo suck a bit less --- OpenRA.Game/GameRules/WeaponInfo.cs | 40 ++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 7756578cb5..2d3dfb78f8 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.Traits; @@ -84,35 +85,28 @@ namespace OpenRA.GameRules public IProjectileInfo Projectile; public List Warheads = new List(); + static readonly string[] SimpleFields = { "Range", "Report", "ROF", "Burst", "Charges", "Underwater", + "ValidTargets", "BurstDelay" }; + public WeaponInfo(string name, MiniYaml content) { + FieldLoader.LoadFields( this, content.Nodes, SimpleFields ); + foreach (var kv in content.Nodes) { var key = kv.Key.Split('@')[0]; - switch (key) + if (SimpleFields.Contains(key)) + continue; + else if (key == "Warhead") { - case "Range": FieldLoader.LoadField(this, "Range", content.Nodes["Range"].Value); break; - case "ROF": FieldLoader.LoadField(this, "ROF", content.Nodes["ROF"].Value); break; - case "Report": FieldLoader.LoadField(this, "Report", content.Nodes["Report"].Value); break; - case "Burst": FieldLoader.LoadField(this, "Burst", content.Nodes["Burst"].Value); break; - case "Charges": FieldLoader.LoadField(this, "Charges", content.Nodes["Charges"].Value); break; - case "ValidTargets": FieldLoader.LoadField(this, "ValidTargets", content.Nodes["ValidTargets"].Value); break; - case "Underwater": FieldLoader.LoadField(this, "Underwater", content.Nodes["Underwater"].Value); break; - case "BurstDelay": FieldLoader.LoadField(this, "BurstDelay", content.Nodes["BurstDelay"].Value); break; - - case "Warhead": - { - var warhead = new WarheadInfo(); - FieldLoader.Load(warhead, kv.Value); - Warheads.Add(warhead); - } break; - - // in this case, it's an implementation of IProjectileInfo - default: - { - Projectile = Game.CreateObject(key + "Info"); - FieldLoader.Load(Projectile, kv.Value); - } break; + var warhead = new WarheadInfo(); + FieldLoader.Load(warhead, kv.Value); + Warheads.Add(warhead); + } + else + { + Projectile = Game.CreateObject(key + "Info"); + FieldLoader.Load(Projectile, kv.Value); } } }