fix #2709 CustomBuildTimeValue should not desync

remove redundant code by outsourcing raw build time calculation
This commit is contained in:
Matthias Mailänder
2013-03-07 21:48:54 +01:00
parent e3fbd40278
commit f3e0ff8758
4 changed files with 27 additions and 18 deletions

View File

@@ -16,8 +16,25 @@ namespace OpenRA.Mods.RA.Buildings
public class CustomBuildTimeValueInfo : TraitInfo<CustomBuildTimeValue>
{
public readonly int Value = 0; //in milisecons
public readonly int Value = 0;
}
public class CustomBuildTimeValue { }
public static class CustomBuildTimeValueExts
{
public static int GetBuildTime(this ActorInfo a)
{
var csv = a.Traits.GetOrDefault<CustomBuildTimeValueInfo>();
if (csv != null)
return csv.Value;
var cost = a.Traits.Contains<ValuedInfo>() ? a.Traits.Get<ValuedInfo>().Cost : 0;
var time = cost
* (25 * 60) /* frames per min */
/ 1000;
return
time;
}
}
}

View File

@@ -87,8 +87,8 @@ namespace OpenRA.Mods.RA
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0;
if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) return 0;
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 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))
@@ -99,11 +99,8 @@ namespace OpenRA.Mods.RA
var speedUp = 1 - (selfsameQueue.SpeedUp * (selfsameBuildings.Count() - 1)).Clamp(0, selfsameQueue.MaxSpeedUp);
var time = cost
* Info.BuildSpeed
* (25 * 60) /* frames per min */
* speedUp
/ 1000;
var time = unit.GetBuildTime() * Info.BuildSpeed * speedUp;
return (int) time;
}

View File

@@ -259,15 +259,10 @@ namespace OpenRA.Mods.RA
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0;
if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) return 0;
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
var time = cost
* Info.BuildSpeed
* (25 * 60) /* frames per min */
/ 1000;
if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0;
if (unit.Traits.Contains<CustomBuildTimeValueInfo>())
time = unit.Traits.Get<CustomBuildTimeValueInfo>().Value * (1 / Info.BuildSpeed);
var time = unit.GetBuildTime() * Info.BuildSpeed;
return (int) time;
}

View File

@@ -59,7 +59,7 @@ PROC:
Tooltip:
Name: Tiberium Refinery
Icon: procicnh
Description: Processes raw Tiberium into useable resources
Description: Processes raw Tiberium to sell it for cash.
Buildable:
BuildPaletteOrder: 20
Prerequisites: anypower
@@ -89,7 +89,7 @@ PROC:
CustomSellValue:
Value: 600
CustomBuildTimeValue:
Value: 80
Value: 900
FreeActor:
Actor: HARV
InitialActivity: FindResources