From 0a122b2b1478e51d8cc1596fd03f26b99d2b3ed3 Mon Sep 17 00:00:00 2001 From: Magus Date: Sat, 3 Aug 2024 21:56:21 +0700 Subject: [PATCH] Add ap rollover component --- README.md | 5 +++ docs/changelog.md | 4 +++ mods/fo2tweaks.ini | 2 ++ source/gl_g_ap_rollover.ssl | 69 +++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 source/gl_g_ap_rollover.ssl diff --git a/README.md b/README.md index 0415116..ad8dfec 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ It is highly configurable, any component can be used with or without others. Som - [No close range penalty for scoped weapons](#no-close-range-penalty-for-scoped-weapons) - [HP over head](#hp-over-head) - [Auto cursor](#auto-cursor) + - [Action Points rollover](#action-points-rollover) - [Miscellaneous](#miscellaneous) - [Autodoors](#autodoors) - [Healing revision](#healing-revision) @@ -191,6 +192,10 @@ _Note:_ This component is not perfect, there might be delays in updating, and it In combat, cursor state automatically changes to "attack" when hovering over an enemy, and back to "move" when over an empty hex. +#### Action Points rollover + +A portion of unused Action Points (default 2) will carry over to the next turn, Jagged Alliance style. This replaces AC bonus from used APs. Applies to everyone. + ### Miscellaneous #### Autodoors diff --git a/docs/changelog.md b/docs/changelog.md index 53be1a3..d0cc0d4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ ## Changelog +### Version 12.21 + +- Added [Action Points rollover](https://github.com/BGforgeNet/FO2tweaks/?tab=readme-ov-file#action-point-rollover) component. + ### Version 12.20 - Tapping current HP hotkey now [also shows](https://github.com/BGforgeNet/FO2tweaks/issues/108) max (only for party and out of combat). diff --git a/mods/fo2tweaks.ini b/mods/fo2tweaks.ini index e1e8061..34f72c3 100644 --- a/mods/fo2tweaks.ini +++ b/mods/fo2tweaks.ini @@ -56,6 +56,8 @@ no_drop_items_on_death=1 gigolo_limit=0 ; Automatic cursor change on mouseover in combat. auto_cursor=0 +; Roll over this many unused action points to the next turn. Replaces AC bonus. +ap_rollover=2 [no_scope_penalty] ; https://github.com/BGforgeNet/Fallout2_Restoration_Project/blob/master/scripts_src/headers/itempid.h#L119 diff --git a/source/gl_g_ap_rollover.ssl b/source/gl_g_ap_rollover.ssl new file mode 100644 index 0000000..ace1a23 --- /dev/null +++ b/source/gl_g_ap_rollover.ssl @@ -0,0 +1,69 @@ +#define SCRIPT_REALNAME "gl_g_ap_rollover" + +#include "headers/fo2tweaks/fo2tweaks.h" + +#define EVENT_turn_start 1 +#define EVENT_turn_end 0 +variable max_rollover = 0; +variable leftover_ap; +variable leftover_ap_map = 0; + +procedure combatturn_handler begin + variable event = get_sfall_arg; + variable who = get_sfall_arg; + variable leftover_ap; + variable current_ap = get_critter_current_ap(who); + + // End turn: save leftover AP + if event == EVENT_turn_end then begin + ndebug(obj_name(who) + ": end turn"); + leftover_ap = current_ap; + if leftover_ap > 0 then begin + ndebug("leftover: " + leftover_ap); + // Limit to max + if leftover_ap > max_rollover then begin + leftover_ap = max_rollover; + end + ndebug(obj_name(who) + " has " + leftover_ap + " rollover AP"); + leftover_ap_map[who] = leftover_ap; + end + end + + // Start turn: restore leftover AP + if event == EVENT_turn_start then begin + ndebug(obj_name(who) + ": start turn"); + variable rollover_ap = leftover_ap_map[who]; + if rollover_ap > 0 then begin + leftover_ap_map[who] = leftover_ap; + ndebug(obj_name(who) + " has " + current_ap + " current AP and " + rollover_ap + " rollover AP"); + set_critter_current_ap(who, current_ap + rollover_ap); + ndebug(obj_name(who) + " now has " + get_critter_current_ap(who) + " AP"); + leftover_ap_map[who] = 0; + end + end + +end + +procedure gamemode_handler begin + variable old_mode = get_sfall_arg_at(1); + variable new_mode = get_game_mode; + if mode_started(COMBAT, old_mode, new_mode) then begin + leftover_ap_map = create_array_map; + end +end + +procedure start begin + if game_loaded then begin + max_rollover = fo2tweaks_setting(sec_main, "ap_rollover"); + if max_rollover > 0 then begin + ndebug(max_rollover); + register_hook_proc(HOOK_COMBATTURN, combatturn_handler); + register_hook_proc(HOOK_GAMEMODECHANGE, gamemode_handler); + if leftover_ap_map == 0 then begin + leftover_ap_map = create_array_map; + end + set_unspent_ap_bonus(0); + ndebug("enabled"); + end + end +end