Prev: 42066 Up: Map Next: 42165
42110: Create Money Bag
Used by the routine at CreateTownObjects.
Creates a money bag (an object of type 24) in the seventh object slot when the player's bounty has dropped below $100. The bag appears close to the sheriff, in a free cell.
Return unless the bounty is below $100 and the slot is free.
CreateMoneyBag 42110 LD HL,41559 Return unless the first two bytes of the bounty are both zero, which means it is less than $100.
42113 LD A,(HL)
42114 INC HL
42115 OR (HL)
42116 RET NZ
42117 LD DE,41693 Point DE at ObjectSlot_07.
42120 LD A,(DE) Fetch the type of the object in the slot.
42121 AND A Return if the slot is already in use.
42122 RET NZ
Copy the template and place the bag near the sheriff.
42123 PUSH DE Copy DE to IY (using the stack).
42124 POP IY
42126 LD HL,42165 Point HL at MoneyBagTemplate.
42129 LD BC,16 Set the size of an object slot in BC.
42132 LDIR Copy the template into the slot.
42134 LD B,1 Set the distance from the sheriff to one cell.
42136 CALL PlaceNearSheriff Place the bag one cell away from the sheriff.
42139 RET NZ Return if that cell is blocked.
Choose a position inside the cell.
42140 LD A,(41496) Fetch a random number.
42143 AND %00110000 Keep bits 4 and 5.
42145 ADD A,128 Add 128 to give a position inside the cell.
42147 LD (IY+1),A Set the horizontal position of the bag within the cell.
42150 LD A,(41497) Fetch another random number.
42153 AND %00110000 Keep bits 4 and 5.
42155 ADD A,128 Add 128 to give a position inside the cell.
42157 LD (IY+3),A Set the vertical position of the bag within the cell.
42160 LD (IY+0),24 Turn the slot into a money bag.
42164 RET Return.
Prev: 42066 Up: Map Next: 42165