-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed mothers attempting to seek their units that were babies #1284
Conversation
Fixed mothers attempting to seek their units that were babies by removing the unit id from the ANY_BABY table. Also made those grown babies act like adults by updating some flags.
table.insert(leftoverUnits, v) | ||
end | ||
end | ||
-- create a shifted table of the leftover units to make up for lua tables starting with index 1 and the game starting with index 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the erase
method on the world.units.other.ANY_BABY
vector for this. this method directly calls the appropriate C++ method on the underlying vector instead of rewriting the vector
you can simply do world.units.other.ANY_BABY:erase(i)
where i
is the (0-based) index of the item to erase. note that this will invalidate the ipairs
iterator, but the unit should only be on the vector once so once you find it you don't have to keep searching to find it again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also avoid finding the index entirely by using utils.erase_sorted(df.global.world.units.other.ANY_BABY, unit, 'id')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also avoid finding the index entirely by using
utils.erase_sorted(df.global.world.units.other.ANY_BABY, unit, 'id')
do note that the unit classification subvectors (such as ANY_BABY
) are not guaranteed to be sorted. the categorize
methods simply insert the unit/item/building at the end of the classified subvector. using tools that expect these vectors to be sorted may result in unexpected behavior
unfortunately just uncategorizing and recategorizing the unit is unsafe, because categorizing a unit sets the unit's forgot that these methods aren't virtual for schedule_id
to -1 (why, toady, why?), which means it's not safe to do this hereunitst
TL;DR: do not use utils.erase_sorted
on a unit
subvector, this is not safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up. I had trouble with lua doing a 1 based index vs C++ (as well as what I'm used to from other languages) doing a 0 based index and then that translating back into the game vector. I'll update with these fixes later this week/this weekend. Appreciate the suggestions
-- set extra flags to defaults | ||
unit.flags1.rider = false | ||
unit.relationship_ids.RiderMount = -1 | ||
unit.mount_type = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use df.rider_positions_type.STANDARD
instead of 0
unit.relationship_ids.RiderMount = -1 | ||
unit.mount_type = 0 | ||
unit.profession2 = df.profession.STANDARD | ||
unit.idle_area_type = 26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use df.unit_station_type.MillBuilding
instead of 26
|
||
-- let the mom know she isn't carrying anyone anymore | ||
local motherUnitId = unit.relationship_ids.Mother | ||
df.unit.find(motherUnitId).flags1.ridden = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a good idea to always protect from nil
when using any find
method. The mother could have just been obliterated and the unit could be gone by the time this is run.
-- let the mom know she isn't carrying anyone anymore | ||
local motherUnitId = unit.relationship_ids.Mother | ||
df.unit.find(motherUnitId).flags1.ridden = false | ||
end | ||
unit.profession = df.profession.STANDARD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check and update unit.profession2
and the profession
in the histfig (df.historical_figure.find(unit.hist_figure_id)
)
table.insert(leftoverUnits, v) | ||
end | ||
end | ||
-- create a shifted table of the leftover units to make up for lua tables starting with index 1 and the game starting with index 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also avoid finding the index entirely by using utils.erase_sorted(df.global.world.units.other.ANY_BABY, unit, 'id')
Do you think you'll have time to finish this up this weekend? If so, we can get it into the upcoming release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a line to changelog.txt
with a description of the fix
There are a few other necessary fixes to |
Fixed mothers attempting to seek their units that were babies by removing the unit id from the ANY_BABY table. Also made those grown babies act like adults by updating some flags.
Fixes: DFHack/dfhack#4894