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

Function update_ucr_alert

library/modules/Gui.cpp:1732–1775  ·  view source on GitHub ↗

Utility functions for reports

Source from the content-addressed store, hash-verified

1730
1731// Utility functions for reports
1732static bool update_ucr_alert(df::unit *unit, df::announcement_alert_type alert_type)
1733{ // Updates combat/sparring/hunting alert
1734 if (!unit)
1735 return false;
1736
1737 df::unit_report_type ucr_type;
1738 // Choose correct UCR type or abort
1739 switch (alert_type)
1740 {
1741 case announcement_alert_type::COMBAT:
1742 ucr_type = unit_report_type::Combat;
1743 break;
1744 case announcement_alert_type::SPARRING:
1745 ucr_type = unit_report_type::Sparring;
1746 break;
1747 case announcement_alert_type::HUNTING:
1748 ucr_type = unit_report_type::Hunting;
1749 break;
1750 default:
1751 return false;
1752 }
1753
1754 auto &alerts = world->status.announcement_alert;
1755 // Find existing alert of same type, else create new
1756 df::announcement_alertst *alert = vector_get(alerts, linear_index(alerts, &df::announcement_alertst::type, alert_type));
1757 if (!alert)
1758 {
1759 alert = new df::announcement_alertst();
1760 alert->type = alert_type;
1761 alerts.push_back(alert);
1762 }
1763
1764 // Add unit id, UCR category pair to alert if not present
1765 for (size_t i = 0; i < alert->report_unid.size(); i++)
1766 {
1767 if (alert->report_unid[i] == unit->id && alert->report_unit_announcement_category[i] == ucr_type)
1768 return false;
1769 }
1770
1771 alert->report_unid.push_back(unit->id);
1772 alert->report_unit_announcement_category.push_back(ucr_type);
1773
1774 return true;
1775}
1776
1777static bool recent_report(df::unit *unit, df::unit_report_type slot)
1778{

Callers 2

add_recent_reportsFunction · 0.85
addCombatReportMethod · 0.85

Calls 3

vector_getFunction · 0.85
linear_indexFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected