Prev: 56293 Up: Map Next: 56632
56481: Handler: Spawn Humans
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 56481 LD A,(54260) Return if *NumberHumans is equal to *MaxHumansCount.
56484 LD B,A
56485 LD A,(53777)
56488 CP B
56489 RET Z
Add a hint of randomness to whether we proceed or not. Roughly 50% chance.
56490 CALL RandomNumber B=random number.
56493 LD B,A
56494 LD A,(53776) A=*HumanGeneratorLimiter (this appears to only ever be set to 128).
56497 CP B Return if A is lower than B.
56498 RET C
Creates a random number between 0000-765.
56499 CALL RandomNumber Call RandomNumber.
56502 LD H,0 HL=random number between 0000-0255.
56504 LD L,A
56505 CALL RandomNumber Call RandomNumber.
56508 LD B,H BC=random number between 0000-0255.
56509 LD C,A
56510 CALL RandomNumber Call RandomNumber.
56513 LD D,H DE=random number between 0000-0255.
56514 LD E,A
56515 ADD HL,DE Add them all together: HL=HL+DE+BC.
56516 ADD HL,BC
56517 LD B,H BC=HL.
56518 LD C,L
Adding 101 to H gives an address range of anywhere between 25856-26621.
56519 LD A,101 H+=101.
56521 ADD A,H
56522 LD H,A
56523 LD A,(HL) Jump to FoundSolidMatter if *HL is not zero.
56524 AND A
56525 JR NZ,FoundSolidMatter
The address in the buffer isn't compatible with containing a human, so have one more try...
56527 DEC H Decrease H by three.
56528 DEC H
56529 DEC H
Just give up here if we still haven't found a building to land on.
56530 LD A,(HL) Return if *HL is zero.
56531 AND A
56532 RET Z
The routine has found "something" but we still need to check that it's compatible with containing a human.
FoundSolidMatter 56533 AND %01000000 Keep only bit 6.
56535 LD D,A D=A.
56536 LD A,(HL) A=*HL.
56537 CP 7 Return if A is higher than 7.
56539 RET NC
56540 CP 3 Return if A is lower than 3.
56542 RET C
56543 AND %00000001 Keep only bit 0.
56545 JR Z,Handler_SpawnHumans_0 Jump to Handler_SpawnHumans_0 if the result is zero.
56547 LD A,7 A=7.
56549 OR D Set the bits from D.
56550 LD (HL),A Write A to *HL.
56551 INC L Increment L by one.
56552 LD A,8 A=8.
56554 OR D Set the bits from D.
56555 LD (HL),A Write A to *HL.
56556 DEC L Decrease L by one.
56557 JR Handler_SpawnHumans_1 Jump to Handler_SpawnHumans_1.
Handler_SpawnHumans_0 56559 LD A,8 A=8.
56561 OR D Set the bits from D.
56562 LD (HL),A Write A to *HL.
56563 DEC L Decrease L by one.
56564 LD A,7 A=7.
56566 OR D Set the bits from D.
56567 LD (HL),A Write A to *HL.
56568 INC L Increment L by one.
56569 DEC C Decrease C by one.
Handler_SpawnHumans_1 56570 PUSH BC Stash BC on the stack.
56571 LD A,104 B+=104.
56573 ADD A,B
56574 LD B,A
56575 LD A,255 Write 255 to *BC.
56577 LD (BC),A
56578 INC C Increment C by one.
56579 LD (BC),A Write A to *BC.
56580 EX DE,HL Exchange the DE and HL registers.
Register that a new human has been created.
56581 LD A,(54260) Increment *NumberHumans by one.
56584 INC A
56585 LD (54260),A
Loop to find an empty slot.
56588 LD HL,53841 HL=MonsterSpriteModifier (Table_Humans-4).
Handler_Humans_FindSlot 56591 INC HL Increment HL by four.
56592 INC HL
56593 INC HL
56594 INC HL
56595 LD A,(HL) Jump to Handler_Humans_FindSlot if *HL is not zero.
56596 AND A
56597 JR NZ,Handler_Humans_FindSlot
Found an empty slot.
All humans start as type 1.
56599 LD (HL),1 Write human type 1 to *HL.
Set a random countdown value.
56601 INC HL Increment HL by one.
56602 CALL RandomNumber Get a random number between 31-62.
56605 AND %00011111
56607 ADD A,31
56609 LD (HL),A Write A as the countdown to *HL.
56610 INC HL Increment HL by one.
56611 POP BC Restore BC from the stack.
56612 LD A,C A=C.
56613 AND %00011111 Keep only bits 0-4.
56615 LD (HL),A Write A to *HL.
56616 INC HL Increment HL by one.
56617 LD A,B A=B.
56618 RLCA Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2).
56619 RLCA
56620 RLCA
56621 LD B,A Store the result in B.
56622 LD A,C A=C.
56623 RLCA Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2).
56624 RLCA
56625 RLCA
56626 AND %00000111 Keep only bits 0-2.
56628 OR B Set the bits from B.
56629 DEC A Decrease A by one.
56630 LD (HL),A Write A to *HL.
56631 RET Return.
Prev: 56293 Up: Map Next: 56632