diff --git a/OpenRa.Game/GameRules/InfoLoader.cs b/OpenRa.Game/GameRules/InfoLoader.cs new file mode 100644 index 0000000000..0634447269 --- /dev/null +++ b/OpenRa.Game/GameRules/InfoLoader.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.FileFormats; +using OpenRa.Game.Graphics; +using IjwFramework.Types; + +namespace OpenRa.Game.GameRules +{ + class InfoLoader + { + readonly Dictionary infos = new Dictionary(); + + public InfoLoader(IniFile rules, params Pair>[] srcs) + { + foreach (var src in srcs) + foreach (var s in Util.ReadAllLines(FileSystem.Open(src.First))) + { + var name = s.Split(',')[0]; + var t = src.Second(name.ToLowerInvariant()); + FieldLoader.Load(t, rules.GetSection(name)); + infos[name.ToLowerInvariant()] = t; + } + } + + public T this[string name] + { + get { return infos[name.ToLowerInvariant()]; } + } + } +} diff --git a/OpenRa.Game/GameRules/ProjectileInfo.cs b/OpenRa.Game/GameRules/ProjectileInfo.cs new file mode 100644 index 0000000000..8521d91c8c --- /dev/null +++ b/OpenRa.Game/GameRules/ProjectileInfo.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.GameRules +{ + class ProjectileInfo + { + public readonly bool AA = false; + public readonly bool AG = false; + public readonly bool ASW = false; + public readonly bool Animates = false; + public readonly bool Arcing = false; + public readonly int Arm = 0; + public readonly bool Degenerates = false; + public readonly bool Dropping = false; + public readonly int Frames = 1; + public readonly bool Gigundo = false; + public readonly bool High = false; + public readonly string Image = null; + public readonly bool Inaccurate = false; + public readonly bool Inviso = false; + public readonly bool Parachuted = false; + public readonly bool Proximity = false; + public readonly int ROT = 0; + public readonly bool Ranged = false; + public readonly bool Rotates = false; + public readonly bool Shadow = true; + public readonly bool Translucent = false; + public readonly bool UnderWater = false; + public readonly int RangeLimit = 0; + } +} diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index 230e3780eb..b1df97a4c2 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -3,23 +3,36 @@ using System.Collections.Generic; using System.Linq; using OpenRa.FileFormats; using OpenRa.Game.GameRules; +using IjwFramework.Types; namespace OpenRa.Game { static class Rules { - public static UnitInfoLoader UnitInfo; - public static WeaponInfoLoader WeaponInfo; - public static WarheadInfoLoader WarheadInfo; + public static InfoLoader UnitInfo; + public static InfoLoader WeaponInfo; + public static InfoLoader WarheadInfo; + public static InfoLoader ProjectileInfo; public static Footprint Footprint; // TODO: load rules from the map, where appropriate. public static void LoadRules() { - var rulesIni = new IniFile( FileSystem.Open( "rules.ini" ) ); - UnitInfo = new UnitInfoLoader( rulesIni ); - WeaponInfo = new WeaponInfoLoader( rulesIni ); - WarheadInfo = new WarheadInfoLoader(rulesIni); + var rulesIni = new IniFile(FileSystem.Open("rules.ini")); + + UnitInfo = new InfoLoader(rulesIni, + Pair.New>( "buildings.txt", s => new UnitInfo.BuildingInfo(s)), + Pair.New>("infantry.txt", s => new UnitInfo.InfantryInfo(s)), + Pair.New>( "vehicles.txt", s => new UnitInfo.VehicleInfo(s))); + + WeaponInfo = new InfoLoader(rulesIni, + Pair.New>("weapons.txt", _ => new WeaponInfo())); + WarheadInfo = new InfoLoader(rulesIni, + Pair.New>("warheads.txt", _ => new WarheadInfo())); + + ProjectileInfo = new InfoLoader(rulesIni, + Pair.New>("projectiles.txt", _ => new ProjectileInfo())); + Footprint = new Footprint(FileSystem.Open("footprint.txt")); } } diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 6000eb6e03..ff695d485a 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -7,44 +7,6 @@ using IjwFramework.Types; namespace OpenRa.Game.GameRules { - public class UnitInfoLoader - { - static Func BindInfoCtor() - where T : UnitInfo - { - var ctor = typeof( T ).GetConstructor( new[] { typeof( string ), typeof( IniSection ) } ); - return ( s, i ) => (UnitInfo)ctor.Invoke( new object[] { s, i } ); - } - - readonly Dictionary unitInfos = new Dictionary(); - - public UnitInfoLoader( IniFile rules ) - { - var srcs = new[] - { - Pair.New( "buildings.txt", BindInfoCtor() ), - Pair.New( "infantry.txt", BindInfoCtor() ), - Pair.New( "vehicles.txt", BindInfoCtor() ), - }; - - foreach( var src in srcs ) - foreach( var s in Util.ReadAllLines( FileSystem.Open( src.First ) ) ) - { - var unitName = s.Split( ',' )[ 0 ]; - unitInfos.Add( unitName.ToLowerInvariant(), - src.Second( unitName, rules.GetSection( unitName ) ) ); - } - } - - public UnitInfo this[ string unitName ] - { - get - { - return unitInfos[ unitName.ToLowerInvariant() ]; - } - } - } - public class UnitInfo { public enum ArmorType @@ -81,22 +43,14 @@ namespace OpenRa.Game.GameRules public readonly int Strength = 1; public readonly int TechLevel = -1; - public UnitInfo( string name, IniSection ini ) - { - Name = name.ToLowerInvariant(); - - FieldLoader.Load( this, ini ); - } + public UnitInfo(string name) { Name = name; } public class MobileInfo : UnitInfo { public readonly int Passengers = 0; public readonly int Speed = 0; - public MobileInfo( string name, IniSection ini ) - : base( name, ini ) - { - } + public MobileInfo(string name) : base(name) { } } public class InfantryInfo : MobileInfo @@ -107,10 +61,7 @@ namespace OpenRa.Game.GameRules public readonly bool Infiltrate = false; public readonly bool IsCanine = false; - public InfantryInfo( string name, IniSection ini ) - : base( name, ini ) - { - } + public InfantryInfo(string name) : base(name) { } } public class VehicleInfo : MobileInfo @@ -119,10 +70,7 @@ namespace OpenRa.Game.GameRules public readonly bool Tracked = false; public readonly bool NoMovingFire = false; - public VehicleInfo( string name, IniSection ini ) - : base( name, ini ) - { - } + public VehicleInfo(string name) : base(name) { } } public class BuildingInfo : UnitInfo @@ -138,10 +86,7 @@ namespace OpenRa.Game.GameRules public readonly bool Unsellable = false; public readonly bool WaterBound = false; - public BuildingInfo( string name, IniSection ini ) - : base( name, ini ) - { - } + public BuildingInfo(string name) : base(name) { } } /* diff --git a/OpenRa.Game/GameRules/WarheadInfo.cs b/OpenRa.Game/GameRules/WarheadInfo.cs index 65441d7e2d..b8d6f52bc7 100644 --- a/OpenRa.Game/GameRules/WarheadInfo.cs +++ b/OpenRa.Game/GameRules/WarheadInfo.cs @@ -7,29 +7,6 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.GameRules { - class WarheadInfoLoader - { - readonly Dictionary warheadInfos = new Dictionary(); - - public WarheadInfoLoader(IniFile rules) - { - foreach (var s in Util.ReadAllLines(FileSystem.Open("warheads.txt"))) - { - var unitName = s.Split(',')[0]; - warheadInfos.Add(unitName.ToLowerInvariant(), - new WarheadInfo(rules.GetSection(unitName))); - } - } - - public WarheadInfo this[string unitName] - { - get - { - return warheadInfos[unitName.ToLowerInvariant()]; - } - } - } - class WarheadInfo { public readonly int Spread = 1; @@ -39,10 +16,5 @@ namespace OpenRa.Game.GameRules public readonly bool Ore = false; public readonly int Explosion = 0; public readonly int InfDeath = 0; - - public WarheadInfo(IniSection ini) - { - FieldLoader.Load(this, ini); - } } } diff --git a/OpenRa.Game/GameRules/WeaponInfo.cs b/OpenRa.Game/GameRules/WeaponInfo.cs index 15569956dc..4dfe1fc01d 100755 --- a/OpenRa.Game/GameRules/WeaponInfo.cs +++ b/OpenRa.Game/GameRules/WeaponInfo.cs @@ -6,29 +6,6 @@ using OpenRa.Game.Graphics; namespace OpenRa.Game.GameRules { - class WeaponInfoLoader - { - readonly Dictionary weaponInfos = new Dictionary(); - - public WeaponInfoLoader( IniFile rules ) - { - foreach( var s in Util.ReadAllLines( FileSystem.Open( "weapons.txt" ) ) ) - { - var unitName = s.Split( ',' )[ 0 ]; - weaponInfos.Add( unitName.ToLowerInvariant(), - new WeaponInfo( rules.GetSection( unitName ) ) ); - } - } - - public WeaponInfo this[ string unitName ] - { - get - { - return weaponInfos[ unitName.ToLowerInvariant() ]; - } - } - } - class WeaponInfo { public readonly string Anim = null; @@ -44,10 +21,5 @@ namespace OpenRa.Game.GameRules public readonly bool Supress = false; public readonly bool TurboBoost = false; public readonly string Warhead = null; - - public WeaponInfo( IniSection ini ) - { - FieldLoader.Load( this, ini ); - } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index f6306613cb..27f432b1de 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -78,6 +78,8 @@ + + diff --git a/projectiles.txt b/projectiles.txt new file mode 100644 index 0000000000..49df40ae87 --- /dev/null +++ b/projectiles.txt @@ -0,0 +1,18 @@ +Invisible +LeapDog +Cannon +Ack +Torpedo +FROG +HeatSeeker +LaserGuided +AAMissile +Lobbed +Catapult +Bomblet +Ballistic +Parachute +GPSSatellite +NukeUp +NukeDown +Fireball \ No newline at end of file diff --git a/warheads.txt b/warheads.txt new file mode 100644 index 0000000000..fe46393a40 --- /dev/null +++ b/warheads.txt @@ -0,0 +1,8 @@ +SA +HE +AP +Fire +HollowPoint +Super +Organic +Nuke \ No newline at end of file