| 1835 | // End of utility functions for reports |
| 1836 | |
| 1837 | DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announcement_flags flags, df::coord pos, std::string message, int color, bool bright) |
| 1838 | { |
| 1839 | if (!world->allow_announcements || !is_valid_enum_item(type) || type == df::announcement_type::NONE) |
| 1840 | return -1; |
| 1841 | else if (message.empty()) |
| 1842 | { |
| 1843 | Core::printerr("Empty announcement {}\n", ENUM_AS_STR(type)); // DF would print this to errorlog.txt |
| 1844 | return -1; |
| 1845 | } |
| 1846 | |
| 1847 | if (flags.bits.PAUSE || flags.bits.RECENTER) |
| 1848 | pauseRecenter((flags.bits.RECENTER ? pos : df::coord()), flags.bits.PAUSE); // Does nothing if not dwarf mode |
| 1849 | |
| 1850 | bool adv_unconscious = false; |
| 1851 | if (auto adv = World::getAdventurer()) |
| 1852 | adv_unconscious = adv->counters.unconscious > 0; |
| 1853 | |
| 1854 | if (flags.bits.DO_MEGA && !adv_unconscious) |
| 1855 | showPopupAnnouncement(message, color, bright); |
| 1856 | |
| 1857 | writeToGamelog(message); |
| 1858 | |
| 1859 | auto &reports = world->status.reports; |
| 1860 | auto &alerts = world->status.announcement_alert; |
| 1861 | |
| 1862 | // Check for repeat report as part of an existing alert |
| 1863 | if (*gamemode == game_mode::DWARF && !flags.bits.ALERT) |
| 1864 | { |
| 1865 | if (linear_index(alerts, &df::announcement_alertst::type, ENUM_ATTR(announcement_type, alert_type, type)) >= 0) // Alert of type exists |
| 1866 | { |
| 1867 | for (size_t i = reports.size(); i-- > 0;) |
| 1868 | { |
| 1869 | auto &cur_report = *reports[i]; |
| 1870 | if (cur_report.text == message) // Repeat if text matches |
| 1871 | { |
| 1872 | cur_report.duration = ANNOUNCE_LINE_DURATION; |
| 1873 | cur_report.repeat_count++; |
| 1874 | |
| 1875 | if (flags.bits.D_DISPLAY) |
| 1876 | world->status.display_timer = ANNOUNCE_DISPLAY_TIME; |
| 1877 | |
| 1878 | return -1; |
| 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | auto new_report = new df::report(); |
| 1885 | new_report->type = type; |
| 1886 | new_report->text = message; |
| 1887 | new_report->color = color; |
| 1888 | new_report->bright = bright; |
| 1889 | new_report->flags.whole = adv_unconscious ? df::announcement_flag::mask_unconscious : 0x0; |
| 1890 | new_report->pos = pos; |
| 1891 | new_report->id = world->status.next_report_id++; |
| 1892 | new_report->year = *df::global::cur_year; |
| 1893 | new_report->time = *df::global::cur_year_tick; |
| 1894 | reports.push_back(new_report); |
nothing calls this directly
no test coverage detected