Simplifies report index safety

develop
Josh Cooper 2022-04-18 19:29:31 -07:00 committed by Myk
parent 1f972d6c1c
commit 018d189494
1 changed files with 6 additions and 8 deletions

@ -895,10 +895,9 @@ static void manageReportEvent(color_ostream& out) {
multimap<Plugin*,EventHandler> copy(handlers[EventType::REPORT].begin(), handlers[EventType::REPORT].end()); multimap<Plugin*,EventHandler> copy(handlers[EventType::REPORT].begin(), handlers[EventType::REPORT].end());
std::vector<df::report*>& reports = df::global::world->status.reports; std::vector<df::report*>& reports = df::global::world->status.reports;
size_t idx = df::report::binsearch_index(reports, lastReport, false); size_t idx = df::report::binsearch_index(reports, lastReport, false);
//this may or may not be needed: I don't know if binsearch_index goes earlier or later if it can't hit the target exactly // returns the index to the key equal to or greater than the key provided
while (idx < reports.size() && reports[idx]->id <= lastReport) { idx = reports[idx]->id == lastReport ? idx + 1 : idx; // we need the index after (where the new stuff is)
idx++;
}
for ( ; idx < reports.size(); idx++ ) { for ( ; idx < reports.size(); idx++ ) {
df::report* report = reports[idx]; df::report* report = reports[idx];
for (auto &key_value : copy) { for (auto &key_value : copy) {
@ -924,10 +923,9 @@ static void manageUnitAttackEvent(color_ostream& out) {
multimap<Plugin*,EventHandler> copy(handlers[EventType::UNIT_ATTACK].begin(), handlers[EventType::UNIT_ATTACK].end()); multimap<Plugin*,EventHandler> copy(handlers[EventType::UNIT_ATTACK].begin(), handlers[EventType::UNIT_ATTACK].end());
std::vector<df::report*>& reports = df::global::world->status.reports; std::vector<df::report*>& reports = df::global::world->status.reports;
size_t idx = df::report::binsearch_index(reports, lastReportUnitAttack, false); size_t idx = df::report::binsearch_index(reports, lastReportUnitAttack, false);
//this may or may not be needed: I don't know if binsearch_index goes earlier or later if it can't hit the target exactly // returns the index to the key equal to or greater than the key provided
while (idx < reports.size() && reports[idx]->id <= lastReportUnitAttack) { idx = reports[idx]->id == lastReportUnitAttack ? idx + 1 : idx; // we need the index after (where the new stuff is)
idx++;
}
std::set<int32_t> strikeReports; std::set<int32_t> strikeReports;
for ( ; idx < reports.size(); idx++ ) { for ( ; idx < reports.size(); idx++ ) {
df::report* report = reports[idx]; df::report* report = reports[idx];