MCPcopy Create free account
hub / github.com/DFHack/dfhack / autoDFAnnouncement

Method autoDFAnnouncement

library/modules/Gui.cpp:2047–2259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2045}
2046
2047bool Gui::autoDFAnnouncement(df::announcement_infost info, string message)
2048{ // Based on reverse-engineering of "make_announcement" FUN_1400574e0 (v50.11 win64 Steam)
2049 if (!world->allow_announcements)
2050 {
2051 DEBUG(gui).print("Skipped announcement because world->allow_announcements is false:\n{}\n", message);
2052 return false;
2053 }
2054 else if (!is_valid_enum_item(info.type) || info.type == df::announcement_type::NONE)
2055 {
2056 WARN(gui).print("Invalid announcement type:\n{}\n", message);
2057 return false;
2058 }
2059 else if (message.empty())
2060 {
2061 Core::printerr("Empty announcement {}\n", ENUM_AS_STR(info.type)); // DF would print this to errorlog.txt
2062 return false;
2063 }
2064
2065 auto a_flags = df::global::d_init->announcements.flags[info.type];
2066
2067 // Check if the announcement will actually be used and written to gamelog
2068 if (*gamemode == game_mode::ADVENTURE)
2069 {
2070 if (!a_flags.bits.A_DISPLAY && !a_flags.bits.DO_MEGA)
2071 {
2072 DEBUG(gui).print("Skipped announcement not enabled at all for adventure mode:\n{}\n", message);
2073 return false;
2074 }
2075
2076 if (info.pos.x >= 0 &&
2077 info.type != announcement_type::CREATURE_SOUND &&
2078 info.type != announcement_type::REGULAR_CONVERSATION &&
2079 info.type != announcement_type::CONFLICT_CONVERSATION &&
2080 info.type != announcement_type::MECHANISM_SOUND)
2081 { // If not sound, make sure we can see pos if we're not involved
2082 if (auto adv = World::getAdventurer(); info.unit_a != adv && info.unit_d != adv)
2083 { // Adventure mode reuses a dwarf mode digging designation bit to determine current visibility
2084 if (!Maps::isValidTilePos(info.pos) || (Maps::getTileDesignation(info.pos)->whole & 0x10) == 0x0)
2085 {
2086 DEBUG(gui).print("Adventure mode announcement not detected:\n{}\n", message);
2087 return false;
2088 }
2089 }
2090 }
2091 }
2092 else // Dwarf mode
2093 {
2094 if ((info.unit_a || info.unit_d) && (!info.unit_a || Units::isHidden(info.unit_a)) && (!info.unit_d || Units::isHidden(info.unit_d)))
2095 {
2096 DEBUG(gui).print("Dwarf mode announcement not detected:\n{}\n", message);
2097 return false;
2098 }
2099
2100 if (!a_flags.bits.D_DISPLAY && !a_flags.bits.DO_MEGA) // Apparently ALERT flag is insufficent for announcement to succeed
2101 {
2102 if (a_flags.bits.UNIT_COMBAT_REPORT)
2103 {
2104 if (!info.unit_a && !info.unit_d)

Callers

nothing calls this directly

Calls 15

is_valid_enum_itemFunction · 0.85
isValidTilePosFunction · 0.85
getTileDesignationFunction · 0.85
recent_report_anyFunction · 0.85
pauseRecenterFunction · 0.85
vector_containsFunction · 0.85
vector_get_randomFunction · 0.85
add_proper_reportFunction · 0.85
add_recent_reportsFunction · 0.85
vector_getFunction · 0.85
insert_into_vectorFunction · 0.85
announcement_infostClass · 0.85

Tested by

no test coverage detected