Skip to navigation

Gameplay: ApplyTactics (Part 7 of 8)

Name: ApplyTactics (Part 7 of 8) [Show more] Type: Subroutine Category: Gameplay Summary: Drain energy from the enemy's target object, or try scanning for a tree to turn into a meanie if the target's tile is obscured
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.tact19 \ If we get here then there is a suitable target for the \ enemy to drain, and the target's object number is in Y TYA \ Store the target number in enemyTarget in the enemy's STA enemyTarget,X \ data, so it is set as the enemy's target going forward LDA targetVisibility \ Store the target's visibility in enemyVisibility for STA enemyVisibility,X \ this enemy LDA enemyDrainTimer,X \ If enemyDrainTimer for this enemy is non-zero then it CMP #1 \ is either counting down or has counted down, so jump BCS tact21 \ to tact21 to process this \ If we get here then enemyDrainTimer is zero, so we \ restart the timer from 120 LDA #120 \ Set enemyDrainTimer for this enemy to 120 so the enemy STA enemyDrainTimer,X \ doesn't drain energy for another 120 timer ticks \ (120 * 0.06 = 7.2 seconds) .tact20 JMP MoveOnToNextEnemy \ Jump to MoveOnToNextEnemy to stop applying tactics to \ this enemy and set things up so we move on to the next \ enemy in the next iteration of the gameplay loop .tact21 BNE tact20 \ We jump knowing that the enemyDrainTimer for the enemy \ is 1 or greater, so this jumps to tact20 to move on to \ the next enemy when enemyDrainTimer is greater than 1 \ and is still counting down \ If we get here then enemyDrainTimer for the enemy has \ counted down to 1, so we need to process that LDA targetVisibility \ If bit 7 of targetVisibility is clear then the enemy BPL tact22 \ can't see the tile containing the enemy's target (but \ we know it can see the enemy object as otherwise we \ wouldn't have reached this point), so jump to tact22 \ to consider turning a tree into a meanie \ If we get here then the enemy can see the tile \ containing the target, so it can drain its target of \ energy JSR DrainObjectEnergy \ Drain energy from the target object into the enemy, \ transforming it into an object with an energy level \ of one unit less (if applicable) \ \ This updates enemyEnergy with the drained energy, so \ it can be expended back onto the landscape later on \ \ It also sets X to the object number of the target that \ has been drained of energy (and which has therefore \ been transformed into a different object type) LDY enemyObject \ Set enemyTacticTimer for the enemy to 30 so we wait LDA #30 \ for 30 * 0.06 = 1.8 seconds before applying tactics STA enemyTacticTimer,Y \ to the enemy again BCS tact27 \ If DrainObjectEnergy set the C flag then the enemy \ just drained the player object, so jump to tact27 to \ stop applying tactics to this enemy and set things up \ so we move on to the next enemy in the next iteration \ of the gameplay loop JMP tact25 \ Otherwise it wasn't the player object being drained, \ so jump to tact25 with X set to the number of the \ object that was drained so we update it on-screen with \ a dithered effect (as it has now been transformed into \ a different type of object) and return from the \ subroutine using a tail call .tact22 \ If we get here then the enemy can't see the tile \ containing the enemy's target, but it can see the \ target object, so now we consider turning a tree into \ a meanie JSR ScanForMeanieTree \ Scan through the objects in the landscape to see if \ any of them are trees that are suitable for turning \ into a meanie to attack the target LDY enemyObject \ Set Y to the object number of the enemy to which we \ are applying tactics (so this is now object #Y) BCC tact24 \ If the call to ScanForMeanieTree cleared the C flag \ then we have successfully turned a tree into a meanie, \ so jump to tact24 to set up the enemy's tactics timer \ and redraw the transformed tree on-screen LDA enemyFailCounter,Y \ If enemyFailCounter for this enemy is two or more then CMP #2 \ the enemy has failed to find a suitable tree to turn BCS tact23 \ into a meanie on more than one occasion, so jump to \ tact23 to have a fairly long pause before applying \ tactics to this enemy again LDA #%10000000 \ Otherwise set bit 7 of enemyDrainScan so the next time STA enemyDrainScan,Y \ we apply tactics to the enemy it will immediately scan \ for an object to drain BNE tact27 \ Jump to tact27 to stop applying tactics to this enemy \ and set things up so we move on to the next enemy in \ the next iteration of the gameplay loop (this BNE is \ effectively a JMP as A is always non-zero) .tact23 LDA #0 \ Set enemyDrainTimer = 0 to restart the drain counter STA enemyDrainTimer,Y \ for the enemy in part 5 of ApplyTactics, so it doesn't \ drain energy for another 120 timer ticks (120 * 0.06 = \ 7.2 seconds) BEQ tact27 \ Jump to tact27 to stop applying tactics to this enemy \ and set things up so we move on to the next enemy in \ the next iteration of the gameplay loop (this BEQ is \ effectively a JMP as A is always zero) .tact24 \ If we get here then we have just turned a tree into a \ meanie and the enemy number is in Y LDA #50 \ Set enemyTacticTimer for the enemy to 50 so we wait STA enemyTacticTimer,Y \ for 50 * 0.06 = 3.0 seconds before applying tactics to \ the enemy again LDX enemyMeanieTree,Y \ Set X to the object number of the tree that we just \ turned into a meanie, and fall through into part 8 to \ redraw the transformed object on the screen with a \ dithered effect