Open PatrikLundell opened 4 years ago
I think it would be in the scope of the tweak plugin, at least. For a fix, were you thinking increasing unit sizes would work? This reminds me a bit of tweak fast-heat and stable-temp from back in 0.34.11; those dealt with items, though, where the buggy code was in a vmethod which could easily be interposed. That's not the case with units, unfortunately.
My intention was to just change the size and length fields from 0 to 1, so it would require iterating over all units, or at least the active ones, but fixing inactive ones before they enter play would probably be the better choice. Units don't tend to be that numerous that I think it would be a problem to iterate over them.
Yeah, if done in C++ it should hardly be noticeable (we could further optimize it by caching the length of the units vector and only scanning if it changes, although depending on exactly when units are added/removed, we could run into an edge case there).
Btw anyone knows why it happens? Maybe a small code patch would be more "correct" fix. Also that would help Toady narrow it down greatly.
Link to mantis issue: https://www.bay12games.com/dwarves/mantisbt/view.php?id=8410
Edit: seems that Quietust figured it out in mantis - genetic variation causes value to be 0. We could check all of raws and figure out which ones could cause this issue maybe fix the raws? This does not seem that hard.
Would changing the raws affect existing creatures, though? IMO a fix ought to handle those too. (Assuming in-memory raw changes affect new creatures, we could use a two-fold approach of fixing broken creatures on world load and fixing the raws to prevent future creatures from having this issue, although I'm not entirely sure what raw changes would be necessary.)
IIRC changing raws would not affect existing creatures (though setting recalc size would? not sure).
Though maybe i'm bikeshedding too much - and just fixing all the broken 0 sized creatures would be enough for 99% of cases.
I don't think it's a raw issue as such: the code shouldn't crash just because you selected some legal values in your raws. I agree a code patch would be the best, assuming the code could be located.
I managed to get a number of zero size creatures when failing to correctly identify which creatures are vermin and which are not (it's surprisingly messy), resulting in "biodiversity" addition of "missing" creatures from biomes setting some vermin as animals. I got (regular) Firefly animals that had a size of 0 or 1, split about evenly, for instance.
I would assume the cause of the problem is the code that calculates size (and length) of spawned creatures that truncates the calculated size to an integer value either directly through an integer calculation or through a type conversion from a floating point value. What would be needed at that point is a selection of the larger of the calculated value or 1.
If i understand the issue correctly it's a raws + code issue: you have base size+ some variation with clamped gaussian distribution. On some corner cases the value you roll gets size to 0. Though even the mantis issue does not have "proof". Correct fix, from DF side, would just be to fix code to never have 0 there even if raws say otherwise. Though there could be other corner cases (e.g. creating true creature with race of a vermin) which would break a lot more stuff.
Well, it's really an issue of math vs computer implementations of math. Unless the range is [0, 0] (which should be erroneous) you'd get a non zero value (that might be arbitrarily close to zero), but the computer implementation has chosen (wisely, I would assume) to use integer math, which would need a guard for the truncation to zero case. Thus, I think warmist and I are on the same page.
My accidental hacking of vermin as real creatures worked fine when they were size 1, so I think DF handles that part (and the only distinction between real animals and vermin from a raw perspective is a number of tags that indicate they're vermin and thus should behave differently. The Creepy Crawler is an example of an animal sized vermin that can be butchered, for instance).
Creating this issue to see if people think it is a good idea, or if there are known issues causing it to be a bad approach.