Skip to navigation

Gameplay: ApplyEnemyTactics

Name: ApplyEnemyTactics [Show more] Type: Subroutine Category: Gameplay Summary: Apply tactics to an enemy object, setting things up so the next call applies tactics to the next enemy object
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessGameplay calls ApplyEnemyTactics

Arguments: enemyObject The object number of the enemy to which we apply tactics (0 to 7)
.ApplyEnemyTactics TSX \ Store the stack pointer in gameplayStack, so we can STX gameplayStack \ return back to the ProcessGameplay routine from deep \ within the tactics routines if required LDX enemyObject \ Set X to the object number of the enemy to which we \ are thinking of applying tactics in this iteration of \ the gameplay loop (so object #X is the object that we \ are considering) LDA objectTypes,X \ Set A to the type of object #X CMP #1 \ If we are considering applying tactics to a sentry (an BEQ etac1 \ object of type 1) then jump to etac1 to apply tactics CMP #5 \ If we are not applying tactics to the Sentinel (an BNE MoveOnToNextEnemy \ object of type 5), then enemyObject is neither a \ sentry nor the Sentinel \ \ We only apply tactics to the Sentinel and sentries, \ so we don't need to apply tactics to this object \ \ So 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 .etac1 STA titleObjectToDraw \ If we get here then we are applying tactics to the \ Sentinel or a sentry, so set titleObjectToDraw to the \ corresponding object type so if the enemy causes the \ player to lose, then the game over screen will show \ that enemy type to indicate that it was responsible \ for the player's demise LDA objectFlags,X \ Set A to the object flags for object #X (which is the \ object that we are applying tactics to) BPL ApplyTactics \ If bit 7 of the object flags is clear then this object \ number is allocated to a valid object, so jump to \ ApplyTactics to apply tactics to the object and return \ from the subroutine using a tail call \ If we get here then bit 7 of the enemy object's flags \ is clear, so the enemy has been removed from the \ landscape at some point JSR ExpendEnemyEnergy \ Drain one unit of energy from the enemy and expend it \ onto the landscape by spawning a tree, if possible \ \ This ensures that if an enemy has absorbed energy from \ somewhere, it always dissipates back into the \ landscape it when it gets the chance \ \ If we can't spawn a tree because we are about to pan \ the screen and the tree would spawn in a position that \ would be visible on-screen, then the routine does not \ expend energy or spawn a tree, and instead it gives up \ and aborts applying tactics for this gameplay loop \ \ If we successfully spawned a tree then the object \ number of the tree is in X BCS MoveOnToNextEnemy \ If the call to ExpendEnemyEnergy returned with the C \ flag set, then either the enemy didn't have any energy \ to expend or we couldn't spawn a tree, so 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 JMP tact25 \ Otherwise jump to tact25 with X set to the object \ number of the tree to update it on-screen with a \ dithered effect and return from the subroutine using \ a tail call