Shift CustomBuildTimeValue to Buildable.
This commit is contained in:
@@ -323,7 +323,6 @@
|
||||
<Compile Include="Traits\Crates\RevealMapCrateAction.cs" />
|
||||
<Compile Include="Traits\Crates\SupportPowerCrateAction.cs" />
|
||||
<Compile Include="Traits\Crushable.cs" />
|
||||
<Compile Include="Traits\CustomBuildTimeValue.cs" />
|
||||
<Compile Include="Traits\CustomSellValue.cs" />
|
||||
<Compile Include="Traits\CustomSelectionSize.cs" />
|
||||
<Compile Include="Traits\DamagedByTerrain.cs" />
|
||||
|
||||
@@ -71,7 +71,20 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
return ai.GetBuildTime();
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
return 0;
|
||||
|
||||
var time = bi.BuildDuration;
|
||||
if (time == -1)
|
||||
{
|
||||
var valued = ai.TraitInfoOrDefault<ValuedInfo>();
|
||||
time = valued != null ? valued.Cost : 0;
|
||||
}
|
||||
|
||||
time = time * bi.BuildDurationModifier / 100;
|
||||
return time;
|
||||
}
|
||||
|
||||
[Desc("Returns the cruise altitude of the requested unit type (zero if it is ground-based).")]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
|
||||
// DisplayTimer was replaced by DisplayTimerStances
|
||||
if (engineVersion < 20160710)
|
||||
if (engineVersion < 20160820)
|
||||
{
|
||||
if (node.Key == "DisplayTimer")
|
||||
{
|
||||
@@ -305,6 +305,30 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
if (engineVersion < 20160821)
|
||||
{
|
||||
// Shifted custom build time properties to Buildable
|
||||
if (depth == 0)
|
||||
{
|
||||
var cbtv = node.Value.Nodes.FirstOrDefault(n => n.Key == "CustomBuildTimeValue");
|
||||
if (cbtv != null)
|
||||
{
|
||||
var bi = node.Value.Nodes.FirstOrDefault(n => n.Key == "Buildable");
|
||||
|
||||
if (bi == null)
|
||||
node.Value.Nodes.Add(bi = new MiniYamlNode("Buildable", ""));
|
||||
|
||||
var value = cbtv.Value.Nodes.First(n => n.Key == "Value");
|
||||
value.Key = "BuildDuration";
|
||||
bi.Value.Nodes.Add(value);
|
||||
bi.Value.Nodes.Add(new MiniYamlNode("BuildDurationModifier", "100"));
|
||||
}
|
||||
|
||||
node.Value.Nodes.RemoveAll(n => n.Key == "CustomBuildTimeValue");
|
||||
node.Value.Nodes.RemoveAll(n => n.Key == "-CustomBuildTimeValue");
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user