Ditto for OrderGenerators.

This commit is contained in:
Bob
2010-01-21 13:37:45 +13:00
parent 4fa56f16c0
commit 6ac384669b
13 changed files with 90 additions and 90 deletions

View File

@@ -47,7 +47,7 @@ namespace OpenRa
{ {
if (orderGenerator == null) return; 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 ); recentOrders.AddRange( orders );
var voicedActor = orders.Select(o => o.Subject) var voicedActor = orders.Select(o => o.Subject)
@@ -157,7 +157,7 @@ namespace OpenRa
Modifiers = GetModifierKeys(), Modifiers = GetModifierKeys(),
}; };
return orderGenerator.GetCursor( MousePosition.ToInt2(), mi ); return orderGenerator.GetCursor( Game.world, MousePosition.ToInt2(), mi );
} }
finally finally
{ {

View File

@@ -131,7 +131,7 @@ namespace OpenRa
{ {
orderManager.Tick(); orderManager.Tick();
if (controller.orderGenerator != null) if (controller.orderGenerator != null)
controller.orderGenerator.Tick(); controller.orderGenerator.Tick( world );
world.Tick(); world.Tick();
} }

View File

@@ -84,7 +84,7 @@ namespace OpenRa.Graphics
DrawBandBox(); DrawBandBox();
if (Game.controller.orderGenerator != null) if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Render(); Game.controller.orderGenerator.Render( world );
world.LocalPlayer.Shroud.Draw(spriteRenderer); world.LocalPlayer.Shroud.Draw(spriteRenderer);

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Orders
this.power = power; this.power = power;
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
@@ -29,15 +29,15 @@ namespace OpenRa.Orders
power != null ? power.Name : null); power != null ? power.Name : null);
} }
public void Tick() {} public void Tick( World world ) {}
public void Render() 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; return Cursor.MoveBlocked;
var movement = self.traits.GetOrDefault<IMovement>(); var movement = self.traits.GetOrDefault<IMovement>();

View File

@@ -15,21 +15,21 @@ namespace OpenRa.Orders
this.power = power; this.power = power;
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return OrderInner(xy, mi); return OrderInner(world, xy, mi);
} }
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.world.FindUnits(loc, loc) var underCursor = world.FindUnits(loc, loc)
.Where(a => a.Owner == Game.world.LocalPlayer .Where(a => a.Owner == world.LocalPlayer
&& a.traits.Contains<Chronoshiftable>() && a.traits.Contains<Chronoshiftable>()
&& a.traits.Contains<Selectable>()).FirstOrDefault(); && a.traits.Contains<Selectable>()).FirstOrDefault();
@@ -38,21 +38,21 @@ namespace OpenRa.Orders
} }
} }
public void Tick() public void Tick( World world )
{ {
var hasChronosphere = Game.world.Actors var hasChronosphere = world.Actors
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<Chronosphere>()); .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<Chronosphere>());
if (!hasChronosphere) if (!hasChronosphere)
Game.controller.CancelInputMode(); 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; mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.ChronoshiftSelect : Cursor.MoveBlocked; ? Cursor.ChronoshiftSelect : Cursor.MoveBlocked;
} }
} }

View File

@@ -4,9 +4,9 @@ namespace OpenRa
{ {
public interface IOrderGenerator public interface IOrderGenerator
{ {
IEnumerable<Order> Order( int2 xy, MouseInput mi ); IEnumerable<Order> Order( World world, int2 xy, MouseInput mi );
void Tick(); void Tick( World world );
void Render(); void Render( World world );
Cursor GetCursor(int2 xy, MouseInput mi); Cursor GetCursor( World world, int2 xy, MouseInput mi );
} }
} }

View File

@@ -15,21 +15,21 @@ namespace OpenRa.Orders
this.power = power; this.power = power;
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return OrderInner(xy, mi); return OrderInner(world, xy, mi);
} }
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.world.FindUnits(loc, loc) var underCursor = world.FindUnits(loc, loc)
.Where(a => a.Owner == Game.world.LocalPlayer .Where(a => a.Owner == world.LocalPlayer
&& a.traits.Contains<IronCurtainable>() && a.traits.Contains<IronCurtainable>()
&& a.traits.Contains<Selectable>()).FirstOrDefault(); && a.traits.Contains<Selectable>()).FirstOrDefault();
@@ -38,21 +38,21 @@ namespace OpenRa.Orders
} }
} }
public void Tick() public void Tick( World world )
{ {
var hasStructure = Game.world.Actors var hasStructure = world.Actors
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<IronCurtain>()); .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<IronCurtain>());
if (!hasStructure) if (!hasStructure)
Game.controller.CancelInputMode(); 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; mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Ability : Cursor.MoveBlocked; ? Cursor.Ability : Cursor.MoveBlocked;
} }
} }

View File

@@ -16,21 +16,21 @@ namespace OpenRa.Orders
Building = name; Building = name;
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return InnerOrder(xy, mi); return InnerOrder(world, xy, mi);
} }
IEnumerable<Order> InnerOrder(int2 xy, MouseInput mi) IEnumerable<Order> InnerOrder(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo ); var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo );
if (!Game.world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null) if (!world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null)
|| !Game.world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft)) || !world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft))
{ {
Sound.Play("nodeply1.aud"); Sound.Play("nodeply1.aud");
yield break; yield break;
@@ -40,19 +40,19 @@ namespace OpenRa.Orders
} }
} }
public void Tick() public void Tick( World world )
{ {
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category ); var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category );
if (producing == null || producing.Item != Building || producing.RemainingTime != 0) if (producing == null || producing.Item != Building || producing.RemainingTime != 0)
Game.controller.CancelInputMode(); 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; return Cursor.Default;
} }

