harvester can be fussy now.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits.Activities
|
||||
{
|
||||
public class Harvest : IActivity
|
||||
@@ -65,13 +67,15 @@ namespace OpenRA.Traits.Activities
|
||||
void FindMoreOre(Actor self)
|
||||
{
|
||||
var res = self.World.WorldActor.traits.Get<ResourceLayer>();
|
||||
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
||||
|
||||
self.QueueActivity(new Move(
|
||||
() =>
|
||||
{
|
||||
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,
|
||||
checkForBlocked = true
|
||||
};
|
||||
|
||||
@@ -19,24 +19,24 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class HarvesterInfo : ITraitInfo
|
||||
{
|
||||
public readonly int BailCount = 28;
|
||||
public readonly int Capacity = 28;
|
||||
public readonly int PipCount = 7;
|
||||
public readonly string[] Resources = { };
|
||||
|
||||
public object Create(Actor self) { return new Harvester(self); }
|
||||
}
|
||||
|
||||
public class Harvester : IIssueOrder, IResolveOrder, IPips
|
||||
{
|
||||
[Sync]
|
||||
public int oreCarried = 0; /* sum of these must not exceed capacity */
|
||||
[Sync]
|
||||
public int gemsCarried = 0;
|
||||
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
|
||||
|
||||
Actor self;
|
||||
public Harvester(Actor self)
|
||||
@@ -44,22 +44,19 @@ namespace OpenRA.Traits
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public bool IsFull { get { return oreCarried + gemsCarried == self.Info.Traits.Get<HarvesterInfo>().BailCount; } }
|
||||
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }
|
||||
public bool IsFull { get { return contents.Values.Sum() == self.Info.Traits.Get<HarvesterInfo>().Capacity; } }
|
||||
public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
|
||||
|
||||
public void AcceptResource(ResourceTypeInfo type)
|
||||
{
|
||||
// FIXME: harvester probably needs to know *exactly* what it is carrying.
|
||||
if (type.Name == "Gems") gemsCarried++;
|
||||
else oreCarried++;
|
||||
if (!contents.ContainsKey(type)) contents[type] = 1;
|
||||
else contents[type]++;
|
||||
}
|
||||
|
||||
public void Deliver(Actor self, Actor proc)
|
||||
{
|
||||
proc.Owner.GiveOre(oreCarried * Rules.General.GoldValue);
|
||||
proc.Owner.GiveOre(gemsCarried * Rules.General.GemValue);
|
||||
oreCarried = 0;
|
||||
gemsCarried = 0;
|
||||
proc.Owner.GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
|
||||
contents.Clear();
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
@@ -71,7 +68,11 @@ namespace OpenRA.Traits
|
||||
&& underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
|
||||
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 null;
|
||||
@@ -95,16 +96,12 @@ namespace OpenRA.Traits
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
int numPips = self.Info.Traits.Get<HarvesterInfo>().PipCount;
|
||||
int n = contents.Values.Sum();
|
||||
|
||||
for (int i = 0; i < numPips; i++)
|
||||
{
|
||||
if (gemsCarried * 1.0f / self.Info.Traits.Get<HarvesterInfo>().BailCount > i * 1.0f / numPips)
|
||||
{
|
||||
yield return PipType.Red;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((gemsCarried + oreCarried) * 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.Yellow;
|
||||
continue;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
|
||||
@@ -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
|
||||
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
|
||||
|
||||
GapRegenInterval=.1 ; gap generators will regenerate their shroud at this time interval
|
||||
|
||||
@@ -37,6 +37,8 @@ HARV:
|
||||
Selectable:
|
||||
Priority: 7
|
||||
Harvester:
|
||||
Resources: Tiberium
|
||||
Capacity: 28
|
||||
Unit:
|
||||
HP: 600
|
||||
Armor: light
|
||||
|
||||
@@ -49,8 +49,6 @@ Incoming=10 ; If an incoming projectile is as slow or slower than th
|
||||
; income and production
|
||||
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
|
||||
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]
|
||||
SeparateAircraft=no ; Is first helicopter to be purchased separately from helipad?
|
||||
SurvivorRate=.4 ; fraction of building cost to be converted to survivors when sold
|
||||
|
||||
@@ -234,7 +234,7 @@ World:
|
||||
Overlays: 5,6,7,8
|
||||
Palette: terrain
|
||||
SpriteNames: gold01,gold02,gold03,gold04
|
||||
ValuePerUnit: 30
|
||||
ValuePerUnit: 25
|
||||
Name: Ore
|
||||
GrowthInterval: .3
|
||||
SpreadInterval: .7
|
||||
@@ -242,7 +242,7 @@ World:
|
||||
Overlays: 9,10,11,12
|
||||
Palette: terrain
|
||||
SpriteNames: gem01,gem02,gem03,gem04
|
||||
ValuePerUnit: 60
|
||||
ValuePerUnit: 50
|
||||
Name: Gems
|
||||
|
||||
MGG:
|
||||
@@ -801,6 +801,8 @@ HARV:
|
||||
Selectable:
|
||||
Priority: 7
|
||||
Harvester:
|
||||
Capacity: 28
|
||||
Resources: Ore,Gems
|
||||
Unit:
|
||||
HP: 600
|
||||
Armor: heavy
|
||||
|
||||
Reference in New Issue
Block a user