Game Internals › War of the Lance › Bugs in the original

Bugs in the original

As released, the game contained quite a few bugs. Some are minor, some major, but all were clearly not what the makers intended. These are fixed in the rebuild, though you can use the original buggy version if you want.

Our approach to bugs

The rebuild plays the original's rules line by line, bugs and all. Fixing the bugs makes a different game, so the fixes are options, in two groups you can switch on and off in the Play page's Options. Both are on to start with.

  • Core bug fixes: where the original reads memory by mistake (the stray reads) or looks up the wrong unit, so that leftover bytes decide the result, and units can be corrupted or moved. Switched off, the rebuild reads its own copy of the computer's memory instead. That is not byte for byte the original's, so the bugs happen as in the original but not always with the same bytes.
  • Rules bug fixes: rules the code gets wrong, such as a reversed retreat test or loops that check one square eight times. Where the intended rule is our guess, the entry says why we chose it.

PC version SSI's 1990 DOS version is a line-by-line translation of the Apple II code. Where we checked it, the notes say whether it has the same bug. It nearly always does, so it rarely tells us what the designers meant; the one exception is the sea odds.

Switched off, each group plays as the original. A game keeps the options it started with. Bugs that only touch the screen, or change nothing, are kept as they are.

Each entry is marked with how sure we are that it's a bug:

  • Certain The code plainly can't do what it sets out to: a test that can never be true, a variable read before it is set, a loop over the wrong side's units.
  • Probably The code works, but the result is unlikely to be what the designers meant: a bonus added where every similar bonus is multiplied, or one side's figure used where the other's would make sense.

And with what the rebuild does: Core fix or Rules fix, fixed with that group of fixes switched on, Cosmetic when only the screen is affected (kept), or No effect when the code is wrong but nothing in the game changes because of it.

Land combat

Digging in barely helps a defender

Rules fixProbably

Infantry, cavalry and Draconians that stay put can dig in: each turn, outside enemy zones of control and off fortified terrain, their fort level may rise by one or two, up to 7. In battle, every other factor multiplies a side's strength, but this one is added to it: + (10 + 3 × fort level) ÷ 10, worth only one to three points. (We checked the 6502 code to be sure.)

This is only about digging in. Fortified terrain (cities, ports, towers, fortresses, dwarven forts, mountain passes) works as it should: it multiplies the defender's strength, by up to four times for a dwarven fort.

The manual says forts greatly increase a defender's strength. In practice a unit that has dug in for turns fights almost exactly as well as one that just arrived.

The fix (rules bug fixes): It multiplies: × (10 + 3 × level) ÷ 10, from × 1 just arrived to × 3.1 after digging in to level 7. Why this fix: Like every other factor, it gives × 1 when it doesn't apply (level 0), which fits a multiplier, and it matches what the manual promises.

PC version The same bug: the fort level is added there too.

The attacker's losses are sized from the defender's infantry

Rules fixProbably

The formula for how many troops a battle costs starts from the attacker's troops, then adjusts for the infantry, cavalry and Draconians. But the variable it uses for those holds the defender's total, not the attacker's.

Losses depend partly on the wrong side's army: attacking a stack with many infantry costs differently from what the formula intends.

The fix (rules bug fixes): From the attacker's own infantry, cavalry and Draconians. Why this fix: The formula adjusts the attacker's troops, and the attacker's own total of those units is worked out alongside the defender's: the two variables were confused.

PC version The same bug.

Defending dragons always add to the defender's losses

Rules fixCertain

The defender's losses get + 2 × defending dragons, meant only while the losses are below 99. The test reads the losses before they've been worked out, when they are still 0, so the dragons always count.

A small extra loss for defenders with dragons, even in big battles.

The fix (rules bug fixes): The dragons count only while the losses are below 99.

PC version The same bug.

The harder a defender is hit, the less likely it is to retreat

Rules fixProbably

After a battle, a defender that isn't fortified and didn't order RETREAT may still fall back. It needs to have lost more than a ninth of its troops, and then it retreats if 100 × RND > 160 × losses ÷ troops. So its chance of retreating is 100% − 1.6 × the share it lost: about 80% after losing 12%, 52% after 30%, 20% after 50%, and none from 62.5%.

The comparison looks reversed. The attacker's test right after it works the other way: an attacker falls back when it loses more than half its troops, or more than a third with a 30% chance. With the defender's comparison flipped, its chance would rise with its losses too, which also fits the rule that small losses never cause a retreat.

