Skip to navigation

Elite on the BBC Micro

Tactics: TACTICS (Part 2 of 7) (Master 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 the space station and it is hostile, consider spawning a cop (6.2% chance, up to a maximum of seven) and we're done * If this is the space station and it is not hostile, consider spawning (0.8% chance if there are no Transporters around) a Transporter or Shuttle (equal odds of each type) and we're done * 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 * Recharge the ship's energy banks by 1 Arguments: X The ship type
.TACTICS LDA #3 \ Set RAT = 3, which is the magnitude we set the pitch STA RAT \ or roll counter to in part 7 when turning a ship \ towards a vector (a higher value giving a longer \ turn). This value is not changed in the TACTICS \ routine, but it is set to different values by the \ DOCKIT routine LDA #4 \ Set RAT2 = 4, which is the threshold below which we STA RAT2 \ don't apply pitch and roll to the ship (so a lower \ value means we apply pitch and roll more often, and a \ value of 0 means we always apply them). The value is \ compared with double the high byte of sidev . XX15, \ where XX15 is the vector from the ship to the enemy \ or planet. This value is set to different values by \ both the TACTICS and DOCKIT routines 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 CPX #SST \ If this is not the space station, jump down to TA13 BNE TA13 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 CMP #240 \ If A < 240 (93.8% chance), return from the subroutine BCC TA1 \ (as TA1 contains an RTS) LDA MANY+COPS \ Check how many cops there are in the vicinity already, CMP #6 \ and if there are 6 or more, return from the subroutine BCS TA22 \ (as TA22 contains an RTS) LDX #COPS \ Set X to the ship type for a cop .TN6 LDA #%11110001 \ Set the AI flag to give the ship E.C.M., enable AI and \ make it very aggressive (60 out of 63) JMP SFS1 \ Jump to SFS1 to spawn the ship, returning from the \ subroutine using a tail call .TA13 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. LDX #%00100100 \ Set the ship's NEWB flags to %00100100 so the ship we STX NEWB \ spawn below will inherit the default values from E% as \ well as having bit 2 (hostile) and bit 5 (innocent \ bystander) set 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