In scenario editor, new towns have default boundaries 1x1 in top-left corner and no town entrances
NQNStudios opened this issue · comments
I was confused when in a new scenario, I would take one step in the starter town and end up outdoors.
Turns out new towns in the scenario editor have their boundaries set to a 1x1 square in the top-left. Probably an un-initialized rectangle in the data structure. I had a hard time figuring out what was happening because I thought it was a game code bug. But the code was actually working correctly.
I found the intended default in the manual: "Every town has a boundary. When the party reaches the boundary, they leave the town. This boundary is marked by a white rectangle, which always starts 4 spaces from the edge of the town."
Looks like it would get set here:
Line 125 in ca81699
A breakpoint at that position doesn't trigger when making a new scenario or a new town.
A grep of the repo doesn't show init_start() called anywhere. So there is another, related bug: N,W,S,and E town entrance points aren't set in new towns, either.
To fix the scenario editor's behavior, I'm seeing we could add an init_start() call in two places.
Scenario::addTown()
cboe/src/scenario/scenario.hpp
Line 96 in ca81699
and scen.townout.cpp's new_town()
cboe/src/scenedit/scen.townout.cpp
Line 1319 in ca81699
Alternatively we could put the call in cTown's constructor directly, which is less repetitive and more future-proof, BUT could have side effects for the game's behavior so feels like a risk.
What potential side-effects do you anticipate from putting it in the constructor?
If avoiding repetition is the only concern, I think we could just make new_town
call addTown
. I'm not sure why it doesn't.
For side-effects I guess I'm imagining a bug where a scenario loaded from a file ends up not overwriting the town boundaries and entrances set by init_start(). I guess that's far-fetched, since the constructor would always be called before the data structure is filled out in a loader function.
The loader also throws an error if the town's XML doesn't specify the bounds.
Calling init_start() fixed the boundaries not getting set, but for some reason the 4 town entrances are still garbage values. This is weird.
Could something later be overwriting them with garbage…?
Ah, here
Line 88 in ca81699