From e3a12baaa68b9c53889c30fd3e37ee88db32b14d Mon Sep 17 00:00:00 2001 From: expwnent Date: Wed, 2 Mar 2016 00:40:34 -0500 Subject: [PATCH 1/4] Update create-unit so that civ -1 creatures are not histfigs and mitigated screen-movement bug. See http://www.bay12forums.com/smf/index.php?topic=139553.msg6845001#msg6845001 --- scripts/modtools/create-unit.lua | 42 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/modtools/create-unit.lua b/scripts/modtools/create-unit.lua index 80a39dda2..700a5aaa1 100644 --- a/scripts/modtools/create-unit.lua +++ b/scripts/modtools/create-unit.lua @@ -1,8 +1,10 @@ -- create-unit.lua -- Originally created by warmist, edited by Putnam for the dragon ball mod to be used in reactions, modified by Dirst for use in The Earth Strikes Back mod, incorporating fixes discovered by Boltgun then Mifiki wrote the bit where it switches to arena mode briefly to do some of the messy work, then Expwnent combined that with the old script to make it function for histfigs --- version 0.5 +-- version 0.51 -- This is a beta version. Use at your own risk. +-- Modifications from 0.5: civ -1 creates are NOT historical figures, mitigated screen-movement bug in createUnit() + --[[ TODO children and babies: set child/baby job @@ -30,6 +32,10 @@ end local utils=require 'utils' function createUnit(race_id, caste_id) + local view_x = df.global.window_x + local view_y = df.global.window_y + local view_z = df.global.window_z + local curViewscreen = dfhack.gui.getCurViewscreen() local dwarfmodeScreen = df.viewscreen_dwarfmodest:new() curViewscreen.child = dwarfmodeScreen @@ -64,6 +70,11 @@ function createUnit(race_id, caste_id) df.global.ui.main.mode = oldMode local id = df.global.unit_next_id-1 + + df.global.window_x = view_x + df.global.window_y = view_y + df.global.window_z = view_z + return id end @@ -261,6 +272,22 @@ function domesticate(uid, group_id) end end +function wild(uid) + local u = df.unit.find(uid) + local caste=df.creature_raw.find(u.race).caste[u.caste] + -- x = df.global.world.world_data.active_site[0].pos.x + -- y = df.global.world.world_data.active_site[0].pos.y + -- region = df.global.map.map_blocks[df.global.map.x_count_block*x+y] + if not(caste.flags.CAN_SPEAK and caste.flags.CAN_LEARN) then + u.animal.population.region_x = 1 + u.animal.population.region_y = 1 + u.animal.population.unk_28 = -1 + u.animal.population.population_idx = 1 + u.animal.population.depth = 0 + end +end + + function nameUnit(id, entityRawName, civ_id) --pick a random appropriate name --choose three random words in the appropriate things @@ -437,7 +464,7 @@ end local civ_id if args.civId == '\\LOCAL' then civ_id = df.global.ui.civ_id -elseif args.civId and tonumber(args.civId) and tonumber(args.civId) ~= -1 then +elseif args.civId and tonumber(args.civId) then civ_id = tonumber(args.civId) end @@ -448,10 +475,17 @@ elseif args.groupId and tonumber(args.groupId) then group_id = tonumber(args.groupId) end -local unitId = createUnitInCiv(raceIndex, casteIndex, civ_id, group_id) - +local unitId +if civ_id == -1 then + unitId = createUnit(raceIndex, casteIndex) + else + unitId = createUnitInCiv(raceIndex, casteIndex, civ_id, group_id) +end + if args.domesticate then domesticate(unitId, group_id) + else + wild(unitId) end if age or age == 0 then From 5a7c667c89b754e25562219f805eccbf67672c63 Mon Sep 17 00:00:00 2001 From: expwnent Date: Wed, 2 Mar 2016 04:39:59 -0500 Subject: [PATCH 2/4] Remove trailing whitespace. --- scripts/modtools/create-unit.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/modtools/create-unit.lua b/scripts/modtools/create-unit.lua index 700a5aaa1..30018a19b 100644 --- a/scripts/modtools/create-unit.lua +++ b/scripts/modtools/create-unit.lua @@ -481,7 +481,7 @@ if civ_id == -1 then else unitId = createUnitInCiv(raceIndex, casteIndex, civ_id, group_id) end - + if args.domesticate then domesticate(unitId, group_id) else From 198571dca316f6ede36bb6e16fd868f1e155a09b Mon Sep 17 00:00:00 2001 From: sv-esk Date: Thu, 3 Mar 2016 01:19:16 +0200 Subject: [PATCH 3/4] fix manipulator bug (unable to apply last custom profession) "selected" starts with 1, not 0 --- plugins/manipulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 7c86b6f7d..dfc7c1f0d 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -1008,7 +1008,7 @@ public: } void select_profession(size_t selected) { - if (selected >= manager.templates.size()) + if (selected > manager.templates.size()) return; ProfessionTemplate prof = manager.templates[selected - 1]; From d508028bccb0cd47dd2eaaba849bcfe09b395812 Mon Sep 17 00:00:00 2001 From: sv-esk Date: Thu, 3 Mar 2016 21:32:16 +0200 Subject: [PATCH 4/4] fix job-duplicate (do not clone posting_index) if job cannot be done right now, game puts it in df.global.world.job_postings when job finally can be done, game removes job from postings and clears posting_index that index should not be cloned by job-duplicate(new jobs(added by vanilla way) have that value -1 always anyway) cloning posting_index into the new job causes that job to be ignored --- library/modules/Job.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index af2fcb4e8..2678eadba 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -71,6 +71,7 @@ df::job *DFHack::Job::cloneJobStruct(df::job *job, bool keepEverything) pnew->flags.bits.suspend = job->flags.bits.suspend; pnew->completion_timer = -1; + pnew->posting_index = -1; } pnew->list_link = NULL;