From 6c1e831e8e19eedfac4604d26a05f98552d154a9 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 1 Mar 2025 14:58:29 -0600 Subject: [PATCH] DRY getting location string --- src/game/boe.graphics.cpp | 24 +----------------------- src/game/boe.text.cpp | 34 ++++++++++++++++++++++++++++++++++ src/game/boe.text.hpp | 2 ++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/game/boe.graphics.cpp b/src/game/boe.graphics.cpp index 3188e0ce..96aedef4 100644 --- a/src/game/boe.graphics.cpp +++ b/src/game/boe.graphics.cpp @@ -625,30 +625,8 @@ std::pair text_bar_text() { std::string text = ""; std::string right_text = ""; - location loc = (is_out()) ? global_to_local(univ.party.out_loc) : univ.party.town_loc; - bool in_area = false; + text = get_location(); - if(is_out()) { - for(short i = 0; i < univ.out->area_desc.size(); i++) - if(loc.in(univ.out->area_desc[i])) { - text = univ.out->area_desc[i].descr; - in_area = true; - } - if(!in_area) { - text = univ.out->name; - } - } - if(is_town()) { - for(short i = 0; i < univ.town->area_desc.size(); i++) - if(loc.in(univ.town->area_desc[i])) { - text = univ.town->area_desc[i].descr; - in_area = true; - } - if(!in_area) { - text = univ.town->name; - } - - } if((is_combat()) && (univ.cur_pc < 6) && !monsters_going) { std::ostringstream sout; diff --git a/src/game/boe.text.cpp b/src/game/boe.text.cpp index 414c80ea..91f05479 100644 --- a/src/game/boe.text.cpp +++ b/src/game/boe.text.cpp @@ -1219,3 +1219,37 @@ bool day_reached(unsigned short which_day, unsigned short which_event) { return true; else return false; } + +std::string get_location(cUniverse* specific_univ) { + // This function is used to determine text bar text, which may be intended to be blank + // even if the party is technically outdoors, depending on the active game mode. + // I'm just trying to keep the old behavior the same. + bool outdoors = is_out(); + bool town = is_town(); + // For checking a save file's location, it can only be one or the other. + if(specific_univ != nullptr){ + outdoors = specific_univ->party.town_num >= 200; + town = !outdoors; + }else{ + specific_univ = &univ; + } + + std::string loc_str = ""; + + location loc = outdoors ? global_to_local(specific_univ->party.out_loc) : specific_univ->party.town_loc; + if(outdoors) { + loc_str = specific_univ->out->name; + for(short i = 0; i < specific_univ->out->area_desc.size(); i++) + if(loc.in(specific_univ->out->area_desc[i])) { + loc_str = specific_univ->out->area_desc[i].descr; + } + } + if(town){ + loc_str = specific_univ->town->name; + for(short i = 0; i < specific_univ->town->area_desc.size(); i++) + if(loc.in(specific_univ->town->area_desc[i])) { + loc_str = specific_univ->town->area_desc[i].descr; + } + } + return loc_str; +} \ No newline at end of file diff --git a/src/game/boe.text.hpp b/src/game/boe.text.hpp index 2f5d4513..5619f199 100644 --- a/src/game/boe.text.hpp +++ b/src/game/boe.text.hpp @@ -48,3 +48,5 @@ struct text_label_t { void place_text_label(std::string string, location at, bool centred); void draw_text_label(const text_label_t& label); + +std::string get_location(cUniverse* specific_univ = nullptr);