Prev: B2FC Up: Map Next: B387
B32D: Door handling: interior
This is called from door_handling to handle doors when not outside.
Used by the routine at door_handling.
Input
IY Pointer to visible character.
door_handling_interior B32D LD HL,$81D6 Point HL at the interior_doors array
Loop through every door index in interior_doors.
Start loop
door_handling_interior_0 B330 LD A,(HL) Fetch a door index
B331 CP $FF Does it equal door_NONE? ($FF)
B333 RET Z If so, we've reached the end of the list - return
B334 EXX Switch register banks until the end of this iteration
B335 LD ($68A1),A Set the global current door to door index
B338 CALL get_door Turn the door_index into a door_t structure pointer in HL
B33B LD A,(HL) Fetch room_and_flags from the door_t and save in C for later
B33C LD C,A
Does the character face the same direction as the door?
B33D AND $03 Mask off the door's direction part (door_FLAGS_MASK_DIRECTION)
B33F LD B,A Stash it in B for a comparison in a moment
B340 LD A,(IY+$0E) Fetch IY's direction & crawl byte
B343 AND $03 Mask off the direction part (vischar_DIRECTION_MASK)
B345 CP B Do the door and vischar have the same direction?
B346 JR NZ,dhi_next Jump to the next iteration if not
Skip any door which is more than three units away.
B348 INC HL Advance HL to point at door's position
B349 EX DE,HL Move it into DE
TODO: Does this treat saved_pos as 8-bit quantities? (it's normally 16-bit)
B34A LD HL,$81A4 Point DE at saved_pos_x
B34D LD B,$02 Iterate twice: X,Y axis
Start loop
door_handling_interior_1 B34F LD A,(DE) Fetch door position x/y
B350 SUB $03 Subtract 3 to form lower bound (pos-3)
B352 CP (HL) Compare to saved_pos_x/y
B353 JR NC,dhi_next If lower bound >= saved_pos goto next
B355 ADD A,$06 Add 6 to form upper bound (pos+3)
B357 CP (HL) Compare to saved_pos_x/y
B358 JR C,dhi_next If upper bound < saved_pos goto next
B35A INC HL Step to the next saved_pos axis
B35B INC HL
B35C INC DE Step to the next door position axis
B35D DJNZ door_handling_interior_1 ...loop
B35F INC DE Skip position height byte
B360 EX DE,HL Move door position back into HL
B361 PUSH HL Preserve door position pointer
B362 PUSH BC Preserve iteration counter
B363 CALL is_door_locked Locate current door. Returns Z set if door is open
B366 POP BC Restore iteration counter
B367 POP HL Restore door position pointer
B368 RET NZ Return if Z clear => the door was locked
The door is in range and is unlocked - proceed with transition.
Set the vischar's room to the door's destination.
B369 LD A,C Retrieve the room_and_flags we saved earlier
B36A RRA Discard the direction bits so it's room index only
B36B RRA
B36C AND $3F
B36E LD (IY+$1C),A Store it in vischar->room
Get the destination position for transition.
If we're going through the door in the forward direction we fetch our destination position from the next element in the list. If we're reversed we fetch the previous element in the list.
B371 INC HL Point at the next door position
B372 LD A,($68A1) Fetch the global current door
B375 BIT 7,A Is door_REVERSE set?
B377 JR Z,door_handling_interior_2 Jump if so. HL is setup for transition call
B379 LD A,L Subtract 8 from HL
B37A SUB $08
B37C LD L,A
B37D JR NC,door_handling_interior_2
B37F DEC H
door_handling_interior_2 B380 JP transition Jump to transition -- never returns
dhi_next B383 EXX Unbank
B384 INC HL Advance to the next door in interior_doors[]
B385 JR door_handling_interior_0 ...loop
Prev: B2FC Up: Map Next: B387