QueuedActivity's Insert is broken

This commit is contained in:
alzeih
2011-03-18 00:18:57 +13:00
committed by Paul Chote
parent 4e89326134
commit 255bac6aff
64 changed files with 218 additions and 251 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenRA
[Sync]
public Player Owner;
private IActivity currentActivity;
private Activity currentActivity;
public Group Group;
internal Actor(World world, string name, TypeDictionary initDict )
@@ -121,7 +121,14 @@ namespace OpenRA
public bool IsInWorld { get; internal set; }
public void QueueActivity( IActivity nextActivity )
public void QueueActivity( bool queued, Activity nextActivity )
{
if( !queued )
CancelActivity();
QueueActivity( nextActivity );
}
public void QueueActivity( Activity nextActivity )
{
if( currentActivity == null )
currentActivity = nextActivity;
@@ -135,7 +142,7 @@ namespace OpenRA
currentActivity.Cancel( this );
}
public IActivity GetCurrentActivity()
public Activity GetCurrentActivity()
{
return currentActivity;
}

View File

@@ -15,12 +15,15 @@ using System.Text;
namespace OpenRA.Traits.Activities
{
public abstract class CancelableActivity : IActivity
public class Activity
{
protected IActivity NextActivity { get; private set; }
public Activity NextActivity { get; set; }
protected bool IsCanceled { get; private set; }
public abstract IActivity Tick( Actor self );
public virtual Activity Tick( Actor self )
{
return this;
}
protected virtual bool OnCancel( Actor self ) { return true; }
public void Cancel( Actor self )
@@ -32,7 +35,7 @@ namespace OpenRA.Traits.Activities
NextActivity.Cancel( self );
}
public void Queue( IActivity activity )
public virtual void Queue( Activity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
@@ -40,9 +43,9 @@ namespace OpenRA.Traits.Activities
NextActivity = activity;
}
public virtual IEnumerable<float2> GetCurrentPath()
public virtual IEnumerable<Target> GetTargetQueue( Actor self )
{
yield break;
}
}
}
}

View File

@@ -237,12 +237,12 @@ namespace OpenRA.Traits
if (activity != null && mobile != null)
{
var alt = new float2(0, -mobile.Altitude);
var path = activity.GetCurrentPath();
var targets = activity.GetTargetQueue(self);
var start = self.CenterLocation + alt;
var c = Color.Green;
foreach (var step in path)
foreach (var step in targets.Select(p => p.CenterLocation))
{
var stp = step + alt;
Game.Renderer.LineRenderer.DrawLine(stp + new float2(-1, -1), stp + new float2(-1, 1), c, c);

View File

@@ -12,6 +12,8 @@ namespace OpenRA.Traits
{
public struct Target // a target: either an actor, or a fixed location.
{
public static Target[] NoTargets = {};
Actor actor;
Player owner;
int2 pos;

View File

@@ -203,14 +203,6 @@ namespace OpenRA.Traits
IBotInfo Info { get; }
}
public interface IActivity
{
IActivity Tick(Actor self);
void Cancel(Actor self);
void Queue(IActivity activity);
IEnumerable<float2> GetCurrentPath();
}
public interface IRenderOverlay { void Render(WorldRenderer wr); }
public interface INotifyIdle { void TickIdle(Actor self); }

View File

@@ -14,6 +14,7 @@ using System.Linq;
using OpenRA.Graphics;
using OpenRA.Support;
using System.Collections.Generic;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits
{
@@ -103,13 +104,13 @@ namespace OpenRA.Traits
return new Renderable(s, loc.Round(), pal, (int)self.CenterLocation.Y);
}
public static IActivity SequenceActivities(params IActivity[] acts)
public static Activity SequenceActivities(params Activity[] acts)
{
return acts.Reverse().Aggregate(
(next, a) => { a.Queue( next ); return a; });
}
public static IActivity RunActivity( Actor self, IActivity act )
public static Activity RunActivity( Actor self, Activity act )
{
while( act != null )
{