Full Version: Monster spawning formula?

Braindead's Mordor Site - Return to Mordor: The Depths Of Dejenol > Mordor: The Depths Of Dejenol > Modding And Development

Does anyone know how monsters are spawned? I assume that, like item drops, a list of candidates are generated and then the odds are monster chance/sum of all candidate chances. But how is that list generated? Is it the set of all monsters from the current floor with a type that matches the areas spawn flags? I know sometimes easier monsters show up. Are all monsters from the previous floor candidates too? How are their chance scores modified, if at all? How are the odds modified by laired monsters?

An examination of the source reveals the following. I might have misread some of it, it's very tangled. I didn't look into how the "companions" of the lead monster are generated, though Wabbit's editor gives a general idea (num group, in group, comp type, companions).

- If there's a laired monster, there's a 75% chance of it showing up.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

On level 1, rooms #1 to #17 have special restrictions on what monsters can appear. These rooms are all within 2 rooms of the entry stairs, plus a few directly to the east of the stairs up to about 5 rooms away.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

- If there's a laired monster, there's a 75% chance of it showing up.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

On level 1, rooms #1 to #17 have special restrictions on what monsters can appear. These rooms are all within 2 rooms of the entry stairs, plus a few directly to the east of the stairs up to about 5 rooms away.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

I still can't discern why T'Manas and Dragon Turtles never show up.

I run a mod by DarkerMuffin that fixes the spawning of a number or problematic monsters, including T'Manas and Dragon Turtles. When he posted the mod, DarkerMuffin explained the spawning problems and how he fixed them. Most of the spawning problems result from the monster being assigned a companion type that can never spawn with it. In the case of Dragon Turtles, they are supposed to spawn with cascading Kyu-type Water Dwellers. But the first one, the Kyu t'Salli, is just a level-10 monster and therefore can't spawn in the second slot on level 14. When that happens, the game apparently goes back to the drawing board and re-rolls the encounter.

DarkerMuffin fixed Indiginis by assigning them animals as companions. It seems to have worked. Immediately after I installed the mod, I started encountering Indiginis, and I've seen lots of T'Manas.

If you want more detail, read DarkerMuffin's original post. He posted it in this forum in 2015, so you won't have to scroll down very far to find it.

An examination of the source reveals the following. I might have misread some of it, it's very tangled. I didn't look into how the "companions" of the lead monster are generated, though Wabbit's editor gives a general idea (num group, in group, comp type, companions).

- If there's a laired monster, there's a 75% chance of it showing up.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

On level 1, rooms #1 to #17 have special restrictions on what monsters can appear. These rooms are all within 2 rooms of the entry stairs, plus a few directly to the east of the stairs up to about 5 rooms away.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

- If there's a laired monster, there's a 75% chance of it showing up.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

On level 1, rooms #1 to #17 have special restrictions on what monsters can appear. These rooms are all within 2 rooms of the entry stairs, plus a few directly to the east of the stairs up to about 5 rooms away.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

Does it pick a type and then pick a monster of the type or does it put all monsters of allowed types in a pile and pick from the pile?

What line of what file is the function? My copy of the source is from a VB3 decompiler and it has no annotations.

I remember getting violated by a Tengu close to the stairs the first time I played M2. Thought I was a Mordor pro at the time. Didn't see it coming.

I run a mod by DarkerMuffin that fixes the spawning of a number or problematic monsters, including T'Manas and Dragon Turtles. When he posted the mod, DarkerMuffin explained the spawning problems and how he fixed them. Most of the spawning problems result from the monster being assigned a companion type that can never spawn with it. In the case of Dragon Turtles, they are supposed to spawn with cascading Kyu-type Water Dwellers. But the first one, the Kyu t'Salli, is just a level-10 monster and therefore can't spawn in the second slot on level 14. When that happens, the game apparently goes back to the drawing board and re-rolls the encounter.

