| 325 | } |
| 326 | |
| 327 | DFhackCExport 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 | |
| 368 | DFhackCExport command_result plugin_shutdown (color_ostream &out) { |
| 369 | DEBUG(control,out).print("shutting down {}\n", plugin_name); |
nothing calls this directly
no test coverage detected