Prev: 41760 Up: Map Next: 41825
41771: 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 41771 CALL FindSectorEnergy Find the energy of the sector using FindSectorEnergy.
41774 DEC (HL) Take one unit of energy off.
41775 LD A,(HL) Fetch the energy that is left.
41776 CP 6 Return if there are at least six units.
41778 RET NC
41779 LD C,A Keep the energy.
41780 AND A Jump if there is some energy left.
41781 JR NZ,ReduceSectorEnergy_Message
41783 LD HL,38489 Point HL at the number of sectors that have been destroyed.
41786 INC (HL) Add one.
41787 LD HL,38526 Point HL at SectorStates.
41790 ADD HL,DE Add the sector number.
41791 LD A,(HL) Fetch the state of the sector.
41792 AND 252 Change it to destroyed (bit 0 set and bit 1 clear), clearing the flag that says it is under attack.
41794 OR 1
41796 LD (HL),A Store the new state.
41797 PUSH DE Save the sector number.
41798 CALL DrawSectorMap Colour the sector map using DrawSectorMap.
41801 POP DE Restore the sector number.
ReduceSectorEnergy_Message 41802 LD A,E Fetch the sector number...
41803 ADD A,177 ...and convert it into the last character of the message "SECTOR n"...
41805 LD (40269),A ...by writing it into the message.
41808 LD D,E Use the sector number as the argument of the message...
41809 LD E,1 ...for message 1.
41811 CALL QueueMessage Queue it using QueueMessage.
41814 LD E,4 Use message 4, "DESTROYED"...
41816 LD A,C ...but use message 7, "CRITICAL", instead...
41817 AND A ...unless the sector has no energy left, in which case jump to use "DESTROYED".
41818 JR Z,ReduceSectorEnergy_QueueMessage
41820 LD E,7 Use message 7, "CRITICAL".
ReduceSectorEnergy_QueueMessage 41822 JP QueueMessage Jump to QueueMessage.
Prev: 41760 Up: Map Next: 41825