DarkerMuffin fixed Indiginis by assigning them animals as companions. It seems to have worked. Immediately after I installed the mod, I started encountering Indiginis, and I've seen lots of T'Manas.

If you want more detail, read DarkerMuffin's original post. He posted it in this forum in 2015, so you won't have to scroll down very far to find it.

DarkerMuffin fixed Indiginis by assigning them animals as companions. It seems to have worked. Immediately after I installed the mod, I started encountering Indiginis, and I've seen lots of T'Manas.

If you want more detail, read DarkerMuffin's original post. He posted it in this forum in 2015, so you won't have to scroll down very far to find it.

This one?

http://dejenol.com/forum/index.php?showtopic=4928

This is the one I meant:

http://dejenol.com/forum/index.php?showtopic=4968

But it looks like there is even more detail in the one you posted, which I had not seen previously. Thanks for digging it up.

http://dejenol.com/forum/index.php?showtopic=4968

But it looks like there is even more detail in the one you posted, which I had not seen previously. Thanks for digging it up.

Does it pick a type and then pick a monster of the type or does it put all monsters of allowed types in a pile and pick from the pile?

What line of what file is the function? My copy of the source is from a VB3 decompiler and it has no annotations.

I remember getting violated by a Tengu close to the stairs the first time I played M2. Thought I was a Mordor pro at the time. Didn't see it coming.

What line of what file is the function? My copy of the source is from a VB3 decompiler and it has no annotations.

I remember getting violated by a Tengu close to the stairs the first time I played M2. Thought I was a Mordor pro at the time. Didn't see it coming.

It picks a type then a monster of the type.

Module4.bas, line 1354.

On level 1, rooms #1 to #17 have special restrictions on what monsters can appear. These rooms are all within 2 rooms of the entry stairs, plus a few directly to the east of the stairs up to about 5 rooms away.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

- They can only have one monster group.

- They can never have a random type.

- They can never be higher than "guild level 2", so no Orcs, Slaves, or Twisted Dwarves. Also no Margoyles or Zombies even in the couple of sub-#18 rooms that allow devils or undead. It looks like Tengus are possible, though still rare.

I still can't discern why T'Manas and Dragon Turtles never show up.

Hmm. I saw two groups of 10-12 slaves in the small room immediately right of the stairs (10,11 and 10,10) just an hour ago.

- If there's a laired monster, there's a 75% chance of it showing up.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

- If it's a stud room, the maximum level of the lead monster in that room is the current level+1 (as advertised!). There's a 2/3 chance that its minimum level is the current level. Otherwise, the min level is the same as for a normal room (see next step).

- If it's a normal room, the minimum level is about 80% of the current level (not sure how it's rounded off), with a 20% chance of it being an additional -1 level, a 20% chance of it being -2 levels, and a 10% chance of -3 levels. (This would suggest that the lowest possible level of a lead monster on level 15 will be 9, and you might still meet level 1 groups on level 5.)

- For the general monster type (insect, demon, thief, etc.), there's a 1% chance it's randomly chosen from all possible types - otherwise, the type is randomly chosen out of what types are assigned to the room.

- For the specific monster within that type, the selection is weighted by each valid monster's "chance". Monsters above or below the previously determined max or min level are excluded.

When is the level picked? Do I pick a type and then select from all the monsters between minLevel and maxLevel by rarity? Or, do I pick a type, pick a level, and then select from all available monsters on the level by rarity?

I listed the steps in the order they're performed. The level range is determined, then monster type, then random roll weighted by monster rarity.

I listed the steps in the order they're performed. The level range is determined, then monster type, then random roll weighted by monster rarity.

Thanks. Is it doing any weird stuff where the file order matters? I remember reading that when generating something it finds the first legit something and then scans to the last legit something and selects from those. If a something is out of place, say at the end of the file, then that something isn’t generated. (Where something is either monsters or items, I can’t remember)

Looking at the source again, I'm pretty sure I got some things wrong. When I have a chance to comb over it in detail, I'll let you know.

