Start thinking about how the harv<->proc interaction is going to work

This commit is contained in:
Paul Chote
2010-02-01 00:58:57 +13:00
parent 4fcb655e2c
commit 249c56d82f
9 changed files with 56 additions and 11 deletions

View File

@@ -117,7 +117,7 @@
<Compile Include="Support\OpenAlInterop.cs" /> <Compile Include="Support\OpenAlInterop.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />
<Compile Include="Traits\AcceptsOre.cs" /> <Compile Include="Traits\OreRefinery.cs" />
<Compile Include="Traits\Activities\Attack.cs" /> <Compile Include="Traits\Activities\Attack.cs" />
<Compile Include="Traits\Activities\CallFunc.cs" /> <Compile Include="Traits\Activities\CallFunc.cs" />
<Compile Include="Traits\Activities\EnterTransport.cs" /> <Compile Include="Traits\Activities\EnterTransport.cs" />
@@ -251,6 +251,7 @@
<Compile Include="Traits\StoresOre.cs" /> <Compile Include="Traits\StoresOre.cs" />
<Compile Include="Traits\Submarine.cs" /> <Compile Include="Traits\Submarine.cs" />
<Compile Include="Traits\TakeCover.cs" /> <Compile Include="Traits\TakeCover.cs" />
<Compile Include="Traits\TiberiumRefinery.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" /> <Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Turreted.cs" /> <Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\Unit.cs" /> <Compile Include="Traits\Unit.cs" />

View File

@@ -15,7 +15,8 @@ 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 ); static readonly int2 refineryDeliverOffset = new int2( 1, 2 );
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
@@ -26,6 +27,8 @@ namespace OpenRa.Traits.Activities
if( isDone ) if( isDone )
{ {
self.traits.Get<Harvester>().Deliver( self, refinery ); self.traits.Get<Harvester>().Deliver( self, refinery );
refinery.traits.Get<IAcceptOre>().OnDock(self);
return NextActivity ?? new Harvest(); return NextActivity ?? new Harvest();
} }
else if( NextActivity != null ) else if( NextActivity != null )
@@ -43,7 +46,7 @@ namespace OpenRa.Traits.Activities
checkForBlocked = false, checkForBlocked = false,
}; };
var refineries = self.World.Queries.OwnedBy[self.Owner] var refineries = self.World.Queries.OwnedBy[self.Owner]
.Where( x => x.traits.Contains<AcceptsOre>()) .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 + refineryDeliverOffset );
@@ -62,6 +65,7 @@ namespace OpenRa.Traits.Activities
// no refineries reachable? // no refineries reachable?
return this; return this;
} }
// TODO: This belongs in the refinery trait
else if( unit.Facing != 64 ) else if( unit.Facing != 64 )
return new Turn( 64 ) { NextActivity = this }; return new Turn( 64 ) { NextActivity = this };

View File

@@ -38,7 +38,7 @@ namespace OpenRa.Traits
if (underCursor != null if (underCursor != null
&& underCursor.Owner == self.Owner && underCursor.Owner == self.Owner
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty) && underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
return new Order("Deliver", self, underCursor); return new Order("Deliver", self, underCursor);
if (underCursor == null && self.World.Map.ContainsResource(xy)) if (underCursor == null && self.World.Map.ContainsResource(xy))

View File

@@ -2,14 +2,14 @@
namespace OpenRa.Traits namespace OpenRa.Traits
{ {
class AcceptsOreInfo : ITraitInfo class OreRefineryInfo : ITraitInfo
{ {
public object Create(Actor self) { return new AcceptsOre(self); } public object Create(Actor self) { return new OreRefinery(self); }
} }
class AcceptsOre class OreRefinery : IAcceptOre
{ {
public AcceptsOre(Actor self) public OreRefinery(Actor self)
{ {
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w =>
@@ -21,5 +21,7 @@ namespace OpenRa.Traits
harvester.QueueActivity(new Harvest()); harvester.QueueActivity(new Harvest());
}); });
} }
public void OnDock(Actor harv) {}
} }
} }

View File

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

View File

@@ -0,0 +1,32 @@
using OpenRa.Traits.Activities;
namespace OpenRa.Traits
{
class TiberiumRefineryInfo : ITraitInfo
{
public object Create(Actor self) { return new TiberiumRefinery(self); }
}
class TiberiumRefinery : IAcceptOre
{
Actor self;
public TiberiumRefinery(Actor self)
{
this.self = self;
self.World.AddFrameEndTask(
w =>
{ /* create the free harvester! */
var harvester = w.CreateActor("harv", self.Location + new int2(1, 2), self.Owner);
var unit = harvester.traits.Get<Unit>();
var mobile = harvester.traits.Get<Mobile>();
unit.Facing = 64;
harvester.QueueActivity(new Harvest());
});
}
public void OnDock(Actor harv)
{
self.traits.Get<RenderBuilding>().PlayCustomAnim(self, "active");
}
}
}

View File

@@ -21,7 +21,7 @@ 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 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

@@ -54,7 +54,7 @@ PROC:
Armor: wood Armor: wood
Crewed: yes Crewed: yes
Sight: 4 Sight: 4
AcceptsOre: TiberiumRefinery:
StoresOre: StoresOre:
Pips: 17 Pips: 17
Capacity: 1000 Capacity: 1000

View File

@@ -1256,7 +1256,7 @@ PROC:
Armor: wood Armor: wood
Crewed: yes Crewed: yes
Sight: 6 Sight: 6
AcceptsOre: OreRefinery:
StoresOre: StoresOre:
Pips: 17 Pips: 17
Capacity: 2000 Capacity: 2000