Prev: A452 Up: Map Next: A4B5
A47E: Create Money Bag
Used by the routine at CreateTownObjects.
Creates a money bag (an object of type 18) 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 A47E LD HL,$A257 Return unless the first two bytes of the bounty are both zero, which means it is less than $100.
A481 LD A,(HL)
A482 INC HL
A483 OR (HL)
A484 RET NZ
A485 LD DE,$A2DD Point DE at ObjectSlot_07.
A488 LD A,(DE) Fetch the type of the object in the slot.
A489 AND A Return if the slot is already in use.
A48A RET NZ
Copy the template and place the bag near the sheriff.
A48B PUSH DE Copy DE to IY (using the stack).
A48C POP IY
A48E LD HL,$A4B5 Point HL at MoneyBagTemplate.
A491 LD BC,$0010 Set the size of an object slot in BC.
A494 LDIR Copy the template into the slot.
A496 LD B,$01 Set the distance from the sheriff to one cell.
A498 CALL PlaceNearSheriff Place the bag one cell away from the sheriff.
A49B RET NZ Return if that cell is blocked.
Choose a position inside the cell.
A49C LD A,($A218) Fetch a random number.
A49F AND %00110000 Keep bits 4 and 5.
A4A1 ADD A,$80 Add 80 to give a position inside the cell.
A4A3 LD (IY+$01),A Set the horizontal position of the bag within the cell.
A4A6 LD A,($A219) Fetch another random number.
A4A9 AND %00110000 Keep bits 4 and 5.
A4AB ADD A,$80 Add 80 to give a position inside the cell.
A4AD LD (IY+$03),A Set the vertical position of the bag within the cell.
A4B0 LD (IY+$00),$18 Turn the slot into a money bag.
A4B4 RET Return.
Prev: A452 Up: Map Next: A4B5