Sunday, January 20, 2019

The Basic mechanics of Akalabeth

My experience playing Akalabeth left me unsatisfied, so I decided to delve into the source code to try to understand how it works. If anything, this was more fun and more satisfying than playing it.

As an Apple BASIC game, the source code is right on the disk image, and can be extracted with CiderPress.

Monster tables

This was the first thing I looked for. Turns out the “table” looks like this:

1 Skeleton
2 Thief
3 Giant rat
4 Orc
5 Viper
6 Carrion crawler
7 Gremlin
8 Mimic
9 Daemon
10 Balrog

Yeah, that’s it. No stats for HP, AC, damage, or any of the usual stuff I’d expect a monster table to have. This is not a very data-driven game. We’ll get into how those are generated later, but the rule is that the higher the row index, the tougher the monster.

This table is also used by Lord British to hand out quests. Your first quest is selected from this table, and after completing it, your next quest will always be the next monster on the list. In my playthrough, the first quest was a Carrion Crawler, followed by a Gremlin, Mimic, Daemon, and Balrog.

When entering a dungeon level, the game loops through the list of monsters. If (monster index – 2) is smaller than or equal to the dungeon level, then the monster has a 60% chance of spawning somewhere. So, on level 1, you might face skeletons, thieves, and giant rats. On level 8, you could hypothetically face all ten monsters, though in practice this will never happen thanks to the way the RNG works. The game will never spawn two monsters of the same type on the same level.

Player stats & combat

Your difficulty affects the amount of HP the monsters get. That’s it.

A monster’s HP is (2 * monster index) + (2 * dungeon level * difficulty level).

Damage on a successful hit is determined by this formula, rounded up:
RND(Base) + 0.2 * Strength

"RND(Base)" is a function that returns a random decimal value smaller than the weapon's listed damage. For instance, if you attack with your axe that says it does 1-5 damage, the function will be RND(3), and return a value with a minimum of 0 and maximum of 4.9999~. And then the strength bonus is added, which can't be less than 0.6.

This strength bonus applies to thrown axes and bows too, and even amulets' Kill spell.

Shield bashes have base damage of 1. Fists have base damage of 0, meaning that only the strength bonus counts.

Dexterity decides your chance to hit an enemy. The formula is:
4% * (dexterity - monster index - dungeon level)

So let’s say you have 20 dexterity points, and are fighting a thief (index 2) on level 5. That’s a 52% chance of hitting.

Ranged weapons follow this code path too, including the amulet’s kill spell. Ranged weapons follow some additional logic that I don’t fully understand, but it does seem like they hit less often.

This also suggests that if your stamina isn’t high enough, beating the game may be impossible. You have to kill a balrog to win, they have a monster index of 10, and they don’t start appearing until dungeon level 9. What if your dexterity is 19 or less? You have no chance at all of hitting them.

Stamina decides your chance to avoid getting hit by an enemy. The formula is:
4% * (stamina - monster index - dungeon level)

This does not affect the chances of being pickpocketed by thieves and gremlins.

Wisdom is interesting. It determines your starting quest from Lord British. When you first visit, take your wisdom, divide by 3, and round down. That’s the monster index of your first quest. After that point, wisdom does nothing. When I had wisdom of 20, this evaluated to a monster index of 6, so I got sent to kill a carrion crawler.

This actually makes it beneficial to have LOW wisdom. With high wisdom, you’ll just be skipping the early easy quests, and won’t get the stat boost reward for completing them.

Also, if your wisdom is 33 or higher, then you’ll crash the game when getting your first quest, because the monster index of 11 (or higher) doesn’t exist. So, don’t transform into a lizard man until AFTER getting your first quest!

Amulet stuff

When using an amulet as a mage, there’s a 25% chance the amulet gets destroyed.

As a fighter, one of the four spells is chosen randomly, with an equal chance for each spell. But the amulet will never be destroyed.

The Kill spell’s base damage is (10 + dungeon level). It then behaves like a ranged weapon, using the dexterity formula to determine if it hits or not, and the RND(Base) function plus strength bonus for damage if it hits.

The Bad? spell invokes one of three effects chosen randomly. Toad sets all of your stats to 3. Backfire halves your hitpoints. Lizard Man multiplies all of your stats by 2.5, rounded down.

More monster stuff

The gold reward for killing a monster is equal to its monster index plus the dungeon level.

The HP reward is stored in a variable called “LK.” Whenever you kill a monster, LK increases by this:
(monster index * dungeon level)/2

On exiting the dungeon, your HP increases by LK.

Monsters normally pursue you, but will flee instead if their HP drops below (dungeon level * difficulty level). A monster in flight status will attack if they cannot retreat.

Fleeing monsters’ HP will regenerate by (dungeon level + difficulty) on turns when they do not attack. When it rises above (dungeon level * difficulty) they will pursue again.

Mimics do not pursue when they are within 3 spaces of you.

Thievery

When gremlins and thieves attack, there is a 50% chance that they will steal instead. Stealing is always successful.

Thieves will randomly select one of six item types to steal (food, rapier, axe, shield, bow, amulet). If you have at least one, then you lose one. If you don’t, then the thief will try again until he picks something you do have. If you have no items and less than one food (a very probable occurrence early on), this can actually make the game lock up, as the thief endlessly rummages in your pockets looking for loot that you don’t have!

Gremlin theft cuts your food supply in half, which really sucks, and is the main reason why I believe this game to be impossible to beat on high difficulties without cheesing.

No comments:

Post a Comment