This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: TACTICS (Part 2 of 7) Type: Subroutine Category: Tactics
Deep dive: Program flow of the tactics routine
This section contains the main entry point at TACTICS, which is called from part 2 of MVEIT for ships that have the AI flag set (i.e. bit 7 of byte #32). This part does the following: * If this is a missile, jump up to the missile code in part 1
* If this is a rock hermit, consider spawning (22% chance) a highly aggressive and hostile Sidewinder, Mamba, Krait, Adder or Gecko (equal odds of each type) and we're done
.TACTICS* Recharge the ship's energy banks by 1
Arguments: X The ship type
The docking computer in the enhanced versions uses its own turning circle configuration, which is different to the turning circle used by the tactics routine, so the latter switches to its own configuration when it starts (as they share configuration variables).
See below for more variations related to this code.
This variation is blank in the Cassette and Electron versions.
Tap on a block to expand it, and tap it again to revert.
Code variation 5 of 16
See variation 4 above for details.
This variation is blank in the Cassette and Electron versions.
LDA #22 \ Set CNT2 = 22, which is the maximum angle beyond which STA CNT2 \ a ship will slow down to start turning towards its \ prey (a lower value means a ship will start to slow \ down even if its angle with the enemy ship is large, \ which gives a tighter turn). This value is not changed \ in the TACTICS routine, but it is set to different \ values by the DOCKIT routine
CPX #MSL \ If this is a missile, jump up to TA18 to implement BEQ TA18 \ missile tactics
The enhanced versions let the NEWB flags determine whether ships should be heading for the planet (which is applied to traders, ships who are docking, escape pods and so on). The cassette and Electron versions are a lot simpler and only send escape pods in the direction of the planet.
This variation is blank in the Disc (flight), 6502 Second Processor and Master versions.
CPX #ESC \ If this is not an escape pod, skip the following two BNE P%+8 \ instructions JSR SPS1 \ This is an escape pod, so call SPS1 to calculate the \ vector to the planet and store it in XX15 JMP TA15 \ Jump down to TA15
CPX #SST \ If this is not the space station, jump down to TA13 BNE TA13
Space stations in the enhanced versions regularly spawn Transporters and Shuttles that ply their trade between the station and the planet.
This variation is blank in the Cassette and Electron versions.
LDA NEWB \ This is the space station, so check whether bit 2 of AND #%00000100 \ the ship's NEWB flags is set, and if it is (i.e. the BNE TN5 \ station is hostile), jump to TN5 to spawn some cops LDA MANY+SHU+1 \ The station is not hostile, so check how many BNE TA1 \ Transporters there are in the vicinity, and if we \ already have one, return from the subroutine (as TA1 \ contains an RTS) \ If we get here then the station is not hostile, so we \ can consider spawning a Transporter or Shuttle JSR DORND \ Set A and X to random numbers CMP #253 \ If A < 253 (99.2% chance), return from the subroutine BCC TA1 \ (as TA1 contains an RTS) AND #1 \ Set A = a random number that's either 0 or 1 ADC #SHU-1 \ The C flag is set (as we didn't take the BCC above), TAX \ so this sets X to a value of either #SHU or #SHU + 1, \ which is the ship type for a Shuttle or a Transporter BNE TN6 \ Jump to TN6 to spawn this ship type and return from \ the subroutine using a tail call (this BNE is \ effectively a JMP as A is never zero) .TN5
\ We only call the tactics routine for the space station \ when it is hostile, so if we get here then this is the \ station, and we already know it's hostile, so we need \ to spawn some cops JSR DORND \ Set A and X to random numbers
In the cassette version there is a 45% chance that an angry station will spawn a cop, while in the enhanced versions there is only a 6.2% chance.
Tap on a block to expand it, and tap it again to revert.
In the Electron version there can be up to three cops in the vicinity, in the cassette and disc versions there can be up to four, in the Master version there can be up to six, and in the 6502SP there can be up to seven.
Tap on a block to expand it, and tap it again to revert.
LDX #COPS \ Set X to the ship type for a cop
The cops that the space station spawns to defend itself are slightly less aggressive in the Electron version than in the other versions.
Tap on a block to expand it, and tap it again to revert.
JMP SFS1 \ Jump to SFS1 to spawn the ship, returning from the \ subroutine using a tail call .TA13
This logic is in part 3 for the other versions.
This variation is blank in the Disc (flight), 6502 Second Processor, Master and Electron versions.
CPX #TGL \ If this is not a Thargon, jump down to TA14 BNE TA14 LDA MANY+THG \ If there is at least one Thargoid in the vicinity, BNE TA14 \ jump down to TA14 LSR INWK+32 \ This is a Thargon but there is no Thargoid mothership, ASL INWK+32 \ so clear bit 0 of the AI flag to disable its E.C.M. LSR INWK+27 \ And halve the Thargon's speed RTS \ Return from the subroutine .TA14
Without the NEWB flags, the logic in the cassette and Electron versions is much simpler (traders always fly a Cobra Mk III).
This variation is blank in the Disc (flight), 6502 Second Processor and Master versions.
CPX #CYL \ If A >= #CYL, i.e. this is a Cobra Mk III trader (as BCS TA62 \ asteroids and cargo canisters never have AI), jump \ down to TA62 CPX #COPS \ If this is a cop, jump down to TA62 BEQ TA62 LDA SSPR \ If we aren't within range of the space station, jump BEQ TA62 \ down to TA62 LDA INWK+32 \ This is a pirate or bounty hunter, but we are inside AND #%10000001 \ the space station's safe zone, so clear bits 1-6 of STA INWK+32 \ the AI flag to stop it being hostile, because even \ pirates aren't crazy enough to breach the station's \ no-fire zone .TA62
Rock hermits have a 22% chance of spawning a ship.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
CPX #HER \ If this is not a rock hermit, jump down to TA17 BNE TA17 JSR DORND \ Set A and X to random numbers CMP #200 \ If A < 200 (78% chance), return from the subroutine BCC TA22 \ (as TA22 contains an RTS) LDX #0 \ Set byte #32 to %00000000 to disable AI, aggression STX INWK+32 \ and E.C.M.
In the Master version, rock hermits spawn ships that are hostile and innocent bystanders.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
Tap on a block to expand it, and tap it again to revert.
Rock hermits can spawn a Sidewinder, Mamba, Krait, Adder or Gecko.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
AND #3 \ Set A = a random number that's in the range 0-3 ADC #SH3 \ The C flag is set (as we didn't take the BCC above), TAX \ so this sets X to a random value between #SH3 + 1 and \ #SH3 + 4, so that's a Sidewinder, Mamba, Krait, Adder \ or Gecko JSR TN6 \ Call TN6 to spawn this ship with E.C.M., AI and a high \ aggression (56 out of 63) LDA #0 \ Set byte #32 to %00000000 to disable AI, aggression STA INWK+32 \ and E.C.M. (for the rock hermit) RTS \ Return from the subroutine .TA17
LDY #14 \ If the ship's energy is greater or equal to the LDA INWK+35 \ maximum value from the ship's blueprint pointed to by CMP (XX0),Y \ XX0, then skip the next instruction BCS TA21 INC INWK+35 \ The ship's energy is not at maximum, so recharge the \ energy banks by 1