Flesh out guided-dock concept; regress on animation continuity in RA mod

This commit is contained in:
Paul Chote
2010-02-01 11:50:12 +13:00
parent 249c56d82f
commit d6f0839a1a
7 changed files with 47 additions and 28 deletions

View File

@@ -2,11 +2,12 @@
namespace OpenRa.Traits.Activities namespace OpenRa.Traits.Activities
{ {
class DeliverOre : IActivity public class DeliverOre : IActivity
{ {
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
bool isDone; bool isDone;
bool isDocking;
Actor refinery; Actor refinery;
public DeliverOre() { } public DeliverOre() { }
@@ -16,28 +17,18 @@ namespace OpenRa.Traits.Activities
this.refinery = refinery; this.refinery = refinery;
} }
// TODO: This belongs on the refinery itself
static readonly int2 refineryDeliverOffset = new int2( 1, 2 );
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
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( isDone ) if( NextActivity != null )
{
self.traits.Get<Harvester>().Deliver( self, refinery );
refinery.traits.Get<IAcceptOre>().OnDock(self);
return NextActivity ?? new Harvest();
}
else if( NextActivity != null )
return NextActivity; return NextActivity;
if( refinery != null && refinery.IsDead ) if( refinery != null && refinery.IsDead )
refinery = null; refinery = null;
if( refinery == null || self.Location != refinery.Location + refineryDeliverOffset ) if( refinery == null || self.Location != refinery.Location + refinery.traits.Get<IAcceptOre>().DeliverOffset )
{ {
var search = new PathSearch var search = new PathSearch
{ {
@@ -49,25 +40,27 @@ namespace OpenRa.Traits.Activities
.Where(x => x.traits.Contains<IAcceptOre>()) .Where(x => x.traits.Contains<IAcceptOre>())
.ToList(); .ToList();
if( refinery != null ) if( refinery != null )
search.AddInitialCell( self.World, refinery.Location + refineryDeliverOffset ); search.AddInitialCell(self.World, refinery.Location + refinery.traits.Get<IAcceptOre>().DeliverOffset);
else else
foreach( var r in refineries ) foreach( var r in refineries )
search.AddInitialCell( self.World, r.Location + refineryDeliverOffset ); search.AddInitialCell(self.World, r.Location + r.traits.Get<IAcceptOre>().DeliverOffset);
var path = self.World.PathFinder.FindPath( search ); var path = self.World.PathFinder.FindPath( search );
path.Reverse(); path.Reverse();
if( path.Count != 0 ) if( path.Count != 0 )
{ {
refinery = refineries.FirstOrDefault( x => x.Location + refineryDeliverOffset == path[ 0 ] ); refinery = refineries.FirstOrDefault(x => x.Location + x.traits.Get<IAcceptOre>().DeliverOffset == path[0]);
return new Move( () => path ) { NextActivity = this }; return new Move( () => path ) { NextActivity = this };
} }
else else
// no refineries reachable? // no refineries reachable?
return this; return this;
} }
// TODO: This belongs in the refinery trait else if (!isDocking)
else if( unit.Facing != 64 ) {
return new Turn( 64 ) { NextActivity = this }; isDocking = true;
refinery.traits.Get<IAcceptOre>().OnDock(self, this);
}
var renderUnit = self.traits.Get<RenderUnit>(); var renderUnit = self.traits.Get<RenderUnit>();
if( renderUnit.anim.CurrentSequence.Name != "empty" ) if( renderUnit.anim.CurrentSequence.Name != "empty" )

View File

@@ -9,8 +9,10 @@ namespace OpenRa.Traits
class OreRefinery : IAcceptOre class OreRefinery : IAcceptOre
{ {
Actor self;
public OreRefinery(Actor self) public OreRefinery(Actor self)
{ {
this.self = self;
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w =>
{ /* create the free harvester! */ { /* create the free harvester! */
@@ -21,7 +23,16 @@ namespace OpenRa.Traits
harvester.QueueActivity(new Harvest()); harvester.QueueActivity(new Harvest());
}); });
} }
public int2 DeliverOffset { get { return new int2(1, 2); } }
public void OnDock(Actor harv, DeliverOre dockOrder)
{
var unit = harv.traits.Get<Unit>();
if (unit.Facing != 64)
harv.QueueActivity(new Turn(64));
public void OnDock(Actor harv) {} // TODO: This should be delayed until the turn order is complete
harv.traits.Get<Harvester>().Deliver(harv, self);
harv.QueueActivity(new Harvest());
}
} }
} }

