Routines |
Prev: CA49 | Up: Map | Next: CB23 |
This is called when a character reaches its target. It handles the various different pursuit modes that vischars can be in (getting caught, bribes, dogs being poisoned) and door transitions.
Used by the routine at character_behaviour.
|
||||||||||
target_reached | CA81 | LD A,(IY+$01) | Fetch the vischar.flags | |||||||
CA84 | LD C,A | Copy to C for the door check later | ||||||||
Check for a pursuit mode.
|
||||||||||
CA85 | AND $3F | Mask with vischar_FLAGS_MASK to get the pursuit mode | ||||||||
CA87 | JR Z,tr_door_check | Jump if not in a pursuit mode | ||||||||
We're in one of the pursuit modes - find out which one.
|
||||||||||
CA89 | CP $01 | Is it vischar_PURSUIT_PURSUE? | ||||||||
CA8B | JR NZ,tr_not_pursue | Jump if not | ||||||||
tr_pursue | CA8D | LD A,($AF8E) | Is this vischar the (pending) bribed character? | |||||||
CA90 | CP (IY+$00) | |||||||||
CA93 | JP Z,accept_bribe | Jump to accept_bribe if so (exit via) | ||||||||
CA96 | JP solitary | Otherwise the pursuing character caught its target. This must be the case when a guard pursues the hero, so send the hero to solitary (exit via) | ||||||||
tr_not_pursue | CA99 | CP $02 | Is it vischar_PURSUIT_HASSLE? | |||||||
CA9B | RET Z | Exit if so | ||||||||
CA9C | CP $04 | Is it vischar_PURSUIT_SAW_BRIBE? | ||||||||
CA9E | RET Z | Exit if so | ||||||||
Otherwise we're in vischar_PURSUIT_DOG_FOOD mode. automatics() only permits dogs to enter this mode.
Decide how long remains until the food is discovered. Use 32 if the food is poisoned, 255 otherwise.
|
||||||||||
CA9F | PUSH HL | Save the vischar pointer | ||||||||
CAA0 | LD HL,$76F9 | Point HL at item_structs_food | ||||||||
CAA3 | BIT 5,(HL) | Is the itemstruct_ITEM_FLAG_POISONED flag set? | ||||||||
CAA5 | LD A,$20 | Set the counter to 32 irrespectively | ||||||||
CAA7 | JR Z,tr_set_food_counter | Jump if the flag was set | ||||||||
CAA9 | LD A,$FF | Otherwise set the counter to 255 | ||||||||
tr_set_food_counter | CAAB | LD ($C891),A | Assign food_discovered_counter | |||||||
CAAE | POP HL | Restore the vischar pointer | ||||||||
CAAF | DEC L | Rewind HL to point at vischar.route.index | ||||||||
CAB0 | DEC L | |||||||||
This dog has been poisoned, so make it halt.
|
||||||||||
CAB1 | XOR A | vischar.route.index = routeindex_0_HALT | ||||||||
CAB2 | LD (HL),A | |||||||||
CAB3 | JP cb_set_input | Exit via character_behaviour_set_input (A is zero here: that's passed as the new input) | ||||||||
tr_door_check | CAB6 | BIT 6,C | Is the flag vischar_FLAGS_TARGET_IS_DOOR set? | |||||||
CAB8 | JR Z,tr_set_route | Jump if not | ||||||||
Handle the door - this results in the character entering.
|
||||||||||
CABA | DEC L | Rewind HL to point at vischar.route.step | ||||||||
CABB | LD C,(HL) | Fetch route.step | ||||||||
CABC | DEC L | Rewind | ||||||||
CABD | LD A,(HL) | Fetch route.index | ||||||||
CABE | PUSH HL | Preserve route pointer | ||||||||
CABF | CALL get_route | Call get_route. A is the index arg. A route *data* pointer is returned in DE | ||||||||
CAC2 | POP HL | Restore route pointer | ||||||||
CAC3 | LD A,E | Advance the route data pointer by 'step' bytes | ||||||||
CAC4 | ADD A,C | |||||||||
CAC5 | LD E,A | |||||||||
CAC6 | JR NC,tr_routebyte_is_door | |||||||||
CAC8 | INC D | |||||||||
tr_routebyte_is_door | CAC9 | LD A,(DE) | Fetch a route byte, which here is a door index | |||||||
CACA | BIT 7,(HL) | Is the route index's route_REVERSED flag set? ($80) | ||||||||
CACC | JR Z,tr_store_door | Jump if not | ||||||||
CACE | XOR $80 | Otherwise toggle the reverse flag | ||||||||
tr_store_door | CAD0 | PUSH AF | Preserve the door index | |||||||
CAD1 | LD A,(HL) | Fetch route.index | ||||||||
CAD2 | INC L | Advance to route.step | ||||||||
Pattern: [-2]+1
|
||||||||||
CAD3 | BIT 7,A | If the route is reversed then step backwards, otherwise step forwards | ||||||||
CAD5 | JR Z,tr_route_step | |||||||||
CAD7 | DEC (HL) | |||||||||
CAD8 | DEC (HL) | |||||||||
tr_route_step | CAD9 | INC (HL) | ||||||||
Get the door structure for the door index and start processing it.
|
||||||||||
CADA | POP AF | Restore door index | ||||||||
CADB | CALL get_door | Call get_door. A door_t pointer is returned in HL | ||||||||
CADE | LD A,(HL) | Fetch door.room_and_direction | ||||||||
CADF | RRA | Discard the bottom two bits | ||||||||
CAE0 | RRA | |||||||||
CAE1 | AND $3F | Extract the room index | ||||||||
CAE3 | LD (IY+$1C),A | Move the vischar to that room (vischar.room = room index) | ||||||||
In which direction is the door facing?
|
||||||||||
CAE6 | LD A,(HL) | Fetch door.room_and_direction | ||||||||
CAE7 | AND $03 | Mask against door_FLAGS_MASK_DIRECTION | ||||||||
Each door in the doors array is a pair of two "half doors" where each half represents one side of the doorway. We test the direction of the half door we find ourselves pointing at and use it to find the counterpart door's position.
|
||||||||||
CAE9 | CP $02 | Is it direction_TOP_*? | ||||||||
CAEB | JP NC,tr_door_top | Jump if not | ||||||||
CAEE | INC HL | Point HL at door[1].pos | ||||||||
CAEF | INC HL | |||||||||
CAF0 | INC HL | |||||||||
CAF1 | INC HL | |||||||||
CAF2 | INC HL | |||||||||
CAF3 | JR tr_door_found | |||||||||
tr_door_top | CAF5 | DEC HL | Otherwise point HL at door[-1].pos | |||||||
CAF6 | DEC HL | |||||||||
CAF7 | DEC HL | |||||||||
tr_door_found | CAF8 | PUSH HL | Preserve the door.pos pointer | |||||||
CAF9 | PUSH IY | Copy the current visible character pointer into HL | ||||||||
CAFB | POP HL | |||||||||
CAFC | LD A,L | Is this vischar the hero? | ||||||||
CAFD | AND A | |||||||||
CAFE | JP NZ,tr_transition | Jump if not | ||||||||
Hero's vischar only.
|
||||||||||
CB01 | INC L | Advance HL to point at vischar.flags | ||||||||
CB02 | RES 6,(HL) | Clear vischar.flags vischar_FLAGS_TARGET_IS_DOOR flag | ||||||||
CB04 | INC L | Advance HL to point at vischar.route | ||||||||
CB05 | CALL get_target_assign_pos | Call get_target_assign_pos | ||||||||
tr_transition | CB08 | POP HL | Restore the door.pos pointer | |||||||
CB09 | CALL transition | Call transition | ||||||||
CB0C | LD BC,$2030 | Play the "character enters 1" sound | ||||||||
CB0F | CALL play_speaker | |||||||||
CB12 | RET | Return | ||||||||
tr_set_route | CB13 | DEC L | Point HL at vischar.route.index | |||||||
CB14 | DEC L | |||||||||
CB15 | LD A,(HL) | Load the route.index | ||||||||
CB16 | CP $FF | Is it routeindex_255_WANDER? | ||||||||
CB18 | JR Z,get_target_assign_pos | Jump if so | ||||||||
CB1A | INC L | Advance HL to vischar.route.step | ||||||||
Pattern: [-2]+1
|
||||||||||
CB1B | BIT 7,A | If the route is reversed then step backwards, otherwise step forwards | ||||||||
CB1D | JR Z,tr_another_route_step | |||||||||
CB1F | DEC (HL) | |||||||||
CB20 | DEC (HL) | |||||||||
tr_another_route_step | CB21 | INC (HL) | ||||||||
CB22 | DEC L | Rewind HL to vischar.route.index | ||||||||
FALL THROUGH to get_target_assign_pos.
|
Prev: CA49 | Up: Map | Next: CB23 |