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.isGeldable(unit)``
* ``dfhack.units.isGelded(unit)`` * ``dfhack.units.isGelded(unit)``
* ``dfhack.units.isEggLayer(unit)`` * ``dfhack.units.isEggLayer(unit)``
* ``dfhack.units.isEggLayerRace(unit)``
* ``dfhack.units.isGrazer(unit)`` * ``dfhack.units.isGrazer(unit)``
* ``dfhack.units.isMilkable(unit)`` * ``dfhack.units.isMilkable(unit)``

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

@ -114,6 +114,7 @@ DFHACK_EXPORT bool isMarkedForGelding(df::unit* unit);
DFHACK_EXPORT bool isGeldable(df::unit* unit); DFHACK_EXPORT bool isGeldable(df::unit* unit);
DFHACK_EXPORT bool isGelded(df::unit* unit); DFHACK_EXPORT bool isGelded(df::unit* unit);
DFHACK_EXPORT bool isEggLayer(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 isGrazer(df::unit* unit);
DFHACK_EXPORT bool isMilkable(df::unit* unit); DFHACK_EXPORT bool isMilkable(df::unit* unit);
DFHACK_EXPORT bool isForest(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); || 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) bool Units::isGrazer(df::unit* unit)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);

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