Prev: 58476 Up: Map Next: 58764
58599: Calculate and print Maroc's rank
Used by the routines at 49315 and 55944.
See Trivia: Maroc's rank for information about how this is determined.
58599 CALL 57081 Clear the scroll status panel at the bottom of the screen
58602 LD A,34 Message number 34 (message texts start from 29042) - #34 is the "YOUR RANK IS NOW" text at 29416.
58604 CALL 58789 Identify address pointer for message text
58607 LD (60065),HL ...and store
58610 LD HL,20584 Set the screen display address pointer for top left of scroll, one character line down
58613 LD (60068),HL ..and store.
58616 CALL 58064 Print the message text on the scroll
GET MAROC'S RANK
This next routine looks through the spells and checks which ones have been collected (first byte of the spell data = 16).
For each spell collected, the C register is incremented by 3, so it looks as if this will play a part in increasing Maroc's rank.
HOWEVER, the routine after this resets the C register to 0 at 58651 before it's stored anywhere, so will effectively nullify any increments calculated here. So collecting spells doesn't have an effect on Maroc's rank after all.
58619 LD DE,16
58622 LD HL,(60261) Address pointer to start of message texts at 28156, starting with spell names
58625 LD A,(60265) Number of spells (27)
58628 LD B,A Store in B register as a counter
58629 LD C,0 C seems to be a counter for spells collected
58631 LD A,16 Check if Maroc has collected this spell
58633 CP (HL)
58634 JR NZ,58639
58636 INC C If so, increment score by 3
58637 INC C
58638 INC C
58639 ADD HL,DE Move onto the next spell
58640 DJNZ 58633 Check for all 27 spells
ADD RANK SCORE FOR WARLOCKS DESTROYED
Maroc can gain rank points by destroying any/all of the 7 warlocks, which appear on walls on various game levels. Warlock attributes are stored at 27772.
Score for destroying a warlock is warlock number * 4. So warlock #1 is worth 4, warlock #7 is worth 28.
58642 LD HL,(60355) Address pointer to warlock information at 27772
58645 INC HL If the second byte in each warlock's data set >0, it means Maroc has destroyed this warlock.
58646 LD DE,8 8 bytes for each set of warlock data
58649 LD B,7 7 warlocks to check
58651 LD C,0 The C register will contain the total score
58653 LD A,(HL) Get byte
58654 ADD HL,DE (Move pointer to the next warlock data set ready for next check)
58655 CP 0 Check if it's 0
58657 JR Z,58666 If so, this warlock has not been destroyed. Continue to the next one.
58659 LD A,8 If the warlock has been destroyed, calculate which of the warlocks it is by starting with 8...
58661 SUB B ...and subtracting the (reversed) warlock number (1-7)
58662 ADD A,A A now contains the warlock number that has been destroyed (1-7). Multiply this by 4
58663 ADD A,A
58664 ADD A,C ...and add it to the total score.
58665 LD C,A
58666 DJNZ 58653 Continue to check all 7 warlocks, adding score for each one that has been destroyed
ADD RANK SCORE BASED ON OTHER CREATURES DESTROYED
Maroc's ranks points are increased by 1 for every 2 creatures destroyed (creature data at 27828)
Rank points are halved in the final calculation, meaning Maroc's rank will increase by 1 for every 4 creatures he destroys.
58668 LD B,4 4 types of creature to check
58670 LD A,(HL) Get (2nd) byte of set, which indicates number of creatures destroyed
58671 ADD HL,DE (Move pointer to the next creature set ready for next check)
58672 SRA A Halve the score value
58674 ADD A,C ...and add it to the score
58675 LD C,A
58676 DJNZ 58670 Continue to check the 4 types of creature, adding score for numbers destroyed
ADD RANK SCORE BASED ON DEMONS DESTROYED
Maroc receives 32 points at the point he destroys his first (but not every) demon in the High Temple of Chaos.
The reason for this score being is a one-off increment is because unlike other creatures, demons respawn indefinitely.
58678 LD A,(HL) Get (2nd) byte of set
58679 CP 0
58681 JR Z,58687 If zero, nothing to add
58683 LD A,32 Otherwise, add a (set) score of 32
58685 ADD A,C
58686 LD C,A
The next check looks at Maroc's dungeon level, when he ran out of energy (or finishes the game). The second paired byte in the table at 50852 is doubled, then added to the rank/score.
Using 'current' level vs 'achieved' level means Maroc receives a higher rank for running out of energy on deeper levels (e.g. by casting the SUMMON spell), but will lose ranks if he dies on the Gatehouse level, for instance.
The score is added to using paired byte x 2 (e.g. running out of energy in the Chambers of Chaos is worth 8 x 2 = 16 points)
58687 LD A,(60105) Byte relating to level number in reference table at 50852
58690 ADD A,A Double it
58691 ADD A,C ...and add to the score
58692 LD C,A
Now a rank demotion. The byte at 60104 counts how many times Maroc has died (i.e. run out of energy).
His score is reduced by 1 for every 4 occurences of this (score reduction = byte value / 4).
58693 LD A,(60104) Get Maroc's current 'death count'
58696 INC A ...and increase by 1
58697 JR C,58702 Avoid re-storing the increased amount if it would mean a wrap around to 0 (if Maroc has already died 255 times!)
58699 LD (60104),A Re-store
58702 RRA Divide by 4
58703 RRA
58704 AND 63 Filter out any unnecesary carry bits caused by the RRAs
58706 LD B,A Subtract value from calculated rank score
58707 LD A,C
58708 SUB B
58709 JR NC,58713
58711 LD A,0 If this subtraction brings down the total rank to less than 0, set it at 0 (APPRENTICE LORE SEEKER).
Halve the score before using it to calculate the rank:
58713 RRA Halve the score value
58714 LD C,A And store in the C register
Use the calculated score to identify Maroc's rank:
58715 RRA Divide the already-halved-score by 8 to move the score into the lowest 4 bits of the byte
58716 RRA
58717 RRA
58718 AND 15 Keep bits 0-3 (values 0-15) - this gives 16 options, which relate to the 16 titles
58720 ADD A,18 The rank title texts start at 29264, which is message #18 from the start of the message texts (49042), so add this.
58722 LD (60103),A Store this value
Calculate and print the 'descriptor' part of the rank text (one of the 8 texts at 29206).
58725 LD A,C Retrieve the original score (halved so will be in the range 0-127)
58726 AND 7 Keep bits 0-2 (values 0-7) - this gives 8 options, which relate to the 8 descriptors
58728 ADD A,10 The rank descriptor texts start at 29206, which is message #10 from the start of the message texts (29042), so add this.
58730 CALL 58789 Identify the address pointer for the descriptor text
58733 LD (60065),HL ...and store.
58736 LD HL,20648 Screen display address to the start of where the descriptor text will be printed on the scroll
58739 LD (60068),HL ...and store
58742 CALL 58064 Print the text on the scroll
Print the 'title' part of the rank text (one of the 16 texts at 29264):
58745 LD A,(60103) Retrieve the calculated text message number
58748 CALL 58789 Identify the address pointer for the text to print
58751 LD (60065),HL ...and store.
58754 LD HL,20680 Screen display address to the start of where the descriptor text will be printed on the scroll, just below where the descriptor was printed
58757 LD (60068),HL
58760 CALL 58064 Print the text on the scroll
58763 RET
Prev: 58476 Up: Map Next: 58764