A lightly scratched defender usually gives up its square, while a badly mauled one stays to be attacked again. In simulated battles, 200 quality-7 troops attacked by 400 quality-1 troops retreated 69% of the time after losing about 26 of them, but almost never once their losses passed half.

The fix (rules bug fixes): The chance is 1.6 × its share lost: 19% after losing 12%, certain from 62.5%. Why this fix: It makes the defender's test work the same way as the attacker's, as the paragraph above explains.

PC version The same comparison. The DOS programmers copied it as it was, so this doesn't tell us what the designers meant.

The computer decides whether to retreat by one square: the one to the south

Rules fixCertain

When the computer is defending and outmatched, it means to choose RETREAT, but first it checks the eight squares around the battle for somewhere to retreat to. The loop never sets the direction it is looking in, so it checks the same square eight times. That square comes from a table entry that works out as one step south.

We confirmed it in the original, with the computer defending, badly outmatched, on open ground:

Squares around the battleThe computer's order
All openRETREAT
Only the square to the south impassableSTAND
Only the square to the north impassableRETREAT
All impassable except the southRETREAT

Only the decision is affected. If the square to the south is blocked, the computer stands and fights even with open ground all around. Once it has chosen RETREAT, its units retreat properly: each goes to the best of all eight neighbouring squares. And heavy losses still force a defender to retreat, whatever it ordered.

The fix (rules bug fixes): It checks all eight squares around the battle.

PC version The same bug: the loop of eight never sets its direction.

The computer's defending dragons always use Dragon Fear

Rules fixCertain

The computer is meant to choose between Dragon Fear and attacking with its dragons when defending, more often attacking when it has many troops. It compares a random number between 0 and 1 with 50 or 75, which is always less.

A defending computer's dragons never attack. Dragon Fear keeps them alive, so they're rarely lost on defence.

The fix (rules bug fixes): It compares a random percentage: its defending dragons sometimes attack, more often when it has many troops. Why this fix: The 50 and 75 are percentages, as everywhere else in the module.

PC version The same bug: it compares the raw random number with 50 or 75.

Watching a battle switches off the dragon orb

Rules fixCertain

When either side holds a dragon orb, each dragon in the battle may be turned away: the chance is 30 + 5 × quality percent. With the text results, a turned-away dragon's strength becomes 1, so it adds next to nothing. If you answer YES to DISPLAY BATTLE?, the battle map marks the dragon and shows TURNED AWAY BY DRAGON ORB!!, but the code leaves its strength at 0, which the strength routine takes to mean "no orb, carry on". The dragon fights at full strength.

With the battle display on, the orb does nothing, even though the screen says the dragons were turned away. Whether you watch a battle changes its result. In a test battle (four dragons attacking a stack holding an orb), the defenders lost about 15% more troops when the battle was displayed. The rebuild applies the orb the same way in both modes.

The fix (rules bug fixes): The orb works the same whether the battle is displayed or not.

PC version The same bug.

At sea

PC version The 1990 DOS version fights sea battles the same way, bugs and all, with two changes: its odds use the exact ratio (below), and its Maelstrom is different. A fleet already in the Maelstrom is caught and drifts to another Maelstrom square about 30% of the time, is thrown out and loses 20–50% of its ships about 35% of the time, and is thrown out unharmed the other 35%. A fleet that chooses to sail in is caught half the time, thrown out with losses 35% of the time, and passes through unharmed only 15% of the time. On the Apple II, every fleet in the Maelstrom has a 40% chance of nothing happening, 20% of losing ships where it is, and 40% of being thrown out unharmed.

Sea battle odds come in only four steps

Rules fixProbably

The odds of a sea battle are put into one of seven classes by the strength ratio, with thresholds at 0.15, 0.3, 0.6, 1.4, 2 and 3 to 1. But the ratio is rounded down to a whole number before it is compared, so only 1, 2 and 3 can ever be told apart.

Sea battles only distinguish below 1:1, 1:1, 2:1 and 3:1 or better. A fleet at 0.9 to 1 fights as if it were hopelessly outnumbered, and one at 1.9 to 1 as if the two were evenly matched.

The fix (rules bug fixes): The ratio is compared unrounded: all seven classes of odds can happen. Why this fix: Thresholds below 1 can never be told apart from a whole number, so they must have been meant for the exact ratio.

PC version Fixed: the DOS version works out the ratio as a percentage before rounding it, so all seven classes happen, as with our fix.

Both sides' hits are based on the moving fleet's size

Rules fixProbably

The number of hits each side takes in a round starts from a base worked out from the ships of the side that moved, for both sides alike.

