MCPcopy Create free account
hub / github.com/DFHack/dfhack / command_result plugin_enable

Function command_result plugin_enable

plugins/spectate.cpp:327–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
328 if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) {
329 out.printerr("Cannot enable {} without a loaded fort.\n", plugin_name);
330 return CR_FAILURE;
331 }
332
333 if (enable != is_enabled) {
334 is_enabled = enable;
335 DEBUG(control,out).print("{} from the API; persisting\n",
336 is_enabled ? "enabled" : "disabled");
337 if (enable) {
338 config.reset();
339 if (!Lua::CallLuaModuleFunction(out, "plugins.spectate", "refresh_cpp_config")) {
340 WARN(control,out).print("Failed to refresh config\n");
341 }
342 if (is_squads_open()) {
343 out.printerr("Cannot enable {} while the squads screen is open.\n", plugin_name);
344 Lua::CallLuaModuleFunction(out, "plugins.spectate", "show_squads_warning");
345 is_enabled = false;
346 return CR_FAILURE;
347 }
348 INFO(control,out).print("Spectate mode enabled!\n");
349 EventManager::registerListener(EventManager::EventType::UNIT_NEW_ACTIVE, new_unit_handler);
350 if (plotinfo->follow_unit > -1)
351 set_next_cycle_unpaused_ms(out);
352 else
353 follow_a_dwarf(out);
354 } else {
355 INFO(control,out).print("Spectate mode disabled!\n");
356 plotinfo->follow_unit = -1;
357 on_disable(out);
358 // don't reset the unit history since we may want to re-enable
359 }
360 } else {
361 DEBUG(control,out).print("{} from the API, but already {}; no action\n",
362 is_enabled ? "enabled" : "disabled",
363 is_enabled ? "enabled" : "disabled");
364 }
365 return CR_OK;
366}
367
368DFhackCExport command_result plugin_shutdown (color_ostream &out) {
369 DEBUG(control,out).print("shutting down {}\n", plugin_name);

Callers

nothing calls this directly

Calls 7

CallLuaModuleFunctionFunction · 0.85
is_squads_openFunction · 0.85
follow_a_dwarfFunction · 0.85
on_disableFunction · 0.85
printMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected