Skip to navigation


Main loop: Main flight loop (Part 11 of 16)

[NES version, Bank 0]

Name: Main flight loop (Part 11 of 16) [Show more] Type: Subroutine Category: Main loop Summary: For each nearby ship: Process missile lock and firing our laser Deep dive: Program flow of the main game loop Flipping axes between space views
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

The main flight loop covers most of the flight-specific aspects of Elite. This section covers the following: * Continue looping through all the ships in the local bubble, and for each one: * If this is not the front space view, flip the axes of the ship's coordinates in INWK * Process missile lock * Process our laser firing
.MA26 LDA QQ11 ; If this is not a space view, jump to MA15 to skip BEQ P%+5 ; missile and laser locking JMP MA15 JSR PLUT ; Call PLUT to update the geometric axes in INWK to ; match the view (front, rear, left, right) LDA LAS ; If we are firing our laser then LAS will contain the BNE main37 ; laser power (which will be non-zero), so jump to ; main37 to check if the current ship is in the ; crosshairs, to see if we are hitting it LDA MSAR ; If the active missile is not looking for a target then BEQ main38 ; MSAR will be zero, so jump to main38 to skip the ; following, as we can't target lock an unarmed missile LDA MSTG ; If MSTG is positive (i.e. it does not have bit 7 set), BPL main38 ; then it indicates we already have a missile locked on ; a target (in which case MSTG contains the ship number ; of the target), so jump to main38 to skip targeting ; ; Or to put it another way, if MSTG = $FF, which means ; there is no current target lock, then keep going .main37 JSR HITCH ; Call HITCH to see if this ship is in the crosshairs, BCS main39 ; in which case the C flag will be set and we jump to ; main39 (so if there is no missile or laser lock, we ; jump to MA8 to skip the following) .main38 JMP MA8 ; Jump to MA8 to skip the following .main39 LDA MSAR ; We have missile lock, so check whether the leftmost BEQ MA47 ; missile is currently armed, and if not, jump to MA47 ; to process laser fire, as we can't lock an unarmed ; missile LDA MSTG ; If MSTG is positive (i.e. it does not have bit 7 set), BPL MA47 ; then it indicates we already have a missile locked on ; a target (in which case MSTG contains the ship number ; of the target), so jump to MA47 to skip setting the ; target and beeping JSR BEEP_b7 ; We have missile lock and an armed missile, so call ; the BEEP subroutine to make a short, high beep LDX XSAV ; Call ABORT2 to store the details of this missile LDY #109 ; lock, with the targeted ship's slot number in X JSR ABORT2 ; (which we stored in XSAV at the start of this ship's ; loop at MAL1), and set the colour of the missile ; indicator to the pattern number in Y (red ; indicator = pattern 109) .MA47 ; If we get here then the ship is in our sights, but ; we didn't lock a missile, so let's see if we're ; firing the laser LDA LAS ; If we are firing the laser then LAS will contain the BEQ MA8 ; laser power (which we set in MA68 above), so if this ; is zero, jump down to MA8 to skip the following LDX #15 ; We are firing our laser and the ship in INWK is in JSR EXNO ; the crosshairs, so call EXNO to make the sound of ; us making a laser strike on another ship LDA TYPE ; Did we just hit the space station? If so, jump to CMP #SST ; MA14+2 to make the station hostile, skipping the BEQ MA14+2 ; following as we can't destroy a space station CMP #SPL ; Did we just hit a splinter? If not jump to main40 to BNE main40 ; skip the following LDX LAS ; We just hit a splinter, so we now check whether we CPX #Mlas ; have a mining laser fitted (in which case the laser BEQ MA14+2 ; power in LAS will be Mlas), and if so, jump to MA14+2 ; to skip the following, so we can't destroy splinters ; with mining lasers (which is handy, as we probably ; want to scoop them up instead) .main40 CMP #CON ; If the ship we hit is less than #CON - i.e. it's not BCC BURN ; a Constrictor, Cougar, Dodo station or the Elite logo, ; jump to BURN to skip the following LDA LAS ; Set A to the power of the laser we just used to hit ; the ship (i.e. the laser in the current view) CMP #(Armlas AND 127) ; If the laser is not a military laser, jump to MA14+2 BNE MA14+2 ; to skip the following, as only military lasers have ; any effect on the Constrictor or Cougar (or the Elite ; logo, should you ever bump into one of those out there ; in the black...) LSR LAS ; Divide the laser power of the current view by 4, so LSR LAS ; the damage inflicted on the super-ship is a quarter of ; the damage our military lasers would inflict on a ; normal ship .BURN LDA INWK+35 ; Fetch the hit ship's energy from byte #35 and subtract SEC ; our current laser power, and if the result is greater SBC LAS ; than zero, the other ship has survived the hit, so BCS MA14 ; jump down to MA14 to make it angry ASL INWK+31 ; Set bit 7 of the ship byte #31 to indicate that it has SEC ; now been killed ROR INWK+31 JSR HideShip_b1 ; Update the ship so it is no longer shown on the ; scanner LDA LAS ; Are we using mining lasers? If not, jump to nosp to CMP #Mlas ; spawn canisters, otherwise keep going BNE nosp ; If we get here then we are using mining lasers LDA TYPE ; Did we just kill an asteroid? If so, jump to main41 CMP #AST ; to break the asteroid up into splinters BEQ main41 CMP #6 ; Did we just kill a boulder? If not jump to nosp to BNE nosp ; spawn canisters, otherwise keep going ; If we get here then we are using mining lasers and we ; just blasted a boulder JSR DORND ; Set A and X to random numbers BPL main43 ; If bit 7 of A is clear (50% chance), jump to main43 to ; skip spawning any splinters LDA #1 ; Otherwise set A = 1 so we spawn one splinter below BNE main42 ; Jump to main42 to spawn one splinter (this BNE is ; effectively a JMP as A is never zero) .main41 ; If we get here then we are using mining lasers and we ; just blasted an asteroid JSR DORND ; Set A and X to random numbers ORA #1 ; Reduce the random number in A to the range 1-3 AND #3 .main42 LDX #SPL ; Set X to the ship type for a splinter JSR SPIN2 ; Call SPIN2 to spawn A items of type X (so we spawn ; 1-3 splinters if we just destroyed an asteroid, or we ; spawn one splinter 50% of the time if we just ; destroyed a boulder) JMP main43 ; Jump to main43 to skip spawning canisters .nosp LDY #PLT ; Randomly spawn some alloy plates JSR SPIN LDY #OIL ; Randomly spawn some cargo canisters JSR SPIN .main43 LDX TYPE ; Set X to the type of the ship that was killed so the ; following call to EXNO2 can award us the correct ; number of fractional kill points JSR EXNO2 ; Call EXNO2 to process the fact that we have killed a ; ship (so increase the kill tally, make an explosion ; sound and so on) .MA14 STA INWK+35 ; Store the hit ship's updated energy in ship byte #35 LDA TYPE ; Call ANGRY to make this ship hostile, now that we JSR ANGRY ; have hit it