Remove BS from ProductionQueue. Move ProductionQueue onto a structure for queue-per-building.

This commit is contained in:
Paul Chote
2010-08-26 21:16:39 +12:00
parent 3b59afcd4f
commit 267d89a459
9 changed files with 209 additions and 158 deletions

View File

@@ -177,6 +177,21 @@ namespace OpenRA
return new Order("Command", null, text) { IsImmediate = true }; return new Order("Command", null, text) { IsImmediate = true };
} }
public static Order StartProduction(Actor subject, string item, int count)
{
return new Order("StartProduction", subject, new int2( count, 0 ), item );
}
public static Order PauseProduction(Actor subject, string item, bool pause)
{
return new Order("PauseProduction", subject, new int2( pause ? 1 : 0, 0 ), item);
}
public static Order CancelProduction(Actor subject, string item)
{
return new Order("CancelProduction", subject, item);
}
public static Order StartProduction(Player subject, string item, int count) public static Order StartProduction(Player subject, string item, int count)
{ {
return new Order("StartProduction", subject.PlayerActor, new int2( count, 0 ), item ); return new Order("StartProduction", subject.PlayerActor, new int2( count, 0 ), item );

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
@@ -56,8 +57,14 @@ namespace OpenRA.Orders
public void Tick( World world ) public void Tick( World world )
{ {
var producing = Producer.Trait<Traits.ProductionQueue>().CurrentItem( Rules.Info[ Building ].Category ); // Find the queue with the target actor
if (producing == null || producing.Item != Building || producing.RemainingTime != 0) var queue = Producer.TraitsImplementing<ProductionQueue>()
.Where(p => p.CurrentItem() != null &&
p.CurrentItem().Item == Building &&
p.CurrentItem().RemainingTime == 0)
.FirstOrDefault();
if (queue == null)
world.CancelInputMode(); world.CancelInputMode();
} }

View File

@@ -27,13 +27,19 @@ namespace OpenRA.Traits
{ {
var prevItems = GetNumBuildables(self.Owner); var prevItems = GetNumBuildables(self.Owner);
var queue = self.Trait<ProductionQueue>(); // Find the queue with the target actor
var unit = Rules.Info[order.TargetString]; var queue = w.Queries.WithTraitMultiple<ProductionQueue>()
var producing = queue.CurrentItem(unit.Category); .Where(p => p.Actor.Owner == self.Owner &&
p.Trait.CurrentItem() != null &&
p.Trait.CurrentItem().Item == order.TargetString &&
p.Trait.CurrentItem().RemainingTime == 0)
.Select(p => p.Trait)
.FirstOrDefault();
if (producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0) if (queue == null)
return; return;
var unit = Rules.Info[order.TargetString];
var buildingInfo = unit.Traits.Get<BuildingInfo>(); var buildingInfo = unit.Traits.Get<BuildingInfo>();
if (order.OrderString == "LineBuild") if (order.OrderString == "LineBuild")
@@ -66,7 +72,7 @@ namespace OpenRA.Traits
PlayBuildAnim( self, unit ); PlayBuildAnim( self, unit );
queue.FinishProduction(unit.Category); queue.FinishProduction();
if (GetNumBuildables(self.Owner) > prevItems) if (GetNumBuildables(self.Owner) > prevItems)
w.Add(new DelayedAction(10, w.Add(new DelayedAction(10,

View File

@@ -17,32 +17,44 @@ namespace OpenRA.Traits
{ {
public class ProductionQueueInfo : ITraitInfo public class ProductionQueueInfo : ITraitInfo
{ {
public readonly string Type = null;
public float BuildSpeed = 0.4f; public float BuildSpeed = 0.4f;
public readonly int LowPowerSlowdown = 3; public readonly int LowPowerSlowdown = 3;
public object Create(ActorInitializer init) { return new ProductionQueue(init.self); } public object Create(ActorInitializer init) { return new ProductionQueue(init.self, this); }
} }
public class ProductionQueue : IResolveOrder, ITick public class ProductionQueue : IResolveOrder, ITick
{ {
Actor self; public readonly Actor self;
public ProductionQueueInfo Info;
// TODO: sync this
List<ProductionItem> Producing = new List<ProductionItem>();
public ProductionQueue( Actor self ) public ProductionQueue( Actor self, ProductionQueueInfo info )
{ {
this.self = self; this.self = self;
this.Info = info;
}
public ProductionItem CurrentItem()
{
return Producing.ElementAtOrDefault(0);
}
public IEnumerable<ProductionItem> AllItems()
{
return Producing;
} }
public void Tick( Actor self ) public void Tick( Actor self )
{ {
foreach( var p in production.OrderBy( p => p.Key ) ) while( Producing.Count > 0 && !Rules.TechTree.BuildableItems( self.Owner, Info.Type ).Contains( Producing[ 0 ].Item ) )
{ {
while( p.Value.Count > 0 && !Rules.TechTree.BuildableItems( self.Owner, p.Key ).Contains( p.Value[ 0 ].Item ) ) self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Producing[0].TotalCost - Producing[0].RemainingCost); // refund what's been paid so far.
{ FinishProduction();
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(p.Value[0].TotalCost - p.Value[0].RemainingCost); // refund what's been paid so far.
FinishProduction(p.Key);
}
if( p.Value.Count > 0 )
( p.Value )[ 0 ].Tick( self.Owner );
} }
if( Producing.Count > 0 )
Producing[ 0 ].Tick( self.Owner );
} }
public void ResolveOrder( Actor self, Order order ) public void ResolveOrder( Actor self, Order order )
@@ -50,20 +62,22 @@ namespace OpenRA.Traits
switch( order.OrderString ) switch( order.OrderString )
{ {
case "StartProduction": case "StartProduction":
{
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
{ {
var unit = Rules.Info[order.TargetString]; var unit = Rules.Info[order.TargetString];
if (unit.Category != Info.Type)
return; /* Not built by this queue */
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0; var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
var time = GetBuildTime(self, order.TargetString); var time = GetBuildTime(order.TargetString);
if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString)) if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString))
return; /* you can't build that!! */ return; /* you can't build that!! */
bool hasPlayedSound = false; bool hasPlayedSound = false;
BeginProduction(unit.Category, for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
new ProductionItem(order.TargetString, (int)time, cost, {
BeginProduction(new ProductionItem(order.TargetString, (int)time, cost,
() => self.World.AddFrameEndTask( () => self.World.AddFrameEndTask(
_ => _ =>
{ {
@@ -82,9 +96,11 @@ namespace OpenRA.Traits
} }
case "PauseProduction": case "PauseProduction":
{ {
var producing = CurrentItem( Rules.Info[ order.TargetString ].Category ); if (Rules.Info[ order.TargetString ].Category != Info.Type)
if( producing != null && producing.Item == order.TargetString ) return; /* Not built by this queue */
producing.Paused = ( order.TargetLocation.X != 0 );
if( Producing.Count > 0 && Producing[0].Item == order.TargetString )
Producing[0].Paused = ( order.TargetLocation.X != 0 );
break; break;
} }
case "CancelProduction": case "CancelProduction":
@@ -95,65 +111,50 @@ namespace OpenRA.Traits
} }
} }
public static int GetBuildTime(Actor self, String unitString) public int GetBuildTime(String unitString)
{ {
var unit = Rules.Info[unitString]; var unit = Rules.Info[unitString];
if (unit == null || ! unit.Traits.Contains<BuildableInfo>()) if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0; return 0;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastBuild) return 0; if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) return 0;
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0; var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
var time = cost var time = cost
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().BuildSpeed /* todo: country-specific build speed bonus */ * Info.BuildSpeed
* (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */
/ 1000; / 1000;
return (int) time; return (int) time;
} }
// Key: Production category.
// TODO: sync this
readonly Cache<string, List<ProductionItem>> production
= new Cache<string, List<ProductionItem>>( _ => new List<ProductionItem>() );
public ProductionItem CurrentItem(string category)
{
return production[category].ElementAtOrDefault(0);
}
public IEnumerable<ProductionItem> AllItems(string category)
{
return production[category];
}
void CancelProduction( string itemName ) void CancelProduction( string itemName )
{ {
var category = Rules.Info[itemName].Category; var category = Rules.Info[itemName].Category;
var queue = production[ category ];
if (queue.Count == 0) return;
var lastIndex = queue.FindLastIndex( a => a.Item == itemName ); if (category != Info.Type || Producing.Count == 0)
return; // Nothing to do here
var lastIndex = Producing.FindLastIndex( a => a.Item == itemName );
if (lastIndex > 0) if (lastIndex > 0)
{ {
queue.RemoveAt(lastIndex); Producing.RemoveAt(lastIndex);
} }
else if( lastIndex == 0 ) else if( lastIndex == 0 )
{ {
var item = queue[0]; var item = Producing[0];
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far.
FinishProduction(category); FinishProduction();
} }
} }
public void FinishProduction( string category ) public void FinishProduction()
{ {
var queue = production[category]; if (Producing.Count == 0) return;
if (queue.Count == 0) return; Producing.RemoveAt(0);
queue.RemoveAt(0);
} }
void BeginProduction( string group, ProductionItem item ) void BeginProduction( ProductionItem item )
{ {
production[group].Add(item); Producing.Add(item);
} }
static bool IsDisabledBuilding(Actor a) static bool IsDisabledBuilding(Actor a)
@@ -164,12 +165,9 @@ namespace OpenRA.Traits
void BuildUnit( string name ) void BuildUnit( string name )
{ {
var newUnitType = Rules.Info[ name ];
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
var producers = self.World.Queries.OwnedBy[self.Owner] var producers = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<Production>() .WithTrait<Production>()
.Where(x => producerTypes.Contains(x.Actor.Info)) .Where(x => x.Trait.Info.Produces.Contains(Info.Type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ) // prioritize the primary. .OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ) // prioritize the primary.
.ToArray(); .ToArray();
@@ -183,9 +181,9 @@ namespace OpenRA.Traits
{ {
if (IsDisabledBuilding(p.Actor)) continue; if (IsDisabledBuilding(p.Actor)) continue;
if (p.Trait.Produce(p.Actor, newUnitType)) if (p.Trait.Produce(p.Actor, Rules.Info[ name ]))
{ {
FinishProduction(newUnitType.Category); FinishProduction();
break; break;
} }
} }

View File

@@ -26,8 +26,11 @@ namespace OpenRA.Traits
public class Production public class Production
{ {
public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>(); public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
public ProductionInfo Info;
public Production(ProductionInfo info) public Production(ProductionInfo info)
{ {
Info = info;
if (info.SpawnOffsets == null || info.ExitCells == null) if (info.SpawnOffsets == null || info.ExitCells == null)
return; return;

View File

@@ -29,7 +29,6 @@ namespace OpenRA.Mods.RA
bool enabled; bool enabled;
int ticks; int ticks;
Player p; Player p;
ProductionQueue productionQueue;
PlayerResources playerResources; PlayerResources playerResources;
int2 baseCenter; int2 baseCenter;
Random random = new Random(); //we do not use the synced random number generator. Random random = new Random(); //we do not use the synced random number generator.
@@ -68,7 +67,6 @@ namespace OpenRA.Mods.RA
this.p = p; this.p = p;
enabled = true; enabled = true;
productionQueue = p.PlayerActor.Trait<ProductionQueue>();
playerResources = p.PlayerActor.Trait<PlayerResources>(); playerResources = p.PlayerActor.Trait<PlayerResources>();
} }
@@ -278,20 +276,33 @@ namespace OpenRA.Mods.RA
//Build a random unit of the given type. Not going to be needed once there is actual AI... //Build a random unit of the given type. Not going to be needed once there is actual AI...
private void BuildRandom(string category) private void BuildRandom(string category)
{ {
var unitInProduction = productionQueue.CurrentItem(category); // Pick a free queue
if (unitInProduction == null) var queue = Game.world.Queries.WithTraitMultiple<ProductionQueue>()
{ .Where(a => a.Actor.Owner == p &&
a.Trait.Info.Type == category &&
a.Trait.CurrentItem() == null)
.Select(a => a.Trait)
.FirstOrDefault();
if (queue == null)
return;
var unit = ChooseRandomUnitToBuild(category); var unit = ChooseRandomUnitToBuild(category);
if (unit != null) if (unit != null)
{ {
Game.IssueOrder(Order.StartProduction(p, unit, 1)); Game.IssueOrder(Order.StartProduction(p, unit, 1));
} }
} }
}
private void BuildBuildings() private void BuildBuildings()
{ {
var currentBuilding = productionQueue.CurrentItem("Building"); // Pick a free queue
var queue = Game.world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(a => a.Actor.Owner == p && a.Trait.Info.Type == "Building")
.Select(a => a.Trait)
.FirstOrDefault();
var currentBuilding = queue.CurrentItem();
switch (state) switch (state)
{ {
case BuildState.ChooseItem: case BuildState.ChooseItem:

View File

@@ -25,10 +25,12 @@ namespace OpenRA.Mods.RA.Widgets
public int Columns = 3; public int Columns = 3;
public int Rows = 5; public int Rows = 5;
string currentTab = null; ProductionQueue CurrentQueue = null;
List<ProductionQueue> visibleTabs = new List<ProductionQueue>();
bool paletteOpen = false; bool paletteOpen = false;
Dictionary<string, string[]> tabImageNames; Dictionary<string, string[]> tabImageNames;
Dictionary<string, Sprite> tabSprites; Dictionary<string, Sprite> iconSprites;
static float2 paletteOpenOrigin = new float2(Game.viewport.Width - 215, 280); static float2 paletteOpenOrigin = new float2(Game.viewport.Width - 215, 280);
static float2 paletteClosedOrigin = new float2(Game.viewport.Width - 16, 280); static float2 paletteClosedOrigin = new float2(Game.viewport.Width - 16, 280);
static float2 paletteOrigin = paletteClosedOrigin; static float2 paletteOrigin = paletteClosedOrigin;
@@ -43,7 +45,6 @@ namespace OpenRA.Mods.RA.Widgets
public readonly string BuildPaletteOpen = "bleep13.aud"; public readonly string BuildPaletteOpen = "bleep13.aud";
public readonly string BuildPaletteClose = "bleep13.aud"; public readonly string BuildPaletteClose = "bleep13.aud";
public readonly string TabClick = "ramenu1.aud"; public readonly string TabClick = "ramenu1.aud";
List<string> visibleTabs = new List<string>();
public BuildPaletteWidget() : base() { } public BuildPaletteWidget() : base() { }
@@ -57,7 +58,7 @@ namespace OpenRA.Mods.RA.Widgets
ready.PlayRepeating("ready"); ready.PlayRepeating("ready");
clock = new Animation("clock"); clock = new Animation("clock");
tabSprites = Rules.Info.Values iconSprites = Rules.Info.Values
.Where(u => u.Traits.Contains<BuildableInfo>()) .Where(u => u.Traits.Contains<BuildableInfo>())
.ToDictionary( .ToDictionary(
u => u.Name, u => u.Name,
@@ -71,29 +72,33 @@ namespace OpenRA.Mods.RA.Widgets
n => i.ToString()))) n => i.ToString())))
.ToDictionary(a => a.First, a => a.Second); .ToDictionary(a => a.First, a => a.Second);
IsVisible = () => { return currentTab != null || (currentTab == null && !paletteOpen); }; IsVisible = () => { return CurrentQueue != null || (CurrentQueue == null && !paletteOpen); };
} }
public override Rectangle EventBounds public override Rectangle EventBounds
{ {
get { return new Rectangle((int)(paletteOrigin.X) - 24, (int)(paletteOrigin.Y), 215, 48 * numActualRows); get { return new Rectangle((int)(paletteOrigin.X) - 24, (int)(paletteOrigin.Y), 215, 48 * numActualRows); }
}
} }
public override void Tick(World world) public override void Tick(World world)
{ {
visibleTabs.Clear(); visibleTabs.Clear();
foreach (var q in tabImageNames)
if (!Rules.TechTree.BuildableItems(world.LocalPlayer, q.Key).Any()) var queues = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(p => p.Actor.Owner == world.LocalPlayer)
.Select(p => p.Trait);
foreach (var queue in queues)
if (!Rules.TechTree.BuildableItems(world.LocalPlayer, queue.Info.Type).Any())
{ {
if (currentTab == q.Key) if (CurrentQueue == queue)
currentTab = null; CurrentQueue = null;
} }
else else
visibleTabs.Add(q.Key); visibleTabs.Add(queue);
if (currentTab == null) if (CurrentQueue == null)
currentTab = visibleTabs.FirstOrDefault(); CurrentQueue = queues.FirstOrDefault();
TickPaletteAnimation(world); TickPaletteAnimation(world);
@@ -131,12 +136,12 @@ namespace OpenRA.Mods.RA.Widgets
} }
} }
public void SetCurrentTab(string produces) public void SetCurrentTab(ProductionQueue queue)
{ {
if (!paletteOpen) if (!paletteOpen)
paletteAnimating = true; paletteAnimating = true;
paletteOpen = true; paletteOpen = true;
currentTab = produces; CurrentQueue = queue;
} }
public override bool HandleKeyPressInner(KeyInput e) public override bool HandleKeyPressInner(KeyInput e)
@@ -175,23 +180,21 @@ namespace OpenRA.Mods.RA.Widgets
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
if (!IsVisible()) return; if (!IsVisible()) return;
paletteHeight = DrawPalette(world, currentTab); // todo: fix
paletteHeight = DrawPalette(world, CurrentQueue);
DrawBuildTabs(world, paletteHeight); DrawBuildTabs(world, paletteHeight);
} }
int DrawPalette(World world, string queueName) int DrawPalette(World world, ProductionQueue queue)
{ {
string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
buttons.Clear(); buttons.Clear();
if (queue == null) return 0;
string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
float2 origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9); float2 origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
var queueName = queue.Info.Type;
if (queueName == null) return 0;
// Collect info // Collect info
var x = 0; var x = 0;
var y = 0; var y = 0;
var buildableItems = Rules.TechTree.BuildableItems(world.LocalPlayer, queueName).ToArray(); var buildableItems = Rules.TechTree.BuildableItems(world.LocalPlayer, queueName).ToArray();
@@ -200,8 +203,6 @@ namespace OpenRA.Mods.RA.Widgets
.OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder) .OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder)
.ToArray(); .ToArray();
var queue = world.LocalPlayer.PlayerActor.Trait<ProductionQueue>();
var overlayBits = new List<Pair<Sprite, float2>>(); var overlayBits = new List<Pair<Sprite, float2>>();
numActualRows = Math.Max((allBuildables.Length + Columns - 1) / Columns, Rows); numActualRows = Math.Max((allBuildables.Length + Columns - 1) / Columns, Rows);
@@ -218,14 +219,14 @@ namespace OpenRA.Mods.RA.Widgets
// Icons // Icons
string tooltipItem = null; string tooltipItem = null;
var isBuildingSomething = queue.CurrentItem() != null;
foreach (var item in allBuildables) foreach (var item in allBuildables)
{ {
var rect = new RectangleF(origin.X + x * 64, origin.Y + 48 * y, 64, 48); var rect = new RectangleF(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
var drawPos = new float2(rect.Location); var drawPos = new float2(rect.Location);
var isBuildingSomething = queue.CurrentItem(queueName) != null; WidgetUtils.DrawSHP(iconSprites[item.Name], drawPos);
WidgetUtils.DrawSHP(tabSprites[item.Name], drawPos);
var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item.Name); var firstOfThis = queue.AllItems().FirstOrDefault(a => a.Item == item.Name);
if (rect.Contains(Viewport.LastMousePos.ToPoint())) if (rect.Contains(Viewport.LastMousePos.ToPoint()))
tooltipItem = item.Name; tooltipItem = item.Name;
@@ -251,8 +252,8 @@ namespace OpenRA.Mods.RA.Widgets
overlayBits.Add(Pair.New(ready.Image, overlayPos)); overlayBits.Add(Pair.New(ready.Image, overlayPos));
} }
var repeats = queue.AllItems(queueName).Count(a => a.Item == item.Name); var repeats = queue.AllItems().Count(a => a.Item == item.Name);
if (repeats > 1 || queue.CurrentItem(queueName) != firstOfThis) if (repeats > 1 || queue.CurrentItem() != firstOfThis)
{ {
var offset = -22; var offset = -22;
var digits = repeats.ToString(); var digits = repeats.ToString();
@@ -311,7 +312,7 @@ namespace OpenRA.Mods.RA.Widgets
}; };
} }
Action<MouseInput> HandleTabClick(string button, World world) Action<MouseInput> HandleTabClick(ProductionQueue queue, World world)
{ {
return mi => { return mi => {
if (mi.Button != MouseButton.Left) if (mi.Button != MouseButton.Left)
@@ -319,8 +320,8 @@ namespace OpenRA.Mods.RA.Widgets
Sound.Play(TabClick); Sound.Play(TabClick);
var wasOpen = paletteOpen; var wasOpen = paletteOpen;
paletteOpen = (currentTab == button && wasOpen) ? false : true; paletteOpen = (CurrentQueue == queue && wasOpen) ? false : true;
currentTab = button; CurrentQueue = queue;
if (wasOpen != paletteOpen) if (wasOpen != paletteOpen)
paletteAnimating = true; paletteAnimating = true;
}; };
@@ -338,13 +339,12 @@ namespace OpenRA.Mods.RA.Widgets
{ {
var player = world.LocalPlayer; var player = world.LocalPlayer;
var unit = Rules.Info[item]; var unit = Rules.Info[item];
var queue = player.PlayerActor.Trait<Traits.ProductionQueue>();
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>(); var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
var producing = queue.AllItems(unit.Category).FirstOrDefault( a => a.Item == item ); var producing = CurrentQueue.AllItems().FirstOrDefault( a => a.Item == item );
if (isLmb) if (isLmb)
{ {
if (producing != null && producing == queue.CurrentItem(unit.Category)) if (producing != null && producing == CurrentQueue.CurrentItem())
{ {
if (producing.Done) if (producing.Done)
{ {
@@ -355,7 +355,7 @@ namespace OpenRA.Mods.RA.Widgets
if (producing.Paused) if (producing.Paused)
{ {
Game.IssueOrder(Order.PauseProduction(player, item, false)); Game.IssueOrder(Order.PauseProduction(CurrentQueue.self, item, false));
return; return;
} }
} }
@@ -370,12 +370,12 @@ namespace OpenRA.Mods.RA.Widgets
if (producing.Paused || producing.Done || producing.TotalCost == producing.RemainingCost) if (producing.Paused || producing.Done || producing.TotalCost == producing.RemainingCost)
{ {
Sound.Play(eva.CancelledAudio); Sound.Play(eva.CancelledAudio);
Game.IssueOrder(Order.CancelProduction(player, item)); Game.IssueOrder(Order.CancelProduction(CurrentQueue.self, item));
} }
else else
{ {
Sound.Play(eva.OnHoldAudio); Sound.Play(eva.OnHoldAudio);
Game.IssueOrder(Order.PauseProduction(player, item, true)); Game.IssueOrder(Order.PauseProduction(CurrentQueue.self, item, true));
} }
} }
} }
@@ -387,19 +387,11 @@ namespace OpenRA.Mods.RA.Widgets
var unit = Rules.Info[item]; var unit = Rules.Info[item];
Sound.Play(unit.Traits.Contains<BuildingInfo>() ? eva.BuildingSelectAudio : eva.UnitSelectAudio); Sound.Play(unit.Traits.Contains<BuildingInfo>() ? eva.BuildingSelectAudio : eva.UnitSelectAudio);
Game.IssueOrder(Order.StartProduction(world.LocalPlayer, item,
Game.IssueOrder(Order.StartProduction(CurrentQueue.self, item,
Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1)); Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1));
} }
static Dictionary<string, string> CategoryNameRemaps = new Dictionary<string, string>
{
{ "Building", "Structures" },
{ "Defense", "Defenses" },
{ "Plane", "Aircraft" },
{ "Ship", "Ships" },
{ "Vehicle", "Vehicles" },
};
void DrawBuildTabs( World world, int paletteHeight) void DrawBuildTabs( World world, int paletteHeight)
{ {
const int tabWidth = 24; const int tabWidth = 24;
@@ -408,26 +400,27 @@ namespace OpenRA.Mods.RA.Widgets
var y = paletteOrigin.Y + 9; var y = paletteOrigin.Y + 9;
tabs.Clear(); tabs.Clear();
var queue = world.LocalPlayer.PlayerActor.Trait<Traits.ProductionQueue>();
foreach (var q in tabImageNames) var queues = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(p => p.Actor.Owner == world.LocalPlayer)
.Select(p => p.Trait);
foreach (var queue in queues)
{ {
var groupName = q.Key;
if (!visibleTabs.Contains(groupName))
continue;
string[] tabKeys = { "normal", "ready", "selected" }; string[] tabKeys = { "normal", "ready", "selected" };
var producing = queue.CurrentItem(groupName); var producing = queue.CurrentItem();
var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0; var index = queue == CurrentQueue ? 2 : (producing != null && producing.Done) ? 1 : 0;
var race = world.LocalPlayer.Country.Race; var race = world.LocalPlayer.Country.Race;
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y)); WidgetUtils.DrawRGBA(ChromeProvider.GetImage("tabs-"+tabKeys[index], race+"-"+queue.Info.Type), new float2(x, y));
var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight); var rect = new Rectangle((int)x,(int)y,(int)tabWidth,(int)tabHeight);
tabs.Add(Pair.New(rect, HandleTabClick(groupName, world))); tabs.Add(Pair.New(rect, HandleTabClick(queue, world)));
if (rect.Contains(Viewport.LastMousePos.ToPoint())) if (rect.Contains(Viewport.LastMousePos.ToPoint()))
{ {
var text = CategoryNameRemaps.ContainsKey(groupName) ? CategoryNameRemaps[groupName] : groupName; //var text = CategoryNameRemaps.ContainsKey(groupName) ? CategoryNameRemaps[groupName] : groupName;
var text = queue.Info.Type;
var sz = Game.Renderer.BoldFont.Measure(text); var sz = Game.Renderer.BoldFont.Measure(text);
WidgetUtils.DrawPanelPartial("dialog4", WidgetUtils.DrawPanelPartial("dialog4",
Rectangle.FromLTRB((int)rect.Left - sz.X - 30, (int)rect.Top, (int)rect.Left - 5, (int)rect.Bottom), Rectangle.FromLTRB((int)rect.Left - sz.X - 30, (int)rect.Top, (int)rect.Left - 5, (int)rect.Bottom),
@@ -478,7 +471,7 @@ namespace OpenRA.Mods.RA.Widgets
(resources.DisplayCash + resources.DisplayOre >= cost ? Color.White : Color.Red )); (resources.DisplayCash + resources.DisplayOre >= cost ? Color.White : Color.Red ));
var lowpower = resources.GetPowerState() != PowerState.Normal; var lowpower = resources.GetPowerState() != PowerState.Normal;
var time = ProductionQueue.GetBuildTime(pl.PlayerActor, info.Name) var time = CurrentQueue.GetBuildTime(info.Name)
* ((lowpower)? pl.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown : 1); * ((lowpower)? pl.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown : 1);
DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White); DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White);
@@ -511,7 +504,7 @@ namespace OpenRA.Mods.RA.Widgets
{ {
if (!paletteOpen) return false; if (!paletteOpen) return false;
var buildable = Rules.TechTree.BuildableItems(world.LocalPlayer, currentTab); var buildable = Rules.TechTree.BuildableItems(world.LocalPlayer, CurrentQueue.Info.Type);
var toBuild = buildable.FirstOrDefault(b => Rules.Info[b.ToLowerInvariant()].Traits.Get<BuildableInfo>().Hotkey == c.ToString()); var toBuild = buildable.FirstOrDefault(b => Rules.Info[b.ToLowerInvariant()].Traits.Get<BuildableInfo>().Hotkey == c.ToString());
@@ -530,7 +523,7 @@ namespace OpenRA.Mods.RA.Widgets
int size = visibleTabs.Count(); int size = visibleTabs.Count();
if (size > 0) if (size > 0)
{ {
int current = visibleTabs.IndexOf(currentTab); int current = visibleTabs.IndexOf(CurrentQueue);
if (!shift) if (!shift)
{ {
if (current + 1 >= size) if (current + 1 >= size)

View File

@@ -40,8 +40,8 @@ namespace OpenRA.Mods.RA.Widgets
if (produces == null) if (produces == null)
return; return;
Widget.RootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE") //Widget.RootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE")
.SetCurrentTab(produces); // .SetCurrentTab(produces);
} }
} }
} }

View File

@@ -1,5 +1,22 @@
Player: Player:
ProductionQueue: 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 BuildSpeed: .4
LowPowerSlowdown: 3 LowPowerSlowdown: 3
PlaceBuilding: PlaceBuilding:
@@ -41,6 +58,7 @@ Player:
InitialCash: 5000 InitialCash: 5000
ActorGroupProxy: ActorGroupProxy:
DeveloperMode: DeveloperMode:
HackyAI:
World: World:
ScreenShaker: ScreenShaker: