diff --git a/OpenRA.Mods.RA/Crates/UnitUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/UnitUpgradeCrateAction.cs new file mode 100644 index 0000000000..0c1f4b158d --- /dev/null +++ b/OpenRA.Mods.RA/Crates/UnitUpgradeCrateAction.cs @@ -0,0 +1,51 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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. For more information, + * see COPYING. + */ +#endregion + +using System.Linq; + +namespace OpenRA.Mods.RA.Crates +{ + public class UnitUpgradeCrateActionInfo : CrateActionInfo + { + public readonly UnitUpgrade? Upgrade = null; + public readonly int Levels = 1; + + public override object Create(ActorInitializer init) { return new UnitUpgradeCrateAction(init.self, this); } + } + + public class UnitUpgradeCrateAction : CrateAction + { + UnitUpgradeCrateActionInfo crateInfo; + + public UnitUpgradeCrateAction(Actor self, UnitUpgradeCrateActionInfo info) + : base(self, info) + { + crateInfo = info; + } + + public override int GetSelectionShares(Actor collector) + { + var up = collector.TraitOrDefault(); + return up != null && up.CanGainUnitUpgrade(crateInfo.Upgrade) ? info.SelectionShares : 0; + } + + public override void Activate(Actor collector) + { + collector.World.AddFrameEndTask(w => + { + var gainsStatBonuses = collector.TraitOrDefault(); + if (gainsStatBonuses != null) + gainsStatBonuses.GiveUnitUpgrade(crateInfo.Upgrade, crateInfo.Levels); + }); + + base.Activate(collector); + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/GainsUnitUpgrades.cs b/OpenRA.Mods.RA/GainsUnitUpgrades.cs new file mode 100644 index 0000000000..66423db5e0 --- /dev/null +++ b/OpenRA.Mods.RA/GainsUnitUpgrades.cs @@ -0,0 +1,86 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Traits; +using OpenRA.GameRules; + +namespace OpenRA.Mods.RA +{ + public class GainsUnitUpgradesInfo : ITraitInfo + { + public readonly int FirepowerMaxLevel = 15; + public readonly float FirepowerModifier = .2f; + public readonly int ArmorMaxLevel = 15; + public readonly float ArmorModifier = .2f; + public readonly int SpeedMaxLevel = 15; + public readonly decimal SpeedModifier = .2m; + // TODO: weapon range, rate of fire modifiers. potentially a vision modifier. + + public object Create(ActorInitializer init) { return new GainsUnitUpgrades(this); } + } + + public class GainsUnitUpgrades : IFirepowerModifier, IDamageModifier, ISpeedModifier + { + GainsUnitUpgradesInfo info; + [Sync] public int FirepowerLevel = 0; + [Sync] public int SpeedLevel = 0; + [Sync] public int ArmorLevel = 0; + + public GainsUnitUpgrades(GainsUnitUpgradesInfo info) + { + this.info = info; + } + + public bool CanGainUnitUpgrade(UnitUpgrade? upgrade) + { + if (upgrade == UnitUpgrade.Firepower) + return FirepowerLevel < info.FirepowerMaxLevel; + if (upgrade == UnitUpgrade.Armor) + return ArmorLevel < info.ArmorMaxLevel; + if (upgrade == UnitUpgrade.Speed) + return SpeedLevel < info.SpeedMaxLevel; + + return false; + } + + public void GiveUnitUpgrade(UnitUpgrade? upgrade, int numLevels) + { + if (upgrade == UnitUpgrade.Firepower) + FirepowerLevel = Math.Min(FirepowerLevel + numLevels, info.FirepowerMaxLevel); + else if (upgrade == UnitUpgrade.Armor) + ArmorLevel = Math.Min(ArmorLevel + numLevels, info.ArmorMaxLevel); + else if (upgrade == UnitUpgrade.Speed) + SpeedLevel = Math.Min(SpeedLevel + numLevels, info.SpeedMaxLevel); + } + + public float GetFirepowerModifier() + { + return FirepowerLevel > 0 ? (1 + FirepowerLevel * info.FirepowerModifier) : 1; + } + + public float GetDamageModifier(Actor attacker, WarheadInfo warhead) + { + return ArmorLevel > 0 ? (1 / (1 + ArmorLevel * info.ArmorModifier)) : 1; + } + + public decimal GetSpeedModifier() + { + return SpeedLevel > 0 ? (1m + SpeedLevel * info.SpeedModifier) : 1m; + } + } + + public enum UnitUpgrade + { + Firepower = 0, + Armor = 1, + Speed = 2 + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index b8cbf51364..16846cd5d5 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -123,6 +123,7 @@ + @@ -237,6 +238,7 @@ + @@ -538,4 +540,4 @@ copy "FuzzyLogicLibrary.dll" "$(SolutionDir)" cd "$(SolutionDir)" - + \ No newline at end of file diff --git a/mods/cnc/bits/ss/armorcrate.shp b/mods/cnc/bits/ss/armorcrate.shp new file mode 100644 index 0000000000..da763b8653 Binary files /dev/null and b/mods/cnc/bits/ss/armorcrate.shp differ diff --git a/mods/cnc/bits/ss/armorup.aud b/mods/cnc/bits/ss/armorup.aud new file mode 100644 index 0000000000..4f255ef38c Binary files /dev/null and b/mods/cnc/bits/ss/armorup.aud differ diff --git a/mods/cnc/bits/ss/firepowercrate.shp b/mods/cnc/bits/ss/firepowercrate.shp new file mode 100644 index 0000000000..2dbedacd9d Binary files /dev/null and b/mods/cnc/bits/ss/firepowercrate.shp differ diff --git a/mods/cnc/bits/ss/firepowerup.aud b/mods/cnc/bits/ss/firepowerup.aud new file mode 100644 index 0000000000..76c43ab626 Binary files /dev/null and b/mods/cnc/bits/ss/firepowerup.aud differ diff --git a/mods/cnc/bits/ss/rangeup.aud b/mods/cnc/bits/ss/rangeup.aud new file mode 100644 index 0000000000..c2466e16cc Binary files /dev/null and b/mods/cnc/bits/ss/rangeup.aud differ diff --git a/mods/cnc/bits/ss/rateoffireup.aud b/mods/cnc/bits/ss/rateoffireup.aud new file mode 100644 index 0000000000..93340527ea Binary files /dev/null and b/mods/cnc/bits/ss/rateoffireup.aud differ diff --git a/mods/cnc/bits/ss/speedcrate.shp b/mods/cnc/bits/ss/speedcrate.shp new file mode 100644 index 0000000000..367ad82654 Binary files /dev/null and b/mods/cnc/bits/ss/speedcrate.shp differ diff --git a/mods/cnc/bits/ss/speedup.aud b/mods/cnc/bits/ss/speedup.aud new file mode 100644 index 0000000000..09238411ba Binary files /dev/null and b/mods/cnc/bits/ss/speedup.aud differ diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index d53de3449b..93e920eaf7 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -8,6 +8,7 @@ Folders: . ./mods/cnc ./mods/cnc/bits + ./mods/cnc/bits/ss ./mods/cnc/uibits ~^/Content/cnc diff --git a/mods/cnc/sequences/misc.yaml b/mods/cnc/sequences/misc.yaml index d520a08acb..e8416aa33a 100644 --- a/mods/cnc/sequences/misc.yaml +++ b/mods/cnc/sequences/misc.yaml @@ -234,6 +234,15 @@ crate-effects: Start: 0 Length: * Tick: 200 + firepowerup: firepowercrate + Start: 0 + Length: * + armorup: armorcrate + Start: 0 + Length: * + speedup: speedcrate + Start: 0 + Length: * atomicup: idle: