Created
March 12, 2013 11:29
-
-
Save Mailaender/5142191 to your computer and use it in GitHub Desktop.
optional ProductionQueueSpeedup with integer math to avoid potential desyncs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClassicProductionQueueInfo : ProductionQueueInfo, Requires<TechTreeInfo>, Requires<PowerManagerInfo>, Requires<PlayerResourcesInfo> | |
{ | |
public readonly bool SpeedUp = false; | |
public readonly int BuildTimeSpeedUpDivisor = 2; | |
public readonly int MaxBuildTimeReductionSteps = 6; | |
public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init.self, this); } | |
} | |
[...] | |
public override int GetBuildTime(String unitString) | |
{ | |
var unit = Rules.Info[unitString]; | |
if (unit == null || ! unit.Traits.Contains<BuildableInfo>()) | |
return 0; | |
if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) | |
return 0; | |
var selfsameBuildings = self.World.ActorsWithTrait<Production>() | |
.Where(p => p.Trait.Info.Produces.Contains(unit.Traits.Get<BuildableInfo>().Queue)) | |
.Where(p => p.Actor.Owner == self.Owner).ToArray(); | |
var time = (int) (unit.GetBuildTime() * Info.BuildSpeedModifier); | |
if (Info.SpeedUp && selfsameBuildings.Count() > 1) | |
for (int i = 1; i < Info.MaxBuildTimeReductionSteps; i++) | |
time /= Info.BuildTimeSpeedUpDivisor; | |
return time; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment