LambdaRogue .:. roguelike RPG


12.08.2008, 12:57, written by Mario Donick

Warning: MonsterSearch x/y out of range

This is a message which sometimes occurs when entering a deeper dungeon level. Unfortunately, what follows is a crash. The bug is not very predictable – it may occur or it may not, and until now, it only occured in levels deeper than 10. Until I have a patch for this, it is a good idea to save the game (as it is a roguelike, this will also quit the game) and make a backup of the savegame file before going downstairs. An inconveniant workaround, I know. I do my best to fix the bug.Background of this bugThe PlaceWhen a dungeon level is entered, the first step is to create this level randomly and to fill it with monsters.Before the player gets positioned in this level (usually at the staircase up), one turn is processed to initialize the level. This includes a first movement of monsters, done in MoveMonsters function.There are several possible states processed (for example: Is a monster in an ice aura and therefore frozen? Is it hurt and runs away? Does the monster follow the player to attack him? and some others). Often the dungeon features of the current monster's position are needed for this.We have, for example, an antbee (Monster ID, say, 45) on position 12/45 and want to check if this antbee is frozen by an ice aura the player did cast a turn ago. If it is frozen, it can't move. So we have to check if the dungeon (DngLvl) on the antbee's position is affected by ice aura (intAirType has to be 2):
if DngLvl[Monster[45].intX, Monster[45].intY].intAirType = 2 thenbegin// ice auraend;
The application of this process in the real LambdaRogue source is a bit more complex, but this demonstration is sufficient to explain the problem of the aforementioned bug:The crash occurs whenever Monster[45].intX or Monster[45].intY have values that exceed the range of the array DngLvl.And exactly this seems to be the case sometimes. So the great question is: WHY?What happens when a dungeon is filled?First, we check how many monsters have to be created. This depends on the selected difficulty level and is a percent value. We first look how many tiles are free for monster creation and then determine the number of actual tiles to be filled (n). The max. for n is 508. 509 and 510 are reserved for unique monsters and for ghosts of dead players.Then, we initialize the array Monster, by moving all current monsters (from the former dungeon level) to a position outside the visible dungeon (but of course still in range of the DngLvl array). When this is done, every monster in the Monster array should have the position DngMaxWidth+10 / DngMaxHeight + 10. As all dungeons currently have a maximum size of 110x110, this »parking position« is 120/120. DngLvl array itself is 200x200, so there is enough room.After we have parked the monsters, we take the first n monsters out of the max. 508 monsters, set up their status values (name, HP etc.) and their position.How monsters are createdFirst, a monster type, appropriate to the current dungeon level, is selected. If we create, for example, Monster[45], an antbee might be selected. We just do Monster[45] := MonTe[selected type], where MonTe is a monster template, containing all information of the monsters.txt data file.Then, we set up the monster's position, by simply creating a random x/y value:
repeatrx := trunc(random(DngMaxWidth)) + 10;ry := trunc(random(DngMaxHeight)) + 10;until DngLvl[rx,ry].intIntegrity = 0;Monster[45].intX := rx;Monster[45].intY := ry;
I just see that some monsters will be created outside the visible dungeon area. Not so good, as this leads to less visible monsters than intended by the aforementioned n value. Have to change this.However, this basic positioning should not lead to any problems, as it will always be inside the DngLvl array.Special Case: Levels with monster hivesSome levels, however, alter the position of the currently created monsters. This is done for levels with monster hives. A monster hive is a dungeon tile where large amounts of monsters concentrate, until the hive is destroyed by the player.The hive's position of the current dungeon level is stored in HiveX/HiveY. If HiveX/HiveY are both -1, there is no hive.If there is a hive, the game tries to fill the area around the hive with monsters:
for i:=1 to lvl dobeginif CheckForMonster(HiveX-i,HiveY)=false thenbeginrx:=HiveX-i;ry:=HiveY;end;// do the same for all remaining 7 quadrants around the hiveend;
And I think that this is the position of the problem, because:Now, I'll do a quick check if monster hives are created in levels 15 and 19 (there I saw this bug occur). If this is true, I have to change the loop.Yeah! My theory was correct, there are indeed hives in DLV 15 and 19. Epistemic writing is great grin

Earlier / Later / Permanent Link

 

Write a comment

Your name:


Headline:


Spam protection: Enter the result of »eleven minus six« as word:


Text of your comment:


Click »Send« to save your comment.

powered by d.elog blogging software v0.6 / 17.04.2009
© Mario Donick 2005–2009.
d.elog contains Xinha, a free WYSIWYG textarea editor.