Skip to content

Commit

Permalink
Add ap rollover component
Browse files Browse the repository at this point in the history
  • Loading branch information
burner1024 committed Aug 3, 2024
1 parent ab96803 commit 0a122b2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
2 changes: 2 additions & 0 deletions mods/fo2tweaks.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions source/gl_g_ap_rollover.ssl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0a122b2

Please sign in to comment.