harvester actually sortof works now
This commit is contained in:
@@ -78,6 +78,7 @@
|
|||||||
<Compile Include="OrderManager.cs" />
|
<Compile Include="OrderManager.cs" />
|
||||||
<Compile Include="Traits\AcceptsOre.cs" />
|
<Compile Include="Traits\AcceptsOre.cs" />
|
||||||
<Compile Include="Traits\Activities\Activity.cs" />
|
<Compile Include="Traits\Activities\Activity.cs" />
|
||||||
|
<Compile Include="Traits\Activities\DeliverOre.cs" />
|
||||||
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Bullet.cs" />
|
<Compile Include="Bullet.cs" />
|
||||||
|
|||||||
34
OpenRa.Game/Traits/Activities/DeliverOre.cs
Normal file
34
OpenRa.Game/Traits/Activities/DeliverOre.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Traits.Activities
|
||||||
|
{
|
||||||
|
class DeliverOre : Activity
|
||||||
|
{
|
||||||
|
public Activity NextActivity { get; set; }
|
||||||
|
|
||||||
|
bool isDone;
|
||||||
|
|
||||||
|
public void Tick(Actor self, Mobile mobile)
|
||||||
|
{
|
||||||
|
if (isDone)
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(NextActivity);
|
||||||
|
/* todo: return to the ore patch */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
|
||||||
|
if (renderUnit.anim.CurrentSequence.Name != "empty")
|
||||||
|
renderUnit.PlayCustomAnimation(self, "empty",
|
||||||
|
() => isDone = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Cancel(Actor self, Mobile mobile)
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
class Harvest : Activity
|
class Harvest : Activity
|
||||||
{
|
{
|
||||||
public Activity NextActivity { get; set; }
|
public Activity NextActivity { get; set; }
|
||||||
|
bool isHarvesting = false;
|
||||||
|
|
||||||
public void Tick(Actor self, Mobile mobile)
|
public void Tick(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
@@ -18,10 +19,16 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
Game.map.ContainsResource(self.Location) &&
|
Game.map.ContainsResource(self.Location) &&
|
||||||
Game.map.Harvest(self.Location, out isGem))
|
Game.map.Harvest(self.Location, out isGem))
|
||||||
{
|
{
|
||||||
|
var harvestAnim = "harvest" + Util.QuantizeFacing(mobile.facing, 8);
|
||||||
|
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
||||||
|
if (harvestAnim != renderUnit.anim.CurrentSequence.Name)
|
||||||
|
renderUnit.PlayCustomAnimation(self, harvestAnim, () => isHarvesting = false);
|
||||||
harv.AcceptResource(isGem);
|
harv.AcceptResource(isGem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isHarvesting) return;
|
||||||
|
|
||||||
if (harv.IsFull)
|
if (harv.IsFull)
|
||||||
PlanReturnToBase(self, mobile);
|
PlanReturnToBase(self, mobile);
|
||||||
else
|
else
|
||||||
@@ -47,7 +54,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
|
|
||||||
mobile.QueueActivity(new Move(proc.Location + new int2(1, 2)));
|
mobile.QueueActivity(new Move(proc.Location + new int2(1, 2)));
|
||||||
mobile.QueueActivity(new Turn(64));
|
mobile.QueueActivity(new Turn(64));
|
||||||
/* todo: DeliverOre activity */
|
mobile.QueueActivity(new DeliverOre());
|
||||||
|
|
||||||
mobile.InternalSetActivity(NextActivity);
|
mobile.InternalSetActivity(NextActivity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,19 +53,12 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
string currentSequence;
|
string currentSequence;
|
||||||
|
|
||||||
static int QuantizeFacing(int facing, int n)
|
|
||||||
{
|
|
||||||
var step = 256 / n;
|
|
||||||
var a = (facing + step/2) & 0xff;
|
|
||||||
return a / step;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaySequence(string seq, bool isFacing)
|
void PlaySequence(string seq, bool isFacing)
|
||||||
{
|
{
|
||||||
if (currentSequence == seq) return;
|
if (currentSequence == seq) return;
|
||||||
|
|
||||||
if (isFacing)
|
if (isFacing)
|
||||||
anim.PlayFetchIndex(seq, () => QuantizeFacing(facing, anim.CurrentSequence.Length));
|
anim.PlayFetchIndex(seq, () => Util.QuantizeFacing(facing, anim.CurrentSequence.Length));
|
||||||
else
|
else
|
||||||
anim.PlayRepeatingPreservingPosition(seq);
|
anim.PlayRepeatingPreservingPosition(seq);
|
||||||
|
|
||||||
@@ -77,7 +70,7 @@ namespace OpenRa.Game.Traits
|
|||||||
name = type;
|
name = type;
|
||||||
anim = new Animation(type);
|
anim = new Animation(type);
|
||||||
anim.PlayFetchIndex("stand",
|
anim.PlayFetchIndex("stand",
|
||||||
() => QuantizeFacing(facing, anim.CurrentSequence.Length));
|
() => Util.QuantizeFacing(facing, anim.CurrentSequence.Length));
|
||||||
location = initialLocation;
|
location = initialLocation;
|
||||||
speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
|
speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
|
||||||
}
|
}
|
||||||
@@ -92,7 +85,7 @@ namespace OpenRa.Game.Traits
|
|||||||
if (float2.WithinEpsilon(d, float2.Zero, .1f))
|
if (float2.WithinEpsilon(d, float2.Zero, .1f))
|
||||||
PlaySequence("stand", true);
|
PlaySequence("stand", true);
|
||||||
else
|
else
|
||||||
PlaySequence("run-" + QuantizeFacing(facing, 8), false);
|
PlaySequence("run-" + Util.QuantizeFacing(facing, 8), false);
|
||||||
|
|
||||||
if (d.Length <= speed)
|
if (d.Length <= speed)
|
||||||
location = desiredLocation;
|
location = desiredLocation;
|
||||||
|
|||||||
@@ -12,9 +12,19 @@ namespace OpenRa.Game.Traits
|
|||||||
public RenderUnit(Actor self)
|
public RenderUnit(Actor self)
|
||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
anim.PlayFetchIndex("idle",
|
PlayFacingAnim(self);
|
||||||
() => self.traits.Get<Mobile>().facing
|
}
|
||||||
/ (256/anim.CurrentSequence.Length));
|
|
||||||
|
void PlayFacingAnim(Actor self)
|
||||||
|
{
|
||||||
|
anim.PlayFetchIndex("idle",
|
||||||
|
() => self.traits.Get<Mobile>().facing
|
||||||
|
/ (256 / anim.CurrentSequence.Length));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||||
|
{
|
||||||
|
anim.PlayThen(newAnim, () => { PlayFacingAnim(self); if (after != null) after(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ namespace OpenRa.Game.Traits
|
|||||||
return facing + turn;
|
return facing + turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int QuantizeFacing(int facing, int numFrames)
|
||||||
|
{
|
||||||
|
var step = 256 / numFrames;
|
||||||
|
var a = (facing + step / 2) & 0xff;
|
||||||
|
return a / step;
|
||||||
|
}
|
||||||
|
|
||||||
static float2 RotateVectorByFacing(float2 v, int facing, float ecc)
|
static float2 RotateVectorByFacing(float2 v, int facing, float ecc)
|
||||||
{
|
{
|
||||||
var angle = (facing / 256f) * (2 * (float)Math.PI);
|
var angle = (facing / 256f) * (2 * (float)Math.PI);
|
||||||
|
|||||||
@@ -57,10 +57,9 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
var mobile = order.Subject.traits.Get<Mobile>();
|
var mobile = order.Subject.traits.Get<Mobile>();
|
||||||
mobile.Cancel(order.Subject);
|
mobile.Cancel(order.Subject);
|
||||||
mobile.QueueActivity( new Traits.Activities.Move( order.TargetActor.Location + new int2( 1, 2 ) ) );
|
mobile.QueueActivity(new Traits.Activities.Move(order.TargetActor.Location + new int2(1, 2)));
|
||||||
mobile.QueueActivity( new Traits.Activities.Turn( 64 ) );
|
mobile.QueueActivity(new Traits.Activities.Turn(64));
|
||||||
|
mobile.QueueActivity(new Traits.Activities.DeliverOre());
|
||||||
/* todo: actual deliver activity! [animation + add cash] */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "Harvest":
|
case "Harvest":
|
||||||
|
|||||||
Reference in New Issue
Block a user