From b134ba41f491ebfc666a1fae49915aa7f33041f8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 11 Feb 2011 20:32:13 +1300 Subject: [PATCH] Convert Waypoints to actors --- OpenRA.Editor/ActorTemplate.cs | 4 -- OpenRA.Editor/Form1.Designer.cs | 9 ---- OpenRA.Editor/Form1.cs | 1 - OpenRA.Editor/LegacyMapImporter.cs | 13 +++-- OpenRA.Editor/OpenRA.Editor.csproj | 3 +- OpenRA.Editor/Surface.cs | 9 ---- OpenRA.Editor/WaypointTool.cs | 51 ------------------- OpenRA.FileFormats/OpenRA.FileFormats.csproj | 3 +- OpenRA.Game/Map.cs | 18 ++----- .../Map => OpenRA.Game}/MapStub.cs | 44 ++++++++-------- OpenRA.Game/OpenRA.Game.csproj | 4 +- OpenRA.Game/Traits/Waypoint.cs | 36 +++++++++++++ OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs | 15 +++--- OpenRA.Mods.Cnc/Missions/Gdi01Script.cs | 28 +++++----- .../Widgets/Delegates/LobbyDelegate.cs | 4 +- mods/cnc/rules/system.yaml | 6 +++ mods/ra/rules/system.yaml | 12 +++-- 17 files changed, 114 insertions(+), 146 deletions(-) delete mode 100644 OpenRA.Editor/WaypointTool.cs rename {OpenRA.FileFormats/Map => OpenRA.Game}/MapStub.cs (68%) create mode 100644 OpenRA.Game/Traits/Waypoint.cs diff --git a/OpenRA.Editor/ActorTemplate.cs b/OpenRA.Editor/ActorTemplate.cs index 98947f4785..5ad09e4d8c 100644 --- a/OpenRA.Editor/ActorTemplate.cs +++ b/OpenRA.Editor/ActorTemplate.cs @@ -33,8 +33,4 @@ namespace OpenRA.Editor public ResourceTypeInfo Info; public int Value; } - - class WaypointTemplate - { - } } diff --git a/OpenRA.Editor/Form1.Designer.cs b/OpenRA.Editor/Form1.Designer.cs index f9d9d64e8f..019b6f2e3f 100755 --- a/OpenRA.Editor/Form1.Designer.cs +++ b/OpenRA.Editor/Form1.Designer.cs @@ -416,15 +416,6 @@ this.toolStripSeparator4.Name = "toolStripSeparator4"; this.toolStripSeparator4.Size = new System.Drawing.Size(139, 6); // - // spawnpointsToolStripMenuItem - // - this.spawnpointsToolStripMenuItem.Enabled = false; - this.spawnpointsToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("spawnpointsToolStripMenuItem.Image"))); - this.spawnpointsToolStripMenuItem.Name = "spawnpointsToolStripMenuItem"; - this.spawnpointsToolStripMenuItem.Size = new System.Drawing.Size(142, 22); - this.spawnpointsToolStripMenuItem.Text = "&Spawnpoints"; - this.spawnpointsToolStripMenuItem.Click += new System.EventHandler(this.SpawnPointsClicked); - // // toolsToolStripMenuItem // this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index fb8b79833a..f2646b0c06 100755 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -347,7 +347,6 @@ namespace OpenRA.Editor } } - void SpawnPointsClicked(object sender, EventArgs e) { surface1.SetTool(new WaypointTool(new WaypointTemplate())); } void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = true; } void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = false; } diff --git a/OpenRA.Editor/LegacyMapImporter.cs b/OpenRA.Editor/LegacyMapImporter.cs index 989ef7f8d9..88e3433f6e 100644 --- a/OpenRA.Editor/LegacyMapImporter.cs +++ b/OpenRA.Editor/LegacyMapImporter.cs @@ -156,14 +156,19 @@ namespace OpenRA.Editor foreach (var p in Players) LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert)); - var wp = file.GetSection("Waypoints") + var wps = file.GetSection("Waypoints") .Where(kv => int.Parse(kv.Value) > 0) .Select(kv => Pair.New(int.Parse(kv.Key), LocationFromMapOffset(int.Parse(kv.Value), MapSize))) .ToArray(); - - foreach (var kv in wp) - Map.Waypoints.Add("spawn" + kv.First, kv.Second); + + // Add waypoint actors + foreach( var kv in wps ) + { + var a = new ActorReference("mpspawn"); + a.Add(new LocationInit(kv.Second)); + Map.Actors.Add("spawn" + kv.First, a); + } } static int2 LocationFromMapOffset(int offset, int mapSize) diff --git a/OpenRA.Editor/OpenRA.Editor.csproj b/OpenRA.Editor/OpenRA.Editor.csproj index b6344efc84..54b082ca74 100644 --- a/OpenRA.Editor/OpenRA.Editor.csproj +++ b/OpenRA.Editor/OpenRA.Editor.csproj @@ -1,4 +1,4 @@ - + Debug @@ -137,7 +137,6 @@ Component - diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 70521291a4..e9d6caf4c7 100755 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -166,9 +166,6 @@ namespace OpenRA.Editor } } - var k = Map.Waypoints.FirstOrDefault(a => a.Value == BrushLocation); - if (k.Key != null) Map.Waypoints.Remove(k.Key); - AfterChange(); } @@ -345,12 +342,6 @@ namespace OpenRA.Editor DrawActor(e.Graphics, ar.Value.Location(), ActorTemplates[ar.Value.Type], GetPaletteForActor(ar.Value)); - foreach (var wp in Map.Waypoints) - e.Graphics.DrawRectangle(Pens.LimeGreen, - TileSet.TileSize * wp.Value.X * Zoom + Offset.X + 4, - TileSet.TileSize * wp.Value.Y * Zoom + Offset.Y + 4, - (TileSet.TileSize - 8) * Zoom, (TileSet.TileSize - 8) * Zoom); - if (Tool != null) Tool.Preview(this, e.Graphics); diff --git a/OpenRA.Editor/WaypointTool.cs b/OpenRA.Editor/WaypointTool.cs deleted file mode 100644 index 97b948ddd3..0000000000 --- a/OpenRA.Editor/WaypointTool.cs +++ /dev/null @@ -1,51 +0,0 @@ -#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.Drawing; -using System.Linq; - -using SGraphics = System.Drawing.Graphics; - -namespace OpenRA.Editor -{ - class WaypointTool : ITool - { - WaypointTemplate Waypoint; - - public WaypointTool(WaypointTemplate waypoint) { Waypoint = waypoint; } - - public void Apply(Surface surface) - { - var k = surface.Map.Waypoints.FirstOrDefault(a => a.Value == surface.GetBrushLocation()); - if (k.Key != null) surface.Map.Waypoints.Remove(k.Key); - - surface.Map.Waypoints.Add(NextWpid(surface), surface.GetBrushLocation()); - } - - public void Preview(Surface surface, SGraphics g) - { - g.DrawRectangle(Pens.LimeGreen, - surface.TileSet.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X + 4, - surface.TileSet.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y + 4, - (surface.TileSet.TileSize - 8) * surface.Zoom, (surface.TileSet.TileSize - 8) * surface.Zoom); - } - - public string NextWpid(Surface surface) - { - int wpid = 0; - for (; ; ) - { - var a = "wp{0}".F(wpid++); - if (!surface.Map.Waypoints.ContainsKey(a)) - return a; - } - } - } -} diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index bc3969d97d..1c8bdeb88a 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -1,4 +1,4 @@ - + Debug @@ -102,7 +102,6 @@ - diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 62973a6f17..8249daed8f 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -24,7 +24,6 @@ namespace OpenRA { // Yaml map data public Dictionary Players = new Dictionary(); - public Dictionary Actors = new Dictionary(); public List Smudges = new List(); // 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( Waypoints ))); root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList( Smudges ))); root.Add(new MiniYamlNode("Rules", null, Rules)); root.Add(new MiniYamlNode("Sequences", null, Sequences)); diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.Game/MapStub.cs similarity index 68% rename from OpenRA.FileFormats/Map/MapStub.cs rename to OpenRA.Game/MapStub.cs index 50c0654ecb..a7ffa0a936 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.Game/MapStub.cs @@ -13,8 +13,10 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Security.Cryptography; +using OpenRA.FileFormats; +using OpenRA.Traits; -namespace OpenRA.FileFormats +namespace OpenRA { public class MapStub { @@ -34,11 +36,10 @@ namespace OpenRA.FileFormats [FieldLoader.Load] public string Author; [FieldLoader.Load] public string Tileset; - [FieldLoader.Load] public string[] StartPoints; - public int PlayerCount { get { return StartPoints.Count(); } } - [FieldLoader.LoadUsing( "LoadWaypoints" )] - public Dictionary Waypoints = new Dictionary(); - public IEnumerable SpawnPoints{ get { return Waypoints.Where(kv => StartPoints.Contains(kv.Key)).Select(kv => kv.Value); } } + public Dictionary Actors = new Dictionary(); + + public int PlayerCount { get { return SpawnPoints.Count(); } } + public IEnumerable SpawnPoints { get { return Actors.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get().value); } } [FieldLoader.Load] public Rectangle Bounds; @@ -50,14 +51,27 @@ namespace OpenRA.FileFormats Container = FileSystem.OpenPackage(path, int.MaxValue); var yaml = new MiniYaml( null, MiniYaml.FromStream(Container.GetContent("map.yaml")) ); FieldLoader.Load(this, yaml); - Uid = ComputeHash(); - // Upgrade maps to define StartPoints + // 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(); - StartPoints = Waypoints.Select(kv => kv.Key).ToArray(); + // 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); @@ -75,17 +89,5 @@ namespace OpenRA.FileFormats using (var csp = SHA1.Create()) return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray()); } - - static object LoadWaypoints( MiniYaml y ) - { - var ret = new Dictionary(); - foreach( var wp in y.NodesDict[ "Waypoints" ].NodesDict ) - { - string[] loc = wp.Value.Value.Split( ',' ); - ret.Add( wp.Key, new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) ); - } - - return ret; - } } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 9584b7c035..db770c5472 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -183,6 +183,8 @@ + + diff --git a/OpenRA.Game/Traits/Waypoint.cs b/OpenRA.Game/Traits/Waypoint.cs new file mode 100644 index 0000000000..0c80f0d8e7 --- /dev/null +++ b/OpenRA.Game/Traits/Waypoint.cs @@ -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(); + } + + public int2 TopLeft { get { return location; } } + + public IEnumerable> OccupiedCells() { yield break; } + public int2 PxPosition { get { return Util.CenterOfCell( location ); } } + } +} diff --git a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs index 16d99dcee2..5f262af212 100755 --- a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs +++ b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs @@ -48,17 +48,16 @@ namespace OpenRA.Mods.RA if (ticks == 0) { - var w = Map.Waypoints; - LoopTrack(Actors["boat1"], w["tl1"], w["tr1"]); - LoopTrack(Actors["boat3"], w["tl1"], w["tr1"]); - LoopTrack(Actors["boat2"], w["tl3"], w["tr3"]); - LoopTrack(Actors["boat4"], w["tl3"], w["tr3"]); + LoopTrack(Actors["boat1"], Actors["tl1"].Location, Actors["tr1"].Location); + LoopTrack(Actors["boat3"], Actors["tl1"].Location, Actors["tr1"].Location); + LoopTrack(Actors["boat2"], Actors["tl3"].Location, Actors["tr3"].Location); + LoopTrack(Actors["boat4"], Actors["tl3"].Location, Actors["tr3"].Location); CreateUnitsInTransport(Actors["lst1"], new string[] {"htnk"}); CreateUnitsInTransport(Actors["lst2"], new string[] {"mcv"}); CreateUnitsInTransport(Actors["lst3"], new string[] {"htnk"}); - LoopTrack(Actors["lst1"], w["tl2"], w["tr2"]); - LoopTrack(Actors["lst2"], w["tl2"], w["tr2"]); - LoopTrack(Actors["lst3"], w["tl2"], w["tr2"]); + LoopTrack(Actors["lst1"], Actors["tl2"].Location, Actors["tr2"].Location); + LoopTrack(Actors["lst2"], Actors["tl2"].Location, Actors["tr2"].Location); + LoopTrack(Actors["lst3"], Actors["tl2"].Location, Actors["tr2"].Location); } ticks++; diff --git a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs index 26cc32ad86..e2b785d0db 100644 --- a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs +++ b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs @@ -97,12 +97,12 @@ namespace OpenRA.Mods.Cnc { new OwnerInit( Players["BadGuy"] ), new FacingInit( 0 ), - new LocationInit ( Map.Waypoints["nod0"] ), + new LocationInit ( Actors["nod0"].Location ), }); var mobile = a.Trait(); - a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod1"], 2 ) ); - a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod2"], 2 ) ); - a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod3"], 2 ) ); + a.QueueActivity( mobile.MoveTo( Actors["nod1"].Location, 2 ) ); + a.QueueActivity( mobile.MoveTo( Actors["nod2"].Location, 2 ) ); + a.QueueActivity( mobile.MoveTo( Actors["nod3"].Location, 2 ) ); // Todo: Queue hunt order } }); @@ -127,8 +127,8 @@ namespace OpenRA.Mods.Cnc if (ticks == 25*5) { ReinforceFromSea(self.World, - Map.Waypoints["lstStart"], - Map.Waypoints["lstEnd"], + Actors["lstStart"].Location, + Actors["lstEnd"].Location, new int2(53,53), new string[] {"e1","e1","e1"}); } @@ -136,8 +136,8 @@ namespace OpenRA.Mods.Cnc if (ticks == 25*15) { ReinforceFromSea(self.World, - Map.Waypoints["lstStart"], - Map.Waypoints["lstEnd"], + Actors["lstStart"].Location, + Actors["lstEnd"].Location, new int2(53,53), new string[] {"e1","e1","e1"}); } @@ -145,8 +145,8 @@ namespace OpenRA.Mods.Cnc if (ticks == 25*30) { ReinforceFromSea(self.World, - Map.Waypoints["lstStart"], - Map.Waypoints["lstEnd"], + Actors["lstStart"].Location, + Actors["lstEnd"].Location, new int2(53,53), new string[] {"jeep"}); } @@ -154,8 +154,8 @@ namespace OpenRA.Mods.Cnc if (ticks == 25*60) { ReinforceFromSea(self.World, - Map.Waypoints["lstStart"], - Map.Waypoints["lstEnd"], + Actors["lstStart"].Location, + Actors["lstEnd"].Location, new int2(53,53), new string[] {"jeep"}); } @@ -167,8 +167,8 @@ namespace OpenRA.Mods.Cnc { var self = Actors[ "Gunboat" ]; var mobile = self.Trait(); - self.QueueActivity(mobile.ScriptedMove( Map.Waypoints["gunboatLeft"] )); - self.QueueActivity(mobile.ScriptedMove( Map.Waypoints["gunboatRight"] )); + self.QueueActivity(mobile.ScriptedMove( Actors["gunboatLeft"].Location )); + self.QueueActivity(mobile.ScriptedMove( Actors["gunboatRight"].Location )); self.QueueActivity(new CallFunc(() => SetGunboatPath())); } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index df8176ca78..45116bd2ed 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -58,8 +58,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates || orderManager.LocalClient.State == Session.ClientState.Ready) return false; - var p = map.Waypoints - .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp.Value), i)) + var p = map.SpawnPoints + .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i)) .Where(a => (a.First - mi.Location).LengthSquared < 64) .Select(a => a.Second + 1) .FirstOrDefault(); diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index c8c4cf19d7..bc207e43a5 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -193,3 +193,9 @@ CRATE: BelowUnits: ProximityCaptor: Types:Crate + +mpspawn: + Waypoint: + +waypoint: + Waypoint: \ No newline at end of file diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 3a9d0ca1e8..24ae511abe 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -306,8 +306,8 @@ FLARE: HiddenUnderFog: Tooltip: Name: Flare - ProximityCaptor: - Types: Flare + ProximityCaptor: + Types: Flare powerproxy.parabombs: AirstrikePower: @@ -328,4 +328,10 @@ powerproxy.sonarpulse: AllowMultiple: yes OneShot: yes EndChargeSound: pulse1.aud - SelectTargetSound: slcttgt1.aud + SelectTargetSound: slcttgt1.aud + +mpspawn: + Waypoint: + +waypoint: + Waypoint: \ No newline at end of file