Skip to navigation

Gameplay: ApplyTactics (Part 8 of 10)

Name: ApplyTactics (Part 8 of 10) [Show more] Type: Subroutine Category: Gameplay Summary: If the drain timer has run down, either drain the target's energy or jump to part 9 to create a meanie; or start the drain timer Deep dive: Enemy timers and state variables
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 part 9 \ 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 \ MoveOnToNextEnemy via 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 in part 10 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