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:
Earlier / Later / Permanent Link
powered by d.elog blogging software v0.6 / 17.04.2009
© Mario Donick 2005–2009.
d.elog contains Xinha, a free WYSIWYG textarea editor.