From 9af7b09e1dfcf1c73f85debbd532aab84afc0c44 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 13 Oct 2009 20:57:43 +1300 Subject: [PATCH] added WeaponInfo --- OpenRa.Game/Actor.cs | 4 +- OpenRa.Game/GameRules/FieldLoader.cs | 2 +- OpenRa.Game/GameRules/Rules.cs | 7 +- OpenRa.Game/GameRules/UnitInfo.cs | 104 ++++++++++++++------------- OpenRa.Game/GameRules/WeaponInfo.cs | 53 ++++++++++++++ OpenRa.Game/OpenRa.Game.csproj | 1 + OpenRa.Game/TechTree/Item.cs | 2 +- OpenRa.Game/TechTree/TechTree.cs | 2 +- weapons.txt | 35 +++++++++ 9 files changed, 152 insertions(+), 58 deletions(-) create mode 100755 OpenRa.Game/GameRules/WeaponInfo.cs create mode 100755 weapons.txt diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index b3671ddf33..ca7f54665d 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -14,14 +14,14 @@ namespace OpenRa.Game class Actor { public readonly TypeDictionary traits = new TypeDictionary(); - public readonly UnitInfo.BaseInfo unitInfo; + public readonly UnitInfo unitInfo; public int2 Location; public Player Owner; public Actor( string name, int2 location, Player owner ) { - unitInfo = Rules.UnitInfo.Get( name ); + unitInfo = Rules.UnitInfo[ name ]; Location = location; CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location; Owner = owner; diff --git a/OpenRa.Game/GameRules/FieldLoader.cs b/OpenRa.Game/GameRules/FieldLoader.cs index d76747b1f6..9c7b17d8af 100755 --- a/OpenRa.Game/GameRules/FieldLoader.cs +++ b/OpenRa.Game/GameRules/FieldLoader.cs @@ -8,7 +8,7 @@ namespace OpenRa.Game.GameRules { static class FieldLoader { - public static void Load( UnitInfo.BaseInfo self, IniSection ini ) + public static void Load( object self, IniSection ini ) { foreach( var x in ini ) { diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index 7bb949e4ec..e7c04dc5aa 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -8,13 +8,16 @@ namespace OpenRa.Game { static class Rules { - public static UnitInfo UnitInfo; + public static UnitInfoLoader UnitInfo; + public static WeaponInfoLoader WeaponInfo; public static Footprint Footprint; // TODO: load rules from the map, where appropriate. public static void LoadRules() { - UnitInfo = new UnitInfo( new IniFile( FileSystem.Open( "rules.ini" ) ) ); + var rulesIni = new IniFile( FileSystem.Open( "rules.ini" ) ); + UnitInfo = new UnitInfoLoader( rulesIni ); + WeaponInfo = new WeaponInfoLoader( rulesIni ); Footprint = new Footprint(FileSystem.Open("footprint.txt")); } } diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 461227d53e..6000eb6e03 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -1,47 +1,52 @@ using System; using System.Collections.Generic; using System.Linq; -using System.IO; using OpenRa.FileFormats; using OpenRa.Game.Graphics; using IjwFramework.Types; namespace OpenRa.Game.GameRules { - public class UnitInfo + public class UnitInfoLoader { - static Func BindInfoCtor() - where T : BaseInfo + static Func BindInfoCtor() + where T : UnitInfo { - var ctor = typeof(T).GetConstructor(new[] { typeof(string), typeof(IniSection) }); - return (s, i) => (BaseInfo)ctor.Invoke(new object [] { s,i }); + 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(); + readonly Dictionary unitInfos = new Dictionary(); - public UnitInfo( IniFile rules ) + public UnitInfoLoader( IniFile rules ) { - var srcs = new [] + var srcs = new[] { - Pair.New( "buildings.txt", BindInfoCtor() ), - Pair.New( "infantry.txt", BindInfoCtor() ), - Pair.New( "vehicles.txt", BindInfoCtor() ), + 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))) + 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))); + var unitName = s.Split( ',' )[ 0 ]; + unitInfos.Add( unitName.ToLowerInvariant(), + src.Second( unitName, rules.GetSection( unitName ) ) ); } } - public BaseInfo Get( string unitName ) + public UnitInfo this[ string unitName ] { - return unitInfos[ unitName.ToLowerInvariant() ]; + get + { + return unitInfos[ unitName.ToLowerInvariant() ]; + } } + } + public class UnitInfo + { public enum ArmorType { none = 0, @@ -51,42 +56,39 @@ namespace OpenRa.Game.GameRules concrete = 4, } - public class BaseInfo + public readonly string Name; + + public readonly int Ammo = -1; + public readonly ArmorType Armor = ArmorType.none; + public readonly bool DoubleOwned = false; + public readonly bool Cloakable = false; + public readonly int Cost = 0; + public readonly bool Crewed = false; + public readonly bool Explodes = false; + public readonly int GuardRange = -1; // -1 = use weapon's range + public readonly string Image = null; // sprite-set to use when rendering + public readonly bool Invisible = false; + public readonly string Owner = "allies,soviet"; // TODO: make this an enum + public readonly int Points = 0; + public readonly string Prerequisite = ""; + public readonly string Primary = null; + public readonly string Secondary = null; + public readonly int ROT = 0; + public readonly int Reload = 0; + public readonly bool SelfHealing = false; + public readonly bool Sensors = false; // no idea what this does + public readonly int Sight = 1; + public readonly int Strength = 1; + public readonly int TechLevel = -1; + + public UnitInfo( string name, IniSection ini ) { - public readonly string Name; + Name = name.ToLowerInvariant(); - public readonly int Ammo = -1; - public readonly ArmorType Armor = ArmorType.none; - public readonly bool DoubleOwned = false; - public readonly bool Cloakable = false; - public readonly int Cost = 0; - public readonly bool Crewed = false; - public readonly bool Explodes = false; - public readonly int GuardRange = -1; // -1 = use weapon's range - public readonly string Image = null; // sprite-set to use when rendering - public readonly bool Invisible = false; - public readonly string Owner = "allies,soviet"; // TODO: make this an enum - public readonly int Points = 0; - public readonly string Prerequisite = ""; - public readonly string Primary = null; - public readonly string Secondary = null; - public readonly int ROT = 0; - public readonly int Reload = 0; - public readonly bool SelfHealing = false; - public readonly bool Sensors = false; // no idea what this does - public readonly int Sight = 1; - public readonly int Strength = 1; - public readonly int TechLevel = -1; - - public BaseInfo( string name, IniSection ini ) - { - Name = name.ToLowerInvariant(); - - FieldLoader.Load( this, ini ); - } + FieldLoader.Load( this, ini ); } - public class MobileInfo : BaseInfo + public class MobileInfo : UnitInfo { public readonly int Passengers = 0; public readonly int Speed = 0; @@ -123,7 +125,7 @@ namespace OpenRa.Game.GameRules } } - public class BuildingInfo : BaseInfo + public class BuildingInfo : UnitInfo { public readonly bool BaseNormal = true; public readonly int Adjacent = 1; diff --git a/OpenRa.Game/GameRules/WeaponInfo.cs b/OpenRa.Game/GameRules/WeaponInfo.cs new file mode 100755 index 0000000000..15569956dc --- /dev/null +++ b/OpenRa.Game/GameRules/WeaponInfo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenRa.FileFormats; +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; + public readonly int Burst = 1; + public readonly bool Camera = false; + public readonly bool Charges = false; + public readonly int Damage = 0; + public readonly string Projectile = "Invisible"; + public readonly int ROF = 1; // in 1/15 second units. + public readonly float Range = 0; + public readonly string Report = null; + public readonly int Speed = -1; + 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 fb865d3bfa..dd105181d4 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -76,6 +76,7 @@ + diff --git a/OpenRa.Game/TechTree/Item.cs b/OpenRa.Game/TechTree/Item.cs index 77c139fb12..bc4b99a2c8 100644 --- a/OpenRa.Game/TechTree/Item.cs +++ b/OpenRa.Game/TechTree/Item.cs @@ -11,7 +11,7 @@ namespace OpenRa.TechTree public bool IsStructure { get { return isStructure; } } - public Item(string tag, string friendlyName, UnitInfo.BaseInfo unitInfo, bool isStructure) + public Item(string tag, string friendlyName, UnitInfo unitInfo, bool isStructure) { this.tag = tag; this.friendlyName = friendlyName; diff --git a/OpenRa.Game/TechTree/TechTree.cs b/OpenRa.Game/TechTree/TechTree.cs index 2b834af0b6..50ab7ae9f7 100644 --- a/OpenRa.Game/TechTree/TechTree.cs +++ b/OpenRa.Game/TechTree/TechTree.cs @@ -54,7 +54,7 @@ namespace OpenRa.TechTree .Concat( Lines( "infantry.txt", false ) ); foreach (Tuple p in definitions) - objects.Add(p.a, new Item(p.a, p.b, Rules.UnitInfo.Get(p.a), p.c)); + objects.Add(p.a, new Item(p.a, p.b, Rules.UnitInfo[p.a], p.c)); } public bool Build(string key, bool force) diff --git a/weapons.txt b/weapons.txt new file mode 100755 index 0000000000..b5e973baac --- /dev/null +++ b/weapons.txt @@ -0,0 +1,35 @@ +Colt45 +ZSU-23 +Vulcan +Maverick +Camera +FireballLauncher +Flamer +Sniper +ChainGun +Pistol +M1Carbine +Dragon +Hellfire +Grenade +75mm +90mm +105mm +120mm +TurretGun +MammothTusk +155mm +M60mg +Napalm +TeslaZap +Nike +RedEye +8Inch +Stinger +TorpTube +2Inch +DepthCharge +ParaBomb +DogJaw +Heal +SCUD