Favour newer buildings over older buildings when a unit can appear from multiple buildings after being built

This commit is contained in:
ScottNZ
2013-06-24 09:16:35 +12:00
parent b93e9a5945
commit 9f1d9e153a

View File

@@ -11,23 +11,23 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.FileFormats;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
[Desc("Attach this to the world actor (not a building!) to define a new shared build queue.", [Desc("Attach this to the world actor (not a building!) to define a new shared build queue.",
"Will only work together with the Production: trait on the actor that actually does the production.", "Will only work together with the Production: trait on the actor that actually does the production.",
"You will also want to add PrimaryBuildings: to let the user choose where new units should exit.")] "You will also want to add PrimaryBuildings: to let the user choose where new units should exit.")]
public class ClassicProductionQueueInfo : ProductionQueueInfo, Requires<TechTreeInfo>, Requires<PowerManagerInfo>, Requires<PlayerResourcesInfo> public class ClassicProductionQueueInfo : ProductionQueueInfo, Requires<TechTreeInfo>, Requires<PowerManagerInfo>, Requires<PlayerResourcesInfo>
{ {
[Desc("If you build more actors of the same type,", "the same queue will get its build time lowered for every actor produced there.")] [Desc("If you build more actors of the same type,", "the same queue will get its build time lowered for every actor produced there.")]
public readonly bool SpeedUp = false; public readonly bool SpeedUp = false;
[Desc("Every time another production building of the same queue is", [Desc("Every time another production building of the same queue is",
"contructed, the build times of all actors in the queue", "contructed, the build times of all actors in the queue",
"decreased by a percentage of the original time.")] "decreased by a percentage of the original time.")]
public readonly int[] BuildTimeSpeedReduction = {100,85,75,65,60,55,50}; public readonly int[] BuildTimeSpeedReduction = { 100, 85, 75, 65, 60, 55, 50 };
public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init.self, this); } public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init.self, this); }
} }
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
[Sync] bool isActive = false; [Sync] bool isActive = false;
public override void Tick( Actor self ) public override void Tick(Actor self)
{ {
isActive = self.World.ActorsWithTrait<Production>() isActive = self.World.ActorsWithTrait<Production>()
.Any(x => x.Actor.Owner == self.Owner .Any(x => x.Actor.Owner == self.Owner
@@ -64,23 +64,24 @@ namespace OpenRA.Mods.RA
return isActive ? base.BuildableItems() : None; return isActive ? base.BuildableItems() : None;
} }
protected override bool BuildUnit( string name ) protected override bool BuildUnit(string name)
{ {
// Find a production structure to build this actor // Find a production structure to build this actor
var producers = self.World.ActorsWithTrait<Production>() var producers = self.World.ActorsWithTrait<Production>()
.Where(x => x.Actor.Owner == self.Owner .Where(x => x.Actor.Owner == self.Owner
&& x.Trait.Info.Produces.Contains(Info.Type)) && x.Trait.Info.Produces.Contains(Info.Type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ); // prioritize the primary. .OrderByDescending(x => x.Actor.IsPrimaryBuilding())
.ThenByDescending(x => x.Actor.ActorID);
if (!producers.Any()) if (!producers.Any())
{ {
CancelProduction(name,1); CancelProduction(name, 1);
return true; return true;
} }
foreach (var p in producers.Where(p => !p.Actor.IsDisabled())) foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
{ {
if (p.Trait.Produce(p.Actor, Rules.Info[ name ])) if (p.Trait.Produce(p.Actor, Rules.Info[name]))
{ {
FinishProduction(); FinishProduction();
return true; return true;
@@ -92,13 +93,13 @@ namespace OpenRA.Mods.RA
public override int GetBuildTime(String unitString) public override 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 (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0; return 0;
var time = (int) (unit.GetBuildTime() * Info.BuildSpeedModifier); var time = (int)(unit.GetBuildTime() * Info.BuildSpeedModifier);
if (Info.SpeedUp) if (Info.SpeedUp)
{ {