Skip to content

Commit

Permalink
don't allow player to assign spouses for non-spouse races
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Aug 23, 2024
1 parent 3ec0681 commit 35516d6
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions gui/pregnancy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ local function is_viable_partner(unit, required_pronoun)
return unit and unit.sex == required_pronoun and dfhack.units.isAdult(unit) and dfhack.units.isSane(unit)
end

local function can_have_spouse(unit)
if not unit then return end
local caste_flags = unit.enemy.caste_flags
return caste_flags.CAN_SPEAK or caste_flags.CAN_LEARN
end

-- clears other_hf's link to hf (assumes there's only one reverse link)
local function clear_rev_hf_link(link_type, hfid, other_hfid)
local other_hf = df.historical_figure.find(other_hfid)
Expand Down Expand Up @@ -148,11 +154,11 @@ function Pregnancy:init()
},
widgets.Label{
frame={t=3, l=0},
text='Spouse:',
text={{text='Spouse:', pen=function() return can_have_spouse(self:get_mother()) and COLOR_WHITE or COLOR_GRAY end}},
},
widgets.Label{
frame={t=3, l=8},
text='None',
text={{text='None', pen=function() return can_have_spouse(self:get_mother()) and COLOR_WHITE or COLOR_GRAY end}},
visible=function() return not self:get_spouse_unit('mother') and not self:get_spouse_hf('mother') end,
},
widgets.Label{
Expand All @@ -166,10 +172,9 @@ function Pregnancy:init()
widgets.Label{
frame={t=3, l=8},
text={
{text=self:callback('get_spouse_hf_name', 'mother')},
' (off-site)',
{text=self:callback('get_spouse_hf_name', 'mother'), pen=COLOR_BLUE},
{gap=1, text='(off-site)', pen=COLOR_YELLOW},
},
text_pen=COLOR_BLUE,
auto_width=true,
visible=function() return not self:get_spouse_unit('mother') and self:get_spouse_hf('mother') end,
},
Expand All @@ -189,7 +194,10 @@ function Pregnancy:init()
label="Dissolve spouse relationship",
key='CUSTOM_X',
auto_width=true,
on_activate=function() clear_spouse(self:get_mother()) self.dirty = 2 end,
on_activate=function()
clear_spouse(self:get_mother())
self.dirty = 3
end,
visible=function()
local mother = self:get_mother()
return mother and mother.relationship_ids.Spouse ~= -1
Expand All @@ -200,13 +208,16 @@ function Pregnancy:init()
label="Set selected father as spouse",
key='CUSTOM_X',
auto_width=true,
on_activate=function() set_spouse(self:get_mother(), self:get_father()) self.dirty = 2 end,
on_activate=function()
set_spouse(self:get_mother(), self:get_father())
self.dirty = 3
end,
visible=function()
local mother = self:get_mother()
return not mother or mother.relationship_ids.Spouse == -1
end,
enabled=function()
if self.mother_id == -1 then return false end
if not can_have_spouse(self:get_mother()) then return false end
local father = self:get_father()
return father and father.relationship_ids.Spouse == -1
end,
Expand Down Expand Up @@ -261,11 +272,11 @@ function Pregnancy:init()
},
widgets.Label{
frame={t=2, l=0},
text='Spouse:',
text={{text='Spouse:', pen=function() return can_have_spouse(self:get_father()) and COLOR_WHITE or COLOR_GRAY end}},
},
widgets.Label{
frame={t=2, l=8},
text='None',
text={{text='None', pen=function() return can_have_spouse(self:get_father()) and COLOR_WHITE or COLOR_GRAY end}},
visible=function() return not self:get_spouse_unit('father') and not self:get_spouse_hf('father') end,
},
widgets.Label{
Expand All @@ -285,10 +296,9 @@ function Pregnancy:init()
widgets.Label{
frame={t=2, l=8},
text={
{text=self:callback('get_spouse_hf_name', 'father')},
' (off-site)',
{text=self:callback('get_spouse_hf_name', 'father'), pen=COLOR_CYAN},
{gap=1, text='(off-site)', pen=COLOR_YELLOW},
},
text_pen=COLOR_CYAN,
auto_width=true,
visible=function() return not self:get_spouse_unit('father') and self:get_spouse_hf('father') end,
},
Expand All @@ -308,7 +318,10 @@ function Pregnancy:init()
label="Dissolve spouse relationship",
key='CUSTOM_SHIFT_X',
auto_width=true,
on_activate=function() clear_spouse(self:get_father()) self.dirty = 2 end,
on_activate=function()
clear_spouse(self:get_father())
self.dirty = 3
end,
visible=function()
local father = self:get_father()
return father and father.relationship_ids.Spouse ~= -1
Expand All @@ -319,13 +332,16 @@ function Pregnancy:init()
label="Set selected mother as spouse",
key='CUSTOM_SHIFT_X',
auto_width=true,
on_activate=function() set_spouse(self:get_mother(), self:get_father()) self.dirty = 2 end,
on_activate=function()
set_spouse(self:get_mother(), self:get_father())
self.dirty = 3
end,
visible=function()
local father = self:get_father()
return not father or father.relationship_ids.Spouse == -1
end,
enabled=function()
if self.father_id == -1 then return false end
if not can_have_spouse(self:get_father()) then return false end
local mother = self:get_mother()
return mother and mother.relationship_ids.Spouse == -1
end,
Expand Down

0 comments on commit 35516d6

Please sign in to comment.