| 169 | } |
| 170 | |
| 171 | DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { |
| 172 | if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) { |
| 173 | out.printerr("Cannot enable {} without a loaded fort.\n", plugin_name); |
| 174 | return CR_FAILURE; |
| 175 | } |
| 176 | |
| 177 | static EventManager::EventHandler new_unit_handler(plugin_self, on_new_active_unit, CYCLE_TICKS); |
| 178 | |
| 179 | if (enable != is_enabled) { |
| 180 | is_enabled = enable; |
| 181 | DEBUG(control,out).print("{} from the API; persisting\n", |
| 182 | is_enabled ? "enabled" : "disabled"); |
| 183 | config.set_bool(CONFIG_IS_ENABLED, is_enabled); |
| 184 | if (enable) { |
| 185 | reset_ephemeral_state(); |
| 186 | EventManager::registerListener(EventManager::EventType::UNIT_NEW_ACTIVE, new_unit_handler); |
| 187 | do_cycle(out); |
| 188 | } else { |
| 189 | do_disable(); |
| 190 | } |
| 191 | } else { |
| 192 | DEBUG(control,out).print("{} from the API, but already {}; no action\n", |
| 193 | is_enabled ? "enabled" : "disabled", |
| 194 | is_enabled ? "enabled" : "disabled"); |
| 195 | } |
| 196 | return CR_OK; |
| 197 | } |
| 198 | |
| 199 | DFhackCExport command_result plugin_shutdown(color_ostream &out) { |
| 200 | DEBUG(control,out).print("shutting down {}\n", plugin_name); |
nothing calls this directly
no test coverage detected