CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
9.73k stars 4.05k forks source link

Treetops fail to generate "randomly" #73474

Closed PatrikLundell closed 2 weeks ago

PatrikLundell commented 2 weeks ago

Describe the bug

It's been known for a while that the magic roof adding functionality doesn't create everything it should create (e.g. #71909).

Attach save file

See #71909

Steps to reproduce

See #71909

Expected behavior

Treetops and roofs should be generated when they should be present.

Screenshots

No response

Versions and configuration

Additional context

I've been trying to figure out how this magic is (and isn't) invoked for quite some time.

I think I've finally found one reason, namely that the logic used most of the time never invokes it because most of the map loading in normal play is performed by map::shift (shift the reality bubble one submap at a time), and that operation calls the loadn operation that takes a tripoint parameter, not the one that takes a point, and it's the point parameter loadn which calls add_roofs...

I made a hack to replace the calls to the 3D version to the 2D one and then loaded a save and moved (on the map, not teleporting) to a nearby forest, and lo and behold, the trees now got their treetops generated (I tested the same thing before the hack, and the treetops were missing). I also tried to the failing chicken coop livestock expansion construction, and the roof was now generated when climbing the roof of the evac shelter (I assume a submap boundary was crossed somewhere in the process, at least when climbing the roof: I don't expect the coop roof to appear without such a trigger).

The reason I'm writing a (new) bug report rather than submitting my hack as a PR is that I'm not sure the hack is the correct solution to the problem. It might well be that other parts of 'shift' should be adjusted, and it might be that some of the additional things the 2D loadn operation does shouldn't be performed in this context. And, of course, hacks never have unexpected side effects or performance implications...