I did start looking at the spawning source again last night. To be absolutely sure how it works is, to be honest, not worth the hours of analysis for me. It's loops within loops checking something against something else and then putting something else in a table and rolling against the total weighted chance of whatever's in that table. I'm sorry I can't offer more.

The other stuff is less convoluted - the safe zone, stud rooms, min and max level (rounding surprises notwithstanding).

The other stuff is less convoluted - the safe zone, stud rooms, min and max level (rounding surprises notwithstanding).

While we're on the subject of monster spawning . . . It appears to me that the range of hit points for a monster is the official "average hits" +/−25%, apart from rounding oddities. Is that correct?

Correct. When created, a monster's base HP has a ~~25% chance of being lower and a 75%~~ 50%/50% chance of being higher or lower by the following amount:

(random * (base HP * 0.5) / 2) + 1

which is basically +/- 25%.

Edit: Mordion is right, I was incorrectly assuming VB's Int() does rounding.

(random * (base HP * 0.5) / 2) + 1

which is basically +/- 25%.

Edit: Mordion is right, I was incorrectly assuming VB's Int() does rounding.

While we're on the subject of monster spawning . . . It appears to me that the range of hit points for a monster is the official "average hits" +/−25%, apart from rounding oddities. Is that correct?

Found the code in monsmod.bas:1868

50/50 chance of adding or subtracting. Int(Rnd * (averageHits * .5) / 2) + 1

which means a monsters HP can never be exactly averageHits.

Thanks for the confirmation.

It seems overly complicated to multiply by .5*and* divide by 2. If I had written such inefficient code when I was in college, I'm sure it would have drawn a negative comment from my profs. But, then, that was back when computers were slow and efficient coding mattered.

It seems overly complicated to multiply by .5

Thanks for the confirmation.

It seems overly complicated to multiply by .5*and* divide by 2. If I had written such inefficient code when I was in college, I'm sure it would have drawn a negative comment from my profs. But, then, that was back when computers were slow and efficient coding mattered.

It seems overly complicated to multiply by .5

Back in the 90's I was of the opinion you should never use float outside of scientific computing and even when you did you should avoid trig and logarithms. There's a lot of algebra that could be simplified in the code base. Peruse the formula's section on the wiki for a glimpse. I also remember Mordor running really laggy on my 486 DX2 even though I had an FPU.

These formulas only have to be run a few times per second, at most (for instance, to resolve combat hits). Mordor's formulas are absurdly elaborate but I doubt they were the source of lag. More likely it's the display code and/or various game logic loops that chew up millions of cycles. I doubt DA ever tried to profile/optimize it unless there was a section of code that causing obvious hangs.

As hairy as the formulas are, I interpret them to be the product of repeated testing and tweaking until DA got the gameplay he wanted. In that regard, I think he did a really good job. The overall game balance is very good.

As hairy as the formulas are, I interpret them to be the product of repeated testing and tweaking until DA got the gameplay he wanted. In that regard, I think he did a really good job. The overall game balance is very good.

It seems overly complicated to multiply by .5 *and* divide by 2. If I had written such inefficient code when I was in college, I'm sure it would have drawn a negative comment from my profs. But, then, that was back when computers were slow and efficient coding mattered.

As Nudibranch suggested, the real reason is likely to be repeated tweaking of code, but there can be a difference between multiplying by a half and dividing by two. Consider the following expressions in python:

>>> ((15 * .5) / 2) + 1

4.75

>>> ((15 / 2) * .5) + 1

4.5

>>> (15 / 4) + 1

4

Given the Int() call in the Mordor code, I don't think DA was trying to leverage this sort of effect, and if he was there are better ways to do it. I'd certainly call out that code in a review if I saw it at work, but when you're working on something complicated in your own time, sometimes it's more important that it's right than that it's elegant.

korexus.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Invision Power Board © 2001-2019 Invision Power Services, Inc.