diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 3862ea1f5a..743468a466 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -47,7 +47,7 @@ namespace OpenRa { if (orderGenerator == null) return; - var orders = orderGenerator.Order(xy.ToInt2(), mi).ToArray(); + var orders = orderGenerator.Order(Game.world, xy.ToInt2(), mi).ToArray(); recentOrders.AddRange( orders ); var voicedActor = orders.Select(o => o.Subject) @@ -157,7 +157,7 @@ namespace OpenRa Modifiers = GetModifierKeys(), }; - return orderGenerator.GetCursor( MousePosition.ToInt2(), mi ); + return orderGenerator.GetCursor( Game.world, MousePosition.ToInt2(), mi ); } finally { diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 2f3e5c075f..464bb457c1 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -131,7 +131,7 @@ namespace OpenRa { orderManager.Tick(); if (controller.orderGenerator != null) - controller.orderGenerator.Tick(); + controller.orderGenerator.Tick( world ); world.Tick(); } diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index 28a394c9ab..c6c1d9faad 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -84,7 +84,7 @@ namespace OpenRa.Graphics DrawBandBox(); if (Game.controller.orderGenerator != null) - Game.controller.orderGenerator.Render(); + Game.controller.orderGenerator.Render( world ); world.LocalPlayer.Shroud.Draw(spriteRenderer); diff --git a/OpenRa.Game/Orders/ChronoshiftDestinationOrderGenerator.cs b/OpenRa.Game/Orders/ChronoshiftDestinationOrderGenerator.cs index 95f6c95cb5..7ce28e2851 100644 --- a/OpenRa.Game/Orders/ChronoshiftDestinationOrderGenerator.cs +++ b/OpenRa.Game/Orders/ChronoshiftDestinationOrderGenerator.cs @@ -18,7 +18,7 @@ namespace OpenRa.Orders this.power = power; } - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -29,15 +29,15 @@ namespace OpenRa.Orders power != null ? power.Name : null); } - public void Tick() {} - public void Render() + public void Tick( World world ) {} + public void Render( World world ) { - Game.world.WorldRenderer.DrawSelectionBox(self, Color.White, true); + world.WorldRenderer.DrawSelectionBox(self, Color.White, true); } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { - if (!Game.world.LocalPlayer.Shroud.IsExplored(xy)) + if (!world.LocalPlayer.Shroud.IsExplored(xy)) return Cursor.MoveBlocked; var movement = self.traits.GetOrDefault(); diff --git a/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs b/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs index 7e9d39b5ae..011c47f345 100644 --- a/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs +++ b/OpenRa.Game/Orders/ChronosphereSelectOrderGenerator.cs @@ -15,21 +15,21 @@ namespace OpenRa.Orders this.power = power; } - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return OrderInner(xy, mi); + return OrderInner(world, xy, mi); } - IEnumerable OrderInner(int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var loc = mi.Location + Game.viewport.Location; - var underCursor = Game.world.FindUnits(loc, loc) - .Where(a => a.Owner == Game.world.LocalPlayer + var underCursor = world.FindUnits(loc, loc) + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains() && a.traits.Contains()).FirstOrDefault(); @@ -38,21 +38,21 @@ namespace OpenRa.Orders } } - public void Tick() + public void Tick( World world ) { - var hasChronosphere = Game.world.Actors - .Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains()); + var hasChronosphere = world.Actors + .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains()); if (!hasChronosphere) Game.controller.CancelInputMode(); } - public void Render() { } + public void Render( World world ) { } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { mi.Button = MouseButton.Left; - return OrderInner(xy, mi).Any() + return OrderInner(world, xy, mi).Any() ? Cursor.ChronoshiftSelect : Cursor.MoveBlocked; } } diff --git a/OpenRa.Game/Orders/IOrderGenerator.cs b/OpenRa.Game/Orders/IOrderGenerator.cs index 17c1cb39bd..6d6bf57294 100644 --- a/OpenRa.Game/Orders/IOrderGenerator.cs +++ b/OpenRa.Game/Orders/IOrderGenerator.cs @@ -4,9 +4,9 @@ namespace OpenRa { public interface IOrderGenerator { - IEnumerable Order( int2 xy, MouseInput mi ); - void Tick(); - void Render(); - Cursor GetCursor(int2 xy, MouseInput mi); + IEnumerable Order( World world, int2 xy, MouseInput mi ); + void Tick( World world ); + void Render( World world ); + Cursor GetCursor( World world, int2 xy, MouseInput mi ); } } diff --git a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs index 6c5e747b8e..d8bbbd77e5 100644 --- a/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs +++ b/OpenRa.Game/Orders/IronCurtainOrderGenerator.cs @@ -15,21 +15,21 @@ namespace OpenRa.Orders this.power = power; } - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return OrderInner(xy, mi); + return OrderInner(world, xy, mi); } - IEnumerable OrderInner(int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var loc = mi.Location + Game.viewport.Location; - var underCursor = Game.world.FindUnits(loc, loc) - .Where(a => a.Owner == Game.world.LocalPlayer + var underCursor = world.FindUnits(loc, loc) + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains() && a.traits.Contains()).FirstOrDefault(); @@ -38,21 +38,21 @@ namespace OpenRa.Orders } } - public void Tick() + public void Tick( World world ) { - var hasStructure = Game.world.Actors - .Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains()); + var hasStructure = world.Actors + .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains()); if (!hasStructure) Game.controller.CancelInputMode(); } - public void Render() { } + public void Render( World world ) { } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { mi.Button = MouseButton.Left; - return OrderInner(xy, mi).Any() + return OrderInner(world, xy, mi).Any() ? Cursor.Ability : Cursor.MoveBlocked; } } diff --git a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs index 9996b680f6..12a565fb88 100644 --- a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs @@ -16,21 +16,21 @@ namespace OpenRa.Orders Building = name; } - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return InnerOrder(xy, mi); + return InnerOrder(world, xy, mi); } - IEnumerable InnerOrder(int2 xy, MouseInput mi) + IEnumerable InnerOrder(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo ); - if (!Game.world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null) - || !Game.world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft)) + if (!world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null) + || !world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft)) { Sound.Play("nodeply1.aud"); yield break; @@ -40,19 +40,19 @@ namespace OpenRa.Orders } } - public void Tick() + public void Tick( World world ) { var producing = Producer.traits.Get().CurrentItem( Rules.Info[ Building ].Category ); if (producing == null || producing.Item != Building || producing.RemainingTime != 0) Game.controller.CancelInputMode(); } - public void Render() + public void Render( World world ) { - Game.world.WorldRenderer.uiOverlay.DrawBuildingGrid( Building, BuildingInfo ); + world.WorldRenderer.uiOverlay.DrawBuildingGrid( Building, BuildingInfo ); } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { return Cursor.Default; } diff --git a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs index 9ed1da8b51..3ecb702812 100644 --- a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs +++ b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs @@ -9,21 +9,21 @@ namespace OpenRa.Orders { class PowerDownOrderGenerator : IOrderGenerator { - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return OrderInner(xy, mi); + return OrderInner(world, xy, mi); } - IEnumerable OrderInner(int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var loc = mi.Location + Game.viewport.Location; - var underCursor = Game.world.FindUnits(loc, loc) - .Where(a => a.Owner == Game.world.LocalPlayer + var underCursor = world.FindUnits(loc, loc) + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains() && a.traits.Contains()).FirstOrDefault(); @@ -32,13 +32,13 @@ namespace OpenRa.Orders } } - public void Tick() { } - public void Render() { } + public void Tick( World world ) { } + public void Render( World world ) { } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { mi.Button = MouseButton.Left; - return OrderInner(xy, mi).Any() + return OrderInner(world, xy, mi).Any() ? Cursor.PowerDown : Cursor.PowerDown; } } diff --git a/OpenRa.Game/Orders/RepairOrderGenerator.cs b/OpenRa.Game/Orders/RepairOrderGenerator.cs index a46eb568ff..b4e8cf1bb1 100644 --- a/OpenRa.Game/Orders/RepairOrderGenerator.cs +++ b/OpenRa.Game/Orders/RepairOrderGenerator.cs @@ -9,21 +9,21 @@ namespace OpenRa.Orders { class RepairOrderGenerator : IOrderGenerator { - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return OrderInner(xy, mi); + return OrderInner(world, xy, mi); } - IEnumerable OrderInner(int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var loc = mi.Location + Game.viewport.Location; - var underCursor = Game.world.FindUnits(loc, loc) - .Where(a => a.Owner == Game.world.LocalPlayer + var underCursor = world.FindUnits(loc, loc) + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains() && a.traits.Contains()).FirstOrDefault(); @@ -34,24 +34,24 @@ namespace OpenRa.Orders } } - public void Tick() + public void Tick( World world ) { if (!Game.Settings.RepairRequiresConyard) return; - var hasFact = Game.world.Actors - .Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains()); + var hasFact = world.Actors + .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains()); if (!hasFact) Game.controller.CancelInputMode(); } - public void Render() {} + public void Render( World world ) {} - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { mi.Button = MouseButton.Left; - return OrderInner(xy, mi).Any() + return OrderInner(world, xy, mi).Any() ? Cursor.Repair : Cursor.RepairBlocked; } } diff --git a/OpenRa.Game/Orders/SellOrderGenerator.cs b/OpenRa.Game/Orders/SellOrderGenerator.cs index 05aef8547d..7c34244dfb 100644 --- a/OpenRa.Game/Orders/SellOrderGenerator.cs +++ b/OpenRa.Game/Orders/SellOrderGenerator.cs @@ -9,21 +9,21 @@ namespace OpenRa.Orders { class SellOrderGenerator : IOrderGenerator { - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Right) Game.controller.CancelInputMode(); - return OrderInner(xy, mi); + return OrderInner(world, xy, mi); } - IEnumerable OrderInner(int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { var loc = mi.Location + Game.viewport.Location; - var underCursor = Game.world.FindUnits(loc, loc) - .Where(a => a.Owner == Game.world.LocalPlayer + var underCursor = world.FindUnits(loc, loc) + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains() && a.traits.Contains()).FirstOrDefault(); @@ -34,13 +34,13 @@ namespace OpenRa.Orders } } - public void Tick() {} - public void Render() {} + public void Tick( World world ) {} + public void Render( World world ) {} - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { mi.Button = MouseButton.Left; - return OrderInner(xy, mi).Any() + return OrderInner(world, xy, mi).Any() ? Cursor.Sell : Cursor.SellBlocked; } } diff --git a/OpenRa.Game/Orders/UnitOrderGenerator.cs b/OpenRa.Game/Orders/UnitOrderGenerator.cs index 38c6b09009..945b8d1cfa 100644 --- a/OpenRa.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRa.Game/Orders/UnitOrderGenerator.cs @@ -15,7 +15,7 @@ namespace OpenRa.Orders selection = selected.ToList(); } - public IEnumerable Order( int2 xy, MouseInput mi ) + public IEnumerable Order( World world, int2 xy, MouseInput mi ) { foreach( var unit in selection ) { @@ -25,31 +25,31 @@ namespace OpenRa.Orders } } - public void Tick() + public void Tick( World world ) { selection.RemoveAll(a => !a.IsInWorld); } - public void Render() + public void Render( World world ) { foreach( var a in selection ) - Game.world.WorldRenderer.DrawSelectionBox( a, Color.White, true ); + world.WorldRenderer.DrawSelectionBox( a, Color.White, true ); } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor( World world, int2 xy, MouseInput mi ) { - return ChooseCursor(mi); + return ChooseCursor(world, mi); } - Cursor ChooseCursor( MouseInput mi ) + Cursor ChooseCursor( World world, MouseInput mi ) { var p = Game.controller.MousePosition; - var c = Order(p.ToInt2(), mi) + var c = Order(world, p.ToInt2(), mi) .Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)) .FirstOrDefault(a => a != null); return c ?? - (Game.world.SelectActorsInBox(Game.CellSize * p, + (world.SelectActorsInBox(Game.CellSize * p, Game.CellSize * p).Any() ? Cursor.Select : Cursor.Default); } @@ -69,7 +69,7 @@ namespace OpenRa.Orders return Cursor.MoveBlocked; case "DeployMcv": var factBuildingInfo = Rules.Info["fact"].Traits.Get(); - if (Game.world.CanPlaceBuilding("fact", factBuildingInfo, a.Location - new int2(1, 1), a)) + if (a.World.CanPlaceBuilding("fact", factBuildingInfo, a.Location - new int2(1, 1), a)) return Cursor.Deploy; else return Cursor.DeployBlocked; diff --git a/OpenRa.Mods.Aftermath/Orders/SetChronoTankDestination.cs b/OpenRa.Mods.Aftermath/Orders/SetChronoTankDestination.cs index efc999aef9..dd69faa23a 100644 --- a/OpenRa.Mods.Aftermath/Orders/SetChronoTankDestination.cs +++ b/OpenRa.Mods.Aftermath/Orders/SetChronoTankDestination.cs @@ -13,7 +13,7 @@ namespace OpenRa.Mods.Aftermath.Orders this.self = self; } - public IEnumerable Order(int2 xy, MouseInput mi) + public IEnumerable Order(World world, int2 xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -24,15 +24,15 @@ namespace OpenRa.Mods.Aftermath.Orders yield return new Order("ChronoshiftSelf", self, null, xy, null); } - public void Tick() { } - public void Render() + public void Tick( World world ) { } + public void Render( World world ) { - Game.world.WorldRenderer.DrawSelectionBox(self, Color.White, true); + world.WorldRenderer.DrawSelectionBox(self, Color.White, true); } - public Cursor GetCursor(int2 xy, MouseInput mi) + public Cursor GetCursor(World world, int2 xy, MouseInput mi) { - if (!Game.world.LocalPlayer.Shroud.IsExplored(xy)) + if (!world.LocalPlayer.Shroud.IsExplored(xy)) return Cursor.MoveBlocked; var movement = self.traits.GetOrDefault();