unit idle tracking via dummy activity; wasn't so bad.
This commit is contained in:
@@ -48,17 +48,23 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
var nextActivity = currentActivity;
|
|
||||||
while( nextActivity != null )
|
while (currentActivity != null)
|
||||||
{
|
{
|
||||||
currentActivity = nextActivity;
|
var a = currentActivity;
|
||||||
nextActivity = nextActivity.Tick( this );
|
currentActivity = a.Tick(this) ?? new Idle();
|
||||||
|
if (a == currentActivity) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tick in traits.WithInterface<ITick>())
|
foreach (var tick in traits.WithInterface<ITick>())
|
||||||
tick.Tick(this);
|
tick.Tick(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsIdle
|
||||||
|
{
|
||||||
|
get { return currentActivity == null || currentActivity is Idle; }
|
||||||
|
}
|
||||||
|
|
||||||
public float2 CenterLocation;
|
public float2 CenterLocation;
|
||||||
public float2 SelectedSize
|
public float2 SelectedSize
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,6 +132,7 @@
|
|||||||
<Compile Include="Graphics\LineRenderer.cs" />
|
<Compile Include="Graphics\LineRenderer.cs" />
|
||||||
<Compile Include="Graphics\OverlayRenderer.cs" />
|
<Compile Include="Graphics\OverlayRenderer.cs" />
|
||||||
<Compile Include="Graphics\WorldRenderer.cs" />
|
<Compile Include="Graphics\WorldRenderer.cs" />
|
||||||
|
<Compile Include="Traits\Activities\Idle.cs" />
|
||||||
<Compile Include="Traits\Activities\Teleport.cs" />
|
<Compile Include="Traits\Activities\Teleport.cs" />
|
||||||
<Compile Include="BuildingInfluenceMap.cs" />
|
<Compile Include="BuildingInfluenceMap.cs" />
|
||||||
<Compile Include="IOrderGenerator.cs" />
|
<Compile Include="IOrderGenerator.cs" />
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
var attack = self.traits.WithInterface<AttackBase>().First();
|
var attack = self.traits.WithInterface<AttackBase>().First();
|
||||||
attack.target = Target;
|
attack.target = Target;
|
||||||
attack.DoAttack(self);
|
attack.DoAttack(self);
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self)
|
public void Cancel(Actor self)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
// no refineries reachable?
|
// no refineries reachable?
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
else if( unit.Facing != 64 )
|
else if( unit.Facing != 64 )
|
||||||
return new Turn( 64 ) { NextActivity = this };
|
return new Turn( 64 ) { NextActivity = this };
|
||||||
@@ -69,7 +69,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
renderUnit.PlayCustomAnimation( self, "empty",
|
renderUnit.PlayCustomAnimation( self, "empty",
|
||||||
() => isDone = true );
|
() => isDone = true );
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self)
|
public void Cancel(Actor self)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
Sound.Play("build5.aud");
|
Sound.Play("build5.aud");
|
||||||
Game.world.Add( new Actor( Rules.UnitInfo["fact"], self.Location - new int2( 1, 1 ), self.Owner ) );
|
Game.world.Add( new Actor( Rules.UnitInfo["fact"], self.Location - new int2( 1, 1 ), self.Owner ) );
|
||||||
} );
|
} );
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel( Actor self )
|
public void Cancel( Actor self )
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||||
@@ -74,7 +74,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||||
@@ -103,7 +103,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
|
|
||||||
unit.Altitude += Math.Sign(targetAltitude - unit.Altitude);
|
unit.Altitude += Math.Sign(targetAltitude - unit.Altitude);
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; }
|
public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; }
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
if( !inRange )
|
if( !inRange )
|
||||||
return new Move( Target, Range ) { NextActivity = this };
|
return new Move( Target, Range ) { NextActivity = this };
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self)
|
public void Cancel(Actor self)
|
||||||
|
|||||||
@@ -12,49 +12,62 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
var mobile = self.traits.Get<Mobile>();
|
var mobile = self.traits.Get<Mobile>();
|
||||||
|
|
||||||
if( isHarvesting ) return null;
|
if( isHarvesting ) return this;
|
||||||
|
if( NextActivity != null ) return NextActivity;
|
||||||
if( NextActivity != null )
|
|
||||||
return NextActivity;
|
|
||||||
|
|
||||||
var harv = self.traits.Get<Harvester>();
|
var harv = self.traits.Get<Harvester>();
|
||||||
|
|
||||||
if( harv.IsFull )
|
if( harv.IsFull )
|
||||||
return new DeliverOre { NextActivity = NextActivity };
|
return new DeliverOre { NextActivity = NextActivity };
|
||||||
|
|
||||||
var isGem = false;
|
if (HarvestThisTile(self))
|
||||||
if( Rules.Map.ContainsResource( self.Location ) &&
|
return this;
|
||||||
Rules.Map.Harvest( self.Location, out isGem ) )
|
|
||||||
{
|
|
||||||
var harvestAnim = "harvest" + Util.QuantizeFacing( unit.Facing, 8 );
|
|
||||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
|
||||||
if( harvestAnim != renderUnit.anim.CurrentSequence.Name )
|
|
||||||
{
|
|
||||||
isHarvesting = true;
|
|
||||||
renderUnit.PlayCustomAnimation( self, harvestAnim, () => isHarvesting = false );
|
|
||||||
}
|
|
||||||
harv.AcceptResource( isGem );
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self.QueueActivity( new Move(
|
FindMoreOre(self);
|
||||||
() =>
|
|
||||||
{
|
|
||||||
var search = new PathSearch
|
|
||||||
{
|
|
||||||
heuristic = loc => ( Rules.Map.ContainsResource( loc ) ? 0 : 1 ),
|
|
||||||
umt = UnitMovementType.Wheel,
|
|
||||||
checkForBlocked = true
|
|
||||||
};
|
|
||||||
search.AddInitialCell( self.Location );
|
|
||||||
return Game.PathFinder.FindPath( search );
|
|
||||||
} ) );
|
|
||||||
self.QueueActivity( new Harvest() );
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HarvestThisTile(Actor self)
|
||||||
|
{
|
||||||
|
var unit = self.traits.Get<Unit>();
|
||||||
|
var harv = self.traits.Get<Harvester>();
|
||||||
|
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
||||||
|
|
||||||
|
var isGem = false;
|
||||||
|
if (!Rules.Map.ContainsResource(self.Location) ||
|
||||||
|
!Rules.Map.Harvest(self.Location, out isGem))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
|
||||||
|
|
||||||
|
if (harvestAnim != renderUnit.anim.CurrentSequence.Name)
|
||||||
|
{
|
||||||
|
isHarvesting = true;
|
||||||
|
renderUnit.PlayCustomAnimation(self, harvestAnim, () => isHarvesting = false);
|
||||||
|
}
|
||||||
|
harv.AcceptResource(isGem);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FindMoreOre(Actor self)
|
||||||
|
{
|
||||||
|
self.QueueActivity(new Move(
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
var search = new PathSearch
|
||||||
|
{
|
||||||
|
heuristic = loc => (Rules.Map.ContainsResource(loc) ? 0 : 1),
|
||||||
|
umt = UnitMovementType.Wheel,
|
||||||
|
checkForBlocked = true
|
||||||
|
};
|
||||||
|
search.AddInitialCell(self.Location);
|
||||||
|
return Game.PathFinder.FindPath(search);
|
||||||
|
}));
|
||||||
|
self.QueueActivity(new Harvest());
|
||||||
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { }
|
public void Cancel(Actor self) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
OpenRa.Game/Traits/Activities/Idle.cs
Normal file
15
OpenRa.Game/Traits/Activities/Idle.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Traits.Activities
|
||||||
|
{
|
||||||
|
class Idle : IActivity
|
||||||
|
{
|
||||||
|
public IActivity NextActivity { get; set; }
|
||||||
|
|
||||||
|
public IActivity Tick(Actor self) { return NextActivity; }
|
||||||
|
public void Cancel(Actor self) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
if( move != null )
|
if( move != null )
|
||||||
{
|
{
|
||||||
move.TickMove( self, mobile, this );
|
move.TickMove( self, mobile, this );
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination == self.Location )
|
if( destination == self.Location )
|
||||||
@@ -74,14 +74,14 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
if( path.Count == 0 )
|
if( path.Count == 0 )
|
||||||
{
|
{
|
||||||
destination = mobile.toCell;
|
destination = mobile.toCell;
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
destination = path[ 0 ];
|
destination = path[ 0 ];
|
||||||
|
|
||||||
var nextCell = PopPath( self, mobile );
|
var nextCell = PopPath( self, mobile );
|
||||||
if( nextCell == null )
|
if( nextCell == null )
|
||||||
return null;
|
return NextActivity;
|
||||||
|
|
||||||
int2 dir = nextCell.Value - mobile.fromCell;
|
int2 dir = nextCell.Value - mobile.fromCell;
|
||||||
var firstFacing = Util.GetFacing( dir, unit.Facing );
|
var firstFacing = Util.GetFacing( dir, unit.Facing );
|
||||||
@@ -103,7 +103,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
|
|
||||||
move.TickMove( self, mobile, this );
|
move.TickMove( self, mobile, this );
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
Util.TickFacing( ref unit.Facing, desiredFacing, self.Info.ROT );
|
Util.TickFacing( ref unit.Facing, desiredFacing, self.Info.ROT );
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel( Actor self )
|
public void Cancel( Actor self )
|
||||||
|
|||||||
Reference in New Issue
Block a user