.FindObjectToDrain LDX #63 \ Set a counter in X to work through the object numbers \ until we find a suitable tree or boulder that can be \ seen by the viewing object \ \ Note that we only call this routine with the viewing \ object set to the enemy that we are processing in the \ ApplyTactics routine, so I'll refer to the viewing \ object as the enemy in the following to make it \ easier to follow .dran1 LDA objectFlags,X \ Set A to the object flags for object #X, which are \ stored in the X-th entry in the objectFlags table BMI dran4 \ If bit 7 of object flags for object #X is set then \ this object number is not yet allocated to an object, \ so jump to dran4 to move on to the next object number CMP #%01000000 \ If bit 6 of the object flags for object #X is set BCS dran2 \ then object #X is stacked on top of another object, \ so jump to dran2 to keep checking as this is a \ potential target LDA objectTypes,X \ If object #X is not a boulder (an object of type 3) CMP #3 \ then jump to dran4 to move on to the next object BNE dran4 \ number .dran2 \ If we get here then object #X is either a boulder or \ it is an object that is stacked on top of another \ object LDA xObject,X \ Set (xTile, zTile) to the tile coordinates of the STA xTile \ tile containing object #X LDA zObject,X STA zTile JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile), setting the C flag if the tile \ contains an object BCC dran4 \ If the C flag is clear then this tile does not already \ have an object placed on it, so jump to dran4 to move \ on to the next object number AND #%00111111 \ Because the tile has an object on it, the tile data TAY \ contains the number of the top object on the tile in \ bits 0 to 5, so extract the object number into Y (so \ object #Y is either directly on the tile or is on the \ top of the stack, so in either case it is the exposed \ object in terms of potential targets) LDA objectTypes,Y \ Set A to the type of object that's exposed on the tile \ (i.e. the type of object #Y) CMP #2 \ If the exposed object is a tree (an object of type 2), BEQ dran3 \ jump to dran3 to keep checking as this is a potential \ target CMP #3 \ If the exposed object is a boulder (an object of BNE dran4 \ type 3), jump to dran4 to move on to the next object \ number .dran3 \ If we get here then object #Y is either a boulder or \ it is a tree that is stacked on top of another object, \ and it is exposed as a potential target, so now we \ check whether the enemy can see the object's tile (and \ therefore whether it can be drained of energy by the \ enemy) JSR CheckEnemyGaze \ Call CheckEnemyGaze to check the gaze of the enemy \ towards object #Y, returning the following if the \ the object matches the object type in A: \ \ * targetVisibility = bit 7 set if the object's tile \ is visible, bit 6 set if the object is visible LDA targetVisibility \ If bit 7 of targetVisibility is clear then the enemy BPL dran4 \ can't see the exposed object's tile, so jump to dran4 \ to move on to the next object number \ If we get here then object #Y's tile can be seen by \ the enemy, so it is a suitable target for draining STY targetObject \ Set targetObject to the object number in Y CLC \ Clear the C flag to indicate that the enemy can see a \ drainable tree or boulder RTS \ Return from the subroutine .dran4 DEX \ Decrement the counter in X to move on to the next \ object number BPL dran1 \ Loop back to dran1 to check the next object number SEC \ If we get here then we have checked all 64 object \ numbers and none of them are suitable targets for the \ enemy to drain, so set the C flag to indicate this RTS \ Return from the subroutineName: FindObjectToDrain [Show more] Type: Subroutine Category: Gameplay Summary: Find a suitable target object for an enemy to drainContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyTactics (Part 4 of 8) calls FindObjectToDrain * ApplyTactics (Part 5 of 8) calls FindObjectToDrain
Arguments: viewingObject The viewing object (i.e. the enemy doing the scanning)
Returns: C flag Status flag: * Clear if we have found an object that is a suitable target for the enemy to drain (i.e. a tree that is stacked on top of another object, or a boulder, which is exposed to the enemy and on a tile that can be seen by the enemy) * Set if no objects of them are suitable targets for the enemy to drain targetObject The number of the target object (if the C flag is set)
[X]
Subroutine CheckEnemyGaze (Part 1 of 2) (category: Gameplay)
Check to see whether the current enemy can see a specific target object of a specific type
[X]
Subroutine GetTileData (category: Landscape)
Get the tile data and tile data address for a specific tile
[X]
Label dran1 is local to this routine
[X]
Label dran2 is local to this routine
[X]
Label dran3 is local to this routine
[X]
Label dran4 is local to this routine
[X]
Variable objectFlags in workspace Stack variables
Object flags for up to 64 objects
[X]
Variable objectTypes (category: 3D objects)
The object types table for up to 64 objects
[X]
Variable targetObject in workspace Main variable workspace
The number of the object that is being targeted in the DrainObjectEnergy routine
[X]
Variable targetVisibility in workspace Zero page
Reports whether a target object is visible from an enemy in the CheckEnemyGaze routine
[X]
Variable xObject (category: 3D objects)
The x-coordinates in 3D space for the 3D objects
[X]
Variable zObject (category: 3D objects)
The z-coordinates in 3D space for the 3D objects