@@ -971,6 +971,36 @@ static int autobutcher_getWatchList(lua_State *L) {
971971 return 1 ;
972972}
973973
974+ static int getMax (int first, int second) {
975+ return first > second ? first : second;
976+ }
977+ // push info used by nestboxes
978+ static int autobutcher_getInfoForNestboxes (lua_State* L) {
979+ PersistentDataItem rconfig;
980+ color_ostream* out = Lua::GetOutput (L);
981+
982+ if (lua_isnumber (L, 1 )) {
983+ int raceId = lua_tointeger (L, 1 );
984+ lua_newtable (L);
985+ int ctable = lua_gettop (L);
986+ Lua::SetField (L, config.get_bool (CONFIG_IS_ENABLED), ctable, " autobutcher_enabled" );
987+
988+ if (!out)
989+ out = &Core::getInstance ().getConsole ();
990+
991+ WatchedRace* w;
992+ if (watched_races.count (raceId)) {
993+ w = watched_races[raceId];
994+ WatchedRace* tally = checkRaceStocksTotal (*out, raceId);
995+ Lua::SetField (L, w->isWatched , ctable, " watched" );
996+ int mac = getMax (w->fk - tally->fk_units .size (), 0 ) + getMax (w->mk - tally->mk_units .size (), 0 ) + getMax (w->fa - tally->fa_units .size (), 0 ) + getMax (w->ma - tally->ma_units .size (), 0 );
997+ Lua::SetField (L, mac, ctable, " mac" ); // missing animals count for race, diff between target for child/adult female/male and current amounts, ignore amounts over target
998+ delete tally;
999+ }
1000+ }
1001+ return 1 ;
1002+ }
1003+
9741004DFHACK_PLUGIN_LUA_FUNCTIONS {
9751005 DFHACK_LUA_FUNCTION (autowatch_isEnabled),
9761006 DFHACK_LUA_FUNCTION (autowatch_setEnabled),
@@ -986,5 +1016,6 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
9861016DFHACK_PLUGIN_LUA_COMMANDS {
9871017 DFHACK_LUA_COMMAND (autobutcher_getSettings),
9881018 DFHACK_LUA_COMMAND (autobutcher_getWatchList),
1019+ DFHACK_LUA_COMMAND (autobutcher_getInfoForNestboxes),
9891020 DFHACK_LUA_END
9901021};
0 commit comments