Prev: 36859 Up: Map Next: 37363
37018: UpdateCrewAI
Assigns a new action to the first idle crew member. Scans the 7-entry crew data table at 29566 (IX+0 = action counter). If a crew member's counter is non-zero they are busy; the first one with counter = 0 gets a new action sourced from the ROM-traversal script via 33589 (AdvanceScriptPtr) and 36763 (ScriptNibbleToDirection). The action sets IX+3 to one of: 1 = idle (action timer 80 frames) 2 = move (action timer 50 frames) 3 = wait (action timer 50 frames) 5 = investigate (action timer 60 frames) and IX+0 to the appropriate frame countdown.
Input
Used by the routine at 36457.
37018 PUSH IX save caller's IX
37020 LD IX,29566 IX = crew data base (first 7-entry crew table)
37024 XOR A A = 0
37025 CP (IX+0) is crew member 0's action counter zero (idle)?
37028 JR Z,37033 yes: assign new action at 45721
37030 POP IX crew member busy: restore IX
37032 RET return without change
37033 JP 45721 tail-call: assign action from script byte
This entry point is used by the routine at 45401.
37036 LD HL,65535
37039 LD (33695),HL
37042 LD DE,33695
37045 LD HL,29575
37048 LD BC,1793
37051 CP (HL)
37052 JR NZ,37058
37054 EX DE,HL
37055 LD (HL),C
37056 EX DE,HL
37057 INC DE
37058 INC C
37059 PUSH DE
37060 LD DE,8
37063 ADD HL,DE
37064 POP DE
37065 DJNZ 37051
37067 LD A,(33695)
37070 CP 255
37072 JR Z,37085
37074 LD (IX+0),60 timer = 60 frames
37078 LD (IX+3),5 action state = 5 (investigate)
37082 POP IX
37084 RET
37085 LD A,(IX+1) actor's current room
37088 AND 63
37090 LD E,A
37091 LD D,0
37093 LD HL,30076 RoomGrilleState[room]
37096 ADD HL,DE
37097 LD A,(HL)
37098 CP 255 grille still in place here?
37100 JR NZ,37122 no: consider moving out instead
37102 CALL 33589 AdvanceScriptPtr → A = next script nibble
37105 CALL 36763 ScriptNibbleToDirection → A ∈ [0..4]
37108 AND A direction 0?
37109 JR NZ,37151 no: branch to idle assignment
37111 LD (IX+0),50 timer = 50 frames
37115 LD (IX+3),3 action state = 3 (remove the grille)
37119 POP IX
37121 RET
37122 CALL 33589 AdvanceScriptPtr → A
37125 CALL 36763 ScriptNibbleToDirection
37128 CP 2 direction < 2?
37130 JR NC,37151 no: idle
This entry point is used by the routine at 45401.
37132 LD A,(IX+1)
37135 XOR 64
37137 LD (IX+2),A
37140 LD (IX+0),50 timer = 50 frames
37144 LD (IX+3),2 action state = 2 (move)
37148 POP IX
37150 RET
37151 CALL 36717
37154 LD (IX+0),80 timer = 80 frames
37158 LD (IX+3),1 action state = 1 (idle / wander)
37162 LD A,(IX+1)
37165 CP (IX+2)
37168 LD A,1
37170 CALL Z,38182
37173 POP IX
37175 RET
This entry point is used by the routines at 35578, 35973, 36859, 37490, 38379, 40439, 40826, 41264 and 45401.
37176 EX DE,HL
37177 LD HL,(33743)
37180 CP L
37181 JR NZ,37187
37183 LD A,E
37184 CP H
37185 RET Z
37186 LD A,L
37187 EX AF,AF'
37188 LD HL,(33741)
37191 LD A,(HL)
37192 CP 255
37194 RET Z
37195 EX AF,AF'
37196 LD (HL),A
37197 INC HL
37198 LD (HL),E
37199 INC HL
37200 LD (HL),D
37201 INC HL
37202 LD (33741),HL
37205 LD L,A
37206 LD H,E
37207 LD (33743),HL
37210 LD A,(33709)
37213 AND A
37214 RET Z
37215 LD A,1
37217 LD (33709),A
37220 RET
This entry point is used by the routine at 37363.
37221 LD HL,20704 HL = screen address for bottom status line
37224 LD (31257),HL
37227 LD DE,33892
37230 AND A
37231 JR Z,37242
37233 LD B,A
37234 LD A,(DE)
37235 INC DE
37236 CP 255
37238 JR NZ,37234
37240 DJNZ 37234
37242 LD A,(DE)
37243 CP 255
37245 JR Z,37310
37247 CP 254
37249 JR Z,37271
37251 CP 253
37253 JR Z,37276
37255 CP 252
37257 JR Z,37287
37259 PUSH DE
37260 CALL 31369
37263 POP DE
37264 INC DE
37265 LD HL,31257
37268 INC (HL)
37269 JR 37242
37271 LD A,(33712)
37274 JR 37279
37276 LD A,(33713)
37279 INC DE
37280 PUSH DE
37281 CALL 31690
37284 POP DE
37285 JR 37242
37287 INC DE
37288 PUSH DE
37289 LD A,(33712)
37292 LD HL,(31257)
37295 PUSH HL
37296 CALL 31634
37299 POP HL
37300 LD DE,10
37303 ADD HL,DE
37304 LD (31257),HL
37307 POP DE
37308 JR 37242
37310 LD HL,(31257)
37313 LD A,L
37314 AND 31
37316 OR 128
37318 LD (33708),A
37321 RET
This entry point is used by the routine at 45401.
37322 LD HL,20704
37325 LD (31257),HL
37328 LD B,32
37330 PUSH BC
37331 XOR A
37332 CALL 31370
37335 LD HL,31257
37338 INC (HL)
37339 POP BC
37340 DJNZ 37330
37342 LD HL,23264
37345 LD (HL),18
37347 LD (33710),HL
37350 INC HL
37351 LD B,31
37353 LD (HL),0
37355 INC HL
37356 DJNZ 37353
37358 LD HL,33709
37361 LD (HL),B
37362 RET
Prev: 36859 Up: Map Next: 37363