From c4fc0e57b3abc731120e0b5736a53debf43b665e Mon Sep 17 00:00:00 2001 From: psydev Date: Mon, 4 Feb 2013 18:39:26 -0800 Subject: [PATCH 01/67] [cnc] Obelisk now AutoTargeted by units, etc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obelisk of light was missing "-AutoTargetIgnore". All the guard towers have it, but for some reason the Obelisk didn't.  --- mods/cnc/rules/structures.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index e6e0f254f5..5dd726a3b4 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -594,6 +594,7 @@ OBLI: Turreted: ROT:255 AutoTarget: + -AutoTargetIgnore: -RenderBuilding: RenderRangeCircle: -EmitInfantryOnSell: From 96d1f8d83b8e4ef749a8c432581db8294e214cad Mon Sep 17 00:00:00 2001 From: Cody Brittain Date: Wed, 6 Feb 2013 08:35:27 -0500 Subject: [PATCH 02/67] Update mods/cnc/mod.yaml Add support for Nyergud's Music Upgrade Pack --- mods/cnc/mod.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 074c33a2ec..d45403031f 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -26,6 +26,7 @@ Packages: ~movies-nod.mix ~movies.mix ~scores.mix + ~scores2.mix ~transit.mix Rules: From f1019ab332e4b75696cef928a92716e88f486e2a Mon Sep 17 00:00:00 2001 From: psydev Date: Wed, 6 Feb 2013 12:21:04 -0800 Subject: [PATCH 03/67] [cnc] added names for explosions Easier-to-understand names for explosions, which can be used in the future. Can phase out old names/numbers slowly. Also included some explosions from the C&C Content which were not in use and did not have names. --- mods/cnc/sequences/misc.yaml | 41 ++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/mods/cnc/sequences/misc.yaml b/mods/cnc/sequences/misc.yaml index 272df55451..df1fd9c5bb 100644 --- a/mods/cnc/sequences/misc.yaml +++ b/mods/cnc/sequences/misc.yaml @@ -85,16 +85,49 @@ explosion: 8: art-exp1 Start: 0 Length: * - building: fball1 - Start: 0 - Length: * 6: atomsfx Start: 0 Length: * 6w: atomsfx Start: 0 Length: * - chemball: chemball + piff: piff + Start: 0 + Length: * + piffs: piffpiff + Start: 0 + Length: * + chemball: chemball #same size as small_napalm, but bright green. + Start: 0 + Length: * + small_napalm: napalm1 #not used by much. currently used for flamethrower. + Start: 0 + Length: * + med_napalm: napalm2 #explosion for bomblets + Start: 0 + Length: * + big_napalm: napalm3 #huge; not used. (SSM used this explosion in C&C Gold?) + Start: 0 + Length: * + small_frag: veh-hit3 #the most common weapon-hit explosion. For rockets, tank shells, etc. + Start: 0 + Length: * + med_frag: frag1 #fragmentation-style; quite large. (MLRS used this explosion in C&C Gold?) + Start: 0 + Length: * + big_frag: frag3 #Same as med_frag, except fire hangs around longer. + Start: 0 + Length: * + small_poof: veh-hit2 #for Grenades; tower missiles; boat missiles; APC AA gun. + Start: 0 + Length: * + big_poof: art-exp1 #For UnitExplode (artillery); artillery shell hit; GrenadierExplode, + Start: 0 + Length: * + small_building: veh-hit1 #like "building' explosion, but much smaller. (Used for heli-explosion in C&C Gold?) + Start: 0 + Length: * + building: fball1 #Large explosion, for when a building explodes. Start: 0 Length: * From d12853ddf7f8e5c763c8e2bc29cff0fc8ab9115d Mon Sep 17 00:00:00 2001 From: psydev Date: Wed, 6 Feb 2013 14:20:09 -0800 Subject: [PATCH 04/67] [cnc] inftry detect cloaked in next tile(C&C orig) Infantry can detect cloaked units in the next tile. This behaviour was in the original C&C Gold. (Even though it says range=2, it is actually just in the next tile) Fixed GrenadierExplode. --- mods/cnc/rules/infantry.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mods/cnc/rules/infantry.yaml b/mods/cnc/rules/infantry.yaml index 45366b0abb..779e4ab6ab 100644 --- a/mods/cnc/rules/infantry.yaml +++ b/mods/cnc/rules/infantry.yaml @@ -19,6 +19,8 @@ E1: PrimaryWeapon: M16 RenderInfantryProne: IdleAnimations: idle1,idle2,idle3,idle4 + DetectCloaked: + Range: 2 E2: Inherits: ^Infantry @@ -46,7 +48,10 @@ E2: IdleAnimations: idle1,idle2 Explodes: Weapon: GrenadierExplode + EmptyWeapon: GrenadierExplode Chance: 50 + DetectCloaked: + Range: 2 E3: Inherits: ^Infantry @@ -71,6 +76,8 @@ E3: FireDelay: 5 RenderInfantryProne: IdleAnimations: idle1,idle2 + DetectCloaked: + Range: 2 E4: Inherits: ^Infantry @@ -97,6 +104,8 @@ E4: WithMuzzleFlash: RenderInfantryProne: IdleAnimations: idle1,idle2 + DetectCloaked: + Range: 2 E5: Inherits: ^Infantry @@ -129,6 +138,8 @@ E5: -PoisonedByTiberium: RenderInfantryProne: IdleAnimations: idle1,idle2 + DetectCloaked: + Range: 2 E6: Inherits: ^Infantry @@ -192,6 +203,8 @@ RMBO: IdleAnimations: idle1,idle2,idle3 AnnounceOnBuild: AnnounceOnKill: + DetectCloaked: + Range: 2 PVICE: Inherits:VICE @@ -210,4 +223,4 @@ PVICE: Selectable: Voice: DinoVoice ActorLostNotification: - Notification: unitlost.aud \ No newline at end of file + Notification: unitlost.aud From dfc880807eab8697d3eae12f4bf5e7972a597dae Mon Sep 17 00:00:00 2001 From: psydev Date: Wed, 6 Feb 2013 16:06:47 -0800 Subject: [PATCH 05/67] [cnc] Airstrike cooldown 3 mins. (from 4). tweaks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Air Strike cooldown time reduced from 4 minutes to 3. (Ion Cannon is 3). [games are short in CNC, and waiting 4 minutes for your first airstrike is a long time.] HQ's hitpoints reduced to 750, so it can be nuked in one shot. (but not Ion Cannon'd)  Airfield HP reduced to 1500, so Ion + Airstrike can destroy it. (For some reason, it doesn't die as easily as Weapons Factory, despite having the same HP) --- mods/cnc/rules/structures.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 5dd726a3b4..406943174d 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -259,7 +259,7 @@ AFLD: Footprint: xxxx xxxx Dimensions: 4,2 Health: - HP: 1750 + HP: 1500 RevealsShroud: Range: 7 Bib: @@ -372,7 +372,7 @@ HQ: Footprint: x_ xx Dimensions: 2,2 Health: - HP: 1000 + HP: 750 RevealsShroud: Range: 10 Bib: @@ -382,7 +382,7 @@ HQ: Range: 8 AirstrikePower: Image: bombicnh - ChargeTime: 240 + ChargeTime: 180 Description: Air Strike LongDesc: Deploy an aerial napalm strike.\nBurns buildings and infantry along a line. EndChargeSound: airredy1.aud From 1f99b1ec8e5f06d06de2a787045115b682214fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 9 Feb 2013 14:08:36 +0100 Subject: [PATCH 06/67] make hotkey user-configurable via in-game settings --- AUTHORS | 1 + OpenRA.Game/GameRules/Settings.cs | 22 +++++ .../Widgets/ProductionTabsWidget.cs | 2 +- OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs | 2 +- .../Widgets/Logic/SettingsMenuLogic.cs | 93 +++++++++++++++++++ OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 55 +++++++---- mods/ra/chrome/settings.yaml | 76 ++++++++++++++- 7 files changed, 228 insertions(+), 23 deletions(-) diff --git a/AUTHORS b/AUTHORS index 04b4c0bccf..4a88044ee7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -37,6 +37,7 @@ Also thanks to: * Raymond Martineau (mart0258) * Riderr3 * Tim Mylemans (gecko) + * Tirili Past developers included: * Paul Chote (pchote) diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index e270d78d49..bb8d3fc0ed 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -120,6 +120,26 @@ namespace OpenRA.GameRules public string ConnectTo = ""; } + public class KeySettings + { + public string PauseKey = "f3"; + + public string CycleBaseKey = "backspace"; + public string GotoLastEventKey = "space"; + public string SellKey = "v"; + public string PowerDownKey = "b"; + public string RepairKey = "n"; + + public string AttackMoveKey = "a"; + public string StopKey = "s"; + public string ScatterKey = "x"; + public string StanceCycleKey = "z"; + public string DeployKey = "f"; + + public string CycleTabsKey = "tab"; + } + + public class Settings { string SettingsFile; @@ -130,6 +150,7 @@ namespace OpenRA.GameRules public GraphicSettings Graphics = new GraphicSettings(); public ServerSettings Server = new ServerSettings(); public DebugSettings Debug = new DebugSettings(); + public KeySettings Keys = new KeySettings(); public Dictionary Sections; @@ -144,6 +165,7 @@ namespace OpenRA.GameRules {"Graphics", Graphics}, {"Server", Server}, {"Debug", Debug}, + {"Keys", Keys}, }; // Override fieldloader to ignore invalid entries diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs index 95f31484ba..c9459eba05 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -266,7 +266,7 @@ namespace OpenRA.Mods.Cnc.Widgets public override bool HandleKeyPress(KeyInput e) { if (e.Event != KeyInputEvent.Down) return false; - if (e.KeyName == "tab") + if (e.KeyName == Game.Settings.Keys.CycleTabsKey) { Sound.PlayNotification(null, "Sounds", "ClickSound", null); SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift)); diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index f0cdaa6517..0ec408ecf6 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -145,7 +145,7 @@ namespace OpenRA.Mods.RA.Widgets public override bool HandleKeyPress(KeyInput e) { if (e.Event == KeyInputEvent.Up) return false; - if (e.KeyName == "tab") + if (e.KeyName == Game.Settings.Keys.CycleTabsKey) { TabChange(e.Modifiers.HasModifier(Modifiers.Shift)); return true; diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index d6b4b847f4..f3552f2987 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic tabs.Get("GENERAL").OnClick = () => FlipToTab("GENERAL_PANE"); tabs.Get("AUDIO").OnClick = () => FlipToTab("AUDIO_PANE"); tabs.Get("DISPLAY").OnClick = () => FlipToTab("DISPLAY_PANE"); + tabs.Get("KEYS").OnClick = () => FlipToTab("KEYS_PANE"); tabs.Get("DEBUG").OnClick = () => FlipToTab("DEBUG_PANE"); FlipToTab("GENERAL_PANE"); @@ -120,6 +121,82 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.viewport.Zoom = gs.PixelDouble ? 2 : 1; }; + // Keys + var keys = bg.Get("KEYS_PANE"); + var keyConfig = Game.Settings.Keys; + + var specialHotkeyList = keys.Get("SPECIALHOTKEY_LIST"); + var specialHotkeyTemplate = specialHotkeyList.Get("SPECIALHOTKEY_TEMPLATE"); + + var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + pauseKey.Get("FUNCTION").GetText = () => "Pause the game:"; + SetupKeyBinding(pauseKey.Get("HOTKEY"), + () => keyConfig.PauseKey, k => keyConfig.PauseKey = k); + specialHotkeyList.AddChild(pauseKey); + + var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + viewportToBase.Get("FUNCTION").GetText = () => "Move Viewport to Base:"; + SetupKeyBinding(viewportToBase.Get("HOTKEY"), + () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k); + specialHotkeyList.AddChild(viewportToBase); + + var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + lastEventKey.Get("FUNCTION").GetText = () => "Move Viewport to Last Event:"; + SetupKeyBinding(lastEventKey.Get("HOTKEY"), + () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); + specialHotkeyList.AddChild(lastEventKey); + + var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + sellKey.Get("FUNCTION").GetText = () => "Switch to Sell-Cursor:"; + SetupKeyBinding(sellKey.Get("HOTKEY"), + () => keyConfig.SellKey, k => keyConfig.SellKey = k); + specialHotkeyList.AddChild(sellKey); + + var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + powerDownKey.Get("FUNCTION").GetText = () => "Switch to Power-Down-Cursor:"; + SetupKeyBinding(powerDownKey.Get("HOTKEY"), + () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k); + specialHotkeyList.AddChild(powerDownKey); + + var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + repairKey.Get("FUNCTION").GetText = () => "Switch to Repair-Cursor:"; + SetupKeyBinding(repairKey.Get("HOTKEY"), + () => keyConfig.RepairKey, k => keyConfig.RepairKey = k); + specialHotkeyList.AddChild(repairKey); + + var unitCommandHotkeyList = keys.Get("UNITCOMMANDHOTKEY_LIST"); + var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get("UNITCOMMANDHOTKEY_TEMPLATE"); + + var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); + attackKey.Get("FUNCTION").GetText = () => "Attack Move:"; + SetupKeyBinding(attackKey.Get("HOTKEY"), + () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k); + unitCommandHotkeyList.AddChild(attackKey); + + var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); + stopKey.Get("FUNCTION").GetText = () => "Stop:"; + SetupKeyBinding(stopKey.Get("HOTKEY"), + () => keyConfig.StopKey, k => keyConfig.StopKey = k); + unitCommandHotkeyList.AddChild(stopKey); + + var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); + scatterKey.Get("FUNCTION").GetText = () => "Scatter:"; + SetupKeyBinding(scatterKey.Get("HOTKEY"), + () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k); + unitCommandHotkeyList.AddChild(scatterKey); + + var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); + stanceCycleKey.Get("FUNCTION").GetText = () => "Cycle Stance:"; + SetupKeyBinding(stanceCycleKey.Get("HOTKEY"), + () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k); + unitCommandHotkeyList.AddChild(stanceCycleKey); + + var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); + deployKey.Get("FUNCTION").GetText = () => "Deploy:"; + SetupKeyBinding(deployKey.Get("HOTKEY"), + () => keyConfig.DeployKey, k => keyConfig.DeployKey = k); + unitCommandHotkeyList.AddChild(deployKey); + // Debug var debug = bg.Get("DEBUG_PANE"); @@ -199,6 +276,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic return true; } + void SetupKeyBinding(TextFieldWidget textBox, Func getValue, Action setValue) + { + textBox.Text = getValue(); + + textBox.OnLoseFocus = () => + { + textBox.Text.Trim(); + if (textBox.Text.Length == 0) + textBox.Text = getValue(); + else + setValue(textBox.Text); + }; + + textBox.OnEnterKey = () => { textBox.LoseFocus(); return true; }; + } + public static bool ShowRendererDropdown(DropDownButtonWidget dropdown, GraphicSettings s) { var options = new Dictionary() diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 3c1262e4a6..753529834d 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -16,6 +16,7 @@ using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Orders; using OpenRA.Widgets; +using OpenRA.Mods.RA.Orders; namespace OpenRA.Mods.RA.Widgets { @@ -23,14 +24,6 @@ namespace OpenRA.Mods.RA.Widgets { public World World { get { return OrderManager.world; } } - public string AttackMoveKey = "a"; - public string StopKey = "s"; - public string ScatterKey = "x"; - public string DeployKey = "f"; - public string StanceCycleKey = "z"; - public string BaseCycleKey = "backspace"; - public string GotoLastEventKey = "space"; - public readonly OrderManager OrderManager; [ObjectCreator.UseCtor] @@ -51,28 +44,37 @@ namespace OpenRA.Mods.RA.Widgets { if (e.Modifiers == Modifiers.None && e.Event == KeyInputEvent.Down) { - if (e.KeyName == BaseCycleKey) + if (e.KeyName == Game.Settings.Keys.CycleBaseKey) return CycleBases(); - if (e.KeyName == GotoLastEventKey) + if (e.KeyName == Game.Settings.Keys.GotoLastEventKey) return GotoLastEvent(); - if (!World.Selection.Actors.Any()) + if (e.KeyName == Game.Settings.Keys.SellKey) + return PerformSwitchToSellMode(); + + if (e.KeyName == Game.Settings.Keys.PowerDownKey) + return PerformSwitchToPowerDownMode(); + + if (e.KeyName == Game.Settings.Keys.RepairKey) + return PerformSwitchToRepairMode(); + + if (!World.Selection.Actors.Any()) // Put all functions, that are no unit-functions, before this line! return false; - if (e.KeyName == AttackMoveKey) + if (e.KeyName == Game.Settings.Keys.AttackMoveKey) return PerformAttackMove(); - if (e.KeyName == StopKey) + if (e.KeyName == Game.Settings.Keys.StopKey) return PerformStop(); - if (e.KeyName == ScatterKey) + if (e.KeyName == Game.Settings.Keys.ScatterKey) return PerformScatter(); - if (e.KeyName == DeployKey) + if (e.KeyName == Game.Settings.Keys.DeployKey) return PerformDeploy(); - if (e.KeyName == StanceCycleKey) + if (e.KeyName == Game.Settings.Keys.StanceCycleKey) return PerformStanceCycle(); } @@ -115,10 +117,11 @@ namespace OpenRA.Mods.RA.Widgets bool PerformDeploy() { - /* hack: three orders here -- ReturnToBase, DeployTransform, Unload. */ + /* hack: multiple orders here */ PerformKeyboardOrderOnSelection(a => new Order("ReturnToBase", a, false)); PerformKeyboardOrderOnSelection(a => new Order("DeployTransform", a, false)); PerformKeyboardOrderOnSelection(a => new Order("Unload", a, false)); + PerformKeyboardOrderOnSelection(a => new Order("DemoDeploy", a, false)); return true; } @@ -184,5 +187,23 @@ namespace OpenRA.Mods.RA.Widgets Game.viewport.Center(eventNotifier.lastAttackLocation.ToFloat2()); return true; } + + private bool PerformSwitchToSellMode () + { + World.ToggleInputMode (); + return true; + } + + private bool PerformSwitchToPowerDownMode () + { + World.ToggleInputMode (); + return true; + } + + private bool PerformSwitchToRepairMode () + { + World.ToggleInputMode(); + return true; + } } } diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 22e831761f..b9113b01c9 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -2,13 +2,13 @@ Background@SETTINGS_MENU: Logic:SettingsMenuLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM- HEIGHT)/2 - Width: 450 - Height: 350 + Width: 540 + Height: 400 Children: Label@SETTINGS_LABEL_TITLE: X:0 Y:20 - Width:450 + Width:540 Height:25 Text:Settings Align:Center @@ -48,11 +48,18 @@ Background@SETTINGS_MENU: Height:25 Text:Display Font:Bold - Button@DEBUG: + Button@KEYS: X:315 Y:0 Width:90 Height:25 + Text:Keys + Font:Bold + Button@DEBUG: + X:405 + Y:0 + Width:90 + Height:25 Text:Debug Font:Bold Container@GENERAL_PANE: @@ -228,6 +235,67 @@ Background@SETTINGS_MENU: Height:20 Font:Regular Text:Enable Pixel Doubling + Container@KEYS_PANE: + X:37 + Y:100 + Width:PARENT_RIGHT - 37 + Height:PARENT_BOTTOM - 100 + Visible: false + Children: + Label@KEYS_SPECIALHOTKEYSHEADLINE: + X:0 + Y:0 + Text: Special Hotkeys: + Font:Bold + ScrollPanel@SPECIALHOTKEY_LIST: + X:0 + Y:20 + Width:449 + Height:85 + Children: + ScrollItem@SPECIALHOTKEY_TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@FUNCTION: + X:10 + Width:200 + Height:25 + TextField@HOTKEY: + X:250 + Width:139 + Height:25 + MaxLength:16 + Label@KEYS_UNITCOMMANDSHEADLINE: + X:0 + Y:130 + Text: Hotkeys for Unit Commands: + Font:Bold + ScrollPanel@UNITCOMMANDHOTKEY_LIST: + X:0 + Y:150 + Width:449 + Height:85 + Children: + ScrollItem@UNITCOMMANDHOTKEY_TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@FUNCTION: + X:10 + Width:200 + Height:25 + TextField@HOTKEY: + X:250 + Width:139 + Height:25 + MaxLength:16 Container@DEBUG_PANE: X:37 Y:100 From d0669823a2adecd6312054f52a2f172bc73e9f6d Mon Sep 17 00:00:00 2001 From: psydev Date: Sat, 9 Feb 2013 15:26:41 -0800 Subject: [PATCH 07/67] changing name of big_poof, for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed "big_poof" to simply "poof".  The word "big" will only appear if there are small, medium and large versions of the explosion. Otherwise, it will just be "explosion" and "small_explosion". --- mods/cnc/sequences/misc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/cnc/sequences/misc.yaml b/mods/cnc/sequences/misc.yaml index df1fd9c5bb..fbb4ebf640 100644 --- a/mods/cnc/sequences/misc.yaml +++ b/mods/cnc/sequences/misc.yaml @@ -121,7 +121,7 @@ explosion: small_poof: veh-hit2 #for Grenades; tower missiles; boat missiles; APC AA gun. Start: 0 Length: * - big_poof: art-exp1 #For UnitExplode (artillery); artillery shell hit; GrenadierExplode, + poof: art-exp1 #For UnitExplode (artillery); artillery shell hit; GrenadierExplode, Start: 0 Length: * small_building: veh-hit1 #like "building' explosion, but much smaller. (Used for heli-explosion in C&C Gold?) From f59380761755a9342a6af7609d9e7d902b6f029b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 21 Feb 2013 18:48:31 +1300 Subject: [PATCH 08/67] Rework color picker palette modification. The old method had the lobby code dig around inside the palette modification machinery, which was a giant hack preventing necessary streamlining. --- OpenRA.FileFormats/Palette.cs | 11 ++-- .../Widgets/Logic/CncIngameMenuLogic.cs | 4 +- OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs | 3 +- .../Widgets/Logic/CncSettingsLogic.cs | 12 +++-- OpenRA.Mods.RA/ColorPickerPaletteModifier.cs | 47 ---------------- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 2 +- .../Widgets/ColorPreviewManagerWidget.cs | 54 +++++++++++++++++++ OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 10 ++-- OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 2 +- mods/cnc/chrome/lobby.yaml | 2 + mods/cnc/chrome/settings.yaml | 2 + mods/cnc/rules/system.yaml | 5 +- mods/d2k/chrome/lobby.yaml | 2 + mods/d2k/rules/system.yaml | 5 +- mods/ra/chrome/lobby.yaml | 2 + mods/ra/rules/system.yaml | 5 +- 16 files changed, 100 insertions(+), 68 deletions(-) delete mode 100644 OpenRA.Mods.RA/ColorPickerPaletteModifier.cs create mode 100755 OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs diff --git a/OpenRA.FileFormats/Palette.cs b/OpenRA.FileFormats/Palette.cs index 9b96021f6f..08effa4285 100644 --- a/OpenRA.FileFormats/Palette.cs +++ b/OpenRA.FileFormats/Palette.cs @@ -39,6 +39,12 @@ namespace OpenRA.FileFormats get { return colors; } } + public void ApplyRemap(IPaletteRemap r) + { + for(int i = 0; i < 256; i++) + colors[i] = (uint)r.GetRemappedColor(Color.FromArgb((int)colors[i]),i).ToArgb(); + } + public Palette(Stream s, int[] remapShadow) { colors = new uint[256]; @@ -61,9 +67,8 @@ namespace OpenRA.FileFormats public Palette(Palette p, IPaletteRemap r) { - colors = new uint[256]; - for(int i = 0; i < 256; i++) - colors[i] = (uint)r.GetRemappedColor(Color.FromArgb((int)p.colors[i]),i).ToArgb(); + colors = (uint[])p.colors.Clone(); + ApplyRemap(r); } public Palette(Palette p) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index b83e0216d4..7d2776a00d 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs @@ -10,6 +10,7 @@ using System; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Widgets; @@ -20,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Widget menu; [ObjectCreator.UseCtor] - public CncIngameMenuLogic(Widget widget, World world, Action onExit) + public CncIngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer) { var resumeDisabled = false; menu = widget.Get("INGAME_MENU"); @@ -72,6 +73,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs() { { "world", world }, + { "worldRenderer", worldRenderer }, { "onExit", () => hideButtons = false }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs index dabf7b3cdc..64d2152b7c 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs @@ -85,9 +85,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic settingsMenu.Get("SETTINGS_BUTTON").OnClick = () => { Menu = MenuType.None; - Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs() + Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs() { - { "world", world }, { "onExit", () => Menu = MenuType.Settings }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs index c8641f2b58..8d8fb13bc7 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs @@ -6,6 +6,7 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ + #endregion using System; @@ -17,6 +18,7 @@ using OpenRA.GameRules; using OpenRA.Mods.RA; using OpenRA.Mods.RA.Widgets.Logic; using OpenRA.Widgets; +using OpenRA.Mods.RA.Widgets; namespace OpenRA.Mods.Cnc.Widgets.Logic { @@ -25,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic enum PanelType { General, Input } PanelType Settings = PanelType.General; - ColorPickerPaletteModifier playerPalettePreview; + ColorPreviewManagerWidget colorPreview; World world; [ObjectCreator.UseCtor] @@ -52,8 +54,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var nameTextfield = generalPane.Get("NAME_TEXTFIELD"); nameTextfield.Text = playerSettings.Name; - playerPalettePreview = world.WorldActor.Trait(); - playerPalettePreview.Ramp = playerSettings.ColorRamp; + colorPreview = panel.Get("COLOR_MANAGER"); + colorPreview.Ramp = playerSettings.ColorRamp; var colorDropdown = generalPane.Get("COLOR"); colorDropdown.OnMouseDown = _ => ShowColorPicker(colorDropdown, playerSettings); @@ -153,8 +155,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s) { - Action onSelect = c => { s.ColorRamp = c; color.RemovePanel(); }; - Action onChange = c => { playerPalettePreview.Ramp = c; }; + Action onSelect = c => {s.ColorRamp = c; color.RemovePanel();}; + Action onChange = c => {colorPreview.Ramp = c;}; var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs() { diff --git a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs deleted file mode 100644 index ba343c9d53..0000000000 --- a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs +++ /dev/null @@ -1,47 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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.Collections.Generic; -using System.Linq; -using OpenRA.FileFormats; -using OpenRA.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class ColorPickerPaletteModifierInfo : ITraitInfo - { - public string PlayerPalette = "player"; - public object Create( ActorInitializer init ) { return new ColorPickerPaletteModifier( this ); } - } - - public class ColorPickerPaletteModifier : IPalette, IPaletteModifier - { - ColorPickerPaletteModifierInfo Info; - int[] index; - public ColorRamp Ramp; - - public ColorPickerPaletteModifier(ColorPickerPaletteModifierInfo info) { Info = info; } - - public void InitPalette( WorldRenderer wr ) - { - var info = Rules.Info["player"].Traits.WithInterface() - .First(p => p.BaseName == Info.PlayerPalette); - index = info.RemapIndex; - wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette)); - } - - public void AdjustPalette(Dictionary palettes) - { - palettes["colorpicker"] = new Palette(palettes["colorpicker"], - new PlayerColorRemap(index, Ramp)); - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index c88eb29ed0..3553a0b857 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -169,7 +169,6 @@ - @@ -407,6 +406,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs new file mode 100755 index 0000000000..9b2a144b6d --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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 System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets +{ + public class ColorPreviewManagerWidget : Widget + { + public readonly string Palette = "colorpicker"; + public readonly int[] RemapIndices = {}; + public ColorRamp Ramp; + + ColorRamp cachedRamp; + WorldRenderer worldRenderer; + Palette preview; + + [ObjectCreator.UseCtor] + public ColorPreviewManagerWidget(WorldRenderer worldRenderer) + : base() + { + this.worldRenderer = worldRenderer; + } + + public override void Initialize(WidgetArgs args) + { + base.Initialize(args); + preview = worldRenderer.GetPalette(Palette); + } + + public override void Tick() + { + if (cachedRamp == Ramp) + return; + + preview.ApplyRemap(new PlayerColorRemap(RemapIndices, Ramp)); + cachedRamp = Ramp; + } + } +} + diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 8319f2d033..2cfeb4ec4a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic string MapUid; Map Map; - ColorPickerPaletteModifier PlayerPalettePreview; + ColorPreviewManagerWidget colorPreview; readonly Action OnGameStart; readonly Action onExit; @@ -96,8 +96,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.ConnectionStateChanged += ConnectionStateChanged; UpdateCurrentMap(); - PlayerPalettePreview = world.WorldActor.Trait(); - PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp; Players = lobby.Get("PLAYERS"); EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER"); NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER"); @@ -105,6 +103,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic EditableSpectatorTemplate = Players.Get("TEMPLATE_EDITABLE_SPECTATOR"); NonEditableSpectatorTemplate = Players.Get("TEMPLATE_NONEDITABLE_SPECTATOR"); NewSpectatorTemplate = Players.Get("TEMPLATE_NEW_SPECTATOR"); + colorPreview = lobby.Get("COLOR_MANAGER"); + colorPreview.Ramp = Game.Settings.Player.ColorRamp; var mapPreview = lobby.Get("MAP_PREVIEW"); mapPreview.IsVisible = () => Map != null; @@ -341,7 +341,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var color = template.Get("COLOR"); color.IsDisabled = () => slot.LockColor || ready; - color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, PlayerPalettePreview); + color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, colorPreview); var colorBlock = color.Get("COLORBLOCK"); colorBlock.GetColor = () => client.ColorRamp.GetColor(0); @@ -421,7 +421,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var color = template.Get("COLOR"); color.IsDisabled = () => ready; - color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview); + color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview); var colorBlock = color.Get("COLORBLOCK"); colorBlock.GetColor = () => c.ColorRamp.GetColor(0); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index fd0ab270f2..d752b16959 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client, - OrderManager orderManager, ColorPickerPaletteModifier preview) + OrderManager orderManager, ColorPreviewManagerWidget preview) { Action onSelect = c => { diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index ae731e3584..ff2cb1bb77 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -5,6 +5,8 @@ Container@SERVER_LOBBY: Width:740 Height:535 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 Label@TITLE: Width:740 Y:0-25 diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index 7b97795882..64c6adda52 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -5,6 +5,8 @@ Container@SETTINGS_PANEL: Width:740 Height:535 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 Label@TITLE: Width:740 Y:0-25 diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index dea084e9f2..f968a228b6 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -80,6 +80,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: temperat.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -104,7 +108,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index 65d6c6fcee..3e96577e50 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -5,6 +5,8 @@ Background@SERVER_LOBBY: Width:800 Height:600 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 Label@TITLE: X:0 Y:17 diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index e22bd4e6c4..31c6ffc05e 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -269,6 +269,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: d2k.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -299,7 +303,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index a57f11c6d8..15b7d3d92b 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -5,6 +5,8 @@ Background@SERVER_LOBBY: Width:800 Height:600 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 Label@TITLE: X:0 Y:17 diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index d3245ddd48..eb0fd1a1ea 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -224,6 +224,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: temperat.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -254,7 +258,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes From db7887687b17f594a80ab537cc5e1ecdfee82ae6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 21 Feb 2013 18:48:31 +1300 Subject: [PATCH 09/67] Remove hardcoded list of palette mod exclusions. --- OpenRA.Game/Graphics/CursorProvider.cs | 2 +- OpenRA.Game/Graphics/HardwarePalette.cs | 8 ++++++-- OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Game/Traits/World/PlayerColorPalette.cs | 3 ++- OpenRA.Mods.Cnc/CncMenuPaletteEffect.cs | 5 ----- OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs | 5 ----- OpenRA.Mods.RA/LightPaletteRotator.cs | 5 ----- OpenRA.Mods.RA/NukePaletteEffect.cs | 5 ----- OpenRA.Mods.RA/PaletteFromCurrentTileset.cs | 5 +++-- OpenRA.Mods.RA/PaletteFromFile.cs | 7 ++++--- OpenRA.Mods.RA/PaletteFromRGBA.cs | 3 ++- OpenRA.Mods.RA/PlayerPaletteFromCurrentTileset.cs | 3 ++- OpenRA.Mods.RA/ShroudPalette.cs | 8 ++++---- OpenRA.Mods.RA/WaterPaletteRotation.cs | 2 +- mods/cnc/rules/system.yaml | 1 + mods/d2k/rules/system.yaml | 1 + mods/ra/rules/system.yaml | 1 + 17 files changed, 29 insertions(+), 37 deletions(-) diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index a0dc94b86d..4184facd60 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -34,7 +34,7 @@ namespace OpenRA.Graphics } foreach (var s in sequences.NodesDict["Palettes"].Nodes) - Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex)); + Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex), false); foreach (var s in sequences.NodesDict["Cursors"].Nodes) LoadSequencesForCursor(s.Key, s.Value); diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index fcda7438e3..98f486e2cf 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -25,11 +25,13 @@ namespace OpenRA.Graphics ITexture texture; Dictionary palettes; Dictionary indices; + Dictionary allowsMods; public HardwarePalette() { palettes = new Dictionary(); indices = new Dictionary(); + allowsMods = new Dictionary(); texture = Game.Renderer.Device.CreateTexture(); } @@ -49,22 +51,24 @@ namespace OpenRA.Graphics return ret; } - public void AddPalette(string name, Palette p) + public void AddPalette(string name, Palette p, bool allowModifiers) { if (palettes.ContainsKey(name)) throw new InvalidOperationException("Palette {0} has already been defined".F(name)); palettes.Add(name, p); indices.Add(name, allocated++); + allowsMods.Add(name, allowModifiers); } uint[,] data = new uint[MaxPalettes, 256]; public void Update(IEnumerable paletteMods) { var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); + var modifiable = copy.Where(p => allowsMods[p.Key]).ToDictionary(p => p.Key, p => p.Value); foreach (var mod in paletteMods) - mod.AdjustPalette(copy); + mod.AdjustPalette(modifiable); foreach (var pal in copy) { diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index ba662975a2..8aaed1c3f2 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -37,7 +37,7 @@ namespace OpenRA.Graphics public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public Palette GetPalette(string name) { return palette.GetPalette(name); } - public void AddPalette(string name, Palette pal) { palette.AddPalette(name, pal); } + public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } class SpriteComparer : IComparer { diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index bb3547aaea..1e50140945 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -18,6 +18,7 @@ namespace OpenRA.Traits public readonly string BasePalette = null; public readonly string BaseName = "player"; public readonly int[] RemapIndex = {}; + public readonly bool AllowModifiers = true; public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); } } @@ -38,7 +39,7 @@ namespace OpenRA.Traits var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName ); var newpal = new Palette(wr.GetPalette(info.BasePalette), new PlayerColorRemap(info.RemapIndex, owner.ColorRamp)); - wr.AddPalette(paletteName, newpal); + wr.AddPalette(paletteName, newpal, info.AllowModifiers); } } } diff --git a/OpenRA.Mods.Cnc/CncMenuPaletteEffect.cs b/OpenRA.Mods.Cnc/CncMenuPaletteEffect.cs index df198b1430..a351b80128 100644 --- a/OpenRA.Mods.Cnc/CncMenuPaletteEffect.cs +++ b/OpenRA.Mods.Cnc/CncMenuPaletteEffect.cs @@ -61,8 +61,6 @@ namespace OpenRA.Mods.Cnc } } - static Set excludePalettes = new Set("cursor", "chrome", "colorpicker", "shroud", "fog"); - public void AdjustPalette(Dictionary palettes) { if (to == EffectType.None && remainingFrames == 0) @@ -70,9 +68,6 @@ namespace OpenRA.Mods.Cnc foreach (var pal in palettes) { - if (excludePalettes.Contains(pal.Key)) - continue; - for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); diff --git a/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs b/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs index 242f112c8e..419875c151 100644 --- a/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs +++ b/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs @@ -32,8 +32,6 @@ namespace OpenRA.Mods.RA if (remainingFrames > 0) remainingFrames--; } - - static List excludePalettes = new List{"cursor", "chrome", "colorpicker", "shroud", "fog"}; public void AdjustPalette(Dictionary palettes) { @@ -44,9 +42,6 @@ namespace OpenRA.Mods.RA foreach (var pal in palettes) { - if (excludePalettes.Contains(pal.Key)) - continue; - for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); diff --git a/OpenRA.Mods.RA/LightPaletteRotator.cs b/OpenRA.Mods.RA/LightPaletteRotator.cs index d3e827b540..ec2e166a3f 100644 --- a/OpenRA.Mods.RA/LightPaletteRotator.cs +++ b/OpenRA.Mods.RA/LightPaletteRotator.cs @@ -24,15 +24,10 @@ namespace OpenRA.Mods.RA t += .5f; } - static readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "terrain" }; - public void AdjustPalette(Dictionary palettes) { foreach (var pal in palettes) { - if (ExcludePalettes.Contains(pal.Key)) - continue; - var rotate = (int)t % 18; if (rotate > 9) rotate = 18 - rotate; diff --git a/OpenRA.Mods.RA/NukePaletteEffect.cs b/OpenRA.Mods.RA/NukePaletteEffect.cs index 3e463fdd11..21215ee546 100644 --- a/OpenRA.Mods.RA/NukePaletteEffect.cs +++ b/OpenRA.Mods.RA/NukePaletteEffect.cs @@ -32,8 +32,6 @@ namespace OpenRA.Mods.RA if (remainingFrames > 0) remainingFrames--; } - - static List excludePalettes = new List{ "cursor", "chrome", "colorpicker", "shroud", "fog" }; public void AdjustPalette(Dictionary palettes) { @@ -44,9 +42,6 @@ namespace OpenRA.Mods.RA foreach (var pal in palettes) { - if (excludePalettes.Contains(pal.Key)) - continue; - for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); diff --git a/OpenRA.Mods.RA/PaletteFromCurrentTileset.cs b/OpenRA.Mods.RA/PaletteFromCurrentTileset.cs index f98af6175c..8c045aef07 100644 --- a/OpenRA.Mods.RA/PaletteFromCurrentTileset.cs +++ b/OpenRA.Mods.RA/PaletteFromCurrentTileset.cs @@ -17,6 +17,7 @@ namespace OpenRA.Mods.RA { public readonly string Name = null; public readonly int[] ShadowIndex = { }; + public readonly bool AllowModifiers = true; public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.world, this); } } @@ -32,9 +33,9 @@ namespace OpenRA.Mods.RA this.info = info; } - public void InitPalette( OpenRA.Graphics.WorldRenderer wr ) + public void InitPalette(OpenRA.Graphics.WorldRenderer wr) { - wr.AddPalette( info.Name, new Palette( FileSystem.Open( world.TileSet.Palette ), info.ShadowIndex ) ); + wr.AddPalette(info.Name, new Palette(FileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.RA/PaletteFromFile.cs b/OpenRA.Mods.RA/PaletteFromFile.cs index 94706ea61e..6a60aa8d67 100644 --- a/OpenRA.Mods.RA/PaletteFromFile.cs +++ b/OpenRA.Mods.RA/PaletteFromFile.cs @@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA public readonly string Tileset = null; public readonly string Filename = null; public readonly int[] ShadowIndex = { }; + public readonly bool AllowModifiers = true; public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); } } @@ -34,10 +35,10 @@ namespace OpenRA.Mods.RA this.info = info; } - public void InitPalette( WorldRenderer wr ) + public void InitPalette(WorldRenderer wr) { - if( info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant() ) - wr.AddPalette( info.Name, new Palette( FileSystem.Open( info.Filename ), info.ShadowIndex ) ); + if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant()) + wr.AddPalette(info.Name, new Palette(FileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.RA/PaletteFromRGBA.cs b/OpenRA.Mods.RA/PaletteFromRGBA.cs index 95ebef6905..9fd84ba698 100644 --- a/OpenRA.Mods.RA/PaletteFromRGBA.cs +++ b/OpenRA.Mods.RA/PaletteFromRGBA.cs @@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA public readonly int G = 0; public readonly int B = 0; public readonly int A = 255; + public readonly bool AllowModifiers = true; public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.world, this); } } @@ -43,7 +44,7 @@ namespace OpenRA.Mods.RA { // TODO: This shouldn't rely on a base palette var pal = wr.GetPalette("terrain"); - wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B)))); + wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.RA/PlayerPaletteFromCurrentTileset.cs b/OpenRA.Mods.RA/PlayerPaletteFromCurrentTileset.cs index 2315236f30..a28fac7522 100644 --- a/OpenRA.Mods.RA/PlayerPaletteFromCurrentTileset.cs +++ b/OpenRA.Mods.RA/PlayerPaletteFromCurrentTileset.cs @@ -17,6 +17,7 @@ namespace OpenRA.Mods.RA { public readonly string Name = null; public readonly int[] ShadowIndex = { }; + public readonly bool AllowModifiers = true; public object Create(ActorInitializer init) { return new PlayerPaletteFromCurrentTileset(init.world, this); } } @@ -35,7 +36,7 @@ namespace OpenRA.Mods.RA public void InitPalette (OpenRA.Graphics.WorldRenderer wr) { string Filename = world.TileSet.PlayerPalette == null ? world.TileSet.Palette : world.TileSet.PlayerPalette; - wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex)); + wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.RA/ShroudPalette.cs b/OpenRA.Mods.RA/ShroudPalette.cs index f8015a979a..a8858b12d6 100644 --- a/OpenRA.Mods.RA/ShroudPalette.cs +++ b/OpenRA.Mods.RA/ShroudPalette.cs @@ -27,12 +27,12 @@ namespace OpenRA.Mods.RA { readonly ShroudPaletteInfo info; - public ShroudPalette( ShroudPaletteInfo info ) { this.info = info; } + public ShroudPalette(ShroudPaletteInfo info) { this.info = info; } - public void InitPalette( WorldRenderer wr ) + public void InitPalette(WorldRenderer wr) { - var pal = wr.GetPalette( "terrain" ); - wr.AddPalette( info.Name, new Palette( pal, new ShroudPaletteRemap( info.IsFog ) ) ); + var pal = wr.GetPalette("terrain"); + wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)), false); } } diff --git a/OpenRA.Mods.RA/WaterPaletteRotation.cs b/OpenRA.Mods.RA/WaterPaletteRotation.cs index 9a3aedf454..a8a24127c1 100644 --- a/OpenRA.Mods.RA/WaterPaletteRotation.cs +++ b/OpenRA.Mods.RA/WaterPaletteRotation.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA { class WaterPaletteRotationInfo : ITraitInfo { - public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "player" }; + public readonly string[] ExcludePalettes = {}; public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.world, this); } } diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index f968a228b6..b03db10d59 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -84,6 +84,7 @@ World: Name: colorpicker Filename: temperat.pal ShadowIndex: 4 + AllowModifiers: false PaletteFromRGBA@shadow: Name: shadow R: 0 diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index 31c6ffc05e..f00901c7f9 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -273,6 +273,7 @@ World: Name: colorpicker Filename: d2k.pal ShadowIndex: 4 + AllowModifiers: false PaletteFromRGBA@shadow: Name: shadow R: 0 diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index eb0fd1a1ea..729edaf08f 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -228,6 +228,7 @@ World: Name: colorpicker Filename: temperat.pal ShadowIndex: 4 + AllowModifiers: false PaletteFromRGBA@shadow: Name: shadow R: 0 From 2d10f6b739522de479073f166402ac7401be269d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 22 Feb 2013 12:12:45 +1300 Subject: [PATCH 10/67] Remove unnecessary indirection from palette creation. --- OpenRA.FileFormats/Palette.cs | 7 +++++ OpenRA.Mods.RA/FogPalette.cs | 44 ++++++++++++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/PaletteFromRGBA.cs | 26 ++++------------ OpenRA.Mods.RA/ShroudPalette.cs | 38 ++++++------------------ mods/cnc/rules/system.yaml | 6 ++-- mods/d2k/rules/system.yaml | 6 ++-- mods/ra/rules/system.yaml | 6 ++-- 8 files changed, 73 insertions(+), 61 deletions(-) create mode 100644 OpenRA.Mods.RA/FogPalette.cs diff --git a/OpenRA.FileFormats/Palette.cs b/OpenRA.FileFormats/Palette.cs index 08effa4285..1202dc8f70 100644 --- a/OpenRA.FileFormats/Palette.cs +++ b/OpenRA.FileFormats/Palette.cs @@ -76,6 +76,13 @@ namespace OpenRA.FileFormats colors = (uint[])p.colors.Clone(); } + public Palette(uint[] data) + { + if (data.Length != 256) + throw new InvalidDataException("Attempting to create palette with incorrect array size"); + colors = (uint[])data.Clone(); + } + public ColorPalette AsSystemPalette() { ColorPalette pal; diff --git a/OpenRA.Mods.RA/FogPalette.cs b/OpenRA.Mods.RA/FogPalette.cs new file mode 100644 index 0000000000..642bb4e684 --- /dev/null +++ b/OpenRA.Mods.RA/FogPalette.cs @@ -0,0 +1,44 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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.Drawing; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class FogPaletteInfo : ITraitInfo + { + public readonly string Name = "fog"; + public object Create(ActorInitializer init) { return new FogPalette(this); } + } + + class FogPalette : IPalette + { + readonly FogPaletteInfo info; + + public FogPalette(FogPaletteInfo info) { this.info = info; } + + public void InitPalette(WorldRenderer wr) + { + var c = new[] { + Color.Transparent, Color.Green, + Color.Blue, Color.Yellow, + Color.FromArgb(128,0,0,0), + Color.FromArgb(128,0,0,0), + Color.FromArgb(128,0,0,0), + Color.FromArgb(64,0,0,0) + }; + + wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 3553a0b857..0be9b84bb3 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -407,6 +407,7 @@ + diff --git a/OpenRA.Mods.RA/PaletteFromRGBA.cs b/OpenRA.Mods.RA/PaletteFromRGBA.cs index 9fd84ba698..4f8a33c14f 100644 --- a/OpenRA.Mods.RA/PaletteFromRGBA.cs +++ b/OpenRA.Mods.RA/PaletteFromRGBA.cs @@ -38,28 +38,14 @@ namespace OpenRA.Mods.RA this.info = info; } - public void InitPalette( WorldRenderer wr ) + public void InitPalette(WorldRenderer wr) { - if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant()) - { - // TODO: This shouldn't rely on a base palette - var pal = wr.GetPalette("terrain"); - wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))), info.AllowModifiers); - } - } - } + // Enable palette only for a specific tileset + if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant()) + return; - class SingleColorRemap : IPaletteRemap - { - Color c; - public SingleColorRemap(Color c) - { - this.c = c; - } - - public Color GetRemappedColor(Color original, int index) - { - return original.A > 0 ? c : original; + var c = (uint)((info.A << 24) | (info.R << 16) | (info.G << 8) | info.B); + wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (i == 0) ? 0 : c)), info.AllowModifiers); } } } diff --git a/OpenRA.Mods.RA/ShroudPalette.cs b/OpenRA.Mods.RA/ShroudPalette.cs index a8858b12d6..5437a1987f 100644 --- a/OpenRA.Mods.RA/ShroudPalette.cs +++ b/OpenRA.Mods.RA/ShroudPalette.cs @@ -18,8 +18,6 @@ namespace OpenRA.Mods.RA class ShroudPaletteInfo : ITraitInfo { public readonly string Name = "shroud"; - public readonly bool IsFog = false; - public object Create(ActorInitializer init) { return new ShroudPalette(this); } } @@ -31,34 +29,16 @@ namespace OpenRA.Mods.RA public void InitPalette(WorldRenderer wr) { - var pal = wr.GetPalette("terrain"); - wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)), false); - } - } + var c = new[] { + Color.Transparent, Color.Green, + Color.Blue, Color.Yellow, + Color.Black, + Color.FromArgb(128,0,0,0), + Color.Transparent, + Color.Transparent + }; - class ShroudPaletteRemap : IPaletteRemap - { - bool isFog; - - public ShroudPaletteRemap(bool isFog) { this.isFog = isFog; } - public Color GetRemappedColor(Color original, int index) - { - if (isFog) - return new[] { - Color.Transparent, Color.Green, - Color.Blue, Color.Yellow, - Color.FromArgb(128,0,0,0), - Color.FromArgb(128,0,0,0), - Color.FromArgb(128,0,0,0), - Color.FromArgb(64,0,0,0)}[index % 8]; - else - return new[] { - Color.Transparent, Color.Green, - Color.Blue, Color.Yellow, - Color.Black, - Color.FromArgb(128,0,0,0), - Color.Transparent, - Color.Transparent}[index % 8]; + wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false); } } } diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index b03db10d59..09e55fe797 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -109,10 +109,8 @@ World: G: 0 B: 0 A: 180 - ShroudPalette@shroud: - ShroudPalette@fog: - IsFog: yes - Name: fog + ShroudPalette: + FogPalette: Country@gdi: Name: GDI Race: gdi diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index f00901c7f9..8376d71d8f 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -304,10 +304,8 @@ World: G: 0 B: 0 A: 180 - ShroudPalette@shroud: - ShroudPalette@fog: - IsFog: yes - Name: fog + ShroudPalette: + FogPalette: Country@Atreides: Name: Atreides Race: atreides diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 729edaf08f..e99790cfe0 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -259,10 +259,8 @@ World: G: 0 B: 0 A: 180 - ShroudPalette@shroud: - ShroudPalette@fog: - IsFog: yes - Name: fog + ShroudPalette: + FogPalette: Country@0: Name: Allies Race: allies From 0287993c31d6ca217b75eda9df2917a92e14d6b8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 21 Feb 2013 23:38:19 +1300 Subject: [PATCH 11/67] Add bitmap export to palette (for debugging). --- OpenRA.FileFormats/Palette.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OpenRA.FileFormats/Palette.cs b/OpenRA.FileFormats/Palette.cs index 1202dc8f70..be5bf5e6bf 100644 --- a/OpenRA.FileFormats/Palette.cs +++ b/OpenRA.FileFormats/Palette.cs @@ -100,6 +100,21 @@ namespace OpenRA.FileFormats return pal; } + public Bitmap AsBitmap() + { + var b = new Bitmap(256, 1, PixelFormat.Format32bppArgb); + var data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), + ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); + unsafe + { + uint* c = (uint*)data.Scan0; + for (var x = 0; x < 256; x++) + *(c + x) = colors[x]; + } + b.UnlockBits(data); + return b; + } + public static Palette Load(string filename, int[] remap) { using(var s = File.OpenRead(filename)) From 35a149ea87a02de3af20d2f99bf56404eb138184 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 23 Feb 2013 09:46:16 +1300 Subject: [PATCH 12/67] Apply consistent formatting to Renderer (no code changes). --- OpenRA.Game/Graphics/Renderer.cs | 58 ++++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 793a656725..77306e1872 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -56,14 +56,14 @@ namespace OpenRA.Graphics RgbaSpriteShader = device.CreateShader("chrome-rgba"); SpriteShader = device.CreateShader("chrome-shp"); - WorldSpriteRenderer = new SpriteRenderer( this, WorldSpriteShader ); + WorldSpriteRenderer = new SpriteRenderer(this, WorldSpriteShader); WorldLineRenderer = new LineRenderer(this, WorldLineShader); LineRenderer = new LineRenderer(this, LineShader); - RgbaSpriteRenderer = new SpriteRenderer( this, RgbaSpriteShader ); - SpriteRenderer = new SpriteRenderer( this, SpriteShader ); + RgbaSpriteRenderer = new SpriteRenderer(this, RgbaSpriteShader); + SpriteRenderer = new SpriteRenderer(this, SpriteShader); - for( int i = 0 ; i < TempBufferCount ; i++ ) - tempBuffers.Enqueue( device.CreateVertexBuffer( TempBufferSize ) ); + for (int i = 0; i < TempBufferCount; i++) + tempBuffers.Enqueue(device.CreateVertexBuffer(TempBufferSize)); } public void InitializeFonts(Manifest m) @@ -80,22 +80,22 @@ namespace OpenRA.Graphics float2 r2 = new float2(-1, 1); var zr1 = zoom*r1; - SetShaderParams( WorldSpriteShader, zr1, r2, scroll ); - SetShaderParams( WorldLineShader, zr1, r2, scroll ); - SetShaderParams( LineShader, r1, r2, scroll ); - SetShaderParams( RgbaSpriteShader, r1, r2, scroll ); - SetShaderParams( SpriteShader, r1, r2, scroll ); + SetShaderParams(WorldSpriteShader, zr1, r2, scroll); + SetShaderParams(WorldLineShader, zr1, r2, scroll); + SetShaderParams(LineShader, r1, r2, scroll); + SetShaderParams(RgbaSpriteShader, r1, r2, scroll); + SetShaderParams(SpriteShader, r1, r2, scroll); } - void SetShaderParams( IShader s, float2 r1, float2 r2, float2 scroll ) + void SetShaderParams(IShader s, float2 r1, float2 r2, float2 scroll) { - s.SetValue( "Palette", PaletteTexture ); - s.SetValue( "Scroll", (int) scroll.X, (int) scroll.Y ); - s.SetValue( "r1", r1.X, r1.Y ); - s.SetValue( "r2", r2.X, r2.Y ); + s.SetValue("Palette", PaletteTexture); + s.SetValue("Scroll", (int)scroll.X, (int)scroll.Y); + s.SetValue("r1", r1.X, r1.Y); + s.SetValue("r2", r2.X, r2.Y); } - public void EndFrame( IInputHandler inputHandler ) + public void EndFrame(IInputHandler inputHandler) { Flush(); device.PumpInput(inputHandler); @@ -129,17 +129,17 @@ namespace OpenRA.Graphics // which makes the window non-interactive in Windowed/Pseudofullscreen mode. static Screen FixOSX() { return Screen.PrimaryScreen; } - internal static void Initialize( WindowMode windowMode ) + internal static void Initialize(WindowMode windowMode) { if (Platform.CurrentPlatform == PlatformType.OSX) FixOSX(); - var resolution = GetResolution( windowMode ); + var resolution = GetResolution(windowMode); - string renderer = Game.Settings.Server.Dedicated?"Null":Game.Settings.Graphics.Renderer; - var rendererPath = Path.GetFullPath( "OpenRA.Renderer.{0}.dll".F(renderer) ); + string renderer = Game.Settings.Server.Dedicated ? "Null" : Game.Settings.Graphics.Renderer; + var rendererPath = Path.GetFullPath("OpenRA.Renderer.{0}.dll".F(renderer)); - device = CreateDevice( Assembly.LoadFile( rendererPath ), resolution.Width, resolution.Height, windowMode ); + device = CreateDevice(Assembly.LoadFile(rendererPath), resolution.Width, resolution.Height, windowMode); } static Size GetResolution(WindowMode windowmode) @@ -150,12 +150,12 @@ namespace OpenRA.Graphics return new Size(size.X, size.Y); } - static IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, WindowMode window ) + static IGraphicsDevice CreateDevice(Assembly rendererDll, int width, int height, WindowMode window) { - foreach( RendererAttribute r in rendererDll.GetCustomAttributes( typeof( RendererAttribute ), false ) ) + foreach (RendererAttribute r in rendererDll.GetCustomAttributes(typeof(RendererAttribute), false)) { - var factory = (IDeviceFactory) r.Type.GetConstructor( Type.EmptyTypes ).Invoke( null ); - return factory.Create( new Size( width, height ), window ); + var factory = (IDeviceFactory)r.Type.GetConstructor(Type.EmptyTypes).Invoke(null); + return factory.Create(new Size(width, height), window); } throw new InvalidOperationException("Renderer DLL is missing RendererAttribute to tell us what type to use!"); @@ -164,7 +164,7 @@ namespace OpenRA.Graphics internal IVertexBuffer GetTempVertexBuffer() { var ret = tempBuffers.Dequeue(); - tempBuffers.Enqueue( ret ); + tempBuffers.Enqueue(ret); return ret; } @@ -176,8 +176,8 @@ namespace OpenRA.Graphics get { return currentBatchRenderer; } set { - if( currentBatchRenderer == value ) return; - if( currentBatchRenderer != null ) + if (currentBatchRenderer == value) return; + if (currentBatchRenderer != null) currentBatchRenderer.Flush(); currentBatchRenderer = value; } @@ -186,7 +186,7 @@ namespace OpenRA.Graphics public void EnableScissor(int left, int top, int width, int height) { Flush(); - Device.EnableScissor( left, top, width, height ); + Device.EnableScissor(left, top, width, height); } public void DisableScissor() From a1668153484d35c25b2c203ce5c7f28edc545909 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 23 Feb 2013 09:53:46 +1300 Subject: [PATCH 13/67] Remove duplication between world/chrome shaders. --- OpenRA.Game/Graphics/Renderer.cs | 16 +++--- cg/chrome-line.fx | 55 ------------------- cg/chrome-shp.fx | 80 ---------------------------- cg/{world-line.fx => line.fx} | 0 cg/{chrome-rgba.fx => rgba.fx} | 0 cg/{world-shp.fx => shp.fx} | 0 glsl/chrome-line.vert | 7 --- glsl/chrome-shp.vert | 17 ------ glsl/{chrome-line.frag => line.frag} | 0 glsl/{world-line.vert => line.vert} | 0 glsl/{chrome-rgba.frag => rgba.frag} | 0 glsl/{chrome-rgba.vert => rgba.vert} | 0 glsl/{chrome-shp.frag => shp.frag} | 0 glsl/{world-shp.vert => shp.vert} | 0 glsl/world-line.frag | 4 -- glsl/world-shp.frag | 8 --- 16 files changed, 8 insertions(+), 179 deletions(-) delete mode 100644 cg/chrome-line.fx delete mode 100644 cg/chrome-shp.fx rename cg/{world-line.fx => line.fx} (100%) rename cg/{chrome-rgba.fx => rgba.fx} (100%) rename cg/{world-shp.fx => shp.fx} (100%) delete mode 100644 glsl/chrome-line.vert delete mode 100644 glsl/chrome-shp.vert rename glsl/{chrome-line.frag => line.frag} (100%) rename glsl/{world-line.vert => line.vert} (100%) rename glsl/{chrome-rgba.frag => rgba.frag} (100%) rename glsl/{chrome-rgba.vert => rgba.vert} (100%) rename glsl/{chrome-shp.frag => shp.frag} (100%) rename glsl/{world-shp.vert => shp.vert} (100%) delete mode 100644 glsl/world-line.frag delete mode 100644 glsl/world-shp.frag diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 77306e1872..e354698882 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -50,11 +50,11 @@ namespace OpenRA.Graphics TempBufferCount = Game.Settings.Graphics.NumTempBuffers; SheetSize = Game.Settings.Graphics.SheetSize; - WorldSpriteShader = device.CreateShader("world-shp"); - WorldLineShader = device.CreateShader("world-line"); - LineShader = device.CreateShader("chrome-line"); - RgbaSpriteShader = device.CreateShader("chrome-rgba"); - SpriteShader = device.CreateShader("chrome-shp"); + WorldSpriteShader = device.CreateShader("shp"); + WorldLineShader = device.CreateShader("line"); + LineShader = device.CreateShader("line"); + RgbaSpriteShader = device.CreateShader("rgba"); + SpriteShader = device.CreateShader("shp"); WorldSpriteRenderer = new SpriteRenderer(this, WorldSpriteShader); WorldLineRenderer = new LineRenderer(this, WorldLineShader); @@ -82,9 +82,9 @@ namespace OpenRA.Graphics SetShaderParams(WorldSpriteShader, zr1, r2, scroll); SetShaderParams(WorldLineShader, zr1, r2, scroll); - SetShaderParams(LineShader, r1, r2, scroll); - SetShaderParams(RgbaSpriteShader, r1, r2, scroll); - SetShaderParams(SpriteShader, r1, r2, scroll); + SetShaderParams(LineShader, r1, r2, float2.Zero); + SetShaderParams(RgbaSpriteShader, r1, r2, float2.Zero); + SetShaderParams(SpriteShader, r1, r2, float2.Zero); } void SetShaderParams(IShader s, float2 r1, float2 r2, float2 scroll) diff --git a/cg/chrome-line.fx b/cg/chrome-line.fx deleted file mode 100644 index ede4851f47..0000000000 --- a/cg/chrome-line.fx +++ /dev/null @@ -1,55 +0,0 @@ -// OpenRA gui lines shader -// Author: C. Forbes -//-------------------------------------------------------- - -float2 r1, r2; // matrix elements - -struct VertexIn { - float4 Position: POSITION; - float4 Color: TEXCOORD0; -}; - -struct VertexOut { - float4 Position: POSITION; - float4 Color: COLOR0; -}; - -VertexOut Simple_vp(VertexIn v) { - VertexOut o; - float2 p = v.Position.xy * r1 + r2; - o.Position = float4(p.x,p.y,0,1); - o.Color = v.Color; - return o; -} - -float4 Simple_fp(VertexOut f) : COLOR0 { - return f.Color; -} - -technique high_quality { - pass p0 { - BlendEnable = true; - DepthTestEnable = false; - //CullMode = None; - //FillMode = Wireframe; - VertexProgram = compile latest Simple_vp(); - FragmentProgram = compile latest Simple_fp(); - - BlendEquation = FuncAdd; - BlendFunc = int2( SrcAlpha, OneMinusSrcAlpha ); - } -} - -technique high_quality_cg21 { - pass p0 { - BlendEnable = true; - DepthTestEnable = false; - //CullMode = None; - //FillMode = Wireframe; - VertexProgram = compile arbvp1 Simple_vp(); - FragmentProgram = compile arbfp1 Simple_fp(); - - BlendEquation = FuncAdd; - BlendFunc = int2( SrcAlpha, OneMinusSrcAlpha ); - } -} \ No newline at end of file diff --git a/cg/chrome-shp.fx b/cg/chrome-shp.fx deleted file mode 100644 index 750d8c9a6c..0000000000 --- a/cg/chrome-shp.fx +++ /dev/null @@ -1,80 +0,0 @@ -// OpenRA test shader -// Author: C. Forbes -//-------------------------------------------------------- - -float2 Scroll; -float2 r1, r2; // matrix elements - -sampler2D DiffuseTexture = sampler_state { - MinFilter = Nearest; - MagFilter = Nearest; - WrapS = Repeat; - WrapT = Repeat; -}; - -sampler2D Palette = sampler_state { - MinFilter = Nearest; - MagFilter = Nearest; - WrapS = Repeat; - WrapT = Repeat; -}; - -struct VertexIn { - float4 Position: POSITION; - float4 Tex0: TEXCOORD0; -}; - -struct VertexOut { - float4 Position: POSITION; - float3 Tex0: TEXCOORD0; - float4 ChannelMask: TEXCOORD1; -}; - -float4 DecodeChannelMask( float x ) -{ - if (x > 0) - return (x > 0.5f) ? float4(1,0,0,0) : float4(0,1,0,0); - else - return (x <-0.5f) ? float4(0,0,0,1) : float4(0,0,1,0); -} - -VertexOut Simple_vp(VertexIn v) { - VertexOut o; - float2 p = v.Position.xy * r1 + r2; - o.Position = float4(p.x,p.y,0,1); - o.Tex0 = float3(v.Tex0.x, v.Tex0.y, v.Tex0.z); - o.ChannelMask = DecodeChannelMask( v.Tex0.w ); - return o; -} - -float4 Palette_fp(VertexOut f) : COLOR0 { - float4 x = tex2D(DiffuseTexture, f.Tex0.xy); - float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z ); - return tex2D(Palette, p); -} - -technique low_quality { - pass p0 { - BlendEnable = true; - DepthTestEnable = false; - CullFaceEnable = false; - VertexProgram = compile latest Simple_vp(); - FragmentProgram = compile latest Palette_fp(); - - BlendEquation = FuncAdd; - BlendFunc = int2( SrcAlpha, OneMinusSrcAlpha ); - } -} - -technique low_quality_cg21 { - pass p0 { - BlendEnable = true; - DepthTestEnable = false; - CullFaceEnable = false; - VertexProgram = compile arbvp1 Simple_vp(); - FragmentProgram = compile arbfp1 Palette_fp(); - - BlendEquation = FuncAdd; - BlendFunc = int2( SrcAlpha, OneMinusSrcAlpha ); - } -} diff --git a/cg/world-line.fx b/cg/line.fx similarity index 100% rename from cg/world-line.fx rename to cg/line.fx diff --git a/cg/chrome-rgba.fx b/cg/rgba.fx similarity index 100% rename from cg/chrome-rgba.fx rename to cg/rgba.fx diff --git a/cg/world-shp.fx b/cg/shp.fx similarity index 100% rename from cg/world-shp.fx rename to cg/shp.fx diff --git a/glsl/chrome-line.vert b/glsl/chrome-line.vert deleted file mode 100644 index 8c1d357cc0..0000000000 --- a/glsl/chrome-line.vert +++ /dev/null @@ -1,7 +0,0 @@ -uniform vec2 r1, r2; // matrix elements -void main() -{ - vec2 p = gl_Vertex.xy*r1 + r2; - gl_Position = vec4(p.x,p.y,0,1); - gl_FrontColor = gl_MultiTexCoord0; -} diff --git a/glsl/chrome-shp.vert b/glsl/chrome-shp.vert deleted file mode 100644 index 8541b53f1e..0000000000 --- a/glsl/chrome-shp.vert +++ /dev/null @@ -1,17 +0,0 @@ -uniform vec2 r1,r2; // matrix elements - -vec4 DecodeChannelMask( float x ) -{ - if (x > 0.0) - return (x > 0.5) ? vec4(1,0,0,0) : vec4(0,1,0,0); - else - return (x < -0.5) ? vec4(0,0,0,1) : vec4(0,0,1,0); -} - -void main() -{ - vec2 p = gl_Vertex.xy*r1 + r2; - gl_Position = vec4(p.x,p.y,0,1); - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_TexCoord[1] = DecodeChannelMask(gl_MultiTexCoord0.w); -} diff --git a/glsl/chrome-line.frag b/glsl/line.frag similarity index 100% rename from glsl/chrome-line.frag rename to glsl/line.frag diff --git a/glsl/world-line.vert b/glsl/line.vert similarity index 100% rename from glsl/world-line.vert rename to glsl/line.vert diff --git a/glsl/chrome-rgba.frag b/glsl/rgba.frag similarity index 100% rename from glsl/chrome-rgba.frag rename to glsl/rgba.frag diff --git a/glsl/chrome-rgba.vert b/glsl/rgba.vert similarity index 100% rename from glsl/chrome-rgba.vert rename to glsl/rgba.vert diff --git a/glsl/chrome-shp.frag b/glsl/shp.frag similarity index 100% rename from glsl/chrome-shp.frag rename to glsl/shp.frag diff --git a/glsl/world-shp.vert b/glsl/shp.vert similarity index 100% rename from glsl/world-shp.vert rename to glsl/shp.vert diff --git a/glsl/world-line.frag b/glsl/world-line.frag deleted file mode 100644 index 3f45d895ff..0000000000 --- a/glsl/world-line.frag +++ /dev/null @@ -1,4 +0,0 @@ -void main() -{ - gl_FragColor = gl_Color; -} \ No newline at end of file diff --git a/glsl/world-shp.frag b/glsl/world-shp.frag deleted file mode 100644 index dbabad7184..0000000000 --- a/glsl/world-shp.frag +++ /dev/null @@ -1,8 +0,0 @@ -uniform sampler2D DiffuseTexture, Palette; - -void main() -{ - vec4 x = texture2D(DiffuseTexture, gl_TexCoord[0].st); - vec2 p = vec2( dot(x, gl_TexCoord[1]), gl_TexCoord[0].p ); - gl_FragColor = texture2D(Palette,p); -} \ No newline at end of file From f0ba0ce2e8f1c68632453a932a073611ef2b6efe Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 11:08:50 +1300 Subject: [PATCH 14/67] Wrap palette references with a PaletteRef object. --- OpenRA.Game/Effects/FlashTarget.cs | 3 +- OpenRA.Game/Graphics/AnimationWithOffset.cs | 2 +- OpenRA.Game/Graphics/WorldRenderer.cs | 31 +++++++++++++++++-- OpenRA.Game/Traits/Render/RenderSimple.cs | 9 ++++-- OpenRA.Game/Traits/TraitsInterfaces.cs | 10 +++--- OpenRA.Mods.Cnc/Effects/IonCannon.cs | 2 +- OpenRA.Mods.RA/Bridge.cs | 2 +- OpenRA.Mods.RA/Cloak.cs | 3 +- OpenRA.Mods.RA/Effects/Bullet.cs | 6 ++-- OpenRA.Mods.RA/Effects/Corpse.cs | 2 +- OpenRA.Mods.RA/Effects/CrateEffect.cs | 3 +- OpenRA.Mods.RA/Effects/Explosion.cs | 2 +- OpenRA.Mods.RA/Effects/GpsSatellite.cs | 2 +- OpenRA.Mods.RA/Effects/GravityBomb.cs | 4 +-- OpenRA.Mods.RA/Effects/InvulnEffect.cs | 3 +- OpenRA.Mods.RA/Effects/LaserZap.cs | 4 +-- OpenRA.Mods.RA/Effects/Missile.cs | 2 +- OpenRA.Mods.RA/Effects/NukeLaunch.cs | 2 +- OpenRA.Mods.RA/Effects/Parachute.cs | 4 +-- OpenRA.Mods.RA/Effects/PowerdownIndicator.cs | 4 +-- OpenRA.Mods.RA/Effects/SatelliteLaunch.cs | 2 +- OpenRA.Mods.RA/Effects/Smoke.cs | 3 +- OpenRA.Mods.RA/Effects/TeslaZap.cs | 3 +- OpenRA.Mods.RA/GainsExperience.cs | 4 +-- .../Orders/PlaceBuildingOrderGenerator.cs | 2 +- OpenRA.Mods.RA/Render/RenderBuilding.cs | 2 +- .../Render/RenderBuildingWarFactory.cs | 3 +- OpenRA.Mods.RA/Render/WithMuzzleFlash.cs | 2 +- OpenRA.Mods.RA/Render/WithShadow.cs | 3 +- .../SupportPowers/ChronoshiftPower.cs | 2 +- 30 files changed, 83 insertions(+), 43 deletions(-) diff --git a/OpenRA.Game/Effects/FlashTarget.cs b/OpenRA.Game/Effects/FlashTarget.cs index 17b8fe42fd..9dd0de5b92 100755 --- a/OpenRA.Game/Effects/FlashTarget.cs +++ b/OpenRA.Game/Effects/FlashTarget.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Effects @@ -39,7 +40,7 @@ namespace OpenRA.Effects if (remainingTicks % 2 == 0) foreach (var r in target.Render()) - yield return r.WithPalette("highlight"); + yield return r.WithPalette(PaletteReference.FromName("highlight")); } } } diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs index c29c341688..c048f5c8fd 100644 --- a/OpenRA.Game/Graphics/AnimationWithOffset.cs +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -32,7 +32,7 @@ namespace OpenRA.Graphics this.DisableFunc = d; } - public Renderable Image(Actor self, string pal) + public Renderable Image(Actor self, PaletteReference pal) { var p = self.CenterLocation; var loc = p.ToFloat2() - 0.5f * Animation.Image.size diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 8aaed1c3f2..1ce9ad5584 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -17,6 +17,33 @@ using OpenRA.Traits; namespace OpenRA.Graphics { + public class PaletteReference + { + string name; + int index; + public PaletteReference(string name, int index) + { + this.name = name; + this.index = index; + } + + public static PaletteReference FromName(string name) + { + return new PaletteReference(name, -1); + } + + public int RowIndex(WorldRenderer wr) + { + if (index == -1) + { + // Too spammy to enable by default + //Log.Write("perf", "Late resolution of palette reference {0}", name); + index = wr.GetPaletteIndex(name); + } + return index; + } + } + public class WorldRenderer { public readonly World world; @@ -78,7 +105,7 @@ namespace OpenRA.Graphics terrainRenderer.Draw(this, Game.viewport); foreach (var a in world.traitDict.ActorsWithTraitMultiple(world)) foreach (var r in a.Trait.RenderAsTerrain(a.Actor)) - r.Sprite.DrawAt(r.Pos, this.GetPaletteIndex(r.Palette), r.Scale); + r.Sprite.DrawAt(r.Pos, r.Palette.RowIndex(this), r.Scale); foreach (var a in world.Selection.Actors) if (!a.Destroyed) @@ -91,7 +118,7 @@ namespace OpenRA.Graphics world.OrderGenerator.RenderBeforeWorld(this, world); foreach (var image in SpritesToRender()) - image.Sprite.DrawAt(image.Pos, this.GetPaletteIndex(image.Palette), image.Scale); + image.Sprite.DrawAt(image.Pos, image.Palette.RowIndex(this), image.Scale); // added for contrails foreach (var a in world.ActorsWithTrait()) diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 1b2d4ff6c7..3e8096e3c0 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -27,8 +27,10 @@ namespace OpenRA.Traits { var anim = new Animation(RenderSimple.GetImage(building), () => 0); anim.PlayRepeating("idle"); + + var pal = Palette ?? (owner != null ? PlayerPalette + owner.InternalName : null); yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), - Palette ?? (owner != null ? PlayerPalette + owner.InternalName : null), 0, Scale); + PaletteReference.FromName(pal), 0, Scale); } } @@ -77,7 +79,10 @@ namespace OpenRA.Traits anim.PlayRepeating("idle"); } - public string Palette(Player p) { return Info.Palette ?? Info.PlayerPalette + p.InternalName; } + public PaletteReference Palette(Player p) + { + return PaletteReference.FromName(Info.Palette ?? Info.PlayerPalette + p.InternalName); + } public virtual IEnumerable Render(Actor self) { diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 2380f474b9..41fb0835d1 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -154,12 +154,12 @@ namespace OpenRA.Traits { public readonly Sprite Sprite; public readonly float2 Pos; - public readonly string Palette; + public readonly PaletteReference Palette; public readonly int Z; public readonly int ZOffset; public float Scale; - public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale) + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, int zOffset, float scale) { Sprite = sprite; Pos = pos; @@ -169,14 +169,14 @@ namespace OpenRA.Traits Scale = scale; /* default */ } - public Renderable(Sprite sprite, float2 pos, string palette, int z) + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z) : this(sprite, pos, palette, z, 0, 1f) { } - public Renderable(Sprite sprite, float2 pos, string palette, int z, float scale) + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, float scale) : this(sprite, pos, palette, z, 0, scale) { } public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } - public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } + public Renderable WithPalette(PaletteReference newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } } diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index 9d7543d9b9..fd53a1dc20 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Cnc.Effects { yield return new Renderable(anim.Image, target.CenterLocation.ToFloat2() - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), - "effect", (int)target.CenterLocation.Y); + PaletteReference.FromName("effect"), (int)target.CenterLocation.Y); } void Finish( World world ) diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index 67d84a569b..88ce8af4fa 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -138,7 +138,7 @@ namespace OpenRA.Mods.RA public IEnumerable RenderAsTerrain(Actor self) { foreach (var t in TileSprites[currentTemplate]) - yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), "terrain", Game.CellSize * t.Key.Y); + yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), PaletteReference.FromName("terrain"), Game.CellSize * t.Key.Y); } bool IsIntact(Bridge b) diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index e4924828d3..84ebf54a6c 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -73,7 +74,7 @@ namespace OpenRA.Mods.RA return rs; if (Cloaked && IsVisible(self)) - return rs.Select(a => a.WithPalette(info.Palette)); + return rs.Select(a => a.WithPalette(PaletteReference.FromName(info.Palette))); else return Nothing; } diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index dffa8b47bd..56551c9430 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -158,15 +158,15 @@ namespace OpenRA.Mods.RA.Effects if (Info.High || Info.Angle > 0) { if (Info.Shadow) - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "shadow", (int)pos.Y); + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, PaletteReference.FromName("shadow"), (int)pos.Y); var highPos = pos - new float2(0, GetAltitude()); - yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, "effect", (int)pos.Y); + yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, PaletteReference.FromName("effect"), (int)pos.Y); } else yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, - Args.weapon.Underwater ? "shadow" : "effect", (int)pos.Y); + PaletteReference.FromName(Args.weapon.Underwater ? "shadow" : "effect"), (int)pos.Y); } } diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index 7a536b9ab8..ace3f0f235 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.Effects { readonly Animation anim; readonly float2 pos; - readonly string palette; + readonly PaletteReference palette; public Corpse(Actor fromActor, string sequence) { diff --git a/OpenRA.Mods.RA/Effects/CrateEffect.cs b/OpenRA.Mods.RA/Effects/CrateEffect.cs index 7f0e7ab083..48bca60799 100644 --- a/OpenRA.Mods.RA/Effects/CrateEffect.cs +++ b/OpenRA.Mods.RA/Effects/CrateEffect.cs @@ -43,7 +43,8 @@ namespace OpenRA.Mods.RA.Effects { if (a.IsInWorld) yield return new Renderable(anim.Image, - a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y); + a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, + PaletteReference.FromName("effect"), (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Explosion.cs b/OpenRA.Mods.RA/Effects/Explosion.cs index 646999ae2f..4ab7089ea3 100644 --- a/OpenRA.Mods.RA/Effects/Explosion.cs +++ b/OpenRA.Mods.RA/Effects/Explosion.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Effects { yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude), - "effect", (int)pos.Y - altitude); + PaletteReference.FromName("effect"), (int)pos.Y - altitude); } public Player Owner { get { return null; } } diff --git a/OpenRA.Mods.RA/Effects/GpsSatellite.cs b/OpenRA.Mods.RA/Effects/GpsSatellite.cs index 30d0d63df3..6dd3b331ff 100644 --- a/OpenRA.Mods.RA/Effects/GpsSatellite.cs +++ b/OpenRA.Mods.RA/Effects/GpsSatellite.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(anim.Image,offset, "effect", (int)offset.Y); + yield return new Renderable(anim.Image,offset, PaletteReference.FromName("effect"), (int)offset.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/GravityBomb.cs b/OpenRA.Mods.RA/Effects/GravityBomb.cs index 36a142c7ab..0b4caf2e34 100755 --- a/OpenRA.Mods.RA/Effects/GravityBomb.cs +++ b/OpenRA.Mods.RA/Effects/GravityBomb.cs @@ -53,8 +53,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(anim.Image, - Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y); + var pos = Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size; + yield return new Renderable(anim.Image, pos, PaletteReference.FromName("effect"), Args.dest.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/InvulnEffect.cs b/OpenRA.Mods.RA/Effects/InvulnEffect.cs index 1e17098892..ef5f431e14 100644 --- a/OpenRA.Mods.RA/Effects/InvulnEffect.cs +++ b/OpenRA.Mods.RA/Effects/InvulnEffect.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using OpenRA.Effects; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA.Effects @@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects yield break; foreach (var r in a.Render()) - yield return r.WithPalette("invuln"); + yield return r.WithPalette(PaletteReference.FromName("invuln")); } } } diff --git a/OpenRA.Mods.RA/Effects/LaserZap.cs b/OpenRA.Mods.RA/Effects/LaserZap.cs index bba07c0386..6480aa30a3 100755 --- a/OpenRA.Mods.RA/Effects/LaserZap.cs +++ b/OpenRA.Mods.RA/Effects/LaserZap.cs @@ -77,8 +77,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { if (explosion != null) - yield return new Renderable(explosion.Image, - args.dest.ToFloat2() - .5f * explosion.Image.size, "effect", (int)args.dest.Y); + yield return new Renderable(explosion.Image, args.dest.ToFloat2() - .5f * explosion.Image.size, + PaletteReference.FromName("effect"), (int)args.dest.Y); if (ticks >= info.BeamDuration) yield break; diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index f6e84ae683..7b0754b529 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -156,7 +156,7 @@ namespace OpenRA.Mods.RA.Effects { if (Args.firedBy.World.RenderedShroud.IsVisible(PxPosition.ToCPos())) yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), - Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y); + PaletteReference.FromName(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y); if (Trail != null) Trail.Render(Args.firedBy); diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index 251370991f..ed9e2a9631 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude), - "effect", (int)pos.Y); + PaletteReference.FromName("effect"), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index eede52a569..fccac9b1fd 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Effects public class Parachute : IEffect { readonly Animation anim; - readonly string palette; + readonly PaletteReference palette; readonly Animation paraAnim; readonly PPos location; @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { var pos = location.ToFloat2() - new float2(0, altitude); - yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, "shadow", 0); + yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, PaletteReference.FromName("shadow"), 0); yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2); yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3); } diff --git a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs index 96b568c3d3..9d9669f705 100644 --- a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs +++ b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs @@ -37,8 +37,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { if (!a.Destroyed && (a.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally)) - yield return new Renderable(anim.Image, - a.CenterLocation.ToFloat2() - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y); + yield return new Renderable(anim.Image, a.CenterLocation.ToFloat2() - .5f * anim.Image.size, + PaletteReference.FromName("chrome"), (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs index 1934e6f3e0..8fd86432eb 100644 --- a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs +++ b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(doors.Image, pos, "effect", (int)doorOffset.Y); + yield return new Renderable(doors.Image, pos, PaletteReference.FromName("effect"), (int)doorOffset.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Smoke.cs b/OpenRA.Mods.RA/Effects/Smoke.cs index e966e9b355..7a035a31e8 100644 --- a/OpenRA.Mods.RA/Effects/Smoke.cs +++ b/OpenRA.Mods.RA/Effects/Smoke.cs @@ -35,7 +35,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, "effect", (int)pos.Y); + yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, + PaletteReference.FromName("effect"), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index 4ef516e5d0..6be01f59dd 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -104,7 +104,8 @@ namespace OpenRA.Mods.RA.Effects var step = steps.Where(t => (to - (z + new float2(t[0],t[1]))).LengthSquared < (to - z).LengthSquared ) .OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First(); - rs.Add(new Renderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), "effect", (int)from.Y)); + rs.Add(new Renderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), + PaletteReference.FromName("effect"), (int)from.Y)); z += new float2(step[0], step[1]); if( rs.Count >= 1000 ) break; diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index a267df8ab9..7d5532d693 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -112,8 +112,8 @@ namespace OpenRA.Mods.RA RankAnim.Tick(); // HACK var bounds = self.Bounds.Value; - yield return new Renderable(RankAnim.Image, - new float2(bounds.Right - 6, bounds.Bottom - 8), "effect", self.CenterLocation.Y); + yield return new Renderable(RankAnim.Image, new float2(bounds.Right - 6, bounds.Bottom - 8), + PaletteReference.FromName("effect"), self.CenterLocation.Y); } } diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 8864ae20ae..f03fc5eb1b 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Orders { foreach (var r in Preview) r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, - wr.GetPaletteIndex(r.Palette), + r.Palette.RowIndex(wr), r.Scale*r.Sprite.size); var res = world.WorldActor.Trait(); diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index 1977b314d1..cb0caed50c 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Render var ret = a.WithPos(a.Pos - Info.Origin); yield return ret; if (disabled) - yield return ret.WithPalette("disabled").WithZOffset(1); + yield return ret.WithPalette(PaletteReference.FromName("disabled")).WithZOffset(1); } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index 83a1d1e738..d1f730dc51 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -34,7 +34,8 @@ namespace OpenRA.Mods.RA.Render var anim = new Animation(RenderSimple.GetImage(building), () => 0); anim.PlayRepeating("idle-top"); var rb = building.Traits.Get(); - yield return new Renderable(anim.Image, rb.Origin + 0.5f*anim.Image.size*(1 - Scale), p.First().Palette, 0, Scale); + yield return new Renderable(anim.Image, rb.Origin + 0.5f*anim.Image.size*(1 - Scale), + p.First().Palette, 0, Scale); } } diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index aead118204..8b229a95d9 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA.Render { foreach (var a in muzzleFlashes.Values) if (a.DisableFunc == null || !a.DisableFunc()) - yield return a.Image(self, "effect"); + yield return a.Image(self, PaletteReference.FromName("effect")); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/WithShadow.cs b/OpenRA.Mods.RA/Render/WithShadow.cs index 1419dd0d8a..c55472fb41 100644 --- a/OpenRA.Mods.RA/Render/WithShadow.cs +++ b/OpenRA.Mods.RA/Render/WithShadow.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Move; @@ -29,7 +30,7 @@ namespace OpenRA.Mods.RA.Render var visualOffset = ((move is Helicopter || move is Mobile) && move.Altitude > 0) ? Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0; - var shadowSprites = r.Select(a => a.WithPalette("shadow")); + var shadowSprites = r.Select(a => a.WithPalette(PaletteReference.FromName("shadow"))); var flyingSprites = (move.Altitude <= 0) ? r : r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude + visualOffset)).WithZOffset(move.Altitude + a.ZOffset)); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 2700551d8f..57fe38832f 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -245,7 +245,7 @@ namespace OpenRA.Mods.RA var targetCell = unit.Location + (xy - sourceLocation); foreach (var r in unit.Render()) r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), - wr.GetPaletteIndex(r.Palette), + r.Palette.RowIndex(wr), r.Scale*r.Sprite.size); } } From 95871e6cc1dbab271b5e1581a71ce2aaf4071210 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 11:31:41 +1300 Subject: [PATCH 15/67] Add a cache of PaletteReferences to WorldRenderer. I don't expect any perf improvements by using this cache, as you're simply moving the row lookup from render-time to fetch-time. However, this is a cleaner abstraction, and allows us to fail early if the palette doesn't exist. --- OpenRA.Game/Graphics/WorldRenderer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 1ce9ad5584..123b352639 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -50,6 +50,7 @@ namespace OpenRA.Graphics internal readonly TerrainRenderer terrainRenderer; internal readonly ShroudRenderer shroudRenderer; internal readonly HardwarePalette palette; + internal Cache palettes; internal WorldRenderer(World world) { @@ -60,8 +61,15 @@ namespace OpenRA.Graphics terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); + palettes = new Cache(CreatePaletteReference); } + PaletteReference CreatePaletteReference(string name) + { + return new PaletteReference(name, palette.GetPaletteIndex(name)); + } + + public PaletteReference Palette(string name) { return palettes[name]; } public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public Palette GetPalette(string name) { return palette.GetPalette(name); } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } From 885eec74440aef29492fb4f43e3847d6dc7e098a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 11:32:32 +1300 Subject: [PATCH 16/67] Move effects to WorldRenderer palette lookup. --- OpenRA.Game/Effects/DelayedAction.cs | 5 +++-- OpenRA.Game/Effects/FlashTarget.cs | 4 ++-- OpenRA.Game/Effects/IEffect.cs | 5 +++-- OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Mods.Cnc/Effects/IonCannon.cs | 4 ++-- OpenRA.Mods.RA/Effects/Bullet.cs | 8 ++++---- OpenRA.Mods.RA/Effects/CashTick.cs | 2 +- OpenRA.Mods.RA/Effects/Corpse.cs | 2 +- OpenRA.Mods.RA/Effects/CrateEffect.cs | 4 ++-- OpenRA.Mods.RA/Effects/Explosion.cs | 4 ++-- OpenRA.Mods.RA/Effects/GpsDot.cs | 2 +- OpenRA.Mods.RA/Effects/GpsSatellite.cs | 4 ++-- OpenRA.Mods.RA/Effects/GravityBomb.cs | 4 ++-- OpenRA.Mods.RA/Effects/InvulnEffect.cs | 4 ++-- OpenRA.Mods.RA/Effects/LaserZap.cs | 4 ++-- OpenRA.Mods.RA/Effects/Missile.cs | 4 ++-- OpenRA.Mods.RA/Effects/NukeLaunch.cs | 4 ++-- OpenRA.Mods.RA/Effects/Parachute.cs | 4 ++-- OpenRA.Mods.RA/Effects/PowerdownIndicator.cs | 4 ++-- OpenRA.Mods.RA/Effects/RallyPoint.cs | 2 +- OpenRA.Mods.RA/Effects/RepairIndicator.cs | 2 +- OpenRA.Mods.RA/Effects/SatelliteLaunch.cs | 4 ++-- OpenRA.Mods.RA/Effects/Smoke.cs | 4 ++-- OpenRA.Mods.RA/Effects/TeslaZap.cs | 2 +- 24 files changed, 45 insertions(+), 43 deletions(-) diff --git a/OpenRA.Game/Effects/DelayedAction.cs b/OpenRA.Game/Effects/DelayedAction.cs index 64603bc9bf..609af16c4a 100755 --- a/OpenRA.Game/Effects/DelayedAction.cs +++ b/OpenRA.Game/Effects/DelayedAction.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Effects @@ -25,12 +26,12 @@ namespace OpenRA.Effects this.delay = delay; } - public void Tick( World world ) + public void Tick(World world) { if (--delay <= 0) world.AddFrameEndTask(w => { w.Remove(this); a(); }); } - public IEnumerable Render() { yield break; } + public IEnumerable Render(WorldRenderer wr) { yield break; } } } diff --git a/OpenRA.Game/Effects/FlashTarget.cs b/OpenRA.Game/Effects/FlashTarget.cs index 9dd0de5b92..6e30ff9b39 100755 --- a/OpenRA.Game/Effects/FlashTarget.cs +++ b/OpenRA.Game/Effects/FlashTarget.cs @@ -33,14 +33,14 @@ namespace OpenRA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (!target.IsInWorld) yield break; if (remainingTicks % 2 == 0) foreach (var r in target.Render()) - yield return r.WithPalette(PaletteReference.FromName("highlight")); + yield return r.WithPalette(wr.Palette("highlight")); } } } diff --git a/OpenRA.Game/Effects/IEffect.cs b/OpenRA.Game/Effects/IEffect.cs index be2f2fb988..5bab9cfcf3 100755 --- a/OpenRA.Game/Effects/IEffect.cs +++ b/OpenRA.Game/Effects/IEffect.cs @@ -9,13 +9,14 @@ #endregion using System.Collections.Generic; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Effects { public interface IEffect { - void Tick( World world ); - IEnumerable Render(); + void Tick(World world); + IEnumerable Render(WorldRenderer r); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 123b352639..9e9dbbbb56 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -95,7 +95,7 @@ namespace OpenRA.Graphics var renderables = actors.SelectMany(a => a.Render()) .OrderBy(r => r, comparer); - var effects = world.Effects.SelectMany(e => e.Render()); + var effects = world.Effects.SelectMany(e => e.Render(this)); return renderables.Concat(effects); } diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index fd53a1dc20..df9ae17f00 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -32,11 +32,11 @@ namespace OpenRA.Mods.Cnc.Effects public void Tick(World world) { anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { yield return new Renderable(anim.Image, target.CenterLocation.ToFloat2() - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), - PaletteReference.FromName("effect"), (int)target.CenterLocation.Y); + wr.Palette("effect"), (int)target.CenterLocation.Y); } void Finish( World world ) diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index 56551c9430..7820e840ea 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -144,7 +144,7 @@ namespace OpenRA.Mods.RA.Effects const float height = .1f; - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (anim != null) { @@ -158,15 +158,15 @@ namespace OpenRA.Mods.RA.Effects if (Info.High || Info.Angle > 0) { if (Info.Shadow) - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, PaletteReference.FromName("shadow"), (int)pos.Y); + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, wr.Palette("shadow"), (int)pos.Y); var highPos = pos - new float2(0, GetAltitude()); - yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, PaletteReference.FromName("effect"), (int)pos.Y); + yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, wr.Palette("effect"), (int)pos.Y); } else yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, - PaletteReference.FromName(Args.weapon.Underwater ? "shadow" : "effect"), (int)pos.Y); + wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), (int)pos.Y); } } diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs index 8c2195da9a..976885945b 100644 --- a/OpenRA.Mods.RA/Effects/CashTick.cs +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Effects pos -= new PVecInt(0, velocity); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1); yield break; diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index ace3f0f235..a22670d0fb 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Effects public void Tick( World world ) { anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, (int)pos.Y); } diff --git a/OpenRA.Mods.RA/Effects/CrateEffect.cs b/OpenRA.Mods.RA/Effects/CrateEffect.cs index 48bca60799..61b70dd326 100644 --- a/OpenRA.Mods.RA/Effects/CrateEffect.cs +++ b/OpenRA.Mods.RA/Effects/CrateEffect.cs @@ -39,12 +39,12 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (a.IsInWorld) yield return new Renderable(anim.Image, a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, - PaletteReference.FromName("effect"), (int)a.CenterLocation.Y); + wr.Palette("effect"), (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Explosion.cs b/OpenRA.Mods.RA/Effects/Explosion.cs index 4ab7089ea3..942abb9a0a 100644 --- a/OpenRA.Mods.RA/Effects/Explosion.cs +++ b/OpenRA.Mods.RA/Effects/Explosion.cs @@ -32,11 +32,11 @@ namespace OpenRA.Mods.RA.Effects public void Tick( World world ) { anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude), - PaletteReference.FromName("effect"), (int)pos.Y - altitude); + wr.Palette("effect"), (int)pos.Y - altitude); } public Player Owner { get { return null; } } diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index 21f1413628..f6400ab2da 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA.Effects } } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (show && !self.Destroyed) { diff --git a/OpenRA.Mods.RA/Effects/GpsSatellite.cs b/OpenRA.Mods.RA/Effects/GpsSatellite.cs index 6dd3b331ff..be28c34cc5 100644 --- a/OpenRA.Mods.RA/Effects/GpsSatellite.cs +++ b/OpenRA.Mods.RA/Effects/GpsSatellite.cs @@ -36,9 +36,9 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image,offset, PaletteReference.FromName("effect"), (int)offset.Y); + yield return new Renderable(anim.Image,offset, wr.Palette("effect"), (int)offset.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/GravityBomb.cs b/OpenRA.Mods.RA/Effects/GravityBomb.cs index 0b4caf2e34..090c776995 100755 --- a/OpenRA.Mods.RA/Effects/GravityBomb.cs +++ b/OpenRA.Mods.RA/Effects/GravityBomb.cs @@ -51,10 +51,10 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { var pos = Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size; - yield return new Renderable(anim.Image, pos, PaletteReference.FromName("effect"), Args.dest.Y); + yield return new Renderable(anim.Image, pos, wr.Palette("effect"), Args.dest.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/InvulnEffect.cs b/OpenRA.Mods.RA/Effects/InvulnEffect.cs index ef5f431e14..953c0826b6 100644 --- a/OpenRA.Mods.RA/Effects/InvulnEffect.cs +++ b/OpenRA.Mods.RA/Effects/InvulnEffect.cs @@ -32,13 +32,13 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (a.Destroyed) // Tick will clean up yield break; foreach (var r in a.Render()) - yield return r.WithPalette(PaletteReference.FromName("invuln")); + yield return r.WithPalette(wr.Palette("invuln")); } } } diff --git a/OpenRA.Mods.RA/Effects/LaserZap.cs b/OpenRA.Mods.RA/Effects/LaserZap.cs index 6480aa30a3..de0589ebd1 100755 --- a/OpenRA.Mods.RA/Effects/LaserZap.cs +++ b/OpenRA.Mods.RA/Effects/LaserZap.cs @@ -74,11 +74,11 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (explosion != null) yield return new Renderable(explosion.Image, args.dest.ToFloat2() - .5f * explosion.Image.size, - PaletteReference.FromName("effect"), (int)args.dest.Y); + wr.Palette("effect"), (int)args.dest.Y); if (ticks >= info.BeamDuration) yield break; diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 7b0754b529..d273a087a9 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -152,11 +152,11 @@ namespace OpenRA.Mods.RA.Effects Combat.DoImpacts(Args); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (Args.firedBy.World.RenderedShroud.IsVisible(PxPosition.ToCPos())) yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), - PaletteReference.FromName(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y); + wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y); if (Trail != null) Trail.Render(Args.firedBy); diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index ed9e2a9631..8b52557bca 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -77,10 +77,10 @@ namespace OpenRA.Mods.RA.Effects a.Trait.Enable(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude), - PaletteReference.FromName("effect"), (int)pos.Y); + wr.Palette("effect"), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index fccac9b1fd..45772abb15 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -73,10 +73,10 @@ namespace OpenRA.Mods.RA.Effects }); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { var pos = location.ToFloat2() - new float2(0, altitude); - yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, PaletteReference.FromName("shadow"), 0); + yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, wr.Palette("shadow"), 0); yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2); yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3); } diff --git a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs index 9d9669f705..1605d9dfcd 100644 --- a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs +++ b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs @@ -34,11 +34,11 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (!a.Destroyed && (a.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally)) yield return new Renderable(anim.Image, a.CenterLocation.ToFloat2() - .5f * anim.Image.size, - PaletteReference.FromName("chrome"), (int)a.CenterLocation.Y); + wr.Palette("chrome"), (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/RallyPoint.cs b/OpenRA.Mods.RA/Effects/RallyPoint.cs index bedd9a904e..2ff23f5fcf 100755 --- a/OpenRA.Mods.RA/Effects/RallyPoint.cs +++ b/OpenRA.Mods.RA/Effects/RallyPoint.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (building.IsInWorld && building.Owner == building.World.LocalPlayer && building.World.Selection.Actors.Contains(building)) diff --git a/OpenRA.Mods.RA/Effects/RepairIndicator.cs b/OpenRA.Mods.RA/Effects/RepairIndicator.cs index e710e92534..1089dd8450 100755 --- a/OpenRA.Mods.RA/Effects/RepairIndicator.cs +++ b/OpenRA.Mods.RA/Effects/RepairIndicator.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { if (!building.Destroyed) { diff --git a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs index 8fd86432eb..047f27e5ba 100644 --- a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs +++ b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs @@ -40,9 +40,9 @@ namespace OpenRA.Mods.RA.Effects } } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(doors.Image, pos, PaletteReference.FromName("effect"), (int)doorOffset.Y); + yield return new Renderable(doors.Image, pos, wr.Palette("effect"), (int)doorOffset.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Smoke.cs b/OpenRA.Mods.RA/Effects/Smoke.cs index 7a035a31e8..f82f963296 100644 --- a/OpenRA.Mods.RA/Effects/Smoke.cs +++ b/OpenRA.Mods.RA/Effects/Smoke.cs @@ -33,10 +33,10 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render() + public IEnumerable Render(WorldRenderer wr) { yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, - PaletteReference.FromName("effect"), (int)pos.Y); + wr.Palette("effect"), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index 6be01f59dd..39b3c64c79 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Effects } } - public IEnumerable Render() { return renderables; } + public IEnumerable Render(WorldRenderer wr) { return renderables; } static IEnumerable DrawZapWandering(PPos from, PPos to, Sequence s) { From 48d713aafd7d379503dbd0226f221bf539b8e08a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 11:42:32 +1300 Subject: [PATCH 17/67] Pass a PaletteReference to RenderPreview. --- OpenRA.Game/Traits/Render/RenderSimple.cs | 6 ++---- OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs | 7 ++++--- OpenRA.Mods.RA/Render/RenderBuilding.cs | 4 ++-- OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs | 10 +++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 3e8096e3c0..3ada42970c 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -23,14 +23,12 @@ namespace OpenRA.Traits public virtual object Create(ActorInitializer init) { return new RenderSimple(init.self); } - public virtual IEnumerable RenderPreview(ActorInfo building, Player owner) + public virtual IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) { var anim = new Animation(RenderSimple.GetImage(building), () => 0); anim.PlayRepeating("idle"); - var pal = Palette ?? (owner != null ? PlayerPalette + owner.InternalName : null); - yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), - PaletteReference.FromName(pal), 0, Scale); + yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), pr, 0, Scale); } } diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index f03fc5eb1b..031e0d8c57 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -30,10 +30,11 @@ namespace OpenRA.Mods.RA.Orders Producer = producer; Building = name; BuildingInfo = Rules.Info[Building].Traits.Get(); + var rbi = Rules.Info[Building].Traits.Get(); + var pr = PaletteReference.FromName(rbi.Palette ?? (producer.Owner != null ? + rbi.PlayerPalette + producer.Owner.InternalName : null)); - Preview = Rules.Info[Building].Traits.Get() - .RenderPreview(Rules.Info[Building], producer.Owner); - + Preview = rbi.RenderPreview(Rules.Info[Building], pr); buildOk = SequenceProvider.GetSequence("overlay", "build-valid").GetSprite(0); buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0); } diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index cb0caed50c..9b7d5c8e41 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -25,9 +25,9 @@ namespace OpenRA.Mods.RA.Render public readonly float2 Origin = float2.Zero; public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);} - public override IEnumerable RenderPreview(ActorInfo building, Player owner) + public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) { - return base.RenderPreview(building, owner) + return base.RenderPreview(building, pr) .Select(a => a.WithPos(a.Pos + building.Traits.Get().Origin)); } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index d1f730dc51..aba2eb45cb 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -20,14 +20,14 @@ namespace OpenRA.Mods.RA.Render public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); } /* get around unverifiability */ - IEnumerable BaseBuildingPreview(ActorInfo building, Player owner) + IEnumerable BaseBuildingPreview(ActorInfo building, PaletteReference pr) { - return base.RenderPreview(building, owner); + return base.RenderPreview(building, pr); } - public override IEnumerable RenderPreview(ActorInfo building, Player owner) + public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) { - var p = BaseBuildingPreview(building, owner); + var p = BaseBuildingPreview(building, pr); foreach (var r in p) yield return r; @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render anim.PlayRepeating("idle-top"); var rb = building.Traits.Get(); yield return new Renderable(anim.Image, rb.Origin + 0.5f*anim.Image.size*(1 - Scale), - p.First().Palette, 0, Scale); + pr, 0, Scale); } } From 000a5eaa56a19b0f99be4d3240a8cd56c10931be Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 12:15:28 +1300 Subject: [PATCH 18/67] Pass WorldRenderer to IRenderModifiers and replace more palette lookups. --- OpenRA.Game/Actor.cs | 11 ++++++----- OpenRA.Game/Effects/FlashTarget.cs | 2 +- OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Mods.Cnc/RenderCargo.cs | 5 +++-- OpenRA.Mods.RA/BelowUnits.cs | 3 ++- OpenRA.Mods.RA/Cloak.cs | 6 +++--- OpenRA.Mods.RA/Effects/InvulnEffect.cs | 2 +- OpenRA.Mods.RA/GainsExperience.cs | 14 +++++++------- OpenRA.Mods.RA/InvisibleToEnemy.cs | 3 ++- OpenRA.Mods.RA/Missions/Allies04Script.cs | 3 ++- OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs | 3 ++- OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs | 3 ++- OpenRA.Mods.RA/Render/RenderBuilding.cs | 4 ++-- OpenRA.Mods.RA/Render/RenderSpy.cs | 3 ++- OpenRA.Mods.RA/Render/WithShadow.cs | 4 ++-- OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs | 2 +- 17 files changed, 40 insertions(+), 32 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 3eea3d1ed0..f431ad149a 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.FileFormats; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA @@ -98,7 +99,7 @@ namespace OpenRA } ApplyIRender = x => x.Render(this); - ApplyRenderModifier = (m, p) => p.ModifyRender(this, m); + ApplyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m); Bounds = Cached.New( () => CalculateBounds(false) ); ExtendedBounds = Cached.New( () => CalculateBounds(true) ); @@ -109,7 +110,7 @@ namespace OpenRA Bounds.Invalidate(); ExtendedBounds.Invalidate(); - currentActivity = Util.RunActivity( this, currentActivity ); + currentActivity = Traits.Util.RunActivity( this, currentActivity ); } public void UpdateSight() @@ -126,12 +127,12 @@ namespace OpenRA // note: these delegates are cached to avoid massive allocation. Func> ApplyIRender; - Func, IRenderModifier, IEnumerable> ApplyRenderModifier; - public IEnumerable Render() + Func, IRenderModifier, WorldRenderer, IEnumerable> ApplyRenderModifier; + public IEnumerable Render(WorldRenderer wr) { var mods = TraitsImplementing(); var sprites = TraitsImplementing().SelectMany(ApplyIRender); - return mods.Aggregate(sprites, ApplyRenderModifier); + return mods.Aggregate(sprites, (m,p) => ApplyRenderModifier(m,p,wr)); } // When useAltitude = true, the bounding box is extended diff --git a/OpenRA.Game/Effects/FlashTarget.cs b/OpenRA.Game/Effects/FlashTarget.cs index 6e30ff9b39..c8c422d791 100755 --- a/OpenRA.Game/Effects/FlashTarget.cs +++ b/OpenRA.Game/Effects/FlashTarget.cs @@ -39,7 +39,7 @@ namespace OpenRA.Effects yield break; if (remainingTicks % 2 == 0) - foreach (var r in target.Render()) + foreach (var r in target.Render(wr)) yield return r.WithPalette(wr.Palette("highlight")); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 9e9dbbbb56..594ac3562b 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -92,7 +92,7 @@ namespace OpenRA.Graphics bounds.BottomRightAsCPos().ToPPos() ); - var renderables = actors.SelectMany(a => a.Render()) + var renderables = actors.SelectMany(a => a.Render(this)) .OrderBy(r => r, comparer); var effects = world.Effects.SelectMany(e => e.Render(this)); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 41fb0835d1..2b100763a3 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -113,7 +113,7 @@ namespace OpenRA.Traits } public interface INotifyAttack { void Attacking(Actor self, Target target); } - public interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } + public interface IRenderModifier { IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r); } public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } public interface ISpeedModifier { decimal GetSpeedModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); } diff --git a/OpenRA.Mods.Cnc/RenderCargo.cs b/OpenRA.Mods.Cnc/RenderCargo.cs index 9e5101f41b..86b96d7e0b 100644 --- a/OpenRA.Mods.Cnc/RenderCargo.cs +++ b/OpenRA.Mods.Cnc/RenderCargo.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.RA; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.Cnc @@ -39,7 +40,7 @@ namespace OpenRA.Mods.Cnc Info = info; } - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { foreach (var c in cargo.Passengers) { @@ -55,7 +56,7 @@ namespace OpenRA.Mods.Cnc Info.PassengerTypes.Contains(p.Trait().info.CargoType)) : cargo.Passengers; - return r.Concat(visiblePassengers.SelectMany(a => a.Render()) + return r.Concat(visiblePassengers.SelectMany(a => a.Render(wr)) .Select(a => a.WithPos(a.Pos - new float2(0, Info.RelativeAltitude)) .WithZOffset(a.ZOffset + Info.RelativeAltitude))); } diff --git a/OpenRA.Mods.RA/BelowUnits.cs b/OpenRA.Mods.RA/BelowUnits.cs index c6336de911..4795bd7f0c 100644 --- a/OpenRA.Mods.RA/BelowUnits.cs +++ b/OpenRA.Mods.RA/BelowUnits.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -18,7 +19,7 @@ namespace OpenRA.Mods.RA class BelowUnits : IRenderModifier { - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return r.Select(a => a.WithZOffset((int) -a.Sprite.size.Y)); } diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index 84ebf54a6c..5a9e320db1 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -68,13 +68,13 @@ namespace OpenRA.Mods.RA static readonly Renderable[] Nothing = { }; - public IEnumerable ModifyRender(Actor self, IEnumerable rs) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { if (remainingTime > 0) - return rs; + return r; if (Cloaked && IsVisible(self)) - return rs.Select(a => a.WithPalette(PaletteReference.FromName(info.Palette))); + return r.Select(a => a.WithPalette(wr.Palette(info.Palette))); else return Nothing; } diff --git a/OpenRA.Mods.RA/Effects/InvulnEffect.cs b/OpenRA.Mods.RA/Effects/InvulnEffect.cs index 953c0826b6..d16dd233a9 100644 --- a/OpenRA.Mods.RA/Effects/InvulnEffect.cs +++ b/OpenRA.Mods.RA/Effects/InvulnEffect.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Effects if (a.Destroyed) // Tick will clean up yield break; - foreach (var r in a.Render()) + foreach (var r in a.Render(wr)) yield return r.WithPalette(wr.Palette("invuln")); } } diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index 7d5532d693..022c78c208 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -97,23 +97,23 @@ namespace OpenRA.Mods.RA return Level > 0 ? Info.SpeedModifier[Level - 1] : 1m; } - public IEnumerable ModifyRender(Actor self, IEnumerable rs) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { if (self.Owner == self.World.LocalPlayer && Level > 0) - return InnerModifyRender(self, rs); + return InnerModifyRender(self, wr, r); else - return rs; + return r; } - IEnumerable InnerModifyRender(Actor self, IEnumerable rs) + IEnumerable InnerModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { - foreach (var r in rs) - yield return r; + foreach (var rs in r) + yield return rs; RankAnim.Tick(); // HACK var bounds = self.Bounds.Value; yield return new Renderable(RankAnim.Image, new float2(bounds.Right - 6, bounds.Bottom - 8), - PaletteReference.FromName("effect"), self.CenterLocation.Y); + wr.Palette("effect"), self.CenterLocation.Y); } } diff --git a/OpenRA.Mods.RA/InvisibleToEnemy.cs b/OpenRA.Mods.RA/InvisibleToEnemy.cs index e3ff497308..248f7d7cd9 100644 --- a/OpenRA.Mods.RA/InvisibleToEnemy.cs +++ b/OpenRA.Mods.RA/InvisibleToEnemy.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Drawing; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -32,7 +33,7 @@ namespace OpenRA.Mods.RA static readonly Renderable[] Nothing = { }; - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return IsVisible(self.Owner.Shroud, self) ? r : Nothing; } diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 4eaa1d8dea..739ae8b7c2 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Render; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Widgets; @@ -505,7 +506,7 @@ namespace OpenRA.Mods.RA.Missions hijackable = self.Trait(); } - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return r.Select(a => a.WithPalette(Palette(hijackable.OldOwner))); } diff --git a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs index 9354c46672..c4f823be48 100644 --- a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -24,7 +25,7 @@ namespace OpenRA.Mods.RA } Renderable[] cache = { }; - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { if (IsVisible(self.World.RenderedShroud, self)) cache = r.ToArray(); diff --git a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs index 865cf7effb..cba548f4e4 100644 --- a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -24,7 +25,7 @@ namespace OpenRA.Mods.RA } static Renderable[] Nothing = { }; - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return IsVisible(self.World.RenderedShroud, self) ? r : Nothing; } diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index 9b7d5c8e41..ce7711bd7c 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Render self.QueueActivity(new CallFunc(() => Complete(self))); } - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { var disabled = self.IsDisabled(); foreach (var a in r) @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Render var ret = a.WithPos(a.Pos - Info.Origin); yield return ret; if (disabled) - yield return ret.WithPalette(PaletteReference.FromName("disabled")).WithZOffset(1); + yield return ret.WithPalette(wr.Palette("disabled")).WithZOffset(1); } } diff --git a/OpenRA.Mods.RA/Render/RenderSpy.cs b/OpenRA.Mods.RA/Render/RenderSpy.cs index 80a571ae08..b281ac304e 100755 --- a/OpenRA.Mods.RA/Render/RenderSpy.cs +++ b/OpenRA.Mods.RA/Render/RenderSpy.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Mods.RA.Orders; @@ -31,7 +32,7 @@ namespace OpenRA.Mods.RA.Render disguisedAsSprite = spy.disguisedAsSprite; } - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return spy.disguisedAsPlayer != null ? r.Select(a => a.WithPalette(Palette(spy.disguisedAsPlayer))) : r; } diff --git a/OpenRA.Mods.RA/Render/WithShadow.cs b/OpenRA.Mods.RA/Render/WithShadow.cs index c55472fb41..76ddf84515 100644 --- a/OpenRA.Mods.RA/Render/WithShadow.cs +++ b/OpenRA.Mods.RA/Render/WithShadow.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render class WithShadow : IRenderModifier { - public IEnumerable ModifyRender(Actor self, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { var move = self.Trait(); @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render var visualOffset = ((move is Helicopter || move is Mobile) && move.Altitude > 0) ? Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0; - var shadowSprites = r.Select(a => a.WithPalette(PaletteReference.FromName("shadow"))); + var shadowSprites = r.Select(a => a.WithPalette(wr.Palette("shadow"))); var flyingSprites = (move.Altitude <= 0) ? r : r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude + visualOffset)).WithZOffset(move.Altitude + a.ZOffset)); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 57fe38832f..5875c93a51 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -243,7 +243,7 @@ namespace OpenRA.Mods.RA { if (manager.self.Owner.Shroud.IsTargetable(unit)) { var targetCell = unit.Location + (xy - sourceLocation); - foreach (var r in unit.Render()) + foreach (var r in unit.Render(wr)) r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), r.Palette.RowIndex(wr), r.Scale*r.Sprite.size); From 0703f3f164e225a7bf2eeda797c6390901e07060 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 13:11:43 +1300 Subject: [PATCH 19/67] Extract auto-selection-size into its own interface. --- OpenRA.Game/Actor.cs | 14 +++++--------- OpenRA.Game/Traits/Render/RenderSimple.cs | 11 ++++++++++- OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index f431ad149a..f61623c4da 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -74,7 +74,7 @@ namespace OpenRA AddTrait(trait.Create(init)); } - Move = Lazy.New( () => TraitOrDefault() ); + Move = Lazy.New(() => TraitOrDefault()); Size = Lazy.New(() => { @@ -82,27 +82,23 @@ namespace OpenRA if (si != null && si.Bounds != null) return new int2(si.Bounds[0], si.Bounds[1]); - // auto size from render - var firstSprite = TraitsImplementing().SelectMany(ApplyIRender).FirstOrDefault(); - if (firstSprite.Sprite == null) return int2.Zero; - return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2(); + return TraitsImplementing().Select(x => x.SelectionSize(this)).FirstOrDefault(); }); - if(this.HasTrait()) + if (this.HasTrait()) { Sight = new Shroud.ActorVisibility { range = this.Trait().RevealRange, vis = Shroud.GetVisOrigins(this).ToArray() }; - } ApplyIRender = x => x.Render(this); ApplyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m); - Bounds = Cached.New( () => CalculateBounds(false) ); - ExtendedBounds = Cached.New( () => CalculateBounds(true) ); + Bounds = Cached.New(() => CalculateBounds(false)); + ExtendedBounds = Cached.New(() => CalculateBounds(true)); } public void Tick() diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 3ada42970c..28cdff3aee 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Graphics; namespace OpenRA.Traits @@ -32,7 +33,7 @@ namespace OpenRA.Traits } } - public class RenderSimple : IRender, ITick + public class RenderSimple : IRender, IAutoSelectionSize, ITick { public Dictionary anims = new Dictionary(); @@ -94,6 +95,14 @@ namespace OpenRA.Traits } } + public int2 SelectionSize(Actor self) + { + return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc()) + && b.Animation.CurrentSequence != null) + .Select(a => (a.Animation.Image.size*Info.Scale).ToInt2()) + .FirstOrDefault(); + } + public virtual void Tick(Actor self) { foreach (var a in anims.Values) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 2b100763a3..06ed8b92aa 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -35,6 +35,7 @@ namespace OpenRA.Traits public interface ITick { void Tick(Actor self); } public interface IRender { IEnumerable Render(Actor self); } + public interface IAutoSelectionSize { int2 SelectionSize(Actor self); } public interface IIssueOrder { From d6fcaafd785509ea370c4784b384f152fe8a4c20 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:00:25 +1300 Subject: [PATCH 20/67] Let parachute cargo render themselves. This allows for tanks and other multi-sprite actors to render correctly while dropping. --- OpenRA.Mods.RA/Air/EjectOnDeath.cs | 6 ++---- OpenRA.Mods.RA/Effects/Parachute.cs | 31 ++++++++++++----------------- OpenRA.Mods.RA/ParaDrop.cs | 6 ++---- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/OpenRA.Mods.RA/Air/EjectOnDeath.cs b/OpenRA.Mods.RA/Air/EjectOnDeath.cs index 20463555c9..d1ed8c28da 100644 --- a/OpenRA.Mods.RA/Air/EjectOnDeath.cs +++ b/OpenRA.Mods.RA/Air/EjectOnDeath.cs @@ -35,10 +35,8 @@ namespace OpenRA.Mods.RA if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10 && self.Owner.WinState != WinState.Lost) { - self.World.AddFrameEndTask(w => w.Add( - new Parachute(pilot.Owner, - Util.CenterOfCell(self.CenterLocation.ToCPos()), - aircraft.Altitude, pilot))); + self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, + Util.CenterOfCell(self.CenterLocation.ToCPos()), aircraft.Altitude))); Sound.Play(info.ChuteSound, self.CenterLocation); } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 45772abb15..9fdb71b549 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Effects; using OpenRA.Graphics; using OpenRA.Traits; @@ -17,8 +18,6 @@ namespace OpenRA.Mods.RA.Effects { public class Parachute : IEffect { - readonly Animation anim; - readonly PaletteReference palette; readonly Animation paraAnim; readonly PPos location; @@ -28,29 +27,19 @@ namespace OpenRA.Mods.RA.Effects float altitude; const float fallRate = .3f; - public Parachute(Player owner, PPos location, int altitude, Actor cargo) + public Parachute(Actor cargo, PPos location, int altitude) { this.location = location; this.altitude = altitude; this.cargo = cargo; - var rs = cargo.Trait(); - var image = rs.anim.Name; - palette = rs.Palette(owner); - - anim = new Animation(image); - if (anim.HasSequence("idle")) - anim.PlayFetchIndex("idle", () => 0); - else - anim.PlayFetchIndex("stand", () => 0); - anim.Tick(); - var pai = cargo.Info.Traits.GetOrDefault(); - paraAnim = new Animation(pai != null ? pai.ParachuteSprite : "parach"); paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle")); if (pai != null) offset = pai.Offset; + + cargo.Trait().SetPxPosition(cargo, location); } public void Tick(World world) @@ -75,10 +64,16 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render(WorldRenderer wr) { + var rc = cargo.Render(wr).Select(a => a.WithPos(a.Pos - new float2(0, altitude)) + .WithZOffset(a.ZOffset + (int)altitude)); + foreach (var c in rc) + { + yield return c.WithPos(location.ToFloat2() - .5f * c.Sprite.size).WithPalette(wr.Palette("shadow")).WithZOffset(0); + yield return c.WithZOffset(2); + } + var pos = location.ToFloat2() - new float2(0, altitude); - yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, wr.Palette("shadow"), 0); - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2); - yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3); + yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, rc.First().Palette, 3); } } } diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 1759c12cab..07788b529a 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -55,11 +55,9 @@ namespace OpenRA.Mods.RA var aircraft = self.Trait(); self.World.AddFrameEndTask(w => w.Add( - new Parachute( - self.Owner, + new Parachute(a, Util.CenterOfCell(self.CenterLocation.ToCPos()), - aircraft.Altitude, a - ) + aircraft.Altitude) )); Sound.Play(info.ChuteSound, self.CenterLocation); From 3380817865fd178c3daf0f4fb0d655263e1086de Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:17:41 +1300 Subject: [PATCH 21/67] Pass WorldRenderer to Render(). --- OpenRA.Game/Actor.cs | 8 ++++---- OpenRA.Game/Traits/Render/RenderSimple.cs | 8 ++++---- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Mods.RA/Effects/Corpse.cs | 9 +++++---- OpenRA.Mods.RA/Effects/GpsDot.cs | 2 +- OpenRA.Mods.RA/Effects/RallyPoint.cs | 4 +++- OpenRA.Mods.RA/Effects/RepairIndicator.cs | 6 +++--- OpenRA.Mods.RA/Missions/Allies04Script.cs | 2 +- OpenRA.Mods.RA/Render/RenderEditorOnly.cs | 3 ++- OpenRA.Mods.RA/Render/RenderSpy.cs | 2 +- OpenRA.Mods.RA/Render/WithMuzzleFlash.cs | 4 ++-- 11 files changed, 27 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index f61623c4da..47232401ee 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -93,8 +93,8 @@ namespace OpenRA vis = Shroud.GetVisOrigins(this).ToArray() }; } - - ApplyIRender = x => x.Render(this); + + ApplyIRender = (x, wr) => x.Render(this, wr); ApplyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m); Bounds = Cached.New(() => CalculateBounds(false)); @@ -122,12 +122,12 @@ namespace OpenRA OpenRA.FileFormats.Lazy Size; // note: these delegates are cached to avoid massive allocation. - Func> ApplyIRender; + Func> ApplyIRender; Func, IRenderModifier, WorldRenderer, IEnumerable> ApplyRenderModifier; public IEnumerable Render(WorldRenderer wr) { var mods = TraitsImplementing(); - var sprites = TraitsImplementing().SelectMany(ApplyIRender); + var sprites = TraitsImplementing().SelectMany(x => ApplyIRender(x, wr)); return mods.Aggregate(sprites, (m,p) => ApplyRenderModifier(m,p,wr)); } diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 28cdff3aee..a3ab0ef66e 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -78,17 +78,17 @@ namespace OpenRA.Traits anim.PlayRepeating("idle"); } - public PaletteReference Palette(Player p) + public PaletteReference Palette(Player p, WorldRenderer wr) { - return PaletteReference.FromName(Info.Palette ?? Info.PlayerPalette + p.InternalName); + return wr.Palette(Info.Palette ?? Info.PlayerPalette + p.InternalName); } - public virtual IEnumerable Render(Actor self) + public virtual IEnumerable Render(Actor self, WorldRenderer wr) { foreach (var a in anims.Values) if (a.DisableFunc == null || !a.DisableFunc()) { - Renderable ret = a.Image(self, Palette(self.Owner)); + Renderable ret = a.Image(self, Palette(self.Owner, wr)); if (Info.Scale != 1f) ret = ret.WithScale(Info.Scale).WithPos(ret.Pos + 0.5f * ret.Sprite.size * (1 - Info.Scale)); yield return ret; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 06ed8b92aa..feadbb2ab3 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -34,7 +34,7 @@ namespace OpenRA.Traits } public interface ITick { void Tick(Actor self); } - public interface IRender { IEnumerable Render(Actor self); } + public interface IRender { IEnumerable Render(Actor self, WorldRenderer wr); } public interface IAutoSelectionSize { int2 SelectionSize(Actor self); } public interface IIssueOrder diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index a22670d0fb..e7103f97a2 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -19,12 +19,13 @@ namespace OpenRA.Mods.RA.Effects { readonly Animation anim; readonly float2 pos; - readonly PaletteReference palette; + readonly RenderSimple rs; + readonly Player p; public Corpse(Actor fromActor, string sequence) { - var rs = fromActor.Trait(); - palette = rs.Palette(fromActor.Owner); + p = fromActor.Owner; + rs = fromActor.Trait(); anim = new Animation(rs.GetImage(fromActor)); anim.PlayThen(sequence, () => fromActor.World.AddFrameEndTask(w => w.Remove(this))); @@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, (int)pos.Y); + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, rs.Palette(p, wr), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index f6400ab2da..5517341fd4 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Effects if (show && !self.Destroyed) { var p = self.CenterLocation; - yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y) + yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner, wr), p.Y) .WithScale(1.5f); } } diff --git a/OpenRA.Mods.RA/Effects/RallyPoint.cs b/OpenRA.Mods.RA/Effects/RallyPoint.cs index 2ff23f5fcf..8c8b56d254 100755 --- a/OpenRA.Mods.RA/Effects/RallyPoint.cs +++ b/OpenRA.Mods.RA/Effects/RallyPoint.cs @@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA.Effects { readonly Actor building; readonly RA.RallyPoint rp; + readonly RenderSimple rs; public Animation flag = new Animation("rallypoint"); public Animation circles = new Animation("rallypoint"); @@ -27,6 +28,7 @@ namespace OpenRA.Mods.RA.Effects { this.building = building; rp = building.Trait(); + rs = building.Trait(); flag.PlayRepeating("flag"); circles.Play("circles"); } @@ -52,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects && building.World.Selection.Actors.Contains(building)) { var pos = Traits.Util.CenterOfCell(rp.rallyPoint); - var palette = building.Trait().Palette(building.Owner); + var palette = rs.Palette(building.Owner, wr); yield return new Renderable(circles.Image, pos.ToFloat2() - .5f * circles.Image.size, diff --git a/OpenRA.Mods.RA/Effects/RepairIndicator.cs b/OpenRA.Mods.RA/Effects/RepairIndicator.cs index 1089dd8450..346beca3f5 100755 --- a/OpenRA.Mods.RA/Effects/RepairIndicator.cs +++ b/OpenRA.Mods.RA/Effects/RepairIndicator.cs @@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA.Effects { Actor building; Player player; + RenderSimple rs; Animation anim = new Animation("allyrepair"); public RepairIndicator(Actor building, Player player) @@ -27,6 +28,7 @@ namespace OpenRA.Mods.RA.Effects this.building = building; this.player = player; anim.PlayRepeating("repair"); + rs = building.Trait(); } public void Tick(World world) @@ -44,10 +46,8 @@ namespace OpenRA.Mods.RA.Effects { if (!building.Destroyed) { - var palette = building.Trait().Palette(player); - yield return new Renderable(anim.Image, - building.CenterLocation.ToFloat2() - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y); + building.CenterLocation.ToFloat2() - .5f * anim.Image.size, rs.Palette(player, wr), (int)building.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 739ae8b7c2..2b89f9194d 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -508,7 +508,7 @@ namespace OpenRA.Mods.RA.Missions public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { - return r.Select(a => a.WithPalette(Palette(hijackable.OldOwner))); + return r.Select(a => a.WithPalette(Palette(hijackable.OldOwner, wr))); } } diff --git a/OpenRA.Mods.RA/Render/RenderEditorOnly.cs b/OpenRA.Mods.RA/Render/RenderEditorOnly.cs index 9339f58d4c..4f2825fb8a 100644 --- a/OpenRA.Mods.RA/Render/RenderEditorOnly.cs +++ b/OpenRA.Mods.RA/Render/RenderEditorOnly.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA.Render @@ -23,6 +24,6 @@ namespace OpenRA.Mods.RA.Render public RenderEditorOnly(Actor self) : base(self, () => 0) { } static readonly Renderable[] Nothing = { }; - public override IEnumerable Render(Actor self) { return Nothing; } + public override IEnumerable Render(Actor self, WorldRenderer wr) { return Nothing; } } } diff --git a/OpenRA.Mods.RA/Render/RenderSpy.cs b/OpenRA.Mods.RA/Render/RenderSpy.cs index b281ac304e..2d5d6dab23 100755 --- a/OpenRA.Mods.RA/Render/RenderSpy.cs +++ b/OpenRA.Mods.RA/Render/RenderSpy.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { - return spy.disguisedAsPlayer != null ? r.Select(a => a.WithPalette(Palette(spy.disguisedAsPlayer))) : r; + return spy.disguisedAsPlayer != null ? r.Select(a => a.WithPalette(Palette(spy.disguisedAsPlayer, wr))) : r; } public override void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index 8b229a95d9..084b48156f 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -57,11 +57,11 @@ namespace OpenRA.Mods.RA.Render mf.Animation.PlayThen("muzzle", () => isShowing = false); } - public IEnumerable Render(Actor self) + public IEnumerable Render(Actor self, WorldRenderer wr) { foreach (var a in muzzleFlashes.Values) if (a.DisableFunc == null || !a.DisableFunc()) - yield return a.Image(self, PaletteReference.FromName("effect")); + yield return a.Image(self, wr.Palette("effect")); } public void Tick(Actor self) From 43159a0e05aa2cab52df90662ffeca2b97e8a892 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:30:44 +1300 Subject: [PATCH 22/67] Remove RepairIndicator dependence on target RenderSimple. This also fixes the case where the building palette doesn't match the indicator, and saves 2 trait lookups per tick. --- OpenRA.Mods.RA/Buildings/RepairableBuilding.cs | 3 ++- OpenRA.Mods.RA/Effects/RepairIndicator.cs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/RepairableBuilding.cs b/OpenRA.Mods.RA/Buildings/RepairableBuilding.cs index 1ddfc42628..67b1095630 100755 --- a/OpenRA.Mods.RA/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.RA/Buildings/RepairableBuilding.cs @@ -19,6 +19,7 @@ namespace OpenRA.Mods.RA.Buildings public readonly int RepairPercent = 20; public readonly int RepairInterval = 24; public readonly int RepairStep = 7; + public readonly string IndicatorPalettePrefix = "player"; public object Create(ActorInitializer init) { return new RepairableBuilding(init.self, this); } } @@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Buildings Sound.PlayNotification(Repairer, "Speech", "Repairing", self.Owner.Country.Race); self.World.AddFrameEndTask( - w => w.Add(new RepairIndicator(self, p))); + w => w.Add(new RepairIndicator(self, Info.IndicatorPalettePrefix, p))); } } } diff --git a/OpenRA.Mods.RA/Effects/RepairIndicator.cs b/OpenRA.Mods.RA/Effects/RepairIndicator.cs index 346beca3f5..302e07f991 100755 --- a/OpenRA.Mods.RA/Effects/RepairIndicator.cs +++ b/OpenRA.Mods.RA/Effects/RepairIndicator.cs @@ -20,23 +20,23 @@ namespace OpenRA.Mods.RA.Effects { Actor building; Player player; - RenderSimple rs; + string palettePrefix; Animation anim = new Animation("allyrepair"); + RepairableBuilding rb; - public RepairIndicator(Actor building, Player player) + public RepairIndicator(Actor building, string palettePrefix, Player player) { this.building = building; this.player = player; + this.palettePrefix = palettePrefix; + rb = building.Trait(); anim.PlayRepeating("repair"); - rs = building.Trait(); } public void Tick(World world) { - if (!building.IsInWorld || - building.IsDead() || - building.Trait().Repairer == null || - building.Trait().Repairer != player) + if (!building.IsInWorld || building.IsDead() || + rb.Repairer == null || rb.Repairer != player) world.AddFrameEndTask(w => w.Remove(this)); anim.Tick(); @@ -47,7 +47,8 @@ namespace OpenRA.Mods.RA.Effects if (!building.Destroyed) { yield return new Renderable(anim.Image, - building.CenterLocation.ToFloat2() - .5f * anim.Image.size, rs.Palette(player, wr), (int)building.CenterLocation.Y); + building.CenterLocation.ToFloat2() - .5f * anim.Image.size, + wr.Palette(palettePrefix+player.InternalName), (int)building.CenterLocation.Y); } } } From 5a4bd14835e32aded0728edfcbd1b681306a808d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:37:28 +1300 Subject: [PATCH 23/67] Ditto for RallyPoint. --- OpenRA.Mods.RA/Effects/RallyPoint.cs | 8 ++++---- OpenRA.Mods.RA/RallyPoint.cs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.RA/Effects/RallyPoint.cs b/OpenRA.Mods.RA/Effects/RallyPoint.cs index 8c8b56d254..555d597bd6 100755 --- a/OpenRA.Mods.RA/Effects/RallyPoint.cs +++ b/OpenRA.Mods.RA/Effects/RallyPoint.cs @@ -20,15 +20,15 @@ namespace OpenRA.Mods.RA.Effects { readonly Actor building; readonly RA.RallyPoint rp; - readonly RenderSimple rs; + readonly string palettePrefix; public Animation flag = new Animation("rallypoint"); public Animation circles = new Animation("rallypoint"); - public RallyPoint(Actor building) + public RallyPoint(Actor building, string palettePrefix) { this.building = building; rp = building.Trait(); - rs = building.Trait(); + this.palettePrefix = palettePrefix; flag.PlayRepeating("flag"); circles.Play("circles"); } @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects && building.World.Selection.Actors.Contains(building)) { var pos = Traits.Util.CenterOfCell(rp.rallyPoint); - var palette = rs.Palette(building.Owner, wr); + var palette = wr.Palette(palettePrefix+building.Owner.InternalName); yield return new Renderable(circles.Image, pos.ToFloat2() - .5f * circles.Image.size, diff --git a/OpenRA.Mods.RA/RallyPoint.cs b/OpenRA.Mods.RA/RallyPoint.cs index ba1c410200..7286f0eb1a 100755 --- a/OpenRA.Mods.RA/RallyPoint.cs +++ b/OpenRA.Mods.RA/RallyPoint.cs @@ -14,11 +14,12 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class RallyPointInfo : ITraitInfo, Requires + public class RallyPointInfo : ITraitInfo { public readonly int[] RallyPoint = { 1, 3 }; + public readonly string IndicatorPalettePrefix = "player"; - public object Create(ActorInitializer init) { return new RallyPoint(init.self); } + public object Create(ActorInitializer init) { return new RallyPoint(init.self, this); } } public class RallyPoint : IIssueOrder, IResolveOrder, ISync @@ -26,11 +27,10 @@ namespace OpenRA.Mods.RA [Sync] public CPos rallyPoint; public int nearEnough = 1; - public RallyPoint(Actor self) + public RallyPoint(Actor self, RallyPointInfo info) { - var info = self.Info.Traits.Get(); rallyPoint = self.Location + new CVec(info.RallyPoint[0], info.RallyPoint[1]); - self.World.AddFrameEndTask(w => w.Add(new Effects.RallyPoint(self))); + self.World.AddFrameEndTask(w => w.Add(new Effects.RallyPoint(self, info.IndicatorPalettePrefix))); } public IEnumerable Orders From 026a86ba75d8ae8397caff95c3b0261351095627 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sat, 16 Feb 2013 15:14:37 +1300 Subject: [PATCH 24/67] Add 'Crates' lobby checkbox and setting for enabling/disabling crate drops --- OpenRA.Game/Network/Session.cs | 1 + OpenRA.Mods.RA/CrateDrop.cs | 2 ++ OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 13 +++++++++++++ OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 10 ++++++++++ mods/ra/chrome/lobby.yaml | 8 +++++++- 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 30f7ae16d5..f911449363 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -79,6 +79,7 @@ namespace OpenRA.Network public bool AllowCheats = false; public bool Dedicated; public string Difficulty; + public bool Crates = true; } public Session(string[] mods) diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index 2e2d362d1d..4a4708e90b 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -40,6 +40,8 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { + if (!self.World.LobbyInfo.GlobalSettings.Crates) return; + if (--ticks <= 0) { ticks = Info.SpawnInterval * 25; // todo: randomize diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index 3d645c162e..c2313dfaa8 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -318,6 +318,19 @@ namespace OpenRA.Mods.RA.Server server.SyncLobbyInfo(); return true; }}, + { "crates", + s => + { + if (!client.IsAdmin) + { + server.SendChatTo(conn, "Only the host can set that option"); + return true; + } + + bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Crates); + server.SyncLobbyInfo(); + return true; + }}, { "difficulty", s => { diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 3029766a98..86e6814709 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -169,6 +169,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); + var crates = lobby.GetOrNull("CRATES_CHECKBOX"); + if (crates != null) + { + crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates; + crates.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null + || orderManager.LocalClient.IsReady; // maybe disable the checkbox if a map forcefully removes CrateDrop? + crates.OnClick = () => orderManager.IssueOrder(Order.Command( + "crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates))); + } + var difficulty = lobby.GetOrNull("DIFFICULTY_DROPDOWNBUTTON"); if (difficulty != null) { diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index 60ab28fe8e..1e91a0a9e1 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -432,9 +432,15 @@ Background@SERVER_LOBBY: Width: 80 Height: 20 Text: Allow Cheats + Checkbox@CRATES_CHECKBOX: + X: PARENT_RIGHT-154 + Y: PARENT_BOTTOM-154 + Width: 80 + Height: 20 + Text: Crates Button@DISCONNECT_BUTTON: X:PARENT_RIGHT-154 - Y:PARENT_BOTTOM-129 + Y:PARENT_BOTTOM-99 Width:120 Height:25 Text:Disconnect From 6b636b166c430e2a0c9b9c201ae1a71568fba349 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sun, 17 Feb 2013 16:54:10 +1300 Subject: [PATCH 25/67] Check Crates setting in CrateSpawner too --- OpenRA.Mods.RA/CrateSpawner.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index 9b58c66ade..67f1ea7c21 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -34,6 +34,8 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { + if (!self.World.LobbyInfo.GlobalSettings.Crates) return; + if (--ticks <= 0) { var info = self.Info.Traits.Get(); From 3bc9e7d2e46687f7f394d9ed8440410b6fa66249 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sat, 23 Feb 2013 00:12:20 +1300 Subject: [PATCH 26/67] Fix some playerstatistics related crashes for other mods --- OpenRA.Game/Widgets/LineGraphWidget.cs | 2 +- .../Widgets/Logic/ObserverStatsLogic.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Widgets/LineGraphWidget.cs b/OpenRA.Game/Widgets/LineGraphWidget.cs index 91846d240f..37e5c94192 100644 --- a/OpenRA.Game/Widgets/LineGraphWidget.cs +++ b/OpenRA.Game/Widgets/LineGraphWidget.cs @@ -101,7 +101,7 @@ namespace OpenRA.Widgets var xAxisSize = GetXAxisSize(); var yAxisSize = GetYAxisSize(); - var maxValue = GetSeries().Select(p => p.Points).SelectMany(d => d).Max(); + var maxValue = GetSeries().Select(p => p.Points).SelectMany(d => d).Concat(new[] { 0f }).Max(); var scale = 200 / Math.Max(5000, (float)Math.Ceiling(maxValue / 1000) * 1000); var xStep = width / xAxisSize; diff --git a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs index 0cd5eb5d78..5b7ca6436f 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs @@ -156,7 +156,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic players.Select(p => new LineGraphSeries( p.PlayerName, p.ColorRamp.GetColor(0), - p.PlayerActor.Trait().EarnedSamples.Select(s => (float)s) + (p.PlayerActor.TraitOrDefault() ?? new PlayerStatistics(p.PlayerActor)).EarnedSamples.Select(s => (float)s) )); playerStatsPanel.AddChild(template); @@ -187,10 +187,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic AddPlayerFlagAndName(template, player); - var stats = player.PlayerActor.Trait(); + var stats = player.PlayerActor.TraitOrDefault(); + if (stats == null) return template; template.Get("CONTROL").GetText = () => MapControl(stats.MapControl); - template.Get("KILLS_COST").GetText = () => "$" + stats.KillsCost.ToString(); - template.Get("DEATHS_COST").GetText = () => "$" + stats.DeathsCost.ToString(); + template.Get("KILLS_COST").GetText = () => "$" + stats.KillsCost; + template.Get("DEATHS_COST").GetText = () => "$" + stats.DeathsCost; template.Get("UNITS_KILLED").GetText = () => stats.UnitsKilled.ToString(); template.Get("UNITS_DEAD").GetText = () => stats.UnitsDead.ToString(); template.Get("BUILDINGS_KILLED").GetText = () => stats.BuildingsKilled.ToString(); @@ -220,7 +221,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic AddPlayerFlagAndName(template, player); var res = player.PlayerActor.Trait(); - var stats = player.PlayerActor.Trait(); + var stats = player.PlayerActor.TraitOrDefault(); + if (stats == null) return template; template.Get("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre); template.Get("EARNED_MIN").GetText = () => AverageEarnedPerMinute(res.Earned); @@ -258,7 +260,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic template.Get("KILLS").GetText = () => player.Kills.ToString(); template.Get("DEATHS").GetText = () => player.Deaths.ToString(); - var stats = player.PlayerActor.Trait(); + var stats = player.PlayerActor.TraitOrDefault(); + if (stats == null) return template; template.Get("ACTIONS_MIN").GetText = () => AverageOrdersPerMinute(stats.OrderCount); return template; From e57de0ebce4f525f7f3e80e2700ca083fd281ba3 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Mon, 25 Feb 2013 20:37:08 +1300 Subject: [PATCH 27/67] Allies 02 code maintenance. Add FreeActorInit so free harvesters with procs can be disabled etc --- OpenRA.Mods.RA/FreeActor.cs | 21 ++- OpenRA.Mods.RA/Missions/Allies02Script.cs | 171 ++++++------------ OpenRA.Mods.RA/Missions/MissionUtils.cs | 26 +-- .../Missions/MonsterTankMadnessScript.cs | 35 ++-- mods/ra/maps/allies-02/map.yaml | 13 +- mods/ra/maps/monster-tank-madness/map.yaml | 11 +- 6 files changed, 95 insertions(+), 182 deletions(-) diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index 1ed405c92b..ba96eb087b 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -21,20 +21,22 @@ namespace OpenRA.Mods.RA public readonly int2 SpawnOffset = int2.Zero; public readonly int Facing = 0; - public object Create( ActorInitializer init ) { return new FreeActor(init.self, this); } + public object Create( ActorInitializer init ) { return new FreeActor(init, this); } } public class FreeActor { - public FreeActor(Actor self, FreeActorInfo info) + public FreeActor(ActorInitializer init, FreeActorInfo info) { - self.World.AddFrameEndTask( + if (init.Contains() && !init.Get().value) return; + + init.self.World.AddFrameEndTask( w => { var a = w.CreateActor(info.Actor, new TypeDictionary { - new LocationInit( self.Location + (CVec)info.SpawnOffset ), - new OwnerInit( self.Owner ), + new LocationInit( init.self.Location + (CVec)info.SpawnOffset ), + new OwnerInit( init.self.Owner ), new FacingInit( info.Facing ), }); @@ -43,4 +45,13 @@ namespace OpenRA.Mods.RA }); } } + + public class FreeActorInit : IActorInit + { + [FieldFromYamlKey] + public readonly bool value = true; + public FreeActorInit() { } + public FreeActorInit(bool init) { value = init; } + public bool Value(World world) { return value; } + } } diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index e728df1822..db591312fd 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -57,6 +57,7 @@ namespace OpenRA.Mods.RA.Missions Actor sam2; Actor sam3; Actor sam4; + Actor[] sams; Actor tanya; Actor einstein; Actor engineer; @@ -74,8 +75,6 @@ namespace OpenRA.Mods.RA.Missions Actor parabombPoint1; Actor parabombPoint2; Actor sovietRallyPoint; - Actor flamersEntryPoint; - Actor tanksEntryPoint; Actor townPoint; Actor sovietTownAttackPoint1; Actor sovietTownAttackPoint2; @@ -103,7 +102,7 @@ namespace OpenRA.Mods.RA.Missions static readonly string[] SovietVehicles1 = { "3tnk" }; static readonly string[] SovietVehicles2 = { "3tnk", "v2rl" }; const int SovietVehiclesUpgradeTicks = 1500 * 4; - const int SovietGroupSize = 20; + const int SovietGroupSize = 5; const int ReinforcementsTicks = 1500 * 12; static readonly string[] Reinforcements = @@ -180,12 +179,6 @@ namespace OpenRA.Mods.RA.Missions if (allies1 != allies2) { - if (world.FrameNumber == TanksTicks) - RushSovietUnits(); - - if (world.FrameNumber == FlamersTicks) - RushSovietFlamers(); - if (yak == null || (yak != null && !yak.IsDead() && (yak.GetCurrentActivity() is FlyCircle || yak.IsIdle))) { var alliedUnitsNearYakPoint = world.FindAliveCombatantActorsInCircle(yakAttackPoint.CenterLocation, 10) @@ -218,22 +211,19 @@ namespace OpenRA.Mods.RA.Missions } if (objectives[DestroySamSitesID].Status == ObjectiveStatus.InProgress) { - if ((sam1.Destroyed || sam1.Owner != soviets) - && (sam2.Destroyed || sam2.Owner != soviets) - && (sam3.Destroyed || sam3.Owner != soviets) - && (sam4.Destroyed || sam4.Owner != soviets)) + if (sams.All(s => s.IsDead() || s.Owner != soviets)) { objectives[DestroySamSitesID].Status = ObjectiveStatus.Completed; objectives[ExtractEinsteinID].Status = ObjectiveStatus.InProgress; OnObjectivesUpdated(true); - SpawnSignalFlare(); + world.CreateActor(SignalFlareName, new TypeDictionary { new OwnerInit(allies1), new LocationInit(extractionLZ.Location) }); Sound.Play("flaren1.aud"); ExtractEinsteinAtLZ(); } } if (objectives[ExtractEinsteinID].Status == ObjectiveStatus.InProgress && einsteinChinook != null) { - if (einsteinChinook.Destroyed) + if (einsteinChinook.IsDead()) { objectives[ExtractEinsteinID].Status = ObjectiveStatus.Failed; objectives[MaintainPresenceID].Status = ObjectiveStatus.Failed; @@ -253,22 +243,19 @@ namespace OpenRA.Mods.RA.Missions } } - if (tanya.Destroyed) + if (tanya.IsDead()) MissionFailed("Tanya was killed."); - else if (einstein.Destroyed) + else if (einstein.IsDead()) MissionFailed("Einstein was killed."); - world.AddFrameEndTask(w => + else if (!world.Actors.Any(a => (a.Owner == allies || a.Owner == allies2) && !a.IsDead() + && (a.HasTrait() && !a.HasTrait()) || a.HasTrait())) { - if (!world.FindAliveCombatantActorsInCircle(allies2BasePoint.CenterLocation, 20) - .Any(a => a.HasTrait() && !a.HasTrait() && (a.Owner == allies || a.Owner == allies2))) - { - objectives[MaintainPresenceID].Status = ObjectiveStatus.Failed; - OnObjectivesUpdated(true); - MissionFailed("The Allied reinforcements have been defeated."); - } - }); + objectives[MaintainPresenceID].Status = ObjectiveStatus.Failed; + OnObjectivesUpdated(true); + MissionFailed("The Allied reinforcements have been defeated."); + } } void UpdateDeaths() @@ -308,10 +295,10 @@ namespace OpenRA.Mods.RA.Missions void BuildSovietUnits() { - if (!sovietBarracks.Destroyed) + if (!sovietBarracks.IsDead()) BuildSovietUnit(InfantryQueueName, SovietInfantry.Random(world.SharedRandom)); - if (!sovietWarFactory.Destroyed) + if (!sovietWarFactory.IsDead()) { var vehicles = world.FrameNumber >= SovietVehiclesUpgradeTicks ? SovietVehicles2 : SovietVehicles1; BuildSovietUnit(VehicleQueueName, vehicles.Random(world.SharedRandom)); @@ -320,44 +307,39 @@ namespace OpenRA.Mods.RA.Missions void ManageSovietUnits() { - var idleSovietUnitsAtRP = world.FindAliveCombatantActorsInCircle(sovietRallyPoint.CenterLocation, 3) - .Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait()); - - if (idleSovietUnitsAtRP.Count() >= SovietGroupSize) + var units = world.FindAliveCombatantActorsInCircle(sovietRallyPoint.CenterLocation, 10) + .Where(u => u.IsIdle && u.HasTrait() && u.HasTrait() && u.Owner == soviets) + .Except(world.WorldActor.Trait().Actors.Values); + if (units.Count() >= SovietGroupSize) { - var firstUnit = idleSovietUnitsAtRP.FirstOrDefault(); - if (firstUnit != null) + foreach (var unit in units) + MissionUtils.AttackNearestLandActor(true, unit, allies2); + } + + var scatteredUnits = world.Actors.Where(u => u.IsInWorld && !u.IsDead() && u.IsIdle + && u.HasTrait() && u.HasTrait() && u.Owner == soviets) + .Except(world.WorldActor.Trait().Actors.Values) + .Except(units); + + foreach (var unit in scatteredUnits) + MissionUtils.AttackNearestLandActor(true, unit, allies2); + } + + void SetupAlliedBase() + { + foreach (var actor in world.Actors.Where(a => a.Owner == allies && a != allies.PlayerActor)) + { + actor.ChangeOwner(allies2); + if (actor.Info.Name == "pbox") { - var closestAlliedBuilding = ClosestAlliedBuilding(firstUnit, 40); - if (closestAlliedBuilding != null) - foreach (var unit in idleSovietUnitsAtRP) - { - unit.Trait().Nudge(unit, unit, true); - unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Attack(Target.FromActor(closestAlliedBuilding), 3))); - } + actor.AddTrait(new TransformedAction(s => s.Trait().Load(s, world.CreateActor(false, "e1", allies2, null, null)))); + actor.QueueActivity(new Transform(actor, "hbox.e1") { SkipMakeAnims = true }); } + if (actor.Info.Name == "proc") + actor.QueueActivity(new Transform(actor, "proc") { SkipMakeAnims = true }); + foreach (var c in actor.TraitsImplementing()) + c.OnCapture(actor, actor, allies, allies2); } - - var idleSovietUnits = world.FindAliveCombatantActorsInCircle(allies2BasePoint.CenterLocation, 20) - .Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait()); - - foreach (var unit in idleSovietUnits) - { - var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40); - - if (closestAlliedBuilding != null) - unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Attack(Target.FromActor(closestAlliedBuilding), 3))); - } - } - - Actor ClosestAlliedBuilding(Actor actor, int range) - { - return MissionUtils.ClosestPlayerBuilding(world, allies2, actor.CenterLocation, range); - } - - IEnumerable ClosestAlliedBuildings(Actor actor, int range) - { - return MissionUtils.ClosestPlayerBuildings(world, allies2, actor.CenterLocation, range); } void InitializeSovietFactories() @@ -365,7 +347,7 @@ namespace OpenRA.Mods.RA.Missions var sbrp = sovietBarracks.Trait(); var swrp = sovietWarFactory.Trait(); sbrp.rallyPoint = swrp.rallyPoint = sovietRallyPoint.Location; - sbrp.nearEnough = swrp.nearEnough = 3; + sbrp.nearEnough = swrp.nearEnough = 6; sovietBarracks.Trait().SetPrimaryProducer(sovietBarracks, true); sovietWarFactory.Trait().SetPrimaryProducer(sovietWarFactory, true); } @@ -378,11 +360,6 @@ namespace OpenRA.Mods.RA.Missions queue.ResolveOrder(queue.self, Order.StartProduction(queue.self, unit, 1)); } - void SpawnSignalFlare() - { - world.CreateActor(SignalFlareName, new TypeDictionary { new OwnerInit(allies1), new LocationInit(extractionLZ.Location) }); - } - void StartReinforcementsTimer() { Sound.Play("timergo1.aud"); @@ -409,38 +386,6 @@ namespace OpenRA.Mods.RA.Missions .QueueActivity(new Move.Move(allies2BasePoint.Location)); } - void RushSovietUnits() - { - var closestAlliedBuildings = ClosestAlliedBuildings(badgerDropPoint1, 40); - if (!closestAlliedBuildings.Any()) return; - - foreach (var tank in Tanks) - { - var unit = world.CreateActor(tank, new TypeDictionary - { - new OwnerInit(soviets), - new LocationInit(tanksEntryPoint.Location) - }); - foreach (var building in closestAlliedBuildings) - unit.QueueActivity(new Attack(Target.FromActor(building), 3)); - } - } - - void RushSovietFlamers() - { - var closestAlliedBuilding = ClosestAlliedBuilding(badgerDropPoint1, 40); - if (closestAlliedBuilding == null) return; - - var apc = world.CreateActor(ApcName, new TypeDictionary { new OwnerInit(soviets), new LocationInit(flamersEntryPoint.Location) }); - foreach (var flamer in Flamers) - { - var unit = world.CreateActor(false, flamer, new TypeDictionary { new OwnerInit(soviets) }); - apc.Trait().Load(apc, unit); - } - apc.QueueActivity(new MoveAdjacentTo(Target.FromActor(closestAlliedBuilding))); - apc.QueueActivity(new UnloadCargo(true)); - } - void ExtractEinsteinAtLZ() { einsteinChinook = MissionUtils.ExtractUnitWithChinook( @@ -461,7 +406,7 @@ namespace OpenRA.Mods.RA.Missions void TransferTownUnitsToAllies() { foreach (var unit in world.FindAliveNonCombatantActorsInCircle(townPoint.CenterLocation, AlliedTownTransferRange) - .Where(a => a.HasTrait())) + .Where(a => a.HasTrait())) unit.ChangeOwner(allies1); } @@ -492,11 +437,14 @@ namespace OpenRA.Mods.RA.Missions allies = w.Players.Single(p => p.InternalName == "Allies"); soviets = w.Players.Single(p => p.InternalName == "Soviets"); + soviets.PlayerActor.Trait().Cash = 1000; + var actors = w.WorldActor.Trait().Actors; sam1 = actors["SAM1"]; sam2 = actors["SAM2"]; sam3 = actors["SAM3"]; sam4 = actors["SAM4"]; + sams = new[] { sam1, sam2, sam3, sam4 }; tanya = actors["Tanya"]; einstein = actors["Einstein"]; engineer = actors["Engineer"]; @@ -515,17 +463,15 @@ namespace OpenRA.Mods.RA.Missions sovietBarracks = actors["SovietBarracks"]; sovietWarFactory = actors["SovietWarFactory"]; sovietRallyPoint = actors["SovietRallyPoint"]; - flamersEntryPoint = actors["FlamersEntryPoint"]; - tanksEntryPoint = actors["TanksEntryPoint"]; townPoint = actors["TownPoint"]; sovietTownAttackPoint1 = actors["SovietTownAttackPoint1"]; sovietTownAttackPoint2 = actors["SovietTownAttackPoint2"]; yakEntryPoint = actors["YakEntryPoint"]; yakAttackPoint = actors["YakAttackPoint"]; - SetupAlliedBase(actors); + SetupAlliedBase(); - var shroud = w.WorldActor.Trait(); + var shroud = allies1.Shroud; shroud.Explore(w, sam1.Location, 2); shroud.Explore(w, sam2.Location, 2); shroud.Explore(w, sam3.Location, 2); @@ -539,20 +485,5 @@ namespace OpenRA.Mods.RA.Missions MissionUtils.PlayMissionMusic(); } - - void SetupAlliedBase(Dictionary actors) - { - world.AddFrameEndTask(w => - { - foreach (var actor in actors.Where(a => a.Value.Owner == allies)) - actor.Value.ChangeOwner(allies2); - - world.CreateActor("proc", new TypeDictionary - { - new LocationInit(actors["Allies2ProcPoint"].Location), - new OwnerInit(allies2) - }); - }); - } } } diff --git a/OpenRA.Mods.RA/Missions/MissionUtils.cs b/OpenRA.Mods.RA/Missions/MissionUtils.cs index 12557b98bd..885d2b810f 100644 --- a/OpenRA.Mods.RA/Missions/MissionUtils.cs +++ b/OpenRA.Mods.RA/Missions/MissionUtils.cs @@ -109,30 +109,6 @@ namespace OpenRA.Mods.RA.Missions return units.Any() && units.All(a => a.Owner == player); } - public static Actor ClosestPlayerUnit(World world, Player player, PPos location, int range) - { - return ClosestPlayerUnits(world, player, location, range).FirstOrDefault(); - } - - public static IEnumerable ClosestPlayerUnits(World world, Player player, PPos location, int range) - { - return world.FindAliveCombatantActorsInCircle(location, range) - .Where(a => a.Owner == player && a.HasTrait()) - .OrderBy(a => (location - a.CenterLocation).LengthSquared); - } - - public static Actor ClosestPlayerBuilding(World world, Player player, PPos location, int range) - { - return ClosestPlayerBuildings(world, player, location, range).FirstOrDefault(); - } - - public static IEnumerable ClosestPlayerBuildings(World world, Player player, PPos location, int range) - { - return world.FindAliveCombatantActorsInCircle(location, range) - .Where(a => a.Owner == player && a.HasTrait() && !a.HasTrait()) - .OrderBy(a => (location - a.CenterLocation).LengthSquared); - } - public static IEnumerable FindQueues(World world, Player player, string category) { return world.ActorsWithTrait() @@ -231,7 +207,7 @@ namespace OpenRA.Mods.RA.Missions public static void AttackNearestLandActor(bool queued, Actor self, Player enemyPlayer) { var enemies = self.World.Actors.Where(u => u.AppearsHostileTo(self) && u.Owner == enemyPlayer - && ((u.HasTrait() && !u.HasTrait()) || u.HasTrait()) && u.IsInWorld && !u.IsDead()); + && ((u.HasTrait() && !u.HasTrait()) || (u.HasTrait() && !u.HasTrait())) && u.IsInWorld && !u.IsDead()); var enemy = enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault(); if (enemy != null) diff --git a/OpenRA.Mods.RA/Missions/MonsterTankMadnessScript.cs b/OpenRA.Mods.RA/Missions/MonsterTankMadnessScript.cs index b4f6344786..7570160b19 100644 --- a/OpenRA.Mods.RA/Missions/MonsterTankMadnessScript.cs +++ b/OpenRA.Mods.RA/Missions/MonsterTankMadnessScript.cs @@ -8,13 +8,13 @@ */ #endregion +using System; +using System.Collections.Generic; +using System.Linq; using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Move; using OpenRA.Traits; -using System; -using System.Collections.Generic; -using System.Linq; namespace OpenRA.Mods.RA.Missions { @@ -137,11 +137,10 @@ namespace OpenRA.Mods.RA.Missions if (baseTransferredTick == -1) { - var actorsInBase = world.FindUnits(alliedBaseTopLeft.CenterLocation, alliedBaseBottomRight.CenterLocation).Where(a => !a.IsDead() && a.IsInWorld); + var actorsInBase = world.FindUnits(alliedBaseTopLeft.CenterLocation, alliedBaseBottomRight.CenterLocation).Where(a => a != a.Owner.PlayerActor); if (actorsInBase.Any(a => a.Owner == greece)) { - foreach (var actor in actorsInBase) - TransferActorToAllies(actor); + SetupAlliedBase(actorsInBase); baseTransferredTick = world.FrameNumber; objectives[FindOutpostID].Status = ObjectiveStatus.Completed; OnObjectivesUpdated(true); @@ -234,20 +233,22 @@ namespace OpenRA.Mods.RA.Missions } } - void TransferActorToAllies(Actor actor) + void SetupAlliedBase(IEnumerable actors) { - // hack hack hack - actor.ChangeOwner(greece); - if (actor.Info.Name == "pbox") + foreach (var actor in actors) { - actor.AddTrait(new TransformedAction(s => s.Trait().Load(s, world.CreateActor(false, "e1", greece, null, null)))); - actor.QueueActivity(new Transform(actor, "hbox.e1") { SkipMakeAnims = true }); + // hack hack hack + actor.ChangeOwner(greece); + if (actor.Info.Name == "pbox") + { + actor.AddTrait(new TransformedAction(s => s.Trait().Load(s, world.CreateActor(false, "e1", greece, null, null)))); + actor.QueueActivity(new Transform(actor, "hbox.e1") { SkipMakeAnims = true }); + } + else if (actor.Info.Name == "proc") + actor.QueueActivity(new Transform(actor, "proc") { SkipMakeAnims = true }); + foreach (var c in actor.TraitsImplementing()) + c.OnCapture(actor, actor, neutral, greece); } - else if (actor.Info.Name == "proc.nofreeactor") - actor.QueueActivity(new Transform(actor, "proc") { SkipMakeAnims = true }); - var building = actor.TraitOrDefault(); - if (building != null) - building.OnCapture(actor, actor, neutral, greece); } void EvacuateCivilians() diff --git a/mods/ra/maps/allies-02/map.yaml b/mods/ra/maps/allies-02/map.yaml index e7733e6e99..efa6b44634 100644 --- a/mods/ra/maps/allies-02/map.yaml +++ b/mods/ra/maps/allies-02/map.yaml @@ -852,9 +852,6 @@ Actors: Actor301: tc04 Location: 27,33 Owner: Neutral - Actor265: miss - Location: 27,23 - Owner: Soviets Actor402: brik Location: 22,67 Owner: Soviets @@ -1481,9 +1478,10 @@ Actors: Actor290: apwr Location: 52,42 Owner: Soviets - Allies2ProcPoint: waypoint + Actor875: proc Location: 25,95 Owner: Allies + FreeActor: False Actor455: fenc Location: 31,93 Owner: Allies @@ -1517,13 +1515,13 @@ Actors: Actor470: fenc Location: 26,93 Owner: Allies - Actor454: pbox.e1 + Actor454: pbox Location: 32,93 Owner: Allies Actor465: fenc Location: 30,93 Owner: Allies - Actor473: pbox.e1 + Actor473: pbox Location: 40,93 Owner: Allies Actor472: gun @@ -3006,6 +3004,9 @@ Rules: CTNK: Buildable: Owner: None + MGG: + Buildable: + Owner: None CRATE: GiveCashCrateAction: SelectionShares: 0 diff --git a/mods/ra/maps/monster-tank-madness/map.yaml b/mods/ra/maps/monster-tank-madness/map.yaml index 105a2e9d49..e00da1a10d 100644 --- a/mods/ra/maps/monster-tank-madness/map.yaml +++ b/mods/ra/maps/monster-tank-madness/map.yaml @@ -1754,11 +1754,12 @@ Actors: Owner: BadGuy Health: 1 Facing: 0 - AlliedBaseProc: proc.nofreeactor + AlliedBaseProc: proc Location: 27,25 Owner: Neutral Health: 0.3476563 Facing: 0 + FreeActor: False Actor508: silo Location: 36,18 Owner: Neutral @@ -2609,14 +2610,6 @@ Rules: RenderBuilding: Image: DOME -InfiltrateForExploration: - PROC.NoFreeActor: - Inherits: PROC - -Buildable: - RenderBuilding: - Image: PROC - Tooltip: - Icon: procicon - -FreeActor: V19: AutoTargetIgnore: TRAN: From b5bd6191c27eed510ab417beed3b6d7ab91bed57 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Mon, 25 Feb 2013 21:12:14 +1300 Subject: [PATCH 28/67] Don't crash (due to replay file being in use) if we have two instances of the game playing --- OpenRA.Game/Game.cs | 2 +- .../Network/ReplayRecorderConnection.cs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b4af0f25d4..8f33d9500e 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -58,7 +58,7 @@ namespace OpenRA static string ChooseReplayFilename() { - return DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddTHHmmssZ.rep"); + return DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddTHHmmssZ"); } static void JoinInner(OrderManager om) diff --git a/OpenRA.Game/Network/ReplayRecorderConnection.cs b/OpenRA.Game/Network/ReplayRecorderConnection.cs index c7aba98b6b..249574ac1c 100644 --- a/OpenRA.Game/Network/ReplayRecorderConnection.cs +++ b/OpenRA.Game/Network/ReplayRecorderConnection.cs @@ -34,12 +34,23 @@ namespace OpenRA.Network void StartSavingReplay(byte[] initialContent) { var filename = chooseFilename(); - var replayPath = Path.Combine(Platform.SupportDir, "Replays"); + var replaysDirectory = Path.Combine(Platform.SupportDir, "Replays"); - if (!Directory.Exists(replayPath)) - Directory.CreateDirectory(replayPath); + if (!Directory.Exists(replaysDirectory)) + Directory.CreateDirectory(replaysDirectory); - var file = File.Create(Path.Combine(replayPath, filename)); + string fullFilename; + var id = -1; + do + { + fullFilename = Path.Combine(replaysDirectory, id < 0 + ? "{0}.rep".F(filename) + : "{0}-{1}.rep".F(filename, id)); + id++; + } + while (File.Exists(fullFilename)); + + var file = File.Create(fullFilename); file.Write(initialContent); this.writer = new BinaryWriter(file); } From 09e4d64f997553cc64604dceeb1269af4f054bb6 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Mon, 25 Feb 2013 23:40:31 +1300 Subject: [PATCH 29/67] Fix Allies 02 warnings --- OpenRA.Mods.RA/Missions/Allies02Script.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index db591312fd..a74df08466 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -119,18 +119,11 @@ namespace OpenRA.Mods.RA.Missions const int ParabombTicks = 750; - const int FlamersTicks = 1500 * 2; - static readonly string[] Flamers = { "e4", "e4", "e4", "e4", "e4" }; - const string ApcName = "apc"; - const int ParatroopersTicks = 1500 * 5; static readonly string[] Badger1Passengers = { "e1", "e1", "e1", "e2", "3tnk" }; static readonly string[] Badger2Passengers = { "e1", "e1", "e1", "e2", "e2" }; static readonly string[] Badger3Passengers = { "e1", "e1", "e1", "e2", "e2" }; - const int TanksTicks = 1500 * 11; - static readonly string[] Tanks = { "3tnk", "3tnk", "3tnk", "3tnk", "3tnk", "3tnk", "3tnk", "3tnk" }; - const string SignalFlareName = "flare"; const string YakName = "yak"; From 1438030e8207a48dfc59a11c9e9bbb102b25f624 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Tue, 26 Feb 2013 00:10:03 +1300 Subject: [PATCH 30/67] Add mood haze effect for Allies 04 --- OpenRA.Mods.RA/Missions/Allies04Script.cs | 24 +++++++++++++++++++++++ mods/ra/maps/allies-04/map.yaml | 1 + 2 files changed, 25 insertions(+) diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index d04525e0aa..67de7a0026 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using OpenRA.FileFormats; using OpenRA.Mods.RA.Activities; @@ -533,4 +534,27 @@ namespace OpenRA.Mods.RA.Missions } class Allies04TransformOnLabInfiltrate { } + + class Allies04HazyPaletteEffectInfo : TraitInfo { } + + class Allies04HazyPaletteEffect : IPaletteModifier + { + static readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud" }; + + public void AdjustPalette(Dictionary palettes) + { + foreach (var pal in palettes) + { + if (ExcludePalettes.Contains(pal.Key)) + continue; + + for (var x = 0; x < 256; x++) + { + var from = pal.Value.GetColor(x); + var to = Color.FromArgb(from.A, Color.FromKnownColor(KnownColor.DarkOrange)); + pal.Value.SetColor(x, Exts.ColorLerp(0.15f, from, to)); + } + } + } + } } diff --git a/mods/ra/maps/allies-04/map.yaml b/mods/ra/maps/allies-04/map.yaml index 9908e043f1..6ad7e412a1 100644 --- a/mods/ra/maps/allies-04/map.yaml +++ b/mods/ra/maps/allies-04/map.yaml @@ -1799,6 +1799,7 @@ Rules: -SpawnMPUnits: -MPStartLocations: Allies04Script: + Allies04HazyPaletteEffect: MissionObjectivesPanel: ObjectivesPanel: MISSION_OBJECTIVES ^Building: From e33c783fc1fa8f31f04b1226b14d601e649adb51 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:48:16 +1300 Subject: [PATCH 31/67] Ditto for GpsDot. --- OpenRA.Mods.RA/Effects/GpsDot.cs | 69 ++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index 5517341fd4..7b63f440dc 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -15,65 +15,76 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Effects { - class GpsDotInfo : ITraitInfo, Requires + class GpsDotInfo : ITraitInfo { public readonly string String = "Infantry"; + public readonly string IndicatorPalettePrefix = "player"; + public object Create(ActorInitializer init) { - return new GpsDot(init, String); + return new GpsDot(init.self, this); } } class GpsDot : IEffect { Actor self; - GpsWatcher watcher; - RenderSimple rs; - bool show = false; + GpsDotInfo info; Animation anim; - public GpsDot(ActorInitializer init, string s) - { - anim = new Animation("gpsdot"); - anim.PlayRepeating(s); + GpsWatcher watcher; + HiddenUnderFog huf; + Spy spy; + bool show = false; + + public GpsDot(Actor self, GpsDotInfo info) + { + this.self = self; + this.info = info; + anim = new Animation("gpsdot"); + anim.PlayRepeating(info.String); - self = init.self; - rs = self.Trait(); self.World.AddFrameEndTask(w => w.Add(this)); - if(self.World.LocalPlayer != null) + if (self.World.LocalPlayer != null) watcher = self.World.LocalPlayer.PlayerActor.Trait(); } + bool firstTick = true; public void Tick(World world) { - show = false; - if (self.Destroyed) world.AddFrameEndTask(w => w.Remove(this)); - if (world.LocalPlayer == null) + if (world.LocalPlayer == null || !self.IsInWorld || self.Destroyed) return; - if ( - self.IsInWorld - && (watcher.Granted || watcher.GrantedAllies) - && !self.Trait().IsVisible(self.World.RenderedShroud, self) // WRONG - && (!self.HasTrait() || !self.Trait().Cloaked) - && (!self.HasTrait() || !self.Trait().Disguised) - ) + // Can be granted at runtime via a crate, so can't cache + var cloak = self.TraitOrDefault(); + + if (firstTick) { - show = true; + huf = self.TraitOrDefault(); + spy = self.TraitOrDefault(); + firstTick = false; } + + var hasGps = (watcher != null && (watcher.Granted || watcher.GrantedAllies)); + var hasDot = (huf != null && !huf.IsVisible(self.World.RenderedShroud, self)); // WRONG (why?) + var dotHidden = (cloak != null && cloak.Cloaked) || (spy != null && spy.Disguised); + + show = hasGps && hasDot && !dotHidden; } public IEnumerable Render(WorldRenderer wr) { - if (show && !self.Destroyed) - { - var p = self.CenterLocation; - yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner, wr), p.Y) - .WithScale(1.5f); - } + if (!show || self.Destroyed) + yield break; + + var p = self.CenterLocation; + var palette = wr.Palette(info.IndicatorPalettePrefix+self.Owner.InternalName); + yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, palette, p.Y) + .WithScale(1.5f); + } } } From fa5cf96f40738ae5ab73d5d71154efaf15e9aad8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 15:18:34 +1300 Subject: [PATCH 32/67] Ditto for Corpse. --- OpenRA.Mods.RA/CrushableInfantry.cs | 12 +++++------- OpenRA.Mods.RA/Effects/Corpse.cs | 20 ++++++++------------ OpenRA.Mods.RA/Render/RenderInfantry.cs | 8 +++++++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/OpenRA.Mods.RA/CrushableInfantry.cs b/OpenRA.Mods.RA/CrushableInfantry.cs index 907e3148cb..3b625c056f 100644 --- a/OpenRA.Mods.RA/CrushableInfantry.cs +++ b/OpenRA.Mods.RA/CrushableInfantry.cs @@ -13,10 +13,11 @@ using System.Linq; using OpenRA.Traits; using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Move; +using OpenRA.Mods.RA.Render; namespace OpenRA.Mods.RA { - class CrushableInfantryInfo : ITraitInfo, Requires + class CrushableInfantryInfo : ITraitInfo, Requires, Requires { public readonly string CrushSound = "squish2.aud"; public readonly string CorpseSequence = "die-crushed"; @@ -29,11 +30,13 @@ namespace OpenRA.Mods.RA { readonly Actor self; readonly CrushableInfantryInfo Info; + readonly RenderInfantry ri; public CrushableInfantry(Actor self, CrushableInfantryInfo info) { this.self = self; this.Info = info; + ri = self.Trait(); } public void WarnCrush(Actor crusher) @@ -45,12 +48,7 @@ namespace OpenRA.Mods.RA public void OnCrush(Actor crusher) { Sound.Play(Info.CrushSound, crusher.CenterLocation); - self.World.AddFrameEndTask(w => - { - if (!self.Destroyed) - w.Add(new Corpse(self, Info.CorpseSequence)); - }); - + ri.SpawnCorpse(self, Info.CorpseSequence); self.Kill(crusher); } diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index e7103f97a2..383cc5dd26 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -19,25 +19,21 @@ namespace OpenRA.Mods.RA.Effects { readonly Animation anim; readonly float2 pos; - readonly RenderSimple rs; - readonly Player p; + readonly string paletteName; - public Corpse(Actor fromActor, string sequence) + public Corpse(World world, float2 pos, string image, string sequence, string paletteName) { - p = fromActor.Owner; - rs = fromActor.Trait(); - anim = new Animation(rs.GetImage(fromActor)); - anim.PlayThen(sequence, - () => fromActor.World.AddFrameEndTask(w => w.Remove(this))); - - pos = fromActor.CenterLocation.ToFloat2(); + this.pos = pos; + this.paletteName = paletteName; + anim = new Animation(image); + anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); } - public void Tick( World world ) { anim.Tick(); } + public void Tick(World world) { anim.Tick(); } public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, rs.Palette(p, wr), (int)pos.Y); + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, wr.Palette(paletteName), (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index bba5c0a611..a0d7df1b9b 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -124,10 +124,16 @@ namespace OpenRA.Mods.RA.Render return; Sound.PlayVoice("Die", self, self.Owner.Country.Race); + SpawnCorpse(self, "die{0}".F(e.Warhead.InfDeath)); + } + + public void SpawnCorpse(Actor self, string sequence) + { self.World.AddFrameEndTask(w => { if (!self.Destroyed) - w.Add(new Corpse(self, "die{0}".F(e.Warhead.InfDeath))); + w.Add(new Corpse(w, self.CenterLocation.ToFloat2(), GetImage(self), + sequence, Info.PlayerPalette+self.Owner.InternalName)); }); } } From 55efd53ef7ac831dc28808984621bc3206f012ee Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 15:19:39 +1300 Subject: [PATCH 33/67] Make RenderSimple.Palette protected. --- OpenRA.Game/Traits/Render/RenderSimple.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index a3ab0ef66e..b9f1ed46bf 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -78,7 +78,7 @@ namespace OpenRA.Traits anim.PlayRepeating("idle"); } - public PaletteReference Palette(Player p, WorldRenderer wr) + protected PaletteReference Palette(Player p, WorldRenderer wr) { return wr.Palette(Info.Palette ?? Info.PlayerPalette + p.InternalName); } From 5b360a7fe2e98ec7b6d7e1899a975ff77422f0ad Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 17:36:22 +1300 Subject: [PATCH 34/67] Use PaletteReferences in ShroudRenderer. --- OpenRA.Game/Graphics/ShroudRenderer.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/Graphics/ShroudRenderer.cs b/OpenRA.Game/Graphics/ShroudRenderer.cs index 4229bf9da9..466e90da2d 100644 --- a/OpenRA.Game/Graphics/ShroudRenderer.cs +++ b/OpenRA.Game/Graphics/ShroudRenderer.cs @@ -105,8 +105,17 @@ namespace OpenRA.Graphics return shadowBits[SpecialShroudTiles[u ^ uSides][v]]; } - internal void Draw( WorldRenderer wr ) + bool initializePalettes = true; + PaletteReference fogPalette, shroudPalette; + internal void Draw(WorldRenderer wr) { + if (initializePalettes) + { + fogPalette = wr.Palette("fog"); + shroudPalette = wr.Palette("shroud"); + initializePalettes = false; + } + if (shroud != null && shroud.dirty) { shroud.dirty = false; @@ -120,14 +129,12 @@ namespace OpenRA.Graphics } var clipRect = Game.viewport.WorldBounds(wr.world); - DrawShroud( wr, clipRect, fogSprites, "fog" ); - DrawShroud( wr, clipRect, sprites, "shroud" ); + DrawShroud(wr, clipRect, fogSprites, fogPalette); + DrawShroud(wr, clipRect, sprites, shroudPalette); } - void DrawShroud( WorldRenderer wr, Rectangle clip, Sprite[,] s, string pal ) + void DrawShroud(WorldRenderer wr, Rectangle clip, Sprite[,] s, PaletteReference pal) { - var shroudPalette = wr.GetPaletteIndex(pal); - for (var j = clip.Top; j < clip.Bottom; j++) { var starti = clip.Left; @@ -142,14 +149,14 @@ namespace OpenRA.Graphics { s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - shroudPalette, + pal.RowIndex(wr), new float2(Game.CellSize * (i - starti), Game.CellSize)); starti = i + 1; } s[i, j].DrawAt( Game.CellSize * new float2(i, j), - shroudPalette); + pal.RowIndex(wr)); starti = i + 1; last = s[i, j]; } @@ -157,7 +164,7 @@ namespace OpenRA.Graphics if (starti < clip.Right) s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - shroudPalette, + pal.RowIndex(wr), new float2(Game.CellSize * (clip.Right - starti), Game.CellSize)); } } From f890ea010e97eea127b7a1bafd5f2f09d0a2941c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 17:46:28 +1300 Subject: [PATCH 35/67] Pass WorldRenderer to RenderAsTerrain for palette lookup. --- OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Mods.RA/Bridge.cs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 594ac3562b..fb66548ffd 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -112,7 +112,7 @@ namespace OpenRA.Graphics terrainRenderer.Draw(this, Game.viewport); foreach (var a in world.traitDict.ActorsWithTraitMultiple(world)) - foreach (var r in a.Trait.RenderAsTerrain(a.Actor)) + foreach (var r in a.Trait.RenderAsTerrain(this, a.Actor)) r.Sprite.DrawAt(r.Pos, r.Palette.RowIndex(this), r.Scale); foreach (var a in world.Selection.Actors) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index feadbb2ab3..9350d0b0ff 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -209,7 +209,7 @@ namespace OpenRA.Traits public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); } public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } - public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(Actor self); } + public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self); } public interface ITargetable { diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index 88ce8af4fa..b98df7974f 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -135,10 +135,18 @@ namespace OpenRA.Mods.RA return bridges.GetBridge(self.Location + new CVec(offset[0], offset[1])); } - public IEnumerable RenderAsTerrain(Actor self) + bool initializePalettes = true; + PaletteReference terrainPalette; + public IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self) { + if (initializePalettes) + { + terrainPalette = wr.Palette("terrain"); + initializePalettes = false; + } + foreach (var t in TileSprites[currentTemplate]) - yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), PaletteReference.FromName("terrain"), Game.CellSize * t.Key.Y); + yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), terrainPalette, Game.CellSize * t.Key.Y); } bool IsIntact(Bridge b) From 6fc4807a104058dbd3992cacb7408f9d40d3fbf6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 26 Feb 2013 09:31:19 +1300 Subject: [PATCH 36/67] Remove PaletteReference.FromName from PBOG. --- .../Orders/PlaceBuildingOrderGenerator.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 031e0d8c57..b65d9cc9c1 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -21,20 +21,17 @@ namespace OpenRA.Mods.RA.Orders { readonly Actor Producer; readonly string Building; - readonly IEnumerable Preview; readonly BuildingInfo BuildingInfo; + IEnumerable preview; Sprite buildOk, buildBlocked; + bool initialized = false; public PlaceBuildingOrderGenerator(Actor producer, string name) { Producer = producer; Building = name; BuildingInfo = Rules.Info[Building].Traits.Get(); - var rbi = Rules.Info[Building].Traits.Get(); - var pr = PaletteReference.FromName(rbi.Palette ?? (producer.Owner != null ? - rbi.PlayerPalette + producer.Owner.InternalName : null)); - Preview = rbi.RenderPreview(Rules.Info[Building], pr); buildOk = SequenceProvider.GetSequence("overlay", "build-valid").GetSprite(0); buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0); } @@ -90,7 +87,17 @@ namespace OpenRA.Mods.RA.Orders } else { - foreach (var r in Preview) + if (!initialized) + { + var rbi = Rules.Info[Building].Traits.Get(); + var palette = rbi.Palette ?? (Producer.Owner != null ? + rbi.PlayerPalette + Producer.Owner.InternalName : null); + + preview = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette)); + initialized = true; + } + + foreach (var r in preview) r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, r.Palette.RowIndex(wr), r.Scale*r.Sprite.size); From ce39c7947761f99c8fcae78d2fa847fb360c0690 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 26 Feb 2013 09:32:16 +1300 Subject: [PATCH 37/67] Apply consistent formatting to PBOG (no code changes). --- .../Orders/PlaceBuildingOrderGenerator.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index b65d9cc9c1..5dde8116ac 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Orders if (mi.Button == MouseButton.Right) world.CancelInputMode(); - var ret = InnerOrder( world, xy, mi ).ToList(); + var ret = InnerOrder(world, xy, mi).ToList(); if (ret.Count > 0) world.CancelInputMode(); @@ -52,26 +52,26 @@ namespace OpenRA.Mods.RA.Orders { if (mi.Button == MouseButton.Left) { - var topLeft = xy - FootprintUtils.AdjustForBuildingSize( BuildingInfo ); - if (!world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null) + var topLeft = xy - FootprintUtils.AdjustForBuildingSize(BuildingInfo); + if (!world.CanPlaceBuilding(Building, BuildingInfo, topLeft, null) || !BuildingInfo.IsCloseEnoughToBase(world, Producer.Owner, Building, topLeft)) { Sound.PlayNotification(Producer.Owner, "Speech", "BuildingCannotPlaceAudio", Producer.Owner.Country.Race); yield break; } - var isLineBuild = Rules.Info[ Building ].Traits.Contains(); + var isLineBuild = Rules.Info[Building].Traits.Contains(); yield return new Order(isLineBuild ? "LineBuild" : "PlaceBuilding", Producer.Owner.PlayerActor, false) { TargetLocation = topLeft, TargetString = Building }; } } - public void Tick( World world ) {} - public void RenderAfterWorld( WorldRenderer wr, World world ) {} - public void RenderBeforeWorld( WorldRenderer wr, World world ) + public void Tick(World world) {} + public void RenderAfterWorld(WorldRenderer wr, World world) {} + public void RenderBeforeWorld(WorldRenderer wr, World world) { var position = Game.viewport.ViewToWorld(Viewport.LastMousePos); - var topLeft = position - FootprintUtils.AdjustForBuildingSize( BuildingInfo ); + var topLeft = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo); var actorInfo = Rules.Info[Building]; foreach (var dec in actorInfo.Traits.WithInterface()) @@ -82,8 +82,8 @@ namespace OpenRA.Mods.RA.Orders // Assumes a 1x1 footprint; weird things will happen for other footprints if (Rules.Info[Building].Traits.Contains()) { - foreach( var t in BuildingUtils.GetLineBuildCells( world, topLeft, Building, BuildingInfo ) ) - cells.Add( t, BuildingInfo.IsCloseEnoughToBase( world, world.LocalPlayer, Building, t ) ); + foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, Building, BuildingInfo)) + cells.Add(t, BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, t)); } else { @@ -105,11 +105,11 @@ namespace OpenRA.Mods.RA.Orders var res = world.WorldActor.Trait(); var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft); foreach (var t in FootprintUtils.Tiles(Building, BuildingInfo, topLeft)) - cells.Add( t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null ); + cells.Add(t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null); } - foreach( var c in cells ) - ( c.Value ? buildOk : buildBlocked ).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain" ); + foreach (var c in cells) + (c.Value ? buildOk : buildBlocked).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain"); } public string GetCursor(World world, CPos xy, MouseInput mi) { return "default"; } From f2fe30a7bbf36bc1aaa0e7a9635563c8499c9e54 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 17:56:15 +1300 Subject: [PATCH 38/67] Remove PaletteReference.FromName from TeslaZap. --- OpenRA.Mods.RA/Effects/TeslaZap.cs | 59 +++++++++++++++++++----------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index 39b3c64c79..3d9a25c801 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -29,27 +29,35 @@ namespace OpenRA.Mods.RA.Effects class TeslaZap : IEffect { readonly ProjectileArgs Args; + readonly TeslaZapInfo Info; + IEnumerable renderables; int timeUntilRemove = 2; // # of frames bool doneDamage = false; - - readonly List renderables = new List(); + bool initialized = false; public TeslaZap(TeslaZapInfo info, ProjectileArgs args) { Args = args; - var bright = SequenceProvider.GetSequence(info.Image, "bright"); - var dim = SequenceProvider.GetSequence(info.Image, "dim"); - - for( var n = 0; n < info.DimZaps; n++ ) - renderables.AddRange(DrawZapWandering(args.src, args.dest, dim)); - for( var n = 0; n < info.BrightZaps; n++ ) - renderables.AddRange(DrawZapWandering(args.src, args.dest, bright)); + Info = info; } - public void Tick( World world ) + public IEnumerable GenerateRenderables(WorldRenderer wr) { - if( timeUntilRemove <= 0 ) - world.AddFrameEndTask( w => w.Remove( this ) ); + var bright = SequenceProvider.GetSequence(Info.Image, "bright"); + var dim = SequenceProvider.GetSequence(Info.Image, "dim"); + + for (var n = 0; n < Info.DimZaps; n++) + foreach (var z in DrawZapWandering(wr, Args.src, Args.dest, dim)) + yield return z; + for (var n = 0; n < Info.BrightZaps; n++) + foreach (var z in DrawZapWandering(wr, Args.src, Args.dest, bright)) + yield return z; + } + + public void Tick(World world) + { + if (timeUntilRemove <= 0) + world.AddFrameEndTask(w => w.Remove(this)); --timeUntilRemove; if (!doneDamage) @@ -62,9 +70,18 @@ namespace OpenRA.Mods.RA.Effects } } - public IEnumerable Render(WorldRenderer wr) { return renderables; } + public IEnumerable Render(WorldRenderer wr) + { + if (!initialized) + { + renderables = GenerateRenderables(wr); + initialized = true; + } - static IEnumerable DrawZapWandering(PPos from, PPos to, Sequence s) + return renderables; + } + + static IEnumerable DrawZapWandering(WorldRenderer wr, PPos from, PPos to, Sequence s) { var z = float2.Zero; /* hack */ var dist = to - from; @@ -76,22 +93,22 @@ namespace OpenRA.Mods.RA.Effects var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; var p2 = from.ToFloat2() + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; - renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1)); - renderables.AddRange(DrawZap(p1, p2, s, out p2)); - renderables.AddRange(DrawZap(p2, to.ToFloat2(), s, out z)); + renderables.AddRange(DrawZap(wr, from.ToFloat2(), p1, s, out p1)); + renderables.AddRange(DrawZap(wr, p1, p2, s, out p2)); + renderables.AddRange(DrawZap(wr, p2, to.ToFloat2(), s, out z)); } else { var p1 = from.ToFloat2() + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; - renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1)); - renderables.AddRange(DrawZap(p1, to.ToFloat2(), s, out z)); + renderables.AddRange(DrawZap(wr, from.ToFloat2(), p1, s, out p1)); + renderables.AddRange(DrawZap(wr, p1, to.ToFloat2(), s, out z)); } return renderables; } - static IEnumerable DrawZap(float2 from, float2 to, Sequence s, out float2 p) + static IEnumerable DrawZap(WorldRenderer wr, float2 from, float2 to, Sequence s, out float2 p) { var dist = to - from; var q = new float2(-dist.Y, dist.X); @@ -105,7 +122,7 @@ namespace OpenRA.Mods.RA.Effects .OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First(); rs.Add(new Renderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), - PaletteReference.FromName("effect"), (int)from.Y)); + wr.Palette("effect"), (int)from.Y)); z += new float2(step[0], step[1]); if( rs.Count >= 1000 ) break; From 72a99544917a367e167961dae309ec2734e2a860 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 18:03:44 +1300 Subject: [PATCH 39/67] Simplify PaletteReference interface. --- OpenRA.Game/Graphics/ShroudRenderer.cs | 6 ++-- OpenRA.Game/Graphics/WorldRenderer.cs | 28 ++++--------------- .../Orders/PlaceBuildingOrderGenerator.cs | 2 +- .../SupportPowers/ChronoshiftPower.cs | 2 +- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/OpenRA.Game/Graphics/ShroudRenderer.cs b/OpenRA.Game/Graphics/ShroudRenderer.cs index 466e90da2d..4d467b67dd 100644 --- a/OpenRA.Game/Graphics/ShroudRenderer.cs +++ b/OpenRA.Game/Graphics/ShroudRenderer.cs @@ -149,14 +149,14 @@ namespace OpenRA.Graphics { s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - pal.RowIndex(wr), + pal.Index, new float2(Game.CellSize * (i - starti), Game.CellSize)); starti = i + 1; } s[i, j].DrawAt( Game.CellSize * new float2(i, j), - pal.RowIndex(wr)); + pal.Index); starti = i + 1; last = s[i, j]; } @@ -164,7 +164,7 @@ namespace OpenRA.Graphics if (starti < clip.Right) s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - pal.RowIndex(wr), + pal.Index, new float2(Game.CellSize * (clip.Right - starti), Game.CellSize)); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index fb66548ffd..ff2e750a0b 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -19,28 +19,12 @@ namespace OpenRA.Graphics { public class PaletteReference { - string name; - int index; + public readonly string Name; + public readonly int Index; public PaletteReference(string name, int index) { - this.name = name; - this.index = index; - } - - public static PaletteReference FromName(string name) - { - return new PaletteReference(name, -1); - } - - public int RowIndex(WorldRenderer wr) - { - if (index == -1) - { - // Too spammy to enable by default - //Log.Write("perf", "Late resolution of palette reference {0}", name); - index = wr.GetPaletteIndex(name); - } - return index; + Name = name; + Index = index; } } @@ -113,7 +97,7 @@ namespace OpenRA.Graphics terrainRenderer.Draw(this, Game.viewport); foreach (var a in world.traitDict.ActorsWithTraitMultiple(world)) foreach (var r in a.Trait.RenderAsTerrain(this, a.Actor)) - r.Sprite.DrawAt(r.Pos, r.Palette.RowIndex(this), r.Scale); + r.Sprite.DrawAt(r.Pos, r.Palette.Index, r.Scale); foreach (var a in world.Selection.Actors) if (!a.Destroyed) @@ -126,7 +110,7 @@ namespace OpenRA.Graphics world.OrderGenerator.RenderBeforeWorld(this, world); foreach (var image in SpritesToRender()) - image.Sprite.DrawAt(image.Pos, image.Palette.RowIndex(this), image.Scale); + image.Sprite.DrawAt(image.Pos, image.Palette.Index, image.Scale); // added for contrails foreach (var a in world.ActorsWithTrait()) diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 5dde8116ac..d630adba81 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Orders foreach (var r in preview) r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, - r.Palette.RowIndex(wr), + r.Palette.Index, r.Scale*r.Sprite.size); var res = world.WorldActor.Trait(); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 5875c93a51..b4459b961b 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -245,7 +245,7 @@ namespace OpenRA.Mods.RA var targetCell = unit.Location + (xy - sourceLocation); foreach (var r in unit.Render(wr)) r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), - r.Palette.RowIndex(wr), + r.Palette.Index, r.Scale*r.Sprite.size); } } From 9bc743068a8ba675cdc4f600099f807fdb61d70f Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 18:06:47 +1300 Subject: [PATCH 40/67] Remove WorldRenderer.GetPalette. --- OpenRA.Game/Graphics/WorldRenderer.cs | 11 ++++++----- OpenRA.Game/Traits/World/PlayerColorPalette.cs | 2 +- OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index ff2e750a0b..5ad228d7ed 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -21,10 +21,12 @@ namespace OpenRA.Graphics { public readonly string Name; public readonly int Index; - public PaletteReference(string name, int index) + public readonly Palette Palette; + public PaletteReference(string name, int index, Palette palette) { Name = name; Index = index; + Palette = palette; } } @@ -40,22 +42,21 @@ namespace OpenRA.Graphics { this.world = world; this.palette = Game.modData.Palette; - foreach( var pal in world.traitDict.ActorsWithTraitMultiple( world ) ) + palettes = new Cache(CreatePaletteReference); + foreach (var pal in world.traitDict.ActorsWithTraitMultiple(world)) pal.Trait.InitPalette( this ); terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); - palettes = new Cache(CreatePaletteReference); } PaletteReference CreatePaletteReference(string name) { - return new PaletteReference(name, palette.GetPaletteIndex(name)); + return new PaletteReference(name, palette.GetPaletteIndex(name), palette.GetPalette(name)); } public PaletteReference Palette(string name) { return palettes[name]; } public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } - public Palette GetPalette(string name) { return palette.GetPalette(name); } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } class SpriteComparer : IComparer diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index 1e50140945..0b35c05ddc 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -37,7 +37,7 @@ namespace OpenRA.Traits public void InitPalette( WorldRenderer wr ) { var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName ); - var newpal = new Palette(wr.GetPalette(info.BasePalette), + var newpal = new Palette(wr.Palette(info.BasePalette).Palette, new PlayerColorRemap(info.RemapIndex, owner.ColorRamp)); wr.AddPalette(paletteName, newpal, info.AllowModifiers); } diff --git a/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs index 9b2a144b6d..78562d1236 100755 --- a/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs +++ b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Widgets public override void Initialize(WidgetArgs args) { base.Initialize(args); - preview = worldRenderer.GetPalette(Palette); + preview = worldRenderer.Palette(Palette).Palette; } public override void Tick() From e9665cf9f3e884a8eebd60ba118c672a7d552ae1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 18:10:07 +1300 Subject: [PATCH 41/67] Remove WorldRenderer.GetPaletteIndex. --- OpenRA.Game/Graphics/SpriteRenderer.cs | 4 ++-- OpenRA.Game/Graphics/WorldRenderer.cs | 1 - OpenRA.Game/Traits/World/ResourceLayer.cs | 4 ++-- OpenRA.Game/Traits/World/ResourceType.cs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Graphics/SpriteRenderer.cs b/OpenRA.Game/Graphics/SpriteRenderer.cs index 957eb6f701..b1bba04e3a 100644 --- a/OpenRA.Game/Graphics/SpriteRenderer.cs +++ b/OpenRA.Game/Graphics/SpriteRenderer.cs @@ -49,12 +49,12 @@ namespace OpenRA.Graphics public void DrawSprite(Sprite s, float2 location, WorldRenderer wr, string palette) { - DrawSprite(s, location, wr.GetPaletteIndex(palette), s.size); + DrawSprite(s, location, wr.Palette(palette).Index, s.size); } public void DrawSprite(Sprite s, float2 location, WorldRenderer wr, string palette, float2 size) { - DrawSprite(s, location, wr.GetPaletteIndex(palette), size); + DrawSprite(s, location, wr.Palette(palette).Index, size); } public void DrawSprite(Sprite s, float2 location, int paletteIndex, float2 size) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 5ad228d7ed..442b0001f6 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -56,7 +56,6 @@ namespace OpenRA.Graphics } public PaletteReference Palette(string name) { return palettes[name]; } - public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } class SpriteComparer : IComparer diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 5c1c35ffcf..a9ab4f2bea 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -33,7 +33,7 @@ namespace OpenRA.Traits { hasSetupPalettes = true; foreach (var rt in world.WorldActor.TraitsImplementing()) - rt.info.PaletteIndex = wr.GetPaletteIndex(rt.info.Palette); + rt.info.PaletteRef = wr.Palette(rt.info.Palette); } var clip = Game.viewport.WorldBounds(world); @@ -47,7 +47,7 @@ namespace OpenRA.Traits if (c.image != null) c.image[c.density].DrawAt( new CPos(x, y).ToPPos().ToFloat2(), - c.type.info.PaletteIndex); + c.type.info.PaletteRef.Index); } } diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index c181fdcbcf..62167b1eda 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -26,7 +26,7 @@ namespace OpenRA.Traits public readonly bool AllowUnderActors = false; public Sprite[][] Sprites; - public int PaletteIndex; + public PaletteReference PaletteRef; public PipType PipColor = PipType.Yellow; From 3033eb8be0198f097f6852d1a1fb8e14dc9991f1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 18:51:44 +1300 Subject: [PATCH 42/67] Die with a helpful error if a palette doesn't exist. --- OpenRA.Game/Graphics/WorldRenderer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 442b0001f6..45ba653799 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -52,7 +52,11 @@ namespace OpenRA.Graphics PaletteReference CreatePaletteReference(string name) { - return new PaletteReference(name, palette.GetPaletteIndex(name), palette.GetPalette(name)); + var pal = palette.GetPalette(name); + if (pal == null) + throw new InvalidOperationException("Palette `{0}` does not exist".F(name)); + + return new PaletteReference(name, palette.GetPaletteIndex(name), pal); } public PaletteReference Palette(string name) { return palettes[name]; } From 82426e0e458618783a30dc4f39cbe7600d196d13 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 19:00:35 +1300 Subject: [PATCH 43/67] Move Palette from ModData to WorldRenderer. --- OpenRA.Game/Graphics/CursorProvider.cs | 12 +++++++----- OpenRA.Game/Graphics/TerrainRenderer.cs | 2 +- OpenRA.Game/Graphics/Viewport.cs | 2 +- OpenRA.Game/Graphics/WorldRenderer.cs | 8 +++++++- OpenRA.Game/ModData.cs | 3 --- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 4184facd60..823e231c41 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -19,6 +19,7 @@ namespace OpenRA.Graphics { public static class CursorProvider { + public static Dictionary Palettes { get; private set; } static Dictionary cursors; public static void Initialize(string[] sequenceFiles) @@ -28,13 +29,14 @@ namespace OpenRA.Graphics int[] ShadowIndex = { }; if (sequences.NodesDict.ContainsKey("ShadowIndex")) - { - Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); - ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); - } + { + Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); + ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); + } + Palettes = new Dictionary(); foreach (var s in sequences.NodesDict["Palettes"].Nodes) - Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex), false); + Palettes.Add(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex)); foreach (var s in sequences.NodesDict["Cursors"].Nodes) LoadSequencesForCursor(s.Key, s.Value); diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 573d480cd1..317820217a 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -39,7 +39,7 @@ namespace OpenRA.Graphics int nv = 0; - var terrainPalette = Game.modData.Palette.GetPaletteIndex("terrain"); + var terrainPalette = wr.Palette("terrain").Index; for( int j = map.Bounds.Top; j < map.Bounds.Bottom; j++ ) for( int i = map.Bounds.Left; i < map.Bounds.Right; i++ ) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index f5881d2e1e..4a15d081ac 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -133,7 +133,7 @@ namespace OpenRA.Graphics renderer.SpriteRenderer.DrawSprite(cursorSprite, Viewport.LastMousePos - cursorSequence.Hotspot, - Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette), + wr.Palette(cursorSequence.Palette).Index, cursorSprite.size); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 45ba653799..c590105a92 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -41,11 +41,17 @@ namespace OpenRA.Graphics internal WorldRenderer(World world) { this.world = world; - this.palette = Game.modData.Palette; + palette = new HardwarePalette(); + foreach (var p in CursorProvider.Palettes) + palette.AddPalette(p.Key, p.Value, false); + palettes = new Cache(CreatePaletteReference); foreach (var pal in world.traitDict.ActorsWithTraitMultiple(world)) pal.Trait.InitPalette( this ); + // Generate initial palette texture + palette.Update(new IPaletteModifier[] {}); + terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index c8770da6b5..c614d4604b 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -28,7 +28,6 @@ namespace OpenRA public ILoadScreen LoadScreen = null; public SheetBuilder SheetBuilder; public SpriteLoader SpriteLoader; - public HardwarePalette Palette { get; private set; } public ModData( params string[] mods ) { @@ -51,13 +50,11 @@ namespace OpenRA AvailableMaps = FindMaps(Manifest.Mods); - Palette = new HardwarePalette(); ChromeMetrics.Initialize(Manifest.ChromeMetrics); ChromeProvider.Initialize(Manifest.Chrome); SheetBuilder = new SheetBuilder(TextureChannel.Red); SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder); CursorProvider.Initialize(Manifest.Cursors); - Palette.Update(new IPaletteModifier[] { }); } public Map PrepareMap(string uid) From dddec1ec612b1be09018a08f1dcb5257a86cffe8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 21:37:52 +1300 Subject: [PATCH 44/67] Add INotifyOwnerChanged interface --- OpenRA.Game/Actor.cs | 5 +++++ OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 47232401ee..9dfefe23a7 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -254,10 +254,15 @@ namespace OpenRA { World.AddFrameEndTask(w => { + var oldOwner = Owner; + // momentarily remove from world so the ownership queries don't get confused w.Remove(this); Owner = newOwner; w.Add(this); + + foreach (var t in this.TraitsImplementing()) + t.OnOwnerChanged(this, oldOwner, newOwner); }); } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 9350d0b0ff..4182ebf6a4 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -63,6 +63,7 @@ namespace OpenRA.Traits public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); } + public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } From 3a11aeb43454cde75febd512468b8e69c60c2aed Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 21:57:47 +1300 Subject: [PATCH 45/67] Cache PaletteReference in RenderSimple. --- OpenRA.Game/Traits/Render/RenderSimple.cs | 21 ++++++++++++++++----- OpenRA.Mods.RA/Missions/Allies04Script.cs | 8 +++++--- OpenRA.Mods.RA/Render/RenderSpy.cs | 10 +++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index b9f1ed46bf..34ec41c879 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -33,7 +33,7 @@ namespace OpenRA.Traits } } - public class RenderSimple : IRender, IAutoSelectionSize, ITick + public class RenderSimple : IRender, IAutoSelectionSize, ITick, INotifyOwnerChanged { public Dictionary anims = new Dictionary(); @@ -56,7 +56,6 @@ namespace OpenRA.Traits return Info.Image ?? actor.Name; } - string cachedImage = null; public string GetImage(Actor self) { if (cachedImage != null) @@ -66,6 +65,9 @@ namespace OpenRA.Traits } RenderSimpleInfo Info; + string cachedImage = null; + bool initializePalette = true; + protected PaletteReference palette; public RenderSimple(Actor self, Func baseFacing) { @@ -78,17 +80,26 @@ namespace OpenRA.Traits anim.PlayRepeating("idle"); } - protected PaletteReference Palette(Player p, WorldRenderer wr) + protected virtual string PaletteName(Actor self) { - return wr.Palette(Info.Palette ?? Info.PlayerPalette + p.InternalName); + return Info.Palette ?? Info.PlayerPalette + self.Owner.InternalName; } + protected void UpdatePalette() { initializePalette = true; } + public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); } + public virtual IEnumerable Render(Actor self, WorldRenderer wr) { + if (initializePalette) + { + palette = wr.Palette(PaletteName(self)); + initializePalette = false; + } + foreach (var a in anims.Values) if (a.DisableFunc == null || !a.DisableFunc()) { - Renderable ret = a.Image(self, Palette(self.Owner, wr)); + Renderable ret = a.Image(self, palette); if (Info.Scale != 1f) ret = ret.WithScale(Info.Scale).WithPos(ret.Pos + 0.5f * ret.Sprite.size * (1 - Info.Scale)); yield return ret; diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 2b89f9194d..a667170785 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -496,19 +496,21 @@ namespace OpenRA.Mods.RA.Missions public override object Create(ActorInitializer init) { return new Allies04RenderHijacked(init.self, this); } } - class Allies04RenderHijacked : RenderUnit, IRenderModifier + class Allies04RenderHijacked : RenderUnit { Allies04Hijackable hijackable; + Allies04RenderHijackedInfo info; public Allies04RenderHijacked(Actor self, Allies04RenderHijackedInfo info) : base(self) { + this.info = info; hijackable = self.Trait(); } - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + protected override string PaletteName(Actor self) { - return r.Select(a => a.WithPalette(Palette(hijackable.OldOwner, wr))); + return info.Palette ?? info.PlayerPalette + hijackable.OldOwner.InternalName; } } diff --git a/OpenRA.Mods.RA/Render/RenderSpy.cs b/OpenRA.Mods.RA/Render/RenderSpy.cs index 2d5d6dab23..966401cd68 100755 --- a/OpenRA.Mods.RA/Render/RenderSpy.cs +++ b/OpenRA.Mods.RA/Render/RenderSpy.cs @@ -21,20 +21,23 @@ namespace OpenRA.Mods.RA.Render public override object Create(ActorInitializer init) { return new RenderSpy(init.self, this); } } - class RenderSpy : RenderInfantryProne, IRenderModifier + class RenderSpy : RenderInfantryProne { + RenderSpyInfo info; string disguisedAsSprite; Spy spy; public RenderSpy(Actor self, RenderSpyInfo info) : base(self, info) { + this.info = info; spy = self.Trait(); disguisedAsSprite = spy.disguisedAsSprite; } - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + protected override string PaletteName(Actor self) { - return spy.disguisedAsPlayer != null ? r.Select(a => a.WithPalette(Palette(spy.disguisedAsPlayer, wr))) : r; + var player = spy.disguisedAsPlayer != null ? spy.disguisedAsPlayer : self.Owner; + return info.Palette ?? info.PlayerPalette + player.InternalName; } public override void Tick(Actor self) @@ -46,6 +49,7 @@ namespace OpenRA.Mods.RA.Render anim.ChangeImage(disguisedAsSprite, "stand"); else anim.ChangeImage(GetImage(self), "stand"); + UpdatePalette(); } base.Tick(self); } From bec29d81c551b0b7ca527c6afdec0fe724dea291 Mon Sep 17 00:00:00 2001 From: psydev Date: Mon, 25 Feb 2013 16:05:11 -0800 Subject: [PATCH 46/67] cnc-structure sequences tickrate fixed Strucutre animations were too fast in many cases. These values seem to match up correctly to C&C 95. Obelisk - Have not yet fixed (will do so when I fix how it fires) SAM site - Someone may later decide to speed up how fast it pops up, for gameplay purposes --- mods/cnc/sequences/structures.yaml | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mods/cnc/sequences/structures.yaml b/mods/cnc/sequences/structures.yaml index d815088349..651805546d 100644 --- a/mods/cnc/sequences/structures.yaml +++ b/mods/cnc/sequences/structures.yaml @@ -5,11 +5,11 @@ fact: idle: Start: 0 Length: 4 - Tick: 80 + Tick: 100 damaged-idle: Start: 24 Length: 4 - Tick: 80 + Tick: 100 damaged-build: Start: 28 Length: 20 @@ -23,14 +23,14 @@ nuke: idle: Start: 0 Length: 4 - Tick: 400 + Tick: 1000 damaged-idle: Start: 4 Length: 4 - Tick: 400 + Tick: 1000 dead: Start: 8 - Tick: 400 + Tick: 1000 make: nukemake Start: 0 Length: * @@ -39,11 +39,11 @@ proc: idle: Start: 0 Length: 6 - Tick: 60 + Tick: 120 damaged-idle: Start: 30 Length: 6 - Tick: 60 + Tick: 120 dead: Start: 60 make: procmake @@ -84,11 +84,14 @@ pyle: idle: Start: 0 Length: 10 + Tick: 100 damaged-idle: Start: 10 Length: 10 + Tick: 100 dead: Start: 20 + Tick: 100 make: pylemake Start: 0 Length: * @@ -139,11 +142,11 @@ hq: idle: Start: 0 Length: 16 - Tick: 200 + Tick: 100 damaged-idle: Start: 16 Length: 16 - Tick: 200 + Tick: 100 dead: Start: 32 make: hqmake @@ -154,11 +157,11 @@ nuk2: idle: Start: 0 Length: 4 - Tick: 400 + Tick: 1000 damaged-idle: Start: 4 Length: 4 - Tick: 400 + Tick: 1000 dead: Start: 8 make: nuk2make @@ -173,9 +176,11 @@ hpad: active: Start: 1 Length: 6 + Tick: 100 damaged-active: Start: 8 Length: 6 + Tick: 100 dead: Start: 14 make: hpadmake @@ -203,11 +208,11 @@ eye: idle: Start: 0 Length: 16 - Tick: 200 + Tick: 100 damaged-idle: Start: 16 Length: 16 - Tick: 200 + Tick: 100 dead: Start: 32 make: eyemake From 81c8f0360f1cb0905a60e29a05650abd7ee2e465 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Tue, 26 Feb 2013 18:08:55 +1300 Subject: [PATCH 47/67] Let's not crash if WeaponInfo.Report[] is empty --- OpenRA.Mods.RA/CarpetBomb.cs | 5 +++-- OpenRA.Mods.RA/Combat.cs | 2 +- OpenRA.Mods.RA/Weapon.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index 1e9473f972..a6162d66c7 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -8,6 +8,7 @@ */ #endregion +using System.Linq; using OpenRA.GameRules; using OpenRA.Traits; @@ -56,7 +57,7 @@ namespace OpenRA.Mods.RA self.World.Add(args.weapon.Projectile.Create(args)); - if (args.weapon.Report != null) + if (args.weapon.Report != null && args.weapon.Report.Any()) Sound.Play(args.weapon.Report.Random(self.World.SharedRandom) + ".aud", self.CenterLocation); } } diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index f880f01a12..37e9ea0263 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA facing = 0 }; - if (args.weapon.Report != null) + if (args.weapon.Report != null && args.weapon.Report.Any()) Sound.Play(args.weapon.Report.Random(attacker.World.SharedRandom) + ".aud", pos); DoImpacts(args); diff --git a/OpenRA.Mods.RA/Weapon.cs b/OpenRA.Mods.RA/Weapon.cs index ecee503ad6..a22ae8c82f 100644 --- a/OpenRA.Mods.RA/Weapon.cs +++ b/OpenRA.Mods.RA/Weapon.cs @@ -148,7 +148,7 @@ namespace OpenRA.Mods.RA if (projectile != null) self.World.Add(projectile); - if (args.weapon.Report != null) + if (args.weapon.Report != null && args.weapon.Report.Any()) Sound.Play(args.weapon.Report.Random(self.World.SharedRandom) + ".aud", self.CenterLocation); } }); From 817e6f1ec16fdb37e648a128bc93ff65f62f948b Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Wed, 27 Feb 2013 17:57:53 +1300 Subject: [PATCH 48/67] Have Tanya not shoot her pistols at buildings, and have her shoot pistols at barrels instead of using C4 on them --- OpenRA.Mods.RA/C4Demolition.cs | 9 ++++++--- mods/cnc/rules/defaults.yaml | 2 ++ mods/d2k/rules/defaults.yaml | 3 ++- mods/ra/maps/allies-01/map.yaml | 2 +- mods/ra/maps/allies-02/map.yaml | 2 +- mods/ra/rules/civilian.yaml | 6 ++++++ mods/ra/rules/defaults.yaml | 2 ++ mods/ra/weapons.yaml | 4 ++-- 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.RA/C4Demolition.cs b/OpenRA.Mods.RA/C4Demolition.cs index 74a444a465..24c2e29483 100644 --- a/OpenRA.Mods.RA/C4Demolition.cs +++ b/OpenRA.Mods.RA/C4Demolition.cs @@ -10,8 +10,8 @@ using System.Collections.Generic; using System.Drawing; +using OpenRA.Effects; using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Orders; using OpenRA.Traits; @@ -35,12 +35,12 @@ namespace OpenRA.Mods.RA public IEnumerable Orders { - get { yield return new UnitTraitOrderTargeter( "C4", 6, "c4", true, false ); } + get { yield return new UnitTraitOrderTargeter("C4", 6, "c4", true, false); } } public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) { - if( order.OrderID == "C4" ) + if (order.OrderID == "C4") return new Order("C4", self, queued) { TargetActor = target.Actor }; return null; @@ -65,4 +65,7 @@ namespace OpenRA.Mods.RA return (order.OrderString == "C4") ? "Attack" : null; } } + + class C4DemolishableInfo : TraitInfo { } + class C4Demolishable { } } diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index d92fb812af..45425a7fad 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -249,6 +249,7 @@ Sellable: Capturable: CapturableBar: + C4Demolishable: ^CivBuilding: Inherits: ^Building @@ -336,6 +337,7 @@ RelativeToTopLeft: yes AutoTargetIgnore: Sellable: + C4Demolishable: ^Tree: Tooltip: diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index 59861909bb..17715b1708 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -256,4 +256,5 @@ ProximityCaptor: Types:Building Sellable: - GivesBounty: \ No newline at end of file + GivesBounty: + C4Demolishable: \ No newline at end of file diff --git a/mods/ra/maps/allies-01/map.yaml b/mods/ra/maps/allies-01/map.yaml index d30a9406bf..3c66ce8b5c 100644 --- a/mods/ra/maps/allies-01/map.yaml +++ b/mods/ra/maps/allies-01/map.yaml @@ -359,7 +359,7 @@ Rules: Range: 0 E7: AutoTarget: - InitialStance: ReturnFire + InitialStance: Defend Passenger: Weight: 0 EINSTEIN: diff --git a/mods/ra/maps/allies-02/map.yaml b/mods/ra/maps/allies-02/map.yaml index efa6b44634..8099ac25f9 100644 --- a/mods/ra/maps/allies-02/map.yaml +++ b/mods/ra/maps/allies-02/map.yaml @@ -2875,7 +2875,7 @@ Rules: Damage: 0 E7: AutoTarget: - InitialStance: ReturnFire + InitialStance: Defend Passenger: Weight: 0 Buildable: diff --git a/mods/ra/rules/civilian.yaml b/mods/ra/rules/civilian.yaml index 6ce0cc9698..3afe7f176c 100644 --- a/mods/ra/rules/civilian.yaml +++ b/mods/ra/rules/civilian.yaml @@ -241,6 +241,9 @@ BARL: Tooltip: Name: Explosive Barrel AutoTargetIgnore: + Armor: + Type: Light + -C4Demolishable: BRL3: Inherits: ^TechBuilding @@ -253,6 +256,9 @@ BRL3: Tooltip: Name: Explosive Barrel AutoTargetIgnore: + Armor: + Type: Light + -C4Demolishable: MISS: Inherits: ^TechBuilding diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 390cdd7ed2..1ace9e750c 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -217,6 +217,7 @@ AcceptsSupplies: GivesBounty: UpdatesPlayerStatistics: + C4Demolishable: ^Wall: AppearsOnRadar: @@ -250,6 +251,7 @@ Types:Wall Sellable: UpdatesPlayerStatistics: + C4Demolishable: ^TechBuilding: Inherits: ^Building diff --git a/mods/ra/weapons.yaml b/mods/ra/weapons.yaml index b67eec369e..d015aefda3 100644 --- a/mods/ra/weapons.yaml +++ b/mods/ra/weapons.yaml @@ -7,11 +7,11 @@ Colt45: Warhead: Spread: 1 Versus: - Wood: 5% + Wood: 0% Light: 5% Heavy: 5% Cybernetic: 5% - Concrete: 5% + Concrete: 0% Explosion: piff InfDeath: 2 Damage: 50 From 6bd3de8ec801b4ab61b95caca1840c5b61336ebb Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 28 Feb 2013 09:02:03 +1300 Subject: [PATCH 49/67] Fixed #2696: Sequences: Allow stride to be specified. This allows you to use just some of the frames of an animation which has multiple facings. For example, if you have an animation which has 8 facings, and 6 frames of animation per facing, but you only want to show 3 of them, you can now do: Facings: 8 Length: 3 # the number of frames in each facing to actually use Stride: 6 # the number of frames per facing present in the SHP If Stride is not specified, it defaults to Length, which is the old behavior. It is an error to specify a stride less than the length -- this would produce overlapping facings, or weirder. --- OpenRA.Game/Graphics/Sequence.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Graphics/Sequence.cs b/OpenRA.Game/Graphics/Sequence.cs index d8a0bfeceb..c4ce07357c 100644 --- a/OpenRA.Game/Graphics/Sequence.cs +++ b/OpenRA.Game/Graphics/Sequence.cs @@ -18,12 +18,13 @@ namespace OpenRA.Graphics public class Sequence { readonly Sprite[] sprites; - readonly int start, length, facings, tick; + readonly int start, length, stride, facings, tick; public readonly string Name; public int Start { get { return start; } } public int End { get { return start + length; } } public int Length { get { return length; } } + public int Stride { get { return stride; } } public int Facings { get { return facings; } } public int Tick { get { return tick; } } @@ -43,6 +44,10 @@ namespace OpenRA.Graphics else length = int.Parse(d["Length"].Value); + if (d.ContainsKey("Stride")) + stride = int.Parse(d["Stride"].Value); + else + stride = length; if(d.ContainsKey("Facings")) facings = int.Parse(d["Facings"].Value); @@ -54,10 +59,15 @@ namespace OpenRA.Graphics else tick = 40; - if (start < 0 || start + facings * length > sprites.Length) + if (length > stride) + throw new InvalidOperationException( + "{0}: Sequence {1}.{2}: Length must be <= stride" + .F(info.Nodes[0].Location, unit, name)); + + if (start < 0 || start + facings * stride > sprites.Length) throw new InvalidOperationException( "{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist" - .F(unit, name, start, start + facings * length - 1, srcOverride ?? unit, sprites.Length - 1, + .F(unit, name, start, start + facings * stride - 1, srcOverride ?? unit, sprites.Length - 1, info.Nodes[0].Location)); } @@ -69,7 +79,7 @@ namespace OpenRA.Graphics public Sprite GetSprite(int frame, int facing) { var f = Traits.Util.QuantizeFacing( facing, facings ); - return sprites[ (f * length) + ( frame % length ) + start ]; + return sprites[ (f * stride) + ( frame % length ) + start ]; } } } From 7e1ee0e2e5b1103858a82353254af2d1afea5272 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 1 Mar 2013 09:28:13 +1300 Subject: [PATCH 50/67] fix #2661: desyncs with shroud/exploration cheats --- OpenRA.Game/Traits/Player/DeveloperMode.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Traits/Player/DeveloperMode.cs b/OpenRA.Game/Traits/Player/DeveloperMode.cs index 446fd6b3cf..85bdbc79ad 100644 --- a/OpenRA.Game/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Game/Traits/Player/DeveloperMode.cs @@ -76,8 +76,7 @@ namespace OpenRA.Traits case "DevShroud": { DisableShroud ^= true; - if (self.World.LocalPlayer == self.Owner) - self.World.RenderedShroud.Disabled = DisableShroud; + self.Owner.Shroud.Disabled = DisableShroud; break; } case "DevPathDebug": @@ -87,8 +86,7 @@ namespace OpenRA.Traits } case "DevGiveExploration": { - if (self.World.LocalPlayer == self.Owner) - self.World.LocalPlayer.Shroud.ExploreAll(self.World); + self.Owner.Shroud.ExploreAll(self.World); break; } case "DevUnlimitedPower": From 0085ac130b64c8104940a0cb7a8e300652f02b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 11 Feb 2013 20:43:36 +0100 Subject: [PATCH 51/67] use PVecFloat in Combat sub-routines --- OpenRA.Mods.RA/Combat.cs | 22 +++++++++++----------- OpenRA.Mods.RA/Effects/Contrail.cs | 2 +- OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs | 2 +- OpenRA.Mods.RA/Weapon.cs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 37e9ea0263..b21034c93b 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -208,18 +208,18 @@ namespace OpenRA.Mods.RA return false; } - static float2 GetRecoil(Actor self, float recoil) + static PVecFloat GetRecoil(Actor self, float recoil) { if (!self.HasTrait()) - return float2.Zero; + return PVecFloat.Zero; var facing = self.Trait().turretFacing; var localRecoil = new float2(0, recoil); // vector in turret-space. - return Util.RotateVectorByFacing(localRecoil, facing, .7f); + return (PVecFloat)Util.RotateVectorByFacing(localRecoil, facing, .7f); } - public static PVecInt GetTurretPosition(Actor self, IFacing facing, Turret turret) + public static PVecFloat GetTurretPosition(Actor self, IFacing facing, Turret turret) { if (facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ @@ -228,23 +228,23 @@ namespace OpenRA.Mods.RA var bodyFacing = facing.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); - return (PVecInt) ((PVecFloat)(Util.RotateVectorByFacing(turret.UnitSpacePosition.ToFloat2(), quantizedFacing, .7f) - + GetRecoil(self, turret.Recoil)) - + turret.ScreenSpacePosition); + return (PVecFloat)Util.RotateVectorByFacing(turret.UnitSpacePosition.ToFloat2(), quantizedFacing, .7f) + + GetRecoil(self, turret.Recoil) + + (PVecFloat)turret.ScreenSpacePosition.ToFloat2(); } - static PVecInt GetUnitspaceBarrelOffset(Actor self, IFacing facing, Turret turret, Barrel barrel) + static PVecFloat GetUnitspaceBarrelOffset(Actor self, IFacing facing, Turret turret, Barrel barrel) { var turreted = self.TraitOrDefault(); if (turreted == null && facing == null) - return PVecInt.Zero; + return PVecFloat.Zero; var turretFacing = turreted != null ? turreted.turretFacing : facing.Facing; - return (PVecInt)(PVecFloat)Util.RotateVectorByFacing(barrel.TurretSpaceOffset.ToFloat2(), turretFacing, .7f); + return (PVecFloat)Util.RotateVectorByFacing(barrel.TurretSpaceOffset.ToFloat2(), turretFacing, .7f); } // gets the screen-space position of a barrel. - public static PVecInt GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) + public static PVecFloat GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) { return GetTurretPosition(self, facing, turret) + barrel.ScreenSpaceOffset + GetUnitspaceBarrelOffset(self, facing, turret, barrel); diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs index 170da8bdc3..1fa6602b5c 100755 --- a/OpenRA.Mods.RA/Effects/Contrail.cs +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - Combat.GetTurretPosition(self, facing, contrailTurret)); + history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - (PVecInt)Combat.GetTurretPosition(self, facing, contrailTurret).ToInt2()); } public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(self); } diff --git a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs index df6ac6f6bb..70419e5d24 100644 --- a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA { var facing = self.Trait(); var altitude = new PVecInt(0, move.Altitude); - position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret)); + position = (self.CenterLocation - (PVecInt)Combat.GetTurretPosition(self, facing, smokeTurret).ToInt2()); if (self.World.RenderedShroud.IsVisible(position.ToCPos())) self.World.AddFrameEndTask( diff --git a/OpenRA.Mods.RA/Weapon.cs b/OpenRA.Mods.RA/Weapon.cs index a22ae8c82f..606df63f75 100644 --- a/OpenRA.Mods.RA/Weapon.cs +++ b/OpenRA.Mods.RA/Weapon.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA firedBy = self, target = target, - src = (self.CenterLocation + Combat.GetBarrelPosition(self, facing, Turret, barrel)), + src = (self.CenterLocation + (PVecInt)Combat.GetBarrelPosition(self, facing, Turret, barrel).ToInt2()), srcAltitude = move != null ? move.Altitude : 0, dest = target.CenterLocation, destAltitude = destMove != null ? destMove.Altitude : 0, From 2bc75706742fafb81c5df2edd3605e88a38d82a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 11:54:53 +0100 Subject: [PATCH 52/67] remove conditional compile left-over junk --- OpenRA.Game/Actor.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 9dfefe23a7..8bd5730a10 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -143,22 +143,14 @@ namespace OpenRA var si = Info.Traits.GetOrDefault(); if (si != null && si.Bounds != null && si.Bounds.Length > 2) { -#if true loc += new PVecInt(si.Bounds[2], si.Bounds[3]); -#else - loc.X += si.Bounds[2]; - loc.Y += si.Bounds[3]; -#endif } var move = Move.Value; if (move != null) { -#if true loc -= new PVecInt(0, move.Altitude); -#else - loc.Y -= move.Altitude; -#endif + if (useAltitude) size = new PVecInt(size.X, size.Y + move.Altitude); } From 05b6b59dadbf52cf52955712353c0118ab990313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 12:56:14 +0100 Subject: [PATCH 53/67] use Combat.IsInRange instead of float2.WithinEpsilon for heli --- OpenRA.Mods.RA/Air/HeliAttack.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/Air/HeliAttack.cs b/OpenRA.Mods.RA/Air/HeliAttack.cs index 34c446d6fb..2bad762b79 100755 --- a/OpenRA.Mods.RA/Air/HeliAttack.cs +++ b/OpenRA.Mods.RA/Air/HeliAttack.cs @@ -38,13 +38,12 @@ namespace OpenRA.Mods.RA.Air } var attack = self.Trait(); - var range = attack.GetMaximumRange() * 0.625f; var dist = target.CenterLocation - self.CenterLocation; var desiredFacing = Util.GetFacing(dist, aircraft.Facing); aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); - if( !float2.WithinEpsilon( float2.Zero, dist.ToFloat2(), range * Game.CellSize ) ) + if (!Combat.IsInRange(self.CenterLocation, attack.GetMaximumRange(), target)) aircraft.TickMove(PSubPos.PerPx * aircraft.MovementSpeed, desiredFacing); attack.DoAttack( self, target ); From a59621910e7926c3c146c6e555dbb27a1d9e7e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 15:25:16 +0100 Subject: [PATCH 54/67] avoid floating point operation with heli fly int coordinates --- OpenRA.Mods.RA/Air/HeliFly.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Air/HeliFly.cs b/OpenRA.Mods.RA/Air/HeliFly.cs index a77236df9a..b0962801dd 100755 --- a/OpenRA.Mods.RA/Air/HeliFly.cs +++ b/OpenRA.Mods.RA/Air/HeliFly.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Air } var dist = Dest - aircraft.PxPosition; - if (float2.WithinEpsilon(float2.Zero, dist.ToFloat2(), 2)) + if (Math.Abs(dist.X) < 2 && Math.Abs(dist.Y) < 2) { aircraft.SubPxPosition = Dest.ToPSubPos(); return NextActivity; From 233088077b6d4c3b3d6c7f41f96189153b3db3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 16:07:04 +0100 Subject: [PATCH 55/67] don't convert to float2 in ReturnToBase as it was int2 before --- OpenRA.Mods.RA/Air/ReturnToBase.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Air/ReturnToBase.cs b/OpenRA.Mods.RA/Air/ReturnToBase.cs index e2b4285890..1244371364 100755 --- a/OpenRA.Mods.RA/Air/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Air/ReturnToBase.cs @@ -56,17 +56,17 @@ namespace OpenRA.Mods.RA.Air var altitude = aircraft.Altitude; if (altitude == 0) altitude = self.Info.Traits.Get().CruiseAltitude; - var approachStart = landPos.ToFloat2() - new float2(altitude * speed, 0); + var approachStart = landPos.ToInt2() - new float2(altitude * speed, 0); var turnRadius = (128f / self.Info.Traits.Get().ROT) * speed / (float)Math.PI; /* work out the center points */ var fwd = -float2.FromAngle(aircraft.Facing / 128f * (float)Math.PI); var side = new float2(-fwd.Y, fwd.X); /* rotate */ var sideTowardBase = new[] { side, -side } - .OrderBy(a => float2.Dot(a, self.CenterLocation.ToFloat2() - approachStart)) + .OrderBy(a => float2.Dot(a, self.CenterLocation.ToInt2() - approachStart)) .First(); - var c1 = self.CenterLocation.ToFloat2() + turnRadius * sideTowardBase; + var c1 = self.CenterLocation.ToInt2() + turnRadius * sideTowardBase; var c2 = approachStart + new float2(0, turnRadius * Math.Sign(self.CenterLocation.Y - approachStart.Y)); // above or below start point /* work out tangent points */ From 4b2f08f21f8001532a2160322e891107de410618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 16:15:06 +0100 Subject: [PATCH 56/67] convert start to int2 as CellContaining() spit that out before --- OpenRA.Mods.RA/Minelayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index 7b76ec7f44..8890d335c4 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA var p = end - start; var q = new float2(p.Y, -p.X); q = (start != end) ? (1 / q.Length) * q : new float2(1, 0); - var c = -float2.Dot(q, start.ToFloat2()); + var c = -float2.Dot(q, start.ToInt2()); /* return all points such that |ax + by + c| < depth */ From 3d8d1161061687fa0b04b7cd7619bf045278f276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 27 Feb 2013 18:32:32 +0100 Subject: [PATCH 57/67] fix NullReferenceException in UnHideActor --- OpenRA.Game/Traits/World/Shroud.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 751f80c8fb..6392caef4c 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -137,6 +137,9 @@ namespace OpenRA.Traits if (a.Owner.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally) return; + if (v == null) + return; + foreach (var p in v.vis) foreach (var q in FindVisibleTiles(a.World, p, range)) foggedCells[q.X, q.Y] = exploredCells[q.X, q.Y]; From b2c867bf2bcaf42a2e98aa3b5290fc44ad4c08dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 16:20:31 +0100 Subject: [PATCH 58/67] remove custom build time for tiberium refinery - this can be enabled again in cnc-classic - needs a fix as it causes desyncs --- mods/cnc/rules/structures.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 406943174d..8077a05040 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -123,8 +123,6 @@ PROC: Bounds: 73,72 CustomSellValue: Value: 300 - CustomBuildTimeValue: - Value: 80 FreeActor: Actor: HARV InitialActivity: FindResources From fc5350c9f8a6eff9bbc99c1cfe82a0f7dea21e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 1 Mar 2013 10:30:41 +0100 Subject: [PATCH 59/67] fix #2663 crash when displaying the spawn tooltip in cnc don't hard-code ra border chrome in shared lobbyutils --- OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index d752b16959..c04e295525 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -183,9 +183,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == spawnPoint); if (client != null) { - var rect = new Rectangle(position.X, position.Y, Game.Renderer.Fonts["Regular"].Measure(client.Name).X + 15, 25); - WidgetUtils.DrawPanel("dialog4", rect); - Game.Renderer.Fonts["Regular"].DrawText(client.Name, position + new int2(5, 5), Color.White); + Game.Renderer.Fonts["Bold"].DrawTextWithContrast(client.Name, position + new int2(5, 5), Color.White, Color.Black, 1); } } } From dd476bbf5c39f7bb44fbf9030c807f9f9204d2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 20:52:48 +0100 Subject: [PATCH 60/67] add the total number of values extracted from RNG to sync report --- OpenRA.FileFormats/Thirdparty/Random.cs | 2 ++ OpenRA.Game/Network/SyncReport.cs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenRA.FileFormats/Thirdparty/Random.cs b/OpenRA.FileFormats/Thirdparty/Random.cs index 8ef212f0c3..05aca361b2 100644 --- a/OpenRA.FileFormats/Thirdparty/Random.cs +++ b/OpenRA.FileFormats/Thirdparty/Random.cs @@ -20,6 +20,7 @@ namespace OpenRA.Thirdparty int index = 0; public int Last; + public int TotalCount = 0; public Random() : this(Environment.TickCount) { } @@ -41,6 +42,7 @@ namespace OpenRA.Thirdparty y ^= y >> 18; index = (index + 1) % 624; + TotalCount++; Last = (int)(y % int.MaxValue); return Last; } diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index f060b8ccf6..a5d7f966ad 100755 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -36,6 +36,7 @@ namespace OpenRA.Network { report.Frame = orderManager.NetFrameNumber; report.SyncedRandom = orderManager.world.SharedRandom.Last; + report.TotalCount = orderManager.world.SharedRandom.TotalCount; report.Traits.Clear(); foreach (var a in orderManager.world.ActorsWithTrait()) { @@ -58,7 +59,7 @@ namespace OpenRA.Network if (r.Frame == frame) { Log.Write("sync", "Sync for net frame {0} -------------", r.Frame); - Log.Write("sync", "SharedRandom: "+r.SyncedRandom); + Log.Write("sync", "SharedRandom: {0} (#{1})", r.SyncedRandom, r.TotalCount); Log.Write("sync", "Synced Traits:"); foreach (var a in r.Traits) Log.Write("sync", "\t {0} {1} {2} {3} ({4})".F( @@ -77,6 +78,7 @@ namespace OpenRA.Network { public int Frame; public int SyncedRandom; + public int TotalCount; public List Traits = new List(); } From 0b493bcb093ffa0086f1824fdca3a5169a0dbfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 21:51:29 +0100 Subject: [PATCH 61/67] remove redundant int to int conversion in rendered circles --- OpenRA.Mods.RA/RenderRangeCircle.cs | 2 +- OpenRA.Mods.RA/RenderShroudCircle.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/RenderRangeCircle.cs b/OpenRA.Mods.RA/RenderRangeCircle.cs index 10e9192681..d1b6642d39 100644 --- a/OpenRA.Mods.RA/RenderRangeCircle.cs +++ b/OpenRA.Mods.RA/RenderRangeCircle.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircle( Color.FromArgb(128, Color.Yellow), - self.CenterLocation.ToFloat2(), (int)self.Trait().GetMaximumRange()); + self.CenterLocation.ToFloat2(), self.Trait().GetMaximumRange()); } } } diff --git a/OpenRA.Mods.RA/RenderShroudCircle.cs b/OpenRA.Mods.RA/RenderShroudCircle.cs index 7ed26059a2..02c9a90bde 100644 --- a/OpenRA.Mods.RA/RenderShroudCircle.cs +++ b/OpenRA.Mods.RA/RenderShroudCircle.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircle( Color.FromArgb(128, Color.Cyan), - self.CenterLocation.ToFloat2(), (int)self.Info.Traits.Get().Range); + self.CenterLocation.ToFloat2(), self.Info.Traits.Get().Range); } } } From 793dfa57481fd9f0e61aca72af8e59d7ce592181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 25 Feb 2013 22:20:17 +0100 Subject: [PATCH 62/67] don't convert cell size to float for bullet inaccuracy change it back to int / int / float from int / float / float was int / int / float before --- OpenRA.Mods.RA/Effects/Bullet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index 7820e840ea..19a1b87a26 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Effects if (info.Inaccuracy > 0) { - var factor = ((Args.dest - Args.src).Length / (float)Game.CellSize) / args.weapon.Range; + var factor = ((Args.dest - Args.src).Length / Game.CellSize) / (float)args.weapon.Range; Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); } From 47075e1cd051ddf9c5dcb02f0017cf678783836f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 1 Mar 2013 10:53:41 +0100 Subject: [PATCH 63/67] generate random numbers as floats as they get converted from double before use anyway --- OpenRA.FileFormats/Thirdparty/Random.cs | 2 +- OpenRA.Game/WorldUtils.cs | 2 +- OpenRA.Mods.RA/AutoTarget.cs | 2 +- OpenRA.Mods.RA/CrateDrop.cs | 2 +- OpenRA.Mods.RA/CrateSpawner.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenRA.FileFormats/Thirdparty/Random.cs b/OpenRA.FileFormats/Thirdparty/Random.cs index 05aca361b2..5bc9d5797a 100644 --- a/OpenRA.FileFormats/Thirdparty/Random.cs +++ b/OpenRA.FileFormats/Thirdparty/Random.cs @@ -49,7 +49,7 @@ namespace OpenRA.Thirdparty public int Next(int low, int high) { return low + Next() % (high - low); } public int Next(int high) { return Next() % high; } - public double NextDouble() { return Math.Abs(Next() / (double)0x7fffffff); } + public float NextFloat() { return Math.Abs(Next() / (float)0x7fffffff); } void Generate() { diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index ec5ce9559c..3fb087a324 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -127,7 +127,7 @@ namespace OpenRA public static float Gauss1D(this Thirdparty.Random r, int samples) { - return Exts.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f) + return Exts.MakeArray(samples, _ => r.NextFloat() * 2 - 1f) .Sum() / samples; } diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index 4725eeb837..7a3f5d936a 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA { var info = self.Info.Traits.Get(); nextScanTime = (int)(25 * (info.ScanTimeAverage + - (self.World.SharedRandom.NextDouble() * 2 - 1) * info.ScanTimeSpread)); + (self.World.SharedRandom.NextFloat() * 2 - 1) * info.ScanTimeSpread)); var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range)); diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index 4a4708e90b..7be813ba3c 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA void SpawnCrate(Actor self) { - var inWater = self.World.SharedRandom.NextDouble() < Info.WaterChance; + var inWater = self.World.SharedRandom.NextFloat() < Info.WaterChance; var pp = ChooseDropCell(self, inWater, 100); if (pp == null) return; diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index 67f1ea7c21..164aa2ec16 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA void SpawnCrate(Actor self, CrateSpawnerInfo info) { var threshold = 100; - var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; + var inWater = self.World.SharedRandom.NextFloat() < info.WaterChance; for (var n = 0; n < threshold; n++ ) { From b31f830cb1f99d67e6af5ff5f4920c71c9bb19e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 1 Mar 2013 19:10:47 +0100 Subject: [PATCH 64/67] key config settings code cleanup - move label and textfield widget lookup into SetupKeyBinding - fix wonkey indentions - remove explicit private in WorldCommandWidget --- .../Widgets/Logic/SettingsMenuLogic.cs | 54 +++++++------------ OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 10 ++-- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index f3552f2987..5846ddd6ce 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -129,72 +129,50 @@ namespace OpenRA.Mods.RA.Widgets.Logic var specialHotkeyTemplate = specialHotkeyList.Get("SPECIALHOTKEY_TEMPLATE"); var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - pauseKey.Get("FUNCTION").GetText = () => "Pause the game:"; - SetupKeyBinding(pauseKey.Get("HOTKEY"), - () => keyConfig.PauseKey, k => keyConfig.PauseKey = k); + SetupKeyBinding(pauseKey, "Pause the game:", () => keyConfig.PauseKey, k => keyConfig.PauseKey = k); specialHotkeyList.AddChild(pauseKey); var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - viewportToBase.Get("FUNCTION").GetText = () => "Move Viewport to Base:"; - SetupKeyBinding(viewportToBase.Get("HOTKEY"), - () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k); + SetupKeyBinding(viewportToBase, "Move Viewport to Base:", () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k); specialHotkeyList.AddChild(viewportToBase); var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - lastEventKey.Get("FUNCTION").GetText = () => "Move Viewport to Last Event:"; - SetupKeyBinding(lastEventKey.Get("HOTKEY"), - () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); + SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); specialHotkeyList.AddChild(lastEventKey); var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - sellKey.Get("FUNCTION").GetText = () => "Switch to Sell-Cursor:"; - SetupKeyBinding(sellKey.Get("HOTKEY"), - () => keyConfig.SellKey, k => keyConfig.SellKey = k); + SetupKeyBinding(sellKey, "Switch to Sell-Cursor:", () => keyConfig.SellKey, k => keyConfig.SellKey = k); specialHotkeyList.AddChild(sellKey); var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - powerDownKey.Get("FUNCTION").GetText = () => "Switch to Power-Down-Cursor:"; - SetupKeyBinding(powerDownKey.Get("HOTKEY"), - () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k); + SetupKeyBinding(powerDownKey, "Switch to Power-Down-Cursor:", () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k); specialHotkeyList.AddChild(powerDownKey); var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - repairKey.Get("FUNCTION").GetText = () => "Switch to Repair-Cursor:"; - SetupKeyBinding(repairKey.Get("HOTKEY"), - () => keyConfig.RepairKey, k => keyConfig.RepairKey = k); + SetupKeyBinding(repairKey, "Switch to Repair-Cursor:", () => keyConfig.RepairKey, k => keyConfig.RepairKey = k); specialHotkeyList.AddChild(repairKey); var unitCommandHotkeyList = keys.Get("UNITCOMMANDHOTKEY_LIST"); var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get("UNITCOMMANDHOTKEY_TEMPLATE"); var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - attackKey.Get("FUNCTION").GetText = () => "Attack Move:"; - SetupKeyBinding(attackKey.Get("HOTKEY"), - () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k); + SetupKeyBinding(attackKey, "Attack Move:", () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k); unitCommandHotkeyList.AddChild(attackKey); var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - stopKey.Get("FUNCTION").GetText = () => "Stop:"; - SetupKeyBinding(stopKey.Get("HOTKEY"), - () => keyConfig.StopKey, k => keyConfig.StopKey = k); + SetupKeyBinding(stopKey, "Stop:", () => keyConfig.StopKey, k => keyConfig.StopKey = k); unitCommandHotkeyList.AddChild(stopKey); var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - scatterKey.Get("FUNCTION").GetText = () => "Scatter:"; - SetupKeyBinding(scatterKey.Get("HOTKEY"), - () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k); + SetupKeyBinding(scatterKey, "Scatter:", () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k); unitCommandHotkeyList.AddChild(scatterKey); var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - stanceCycleKey.Get("FUNCTION").GetText = () => "Cycle Stance:"; - SetupKeyBinding(stanceCycleKey.Get("HOTKEY"), - () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k); + SetupKeyBinding(stanceCycleKey, "Cycle Stance:", () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k); unitCommandHotkeyList.AddChild(stanceCycleKey); var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {}); - deployKey.Get("FUNCTION").GetText = () => "Deploy:"; - SetupKeyBinding(deployKey.Get("HOTKEY"), - () => keyConfig.DeployKey, k => keyConfig.DeployKey = k); + SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k); unitCommandHotkeyList.AddChild(deployKey); // Debug @@ -276,17 +254,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic return true; } - void SetupKeyBinding(TextFieldWidget textBox, Func getValue, Action setValue) + void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func getValue, Action setValue) { + keyWidget.Get("FUNCTION").GetText = () => description; + + var textBox = keyWidget.Get("HOTKEY"); + textBox.Text = getValue(); textBox.OnLoseFocus = () => { textBox.Text.Trim(); if (textBox.Text.Length == 0) - textBox.Text = getValue(); + textBox.Text = getValue(); else - setValue(textBox.Text); + setValue(textBox.Text); }; textBox.OnEnterKey = () => { textBox.LoseFocus(); return true; }; diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 753529834d..b40b9f6890 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -188,19 +188,19 @@ namespace OpenRA.Mods.RA.Widgets return true; } - private bool PerformSwitchToSellMode () + bool PerformSwitchToSellMode() { - World.ToggleInputMode (); + World.ToggleInputMode(); return true; } - private bool PerformSwitchToPowerDownMode () + bool PerformSwitchToPowerDownMode() { - World.ToggleInputMode (); + World.ToggleInputMode(); return true; } - private bool PerformSwitchToRepairMode () + bool PerformSwitchToRepairMode() { World.ToggleInputMode(); return true; From 8358597fd2d003076dee9a564c7cee718b728c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 1 Mar 2013 21:06:09 +0100 Subject: [PATCH 65/67] render crystals in a different color on the mini-map --- mods/ra/rules/system.yaml | 2 ++ mods/ra/tilesets/desert.yaml | 4 ++++ mods/ra/tilesets/interior.yaml | 4 ++++ mods/ra/tilesets/snow.yaml | 4 ++++ mods/ra/tilesets/temperat.yaml | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index e99790cfe0..36fc421ecf 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -279,6 +279,7 @@ World: PipColor: Yellow AllowedTerrainTypes: Clear,Road AllowUnderActors: false + TerrainType: Ore ResourceType@gem: ResourceType: 2 Palette: player @@ -288,6 +289,7 @@ World: PipColor: Red AllowedTerrainTypes: Clear,Road AllowUnderActors: false + TerrainType: Gems SmudgeLayer@SCORCH: Type:Scorch SmokePercentage:50 diff --git a/mods/ra/tilesets/desert.yaml b/mods/ra/tilesets/desert.yaml index df57060819..1ba9d9a4e8 100644 --- a/mods/ra/tilesets/desert.yaml +++ b/mods/ra/tilesets/desert.yaml @@ -64,6 +64,10 @@ Terrain: Buildable: False AcceptsSmudgeType: Crater, Scorch Color: 148, 128, 96 + TerrainType@Gems: + Type: Gems + AcceptsSmudgeType: Crater, Scorch + Color: 132, 112, 255 Templates: Template@255: diff --git a/mods/ra/tilesets/interior.yaml b/mods/ra/tilesets/interior.yaml index de092f2004..30ddb2b4bb 100644 --- a/mods/ra/tilesets/interior.yaml +++ b/mods/ra/tilesets/interior.yaml @@ -46,6 +46,10 @@ Terrain: Type: Ore AcceptsSmudgeType: Crater, Scorch Color: 148, 128, 96 + TerrainType@Gems: + Type: Gems + AcceptsSmudgeType: Crater, Scorch + Color: 132, 112, 255 Templates: Template@255: diff --git a/mods/ra/tilesets/snow.yaml b/mods/ra/tilesets/snow.yaml index 776964d696..255f14e890 100644 --- a/mods/ra/tilesets/snow.yaml +++ b/mods/ra/tilesets/snow.yaml @@ -47,6 +47,10 @@ Terrain: Type: Ore AcceptsSmudgeType: Crater, Scorch Color: 148, 128, 96 + TerrainType@Gems: + Type: Gems + AcceptsSmudgeType: Crater, Scorch + Color: 132, 112, 255 Templates: Template@255: diff --git a/mods/ra/tilesets/temperat.yaml b/mods/ra/tilesets/temperat.yaml index 4f2c4706c3..17625ef86e 100644 --- a/mods/ra/tilesets/temperat.yaml +++ b/mods/ra/tilesets/temperat.yaml @@ -47,6 +47,10 @@ Terrain: Type: Ore AcceptsSmudgeType: Crater, Scorch Color: 148, 128, 96 + TerrainType@Gems: + Type: Gems + AcceptsSmudgeType: Crater, Scorch + Color: 132, 112, 255 Templates: Template@255: From fb0ce8c06a82eab8b0f0a95148139d386985e1fc Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 2 Mar 2013 10:09:24 +1300 Subject: [PATCH 66/67] Fix crash when an opponent uses Paratroopers. --- OpenRA.Mods.RA/Effects/Parachute.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 9fdb71b549..daf2e9d92e 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -66,6 +66,11 @@ namespace OpenRA.Mods.RA.Effects { var rc = cargo.Render(wr).Select(a => a.WithPos(a.Pos - new float2(0, altitude)) .WithZOffset(a.ZOffset + (int)altitude)); + + // Don't render anything if the cargo is invisible (e.g. under fog) + if (!rc.Any()) + yield break; + foreach (var c in rc) { yield return c.WithPos(location.ToFloat2() - .5f * c.Sprite.size).WithPalette(wr.Palette("shadow")).WithZOffset(0); From 63467cd0007dc648ee88213b51b6482c051ba1d8 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sat, 2 Mar 2013 16:18:09 +1300 Subject: [PATCH 67/67] Revert client colours to their preferred colours after the map is changed to a map which doesn't lock colours. --- OpenRA.Game/Network/Session.cs | 4 +++- OpenRA.Game/Network/UnitOrders.cs | 1 + OpenRA.Game/Server/Server.cs | 2 ++ OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index f911449363..7e63d9ba4a 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -42,7 +42,9 @@ namespace OpenRA.Network public class Client { public int Index; - public ColorRamp ColorRamp; + public ColorRamp PreferredColorRamp; // Color that the client normally uses from settings.yaml. + public ColorRamp ColorRamp; // Actual color that the client is using. + // Usually the same as PreferredColorRamp but can be different on maps with locked colors. public string Country; public int SpawnPoint; public string Name; diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 8f0c4a6bf5..cdd06bb41e 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -119,6 +119,7 @@ namespace OpenRA.Network var info = new Session.Client() { Name = Game.Settings.Player.Name, + PreferredColorRamp = Game.Settings.Player.ColorRamp, ColorRamp = Game.Settings.Player.ColorRamp, Country = "random", SpawnPoint = 0, diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 54eef011f2..478b12085a 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -374,6 +374,8 @@ namespace OpenRA.Server return; if (pr.LockColor) c.ColorRamp = pr.ColorRamp; + else + c.ColorRamp = c.PreferredColorRamp; if (pr.LockRace) c.Country = pr.Race; if (pr.LockSpawn) diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index c2313dfaa8..1530fcb925 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -230,7 +230,7 @@ namespace OpenRA.Mods.RA.Server var hue = (byte)server.Random.Next(255); var sat = (byte)server.Random.Next(255); var lum = (byte)server.Random.Next(51,255); - bot.ColorRamp = new ColorRamp(hue, sat, lum, 10); + bot.ColorRamp = bot.PreferredColorRamp = new ColorRamp(hue, sat, lum, 10); server.lobbyInfo.Clients.Add(bot); } @@ -472,7 +472,7 @@ namespace OpenRA.Mods.RA.Server return true; var ci = parts[1].Split(',').Select(cc => int.Parse(cc)).ToArray(); - targetClient.ColorRamp = new ColorRamp((byte)ci[0], (byte)ci[1], (byte)ci[2], (byte)ci[3]); + targetClient.ColorRamp = targetClient.PreferredColorRamp = new ColorRamp((byte)ci[0], (byte)ci[1], (byte)ci[2], (byte)ci[3]); server.SyncLobbyInfo(); return true; }}