Per-structure queues for cnc

This commit is contained in:
Paul Chote
2010-08-26 22:10:21 +12:00
parent ee546750b2
commit 61ebe0d0a0
4 changed files with 48 additions and 31 deletions

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Traits
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
{
BeginProduction(new ProductionItem(order.TargetString, (int)time, cost,
BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost,
() => self.World.AddFrameEndTask(
_ =>
{
@@ -165,6 +165,15 @@ namespace OpenRA.Traits
void BuildUnit( string name )
{
// If the actor has a production trait, use it.
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
if (sp != null)
{
if (!IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ]))
FinishProduction();
return;
}
var producers = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<Production>()
.Where(x => x.Trait.Info.Produces.Contains(Info.Type))
@@ -193,7 +202,7 @@ namespace OpenRA.Traits
public class ProductionItem
{
public readonly string Item;
public readonly ProductionQueue Queue;
public readonly int TotalTime;
public readonly int TotalCost;
public int RemainingTime { get; private set; }
@@ -204,13 +213,14 @@ namespace OpenRA.Traits
int slowdown = 0;
public ProductionItem(string item, int time, int cost, Action onComplete)
public ProductionItem(ProductionQueue queue, string item, int time, int cost, Action onComplete)
{
if (time <= 0) time = 1;
Item = item;
RemainingTime = TotalTime = time;
RemainingCost = TotalCost = cost;
OnComplete = onComplete;
Queue = queue;
Log.Write("debug", "new ProductionItem: {0} time={1} cost={2}", item, time, cost);
}
@@ -228,7 +238,7 @@ namespace OpenRA.Traits
if (player.PlayerActor.Trait<PlayerResources>().GetPowerState() != PowerState.Normal)
{
if (--slowdown <= 0)
slowdown = player.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown;
slowdown = Queue.Info.LowPowerSlowdown;
else
return;
}

View File

@@ -349,7 +349,7 @@ namespace OpenRA.Mods.RA.Widgets
if (producing.Done)
{
if (unit.Traits.Contains<BuildingInfo>())
world.OrderGenerator = new PlaceBuildingOrderGenerator(player.PlayerActor, item);
world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, item);
return;
}
@@ -472,7 +472,7 @@ namespace OpenRA.Mods.RA.Widgets
var lowpower = resources.GetPowerState() != PowerState.Normal;
var time = CurrentQueue.GetBuildTime(info.Name)
* ((lowpower)? pl.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown : 1);
* ((lowpower)? CurrentQueue.Info.LowPowerSlowdown : 1);
DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White);
var bi = info.Traits.GetOrDefault<BuildingInfo>();

View File

@@ -24,6 +24,15 @@ FACT:
IntoActor: mcv
Offset:1,1
Facing: 108
ProductionQueue@Building:
Type: Building
BuildSpeed: .4
LowPowerSlowdown: 3
ProductionQueue@Defense:
Type: Defense
BuildSpeed: .4
LowPowerSlowdown: 3
NUKE:
Inherits: ^Building
Valued:
@@ -173,7 +182,10 @@ PYLE:
SpawnOffsets: -10,2, 7,7
ExitCells: 0,1, 1,1
PrimaryBuilding:
ProductionQueue@Vehicle:
Type: Infantry
BuildSpeed: .4
LowPowerSlowdown: 3
HAND:
Inherits: ^Building
Valued:
@@ -204,7 +216,10 @@ HAND:
SpawnOffsets: 12,24
ExitCells:1,2
PrimaryBuilding:
ProductionQueue@Infantry:
Type: Infantry
BuildSpeed: .4
LowPowerSlowdown: 3
AFLD:
Inherits: ^Building
Valued:
@@ -237,6 +252,10 @@ AFLD:
SpawnOffsets: -24,0
ExitCells:3,1
PrimaryBuilding:
ProductionQueue@Vehicle:
Type: Vehicle
BuildSpeed: .4
LowPowerSlowdown: 3
WEAP:
Inherits: ^Building
@@ -270,6 +289,10 @@ WEAP:
SpawnOffsets: -8,-8
ExitCells: 0,2
PrimaryBuilding:
ProductionQueue@Vehicle:
Type: Vehicle
BuildSpeed: .4
LowPowerSlowdown: 3
HQ:
RequiresPower:
@@ -383,6 +406,10 @@ HPAD:
Reservable:
RepairsUnits:
RallyPoint:
ProductionQueue@Plane:
Type: Plane
BuildSpeed: .4
LowPowerSlowdown: 3
EYE:
RequiresPower:

View File

@@ -1,24 +1,4 @@
Player:
ProductionQueue@Building:
Type: Building
BuildSpeed: .4
LowPowerSlowdown: 3
ProductionQueue@Defense:
Type: Defense
BuildSpeed: .4
LowPowerSlowdown: 3
ProductionQueue@Infantry:
Type: Infantry
BuildSpeed: .4
LowPowerSlowdown: 3
ProductionQueue@Vehicle:
Type: Vehicle
BuildSpeed: .4
LowPowerSlowdown: 3
ProductionQueue@Plane:
Type: Plane
BuildSpeed: .4
LowPowerSlowdown: 3
PlaceBuilding:
TechTreeCache:
NukePower: