11/*
2+ Firefighter game loop and its helper functions.
3+
24 Firefighting game for the Atari 8-bit
3546 http://www.newbreedsoftware.com/firefighter/
1416#include "draw_text.h"
1517#include "dli.h"
1618
17- /* FIXME: Shove in a "score.h" header? */
19+ /* FIXME: Shove in a "score.h" header? -bjk 2023.08.22 */
1820#define SCORE_AX_COLLECT 15
1921#define SCORE_CIVILIAN_RESCUE 100
2022#define SCORE_CRATE_BREAK_DEDUCTION 1
@@ -469,7 +471,13 @@ void start_game(void) {
469471 tip shape near the player, and three other shapes
470472 beyond that; we'll avoid drawing those other three
471473 if the first part failed to draw, to avoid being
472- able to spray through solid objects! */
474+ able to spray through solid objects!i
475+
476+ @param unsigned char x - X position to [attempt to] draw
477+ @param unsigned char y - Y position to [attempt to] draw
478+ @param unsigned char want_shape - water shape to [attempt to] draw
479+ @return boolean 1 if it was drawn, 0 otherwise (e.g., obstacle, fire, etc.)
480+ */
473481unsigned char spray (unsigned char x , unsigned char y , unsigned char want_shape ) {
474482 unsigned char shape ;
475483
@@ -545,7 +553,9 @@ void setup_game_screen(void) {
545553 OS .sdmctl = (DMACTL_PLAYFIELD_NORMAL | DMACTL_DMA_FETCH );
546554}
547555
548- /* FIXME */
556+ /* Draw the current level, including drawing the
557+ level/score/bonus status bar at the top.
558+ Flashes a "GET READY!" message, before proceeding. */
549559void draw_level (void ) {
550560 int l ;
551561
@@ -571,7 +581,7 @@ void draw_level(void) {
571581 memcpy (scr_mem + 60 , levels_data + l * LEVEL_TOT_SIZE + 1 , LEVEL_SPAN );
572582}
573583
574- /* FIXME */
584+ /* Draws the level/score/bonus in the status bar */
575585void draw_score (void ) {
576586 draw_number (level , 2 , scr_mem + 28 );
577587 draw_number (score , 6 , scr_mem + 39 );
@@ -657,6 +667,7 @@ void cellular_automata(void) {
657667 if (valid_dir (x , y , dir ) &&
658668 shape_at (x + dir_x [dir ], y + dir_y [dir ]) == 0 ) {
659669 set_shape (x , y , 0 );
670+
660671 if ((dir_x [dir ] == 1 && dir_y [dir ] >= 0 ) || dir_y [dir ] == 1 ) {
661672 set_shape (x + dir_x [dir ], y + dir_y [dir ], CIVILIAN_MOVED );
662673 } else {
@@ -665,7 +676,12 @@ void cellular_automata(void) {
665676 }
666677 }
667678 } else if (shape == CIVILIAN_MOVED ) {
668- /* FIXME */
679+ /* Turn a previously-moved worker back into a regular worker.
680+
681+ (Since cellular automaton goes from top-to-bottom, left-to-right,
682+ we use an interim 'shape' to avoid processing the same worker
683+ multiple times per frame (causing them to 'fly' across or down
684+ the screen) if they move down or right) */
669685 set_shape (x , y , CIVILIAN );
670686 } else if (shape == PIPE_BROKEN_UP_DOWN && rand < 128 ) {
671687 /* Draw (or erase) gas leak on left/right of a broken vertical pipe */
@@ -682,21 +698,8 @@ void cellular_automata(void) {
682698 }
683699 }
684700
685- /* FIXME */
686- /*
687- for (y = 0; y < LEVEL_H; y++) {
688- for (x = 0; x < LEVEL_W; x++) {
689- shape = shape_at(x, y);
690- if (shape == CIVILIAN_MOVED) {
691- set_shape(x, y, CIVILIAN);
692- } else if (shape == FIRE_SM || shape == FIRE_MD || shape == FIRE_LG) {
693- any_fire++;
694- }
695- }
696- }
697- */
698-
699- /* FIXME */
701+ /* Play crackling fire sound effect
702+ (the more fire, the higher the volume) */
700703 if (any_fire ) {
701704 POKEY_WRITE .audf1 = ((POKEY_READ .random ) >> 4 ) + 128 ;
702705 POKEY_WRITE .audc1 = (any_fire >> 4 ) + 1 ;
@@ -705,7 +708,14 @@ void cellular_automata(void) {
705708 }
706709}
707710
708- /* FIXME */
711+ /* Given a broken pipe at a position on the screen,
712+ [attempt to] draw a gas leak shape, or a blank,
713+ depending on the state of all valves on the screen.
714+
715+ @param int x - X position to [attempt to] draw/erase gas leak
716+ @param int y - Y position to [attempt to] draw/erase gas leak
717+ @param char shape - gas leak shape to [attempt to] draw there
718+ */
709719void broken_pipe (int x , int y , char shape ) {
710720 char c ;
711721
@@ -752,7 +762,11 @@ char pipe_corner[16] = {
752762
753763
754764/* Create an explosion of fire at the given position
755- (occurs when fire touches oil barrels or gas leaks) */
765+ (occurs when fire touches oil barrels or gas leaks)
766+
767+ @param char x - X position for explosion
768+ @param char y - Y position for explosion
769+ */
756770void explode (char x , char y ) {
757771 char shape , flam ;
758772
@@ -801,7 +815,13 @@ void explode(char x, char y) {
801815}
802816
803817/* Determines whether moving a given direction from
804- a particular position is still in-bounds */
818+ a particular position is still in-bounds
819+
820+ @param unsigned char x - X position from which to test
821+ @param unsigned char y - Y position from which to test
822+ @param unsigned char dir - direction (0-7; see dir_x[] & dir_y[]) to test
823+ @return unsigned char boolean whether the new position is in bounds
824+ */
805825unsigned char valid_dir (unsigned char x , unsigned char y , unsigned char dir ) {
806826 int dx , dy ;
807827
@@ -814,7 +834,14 @@ unsigned char valid_dir(unsigned char x, unsigned char y, unsigned char dir) {
814834};
815835
816836/* Return the flammability of an object; used to determine
817- how (and if) fire spreads */
837+ how (and if) fire spreads
838+
839+ @param unsigned char c - Object shape to test for flammability
840+ @param unsigned char - Fire shape to draw on the screen
841+ (FIRE_SM, FIRE_MD, or FIRE_LG),
842+ or FIRE_INFLAM if the shape is not flammable (don't spread fire),
843+ or FIRE_XLG if the shape is explosive
844+ */
818845unsigned char flammable (unsigned char c ) {
819846 if (c == OIL || c == GASLEAK_RIGHT || c == GASLEAK_LEFT || c == GASLEAK_UP || c == GASLEAK_DOWN ) {
820847 /* Oil barrel and gas leaks cause an explosion */
@@ -841,7 +868,16 @@ unsigned char flammable(unsigned char c) {
841868 }
842869}
843870
844- /* FIXME */
871+ /* Set sound parameters
872+ @param char p - Starting pitch (0-255)
873+ @param char pch - Pitch delta
874+ (negative for higher, positive for lower, zero for no change)
875+ @param char dist - Distortion (as high nybble)
876+ (e.g., (10<<4) aka 160 aka 0xA0 for 'pure' tone (square wave)
877+ @param char vol - Starting volume (0-15)
878+ @param char volch - Volume change; how fast to decrease volume
879+ (note: always _positive_)
880+ */
845881void set_sound (char p , char pch , char dist , char vol , char volch ) {
846882 hit_pitch = p ;
847883 hit_pitch_change = pch ;
@@ -850,7 +886,11 @@ void set_sound(char p, char pch, char dist, char vol, char volch) {
850886 hit_vol_decrease = volch ;
851887}
852888
853- /* FIXME */
889+ /* End-of-level bonus sequence:
890+ + Show "Level Complete!"
891+ + Show and tally Time Bonus
892+ + Show and tally Safety Bonus
893+ */
854894void level_end_bonus (void ) {
855895 int i ;
856896 char c , any_fire ;
@@ -908,7 +948,7 @@ void level_end_bonus(void) {
908948 }
909949}
910950
911- /* FIXME */
951+ /* Briefly flash the background color (of the entire screen) */
912952void flash (void ) {
913953 char i , j ;
914954
@@ -924,6 +964,7 @@ void flash(void) {
924964 }
925965}
926966
967+ /* Pause for a few seconds */
927968void pause (void ) {
928969 int i ;
929970
@@ -932,7 +973,10 @@ void pause(void) {
932973 }
933974}
934975
935- /* FIXME */
976+ /* Bonus score tally sequence (used by end-of-level bonus sequence)
977+ @param int x - X position to draw bonus score for countdown
978+ @param int deduct - How quickly to deduct points from bonus during tally
979+ */
936980void bonus_tally (int x , int deduct ) {
937981 while (bonus >= deduct ) {
938982 bonus = bonus - deduct ;
@@ -966,4 +1010,3 @@ void quiet(void) {
9661010 POKEY_WRITE .audf4 = 0 ;
9671011 POKEY_WRITE .audc4 = 0 ;
9681012}
969-
0 commit comments