1990 · Blade Software

Lords of Chaos

This minisite was contributed by air. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/spectrum/lords-of-chaos with me to Gold.

Up to four wizards share one 36 by 36 square island, summon armies, fight over treasure and race for a portal that opens on a random turn. Every scenario brings its own map, creatures, words and even pieces of code that the engine calls at fixed moments.

01 · The game

Each player is a wizard, playing for points

A turn is a budget of action points, spent on steps, blows, spells and picking things up.

The play screen: the map window on the left, the information display on the right
A wizard at home in scenario 1. The map window shows seven squares by seven; the information display on the right shows what stands on the square under the cursor.
The panel shown before a wizard's turn
The panel before each turn: whose turn it is, the turn number and each wizard's victory points.

Lords of Chaos was written by Julian Gollop and released by Blade Software in 1990. One to four people play, taking turns at the same Spectrum, and in a one-player game the computer plays a wizard of its own. Wizards cast spells that summon dragons, goblins, ghosts and the rest, and their creatures walk, fly, fight and carry things. Points come from kills, from treasure carried out, and from escaping through the portal before it closes.

The tape holds the program, a wizard designer and three scenarios. A scenario is not just a map. It is a 12 KB block loaded over the top of memory, holding the creatures' figures, the terrain's rules, every word the game prints, the graphics and some routines of its own. The engine underneath stays the same.

02 · The map window

Seven squares by seven, drawn from the scenario's tables

Every map square is a block of three by three characters. Pick a scenario, move the window with the arrows, and choose a square to see what the scenario says about it.

Loading the listings…

Drawn by the page from the engine's character sets and the scenario's things, graphics and colour sets ($A94C draw_map, $A7B6 draw_block). The squares here are as the scenario file has them, before the start of a game scatters objects and places the wizards.

The map is 36 rows of 36 bytes (the pointer at $D030). A byte below $50 is a terrain, $50 to $83 an object lying there, and $8C and up a creature. Each value has a five-byte entry in the scenario's table of things: which of four character sets to draw from, which graphic (nine character numbers), which colour set (nine attributes), and two bytes for animation that the interrupt counts down every other frame ($A891). Water ripples and fire flickers because the interrupt swaps their graphics, and the main program never has to think about it. The Graphics tab draws every thing in each scenario, moving as the game moves it, with the cursor, the bursts, a wizard's death and the missiles.

The map wraps round: walking off the right edge brings a creature in on the left. The window scrolls a row or column at a time when the cursor reaches its edge ($629B).

With Line of sight on, the chosen square is a creature on the ground, and every square it could see is lit. The game traces a line square by square from the viewer to each square within 18 half squares, a straight step counting 2 and a diagonal 3, and a square whose terrain has bit 0 set in its flags ($D38E) blocks it ($B41B). The squares next to the viewer are always seen.

03 · Terrain

What each kind of ground costs, resists and burns

Five bytes for each of 78 terrains ($D208) decide how much a step costs, how hard the terrain is to break, and how the area spells take on it.

From each scenario's terrain records at $D208 and its flags at $D38E, named by the scenario's own messages. Each picture is the terrain's square drawn from the scenario's table of things as the map starts; on the Graphics tab they move. A plain square is a terrain the scenario never puts on its map. "–" in the step column is $FF, a square nothing can walk into.

The first byte is the cost of a step in action points ($CA2B). A diagonal step costs half as much again. A flying creature, a ghost, and a creature whose type matches the terrain (a swimmer in water) always pay 4. A step also costs half its cost in stamina ($B4EB).

The second byte is the terrain's toughness. A creature that walks into a square it cannot enter attacks the terrain instead, for 6 action points and 6 stamina, and breaks it when a random number beats the toughness ($6862). The top two bits of the fifth byte say what the broken square becomes. Magic lightning breaks terrain the same way.

The third and fourth bytes are the area spells' chances: how readily the ground floods or grows tangle vine, and how readily it catches magic fire or gooey blob ($86B2). A 0 means the spell does nothing there. Fire spreads each turn to neighbours by the same numbers ($7DBD).

04 · Creatures and combat

What one blow does

The scenario holds the figures of every creature it uses. Choose an attacker and a defender to see what one blow does.

The table is each scenario's creature types (the pointer at $D003, twelve bytes a type from $90), each drawn as it stands on the map when the scenario starts. The blow follows $8645.

An attack costs 8 action points and 8 stamina ($84EC). The blow is a random number below twice the attacker's combat plus 2, less the defender's defence. Anything left comes off the defender's constitution. If the defender survives with 4 action points and 4 stamina it strikes back at once.

The figures in the table are the type's own. In play they move: a strength potion adds 20 to combat, a protection potion 25 to defence, a weapon in use adds its combat, and the best defence among the weapons carried counts. Then both are divided by the number of times the creature's constitution goes into its most ($9342): nothing changes until it is down to half, when they halve, and at a third they are a third.

