Prev: 53268 Up: Map Next: 53762
53303: Move Entity
Used by the routines at SettlePlayer, RunFrame and UpdateEntity.
Moves an entity for one frame, which is used for all of the types of entity that move. The entity is moved along its heading by the speed in fields 18-21 changed by its direction vector from GetDirectionVector, and the vertical speed in fields 18 and 19 is applied to the height. Purpose of the individual steps is not yet known.
Input
IX The entity
Return if the entity is not in use, and hand over to FollowPath if it is following a path.
MoveEntity 53303 LD A,(IX+0) Fetch the type of the entity.
53306 AND A Test it.
53307 RET Z Return if the entity is not in use.
53308 LD A,(IX+36) Fetch the first byte of the path of the entity.
53311 OR (IX+37) Combine it with the second byte.
53314 JP NZ,FollowPath Jump to FollowPath to follow the path if the entity has one.
Return if the sprite of the entity has not been set up, and note whether the entity is fast.
53317 LD A,(IX+22) Fetch the width of the sprite.
53320 AND %11110000 Use bits 4-7.
53322 RET NZ Return if any of them are set.
53323 LD A,(IX+23) Fetch the height of the sprite.
53326 AND %11000000 Use bits 6-7.
53328 RET NZ Return if any of them are set.
53329 LD A,(IX+16) Fetch the speed of the entity.
53332 SUB 80 Subtract 80.
53334 JR NC,MoveEntity_Fast Jump to MoveEntity_Fast if the speed is at least 80.
53336 RES 7,(IX+30) Clear bit 7 of the flags of the entity.
53340 JR MoveEntity_Position Jump to MoveEntity_Position.
MoveEntity_Fast 53342 SET 7,(IX+30) Set bit 7 of the flags of the entity.
Copy the position of the entity into the code that tests its collisions and the code at the end of this routine, which use it as the position that the entity started the frame at.
MoveEntity_Position 53346 LD H,(IX+2) Fetch the x coordinate of the entity.
53349 LD L,(IX+3)
53352 LD (54359),HL Store it in the collision code.
53355 LD H,(IX+5) Fetch the y coordinate of the entity.
53358 LD L,(IX+6)
53361 LD (54374),HL Store it in the collision code.
53364 LD H,(IX+8) Fetch the z coordinate of the entity.
53367 LD L,(IX+9)
53370 LD (53749),HL Store it in the instruction at 53748, as the height that the entity started the frame at.
Change the speed of the entity. If the entity is not moving then the speed falls, and if it is moving then the speed rises, one step at a time, to the maximum.
53373 BIT 7,(IX+17) Test bit 7 of the heading of the entity.
53377 LD A,(IX+26) Fetch the fraction of the speed.
53380 JR NZ,MoveEntity_Moving Jump to MoveEntity_Moving if the entity is moving.
53382 SUB (IX+27) Subtract the rate of change from the fraction.
53385 LD (IX+26),A Store the fraction.
53388 JP NC,MoveEntity_Speed Jump to MoveEntity_Speed if there was no step down.
53391 LD A,(IX+16) Fetch the speed of the entity and keep it in B.
53394 LD B,A
53395 AND %11110000 Keep the maximum speed in bits 4-7.
53397 LD E,A Keep it in E.
53398 LD A,B Fetch the speed again.
53399 AND %00001111 Keep the current speed in bits 0-3.
53401 SUB 1 Take one away.
53403 JR C,MoveEntity_ZeroSpeed Jump to MoveEntity_ZeroSpeed if the speed was zero already.
53405 OR E Add the maximum speed.
53406 LD (IX+16),A Store the new speed.
53409 JP MoveEntity_Speed Jump to MoveEntity_Speed.
MoveEntity_ZeroSpeed 53412 LD (IX+16),E Store the maximum speed as the speed, with the current speed zero.
53415 LD (IX+26),0 Set the fraction of the speed to 0.
53419 JP MoveEntity_Speed Jump to MoveEntity_Speed.
MoveEntity_Moving 53422 ADD A,(IX+27) Add the rate of change to the fraction.
53425 LD (IX+26),A Store the fraction.
53428 LD B,(IX+16) Fetch the speed of the entity.
53431 JR C,MoveEntity_StepUp Jump to MoveEntity_StepUp if there was a step up.
53433 LD A,B Fetch the speed again.
53434 RRCA Move the maximum speed down to bits 0-3.
53435 RRCA
53436 RRCA
53437 RRCA
53438 XOR B Compare it with the current speed.
53439 AND %00001111 Use bits 0-3.
53441 JR NZ,MoveEntity_Speed Jump to MoveEntity_Speed if the current speed has not reached the maximum.
53443 LD (IX+26),A Set the fraction of the speed to zero.
53446 JR MoveEntity_Speed Jump to MoveEntity_Speed.
MoveEntity_StepUp 53448 LD A,B Fetch the speed.
53449 AND %11110000 Keep the maximum speed in bits 4-7.
53451 LD E,A Keep it in E.
53452 RRCA Move the maximum speed down to bits 0-3...
53453 RRCA
53454 RRCA
53455 RRCA
53456 LD C,A ...and keep it in C.
53457 LD A,B Fetch the speed again.
53458 AND %00001111 Keep the current speed in bits 0-3.
53460 INC A Add one.
53461 CP C Compare it with the maximum speed.
53462 JR C,MoveEntity_StoreSpeed Jump to MoveEntity_StoreSpeed if it is below the maximum.
53464 LD A,C Limit it to the maximum.
MoveEntity_StoreSpeed 53465 OR E Add the maximum speed in bits 4-7.
53466 LD (IX+16),A Store the new speed.
Change the vertical speed of the entity by its acceleration, limit it, and move the entity up or down by it.
MoveEntity_Speed 53469 LD H,(IX+18) Fetch the vertical speed of the entity.
53472 LD L,(IX+19)
53475 LD D,(IX+20) Fetch the acceleration of the entity.
53478 LD E,(IX+21)
53481 LD A,H Combine the four bytes.
53482 OR L
53483 OR D
53484 OR E
53485 JP Z,MoveEntity_Heading Jump to MoveEntity_Heading if the entity is neither moving vertically nor accelerating.
53488 ADD HL,DE Add the acceleration to the vertical speed.
53489 BIT 7,H Jump to MoveEntity_Falling if the entity is moving down.
53491 JR NZ,MoveEntity_Falling
53493 LD A,(IX+28) Fetch the limit of the vertical speed from field 28.
53496 AND %00001111 Use bits 0-3.
53498 DEC A Take one away.
53499 CP H Compare it with the high byte of the vertical speed.
53500 JR NC,MoveEntity_Height Jump to MoveEntity_Height if the speed is within the limit.
53502 INC A Add one back.
53503 LD H,A Limit the vertical speed to the limit...
53504 LD L,0 ...with no fraction.
53506 JR MoveEntity_Height Jump to MoveEntity_Height.
MoveEntity_Falling 53508 LD A,(IX+28) Fetch the limit of the vertical speed from field 28.
53511 AND %00001111 Use bits 0-3.
53513 CPL Make it negative, for moving down.
53514 CP H Compare it with the high byte of the vertical speed.
53515 JR C,MoveEntity_Height Jump to MoveEntity_Height if the speed is within the limit.
53517 INC A Add one back.
53518 LD H,A Limit the vertical speed to the limit...
53519 LD L,0 ...with no fraction.
MoveEntity_Height 53521 LD (IX+18),H Store the vertical speed.
53524 LD (IX+19),L
53527 LD D,(IX+9) Fetch the z coordinate of the entity.
53530 LD E,(IX+10)
53533 LD C,(IX+8)
53536 CALL AddDisplacement Add the vertical speed to the z coordinate.
53539 LD (IX+9),H Store the new z coordinate.
53542 LD (IX+10),L
53545 LD (IX+8),C
Set the entity going in the direction that it is heading. If the heading has changed, centre the entity within its cell on each axis.
MoveEntity_Heading 53548 LD A,(IX+34) Fetch the heading that the entity had.
53551 AND %00111111 Use bits 0-5.
53553 LD B,A Keep it in B.
53554 LD A,(IX+17) Fetch the heading of the entity.
53557 AND %00111111 Use bits 0-5.
53559 CP B Compare it with the old heading.
53560 JR Z,MoveEntity_StoreHeading Jump to MoveEntity_StoreHeading if it has not changed.
53562 LD (IX+4),127 Set the fraction of the x coordinate to 127.
53566 LD (IX+7),127 Set the fraction of the y coordinate to 127.
MoveEntity_StoreHeading 53570 LD B,A Keep the heading in B.
53571 LD A,(IX+34) Fetch the old heading, with its flag.
53574 AND %01000000 Keep bit 6.
53576 OR B Combine it with the heading.
53577 LD (IX+34),A Store it as the heading that the entity has.
Work out the distance to move, from the speed, and the amount of it along each axis from the direction vector of the heading.
53580 LD H,(IX+16) Fetch the speed of the entity into H...
53583 LD L,(IX+26) ...and the fraction of the speed into L.
53586 ADD HL,HL Multiply the speed by sixteen.
53587 ADD HL,HL
53588 ADD HL,HL
53589 ADD HL,HL
53590 LD A,(IX+0) Fetch the type of the entity.
53593 DEC A Take one away.
53594 CALL Z,LimitDisplacement Limit the distance if the entity is the player.
53597 LD (23786),HL Store the distance.
53600 LD A,(IX+17) Fetch the heading of the entity.
53603 CALL GetDirectionVector Get the direction vector of the heading.
53606 PUSH BC Keep the first part of the vector.
53607 EXX Switch to the alternate registers.
53608 POP BC Take the first part of the vector off the stack.
53609 CALL ScaleDisplacement Work out the displacement along the x axis.
53612 LD A,(IX+0) Fetch the type of the entity.
53615 DEC A Take one away.
53616 JR NZ,MoveEntity_First Jump to MoveEntity_First unless the entity is the player.
53618 LD B,(IX+16) Fetch the speed of the player.
53621 LD A,(IX+30) Fetch the flags of the player, which hold the change of the drift.
53624 CALL UpdateDrift Change the drift, and limit the displacement.
MoveEntity_First 53627 LD D,(IX+3) Fetch the x coordinate of the entity.
53630 LD E,(IX+4)
53633 LD C,(IX+2)
53636 CALL AddDisplacement Add the displacement to the x coordinate.
53639 LD (IX+2),C Store the new x coordinate.
53642 LD (IX+4),L
53645 LD (IX+3),H
53648 EXX Switch to the alternate registers.
53649 PUSH HL Save the displacement along the y axis.
53650 EXX Switch to the alternate registers.
53651 POP BC Restore it into BC.
53652 CALL ScaleDisplacement Work out the displacement along the y axis.
53655 LD A,(IX+0) Fetch the type of the entity.
53658 DEC A Take one away.
53659 JR NZ,MoveEntity_Second Jump to MoveEntity_Second unless the entity is the player.
53661 LD B,(IX+16) Fetch the speed of the player.
53664 LD A,(IX+30) Fetch the flags of the player, which hold the change of the drift.
53667 RRA Shift the part that is for the y axis down to bits 0-2.
53668 RRA
53669 RRA
53670 INC IX Use the next field of the entity.
53672 CALL UpdateDrift Change the drift, and limit the displacement.
53675 DEC IX Use the first field of the entity again.
MoveEntity_Second 53677 LD D,(IX+6) Fetch the y coordinate of the entity.
53680 LD E,(IX+7)
53683 LD C,(IX+5)
53686 CALL AddDisplacement Add the displacement to the y coordinate.
53689 LD (IX+5),C Store the new y coordinate.
53692 LD (IX+7),L
53695 LD (IX+6),H
Note that the entity has moved, and check what it has collided with.
53698 LD A,(IX+30) Fetch the flags of the entity.
53701 AND %11000000 Use bits 6-7.
53703 OR %01000000 Set bit 6, to show that it has moved.
53705 LD (IX+30),A Store the flags.
53708 LD (IX+31),255 Set field 31 of the entity to 255.
53712 BIT 6,(IX+1) Test bit 6 of the frame of the entity.
53716 RET NZ Return if it is set.
53717 LD A,(IX+0) Fetch the type of the entity.
53720 CP 9 Jump to MoveEntity_TestCollisions unless it is a shot.
53722 JR NZ,MoveEntity_TestCollisions
53724 XOR A Set the vertical speed of the shot to zero.
53725 LD (IX+18),A
MoveEntity_TestCollisions 53728 CALL TestEntityCollisions Test the collisions of the entity.
53731 LD A,(IX+0) Fetch the type of the entity.
53734 AND A Test it.
53735 RET Z Return if the entity has been removed.
53736 CP 5 Compare the type with 5.
53738 LD A,255 Set the height to test to 255.
53740 JR Z,MoveEntity_TestCells Jump to MoveEntity_TestCells if the type is 5.
53742 LD H,(IX+8) Fetch the z coordinate of the entity.
53745 LD L,(IX+9)
53748 LD DE,0 Set DE to the height that the entity started at, which is patched in.
53751 SBC HL,DE Subtract it to find how far the entity has risen.
53753 DEC HL Take one away.
53754 LD A,L Keep the low byte.
MoveEntity_TestCells 53755 LD (55986),A Store it in the code that tests the cells.
53758 CALL TestEntityCells Test the cells that the entity is in.
53761 RET Return.
Prev: 53268 Up: Map Next: 53762