This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: Main game loop (Part 4 of 6) Type: Subroutine Category: Main loop
This section covers the following:
INC EV \ EV is negative, so bump it up again, setting it back \ to 0
In mission 2, after picking up the plans, there's an extra 22% chance that a Thargoid will spawn (this is on top of the normal spawning rate of pirates, bounty hunters and Thargoids).
This variation is blank in the Cassette and Electron versions.
LDA TP \ Fetch bits 2 and 3 of TP, which contain the status of AND #%00001100 \ mission 2 CMP #%00001000 \ If bit 3 is set and bit 2 is clear, keep going to BNE nopl \ spawn a Thargoid as we are transporting the plans in \ mission 2 and the Thargoids are trying to stop us, \ otherwise jump to nopl to skip spawning a Thargoid
In the disc and 6502SP versions there's a 22% chance of spawning a Thargoid during mission 2, while it's a 14% chance in the Master version.
This variation is blank in the Cassette, Master and Electron versions.
JSR DORND \ Set A and X to random numbers LDY gov \ If the government of this system is 0 (anarchy), jump BEQ LABEL_2 \ straight to LABEL_2 to start spawning pirates or a \ lone bounty hunter
In the disc there's a 47% chance of spawning a group of pirates or a lone bounty hunter, while in the other versions there's a 35% chance.
Tap on a block to expand it, and tap it again to revert.
.LABEL_2
This variation is blank in the Cassette, Disc (flight), Master and Electron versions.
\ In the 6502 Second Processor version, the LABEL_2 \ label is actually ` (a backtick), but that doesn't \ compile in BeebAsm and it's pretty cryptic, so \ instead this version sticks with the label LABEL_2 \ from the cassette version
JSR Ze \ Call Ze to initialise INWK to a potentially hostile \ ship, and set A and X to random values \ \ Note that because Ze uses the value of X returned by \ DORND, and X contains the value of A returned by the \ previous call to DORND, this does not set the new ship \ to a totally random location. See the deep dive on \ "Fixing ship positions" for details
In the cassette version there's a 13% chance of spawning a group of pirates, while in the other versions there's a 61% chance.
Tap on a block to expand it, and tap it again to revert.
INC EV \ Increase the extra vessels spawning counter, to \ prevent the next attempt to spawn extra vessels
In the enhanced versions, lone bounty hunters can be in a Cobra Mk III (pirate), Asp Mk II, Python (pirate) or Fer-de-lance, while in the cassette version they can be in a Mamba, Python or Cobra Mk III.
Tap on a block to expand it, and tap it again to revert.
In the advanced versions, lone bounty hunters are always spawned as hostile.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
LDA #%00000100 \ Set bit 2 of the NEWB flags and clear all other bits, STA NEWB \ so the ship we are about to spawn is hostile \ We now build the AI flag for this ship in A JSR DORND \ Set A and X to random numbers
Lone bounty hunters in the disc version don't have E.C.M., while in the other versions they have a 22% chance of having E.C.M.
This variation is blank in the Disc (flight) version.
CMP #200 \ First, set the C flag if X >= 200 (22% chance) ROL A \ Set bit 0 of A to the C flag (i.e. there's a 22% \ chance of this ship having E.C.M.) ORA #%11000000 \ Set bits 6 and 7 of A, so the ship is hostile (bit 6) \ and has AI (bit 7)
This variation is blank in the Disc (flight), 6502 Second Processor, Master and Electron versions.
CPY #6 \ If Y = 6 (i.e. a Thargoid), jump down to the tha BEQ tha \ routine in part 6 to decide whether or not to spawn it \ (where there's a 22% chance of this happening)
This variation is blank in the Disc (flight) version.
Tap on a block to expand it, and tap it again to revert.
The Constrictor only spawns in its home system, during the mission 1 endgame, and then it only spawns once... though it can still appear in the ship hangar from time to time.
This variation is blank in the Cassette and Electron versions.
TYA \ Set A to the new ship type in Y EQUB &2C \ Skip the next instruction by turning it into \ &2C &A9 &1F, or BIT &1FA9, which does nothing apart \ from affect the flags .YESCON LDA #CON \ If we jump straight here, we are in the mission 1 \ endgame and it's time to spawn the Constrictor, so \ set A to the Constrictor's type .focoug
This variation is blank in the Cassette and Electron versions.
Tap on a block to expand it, and tap it again to revert.
.mj1 JMP MLOOP \ Jump down to MLOOP, as we are done spawning ships
When considering spawning a Cougar or a Thargoid instead of a cop, the advanced versions spawn a Thargoid 96.8% of the time, and a Cougar 3.2% of the time.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
.fothg LDA K%+6 \ Fetch the z_lo coordinate of the first ship in the K% AND #%00111110 \ block (i.e. the planet) and extract bits 1-5 BNE fothg2 \ If any of bits 1-5 are set (96.8% chance), jump up to \ fothg2 to spawn a Thargoid \ If we get here then we're going to spawn a Cougar, a \ very rare event indeed. How rare? Well, all the \ following have to happen in sequence: \ \ * Main loop iteration = 0 (1 in 256 iterations) \ * Skip asteroid spawning (87% chance) \ * Skip cop spawning (0.4% chance) \ * Skip Thargoid spawning (3.2% chance) \ \ so the chances of spawning a Cougar on any single main \ loop iteration are slim, to say the least LDA #18 \ Give the ship we're about to spawn a speed of 27 STA INWK+27 LDA #%01111001 \ Give it an E.C.M., and make it hostile and pretty STA INWK+32 \ aggressive (though don't give it AI) LDA #COU \ Set the ship type to a Cougar and jump up to focoug BNE focoug \ to spawn it
.mt1 AND #3 \ It's time to spawn a group of pirates, so set A to a \ random number in the range 0-3, which will be the \ loop counter for spawning pirates below (so we will \ spawn 1-4 pirates) STA EV \ Delay further spawnings by this number STA XX13 \ Store the number in XX13, the pirate counter .mt3 JSR DORND \ Set A and X to random numbers
When spawning a pack of pirates in the enhanced versions, the chances of each ship type appearing in the pack are slightly different, with the most likely candidates appearing first in this list: Sidewinder, Mamba, Krait, Adder, Gecko, Cobra Mk I, Worm or Cobra Mk III (pirate).
Tap on a block to expand it, and tap it again to revert.
This variation is blank in the Cassette, 6502 Second Processor, Master and Electron versions.
In the enhanced versions, a pack-hunting pirate will fly a Sidewinder, Mamba, Krait, Adder, Gecko, Cobra Mk I, Worm or Cobra Mk III (pirate), while in the cassette version you'll only find them in the cockpit of a Sidewinder or Mamba.
This variation is blank in the Cassette and Electron versions.
ADC #PACK \ #PACK is set to #SH3, the ship type for a Sidewinder, \ so this sets our new ship type to one of the pack \ hunters, namely a Sidewinder, Mamba, Krait, Adder, \ Gecko, Cobra Mk I, Worm or Cobra Mk III (pirate)
JSR NWSHP \ Try adding a new ship of type A to the local bubble
This variation is blank in the Cassette, 6502 Second Processor, Master and Electron versions.
BCS P%+7 \ If the ship was successfully added, skip the following \ two instructions DEC CPIR \ The ship wasn't added, which might be because the ship \ blueprint for this ship type isn't in the currently \ loaded ship blueprints file, so decrement CPIR to \ point to the previous ship type, so we can try \ spawning that type of pirate instead BPL more \ Loop back to more to have another go at spawning this \ pirate, until we have tried spawning a Sidewinder when \ CPIR is 0, in which case give up and move on to the \ next pirate to spawn
DEC XX13 \ Decrement the pirate counter BPL mt3 \ If we need more pirates, loop back up to mt3, \ otherwise we are done spawning, so fall through into \ the end of the main loop at MLOOP