Skip to content

Instantly share code, notes, and snippets.

@Mailaender
Created March 12, 2013 11:29
Show Gist options
  • Save Mailaender/5142191 to your computer and use it in GitHub Desktop.
Save Mailaender/5142191 to your computer and use it in GitHub Desktop.
optional ProductionQueueSpeedup with integer math to avoid potential desyncs
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