From 47f95ff596a249a7e676c20c8afe4ebe1efa6391 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 17 Jan 2010 09:35:51 +1300 Subject: [PATCH] moved the rest of the mine crap into mod dll --- OpenRa.Game/Effects/Explosion.cs | 2 +- OpenRa.Game/GameRules/AftermathInfo.cs | 2 +- OpenRa.Game/GameRules/GeneralInfo.cs | 2 +- OpenRa.Game/GameRules/InfoLoader.cs | 2 +- OpenRa.Game/GameRules/ProjectileInfo.cs | 2 +- OpenRa.Game/GameRules/Rules.cs | 2 +- OpenRa.Game/GameRules/TechTree.cs | 2 +- OpenRa.Game/GameRules/VoiceInfo.cs | 27 ++++++++++- OpenRa.Game/GameRules/WeaponInfo.cs | 2 +- OpenRa.Game/OpenRa.Game.csproj | 1 - OpenRa.Game/Traits/Mine.cs | 46 ------------------- OpenRa.Game/Traits/MineImmune.cs | 3 +- OpenRa.Game/Traits/TraitsInterfaces.cs | 18 ++++---- OpenRa.Game/VoicePool.cs | 29 ------------ OpenRa.Mods.RA/Mine.cs | 60 +++++++++++++++++++++++++ OpenRa.Mods.RA/OpenRa.Mods.RA.csproj | 1 + 16 files changed, 105 insertions(+), 96 deletions(-) delete mode 100644 OpenRa.Game/VoicePool.cs create mode 100644 OpenRa.Mods.RA/Mine.cs diff --git a/OpenRa.Game/Effects/Explosion.cs b/OpenRa.Game/Effects/Explosion.cs index fc1509c6de..e6ac46ccb2 100755 --- a/OpenRa.Game/Effects/Explosion.cs +++ b/OpenRa.Game/Effects/Explosion.cs @@ -4,7 +4,7 @@ using OpenRa.Traits; namespace OpenRa.Effects { - class Explosion : IEffect + public class Explosion : IEffect { Animation anim; int2 pos; diff --git a/OpenRa.Game/GameRules/AftermathInfo.cs b/OpenRa.Game/GameRules/AftermathInfo.cs index 540d4c8f03..e571f171c2 100644 --- a/OpenRa.Game/GameRules/AftermathInfo.cs +++ b/OpenRa.Game/GameRules/AftermathInfo.cs @@ -1,7 +1,7 @@  namespace OpenRa.GameRules { - class AftermathInfo + public class AftermathInfo { public readonly int MTankDistance = 0; public readonly float QuakeUnitDamage = 0f; diff --git a/OpenRa.Game/GameRules/GeneralInfo.cs b/OpenRa.Game/GameRules/GeneralInfo.cs index 82cc69b453..1a60e473d9 100644 --- a/OpenRa.Game/GameRules/GeneralInfo.cs +++ b/OpenRa.Game/GameRules/GeneralInfo.cs @@ -2,7 +2,7 @@ using System; namespace OpenRa.GameRules { - class GeneralInfo + public class GeneralInfo { /* Crates */ public readonly int CrateMinimum = 0; diff --git a/OpenRa.Game/GameRules/InfoLoader.cs b/OpenRa.Game/GameRules/InfoLoader.cs index 76a4e331c3..5e6cafb88f 100644 --- a/OpenRa.Game/GameRules/InfoLoader.cs +++ b/OpenRa.Game/GameRules/InfoLoader.cs @@ -9,7 +9,7 @@ using System.Collections; namespace OpenRa.GameRules { - class InfoLoader : IEnumerable> + public class InfoLoader : IEnumerable> { readonly Dictionary infos = new Dictionary(); diff --git a/OpenRa.Game/GameRules/ProjectileInfo.cs b/OpenRa.Game/GameRules/ProjectileInfo.cs index 92336ba80f..70140bf598 100644 --- a/OpenRa.Game/GameRules/ProjectileInfo.cs +++ b/OpenRa.Game/GameRules/ProjectileInfo.cs @@ -1,7 +1,7 @@  namespace OpenRa.GameRules { - class ProjectileInfo + public class ProjectileInfo { public readonly bool AA = false; public readonly bool AG = true; diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index 03e1ad5f11..c79ce4a3fa 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -7,7 +7,7 @@ using OpenRa.GameRules; namespace OpenRa { - static class Rules + public static class Rules { public static IniFile AllRules; public static Dictionary> Categories = new Dictionary>(); diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index 47843b51f8..f11343fc39 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -5,7 +5,7 @@ using OpenRa.Traits; namespace OpenRa.GameRules { - class TechTree + public class TechTree { readonly Cache> producesIndex = new Cache>(x => new List()); diff --git a/OpenRa.Game/GameRules/VoiceInfo.cs b/OpenRa.Game/GameRules/VoiceInfo.cs index a458c4a139..8505ecaf26 100644 --- a/OpenRa.Game/GameRules/VoiceInfo.cs +++ b/OpenRa.Game/GameRules/VoiceInfo.cs @@ -7,7 +7,7 @@ using IjwFramework.Collections; namespace OpenRa.GameRules { - class VoiceInfo + public class VoiceInfo { public readonly string[] SovietVariants = { ".aud" }; public readonly string[] AlliedVariants = { ".aud" }; @@ -30,4 +30,29 @@ namespace OpenRa.GameRules }); } } + + public class VoicePool + { + readonly string[] clips; + readonly List liveclips = new List(); + + public VoicePool(params string[] clips) + { + this.clips = clips; + } + + public string GetNext() + { + if (liveclips.Count == 0) + liveclips.AddRange(clips); + + if (liveclips.Count == 0) + return null; /* avoid crashing if there's no clips at all */ + + var i = Game.CosmeticRandom.Next(liveclips.Count); + var s = liveclips[i]; + liveclips.RemoveAt(i); + return s; + } + } } diff --git a/OpenRa.Game/GameRules/WeaponInfo.cs b/OpenRa.Game/GameRules/WeaponInfo.cs index 71b3ec760e..e76ce3c4ea 100755 --- a/OpenRa.Game/GameRules/WeaponInfo.cs +++ b/OpenRa.Game/GameRules/WeaponInfo.cs @@ -1,7 +1,7 @@  namespace OpenRa.GameRules { - class WeaponInfo + public class WeaponInfo { public readonly string Anim = null; public readonly int Burst = 1; diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index f6c2dd173a..4f3afcfc26 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -288,7 +288,6 @@ - diff --git a/OpenRa.Game/Traits/Mine.cs b/OpenRa.Game/Traits/Mine.cs index 319d672c39..34188ff23f 100644 --- a/OpenRa.Game/Traits/Mine.cs +++ b/OpenRa.Game/Traits/Mine.cs @@ -4,51 +4,5 @@ using OpenRa.Effects; namespace OpenRa.Traits { - class MineInfo : ITraitInfo - { - public readonly int Damage = 0; - public readonly UnitMovementType[] TriggeredBy = { }; - public readonly string Warhead = "ATMine"; - public readonly bool AvoidFriendly = true; - public object Create(Actor self) { return new Mine(self); } - } - - class Mine : ICrushable, IOccupySpace - { - readonly Actor self; - public Mine(Actor self) - { - this.self = self; - Game.UnitInfluence.Add(self, this); - } - - public void OnCrush(Actor crusher) - { - if (crusher.traits.Contains() && crusher.Owner == self.Owner) - return; - - var info = self.Info.Traits.Get(); - var warhead = Rules.WarheadInfo[info.Warhead]; - - Game.world.AddFrameEndTask(_ => - { - Game.world.Remove(self); - Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false)); - crusher.InflictDamage(crusher, info.Damage, warhead); - }); - } - - public bool IsPathableCrush(UnitMovementType umt, Player player) - { - return !self.Info.Traits.Get().AvoidFriendly || (player != Game.LocalPlayer); - } - - public bool IsCrushableBy(UnitMovementType umt, Player player) - { - return self.Info.Traits.Get().TriggeredBy.Contains(umt); - } - - public IEnumerable OccupiedCells() { yield return self.Location; } - } } diff --git a/OpenRa.Game/Traits/MineImmune.cs b/OpenRa.Game/Traits/MineImmune.cs index ad195c13a3..79f1140290 100644 --- a/OpenRa.Game/Traits/MineImmune.cs +++ b/OpenRa.Game/Traits/MineImmune.cs @@ -1,6 +1,5 @@  namespace OpenRa.Traits { - class MineImmuneInfo : StatelessTraitInfo { } - class MineImmune { } + } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 3f50c948da..7b51842468 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -32,19 +32,19 @@ namespace OpenRa.Traits } public interface IOccupySpace { IEnumerable OccupiedCells(); } interface INotifyAttack { void Attacking(Actor self); } - interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } - interface IDamageModifier { float GetDamageModifier(); } - interface ISpeedModifier { float GetSpeedModifier(); } - interface IPaletteModifier { void AdjustPalette(Bitmap b); } - interface IPips { IEnumerable GetPips(Actor self); } - interface ITags { IEnumerable GetTags(); } - interface IMovement + public interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } + public interface IDamageModifier { float GetDamageModifier(); } + public interface ISpeedModifier { float GetSpeedModifier(); } + public interface IPaletteModifier { void AdjustPalette(Bitmap b); } + public interface IPips { IEnumerable GetPips(Actor self); } + public interface ITags { IEnumerable GetTags(); } + public interface IMovement { UnitMovementType GetMovementType(); bool CanEnterCell(int2 location); } - interface ICrushable + public interface ICrushable { void OnCrush(Actor crusher); bool IsCrushableBy(UnitMovementType umt, Player player); @@ -75,7 +75,7 @@ namespace OpenRa.Traits public interface ITraitInfo { object Create(Actor self); } - class StatelessTraitInfo : ITraitInfo + public class StatelessTraitInfo : ITraitInfo where T : new() { static Lazy Instance = Lazy.New(() => new T()); diff --git a/OpenRa.Game/VoicePool.cs b/OpenRa.Game/VoicePool.cs deleted file mode 100644 index 8d944db5ec..0000000000 --- a/OpenRa.Game/VoicePool.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; - -namespace OpenRa -{ - class VoicePool - { - readonly string[] clips; - readonly List liveclips = new List(); - - public VoicePool(params string[] clips) - { - this.clips = clips; - } - - public string GetNext() - { - if (liveclips.Count == 0) - liveclips.AddRange(clips); - - if (liveclips.Count == 0) - return null; /* avoid crashing if there's no clips at all */ - - var i = Game.CosmeticRandom.Next(liveclips.Count); - var s = liveclips[i]; - liveclips.RemoveAt(i); - return s; - } - } -} diff --git a/OpenRa.Mods.RA/Mine.cs b/OpenRa.Mods.RA/Mine.cs new file mode 100644 index 0000000000..f38d61fc9c --- /dev/null +++ b/OpenRa.Mods.RA/Mine.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Traits; +using OpenRa.Effects; + +namespace OpenRa.Mods.RA +{ + class MineInfo : ITraitInfo + { + public readonly int Damage = 0; + public readonly UnitMovementType[] TriggeredBy = { }; + public readonly string Warhead = "ATMine"; + public readonly bool AvoidFriendly = true; + + public object Create(Actor self) { return new Mine(self); } + } + + class Mine : ICrushable, IOccupySpace + { + readonly Actor self; + public Mine(Actor self) + { + this.self = self; + Game.UnitInfluence.Add(self, this); + } + + public void OnCrush(Actor crusher) + { + if (crusher.traits.Contains() && crusher.Owner == self.Owner) + return; + + var info = self.Info.Traits.Get(); + var warhead = Rules.WarheadInfo[info.Warhead]; + + Game.world.AddFrameEndTask(_ => + { + Game.world.Remove(self); + Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false)); + crusher.InflictDamage(crusher, info.Damage, warhead); + }); + } + + public bool IsPathableCrush(UnitMovementType umt, Player player) + { + return !self.Info.Traits.Get().AvoidFriendly || (player != Game.LocalPlayer); + } + + public bool IsCrushableBy(UnitMovementType umt, Player player) + { + return self.Info.Traits.Get().TriggeredBy.Contains(umt); + } + + public IEnumerable OccupiedCells() { yield return self.Location; } + } + + class MineImmuneInfo : StatelessTraitInfo { } + class MineImmune { } +} diff --git a/OpenRa.Mods.RA/OpenRa.Mods.RA.csproj b/OpenRa.Mods.RA/OpenRa.Mods.RA.csproj index 42717417c7..0054171f18 100644 --- a/OpenRa.Mods.RA/OpenRa.Mods.RA.csproj +++ b/OpenRa.Mods.RA/OpenRa.Mods.RA.csproj @@ -45,6 +45,7 @@ +