Link harvesters with refineries.

This commit is contained in:
Paul Chote
2010-06-15 18:46:09 +12:00
parent f4421d89ea
commit 5f83f97747
6 changed files with 435 additions and 328 deletions

View File

@@ -48,6 +48,11 @@ namespace OpenRA.Graphics
palette = new HardwarePalette(renderer, world.Map); palette = new HardwarePalette(renderer, world.Map);
} }
public void DrawLine(float2 start, float2 end, Color startColor, Color endColor)
{
lineRenderer.DrawLine(start,end,startColor,endColor);
}
public int GetPaletteIndex(string name) public int GetPaletteIndex(string name)
{ {
return palette.GetPaletteIndex(name); return palette.GetPaletteIndex(name);

View File

@@ -1,118 +1,151 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Mods.RA; using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
using System.Drawing;
namespace OpenRA.Mods.Cnc
{ namespace OpenRA.Mods.Cnc
class TiberiumRefineryInfo : ITraitInfo {
{ class TiberiumRefineryInfo : ITraitInfo
public readonly int PipCount = 0; {
public readonly PipType PipColor = PipType.Red; public readonly int PipCount = 0;
public readonly int Capacity = 0; public readonly PipType PipColor = PipType.Red;
public readonly int ProcessTick = 25; public readonly int Capacity = 0;
public readonly int ProcessAmount = 50; public readonly int ProcessTick = 25;
public readonly string DeathWeapon = null; public readonly int ProcessAmount = 50;
public object Create(Actor self) { return new TiberiumRefinery(self, this); } public readonly string DeathWeapon = null;
} public object Create(Actor self) { return new TiberiumRefinery(self, this); }
}
class TiberiumRefinery : ITick, IAcceptOre, INotifyDamage, IPips
{ class TiberiumRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips
readonly Actor self; {
readonly TiberiumRefineryInfo Info; readonly Actor self;
readonly PlayerResources Player; readonly TiberiumRefineryInfo Info;
readonly PlayerResources Player;
[Sync] List<Actor> LinkedHarv;
int nextProcessTime = 0;
[Sync] [Sync]
public int Tiberium = 0; int nextProcessTime = 0;
[Sync]
public TiberiumRefinery(Actor self, TiberiumRefineryInfo info) public int Tiberium = 0;
{
this.self = self; public TiberiumRefinery(Actor self, TiberiumRefineryInfo info)
Info = info; {
Player = self.Owner.PlayerActor.traits.Get<PlayerResources>(); this.self = self;
Info = info;
} Player = self.Owner.PlayerActor.traits.Get<PlayerResources>();
LinkedHarv = new List<Actor>();
public void GiveOre(int amount) }
{
Tiberium += amount; public void LinkHarvester(Actor self, Actor harv)
if (Tiberium > Info.Capacity) {
Tiberium = Info.Capacity; LinkedHarv.Add(harv);
} }
public void Tick(Actor self) public void UnlinkHarvester(Actor self, Actor harv)
{ {
if (--nextProcessTime <= 0) if (LinkedHarv.Contains(harv))
{ LinkedHarv.Remove(harv);
// Convert resources to cash }
int amount = Math.Min(Tiberium, Info.ProcessAmount);
amount = Math.Min(amount, Player.OreCapacity - Player.Ore); public void GiveOre(int amount)
{
if (amount > 0) Tiberium += amount;
{ if (Tiberium > Info.Capacity)
Tiberium -=amount; Tiberium = Info.Capacity;
Player.GiveOre(amount); }
}
nextProcessTime = Info.ProcessTick; public void Tick(Actor self)
} {
} if (--nextProcessTime <= 0)
{
public void Damaged(Actor self, AttackInfo e) // Convert resources to cash
{ int amount = Math.Min(Tiberium, Info.ProcessAmount);
if (self.IsDead && Tiberium > 0) amount = Math.Min(amount, Player.OreCapacity - Player.Ore);
{
if (Info.DeathWeapon != null) if (amount > 0)
{ {
Combat.DoExplosion(e.Attacker, Info.DeathWeapon, Tiberium -=amount;
self.CenterLocation.ToInt2(), 0); Player.GiveOre(amount);
} }
} nextProcessTime = Info.ProcessTick;
} }
}
public int2 DeliverOffset { get { return new int2(0, 2); } }
public void OnDock(Actor harv, DeliverResources dockOrder) public void Damaged(Actor self, AttackInfo e)
{ {
// Todo: need to be careful about cancellation and multiple harvs if (self.IsDead)
harv.QueueActivity(new Move(self.Location + new int2(1,1), self)); {
harv.QueueActivity(new Turn(96)); if (Info.DeathWeapon != null && Tiberium > 0)
harv.QueueActivity( new CallFunc( () => {
self.traits.Get<RenderBuilding>().PlayCustomAnimThen(self, "active", () => { Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
harv.traits.Get<Harvester>().Deliver(harv, self); self.CenterLocation.ToInt2(), 0);
harv.QueueActivity(new Move(self.Location + DeliverOffset, self)); }
harv.QueueActivity(new Harvest());
}))); foreach (var harv in LinkedHarv)
} harv.traits.Get<Harvester>().UnlinkProc(harv, self);
}
public IEnumerable<PipType> GetPips(Actor self) }
{
return Graphics.Util.MakeArray( Info.PipCount, public int2 DeliverOffset { get { return new int2(0, 2); } }
i => (Tiberium * 1.0f / Info.Capacity > i * 1.0f / Info.PipCount) public void OnDock(Actor harv, DeliverResources dockOrder)
? Info.PipColor : PipType.Transparent ); {
} // Todo: need to be careful about cancellation and multiple harvs
} harv.QueueActivity(new Move(self.Location + new int2(1,1), self));
} harv.QueueActivity(new Turn(96));
harv.QueueActivity( new CallFunc( () =>
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());
})));
}
public void OnCapture(Actor self, Actor captor)
{
// Todo: Do the right thing if a harv is docked
// Unlink any other harvs
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester>().UnlinkProc(harv, self);
}
public void Selling(Actor self) {}
public void Sold(Actor self)
{
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester>().UnlinkProc(harv, self);
}
public IEnumerable<PipType> GetPips(Actor self)
{
return Graphics.Util.MakeArray( Info.PipCount,
i => (Tiberium * 1.0f / Info.Capacity > i * 1.0f / Info.PipCount)
? Info.PipColor : PipType.Transparent );
}
}
}

