Skip to navigation

BBC Micro Elite

Main loop: Main game loop (Part 4 of 6)

Name: Main game loop (Part 4 of 6) [View in context] Type: Subroutine Category: Main loop Summary: Potentially spawn lone bounty hunter, Thargoid, or up to 4 pirates
This section covers the following: * Potentially spawn (35% chance) either a lone bounty hunter (a Mamba, Python or Cobra Mk III), a Thargoid, or a group of up to 4 pirates (Sidewinders and/or Mambas)
DEC EV \ Decrement EV, the extra vessels spawning delay, and BPL MLOOP \ jump to MLOOP if it is still positive, so we only \ do the following when the EV counter runs down INC EV \ EV is negative, so bump it up again, setting it back \ to 0 JSR DORND \ Set A and X to random numbers LDY gov \ If the government of this system is 0 (anarchy), jump BEQ LABEL_2 \ straight to LABEL_2 to start spawning pirates or a \ lone bounty hunter CMP #90 \ If the random number in A >= 90 (65% chance), jump to BCS MLOOP \ MLOOP to stop spawning (so there's a 35% chance of \ spawning pirates or a lone bounty hunter) AND #7 \ Reduce the random number in A to the range 0-7, and CMP gov \ if A is less than government of this system, jump BCC MLOOP \ to MLOOP to stop spawning (so safer governments with \ larger gov numbers have a greater chance of jumping \ out, which is another way of saying that more \ dangerous systems spawn pirates and bounty hunters \ more often) .LABEL_2 \ Now to spawn a lone bounty hunter, a Thargoid or a \ group of pirates JSR Ze \ Call Ze to initialise INWK to a potentially hostile \ ship, and set X to a random value and A to a random \ value between 192 and 255 CMP #200 \ If the random number in A >= 200 (13% chance), jump BCS mt1 \ to mt1 to spawn pirates, otherwise keep going to \ spawn a lone bounty hunter or a Thargoid INC EV \ Increase the extra vessels spawning counter, to \ prevent the next attempt to spawn extra vessels AND #3 \ Set A = Y = random number in the range 3-6, which ADC #3 \ we will use to determine the type of ship TAY \ We now build the AI flag for this ship in A TXA \ First, set the C flag if X >= 200 (22% chance) CMP #200 ROL A \ Set bit 0 of A to the C flag (i.e. there's a 22% \ chance of this ship having E.C.M.) ORA #%11000000 \ Set bits 6 and 7 of A, so the ship is hostile (bit 6 \ and has AI (bit 7) CPY #6 \ If Y = 6 (i.e. a Thargoid), jump down to the tha BEQ tha \ routine to decide whether or not to spawn it (where \ there's a 22% chance of this happening) STA INWK+32 \ Store A in the AI flag of this ship TYA \ Add a new ship of type Y to the local bubble, so JSR NWSHP \ that's a Mamba, Cobra Mk III or Python .mj1 JMP MLOOP \ Jump down to MLOOP, as we are done spawning ships .mt1 AND #3 \ It's time to spawn a group of pirates, so set A to a \ random number in the range 0-3, which will be the \ loop counter for spawning pirates below (so we will \ spawn 1-4 pirates) STA EV \ Delay further spawnings by this number STA XX13 \ Store the number in XX13, the pirate counter .mt3 JSR DORND \ Set A and X to random numbers AND #3 \ Set A to a random number in the range 0-3 ORA #1 \ Set A to %01 or %11 (Sidewinder or Mamba) JSR NWSHP \ Add a new ship of type A to the local bubble DEC XX13 \ Decrement the pirate counter BPL mt3 \ If we need more pirates, loop back up to mt3, \ otherwise we are done spawning, so fall through into \ the end of the main loop at MLOOP