diff options
author | Bardur Arantsson <bardur@scientician.net> | 2017-06-13 18:24:42 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2017-06-13 18:24:42 +0200 |
commit | dd900258b2c67562dc58840722b0223f68769b3c (patch) | |
tree | 0e7869e6d2cfa43e720911f9a7c0f43027bbc87a | |
parent | 29dce5dd3fadafc1f4b775ecbf7980ce5223dd1e (diff) |
Rework loadsave.c:loaded_game_module to use std::string
-rw-r--r-- | src/loadsave.cc | 39 | ||||
-rw-r--r-- | src/modules.cc | 4 | ||||
-rw-r--r-- | src/modules.hpp | 3 |
3 files changed, 24 insertions, 22 deletions
diff --git a/src/loadsave.cc b/src/loadsave.cc index 5968e7c5..8413086d 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -39,6 +39,7 @@ #include "z-rand.hpp" #include <cassert> +#include <fmt/format.h> #include <memory> static u32b vernum; /* Version flag */ @@ -483,7 +484,6 @@ static void note(cptr msg) /* * Misc. other data */ -static char loaded_game_module[80]; static bool_ do_extra(ls_flag_t flag) { auto const &d_info = game->edit_data.d_info; @@ -864,21 +864,6 @@ static bool_ do_extra(ls_flag_t flag) /* Write death */ do_bool(&death, flag); - /* Incompatible module? */ - if (flag == ls_flag_t::LOAD) - { - s32b ok; - - ok = module_savefile_loadable(loaded_game_module); - - /* Argh bad game module! */ - if (!ok) - { - note(format("Bad game module. Savefile was saved with module '%s' but game is '%s'.", loaded_game_module, game_module)); - return (FALSE); - } - } - /* Level feeling */ do_s16b(&feeling, flag); @@ -2393,11 +2378,27 @@ static bool_ do_savefile_aux(ls_flag_t flag) } /* Game module */ - if (flag == ls_flag_t::SAVE) { - strcpy(loaded_game_module, game_module); + std::string loaded_game_module; + + if (flag == ls_flag_t::SAVE) + { + loaded_game_module = game_module; + } + do_std_string(loaded_game_module, flag); + + // Check for incompatible module + if (flag == ls_flag_t::LOAD) + { + if (!module_savefile_loadable(loaded_game_module)) + { + note(fmt::format("Bad game module. Savefile was saved with module '{:s}' but game is '{:s}'.", + loaded_game_module, + game_module).c_str()); + return FALSE; + } + } } - do_string(loaded_game_module, 80, flag); /* Timers */ do_timers(flag); diff --git a/src/modules.cc b/src/modules.cc index aba71731..de9ad1ad 100644 --- a/src/modules.cc +++ b/src/modules.cc @@ -232,9 +232,9 @@ static void init_module(module_type *module_ptr) } } -bool_ module_savefile_loadable(cptr savefile_mod) +bool module_savefile_loadable(std::string const &tag) { - return (strcmp(savefile_mod, modules[game_module_idx].meta.save_file_tag) == 0); + return tag == modules[game_module_idx].meta.save_file_tag; } /* Did the player force a module on command line */ diff --git a/src/modules.hpp b/src/modules.hpp index b57120c3..867955c9 100644 --- a/src/modules.hpp +++ b/src/modules.hpp @@ -1,9 +1,10 @@ #pragma once #include "h-basic.h" +#include <string> bool_ select_module(); -bool_ module_savefile_loadable(cptr savefile_mod); +bool module_savefile_loadable(std::string const &savefile_mod); void tome_intro(); void theme_intro(); s16b *theme_race_status(int r_idx); |