Prev: C7B9 Up: Map Next: C891
C7C6: Character event
This is called when a route has ended. It makes characters wander around, sit, sleep, etc.
Used by the routines at move_a_character and route_ended.
Input
HL Points to character_struct.route or vischar.route.
character_event C7C6 LD A,(HL) Load route.index
C7C7 CP $07 Is it less than routeindex 7?
C7C9 JR C,character_event_0 Jump if so
C7CB CP $0D Is it less than routeindex 13?
C7CD JP C,character_sleeps Call 'character sleeps' if so (if indices 7..12)
character_event_0 C7D0 CP $12 Is it less than routeindex_18?
C7D2 JR C,character_event_1 Jump if so
Bug: The sixth prisoner doesn't sit for breakfast because this should be $18.
C7D4 CP $17 Is it less than routeindex 23?
C7D6 JP C,character_sits Call 'character sits' if so (if indices 18..22)
character_event_1 C7D9 PUSH HL Stack the route pointer - the event handlers will pop
Locate the character in the character_to_event_handler_index_map.
C7DA LD HL,$C7F9 Point HL at character_to_event_handler_index_map[0]
C7DD LD B,$18 Set B for 24 iterations - length of the map
Start loop
character_event_2 C7DF CP (HL) Does the route index in A match the map's route index?
C7E0 JR Z,ce_call_action Jump if so
C7E2 INC HL Advance to the next map entry
C7E3 INC HL
C7E4 DJNZ character_event_2 ...loop
C7E6 POP HL Unstack the route pointer
C7E7 LD (HL),$00 Make the character stand still by setting the new route index to routeindex_0_HALT
C7E9 RET Return
ce_call_action C7EA INC HL Read the index of the handler from the map
C7EB LD A,(HL)
C7EC ADD A,A Double it
C7ED LD C,A Copy it to BC
C7EE LD B,$00
C7F0 LD HL,$C829 Point HL at character_event_handlers[index]
C7F3 ADD HL,BC
C7F4 LD A,(HL) Load the event handler address into HL
C7F5 INC HL
C7F6 LD H,(HL)
C7F7 LD L,A
C7F8 JP (HL) Jump to the event handler
character_to_event_handler_index_map
Array of (character + flags, character event handler index) mappings.
character_to_event_handler_index_map C7F9 DEFW $00A6 routeindex_38_GUARD_12_BED | REVERSE, 0 - wander between locations 8..15
C7FB DEFW $00A7 routeindex_39_GUARD_13_BED | REVERSE, 0 - wander between locations 8..15
C7FD DEFW $01A8 routeindex_40_GUARD_14_BED | REVERSE, 1 - wander between locations 16..23
C7FF DEFW $01A9 routeindex_41_GUARD_15_BED | REVERSE, 1 - wander between locations 16..23
C801 DEFW $0005 routeindex_5_EXIT_HUT2, 0 - wander between locations 8..15
C803 DEFW $0106 routeindex_6_EXIT_HUT3, 1 - wander between locations 16..23
C805 DEFW $0385 routeindex_5_EXIT_HUT2 | REVERSE, 3 -
C807 DEFW $0386 routeindex_6_EXIT_HUT3 | REVERSE, 3 -
C809 DEFW $020E routeindex_14_GO_TO_YARD, 2 - wander between locations 56..63
C80B DEFW $020F routeindex_15_GO_TO_YARD, 2 - wander between locations 56..63
C80D DEFW $008E routeindex_14_GO_TO_YARD | REVERSE, 0 - wander between locations 8..15
C80F DEFW $018F routeindex_15_GO_TO_YARD | REVERSE, 1 - wander between locations 16..23
C811 DEFW $0510 routeindex_16_BREAKFAST_25, 5 -
C813 DEFW $0511 routeindex_17_BREAKFAST_23, 5 -
C815 DEFW $0090 routeindex_16_BREAKFAST_25 | REVERSE, 0 - wander between locations 8..15
C817 DEFW $0191 routeindex_17_BREAKFAST_23 | REVERSE, 1 - wander between locations 16..23
C819 DEFW $00A0 routeindex_32_GUARD_15_ROLL_CALL | REVERSE, 0 - wander between locations 8..15
C81B DEFW $01A1 routeindex_33_PRISONER_4_ROLL_CALL | REVERSE, 1 - wander between locations 16..23
C81D DEFW $072A routeindex_42_HUT2_LEFT_TO_RIGHT, 7 -
C81F DEFW $082C routeindex_44_HUT2_RIGHT_TO_LEFT, 8 - hero sleeps
C821 DEFW $092B routeindex_43_7833, 9 - hero sits
C823 DEFW $06A4 routeindex_36_GO_TO_SOLITARY | REVERSE, 6 -
C825 DEFW $0A24 routeindex_36_GO_TO_SOLITARY, 10 - hero released from solitary
C827 DEFW $0425 routeindex_37_HERO_LEAVE_SOLITARY, 4 - solitary ends
character_event_handlers
Array of pointers to character event handlers.
character_event_handlers C829 DEFW charevnt_wander_top
C82B DEFW charevnt_wander_left
C82D DEFW charevnt_wander_yard
C82F DEFW charevnt_bed
C831 DEFW charevnt_solitary_ends
C833 DEFW charevnt_breakfast
C835 DEFW charevnt_commandant_to_yard
C837 DEFW charevnt_exit_hut2
C839 DEFW charevnt_hero_sleeps
C83B DEFW charevnt_hero_sits
C83D DEFW charevnt_hero_release
charevnt_solitary_end
charevnt_solitary_ends C83F XOR A in_solitary = 0; // enable player control
C840 LD ($A13A),A
C843 JR charevnt_wander_top goto charevnt_wander_top;
charevnt_commandant_to_yard
charevnt_commandant_to_yard C845 POP HL // (popped) sampled HL=$80C2 (x2),$8042 // route
C846 LD (HL),$03 *HL++ = 0x03;
C848 INC HL
C849 LD (HL),$15 *HL = 0x15;
C84B RET Return
charevnt_hero_release
charevnt_hero_release C84C POP HL
C84D LD (HL),$A4 *HL++ = 0xA4;
C84F INC HL
C850 LD (HL),$03 *HL = 0x03;
C852 XOR A automatic_player_counter = 0; // force automatic control
C853 LD ($A139),A
C856 LD BC,$2500 set_hero_route(0x0025); return;
C859 JP set_hero_route_force
charevnt_wander_left
charevnt_wander_left C85C LD C,$10 C = 0x10; // 0xFF10
C85E JR character_event_3 goto exit;
charevnt_wander_yard
charevnt_wander_yard C860 LD C,$38 C = 0x38; // 0xFF38
C862 JR character_event_3 goto exit;
charevnt_wander_top
charevnt_wander_top C864 LD C,$08 C = 0x08; // 0xFF08 // sampled HL=$8022,$8042,$8002,$8062
character_event_3 C866 POP HL exit:
C867 LD (HL),$FF *HL++ = 0xFF;
C869 INC HL
C86A LD (HL),C *HL = C;
C86B RET Return
charevnt_bed
charevnt_bed C86C POP HL
C86D LD A,($A13E) if (entered_move_a_character == 0) goto character_bed_vischar; else goto character_bed_state;
C870 AND A
C871 JP Z,character_bed_vischar
C874 JP character_bed_state
charevnt_breakfast
charevnt_breakfast C877 POP HL
C878 LD A,($A13E) if (entered_move_a_character == 0) goto charevnt_breakfast_vischar; else goto charevnt_breakfast_state;
C87B AND A
C87C JP Z,charevnt_breakfast_vischar
C87F JP charevnt_breakfast_state
charevnt_exit_hut2
charevnt_exit_hut2 C882 POP HL
C883 LD (HL),$05 *HL++ = 0x05;
C885 INC HL
C886 LD (HL),$00 *HL = 0x00;
C888 RET Return
charevnt_hero_sits
charevnt_hero_sits C889 POP HL
C88A JP hero_sits goto hero_sits;
charevnt_hero_sleeps
charevnt_hero_sleeps C88D POP HL
C88E JP hero_sleeps goto hero_sleeps;
Prev: C7B9 Up: Map Next: C891