spyplane works

This commit is contained in:
Chris Forbes
2010-01-24 14:53:18 +13:00
parent 74af815f24
commit da40ab449e
7 changed files with 70 additions and 10 deletions

View File

@@ -160,6 +160,7 @@
<Compile Include="Traits\Activities\Idle.cs" />
<Compile Include="Traits\Activities\Land.cs" />
<Compile Include="Traits\Activities\Rearm.cs" />
<Compile Include="Traits\Activities\RemoveSelf.cs" />
<Compile Include="Traits\Activities\Repair.cs" />
<Compile Include="Traits\Activities\ReturnToBase.cs" />
<Compile Include="Traits\Activities\Sell.cs" />

View File

@@ -7,6 +7,8 @@ namespace OpenRa.Traits.Activities
{
public class CallFunc : IActivity
{
public CallFunc(Action a) { this.a = a; }
Action a;
public IActivity NextActivity { get; set; }

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Traits.Activities
{
class RemoveSelf : IActivity
{
bool isCanceled;
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
self.World.AddFrameEndTask(w => w.Remove(self));
return null;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Traits.Activities;
namespace OpenRa.Traits
{
class SpyPlanePowerInfo : SupportPowerInfo
{
public readonly int Range = 10;
public override object Create(Actor self) { return new SpyPlanePower(self,this); }
}
@@ -21,6 +23,18 @@ namespace OpenRa.Traits
Sound.Play("slcttgt1.aud");
}
static int2 ChooseRandomEdgeCell(World w)
{
var isX = Game.SharedRandom.Next(2) == 0;
var edge = Game.SharedRandom.Next(2) == 0;
return new int2(
isX ? Game.SharedRandom.Next(w.Map.XOffset, w.Map.XOffset + w.Map.Width)
: (edge ? w.Map.XOffset : w.Map.XOffset + w.Map.Width),
!isX ? Game.SharedRandom.Next(w.Map.YOffset, w.Map.YOffset + w.Map.Height)
: (edge ? w.Map.YOffset : w.Map.YOffset + w.Map.Height));
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "SpyPlane")
@@ -30,14 +44,17 @@ namespace OpenRa.Traits
if (order.Player == Owner.World.LocalPlayer)
Game.controller.CancelInputMode();
// todo: pick a cell p1 on the edge of the map; get the cell p2 at the other end of the line
// through that p1 & the target location;
var enterCell = ChooseRandomEdgeCell(self.World);
var exitCell = ChooseRandomEdgeCell(self.World);
// todo: spawn a SpyPlane at p1 with activities:
// -- fly to target point
// -- take picture
// -- fly to p2
// -- leave the world
var plane = self.World.CreateActor("U2", enterCell, self.Owner);
plane.CancelActivity();
plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
plane.QueueActivity(new CallFunc(
() => Owner.Shroud.Explore(Owner.World, order.TargetLocation,
(Info as SpyPlanePowerInfo).Range)));
plane.QueueActivity(new Fly(Util.CenterOfCell(exitCell)));
plane.QueueActivity(new RemoveSelf());
}
}