Update copyright header. Normalize line endings to LF.
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
/* non-turreted attack */
|
||||
public class Attack : CancelableActivity
|
||||
{
|
||||
protected Target Target;
|
||||
ITargetable targetable;
|
||||
int Range;
|
||||
bool AllowMovement;
|
||||
|
||||
int nextPathTime;
|
||||
|
||||
const int delayBetweenPathingAttempts = 20;
|
||||
const int delaySpread = 5;
|
||||
|
||||
public Attack(Target target, int range, bool allowMovement)
|
||||
{
|
||||
Target = target;
|
||||
if (target.IsActor)
|
||||
targetable = target.Actor.TraitOrDefault<ITargetable>();
|
||||
|
||||
Range = range;
|
||||
AllowMovement = allowMovement;
|
||||
}
|
||||
|
||||
public Attack(Target target, int range) : this(target, range, true) {}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
|
||||
var ret = InnerTick( self, attack );
|
||||
attack.IsAttacking = ( ret == this );
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected virtual IActivity InnerTick( Actor self, AttackBase attack )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var facing = self.Trait<IFacing>();
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
|
||||
return NextActivity;
|
||||
|
||||
if (!Combat.IsInRange(self.CenterLocation, Range, Target))
|
||||
{
|
||||
if (--nextPathTime > 0)
|
||||
return this;
|
||||
|
||||
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
|
||||
delayBetweenPathingAttempts + delaySpread);
|
||||
|
||||
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
|
||||
}
|
||||
|
||||
var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0);
|
||||
if (facing.Facing != desiredFacing)
|
||||
return Util.SequenceActivities( new Turn( desiredFacing ), this );
|
||||
|
||||
attack.DoAttack(self, Target);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
/* non-turreted attack */
|
||||
public class Attack : CancelableActivity
|
||||
{
|
||||
protected Target Target;
|
||||
ITargetable targetable;
|
||||
int Range;
|
||||
bool AllowMovement;
|
||||
|
||||
int nextPathTime;
|
||||
|
||||
const int delayBetweenPathingAttempts = 20;
|
||||
const int delaySpread = 5;
|
||||
|
||||
public Attack(Target target, int range, bool allowMovement)
|
||||
{
|
||||
Target = target;
|
||||
if (target.IsActor)
|
||||
targetable = target.Actor.TraitOrDefault<ITargetable>();
|
||||
|
||||
Range = range;
|
||||
AllowMovement = allowMovement;
|
||||
}
|
||||
|
||||
public Attack(Target target, int range) : this(target, range, true) {}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
|
||||
var ret = InnerTick( self, attack );
|
||||
attack.IsAttacking = ( ret == this );
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected virtual IActivity InnerTick( Actor self, AttackBase attack )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var facing = self.Trait<IFacing>();
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
|
||||
return NextActivity;
|
||||
|
||||
if (!Combat.IsInRange(self.CenterLocation, Range, Target))
|
||||
{
|
||||
if (--nextPathTime > 0)
|
||||
return this;
|
||||
|
||||
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
|
||||
delayBetweenPathingAttempts + delaySpread);
|
||||
|
||||
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
|
||||
}
|
||||
|
||||
var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0);
|
||||
if (facing.Facing != desiredFacing)
|
||||
return Util.SequenceActivities( new Turn( desiredFacing ), this );
|
||||
|
||||
attack.DoAttack(self, Target);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class CallFunc : IActivity
|
||||
{
|
||||
public CallFunc(Action a) { this.a = a; }
|
||||
public CallFunc(Action a, bool interruptable)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
Action a;
|
||||
bool interruptable;
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (a != null) a();
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
if (!interruptable)
|
||||
return;
|
||||
|
||||
a = null;
|
||||
NextActivity = null;
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class CallFunc : IActivity
|
||||
{
|
||||
public CallFunc(Action a) { this.a = a; }
|
||||
public CallFunc(Action a, bool interruptable)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
Action a;
|
||||
bool interruptable;
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (a != null) a();
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
if (!interruptable)
|
||||
return;
|
||||
|
||||
a = null;
|
||||
NextActivity = null;
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class CaptureBuilding : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
|
||||
public CaptureBuilding(Actor target) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
// todo: clean this up
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
var oldOwner = target.Owner;
|
||||
w.Remove(target);
|
||||
target.Owner = self.Owner;
|
||||
w.Add(target);
|
||||
|
||||
foreach (var t in target.TraitsImplementing<INotifyCapture>())
|
||||
t.OnCapture(target, self, oldOwner, self.Owner);
|
||||
|
||||
foreach (var t in self.World.Queries.WithTrait<INotifyOtherCaptured>())
|
||||
t.Trait.OnActorCaptured(t.Actor, target, self, oldOwner, self.Owner);
|
||||
|
||||
self.Destroy();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class CaptureBuilding : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
|
||||
public CaptureBuilding(Actor target) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
// todo: clean this up
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
var oldOwner = target.Owner;
|
||||
w.Remove(target);
|
||||
target.Owner = self.Owner;
|
||||
w.Add(target);
|
||||
|
||||
foreach (var t in target.TraitsImplementing<INotifyCapture>())
|
||||
t.OnCapture(target, self, oldOwner, self.Owner);
|
||||
|
||||
foreach (var t in self.World.Queries.WithTrait<INotifyOtherCaptured>())
|
||||
t.Trait.OnActorCaptured(t.Actor, target, self, oldOwner, self.Owner);
|
||||
|
||||
self.Destroy();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class DeliverResources : IActivity
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
bool isDocking;
|
||||
|
||||
public DeliverResources() { }
|
||||
|
||||
public IActivity Tick( Actor self )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var harv = self.Trait<Harvester>();
|
||||
|
||||
if (harv.LinkedProc == null || !harv.LinkedProc.IsInWorld)
|
||||
harv.ChooseNewProc(self, null);
|
||||
|
||||
if (harv.LinkedProc == null) // no procs exist; check again in 1s.
|
||||
return Util.SequenceActivities( new Wait(25), this );
|
||||
|
||||
var proc = harv.LinkedProc;
|
||||
|
||||
if( self.Location != proc.Location + proc.Trait<IAcceptOre>().DeliverOffset )
|
||||
{
|
||||
return Util.SequenceActivities( mobile.MoveTo(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0), this );
|
||||
}
|
||||
else if (!isDocking)
|
||||
{
|
||||
isDocking = true;
|
||||
proc.Trait<IAcceptOre>().OnDock(self, this);
|
||||
}
|
||||
return Util.SequenceActivities( new Wait(10), this );
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
// TODO: allow canceling of deliver orders?
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class DeliverResources : IActivity
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
bool isDocking;
|
||||
|
||||
public DeliverResources() { }
|
||||
|
||||
public IActivity Tick( Actor self )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var harv = self.Trait<Harvester>();
|
||||
|
||||
if (harv.LinkedProc == null || !harv.LinkedProc.IsInWorld)
|
||||
harv.ChooseNewProc(self, null);
|
||||
|
||||
if (harv.LinkedProc == null) // no procs exist; check again in 1s.
|
||||
return Util.SequenceActivities( new Wait(25), this );
|
||||
|
||||
var proc = harv.LinkedProc;
|
||||
|
||||
if( self.Location != proc.Location + proc.Trait<IAcceptOre>().DeliverOffset )
|
||||
{
|
||||
return Util.SequenceActivities( mobile.MoveTo(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0), this );
|
||||
}
|
||||
else if (!isDocking)
|
||||
{
|
||||
isDocking = true;
|
||||
proc.Trait<IAcceptOre>().OnDock(self, this);
|
||||
}
|
||||
return Util.SequenceActivities( new Wait(10), this );
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
// TODO: allow canceling of deliver orders?
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Demolish : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
|
||||
public Demolish( Actor target ) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25 * 2,
|
||||
() => { if (target.IsInWorld) target.Kill(self); })));
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Demolish : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
|
||||
public Demolish( Actor target ) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25 * 2,
|
||||
() => { if (target.IsInWorld) target.Kill(self); })));
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Enter : CancelableActivity
|
||||
{
|
||||
readonly Actor target;
|
||||
public Enter( Actor target ) { this.target = target; }
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled || target.Destroyed || !target.IsInWorld )
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var nearest = target.Trait<IOccupySpace>().NearestCellTo( mobile.toCell );
|
||||
if( ( nearest - mobile.toCell ).LengthSquared > 2 )
|
||||
return Util.SequenceActivities( new MoveAdjacentTo( target ), this );
|
||||
|
||||
return Util.SequenceActivities( mobile.MoveTo( nearest, target ), NextActivity );
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Enter : CancelableActivity
|
||||
{
|
||||
readonly Actor target;
|
||||
public Enter( Actor target ) { this.target = target; }
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled || target.Destroyed || !target.IsInWorld )
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var nearest = target.Trait<IOccupySpace>().NearestCellTo( mobile.toCell );
|
||||
if( ( nearest - mobile.toCell ).LengthSquared > 2 )
|
||||
return Util.SequenceActivities( new MoveAdjacentTo( target ), this );
|
||||
|
||||
return Util.SequenceActivities( mobile.MoveTo( nearest, target ), NextActivity );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class EnterTransport : CancelableActivity
|
||||
{
|
||||
public Actor transport;
|
||||
|
||||
public EnterTransport(Actor self, Actor transport)
|
||||
{
|
||||
this.transport = transport;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (transport == null || !transport.IsInWorld) return NextActivity;
|
||||
|
||||
var cargo = transport.Trait<Cargo>();
|
||||
if (cargo.IsFull(transport))
|
||||
return NextActivity;
|
||||
|
||||
|
||||
// Todo: Queue a move order to the transport? need to be
|
||||
// careful about units that can't path to the transport
|
||||
if ((transport.Location - self.Location).Length > 1)
|
||||
return NextActivity;
|
||||
|
||||
cargo.Load(transport, self);
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class EnterTransport : CancelableActivity
|
||||
{
|
||||
public Actor transport;
|
||||
|
||||
public EnterTransport(Actor self, Actor transport)
|
||||
{
|
||||
this.transport = transport;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (transport == null || !transport.IsInWorld) return NextActivity;
|
||||
|
||||
var cargo = transport.Trait<Cargo>();
|
||||
if (cargo.IsFull(transport))
|
||||
return NextActivity;
|
||||
|
||||
|
||||
// Todo: Queue a move order to the transport? need to be
|
||||
// careful about units that can't path to the transport
|
||||
if ((transport.Location - self.Location).Length > 1)
|
||||
return NextActivity;
|
||||
|
||||
cargo.Load(transport, self);
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Follow : CancelableActivity
|
||||
{
|
||||
Target Target;
|
||||
int Range;
|
||||
int nextPathTime;
|
||||
|
||||
const int delayBetweenPathingAttempts = 20;
|
||||
const int delaySpread = 5;
|
||||
|
||||
public Follow(Target target, int range)
|
||||
{
|
||||
Target = target;
|
||||
Range = range;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (!Target.IsValid) return NextActivity;
|
||||
|
||||
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
|
||||
|
||||
if( inRange ) return this;
|
||||
if (--nextPathTime > 0) return this;
|
||||
|
||||
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
|
||||
delayBetweenPathingAttempts + delaySpread);
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
return Util.SequenceActivities( mobile.MoveWithinRange( Target, Range ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Follow : CancelableActivity
|
||||
{
|
||||
Target Target;
|
||||
int Range;
|
||||
int nextPathTime;
|
||||
|
||||
const int delayBetweenPathingAttempts = 20;
|
||||
const int delaySpread = 5;
|
||||
|
||||
public Follow(Target target, int range)
|
||||
{
|
||||
Target = target;
|
||||
Range = range;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (!Target.IsValid) return NextActivity;
|
||||
|
||||
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
|
||||
|
||||
if( inRange ) return this;
|
||||
if (--nextPathTime > 0) return this;
|
||||
|
||||
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
|
||||
delayBetweenPathingAttempts + delaySpread);
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
return Util.SequenceActivities( mobile.MoveWithinRange( Target, Range ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Harvest : CancelableActivity
|
||||
{
|
||||
bool isHarvesting = false;
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( isHarvesting ) return this;
|
||||
if( IsCanceled ) return NextActivity;
|
||||
if( NextActivity != null ) return NextActivity;
|
||||
|
||||
var harv = self.Trait<Harvester>();
|
||||
harv.LastHarvestedCell = self.Location;
|
||||
|
||||
if( harv.IsFull )
|
||||
return Util.SequenceActivities( new DeliverResources(), NextActivity );
|
||||
|
||||
if (HarvestThisTile(self))
|
||||
return this;
|
||||
else
|
||||
{
|
||||
FindMoreResource(self);
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
|
||||
bool HarvestThisTile(Actor self)
|
||||
{
|
||||
var harv = self.Trait<Harvester>();
|
||||
var renderUnit = self.Trait<RenderUnit>(); /* better have one of these! */
|
||||
|
||||
var resource = self.World.WorldActor.Trait<ResourceLayer>().Harvest(self.Location);
|
||||
if (resource == null)
|
||||
return false;
|
||||
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
harv.AcceptResource(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindMoreResource(Actor self)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
self.QueueActivity(mobile.MoveTo(
|
||||
() =>
|
||||
{
|
||||
return self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, true)
|
||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
}));
|
||||
self.QueueActivity(new Harvest());
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Harvest : CancelableActivity
|
||||
{
|
||||
bool isHarvesting = false;
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( isHarvesting ) return this;
|
||||
if( IsCanceled ) return NextActivity;
|
||||
if( NextActivity != null ) return NextActivity;
|
||||
|
||||
var harv = self.Trait<Harvester>();
|
||||
harv.LastHarvestedCell = self.Location;
|
||||
|
||||
if( harv.IsFull )
|
||||
return Util.SequenceActivities( new DeliverResources(), NextActivity );
|
||||
|
||||
if (HarvestThisTile(self))
|
||||
return this;
|
||||
else
|
||||
{
|
||||
FindMoreResource(self);
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
|
||||
bool HarvestThisTile(Actor self)
|
||||
{
|
||||
var harv = self.Trait<Harvester>();
|
||||
var renderUnit = self.Trait<RenderUnit>(); /* better have one of these! */
|
||||
|
||||
var resource = self.World.WorldActor.Trait<ResourceLayer>().Harvest(self.Location);
|
||||
if (resource == null)
|
||||
return false;
|
||||
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
harv.AcceptResource(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindMoreResource(Actor self)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
self.QueueActivity(mobile.MoveTo(
|
||||
() =>
|
||||
{
|
||||
return self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, true)
|
||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
}));
|
||||
self.QueueActivity(new Harvest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
/* non-turreted attack */
|
||||
public class Heal : Attack
|
||||
{
|
||||
public Heal(Target target, int range, bool allowMovement)
|
||||
: base(target, range, allowMovement) {}
|
||||
|
||||
protected override IActivity InnerTick( Actor self, AttackBase attack )
|
||||
{
|
||||
if (Target.IsActor && Target.Actor.GetDamageState() == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
return base.InnerTick(self, attack);
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
/* non-turreted attack */
|
||||
public class Heal : Attack
|
||||
{
|
||||
public Heal(Target target, int range, bool allowMovement)
|
||||
: base(target, range, allowMovement) {}
|
||||
|
||||
protected override IActivity InnerTick( Actor self, AttackBase attack )
|
||||
{
|
||||
if (Target.IsActor && Target.Actor.GetDamageState() == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
return base.InnerTick(self, attack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Infiltrate : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
public Infiltrate(Actor target) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
foreach (var t in target.TraitsImplementing<IAcceptSpy>())
|
||||
t.OnInfiltrate(target, self);
|
||||
|
||||
self.Destroy();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Infiltrate : CancelableActivity
|
||||
{
|
||||
Actor target;
|
||||
public Infiltrate(Actor target) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
foreach (var t in target.TraitsImplementing<IAcceptSpy>())
|
||||
t.OnInfiltrate(target, self);
|
||||
|
||||
self.Destroy();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
// assumes you have Minelayer on that unit
|
||||
|
||||
class LayMines : CancelableActivity
|
||||
{
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (!limitedAmmo.HasAmmo())
|
||||
{
|
||||
// rearm & repair at fix, then back out here to refill the minefield some more
|
||||
var buildings = self.Info.Traits.Get<MinelayerInfo>().RearmBuildings;
|
||||
var rearmTarget = self.World.Actors.FirstOrDefault(a => a.Owner != null && self.Owner.Stances[a.Owner] == Stance.Ally
|
||||
&& buildings.Contains(a.Info.Name));
|
||||
|
||||
if (rearmTarget == null)
|
||||
return new Wait(20);
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new Enter(rearmTarget),
|
||||
//new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget),
|
||||
new Rearm(),
|
||||
new Repair(rearmTarget),
|
||||
this );
|
||||
}
|
||||
|
||||
var ml = self.Trait<Minelayer>();
|
||||
if (ml.minefield.Contains(self.Location) &&
|
||||
ShouldLayMine(self, self.Location))
|
||||
{
|
||||
LayMine(self);
|
||||
return Util.SequenceActivities( new Wait(20), this ); // a little wait after placing each mine, for show
|
||||
}
|
||||
|
||||
for (var n = 0; n < 20; n++) // dont get stuck forever here
|
||||
{
|
||||
var p = ml.minefield.Random(self.World.SharedRandom);
|
||||
if (ShouldLayMine(self, p))
|
||||
return Util.SequenceActivities( mobile.MoveTo(p, 0), this );
|
||||
}
|
||||
|
||||
// todo: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield.
|
||||
|
||||
return new Wait(20); // nothing to do here
|
||||
}
|
||||
|
||||
bool ShouldLayMine(Actor self, int2 p)
|
||||
{
|
||||
// if there is no unit (other than me) here, we want to place a mine here
|
||||
return !self.World.WorldActor.Trait<UnitInfluence>()
|
||||
.GetUnitsAt(p).Any(a => a != self);
|
||||
}
|
||||
|
||||
void LayMine(Actor self)
|
||||
{
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo != null) limitedAmmo.Attacking(self, Target.FromCell(self.Location));
|
||||
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location ),
|
||||
new OwnerInit( self.Owner ),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
// assumes you have Minelayer on that unit
|
||||
|
||||
class LayMines : CancelableActivity
|
||||
{
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (!limitedAmmo.HasAmmo())
|
||||
{
|
||||
// rearm & repair at fix, then back out here to refill the minefield some more
|
||||
var buildings = self.Info.Traits.Get<MinelayerInfo>().RearmBuildings;
|
||||
var rearmTarget = self.World.Actors.FirstOrDefault(a => a.Owner != null && self.Owner.Stances[a.Owner] == Stance.Ally
|
||||
&& buildings.Contains(a.Info.Name));
|
||||
|
||||
if (rearmTarget == null)
|
||||
return new Wait(20);
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new Enter(rearmTarget),
|
||||
//new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget),
|
||||
new Rearm(),
|
||||
new Repair(rearmTarget),
|
||||
this );
|
||||
}
|
||||
|
||||
var ml = self.Trait<Minelayer>();
|
||||
if (ml.minefield.Contains(self.Location) &&
|
||||
ShouldLayMine(self, self.Location))
|
||||
{
|
||||
LayMine(self);
|
||||
return Util.SequenceActivities( new Wait(20), this ); // a little wait after placing each mine, for show
|
||||
}
|
||||
|
||||
for (var n = 0; n < 20; n++) // dont get stuck forever here
|
||||
{
|
||||
var p = ml.minefield.Random(self.World.SharedRandom);
|
||||
if (ShouldLayMine(self, p))
|
||||
return Util.SequenceActivities( mobile.MoveTo(p, 0), this );
|
||||
}
|
||||
|
||||
// todo: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield.
|
||||
|
||||
return new Wait(20); // nothing to do here
|
||||
}
|
||||
|
||||
bool ShouldLayMine(Actor self, int2 p)
|
||||
{
|
||||
// if there is no unit (other than me) here, we want to place a mine here
|
||||
return !self.World.WorldActor.Trait<UnitInfluence>()
|
||||
.GetUnitsAt(p).Any(a => a != self);
|
||||
}
|
||||
|
||||
void LayMine(Actor self)
|
||||
{
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo != null) limitedAmmo.Attacking(self, Target.FromCell(self.Location));
|
||||
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location ),
|
||||
new OwnerInit( self.Owner ),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Leap : CancelableActivity
|
||||
{
|
||||
Target target;
|
||||
int2 initialLocation;
|
||||
|
||||
int moveFraction;
|
||||
const int delay = 6;
|
||||
|
||||
public Leap(Actor self, Target target)
|
||||
{
|
||||
this.target = target;
|
||||
initialLocation = self.Trait<Mobile>().PxPosition;
|
||||
|
||||
self.Trait<RenderInfantry>().Attacking(self, target);
|
||||
Sound.Play("dogg5p.aud", self.CenterLocation);
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if( moveFraction == 0 && IsCanceled ) return NextActivity;
|
||||
if (!target.IsValid) return NextActivity;
|
||||
|
||||
self.Trait<AttackLeap>().IsLeaping = true;
|
||||
var mobile = self.Trait<Mobile>();
|
||||
++moveFraction;
|
||||
|
||||
mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
|
||||
|
||||
if (moveFraction >= delay)
|
||||
{
|
||||
self.TraitsImplementing<IMove>().FirstOrDefault()
|
||||
.SetPosition(self, Util.CellContaining(target.CenterLocation));
|
||||
|
||||
if (target.IsActor)
|
||||
target.Actor.Kill(self);
|
||||
self.Trait<AttackLeap>().IsLeaping = false;
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Leap : CancelableActivity
|
||||
{
|
||||
Target target;
|
||||
int2 initialLocation;
|
||||
|
||||
int moveFraction;
|
||||
const int delay = 6;
|
||||
|
||||
public Leap(Actor self, Target target)
|
||||
{
|
||||
this.target = target;
|
||||
initialLocation = self.Trait<Mobile>().PxPosition;
|
||||
|
||||
self.Trait<RenderInfantry>().Attacking(self, target);
|
||||
Sound.Play("dogg5p.aud", self.CenterLocation);
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if( moveFraction == 0 && IsCanceled ) return NextActivity;
|
||||
if (!target.IsValid) return NextActivity;
|
||||
|
||||
self.Trait<AttackLeap>().IsLeaping = true;
|
||||
var mobile = self.Trait<Mobile>();
|
||||
++moveFraction;
|
||||
|
||||
mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
|
||||
|
||||
if (moveFraction >= delay)
|
||||
{
|
||||
self.TraitsImplementing<IMove>().FirstOrDefault()
|
||||
.SetPosition(self, Util.CellContaining(target.CenterLocation));
|
||||
|
||||
if (target.IsActor)
|
||||
target.Actor.Kill(self);
|
||||
self.Trait<AttackLeap>().IsLeaping = false;
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class MoveAdjacentTo : CancelableActivity
|
||||
{
|
||||
readonly Actor target;
|
||||
|
||||
public MoveAdjacentTo( Actor target )
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var ps1 = new PathSearch( self.World, mobile.Info )
|
||||
{
|
||||
checkForBlocked = true,
|
||||
heuristic = location => 0,
|
||||
inReverse = true
|
||||
};
|
||||
foreach( var cell in target.Trait<IOccupySpace>().OccupiedCells() )
|
||||
{
|
||||
ps1.AddInitialCell( cell.First );
|
||||
if( ( mobile.toCell - cell.First ).LengthSquared <= 2 )
|
||||
return NextActivity;
|
||||
}
|
||||
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
|
||||
|
||||
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true );
|
||||
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
|
||||
if( ret.Count > 0 )
|
||||
ret.RemoveAt( 0 );
|
||||
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class MoveAdjacentTo : CancelableActivity
|
||||
{
|
||||
readonly Actor target;
|
||||
|
||||
public MoveAdjacentTo( Actor target )
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var ps1 = new PathSearch( self.World, mobile.Info )
|
||||
{
|
||||
checkForBlocked = true,
|
||||
heuristic = location => 0,
|
||||
inReverse = true
|
||||
};
|
||||
foreach( var cell in target.Trait<IOccupySpace>().OccupiedCells() )
|
||||
{
|
||||
ps1.AddInitialCell( cell.First );
|
||||
if( ( mobile.toCell - cell.First ).LengthSquared <= 2 )
|
||||
return NextActivity;
|
||||
}
|
||||
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
|
||||
|
||||
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true );
|
||||
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
|
||||
if( ret.Count > 0 )
|
||||
ret.RemoveAt( 0 );
|
||||
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class QueuedActivity : IActivity
|
||||
{
|
||||
public QueuedActivity(Action<QueuedActivity> a) { this.a = a; }
|
||||
|
||||
public QueuedActivity(Action<QueuedActivity> a, bool interruptable)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
Action<QueuedActivity> a;
|
||||
private bool interruptable = true;
|
||||
public IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick(Actor self) { return Run(self); }
|
||||
|
||||
public IActivity Run(Actor self)
|
||||
{
|
||||
if (a != null)
|
||||
a(this);
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public void Insert(IActivity activity)
|
||||
{
|
||||
if (activity == null)
|
||||
return;
|
||||
activity.Queue(NextActivity);
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
if (!interruptable)
|
||||
return;
|
||||
|
||||
a = null;
|
||||
NextActivity = null;
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
if (NextActivity != null)
|
||||
foreach (var path in NextActivity.GetCurrentPath())
|
||||
{
|
||||
yield return path;
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class QueuedActivity : IActivity
|
||||
{
|
||||
public QueuedActivity(Action<QueuedActivity> a) { this.a = a; }
|
||||
|
||||
public QueuedActivity(Action<QueuedActivity> a, bool interruptable)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
Action<QueuedActivity> a;
|
||||
private bool interruptable = true;
|
||||
public IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick(Actor self) { return Run(self); }
|
||||
|
||||
public IActivity Run(Actor self)
|
||||
{
|
||||
if (a != null)
|
||||
a(this);
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public void Insert(IActivity activity)
|
||||
{
|
||||
if (activity == null)
|
||||
return;
|
||||
activity.Queue(NextActivity);
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
if (!interruptable)
|
||||
return;
|
||||
|
||||
a = null;
|
||||
NextActivity = null;
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
if (NextActivity != null)
|
||||
foreach (var path in NextActivity.GetCurrentPath())
|
||||
{
|
||||
yield return path;
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Rearm : CancelableActivity
|
||||
{
|
||||
int remainingTicks = ticksPerPip;
|
||||
|
||||
const int ticksPerPip = 25 * 2;
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo == null) return NextActivity;
|
||||
|
||||
if (--remainingTicks == 0)
|
||||
{
|
||||
if (!limitedAmmo.GiveAmmo()) return NextActivity;
|
||||
|
||||
var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation)
|
||||
.FirstOrDefault(a => a.HasTrait<RenderBuilding>());
|
||||
|
||||
if (hostBuilding != null)
|
||||
hostBuilding.Trait<RenderBuilding>().PlayCustomAnim(hostBuilding, "active");
|
||||
|
||||
remainingTicks = ticksPerPip;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Rearm : CancelableActivity
|
||||
{
|
||||
int remainingTicks = ticksPerPip;
|
||||
|
||||
const int ticksPerPip = 25 * 2;
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo == null) return NextActivity;
|
||||
|
||||
if (--remainingTicks == 0)
|
||||
{
|
||||
if (!limitedAmmo.GiveAmmo()) return NextActivity;
|
||||
|
||||
var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation)
|
||||
.FirstOrDefault(a => a.HasTrait<RenderBuilding>());
|
||||
|
||||
if (hostBuilding != null)
|
||||
hostBuilding.Trait<RenderBuilding>().PlayCustomAnim(hostBuilding, "active");
|
||||
|
||||
remainingTicks = ticksPerPip;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class RemoveSelf : CancelableActivity
|
||||
{
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
self.Destroy();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class RemoveSelf : CancelableActivity
|
||||
{
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
self.Destroy();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Repair : CancelableActivity
|
||||
{
|
||||
int remainingTicks;
|
||||
Actor host;
|
||||
|
||||
public Repair(Actor host) { this.host = host; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (host != null && !host.IsInWorld) return NextActivity;
|
||||
if (remainingTicks == 0)
|
||||
{
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
if (health == null) return NextActivity;
|
||||
|
||||
var repairsUnits = host.Info.Traits.Get<RepairsUnitsInfo>();
|
||||
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var hpToRepair = Math.Min(repairsUnits.HpPerStep, health.MaxHP - health.HP);
|
||||
var cost = (hpToRepair * unitCost * repairsUnits.ValuePercentage) / (health.MaxHP * 100);
|
||||
|
||||
if (!self.Owner.PlayerActor.Trait<PlayerResources>().TakeCash(cost))
|
||||
{
|
||||
remainingTicks = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
self.InflictDamage(self, -hpToRepair, null);
|
||||
if (health.DamageState == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
if (host != null)
|
||||
host.Trait<RenderBuilding>()
|
||||
.PlayCustomAnim(host, "active");
|
||||
|
||||
remainingTicks = repairsUnits.Interval;
|
||||
}
|
||||
else
|
||||
--remainingTicks;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Repair : CancelableActivity
|
||||
{
|
||||
int remainingTicks;
|
||||
Actor host;
|
||||
|
||||
public Repair(Actor host) { this.host = host; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (host != null && !host.IsInWorld) return NextActivity;
|
||||
if (remainingTicks == 0)
|
||||
{
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
if (health == null) return NextActivity;
|
||||
|
||||
var repairsUnits = host.Info.Traits.Get<RepairsUnitsInfo>();
|
||||
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var hpToRepair = Math.Min(repairsUnits.HpPerStep, health.MaxHP - health.HP);
|
||||
var cost = (hpToRepair * unitCost * repairsUnits.ValuePercentage) / (health.MaxHP * 100);
|
||||
|
||||
if (!self.Owner.PlayerActor.Trait<PlayerResources>().TakeCash(cost))
|
||||
{
|
||||
remainingTicks = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
self.InflictDamage(self, -hpToRepair, null);
|
||||
if (health.DamageState == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
if (host != null)
|
||||
host.Trait<RenderBuilding>()
|
||||
.PlayCustomAnim(host, "active");
|
||||
|
||||
remainingTicks = repairsUnits.Interval;
|
||||
}
|
||||
else
|
||||
--remainingTicks;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
@@ -21,20 +21,20 @@ namespace OpenRA.Mods.RA.Activities
|
||||
public RepairBuilding(Actor target) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
var health = target.Trait<Health>();
|
||||
if (health.DamageState == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
target.InflictDamage(self, -health.MaxHP, null);
|
||||
target.InflictDamage(self, -health.MaxHP, null);
|
||||
self.Destroy();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Teleport : CancelableActivity
|
||||
{
|
||||
int2 destination;
|
||||
|
||||
public Teleport(int2 destination)
|
||||
{
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
self.TraitsImplementing<ITeleportable>().FirstOrDefault().SetPosition(self, destination);
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Teleport : CancelableActivity
|
||||
{
|
||||
int2 destination;
|
||||
|
||||
public Teleport(int2 destination)
|
||||
{
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
self.TraitsImplementing<ITeleportable>().FirstOrDefault().SetPosition(self, destination);
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Transform : CancelableActivity
|
||||
{
|
||||
string actor = null;
|
||||
int2 offset;
|
||||
string[] sounds = null;
|
||||
int facing;
|
||||
|
||||
RenderBuilding rb;
|
||||
public Transform(Actor self, string toActor, int2 offset, int facing, string[] sounds)
|
||||
{
|
||||
this.actor = toActor;
|
||||
this.offset = offset;
|
||||
this.sounds = sounds;
|
||||
this.facing = facing;
|
||||
rb = self.TraitOrDefault<RenderBuilding>();
|
||||
}
|
||||
|
||||
void DoTransform(Actor self)
|
||||
{
|
||||
// Hack: repeat the first frame of the make anim instead
|
||||
// of flashing the full structure for a frame
|
||||
if (rb != null)
|
||||
rb.PlayCustomAnim(self, "make");
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var selected = w.Selection.Contains(self);
|
||||
|
||||
self.Destroy();
|
||||
foreach (var s in sounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
var init = new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location + offset ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( facing ),
|
||||
};
|
||||
if (self.HasTrait<Health>())
|
||||
init.Add( new HealthInit( self.Trait<Health>().HPFraction ));
|
||||
|
||||
var a = w.CreateActor( actor, init );
|
||||
|
||||
if (selected)
|
||||
w.Selection.Add(w, a);
|
||||
});
|
||||
}
|
||||
|
||||
bool started = false;
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (started) return this;
|
||||
|
||||
if (rb == null)
|
||||
DoTransform(self);
|
||||
else
|
||||
{
|
||||
rb.PlayCustomAnimBackwards(self, "make", () => DoTransform(self));
|
||||
|
||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
started = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Transform : CancelableActivity
|
||||
{
|
||||
string actor = null;
|
||||
int2 offset;
|
||||
string[] sounds = null;
|
||||
int facing;
|
||||
|
||||
RenderBuilding rb;
|
||||
public Transform(Actor self, string toActor, int2 offset, int facing, string[] sounds)
|
||||
{
|
||||
this.actor = toActor;
|
||||
this.offset = offset;
|
||||
this.sounds = sounds;
|
||||
this.facing = facing;
|
||||
rb = self.TraitOrDefault<RenderBuilding>();
|
||||
}
|
||||
|
||||
void DoTransform(Actor self)
|
||||
{
|
||||
// Hack: repeat the first frame of the make anim instead
|
||||
// of flashing the full structure for a frame
|
||||
if (rb != null)
|
||||
rb.PlayCustomAnim(self, "make");
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var selected = w.Selection.Contains(self);
|
||||
|
||||
self.Destroy();
|
||||
foreach (var s in sounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
var init = new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location + offset ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( facing ),
|
||||
};
|
||||
if (self.HasTrait<Health>())
|
||||
init.Add( new HealthInit( self.Trait<Health>().HPFraction ));
|
||||
|
||||
var a = w.CreateActor( actor, init );
|
||||
|
||||
if (selected)
|
||||
w.Selection.Add(w, a);
|
||||
});
|
||||
}
|
||||
|
||||
bool started = false;
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (started) return this;
|
||||
|
||||
if (rb == null)
|
||||
DoTransform(self);
|
||||
else
|
||||
{
|
||||
rb.PlayCustomAnimBackwards(self, "make", () => DoTransform(self));
|
||||
|
||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
started = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Turn : CancelableActivity
|
||||
{
|
||||
int desiredFacing;
|
||||
|
||||
public Turn( int desiredFacing )
|
||||
{
|
||||
this.desiredFacing = desiredFacing;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
if( desiredFacing == facing.Facing )
|
||||
return NextActivity;
|
||||
facing.Facing = Util.TickFacing(facing.Facing, desiredFacing, facing.ROT);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Turn : CancelableActivity
|
||||
{
|
||||
int desiredFacing;
|
||||
|
||||
public Turn( int desiredFacing )
|
||||
{
|
||||
this.desiredFacing = desiredFacing;
|
||||
}
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
if( desiredFacing == facing.Facing )
|
||||
return NextActivity;
|
||||
facing.Facing = Util.TickFacing(facing.Facing, desiredFacing, facing.ROT);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class UnloadCargo : CancelableActivity
|
||||
{
|
||||
int2? ChooseExitTile(Actor self, Actor cargo)
|
||||
{
|
||||
// is anyone still hogging this tile?
|
||||
if (self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
|
||||
return null;
|
||||
|
||||
var mobile = cargo.Trait<Mobile>();
|
||||
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
if ((i != 0 || j != 0) &&
|
||||
mobile.CanEnterCell(self.Location + new int2(i, j)))
|
||||
return self.Location + new int2(i, j);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
// if we're a thing that can turn, turn to the
|
||||
// right facing for the unload animation
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
|
||||
if (facing != null && facing.Facing != unloadFacing)
|
||||
return Util.SequenceActivities( new Turn(unloadFacing), this );
|
||||
|
||||
// todo: handle the BS of open/close sequences, which are inconsistent,
|
||||
// for reasons that probably make good sense to the westwood guys.
|
||||
|
||||
var cargo = self.Trait<Cargo>();
|
||||
if (cargo.IsEmpty(self))
|
||||
return NextActivity;
|
||||
|
||||
var ru = self.TraitOrDefault<RenderUnit>();
|
||||
if (ru != null)
|
||||
ru.PlayCustomAnimation(self, "unload", null);
|
||||
|
||||
var exitTile = ChooseExitTile(self, cargo.Peek(self));
|
||||
if (exitTile == null)
|
||||
return this;
|
||||
|
||||
var actor = cargo.Unload(self);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (actor.Destroyed) return;
|
||||
w.Add(actor);
|
||||
|
||||
var mobile = actor.Trait<Mobile>();
|
||||
mobile.SetPosition(actor, self.Location);
|
||||
actor.CancelActivity();
|
||||
actor.QueueActivity(mobile.MoveTo(exitTile.Value, 0));
|
||||
actor.SetTargetLine(Target.FromCell(exitTile.Value), Color.Green, false);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class UnloadCargo : CancelableActivity
|
||||
{
|
||||
int2? ChooseExitTile(Actor self, Actor cargo)
|
||||
{
|
||||
// is anyone still hogging this tile?
|
||||
if (self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
|
||||
return null;
|
||||
|
||||
var mobile = cargo.Trait<Mobile>();
|
||||
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
if ((i != 0 || j != 0) &&
|
||||
mobile.CanEnterCell(self.Location + new int2(i, j)))
|
||||
return self.Location + new int2(i, j);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
// if we're a thing that can turn, turn to the
|
||||
// right facing for the unload animation
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
|
||||
if (facing != null && facing.Facing != unloadFacing)
|
||||
return Util.SequenceActivities( new Turn(unloadFacing), this );
|
||||
|
||||
// todo: handle the BS of open/close sequences, which are inconsistent,
|
||||
// for reasons that probably make good sense to the westwood guys.
|
||||
|
||||
var cargo = self.Trait<Cargo>();
|
||||
if (cargo.IsEmpty(self))
|
||||
return NextActivity;
|
||||
|
||||
var ru = self.TraitOrDefault<RenderUnit>();
|
||||
if (ru != null)
|
||||
ru.PlayCustomAnimation(self, "unload", null);
|
||||
|
||||
var exitTile = ChooseExitTile(self, cargo.Peek(self));
|
||||
if (exitTile == null)
|
||||
return this;
|
||||
|
||||
var actor = cargo.Unload(self);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (actor.Destroyed) return;
|
||||
w.Add(actor);
|
||||
|
||||
var mobile = actor.Trait<Mobile>();
|
||||
mobile.SetPosition(actor, self.Location);
|
||||
actor.CancelActivity();
|
||||
actor.QueueActivity(mobile.MoveTo(exitTile.Value, 0));
|
||||
actor.SetTargetLine(Target.FromCell(exitTile.Value), Color.Green, false);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Wait : CancelableActivity
|
||||
{
|
||||
int remainingTicks;
|
||||
bool interruptable = true;
|
||||
|
||||
public Wait(int period) { remainingTicks = period; }
|
||||
public Wait(int period, bool interruptable)
|
||||
{
|
||||
remainingTicks = period;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (remainingTicks-- == 0) return NextActivity;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override bool OnCancel( Actor self )
|
||||
{
|
||||
if( !interruptable ) return false;
|
||||
remainingTicks = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Wait : CancelableActivity
|
||||
{
|
||||
int remainingTicks;
|
||||
bool interruptable = true;
|
||||
|
||||
public Wait(int period) { remainingTicks = period; }
|
||||
public Wait(int period, bool interruptable)
|
||||
{
|
||||
remainingTicks = period;
|
||||
this.interruptable = interruptable;
|
||||
}
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if (remainingTicks-- == 0) return NextActivity;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override bool OnCancel( Actor self )
|
||||
{
|
||||
if( !interruptable ) return false;
|
||||
remainingTicks = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user