From 294fe0b30c5b2bdafa3334aec9415c79ffff8d4c Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Mon, 5 Jan 2015 08:33:10 -0500 Subject: [PATCH 1/5] Update siren.lua for emotions Runs now without exception/error and adds emotions correctly. Seems to work as intended. --- scripts/siren.lua | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/scripts/siren.lua b/scripts/siren.lua index 4fc574ed0..3a799c3e2 100644 --- a/scripts/siren.lua +++ b/scripts/siren.lua @@ -32,15 +32,18 @@ function is_in_burrows(pos) end end -function add_thought(unit, code) - for _,v in ipairs(unit.status.recent_events) do - if v.type == code then - v.age = 0 - return - end - end - - unit.status.recent_events:insert('#', { new = true, type = code }) +function add_thought(unit, emotion, thought) + unit.status.current_soul.personality.emotions:insert('#', { new = true, + type = emotion, + unk2=1, + strength=1, + thought=thought, + subthought=0, + severity=0, + flags=0, + unk7=0, + year=df.global.cur_year, + year_tick=df.global.cur_year_tick}) end function wake_unit(unit) @@ -51,9 +54,9 @@ function wake_unit(unit) if job.completion_timer > 0 then unit.counters.unconscious = 0 - add_thought(unit, df.unit_thought_type.SleepNoiseWake) + add_thought(unit, df.emotion_type.Grouchiness, df.unit_thought_type.Drowsy) elseif job.completion_timer < 0 then - add_thought(unit, df.unit_thought_type.Tired) + add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy) end job.pos:assign(unit.pos) @@ -73,7 +76,7 @@ function stop_break(unit) if counter then counter.id = df.misc_trait_type.TimeSinceBreak counter.value = 100800 - 30*1200 - add_thought(unit, df.unit_thought_type.Tired) + add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy) end end @@ -90,7 +93,7 @@ for _,v in ipairs(df.global.world.units.active) do local x,y,z = dfhack.units.getPosition(v) if x and dfhack.units.isCitizen(v) and is_in_burrows(xyz2pos(x,y,z)) then if not in_siege and v.military.squad_id < 0 then - add_thought(v, df.unit_thought_type.LackProtection) + add_thought(v, df.emotion_type.Nervousness, df.unit_thought_type.LackProtection) end wake_unit(v) stop_break(v) @@ -103,7 +106,7 @@ for _,v in ipairs(df.global.ui.parties) do if is_in_burrows(pos) then v.timer = 0 for _, u in ipairs(v.units) do - add_thought(unit, df.unit_thought_type.Tired) + add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy) end end end From 084bbc316233297dd279cf1eb9db9e36d4f06bb2 Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Mon, 5 Jan 2015 13:54:17 -0500 Subject: [PATCH 2/5] Add isGay(df::unit*) method --- plugins/zone.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index c88e82154..c7dfd3b81 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -67,6 +67,7 @@ using namespace std; #include "df/general_ref_building_civzone_assignedst.h" #include #include +#include "df/unit_soul.h" #include "df/viewscreen_dwarfmodest.h" #include "modules/Translation.h" @@ -345,6 +346,7 @@ bool isHunter(df::unit* unit); bool isOwnCiv(df::unit* unit); bool isMerchant(df::unit* unit); bool isForest(df::unit* unit); +bool isGay(df::unit* unit); bool isActivityZone(df::building * building); bool isPenPasture(df::building * building); @@ -705,6 +707,11 @@ int getUnitIndexFromId(df::unit* unit_) return -1; } +bool isGay(df::unit* unit) +{ + return isFemale(unit) && unit->status.current_soul->orientation_flags.bits.romance_female || unit->status.current_soul->orientation_flags.bits.romance_male; +} + // dump some unit info void unitInfo(color_ostream & out, df::unit* unit, bool verbose = false) { From 1cdf61908ea81578944ba6811c697a5a69464b65 Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Mon, 5 Jan 2015 14:22:07 -0500 Subject: [PATCH 3/5] Collapse ProcessUnits_* methods. --- plugins/zone.cpp | 60 ++++++++---------------------------------------- 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index c7dfd3b81..cf51dfa6f 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -709,7 +709,7 @@ int getUnitIndexFromId(df::unit* unit_) bool isGay(df::unit* unit) { - return isFemale(unit) && unit->status.current_soul->orientation_flags.bits.romance_female || unit->status.current_soul->orientation_flags.bits.romance_male; + return isFemale(unit) && unit->status.current_soul->orientation_flags.bits.romance_female || unit->status.current_soul->orientation_flags.bits.romance_male; } // dump some unit info @@ -2803,8 +2803,7 @@ public: int mk_prot; int ma_prot; - // bah, this should better be an array of 4 vectors - // that way there's no need for the 4 ugly process methods + // butcherable units vector fk_ptr; vector mk_ptr; vector fa_ptr; @@ -2910,53 +2909,14 @@ public: ma_ptr.clear(); } - int ProcessUnits_fk() + int ProcessUnits(vector& unit_ptr, int prot, int goal) { int subcount = 0; - while(fk_ptr.size() && (fk_ptr.size() + fk_prot > fk) ) + while(unit_ptr.size() && (unit_ptr.size() + prot > goal) ) { - df::unit* unit = fk_ptr.back(); + df::unit* unit = unit_ptr.back(); doMarkForSlaughter(unit); - fk_ptr.pop_back(); - subcount++; - } - return subcount; - } - - int ProcessUnits_mk() - { - int subcount = 0; - while(mk_ptr.size() && (mk_ptr.size() + mk_prot > mk) ) - { - df::unit* unit = mk_ptr.back(); - doMarkForSlaughter(unit); - mk_ptr.pop_back(); - subcount++; - } - return subcount; - } - - int ProcessUnits_fa() - { - int subcount = 0; - while(fa_ptr.size() && (fa_ptr.size() + fa_prot > fa) ) - { - df::unit* unit = fa_ptr.back(); - doMarkForSlaughter(unit); - fa_ptr.pop_back(); - subcount++; - } - return subcount; - } - - int ProcessUnits_ma() - { - int subcount = 0; - while(ma_ptr.size() && (ma_ptr.size() + ma_prot > ma) ) - { - df::unit* unit = ma_ptr.back(); - doMarkForSlaughter(unit); - ma_ptr.pop_back(); + unit_ptr.pop_back(); subcount++; } return subcount; @@ -2966,10 +2926,10 @@ public: { SortUnitsByAge(); int slaughter_count = 0; - slaughter_count += ProcessUnits_fk(); - slaughter_count += ProcessUnits_mk(); - slaughter_count += ProcessUnits_fa(); - slaughter_count += ProcessUnits_ma(); + slaughter_count += ProcessUnits(fk_ptr, fk_prot, fk); + slaughter_count += ProcessUnits(mk_ptr, mk_prot, mk); + slaughter_count += ProcessUnits(fa_ptr, fa_prot, fa); + slaughter_count += ProcessUnits(ma_ptr, ma_prot, ma); ClearUnits(); return slaughter_count; } From c069a87b47334c490aa0d4f6c5878ab3c6054159 Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Mon, 5 Jan 2015 14:59:32 -0500 Subject: [PATCH 4/5] Update isGay(df::unit) with better determination --- plugins/zone.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index cf51dfa6f..594840361 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -709,7 +709,9 @@ int getUnitIndexFromId(df::unit* unit_) bool isGay(df::unit* unit) { - return isFemale(unit) && unit->status.current_soul->orientation_flags.bits.romance_female || unit->status.current_soul->orientation_flags.bits.romance_male; + df::orientation_flags orientation = unit->status.current_soul->orientation_flags; + return isFemale(unit) && ! (orientation.whole & (orientation.mask_marry_male | orientation.mask_romance_male)) + || ! isFemale(unit) && ! (orientation.whole & (orientation.mask_marry_female | orientation.mask_romance_female)); } // dump some unit info @@ -2809,6 +2811,12 @@ public: vector fa_ptr; vector ma_ptr; + // priority butcherable units + vector fk_pri_ptr; + vector mk_pri_ptr; + vector fa_pri_ptr; + vector ma_pri_ptr; + WatchedRace(bool watch, int id, int _fk, int _mk, int _fa, int _ma) { isWatched = watch; @@ -2862,6 +2870,10 @@ public: sort(mk_ptr.begin(), mk_ptr.end(), compareUnitAgesOlder); sort(fa_ptr.begin(), fa_ptr.end(), compareUnitAgesYounger); sort(ma_ptr.begin(), ma_ptr.end(), compareUnitAgesYounger); + sort(fk_pri_ptr.begin(), fk_ptr.end(), compareUnitAgesOlder); + sort(mk_pri_ptr.begin(), mk_ptr.end(), compareUnitAgesOlder); + sort(fa_pri_ptr.begin(), fa_ptr.end(), compareUnitAgesYounger); + sort(ma_pri_ptr.begin(), ma_ptr.end(), compareUnitAgesYounger); } void PushUnit(df::unit * unit) @@ -2882,6 +2894,24 @@ public: } } + void PushPriorityUnit(df::unit * unit) + { + if(isFemale(unit)) + { + if(isBaby(unit) || isChild(unit)) + fk_pri_ptr.push_back(unit); + else + fa_pri_ptr.push_back(unit); + } + else + { + if(isBaby(unit) || isChild(unit)) + mk_pri_ptr.push_back(unit); + else + ma_pri_ptr.push_back(unit); + } + } + void PushProtectedUnit(df::unit * unit) { if(isFemale(unit)) @@ -2907,11 +2937,22 @@ public: mk_ptr.clear(); fa_ptr.clear(); ma_ptr.clear(); + fk_pri_ptr.clear(); + mk_pri_ptr.clear(); + fa_pri_ptr.clear(); + ma_pri_ptr.clear(); } - int ProcessUnits(vector& unit_ptr, int prot, int goal) + int ProcessUnits(vector& unit_ptr, vector& unit_pri_ptr, int prot, int goal) { int subcount = 0; + while(unit_pri_ptr.size() && (unit_ptr.size() + unit_pri_ptr.size() + prot > goal) ) + { + df::unit* unit = unit_pri_ptr.back(); + doMarkForSlaughter(unit); + unit_pri_ptr.pop_back(); + subcount++; + } while(unit_ptr.size() && (unit_ptr.size() + prot > goal) ) { df::unit* unit = unit_ptr.back(); @@ -2926,10 +2967,10 @@ public: { SortUnitsByAge(); int slaughter_count = 0; - slaughter_count += ProcessUnits(fk_ptr, fk_prot, fk); - slaughter_count += ProcessUnits(mk_ptr, mk_prot, mk); - slaughter_count += ProcessUnits(fa_ptr, fa_prot, fa); - slaughter_count += ProcessUnits(ma_ptr, ma_prot, ma); + slaughter_count += ProcessUnits(fk_ptr, fk_pri_ptr, fk_prot, fk); + slaughter_count += ProcessUnits(mk_ptr, mk_pri_ptr, mk_prot, mk); + slaughter_count += ProcessUnits(fa_ptr, fa_pri_ptr, fa_prot, fa); + slaughter_count += ProcessUnits(ma_ptr, ma_pri_ptr, ma_prot, ma); ClearUnits(); return slaughter_count; } @@ -3440,6 +3481,8 @@ command_result autoButcher( color_ostream &out, bool verbose = false ) || isAvailableForAdoption(unit) || unit->name.has_name ) w->PushProtectedUnit(unit); + else if (isGay(unit)) + w->PushPriorityUnit(unit); else w->PushUnit(unit); } From 929f63ee2e95e1c2f35f2c3ff9816a3400bfe063 Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Mon, 5 Jan 2015 15:57:34 -0500 Subject: [PATCH 5/5] Fix error in WatchedRace::SortUnitsByAge --- plugins/zone.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index 594840361..571eb6bba 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -2870,10 +2870,10 @@ public: sort(mk_ptr.begin(), mk_ptr.end(), compareUnitAgesOlder); sort(fa_ptr.begin(), fa_ptr.end(), compareUnitAgesYounger); sort(ma_ptr.begin(), ma_ptr.end(), compareUnitAgesYounger); - sort(fk_pri_ptr.begin(), fk_ptr.end(), compareUnitAgesOlder); - sort(mk_pri_ptr.begin(), mk_ptr.end(), compareUnitAgesOlder); - sort(fa_pri_ptr.begin(), fa_ptr.end(), compareUnitAgesYounger); - sort(ma_pri_ptr.begin(), ma_ptr.end(), compareUnitAgesYounger); + sort(fk_pri_ptr.begin(), fk_pri_ptr.end(), compareUnitAgesOlder); + sort(mk_pri_ptr.begin(), mk_pri_ptr.end(), compareUnitAgesOlder); + sort(fa_pri_ptr.begin(), fa_pri_ptr.end(), compareUnitAgesYounger); + sort(ma_pri_ptr.begin(), ma_pri_ptr.end(), compareUnitAgesYounger); } void PushUnit(df::unit * unit)