Prev: C4E0 Up: Map Next: C651
C5D3: Reset visible character
This resets a visible character (vischar). It could be a person or a stove/crate object.
Input
HL Pointer to visible character.
reset_visible_character C5D3 LD A,(HL) Fetch the vischar's character index
C5D4 CP $FF Is it character_NONE? ($FF)
C5D6 RET Z Return if so
C5D7 CP $1A Is it a stove/crate character? (character_26_STOVE_1+)
C5D9 JR C,rvc_humans Jump if not
C5DB EX AF,AF' Bank
It's a stove or crate character.
C5DC LD (HL),$FF Set vischar.character to $FF (character_NONE)
C5DE INC L Advance HL to vischar.flags
C5DF LD (HL),$FF Reset flags to $FF (vischar_FLAGS_EMPTY_SLOT)
C5E1 LD A,$06 Point HL at counter_and_flags
C5E3 ADD A,L
C5E4 LD L,A
C5E5 LD (HL),$00 Set counter_and_flags to zero
C5E7 ADD A,$08 Point HL at vischar.mi.pos
C5E9 LD L,A
C5EA EX AF,AF' Unbank
Save the old position.
C5EB LD DE,$69AE Point DE at movable_items[0] / stove 1
C5EE CP $1A Is A character_26_STOVE_1?
C5F0 JR Z,rvc_copy_mi Jump if so
C5F2 LD DE,$69C0 Point DE at movable_items[2] / stove 2
C5F5 CP $1B Is A character_27_STOVE_2?
C5F7 JR Z,rvc_copy_mi Jump if so
C5F9 LD DE,$69B7 Otherwise point DE at movable_items[1] / crate
Note: The DOS version of the game has a difference here. Instead of copying the current vischar's position into the movable_items's position, it only copies the first two bytes. The code is setup for a copy of six bytes (cx is set to 3) but the 'movsw' ought to be a 'rep movsw' for it to work. It fixes the bug where stoves get left in place after a restarted game, but almost looks like an accident.
rvc_copy_mi C5FC LD BC,$0006 Copy six bytes to the movable_items entry
C5FF LDIR
C601 RET Return
A non-object character.
rvc_humans C602 EX DE,HL Bank vischar pointer
C603 CALL get_character_struct Get character struct for A, result in HL
C606 RES 6,(HL) Clear flag characterstruct_FLAG_ON_SCREEN
C608 LD A,$1C Point DE at vischar.room
C60A ADD A,E
C60B LD E,A
C60C LD A,(DE) Fetch vischar.room
C60D INC HL Copy it to charstr.room
C60E LD (HL),A
C60F EX AF,AF' Bank room index
C610 EX DE,HL Unbank vischar pointer
C611 LD A,L Point HL at vischar.counter_and_flags
C612 SUB $15
C614 LD L,A
C615 LD (HL),$00 Clear vischar.counter_and_flags
C617 ADD A,$08 Point HL at vischar.mi.pos
C619 LD L,A
Save the old position.
C61A INC DE Point DE at charstr.pos.x
C61B EX AF,AF' Unbank room index
C61C AND A Are we outdoors?
C61D JR NZ,rvc_indoors Jump if not
Outdoors.
C61F CALL pos_to_tinypos Scale down vischar.mi.pos to charstr.pos
C622 JR rvc_reset_common (else)
Indoors.
rvc_indoors C624 LD B,$03 Set B for three iterations
Start loop
rvc_indoors_loop C626 LD A,(HL) Copy coordinate
C627 LD (DE),A
C628 INC L Advance the source pointer
C629 INC L
C62A INC DE
C62B DJNZ rvc_indoors_loop ...loop
rvc_reset_common C62D LD A,L Reset HL to point to the original vischar
C62E SUB $15
C630 LD L,A
C631 LD A,(HL) Fetch character index
C632 LD (HL),$FF Set vischar.character to $FF (character_NONE)
C634 INC L Advance HL to vischar.flags
C635 LD (HL),$FF Reset flags to $FF (vischar_FLAGS_EMPTY_SLOT)
C637 INC L Advance HL to vischar.route
Guard dogs only.
C638 CP $10 Is this a guard dog character? character_16_GUARD_DOG_1..character_19_GUARD_DOG_4
C63A JR C,rvc_end
C63C CP $14
C63E JR NC,rvc_end
Choose random locations in the fenced off area (right side).
rvc_dogs C640 LD (HL),$FF Set route to (routeindex_255_WANDER,0) ($FF,$00) -- wander from locations 0..7
C642 INC L
C643 LD (HL),$00
C645 CP $12 Is this character_18_GUARD_DOG_3 or character_19_GUARD_DOG_4?
C647 JR C,rvc_dogs_done Jump if not
Choose random locations in the fenced off area (bottom side).
C649 LD (HL),$18 Set route.step to $18 -- wander from locations 24..31
rvc_dogs_done C64B DEC L Point HL at vischar.route
rvc_end C64C LDI Copy route into charstr
C64E LDI
C650 RET Return
Prev: C4E0 Up: Map Next: C651