Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spectate] get rid of auto-disengage option and make it always on #5299

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions docs/plugins/spectate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ to following a different dwarf. It can also switch to following animals,
hostiles, or visiting units. You can switch to the next target (or a previous
target) immediately with the left/right arrow keys.

By default, `spectate` will disengage and turn itself off when you move the
`spectate` will automatically disengage and turn itself off when you move the
map, just like the vanilla follow mechanic. It will also disengage immediately
if you open the squads menu for military action.

Expand All @@ -36,7 +36,7 @@ Usage
enable spectate
spectate [status]
spectate toggle
spectate set <setting> <value>
spectate set <setting> <value> [<subvalue>]
spectate overlay enable|disable

Examples
Expand Down Expand Up @@ -71,12 +71,6 @@ Examples
Settings
--------

``auto-disengage`` (default: enabled)
Toggle automatically disabling the plugin when the player moves the map or
opens the squad panel. If this is disabled, you will need to manually
disable the plugin to turn off follow mode. You can still interact normally
with the DF UI.

``auto-unpause`` (default: disabled)
Toggle auto-dismissal of announcements that pause the game, like sieges,
forgotten beasts, etc.
Expand Down
13 changes: 4 additions & 9 deletions plugins/lua/spectate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local max_banner_y_offset = 4

local function get_default_state()
return {
['auto-disengage']=true,
['auto-unpause']=false,
['cinematic-action']=true,
['follow-seconds']=10,
Expand Down Expand Up @@ -89,7 +88,7 @@ local config, save_state = load_state()
-- called by gui/spectate
function get_config_elem(name, key)
local elem = config[name]
if not elem then return end
if elem == nil then return end
if type(elem) == 'table' then
return elem[key]
end
Expand All @@ -109,14 +108,10 @@ end

function show_squads_warning()
local message = {
'Cannot start spectate mode while auto-disengage is enabled and',
'the squads panel is open. The auto-disengage feature automatically',
'stops spectate mode when you open the squads panel.',
'Cannot start spectate mode while the squads panel is open. Spectate',
'automatically disengages when you open the squads panel.',
'',
'Please either close the squads panel or disable auto-disengage by',
'running the following command:',
'',
'spectate set auto-disengage false',
'Please close the squads panel before enabling spectate mode.',
}
dlg.showMessage("Spectate", table.concat(message, '\n'))
end
Expand Down
14 changes: 5 additions & 9 deletions plugins/spectate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static const std::unordered_set<int32_t> boring_jobs = {
// Configuration

static struct Configuration {
bool auto_disengage;
bool auto_unpause;
bool cinematic_action;
bool include_animals;
Expand All @@ -75,7 +74,6 @@ static struct Configuration {
int32_t follow_ms;

void reset() {
auto_disengage = true;
auto_unpause = false;
cinematic_action = true;
include_animals = false;
Expand Down Expand Up @@ -338,8 +336,8 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
if (!Lua::CallLuaModuleFunction(out, "plugins.spectate", "refresh_cpp_config")) {
WARN(control,out).print("Failed to refresh config\n");
}
if (config.auto_disengage && is_squads_open()) {
out.printerr("Cannot enable %s while auto-disengage is enabled and the squads screen is open.\n", plugin_name);
if (is_squads_open()) {
out.printerr("Cannot enable %s while the squads screen is open.\n", plugin_name);
Lua::CallLuaModuleFunction(out, "plugins.spectate", "show_squads_warning");
is_enabled = false;
return CR_FAILURE;
Expand Down Expand Up @@ -394,15 +392,15 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_onupdate(color_ostream &out) {
announcement_settings.on_update(out);

if (config.auto_disengage && (plotinfo->follow_unit < 0 || plotinfo->follow_item > -1 || is_squads_open())) {
if (plotinfo->follow_unit < 0 || plotinfo->follow_item > -1 || is_squads_open()) {
DEBUG(cycle,out).print("auto-disengage triggered\n");
is_enabled = false;
plotinfo->follow_unit = -1;
on_disable(out);
return CR_OK;
}

if ((!config.auto_disengage && plotinfo->follow_unit < 0) || Core::getInstance().getUnpausedMs() >= next_cycle_unpaused_ms) {
if (Core::getInstance().getUnpausedMs() >= next_cycle_unpaused_ms) {
recent_units.trim();
follow_a_dwarf(out);
}
Expand Down Expand Up @@ -556,9 +554,7 @@ static void follow_a_dwarf(color_ostream &out) {
static void spectate_setSetting(color_ostream &out, string name, int val) {
DEBUG(control,out).print("entering spectate_setSetting %s = %d\n", name.c_str(), val);

if (name == "auto-disengage") {
config.auto_disengage = val;
} else if (name == "auto-unpause") {
if (name == "auto-unpause") {
if (val && !config.auto_unpause) {
announcement_settings.save_and_scrub_settings(out);
} else if (!val && config.auto_unpause) {
Expand Down
2 changes: 1 addition & 1 deletion scripts