use static instead of anon namespace; suggested changes

develop
Ryan Williams 2022-05-30 13:51:24 -07:00 committed by GitHub
parent 1c3ea000e1
commit 0ff0d272b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 80 deletions

@ -140,7 +140,7 @@ namespace DFHack
// Recenter the viewscreen, based on DF code for announcements and scrolling
DFHACK_EXPORT void pauseRecenter(int32_t x, int32_t y, int32_t z, bool pause);
DFHACK_EXPORT inline void pauseRecenter(df::coord pos, bool pause) { return pauseRecenter(pos.x, pos.y, pos.z, pause); }
DFHACK_EXPORT inline void pauseRecenter(df::coord pos, bool pause) { pauseRecenter(pos.x, pos.y, pos.z, pause); }
DFHACK_EXPORT void recenterViewscreen(int32_t x, int32_t y, int32_t z, df::report_zoom_type zoom = df::enums::report_zoom_type::Item);
DFHACK_EXPORT inline void recenterViewscreen(df::coord pos, df::report_zoom_type zoom = df::enums::report_zoom_type::Item) { recenterViewscreen(pos.x, pos.y, pos.z, zoom); };
DFHACK_EXPORT inline void recenterViewscreen(df::report_zoom_type zoom = df::enums::report_zoom_type::Item) { recenterViewscreen(getCursorPos(), zoom); };

@ -1368,10 +1368,9 @@ DFHACK_EXPORT void Gui::writeToGamelog(std::string message)
fseed.close();
}
namespace
{ // Utility functions for reports
bool parseReportString(std::vector<std::string> *out, const std::string &str, size_t line_length = 73)
{ // parse a string into output strings like DF does for reports
// Utility functions for reports
static bool parseReportString(std::vector<std::string> *out, const std::string &str, size_t line_length = 73)
{ // parse a string into output strings like DF does for reports
if (str.empty() || line_length == 0)
return false;
@ -1388,7 +1387,7 @@ namespace
if (str[i] == 'r') // "&r" adds a blank line
{
word_wrap(out, parsed, line_length, false/*, true*/);
word_wrap(out, parsed, line_length/*, WSMODE_TRIM_LEADING*/);
out->push_back(" "); // DF adds a line with a space for some reason
parsed.clear();
}
@ -1402,34 +1401,30 @@ namespace
while (++i < str.length());
if (parsed.length())
word_wrap(out, parsed, line_length, false/*, true*/);
word_wrap(out, parsed, line_length/*, WSMODE_TRIM_LEADING*/);
return true;
}
}
bool recent_report(df::unit *unit, df::unit_report_type slot)
{
if (unit && !unit->reports.log[slot].empty() &&
static bool recent_report(df::unit *unit, df::unit_report_type slot)
{
return unit && !unit->reports.log[slot].empty() &&
*df::global::cur_year == unit->reports.last_year[slot] &&
(*df::global::cur_year_tick - unit->reports.last_year_tick[slot]) <= 500)
{
return true;
}
return false;
}
(*df::global::cur_year_tick - unit->reports.last_year_tick[slot]) <= 500;
}
bool recent_report_any(df::unit *unit)
{
static bool recent_report_any(df::unit *unit)
{
FOR_ENUM_ITEMS(unit_report_type, slot)
{
if (recent_report(unit, slot))
return true;
}
return false;
}
}
void delete_old_reports()
{
static void delete_old_reports()
{
auto &reports = world->status.reports;
while (reports.size() > 3000)
{
@ -1441,10 +1436,10 @@ namespace
}
reports.erase(reports.begin());
}
}
}
int32_t check_repeat_report(vector<string> &results)
{ // returns the new repeat count, else 0
static int32_t check_repeat_report(vector<string> &results)
{ // returns the new repeat count, else 0
if (*gamemode == game_mode::DWARF && !results.empty() && world->status.reports.size() >= results.size())
{
auto &reports = world->status.reports;
@ -1459,8 +1454,8 @@ namespace
}
}
return 0;
}
}
// End of utility functions for reports
DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announcement_flags flags, df::coord pos, std::string message, int color, bool bright)
{
@ -1592,17 +1587,15 @@ bool Gui::addCombatReport(df::unit *unit, df::unit_report_type slot, int report_
return true;
}
namespace
{ // An additional utility function for reports
bool add_proper_report(df::unit *unit, bool is_sparring, int report_index)
{
// An additional utility function for reports
static bool add_proper_report(df::unit *unit, bool is_sparring, int report_index)
{
if (is_sparring)
return Gui::addCombatReport(unit, unit_report_type::Sparring, report_index);
else if (unit->job.current_job != NULL && unit->job.current_job->job_type == job_type::Hunt)
return Gui::addCombatReport(unit, unit_report_type::Hunting, report_index);
else
return Gui::addCombatReport(unit, unit_report_type::Combat, report_index);
}
}
bool Gui::addCombatReportAuto(df::unit *unit, df::announcement_flags mode, int report_index)