Prev: 43153 Up: Map Next: 43236
43172: Finish Robot Turn
The handler for entity types 32 to 47, which are the sprites that the robot has while it is turning. The turn is finished at once; the entity gets one of the types for walking (16 to 31) and the robot is checked for a collision with an enemy. If the robot has hit an enemy it loses some energy, and it is destroyed if it has none left. This routine then handles the entity again as its new type, without drawing it.
Input
IX Entity
FinishRobotTurn 43172 LD A,(38437) Fetch the controls...
43175 AND 252 ...clear the left and right bits...
43177 LD (38437),A ...and store them.
43180 LD B,(IX+6) Fetch the speed of the robot into B.
43183 LD C,0 Clear the low byte of the step count.
43185 LD A,(IX+0) Fetch the type of the robot...
43188 AND 143 ...change it into the matching type for walking...
43190 OR 16
43192 LD (IX+0),A ...and store it.
43195 LD A,(IX+0) Fetch the new type...
43198 EX AF,AF' ...and keep it in A'.
43199 CALL CheckShotHit Check whether the robot has hit an enemy using CheckShotHit.
43202 LD A,(IX+0) Fetch the type of the robot again.
43205 CP 56 Jump if it has not been turned into smoke.
43207 JR NZ,FinishRobotTurn_Discard
43209 LD A,(38490) Fetch the number of sectors that have been dealt with.
43212 ADD A,26 Add 26 to get the energy that the collision costs...
43214 LD B,A ...and keep it in B.
43215 LD A,(38459) Fetch the energy of the battery.
43218 SUB B Take off the cost.
43219 JR C,FinishRobotTurn_NoEnergy Jump if there is not enough energy.
43221 EX AF,AF' Otherwise get the type that the robot had...
43222 LD (IX+0),A ...and restore it, so that it is not destroyed...
43225 EX AF,AF' Switch back to the energy.
43226 JR FinishRobotTurn_Store ...and jump to store the energy.
FinishRobotTurn_NoEnergy 43228 XOR A The battery is empty.
FinishRobotTurn_Store 43229 LD (38459),A Store the energy of the battery.
FinishRobotTurn_Discard 43232 POP HL Discard the return address...
43233 JP MainLoop_Dispatch ...and handle the entity again as its new type using MainLoop_Dispatch.
Prev: 43153 Up: Map Next: 43236