From 982fde6d0aee952149b953e9d8d8e599d81a3d22 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 23 Dec 2009 21:48:15 +1300 Subject: [PATCH 1/2] force-move; cleaning some dead bits; etc --- OpenRa.Game/Game.cs | 5 +++-- OpenRa.Game/Graphics/SequenceProvider.cs | 2 -- OpenRa.Game/MainWindow.cs | 28 +++++++++++------------- OpenRa.Game/Traits/Infantry.cs | 9 +++++--- OpenRa.Game/Traits/Mobile.cs | 9 +++++++- OpenRa.Game/Traits/TraitsInterfaces.cs | 2 +- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index a11ccfbc25..4c73ee6b68 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -245,8 +245,9 @@ namespace OpenRa.Game { foreach (var crush in a.traits.WithInterface()) { - if (((crush.IsCrushableByEnemy() && a.Owner != Game.LocalPlayer) || (crush.IsCrushableByFriend() && a.Owner == Game.LocalPlayer)) - && crush.CrushableBy().Contains(umt)) + if (((crush.IsCrushableByEnemy() && a.Owner != Game.LocalPlayer) + || (crush.IsCrushableByFriend() && a.Owner == Game.LocalPlayer)) + && crush.CrushableBy(umt)) { Log.Write("{0} is crushable by MovementType {1}", a.Info.Name, umt); return true; diff --git a/OpenRa.Game/Graphics/SequenceProvider.cs b/OpenRa.Game/Graphics/SequenceProvider.cs index 16b18bfc88..4915033531 100644 --- a/OpenRa.Game/Graphics/SequenceProvider.cs +++ b/OpenRa.Game/Graphics/SequenceProvider.cs @@ -43,8 +43,6 @@ namespace OpenRa.Game.Graphics Log.Write("* LoadSequencesForCursor() done"); } - public static void ForcePrecache() { } // force static ctor to run - static void LoadSequencesForUnit(XmlElement eUnit) { string unitName = eUnit.GetAttribute("name"); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index f658f50865..c110d5cf9a 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -37,32 +37,30 @@ namespace OpenRa.Game WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false); Game.timestep = settings.GetValue("rate", 40); Game.Replay = settings.GetValue("replay", ""); - Game.NetworkHost = settings.GetValue( "host", "" ); - Game.NetworkPort = int.Parse( settings.GetValue( "port", "0" ) ); + Game.NetworkHost = settings.GetValue("host", ""); + Game.NetworkPort = int.Parse(settings.GetValue("port", "0")); - var useAftermath = bool.Parse( settings.GetValue( "aftermath", "false" ) ); + var useAftermath = bool.Parse(settings.GetValue("aftermath", "false")); - Renderer.SheetSize = int.Parse( settings.GetValue( "sheetsize", "512" ) ); + Renderer.SheetSize = int.Parse(settings.GetValue("sheetsize", "512")); - while( !File.Exists( "redalert.mix" ) ) + while (!File.Exists("redalert.mix")) { var current = Directory.GetCurrentDirectory(); - if( Directory.GetDirectoryRoot( current ) == current ) - throw new InvalidOperationException( "Unable to load MIX files." ); - Directory.SetCurrentDirectory( ".." ); + if (Directory.GetDirectoryRoot(current) == current) + throw new InvalidOperationException("Unable to load MIX files."); + Directory.SetCurrentDirectory(".."); } - FileSystem.MountDefault( useAftermath ); + FileSystem.MountDefault(useAftermath); - bool windowed = !settings.GetValue( "fullscreen", false ); - renderer = new Renderer( this, GetResolution( settings ), windowed ); + bool windowed = !settings.GetValue("fullscreen", false); + renderer = new Renderer(this, GetResolution(settings), windowed); - var controller = new Controller( () => (Modifiers)(int)ModifierKeys ); /* a bit of insane input routing */ + var controller = new Controller(() => (Modifiers)(int)ModifierKeys); /* a bit of insane input routing */ Game.Initialize(settings.GetValue("map", "scm12ea.ini"), renderer, new int2(ClientSize), - settings.GetValue("player", 1), useAftermath, controller ); - - SequenceProvider.ForcePrecache(); + settings.GetValue("player", 1), useAftermath, controller); ShowCursor(false); Game.ResetTimer(); diff --git a/OpenRa.Game/Traits/Infantry.cs b/OpenRa.Game/Traits/Infantry.cs index 0c4d5e5530..8f1a7a0155 100644 --- a/OpenRa.Game/Traits/Infantry.cs +++ b/OpenRa.Game/Traits/Infantry.cs @@ -29,10 +29,13 @@ namespace OpenRa.Game.Traits self.InflictDamage(crusher, self.Health, Rules.WarheadInfo["Crush"]); } - public IEnumerable CrushableBy() + public bool CrushableBy(UnitMovementType umt) { - yield return UnitMovementType.Track; - //yield return UnitMovementType.Wheel; // Can infantry be crushed by wheel? + switch (umt) + { + case UnitMovementType.Track: return true; + default: return false; + } } } } diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index c009ab0a1c..e1fd485391 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -37,7 +37,14 @@ namespace OpenRa.Game.Traits public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { if (mi.Button == MouseButton.Left) return null; - if (underCursor != null) return null; + + if (underCursor != null) + { + // force-move + if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null; + if (!Game.IsActorCrushableByActor(underCursor, self)) return null; + } + if (Util.GetEffectiveSpeed(self) == 0) return null; /* allow disabling move orders from modifiers */ if (xy == toCell) return null; return Order.Move(self, xy); diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index aaa9bb8ebd..b7a2b6f7b2 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -64,6 +64,6 @@ namespace OpenRa.Game.Traits bool IsCrushableByFriend(); bool IsCrushableByEnemy(); void OnCrush(Actor crusher); - IEnumerableCrushableBy(); + bool CrushableBy(UnitMovementType umt); } } From a6c8b234a55b490840fd3048b50f4e8f2b8630d8 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 23 Dec 2009 22:01:03 +1300 Subject: [PATCH 2/2] linqhax --- OpenRa.Game/Game.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 4c73ee6b68..9290bd156c 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -241,21 +241,11 @@ namespace OpenRa.Game } public static bool IsActorCrushableByMovementType(Actor a, UnitMovementType umt) { - if (a != null) - { - foreach (var crush in a.traits.WithInterface()) - { - if (((crush.IsCrushableByEnemy() && a.Owner != Game.LocalPlayer) - || (crush.IsCrushableByFriend() && a.Owner == Game.LocalPlayer)) - && crush.CrushableBy(umt)) - { - Log.Write("{0} is crushable by MovementType {1}", a.Info.Name, umt); - return true; - } - } - Log.Write("{0} is NOT crushable by MovementType {1}", a.Info.Name, umt); - } - return false; + return a != null && + a.traits.WithInterface() + .Any(c => c.CrushableBy(umt) && + ((c.IsCrushableByEnemy() && a.Owner != Game.LocalPlayer) || + (c.IsCrushableByFriend() && a.Owner == Game.LocalPlayer))); } public static bool IsWater(int2 a)