Prev: A320 Up: Map Next: A361
A32B: Reduce Sector Energy
Used by the routines at MoveSpark and MoveDestroyer.
Takes one unit of energy off the sector that an entity is in. If the energy is down to five or fewer units then the player is told, and when it reaches zero the sector has been destroyed.
Input
IX Entity
ReduceSectorEnergy A32B CALL FindSectorEnergy Find the energy of the sector using FindSectorEnergy.
A32E DEC (HL) Take one unit of energy off.
A32F LD A,(HL) Fetch the energy that is left.
A330 CP $06 Return if there are at least six units.
A332 RET NC
A333 LD C,A Keep the energy.
A334 AND A Jump if there is some energy left.
A335 JR NZ,ReduceSectorEnergy_Message
A337 LD HL,$9659 Point HL at the number of sectors that have been destroyed.
A33A INC (HL) Add one.
A33B LD HL,$967E Point HL at SectorStates.
A33E ADD HL,DE Add the sector number.
A33F LD A,(HL) Fetch the state of the sector.
A340 AND $FC Change it to destroyed (bit 0 set and bit 1 clear), clearing the flag that says it is under attack.
A342 OR $01
A344 LD (HL),A Store the new state.
A345 PUSH DE Save the sector number.
A346 CALL DrawSectorMap Colour the sector map using DrawSectorMap.
A349 POP DE Restore the sector number.
ReduceSectorEnergy_Message A34A LD A,E Fetch the sector number...
A34B ADD A,$B1 ...and convert it into the last character of the message "SECTOR n"...
A34D LD ($9D4D),A ...by writing it into the message.
A350 LD D,E Use the sector number as the argument of the message...
A351 LD E,$01 ...for message 01.
A353 CALL QueueMessage Queue it using QueueMessage.
A356 LD E,$04 Use message 04, "DESTROYED"...
A358 LD A,C ...but use message 07, "CRITICAL", instead...
A359 AND A ...unless the sector has no energy left, in which case jump to use "DESTROYED".
A35A JR Z,ReduceSectorEnergy_QueueMessage
A35C LD E,$07 Use message 07, "CRITICAL".
ReduceSectorEnergy_QueueMessage A35E JP QueueMessage Jump to QueueMessage.
Prev: A320 Up: Map Next: A361