Prev: B1F5 Up: Map Next: B295
B252: Door in range?
This tests whether an exterior door is in range. A door is in range if (saved_X,saved_Y) is within -3..+2 of its position (once scaled).
Used by the routines at door_handling and get_nearest_door.
Input
HL Pointer to a door_t structure.
Output
F C set if no match.
door_in_range B252 INC HL Step over the room_and_direction field
Are we in range on the X axis?
B253 LD A,(HL) Fetch door's pos.x
B254 EX DE,HL Preserve the door position pointer
B255 CALL multiply_by_4 Multiply pos.x by 4 returning the result in BC
B258 LD A,C Subtract 3
B259 SUB $03
B25B LD C,A
B25C JR NC,door_in_range_0
B25E DEC B
door_in_range_0 B25F LD HL,($81A4) Get saved_pos_x
B262 SBC HL,BC Calculate saved_pos_x - (pos.x * 4 - 3)
B264 RET C Return if carry set (saved_pos_x is under)
B265 LD A,$06 Add 6, to make pos.x * 4 + 3
B267 ADD A,C
B268 LD C,A
B269 JR NC,door_in_range_1
B26B INC B
door_in_range_1 B26C LD HL,($81A4) Get saved_pos_x again
B26F SBC HL,BC Calculate saved_pos_x - (pos.x * 4 + 3)
B271 CCF Invert the carry flag
B272 RET C Return if carry set (saved_pos_x is over)
Are we in range on the Y axis?
B273 EX DE,HL Restore door position pointer
B274 INC HL Fetch door's pos.y
B275 LD A,(HL)
B276 CALL multiply_by_4 Multiply pos.y by 4 returning the result in BC
B279 EX DE,HL Preserve door position pointer
B27A LD A,C Subtract 3
B27B SUB $03
B27D LD C,A
B27E JR NC,door_in_range_2
B280 DEC B
door_in_range_2 B281 LD HL,($81A6) Get saved_pos_y
B284 SBC HL,BC Calculate saved_pos_y - (pos.y * 4 - 3)
B286 RET C Return if carry set (saved_pos_y is under)
B287 LD A,$06 Add 6, to make pos.y * 4 + 3
B289 ADD A,C
B28A LD C,A
B28B JR NC,door_in_range_3
B28D INC B
door_in_range_3 B28E LD HL,($81A6) Get saved_pos_y again
B291 SBC HL,BC Calculate saved_pos_y - (pos.y * 4 + 3)
B293 CCF Invert the carry flag
B294 RET Return with result of final test
Prev: B1F5 Up: Map Next: B295