Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record advance time #457

Merged
merged 34 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a9887ba
remove duplicate include
NQNStudios Sep 23, 2024
c705775
record and replay cancelling item target mode
NQNStudios Sep 23, 2024
670ef92
record and validate advance_time() calls with --advance-time
NQNStudios Sep 23, 2024
cbc559b
fix some advance_time cases
NQNStudios Sep 24, 2024
730a7bb
missing advance_time print last command
NQNStudios Sep 24, 2024
3e2b3ea
after advance_time with wrong args, print last action type
NQNStudios Sep 25, 2024
8954ce2
fix an advance_time case
NQNStudios Sep 25, 2024
fc67811
fix replay behavior of item stats window buttons
NQNStudios Sep 25, 2024
fd8058e
fix advancee_time behavior of more actions
NQNStudios Sep 25, 2024
c63dce5
discard control_click when tracking last_action_type
NQNStudios Sep 25, 2024
8725288
fix more advance_time cases
NQNStudios Sep 25, 2024
a8102da
fix more advance_time calls
NQNStudios Sep 25, 2024
11ed073
fix more advance_time calls
NQNStudios Sep 25, 2024
96e3935
fix parsing display_spells and display_skills actions
NQNStudios Sep 25, 2024
c877eed
fix more advance_time
NQNStudios Sep 25, 2024
091fd87
TODO comment on adj_town_look()
NQNStudios Sep 25, 2024
efa5893
change --advance-time to --verbose, w/ better replay behavior
NQNStudios Sep 25, 2024
762feec
fix an advance_time case
NQNStudios Sep 25, 2024
382dfaf
fix more advance_time cases
NQNStudios Sep 25, 2024
ab2cabe
consistent advance_time behavior for display_map key vs. button
NQNStudios Sep 25, 2024
b60ccaa
fix more advance_time cases
NQNStudios Sep 25, 2024
9ef5643
fix a new crash at end of replay log
NQNStudios Sep 25, 2024
cc7c8b4
fix more advance_time cases
NQNStudios Sep 25, 2024
081578c
replay load_party() more accurately
NQNStudios Sep 25, 2024
47b4456
handle last (?) advance_time case
NQNStudios Sep 25, 2024
c2ef6e2
replay test bash script (tested, works on mac)
NQNStudios Sep 25, 2024
e89f1e9
prefix action debug prints
NQNStudios Sep 26, 2024
147ad4e
rename control_click to click_control
NQNStudios Sep 26, 2024
24f49c7
remove TODOs
NQNStudios Sep 26, 2024
2122227
call advance_time for cancel_item_target
NQNStudios Sep 26, 2024
0eb48d9
make cosmetic advance_time() mismatches warnings unless --strict
NQNStudios Sep 26, 2024
e21b1d8
thoroughness level 2 - use --strict
NQNStudios Sep 26, 2024
76e76d8
make build_scen_headers use cdata
NQNStudios Nov 10, 2024
3ac948c
wrap load_party base64 data
NQNStudios Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 73 additions & 18 deletions src/game/boe.actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "tools/enum_map.hpp"
#include <string>
#include <boost/lexical_cast.hpp>
#include <sstream>

