![]() |
Routines |
| Prev: DBE5 | Up: Map | Next: DD38 |
|
Used by the routine at RunHandlers.
|
||||
|
Just return if the number of active humans is already at the maximum amount for this level.
|
||||
| Handler_SpawnHumans | DCA1 | LD A,($D3F4) | Return if *NumberHumans is equal to *MaxHumansCount. | |
| DCA4 | LD B,A | |||
| DCA5 | LD A,($D211) | |||
| DCA8 | CP B | |||
| DCA9 | RET Z | |||
|
Add a hint of randomness to whether we proceed or not. Roughly 50% chance.
|
||||
| DCAA | CALL RandomNumber | B=random number. | ||
| DCAD | LD B,A | |||
| DCAE | LD A,($D210) | A=*HumanGeneratorLimiter (this appears to only ever be set to 80). | ||
| DCB1 | CP B | Return if A is lower than B. | ||
| DCB2 | RET C | |||
|
Creates a random number between 0000-02FD.
|
||||
| DCB3 | CALL RandomNumber | Call RandomNumber. | ||
| DCB6 | LD H,$00 | HL=random number between 0000-00FF. | ||
| DCB8 | LD L,A | |||
| DCB9 | CALL RandomNumber | Call RandomNumber. | ||
| DCBC | LD B,H | BC=random number between 0000-00FF. | ||
| DCBD | LD C,A | |||
| DCBE | CALL RandomNumber | Call RandomNumber. | ||
| DCC1 | LD D,H | DE=random number between 0000-00FF. | ||
| DCC2 | LD E,A | |||
| DCC3 | ADD HL,DE | Add them all together: HL=HL+DE+BC. | ||
| DCC4 | ADD HL,BC | |||
| DCC5 | LD B,H | BC=HL. | ||
| DCC6 | LD C,L | |||
|
Adding 65 to H gives an address range of anywhere between 6500-67FD.
|
||||
| DCC7 | LD A,$65 | H+=65. | ||
| DCC9 | ADD A,H | |||
| DCCA | LD H,A | |||
| DCCB | LD A,(HL) | Jump to FoundSolidMatter if *HL is not zero. | ||
| DCCC | AND A | |||
| DCCD | JR NZ,FoundSolidMatter | |||
|
The address in the buffer isn't compatible with containing a human, so have one more try...
|
||||
| DCCF | DEC H | Decrease H by three. | ||
| DCD0 | DEC H | |||
| DCD1 | DEC H | |||
|
Just give up here if we still haven't found a building to land on.
|
||||
| DCD2 | LD A,(HL) | Return if *HL is zero. | ||
| DCD3 | AND A | |||
| DCD4 | RET Z | |||
|
The routine has found "something" but we still need to check that it's compatible with containing a human.
|
||||
| FoundSolidMatter | DCD5 | AND %01000000 | Keep only bit 6. | |
| DCD7 | LD D,A | D=A. | ||
| DCD8 | LD A,(HL) | A=*HL. | ||
| DCD9 | CP $07 | Return if A is higher than 07. | ||
| DCDB | RET NC | |||
| DCDC | CP $03 | Return if A is lower than 03. | ||
| DCDE | RET C | |||
| DCDF | AND %00000001 | Keep only bit 0. | ||
| DCE1 | JR Z,Handler_SpawnHumans_0 | Jump to Handler_SpawnHumans_0 if the result is zero. | ||
| DCE3 | LD A,$07 | A=07. | ||
| DCE5 | OR D | Set the bits from D. | ||
| DCE6 | LD (HL),A | Write A to *HL. | ||
| DCE7 | INC L | Increment L by one. | ||
| DCE8 | LD A,$08 | A=08. | ||
| DCEA | OR D | Set the bits from D. | ||
| DCEB | LD (HL),A | Write A to *HL. | ||
| DCEC | DEC L | Decrease L by one. | ||
| DCED | JR Handler_SpawnHumans_1 | Jump to Handler_SpawnHumans_1. | ||
| Handler_SpawnHumans_0 | DCEF | LD A,$08 | A=08. | |
| DCF1 | OR D | Set the bits from D. | ||
| DCF2 | LD (HL),A | Write A to *HL. | ||
| DCF3 | DEC L | Decrease L by one. | ||
| DCF4 | LD A,$07 | A=07. | ||
| DCF6 | OR D | Set the bits from D. | ||
| DCF7 | LD (HL),A | Write A to *HL. | ||
| DCF8 | INC L | Increment L by one. | ||
| DCF9 | DEC C | Decrease C by one. | ||
| Handler_SpawnHumans_1 | DCFA | PUSH BC | Stash BC on the stack. | |
| DCFB | LD A,$68 | B+=68. | ||
| DCFD | ADD A,B | |||
| DCFE | LD B,A | |||
| DCFF | LD A,$FF | Write FF to *BC. | ||
| DD01 | LD (BC),A | |||
| DD02 | INC C | Increment C by one. | ||
| DD03 | LD (BC),A | Write A to *BC. | ||
| DD04 | EX DE,HL | Exchange the DE and HL registers. | ||
|
Register that a new human has been created.
|
||||
| DD05 | LD A,($D3F4) | Increment *NumberHumans by one. | ||
| DD08 | INC A | |||
| DD09 | LD ($D3F4),A | |||
|
Loop to find an empty slot.
|
||||
| DD0C | LD HL,$D251 | HL=MonsterSpriteModifier (Table_Humans-04). | ||
| Handler_Humans_FindSlot | DD0F | INC HL | Increment HL by four. | |
| DD10 | INC HL | |||
| DD11 | INC HL | |||
| DD12 | INC HL | |||
| DD13 | LD A,(HL) | Jump to Handler_Humans_FindSlot if *HL is not zero. | ||
| DD14 | AND A | |||
| DD15 | JR NZ,Handler_Humans_FindSlot | |||
|
Found an empty slot.
All humans start as type 01.
|
||||
| DD17 | LD (HL),$01 | Write human type 01 to *HL. | ||
|
Set a random countdown value.
|
||||
| DD19 | INC HL | Increment HL by one. | ||
| DD1A | CALL RandomNumber | Get a random number between 1F-3E. | ||
| DD1D | AND %00011111 | |||
| DD1F | ADD A,$1F | |||
| DD21 | LD (HL),A | Write A as the countdown to *HL. | ||
| DD22 | INC HL | Increment HL by one. | ||
| DD23 | POP BC | Restore BC from the stack. | ||
| DD24 | LD A,C | A=C. | ||
| DD25 | AND %00011111 | Keep only bits 0-4. | ||
| DD27 | LD (HL),A | Write A to *HL. | ||
| DD28 | INC HL | Increment HL by one. | ||
| DD29 | LD A,B | A=B. | ||
| DD2A | RLCA | Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2). | ||
| DD2B | RLCA | |||
| DD2C | RLCA | |||
| DD2D | LD B,A | Store the result in B. | ||
| DD2E | LD A,C | A=C. | ||
| DD2F | RLCA | Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2). | ||
| DD30 | RLCA | |||
| DD31 | RLCA | |||
| DD32 | AND %00000111 | Keep only bits 0-2. | ||
| DD34 | OR B | Set the bits from B. | ||
| DD35 | DEC A | Decrease A by one. | ||
| DD36 | LD (HL),A | Write A to *HL. | ||
| DD37 | RET | Return. | ||
| Prev: DBE5 | Up: Map | Next: DD38 |