Routines |
Prev: C891 | Up: Map | Next: C918 |
Drives automatic behaviour for NPCs and the hero when the player idles. Causes characters to follow the hero if he's being suspicious. Also: Food item discovery.
Used by the routine at main_loop.
|
||||
automatics | C892 | XOR A | Clear the 'character index is valid' flag | |
C893 | LD ($A13E),A | |||
Hostiles pursue if the bell is not ringing.
|
||||
C896 | LD A,($A130) | Read the bell ring counter/flag | ||
C899 | AND A | Is it bell_RING_PERPETUAL? | ||
C89A | CALL Z,hostiles_pursue | Call (hostiles pursue prisoners) if so | ||
If food was dropped then count down until it is discovered.
|
||||
C89D | LD HL,$C891 | Point HL at food_discovered_counter | ||
C8A0 | LD A,(HL) | Fetch the counter | ||
C8A1 | AND A | Is it zero? | ||
C8A2 | JR Z,auto_react | Jump if so (it already hit zero) | ||
C8A4 | DEC (HL) | Otherwise decrement it | ||
C8A5 | JR NZ,auto_react | Jump if it's not zero | ||
De-poison the food.
|
||||
C8A7 | LD HL,$76F9 | Point HL at item_structs[item_FOOD].item | ||
C8AA | RES 5,(HL) | Clear its itemstruct_ITEM_FLAG_POISONED flag | ||
C8AC | LD C,$07 | Set C to item_FOOD | ||
C8AE | CALL item_discovered | Cause item C to be discovered | ||
Make supporting characters react.
|
||||
auto_react | C8B1 | LD IY,$8020 | Point HL at the second visible character | |
C8B5 | LD B,$07 | Set B for seven iterations | ||
Start loop
|
||||
auto_react_loop | C8B7 | PUSH BC | Preserve the loop counter | |
C8B8 | LD A,(IY+$01) | Load vischar.flags | ||
C8BB | CP $FF | Is it an empty slot? | ||
C8BD | JP Z,auto_next | Jump if so | ||
C8C0 | LD A,(IY+$00) | Load vischar.character | ||
C8C3 | AND $1F | Mask with vischar_CHARACTER_MASK to get character index | ||
C8C5 | CP $14 | Is it a hostile character? (character_19_GUARD_DOG_4 or below) | ||
C8C7 | JP NC,auto_behaviour | Jump if not | ||
Characters 0..19.
|
||||
C8CA | PUSH AF | Preserve the character index | ||
C8CB | CALL is_item_discoverable | Is the item discoverable? | ||
C8CE | LD A,($A138) | Is red_flag set? | ||
C8D1 | AND A | |||
C8D2 | JR NZ,auto_follow | Jump if so | ||
C8D4 | LD A,($A139) | Is automatic_player_counter non-zero? | ||
C8D7 | AND A | |||
auto_follow | C8D8 | CALL NZ,guards_follow_suspicious_character | Call (guards follow suspicious character) if so | |
C8DB | POP AF | Restore character index | ||
Guard dogs 1..4 (characters 16..19).
|
||||
C8DC | CP $0F | Is this character a guard dog? | ||
C8DE | JP Z,auto_behaviour | Jump if not | ||
C8E1 | JP C,auto_behaviour | |||
Dog handling: Is the food nearby?
|
||||
C8E4 | PUSH IY | Copy global vischar pointer to HL | ||
C8E6 | POP HL | |||
C8E7 | INC L | Point HL at vischar.flags | ||
C8E8 | LD A,($76FA) | Fetch item_structs[item_FOOD].room | ||
C8EB | BIT 7,A | Test for itemstruct_ROOM_FLAG_NEARBY_7 | ||
C8ED | JR Z,auto_behaviour | Jump if clear | ||
C8EF | LD (HL),$03 | Set vischar.flags to vischar_PURSUIT_DOG_FOOD | ||
auto_behaviour | C8F1 | CALL character_behaviour | Call (character behaviour) | |
auto_next | C8F4 | POP BC | Restore the loop counter | |
C8F5 | LD DE,$0020 | Advance to the next vischar | ||
C8F8 | ADD IY,DE | |||
C8FA | DEC B | ...loop | ||
C8FB | JP NZ,auto_react_loop | |||
Inhibit hero automatic behaviour when the flag is red, or otherwise inhibited.
|
||||
C8FE | LD A,($A138) | Is red_flag set? | ||
C901 | AND A | |||
Bug: Pointless JP NZ (jumps to a RET where a RET NZ would suffice).
|
||||
C902 | JP NZ,auto_return | Jump (return) if so | ||
C905 | LD A,($A13A) | Is in_solitary set? | ||
C908 | AND A | |||
C909 | JR NZ,auto_run_cb | Jump if so | ||
C90B | LD A,($A139) | Is automatic_player_counter non-zero? | ||
C90E | AND A | |||
C90F | RET NZ | Return if so | ||
Otherwise run character behaviour
|
||||
auto_run_cb | C910 | LD IY,$8000 | Point IY at the hero's vischar | |
C914 | CALL character_behaviour | Run character behaviour | ||
auto_return | C917 | RET | Return |
Prev: C891 | Up: Map | Next: C918 |