Import actor facing and health from legacy maps

This commit is contained in:
Paul Chote
2010-08-15 17:47:04 +12:00
parent 50950cba22
commit a8be81ea2b
2 changed files with 9 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ using System.Linq;
using System.Text;
using OpenRA;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Editor
{
@@ -346,16 +347,21 @@ namespace OpenRA.Editor
{
foreach (var s in file.GetSection(section, true))
{
//num=owner,type,health,location,facing,...
//Structures: num=owner,type,health,location,turret-facing,trigger
//Units: num=owner,type,health,location,facing,action,trigger
//Infantry: num=owner,type,health,location,subcell,action,facing,trigger
var parts = s.Value.Split(',');
var loc = int.Parse(parts[3]);
if (parts[0] == "")
parts[0] = "Neutral";
Map.Actors.Add("Actor" + ActorCount++,
new ActorReference(parts[1].ToLowerInvariant())
{
new LocationInit(new int2(loc % MapSize, loc / MapSize)),
new OwnerInit(parts[0])
new OwnerInit(parts[0]),
new HealthInit(float.Parse(parts[2])/256),
new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])),
});
}
}

View File

@@ -23,7 +23,7 @@ namespace OpenRA.FileFormats
public ActorReference( string type, Dictionary<string, MiniYaml> inits )
{
if (!Rules.Info.ContainsKey(type))
if (Rules.Info != null && !Rules.Info.ContainsKey(type))
throw new InvalidDataException("Unknown actor: `{0}'".F(type));
Type = type;