added WeaponInfo
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, IniSection, BaseInfo> BindInfoCtor<T>()
|
||||
where T : BaseInfo
|
||||
static Func<string, IniSection, UnitInfo> BindInfoCtor<T>()
|
||||
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<string, BaseInfo> unitInfos = new Dictionary<string, BaseInfo>();
|
||||
readonly Dictionary<string, UnitInfo> unitInfos = new Dictionary<string, UnitInfo>();
|
||||
|
||||
public UnitInfo( IniFile rules )
|
||||
public UnitInfoLoader( IniFile rules )
|
||||
{
|
||||
var srcs = new []
|
||||
var srcs = new[]
|
||||
{
|
||||
Pair.New( "buildings.txt", BindInfoCtor<BuildingInfo>() ),
|
||||
Pair.New( "infantry.txt", BindInfoCtor<InfantryInfo>() ),
|
||||
Pair.New( "vehicles.txt", BindInfoCtor<VehicleInfo>() ),
|
||||
Pair.New( "buildings.txt", BindInfoCtor<UnitInfo.BuildingInfo>() ),
|
||||
Pair.New( "infantry.txt", BindInfoCtor<UnitInfo.InfantryInfo>() ),
|
||||
Pair.New( "vehicles.txt", BindInfoCtor<UnitInfo.VehicleInfo>() ),
|
||||
};
|
||||
|
||||
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 ]
|
||||
{
|
||||
get
|
||||
{
|
||||
return unitInfos[ unitName.ToLowerInvariant() ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitInfo
|
||||
{
|
||||
public enum ArmorType
|
||||
{
|
||||
none = 0,
|
||||
@@ -51,8 +56,6 @@ namespace OpenRa.Game.GameRules
|
||||
concrete = 4,
|
||||
}
|
||||
|
||||
public class BaseInfo
|
||||
{
|
||||
public readonly string Name;
|
||||
|
||||
public readonly int Ammo = -1;
|
||||
@@ -78,15 +81,14 @@ namespace OpenRa.Game.GameRules
|
||||
public readonly int Strength = 1;
|
||||
public readonly int TechLevel = -1;
|
||||
|
||||
public BaseInfo( string name, IniSection ini )
|
||||
public UnitInfo( string name, IniSection ini )
|
||||
{
|
||||
Name = name.ToLowerInvariant();
|
||||
|
||||
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;
|
||||
|
||||
53
OpenRa.Game/GameRules/WeaponInfo.cs
Executable file
53
OpenRa.Game/GameRules/WeaponInfo.cs
Executable file
@@ -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<string, WeaponInfo> weaponInfos = new Dictionary<string, WeaponInfo>();
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@
|
||||
<Compile Include="GameRules\Footprint.cs" />
|
||||
<Compile Include="GameRules\Rules.cs" />
|
||||
<Compile Include="GameRules\UnitInfo.cs" />
|
||||
<Compile Include="GameRules\WeaponInfo.cs" />
|
||||
<Compile Include="Graphics\Animation.cs" />
|
||||
<Compile Include="Game.cs" />
|
||||
<Compile Include="Graphics\CursorSheetBuilder.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;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRa.TechTree
|
||||
.Concat( Lines( "infantry.txt", false ) );
|
||||
|
||||
foreach (Tuple<string, string, bool> 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)
|
||||
|
||||
35
weapons.txt
Executable file
35
weapons.txt
Executable file
@@ -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
|
||||
Reference in New Issue
Block a user