.TA3 \ If we get here then the ship either has plenty of \ energy, or levels are low but it couldn't manage to \ launch a missile, so maybe we can fire the laser? LDA #0 \ Set A to x_hi OR y_hi OR z_hi JSR MAS4 AND #%11100000 \ If any of the hi bytes have any of bits 5-7 set, then BNE TA4 \ jump to TA4 to skip the laser checks, as the ship is \ too far away from us to hit us with a laser LDX CNT \ Set X = the dot product set above in CNT. If this is \ positive, this ship and our ship are facing in similar \ directions, but if it's negative then we are facing \ each other, so for us to be in the enemy ship's line \ of fire, X needs to be negative. The value in X can \ have a maximum magnitude of 36, which would mean we \ were facing each other square on, so in the following \ code we check X like this: \ \ X = 0 to -31, we are not in the enemy ship's line \ of fire, so they can't shoot at us \ \ X = -32 to -34, we are in the enemy ship's line \ of fire, so they can shoot at us, but they can't \ hit us as we're not dead in their crosshairs \ \ X = -35 to -36, we are bang in the middle of the \ enemy ship's crosshairs, so they can not only \ shoot us, they can hit us CPX #160 \ If X < 160, i.e. X > -32, then we are not in the enemy BCC TA4 \ ship's line of fire, so jump to TA4 to skip the laser \ checks LDA INWK+31 \ Set bit 6 in byte #31 to denote that the ship is ORA #%01000000 \ firing its laser at us STA INWK+31 CPX #163 \ If X < 163, i.e. X > -35, then we are not in the enemy BCC TA4 \ ship's crosshairs, so jump to TA4 to skip the laser \ checks .HIT LDY #19 \ We are being hit by enemy laser fire, so fetch the LDA (XX0),Y \ enemy ship's byte #19 from their ship's blueprint \ into A LSR A \ Halve the enemy ship's byte #19 (which contains both \ the laser power and number of missiles) to get the \ amount of damage we should take JSR OOPS \ Call OOPS to take some damage, which could do anything \ from reducing the shields and energy, all the way to \ losing cargo or dying (if the latter, we don't come \ back from this subroutine) DEC INWK+28 \ Halve the attacking ship's acceleration in byte #28 \ --- Mod: Code removed for Demonstration Disc: -------> \LDA ECMA \ If an E.C.M. is currently active (either ours or an \BNE TA10 \ opponent's), return from the subroutine without making \ \ the laser-strike sound (as TA10 contains an RTS) \ --- And replaced by: --------------------------------> LDA ECMA \ If no E.C.M. is currently active, jump to tact2 BEQ tact2 RTS \ If we get here then an E.C.M. is currently active \ (either ours or an opponent's), so return from the \ subroutine without making the laser-strike sound .tact2 LDA XSAV \ Set attackingShip to the slot number of the ship that STA attackingShip \ is attacking us (i.e. the ship that we are currently \ applying tactics to, and which is firing at us) LDA targetShip \ If we already have a target, jump to tact3 to skip the BNE tact3 \ following LDA XSAV \ We don't currently have a target but a ship is firing STA targetShip \ on us, so set our target to the attacking ship LDA #&23 \ Call PressMissileKey to "press" the "T" button to arm JSR PressMissileKey \ a missile .tact3 \ --- End of replacement ------------------------------> LDA #8 \ Call the NOISE routine with A = 8 to make the sound JMP NOISE \ of us being hit by lasers, returning from the \ subroutine using a tail callName: TACTICS (Part 6 of 7) [Show more] Type: Subroutine Category: Tactics Summary: Apply tactics: Consider firing a laser at us, if aim is true Deep dive: Program flow of the tactics routineContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
This section looks at potentially firing the ship's laser at us. Specifically: * If the ship is not pointing at us, skip to the next part * If the ship is pointing at us but not accurately, fire its laser at us and skip to the next part * If we are in the ship's crosshairs, register some damage to our ship, slow down the attacking ship, make the noise of us being hit by laser fire, and we're done
[X]
Subroutine MAS4 (category: Maths (Geometry))
Calculate a cap on the maximum distance to a ship
[X]
Subroutine NOISE (category: Sound)
Make the sound whose number is in A
[X]
Subroutine OOPS (category: Flight)
Take some damage
[X]
Subroutine PressMissileKey (category: Demo)
"Press" a key by populating the key logger directly
[X]
Label TA4 in subroutine TACTICS (Part 7 of 7)
[X]
Temporary storage, used to store the address of a ship blueprint. For example, it is used when we add a new ship to the local bubble in routine NWSHP, and it contains the address of the current ship's blueprint as we loop through all the nearby ships in the main flight loop
[X]
Variable attackingShip in workspace WP
The slot number of the ship that is firing its lasers at us
[X]
Label tact2 is local to this routine
[X]
Label tact3 is local to this routine
[X]
Variable targetShip in workspace WP
Our target ship