A blow of more than a quarter of the creature's starting constitution adds one to its fatal wound, up to 7, and every turn after that it loses twice the wound in constitution ($7755, $7560). Undead creatures take damage only from magic: another undead creature, a magic weapon or a spell ($8605).

05 · Spells

Forty-five spells, priced by level

A spell costs its base price times its level plus one, and every cast lowers its level by one.

Base costs from $B4BE, names from the scenario's messages through spell_name ($80A0). The cost is worked out by $81D4. The picture is what the spell leaves on the map: the creature it summons, the potion it brews, the ground it spreads (magic fire and gooey blob in the first wizard's own). A spell with nothing to leave shows its flight, the missile drawn in its colour.

A wizard's record holds a byte for each of the 45 spells: the level it was designed with in the high four bits and the level left in the low four ($CEEA). Casting needs 8 action points and the mana, and takes one level off ($82A2). A summon spell brings as many creatures as its level, on free squares round the wizard ($8342). Mana comes back by a 25th of the starting mana each turn ($7560).

A spell cast at a square or a creature flies there first, as a cross or a star of pixels in its own colour, and ends in the burst a blow makes ($AEBE): magic fire, gooey blob, tangle vine and flood on their way to the ground they spread, ENCHANT, SUBVERSION and CURSE in one colour, MAGIC BOLT and MAGIC LIGHTNING in colours of their own. MAGIC ATTACK bursts again on every creature it kills. A summons shows the sparkle where the creatures appear, a brew where the potion is, and MAGIC SHIELD on the wizard. TELEPORT and MAGIC EYE draw nothing of their own: one moves the wizard, the other shows the map as a creature on the target square would see it.

Potions are brewed rather than cast at a creature: an empty cauldron, the right ingredient and the wizard on one square, and the spell turns the cauldron into the potion with the level plus 3 gulps in it ($848A). Dragons need a dragon potion made the same way from dragon herb before the summon works ($8320).

06 · Sound

Sound: sixteen effects from one loop

Every sound in the game comes from the same eight-byte recipe and the same routine. Press one to hear it.

Played from the edges of the speaker that the page works out from each sound's eight bytes at $C7B0, timed as the game's loop at $C856 takes them. The Spectrum's speaker plays a square wave; low clicks below about 100 Hz are hard to hear on laptop and phone speakers.

A sound is a number of groups, a number of repeats, and three notes. Each note is an empty loop of its delay followed by one click of the speaker ($C856). After each group every delay moves on by its own step, which turns three clicks into a rising or falling sweep. The game plays nothing during a turn the computer plays out of sight, and a sound started while the map is being drawn gets a step after each row, so the drawing and the sound share the time.

07 · Random numbers

Random numbers from the refresh register

The game's dice depend on how many instructions the processor has run.

random_below ($A737) takes the Z80's refresh register, R, which goes up by one with every instruction fetched, and ex-ors it with three bytes at each of two pointers that walk through memory a byte a call ($606F, $6071), and with a counter that every poll of the controls moves on ($FFF8). It draws again until the number is below the limit asked for.

So the outcome of a blow depends on exactly how long everything before it took, down to the instruction, and on how many times the game polled the controls while the player held a key. Two players who make the same moves at different speeds see different fights.

08 · The computer's turn

How the computer moves its creatures

The computer moves each of its creatures up to 50 times, choosing at each step from a fixed order of checks.

computer_move_creature ($974E) loads a creature and asks, in order, whether it should drink a potion, eat, use a vial, pick something up, cast a spell, shoot, chase an enemy it can beat, run from one it cannot, or walk on along its route. Each test sets a reason it is done ($D181) when it ends the creature's move.

Routes and waypoints belong to the scenario ($D00F, $D013). A creature the computer summons gets a route that suits it: flyers, carriers, swimmers or wizards, by the route's flags ($A4FA). Some are made guards and stay by their wizard, by the type's bodyguard chance. Creatures the computer cannot see do not exist for it: each creature keeps a list of up to twenty enemies it has seen, with their combat and defence ($9C8C), and chooses its prey from that list ($9DAD). The Levels tab draws each scenario's routes on its map.

The computer's wizard tries spells in the order of the scenario's priorities ($D3DC), halving a spell's priority each time it casts it, so it varies what it casts ($A382). Each scenario also brings its own routines for the attack spells, which pick a target from the enemy list.

09 · Saving to tape

Every file goes through the ROM's tape routines

Every file the game reads or writes goes through the ROM's own tape routines, with a twelve-character header of its own.

A wizard is saved as its 70-byte record, named after the first word of its name and its level: MERLIN at level 2 becomes MERLIN2 with the extension WIZ ($CCBD). A saved game is the object table and creature records, then everything from the wizard records to the top of memory, with the extension SVG ($C74D). A scenario is 12,285 bytes loaded at $D003 with the extension GAM ($C708).

Loading reads headers until one matches, and the match looks only at the first character of the name, whatever the extension ($C675). The Discoveries tab has what that does. In a game against the computer, the end of turn menu lets a player save only five times ($C8E4).