View File

@@ -9,21 +9,21 @@ namespace OpenRa.Orders
{ {
class PowerDownOrderGenerator : IOrderGenerator class PowerDownOrderGenerator : IOrderGenerator
{ {
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return OrderInner(xy, mi); return OrderInner(world, xy, mi);
} }
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.world.FindUnits(loc, loc) var underCursor = world.FindUnits(loc, loc)
.Where(a => a.Owner == Game.world.LocalPlayer .Where(a => a.Owner == world.LocalPlayer
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.traits.Contains<Selectable>()).FirstOrDefault(); && a.traits.Contains<Selectable>()).FirstOrDefault();
@@ -32,13 +32,13 @@ namespace OpenRa.Orders
} }
} }
public void Tick() { } public void Tick( World world ) { }
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; mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.PowerDown : Cursor.PowerDown; ? Cursor.PowerDown : Cursor.PowerDown;
} }
} }

View File

@@ -9,21 +9,21 @@ namespace OpenRa.Orders
{ {
class RepairOrderGenerator : IOrderGenerator class RepairOrderGenerator : IOrderGenerator
{ {
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return OrderInner(xy, mi); return OrderInner(world, xy, mi);
} }
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.world.FindUnits(loc, loc) var underCursor = world.FindUnits(loc, loc)
.Where(a => a.Owner == Game.world.LocalPlayer .Where(a => a.Owner == world.LocalPlayer
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.traits.Contains<Selectable>()).FirstOrDefault(); && a.traits.Contains<Selectable>()).FirstOrDefault();
@@ -34,24 +34,24 @@ namespace OpenRa.Orders
} }
} }
public void Tick() public void Tick( World world )
{ {
if (!Game.Settings.RepairRequiresConyard) if (!Game.Settings.RepairRequiresConyard)
return; return;
var hasFact = Game.world.Actors var hasFact = world.Actors
.Any(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<ConstructionYard>()); .Any(a => a.Owner == world.LocalPlayer && a.traits.Contains<ConstructionYard>());
if (!hasFact) if (!hasFact)
Game.controller.CancelInputMode(); 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; mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Repair : Cursor.RepairBlocked; ? Cursor.Repair : Cursor.RepairBlocked;
} }
} }

View File

@@ -9,21 +9,21 @@ namespace OpenRa.Orders
{ {
class SellOrderGenerator : IOrderGenerator class SellOrderGenerator : IOrderGenerator
{ {
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Right) if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
return OrderInner(xy, mi); return OrderInner(world, xy, mi);
} }
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.world.FindUnits(loc, loc) var underCursor = world.FindUnits(loc, loc)
.Where(a => a.Owner == Game.world.LocalPlayer .Where(a => a.Owner == world.LocalPlayer
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.traits.Contains<Selectable>()).FirstOrDefault(); && a.traits.Contains<Selectable>()).FirstOrDefault();
@@ -34,13 +34,13 @@ namespace OpenRa.Orders
} }
} }
public void Tick() {} public void Tick( World world ) {}
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; mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Sell : Cursor.SellBlocked; ? Cursor.Sell : Cursor.SellBlocked;
} }
} }

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Orders
selection = selected.ToList(); selection = selected.ToList();
} }
public IEnumerable<Order> Order( int2 xy, MouseInput mi ) public IEnumerable<Order> Order( World world, int2 xy, MouseInput mi )
{ {
foreach( var unit in selection ) 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); selection.RemoveAll(a => !a.IsInWorld);
} }
public void Render() public void Render( World world )
{ {
foreach( var a in selection ) 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 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)) .Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
.FirstOrDefault(a => a != null); .FirstOrDefault(a => a != null);
return c ?? return c ??
(Game.world.SelectActorsInBox(Game.CellSize * p, (world.SelectActorsInBox(Game.CellSize * p,
Game.CellSize * p).Any() Game.CellSize * p).Any()
? Cursor.Select : Cursor.Default); ? Cursor.Select : Cursor.Default);
} }
@@ -69,7 +69,7 @@ namespace OpenRa.Orders
return Cursor.MoveBlocked; return Cursor.MoveBlocked;
case "DeployMcv": case "DeployMcv":
var factBuildingInfo = Rules.Info["fact"].Traits.Get<BuildingInfo>(); var factBuildingInfo = Rules.Info["fact"].Traits.Get<BuildingInfo>();
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; return Cursor.Deploy;
else else
return Cursor.DeployBlocked; return Cursor.DeployBlocked;

View File

@@ -13,7 +13,7 @@ namespace OpenRa.Mods.Aftermath.Orders
this.self = self; this.self = self;
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
@@ -24,15 +24,15 @@ namespace OpenRa.Mods.Aftermath.Orders
yield return new Order("ChronoshiftSelf", self, null, xy, null); yield return new Order("ChronoshiftSelf", self, null, xy, null);
} }
public void Tick() { } public void Tick( World world ) { }
public void Render() 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; return Cursor.MoveBlocked;
var movement = self.traits.GetOrDefault<IMovement>(); var movement = self.traits.GetOrDefault<IMovement>();