1- #include " Debug.h"
21#include " LuaTools.h"
32#include " PluginManager.h"
43#include " PluginLua.h"
@@ -32,33 +31,26 @@ static bool clear_combat = false;
3231static bool clear_sparring = true ;
3332static bool clear_hunting = false ;
3433
35- namespace DFHack {
36- DBG_DECLARE (logcleaner, control, DebugCategory::LINFO);
37- DBG_DECLARE (logcleaner, cleanup, DebugCategory::LINFO);
38- }
39-
4034static void cleanupLogs (color_ostream& out);
4135static command_result do_command (color_ostream& out, std::vector<std::string>& params);
42- static void do_enable ();
43- static void do_disable ();
4436
4537// Getter functions for Lua
4638static bool logcleaner_getCombat () { return clear_combat; }
4739static bool logcleaner_getSparring () { return clear_sparring; }
4840static bool logcleaner_getHunting () { return clear_hunting; }
4941
5042// Setter functions for Lua (also persist to config)
51- static void logcleaner_setCombat (color_ostream& out, bool val) {
43+ static void logcleaner_setCombat (bool val) {
5244 clear_combat = val;
5345 config.set_bool (CONFIG_CLEAR_COMBAT, clear_combat);
5446}
5547
56- static void logcleaner_setSparring (color_ostream& out, bool val) {
48+ static void logcleaner_setSparring (bool val) {
5749 clear_sparring = val;
5850 config.set_bool (CONFIG_CLEAR_SPARING, clear_sparring);
5951}
6052
61- static void logcleaner_setHunting (color_ostream& out, bool val) {
53+ static void logcleaner_setHunting (bool val) {
6254 clear_hunting = val;
6355 config.set_bool (CONFIG_CLEAR_HUNTING, clear_hunting);
6456}
@@ -89,12 +81,6 @@ static command_result do_command(color_ostream& out, std::vector<std::string>& p
8981 return show_help ? CR_WRONG_USAGE : CR_OK;
9082}
9183
92- static void do_enable () {
93- }
94-
95- static void do_disable () {
96- }
97-
9884DFhackCExport command_result plugin_enable (color_ostream& out, bool enable) {
9985 if (!Core::getInstance ().isMapLoaded () || !World::isFortressMode ()) {
10086 out.printerr (" Cannot enable {} without a loaded fort.\n " , plugin_name);
@@ -103,31 +89,19 @@ DFhackCExport command_result plugin_enable(color_ostream& out, bool enable) {
10389
10490 if (enable != is_enabled) {
10591 is_enabled = enable;
106- DEBUG (control, out).print (" {} from the API; persisting\n " ,
107- is_enabled ? " enabled" : " disabled" );
10892 config.set_bool (CONFIG_IS_ENABLED, is_enabled);
109- if (enable)
110- do_enable ();
111- else
112- do_disable ();
113- } else {
114- DEBUG (control, out).print (" {} from the API, but already {}; no action\n " ,
115- is_enabled ? " enabled" : " disabled" ,
116- is_enabled ? " enabled" : " disabled" );
11793 }
11894 return CR_OK;
11995}
12096
12197DFhackCExport command_result plugin_shutdown (color_ostream& out) {
122- DEBUG (control, out).print (" shutting down {}\n " , plugin_name);
12398 return CR_OK;
12499}
125100
126101DFhackCExport command_result plugin_load_site_data (color_ostream& out) {
127102 config = World::GetPersistentSiteData (CONFIG_KEY);
128103
129104 if (!config.isValid ()) {
130- DEBUG (control, out).print (" no config found in this save; initializing\n " );
131105 config = World::AddPersistentSiteData (CONFIG_KEY);
132106 config.set_bool (CONFIG_IS_ENABLED, is_enabled);
133107 config.set_bool (CONFIG_CLEAR_COMBAT, clear_combat);
@@ -140,19 +114,12 @@ DFhackCExport command_result plugin_load_site_data(color_ostream& out) {
140114 clear_sparring = config.get_bool (CONFIG_CLEAR_SPARING);
141115 clear_hunting = config.get_bool (CONFIG_CLEAR_HUNTING);
142116
143- DEBUG (control, out).print (" loading persisted enabled state: {}\n " ,
144- is_enabled ? " true" : " false" );
145- if (is_enabled)
146- do_enable ();
147-
148117 return CR_OK;
149118}
150119
151120DFhackCExport command_result plugin_onstatechange (color_ostream& out, state_change_event event) {
152121 if (event == DFHack::SC_WORLD_UNLOADED && is_enabled) {
153- DEBUG (control, out).print (" world unloaded; disabling {}\n " , plugin_name);
154122 is_enabled = false ;
155- do_disable ();
156123 }
157124 return CR_OK;
158125}
@@ -163,31 +130,17 @@ static void cleanupLogs(color_ostream& out) {
163130
164131 // Collect all report IDs from unit combat/sparring/hunting logs
165132 std::unordered_set<int32_t > report_ids_to_remove;
133+ bool log_types[] = {clear_combat, clear_sparring, clear_hunting};
166134
167135 for (auto unit : world->units .all ) {
168- // Combat logs (index 0)
169- if (clear_combat) {
170- auto & log = unit->reports .log [0 ];
171- for (auto report_id : log) {
172- report_ids_to_remove.insert (report_id);
173- }
174- log.clear ();
175- }
176- // Sparring logs (index 1)
177- if (clear_sparring) {
178- auto & log = unit->reports .log [1 ];
179- for (auto report_id : log) {
180- report_ids_to_remove.insert (report_id);
136+ for (int log_idx = 0 ; log_idx < 3 ; log_idx++) {
137+ if (log_types[log_idx]) {
138+ auto & log = unit->reports .log [log_idx];
139+ for (auto report_id : log) {
140+ report_ids_to_remove.insert (report_id);
141+ }
142+ log.clear ();
181143 }
182- log.clear ();
183- }
184- // Hunting logs (index 2)
185- if (clear_hunting) {
186- auto & log = unit->reports .log [2 ];
187- for (auto report_id : log) {
188- report_ids_to_remove.insert (report_id);
189- }
190- log.clear ();
191144 }
192145 }
193146
@@ -197,8 +150,6 @@ static void cleanupLogs(color_ostream& out) {
197150 // Remove collected reports from global buffers
198151 auto & reports = world->status .reports ;
199152
200- int reports_erased = 0 ;
201-
202153 for (auto report_id : report_ids_to_remove) {
203154 df::report* report = df::report::find (report_id);
204155 if (!report)
@@ -208,7 +159,6 @@ static void cleanupLogs(color_ostream& out) {
208159 if (it != reports.end ()) {
209160 delete report;
210161 reports.erase (it);
211- reports_erased++;
212162 }
213163 }
214164}
0 commit comments