Skip to navigation

Gameplay: ScanForMeanieTree

Name: ScanForMeanieTree [Show more] Type: Subroutine Category: Gameplay Summary: Scan through the objects in the landscape to see if any of them are trees that are suitable for turning into a meanie
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyTactics (Part 7 of 8) calls ScanForMeanieTree

Returns: C flag The result of the tree scan: * Clear = we have successfully turned a tree into a meanie * Set = we have not been able to find a suitable tree to turn into a meanie
.ScanForMeanieTree LDA #40 \ Set enemyViewingArc = 40, so the enemy's gaze has a STA enemyViewingArc \ viewing arc that's twice the width of the screen (as \ the screen is 20 yaw angles across) LDX enemyObject \ Set the viewing object to the enemy so the gaze checks STX viewingObject \ below are performed from the point of view of the \ enemy object .mean1 LDX enemyObject \ Set X to the object number of the enemy to which we \ are applying tactics (so this is now object #X) LDY enemyMeanieScan,X \ Set Y to the object number that we have reached while \ scanning for a tree to turn into a meanie, which is \ stored in the enemyMeanieScan for this enemy BNE mean2 \ If enemyMeanieScan is non-zero then we have not yet \ scanned every object for a tree to turn into a meanie, \ so jump to mean2 to check the next object INC enemyFailCounter,X \ We just failed to find a suitable tree to attack the \ target, so increment the failure counter for the enemy \ in enemyFailCounter LDA enemyTarget,X \ We just failed to find a suitable tree to attack the STA enemyFailTarget,X \ target, so store the target number in enemyFailTarget \ for this enemy to record this fact, so the enemy \ doesn't try spawning a meanie for this target again \ (at least, until the enemy's data is reset) SEC \ Set the C flag to indicate that we have not been able \ to find a suitable tree to turn into a meanie RTS \ Return from the subroutine .mean2 DEC enemyMeanieScan,X \ Decrement the object number that we are checking for \ meanie potential, so we work our way down the object \ list DEY \ We already set Y to the object number before jumping \ here, so decrement Y as well, so object #Y is our \ potential meanie LDA objectFlags,Y \ If bit 7 of the object flags for the potential meanie BMI mean1 \ is set then the object number doesn't have an \ associated object, so jump to mean1 to move on to the \ next object to check that instead LDA objectTypes,Y \ If the potential meanie is not a tree (an object of CMP #2 \ type 2) then it can't be turned into a meanie, so jump BNE mean1 \ to mean1 to move on to the next object to check that \ instead LDA enemyTarget,X \ Set X to the enemy's current target object, so object TAX \ #X is the target object LDA xObject,X \ Set A to the difference in x-coordinate between object SEC \ #X and object #Y (i.e. between the target and SBC xObject,Y \ potential meanie) BPL mean3 \ If the result is positive, jump to mean3 as the result \ is already the correct sign EOR #&FF \ Negate A using two's complement, so that A is now CLC \ positive and contains the absolute value of the ADC #1 \ distance in the x-axis between the target and \ potential meanie .mean3 CMP #10 \ If the target and potential meanie are ten or more BCS mean1 \ tiles apart then this is too far away from the target \ to be turned into a meanie, so jump to mean1 to move \ on to the next object to check that instead LDA zObject,X \ Set A to the difference in z-coordinate between object SEC \ #X and object #Y (i.e. between the target and SBC zObject,Y \ potential meanie) BPL mean4 \ If the result is positive, jump to mean4 as the result \ is already the correct sign EOR #&FF \ Negate A using two's complement, so that A is now CLC \ positive and contains the absolute value of the ADC #1 \ distance in the z-axis between the target and \ potential meanie .mean4 CMP #10 \ If the target and potential meanie are ten or more BCS mean1 \ tiles apart then this is too far away from the target \ to be turned into a meanie, so jump to mean1 to move \ on to the next object to check that instead LDA #2 \ Call CheckEnemyGaze to check the gaze of the enemy JSR CheckEnemyGaze \ towards the potential meanie in object #Y, returning \ the following if object #Y is a tree (an object of \ type 2), which we have already confirmed: \ \ * targetVisibility = bit 7 set if the tree's tile \ is visible, bit 6 set if the tree is visible LDA targetVisibility \ If bit 7 of targetVisibility is clear then the enemy BPL mean1 \ can't see the tree's tile, so it can't turn it into \ a meanie, so jump to mean1 to move on to the next \ object to check that instead LDX enemyObject \ Set X to the object number of the enemy to which we \ are applying tactics (so this is now object #X) TYA \ Set A to the object number of the potential meanie JSR CheckObjVisibility \ Check whether the potential meanie in object A is \ visible and could therefore be seen on-screen by the \ player BCC mean5 \ If the C flag is clear then we are about to repeat the \ same screen pan (as the player is still holding down \ the same pan key) and the potential meanie would be \ visible in the landscape view if we drew it again \ \ This means that when we pan the screen, the new part \ of the screen that pans into view might show part of \ the meanie while the rest of the screen won't, and \ that won't look good \ \ So jump to mean5 to stop processing this potential \ meanie for now, but set things up so we can come back \ to it the next time we process tactics for this enemy, \ as the player might not be panning the screen by then \ If we get here then we have found a suitable tree to \ turn into a meanie, so let's do that TYA \ Set enemyMeanieTree for this enemy to Y, as object #Y STA enemyMeanieTree,X \ is the object number of the tree that we are going to \ turn into a meanie, and storing it in enemyMeanieTree \ records the fact that the enemy has changed this \ object from a tree into a meanie LDA #4 \ Set the type of object #Y to 4, so it turns into a STA objectTypes,Y \ meanie (an object of type 4) LDA #104 \ Set minObjWidth = 104 so we use the width of the wider STA minObjWidth \ object, the tree, when we calculate the object's \ visibility when updating the object on-screen CLC \ Clear the C flag to indicate that we have successfully \ turned a tree into a meanie RTS \ Return from the subroutine .mean5 INC enemyMeanieScan,X \ If we get here then we have found a suitable tree to \ turn into a meanie but updating it on-screen might \ corrupt the landscape view as a pan is in progress \ \ So increment the object number in enemyMeanieScan, so \ the next time we apply tactics to this enemy, we can \ pick up where we left off, by which time the player \ might no longer be panning the screen JMP FinishEnemyTactics \ Jump to FinishEnemyTactics to stop applying tactics to \ the current enemy and return to the ProcessGameplay \ routine to continue with the gameplay loop