@ -28,6 +28,8 @@ The target/s must be alive, sane, and in fortress mode.
= end ] ]
= end ] ]
helpstr = help : gsub ( ' =begin ' , ' ' ) : gsub ( ' =end ' , ' ' )
local dlg = require ( ' gui.dialogs ' )
local dlg = require ( ' gui.dialogs ' )
function ErrorPopup ( msg , color )
function ErrorPopup ( msg , color )
@ -36,14 +38,8 @@ function ErrorPopup (msg,color)
dlg.showMessage ( " Dwarven Family Affairs " , msg , color , nil )
dlg.showMessage ( " Dwarven Family Affairs " , msg , color , nil )
end
end
function AnnounceAndGamelog ( text , l )
function AnnounceAndGamelog ( text )
if not l then l = true end
dfhack.gui . showAnnouncement ( text , COLOR_LIGHTMAGENTA )
dfhack.gui . showAnnouncement ( text , _G [ " COLOR_LIGHTMAGENTA " ] )
if l then
local log = io.open ( ' gamelog.txt ' , ' a ' )
log : write ( text .. " \n " )
log : close ( )
end
end
end
function ListPrompt ( msg , choicelist , bool , yes_func )
function ListPrompt ( msg , choicelist , bool , yes_func )
@ -181,7 +177,7 @@ function ChooseNewSpouse (source)
if not source then
if not source then
qerror ( " no unit " ) return
qerror ( " no unit " ) return
end
end
if ( source.profession == 103 or source.profession == 104 ) then
if not dfhack.units . isAdult ( source ) then
ErrorPopup ( " target is too young " ) return
ErrorPopup ( " target is too young " ) return
end
end
if not ( source.relations . spouse_id == - 1 and source.relations . lover_id == - 1 ) then
if not ( source.relations . spouse_id == - 1 and source.relations . lover_id == - 1 ) then
@ -199,7 +195,7 @@ function ChooseNewSpouse (source)
and v.sex ~= source.sex
and v.sex ~= source.sex
and v.relations . spouse_id == - 1
and v.relations . spouse_id == - 1
and v.relations . lover_id == - 1
and v.relations . lover_id == - 1
and not ( v.profession == 103 or v.profession == 104 )
and dfhack.units . isAdult ( v )
then
then
table.insert ( choicelist , dfhack.TranslateName ( v.name ) .. ' , ' .. dfhack.units . getProfessionName ( v ) )
table.insert ( choicelist , dfhack.TranslateName ( v.name ) .. ' , ' .. dfhack.units . getProfessionName ( v ) )
table.insert ( targetlist , v )
table.insert ( targetlist , v )
@ -229,11 +225,11 @@ function MainDialog (source)
local choicelist = { }
local choicelist = { }
local on_select = { }
local on_select = { }
local child = ( source.profession == 103 or source.profession == 104 )
local adult = dfhack.units . isAdult ( source )
local is_ single = source.relations . spouse_id == - 1 and source.relations . lover_id == - 1
local single = source.relations . spouse_id == - 1 and source.relations . lover_id == - 1
local ready_for_marriage = single and not child
local ready_for_marriage = single and adult
if not child then
if adult then
table.insert ( choicelist , " Remove romantic relationships (if any) " )
table.insert ( choicelist , " Remove romantic relationships (if any) " )
table.insert ( on_select , Divorce )
table.insert ( on_select , Divorce )
if ready_for_marriage then
if ready_for_marriage then
@ -258,8 +254,8 @@ local args = {...}
if args [ 1 ] == " help " or args [ 1 ] == " ? " then print ( helpstr ) return end
if args [ 1 ] == " help " or args [ 1 ] == " ? " then print ( helpstr ) return end
if not df .global. gamemode == 0 then
if not df hack.world. isFortressMode ( ) then
print ( helpstr ) qerror ( " invalid game mode" ) return
print ( helpstr ) qerror ( " invalid game mode" ) return
end
end
if args [ 1 ] == " divorce " and tonumber ( args [ 2 ] ) then
if args [ 1 ] == " divorce " and tonumber ( args [ 2 ] ) then
@ -287,10 +283,10 @@ if selected then
if dfhack.units . isCitizen ( selected ) and dfhack.units . isSane ( selected ) then
if dfhack.units . isCitizen ( selected ) and dfhack.units . isSane ( selected ) then
MainDialog ( selected )
MainDialog ( selected )
else
else
qerror ( " You must select sane fortress citizen." )
qerror ( " You must select a sane fortress citizen." )
return
return
end
end
else
else
print ( helpstr )
print ( helpstr )
qerror ( " s elect a sane fortress dwarf" )
qerror ( " S elect a sane fortress dwarf" )
end
end