Prev: 48998 Up: Map Next: 49166
49017: Handle Pickup And Drop
Used by the routine at HandlePlayerLegs.
Deals with the key for picking up and dropping objects. The key only does something once for each time that it is pressed, and only if the player is standing on the ground, away from the walls.
If the player is touching an object that can be carried, it is picked up. The player carries three objects at most, so if the carried objects are all in use the oldest one is dropped in its place. If the player is not touching anything, the object that is in the last place of the inventory (the oldest one) is dropped, if there is a free object record and nothing is in the way above the player. When that place is empty, the carried objects are only moved along one place towards it.
An object is dropped by creating it in a free object record, at the position of the player, who is moved up out of the way.
Input
IX Record of the object of the legs of the player
Do nothing if the key is still being held down from the last time.
HandlePickupAndDrop 49017 LD A,(42816) Fetch the flag from PickupDropPressedFlag.
49020 AND A Jump to CheckActionKeyReleased if the key was already being held down.
49021 JP NZ,CheckActionKeyReleased
The key was not being held, so find out if it is pressed, and if the player is able to pick things up or drop them.
49024 CALL TestPickupDropKey Return if the key is not being pressed.
49027 RET Z
49028 CALL TestPlayerInRoom Return if the player is touching a wall.
49031 RET NC
49032 BIT 3,(IX+12) Return if the player is jumping.
49036 RET NZ
49037 BIT 2,(IX+12) Return if the player is not on the ground.
49041 RET Z
49042 XOR A Clear the flag that says that there is no room to drop an object.
49043 LD (42817),A
49046 LD A,(IX+3) Stash the height of the player in B.
49049 LD B,A
49050 ADD A,12 Raise the player by 12.
49052 LD (IX+3),A
49055 CALL TestObjectIntersections Call TestObjectIntersections to find out if there is room for the player there.
49058 LD (IX+3),B Put the player back where it was.
49061 JR NC,HandlePickupAndDrop_Start Jump to HandlePickupAndDrop_Start if there is room.
49063 LD A,1 Set the flag that says that there is no room to drop an object.
49065 LD (42817),A
HandlePickupAndDrop_Start 49068 LD A,1 Set the flag that says that the key is being held down.
49070 LD (42816),A
49073 LD (42784),A Set the flag to redraw the inventory in ObjectsCarriedChangedFlag.
49076 LD B,48 Set a counter in B of the number of ordinary object records, which is 48.
Make the player larger by 4 along each axis, so that it can touch objects that are close.
49078 LD L,(IX+4) Make the half size along x larger by 4.
49081 LD A,L
49082 ADD A,4
49084 LD (IX+4),A
49087 LD H,(IX+5) Make the half size along y larger by 4.
49090 LD A,H
49091 ADD A,4
49093 LD (IX+5),A
49096 PUSH HL Stash the old half sizes along x and y on the stack.
49097 LD L,(IX+6) Make the size along z larger by 4.
49100 LD A,L
49101 ADD A,4
49103 LD (IX+6),A
49106 PUSH HL Stash the old size along z on the stack.
49107 LD IY,43055 Start with the first ordinary object record, ObjectsTable_RoomObjects.
Look for an object that can be picked up.
HandlePickupAndDrop_Search 49111 CALL TestObjectCanBePickedUp Call TestObjectCanBePickedUp to test if the object can be picked up and touches the player.
49114 JP C,PickUpObject Jump to PickUpObject to pick it up if it does.
49117 LD DE,32 Move on to the next object record.
49120 ADD IY,DE
49122 DJNZ HandlePickupAndDrop_Search Decrease the counter and loop until all the records have been tried.
Nothing can be picked up, so look for a free object record to drop an object in.
49124 CALL TestPickupDropKey Jump to HandlePickupAndDrop_Done if the key is no longer pressed.
49127 JR Z,HandlePickupAndDrop_Done
49129 LD DE,32 Set the size of an object record in DE.
49132 LD B,48 Set a counter in B of the number of ordinary object records.
49134 LD IY,43055 Start with the first ordinary object record.
HandlePickupAndDrop_FindFree 49138 LD A,(IY+0) Jump to DropObject to drop an object if this record is free.
49141 AND A
49142 JR Z,DropObject
49144 ADD IY,DE Advance to the next record and loop until all of them have been tried.
49146 DJNZ HandlePickupAndDrop_FindFree
This entry point is used by the routine at DropObject.
Put the size of the player back to what it was, and make a noise.
HandlePickupAndDrop_Done 49148 POP HL Restore the old size along z from the stack.
49149 LD (IX+6),L
49152 POP HL Restore the old half sizes along x and y from the stack.
49153 LD (IX+4),L Put the old half sizes back.
49156 LD (IX+5),H
49159 LD HL,261 Start a sound effect with a type of 1 and a count of 5.
49162 LD (42825),HL
49165 RET Return.
View the equivalent code in;
Prev: 48998 Up: Map Next: 49166