2012-03-05 08:47:06 -07:00
|
|
|
// A container for random minor tweaks that don't fit anywhere else,
|
|
|
|
// in order to avoid creating lots of plugins and polluting the namespace.
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
|
|
|
|
#include "modules/Gui.h"
|
2012-08-30 10:48:06 -06:00
|
|
|
#include "modules/Screen.h"
|
2012-04-11 13:07:54 -06:00
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Items.h"
|
2012-10-28 11:13:28 -06:00
|
|
|
#include "modules/Job.h"
|
2014-05-08 13:22:45 -06:00
|
|
|
#include "modules/Materials.h"
|
2014-09-27 17:55:39 -06:00
|
|
|
#include "modules/MapCache.h"
|
2015-01-01 12:36:30 -07:00
|
|
|
#include "modules/Buildings.h"
|
2015-12-26 09:47:55 -07:00
|
|
|
#include "modules/Filesystem.h"
|
2012-03-05 08:47:06 -07:00
|
|
|
|
2012-04-12 06:40:39 -06:00
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
2012-03-05 08:47:06 -07:00
|
|
|
#include "DataDefs.h"
|
2012-08-26 11:19:56 -06:00
|
|
|
#include <VTableInterpose.h>
|
2014-09-27 16:14:25 -06:00
|
|
|
#include "../uicommon.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/plotinfost.h"
|
2012-03-05 08:47:06 -07:00
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_soul.h"
|
|
|
|
#include "df/historical_entity.h"
|
|
|
|
#include "df/historical_figure.h"
|
|
|
|
#include "df/historical_figure_info.h"
|
2014-07-29 15:30:22 -06:00
|
|
|
#include "df/identity.h"
|
2012-03-05 08:47:06 -07:00
|
|
|
#include "df/language_name.h"
|
2014-07-29 15:26:14 -06:00
|
|
|
#include "df/incident.h"
|
2014-07-29 15:27:16 -06:00
|
|
|
#include "df/crime.h"
|
2012-04-11 13:07:54 -06:00
|
|
|
#include "df/unit_inventory_item.h"
|
2012-08-26 11:19:56 -06:00
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
2015-06-26 19:16:27 -06:00
|
|
|
#include "df/viewscreen_kitchenprefst.h"
|
2012-09-18 07:39:37 -06:00
|
|
|
#include "df/viewscreen_layer_unit_actionst.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/buildreq.h"
|
|
|
|
#include "df/gamest.h"
|
2012-08-30 10:48:06 -06:00
|
|
|
#include "df/building_trapst.h"
|
2015-06-27 09:02:26 -06:00
|
|
|
#include "df/building_workshopst.h"
|
2012-09-03 11:11:35 -06:00
|
|
|
#include "df/item_actual.h"
|
2014-05-08 13:22:45 -06:00
|
|
|
#include "df/item_crafted.h"
|
|
|
|
#include "df/item_armorst.h"
|
|
|
|
#include "df/item_helmst.h"
|
|
|
|
#include "df/item_glovesst.h"
|
|
|
|
#include "df/item_shoesst.h"
|
|
|
|
#include "df/item_pantsst.h"
|
2022-04-26 20:52:24 -06:00
|
|
|
#include "df/item_drinkst.h"
|
|
|
|
#include "df/item_globst.h"
|
2012-10-10 08:22:01 -06:00
|
|
|
#include "df/item_liquid_miscst.h"
|
|
|
|
#include "df/item_powder_miscst.h"
|
2012-09-17 07:19:24 -06:00
|
|
|
#include "df/item_barst.h"
|
|
|
|
#include "df/item_threadst.h"
|
|
|
|
#include "df/item_clothst.h"
|
2022-04-26 20:52:24 -06:00
|
|
|
#include "df/item_sheetst.h"
|
2014-09-18 14:05:15 -06:00
|
|
|
#include "df/spatter.h"
|
2012-09-18 07:39:37 -06:00
|
|
|
#include "df/layer_object.h"
|
|
|
|
#include "df/reaction.h"
|
|
|
|
#include "df/reaction_reagent_itemst.h"
|
|
|
|
#include "df/reaction_reagent_flags.h"
|
2020-06-02 09:10:25 -06:00
|
|
|
#include "df/reaction_product_itemst.h"
|
2014-06-03 16:29:13 -06:00
|
|
|
#include "df/viewscreen_setupdwarfgamest.h"
|
2012-09-28 03:32:41 -06:00
|
|
|
#include "df/viewscreen_layer_assigntradest.h"
|
|
|
|
#include "df/viewscreen_tradegoodsst.h"
|
2012-09-28 08:01:17 -06:00
|
|
|
#include "df/viewscreen_layer_militaryst.h"
|
2012-10-28 11:13:28 -06:00
|
|
|
#include "df/job.h"
|
|
|
|
#include "df/general_ref_building_holderst.h"
|
2012-11-16 11:51:07 -07:00
|
|
|
#include "df/unit_health_info.h"
|
2022-04-26 20:52:24 -06:00
|
|
|
#include "df/caste_body_info.h"
|
2012-03-05 08:47:06 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-09-26 16:40:19 -06:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "tweaks/adamantine-cloth-wear.h"
|
|
|
|
#include "tweaks/advmode-contained.h"
|
2016-01-08 17:27:11 -07:00
|
|
|
#include "tweaks/block-labors.h"
|
2017-06-25 14:42:30 -06:00
|
|
|
#include "tweaks/burrow-name-cancel.h"
|
2017-06-25 13:21:45 -06:00
|
|
|
#include "tweaks/cage-butcher.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "tweaks/civ-agreement-plotinfo.h"
|
2017-03-28 07:50:38 -06:00
|
|
|
#include "tweaks/condition-material.h"
|
2014-09-26 16:40:19 -06:00
|
|
|
#include "tweaks/craft-age-wear.h"
|
2020-08-06 20:30:29 -06:00
|
|
|
#include "tweaks/do-job-now.h"
|
2015-01-01 11:47:47 -07:00
|
|
|
#include "tweaks/eggs-fertile.h"
|
2015-08-25 08:12:31 -06:00
|
|
|
#include "tweaks/embark-profile-name.h"
|
2014-09-27 17:55:39 -06:00
|
|
|
#include "tweaks/farm-plot-select.h"
|
2014-09-26 16:40:19 -06:00
|
|
|
#include "tweaks/fast-heat.h"
|
|
|
|
#include "tweaks/fast-trade.h"
|
2015-03-04 17:03:39 -07:00
|
|
|
#include "tweaks/fps-min.h"
|
2016-01-04 17:29:30 -07:00
|
|
|
#include "tweaks/hide-priority.h"
|
2017-04-19 11:31:25 -06:00
|
|
|
#include "tweaks/hotkey-clear.h"
|
2014-09-27 16:14:25 -06:00
|
|
|
#include "tweaks/import-priority-category.h"
|
2018-05-17 17:47:56 -06:00
|
|
|
#include "tweaks/kitchen-prefs-all.h"
|
2015-06-26 21:18:08 -06:00
|
|
|
#include "tweaks/kitchen-prefs-color.h"
|
2015-06-26 19:16:27 -06:00
|
|
|
#include "tweaks/kitchen-prefs-empty.h"
|
2015-01-01 12:36:30 -07:00
|
|
|
#include "tweaks/max-wheelbarrow.h"
|
2014-09-26 16:40:19 -06:00
|
|
|
#include "tweaks/military-assign.h"
|
2014-10-01 18:13:31 -06:00
|
|
|
#include "tweaks/nestbox-color.h"
|
2022-04-26 20:52:24 -06:00
|
|
|
#include "tweaks/partial-items.h"
|
|
|
|
#include "tweaks/pausing-fps-counter.h"
|
|
|
|
#include "tweaks/reaction-gloves.h"
|
2015-02-17 08:43:55 -07:00
|
|
|
#include "tweaks/shift-8-scroll.h"
|
2014-09-26 16:40:19 -06:00
|
|
|
#include "tweaks/stable-cursor.h"
|
2018-05-14 20:54:20 -06:00
|
|
|
#include "tweaks/stone-status-all.h"
|
2015-12-26 09:47:55 -07:00
|
|
|
#include "tweaks/title-start-rename.h"
|
2015-01-28 14:54:53 -07:00
|
|
|
#include "tweaks/tradereq-pet-gender.h"
|
2012-03-05 08:47:06 -07:00
|
|
|
|
2013-10-08 07:41:49 -06:00
|
|
|
using std::set;
|
2012-03-05 08:47:06 -07:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("tweak");
|
2015-03-04 17:03:39 -07:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
2014-12-06 16:47:35 -07:00
|
|
|
|
2015-06-26 21:18:08 -06:00
|
|
|
REQUIRE_GLOBAL(enabler);
|
2023-01-05 18:11:01 -07:00
|
|
|
REQUIRE_GLOBAL(plotinfo);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(ui_build_selector);
|
2017-06-25 13:21:45 -06:00
|
|
|
REQUIRE_GLOBAL(ui_building_in_assign);
|
|
|
|
REQUIRE_GLOBAL(ui_building_in_resize);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(ui_building_item_cursor);
|
2016-01-08 17:27:11 -07:00
|
|
|
REQUIRE_GLOBAL(ui_look_cursor);
|
2017-12-07 12:37:15 -07:00
|
|
|
REQUIRE_GLOBAL(ui_menu_width);
|
2023-01-05 18:11:01 -07:00
|
|
|
REQUIRE_GLOBAL(game);
|
2016-01-08 17:27:11 -07:00
|
|
|
REQUIRE_GLOBAL(ui_unit_view_mode);
|
2015-06-27 09:02:26 -06:00
|
|
|
REQUIRE_GLOBAL(ui_workshop_in_add);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
2012-03-05 08:47:06 -07:00
|
|
|
|
|
|
|
using namespace DFHack::Gui;
|
|
|
|
|
2015-03-04 17:03:39 -07:00
|
|
|
class tweak_onupdate_hookst {
|
|
|
|
public:
|
|
|
|
typedef void(*T_callback)(void);
|
2018-04-06 13:17:34 -06:00
|
|
|
tweak_onupdate_hookst(std::string name_, T_callback cb)
|
|
|
|
:enabled(false), name(name_), callback(cb) {}
|
2015-03-04 17:03:39 -07:00
|
|
|
bool enabled;
|
|
|
|
std::string name;
|
|
|
|
T_callback callback;
|
|
|
|
};
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result tweak(color_ostream &out, vector <string> & parameters);
|
2014-09-26 16:40:19 -06:00
|
|
|
static std::multimap<std::string, VMethodInterposeLinkBase> tweak_hooks;
|
2015-03-04 17:03:39 -07:00
|
|
|
static std::multimap<std::string, tweak_onupdate_hookst> tweak_onupdate_hooks;
|
2012-03-05 08:47:06 -07:00
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
#define TWEAK_HOOK(tweak, cls, func) tweak_hooks.insert(std::pair<std::string, VMethodInterposeLinkBase>\
|
|
|
|
(tweak, INTERPOSE_HOOK(cls, func)))
|
2015-03-04 17:03:39 -07:00
|
|
|
#define TWEAK_ONUPDATE_HOOK(tweak, func) tweak_onupdate_hooks.insert(\
|
|
|
|
std::pair<std::string, tweak_onupdate_hookst>(tweak, tweak_onupdate_hookst(#func, func)))
|
2014-09-26 16:40:19 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-03-05 08:47:06 -07:00
|
|
|
{
|
2015-05-08 15:35:46 -06:00
|
|
|
is_enabled = true; // Allow plugin_onupdate to work (subcommands are enabled individually)
|
2012-03-05 08:47:06 -07:00
|
|
|
commands.push_back(PluginCommand(
|
2022-07-31 14:31:54 -06:00
|
|
|
"tweak",
|
|
|
|
"Various tweaks for minor bugs.",
|
|
|
|
tweak));
|
2014-09-26 16:40:19 -06:00
|
|
|
|
|
|
|
TWEAK_HOOK("adamantine-cloth-wear", adamantine_cloth_wear_armor_hook, incWearTimer);
|
|
|
|
TWEAK_HOOK("adamantine-cloth-wear", adamantine_cloth_wear_helm_hook, incWearTimer);
|
|
|
|
TWEAK_HOOK("adamantine-cloth-wear", adamantine_cloth_wear_gloves_hook, incWearTimer);
|
|
|
|
TWEAK_HOOK("adamantine-cloth-wear", adamantine_cloth_wear_shoes_hook, incWearTimer);
|
|
|
|
TWEAK_HOOK("adamantine-cloth-wear", adamantine_cloth_wear_pants_hook, incWearTimer);
|
|
|
|
|
|
|
|
TWEAK_HOOK("advmode-contained", advmode_contained_hook, feed);
|
|
|
|
|
2016-01-08 17:27:11 -07:00
|
|
|
TWEAK_HOOK("block-labors", block_labors_hook, feed);
|
|
|
|
TWEAK_HOOK("block-labors", block_labors_hook, render);
|
|
|
|
|
2017-06-25 14:42:30 -06:00
|
|
|
TWEAK_HOOK("burrow-name-cancel", burrow_name_cancel_hook, feed);
|
|
|
|
|
2017-06-25 13:21:45 -06:00
|
|
|
TWEAK_HOOK("cage-butcher", cage_butcher_hook, feed);
|
|
|
|
TWEAK_HOOK("cage-butcher", cage_butcher_hook, render);
|
|
|
|
|
2014-09-28 11:13:01 -06:00
|
|
|
TWEAK_HOOK("civ-view-agreement", civ_agreement_view_hook, render);
|
|
|
|
|
2017-03-28 07:50:38 -06:00
|
|
|
TWEAK_HOOK("condition-material", condition_material_hook, feed);
|
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
TWEAK_HOOK("craft-age-wear", craft_age_wear_hook, ageItem);
|
|
|
|
|
2020-08-06 20:30:29 -06:00
|
|
|
TWEAK_HOOK("do-job-now", do_job_now_hook, feed);
|
|
|
|
TWEAK_HOOK("do-job-now", do_job_now_hook, render);
|
|
|
|
|
2015-01-01 11:47:47 -07:00
|
|
|
TWEAK_HOOK("eggs-fertile", egg_fertile_hook, render);
|
|
|
|
|
2015-08-25 08:12:31 -06:00
|
|
|
TWEAK_HOOK("embark-profile-name", embark_profile_name_hook, feed);
|
|
|
|
|
2014-09-27 17:55:39 -06:00
|
|
|
TWEAK_HOOK("farm-plot-select", farm_select_hook, feed);
|
|
|
|
TWEAK_HOOK("farm-plot-select", farm_select_hook, render);
|
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
TWEAK_HOOK("fast-heat", fast_heat_hook, updateTempFromMap);
|
|
|
|
TWEAK_HOOK("fast-heat", fast_heat_hook, updateTemperature);
|
|
|
|
TWEAK_HOOK("fast-heat", fast_heat_hook, adjustTemperature);
|
|
|
|
|
|
|
|
TWEAK_HOOK("fast-trade", fast_trade_assign_hook, feed);
|
|
|
|
TWEAK_HOOK("fast-trade", fast_trade_select_hook, feed);
|
|
|
|
|
2015-03-04 17:03:39 -07:00
|
|
|
TWEAK_ONUPDATE_HOOK("fps-min", fps_min_hook);
|
|
|
|
|
2016-01-04 17:29:30 -07:00
|
|
|
TWEAK_HOOK("hide-priority", hide_priority_hook, feed);
|
|
|
|
TWEAK_HOOK("hide-priority", hide_priority_hook, render);
|
|
|
|
|
2017-04-19 11:31:25 -06:00
|
|
|
TWEAK_HOOK("hotkey-clear", hotkey_clear_hook, feed);
|
|
|
|
TWEAK_HOOK("hotkey-clear", hotkey_clear_hook, render);
|
|
|
|
|
2014-09-27 16:14:25 -06:00
|
|
|
TWEAK_HOOK("import-priority-category", takerequest_hook, feed);
|
|
|
|
TWEAK_HOOK("import-priority-category", takerequest_hook, render);
|
|
|
|
|
2018-05-17 17:47:56 -06:00
|
|
|
TWEAK_HOOK("kitchen-prefs-all", kitchen_prefs_all_hook, feed);
|
|
|
|
TWEAK_HOOK("kitchen-prefs-all", kitchen_prefs_all_hook, render);
|
|
|
|
|
2015-06-26 21:18:08 -06:00
|
|
|
TWEAK_HOOK("kitchen-prefs-color", kitchen_prefs_color_hook, render);
|
|
|
|
|
2015-06-26 19:16:27 -06:00
|
|
|
TWEAK_HOOK("kitchen-prefs-empty", kitchen_prefs_empty_hook, render);
|
|
|
|
|
2015-01-01 12:36:30 -07:00
|
|
|
TWEAK_HOOK("max-wheelbarrow", max_wheelbarrow_hook, render);
|
|
|
|
TWEAK_HOOK("max-wheelbarrow", max_wheelbarrow_hook, feed);
|
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
TWEAK_HOOK("military-color-assigned", military_assign_hook, render);
|
|
|
|
|
|
|
|
TWEAK_HOOK("military-stable-assign", military_assign_hook, feed);
|
|
|
|
|
2014-10-01 18:13:31 -06:00
|
|
|
TWEAK_HOOK("nestbox-color", nestbox_color_hook, drawBuilding);
|
|
|
|
|
2022-04-26 20:52:24 -06:00
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_bar, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_drink, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_glob, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_liquid_misc, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_powder_misc, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_cloth, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_sheet, getItemDescription);
|
|
|
|
TWEAK_HOOK("partial-items", partial_items_hook_thread, getItemDescription);
|
|
|
|
|
2018-02-03 08:29:30 -07:00
|
|
|
TWEAK_HOOK("pausing-fps-counter", dwarfmode_pausing_fps_counter_hook, render);
|
|
|
|
TWEAK_HOOK("pausing-fps-counter", title_pausing_fps_counter_hook, render);
|
|
|
|
|
2022-04-26 20:52:24 -06:00
|
|
|
TWEAK_HOOK("reaction-gloves", reaction_gloves_hook, produce);
|
|
|
|
|
2015-02-17 08:43:55 -07:00
|
|
|
TWEAK_HOOK("shift-8-scroll", shift_8_scroll_hook, feed);
|
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
TWEAK_HOOK("stable-cursor", stable_cursor_hook, feed);
|
|
|
|
|
2018-05-14 20:54:20 -06:00
|
|
|
TWEAK_HOOK("stone-status-all", stone_status_all_hook, feed);
|
|
|
|
TWEAK_HOOK("stone-status-all", stone_status_all_hook, render);
|
|
|
|
|
2015-12-26 09:47:55 -07:00
|
|
|
TWEAK_HOOK("title-start-rename", title_start_rename_hook, feed);
|
|
|
|
TWEAK_HOOK("title-start-rename", title_start_rename_hook, render);
|
|
|
|
|
2015-01-28 14:54:53 -07:00
|
|
|
TWEAK_HOOK("tradereq-pet-gender", pet_gender_hook, render);
|
|
|
|
|
2012-03-05 08:47:06 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-04 17:03:39 -07:00
|
|
|
DFhackCExport command_result plugin_onupdate (color_ostream &out)
|
|
|
|
{
|
|
|
|
for (auto it = tweak_onupdate_hooks.begin(); it != tweak_onupdate_hooks.end(); ++it)
|
|
|
|
{
|
|
|
|
tweak_onupdate_hookst hook = it->second;
|
|
|
|
if (hook.enabled)
|
|
|
|
hook.callback();
|
|
|
|
}
|
2015-03-29 12:21:59 -06:00
|
|
|
return CR_OK;
|
2015-03-04 17:03:39 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown (color_ostream &out)
|
2012-03-05 08:47:06 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
|
2012-04-12 06:40:39 -06:00
|
|
|
// to be called by tweak-fixmigrant
|
2012-04-11 13:07:54 -06:00
|
|
|
// units forced into the fort by removing the flags do not own their clothes
|
|
|
|
// which has the result that they drop all their clothes and become unhappy because they are naked
|
2012-04-12 06:40:39 -06:00
|
|
|
// so we need to make them own their clothes and add them to their uniform
|
2012-04-11 13:07:54 -06:00
|
|
|
command_result fix_clothing_ownership(color_ostream &out, df::unit* unit)
|
|
|
|
{
|
|
|
|
// first, find one owned item to initialize the vtable
|
|
|
|
bool vt_initialized = false;
|
|
|
|
size_t numItems = world->items.all.size();
|
|
|
|
for(size_t i=0; i< numItems; i++)
|
|
|
|
{
|
|
|
|
df::item * item = world->items.all[i];
|
|
|
|
if(Items::getOwner(item))
|
|
|
|
{
|
|
|
|
vt_initialized = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!vt_initialized)
|
|
|
|
{
|
|
|
|
out << "fix_clothing_ownership: could not initialize vtable!" << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fixcount = 0;
|
|
|
|
for(size_t j=0; j<unit->inventory.size(); j++)
|
|
|
|
{
|
|
|
|
df::unit_inventory_item* inv_item = unit->inventory[j];
|
|
|
|
df::item* item = inv_item->item;
|
2012-04-14 05:36:22 -06:00
|
|
|
// unforbid items (for the case of kidnapping caravan escorts who have their stuff forbidden by default)
|
|
|
|
inv_item->item->flags.bits.forbid = 0;
|
2012-04-11 13:07:54 -06:00
|
|
|
if(inv_item->mode == df::unit_inventory_item::T_mode::Worn)
|
|
|
|
{
|
|
|
|
// ignore armor?
|
|
|
|
// it could be leather boots, for example, in which case it would not be nice to forbid ownership
|
|
|
|
//if(item->getEffectiveArmorLevel() != 0)
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
if(!Items::getOwner(item))
|
|
|
|
{
|
|
|
|
if(Items::setOwner(item, unit))
|
2012-04-12 06:40:39 -06:00
|
|
|
{
|
|
|
|
// add to uniform, so they know they should wear their clothes
|
|
|
|
insert_into_vector(unit->military.uniforms[0], item->id);
|
2012-04-11 13:07:54 -06:00
|
|
|
fixcount++;
|
2012-04-12 06:40:39 -06:00
|
|
|
}
|
2012-04-11 13:07:54 -06:00
|
|
|
else
|
|
|
|
out << "could not change ownership for item!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 06:40:39 -06:00
|
|
|
// clear uniform_drop (without this they would drop their clothes and pick them up some time later)
|
|
|
|
unit->military.uniform_drop.clear();
|
2012-04-11 13:07:54 -06:00
|
|
|
out << "ownership for " << fixcount << " clothes fixed" << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-30 10:48:06 -06:00
|
|
|
static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector <string> ¶meters)
|
|
|
|
{
|
|
|
|
if (vector_get(parameters, 1) == "disable")
|
|
|
|
{
|
|
|
|
hook.remove();
|
2015-05-16 16:23:02 -06:00
|
|
|
fprintf(stderr, "Disabled tweak %s (%s)\n", parameters[0].c_str(), hook.name());
|
|
|
|
fflush(stderr);
|
2012-08-30 10:48:06 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (hook.apply())
|
2015-05-16 16:23:02 -06:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Enabled tweak %s (%s)\n", parameters[0].c_str(), hook.name());
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
2012-08-30 10:48:06 -06:00
|
|
|
else
|
2013-08-22 02:14:45 -06:00
|
|
|
out.printerr("Could not activate tweak %s (%s)\n", parameters[0].c_str(), hook.name());
|
2012-08-30 10:48:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:40:19 -06:00
|
|
|
static command_result enable_tweak(string tweak, color_ostream &out, vector <string> ¶meters)
|
|
|
|
{
|
|
|
|
bool recognized = false;
|
|
|
|
string cmd = parameters[0];
|
|
|
|
for (auto it = tweak_hooks.begin(); it != tweak_hooks.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it->first == cmd)
|
|
|
|
{
|
|
|
|
recognized = true;
|
|
|
|
enable_hook(out, it->second, parameters);
|
|
|
|
}
|
|
|
|
}
|
2015-03-04 17:03:39 -07:00
|
|
|
for (auto it = tweak_onupdate_hooks.begin(); it != tweak_onupdate_hooks.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it->first == cmd)
|
|
|
|
{
|
|
|
|
bool state = (vector_get(parameters, 1) != "disable");
|
|
|
|
recognized = true;
|
2015-05-08 15:35:46 -06:00
|
|
|
tweak_onupdate_hookst &hook = it->second;
|
2015-03-04 17:03:39 -07:00
|
|
|
hook.enabled = state;
|
2015-05-16 16:23:02 -06:00
|
|
|
fprintf(stderr, "%s tweak %s (%s)\n", state ? "Enabled" : "Disabled", cmd.c_str(), hook.name.c_str());
|
|
|
|
fflush(stderr);
|
2015-03-04 17:03:39 -07:00
|
|
|
}
|
|
|
|
}
|
2014-09-26 16:40:19 -06:00
|
|
|
if (!recognized)
|
|
|
|
{
|
|
|
|
out.printerr("Unrecognized tweak: %s\n", cmd.c_str());
|
2015-02-17 08:43:55 -07:00
|
|
|
out.print("Run 'help tweak' to display a full list\n");
|
|
|
|
return CR_FAILURE; // Avoid dumping usage information
|
2014-09-26 16:40:19 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result tweak(color_ostream &out, vector <string> ¶meters)
|
2012-03-05 08:47:06 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-03-05 08:47:06 -07:00
|
|
|
|
|
|
|
if (parameters.empty())
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
string cmd = parameters[0];
|
|
|
|
|
|
|
|
if (cmd == "clear-missing")
|
|
|
|
{
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-03-05 08:47:06 -07:00
|
|
|
if (!unit)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
2014-07-29 15:26:14 -06:00
|
|
|
auto death = df::incident::find(unit->counters.death_id);
|
2012-03-05 08:47:06 -07:00
|
|
|
|
|
|
|
if (death)
|
|
|
|
{
|
|
|
|
death->flags.bits.discovered = true;
|
|
|
|
|
2014-07-29 15:27:16 -06:00
|
|
|
auto crime = df::crime::find(death->crime_id);
|
2012-03-05 08:47:06 -07:00
|
|
|
if (crime)
|
|
|
|
crime->flags.bits.discovered = true;
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 09:30:15 -06:00
|
|
|
else if (cmd == "clear-ghostly")
|
|
|
|
{
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-03-22 09:30:15 -06:00
|
|
|
if (!unit)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
// don't accidentally kill non-ghosts!
|
|
|
|
if (unit->flags3.bits.ghostly)
|
|
|
|
{
|
|
|
|
// remove ghostly, set to dead instead
|
|
|
|
unit->flags3.bits.ghostly = 0;
|
2018-06-21 09:17:09 -06:00
|
|
|
unit->flags1.bits.inactive = 1;
|
2012-03-22 09:30:15 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.print("That's not a ghost!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 14:29:56 -06:00
|
|
|
else if (cmd == "fixmigrant")
|
2012-04-09 16:22:38 -06:00
|
|
|
{
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-04-11 14:29:56 -06:00
|
|
|
if (!unit)
|
|
|
|
return CR_FAILURE;
|
2014-06-03 16:29:13 -06:00
|
|
|
|
2015-01-28 14:26:17 -07:00
|
|
|
if(!Units::isOwnRace(unit))
|
2012-04-09 16:22:38 -06:00
|
|
|
{
|
2012-04-11 14:29:56 -06:00
|
|
|
out << "Selected unit does not belong to your race!" << endl;
|
2012-04-09 16:22:38 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-04-12 06:40:39 -06:00
|
|
|
// case #1: migrants who have the resident flag set
|
2012-04-11 14:29:56 -06:00
|
|
|
if (unit->flags2.bits.resident)
|
|
|
|
unit->flags2.bits.resident = 0;
|
2014-06-03 16:29:13 -06:00
|
|
|
|
2012-04-12 06:40:39 -06:00
|
|
|
// case #2: migrants who have the merchant flag
|
|
|
|
// happens on almost all maps after a few migrant waves
|
2015-01-28 14:26:17 -07:00
|
|
|
if(Units::isMerchant(unit))
|
2012-04-09 16:22:38 -06:00
|
|
|
unit->flags1.bits.merchant = 0;
|
2012-04-11 14:29:56 -06:00
|
|
|
|
2014-06-03 16:29:13 -06:00
|
|
|
// this one is a cheat, but bugged migrants usually have the same civ_id
|
2012-04-12 06:40:39 -06:00
|
|
|
// so it should not be triggered in most cases
|
2014-06-03 16:29:13 -06:00
|
|
|
// if it happens that the player has 'foreign' units of the same race
|
2012-04-12 06:40:39 -06:00
|
|
|
// (vanilla df: dwarves not from mountainhome) on his map, just grab them
|
2015-01-28 14:26:17 -07:00
|
|
|
if(!Units::isOwnCiv(unit))
|
2023-01-05 18:11:01 -07:00
|
|
|
unit->civ_id = plotinfo->civ_id;
|
2012-04-11 14:29:56 -06:00
|
|
|
|
|
|
|
return fix_clothing_ownership(out, unit);
|
2012-04-09 16:22:38 -06:00
|
|
|
}
|
2012-04-14 05:36:22 -06:00
|
|
|
else if (cmd == "makeown")
|
|
|
|
{
|
|
|
|
// force a unit into your fort, regardless of civ or race
|
|
|
|
// allows to "steal" caravan guards etc
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-04-14 05:36:22 -06:00
|
|
|
if (!unit)
|
|
|
|
return CR_FAILURE;
|
2012-04-17 08:57:41 -06:00
|
|
|
|
2012-04-14 05:36:22 -06:00
|
|
|
if (unit->flags2.bits.resident)
|
|
|
|
unit->flags2.bits.resident = 0;
|
2015-01-28 14:26:17 -07:00
|
|
|
if(Units::isMerchant(unit))
|
2012-04-14 05:36:22 -06:00
|
|
|
unit->flags1.bits.merchant = 0;
|
2015-01-28 14:26:17 -07:00
|
|
|
if(Units::isForest(unit))
|
2012-04-14 05:36:22 -06:00
|
|
|
unit->flags1.bits.forest = 0;
|
2015-01-28 14:26:17 -07:00
|
|
|
if(!Units::isOwnCiv(unit))
|
2023-01-05 18:11:01 -07:00
|
|
|
unit->civ_id = plotinfo->civ_id;
|
2012-04-14 11:06:03 -06:00
|
|
|
if(unit->profession == df::profession::MERCHANT)
|
|
|
|
unit->profession = df::profession::TRADER;
|
|
|
|
if(unit->profession2 == df::profession::MERCHANT)
|
|
|
|
unit->profession2 = df::profession::TRADER;
|
2012-04-14 05:36:22 -06:00
|
|
|
return fix_clothing_ownership(out, unit);
|
|
|
|
}
|
2012-09-14 02:14:36 -06:00
|
|
|
else if (cmd == "fast-heat")
|
|
|
|
{
|
|
|
|
if (parameters.size() < 2)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
max_heat_ticks = atoi(parameters[1].c_str());
|
|
|
|
if (max_heat_ticks <= 0)
|
|
|
|
parameters[1] = "disable";
|
2014-09-26 16:40:19 -06:00
|
|
|
enable_tweak(cmd, out, parameters);
|
|
|
|
return CR_OK;
|
2012-09-14 02:14:36 -06:00
|
|
|
}
|
2014-09-26 16:40:19 -06:00
|
|
|
else
|
2014-05-08 13:22:45 -06:00
|
|
|
{
|
2014-09-26 16:40:19 -06:00
|
|
|
return enable_tweak(cmd, out, parameters);
|
2014-05-08 13:22:45 -06:00
|
|
|
}
|
2012-03-05 08:47:06 -07:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|