View File

@@ -65,7 +65,7 @@ namespace OpenRa.Traits
() => anim.PlayRepeating(GetPrefix(self) + "idle")); () => anim.PlayRepeating(GetPrefix(self) + "idle"));
} }
public void PlayCustomAnim(Actor self, string name, Action a) public void PlayCustomAnimThen(Actor self, string name, Action a)
{ {
anim.PlayThen(GetPrefix(self) + name, anim.PlayThen(GetPrefix(self) + name,
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); }); () => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Traits
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w =>
{ /* create the free harvester! */ { /* create the free harvester! */
var harvester = w.CreateActor("harv", self.Location + new int2(1, 2), self.Owner); var harvester = w.CreateActor("harv", self.Location + new int2(0, 2), self.Owner);
var unit = harvester.traits.Get<Unit>(); var unit = harvester.traits.Get<Unit>();
var mobile = harvester.traits.Get<Mobile>(); var mobile = harvester.traits.Get<Mobile>();
unit.Facing = 64; unit.Facing = 64;
@@ -24,9 +24,19 @@ namespace OpenRa.Traits
}); });
} }
public void OnDock(Actor harv) public int2 DeliverOffset { get { return new int2(0, 2); } }
public void OnDock(Actor harv, DeliverOre dockOrder)
{ {
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active"); var unit = harv.traits.Get<Unit>();
harv.QueueActivity(new Move(self.Location + DeliverOffset, self));
harv.QueueActivity(new Turn(96));
// TODO: This should be delayed until the turn order is complete
self.traits.Get<RenderBuilding>().PlayCustomAnimThen(self, "active", () => {
harv.traits.Get<Harvester>().Deliver(harv, self);
harv.QueueActivity(new Move(self.Location + DeliverOffset, self));
harv.QueueActivity(new Harvest());
});
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using System.Drawing;
using IjwFramework.Types; using IjwFramework.Types;
using OpenRa.GameRules; using OpenRa.GameRules;
using OpenRa.Graphics; using OpenRa.Graphics;
using OpenRa.Traits.Activities;
namespace OpenRa.Traits namespace OpenRa.Traits
{ {
@@ -21,7 +22,11 @@ namespace OpenRa.Traits
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
public interface INotifyProduction { void UnitProduced(Actor self, Actor other); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
public interface IAcceptOre { void OnDock(Actor harv); } public interface IAcceptOre
{
void OnDock(Actor harv, DeliverOre dockOrder);
int2 DeliverOffset { get; }
}
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); } public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }

View File

@@ -8,7 +8,7 @@ RefundPercent=50% ; percent of original cost to refund when building/unit
RepairRate=.016 ; minutes between applying repair step RepairRate=.016 ; minutes between applying repair step
URepairPercent=20% ; [units only] percent cost to fully repair as ratio of full cost URepairPercent=20% ; [units only] percent cost to fully repair as ratio of full cost
URepairStep=10 ; [units only] hit points to heal per repair 'tick' for units URepairStep=10 ; [units only] hit points to heal per repair 'tick' for units
BuildSpeed=.8 ; general build speed [time (in minutes) to produce a 1000 credit cost item] BuildSpeed=.1 ; general build speed [time (in minutes) to produce a 1000 credit cost item]
OreGrows=yes ; Does ore grow denser over time? OreGrows=yes ; Does ore grow denser over time?
OreSpreads=yes ; Does ore spread into adjacent areas OreSpreads=yes ; Does ore spread into adjacent areas

View File

@@ -46,7 +46,7 @@ PROC:
LongDesc: Processes Tiberium into useable resources LongDesc: Processes Tiberium into useable resources
Building: Building:
Power: -30 Power: -30
Footprint: ___ xxx x=x Footprint: ___ xxx ===
Dimensions: 3,3 Dimensions: 3,3
Capturable: true Capturable: true
Bib: yes Bib: yes