diff --git a/OpenRA.Game/Effects/FlashTarget.cs b/OpenRA.Game/Effects/FlashTarget.cs index d6ee3a934e..4a6ff943f6 100755 --- a/OpenRA.Game/Effects/FlashTarget.cs +++ b/OpenRA.Game/Effects/FlashTarget.cs @@ -24,7 +24,7 @@ using OpenRA.Traits; namespace OpenRA.Effects { - class FlashTarget : IEffect + public class FlashTarget : IEffect { Actor target; int remainingTicks = 4; diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 7abb2d3b6c..f40f0fcc30 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -21,9 +21,8 @@ using System; using System.Collections.Generic; using System.Linq; -using OpenRA.GameRules; -using OpenRA.Traits; using OpenRA.Support; +using OpenRA.Traits; namespace OpenRA { @@ -45,28 +44,6 @@ namespace OpenRA return xs.Aggregate(1f, (a, x) => a * x); } - public static WeaponInfo GetPrimaryWeapon(this Actor self) - { - var info = self.Info.Traits.GetOrDefault(); - if (info == null) return null; - - var weapon = info.PrimaryWeapon; - if (weapon == null) return null; - - return Rules.Weapons[weapon.ToLowerInvariant()]; - } - - public static WeaponInfo GetSecondaryWeapon(this Actor self) - { - var info = self.Info.Traits.GetOrDefault(); - if (info == null) return null; - - var weapon = info.SecondaryWeapon; - if (weapon == null) return null; - - return Rules.Weapons[weapon.ToLowerInvariant()]; - } - public static int GetMaxHP(this Actor self) { var oai = self.Info.Traits.GetOrDefault(); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index dfc2308e5b..5eef46011b 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -89,7 +89,6 @@ - @@ -102,7 +101,6 @@ - @@ -136,7 +134,6 @@ - @@ -175,7 +172,6 @@ - @@ -235,7 +231,6 @@ - diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 9407e8ce9b..9eaf47d474 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -52,9 +52,9 @@ namespace OpenRA.Orders world.WorldRenderer.DrawSelectionBox(a, Color.White, true); if (a.Owner == world.LocalPlayer) { - if (a.traits.Contains()) - world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.Yellow), - a.CenterLocation, (int)a.GetPrimaryWeapon().Range); + //if (a.traits.Contains()) + // world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.Yellow), + // a.CenterLocation, (int)a.GetPrimaryWeapon().Range); if (a.traits.Contains()) world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.LimeGreen), diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 0bf8bfc186..5138188576 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -21,7 +21,6 @@ using System; using System.Drawing; using System.Linq; -using OpenRA.GameRules; using OpenRA.Graphics; namespace OpenRA.Traits @@ -82,7 +81,7 @@ namespace OpenRA.Traits return a / step; } - static float2 RotateVectorByFacing(float2 v, int facing, float ecc) + public static float2 RotateVectorByFacing(float2 v, int facing, float ecc) { var angle = (facing / 256f) * (2 * (float)Math.PI); var sinAngle = (float)Math.Sin(angle); @@ -93,17 +92,6 @@ namespace OpenRA.Traits ecc * (cosAngle * v.Y - sinAngle * v.X)); } - static float2 GetRecoil(Actor self, float recoil) - { - var abInfo = self.Info.Traits.GetOrDefault(); - if (abInfo == null || abInfo.Recoil == 0) return float2.Zero; - var rut = self.traits.GetOrDefault(); - if (rut == null) return float2.Zero; - - var facing = self.traits.Get().turretFacing; - return RotateVectorByFacing(new float2(0, recoil * self.Info.Traits.Get().Recoil), facing, .7f); - } - public static float2 CenterOfCell(int2 loc) { return new float2(12, 12) + Game.CellSize * (float2)loc; @@ -114,19 +102,6 @@ namespace OpenRA.Traits return 0.5f * (CenterOfCell(from) + CenterOfCell(to)); } - public static float2 GetTurretPosition(Actor self, Unit unit, int[] offset, float recoil) - { - if( unit == null ) return offset.AbsOffset(); /* things that don't have a rotating base don't need the turrets repositioned */ - - var ru = self.traits.GetOrDefault(); - var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8; - var bodyFacing = unit.Facing; - var quantizedFacing = QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); - - return (RotateVectorByFacing(offset.RelOffset(), quantizedFacing, .7f) + GetRecoil(self, recoil)) - + offset.AbsOffset(); - } - public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); } public static float2 RelOffset(this int[] offset) { return new float2(offset[0], offset[1]); } public static float2 AbsOffset(this int[] offset) { return new float2(offset.ElementAtOrDefault(2), offset.ElementAtOrDefault(3)); } @@ -144,12 +119,6 @@ namespace OpenRA.Traits (next, a) => { a.NextActivity = next; return a; }); } - public static float GetMaximumRange(Actor self) - { - return new[] { self.GetPrimaryWeapon(), self.GetSecondaryWeapon() } - .Where(w => w != null).Max(w => w.Range); - } - public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } public static int2 CellContaining(float2 pos) { return (1f / Game.CellSize * pos).ToInt2(); } diff --git a/OpenRA.Game/Traits/World/SmudgeLayer.cs b/OpenRA.Game/Traits/World/SmudgeLayer.cs index c76667f325..b827cfdd18 100644 --- a/OpenRA.Game/Traits/World/SmudgeLayer.cs +++ b/OpenRA.Game/Traits/World/SmudgeLayer.cs @@ -26,7 +26,7 @@ using OpenRA.FileFormats; namespace OpenRA.Traits { - class SmudgeLayerInfo : ITraitInfo + public class SmudgeLayerInfo : ITraitInfo { public readonly string Type = "Scorch"; public readonly string[] Types = {"sc1", "sc2", "sc3", "sc4", "sc5", "sc6"}; @@ -34,7 +34,7 @@ namespace OpenRA.Traits public object Create(ActorInitializer init) { return new SmudgeLayer(this); } } - class SmudgeLayer: IRenderOverlay, ILoadWorldHook + public class SmudgeLayer: IRenderOverlay, ILoadWorldHook { public SmudgeLayerInfo Info; SpriteRenderer spriteRenderer; diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index 5181c0d224..cc6777f05e 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -18,10 +18,10 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Effects; using OpenRA.Graphics; +using OpenRA.Mods.RA; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Effects diff --git a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs index 3459cce13e..a0a04422d1 100644 --- a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs +++ b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs @@ -20,6 +20,7 @@ using System.Linq; using OpenRA.GameRules; +using OpenRA.Mods.RA; using OpenRA.Traits; namespace OpenRA.Mods.Cnc diff --git a/OpenRA.Game/Traits/Activities/Attack.cs b/OpenRA.Mods.RA/Activities/Attack.cs old mode 100644 new mode 100755 similarity index 92% rename from OpenRA.Game/Traits/Activities/Attack.cs rename to OpenRA.Mods.RA/Activities/Attack.cs index b060183329..c227e9b6c3 --- a/OpenRA.Game/Traits/Activities/Attack.cs +++ b/OpenRA.Mods.RA/Activities/Attack.cs @@ -18,7 +18,10 @@ */ #endregion -namespace OpenRA.Traits.Activities +using OpenRA.Traits; +using OpenRA.Traits.Activities; + +namespace OpenRA.Mods.RA.Activities { /* non-turreted attack */ public class Attack : IActivity diff --git a/OpenRA.Game/Traits/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs old mode 100644 new mode 100755 similarity index 95% rename from OpenRA.Game/Traits/AttackBase.cs rename to OpenRA.Mods.RA/AttackBase.cs index 3b897c7a4a..b2b38e77e4 --- a/OpenRA.Game/Traits/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -24,8 +24,9 @@ using System.Linq; using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.GameRules; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.RA { public class AttackBaseInfo : ITraitInfo { @@ -178,7 +179,7 @@ namespace OpenRA.Traits firedBy = self, target = target, - src = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2(), + src = self.CenterLocation.ToInt2() + Combat.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2(), srcAltitude = unit != null ? unit.Altitude : 0, dest = target.CenterLocation.ToInt2(), destAltitude = destUnit != null ? destUnit.Altitude : 0, diff --git a/OpenRA.Mods.RA/AutoHeal.cs b/OpenRA.Mods.RA/AutoHeal.cs index a55329cacf..dbb62b77f7 100644 --- a/OpenRA.Mods.RA/AutoHeal.cs +++ b/OpenRA.Mods.RA/AutoHeal.cs @@ -19,8 +19,8 @@ #endregion using System.Linq; +using OpenRA.Mods.RA.Activities; using OpenRA.Traits; -using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA { @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA bool NeedsNewTarget(Actor self) { var attack = self.traits.Get(); - var range = Util.GetMaximumRange(self); + var range = Combat.GetMaximumRange(self); if (attack.target == null) return true; // he's dead. @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - var range = Util.GetMaximumRange(self); + var range = Combat.GetMaximumRange(self); if (NeedsNewTarget(self)) AttackTarget(self, ChooseTarget(self, range)); diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index 053e3a0575..c72955b0e9 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA if (--nextScanTime <= 0) { var attack = self.traits.Get(); - var range = Util.GetMaximumRange(self); + var range = Combat.GetMaximumRange(self); if (attack.target == null || (attack.target.Location - self.Location).LengthSquared > range * range) diff --git a/OpenRA.Game/Combat.cs b/OpenRA.Mods.RA/Combat.cs old mode 100644 new mode 100755 similarity index 74% rename from OpenRA.Game/Combat.cs rename to OpenRA.Mods.RA/Combat.cs index 49164f85c0..1ed1d50449 --- a/OpenRA.Game/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -23,9 +23,8 @@ using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; using OpenRA.Traits; -using OpenRA.FileFormats; -namespace OpenRA +namespace OpenRA.Mods.RA { public static class Combat /* some utility bits that are shared between various things */ { @@ -194,5 +193,57 @@ namespace OpenRA return false; } + + public static float GetMaximumRange(Actor self) + { + return new[] { self.GetPrimaryWeapon(), self.GetSecondaryWeapon() } + .Where(w => w != null).Max(w => w.Range); + } + + public static WeaponInfo GetPrimaryWeapon(this Actor self) + { + var info = self.Info.Traits.GetOrDefault(); + if (info == null) return null; + + var weapon = info.PrimaryWeapon; + if (weapon == null) return null; + + return Rules.Weapons[weapon.ToLowerInvariant()]; + } + + public static WeaponInfo GetSecondaryWeapon(this Actor self) + { + var info = self.Info.Traits.GetOrDefault(); + if (info == null) return null; + + var weapon = info.SecondaryWeapon; + if (weapon == null) return null; + + return Rules.Weapons[weapon.ToLowerInvariant()]; + } + + static float2 GetRecoil(Actor self, float recoil) + { + var abInfo = self.Info.Traits.GetOrDefault(); + if (abInfo == null || abInfo.Recoil == 0) return float2.Zero; + var rut = self.traits.GetOrDefault(); + if (rut == null) return float2.Zero; + + var facing = self.traits.Get().turretFacing; + return Util.RotateVectorByFacing(new float2(0, recoil * self.Info.Traits.Get().Recoil), facing, .7f); + } + + public static float2 GetTurretPosition(Actor self, Unit unit, int[] offset, float recoil) + { + if( unit == null ) return offset.AbsOffset(); /* things that don't have a rotating base don't need the turrets repositioned */ + + var ru = self.traits.GetOrDefault(); + var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8; + var bodyFacing = unit.Facing; + var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); + + return (Util.RotateVectorByFacing(offset.RelOffset(), quantizedFacing, .7f) + GetRecoil(self, recoil)) + + offset.AbsOffset(); + } } } diff --git a/OpenRA.Game/Traits/Hazardous.cs b/OpenRA.Mods.RA/Hazardous.cs old mode 100644 new mode 100755 similarity index 97% rename from OpenRA.Game/Traits/Hazardous.cs rename to OpenRA.Mods.RA/Hazardous.cs index 615472cb64..2e44c716bc --- a/OpenRA.Game/Traits/Hazardous.cs +++ b/OpenRA.Mods.RA/Hazardous.cs @@ -16,12 +16,13 @@ * You should have received a copy of the GNU General Public License * along with OpenRA. If not, see . */ -#endregion +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.Traits; -using System.Linq; -using System.Collections.Generic; - -namespace OpenRA.Traits +namespace OpenRA.Mods.RA { class AntiAirInfo : ITraitInfo { diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 7629fe2562..9444b96461 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -46,6 +46,7 @@ + @@ -70,14 +71,18 @@ + + + + diff --git a/OpenRA.Mods.RA/RenderUnitReload.cs b/OpenRA.Mods.RA/RenderUnitReload.cs index 5dc5042b79..c7884bf5fc 100644 --- a/OpenRA.Mods.RA/RenderUnitReload.cs +++ b/OpenRA.Mods.RA/RenderUnitReload.cs @@ -18,8 +18,8 @@ */ #endregion +using OpenRA.Mods.RA.Activities; using OpenRA.Traits; -using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA { diff --git a/OpenRA.Mods.RA/RenderUnitRotor.cs b/OpenRA.Mods.RA/RenderUnitRotor.cs index 64975d93e4..7c3122dae2 100644 --- a/OpenRA.Mods.RA/RenderUnitRotor.cs +++ b/OpenRA.Mods.RA/RenderUnitRotor.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA rotorAnim.PlayRepeating("rotor"); anims.Add( "rotor_1", new AnimationWithOffset( rotorAnim, - () => Traits.Util.GetTurretPosition( self, unit, info.PrimaryOffset, 0 ), + () => Combat.GetTurretPosition( self, unit, info.PrimaryOffset, 0 ), null ) { ZOffset = 1 } ); if (info.SecondaryOffset == null) return; @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA secondRotorAnim.PlayRepeating( "rotor2" ); anims.Add( "rotor_2", new AnimationWithOffset( secondRotorAnim, - () => Traits.Util.GetTurretPosition(self, unit, info.SecondaryOffset, 0), + () => Combat.GetTurretPosition(self, unit, info.SecondaryOffset, 0), null) { ZOffset = 1 }); } diff --git a/OpenRA.Mods.RA/RenderUnitSpinner.cs b/OpenRA.Mods.RA/RenderUnitSpinner.cs index 17a34fa08a..96898a2ad6 100644 --- a/OpenRA.Mods.RA/RenderUnitSpinner.cs +++ b/OpenRA.Mods.RA/RenderUnitSpinner.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA spinnerAnim.PlayRepeating( "spinner" ); anims.Add( "spinner", new AnimationWithOffset( spinnerAnim, - () => Traits.Util.GetTurretPosition( self, unit, info.Offset, 0 ), + () => Combat.GetTurretPosition( self, unit, info.Offset, 0 ), null ) { ZOffset = 1 } ); } } diff --git a/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs b/OpenRA.Mods.RA/RenderUnitTurreted.cs old mode 100644 new mode 100755 similarity index 84% rename from OpenRA.Game/Traits/Render/RenderUnitTurreted.cs rename to OpenRA.Mods.RA/RenderUnitTurreted.cs index a8bff2e084..6660b6c792 --- a/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs +++ b/OpenRA.Mods.RA/RenderUnitTurreted.cs @@ -19,8 +19,9 @@ #endregion using OpenRA.Graphics; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.RA { class RenderUnitTurretedInfo : RenderUnitInfo { @@ -43,13 +44,13 @@ namespace OpenRA.Traits if( attackInfo.PrimaryOffset != null ) anims.Add("turret_1", new AnimationWithOffset( turretAnim, - () => Util.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil), + () => Combat.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil), null) { ZOffset = 1 }); if (attackInfo.SecondaryOffset != null) anims.Add("turret_2", new AnimationWithOffset( turretAnim, - () => Util.GetTurretPosition(self, unit, attackInfo.SecondaryOffset, attack.secondaryRecoil), + () => Combat.GetTurretPosition(self, unit, attackInfo.SecondaryOffset, attack.secondaryRecoil), null) { ZOffset = 1 }); if( attackInfo.MuzzleFlash ) @@ -59,7 +60,7 @@ namespace OpenRA.Traits () => (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */ anims.Add( "muzzle_flash", new AnimationWithOffset( muzzleFlash, - () => Util.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil), + () => Combat.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil), () => attack.primaryRecoil <= 0 ) ); } } diff --git a/OpenRA.Mods.RA/ThrowsParticles.cs b/OpenRA.Mods.RA/ThrowsParticles.cs index e8e1e6784d..a0e1fca12e 100644 --- a/OpenRA.Mods.RA/ThrowsParticles.cs +++ b/OpenRA.Mods.RA/ThrowsParticles.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA if (info != null) { alt = 0; - pos = Traits.Util.GetTurretPosition(self, self.traits.Get(), info.Offset, 0); + pos = Combat.GetTurretPosition(self, self.traits.Get(), info.Offset, 0); var ru = self.traits.Get(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset();