Avoid unnecessary lookups in the production logic

by improving the GetBuildTime method and moving lookups around.
This commit is contained in:
abcdefg30
2016-01-21 16:18:14 +01:00
parent 6272d79072
commit 17daac11a1
3 changed files with 16 additions and 7 deletions

View File

@@ -125,14 +125,19 @@ namespace OpenRA.Mods.Common.Traits
if (bi == null)
return 0;
return GetBuildTime(ai);
}
public override int GetBuildTime(ActorInfo unit)
{
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0;
var time = (int)(ai.GetBuildTime() * Info.BuildSpeed);
var time = (int)(unit.GetBuildTime() * Info.BuildSpeed);
if (info.SpeedUp)
{
var type = bi.BuildAtProductionType ?? info.Type;
var type = unit.TraitInfo<BuildableInfo>().BuildAtProductionType ?? info.Type;
var selfsameProductionsCount = self.World.ActorsWithTrait<Production>()
.Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));