| 792 | } |
| 793 | |
| 794 | DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { |
| 795 | if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) { |
| 796 | out.printerr("Cannot enable {} without a loaded fort.\n", plugin_name); |
| 797 | return CR_FAILURE; |
| 798 | } |
| 799 | |
| 800 | if (enable != is_enabled) { |
| 801 | is_enabled = enable; |
| 802 | DEBUG(control,out).print("{} from the API; persisting\n", |
| 803 | is_enabled ? "enabled" : "disabled"); |
| 804 | config.set_bool(CONFIG_IS_ENABLED, is_enabled); |
| 805 | if (enable) { |
| 806 | EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, *eventhandler_instance); |
| 807 | EventManager::registerListener(EventManager::EventType::JOB_INITIATED, *eventhandler_instance); |
| 808 | do_cycle(out); |
| 809 | } else { |
| 810 | EventManager::unregisterAll(plugin_self); |
| 811 | } |
| 812 | |
| 813 | } else { |
| 814 | DEBUG(control,out).print("{} from the API, but already {}; no action\n", |
| 815 | is_enabled ? "enabled" : "disabled", |
| 816 | is_enabled ? "enabled" : "disabled"); |
| 817 | } |
| 818 | return CR_OK; |
| 819 | } |
| 820 | |
| 821 | DFhackCExport command_result plugin_shutdown (color_ostream &out) { |
| 822 | DEBUG(control,out).print("shutting down {}\n", plugin_name); |