Disables pause locking and announcement manipulation code in spectate

develop
Josh Cooper 2022-10-14 12:42:20 -07:00
parent ff072bf0c2
commit 7c769ebb9c
1 changed files with 64 additions and 50 deletions

@ -56,7 +56,7 @@ std::set<int32_t> job_tracker;
std::map<uint16_t,uint16_t> freq; std::map<uint16_t,uint16_t> freq;
std::default_random_engine RNG; std::default_random_engine RNG;
void enable_auto_unpause(color_ostream &out, bool state);
#define base 0.99 #define base 0.99
@ -121,6 +121,7 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
EM::registerListener(EventType::TICK, ticking, plugin_self); EM::registerListener(EventType::TICK, ticking, plugin_self);
EM::registerListener(EventType::JOB_STARTED, start, plugin_self); EM::registerListener(EventType::JOB_STARTED, start, plugin_self);
EM::registerListener(EventType::JOB_COMPLETED, complete, plugin_self); EM::registerListener(EventType::JOB_COMPLETED, complete, plugin_self);
enable_auto_unpause(out, unpause_enabled);
} else if (!enable && enabled) { } else if (!enable && enabled) {
// warp 8, engage! // warp 8, engage!
out.print("Spectate mode disabled!\n"); out.print("Spectate mode disabled!\n");
@ -141,6 +142,12 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
our_dorf = nullptr; our_dorf = nullptr;
job_watched = nullptr; job_watched = nullptr;
following_dwarf = false; following_dwarf = false;
//pause_lock->unlock();
break;
case SC_MAP_LOADED:
// todo: RE UNDEAD_ATTACK event still pausing regardless of announcement settings
//enable_auto_unpause(out, unpause_enabled);
break;
default: default:
break; break;
} }
@ -150,22 +157,21 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_onupdate(color_ostream &out) { DFhackCExport command_result plugin_onupdate(color_ostream &out) {
// keeps announcement pause settings locked // keeps announcement pause settings locked
World::Update(); // from pause.h // World::Update(); // from pause.h
if (lock_collision) { // if (lock_collision) {
if (unpause_enabled) { // if (unpause_enabled) {
// player asked for auto-unpause enabled // // player asked for auto-unpause enabled
World::SaveAnnouncementSettings(); // World::SaveAnnouncementSettings();
if (World::DisableAnnouncementPausing()) { // if (World::DisableAnnouncementPausing(out)) {
// now that we've got what we want, we can lock it down // // now that we've got what we want, we can lock it down
lock_collision = false; // lock_collision = false;
pause_lock->lock(); // }
} // } else {
} else { // if (World::RestoreAnnouncementSettings()) {
if (World::RestoreAnnouncementSettings()) { // lock_collision = false;
lock_collision = false; // }
} // }
} // }
}
while (unpause_enabled && !world->status.popups.empty()) { while (unpause_enabled && !world->status.popups.empty()) {
// dismiss announcement popup(s) // dismiss announcement popup(s)
Gui::getCurViewscreen(true)->feed_key(interface_key::CLOSE_MEGA_ANNOUNCEMENT); Gui::getCurViewscreen(true)->feed_key(interface_key::CLOSE_MEGA_ANNOUNCEMENT);
@ -179,40 +185,48 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out) {
} }
void enable_auto_unpause(color_ostream &out, bool state) { void enable_auto_unpause(color_ostream &out, bool state) {
// lock_collision == true means: enable_auto_unpause() was already invoked and didn't complete // we don't need to do any of this yet if the plugin isn't enabled
// The onupdate function above ensure the procedure properly completes, thus we only care about if (enabled) {
// state reversal here ergo `enabled != state` // Announcement manipulation doesn't prevent siege pauses
if (lock_collision && unpause_enabled != state) { // if(pause_lock) {
// if unpaused_enabled is true, then a lock collision means: we couldn't save/disable the pause settings, // // lock_collision == true means: enable_auto_unpause() was already invoked and didn't complete
// therefore nothing to revert and the lock won't even be engaged (nothing to unlock) // // The onupdate function above ensure the procedure properly completes, thus we only care about
lock_collision = false; // // state reversal here ergo `enabled != state`
// if (lock_collision && unpause_enabled != state) {
// out.print("handling collision\n");
// // if unpaused_enabled is true, then a lock collision means: we couldn't save/disable the pause settings,
// // therefore nothing to revert and the lock won't even be engaged (nothing to unlock)
// lock_collision = false;
// unpause_enabled = state;
// if (unpause_enabled) {
// // a collision means we couldn't restore the pause settings, therefore we only need re-engage the lock
// pause_lock->lock();
// }
// return;
// }
// // update the announcement settings if we can
// if (state) {
// if (World::SaveAnnouncementSettings()) {
// World::DisableAnnouncementPausing(out);
// pause_lock->lock();
// } else {
// lock_collision = true;
// }
// } else {
// pause_lock->unlock();
// if (!World::RestoreAnnouncementSettings()) {
// // this in theory shouldn't happen, if others use the lock like we do in spectate
// lock_collision = true;
// }
// }
// if (lock_collision) {
// out.printerr(
// "auto-unpause: must wait for another Pausing::AnnouncementLock to be lifted."
// " This setting will complete when the lock lifts.\n");
// pause_lock->reportLocks(out);
// }
// }
unpause_enabled = state; unpause_enabled = state;
if (unpause_enabled) {
// a collision means we couldn't restore the pause settings, therefore we only need re-engage the lock
pause_lock->lock();
}
return;
}
unpause_enabled = state;
// update the announcement settings if we can
if (unpause_enabled) {
if (World::SaveAnnouncementSettings()) {
World::DisableAnnouncementPausing();
pause_lock->lock();
} else {
lock_collision = true;
}
} else {
pause_lock->unlock();
if (!World::RestoreAnnouncementSettings()) {
// this in theory shouldn't happen, if others use the lock like we do in spectate
lock_collision = true;
}
}
if (lock_collision) {
out.printerr(
"auto-unpause: must wait for another Pausing::AnnouncementLock to be lifted."
" This setting will complete when the lock lifts.\n");
} }
} }