diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index fc4d6ad08b..22ae147fe4 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -250,6 +250,7 @@ namespace OpenRA public static event Action ConnectionStateChanged = () => { }; static ConnectionState lastConnectionState = ConnectionState.PreConnecting; + public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } } static void Tick() { diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 833aa255fb..0ac3703669 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -161,7 +161,8 @@ namespace OpenRA.Traits public interface INotifySelection { void SelectionChanged(); } public interface ILoadWorldHook { void WorldLoaded(World w); } public interface IGameStarted { void GameStarted(World w); } - + public interface ICreatePlayers { void CreatePlayers(World w); } + public interface IActivity { IActivity NextActivity { get; set; } diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index e71608f885..899f45411f 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -93,43 +93,18 @@ namespace OpenRA WorldActor = CreateActor( "World", new TypeDictionary() ); - // Add Map Players - int mapPlayerIndex = -1; - Dictionary MapPlayers = new Dictionary(); + // Add players + foreach (var cmp in WorldActor.TraitsImplementing()) + cmp.CreatePlayers(this); - foreach (var kv in Map.Players) - { - var player = new Player(this, kv.Value, mapPlayerIndex--); - AddPlayer(player); - MapPlayers.Add(kv.Key,player); - if (kv.Value.OwnsWorld) - WorldActor.Owner = player; - } - foreach(var p in MapPlayers) - { - foreach(var q in Map.Players[p.Key].Allies) - p.Value.Stances[MapPlayers[q]] = Stance.Ally; - - foreach(var q in Map.Players[p.Key].Enemies) - p.Value.Stances[MapPlayers[q]] = Stance.Enemy; - } - - - // Add real players - SetLocalPlayer(Game.orderManager.Connection.LocalClientId); - - foreach (var c in Game.LobbyInfo.Clients) - AddPlayer(new Player(this, c)); - + // Set defaults for any unset stances foreach (var p in players.Values) foreach (var q in players.Values) - { if (!p.Stances.ContainsKey(q)) - p.Stances[q] = Game.ChooseInitialStance(p, q); - } + p.Stances[q] = Stance.Neutral; + + Timer.Time( "worldActor, players: {0}" ); - Timer.Time( "worldActor: {0}" ); - foreach (var wlh in WorldActor.TraitsImplementing()) wlh.WorldLoaded(this); diff --git a/OpenRA.Mods.RA/CreateMPPlayers.cs b/OpenRA.Mods.RA/CreateMPPlayers.cs new file mode 100644 index 0000000000..bc2d6754a7 --- /dev/null +++ b/OpenRA.Mods.RA/CreateMPPlayers.cs @@ -0,0 +1,39 @@ +#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 System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class CreateMPPlayersInfo : TraitInfo { } + + public class CreateMPPlayers : ICreatePlayers + { + public Dictionary Players = new Dictionary(); + + public void CreatePlayers(World w) + { + // Add real players + w.SetLocalPlayer(Game.LocalClientId); + + foreach (var c in Game.LobbyInfo.Clients) + w.AddPlayer(new Player(w, c)); + + foreach (var p in w.players.Values) + foreach (var q in w.players.Values) + { + if (!p.Stances.ContainsKey(q)) + p.Stances[q] = Game.ChooseInitialStance(p, q); + } + } + } +} diff --git a/OpenRA.Mods.RA/CreateMapPlayers.cs b/OpenRA.Mods.RA/CreateMapPlayers.cs new file mode 100644 index 0000000000..9e07f36eae --- /dev/null +++ b/OpenRA.Mods.RA/CreateMapPlayers.cs @@ -0,0 +1,46 @@ +#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 System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class CreateMapPlayersInfo : TraitInfo { } + + public class CreateMapPlayers : ICreatePlayers + { + public Dictionary Players = new Dictionary(); + + public void CreatePlayers(World w) + { + int mapPlayerIndex = -1; + + foreach (var kv in w.Map.Players) + { + var player = new Player(w, kv.Value, mapPlayerIndex--); + w.AddPlayer(player); + Players.Add(kv.Key,player); + if (kv.Value.OwnsWorld) + w.WorldActor.Owner = player; + } + + foreach(var p in Players) + { + foreach(var q in w.Map.Players[p.Key].Allies) + p.Value.Stances[Players[q]] = Stance.Ally; + + foreach(var q in w.Map.Players[p.Key].Enemies) + p.Value.Stances[Players[q]] = Stance.Enemy; + } + } + } +} diff --git a/OpenRA.Mods.RA/DefaultShellmapScript.cs b/OpenRA.Mods.RA/DefaultShellmapScript.cs index a4fe5358f3..e2cb4ee891 100644 --- a/OpenRA.Mods.RA/DefaultShellmapScript.cs +++ b/OpenRA.Mods.RA/DefaultShellmapScript.cs @@ -18,12 +18,12 @@ namespace OpenRA.Mods.RA class DefaultShellmapScript: ILoadWorldHook, ITick { - Dictionary MapActors; + Dictionary Actors; public void WorldLoaded(World w) { Game.MoveViewport((.5f * (w.Map.TopLeft + w.Map.BottomRight).ToFloat2()).ToInt2()); - MapActors = w.WorldActor.Trait().MapActors; + Actors = w.WorldActor.Trait().Actors; } int ticks = 0; @@ -31,15 +31,15 @@ namespace OpenRA.Mods.RA { if (ticks == 250) { - MapActors["pdox"].Trait().Teleport(MapActors["ca1"], new int2(90, 70)); - MapActors["pdox"].Trait().Teleport(MapActors["ca2"], new int2(92, 71)); + Actors["pdox"].Trait().Teleport(Actors["ca1"], new int2(90, 70)); + Actors["pdox"].Trait().Teleport(Actors["ca2"], new int2(92, 71)); } if (ticks == 100) - MapActors["mslo1"].Trait().Attack(new int2(96,53)); + Actors["mslo1"].Trait().Attack(new int2(96,53)); if (ticks == 110) - MapActors["mslo2"].Trait().Attack(new int2(92,53)); + Actors["mslo2"].Trait().Attack(new int2(92,53)); if (ticks == 120) - MapActors["mslo3"].Trait().Attack(new int2(94,50)); + Actors["mslo3"].Trait().Attack(new int2(94,50)); ticks++; } diff --git a/OpenRA.Mods.RA/LocalPlayerFromMap.cs b/OpenRA.Mods.RA/LocalPlayerFromMap.cs new file mode 100644 index 0000000000..2a842b071e --- /dev/null +++ b/OpenRA.Mods.RA/LocalPlayerFromMap.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 System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class LocalPlayerFromMapInfo : TraitInfo, ITraitPrerequisite + { + public readonly string Player = "GoodGuy"; + } + + class LocalPlayerFromMap: ICreatePlayers + { + public void CreatePlayers(World w) + { + var name = w.WorldActor.Info.Traits.Get().Player; + var player = w.WorldActor.Trait().Players[name]; + + // Hack: the player *must* be keyed by LocalClientId for orders to be processed correctly + var local = w.players.FirstOrDefault(p => p.Value == player); + w.players.Remove(local.Key); + w.players.Add(Game.LocalClientId,local.Value); + w.SetLocalPlayer(Game.LocalClientId); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 6540c965b9..c6ffac11f1 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -185,7 +185,6 @@ - @@ -235,6 +234,10 @@ + + + + diff --git a/OpenRA.Mods.RA/SpawnDefaultUnits.cs b/OpenRA.Mods.RA/SpawnMPUnits.cs similarity index 88% rename from OpenRA.Mods.RA/SpawnDefaultUnits.cs rename to OpenRA.Mods.RA/SpawnMPUnits.cs index 5a67abf55f..d15e1fdd76 100644 --- a/OpenRA.Mods.RA/SpawnDefaultUnits.cs +++ b/OpenRA.Mods.RA/SpawnMPUnits.cs @@ -16,12 +16,12 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class SpawnDefaultUnitsInfo : TraitInfo + class SpawnMPUnitsInfo : TraitInfo { public readonly int InitialExploreRange = 5; } - class SpawnDefaultUnits : IGameStarted + class SpawnMPUnits : IGameStarted { public void GameStarted(World world) { @@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA if (p == p.World.LocalPlayer || p.Stances[p.World.LocalPlayer] == Stance.Ally) p.World.WorldActor.Trait().Explore(p.World, sp, - p.World.WorldActor.Info.Traits.Get().InitialExploreRange); + p.World.WorldActor.Info.Traits.Get().InitialExploreRange); } static int2 ChooseSpawnPoint(World world, List available, List taken) diff --git a/OpenRA.Mods.RA/SpawnMapActors.cs b/OpenRA.Mods.RA/SpawnMapActors.cs index 7b1dc1c52e..8311ceb4af 100644 --- a/OpenRA.Mods.RA/SpawnMapActors.cs +++ b/OpenRA.Mods.RA/SpawnMapActors.cs @@ -18,14 +18,14 @@ namespace OpenRA.Mods.RA public class SpawnMapActors : IGameStarted { - public Dictionary MapActors = new Dictionary(); + public Dictionary Actors = new Dictionary(); public void GameStarted(World world) { Game.skipMakeAnims = true; // rude hack foreach (var actorReference in world.Map.Actors) - MapActors[actorReference.Key] = world.CreateActor(actorReference.Value.Type, actorReference.Value.InitDict); + Actors[actorReference.Key] = world.CreateActor(actorReference.Value.Type, actorReference.Value.InitDict); Game.skipMakeAnims = false; } diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 0b42dffe2e..aee6a6a8c7 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -115,8 +115,10 @@ World: Type:Crater Types:cr1,cr2,cr3,cr4,cr5,cr6 Depths:5,5,5,5,5,5 + CreateMapPlayers: SpawnMapActors: - SpawnDefaultUnits: + CreateMPPlayers: + SpawnMPUnits: EvaAlerts: RadarUp: comcntr1.aud RadarDown: powrdn1.aud diff --git a/mods/ra/maps/shellmap/map.yaml b/mods/ra/maps/shellmap/map.yaml index d8171f8f9b..e81610c053 100644 --- a/mods/ra/maps/shellmap/map.yaml +++ b/mods/ra/maps/shellmap/map.yaml @@ -1235,4 +1235,5 @@ Smudges: Rules: World: DefaultShellmapScript: - + -CreateMPPlayers: + -SpawnMPUnits: diff --git a/mods/ra/system.yaml b/mods/ra/system.yaml index 059853f5c4..e75bb45f87 100644 --- a/mods/ra/system.yaml +++ b/mods/ra/system.yaml @@ -171,8 +171,10 @@ World: Type:Crater Types:cr1,cr2,cr3,cr4,cr5,cr6 Depths:5,5,5,5,5,5 + CreateMapPlayers: SpawnMapActors: - SpawnDefaultUnits: + CreateMPPlayers: + SpawnMPUnits: EvaAlerts: SpatialBins: BinSize: 4