![]() |
Routines |
| Prev: 40262 | Up: Map | Next: 40446 |
|
Used by the routine at MainLoop.
Called every frame. It counts down to the next attack on one of the nine sectors. When the count reaches zero a sector is picked at random. If it still has some energy then it comes under attack, and the messages "SECTOR n" and "UNDER ATTACK" are queued. The attack lasts until the next sector is attacked.
|
||||
| AttackSector | 40359 | LD A,(38470) | Fetch the number of frames until the next attack. | |
| 40362 | DEC A | Count down. | ||
| 40363 | LD (38470),A | Store it. | ||
| 40366 | RET NZ | Return if it has not reached zero. | ||
| 40367 | LD A,80 | Set the time until the next attack to 80 frames. | ||
| 40369 | LD (38470),A | Store it. | ||
| 40372 | LD A,(38423) | Fetch the random number. | ||
| 40375 | AND 198 | Keep the bits that choose the sector (bits 1 and 2 give the column, bits 6 and 7 the row). | ||
| 40377 | LD C,A | Keep the sector bits. | ||
| 40378 | AND 192 | Test the row. | ||
| 40380 | CP 192 | Jump if it is 3, as there is no such row. | ||
| 40382 | JR Z,AttackSector_Retry | |||
| 40384 | LD A,C | Fetch the number again. | ||
| 40385 | AND 6 | Test the column. | ||
| 40387 | CP 6 | Jump if it is 3, as there is no such column. | ||
| 40389 | JR Z,AttackSector_Retry | |||
| 40391 | RRCA | Move the column into bits 0 and 1... | ||
| 40392 | LD D,A | ...and keep it in D. | ||
| 40393 | LD A,C | Fetch the number again. | ||
| 40394 | RLCA | Move the row into bits 0 and 1... | ||
| 40395 | RLCA | |||
| 40396 | AND 3 | ...clear the other bits... | ||
| 40398 | LD E,A | ...and keep the row in E. | ||
| 40399 | RLCA | Double the row... | ||
| 40400 | ADD A,E | ...add the row to make three times the row... | ||
| 40401 | ADD A,D | ...and add the column to find the sector number. | ||
| 40402 | LD E,A | Keep the sector number... | ||
| 40403 | LD D,0 | ...and clear D. | ||
| 40405 | LD HL,41825 | Point HL at SectorEnergy. | ||
| 40408 | ADD HL,DE | Add the sector number. | ||
| 40409 | LD A,(HL) | Fetch the energy of the sector. | ||
| 40410 | AND A | Jump if the sector has no energy left, as it cannot be attacked. | ||
| 40411 | JR Z,AttackSector_NoEnergy | |||
| 40413 | LD HL,38526 | Point HL at SectorStates. | ||
| 40416 | ADD HL,DE | Add the sector number. | ||
| 40417 | SET 2,(HL) | Mark the sector as under attack. | ||
| 40419 | LD D,E | Use the sector number as the argument of the message... | ||
| 40420 | LD E,1 | ...for message 1, "SECTOR n". | ||
| 40422 | CALL QueueMessage | Queue the message using QueueMessage. | ||
| 40425 | LD DE,6 | Queue message 6, "UNDER ATTACK"... | ||
| 40428 | CALL QueueMessage | ...as well. | ||
| 40431 | JP SetAttackedSector | Mark the sector as the one under attack and colour the sector map using SetAttackedSector. | ||
|
The time until the next attack is shortened if there was no sector that could be attacked.
|
||||
| AttackSector_Retry | 40434 | LD A,32 | Set the time until the next attack to 32 frames. | |
| AttackSector_Store | 40436 | LD (38470),A | Store it. | |
| 40439 | JP SetAttackedSector | Mark the sector as the one under attack and colour the sector map using SetAttackedSector. | ||
| AttackSector_NoEnergy | 40442 | LD A,1 | Set the time until the next attack to one frame. | |
| 40444 | JR AttackSector_Store | Jump back to store it. | ||
| Prev: 40262 | Up: Map | Next: 40446 |