DRY getting location string
This commit is contained in:
@@ -625,30 +625,8 @@ std::pair<std::string, std::string> 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;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user