Prev: 41261 Up: Map Next: 41485
41284: Move Spark
The handler for entity types 60 to 63, which are the shots that the robot fires using the first weapon. A shot moves across the map until it hits something or has run out of range. The shot destroys the contents of the cell that it hits, apart from the cells that are solid.
Input
IX Entity
MoveSpark 41284 CALL NextSpriteNumber Move on to the next sprite using NextSpriteNumber.
41287 CALL GetPosition Fetch the position of the shot.
41290 LD B,96 The shot can take up to 96 steps in this frame.
MoveSpark_Step 41292 CALL TryMove Take a step using TryMove.
41295 JR NZ,MoveSpark_Hit Jump if the shot has hit something.
41297 LD A,E Jump if the shot is not at the start of a cell.
41298 OR L
41299 JR NZ,MoveSpark_Store
41301 LD A,(IX+7) Fetch the range of the shot...
41304 SUB 16 ...take away one cell...
41306 LD (IX+7),A ...and store it.
41309 AND 240 Jump to explode the shot if it has run out of range.
41311 JR Z,MoveSpark_Explode
41313 LD A,B Loop back to take another step if there are steps left.
41314 AND A
41315 JR NZ,MoveSpark_Step
This entry point is used by the routine at MovePellet.
MoveSpark_Store 41317 CALL SetPosition Store the new position of the shot.
41320 CALL CheckShotHit Check whether it has hit an enemy using CheckShotHit.
41323 LD A,(IX+0) Fetch the type of the shot, and draw it using AddEntity unless it has become smoke.
41326 CP 56
41328 JP NZ,AddEntity
41331 LD A,(IY+8) Fetch the item that the enemy was carrying, and draw the shot if it was not carrying any.
41334 AND A
41335 JP Z,AddEntity
41338 LD C,A Keep the item.
41339 LD HL,(38446) Fetch the address of the cell that the shot was in.
41342 LD A,(HL) Fetch the contents of the cell.
41343 AND 240 Keep the initial type of the cell and use the item as the current type, so that the enemy drops it.
41345 OR C
41346 LD (HL),A Store the new contents of the cell.
41347 XOR A Clear the item that the enemy was carrying...
41348 LD (IY+8),A ...and store it.
41351 JP AddEntity Draw the shot using AddEntity.
MoveSpark_Explode 41354 LD (IX+0),56 Turn the shot into smoke by changing its type to 56.
41358 JR MoveSpark_Store Store the position.
The shot has hit something.
MoveSpark_Hit 41360 PUSH DE Save the X position.
41361 LD DE,16 Each entity is 16 bytes long.
41364 LD B,2 There are two entities that are used for puffs of smoke.
41366 LD IY,39088 Point IY at CloudEntities.
MoveSpark_FindPuff 41370 LD A,(IY+0) Fetch its type, and jump if it is not being used.
41373 AND A
41374 JR Z,MoveSpark_Unused
41376 ADD IY,DE Move on to the next one.
41378 DJNZ MoveSpark_FindPuff Loop back until both have been tried.
41380 POP DE Restore the X position.
41381 JR MoveSpark_Explode Make the shot explode without hitting the cell, as there is no puff to use.
MoveSpark_Unused 41383 POP DE Restore the X position.
41384 PUSH HL Save the Y position.
41385 LD HL,(38446) Fetch the address of the cell that was hit.
41388 LD A,(HL) Fetch its contents.
41389 AND 15 Keep the current type of the cell.
41391 CP 5 Jump to explode the shot if the type is 5.
41393 JR Z,MoveSpark_Restore
41395 CP 4 Jump to explode the shot if the type is 4.
41397 JR Z,MoveSpark_Restore
41399 CP 1 Jump to explode the shot if the type is 1.
41401 JR Z,MoveSpark_Restore
41403 CP 7 Jump to explode the shot if the type is 7.
41405 JR Z,MoveSpark_Restore
41407 CP 8 Jump to explode the shot if the type is 8.
41409 JR Z,MoveSpark_Restore
41411 CP 9 Jump to explode the shot if the type is 9.
41413 JR Z,MoveSpark_Restore
41415 CP 12 Jump to explode the shot if the type is 12.
41417 JR Z,MoveSpark_Restore
41419 CP 14 Jump to explode the shot if the type is 14.
41421 JR Z,MoveSpark_Restore
41423 LD A,(HL) Fetch the contents of the cell again...
41424 AND 240 ...and keep the initial type, so that the cell is emptied.
41426 JR MoveSpark_Destroy
MoveSpark_Replace 41428 LD (HL),A Store the new contents of the cell.
41429 LD (IY+0),84 Start a puff of smoke...
41433 LD HL,(38444) ...at the position of the cell.
41436 LD (IY+2),L Set the X cell of the puff...
41439 LD (IY+4),H ...and then its Y cell.
MoveSpark_Restore 41442 POP HL Restore the Y position.
41443 JR MoveSpark_Explode Make the shot explode.
MoveSpark_Destroy 41445 LD C,A Keep the initial type of the cell.
41446 LD A,(HL) Fetch the contents of the cell...
41447 AND 15 ...and keep its current type.
41449 CP 2 Jump to empty the cell if it is not type 2 (an installed program).
41451 LD A,C
41452 JR NZ,MoveSpark_Replace
41454 PUSH AF Save the contents...
41455 PUSH DE ...and the X position...
41456 PUSH HL ...and the Y position.
41457 CALL FindSector Find the sector that the cell is in using FindSector.
41460 LD E,D Use the sector number as an index.
41461 LD D,0
41463 LD HL,38491 Point HL at SectorFlags.
41466 ADD HL,DE Add the index.
41467 LD A,(HL) Fetch the flag, and jump if the sector has been activated (as its programs are safe).
41468 AND A
41469 JR NZ,MoveSpark_Safe
41471 CALL ReduceSectorEnergy Otherwise take one unit of energy off the sector using ReduceSectorEnergy.
41474 POP HL Restore the Y position...
41475 POP DE ...and the X position...
41476 POP AF ...and the contents.
41477 JR MoveSpark_Replace Jump back to empty the cell.
MoveSpark_Safe 41479 POP HL Restore the Y position...
41480 POP DE ...and the X position...
41481 POP AF ...and the contents.
41482 LD A,(HL) Fetch the contents of the cell, which are left as they are.
41483 JR MoveSpark_Replace Jump back to start the puff of smoke.
Prev: 41261 Up: Map Next: 41485