A large fleet that sails into battle both deals and takes more hits than its opponent's size would suggest.

The fix (rules bug fixes): The hits a side takes start from the other side's ships, so a big fleet deals more hits instead of taking more. Why this fix: Hits are what the enemy deals, so they should grow with the enemy's ships; as written, a large fleet that sails in takes more hits as well as dealing them.

PC version The same bug.

The Maelstrom damages the wrong cargo

Core fixCertain

When a fleet loses ships in the Maelstrom, its cargo is meant to suffer too. The damage goes to a list of units left over from earlier in the phase instead of the fleet's own cargo, and the loop runs one entry past the end of that list, where an empty entry points at unit 0's records.

The troops aboard the stricken fleet are spared, while units that happened to be in the earlier list, and unit 0, can be hit instead.

The fix (core bug fixes): The damage goes to the fleet's own cargo.

PC version The same bug, except that a fleet carrying nothing damages no one.

A patrol hemmed in by enemy fleets sails out anyway

Rules fixCertain

A patrol 2–4 squares from a battle sails in to join it, unless it stands in the moving side's zone of control with the moving side's fleets right next to it. To look for those fleets the code checks the eight squares around the patrol, but never sets the direction, so it checks one square eight times.

Unless an enemy fleet happens to be in that one square, the patrol doesn't see the fleets beside it, and sails in to the battle anyway.

The fix (rules bug fixes): It looks at all eight squares around the patrol.

PC version The same bug, while the loop beside it does set its direction.

Interception stops after the first patrol sails in

Core fixCertain

Once an enemy patrol has sailed in to fight one of the moving side's fleets, the rest of that side's fleets are looked up from scratch memory and get no interception check for the rest of the phase. A stray read: see Stray reads.

The fix (core bug fixes): Every fleet of the moving side is checked.

Every arrow key counts as "left" in naval menus

CosmeticCertain

The naval module's key reader adds up its four arrow tests without weighting them, so any arrow reads as "left".

In its two-item menus (such as CONTINUE BATTLE or WITHDRAW) any arrow switches between the two, so nobody notices.

Moving

NO ATTACK cancels orders in the wrong square

Rules fixProbably

NO ATTACK should cancel the attack orders of the units in the attacker's square. It uses whichever square the game listed last. That is usually the attacker's own, whether it has moved or not. But choosing a target the game refuses (ILLEGAL TARGET, such as a square of your own units) lists the target's square.

After a refused target, NO ATTACK cancels the orders of your units on that square, and the attacker's stack keeps its orders.

The fix (rules bug fixes): It cancels the orders of the units in the attacker's square. Why this fix: TARGET ALL, beside it on the same menu, lists the attacker's square afresh before it gives its orders; NO ATTACK was meant to work on the same units.

NO ATTACK on an empty square hits a random unit

Core fixCertain

If that last-listed square was empty, the loop runs once anyway and cancels the orders of whatever unit leftover memory names. A stray read: see Stray reads.

The fix (core bug fixes): An empty square has no units: nothing changes.

A stack over both limits at once is allowed

Rules fixCertain

When a move ends on a square that may be overstacked, the game checks two limits: too many big units, or too many fliers. It refuses a stack that breaks exactly one of them, but the test is written so that breaking both at once passes.

A square can end up holding too many big units and too many fliers, which neither limit alone would allow.

The fix (rules bug fixes): Breaking either limit, or both, is refused.

PC version The same test, at least where a battle checks the squares to retreat to.

Unloading into a full side puts the unit in another unit's slot

Core fixCertain

Unloading a unit from a ship needs a free slot in its side's list. If there is none, the code carries on with whatever slot number its variable last held.

The unit lands in a slot that's already in use. It needs an enormous army to happen (Whitestone has 160 slots).

The fix (core bug fixes): The unload is refused: the unit stays aboard.

"MAXIMUM LOAD REACHED" trails old text

CosmeticCertain

The movement module uses one string variable for both its menu options and its messages, so this message is followed by whatever the variable held last.

The turn

Whitestone's good fortune skips part of its army

Rules fixCertain

Some turns bring a side a boost: better quality, or less fatigue, for each of its units. Both loops run over the Highlord's range of unit slots, even when the boost is Whitestone's.

Whitestone units in slots beyond the Highlord's last used slot miss out on Whitestone's boosts.

The fix (rules bug fixes): Whitestone's boosts go over Whitestone's own units.

PC version The same bug.

The movement bonus can go to the wrong side

