Skip to navigation

Elite on the BBC Micro

Tactics: TACTICS (Part 2 of 7) (Cassette version)

Name: TACTICS (Part 2 of 7) [View in context] Type: Subroutine [Compare versions] Category: Tactics Summary: Apply tactics: Escape pod, station, lone Thargon, safe-zone pirate 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 an escape pod, point it at the planet and jump to the manoeuvring code in part 7 * If this is the space station and it is hostile, consider spawning a cop (45% chance, up to a maximum of four) and we're done * If this is a lone Thargon without a mothership, set it adrift aimlessly and we're done * If this is a pirate and we are within the space station safe zone, stop the pirate from attacking by removing all its aggression * Recharge the ship's energy banks by 1 Arguments: X The ship type
.TACTICS CPX #MSL \ If this is a missile, jump up to TA18 to implement BEQ TA18 \ missile tactics 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 \ 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 CMP #140 \ If A < 140 (55% chance) then return from the BCC TA14-1 \ subroutine (as TA14-1 contains an RTS) LDA MANY+COPS \ We only call the tactics routine for the space station CMP #4 \ when it is hostile, so first check the number of cops BCS TA14-1 \ in the vicinity, and if we already have 4 or more, we \ don't need to spawn any more, so return from the \ subroutine (as TA14-1 contains an RTS) LDX #COPS \ Set X to the ship type for a cop LDA #%11110001 \ Set the AI flag to give the ship E.C.M., enable AI and \ make it very aggressive (56 out of 63) JMP SFS1 \ Jump to SFS1 to spawn the ship, returning from the \ subroutine using a tail call .TA13 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 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 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