summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/files.cc32
-rw-r--r--src/files.hpp2
-rw-r--r--src/spells2.cc2
3 files changed, 20 insertions, 16 deletions
diff --git a/src/files.cc b/src/files.cc
index 183ae0af..a2c11846 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -60,8 +60,10 @@
#include "xtra1.hpp"
#include "z-rand.hpp"
+#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
+#include <fmt/format.h>
#include <fstream>
#include <limits>
#include <memory>
@@ -2322,28 +2324,28 @@ void display_player(int mode)
* Describe the player's location -- either by dungeon level, town, or in
* wilderness with landmark reference.
*/
-cptr describe_player_location()
+std::string describe_player_location()
{
auto const &wilderness = game->wilderness;
auto const &d_info = game->edit_data.d_info;
- int i;
- static char desc[80];
+ std::string desc;
+
int pwx = (p_ptr->wild_mode ? p_ptr->px : p_ptr->wilderness_x);
int pwy = (p_ptr->wild_mode ? p_ptr->py : p_ptr->wilderness_y);
int feat = wilderness(pwx, pwy).feat;
if (dungeon_type != DUNGEON_WILDERNESS && dun_level > 0)
{
- sprintf(desc, "on level %d of %s", dun_level, d_info[dungeon_type].name.c_str());
+ desc += fmt::format("on level {:d} of {}", dun_level, d_info[dungeon_type].name);
}
else if (wf_info[feat].terrain_idx == TERRAIN_TOWN)
{
- sprintf(desc, "in the town of %s", wf_info[feat].name);
+ desc += fmt::format("in the town of {}", wf_info[feat].name);
}
else if (wf_info[feat].entrance)
{
- sprintf(desc, "near %s", wf_info[feat].name);
+ desc += fmt::format("near {}", wf_info[feat].name);
}
else
{
@@ -2382,12 +2384,12 @@ cptr describe_player_location()
if (!landmark)
{
- sprintf(desc, "in %s", wf_info[feat].text);
+ desc += fmt::format("in {}", wf_info[feat].text);
}
else if (pwx == lwx && pwy == lwy)
{
/* Paranoia; this should have been caught above */
- sprintf(desc, "near %s", wf_info[feat].name);
+ desc += fmt::format("near {}", wf_info[feat].name);
}
else
{
@@ -2409,7 +2411,8 @@ cptr describe_player_location()
if (dy * 81 < dx * 31) ns = "";
if (dx * 81 < dy * 31) ew = "";
- sprintf(desc, "in %s %s%s of %s",
+ desc += fmt::format(
+ "in {} {}{} of {}",
wf_info[feat].text,
ns,
ew,
@@ -2417,10 +2420,8 @@ cptr describe_player_location()
}
}
- /* strip trailing whitespace */
- for (i = 0; desc[i]; ++i);
- while (desc[--i] == ' ')
- desc[i] = 0;
+ /* Strip trailing whitespace */
+ boost::trim_right(desc);
return desc;
}
@@ -2724,7 +2725,10 @@ errr file_character(cptr name, bool_ full)
}
/* Where we are, if we're alive */
- if (!death) fprintf(fff, "\n You are currently %s.", describe_player_location());
+ if (!death)
+ {
+ fprintf(fff, "\n You are currently %s.", describe_player_location().c_str());
+ }
/* Monsters slain */
{
diff --git a/src/files.hpp b/src/files.hpp
index 35a10079..bd39c759 100644
--- a/src/files.hpp
+++ b/src/files.hpp
@@ -13,7 +13,7 @@ extern object_flag_set player_flags();
extern void wipe_saved(void);
extern s16b tokenize(char *buf, s16b num, char **tokens, char delim1, char delim2);
extern void display_player(int mode);
-extern cptr describe_player_location(void);
+extern std::string describe_player_location();
extern errr file_character(cptr name, bool_ full);
extern errr process_pref_file_aux(char *buf);
extern errr process_pref_file(cptr name);
diff --git a/src/spells2.cc b/src/spells2.cc
index ae7f8aa1..02b51056 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -831,7 +831,7 @@ void self_knowledge(FILE *fff)
static char buf[250];
sprintf(buf, "You are dead, killed by %s %s.",
- died_from, describe_player_location());
+ died_from, describe_player_location().c_str());
info[i++] = buf;
}