![]() |
Routines |
| Prev: 980B | Up: Map | Next: 9918 |
|
Used by the routine at END_OF_TURN.
Walks CHARACTERS and runs each character's script until it has done something. Each instruction is an action the character tries, as if it had typed a sentence: the action code and its objects go into ACTION to INSTRUMENT exactly as the parser puts them for the player, and ACTOR_TRIES carries it out through the same ACTION_TABLE. So Thorin opens a door by the same code the player does.
A step that is refused moves on to the next, or to a fallback of its own, and the script goes on; a step that succeeds ends the character's turn. Six refusals in a row end it too. What a character does is printed only when the player can see it.
An order comes first. Whatever the player has told a character to do (see ORDERS) replaces its script's step for the turn, unless the step has bit 6 set, which makes it one that cannot be interrupted.
|
||||
| CHARACTERS_ACT | 980E | CALL NOTE_LIGHT | Note where the player is and whether it is dark there (NOTE_LIGHT) | |
| 9811 | LD IY,CHARACTERS | IY = the first character | ||
| CHARACTERS_ACT_0 | 9815 | XOR A | No steps refused yet | |
| 9816 | LD (STEPS_REFUSED),A | |||
| 9819 | LD A,(IY+$00) | $FF ends the table | ||
| 981C | CP $FF | |||
| 981E | JP Z,CHARACTERS_ACT_9 | |||
| 9821 | CP $00 | An empty slot | ||
| 9823 | JP Z,NEXT_CHARACTER | |||
| 9826 | LD (ACTING),A | The sentence is about this character: its number, its record, and its location in ACTOR_AT | ||
| 9829 | CALL LOCATION_OF | |||
| 982C | LD (ACTOR),IX | |||
| 9830 | LD (ACTOR_AT),A | |||
| 9833 | SUB A | Printing off | ||
| 9834 | LD (PRINTING_ON),A | |||
| 9837 | LD A,(IY+$00) | Can the player see it (IN_REACH_OF, the other way round)? | ||
| 983A | PUSH IY | |||
| 983C | LD IY,PLAYER | |||
| 9840 | CALL ACTOR_IN_REACH | |||
| 9843 | POP IY | |||
| 9845 | JR Z,CHARACTERS_ACT_1 | |||
| 9847 | LD A,(PLAYER_IN_DARK) | Then print what it does -- unless the player is in the dark (PLAYER_IN_DARK, set by NOTE_LIGHT): then the first one is only heard, "you hear a noise.", and nothing is printed | ||
| 984A | CP $02 | |||
| 984C | JR Z,CHARACTERS_ACT_1 | |||
| 984E | LD A,$01 | |||
| 9850 | LD (PRINTING_ON),A | |||
| 9853 | LD A,(PLAYER_IN_DARK) | |||
| 9856 | CP $01 | |||
| 9858 | JR NZ,CHARACTERS_ACT_1 | |||
| 985A | INC A | |||
| 985B | LD (PLAYER_IN_DARK),A | |||
| 985E | LD HL,MSG_YOU_HEAR_A_NOISE | |||
| 9861 | CALL RUN_MESSAGE_HL | |||
| 9864 | SUB A | |||
| 9865 | LD (PRINTING_ON),A | |||
| CHARACTERS_ACT_1 | 9868 | LD A,$FF | Held by something? Try to get out (CAPTIVE) | |
| 986A | CP (IX+$01) | |||
| 986D | JP NZ,CAPTIVE | |||
|
This entry point is used by the routine at CAPTIVE.
|
||||
| CHARACTER_FREE | 9870 | LD IX,(ACTOR) | ORDER_WAITING = 1 if it has an order waiting | |
| 9874 | CALL HAS_ORDER | |||
| 9877 | LD A,$00 | |||
| 9879 | JR NZ,CHARACTERS_ACT_2 | |||
| 987B | INC A | |||
| CHARACTERS_ACT_2 | 987C | LD (ORDER_WAITING),A | ||
|
This entry point is used by the routine at SCRIPT_BARE.
|
||||
| RUN_SCRIPT | 987F | LD L,(IY+$02) | HL = where its script has got to | |
| 9882 | LD H,(IY+$03) | |||
|
This entry point is used by the routine at SCRIPT_BARE.
|
||||
| SCRIPT_STEP | 9885 | LD A,(STEPS_REFUSED) | Six steps refused: its turn is over | |
| 9888 | CP $06 | |||
| 988A | JR Z,NEXT_CHARACTER | |||
| 988C | LD A,(HL) | IX = the instruction | ||
| 988D | LD DE,$0004 | |||
| 9890 | PUSH HL | |||
| 9891 | POP IX | |||
| 9893 | AND $0F | Opcodes 5 and up | ||
| 9895 | CP $05 | |||
| 9897 | JR NC,CHARACTERS_ACT_4 | |||
| 9899 | LD A,(ORDER_WAITING) | An order, and this step may be interrupted (bit 6 clear)? Take the order and carry it out, and that is its turn | ||
| 989C | CP $01 | |||
| 989E | JR NZ,CHARACTERS_ACT_3 | |||
| 98A0 | BIT 6,(HL) | |||
| 98A2 | JR NZ,CHARACTERS_ACT_3 | |||
| 98A4 | SUB A | |||
| 98A5 | LD (ORDER_WAITING),A | |||
| 98A8 | INC A | |||
| 98A9 | CALL TAKE_ORDER | |||
| 98AC | JR Z,CHARACTERS_ACT_3 | |||
| 98AE | LD A,$01 | |||
| 98B0 | LD (DOING_IT),A | |||
| 98B3 | LD (SUCCEEDED),A | |||
| 98B6 | LD HL,NEXT_CHARACTER | |||
| 98B9 | PUSH HL | |||
| 98BA | PUSH IX | |||
| 98BC | JP ACTOR_DOES | |||
| CHARACTERS_ACT_3 | 98BF | LD A,(HL) | Opcode 4: an action with no objects, or a jump; 0 to 3: an action with objects, or a routine | |
| 98C0 | AND $0F | |||
| 98C2 | CP $04 | |||
| 98C4 | JP Z,SCRIPT_BARE | |||
| 98C7 | JR C,SCRIPT_DO | |||
| 98C9 | JR NEXT_CHARACTER | |||
| CHARACTERS_ACT_4 | 98CB | CP $0E | $0E: go to the address that follows, and carry on | |
| 98CD | JR NZ,CHARACTERS_ACT_5 | |||
| 98CF | LD E,(IX+$01) | |||
| 98D2 | LD (IY+$02),E | |||
| 98D5 | LD E,(IX+$02) | |||
| 98D8 | LD (IY+$03),E | |||
| 98DB | JR RUN_SCRIPT | |||
| CHARACTERS_ACT_5 | 98DD | CP $0C | $0C: switch to the script its table keys under the byte that follows | |
| 98DF | JR NZ,CHARACTERS_ACT_6 | |||
| 98E1 | LD B,(IX+$01) | |||
| 98E4 | LD A,(IY+$00) | |||
| 98E7 | CALL REACT | |||
| 98EA | JR RUN_SCRIPT | |||
| CHARACTERS_ACT_6 | 98EC | CP $0F | $0F: switch to one of its scripts at random | |
| 98EE | JR NZ,CHARACTERS_ACT_7 | |||
| 98F0 | CALL SCRIPT_RANDOM | |||
| 98F3 | JR RUN_SCRIPT | |||
| CHARACTERS_ACT_7 | 98F5 | CP $00 | Never taken: A is at least 5 here | |
| 98F7 | JR NZ,CHARACTERS_ACT_8 | |||
| 98F9 | ADD HL,DE | |||
| 98FA | JR SCRIPT_STEP | |||
| CHARACTERS_ACT_8 | 98FC | SUB A | Anything else: back to its first script, and its turn is over | |
| 98FD | LD E,A | |||
| 98FE | CALL SCRIPT_PICK | |||
|
|
||||
| NEXT_CHARACTER | 9901 | LD DE,$0007 | On to the next 7-byte slot | |
| 9904 | ADD IY,DE | |||
| 9906 | JP CHARACTERS_ACT_0 | |||
| CHARACTERS_ACT_9 | 9909 | SUB A | Done: the sentence is about the player again, and printing on | |
| 990A | LD (ACTING),A | |||
| 990D | INC A | |||
| 990E | LD (PRINTING_ON),A | |||
| 9911 | LD HL,PLAYER | |||
| 9914 | LD (ACTOR),HL | |||
| 9917 | RET | |||
| Prev: 980B | Up: Map | Next: 9918 |