expand egg-laying filter to the entire race, not just the unit

develop
Myk Taylor 2023-07-16 12:30:12 -07:00
parent 4331d7bcc7
commit 5fb299c6df
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 24 additions and 13 deletions

@ -1360,6 +1360,7 @@ Units module
* ``dfhack.units.isGeldable(unit)``
* ``dfhack.units.isGelded(unit)``
* ``dfhack.units.isEggLayer(unit)``
* ``dfhack.units.isEggLayerRace(unit)``
* ``dfhack.units.isGrazer(unit)``
* ``dfhack.units.isMilkable(unit)``

@ -1765,6 +1765,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isGeldable),
WRAPM(Units, isGelded),
WRAPM(Units, isEggLayer),
WRAPM(Units, isEggLayerRace),
WRAPM(Units, isGrazer),
WRAPM(Units, isMilkable),
WRAPM(Units, isForest),

@ -114,6 +114,7 @@ DFHACK_EXPORT bool isMarkedForGelding(df::unit* unit);
DFHACK_EXPORT bool isGeldable(df::unit* unit);
DFHACK_EXPORT bool isGelded(df::unit* unit);
DFHACK_EXPORT bool isEggLayer(df::unit* unit);
DFHACK_EXPORT bool isEggLayerRace(df::unit* unit);
DFHACK_EXPORT bool isGrazer(df::unit* unit);
DFHACK_EXPORT bool isMilkable(df::unit* unit);
DFHACK_EXPORT bool isForest(df::unit* unit);

@ -555,6 +555,18 @@ bool Units::isEggLayer(df::unit* unit)
|| caste->flags.is_set(caste_raw_flags::LAYS_UNUSUAL_EGGS);
}
bool Units::isEggLayerRace(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto &caste : raw->caste) {
if (caste->flags.is_set(caste_raw_flags::LAYS_EGGS)
|| caste->flags.is_set(caste_raw_flags::LAYS_UNUSUAL_EGGS))
return true;
}
return false;
}
bool Units::isGrazer(df::unit* unit)
{
CHECK_NULL_POINTER(unit);

@ -294,15 +294,14 @@ function Pasture:init()
subviews={
widgets.CycleHotkeyLabel{
view_id='min_egg',
frame={l=0, t=0, w=SMALL_SLIDER_LABEL_WIDTH},
label='Min egg:',
label_below=true,
frame={l=0, t=1, w=SMALL_SLIDER_LABEL_WIDTH},
key_back='CUSTOM_SHIFT_B',
key='CUSTOM_SHIFT_N',
options={
{label=EGG.NOT_EGG_LAYING.label, value=EGG.NOT_EGG_LAYING.value},
{label=EGG.EGG_LAYING.label, value=EGG.EGG_LAYING.value},
},
option_gap=0,
initial_option=EGG.NOT_EGG_LAYING.value,
on_change=function(val)
if self.subviews.max_egg:getOptionValue() < val then
@ -313,15 +312,14 @@ function Pasture:init()
},
widgets.CycleHotkeyLabel{
view_id='max_egg',
frame={r=1, t=0, w=SMALL_SLIDER_LABEL_WIDTH},
label='Max egg:',
label_below=true,
frame={r=1, t=1, w=SMALL_SLIDER_LABEL_WIDTH},
key_back='CUSTOM_SHIFT_T',
key='CUSTOM_SHIFT_Y',
options={
{label=EGG.NOT_EGG_LAYING.label, value=EGG.NOT_EGG_LAYING.value},
{label=EGG.EGG_LAYING.label, value=EGG.EGG_LAYING.value},
},
option_gap=0,
initial_option=EGG.EGG_LAYING.value,
on_change=function(val)
if self.subviews.min_egg:getOptionValue() > val then
@ -349,15 +347,14 @@ function Pasture:init()
subviews={
widgets.CycleHotkeyLabel{
view_id='min_graze',
frame={l=0, t=0, w=SMALL_SLIDER_LABEL_WIDTH},
label='Min graze:',
label_below=true,
frame={l=0, t=1, w=SMALL_SLIDER_LABEL_WIDTH},
key_back='CUSTOM_SHIFT_M',
key='CUSTOM_SHIFT_L',
options={
{label=GRAZE.NOT_GRAZING.label, value=GRAZE.NOT_GRAZING.value},
{label=GRAZE.GRAZING.label, value=GRAZE.GRAZING.value},
},
option_gap=0,
initial_option=GRAZE.NOT_GRAZING.value,
on_change=function(val)
if self.subviews.max_graze:getOptionValue() < val then
@ -368,15 +365,14 @@ function Pasture:init()
},
widgets.CycleHotkeyLabel{
view_id='max_graze',
frame={r=1, t=0, w=SMALL_SLIDER_LABEL_WIDTH},
label='Max graze:',
label_below=true,
frame={r=1, t=1, w=SMALL_SLIDER_LABEL_WIDTH},
key_back='CUSTOM_SHIFT_U',
key='CUSTOM_SHIFT_I',
options={
{label=GRAZE.NOT_GRAZING.label, value=GRAZE.NOT_GRAZING.value},
{label=GRAZE.GRAZING.label, value=GRAZE.GRAZING.value},
},
option_gap=0,
initial_option=GRAZE.GRAZING.value,
on_change=function(val)
if self.subviews.min_graze:getOptionValue() > val then
@ -605,7 +601,7 @@ function Pasture:cache_choices()
race=raw.creature_id,
status=get_status(unit),
disposition=get_disposition(unit),
egg=dfhack.units.isEggLayer(unit) and EGG.EGG_LAYING.value or EGG.NOT_EGG_LAYING.value,
egg=dfhack.units.isEggLayerRace(unit) and EGG.EGG_LAYING.value or EGG.NOT_EGG_LAYING.value,
graze=dfhack.units.isGrazer(unit) and GRAZE.GRAZING.value or GRAZE.NOT_GRAZING.value,
}
local choice = {