calref / cboe

Classic Blades of Exile
http://spiderwebforums.ipbhost.com/index.php?/forum/12-blades-of-exile/
Other
167 stars 41 forks source link

In scenario editor, new towns have default boundaries 1x1 in top-left corner and no town entrances #337

Closed NQNStudios closed 1 year ago

NQNStudios commented 1 year ago

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.

NQNStudios commented 1 year ago

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."

NQNStudios commented 1 year ago

Looks like it would get set here: https://github.com/calref/cboe/blob/ca816995ba9da539ed08a568616fbf36bea8bde0/src/scenario/town.cpp#L125

A breakpoint at that position doesn't trigger when making a new scenario or a new town.

NQNStudios commented 1 year ago

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.

NQNStudios commented 1 year ago

To fix the scenario editor's behavior, I'm seeing we could add an init_start() call in two places.

Scenario::addTown() https://github.com/calref/cboe/blob/ca816995ba9da539ed08a568616fbf36bea8bde0/src/scenario/scenario.hpp#L96

and scen.townout.cpp's new_town() https://github.com/calref/cboe/blob/ca816995ba9da539ed08a568616fbf36bea8bde0/src/scenedit/scen.townout.cpp#L1319

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.

CelticMinstrel commented 1 year ago

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.

NQNStudios commented 1 year ago

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.

CelticMinstrel commented 1 year ago

The loader also throws an error if the town's XML doesn't specify the bounds.

NQNStudios commented 1 year ago

Calling init_start() fixed the boundaries not getting set, but for some reason the 4 town entrances are still garbage values. This is weird.

CelticMinstrel commented 1 year ago

Could something later be overwriting them with garbage…?

NQNStudios commented 1 year ago

Ah, here https://github.com/calref/cboe/blob/ca816995ba9da539ed08a568616fbf36bea8bde0/src/scenario/town.cpp#L88