Convert Waypoints to actors
This commit is contained in:
@@ -24,7 +24,6 @@ namespace OpenRA
|
||||
{
|
||||
// Yaml map data
|
||||
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
|
||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||
public List<SmudgeReference> Smudges = new List<SmudgeReference>();
|
||||
|
||||
// Rules overrides
|
||||
@@ -93,13 +92,7 @@ namespace OpenRA
|
||||
// Use release-20110207 to convert older maps to format 4
|
||||
if (MapFormat < 4)
|
||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
||||
|
||||
|
||||
// Define RequiresMod for map installer
|
||||
if (MapFormat < 5)
|
||||
RequiresMod = Game.CurrentMods.Keys.First();
|
||||
|
||||
|
||||
|
||||
// Load players
|
||||
foreach (var kv in yaml.NodesDict["Players"].NodesDict)
|
||||
{
|
||||
@@ -125,7 +118,7 @@ namespace OpenRA
|
||||
/* hack: make some slots. */
|
||||
if (!Players.Any(p => p.Value.Playable))
|
||||
{
|
||||
for (int index = 0; index < Waypoints.Count; index++)
|
||||
for (int index = 0; index < SpawnPoints.Count(); index++)
|
||||
{
|
||||
var p = new PlayerReference
|
||||
{
|
||||
@@ -138,11 +131,7 @@ namespace OpenRA
|
||||
Players.Add(p.Name, p);
|
||||
}
|
||||
}
|
||||
|
||||
// Load actors
|
||||
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
|
||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||
|
||||
|
||||
// Smudges
|
||||
foreach (var kv in yaml.NodesDict["Smudges"].NodesDict)
|
||||
{
|
||||
@@ -205,7 +194,6 @@ namespace OpenRA
|
||||
x.Key,
|
||||
x.Value.Save() ) ).ToList() ) );
|
||||
|
||||
root.Add(new MiniYamlNode("Waypoints", MiniYaml.FromDictionary<string, int2>( Waypoints )));
|
||||
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>( Smudges )));
|
||||
root.Add(new MiniYamlNode("Rules", null, Rules));
|
||||
root.Add(new MiniYamlNode("Sequences", null, Sequences));
|
||||
|
||||
93
OpenRA.Game/MapStub.cs
Normal file
93
OpenRA.Game/MapStub.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class MapStub
|
||||
{
|
||||
protected IFolder Container;
|
||||
public string Path {get; protected set;}
|
||||
|
||||
// Yaml map data
|
||||
public string Uid { get; protected set; }
|
||||
[FieldLoader.Load] public int MapFormat;
|
||||
[FieldLoader.Load] public bool Selectable;
|
||||
[FieldLoader.Load] public bool UseAsShellmap;
|
||||
[FieldLoader.Load] public string RequiresMod;
|
||||
|
||||
[FieldLoader.Load] public string Title;
|
||||
[FieldLoader.Load] public string Type = "Conquest";
|
||||
[FieldLoader.Load] public string Description;
|
||||
[FieldLoader.Load] public string Author;
|
||||
[FieldLoader.Load] public string Tileset;
|
||||
|
||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||
|
||||
public int PlayerCount { get { return SpawnPoints.Count(); } }
|
||||
public IEnumerable<int2> SpawnPoints { get { return Actors.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get<LocationInit>().value); } }
|
||||
|
||||
[FieldLoader.Load] public Rectangle Bounds;
|
||||
|
||||
public MapStub() {} // Hack for the editor - not used for anything important
|
||||
|
||||
public MapStub(string path)
|
||||
{
|
||||
Path = path;
|
||||
Container = FileSystem.OpenPackage(path, int.MaxValue);
|
||||
var yaml = new MiniYaml( null, MiniYaml.FromStream(Container.GetContent("map.yaml")) );
|
||||
FieldLoader.Load(this, yaml);
|
||||
Uid = ComputeHash();
|
||||
|
||||
// Load actors
|
||||
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
|
||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||
|
||||
// Upgrade map to format 5
|
||||
if (MapFormat < 5)
|
||||
{
|
||||
// Define RequiresMod for map installer
|
||||
RequiresMod = Game.CurrentMods.Keys.First();
|
||||
|
||||
// Add waypoint actors
|
||||
foreach( var wp in yaml.NodesDict[ "Waypoints" ].NodesDict )
|
||||
{
|
||||
string[] loc = wp.Value.Value.Split( ',' );
|
||||
var a = new ActorReference("mpspawn");
|
||||
a.Add(new LocationInit(new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) )));
|
||||
Actors.Add(wp.Key, a);
|
||||
}
|
||||
|
||||
var TopLeft = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["TopLeft"].Value);
|
||||
var BottomRight = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["BottomRight"].Value);
|
||||
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
||||
}
|
||||
}
|
||||
|
||||
string ComputeHash()
|
||||
{
|
||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||
// Read the relevant data into a buffer
|
||||
var data = Container.GetContent("map.yaml").ReadAllBytes()
|
||||
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
|
||||
|
||||
// Take the SHA1
|
||||
using (var csp = SHA1.Create())
|
||||
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -183,6 +183,8 @@
|
||||
<Compile Include="Network\Handshake.cs" />
|
||||
<Compile Include="Widgets\ProgressBarWidget.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="Traits\Waypoint.cs" />
|
||||
<Compile Include="MapStub.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
36
OpenRA.Game/Traits/Waypoint.cs
Normal file
36
OpenRA.Game/Traits/Waypoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class WaypointInfo : ITraitInfo
|
||||
{
|
||||
public object Create( ActorInitializer init ) { return new Waypoint( init ); }
|
||||
}
|
||||
|
||||
class Waypoint : IOccupySpace, ISync
|
||||
{
|
||||
[Sync]
|
||||
int2 location;
|
||||
|
||||
public Waypoint(ActorInitializer init)
|
||||
{
|
||||
this.location = init.Get<LocationInit,int2>();
|
||||
}
|
||||
|
||||
public int2 TopLeft { get { return location; } }
|
||||
|
||||
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield break; }
|
||||
public int2 PxPosition { get { return Util.CenterOfCell( location ); } }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user