added WeaponInfo
This commit is contained in:
@@ -14,14 +14,14 @@ namespace OpenRa.Game
|
|||||||
class Actor
|
class Actor
|
||||||
{
|
{
|
||||||
public readonly TypeDictionary traits = new TypeDictionary();
|
public readonly TypeDictionary traits = new TypeDictionary();
|
||||||
public readonly UnitInfo.BaseInfo unitInfo;
|
public readonly UnitInfo unitInfo;
|
||||||
|
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
public Player Owner;
|
public Player Owner;
|
||||||
|
|
||||||
public Actor( string name, int2 location, Player owner )
|
public Actor( string name, int2 location, Player owner )
|
||||||
{
|
{
|
||||||
unitInfo = Rules.UnitInfo.Get( name );
|
unitInfo = Rules.UnitInfo[ name ];
|
||||||
Location = location;
|
Location = location;
|
||||||
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
|
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace OpenRa.Game.GameRules
|
|||||||
{
|
{
|
||||||
static class FieldLoader
|
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 )
|
foreach( var x in ini )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,13 +8,16 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
static class Rules
|
static class Rules
|
||||||
{
|
{
|
||||||
public static UnitInfo UnitInfo;
|
public static UnitInfoLoader UnitInfo;
|
||||||
|
public static WeaponInfoLoader WeaponInfo;
|
||||||
public static Footprint Footprint;
|
public static Footprint Footprint;
|
||||||
|
|
||||||
// TODO: load rules from the map, where appropriate.
|
// TODO: load rules from the map, where appropriate.
|
||||||
public static void LoadRules()
|
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"));
|
Footprint = new Footprint(FileSystem.Open("footprint.txt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
|
|
||||||
namespace OpenRa.Game.GameRules
|
namespace OpenRa.Game.GameRules
|
||||||
{
|
{
|
||||||
public class UnitInfo
|
public class UnitInfoLoader
|
||||||
{
|
{
|
||||||
static Func<string, IniSection, BaseInfo> BindInfoCtor<T>()
|
static Func<string, IniSection, UnitInfo> BindInfoCtor<T>()
|
||||||
where T : BaseInfo
|
where T : UnitInfo
|
||||||
{
|
{
|
||||||
var ctor = typeof(T).GetConstructor(new[] { typeof(string), typeof(IniSection) });
|
var ctor = typeof( T ).GetConstructor( new[] { typeof( string ), typeof( IniSection ) } );
|
||||||
return (s, i) => (BaseInfo)ctor.Invoke(new object [] { s,i });
|
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( "buildings.txt", BindInfoCtor<UnitInfo.BuildingInfo>() ),
|
||||||
Pair.New( "infantry.txt", BindInfoCtor<InfantryInfo>() ),
|
Pair.New( "infantry.txt", BindInfoCtor<UnitInfo.InfantryInfo>() ),
|
||||||
Pair.New( "vehicles.txt", BindInfoCtor<VehicleInfo>() ),
|
Pair.New( "vehicles.txt", BindInfoCtor<UnitInfo.VehicleInfo>() ),
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach( var src in srcs )
|
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];
|
var unitName = s.Split( ',' )[ 0 ];
|
||||||
unitInfos.Add(unitName.ToLowerInvariant(),
|
unitInfos.Add( unitName.ToLowerInvariant(),
|
||||||
src.Second(unitName, rules.GetSection(unitName)));
|
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
|
public enum ArmorType
|
||||||
{
|
{
|
||||||
none = 0,
|
none = 0,
|
||||||
@@ -51,42 +56,39 @@ namespace OpenRa.Game.GameRules
|
|||||||
concrete = 4,
|
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;
|
FieldLoader.Load( this, ini );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MobileInfo : BaseInfo
|
public class MobileInfo : UnitInfo
|
||||||
{
|
{
|
||||||
public readonly int Passengers = 0;
|
public readonly int Passengers = 0;
|
||||||
public readonly int Speed = 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 bool BaseNormal = true;
|
||||||
public readonly int Adjacent = 1;
|
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\Footprint.cs" />
|
||||||
<Compile Include="GameRules\Rules.cs" />
|
<Compile Include="GameRules\Rules.cs" />
|
||||||
<Compile Include="GameRules\UnitInfo.cs" />
|
<Compile Include="GameRules\UnitInfo.cs" />
|
||||||
|
<Compile Include="GameRules\WeaponInfo.cs" />
|
||||||
<Compile Include="Graphics\Animation.cs" />
|
<Compile Include="Graphics\Animation.cs" />
|
||||||
<Compile Include="Game.cs" />
|
<Compile Include="Game.cs" />
|
||||||
<Compile Include="Graphics\CursorSheetBuilder.cs" />
|
<Compile Include="Graphics\CursorSheetBuilder.cs" />
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
public bool IsStructure { get { return isStructure; } }
|
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.tag = tag;
|
||||||
this.friendlyName = friendlyName;
|
this.friendlyName = friendlyName;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace OpenRa.TechTree
|
|||||||
.Concat( Lines( "infantry.txt", false ) );
|
.Concat( Lines( "infantry.txt", false ) );
|
||||||
|
|
||||||
foreach (Tuple<string, string, bool> p in definitions)
|
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)
|
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