Skip to navigation

Elite on the BBC Micro and NES

Flight: OUCH

[Elite-A, Parasite]

Name: OUCH [Show more] Type: Subroutine Category: Flight Summary: Potentially lose cargo or equipment following damage
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * OOPS calls OUCH

Our shields are dead and we are taking damage, so there is a small chance of losing cargo or equipment.
.OUCH JSR DORND \ Set A and X to random numbers BMI DK5 \ If A < 0 (50% chance), return from the subroutine \ (as DK5 contains an RTS) CPX #24 \ If X >= 24 (90% chance), return from the subroutine BCS DK5 \ (as DK5 contains an RTS) LDA CRGO,X \ If we do not have any of item CRGO+X, return from the BEQ DK5 \ subroutine (as DK5 contains an RTS). X is in the range \ 0-23, so this not only checks for cargo, but also for \ the I.F.F. system, E.C.M. system, fuel scoops, \ hyperspace unit, energy unit, docking computer and \ galactic hyperdrive, all of which can be destroyed LDA DLY \ If there is already an in-flight message on-screen, BNE DK5 \ return from the subroutine (as DK5 contains an RTS) LDY #3 \ Set bit 1 of de, the equipment destruction flag, so STY de \ that when we call MESS below, " DESTROYED" is appended \ to the in-flight message STA CRGO,X \ A is 0 (as we didn't branch with the BNE above), so \ this sets CRGO+X to 0, which destroys any cargo or \ equipment we have of that type DEX \ Decrement X, so X is now in the range -1 to 22, and a \ value of 0 means we just lost some food, 1 means we \ lost some textiles, and so on BMI ou1 \ If X is now negative, then we just lost the I.F.F. \ system (as X was 0 before being decremented), so jump \ to ou1 to print the relevant message, which will be \ "I.F.F.SYSTEM DESTROYED" as A = 0 and the C flag is \ clear (as we passed through the BCS above) CPX #17 \ If X = 17 then we just lost the E.C.M., so jump to ou1 BEQ ou1 \ to print the relevant message, which will be \ "E.C.M.SYSTEM DESTROYED" as A = 0 and the C flag is \ set from the CPX \ If we get here then X is in the range 0-16 or 18-22 TXA \ Copy the value of X into A BCC cargo_mtok \ If X < 17 then we just lost some cargo (as opposed to \ equipment), so jump to cargo_mtok to print the name of \ the cargo whose number is in A, plus " DESTROYED", and \ return from the subroutine using a tail call \ If we get here then X (and A) are in the range 18-22 CMP #18 \ If A is not 18, jump down to equip_mtok with A in the BNE equip_mtok \ range 19-22 and the C flag set from the CMP, to print \ token 113 ("HYPERSPACE UNIT") through 116 ("GALACTIC \ HYPERSPACE") LDA #111-107-1 \ Otherwise A is 18, so we have lost the fuel scoops, so \ set A to 111-107-1 = 3 and the C flag set from the CMP \ to print token 111 ("FUEL SCOOPS") .ou1 ADC #107-93 \ We can reach here with three values of A and the C \ flag, and then add 93 below to print the following \ tokens: \ \ A = 0, C flag clear = token 107 ("I.F.F.SYSTEM") \ A = 0, C flag set = token 108 ("E.C.M.SYSTEM") \ A = 3, C flag set = token 111 ("FUEL SCOOPS") .equip_mtok ADC #93 \ We can either reach here from above, or jump straight \ here with A = 19-22 and the C flag set, in which case \ adding 93 will give us token 113 ("HYPERSPACE UNIT") \ through 116 ("GALACTIC HYPERSPACE ") INC new_hold \ We just lost a piece of equipment, so increment the \ amount of free space in the hold BNE MESS \ Print recursive token A as an in-flight message, \ followed by " DESTROYED", and return from the \ subroutine using a tail call