start of smart minelayer

This commit is contained in:
Chris Forbes
2010-05-23 13:03:57 +12:00
parent bb289101fc
commit baf37f7d04
3 changed files with 60 additions and 18 deletions

View File

@@ -115,6 +115,7 @@ namespace OpenRA.Orders
case "Capture": return "capture"; case "Capture": return "capture";
case "Harvest": return "attackmove"; case "Harvest": return "attackmove";
case "Steal" : return "enter"; case "Steal" : return "enter";
case "BeginMinefield": return "ability";
default: default:
return null; return null;
} }

View File

@@ -59,7 +59,8 @@ namespace OpenRA.Mods.Aftermath
{ {
if (order.OrderString == "Deploy") if (order.OrderString == "Deploy")
{ {
Game.controller.orderGenerator = new SetChronoTankDestination(self); if (self.Owner == self.World.LocalPlayer)
Game.controller.orderGenerator = new SetChronoTankDestination(self);
return; return;
} }
@@ -70,7 +71,9 @@ namespace OpenRA.Mods.Aftermath
if (!self.Owner.Shroud.IsExplored(order.TargetLocation)) if (!self.Owner.Shroud.IsExplored(order.TargetLocation))
return; return;
Game.controller.CancelInputMode(); if (self.Owner == self.World.LocalPlayer)
Game.controller.CancelInputMode();
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Teleport(order.TargetLocation)); self.QueueActivity(new Teleport(order.TargetLocation));
Sound.Play("chrotnk1.aud", self.CenterLocation); Sound.Play("chrotnk1.aud", self.CenterLocation);

View File

@@ -21,42 +21,80 @@
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using System.Collections.Generic;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class MinelayerInfo : TraitInfo<Minelayer> class MinelayerInfo : TraitInfo<Minelayer>
{ {
public readonly string Mine = "minv"; public readonly string Mine = "minv";
public readonly int MinefieldDepth = 2;
} }
class Minelayer : IIssueOrder, IResolveOrder class Minelayer : IIssueOrder, IResolveOrder
{ {
int2[] minefield = null;
int2 minefieldStart; /* nosync! */
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{ {
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>(); if (mi.Button == MouseButton.Right && underCursor == null)
if (limitedAmmo != null && !limitedAmmo.HasAmmo()) return new Order("BeginMinefield", self, xy);
return null;
// Ensure that the cell is empty except for the minelayer
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(xy).Any(a => a != self))
return null;
if (mi.Button == MouseButton.Right && underCursor == self)
return new Order("Deploy", self);
return null; return null;
} }
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (order.OrderString == "Deploy") if (order.OrderString == "BeginMinefield")
{ if (self.Owner == self.World.LocalPlayer)
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>(); {
if (limitedAmmo != null) minefieldStart = order.TargetLocation;
limitedAmmo.Attacking(self); Game.controller.orderGenerator = new MinefieldOrderGenerator(self);
}
self.QueueActivity( new LayMine() ); if (order.OrderString == "PlaceMinefield")
{
if (self.Owner == self.World.LocalPlayer)
Game.controller.CancelInputMode();
minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth).ToArray();
/* todo: start the mnly actually laying mines there */
} }
} }
IEnumerable<int2> GetMinefieldCells(int2 start, int2 end, int depth)
{
yield break; /* todo: cells in locus */
}
class MinefieldOrderGenerator : IOrderGenerator
{
Actor minelayer;
public MinefieldOrderGenerator(Actor self) { minelayer = self; }
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<SelectableInfo>())
.OrderByDescending(a => a.Info.Traits.Get<SelectableInfo>().Priority)
.FirstOrDefault();
if (mi.Button == MouseButton.Right && underCursor == null)
yield return new Order("PlaceMinefield", minelayer, xy);
}
public void Tick(World world)
{
if (minelayer.IsDead || !minelayer.IsInWorld)
Game.controller.CancelInputMode();
}
public void Render(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) { return "ability"; } /* todo */
}
} }
} }