harvester can be fussy now.

This commit is contained in:
Chris Forbes
2010-03-03 21:56:33 +13:00
parent 40dbd3c9c5
commit 0e73431209
7 changed files with 31 additions and 30 deletions

View File

@@ -18,6 +18,8 @@
*/ */
#endregion #endregion
using System.Linq;
namespace OpenRA.Traits.Activities namespace OpenRA.Traits.Activities
{ {
public class Harvest : IActivity public class Harvest : IActivity
@@ -65,13 +67,15 @@ namespace OpenRA.Traits.Activities
void FindMoreOre(Actor self) void FindMoreOre(Actor self)
{ {
var res = self.World.WorldActor.traits.Get<ResourceLayer>(); var res = self.World.WorldActor.traits.Get<ResourceLayer>();
var harv = self.Info.Traits.Get<HarvesterInfo>();
self.QueueActivity(new Move( self.QueueActivity(new Move(
() => () =>
{ {
var search = new PathSearch var search = new PathSearch
{ {
heuristic = loc => (res.GetResource(loc) != null ? 0 : 1), heuristic = loc => (res.GetResource(loc) != null
&& harv.Resources.Any( r => res.GetResource(loc).Name == r )) ? 0 : 1,
umt = UnitMovementType.Wheel, umt = UnitMovementType.Wheel,
checkForBlocked = true checkForBlocked = true
}; };

View File

@@ -19,24 +19,24 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
using OpenRA.FileFormats;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class HarvesterInfo : ITraitInfo class HarvesterInfo : ITraitInfo
{ {
public readonly int BailCount = 28; public readonly int Capacity = 28;
public readonly int PipCount = 7; public readonly int PipCount = 7;
public readonly string[] Resources = { };
public object Create(Actor self) { return new Harvester(self); } public object Create(Actor self) { return new Harvester(self); }
} }
public class Harvester : IIssueOrder, IResolveOrder, IPips public class Harvester : IIssueOrder, IResolveOrder, IPips
{ {
[Sync] Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
public int oreCarried = 0; /* sum of these must not exceed capacity */
[Sync]
public int gemsCarried = 0;
Actor self; Actor self;
public Harvester(Actor self) public Harvester(Actor self)
@@ -44,22 +44,19 @@ namespace OpenRA.Traits
this.self = self; this.self = self;
} }
public bool IsFull { get { return oreCarried + gemsCarried == self.Info.Traits.Get<HarvesterInfo>().BailCount; } } public bool IsFull { get { return contents.Values.Sum() == self.Info.Traits.Get<HarvesterInfo>().Capacity; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
public void AcceptResource(ResourceTypeInfo type) public void AcceptResource(ResourceTypeInfo type)
{ {
// FIXME: harvester probably needs to know *exactly* what it is carrying. if (!contents.ContainsKey(type)) contents[type] = 1;
if (type.Name == "Gems") gemsCarried++; else contents[type]++;
else oreCarried++;
} }
public void Deliver(Actor self, Actor proc) public void Deliver(Actor self, Actor proc)
{ {
proc.Owner.GiveOre(oreCarried * Rules.General.GoldValue); proc.Owner.GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
proc.Owner.GiveOre(gemsCarried * Rules.General.GemValue); contents.Clear();
oreCarried = 0;
gemsCarried = 0;
} }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
@@ -71,7 +68,11 @@ namespace OpenRA.Traits
&& underCursor.traits.Contains<IAcceptOre>() && !IsEmpty) && underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
return new Order("Deliver", self, underCursor); return new Order("Deliver", self, underCursor);
if (underCursor == null && self.World.WorldActor.traits.Get<ResourceLayer>().GetResource(xy) != null) var res = self.World.WorldActor.traits.Get<ResourceLayer>().GetResource(xy);
if (underCursor == null &&
res != null && self.Info.Traits.Get<HarvesterInfo>().Resources
.Any(r => r == res.Name))
return new Order("Harvest", self, xy); return new Order("Harvest", self, xy);
return null; return null;
@@ -95,16 +96,12 @@ namespace OpenRA.Traits
public IEnumerable<PipType> GetPips(Actor self) public IEnumerable<PipType> GetPips(Actor self)
{ {
int numPips = self.Info.Traits.Get<HarvesterInfo>().PipCount; int numPips = self.Info.Traits.Get<HarvesterInfo>().PipCount;
int n = contents.Values.Sum();
for (int i = 0; i < numPips; i++) for (int i = 0; i < numPips; i++)
{ {
if (gemsCarried * 1.0f / self.Info.Traits.Get<HarvesterInfo>().BailCount > i * 1.0f / numPips) // todo: pip colors based on ResourceTypeInfo
{ if (n * 1.0f / self.Info.Traits.Get<HarvesterInfo>().Capacity > i * 1.0f / numPips)
yield return PipType.Red;
continue;
}
if ((gemsCarried + oreCarried) * 1.0f / self.Info.Traits.Get<HarvesterInfo>().BailCount > i * 1.0f / numPips)
{ {
yield return PipType.Yellow; yield return PipType.Yellow;
continue; continue;

View File

@@ -18,8 +18,8 @@
*/ */
#endregion #endregion
using System.Linq;
using System; using System;
using System.Linq;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {

View File

@@ -10,8 +10,6 @@ URepairPercent=20% ; [units only] percent cost to fully repair as ratio of
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=.1 ; 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]
GemValue=50 ; gem credits per 'bail' carried by a harvester
GoldValue=25 ; gold credits per 'bail' carried by a harvester
LowPowerSlowdown=3 ; slowdown factor for low power LowPowerSlowdown=3 ; slowdown factor for low power
GapRegenInterval=.1 ; gap generators will regenerate their shroud at this time interval GapRegenInterval=.1 ; gap generators will regenerate their shroud at this time interval

View File

@@ -37,6 +37,8 @@ HARV:
Selectable: Selectable:
Priority: 7 Priority: 7
Harvester: Harvester:
Resources: Tiberium
Capacity: 28
Unit: Unit:
HP: 600 HP: 600
Armor: light Armor: light

View File

@@ -49,8 +49,6 @@ Incoming=10 ; If an incoming projectile is as slow or slower than th
; income and production ; income and production
BuildSpeed=.8 ; general build speed [time (in minutes) to produce a 1000 credit cost item] BuildSpeed=.8 ; general build speed [time (in minutes) to produce a 1000 credit cost item]
BuildupTime=.06 ; average minutes that building build-up animation runs BuildupTime=.06 ; average minutes that building build-up animation runs
GemValue=50 ; gem credits per 'bail' carried by a harvester
GoldValue=25 ; gold credits per 'bail' carried by a harvester
OreTruckRate=1 ; speed that harvester truck manages ore [larger means slower] OreTruckRate=1 ; speed that harvester truck manages ore [larger means slower]
SeparateAircraft=no ; Is first helicopter to be purchased separately from helipad? SeparateAircraft=no ; Is first helicopter to be purchased separately from helipad?
SurvivorRate=.4 ; fraction of building cost to be converted to survivors when sold SurvivorRate=.4 ; fraction of building cost to be converted to survivors when sold

View File

@@ -234,7 +234,7 @@ World:
Overlays: 5,6,7,8 Overlays: 5,6,7,8
Palette: terrain Palette: terrain
SpriteNames: gold01,gold02,gold03,gold04 SpriteNames: gold01,gold02,gold03,gold04
ValuePerUnit: 30 ValuePerUnit: 25
Name: Ore Name: Ore
GrowthInterval: .3 GrowthInterval: .3
SpreadInterval: .7 SpreadInterval: .7
@@ -242,7 +242,7 @@ World:
Overlays: 9,10,11,12 Overlays: 9,10,11,12
Palette: terrain Palette: terrain
SpriteNames: gem01,gem02,gem03,gem04 SpriteNames: gem01,gem02,gem03,gem04
ValuePerUnit: 60 ValuePerUnit: 50
Name: Gems Name: Gems
MGG: MGG:
@@ -801,6 +801,8 @@ HARV:
Selectable: Selectable:
Priority: 7 Priority: 7
Harvester: Harvester:
Capacity: 28
Resources: Ore,Gems
Unit: Unit:
HP: 600 HP: 600
Armor: heavy Armor: heavy