Thursday, 29 November 2012


The way stairs are created in Teemu is simple. I found out it was too simple, actually. It works by creating automatic pair for an entrance. So called border exit is a special case which is made in outdoor levels you enter from the island, such as the forest or hut area. Border exit is simply "stairs" activated when the player steps on the border of the level.

What I needed in one of the dungeon levels was a border exit to another level at the same depth. However a border exit can't be an entrance to another level. It can only be a way to return to the previous entrance and to change that would have required a large scale refactoring in the way nodes (connection data between level themes) work in level theme data.

I tried to use a border exit, but it of course returned to previous dungeon level from where you came from due to automatic node setup. I knew then I had to hack it. Just hack it any way I can. After some time I managed to come up with a quite neat solution. First of all, I created a new type of entrance called Transition. Then I added a code checking if there was a transition in that level when trying to exit the level from edges (border exit).

The destination level could have a normal border exit of course, but there was one problem: IF the level has a border exit, it's the place where you enter, no matter from where you enter in the level. The issue was another stairs in that level, leading out from it. This is where some clever hacking was involved by checking the particular source and destination levels in node setup, then changing the destination stair type to upward stairs, preventing a regular enter to border exit location.

This is yet another example why hacking can be a viable solution, because the engine can be too restricted to do something more specific like this. Now the feature (transition) is there and it's working. It took way less time to code than actual engine support for that feature and there was a minimum amount of source code hacking, actually only 3 lines of code in the border exit routine and one line in node setup.

No comments: