From 0df2d71506b78d367dc31da8867fbd33d9fd6b9a Mon Sep 17 00:00:00 2001 From: expwnent Date: Sat, 4 Oct 2014 21:52:28 -0400 Subject: [PATCH 1/8] Fix repeat.lua documentation. --- scripts/repeat.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/repeat.lua b/scripts/repeat.lua index fe9afb026..0c08d8fa8 100644 --- a/scripts/repeat.lua +++ b/scripts/repeat.lua @@ -24,13 +24,13 @@ if args.help then print this help message repeat -cancel bob cancels the repetition with the name bob - repeat -name jim -time delay -timeUnits units -printResult true -command printArgs 3 1 2 + repeat -name jim -time delay -timeUnits units -printResult true -command [ printArgs 3 1 2 ] -name sets the name for the purposes of cancelling and making sure you don't schedule the same repeating event twice if not specified, it's set to the first argument after -command -time delay -timeUnits units delay is some positive integer units is some valid time unit for dfhack.timeout(delay,timeUnits,function) - -command ... + -command [ ... ] specify the command to be run ]]) return From 0471294b1e053139212fa4202956b8d7c7a6940a Mon Sep 17 00:00:00 2001 From: expwnent Date: Sat, 4 Oct 2014 21:54:07 -0400 Subject: [PATCH 2/8] Fix syndrome-util. --- library/lua/syndrome-util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/lua/syndrome-util.lua b/library/lua/syndrome-util.lua index 90e699de7..083c90371 100644 --- a/library/lua/syndrome-util.lua +++ b/library/lua/syndrome-util.lua @@ -119,7 +119,7 @@ function isValidTarget(unit,syndrome) end for caste,creature in ipairs(syndrome.syn_affected_creature) do local affectedCreature = creature.value - local affectedCaste = syndrome.syn_affectedCaste[caste].value + local affectedCaste = syndrome.syn_affected_caste[caste].value if affectedCreature == unitRaceName and (affectedCaste == unitCasteName or affectedCaste == "ALL") then affected = true end From 04ec2c99324817828295d22f1e1dce00d5750438 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 26 Oct 2014 16:40:39 +0300 Subject: [PATCH 3/8] Update version to v0.40.14 and hack things so they compile. Also make the find-offsets script less likely to crash if the unit structure is misaligned and add more integrity checks. --- CMakeLists.txt | 4 +-- library/modules/Units.cpp | 2 +- library/xml | 2 +- plugins/CMakeLists.txt | 4 +-- plugins/autolabor.cpp | 2 +- plugins/manipulator.cpp | 7 +++--- plugins/strangemood.cpp | 4 +-- scripts/devel/find-offsets.lua | 46 +++++++++++++++++++++++----------- 8 files changed, 45 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a353495b8..c1862d122 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,8 @@ if (NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl OR NOT EXISTS ${dfhac endif() # set up versioning. -set(DF_VERSION "0.40.13") -SET(DFHACK_RELEASE "r1" CACHE STRING "Current release revision.") +set(DF_VERSION "0.40.14") +SET(DFHACK_RELEASE "r0" CACHE STRING "Current release revision.") set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}") diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 9d2ebf2dd..463cea227 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -154,7 +154,7 @@ void Units::CopyCreature(df::unit * source, t_unit & furball) // profession furball.profession = source->profession; // happiness - furball.happiness = source->status.happiness; + furball.happiness = 100;//source->status.happiness; // physical attributes memcpy(&furball.strength, source->body.physical_attrs, sizeof(source->body.physical_attrs)); diff --git a/library/xml b/library/xml index aed9a7644..62dcffa67 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit aed9a7644cd1d4a599c10d5f579fc742ced6bc3f +Subproject commit 62dcffa67998643966267763526b82bd7674b583 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 6ebe3ad6d..2aea9542c 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -110,7 +110,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(digFlood digFlood.cpp) add_subdirectory(diggingInvaders) DFHACK_PLUGIN(drybuckets drybuckets.cpp) - DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp) + #DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp) DFHACK_PLUGIN(embark-tools embark-tools.cpp) DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) @@ -132,7 +132,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) DFHACK_PLUGIN(manipulator manipulator.cpp) DFHACK_PLUGIN(mode mode.cpp) - DFHACK_PLUGIN(misery misery.cpp) + #DFHACK_PLUGIN(misery misery.cpp) DFHACK_PLUGIN(mousequery mousequery.cpp) DFHACK_PLUGIN(petcapRemover petcapRemover.cpp) DFHACK_PLUGIN(plants plants.cpp) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index 05855a749..23ae71969 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -819,7 +819,7 @@ static void assign_labor(unit_labor::unit_labor labor, // bias by happiness - value += dwarfs[dwarf]->status.happiness; + //value += dwarfs[dwarf]->status.happiness; values[dwarf] = value; diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index ebd23a9d7..8deddec11 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -313,10 +313,11 @@ bool sortBySquad (const UnitInfo *d1, const UnitInfo *d2) bool sortByHappiness (const UnitInfo *d1, const UnitInfo *d2) { - if (descending) + return sortByName(d1, d2); + /*if (descending) return (d1->unit->status.happiness > d2->unit->status.happiness); else - return (d1->unit->status.happiness < d2->unit->status.happiness); + return (d1->unit->status.happiness < d2->unit->status.happiness);*/ } bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2) @@ -1043,7 +1044,7 @@ void viewscreen_unitlaborsst::render() df::unit *unit = cur->unit; int8_t fg = 15, bg = 0; - int happy = cur->unit->status.happiness; + int happy = 100;//cur->unit->status.happiness; string happiness = stl_sprintf("%4i", happy); if (happy == 0) // miserable fg = 13; // 5:1 diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index e1cedbfe3..41b25a9bc 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -631,7 +631,7 @@ command_result df_strangemood (color_ostream &out, vector & parameters) // If no mood type was specified, pick one randomly if (type == mood_type::None) { - if (rng.df_trandom(100) > unit->status.happiness) + if (rng.df_trandom(100) > 90)//rng.df_trandom(100) > unit->status.happiness) { switch (rng.df_trandom(2)) { @@ -691,7 +691,7 @@ command_result df_strangemood (color_ostream &out, vector & parameters) unit->relations.mood_copy = unit->mood; Gui::showAutoAnnouncement(announcement_type::STRANGE_MOOD, unit->pos, msg, color, bright); - unit->status.happiness = 100; + //unit->status.happiness = 100; // TODO: make sure unit drops any wrestle items unit->job.mood_timeout = 50000; unit->flags1.bits.has_mood = true; diff --git a/scripts/devel/find-offsets.lua b/scripts/devel/find-offsets.lua index d8b3406f9..ae99adbca 100644 --- a/scripts/devel/find-offsets.lua +++ b/scripts/devel/find-offsets.lua @@ -131,15 +131,24 @@ local function zoomed_searcher(startn, end_or_sz) end local finder_searches = {} -local function exec_finder(finder, names) +local function exec_finder(finder, names, validators) if type(names) ~= 'table' then names = { names } end + if type(validators) ~= 'table' then + validators = { validators } + end local search = force_scan['all'] - for _,v in ipairs(names) do + for k,v in ipairs(names) do if force_scan[v] or not is_known(v) then table.insert(finder_searches, v) search = true + elseif validators[k] then + if not validators[k](df.global[v]) then + dfhack.printerr('Validation failed for '..v..', will try to find again') + table.insert(finder_searches, v) + search = true + end end end if search then @@ -505,6 +514,7 @@ end local function is_valid_world(world) if not ms.is_valid_vector(world.units.all, 4) + or not ms.is_valid_vector(world.units.active, 4) or not ms.is_valid_vector(world.units.bad, 4) or not ms.is_valid_vector(world.history.figures, 4) or not ms.is_valid_vector(world.features.map_features, 4) @@ -776,11 +786,6 @@ end -- local function find_current_weather() - print('\nPlease load the save previously processed with prepare-save.') - if not utils.prompt_yes_no('Proceed?', true) then - return - end - local zone if os_type == 'windows' then zone = zoomed_searcher('crime_next_id', 512) @@ -839,7 +844,14 @@ local function find_ui_selected_unit() end for i,unit in ipairs(df.global.world.units.active) do - dfhack.units.setNickname(unit, i) + -- This function does a lot of things and accesses histfigs, souls and so on: + --dfhack.units.setNickname(unit, i) + + -- Instead use just a simple bit of code that only requires the start of the + -- unit to be valid. It may not work properly with vampires or reset later + -- if unpaused, but is sufficient for this script and won't crash: + unit.name.nickname = tostring(i) + unit.name.has_name = true end local addr = searcher:find_menu_cursor([[ @@ -1506,17 +1518,23 @@ print('\nInitial globals (need title screen):\n') exec_finder(find_gview, 'gview') exec_finder(find_cursor, { 'cursor', 'selection_rect', 'gamemode', 'gametype' }) exec_finder(find_announcements, 'announcements') -exec_finder(find_d_init, 'd_init') -exec_finder(find_enabler, 'enabler') -exec_finder(find_gps, 'gps') +exec_finder(find_d_init, 'd_init', is_valid_d_init) +exec_finder(find_enabler, 'enabler', is_valid_enabler) +exec_finder(find_gps, 'gps', is_valid_gps) print('\nCompound globals (need loaded world):\n') -exec_finder(find_world, 'world') -exec_finder(find_ui, 'ui') +print('\nPlease load the save previously processed with prepare-save.') +if not utils.prompt_yes_no('Proceed?', true) then + searcher:reset() + return +end + +exec_finder(find_world, 'world', is_valid_world) +exec_finder(find_ui, 'ui', is_valid_ui) exec_finder(find_ui_sidebar_menus, 'ui_sidebar_menus') exec_finder(find_ui_build_selector, 'ui_build_selector') -exec_finder(find_init, 'init') +exec_finder(find_init, 'init', is_valid_init) print('\nPrimitive globals:\n') From f683395caea03a6f3e732434a565870f20907c89 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 31 Oct 2014 13:33:04 -0500 Subject: [PATCH 4/8] Comment out more of military-training tweak, which no longer compiles --- plugins/tweak.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index 1e114fc43..0420d61ca 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -765,6 +765,7 @@ struct military_assign_hook : df::viewscreen_layer_militaryst { IMPLEMENT_VMETHOD_INTERPOSE(military_assign_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(military_assign_hook, render); +/* // Unit updates are executed based on an action divisor variable, // which is computed from the alive unit count and has range 10-100. static int adjust_unit_divisor(int value) { @@ -943,6 +944,7 @@ struct military_training_ct_hook : df::activity_event_combat_trainingst { } } }; +*/ /* IMPLEMENT_VMETHOD_INTERPOSE(military_training_ct_hook, process); From ed225de3651b44153b421c56c46c646b1ae447f2 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 31 Oct 2014 13:33:18 -0500 Subject: [PATCH 5/8] Update strangemood to check stress level for fell/macabre moods --- plugins/strangemood.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index 41b25a9bc..b91b1ff94 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -631,7 +631,11 @@ command_result df_strangemood (color_ostream &out, vector & parameters) // If no mood type was specified, pick one randomly if (type == mood_type::None) { - if (rng.df_trandom(100) > 90)//rng.df_trandom(100) > unit->status.happiness) + if (soul && ( + (soul->personality.stress_level >= 500000) || + (soul->personality.stress_level >= 250000 && !rng.df_trandom(2)) || + (soul->personality.stress_level >= 100000 && !rng.df_trandom(10)) + )) { switch (rng.df_trandom(2)) { From f08a32f4e2fd2da676b459a08319170ddeddcbb3 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 31 Oct 2014 13:33:35 -0500 Subject: [PATCH 6/8] Update Manipulator to display stress level instead of happiness --- plugins/manipulator.cpp | 65 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 8deddec11..8e379f98a 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -270,7 +270,7 @@ struct UnitInfo enum altsort_mode { ALTSORT_NAME, ALTSORT_PROFESSION_OR_SQUAD, - ALTSORT_HAPPINESS, + ALTSORT_STRESS, ALTSORT_ARRIVAL, ALTSORT_MAX }; @@ -311,13 +311,17 @@ bool sortBySquad (const UnitInfo *d1, const UnitInfo *d2) return descending ? gt : !gt; } -bool sortByHappiness (const UnitInfo *d1, const UnitInfo *d2) +bool sortByStress (const UnitInfo *d1, const UnitInfo *d2) { - return sortByName(d1, d2); - /*if (descending) - return (d1->unit->status.happiness > d2->unit->status.happiness); + if (!d1->unit->status.current_soul) + return !descending; + if (!d2->unit->status.current_soul) + return descending; + + if (descending) + return (d1->unit->status.current_soul->personality.stress_level > d2->unit->status.current_soul->personality.stress_level); else - return (d1->unit->status.happiness < d2->unit->status.happiness);*/ + return (d1->unit->status.current_soul->personality.stress_level < d2->unit->status.current_soul->personality.stress_level); } bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2) @@ -368,7 +372,7 @@ bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2) } enum display_columns { - DISP_COLUMN_HAPPINESS, + DISP_COLUMN_STRESS, DISP_COLUMN_NAME, DISP_COLUMN_PROFESSION_OR_SQUAD, DISP_COLUMN_LABORS, @@ -510,8 +514,8 @@ void viewscreen_unitlaborsst::calcSize() // min/max width of columns int col_minwidth[DISP_COLUMN_MAX]; int col_maxwidth[DISP_COLUMN_MAX]; - col_minwidth[DISP_COLUMN_HAPPINESS] = 4; - col_maxwidth[DISP_COLUMN_HAPPINESS] = 4; + col_minwidth[DISP_COLUMN_STRESS] = 6; + col_maxwidth[DISP_COLUMN_STRESS] = 6; col_minwidth[DISP_COLUMN_NAME] = 16; col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; @@ -779,10 +783,10 @@ void viewscreen_unitlaborsst::feed(set *events) switch (click_header) { - case DISP_COLUMN_HAPPINESS: + case DISP_COLUMN_STRESS: if (enabler->mouse_lbut || enabler->mouse_rbut) { - input_sort = ALTSORT_HAPPINESS; + input_sort = ALTSORT_STRESS; if (enabler->mouse_lbut) events->insert(interface_key::SECONDSCROLL_PAGEUP); if (enabler->mouse_rbut) @@ -826,7 +830,7 @@ void viewscreen_unitlaborsst::feed(set *events) switch (click_body) { - case DISP_COLUMN_HAPPINESS: + case DISP_COLUMN_STRESS: // do nothing break; @@ -932,8 +936,8 @@ void viewscreen_unitlaborsst::feed(set *events) case ALTSORT_PROFESSION_OR_SQUAD: std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession); break; - case ALTSORT_HAPPINESS: - std::sort(units.begin(), units.end(), sortByHappiness); + case ALTSORT_STRESS: + std::sort(units.begin(), units.end(), sortByStress); break; case ALTSORT_ARRIVAL: std::sort(units.begin(), units.end(), sortByArrival); @@ -948,9 +952,9 @@ void viewscreen_unitlaborsst::feed(set *events) altsort = ALTSORT_PROFESSION_OR_SQUAD; break; case ALTSORT_PROFESSION_OR_SQUAD: - altsort = ALTSORT_HAPPINESS; + altsort = ALTSORT_STRESS; break; - case ALTSORT_HAPPINESS: + case ALTSORT_STRESS: altsort = ALTSORT_ARRIVAL; break; case ALTSORT_ARRIVAL: @@ -1001,7 +1005,7 @@ void viewscreen_unitlaborsst::render() Screen::clear(); Screen::drawBorder(" Dwarf Manipulator - Manage Labors "); - Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_HAPPINESS], 2, "Hap."); + Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_STRESS], 2, "Stress"); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name"); Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 2, show_squad ? "Squad" : "Profession"); @@ -1044,23 +1048,22 @@ void viewscreen_unitlaborsst::render() df::unit *unit = cur->unit; int8_t fg = 15, bg = 0; - int happy = 100;//cur->unit->status.happiness; - string happiness = stl_sprintf("%4i", happy); - if (happy == 0) // miserable + int stress_lvl = unit->status.current_soul ? unit->status.current_soul->personality.stress_level : 0; + // cap at 6 digits + if (stress_lvl < -99999) stress_lvl = -99999; + if (stress_lvl > 999999) stress_lvl = 999999; + string stress = stl_sprintf("%6i", stress_lvl); + if (stress_lvl >= 500000) fg = 13; // 5:1 - else if (happy <= 25) // very unhappy + else if (stress_lvl >= 250000) fg = 12; // 4:1 - else if (happy <= 50) // unhappy - fg = 4; // 4:0 - else if (happy < 75) // fine + else if (stress_lvl >= 100000) fg = 14; // 6:1 - else if (happy < 125) // quite content - fg = 6; // 6:0 - else if (happy < 150) // happy + else if (stress_lvl >= 0) fg = 2; // 2:0 - else // ecstatic + else fg = 10; // 2:1 - Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_HAPPINESS], 4 + row, happiness); + Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_STRESS], 4 + row, stress); fg = 15; if (row_offset == sel_row) @@ -1233,8 +1236,8 @@ void viewscreen_unitlaborsst::render() case ALTSORT_PROFESSION_OR_SQUAD: OutputString(15, x, y, show_squad ? "Squad" : "Profession"); break; - case ALTSORT_HAPPINESS: - OutputString(15, x, y, "Happiness"); + case ALTSORT_STRESS: + OutputString(15, x, y, "Stress Level"); break; case ALTSORT_ARRIVAL: OutputString(15, x, y, "Arrival"); From 7c92f4abaac5ca88b0a2677924f8065e219300b6 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 31 Oct 2014 13:47:04 -0500 Subject: [PATCH 7/8] Seems I misread the code from 0.34.11 - it switches against rand(2), not rand(3) --- plugins/strangemood.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index b91b1ff94..74c717816 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -695,7 +695,6 @@ command_result df_strangemood (color_ostream &out, vector & parameters) unit->relations.mood_copy = unit->mood; Gui::showAutoAnnouncement(announcement_type::STRANGE_MOOD, unit->pos, msg, color, bright); - //unit->status.happiness = 100; // TODO: make sure unit drops any wrestle items unit->job.mood_timeout = 50000; unit->flags1.bits.has_mood = true; @@ -1148,7 +1147,7 @@ command_result df_strangemood (color_ostream &out, vector & parameters) { if ((job->job_type == job_type::StrangeMoodBrooding) && (rng.df_trandom(2))) { - switch (rng.df_trandom(3)) + switch (rng.df_trandom(2)) { case 0: job->job_items.push_back(item = new df::job_item()); @@ -1163,10 +1162,6 @@ command_result df_strangemood (color_ostream &out, vector & parameters) item->flags2.bits.body_part = true; item->quantity = 1; break; - case 2: - // in older versions, they would request additional skulls - // in 0.34.11, the request becomes "nothing" - break; } } else From bad923130c5454885cd76940ec5ab79d8d59f590 Mon Sep 17 00:00:00 2001 From: Quietust Date: Sat, 1 Nov 2014 11:24:05 -0500 Subject: [PATCH 8/8] Manipulator - remove minimum width for Labors column, since it triggered the "should never happen" case upon extending the first column from 4 to 6 --- plugins/manipulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 8e379f98a..16cef345f 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -520,7 +520,7 @@ void viewscreen_unitlaborsst::calcSize() col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; // adjusted in the loop below - col_minwidth[DISP_COLUMN_LABORS] = num_columns*3/5; // 60% + col_minwidth[DISP_COLUMN_LABORS] = 1; col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS; // get max_name/max_prof from strings length