rectangle item_screen_button_rects[9] = {
{125,10,141,28},{125,40,141,58},{125,68,141,86},{125,98,141,116},{125,126,141,144},{125,156,141,174},
Expand Down Expand Up @@ -108,6 +109,8 @@ extern sf::RenderWindow mini_map;
extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
extern short shop_identify_cost, shop_recharge_amount;

extern bool record_verbose;
extern bool replay_verbose;

const char *dir_string[] = {"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest"};
char get_new_terrain();
Expand Down Expand Up @@ -1250,7 +1253,7 @@ void screen_shift(int dx, int dy, bool& need_redraw) {
need_redraw = true;
}

void handle_print_pc_hp(int which_pc) {
void handle_print_pc_hp(int which_pc, bool& need_reprint) {
if(recording){
record_action("handle_print_pc_hp", boost::lexical_cast<std::string>(which_pc));
}
Expand All @@ -1259,9 +1262,10 @@ void handle_print_pc_hp(int which_pc) {
str << pc.name << " has ";
str << pc.cur_health << " health out of " << pc.max_health << '.';
add_string_to_buf(str.str());
need_reprint = true;
}

void handle_print_pc_sp(int which_pc) {
void handle_print_pc_sp(int which_pc, bool& need_reprint) {
if(recording){
record_action("handle_print_pc_sp", boost::lexical_cast<std::string>(which_pc));
}
Expand All @@ -1270,9 +1274,10 @@ void handle_print_pc_sp(int which_pc) {
str << pc.name << " has ";
str << pc.cur_sp << " spell pts. out of " << pc.max_sp << '.';
add_string_to_buf(str.str());
need_reprint = true;
}

void handle_trade_places(int which_pc) {
void handle_trade_places(int which_pc, bool& need_reprint) {
if(recording){
record_action("handle_trade_places", boost::lexical_cast<std::string>(which_pc));
}
Expand All @@ -1283,6 +1288,7 @@ void handle_trade_places(int which_pc) {
else {
switch_pc(which_pc);
}
need_reprint = true;
}

void show_item_info(short item_hit) {
Expand All @@ -1296,6 +1302,12 @@ void show_item_info(short item_hit) {
else display_pc_item(stat_window, item_hit,univ.party[stat_window].items[item_hit],0);
}

void update_item_stats_area(bool& need_reprint) {
put_pc_screen();
put_item_screen(stat_window);
need_reprint = true;
}

bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
long item_hit;
bool are_done = false;
Expand Down Expand Up @@ -1363,7 +1375,8 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {

case TOOLBAR_SCROLL: case TOOLBAR_MAP:
display_map();
break;
// do not call advance_time
return false;

case TOOLBAR_BAG: case TOOLBAR_HAND:
if(overall_mode == MODE_TOWN || overall_mode == MODE_COMBAT)
Expand Down Expand Up @@ -1523,22 +1536,22 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
handle_switch_pc(i, need_redraw, need_reprint);
break;
case PCBTN_HP:
handle_print_pc_hp(i);
handle_print_pc_hp(i, need_reprint);
break;
case PCBTN_SP:
handle_print_pc_sp(i);
handle_print_pc_sp(i, need_reprint);
break;
case PCBTN_INFO:
give_pc_info(i);
break;
// don't call advance_time
return false;
case PCBTN_TRADE:
handle_trade_places(i);
handle_trade_places(i, need_reprint);
break;
case MAX_ePlayerButton:
break; // Not a button
}
}
need_reprint = true;
put_pc_screen();
put_item_screen(stat_window);
if(overall_mode == MODE_SHOPPING) {
Expand Down Expand Up @@ -1610,9 +1623,7 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
}
}
}
put_pc_screen();
put_item_screen(stat_window);
need_reprint = true;
update_item_stats_area(need_reprint);
}

advance_time(did_something, need_redraw, need_reprint);
Expand All @@ -1622,6 +1633,42 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
}

void advance_time(bool did_something, bool need_redraw, bool need_reprint) {
if(recording && record_verbose){
std::map<std::string,std::string> info;
info["did_something"] = bool_to_str(did_something);
info["need_redraw"] = bool_to_str(need_redraw);
info["need_reprint"] = bool_to_str(need_reprint);
record_action("advance_time", info);
}
if(replaying && replay_verbose){
if(has_next_action("advance_time")){
std::string _last_action_type = last_action_type;
Element& element = pop_next_action();
std::map<std::string,std::string> info = info_from_action(element);
std::ostringstream sstr;
sstr << std::boolalpha;
bool wrong_args = false;
if(did_something != str_to_bool(info["did_something"])){
wrong_args = true;
sstr << "did_something: expected " << !did_something << ", was " << did_something << ". ";
}
if(need_redraw != str_to_bool(info["need_redraw"])){
wrong_args = true;
sstr << "need_redraw: expected " << !need_redraw << ", was " << need_redraw << ". ";
}
if(need_reprint != str_to_bool(info["need_reprint"])){
wrong_args = true;
sstr << "need_reprint: expected " << !need_reprint << ", was " << need_reprint << ". ";
}
sstr << "After " << _last_action_type;
if(wrong_args){
throw std::string { "Replay system internal error! advance_time() was called with the wrong args. " } + sstr.str();
}
}else{
throw std::string { "Replay system internal error! advance_time() was called following an action which does not advance time: " } + last_action_type;
}
}

// MARK: At this point, see if any specials have been queued up, and deal with them
// Note: We just check once here instead of looping because run_special also pulls from the queue.
if(!special_queue.empty()) {
Expand Down Expand Up @@ -2091,6 +2138,18 @@ void close_map(bool record) {
mainPtr.setActive();
}

void cancel_item_target() {
if(recording){
record_action("cancel_item_target", "");
}
if(stat_screen_mode == MODE_IDENTIFY)
ASB("Identify: Finished");
else if(stat_screen_mode == MODE_RECHARGE)
ASB("Recharge: Finished");
overall_mode = MODE_TOWN;
stat_screen_mode = MODE_INVEN;
}

bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
bool are_done = false;
location pass_point; // TODO: This isn't needed
Expand Down Expand Up @@ -2248,12 +2307,8 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
// Rotate a force wall
spell_cast_hit_return();
else if(overall_mode == MODE_ITEM_TARGET) {
if(stat_screen_mode == MODE_IDENTIFY)
ASB("Identify: Finished");
else if(stat_screen_mode == MODE_RECHARGE)
ASB("Recharge: Finished");
overall_mode = MODE_TOWN;
stat_screen_mode = MODE_INVEN;
// Cancel choosing items
cancel_item_target();
} else if(overall_mode == MODE_TOWN || overall_mode == MODE_COMBAT || overall_mode == MODE_OUTDOORS) {
// Pause (skip turn)
handle_pause(did_something, need_redraw);
Expand Down
8 changes: 5 additions & 3 deletions src/game/boe.actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ void debug_increase_age();
void debug_towns_forget();
void debug_heal_plus_extra();
void debug_heal();
void handle_print_pc_hp(int which_pc);
void handle_print_pc_sp(int which_pc);
void handle_trade_places(int which_pc);
void handle_print_pc_hp(int which_pc, bool& need_reprint);
void handle_print_pc_sp(int which_pc, bool& need_reprint);
void handle_trade_places(int which_pc, bool& need_reprint);
void handle_begin_talk(bool& need_reprint);
void handle_talk(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);
void give_help_and_record(short help1, short help2);
void show_item_info(short item_hit);
void close_map(bool record = false);
void cancel_item_target();
void update_item_stats_area(bool& need_reprint);

#endif
Loading