Prev: 26337 Up: Map Next: 26459
26375: Recalc alien numeric data on alien hit
This updates a set of numerical values which control alien horde data. We have _ALIENS_LEFT_IN_ROWS which holds a 5 entry array containing the number of aliens in each row. One entry in that needs to be decremented. Then there's _ALIENS_LEFT_IN_COLs which holds an 11 entry array containing the number of aliens in each column. Decrement an entry in there too. _LOWEST_ACTIVE_ALIEN_ROW is then recalculated so we know which is the lowest on screen row which still has at least one alien left in it. _LEFTMOST_ACTIVE_ALIEN_COL and _RIGHTMOST_ACTIVE_ALIEN_COL are then recalculated so we know how far across the horde has to move left to right.
Used by the routine at alien_hit.
Input
_HIT_ALIEN_ROW holds row of alien that has been hit
_CX_OFFSET_HIT_ALIEN holds cx value of hit alien, so 0 to 21.
Start by decrementing the number of aliens in the hit alien's row
recalc_horde_stats 26375 LD HL,_ALIENS_LEFT_IN_ROWS Find this row's entry in the table which holds the number of aliens left in each row (0 to 11). Decrement it.
26378 LD A,(_HIT_ALIEN_ROW)
26381 CALL add_a_to_hl_2
26384 DEC (HL)
Now decrement the number of aliens in the hit alien's column
26385 LD HL,_ALIENS_LEFT_IN_COLs Find the column the hit alien is in and get the aliens-left value for that column (0 to 5). Decrement it. IX value set here appears to be redundant.
26388 LD IX,_ALIEN_ROW_PTR
26392 LD A,(_CX_OFFSET_HIT_ALIEN)
26395 SRL A
26397 CALL add_a_to_hl_2
26400 DEC (HL)
The row and columns tables have been decremented, so now update the values which store the extremes of the horde. If the last alien in a row and/or column was just zapped we need to update these values.
Look for row with at least one alien in it. Work from the bottom row upwards.
26401 LD HL,_ALIENS_LEFT_IN_ROWS Pick up the number-left-in-rows table
26404 LD A,(_LOWEST_ACTIVE_ALIEN_ROW) Current lowest screen row with at least one alien left
26407 INC A Make it correct for this purpose
26408 LD B,A B is the counter for this loop
26409 CALL add_a_to_hl_2 Find entry in alien rows table
26412 XOR A Zero A
recalc_horde_stats_0 26413 DEC HL We're going from bottom row to top. HL is now the row above where we last thought the lowest empty row was.
26414 DEC B Move up a row - is the number of aliens in this row zero?
26415 OR (HL)
26416 JR Z,recalc_horde_stats_0 Yes, jump back to check next row up.
B now contains index of the lowest non-empty alien row. Update _LOWEST_ACTIVE_ALIEN_ROW with that.
26418 LD A,B Update value which stores the lowest screen row with at least one alien
26419 LD (_LOWEST_ACTIVE_ALIEN_ROW),A
Look for the left most column with an alien still in it
26422 LD B,255 B is -1 for the start of the loop
26424 LD HL,_ALIENS_LEFT_IN_COLs HL is number of aliens in column table
26427 XOR A Zero A
26428 DEC HL Back one, just for the loop
recalc_horde_stats_1 26429 INC HL Move along the aliens-in-cols table looking for the first entry with non-zero aliens. That's what we're looking for.
26430 INC B
26431 OR (HL)
26432 JR Z,recalc_horde_stats_1
Non-empty column on left side found, its index is in B
26434 LD A,B A contains index of leftmost non-empty alien column. Store that.
26435 LD (_LEFTMOST_ACTIVE_ALIEN_COL),A
Look for the right most column with an alien still in it
26438 LD HL,_ALIENS_LEFT_IN_COLs HL is number of aliens in column table
26441 LD A,11 B starts at 12
26443 LD B,A
26444 INC B
26445 CALL add_a_to_hl_2 HL contains right most column
26448 XOR A Zero A
recalc_horde_stats_2 26449 DEC HL Work back leftwards, looking for the first column which has a non-zero number of aliens in it.
26450 DEC B
26451 OR (HL)
26452 JR Z,recalc_horde_stats_2
Non-empty column on right side found, its index is in B
26454 LD A,B A contains index of rightmost non-empty alien column. Store that.
26455 LD (_RIGHTMOST_ACTIVE_ALIEN_COL),A
26458 RET
Prev: 26337 Up: Map Next: 26459