Rules fixCertain

The side with the initiative is meant to get 25% more movement points. The status module keeps the favoured side in a variable that its recovery step reuses, one unit at a time, for each unit's owner.

Except on turn 1 and in winter, when recovery is skipped, the bonus goes to whichever side owns the highest-numbered unit recovery looked at, not necessarily the side with the initiative.

The fix (rules bug fixes): The bonus goes to the side with the initiative.

The terrain table swaps after a battle display or a save

No effectCertain

The map routines read terrain heights from a table file. The scenario disk's copy, loaded when the game starts, has heights for the hills. The game disk's copy, loaded after the graphic battle display and after saving, has them set to 0, and it stays loaded until the next new game.

The only thing that reads those heights is the routine that searches for units near a square. It was built as a line-of-sight test: it walks the line between two squares, and every square that rises above the line uses up part of a budget the caller gives it, until the line counts as blocked. But in this game every tile's cost is 0, in both table files and in the battle display's, so nothing ever blocks. The search finds units purely by distance, and the heights never matter.

No effect on play. (We first thought this changed what units could see; looking closer showed that no line is ever blocked at all.)

The news odds read the wrong memory

Core fixCertain

The check for Highlord armies in the west reads zero page as if it were the country map. A stray read: see Stray reads.

The fix (core bug fixes): It reads the country map.

PC version Not in the DOS version: its lookup uses map addresses set when the game starts, so it reads the real country map, as our fix does.

The computer player

It never falls back to defend Neraka

Rules fixCertain

The computer has a plan to pull every free unit back to Neraka when Whitestone threatens it with more than 500 strength and dragons. The test for it sits inside a branch that only runs for a different kind of objective, so it can never be true.

Neraka is only ever defended by the units its first priority assigns. See The computer Highlord.

The fix (rules bug fixes): The test is made for every objective, as the code meant.

It passes over Lemish and Throtyl in diplomacy

Core fixCertain

Before trying to win over Lemish or Throtyl, the computer means to check that it has more than two dragons near their border. The count reads one entry past the end of the list of units found, the same wrong entry every time, which names an empty slot. The "dragon" it checks is then a byte from another table, unit 0's slot number.

In both starting positions that byte isn't a dragon's type, so the check fails: when Lemish or Throtyl is its best prospect for an alliance, the computer moves on to another nation.

The fix (core bug fixes): It counts the dragons found.

A fleet that can't unload moves one of Whitestone's units

Core fixCertain

When a computer fleet ends its move in a square over the stacking limit, the computer takes it back to the last square where it may stop. If the fleet was trying to unload there and no square around it would take the troops, the unloading routine gives up while still pointing at the unit it was trying to land, not at the fleet. That unit is aboard, so it has no place in the list of units on the map: its slot number is 255. The move back is then made for "slot 255" of the Highlord's list, which is past its end, where Whitestone's list begins: it is Whitestone's 76th unit.

Whichever Whitestone unit is in that slot, anywhere on the map, jumps into the square the fleet came from, and the fleet stays where it may not stop. Found in a test game, turn 21: a newly arrived dragon jumped from the grassland of Northern Ergoth to the sea west of it, in with the computer's fleets. There, GET finds the computer's units first and refuses, so the unit can't move until they leave. The rebuild takes the fleet back, as the code meant.

The fix (core bug fixes): The fleet goes back, as the code meant.

Recalling a unit counts a phantom

Core fixCertain

Bringing a unit back from subversion onto an empty square counts a unit from leftover memory towards the stacking limit. A stray read: see Stray reads.

The fix (core bug fixes): No phantom.

Saving

DISK FULL is only reported in winter

Core fixCertain

When a save fails, the save menu stores the error number, then redraws the screen. Redrawing the date reuses the same variable for the season. The test that follows, "is the error DISK FULL?", is really testing "is it winter?".

A full disk shows ** DISK FULL ** only in winter. In any other season it shows "IS THE SSI DATA DISKETTE INSERTED PROPERLY?".

The fix (core bug fixes): A full disk shows ** DISK FULL ** in any season.

On screen

Scrolling at the map's edge jumps three rows

CosmeticProbably

When the map window scrolls by one square at the edge of the map, it shifts by three text rows instead of two, from the map routine's own arithmetic.

Drawing a box changes a byte of the game state

CosmeticCertain

The routine that draws text boxes modifies its own code, which lives inside the memory saved as the game state. Every box drawn changes one byte of a saved game.

No effect on play; it only matters for checking a rebuild byte for byte, which is how it was found.