Skip to navigation


Tactics: TACTICS (Part 2 of 7)

[Acorn Electron version]

Name: TACTICS (Part 2 of 7) [Show more] Type: Subroutine Category: Tactics Summary: Apply tactics: Escape pod, station, safe-zone pirate Deep dive: Program flow of the tactics routine
Context: See this subroutine in context in the source code Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * MVEIT (Part 2 of 9) calls TACTICS

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 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 TA1 \ subroutine (as TA1 contains an RTS) LDA MANY+COPS \ We only call the tactics routine for the space station CMP #3 \ when it is hostile, so first check the number of cops BCS TA1 \ in the vicinity, and if we already have 3 or more, we \ don't need to spawn any more, so return from the \ subroutine (as TA1 contains an RTS) LDX #COPS \ Set X to the ship type for a cop LDA #%11100001 \ Set the AI flag to give the ship E.C.M., enable AI and \ make it pretty aggressive (56 out of 63) JMP SFS1 \ Jump to SFS1 to spawn the ship, returning from the \ subroutine using a tail call .TA13 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