.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 ADC #10 ; minimum of 10 and a maximum of 26 (as the C flag is STA INWK+27 ; also randomly set) 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 AND #2 ; If we jumped here with a random value of A from the ; BMI above, then this reduces A to a random value of ; either 0 or 2; if we didn't take the BMI and made the ; ship hostile, then A will be 0 ADC #CYL ; Set A = A + C + #CYL ; ; where A is 0 or 2 and C is 0 or 1, so this gives us a ; ship type from the following: Cobra Mk III, Python, ; Boa or Anaconda CMP #HER ; If A is not the ship type of a rock hermit, jump to BNE game1 ; game1 to skip the following instruction LDA #CYL ; This is a rock hermit, so set A = #CYL so we spawn a ; Cobra Mk III .game1 JSR NWSHP ; Add a new ship of type A to the local bubble and fall ; through into the main game loop again JMP MLOOP ; Jump down to MLOOP to do some end-of-loop tidying and ; restart the main loopName: Main game loop (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 blocksContext: 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 where the core loop of the game lives, and it's in two parts. The shorter loop (just parts 5 and 6) is iterated when we are docked, while the entire loop from part 1 to 6 iterates if we are in space. 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.
[X]
Configuration variable CYL = 11
Ship type for a Cobra Mk III
[X]
Subroutine DORND (category: Maths (Arithmetic))
Generate random numbers
[X]
Configuration variable HER = 15
Ship type for a rock hermit (asteroid)
[X]
Entry point MLOOP in subroutine Main game loop (Part 5 of 6) (category: Main loop)
The entry point for the main game loop. This entry point comes after the call to the main flight loop and spawning routines, so it marks the start of the main game loop for when we are docked (as we don't need to call the main flight loop or spawning routines if we aren't in space)
[X]
Subroutine NWSHP (category: Universe)
Add a new ship to our local bubble of universe
[X]
Label game1 is local to this routine
[X]
Label nodo is local to this routine