From 59bad96d5fb6f12ce17039d94e42a26938297a40 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 29 Jan 2017 21:02:48 +0000 Subject: [PATCH] Add back homing weapons cheat for D2 Kreator proposed restoring the Descent 2 cheat that grants homing capability to all weapons. This commit implements that proposition, with some changes to the implementation details. Based-on-patch-by: Chris Taylor Requested-by: Chris Taylor --- common/main/fwd-weapon.h | 3 +++ common/main/game.h | 1 + similar/main/game.cpp | 5 +++++ similar/main/gamecntl.cpp | 6 ++++++ similar/main/gameseq.cpp | 8 ++++++++ similar/main/weapon.cpp | 17 +++++++++++++++++ 6 files changed, 40 insertions(+) diff --git a/common/main/fwd-weapon.h b/common/main/fwd-weapon.h index 3d123b1ba..13c53579d 100644 --- a/common/main/fwd-weapon.h +++ b/common/main/fwd-weapon.h @@ -211,6 +211,9 @@ int attempt_to_steal_item(vobjptridx_t objp, vobjptr_t playerobjp); #define SMEGA_ID 40 +void weapons_homing_all(); +void weapons_homing_all_reset(); + extern void rock_the_mine_frame(void); extern void smega_rock_stuff(void); extern void init_smega_detonates(void); diff --git a/common/main/game.h b/common/main/game.h index a272c5169..4ab51c96f 100644 --- a/common/main/game.h +++ b/common/main/game.h @@ -333,6 +333,7 @@ struct game_cheats : prohibit_void_ptr int lamer; int accessory; int bouncyfire; + int homingfire; int killallrobots; int robotskillrobots; int monsterdamage; diff --git a/similar/main/game.cpp b/similar/main/game.cpp index 4a948f993..f30dff921 100644 --- a/similar/main/game.cpp +++ b/similar/main/game.cpp @@ -1149,6 +1149,11 @@ int cheats_enabled() //turns off all cheats & resets cheater flag void game_disable_cheats() { +#if defined(DXX_BUILD_DESCENT_II) + if (cheats.homingfire) + weapons_homing_all_reset(); +#endif + cheats = {}; } diff --git a/similar/main/gamecntl.cpp b/similar/main/gamecntl.cpp index df6cf8276..d0e8f81b4 100644 --- a/similar/main/gamecntl.cpp +++ b/similar/main/gamecntl.cpp @@ -1405,6 +1405,7 @@ constexpr cheat_code cheat_codes[] = { { "rockrgrl", &game_cheats::fullautomap }, { "wildfire", &game_cheats::rapidfire }, { "duddaboo", &game_cheats::bouncyfire }, + { "lpnlizard", &game_cheats::homingfire }, { "imagespace", &game_cheats::robotfiringsuspended }, { "spaniard", &game_cheats::killallrobots }, { "silkwing", &game_cheats::robotskillrobots }, @@ -1639,6 +1640,11 @@ static window_event_result FinalCheats() HUD_init_message(HM_DEFAULT, "Bouncing weapons %s!", cheats.bouncyfire?TXT_ON:TXT_OFF); } + + if (gotcha == &game_cheats::homingfire) + { + HUD_init_message(HM_DEFAULT, "Homing weapons %s!", cheats.homingfire ? (weapons_homing_all(), TXT_ON) : (weapons_homing_all_reset(), TXT_OFF)); + } #endif if (gotcha == &game_cheats::turbo) diff --git a/similar/main/gameseq.cpp b/similar/main/gameseq.cpp index 698cd43f5..a091075e6 100644 --- a/similar/main/gameseq.cpp +++ b/similar/main/gameseq.cpp @@ -1383,6 +1383,14 @@ static window_event_result AdvanceLevel(int secret_flag) #if defined(DXX_BUILD_DESCENT_II) Assert(!secret_flag); + + // Loading a level can write over homing_flag. + // So for simplicity, reset the homing weapon cheat here. + if (cheats.homingfire) + { + cheats.homingfire = 0; + weapons_homing_all_reset(); + } #endif if (Current_level_num != Last_level) { diff --git a/similar/main/weapon.cpp b/similar/main/weapon.cpp index 5632aa724..2ec9dbef7 100644 --- a/similar/main/weapon.cpp +++ b/similar/main/weapon.cpp @@ -1013,6 +1013,23 @@ int pick_up_vulcan_ammo(player_info &player_info, uint_fast32_t ammo_count, cons } #if defined(DXX_BUILD_DESCENT_II) +// Homing weapons cheat + +void weapons_homing_all() +{ + range_for(auto &&objp, vobjptr) + if (objp->type == OBJ_WEAPON) + objp->ctype.laser_info.track_goal = object_none; + range_for (auto &w, Weapon_info) + w.homing_flag |= 2; +} + +void weapons_homing_all_reset() +{ + range_for (auto &w, Weapon_info) + w.homing_flag &= ~2; +} + #define SMEGA_SHAKE_TIME (F1_0*2) #define MAX_SMEGA_DETONATES 4 static array Smega_detonate_times;