Skip to navigation

Elite on the BBC Micro and NES

Main loop: Main game loop for flight (Part 1 of 6)

[Elite-A, Parasite]

Name: Main game loop for flight (Part 1 of 6) [Show more] Type: Subroutine Category: Main loop Summary: Spawn a trader (a Cobra Mk III, Python, Boa or Anaconda) Deep dive: Program flow of the main game loop Ship data blocks
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This is part of the main game loop. This is the loop for when we are in flight, while the main game loop for when we are docked is at TT100. This section covers the following: * Spawn a trader, i.e. a Cobra Mk III, Python, Boa or Anaconda, with a 50% chance of it having a missile, a 50% chance of it having an E.C.M., a 50% chance of it docking and being aggressive if attacked, a speed between 16 and 31, and a gentle clockwise roll We call this from within the main loop.
.MTT4 JSR DORND \ Set A and X to random numbers LSR A \ Clear bit 7 of our random number in A and set the C \ flag to bit 0 of A, which is random STA INWK+32 \ Store this in the ship's AI flag, so this ship does \ not have AI STA INWK+29 \ Store A in the ship's roll counter, giving it a \ clockwise roll (as bit 7 is clear), and a 1 in 127 \ chance of it having no damping ROL INWK+31 \ Set bit 0 of the ship's missile count randomly (as the \ C flag was set), giving the ship either no missiles or \ one missile AND #15 \ Set the ship speed to our random number, set to a STA INWK+27 \ minimum of 0 and a maximum of 15 JSR DORND \ Set A and X to random numbers, plus the C flag BMI nodo \ If A is negative (50% chance), jump to nodo to skip \ the following \ If we get here then we are going to spawn a ship that \ is minding its own business and trying to dock LDA INWK+32 \ Set bits 6 and 7 of the ship's AI flag, to make it ORA #%11000000 \ aggressive if attacked, and enable its AI STA INWK+32 LDX #%00010000 \ Set bit 4 of the ship's NEWB flags, to indicate that STX NEWB \ this ship is docking .nodo LDA #11 \ Call hordes to spawn a pack of ships from ship slots LDX #3 \ 11 to 14, which is where the trader ships live in the JMP hordes \ ship files