View File

@@ -29,64 +29,28 @@ namespace OpenRA.Mods.RA.Activities
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
bool isDocking; bool isDocking;
Actor refinery;
public DeliverResources() { } public DeliverResources() { }
public DeliverResources( Actor refinery )
{
this.refinery = refinery;
}
Actor ChooseRefinery(Actor self)
{
var mobile = self.traits.Get<Mobile>();
var search = new PathSearch(self.World)
{
heuristic = PathSearch.DefaultEstimator(self.Location),
umt = mobile.GetMovementType(),
checkForBlocked = false,
};
var refineries = self.World.Queries.OwnedBy[self.Owner]
.Where(x => x.traits.Contains<IAcceptOre>())
.ToList();
if (refinery != null)
search.AddInitialCell(self.World, refinery.Location + refinery.traits.Get<IAcceptOre>().DeliverOffset);
else
foreach (var r in refineries)
search.AddInitialCell(self.World, r.Location + r.traits.Get<IAcceptOre>().DeliverOffset);
var path = self.World.PathFinder.FindPath(search);
path.Reverse();
if (path.Count != 0)
return refineries.FirstOrDefault(x => x.Location + x.traits.Get<IAcceptOre>().DeliverOffset == path[0]);
else
return null;
}
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
if( NextActivity != null ) if( NextActivity != null )
return NextActivity; return NextActivity;
if( refinery != null && refinery.IsDead ) var proc = self.traits.Get<Harvester>().LinkedProc;
refinery = null;
if (proc == null)
if( refinery == null || self.Location != refinery.Location + refinery.traits.Get<IAcceptOre>().DeliverOffset ) return new Wait(10) { NextActivity = this };
if( self.Location != proc.Location + proc.traits.Get<IAcceptOre>().DeliverOffset )
{ {
refinery = ChooseRefinery(self); return new Move(proc.Location + proc.traits.Get<IAcceptOre>().DeliverOffset, 0) { NextActivity = this };
if (refinery == null)
return new Wait(10) { NextActivity = this };
return new Move(refinery.Location + refinery.traits.Get<IAcceptOre>().DeliverOffset, 0) { NextActivity = this };
} }
else if (!isDocking) else if (!isDocking)
{ {
isDocking = true; isDocking = true;
refinery.traits.Get<IAcceptOre>().OnDock(self, this); proc.traits.Get<IAcceptOre>().OnDock(self, this);
} }
return new Wait(10) { NextActivity = this }; return new Wait(10) { NextActivity = this };
} }

