Shift CustomBuildTimeValue to Buildable.

This commit is contained in:
Zimmermann Gyula
2016-08-21 12:05:32 +02:00
parent e93d7dd172
commit de10cb22e8
7 changed files with 61 additions and 50 deletions

View File

@@ -37,6 +37,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Palette used for the production icon.")]
[PaletteReference] public readonly string IconPalette = "chrome";
[Desc("Base build time in frames (-1 indicates to use the unit's Value).")]
public readonly int BuildDuration = -1;
[Desc("Percentage modifier to apply to the build duration.")]
public readonly int BuildDurationModifier = 150;
// TODO: UI fluff; doesn't belong here
public readonly int BuildPaletteOrder = 9999;
}

View File

@@ -1,40 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Overrides the build time calculated by actor value.")]
public class CustomBuildTimeValueInfo : TraitInfo<CustomBuildTimeValue>
{
[FieldLoader.Require]
[Desc("Measured in ticks.")]
public readonly int Value = 0;
}
public class CustomBuildTimeValue { }
public static class CustomBuildTimeValueExts
{
const int FramesPerMin = 25 * 60;
public static int GetBuildTime(this ActorInfo a)
{
var csv = a.TraitInfoOrDefault<CustomBuildTimeValueInfo>();
if (csv != null)
return csv.Value;
var cost = a.HasTraitInfo<ValuedInfo>() ? a.TraitInfo<ValuedInfo>().Cost : 0;
return cost * FramesPerMin / 1000;
}
}
}

View File

@@ -120,19 +120,20 @@ namespace OpenRA.Mods.Common.Traits
public override int GetBuildTime(string unitString)
{
return GetBuildTime(self.World.Map.Rules.Actors[unitString]);
var actorInfo = self.World.Map.Rules.Actors[unitString];
return GetBuildTime(actorInfo, actorInfo.TraitInfo<BuildableInfo>());
}
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi)
{
if (developerMode.FastBuild)
return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
var time = base.GetBuildTime(unit, bi);
if (info.SpeedUp)
{
var type = (bi ?? unit.TraitInfo<BuildableInfo>()).BuildAtProductionType ?? info.Type;
var type = bi.BuildAtProductionType ?? info.Type;
var selfsameProductionsCount = self.World.ActorsWithTrait<Production>()
.Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));

View File

@@ -311,15 +311,23 @@ namespace OpenRA.Mods.Common.Traits
public virtual int GetBuildTime(string unitString)
{
return GetBuildTime(self.World.Map.Rules.Actors[unitString]);
var actorInfo = self.World.Map.Rules.Actors[unitString];
return GetBuildTime(actorInfo, actorInfo.TraitInfo<BuildableInfo>());
}
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi)
{
if (developerMode.FastBuild)
return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
var time = bi.BuildDuration;
if (time == -1)
{
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
time = valued != null ? valued.Cost : 0;
}
time = time * bi.BuildDurationModifier * Info.BuildSpeed / 10000;
return time;
}