Prev: 54439 Up: Map Next: 54511
54476: Count Objects In Location
Counts how many objects are inside the current room.
Input
A Location ID (or 255 for current character location)
Output
A Count of visible objects found in the specified location
CountObjectsInLocation 54476 PUSH IX Save the character record, the schedule entry, the pointer and the count.
54478 PUSH IY
54480 PUSH HL
54481 PUSH BC
54482 CALL AdjustObjectTableForSum Call AdjustObjectTableForSum to set up the object table pointer.
54485 LD B,0 Initialise the object counter in B to zero.
54487 LD C,A Store the location ID in C for later use.
CountObjectsInLocation_Loop 54488 CALL FetchNextObject Go to CountObjectsInLocation_End if the next object id is 255.
54491 JR Z,CountObjectsInLocation_End
54493 LD A,C Take the count.
54494 CALL CheckObjectMatchCriteria Call CheckObjectMatchCriteria to check if this object matches the location and visibility criteria.
Skip this object if it does not match the location and visibility criteria.
54497 JR NC,CountObjectsInLocation_Loop Jump back to CountObjectsInLocation_Loop to continue checking objects if this one doesn't match.
This object matches the criteria, so count it.
54499 INC B Increment the object counter in B by one.
54500 JR CountObjectsInLocation_Loop Jump back to CountObjectsInLocation_Loop to check the next object.
Read the count.
CountObjectsInLocation_End 54502 LD A,B Transfer the object count from B to A.
54503 AND A Set the zero flag when the count is zero.
54504 POP BC Restore the saved count, the saved pointer, the saved schedule entry and the saved character record from the stack.
54505 POP HL
54506 POP IY
54508 POP IX
54510 RET Return.
View the equivalent code in;
Prev: 54439 Up: Map Next: 54511