View File

@@ -1,124 +1,184 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class HarvesterInfo : ITraitInfo public class HarvesterInfo : ITraitInfo
{ {
public readonly int Capacity = 28; public readonly int Capacity = 28;
public readonly int PipCount = 7; public readonly int PipCount = 7;
public readonly PipType PipColor = PipType.Yellow; public readonly PipType PipColor = PipType.Yellow;
public readonly string[] Resources = { }; public readonly string[] Resources = { };
public readonly string DeathWeapon = null; public readonly string DeathWeapon = null;
public object Create(Actor self) { return new Harvester(self, this); } public object Create(Actor self) { return new Harvester(self, this); }
} }
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips
{ {
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>(); Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
public Actor LinkedProc = null;
readonly HarvesterInfo Info;
public Harvester(Actor self, HarvesterInfo info) readonly HarvesterInfo Info;
{ public Harvester(Actor self, HarvesterInfo info)
Info = info; {
} Info = info;
self.QueueActivity( new CallFunc( () => ChooseNewProc(self, null)));
public bool IsFull { get { return contents.Values.Sum() == Info.Capacity; } } }
public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
void ChooseNewProc(Actor self, Actor ignore)
public void AcceptResource(ResourceType type) {
{ LinkedProc = ClosestProc(self, ignore);
if (!contents.ContainsKey(type.info)) contents[type.info] = 1; if (LinkedProc != null)
else contents[type.info]++; LinkedProc.traits.WithInterface<IAcceptOre>().FirstOrDefault().LinkHarvester(LinkedProc,self);
} }
public void Deliver(Actor self, Actor proc) Actor ClosestProc(Actor self, Actor ignore)
{ {
proc.traits.Get<IAcceptOre>().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value)); var mobile = self.traits.Get<Mobile>();
contents.Clear();
} var search = new PathSearch(self.World)
{
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) heuristic = PathSearch.DefaultEstimator(self.Location),
{ umt = mobile.GetMovementType(),
if (mi.Button == MouseButton.Left) return null; checkForBlocked = false,
};
if (underCursor != null var refineries = self.World.Queries.OwnedBy[self.Owner]
&& underCursor.Owner == self.Owner .Where(x => x != ignore && x.traits.Contains<IAcceptOre>())
&& underCursor.traits.Contains<IAcceptOre>() && !IsEmpty) .ToList();
return new Order("Deliver", self, underCursor);
foreach (var r in refineries)
var res = self.World.WorldActor.traits.Get<ResourceLayer>().GetResource(xy); search.AddInitialCell(self.World, r.Location + r.traits.Get<IAcceptOre>().DeliverOffset);
var info = self.Info.Traits.Get<HarvesterInfo>();
var path = self.World.PathFinder.FindPath(search);
if (underCursor == null && res != null && info.Resources.Contains(res.info.Name)) path.Reverse();
return new Order("Harvest", self, xy); if (path.Count != 0)
return refineries.FirstOrDefault(x => x.Location + x.traits.Get<IAcceptOre>().DeliverOffset == path[0]);
return null; else
} return null;
}
public void ResolveOrder(Actor self, Order order)
{ public bool IsFull { get { return contents.Values.Sum() == Info.Capacity; } }
if (order.OrderString == "Harvest") public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
{
self.CancelActivity(); public void AcceptResource(ResourceType type)
self.QueueActivity(new Move(order.TargetLocation, 0)); {
self.QueueActivity(new Harvest()); if (!contents.ContainsKey(type.info)) contents[type.info] = 1;
} else contents[type.info]++;
else if (order.OrderString == "Deliver") }
{
self.CancelActivity(); public void Deliver(Actor self, Actor proc)
self.QueueActivity(new DeliverResources(order.TargetActor)); {
} proc.traits.Get<IAcceptOre>().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
} contents.Clear();
}
public void Damaged(Actor self, AttackInfo e)
{ public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
if (self.IsDead && contents.Count > 0) {
{ if (mi.Button == MouseButton.Left) return null;
if (Info.DeathWeapon != null)
{ if (underCursor != null
Combat.DoExplosion(e.Attacker, Info.DeathWeapon, && underCursor.Owner == self.Owner
self.CenterLocation.ToInt2(), 0); && underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
} {
} return new Order("Deliver", self, underCursor);
} }
var res = self.World.WorldActor.traits.Get<ResourceLayer>().GetResource(xy);
public IEnumerable<PipType> GetPips(Actor self) var info = self.Info.Traits.Get<HarvesterInfo>();
{
int numPips = Info.PipCount; if (underCursor == null && res != null && info.Resources.Contains(res.info.Name))
int n = contents.Values.Sum(); return new Order("Harvest", self, xy);
for (int i = 0; i < numPips; i++) return null;
{ }
if (n * 1.0f / Info.Capacity > i * 1.0f / numPips)
yield return Info.PipColor; public void ResolveOrder(Actor self, Order order)
else {
yield return PipType.Transparent; if (order.OrderString == "Harvest")
} {
} self.CancelActivity();
} self.QueueActivity(new Move(order.TargetLocation, 0));
} self.QueueActivity(new Harvest());
}
else if (order.OrderString == "Deliver")
{
self.CancelActivity();
if (order.TargetActor != LinkedProc)
{
if (LinkedProc != null)
LinkedProc.traits.WithInterface<IAcceptOre>().FirstOrDefault().UnlinkHarvester(LinkedProc,self);
LinkedProc = order.TargetActor;
LinkedProc.traits.WithInterface<IAcceptOre>().FirstOrDefault().LinkHarvester(LinkedProc,self);
}
self.QueueActivity(new DeliverResources());
}
}
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead)
{
if (Info.DeathWeapon != null && contents.Count > 0)
{
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
self.CenterLocation.ToInt2(), 0);
}
if (LinkedProc != null)
LinkedProc.traits.WithInterface<IAcceptOre>().FirstOrDefault().UnlinkHarvester(LinkedProc,self);
}
}
public void LinkProc(Actor self, Actor proc)
{
LinkedProc = proc;
}
public void UnlinkProc(Actor self, Actor proc)
{
if (LinkedProc != proc)
return;
ChooseNewProc(self, proc);
}
public IEnumerable<PipType> GetPips(Actor self)
{
int numPips = Info.PipCount;
int n = contents.Values.Sum();
for (int i = 0; i < numPips; i++)
{
if (n * 1.0f / Info.Capacity > i * 1.0f / numPips)
yield return Info.PipColor;
else
yield return PipType.Transparent;
}
}
}
}

