WarheadInfo loading

This commit is contained in:
Chris Forbes
2009-10-14 13:59:27 +13:00
parent f41fddef8e
commit 6432ba8779
4 changed files with 55 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Collections;
namespace OpenRa.FileFormats namespace OpenRa.FileFormats
{ {
@@ -75,18 +76,17 @@ namespace OpenRa.FileFormats
public class IniSection : IEnumerable<KeyValuePair<string, string>> public class IniSection : IEnumerable<KeyValuePair<string, string>>
{ {
string name; public string Name { get; private set; }
Dictionary<string, string> values = new Dictionary<string, string>(); Dictionary<string, string> values = new Dictionary<string, string>();
public IniSection( string name ) public IniSection( string name )
{ {
this.name = name; Name = name;
} }
public void Add( string key, string value ) public void Add( string key, string value )
{ {
values[key] = value; values[key] = value;
//values.Add( key, value );
} }
public string GetValue( string key, string defaultValue ) public string GetValue( string key, string defaultValue )
@@ -100,7 +100,7 @@ namespace OpenRa.FileFormats
return values.GetEnumerator(); return values.GetEnumerator();
} }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }

View File

@@ -10,6 +10,7 @@ namespace OpenRa.Game
{ {
public static UnitInfoLoader UnitInfo; public static UnitInfoLoader UnitInfo;
public static WeaponInfoLoader WeaponInfo; public static WeaponInfoLoader WeaponInfo;
public static WarheadInfoLoader WarheadInfo;
public static Footprint Footprint; public static Footprint Footprint;
// TODO: load rules from the map, where appropriate. // TODO: load rules from the map, where appropriate.
@@ -18,6 +19,7 @@ namespace OpenRa.Game
var rulesIni = new IniFile( FileSystem.Open( "rules.ini" ) ); var rulesIni = new IniFile( FileSystem.Open( "rules.ini" ) );
UnitInfo = new UnitInfoLoader( rulesIni ); UnitInfo = new UnitInfoLoader( rulesIni );
WeaponInfo = new WeaponInfoLoader( rulesIni ); WeaponInfo = new WeaponInfoLoader( rulesIni );
WarheadInfo = new WarheadInfoLoader(rulesIni);
Footprint = new Footprint(FileSystem.Open("footprint.txt")); Footprint = new Footprint(FileSystem.Open("footprint.txt"));
} }
} }

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.FileFormats;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.GameRules
{
class WarheadInfoLoader
{
readonly Dictionary<string, WarheadInfo> warheadInfos = new Dictionary<string, WarheadInfo>();
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;
public readonly string Verses = "100%,100%,100%,100%,100%";
public readonly bool Wall = false;
public readonly bool Wood = false;
public readonly bool Ore = false;
public readonly int Explosion = 0;
public readonly int InfDeath = 0;
public WarheadInfo(IniSection ini)
{
FieldLoader.Load(this, ini);
}
}
}

View File

@@ -80,6 +80,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\WarheadInfo.cs" />
<Compile Include="GameRules\WeaponInfo.cs" /> <Compile Include="GameRules\WeaponInfo.cs" />
<Compile Include="Graphics\Animation.cs" /> <Compile Include="Graphics\Animation.cs" />
<Compile Include="Game.cs" /> <Compile Include="Game.cs" />