View File

@@ -34,72 +34,115 @@ namespace OpenRA.Mods.RA
public readonly int Capacity = 0; public readonly int Capacity = 0;
public readonly int ProcessTick = 25; public readonly int ProcessTick = 25;
public readonly int ProcessAmount = 50; public readonly int ProcessAmount = 50;
public object Create(Actor self) { return new OreRefinery(self, this); } public readonly string DeathWeapon = null;
public object Create (Actor self)
{
return new OreRefinery (self, this);
}
} }
class OreRefinery : ITick, IAcceptOre, IPips class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips
{ {
Actor self; readonly Actor self;
OreRefineryInfo Info; readonly OreRefineryInfo Info;
readonly PlayerResources Player;
List<Actor> LinkedHarv;
[Sync] [Sync]
int nextProcessTime = 0; int nextProcessTime = 0;
[Sync] [Sync]
public int Ore = 0; public int Ore = 0;
public OreRefinery(Actor self, OreRefineryInfo info)
public OreRefinery (Actor self, OreRefineryInfo info)
{ {
this.self = self; this.self = self;
Info = info; Info = info;
Player = self.Owner.PlayerActor.traits.Get<PlayerResources> ();
LinkedHarv = new List<Actor> ();
} }
public void GiveOre(int amount) public void LinkHarvester (Actor self, Actor harv)
{
LinkedHarv.Add (harv);
}
public void UnlinkHarvester (Actor self, Actor harv)
{
if (LinkedHarv.Contains (harv))
LinkedHarv.Remove (harv);
}
public void GiveOre (int amount)
{ {
Ore += amount; Ore += amount;
if (Ore > Info.Capacity) if (Ore > Info.Capacity)
Ore = Info.Capacity; Ore = Info.Capacity;
} }
public void Tick(Actor self) public void Tick (Actor self)
{ {
if (--nextProcessTime <= 0) if (--nextProcessTime <= 0) {
{
// Convert resources to cash // Convert resources to cash
var pr = self.Owner.PlayerActor.traits.Get<PlayerResources>(); int amount = Math.Min (Ore, Info.ProcessAmount);
int amount = Math.Min(Ore, Info.ProcessAmount); amount = Math.Min (amount, Player.OreCapacity - Player.Ore);
amount = Math.Min(amount, pr.OreCapacity - pr.Ore);
if (amount > 0) if (amount > 0) {
{ Ore -= amount;
Ore -=amount; Player.GiveOre (amount);
pr.GiveOre(amount);
} }
nextProcessTime = Info.ProcessTick; nextProcessTime = Info.ProcessTick;
} }
} }
public IEnumerable<PipType> GetPips(Actor self) public void Damaged (Actor self, AttackInfo e)
{ {
return Graphics.Util.MakeArray( Info.PipCount, if (self.IsDead) {
i => (Ore * 1.0f / Info.Capacity > i * 1.0f / Info.PipCount) if (Info.DeathWeapon != null && Ore > 0) {
? Info.PipColor : PipType.Transparent ); Combat.DoExplosion (e.Attacker, Info.DeathWeapon, self.CenterLocation.ToInt2 (), 0);
}
public int2 DeliverOffset { get { return new int2(1, 2); } }
public void OnDock(Actor harv, DeliverResources dockOrder)
{
var unit = harv.traits.Get<Unit>();
if (unit.Facing != 64)
harv.QueueActivity(new Turn(64));
harv.QueueActivity( new CallFunc( () => {
var renderUnit = harv.traits.Get<RenderUnit>();
if (renderUnit.anim.CurrentSequence.Name != "empty")
renderUnit.PlayCustomAnimation(harv, "empty", () =>
{
harv.traits.Get<Harvester>().Deliver(harv, self);
harv.QueueActivity(new Harvest());
});
} }
));
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester> ().UnlinkProc (harv, self);
}
}
public int2 DeliverOffset {get{ return new int2 (1, 2); }}
public void OnDock (Actor harv, DeliverResources dockOrder)
{
var unit = harv.traits.Get<Unit> ();
if (unit.Facing != 64)
harv.QueueActivity (new Turn (64));
harv.QueueActivity (new CallFunc (() =>
{
var renderUnit = harv.traits.Get<RenderUnit> ();
if (renderUnit.anim.CurrentSequence.Name != "empty")
renderUnit.PlayCustomAnimation (harv, "empty", () =>
{
harv.traits.Get<Harvester> ().Deliver (harv, self);
harv.QueueActivity (new Harvest ());
});
}));
}
public void OnCapture (Actor self, Actor captor)
{
// Todo: Do the right thing if a harv is docked
// Unlink any other harvs
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester> ().UnlinkProc (harv, self);
}
public void Selling (Actor self) {}
public void Sold (Actor self)
{
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester> ().UnlinkProc (harv, self);
}
public IEnumerable<PipType> GetPips (Actor self)
{
return Graphics.Util.MakeArray (Info.PipCount, i => (Ore * 1f / Info.Capacity > i * 1f / Info.PipCount) ? Info.PipColor : PipType.Transparent);
} }
} }
} }

View File

@@ -26,6 +26,8 @@ namespace OpenRA.Mods.RA
{ {
void OnDock(Actor harv, DeliverResources dockOrder); void OnDock(Actor harv, DeliverResources dockOrder);
void GiveOre(int amount); void GiveOre(int amount);
void LinkHarvester(Actor self, Actor harv);
void UnlinkHarvester(Actor self, Actor harv);
int2 DeliverOffset { get; } int2 DeliverOffset { get; }
} }
} }