diff --git a/src/campaign.c b/src/campaign.c
index 3422139..05d150a 100644
--- a/src/campaign.c
+++ b/src/campaign.c
@@ -1,4 +1,4 @@
-/*
+/*
campaign.c - handle TuxMath's 'Mission mode'
Copyright (C) 2008, 2009, 2010, 2011.
@@ -23,9 +23,6 @@ along with this program. If not, see .
*/
-
-
-
#include "campaign.h"
#include "tuxmath.h"
#include "credits.h"
@@ -35,14 +32,13 @@ along with this program. If not, see .
#include "mathcards.h"
#include "options.h"
-
-void briefPlayer(int stage); //show text introducing the given stage
+void briefPlayer(int stage); // show text introducing the given stage
void readStageSettings(int stage);
void readRoundSettings(int stage, int round);
void showGameOver();
void showGameWon();
-char* stagenames[NUM_STAGES] = {"cadet", "scout", "ranger", "ace", "commando"};
+char *stagenames[NUM_STAGES] = {"cadet", "scout", "ranger", "ace", "commando"};
int start_campaign()
{
@@ -52,7 +48,6 @@ int start_campaign()
char endtext[2][MAX_LINEWIDTH] = {N_("Congratulations! You win!"), " "};
fprintf(stderr, "Entering start_campaign()\n");
-
for (i = 0; i < NUM_STAGES; ++i)
{
fprintf(stderr, "Stage %s\n", stagenames[i]);
@@ -61,8 +56,8 @@ int start_campaign()
{
fprintf(stderr, "Round %d\n", j);
- //read in settings
- read_named_config_file(local_game, "campaign/campaign");
+ // read in settings
+ read_named_config_file(local_game, "campaign/campaign");
readStageSettings(i);
readRoundSettings(i, j);
Opts_SetKeepScore(0);
@@ -75,11 +70,11 @@ int start_campaign()
MC_PrintMathOptions(local_game, stdout, 0);
}
- //play!
+ // play!
fprintf(stderr, "Starting game...\n");
gameresult = comets_game(local_game);
- //move on if we've won, game over if not
+ // move on if we've won, game over if not
if (gameresult == GAME_OVER_WON)
;
else if (gameresult == GAME_OVER_LOST)
@@ -98,7 +93,7 @@ int start_campaign()
DEBUGMSG(debug_game, "hit escape\n");
endcampaign = 1;
}
-#endif
+#endif
else
{
fprintf(stderr, "gameresult = %d\n", gameresult);
@@ -109,7 +104,7 @@ int start_campaign()
return 0;
}
- //if we've beaten the last stage, there is no bonus, skip to win sequence
+ // if we've beaten the last stage, there is no bonus, skip to win sequence
if (i == NUM_STAGES - 1)
{
showGameWon();
@@ -133,82 +128,75 @@ void briefPlayer(int stage)
string. This is a consequence of the linewrapping code. TEH Feb
2009. */
- const char briefings[NUM_STAGES][MAX_LINES][MAX_LINEWIDTH] =
- {
- //cadet
- {
- {N_("-[Esc] to skip")},
- {N_("Mission One: Careful Cadet")},
- {"--------------------------"},
- {N_("I'm so glad you've come!")},
- {" "},
- {N_("The penguins need your help! Comets are falling from the sky, and are melting the penguins' igloos. To save their homes, we need you to find the secret code that will zap each comet.")},
- {" "},
- {N_("Do your best!")},
- {""}
- },
- //scout
- {
- {N_("-[Esc] to skip")},
- {N_("Mission Two: Smart Scout")},
- {"------------------------"},
- {N_("Great job! Since you saved the penguins' homes, we are promoting you to Scout. Scouts are good for keeping an eye out for trouble...")},
- {" "},
- {N_("...like what's happening right now! The TakeAways have come, and they're sending new, trickier comets against the penguins!")},
- {N_("But you can save them!")},
- {""}
- },
- //ranger
- {
- {"-[Esc] to skip"},
- {N_("Mission Three: Royal Ranger")},
- {"---------------------------"},
- {N_("You've done it again! The Penguin Emperor has chosen you to join his team of Rangers that help protect the city. We're sending you there now...")},
- {" "},
- {N_("...oh no! Now the Emperor himself is under attack, from new types of comets: these problems are multiplying! To fight these, you need great skill. We think you can do it. Join the Rangers and help save the city!")},
- {""}
- },
- //ace
- {
- {N_("-[Esc] to skip")},
- {N_("Mission Four: Imperial Ace")},
- {"--------------------------"},
- {N_("You did it! The Emperor wants to thank you in person. We are taking you to his ice palace for a great honor: you will become the Imperial Ace!")},
- {" "},
- {N_("But right in the middle of the ceremony, a new attack from the land of Division starts!")},
- {N_("Now is no time for resting; the city needs your help!")},
- {""}
- },
- //commando
+ const char briefings[NUM_STAGES][MAX_LINES][MAX_LINEWIDTH] =
{
- {N_("-[Esc] to skip")},
- {N_("Final Mission: Computing Commando")},
- {"---------------------------------"},
- {N_("Penguin scientists have learned that all these attacks are coming from a secret base, and they need you to go fight the final battle. They also give you this clue: first do multiplication and division, and then do addition and subtraction.")},
- {N_("I hope that hint helps!")},
- {" "},
- {N_("This is it! You can stop these attacks forever, Commando!")},
- {""}
- },
- };
- char* sprites[] = {
+ // cadet
+ {
+ {N_("-[Esc] to skip")},
+ {N_("Mission One: Careful Cadet")},
+ {"--------------------------"},
+ {N_("I'm so glad you've come!")},
+ {" "},
+ {N_("The penguins need your help! Comets are falling from the sky, and are melting the penguins' igloos. To save their homes, we need you to find the secret code that will zap each comet.")},
+ {" "},
+ {N_("Do your best!")},
+ {""}},
+ // scout
+ {
+ {N_("-[Esc] to skip")},
+ {N_("Mission Two: Smart Scout")},
+ {"------------------------"},
+ {N_("Great job! Since you saved the penguins' homes, we are promoting you to Scout. Scouts are good for keeping an eye out for trouble...")},
+ {" "},
+ {N_("...like what's happening right now! The TakeAways have come, and they're sending new, trickier comets against the penguins!")},
+ {N_("But you can save them!")},
+ {""}},
+ // ranger
+ {
+ {"-[Esc] to skip"},
+ {N_("Mission Three: Royal Ranger")},
+ {"---------------------------"},
+ {N_("You've done it again! The Penguin Emperor has chosen you to join his team of Rangers that help protect the city. We're sending you there now...")},
+ {" "},
+ {N_("...oh no! Now the Emperor himself is under attack, from new types of comets: these problems are multiplying! To fight these, you need great skill. We think you can do it. Join the Rangers and help save the city!")},
+ {""}},
+ // ace
+ {
+ {N_("-[Esc] to skip")},
+ {N_("Mission Four: Imperial Ace")},
+ {"--------------------------"},
+ {N_("You did it! The Emperor wants to thank you in person. We are taking you to his ice palace for a great honor: you will become the Imperial Ace!")},
+ {" "},
+ {N_("But right in the middle of the ceremony, a new attack from the land of Division starts!")},
+ {N_("Now is no time for resting; the city needs your help!")},
+ {""}},
+ // commando
+ {
+ {N_("-[Esc] to skip")},
+ {N_("Final Mission: Computing Commando")},
+ {"---------------------------------"},
+ {N_("Penguin scientists have learned that all these attacks are coming from a secret base, and they need you to go fight the final battle. They also give you this clue: first do multiplication and division, and then do addition and subtraction.")},
+ {N_("I hope that hint helps!")},
+ {" "},
+ {N_("This is it! You can stop these attacks forever, Commando!")},
+ {""}},
+ };
+ char *sprites[] = {
"sprites/tux_helmet_yellow.svg",
"sprites/tux_helmet_green.svg",
"sprites/tux_helmet_blue.svg",
"sprites/tux_helmet_red.svg",
- "sprites/tux_helmet_black.svg"
- };
-
- SDL_Surface* icon = NULL;
- SDL_Rect textarea = screen->clip_rect;
- SDL_Surface* loadedsprite = T4K_LoadScaledImage(
- sprites[stage], IMG_REGULAR|IMG_NOT_REQUIRED,
- screen->h / 4, screen->h / 4
- );
+ "sprites/tux_helmet_black.svg"};
+ char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
+ SDL_Surface *icon = NULL;
+ SDL_Rect textarea = screen->clip_rect;
+ SDL_Surface *loadedsprite = T4K_LoadScaledImage(
+ sprites[stage], IMG_REGULAR | IMG_NOT_REQUIRED,
+ screen->h / 4, screen->h / 4);
- if (loadedsprite) //if using an image, make sure the text doesn't hit it
+ if (loadedsprite) // if using an image, make sure the text doesn't hit it
{
icon = loadedsprite;
textarea.x = icon->w;
@@ -216,20 +204,21 @@ void briefPlayer(int stage)
textarea.w = screen->w - icon->w;
textarea.h = screen->h - icon->h;
}
-
- char tts_text[1000];int i;
+
+ char tts_text[1000];
+ int i;
tts_text[0] = '\0';
- for(i = 0;i < MAX_LINES;i++)
+ for (i = 0; i < MAX_LINES; i++)
{
- strcat(tts_text,briefings[stage][i]);
- }
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"%s",tts_text);
+ strcat(tts_text, briefings[stage][i]);
+ }
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "%s", tts_text);
- //background is dark blue with a black text area
+ // background is dark blue with a black text area
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 32));
SDL_FillRect(screen, &textarea, 0);
- //show this stage's text
+ // show this stage's text
DEBUGMSG(debug_game, "Briefing\n");
SDL_BlitSurface(icon, NULL, screen, NULL);
@@ -247,7 +236,7 @@ void briefPlayer(int stage)
void readStageSettings(int stage)
{
char fn[PATH_MAX];
- snprintf(fn,PATH_MAX, "campaign/%s/%s", stagenames[stage], stagenames[stage]);
+ snprintf(fn, PATH_MAX, "campaign/%s/%s", stagenames[stage], stagenames[stage]);
read_named_config_file(local_game, fn);
}
@@ -257,13 +246,14 @@ void readRoundSettings(int stage, int round)
if (round == -1)
snprintf(fn, PATH_MAX, "campaign/%s/bonus", stagenames[stage]);
else
- snprintf(fn,PATH_MAX, "campaign/%s/round%d", stagenames[stage], round);
+ snprintf(fn, PATH_MAX, "campaign/%s/round%d", stagenames[stage], round);
read_named_config_file(local_game, fn);
}
void showGameOver()
{
const char text[2][MAX_LINEWIDTH] = {N_("Sorry, try again!"), ""};
+ char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
T4K_LineWrapList(text, wrapped_lines, 40, MAX_LINES, MAX_LINEWIDTH);
scroll_text(wrapped_lines, screen->clip_rect, 3);
}
@@ -271,6 +261,7 @@ void showGameOver()
void showGameWon()
{
const char text[2][MAX_LINEWIDTH] = {N_("Mission accomplished. The galaxy is safe!"), ""};
+ char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
T4K_LineWrapList(text, wrapped_lines, 40, MAX_LINES, MAX_LINEWIDTH);
scroll_text(wrapped_lines, screen->clip_rect, 3);
}
diff --git a/src/comets.c b/src/comets.c
index 84c9b6e..5f62306 100644
--- a/src/comets.c
+++ b/src/comets.c
@@ -23,9 +23,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-
-
-
/* put this first so we get and immediately: */
#include "tuxmath.h"
@@ -80,14 +77,14 @@ along with this program. If not, see . */
#define POWERUP_Y_POS 100
#define MS_POWERUP_SPEED 250
-#define SMARTBOMB_ICON_W 40
-#define SMARTBOMB_ICON_H 47
-#define SMARTBOMB_ICON_X screen->w - SMARTBOMB_ICON_W
-#define SMARTBOMB_ICON_Y screen->h - SMARTBOMB_ICON_H
+#define SMARTBOMB_ICON_W 40
+#define SMARTBOMB_ICON_H 47
+#define SMARTBOMB_ICON_X screen->w - SMARTBOMB_ICON_W
+#define SMARTBOMB_ICON_Y screen->h - SMARTBOMB_ICON_H
#define BASE_COMET_FONTSIZE 24
-static MC_MathGame* curr_game;
+static MC_MathGame *curr_game;
static int powerup_comet_running = 0;
static int smartbomb_alive = 0;
@@ -98,7 +95,7 @@ int user_quit_received;
/* Local (to game.c) 'globals': */
-static char* comets_music_filenames[NUM_MUSICS] = {
+static char *comets_music_filenames[NUM_MUSICS] = {
"01_rush.ogg",
"02_on_the_edge_of_the_universe.ogg",
"03_gravity.ogg",
@@ -132,7 +129,7 @@ static int smartbomb_firing;
static int level_start_wait;
static int last_bkgd;
static int igloo_vertical_offset;
-//static int extra_life_counter;
+// static int extra_life_counter;
static int bonus_comet_counter;
static int extra_life_earned;
static int key_pressed;
@@ -148,26 +145,25 @@ static float danger_level;
static int digits[MC_MAX_DIGITS];
-static comet_type* comets = NULL;
-static powerup_comet_type* powerup_comet = NULL;
+static comet_type *comets = NULL;
+static powerup_comet_type *powerup_comet = NULL;
-static city_type* cities = NULL;
-static penguin_type* penguins = NULL;
-static steam_type* steam = NULL;
+static city_type *cities = NULL;
+static penguin_type *penguins = NULL;
+static steam_type *steam = NULL;
static cloud_type cloud;
static laser_type laser[MAX_LASER];
-static SDL_Surface* bkgd = NULL; //640x480 background (windowed)
-static SDL_Surface* scaled_bkgd = NULL; //fullscreen resolution (from OS)
-
+static SDL_Surface *bkgd = NULL; // 640x480 background (windowed)
+static SDL_Surface *scaled_bkgd = NULL; // fullscreen resolution (from OS)
static game_message s1, s2, s3, s4, s5;
static int start_message_chosen = 0;
/*****************************************************************/
#ifdef HAVE_LIBSDL_NET
-SDL_Surface* player_left_surf = NULL;
+SDL_Surface *player_left_surf = NULL;
int player_left_time = 0;
SDL_Rect player_left_pos = {0};
#endif
@@ -176,7 +172,7 @@ SDL_Rect player_left_pos = {0};
static help_controls_type help_controls;
/* Local function prototypes: */
-static int comets_initialize(void);
+static int comets_initialize(void);
static void comets_cleanup(void);
static void comets_handle_help(void);
static void comets_handle_user_events(void);
@@ -192,16 +188,18 @@ static void comets_handle_extra_life(void);
static void comets_draw(void);
static void comets_handle_game_over(int comets_status);
-static SDL_Surface* current_bkgd()
-{ return screen->flags & SDL_FULLSCREEN ? scaled_bkgd : bkgd; } //too clever for my brain to process
+static SDL_Surface *current_bkgd()
+{
+ return screen->flags & SDL_FULLSCREEN ? scaled_bkgd : bkgd;
+} // too clever for my brain to process
static int check_extra_life(void);
static int check_exit_conditions(void);
-static void game_set_message(game_message*, const char* ,int x, int y);
-static void comets_clear_message(game_message*);
+static void game_set_message(game_message *, const char *, int x, int y);
+static void comets_clear_message(game_message *);
static void comets_clear_messages(void);
-void comets_write_message(const game_message* msg);
+void comets_write_message(const game_message *msg);
static void comets_write_messages(void);
static void reset_level(void);
@@ -214,12 +212,12 @@ static void comets_mouse_event(SDL_Event event);
static void comets_key_event(SDLKey key, SDLMod mod);
static void free_on_exit(void);
-static void help_add_comet(const char* formula_str, const char* ans_str);
+static void help_add_comet(const char *formula_str, const char *ans_str);
static int help_renderframe_exit(void);
static void comets_recalc_positions(int xres, int yres);
-//Accessibility functions
-wchar_t* convert_formula_to_sentence(char *formula_string);
+// Accessibility functions
+wchar_t *convert_formula_to_sentence(char *formula_string);
int tts_announcer_switch;
int tts_announcer(void *unused);
void stop_tts_announcer_thread();
@@ -232,22 +230,22 @@ int powerup_add_comet(void);
void comets_handle_powerup(void);
void smartbomb_activate(void);
-void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
+void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
/*****************************************************/
#ifdef HAVE_LIBSDL_NET
void comets_handle_net_messages(void);
-void comets_handle_net_msg(char* buf);
-int lan_add_comet(MC_FlashCard* fc);
-int add_quest_recvd(char* buf);
-int remove_quest_recvd(char* buf);
-int wave_recvd(char* buf);
-int player_left_recvd(char* buf);
-int comets_halted_recvd(char* buf);
-int erase_comet_on_screen(comet_type* zapped_comet, int answered_by);
-//MC_FlashCard* search_queue_by_id(int id);
-comet_type* search_comets_by_id(int id);
-int compare_scores(const void* p1, const void* p2);
+void comets_handle_net_msg(char *buf);
+int lan_add_comet(MC_FlashCard *fc);
+int add_quest_recvd(char *buf);
+int remove_quest_recvd(char *buf);
+int wave_recvd(char *buf);
+int player_left_recvd(char *buf);
+int comets_halted_recvd(char *buf);
+int erase_comet_on_screen(comet_type *zapped_comet, int answered_by);
+// MC_FlashCard* search_queue_by_id(int id);
+comet_type *search_comets_by_id(int id);
+int compare_scores(const void *p1, const void *p2);
#endif
/******************************************************/
@@ -256,36 +254,33 @@ void print_current_quests(void);
static void print_exit_conditions(void);
static void print_status(void);
-
/* --- MAIN GAME FUNCTION!!! --- */
-
-int comets_game(MC_MathGame* mgame)
+int comets_game(MC_MathGame *mgame)
{
DEBUGMSG(debug_game, "Entering game():\n");
srand(time(0));
- if(!mgame && !Opts_LanMode())
+ if (!mgame && !Opts_LanMode())
{
fprintf(stderr, "Error - null game struct passed for non_LAN game\n");
return 0;
}
- //Save this in a "file global" so we don't have to pass it to every function:
+ // Save this in a "file global" so we don't have to pass it to every function:
curr_game = mgame;
- //see if the option matches the actual screen
- //FIXME figure out how this is happening so we don't need this workaround
- if (Opts_GetGlobalOpt(FULLSCREEN) == !(screen->flags & SDL_FULLSCREEN) )
+ // see if the option matches the actual screen
+ // FIXME figure out how this is happening so we don't need this workaround
+ if (Opts_GetGlobalOpt(FULLSCREEN) == !(screen->flags & SDL_FULLSCREEN))
{
fprintf(stderr, "\nWarning: Opts_GetGlobalOpt(FULLSCREEN) does not match"
- " actual screen resolution! Resetting selected option.\n");
+ " actual screen resolution! Resetting selected option.\n");
Opts_SetGlobalOpt(FULLSCREEN, !Opts_GetGlobalOpt(FULLSCREEN));
}
-
/* most code moved into smaller functions (comets_*()): */
if (!comets_initialize())
{
@@ -293,13 +288,14 @@ int comets_game(MC_MathGame* mgame)
return 0;
}
- if (Opts_HelpMode()) {
+ if (Opts_HelpMode())
+ {
comets_handle_help();
comets_cleanup();
return GAME_OVER_OTHER;
}
-
- //Calling tts_announcer
+
+ // Calling tts_announcer
start_tts_announcer_thread();
DEBUGMSG(debug_game, "About to enter main game loop.\n");
@@ -312,19 +308,19 @@ int comets_game(MC_MathGame* mgame)
/* reset or increment various things with each loop: */
old_tux_img = tux_img;
tux_pressing = 0;
- int i;
- for(i=0;i 0)
- laser[i].alive -= 15*FC_time_elapsed;
+ laser[i].alive -= 15 * FC_time_elapsed;
}
#ifdef HAVE_LIBSDL_NET
/* Check for server messages if we are playing a LAN game: */
- if(Opts_LanMode())
- {
+ if (Opts_LanMode())
+ {
comets_handle_net_messages();
/* Ask server to send our index if somehow we don't yet have it: */
- if(LAN_MyIndex() < 0)
+ if (LAN_MyIndex() < 0)
LAN_RequestIndex();
}
#endif
@@ -349,13 +345,13 @@ int comets_game(MC_MathGame* mgame)
// 4. Figure out if we should leave loop:
comets_status = check_exit_conditions();
if (comets_status != GAME_IN_PROGRESS)
- stop_tts_announcer_thread();
+ stop_tts_announcer_thread();
/* If we're in "PAUSE" mode, pause! */
if (paused)
{
- stop_tts_announcer_thread();
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,_("Game paused. Press escape or p to continue"));
+ stop_tts_announcer_thread();
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, _("Game paused. Press escape or p to continue"));
pause_game();
paused = 0;
start_tts_announcer_thread();
@@ -364,7 +360,7 @@ int comets_game(MC_MathGame* mgame)
/* Keep playing music: */
#ifndef NOSOUND
- if(Opts_GetGlobalOpt(USE_SOUND))
+ if (Opts_GetGlobalOpt(USE_SOUND))
{
if (!Mix_PlayingMusic())
{
@@ -374,11 +370,9 @@ int comets_game(MC_MathGame* mgame)
#endif
FC_frame_end();
- }
- while(GAME_IN_PROGRESS == comets_status);
+ } while (GAME_IN_PROGRESS == comets_status);
/* END OF MAIN GAME LOOP! */
-
comets_handle_game_over(comets_status);
comets_cleanup();
@@ -408,14 +402,13 @@ int comets_game(MC_MathGame* mgame)
}
}
-
-
int comets_initialize(void)
{
int i, img;
- DEBUGMSG(debug_game,"Entering comets_initialize()\n");
- DEBUGCODE(debug_game) print_game_options(stderr, 0);
+ DEBUGMSG(debug_game, "Entering comets_initialize()\n");
+ DEBUGCODE(debug_game)
+ print_game_options(stderr, 0);
/* Clear window: */
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -445,22 +438,22 @@ int comets_initialize(void)
/* NOTE if we are playing a network game, MC_StartGame() has already */
/* been called on the server by the time we get to here: */
- if(!Opts_LanMode())
+ if (!Opts_LanMode())
{
if (!MC_StartGame(curr_game))
{
fprintf(stderr, "\nMC_StartGame() failed!");
return 0;
- }
- DEBUGMSG(debug_mathcards | debug_game,"MC_StartGame() finished.\n")
+ }
+ DEBUGMSG(debug_mathcards | debug_game, "MC_StartGame() finished.\n")
}
- else
+ else
{
/* Reset question queue and player name/score lists: */
- //int i;
+ // int i;
- //for(i = 0; i < QUEST_QUEUE_SIZE; i ++)
- //MC_ResetFlashCard(&(quest_queue[i]));
+ // for(i = 0; i < QUEST_QUEUE_SIZE; i ++)
+ // MC_ResetFlashCard(&(quest_queue[i]));
// for(i = 0; i < MAX_CLIENTS; i++)
// {
@@ -476,12 +469,12 @@ int comets_initialize(void)
}
/* Allocate memory */
- comets = NULL; // set in case allocation fails partway through
+ comets = NULL; // set in case allocation fails partway through
cities = NULL;
penguins = NULL;
steam = NULL;
- comets = (comet_type *) malloc(MAX_MAX_COMETS * sizeof(comet_type));
+ comets = (comet_type *)malloc(MAX_MAX_COMETS * sizeof(comet_type));
if (comets == NULL)
{
fprintf(stderr, "Allocation of comets failed");
@@ -489,35 +482,34 @@ int comets_initialize(void)
}
/* create only one powerup comet */
- powerup_comet = (powerup_comet_type *) malloc(sizeof(powerup_comet_type));
- if(powerup_comet == NULL)
+ powerup_comet = (powerup_comet_type *)malloc(sizeof(powerup_comet_type));
+ if (powerup_comet == NULL)
{
fprintf(stderr, "Allocation of powerup comet failed");
return 0;
}
- cities = (city_type *) malloc(NUM_CITIES * sizeof(city_type));
+ cities = (city_type *)malloc(NUM_CITIES * sizeof(city_type));
if (cities == NULL)
{
fprintf(stderr, "Allocation of cities failed");
return 0;
}
- penguins = (penguin_type *) malloc(NUM_CITIES * sizeof(penguin_type));
+ penguins = (penguin_type *)malloc(NUM_CITIES * sizeof(penguin_type));
if (penguins == NULL)
{
fprintf(stderr, "Allocation of penguins failed");
return 0;
}
- steam = (steam_type *) malloc(NUM_CITIES * sizeof(steam_type));
+ steam = (steam_type *)malloc(NUM_CITIES * sizeof(steam_type));
if (steam == NULL)
{
fprintf(stderr, "Allocation of steam failed");
return 0;
}
-
/* Write pre-game info to game summary file: */
if (Opts_SaveSummary())
{
@@ -534,7 +526,7 @@ int comets_initialize(void)
wave = 1;
num_attackers = prev_wave_comets = Opts_StartingComets();
- speed = Opts_Speed()*15; //The old fps limit was 15
+ speed = Opts_Speed() * 15; // The old fps limit was 15
slowdown = 0;
score = 0;
demo_countdown = 2000;
@@ -561,14 +553,14 @@ int comets_initialize(void)
if (i < NUM_CITIES / 2)
{
cities[i].x = (((screen->w / (NUM_CITIES + 1)) * i) +
- ((images[img] -> w) / 2));
+ ((images[img]->w) / 2));
}
else
{
cities[i].x = (screen->w -
- ((((screen->w / (NUM_CITIES + 1)) *
- (i - (NUM_CITIES / 2)) +
- ((images[img] -> w) / 2)))));
+ ((((screen->w / (NUM_CITIES + 1)) *
+ (i - (NUM_CITIES / 2)) +
+ ((images[img]->w) / 2)))));
}
}
@@ -591,15 +583,15 @@ int comets_initialize(void)
if (Opts_BonusCometInterval())
{
bonus_comet_counter = Opts_BonusCometInterval() + 1;
- DEBUGMSG(debug_game,"\nInitializing with bonus_comet_counter = %d\n",bonus_comet_counter);
+ DEBUGMSG(debug_game, "\nInitializing with bonus_comet_counter = %d\n", bonus_comet_counter);
}
extra_life_earned = 0;
cloud.status = EXTRA_LIFE_OFF;
/* (Clear laser) */
- for(i= 0; i < MAX_LASER; i++)
- laser[i].alive = 0;
+ for (i = 0; i < MAX_LASER; i++)
+ laser[i].alive = 0;
/* Assign all comet surfs to NULL initially: */
for (i = 0; i < MAX_MAX_COMETS; i++)
@@ -637,25 +629,24 @@ int comets_initialize(void)
help_controls.extra_life_is_blinking = 0;
help_controls.laser_enabled = 1;
- //This tells t4k_common what function we want called
- //when the screen size changes.
+ // This tells t4k_common what function we want called
+ // when the screen size changes.
T4K_OnResolutionSwitch(comets_recalc_positions);
- DEBUGMSG(debug_game,"Exiting comets_initialize()\n");
+ DEBUGMSG(debug_game, "Exiting comets_initialize()\n");
FC_init();
return 1;
}
-
void comets_cleanup(void)
{
DEBUGMSG(debug_game, "Enter comets_cleanup():\n");
/* Stop music: */
#ifndef NOSOUND
- if(Opts_GetGlobalOpt(USE_SOUND))
+ if (Opts_GetGlobalOpt(USE_SOUND))
{
if (Mix_PlayingMusic())
{
@@ -664,13 +655,11 @@ void comets_cleanup(void)
}
#endif
-
-#ifdef HAVE_LIBSDL_NET
- if (Opts_LanMode() )
+#ifdef HAVE_LIBSDL_NET
+ if (Opts_LanMode())
LAN_Cleanup();
#endif
-
/* clear start message */
start_message_chosen = 0;
@@ -680,13 +669,12 @@ void comets_cleanup(void)
DEBUGMSG(debug_game, "Leaving comets_cleanup():\n");
}
-
-/*
+/*
Set one to four lines of text to display at the game's start. Eventually
this should stylishly fade out over the first few moments of the game.
*/
-void game_set_start_message(const char* m1, const char* m2,
- const char* m3, const char* m4)
+void game_set_start_message(const char *m1, const char *m2,
+ const char *m3, const char *m4)
{
game_set_message(&s1, m1, -1, screen->h * 2 / 10);
game_set_message(&s2, m2, screen->w / 2 - 40, screen->h * 3 / 10);
@@ -695,7 +683,6 @@ void game_set_start_message(const char* m1, const char* m2,
start_message_chosen = 1;
}
-
void comets_handle_help(void)
{
const int left_edge = 140;
@@ -713,12 +700,11 @@ void comets_handle_help(void)
tux_pressing = 0;
// Write the introductory text
- game_set_message(&s1,_("Welcome to TuxMath!"),-1,50);
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,_("Welcome to TuxMath!"));
-
+ game_set_message(&s1, _("Welcome to TuxMath!"), -1, 50);
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, _("Welcome to TuxMath!"));
#ifndef NOSOUND
- if(Opts_GetGlobalOpt(USE_SOUND))
+ if (Opts_GetGlobalOpt(USE_SOUND))
{
if (!Mix_PlayingMusic())
{
@@ -728,229 +714,240 @@ void comets_handle_help(void)
#endif
// Wait 2 seconds while rendering frames
- while ((timer+=FC_time_elapsed) < 2 && !(quit_help = help_renderframe_exit()));
+ while ((timer += FC_time_elapsed) < 2 && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
- game_set_message(&s2,_("Your mission is to save your"), left_edge, 100);
- game_set_message(&s3,_("penguins' igloos from the"), left_edge, 135);
- game_set_message(&s4,_("falling comets."), left_edge, 170);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s",
- _("Your mission is to save your"),
- _("penguins' igloos from the"),
- _("falling comets."));
+ game_set_message(&s2, _("Your mission is to save your"), left_edge, 100);
+ game_set_message(&s3, _("penguins' igloos from the"), left_edge, 135);
+ game_set_message(&s4, _("falling comets."), left_edge, 170);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s %s",
+ _("Your mission is to save your"),
+ _("penguins' igloos from the"),
+ _("falling comets."));
timer = 0;
- while ((timer+=FC_time_elapsed) < 5 && !(quit_help = help_renderframe_exit())); // wait 5 more secs
+ while ((timer += FC_time_elapsed) < 5 && !(quit_help = help_renderframe_exit()))
+ ; // wait 5 more secs
if (quit_help)
return;
// Bring in a comet
speed = 30;
help_add_comet("2 + 1 = ?", "3");
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"2 + 1 = ?");
-
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "2 + 1 = ?");
+
help_controls.laser_enabled = 1;
level_start_wait = 0;
timer = 0;
- while (comets[0].alive && (timer+=FC_time_elapsed) < 7 && !(quit_help = help_renderframe_exit())); // advance comet
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"2 + 1 = ?");
- if (quit_help)
- return;
- }
-
- if (comets[0].alive == 1) {
- game_set_message(&s1,_("Stop a comet by typing"),left_edge,100);
- game_set_message(&s2,_("the answer to the math problem"),left_edge,135);
- game_set_message(&s3,_("and hitting 'space' or 'enter'."),left_edge,170);
- game_set_message(&s4,_("Try it now!"),left_edge,225);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s %s 2 + 1 = ",
- _("Stop a comet by typing"),_("the answer to the math problem"),
- _("and hitting 'space' or 'enter'."),_("Try it now!"));
-
-
+ while (comets[0].alive && (timer += FC_time_elapsed) < 7 && !(quit_help = help_renderframe_exit()))
+ ; // advance comet
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "2 + 1 = ?");
+ if (quit_help)
+ return;
+ }
+
+ if (comets[0].alive == 1)
+ {
+ game_set_message(&s1, _("Stop a comet by typing"), left_edge, 100);
+ game_set_message(&s2, _("the answer to the math problem"), left_edge, 135);
+ game_set_message(&s3, _("and hitting 'space' or 'enter'."), left_edge, 170);
+ game_set_message(&s4, _("Try it now!"), left_edge, 225);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s %s %s 2 + 1 = ",
+ _("Stop a comet by typing"), _("the answer to the math problem"),
+ _("and hitting 'space' or 'enter'."), _("Try it now!"));
speed = 0;
- while (comets[0].alive && !(quit_help = help_renderframe_exit()));
+ while (comets[0].alive && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
- return;
-
+ return;
}
- game_set_message(&s1,_("Good shot!"),left_edge,100);
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s",_("Good shot!"));
-
+ game_set_message(&s1, _("Good shot!"), left_edge, 100);
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s", _("Good shot!"));
+
comets_clear_message(&s2);
comets_clear_message(&s3);
comets_clear_message(&s4);
help_controls.laser_enabled = 0;
timer = 0;
- while ((timer+=FC_time_elapsed) < 3 && !(quit_help = help_renderframe_exit())); // wait 3 secs
+ while ((timer += FC_time_elapsed) < 3 && !(quit_help = help_renderframe_exit()))
+ ; // wait 3 secs
speed = 30;
- game_set_message(&s1,_("If an igloo gets hit by a comet,"),left_edge,100);
- game_set_message(&s2,_("it melts. But don't worry: the"),left_edge,135);
- game_set_message(&s3,_("penguin is OK!"),left_edge,170);
- game_set_message(&s4,_("Just watch what happens:"),left_edge,225);
- game_set_message(&s5,_("(Press a key to start)"),left_edge,260);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s %s %s",
- _("If an igloo gets hit by a comet,"),_("it melts. But don't worry: the"),
- _("penguin is OK!"),_("Just watch what happens:"),_("(Press a key to start)"));
+ game_set_message(&s1, _("If an igloo gets hit by a comet,"), left_edge, 100);
+ game_set_message(&s2, _("it melts. But don't worry: the"), left_edge, 135);
+ game_set_message(&s3, _("penguin is OK!"), left_edge, 170);
+ game_set_message(&s4, _("Just watch what happens:"), left_edge, 225);
+ game_set_message(&s5, _("(Press a key to start)"), left_edge, 260);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s %s %s %s",
+ _("If an igloo gets hit by a comet,"), _("it melts. But don't worry: the"),
+ _("penguin is OK!"), _("Just watch what happens:"), _("(Press a key to start)"));
key_pressed = 0;
- while (!key_pressed && !(quit_help = help_renderframe_exit()));
+ while (!key_pressed && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
comets_clear_message(&s5);
help_add_comet("3 x 3 = ?", "9");
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"3 x 3 = ?");
-
- comets[0].y = 2*(screen->h)/3; // start it low down
- while ((comets[0].expl == -1) && !(quit_help = help_renderframe_exit())); // wait 3 secs
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "3 x 3 = ?");
+
+ comets[0].y = 2 * (screen->h) / 3; // start it low down
+ while ((comets[0].expl == -1) && !(quit_help = help_renderframe_exit()))
+ ; // wait 3 secs
if (quit_help)
return;
- game_set_message(&s4,_("Notice the answer"),left_edge,comets[0].y-100);
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s 9",_("Notice the answer"));
-
+ game_set_message(&s4, _("Notice the answer"), left_edge, comets[0].y - 100);
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s 9", _("Notice the answer"));
+
help_renderframe_exit();
SDL_Delay(4000);
comets_clear_message(&s4);
timer = 0;
- while ((timer+=FC_time_elapsed) < 5 && !(quit_help = help_renderframe_exit())); // wait 5 secs
+ while ((timer += FC_time_elapsed) < 5 && !(quit_help = help_renderframe_exit()))
+ ; // wait 5 secs
if (quit_help)
return;
- game_set_message(&s1,_("If it gets hit again, the"),left_edge,100);
- game_set_message(&s2,_("penguin leaves."),left_edge,135);
- game_set_message(&s3,_("(Press a key when ready)"),left_edge,200);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s",
- _("If it gets hit again, the"),_("penguin leaves."),_("(Press a key when ready)"));
+ game_set_message(&s1, _("If it gets hit again, the"), left_edge, 100);
+ game_set_message(&s2, _("penguin leaves."), left_edge, 135);
+ game_set_message(&s3, _("(Press a key when ready)"), left_edge, 200);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s %s",
+ _("If it gets hit again, the"), _("penguin leaves."), _("(Press a key when ready)"));
key_pressed = 0;
- while (!key_pressed && !(quit_help = help_renderframe_exit()));
+ while (!key_pressed && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
comets_clear_message(&s3);
help_add_comet("56 ÷ 8 = ?", "7");
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"56 ÷ 8 = ?");
-
- comets[0].y = 2*(screen->h)/3; // start it low down
- while (comets[0].alive && !(quit_help = help_renderframe_exit()));
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "56 ÷ 8 = ?");
+
+ comets[0].y = 2 * (screen->h) / 3; // start it low down
+
+ while (comets[0].alive && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
timer = 0;
- while ((timer+=FC_time_elapsed) < 3 && !(quit_help = help_renderframe_exit()));
+ while ((timer += FC_time_elapsed) < 3 && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
help_controls.laser_enabled = 1;
- game_set_message(&s1,_("You can fix the igloos"), left_edge,100);
- game_set_message(&s2,_("by stopping bonus comets."), left_edge,135);
+ game_set_message(&s1, _("You can fix the igloos"), left_edge, 100);
+ game_set_message(&s2, _("by stopping bonus comets."), left_edge, 135);
help_add_comet("2 + 2 = ?", "4");
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s 2 + 2 = ?",
- _("You can fix the igloos"),_("by stopping bonus comets."));
-
-
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s 2 + 2 = ?",
+ _("You can fix the igloos"), _("by stopping bonus comets."));
+
comets[0].bonus = 1;
timer = 0;
- while (comets[0].alive && ((timer+=FC_time_elapsed) < 3) && !(quit_help = help_renderframe_exit()));
+ while (comets[0].alive && ((timer += FC_time_elapsed) < 3) && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
if (comets[0].alive)
speed = 0;
- game_set_message(&s3,_("Zap it now!"),left_edge,225);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"2 + 2 = %s",_("Zap it now!"));
+ game_set_message(&s3, _("Zap it now!"), left_edge, 225);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "2 + 2 = %s", _("Zap it now!"));
- while (comets[0].alive && !(quit_help = help_renderframe_exit()));
+ while (comets[0].alive && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
- game_set_message(&s1,_("Great job!"),left_edge,100);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s",_("Great job!"));
-
+ game_set_message(&s1, _("Great job!"), left_edge, 100);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s", _("Great job!"));
+
comets_clear_message(&s2);
comets_clear_message(&s3);
timer = 0;
- while (((timer+=FC_time_elapsed) < 2) && !(quit_help = help_renderframe_exit()));
+ while (((timer += FC_time_elapsed) < 2) && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
check_extra_life();
timer = 0;
- while (((timer+=FC_time_elapsed) < 10) && !(quit_help = help_renderframe_exit()));
+ while (((timer += FC_time_elapsed) < 10) && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
/* Demo of "superbonus" powerup comet: */
help_controls.laser_enabled = 1;
- game_set_message(&s1,_("Fast-moving powerup comets"), left_edge,100);
- game_set_message(&s2,_("earn you a secret weapon:"), left_edge,135);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s",
- _("Fast-moving powerup comets"),_("earn you a secret weapon:"));
-
+ game_set_message(&s1, _("Fast-moving powerup comets"), left_edge, 100);
+ game_set_message(&s2, _("earn you a secret weapon:"), left_edge, 135);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s",
+ _("Fast-moving powerup comets"), _("earn you a secret weapon:"));
+
powerup_add_comet();
timer = 0;
- while (powerup_comet->comet.alive && ((timer+=FC_time_elapsed) < 1) && !(quit_help = help_renderframe_exit()));
+ while (powerup_comet->comet.alive && ((timer += FC_time_elapsed) < 1) && !(quit_help = help_renderframe_exit()))
+ ;
{
- if (quit_help)
- return;
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s",powerup_comet->comet.flashcard.formula_string);
- }
-
-
+ if (quit_help)
+ return;
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s", powerup_comet->comet.flashcard.formula_string);
+ }
+
if (powerup_comet->comet.alive)
powerup_comet->inc_speed = 0;
- game_set_message(&s3,_("Zap it now!"),left_edge,225);
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s",_("Zap it now!"));
+ game_set_message(&s3, _("Zap it now!"), left_edge, 225);
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s", _("Zap it now!"));
- while (powerup_comet->comet.alive && !(quit_help = help_renderframe_exit()));
+ while (powerup_comet->comet.alive && !(quit_help = help_renderframe_exit()))
+ ;
if (quit_help)
return;
- game_set_message(&s1,_("Quit at any time by pressing"),left_edge,100);
- game_set_message(&s2,_("'Esc' or clicking the 'X'"),left_edge,135);
- game_set_message(&s3,_("in the upper right corner."),left_edge,170);
- game_set_message(&s4,_("Do it now, and then play!"),left_edge,225);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s %s",
- _("Quit at any time by pressing"),_("'Esc' or clicking the 'X'"),
- _("in the upper right corner."),_("Do it now, and then play!"));
-
-
-
+ game_set_message(&s1, _("Quit at any time by pressing"), left_edge, 100);
+ game_set_message(&s2, _("'Esc' or clicking the 'X'"), left_edge, 135);
+ game_set_message(&s3, _("in the upper right corner."), left_edge, 170);
+ game_set_message(&s4, _("Do it now, and then play!"), left_edge, 225);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %s %s %s",
+ _("Quit at any time by pressing"), _("'Esc' or clicking the 'X'"),
+ _("in the upper right corner."), _("Do it now, and then play!"));
help_controls.x_is_blinking = 1;
- while (!help_renderframe_exit());
+ while (!help_renderframe_exit())
+ ;
}
// This function handles all the interactions expected during help
@@ -962,10 +959,10 @@ int help_renderframe_exit(void)
tux_pressing = 0;
int i;
- for(i=0;i 0)
- laser[i].alive -= 15*FC_time_elapsed;
+ laser[i].alive -= 15 * FC_time_elapsed;
}
comets_handle_user_events();
comets_handle_answer();
@@ -978,9 +975,9 @@ int help_renderframe_exit(void)
comets_handle_extra_life();
comets_draw();
comets_status = check_exit_conditions();
-
+
if (comets_status != GAME_IN_PROGRESS)
- stop_tts_announcer_thread();
+ stop_tts_announcer_thread();
// Delay to keep frame rate constant. Do this in a way
// that won't cause a freeze if the timer wraps around.
@@ -990,7 +987,7 @@ int help_renderframe_exit(void)
}
/* explicitly create a comet with a hardcoded problem */
-void help_add_comet(const char* formula_str, const char* ans_str)
+void help_add_comet(const char *formula_str, const char *ans_str)
{
// char probstr[MC_FORMULA_LEN];
// char ansstr[MC_ANSWER_LEN];
@@ -1005,28 +1002,30 @@ void help_add_comet(const char* formula_str, const char* ans_str)
comets[0].zapped = 0;
comets[0].bonus = 0;
- strncpy(comets[0].flashcard.formula_string,formula_str, MC_MaxFormulaSize() );
- strncpy(comets[0].flashcard.answer_string,ans_str,MC_MaxAnswerSize() );
- if(comets[0].formula_surf) SDL_FreeSurface(comets[0].formula_surf);
- if(comets[0].answer_surf) SDL_FreeSurface(comets[0].answer_surf);
+ strncpy(comets[0].flashcard.formula_string, formula_str, MC_MaxFormulaSize());
+ strncpy(comets[0].flashcard.answer_string, ans_str, MC_MaxAnswerSize());
+ if (comets[0].formula_surf)
+ SDL_FreeSurface(comets[0].formula_surf);
+ if (comets[0].answer_surf)
+ SDL_FreeSurface(comets[0].answer_surf);
comets[0].formula_surf = T4K_BlackOutline(comets[0].flashcard.formula_string, comet_fontsize, &white);
comets[0].answer_surf = T4K_BlackOutline(comets[0].flashcard.answer_string, comet_fontsize, &white);
}
-void game_set_message(game_message *msg,const char *txt,int x,int y)
+void game_set_message(game_message *msg, const char *txt, int x, int y)
{
if (msg && txt)
{
msg->x = x;
msg->y = y;
msg->alpha = SDL_ALPHA_OPAQUE;
- strncpy(msg->message,txt,GAME_MESSAGE_LENGTH);
+ strncpy(msg->message, txt, GAME_MESSAGE_LENGTH);
}
}
void comets_clear_message(game_message *msg)
{
- game_set_message(msg,"",0,0);
+ game_set_message(msg, "", 0, 0);
}
void comets_clear_messages()
@@ -1040,22 +1039,22 @@ void comets_clear_messages()
void comets_write_message(const game_message *msg)
{
- SDL_Surface* surf;
+ SDL_Surface *surf;
SDL_Rect rect;
if (strlen(msg->message) > 0)
{
- surf = T4K_BlackOutline( _(msg->message), DEFAULT_HELP_FONT_SIZE, &white);
- if(surf)
+ surf = T4K_BlackOutline(_(msg->message), DEFAULT_HELP_FONT_SIZE, &white);
+ if (surf)
{
rect.w = surf->w;
rect.h = surf->h;
if (msg->x < 0)
- rect.x = (screen->w/2) - (rect.w/2); // centered
+ rect.x = (screen->w / 2) - (rect.w / 2); // centered
else
- rect.x = msg->x; // left justified
+ rect.x = msg->x; // left justified
rect.y = msg->y;
- //FIXME alpha blending doesn't seem to work properly
+ // FIXME alpha blending doesn't seem to work properly
SDL_SetAlpha(surf, SDL_SRCALPHA, msg->alpha);
SDL_BlitSurface(surf, NULL, screen, &rect);
SDL_FreeSurface(surf);
@@ -1112,7 +1111,7 @@ void comets_handle_demo(void)
{
static int demo_answer = 0;
static int answer_digit = 0;
- static int picked_comet=-1;
+ static int picked_comet = -1;
if (picked_comet == -1 && (rand() % 10) < 3)
{
@@ -1120,8 +1119,8 @@ void comets_handle_demo(void)
picked_comet = (rand() % Opts_MaxComets());
if (!(comets[picked_comet].alive &&
- comets[picked_comet].expl == -1)
- || comets[picked_comet].y < 80)
+ comets[picked_comet].expl == -1) ||
+ comets[picked_comet].y < 80)
{
picked_comet = -1;
}
@@ -1130,9 +1129,9 @@ void comets_handle_demo(void)
/* found a comet to blow up! */
demo_answer = comets[picked_comet].answer;
if ((rand() % 3) < 1)
- demo_answer--; // sometimes get it wrong on purpose
+ demo_answer--; // sometimes get it wrong on purpose
- DEBUGMSG(debug_game, "Demo mode, comet %d attacked with answer %d\n", picked_comet,demo_answer);
+ DEBUGMSG(debug_game, "Demo mode, comet %d attacked with answer %d\n", picked_comet, demo_answer);
/* handle negative answer: */
if (demo_answer < 0)
@@ -1178,7 +1177,7 @@ void comets_handle_demo(void)
{
/* "Press Return" */
DEBUGMSG(debug_game, "Demo mode firing with these digits: %d%d%d\n",
- digits[0], digits[1], digits[2]);
+ digits[0], digits[1], digits[2]);
doing_answer = 1;
picked_comet = -1;
}
@@ -1192,8 +1191,8 @@ void comets_handle_demo(void)
void comets_handle_answer(void)
{
int i, j, num_zapped;
- int comets_answer[MAX_MAX_COMETS] = {-1};
- char ans[MC_MAX_DIGITS + 2]; //extra space for negative, and for final '\0'
+ int comets_answer[MAX_MAX_COMETS] = {-1};
+ char ans[MC_MAX_DIGITS + 2]; // extra space for negative, and for final '\0'
Uint32 ctime;
int powerup_ans = 0;
@@ -1206,8 +1205,9 @@ void comets_handle_answer(void)
/* negative answer support DSB */
- ans[0] = '-'; //for math questions only, this is just replaced.
- for (i = 0; i < MC_MAX_DIGITS - 1 && !digits[i]; ++i); //skip leading 0s
+ ans[0] = '-'; // for math questions only, this is just replaced.
+ for (i = 0; i < MC_MAX_DIGITS - 1 && !digits[i]; ++i)
+ ; // skip leading 0s
for (j = neg_answer_picked ? 1 : 0; i < MC_MAX_DIGITS; ++i, ++j)
ans[j] = digits[i] + '0';
ans[j] = '\0';
@@ -1220,8 +1220,8 @@ void comets_handle_answer(void)
for (i = 0; i < MAX_MAX_COMETS; i++)
{
if (comets[i].alive &&
- comets[i].expl == -1 &&
- (smartbomb_firing || 0 == strncmp(comets[i].flashcard.answer_string, ans, MC_MAX_DIGITS + 1)))
+ comets[i].expl == -1 &&
+ (smartbomb_firing || 0 == strncmp(comets[i].flashcard.answer_string, ans, MC_MAX_DIGITS + 1)))
{
comets_answer[num_zapped] = i;
num_zapped++;
@@ -1231,39 +1231,39 @@ void comets_handle_answer(void)
smartbomb_firing = 0;
/* powerup comet */
- if( powerup_comet->comet.alive &&
- strncmp(powerup_comet->comet.flashcard.answer_string, ans, MC_MAX_DIGITS + 1) == 0)
+ if (powerup_comet->comet.alive &&
+ strncmp(powerup_comet->comet.flashcard.answer_string, ans, MC_MAX_DIGITS + 1) == 0)
{
powerup_ans = 1;
}
/* If there was a comet with this answer, destroy it! */
- if (num_zapped != 0 || powerup_ans)
+ if (num_zapped != 0 || powerup_ans)
{
float t;
ctime = SDL_GetTicks();
/* Store the time the question was present on screen (do this */
/* in a way that avoids storing it if the time wrapped around */
- for(i = 0; i < num_zapped; i++)
+ for (i = 0; i < num_zapped; i++)
{
int index_comets = comets_answer[i];
if (ctime > comets[index_comets].time_started)
- t = ((float)(ctime - comets[index_comets].time_started)/1000);
+ t = ((float)(ctime - comets[index_comets].time_started) / 1000);
else
- t = -1; //Mathcards will ignore t == -1
+ t = -1; // Mathcards will ignore t == -1
/* Tell Mathcards or the server that we answered correctly: */
- if(Opts_LanMode())
+ if (Opts_LanMode())
#ifdef HAVE_LIBSDL_NET
LAN_AnsweredCorrectly(comets[index_comets].flashcard.question_id, t);
#else
- {} // Needed for compiler, even though this path can't occur
-#endif
+ {
+ } // Needed for compiler, even though this path can't occur
+#endif
else
{
MC_AnsweredCorrectly(curr_game, comets[index_comets].flashcard.question_id, t);
}
-
-
+
/* Destroy comet: */
comets[index_comets].expl = 0;
comets[index_comets].zapped = 1;
@@ -1273,35 +1273,35 @@ void comets_handle_answer(void)
laser[i].y1 = screen->h;
laser[i].x2 = comets[index_comets].x;
laser[i].y2 = comets[index_comets].y;
- if(num_zapped == 1)
+ if (num_zapped == 1)
{
playsound(SND_LASER);
playsound(SND_SIZZLE);
}
- else if(num_zapped > 1 && i == num_zapped-1) //only play sounds once for group
+ else if (num_zapped > 1 && i == num_zapped - 1) // only play sounds once for group
{
playsound(SND_LASER);
playsound(SND_SIZZLE);
playsound(SND_EXTRA_LIFE);
tux_anim = IMG_TUX_YES1;
- tux_anim_frame = ANIM_FRAME_START;
+ tux_anim_frame = ANIM_FRAME_START;
}
/* Record data for feedback */
if (Opts_UseFeedback())
{
comet_feedback_number++;
- comet_feedback_height += comets[index_comets].y/city_expl_height;
+ comet_feedback_height += comets[index_comets].y / city_expl_height;
#ifdef FEEDBACK_DEBUG
- fprintf(stderr, "Added comet feedback with height %g\n",comets[index_comets].y/city_expl_height);
+ fprintf(stderr, "Added comet feedback with height %g\n", comets[index_comets].y / city_expl_height);
#endif
}
/* Pick Tux animation: */
/* 50% of the time.. */
- if(num_zapped == 1)
+ if (num_zapped == 1)
{
if ((rand() % 10) < 5)
{
@@ -1312,7 +1312,7 @@ void comets_handle_answer(void)
tux_anim = IMG_TUX_YAY1;
tux_anim_frame = ANIM_FRAME_START;
}
- }
+ }
/* Increment score: */
@@ -1320,11 +1320,11 @@ void comets_handle_answer(void)
/* [ the higher the better ] */
/* FIXME looks like it might score a bit differently based on screen mode? */
add_score(25 * comets[index_comets].flashcard.difficulty *
- (screen->h - comets[index_comets].y + 1) /
- screen->h);
- }
+ (screen->h - comets[index_comets].y + 1) /
+ screen->h);
+ }
- if(powerup_ans)
+ if (powerup_ans)
{
powerup_comet->comet.expl = 0;
powerup_comet->comet.zapped = 1;
@@ -1340,16 +1340,17 @@ void comets_handle_answer(void)
* remaining questions will not be correct - DSB
*/
if (ctime > powerup_comet->comet.time_started)
- t = ((float)(ctime - powerup_comet->comet.time_started)/1000);
+ t = ((float)(ctime - powerup_comet->comet.time_started) / 1000);
else
- t = -1; //Mathcards will ignore t == -1
+ t = -1; // Mathcards will ignore t == -1
- if(Opts_LanMode())
+ if (Opts_LanMode())
#ifdef HAVE_LIBSDL_NET
LAN_AnsweredCorrectly(powerup_comet->comet.flashcard.question_id, t);
#else
- {} // Needed for compiler, even though this path can't occur
-#endif
+ {
+ } // Needed for compiler, even though this path can't occur
+#endif
else
MC_AnsweredCorrectly(curr_game, powerup_comet->comet.flashcard.question_id, t);
}
@@ -1375,7 +1376,6 @@ void comets_handle_answer(void)
for (i = 0; i < MC_MAX_DIGITS; ++i)
digits[i] = 0;
neg_answer_picked = 0;
-
}
void comets_countdown(void)
@@ -1386,7 +1386,7 @@ void comets_countdown(void)
return;
}
- //dim start messages
+ // dim start messages
s1.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
s2.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
s3.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
@@ -1413,8 +1413,10 @@ void comets_handle_tux(void)
/* If Tux pressed a button, pick a new (different!) stance: */
if (tux_pressing)
{
- do { tux_img = IMG_TUX_CONSOLE1 + (rand() % 4); }
- while (tux_img == old_tux_img);
+ do
+ {
+ tux_img = IMG_TUX_CONSOLE1 + (rand() % 4);
+ } while (tux_img == old_tux_img);
playsound(SND_TOCK);
}
@@ -1441,8 +1443,8 @@ void comets_handle_tux(void)
tux_same_counter = 0;
}
-//FIXME might be simpler to store vertical position (and speed) in terms of time
-//rather than absolute position, and determine the latter in comets_draw_comets()
+// FIXME might be simpler to store vertical position (and speed) in terms of time
+// rather than absolute position, and determine the latter in comets_draw_comets()
void comets_handle_comets(void)
{
/* Handle comets. Since the comets also are the things that trigger
@@ -1470,12 +1472,12 @@ void comets_handle_comets(void)
if (comets[i].bonus)
{
comets[i].y += FC_time_elapsed * speed * Opts_BonusSpeedRatio() *
- city_expl_height / (480 - images[IMG_CITY_BLUE]->h);
+ city_expl_height / (480 - images[IMG_CITY_BLUE]->h);
}
else /* Regular comet: */
{
comets[i].y += FC_time_elapsed * speed *
- city_expl_height / (480 - images[IMG_CITY_BLUE]->h);
+ city_expl_height / (480 - images[IMG_CITY_BLUE]->h);
}
/* Does it threaten a city? */
@@ -1484,34 +1486,36 @@ void comets_handle_comets(void)
/* Did it hit a city? */
if (comets[i].y >= city_expl_height &&
- comets[i].expl == -1)
- /* Oh no - an igloo or city has been hit! */
+ comets[i].expl == -1)
+ /* Oh no - an igloo or city has been hit! */
{
/* Tell MathCards about it - question not answered correctly: */
- if(Opts_LanMode())
+ if (Opts_LanMode())
#ifdef HAVE_LIBSDL_NET
LAN_NotAnsweredCorrectly(comets[i].flashcard.question_id);
#else
- {}
+ {
+ }
#endif
else
MC_NotAnsweredCorrectly(curr_game, comets[i].flashcard.question_id);
-
/* Destroy comet: */
comets[i].expl = 0;
/* Store the time the question was present on screen (do this */
/* in a way that avoids storing it if the time wrapped around */
ctime = SDL_GetTicks();
- if (ctime > comets[i].time_started) {
- MC_AddTimeToList(curr_game, (float)(ctime - comets[i].time_started)/1000);
+ if (ctime > comets[i].time_started)
+ {
+ MC_AddTimeToList(curr_game, (float)(ctime - comets[i].time_started) / 1000);
}
/* Record data for speed feedback */
/* Do this only for cities that are alive; dead cities */
/* might not get much protection from the player */
- if (Opts_UseFeedback() && cities[this_city].hits_left) {
+ if (Opts_UseFeedback() && cities[this_city].hits_left)
+ {
comet_feedback_number++;
comet_feedback_height += 1.0 + Opts_CityExplHandicap();
@@ -1525,18 +1529,22 @@ void comets_handle_comets(void)
if (cities[this_city].hits_left)
{
cities[this_city].status = CITY_EXPLODING;
- if (Opts_GetGlobalOpt(USE_IGLOOS)) {
+ if (Opts_GetGlobalOpt(USE_IGLOOS))
+ {
playsound(SND_IGLOO_SIZZLE);
cities[this_city].counter = IGLOO_SWITCH_START;
steam[this_city].status = STEAM_ON;
steam[this_city].counter = STEAM_START;
}
- else {
- if (cities[comets[i].city].hits_left == 2) {
+ else
+ {
+ if (cities[comets[i].city].hits_left == 2)
+ {
playsound(SND_SHIELDSDOWN);
- cities[this_city].counter = 1; /* Will act immediately */
+ cities[this_city].counter = 1; /* Will act immediately */
}
- else {
+ else
+ {
playsound(SND_EXPLOSION);
cities[this_city].counter = CITY_EXPL_START;
}
@@ -1546,37 +1554,45 @@ void comets_handle_comets(void)
/* If this was a bonus comet, restart the counter */
if (comets[i].bonus)
- bonus_comet_counter = Opts_BonusCometInterval()+1;
+ bonus_comet_counter = Opts_BonusCometInterval() + 1;
/* If slow_after_wrong selected, set flag to go back to starting speed and */
/* number of attacking comets: */
if (Opts_SlowAfterWrong())
{
- speed = Opts_Speed()*15; //The old fps limit was 15;
+ speed = Opts_Speed() * 15; // The old fps limit was 15;
slowdown = 1;
}
tux_anim = IMG_TUX_FIST1;
tux_anim_frame = ANIM_FRAME_START;
-
}
/* Handle animation of any comets that are "exploding": */
if (comets[i].expl >= 0)
{
comets[i].expl++;
- if (comets[i].expl >= sprites[IMG_COMET_EXPL]->num_frames * 2) {
+ if (comets[i].expl >= sprites[IMG_COMET_EXPL]->num_frames * 2)
+ {
comets[i].alive = 0;
comets[i].expl = -1;
- if(comets[i].answer_surf)
- {SDL_FreeSurface(comets[i].answer_surf); comets[i].answer_surf = NULL; }
- if(comets[i].formula_surf)
- {SDL_FreeSurface(comets[i].formula_surf); comets[i].formula_surf = NULL; }
- if (bonus_comet_counter > 1 && comets[i].zapped) {
+ if (comets[i].answer_surf)
+ {
+ SDL_FreeSurface(comets[i].answer_surf);
+ comets[i].answer_surf = NULL;
+ }
+ if (comets[i].formula_surf)
+ {
+ SDL_FreeSurface(comets[i].formula_surf);
+ comets[i].formula_surf = NULL;
+ }
+ if (bonus_comet_counter > 1 && comets[i].zapped)
+ {
bonus_comet_counter--;
- DEBUGMSG(debug_game, "bonus_comet_counter is now %d\n",bonus_comet_counter);
+ DEBUGMSG(debug_game, "bonus_comet_counter is now %d\n", bonus_comet_counter);
}
- if (comets[i].bonus && comets[i].zapped) {
+ if (comets[i].bonus && comets[i].zapped)
+ {
playsound(SND_EXTRA_LIFE);
extra_life_earned = 1;
DEBUGMSG(debug_game, "Extra life earned!");
@@ -1596,18 +1612,15 @@ void comets_handle_comets(void)
if (level_start_wait > 0)
return;
-
-
/* In LAN mode, the server keeps track of when to add comets
* and when to go on to the next level.
*/
- if(!Opts_LanMode())
+ if (!Opts_LanMode())
{
/* num_attackers is how many comets are left in wave */
- if (num_attackers <= 0) /* Go on to next wave */
+ if (num_attackers <= 0) /* Go on to next wave */
{
- if (!num_comets_alive()
- && !check_extra_life())
+ if (!num_comets_alive() && !check_extra_life())
{
wave++;
reset_level();
@@ -1623,7 +1636,6 @@ void comets_handle_comets(void)
}
}
-
void comets_handle_cities(void)
{
/* Update the status of the cities. These also determine the changes
@@ -1643,15 +1655,20 @@ void comets_handle_cities(void)
if (cities[i].status == CITY_EXPLODING)
{
cities[i].counter--;
- if (cities[i].counter == 0) {
+ if (cities[i].counter == 0)
+ {
if (cities[i].hits_left)
cities[i].status = CITY_PRESENT;
- else {
- if (Opts_GetGlobalOpt(USE_IGLOOS)) {
+ else
+ {
+ if (Opts_GetGlobalOpt(USE_IGLOOS))
+ {
cities[i].status = CITY_EVAPORATING;
cities[i].counter = EVAPORATING_COUNTER_START;
cities[i].img = IMG_IGLOO_MELTED1;
- } else {
+ }
+ else
+ {
cities[i].status = CITY_GONE;
cities[i].img = IMG_CITY_NONE;
}
@@ -1659,23 +1676,30 @@ void comets_handle_cities(void)
}
}
/* Choose the correct city/igloo image */
- if (Opts_GetGlobalOpt(USE_IGLOOS)) {
- if (cities[i].status == CITY_EVAPORATING) {
+ if (Opts_GetGlobalOpt(USE_IGLOOS))
+ {
+ if (cities[i].status == CITY_EVAPORATING)
+ {
/* Handle the evaporation animation */
- cities[i].layer = 0; /* these have to be drawn below the penguin */
+ cities[i].layer = 0; /* these have to be drawn below the penguin */
cities[i].counter--;
- if (cities[i].counter == 0) {
+ if (cities[i].counter == 0)
+ {
cities[i].img--;
- if (cities[i].img < IMG_IGLOO_MELTED3) {
+ if (cities[i].img < IMG_IGLOO_MELTED3)
+ {
cities[i].img = IMG_CITY_NONE;
cities[i].status = CITY_GONE;
}
else
cities[i].counter = EVAPORATING_COUNTER_START;
}
- } else {
- if (cities[i].status != CITY_GONE) {
- cities[i].layer = 1; /* these have to be drawn above the penguin */
+ }
+ else
+ {
+ if (cities[i].status != CITY_GONE)
+ {
+ cities[i].layer = 1; /* these have to be drawn above the penguin */
cities[i].img = IMG_IGLOO_MELTED1 + cities[i].hits_left;
/* If we're in the middle of an "explosion," don't switch to the
new igloo. Note the steam may have a different counter than
@@ -1686,9 +1710,10 @@ void comets_handle_cities(void)
}
}
}
- else {
+ else
+ {
/* We're using the original "city" graphics */
- cities[i].layer = 0; /* No layering needed */
+ cities[i].layer = 0; /* No layering needed */
if (cities[i].hits_left)
cities[i].img = IMG_CITY_BLUE;
else if (cities[i].status == CITY_EXPLODING)
@@ -1698,115 +1723,122 @@ void comets_handle_cities(void)
/* Change image to appropriate color: */
cities[i].img = cities[i].img + ((wave % MAX_CITY_COLORS) *
- (IMG_CITY_GREEN - IMG_CITY_BLUE));
-
+ (IMG_CITY_GREEN - IMG_CITY_BLUE));
}
}
}
-
void comets_handle_penguins(void)
{
- int i,direction,walk_counter;
+ int i, direction, walk_counter;
if (!Opts_GetGlobalOpt(USE_IGLOOS))
return;
- for (i = 0; i < NUM_CITIES; i++) {
+ for (i = 0; i < NUM_CITIES; i++)
+ {
penguins[i].layer = 0;
if (cities[i].status == CITY_EVAPORATING)
- penguins[i].layer = 1; /* will go higher in certain cases */
+ penguins[i].layer = 1; /* will go higher in certain cases */
/* Handle interaction with comets & city status (ducking) */
- if (cities[i].threatened && penguins[i].status < PENGUIN_WALKING_OFF
- && penguins[i].status != PENGUIN_OFFSCREEN)
+ if (cities[i].threatened && penguins[i].status < PENGUIN_WALKING_OFF && penguins[i].status != PENGUIN_OFFSCREEN)
penguins[i].status = PENGUIN_DUCKING;
- else if (!cities[i].threatened && penguins[i].status == PENGUIN_DUCKING) {
+ else if (!cities[i].threatened && penguins[i].status == PENGUIN_DUCKING)
+ {
if (cities[i].hits_left == 2)
penguins[i].status = PENGUIN_HAPPY;
else
penguins[i].status = PENGUIN_GRUMPY;
}
- switch (penguins[i].status) {
- case PENGUIN_HAPPY:
+ switch (penguins[i].status)
+ {
+ case PENGUIN_HAPPY:
+ penguins[i].img = IMG_PENGUIN_FLAPDOWN;
+ if (rand() % FLAPPING_INTERVAL == 0)
+ {
+ penguins[i].status = PENGUIN_FLAPPING;
+ penguins[i].counter = FLAPPING_START;
+ }
+ break;
+ case PENGUIN_FLAPPING:
+ if (penguins[i].counter % 4 >= 2)
+ penguins[i].img = IMG_PENGUIN_FLAPUP;
+ else
penguins[i].img = IMG_PENGUIN_FLAPDOWN;
- if (rand() % FLAPPING_INTERVAL == 0) {
- penguins[i].status = PENGUIN_FLAPPING;
- penguins[i].counter = FLAPPING_START;
- }
- break;
- case PENGUIN_FLAPPING:
- if (penguins[i].counter % 4 >= 2)
- penguins[i].img = IMG_PENGUIN_FLAPUP;
- else
- penguins[i].img = IMG_PENGUIN_FLAPDOWN;
- penguins[i].counter--;
- if (penguins[i].counter == 0)
- penguins[i].status = PENGUIN_HAPPY;
- break;
- case PENGUIN_DUCKING:
- penguins[i].img = IMG_PENGUIN_INCOMING;
- break;
- case PENGUIN_GRUMPY:
- penguins[i].img = IMG_PENGUIN_GRUMPY;
- if (rand() % FLAPPING_INTERVAL == 0) {
- penguins[i].status = PENGUIN_WORRIED;
- penguins[i].counter = FLAPPING_START;
- }
- break;
- case PENGUIN_WORRIED:
- penguins[i].img = IMG_PENGUIN_WORRIED;
- penguins[i].counter--;
- if (penguins[i].counter == 0)
- penguins[i].status = PENGUIN_GRUMPY;
- break;
- case PENGUIN_STANDING_UP:
- penguins[i].img = IMG_PENGUIN_STANDING_UP;
- penguins[i].counter--;
- if (penguins[i].counter == 0)
- penguins[i].status = PENGUIN_WALKING_OFF;
- break;
- case PENGUIN_SITTING_DOWN:
- penguins[i].img = IMG_PENGUIN_SITTING_DOWN;
- penguins[i].counter--;
- if (penguins[i].counter == 0) {
- penguins[i].status = PENGUIN_FLAPPING;
- penguins[i].counter = FLAPPING_START;
- }
- break;
- case PENGUIN_WALKING_ON:
- walk_counter = (penguins[i].counter % 8)/2;
- if (walk_counter == 3)
- walk_counter = 1;
- penguins[i].img = IMG_PENGUIN_WALK_ON1 + walk_counter;
- penguins[i].counter++;
- direction = 2*(i < NUM_CITIES/2)-1; /* +1 for walk right, -1 for left */
- penguins[i].x += FC_time_elapsed*direction*PENGUIN_WALK_SPEED;
- if (direction*penguins[i].x >= direction*cities[i].x) {
- penguins[i].status = PENGUIN_SITTING_DOWN;
- penguins[i].counter = STANDING_COUNTER_START;
- penguins[i].x = cities[i].x;
- }
- penguins[i].layer = 3; /* Stand in front of steam */
- break;
- case PENGUIN_WALKING_OFF:
- walk_counter = (penguins[i].counter % 8)/2;
- if (walk_counter == 3)
- walk_counter = 1;
- penguins[i].img = IMG_PENGUIN_WALK_OFF1 + walk_counter;
- penguins[i].counter++;
- direction = 1-2*(i < NUM_CITIES/2);
- penguins[i].x += FC_time_elapsed*direction*PENGUIN_WALK_SPEED;
- if (direction < 0) {
- if (penguins[i].x + images[IMG_PENGUIN_WALK_OFF1]->w/2 <= 0)
- penguins[i].status = PENGUIN_OFFSCREEN;
- } else {
- if (penguins[i].x - images[IMG_PENGUIN_WALK_OFF1]->w/2 >= screen->w)
- penguins[i].status = PENGUIN_OFFSCREEN;
- }
- penguins[i].layer = 3;
- break;
- case PENGUIN_OFFSCREEN:
- penguins[i].img = -1;
- break;
+ penguins[i].counter--;
+ if (penguins[i].counter == 0)
+ penguins[i].status = PENGUIN_HAPPY;
+ break;
+ case PENGUIN_DUCKING:
+ penguins[i].img = IMG_PENGUIN_INCOMING;
+ break;
+ case PENGUIN_GRUMPY:
+ penguins[i].img = IMG_PENGUIN_GRUMPY;
+ if (rand() % FLAPPING_INTERVAL == 0)
+ {
+ penguins[i].status = PENGUIN_WORRIED;
+ penguins[i].counter = FLAPPING_START;
+ }
+ break;
+ case PENGUIN_WORRIED:
+ penguins[i].img = IMG_PENGUIN_WORRIED;
+ penguins[i].counter--;
+ if (penguins[i].counter == 0)
+ penguins[i].status = PENGUIN_GRUMPY;
+ break;
+ case PENGUIN_STANDING_UP:
+ penguins[i].img = IMG_PENGUIN_STANDING_UP;
+ penguins[i].counter--;
+ if (penguins[i].counter == 0)
+ penguins[i].status = PENGUIN_WALKING_OFF;
+ break;
+ case PENGUIN_SITTING_DOWN:
+ penguins[i].img = IMG_PENGUIN_SITTING_DOWN;
+ penguins[i].counter--;
+ if (penguins[i].counter == 0)
+ {
+ penguins[i].status = PENGUIN_FLAPPING;
+ penguins[i].counter = FLAPPING_START;
+ }
+ break;
+ case PENGUIN_WALKING_ON:
+ walk_counter = (penguins[i].counter % 8) / 2;
+ if (walk_counter == 3)
+ walk_counter = 1;
+ penguins[i].img = IMG_PENGUIN_WALK_ON1 + walk_counter;
+ penguins[i].counter++;
+ direction = 2 * (i < NUM_CITIES / 2) - 1; /* +1 for walk right, -1 for left */
+ penguins[i].x += FC_time_elapsed * direction * PENGUIN_WALK_SPEED;
+ if (direction * penguins[i].x >= direction * cities[i].x)
+ {
+ penguins[i].status = PENGUIN_SITTING_DOWN;
+ penguins[i].counter = STANDING_COUNTER_START;
+ penguins[i].x = cities[i].x;
+ }
+ penguins[i].layer = 3; /* Stand in front of steam */
+ break;
+ case PENGUIN_WALKING_OFF:
+ walk_counter = (penguins[i].counter % 8) / 2;
+ if (walk_counter == 3)
+ walk_counter = 1;
+ penguins[i].img = IMG_PENGUIN_WALK_OFF1 + walk_counter;
+ penguins[i].counter++;
+ direction = 1 - 2 * (i < NUM_CITIES / 2);
+ penguins[i].x += FC_time_elapsed * direction * PENGUIN_WALK_SPEED;
+ if (direction < 0)
+ {
+ if (penguins[i].x + images[IMG_PENGUIN_WALK_OFF1]->w / 2 <= 0)
+ penguins[i].status = PENGUIN_OFFSCREEN;
+ }
+ else
+ {
+ if (penguins[i].x - images[IMG_PENGUIN_WALK_OFF1]->w / 2 >= screen->w)
+ penguins[i].status = PENGUIN_OFFSCREEN;
+ }
+ penguins[i].layer = 3;
+ break;
+ case PENGUIN_OFFSCREEN:
+ penguins[i].img = -1;
+ break;
}
}
}
@@ -1817,16 +1849,21 @@ void comets_handle_steam(void)
if (!Opts_GetGlobalOpt(USE_IGLOOS))
return;
- for (i = 0; i < NUM_CITIES; i++) {
- if (steam[i].counter) {
+ for (i = 0; i < NUM_CITIES; i++)
+ {
+ if (steam[i].counter)
+ {
steam[i].counter--;
- if (!steam[i].counter) {
+ if (!steam[i].counter)
+ {
steam[i].status = STEAM_OFF;
- if (cloud.status != EXTRA_LIFE_ON || cloud.city != i) {
+ if (cloud.status != EXTRA_LIFE_ON || cloud.city != i)
+ {
/* The penguin was ducking, now we can stop */
if (cities[i].hits_left)
penguins[i].status = PENGUIN_GRUMPY;
- else {
+ else
+ {
penguins[i].status = PENGUIN_STANDING_UP;
penguins[i].counter = STANDING_COUNTER_START;
}
@@ -1835,8 +1872,9 @@ void comets_handle_steam(void)
}
if (steam[i].status == STEAM_OFF)
steam[i].img = -1;
- else {
- steam[i].img = IMG_STEAM5 - steam[i].counter/3;
+ else
+ {
+ steam[i].img = IMG_STEAM5 - steam[i].counter / 3;
steam[i].layer = 2;
}
}
@@ -1846,100 +1884,111 @@ int check_extra_life(void)
{
/* This is called at the end of a wave. Returns 1 if we're in the
middle of handling an extra life, otherwise 0 */
- int i,fewest_hits_left,fewest_index,snow_width;
+ int i, fewest_hits_left, fewest_index, snow_width;
if (cloud.status == EXTRA_LIFE_ON)
return 1;
DEBUGCODE(debug_game)
- print_status();
+ print_status();
- if (extra_life_earned) {
+ if (extra_life_earned)
+ {
/* Check to see if any ingloo has been hit */
fewest_hits_left = 2;
fewest_index = -1;
- for (i = 0; i < NUM_CITIES; i++) {
- if (cities[i].hits_left < fewest_hits_left) {
+ for (i = 0; i < NUM_CITIES; i++)
+ {
+ if (cities[i].hits_left < fewest_hits_left)
+ {
fewest_hits_left = cities[i].hits_left;
fewest_index = i;
}
}
if (fewest_hits_left == 2)
- return 0; /* Don't need an extra life, there's no damage */
-
+ return 0; /* Don't need an extra life, there's no damage */
+
/* Begin the extra life sequence */
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,_("fixing ingloo damage! ...."));
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, _("fixing ingloo damage! ...."));
extra_life_earned = 0;
cloud.status = EXTRA_LIFE_ON;
- cloud.y = screen->h/3;
+ cloud.y = screen->h / 3;
cloud.city = fewest_index;
- bonus_comet_counter = Opts_BonusCometInterval()+1;
+ bonus_comet_counter = Opts_BonusCometInterval() + 1;
- DEBUGMSG(debug_game, "Bonus comet counter restored to %d\n",bonus_comet_counter);
+ DEBUGMSG(debug_game, "Bonus comet counter restored to %d\n", bonus_comet_counter);
- if (cloud.city < NUM_CITIES/2)
- cloud.x = -images[IMG_CLOUD]->w/2; /* come in from the left */
+ if (cloud.city < NUM_CITIES / 2)
+ cloud.x = -images[IMG_CLOUD]->w / 2; /* come in from the left */
else
- cloud.x = screen->w + images[IMG_CLOUD]->w/2; /* come from the right */
+ cloud.x = screen->w + images[IMG_CLOUD]->w / 2; /* come from the right */
penguins[cloud.city].status = PENGUIN_WALKING_ON;
/* initialize the snowflakes */
snow_width = images[IMG_CLOUD]->w - images[IMG_SNOW1]->w;
- for (i = 0; i < NUM_SNOWFLAKES; i++) {
- cloud.snowflake_y[i] = cloud.y - i*SNOWFLAKE_SEPARATION;
- cloud.snowflake_x[i] = - snow_width/2 + (rand() % snow_width);
+ for (i = 0; i < NUM_SNOWFLAKES; i++)
+ {
+ cloud.snowflake_y[i] = cloud.y - i * SNOWFLAKE_SEPARATION;
+ cloud.snowflake_x[i] = -snow_width / 2 + (rand() % snow_width);
cloud.snowflake_size[i] = rand() % 3;
}
DEBUGCODE(debug_game)
- print_status();
+ print_status();
return 1;
}
else
return 0;
}
-
void comets_handle_extra_life(void)
{
// This handles the animation sequence during the rebuilding of an igloo
int i, igloo_top, num_below_igloo, direction;
- if (cloud.status == EXTRA_LIFE_ON) {
+ if (cloud.status == EXTRA_LIFE_ON)
+ {
DEBUGCODE(debug_game)
{
- if (penguins[cloud.city].status == PENGUIN_WALKING_OFF) {
+ if (penguins[cloud.city].status == PENGUIN_WALKING_OFF)
+ {
print_status();
pause_game();
}
}
// Get the cloud moving in the right direction, if not yet "parked"
- direction = 2*(cloud.city < NUM_CITIES/2) - 1;
- if (direction*cloud.x < direction*cities[cloud.city].x) {
- cloud.x += FC_time_elapsed*direction*PENGUIN_WALK_SPEED;
+ direction = 2 * (cloud.city < NUM_CITIES / 2) - 1;
+ if (direction * cloud.x < direction * cities[cloud.city].x)
+ {
+ cloud.x += FC_time_elapsed * direction * PENGUIN_WALK_SPEED;
}
- else {
+ else
+ {
// Cloud is "parked," handle the snowfall and igloo rebuilding
cities[cloud.city].status = CITY_REBUILDING;
- igloo_top = screen->h - igloo_vertical_offset
- - images[IMG_IGLOO_INTACT]->h;
- for (i = 0, num_below_igloo = 0; i < NUM_SNOWFLAKES; i++) {
- cloud.snowflake_y[i] += FC_time_elapsed*SNOWFLAKE_SPEED;
+ igloo_top = screen->h - igloo_vertical_offset - images[IMG_IGLOO_INTACT]->h;
+ for (i = 0, num_below_igloo = 0; i < NUM_SNOWFLAKES; i++)
+ {
+ cloud.snowflake_y[i] += FC_time_elapsed * SNOWFLAKE_SPEED;
if (cloud.snowflake_y[i] > igloo_top)
num_below_igloo++;
}
- if (cloud.snowflake_y[NUM_SNOWFLAKES-1] > igloo_top) {
+ if (cloud.snowflake_y[NUM_SNOWFLAKES - 1] > igloo_top)
+ {
cities[cloud.city].hits_left = 2;
cities[cloud.city].img = IMG_IGLOO_INTACT; // completely rebuilt
- } else if (cities[cloud.city].hits_left == 0) {
+ }
+ else if (cities[cloud.city].hits_left == 0)
+ {
// We're going to draw one of the blended igloos
// FIXME: It's a hack to encode a blended igloo with a negative number!
penguins[cloud.city].layer = 0;
cities[cloud.city].layer = 1;
if (num_below_igloo < 3)
- num_below_igloo = 0; // Don't show progress until a few have fallen
- cities[cloud.city].img = -((float) (num_below_igloo)/NUM_SNOWFLAKES) * NUM_BLENDED_IGLOOS;
+ num_below_igloo = 0; // Don't show progress until a few have fallen
+ cities[cloud.city].img = -((float)(num_below_igloo) / NUM_SNOWFLAKES) * NUM_BLENDED_IGLOOS;
}
- if (cloud.snowflake_y[NUM_SNOWFLAKES-1] > screen->h - igloo_vertical_offset) {
+ if (cloud.snowflake_y[NUM_SNOWFLAKES - 1] > screen->h - igloo_vertical_offset)
+ {
/* exit rebuilding when last snowflake at igloo bottom */
cloud.status = EXTRA_LIFE_OFF;
cities[cloud.city].status = CITY_PRESENT;
@@ -1957,7 +2006,7 @@ void comets_draw(void)
/* Draw miscellaneous informational items */
comets_draw_misc(curr_game, wave, extra_life_earned, bonus_comet_counter,
- score, total_questions_left, &help_controls);
+ score, total_questions_left, &help_controls);
/* Draw cities/igloos and (if applicable) penguins: */
comets_draw_cities(igloo_vertical_offset, &cloud, cities, penguins, steam);
@@ -1973,14 +2022,14 @@ void comets_draw(void)
/* Draw laser: */
int i;
- for(i = 0; i < MAX_LASER; i++)
+ for (i = 0; i < MAX_LASER; i++)
{
if (laser[i].alive > 0)
{
draw_line(screen, laser[i].x1, laser[i].y1, laser[i].x2, laser[i].y2,
- 255 / ((LASER_START + 1) - laser[i].alive),
- 192 / ((LASER_START + 1) - laser[i].alive),
- 64);
+ 255 / ((LASER_START + 1) - laser[i].alive),
+ 192 / ((LASER_START + 1) - laser[i].alive),
+ 64);
}
}
@@ -1989,7 +2038,7 @@ void comets_draw(void)
{
/* pick image to draw: */
int keypad_image;
- if (MC_GetOpt(curr_game, ALLOW_NEGATIVES) )
+ if (MC_GetOpt(curr_game, ALLOW_NEGATIVES))
{
/* draw regular keypad */
keypad_image = IMG_KEYPAD;
@@ -2017,7 +2066,7 @@ void comets_draw(void)
#ifdef HAVE_LIBSDL_NET
/* Display message indicating that a player left */
- if(player_left_surf != NULL && (SDL_GetTicks() - player_left_time) < 2000)
+ if (player_left_surf != NULL && (SDL_GetTicks() - player_left_time) < 2000)
SDL_BlitSurface(player_left_surf, NULL, T4K_GetScreen(), &player_left_pos);
#endif
@@ -2025,7 +2074,6 @@ void comets_draw(void)
SDL_Flip(screen);
}
-
int check_exit_conditions(void)
{
// int x;
@@ -2033,13 +2081,13 @@ int check_exit_conditions(void)
if (user_quit_received)
{
if (user_quit_received != GAME_OVER_WINDOW_CLOSE &&
- user_quit_received != GAME_OVER_ESCAPE &&
- user_quit_received != GAME_OVER_CHEATER)
+ user_quit_received != GAME_OVER_ESCAPE &&
+ user_quit_received != GAME_OVER_CHEATER)
{
fprintf(stderr, "Unexpected value %d for user_quit_received\n", user_quit_received);
return GAME_OVER_OTHER;
}
- return user_quit_received;
+ return user_quit_received;
}
/* determine if game lost (i.e. all igloos melted): */
@@ -2053,44 +2101,42 @@ int check_exit_conditions(void)
}
/* determine if game won (i.e. all questions in mission answered correctly): */
- if(Opts_LanMode())
+ if (Opts_LanMode())
{
- //Different victory display for LAN multiplayer game:
- if(game_over_won)
+ // Different victory display for LAN multiplayer game:
+ if (game_over_won)
return GAME_OVER_LAN_WON;
- //Also report if we lost the server:
- if(network_error)
+ // Also report if we lost the server:
+ if (network_error)
return GAME_OVER_LAN_DISCONNECT;
- //Also report if the server aborted the game:
- if(comets_halted_by_server)
+ // Also report if the server aborted the game:
+ if (comets_halted_by_server)
return GAME_OVER_LAN_HALTED;
}
else
{
if (MC_MissionAccomplished(curr_game))
{
- DEBUGMSG(debug_game,"Mission accomplished!\n");
+ DEBUGMSG(debug_game, "Mission accomplished!\n");
return GAME_OVER_WON;
}
}
-
/* Could have situation where mathcards doesn't have more questions */
/* even though not all questions answered correctly: */
- if(Opts_LanMode())
+ if (Opts_LanMode())
{
- if(game_over_other)
+ if (game_over_other)
return GAME_OVER_OTHER;
}
else
{
- if(!MC_TotalQuestionsLeft(curr_game))
+ if (!MC_TotalQuestionsLeft(curr_game))
return GAME_OVER_OTHER;
}
-
- //NOTE can't use this check in LAN mode because we don't know if the server has
- //questions left
+ // NOTE can't use this check in LAN mode because we don't know if the server has
+ // questions left
/* Need to get out if no comets alive and MathCards has no questions left in list, */
/* even though MathCards thinks there are still questions "in play". */
@@ -2104,12 +2150,12 @@ int check_exit_conditions(void)
DEBUGMSG(debug_game, "num_comets_alive() = %d", num_comets_alive());
return GAME_OVER_ERROR;
}
- }
+ }
/* If using demo mode, see if counter has run out: */
if (Opts_DemoMode())
{
- if (demo_countdown <= 0 )
+ if (demo_countdown <= 0)
return GAME_OVER_OTHER;
}
@@ -2117,76 +2163,74 @@ int check_exit_conditions(void)
return GAME_IN_PROGRESS;
}
-
void print_exit_conditions(void)
{
fprintf(stderr, "\ncomets_status:\t");
switch (comets_status)
{
- case GAME_IN_PROGRESS:
- {
- fprintf(stderr, "GAME_IN_PROGRESS\n");
- break;
- }
- case GAME_OVER_WON:
- {
- fprintf(stderr, "comets_OVER_WON\n");
- break;
- }
- case GAME_OVER_LOST:
- {
- fprintf(stderr, "GAME_OVER_LOST\n");
- break;
- }
- case GAME_OVER_OTHER:
- {
- fprintf(stderr, "GAME_OVER_OTHER\n");
- break;
- }
- case GAME_OVER_ESCAPE:
- {
- fprintf(stderr, "GAME_OVER_ESCAPE\n");
- print_status();
- break;
- }
- case GAME_OVER_WINDOW_CLOSE:
- {
- fprintf(stderr, "GAME_OVER_WINDOW_CLOSE\n");
- break;
- }
- case GAME_OVER_LAN_HALTED:
- {
- fprintf(stderr, "GAME_OVER_LAN_HALTED\n");
- break;
- }
- case GAME_OVER_LAN_DISCONNECT:
- {
- fprintf(stderr, "GAME_OVER_LAN_DISCONNECT\n");
- break;
- }
- case GAME_OVER_LAN_WON:
- {
- fprintf(stderr, "GAME_OVER_LAN_WON\n");
- break;
- }
- case GAME_OVER_ERROR:
- {
- fprintf(stderr, "GAME_OVER_ERROR\n");
- break;
- }
- default:
- {
- fprintf(stderr, "Unrecognized value\n");
- break;
- }
+ case GAME_IN_PROGRESS:
+ {
+ fprintf(stderr, "GAME_IN_PROGRESS\n");
+ break;
+ }
+ case GAME_OVER_WON:
+ {
+ fprintf(stderr, "comets_OVER_WON\n");
+ break;
+ }
+ case GAME_OVER_LOST:
+ {
+ fprintf(stderr, "GAME_OVER_LOST\n");
+ break;
+ }
+ case GAME_OVER_OTHER:
+ {
+ fprintf(stderr, "GAME_OVER_OTHER\n");
+ break;
+ }
+ case GAME_OVER_ESCAPE:
+ {
+ fprintf(stderr, "GAME_OVER_ESCAPE\n");
+ print_status();
+ break;
+ }
+ case GAME_OVER_WINDOW_CLOSE:
+ {
+ fprintf(stderr, "GAME_OVER_WINDOW_CLOSE\n");
+ break;
+ }
+ case GAME_OVER_LAN_HALTED:
+ {
+ fprintf(stderr, "GAME_OVER_LAN_HALTED\n");
+ break;
+ }
+ case GAME_OVER_LAN_DISCONNECT:
+ {
+ fprintf(stderr, "GAME_OVER_LAN_DISCONNECT\n");
+ break;
+ }
+ case GAME_OVER_LAN_WON:
+ {
+ fprintf(stderr, "GAME_OVER_LAN_WON\n");
+ break;
+ }
+ case GAME_OVER_ERROR:
+ {
+ fprintf(stderr, "GAME_OVER_ERROR\n");
+ break;
+ }
+ default:
+ {
+ fprintf(stderr, "Unrecognized value\n");
+ break;
+ }
}
}
-
void comets_handle_game_over(int game_status)
{
DEBUGCODE(debug_game)
- {
+ {
fprintf(stderr, "Entering comets_handle_comets_over() - game status = %d\n", game_status);
print_exit_conditions();
}
@@ -2194,7 +2238,7 @@ void comets_handle_game_over(int game_status)
/* For turn-based multiplayer, don't show victory screen after
* each player's "game":
*/
- if(mp_get_parameter(PLAYERS))
+ if (mp_get_parameter(PLAYERS))
return;
/* TODO: need better "victory" screen with animation, special music, etc., */
@@ -2206,293 +2250,276 @@ void comets_handle_game_over(int game_status)
SDL_Rect dest_tux;
SDL_Event event;
- case GAME_OVER_WON:
+ case GAME_OVER_WON:
+ {
+ int looping = 1;
+ int tux_offset = 0;
+ int tux_step = -3;
+
+ /* set up victory message: */
+ dest_message.x = (screen->w - images[IMG_GAMEOVER_WON]->w) / 2;
+ dest_message.y = (screen->h - images[IMG_GAMEOVER_WON]->h) / 2;
+ dest_message.w = images[IMG_GAMEOVER_WON]->w;
+ dest_message.h = images[IMG_GAMEOVER_WON]->h;
+
+ // stop_tts_announcer_thread();
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, _("Mission Accomplished! You won!"));
+
+ do
{
- int looping = 1;
- int tux_offset = 0;
- int tux_step = -3;
-
- /* set up victory message: */
- dest_message.x = (screen->w - images[IMG_GAMEOVER_WON]->w) / 2;
- dest_message.y = (screen->h - images[IMG_GAMEOVER_WON]->h) / 2;
- dest_message.w = images[IMG_GAMEOVER_WON]->w;
- dest_message.h = images[IMG_GAMEOVER_WON]->h;
-
- //stop_tts_announcer_thread();
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,_("Mission Accomplished! You won!"));
-
-
- do
- {
- FC_frame_begin();
+ FC_frame_begin();
- while (SDL_PollEvent(&event) > 0)
+ while (SDL_PollEvent(&event) > 0)
+ {
+ if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN || event.type == SDL_MOUSEBUTTONDOWN)
{
- if (event.type == SDL_QUIT
- || event.type == SDL_KEYDOWN
- || event.type == SDL_MOUSEBUTTONDOWN)
- {
- looping = 0;
- }
+ looping = 0;
}
+ }
- if (current_bkgd() )
- SDL_BlitSurface(current_bkgd(), NULL, screen, NULL);
+ if (current_bkgd())
+ SDL_BlitSurface(current_bkgd(), NULL, screen, NULL);
- /* draw flashing victory message: */
- if ((FC_sprite_counter / 2) % 4)
- {
- SDL_BlitSurface(images[IMG_GAMEOVER_WON], NULL, screen, &dest_message);
- }
+ /* draw flashing victory message: */
+ if ((FC_sprite_counter / 2) % 4)
+ {
+ SDL_BlitSurface(images[IMG_GAMEOVER_WON], NULL, screen, &dest_message);
+ }
- /* draw dancing tux: */
- draw_console_image(IMG_CONSOLE_BASH);
- /* walk tux back and forth */
- tux_offset += tux_step;
- /* select tux_egypt images according to which way tux is headed: */
- if (tux_step < 0)
- tux_img = IMG_TUX_EGYPT1 + ((FC_sprite_counter / 3) % 2);
- else
- tux_img = IMG_TUX_EGYPT3 + ((FC_sprite_counter / 3) % 2);
+ /* draw dancing tux: */
+ draw_console_image(IMG_CONSOLE_BASH);
+ /* walk tux back and forth */
+ tux_offset += tux_step;
+ /* select tux_egypt images according to which way tux is headed: */
+ if (tux_step < 0)
+ tux_img = IMG_TUX_EGYPT1 + ((FC_sprite_counter / 3) % 2);
+ else
+ tux_img = IMG_TUX_EGYPT3 + ((FC_sprite_counter / 3) % 2);
- /* turn around if we go far enough: */
- if (tux_offset >= (screen->w)/2
- || tux_offset <= -(screen->w)/2)
- {
- tux_step = -tux_step;
- }
+ /* turn around if we go far enough: */
+ if (tux_offset >= (screen->w) / 2 || tux_offset <= -(screen->w) / 2)
+ {
+ tux_step = -tux_step;
+ }
- dest_tux.x = ((screen->w - images[tux_img]->w) / 2) + tux_offset;
- dest_tux.y = (screen->h - images[tux_img]->h);
- dest_tux.w = images[tux_img]->w;
- dest_tux.h = images[tux_img]->h;
+ dest_tux.x = ((screen->w - images[tux_img]->w) / 2) + tux_offset;
+ dest_tux.y = (screen->h - images[tux_img]->h);
+ dest_tux.w = images[tux_img]->w;
+ dest_tux.h = images[tux_img]->h;
- SDL_BlitSurface(images[tux_img], NULL, screen, &dest_tux);
+ SDL_BlitSurface(images[tux_img], NULL, screen, &dest_tux);
- /* draw_console_image(tux_img);*/
+ /* draw_console_image(tux_img);*/
- SDL_Flip(screen);
- FC_frame_end();
- }
- while (looping);
- break;
- }
+ SDL_Flip(screen);
+ FC_frame_end();
+ } while (looping);
+ break;
+ }
- case GAME_OVER_LAN_WON:
- {
- int looping = 1;
- int tux_offset = 0;
- int tux_step = -3;
- int i = 0;
- int rank = 1;
- int entries = 0;
- int first = 1;
- char str[64];
- SDL_Surface* surf = NULL;
- SDL_Rect loc;
-
- //Adjust font size for resolution:
- int fontsize = (int)(DEFAULT_MENU_FONT_SIZE * get_scale());
-
- //For sorted list of scores:
- lan_player_type sorted_scores[MAX_CLIENTS];
- /* Sort scores: */
- for(i = 0; i < MAX_CLIENTS; i++)
- {
- strncpy(sorted_scores[i].name, LAN_PlayerName(i), NAME_SIZE);
- sorted_scores[i].mine = LAN_PlayerMine(i);
- sorted_scores[i].score = LAN_PlayerScore(i);
- sorted_scores[i].connected = LAN_PlayerConnected(i);
- }
- qsort((void*)sorted_scores, MAX_CLIENTS, sizeof(lan_player_type), compare_scores);
+ case GAME_OVER_LAN_WON:
+ {
+ int looping = 1;
+ int tux_offset = 0;
+ int tux_step = -3;
+ int i = 0;
+ int rank = 1;
+ int entries = 0;
+ int first = 1;
+ char str[64];
+ SDL_Surface *surf = NULL;
+ SDL_Rect loc;
+ // Adjust font size for resolution:
+ int fontsize = (int)(DEFAULT_MENU_FONT_SIZE * get_scale());
- //Announce the sorted Final score
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,_("Final Scores:"));
- for (i = 0; i < MAX_CLIENTS; i++)
+ // For sorted list of scores:
+ lan_player_type sorted_scores[MAX_CLIENTS];
+ /* Sort scores: */
+ for (i = 0; i < MAX_CLIENTS; i++)
+ {
+ strncpy(sorted_scores[i].name, LAN_PlayerName(i), NAME_SIZE);
+ sorted_scores[i].mine = LAN_PlayerMine(i);
+ sorted_scores[i].score = LAN_PlayerScore(i);
+ sorted_scores[i].connected = LAN_PlayerConnected(i);
+ }
+ qsort((void *)sorted_scores, MAX_CLIENTS, sizeof(lan_player_type), compare_scores);
+
+ // Announce the sorted Final score
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, _("Final Scores:"));
+ for (i = 0; i < MAX_CLIENTS; i++)
+ {
+ if (sorted_scores[i].connected)
{
- if(sorted_scores[i].connected)
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%d.\t%s: %d", rank, sorted_scores[i].name, sorted_scores[i].score);
- }
- }
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%d.\t%s: %d", rank, sorted_scores[i].name, sorted_scores[i].score);
+ }
+ }
+ /* Begin display loop: */
+ do
+ {
+ FC_frame_begin();
+ entries = 0;
+ rank = 1;
- /* Begin display loop: */
- do
+ while (SDL_PollEvent(&event) > 0)
{
- FC_frame_begin();
- entries = 0;
- rank = 1;
-
- while (SDL_PollEvent(&event) > 0)
+ if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN || event.type == SDL_MOUSEBUTTONDOWN)
{
- if (event.type == SDL_QUIT
- || event.type == SDL_KEYDOWN
- || event.type == SDL_MOUSEBUTTONDOWN)
- {
- looping = 0;
- }
+ looping = 0;
}
+ }
- if (current_bkgd() )
- SDL_BlitSurface(current_bkgd(), NULL, screen, NULL);
-
- /* Make top heading a little bigger: */
- surf = T4K_BlackOutline(_("The Penguins Have Been Saved!"),
- 1.2 * fontsize, &white);
- if(surf)
- {
- loc.x = screen->w/2 - surf->w/2;
- loc.y = surf->h * 2;
- loc.w = surf->w;
- loc.h = surf->h;
- /* Make this blink: */
- if ((FC_sprite_counter / 2) % 4)
- SDL_BlitSurface(surf, NULL, screen, &loc);
- SDL_FreeSurface(surf);
- surf = NULL;
- }
+ if (current_bkgd())
+ SDL_BlitSurface(current_bkgd(), NULL, screen, NULL);
- surf = T4K_BlackOutline(_("Final Scores:"), fontsize, &white);
- if(surf)
- {
- loc.x = screen->w/2 - surf->w/2;
- loc.y += surf->h;
- loc.w = surf->w;
- loc.h = surf->h;
+ /* Make top heading a little bigger: */
+ surf = T4K_BlackOutline(_("The Penguins Have Been Saved!"),
+ 1.2 * fontsize, &white);
+ if (surf)
+ {
+ loc.x = screen->w / 2 - surf->w / 2;
+ loc.y = surf->h * 2;
+ loc.w = surf->w;
+ loc.h = surf->h;
+ /* Make this blink: */
+ if ((FC_sprite_counter / 2) % 4)
SDL_BlitSurface(surf, NULL, screen, &loc);
- SDL_FreeSurface(surf);
- surf = NULL;
- }
+ SDL_FreeSurface(surf);
+ surf = NULL;
+ }
+ surf = T4K_BlackOutline(_("Final Scores:"), fontsize, &white);
+ if (surf)
+ {
+ loc.x = screen->w / 2 - surf->w / 2;
+ loc.y += surf->h;
+ loc.w = surf->w;
+ loc.h = surf->h;
+ SDL_BlitSurface(surf, NULL, screen, &loc);
+ SDL_FreeSurface(surf);
+ surf = NULL;
+ }
- /* draw sorted list of scores: */
- for (i = 0; i < MAX_CLIENTS; i++)
+ /* draw sorted list of scores: */
+ for (i = 0; i < MAX_CLIENTS; i++)
+ {
+ if (sorted_scores[i].connected)
{
- if(sorted_scores[i].connected)
+ snprintf(str, 64, "%d.\t%s: %d", rank, sorted_scores[i].name, sorted_scores[i].score);
+ rank++;
+ if (sorted_scores[i].mine)
+ surf = T4K_BlackOutline(str, fontsize, &yellow);
+ else
+ surf = T4K_BlackOutline(str, fontsize, &white);
+ if (surf)
{
- snprintf(str, 64, "%d.\t%s: %d", rank, sorted_scores[i].name, sorted_scores[i].score);
- rank++;
- if(sorted_scores[i].mine)
- surf = T4K_BlackOutline(str, fontsize, &yellow);
- else
- surf = T4K_BlackOutline(str, fontsize, &white);
- if(surf)
+ if (first)
{
- if(first)
- {
- loc.x = screen->w/2 - surf->w/2;
- first = 0;
- }
- loc.w = surf->w;
- loc.h = surf->h;
- loc.y += surf->h;
- SDL_BlitSurface(surf, NULL, screen, &loc);
- entries++;
- SDL_FreeSurface(surf);
- surf = NULL;
+ loc.x = screen->w / 2 - surf->w / 2;
+ first = 0;
}
+ loc.w = surf->w;
+ loc.h = surf->h;
+ loc.y += surf->h;
+ SDL_BlitSurface(surf, NULL, screen, &loc);
+ entries++;
+ SDL_FreeSurface(surf);
+ surf = NULL;
}
}
- /* draw dancing tux: */
- draw_console_image(IMG_CONSOLE_BASH);
- /* walk tux back and forth */
- tux_offset += tux_step;
- /* select tux_egypt images according to which way tux is headed: */
- if (tux_step < 0)
- tux_img = IMG_TUX_EGYPT1 + ((FC_sprite_counter / 3) % 2);
- else
- tux_img = IMG_TUX_EGYPT3 + ((FC_sprite_counter / 3) % 2);
+ }
+ /* draw dancing tux: */
+ draw_console_image(IMG_CONSOLE_BASH);
+ /* walk tux back and forth */
+ tux_offset += tux_step;
+ /* select tux_egypt images according to which way tux is headed: */
+ if (tux_step < 0)
+ tux_img = IMG_TUX_EGYPT1 + ((FC_sprite_counter / 3) % 2);
+ else
+ tux_img = IMG_TUX_EGYPT3 + ((FC_sprite_counter / 3) % 2);
- /* turn around if we go far enough: */
- if (tux_offset >= (screen->w)/2
- || tux_offset <= -(screen->w)/2)
- {
- tux_step = -tux_step;
- }
+ /* turn around if we go far enough: */
+ if (tux_offset >= (screen->w) / 2 || tux_offset <= -(screen->w) / 2)
+ {
+ tux_step = -tux_step;
+ }
- dest_tux.x = ((screen->w - images[tux_img]->w) / 2) + tux_offset;
- dest_tux.y = (screen->h - images[tux_img]->h);
- dest_tux.w = images[tux_img]->w;
- dest_tux.h = images[tux_img]->h;
+ dest_tux.x = ((screen->w - images[tux_img]->w) / 2) + tux_offset;
+ dest_tux.y = (screen->h - images[tux_img]->h);
+ dest_tux.w = images[tux_img]->w;
+ dest_tux.h = images[tux_img]->h;
- SDL_BlitSurface(images[tux_img], NULL, screen, &dest_tux);
+ SDL_BlitSurface(images[tux_img], NULL, screen, &dest_tux);
- /* draw_console_image(tux_img);*/
+ /* draw_console_image(tux_img);*/
- SDL_Flip(screen);
- FC_frame_end();
- }
- while (looping);
- break;
- }
+ SDL_Flip(screen);
+ FC_frame_end();
+ } while (looping);
+ break;
+ }
- case GAME_OVER_LAN_HALTED:
- {
- ShowMessageWrap(DEFAULT_MENU_FONT_SIZE,
- _("Network game terminated by server.\n The server is still running."));
- break;
- }
- case GAME_OVER_LAN_DISCONNECT:
- {
- ShowMessageWrap(DEFAULT_MENU_FONT_SIZE,
+ case GAME_OVER_LAN_HALTED:
+ {
+ ShowMessageWrap(DEFAULT_MENU_FONT_SIZE,
+ _("Network game terminated by server.\n The server is still running."));
+ break;
+ }
+ case GAME_OVER_LAN_DISCONNECT:
+ {
+ ShowMessageWrap(DEFAULT_MENU_FONT_SIZE,
+ _("Network game terminated.\n Connection with server was lost."));
+
+ // stop_tts_announcer_thread();
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT,
_("Network game terminated.\n Connection with server was lost."));
-
- //stop_tts_announcer_thread();
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,
- _("Network game terminated.\n Connection with server was lost."));
- break;
- }
+ break;
+ }
- case GAME_OVER_ERROR:
+ case GAME_OVER_ERROR:
DEBUGMSG(debug_game, "game() exiting with error:\n");
- case GAME_OVER_LOST:
- case GAME_OVER_OTHER:
+ case GAME_OVER_LOST:
+ case GAME_OVER_OTHER:
+ {
+ // stop_tts_announcer_thread();
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, _("Game Over!"));
+
+ int looping = 1;
+
+ /* set up GAMEOVER message: */
+ dest_message.x = (screen->w - images[IMG_GAMEOVER]->w) / 2;
+ dest_message.y = (screen->h - images[IMG_GAMEOVER]->h) / 2;
+ dest_message.w = images[IMG_GAMEOVER]->w;
+ dest_message.h = images[IMG_GAMEOVER]->h;
+
+ do
{
- //stop_tts_announcer_thread();
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,_("Game Over!"));
-
- int looping = 1;
-
- /* set up GAMEOVER message: */
- dest_message.x = (screen->w - images[IMG_GAMEOVER]->w) / 2;
- dest_message.y = (screen->h - images[IMG_GAMEOVER]->h) / 2;
- dest_message.w = images[IMG_GAMEOVER]->w;
- dest_message.h = images[IMG_GAMEOVER]->h;
-
- do
- {
- FC_frame_begin();
+ FC_frame_begin();
- while (SDL_PollEvent(&event) > 0)
+ while (SDL_PollEvent(&event) > 0)
+ {
+ if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN || event.type == SDL_MOUSEBUTTONDOWN)
{
- if (event.type == SDL_QUIT
- || event.type == SDL_KEYDOWN
- || event.type == SDL_MOUSEBUTTONDOWN)
- {
- looping = 0;
- }
+ looping = 0;
}
+ }
- SDL_BlitSurface(images[IMG_GAMEOVER], NULL, screen, &dest_message);
- SDL_Flip(screen);
+ SDL_BlitSurface(images[IMG_GAMEOVER], NULL, screen, &dest_message);
+ SDL_Flip(screen);
- FC_frame_end();
- }
- while (looping);
+ FC_frame_end();
+ } while (looping);
- break;
- }
+ break;
+ }
- case GAME_OVER_ESCAPE:
- case GAME_OVER_WINDOW_CLOSE:
+ case GAME_OVER_ESCAPE:
+ case GAME_OVER_WINDOW_CLOSE:
break;
}
}
-
-
/* Reset stuff for the next level! */
void reset_level(void)
{
@@ -2502,7 +2529,6 @@ void reset_level(void)
int use_feedback;
float comet_avg_height, height_differential;
-
/* Clear all comets: */
/* NOTE - we should not need to reset them to not alive, as the wave is supposed to be over.
* In LAN game, we can clobber the first comet in the new wave if the messages come out of order,
@@ -2514,10 +2540,10 @@ void reset_level(void)
{
DEBUGCODE(debug_game)
{
- if(comets[i].alive)
+ if (comets[i].alive)
fprintf(stderr, "Warning - changing wave but comet[%d] still alive (could be OK in LAN mode)\n", i);
}
- //comets[i].alive = 0;
+ // comets[i].alive = 0;
}
/* Clear LED: */
@@ -2527,7 +2553,8 @@ void reset_level(void)
neg_answer_picked = 0;
/* Load random background image, but ensure it's different from this one: */
- for (i = last_bkgd; i == last_bkgd; i = rand() % NUM_BKGDS);
+ for (i = last_bkgd; i == last_bkgd; i = rand() % NUM_BKGDS)
+ ;
last_bkgd = i;
@@ -2558,14 +2585,12 @@ void reset_level(void)
}
}
-
-
/* Record score before this wave: */
pre_wave_score = score;
/* Set speed and number of comets for this wave.
- * Note that in LAN mode, the number of comets is handled by the
+ * Note that in LAN mode, the number of comets is handled by the
* server, and feedback/slowdown are disallowed, so we just set
* the speed and get out.
* */
@@ -2582,12 +2607,12 @@ void reset_level(void)
if (wave == 1 || slowdown)
{
next_wave_comets = Opts_StartingComets();
- speed = Opts_Speed()*15; //The old fps limit was 15;
+ speed = Opts_Speed() * 15; // The old fps limit was 15;
slowdown = 0;
}
else /* Otherwise increase comets and speed if selected, not to */
- /* exceed maximum: */
+ /* exceed maximum: */
{
next_wave_comets = prev_wave_comets;
if (Opts_AllowSpeedup())
@@ -2603,23 +2628,23 @@ void reset_level(void)
if (use_feedback)
{
#ifdef FEEDBACK_DEBUG
- fprintf(stderr, "Evaluating feedback...\n old danger level = %g,",danger_level);
+ fprintf(stderr, "Evaluating feedback...\n old danger level = %g,", danger_level);
#endif
/* Update our danger level, i.e., the target height */
- danger_level = 1 - (1-danger_level) /
- Opts_DangerLevelSpeedup();
+ danger_level = 1 - (1 - danger_level) /
+ Opts_DangerLevelSpeedup();
if (danger_level > Opts_DangerLevelMax())
danger_level = Opts_DangerLevelMax();
#ifdef FEEDBACK_DEBUG
- fprintf(stderr, " new danger level = %g.\n",danger_level);
+ fprintf(stderr, " new danger level = %g.\n", danger_level);
#endif
/* Check to see whether we have any feedback data. If not, skip it. */
if (comet_feedback_number == 0)
{
- use_feedback = 0; /* No comets above living cities, skip feedback */
+ use_feedback = 0; /* No comets above living cities, skip feedback */
#ifdef FEEDBACK_DEBUG
fprintf(stderr, "No feedback data available, aborting.\n\n");
@@ -2628,7 +2653,7 @@ void reset_level(void)
else
{
/* Compute the average height of comet destruction. */
- comet_avg_height = comet_feedback_height/comet_feedback_number;
+ comet_avg_height = comet_feedback_height / comet_feedback_number;
/* Determine how this average height compares with target. */
height_differential = comet_avg_height - danger_level;
@@ -2639,10 +2664,10 @@ void reset_level(void)
#ifdef FEEDBACK_DEBUG
fprintf(stderr, " comet average height = %g, height differential = %g.\n",
comet_avg_height, height_differential);
- fprintf(stderr, " old speed = %g,",speed);
+ fprintf(stderr, " old speed = %g,", speed);
#endif
- speed *= (1 - height_differential/danger_level/2);
+ speed *= (1 - height_differential / danger_level / 2);
/* Enforce bounds on speed */
if (speed < MINIMUM_SPEED)
@@ -2651,7 +2676,7 @@ void reset_level(void)
speed = Opts_MaxSpeed();
#ifdef FEEDBACK_DEBUG
- fprintf(stderr, " new speed = %g.\n",speed);
+ fprintf(stderr, " new speed = %g.\n", speed);
fprintf(stderr, "Feedback evaluation complete.\n\n");
#endif
}
@@ -2677,8 +2702,6 @@ void reset_level(void)
num_attackers = next_wave_comets;
}
-
-
/* Add a comet to the game (if there's room): */
int add_comet(void)
{
@@ -2697,11 +2720,12 @@ int add_comet(void)
if (comets[i].y < y_spacing)
{
DEBUGMSG(debug_game,
- "add_comet() - returning because comet[%d] not"
- " far enough down: %f\n", i, comets[i].y);
+ "add_comet() - returning because comet[%d] not"
+ " far enough down: %f\n",
+ i, comets[i].y);
return 0;
}
- }
+ }
/* Now look for a free comet slot: */
for (i = 0; i < MAX_MAX_COMETS; i++)
@@ -2717,7 +2741,8 @@ int add_comet(void)
{
/* free comet slot not found - no comet added: */
DEBUGMSG(debug_game, "add_comet() called but no free comet slot\n");
- DEBUGCODE(debug_game) print_current_quests();
+ DEBUGCODE(debug_game)
+ print_current_quests();
return 0;
}
@@ -2734,8 +2759,7 @@ int add_comet(void)
}
/* Make sure question is "sane" before we add it: */
- if( (comets[com_found].flashcard.answer > 999)
- ||(comets[com_found].flashcard.answer < -999))
+ if ((comets[com_found].flashcard.answer > 999) || (comets[com_found].flashcard.answer < -999))
{
fprintf(stderr, "Warning, card with invalid answer encountered: %d\n",
comets[com_found].flashcard.answer);
@@ -2746,8 +2770,10 @@ int add_comet(void)
/* If we make it to here, create a new comet!*/
comets[com_found].answer = comets[com_found].flashcard.answer;
comets[com_found].alive = 1;
- if(comets[com_found].formula_surf) SDL_FreeSurface(comets[com_found].formula_surf);
- if(comets[com_found].answer_surf) SDL_FreeSurface(comets[com_found].answer_surf);
+ if (comets[com_found].formula_surf)
+ SDL_FreeSurface(comets[com_found].formula_surf);
+ if (comets[com_found].answer_surf)
+ SDL_FreeSurface(comets[com_found].answer_surf);
comets[com_found].formula_surf = T4K_BlackOutline(comets[com_found].flashcard.formula_string, comet_fontsize, &white);
comets[com_found].answer_surf = T4K_BlackOutline(comets[com_found].flashcard.answer_string, comet_fontsize, &white);
// num_comets_alive++;
@@ -2757,8 +2783,7 @@ int add_comet(void)
do
{
i = rand() % NUM_CITIES;
- }
- while (i == prev_city);
+ } while (i == prev_city);
prev_city = i;
@@ -2771,7 +2796,7 @@ int add_comet(void)
/* Should it be a bonus comet? */
comets[com_found].bonus = 0;
- DEBUGMSG(debug_game, "bonus_comet_counter is %d\n",bonus_comet_counter);
+ DEBUGMSG(debug_game, "bonus_comet_counter is %d\n", bonus_comet_counter);
if (bonus_comet_counter == 1)
{
@@ -2787,22 +2812,20 @@ int add_comet(void)
comets[com_found].time_started = SDL_GetTicks();
/* If enabled, add powerup comet occasionally:
- */
- if(Opts_UsePowerupComets()
- && !mp_get_parameter(PLAYERS) // no powerups in mp game, for now
- && !powerup_comet_running)
+ */
+ if (Opts_UsePowerupComets() && !mp_get_parameter(PLAYERS) // no powerups in mp game, for now
+ && !powerup_comet_running)
{
- int t = rand()%Opts_PowerupFreq();
- if( t < 1 )
+ int t = rand() % Opts_PowerupFreq();
+ if (t < 1)
{
powerup_add_comet();
- }
+ }
}
/* comet slot found and question found so return successfully: */
return 1;
}
-
/* Translates mouse events into keyboard events when on-screen keypad used */
/* or when exit button clicked. */
void comets_mouse_event(SDL_Event event)
@@ -2815,20 +2838,20 @@ void comets_mouse_event(SDL_Event event)
/* Check to see if user clicked exit button: */
/* The exit button is in the upper right corner of the screen: */
- if(event.button.button == SDL_BUTTON_LEFT &&
- (event.button.x >= (screen->w - images[IMG_STOP]->w)) &&
- (event.button.y <= images[IMG_STOP]->h))
+ if (event.button.button == SDL_BUTTON_LEFT &&
+ (event.button.x >= (screen->w - images[IMG_STOP]->w)) &&
+ (event.button.y <= images[IMG_STOP]->h))
{
key = SDLK_ESCAPE;
comets_key_event(key, mod);
return;
}
- if(event.button.button == SDL_BUTTON_LEFT &&
- event.button.x >= SMARTBOMB_ICON_X && event.button.x <= SMARTBOMB_ICON_X+SMARTBOMB_ICON_W &&
- event.button.y >= SMARTBOMB_ICON_Y && event.button.y <= SMARTBOMB_ICON_Y+SMARTBOMB_ICON_H)
+ if (event.button.button == SDL_BUTTON_LEFT &&
+ event.button.x >= SMARTBOMB_ICON_X && event.button.x <= SMARTBOMB_ICON_X + SMARTBOMB_ICON_W &&
+ event.button.y >= SMARTBOMB_ICON_Y && event.button.y <= SMARTBOMB_ICON_Y + SMARTBOMB_ICON_H)
{
- if(smartbomb_alive)
+ if (smartbomb_alive)
{
smartbomb_activate();
smartbomb_alive = 0;
@@ -2836,14 +2859,11 @@ void comets_mouse_event(SDL_Event event)
}
/* get out unless we really are using keypad */
- if ( level_start_wait
- || Opts_DemoMode()
- || !Opts_GetGlobalOpt(USE_KEYPAD))
+ if (level_start_wait || Opts_DemoMode() || !Opts_GetGlobalOpt(USE_KEYPAD))
{
return;
}
-
/* make sure keypad image is valid and has non-zero dimensions: */
/* FIXME maybe this checking should be done once at the start */
/* of game() rather than with every mouse click */
@@ -2873,17 +2893,16 @@ void comets_mouse_event(SDL_Event event)
return;
}
-
/* only proceed if click falls within keypad: */
if (!((event.button.x >=
- (screen->w / 2) - (keypad_w / 2) &&
- event.button.x <=
- (screen->w / 2) + (keypad_w / 2) &&
- event.button.y >=
- (screen->h / 2) - (keypad_h / 2) &&
- event.button.y <=
- (screen->h / 2) + (keypad_h / 2))))
- /* click outside of keypad - do nothing */
+ (screen->w / 2) - (keypad_w / 2) &&
+ event.button.x <=
+ (screen->w / 2) + (keypad_w / 2) &&
+ event.button.y >=
+ (screen->h / 2) - (keypad_h / 2) &&
+ event.button.y <=
+ (screen->h / 2) + (keypad_h / 2))))
+ /* click outside of keypad - do nothing */
{
return;
}
@@ -2919,14 +2938,11 @@ void comets_mouse_event(SDL_Event event)
/* row and column based on x and y and looks */
/* up the SDlKey accordingly. */
- column = x/((keypad_w)/4);
- row = y/((keypad_h)/4);
+ column = x / ((keypad_w) / 4);
+ row = y / ((keypad_h) / 4);
/* make sure row and column are sane */
- if (column < 0
- || column > 3
- || row < 0
- || row > 3)
+ if (column < 0 || column > 3 || row < 0 || row > 3)
{
fprintf(stderr, "\nIllegal row or column value!\n");
return;
@@ -2994,23 +3010,22 @@ void comets_mouse_event(SDL_Event event)
void comets_key_event(SDLKey key, SDLMod mod)
{
int i;
- key_pressed = 1; // Signal back in cases where waiting on any key
+ key_pressed = 1; // Signal back in cases where waiting on any key
if (key == SDLK_ESCAPE)
{
/* Escape key - quit! */
- //stop_tts_announcer_thread();
+ // stop_tts_announcer_thread();
user_quit_received = GAME_OVER_ESCAPE;
}
DEBUGCODE(debug_game)
{
- if (key == SDLK_LEFTBRACKET) //a nice nonobvious/unused key
+ if (key == SDLK_LEFTBRACKET) // a nice nonobvious/unused key
{
user_quit_received = GAME_OVER_CHEATER;
}
}
- else if (key == SDLK_TAB
- || key == SDLK_p)
+ else if (key == SDLK_TAB || key == SDLK_p)
{
/* [TAB] or [P]: Pause! (if settings allow) */
if (Opts_AllowPause())
@@ -3043,15 +3058,14 @@ void comets_key_event(SDLKey key, SDLMod mod)
key = SDLK_UNKNOWN;
}
-
/* The rest of the keys control the numeric answer console: */
if (key >= SDLK_0 && key <= SDLK_9)
{
/* [0]-[9]: Add a new digit: */
- for (i = 0; i < MC_MAX_DIGITS-1; ++i)
- digits[i] = digits[i+1];
- digits[MC_MAX_DIGITS-1] = key - SDLK_0;
+ for (i = 0; i < MC_MAX_DIGITS - 1; ++i)
+ digits[i] = digits[i + 1];
+ digits[MC_MAX_DIGITS - 1] = key - SDLK_0;
// digits[0] = digits[1];
// digits[1] = digits[2];
@@ -3061,9 +3075,9 @@ void comets_key_event(SDLKey key, SDLMod mod)
else if (key >= SDLK_KP0 && key <= SDLK_KP9)
{
/* Keypad [0]-[9]: Add a new digit: */
- for (i = 0; i < MC_MAX_DIGITS-1; ++i)
- digits[i] = digits[i+1];
- digits[MC_MAX_DIGITS-1] = key - SDLK_KP0;
+ for (i = 0; i < MC_MAX_DIGITS - 1; ++i)
+ digits[i] = digits[i + 1];
+ digits[MC_MAX_DIGITS - 1] = key - SDLK_KP0;
// digits[0] = digits[1];
// digits[1] = digits[2];
@@ -3071,26 +3085,18 @@ void comets_key_event(SDLKey key, SDLMod mod)
tux_pressing = 1;
}
/* support for negative answer input DSB */
- else if ((key == SDLK_MINUS || key == SDLK_KP_MINUS)
- && MC_GetOpt(curr_game, ALLOW_NEGATIVES) ) /* do nothing unless neg answers allowed */
+ else if ((key == SDLK_MINUS || key == SDLK_KP_MINUS) && MC_GetOpt(curr_game, ALLOW_NEGATIVES)) /* do nothing unless neg answers allowed */
{
/* allow player to make answer negative: */
neg_answer_picked = 1;
tux_pressing = 1;
}
- else if ( /* Effort to make logical operators clear: */
- (
- ( /* HACK this hard-codes the plus sign to the US layout: */
- (key == SDLK_EQUALS) && (mod & KMOD_SHIFT)
- )
- ||
+ else if (/* Effort to make logical operators clear: */
(
- key == SDLK_KP_PLUS
- )
- )
- &&
- MC_GetOpt(curr_game, ALLOW_NEGATIVES)
- ) /* do nothing unless neg answers allowed */
+ (/* HACK this hard-codes the plus sign to the US layout: */
+ (key == SDLK_EQUALS) && (mod & KMOD_SHIFT)) ||
+ (key == SDLK_KP_PLUS)) &&
+ MC_GetOpt(curr_game, ALLOW_NEGATIVES)) /* do nothing unless neg answers allowed */
{
/* allow player to make answer positive: */
fprintf(stderr, "SDKL_PLUS received\n");
@@ -3098,8 +3104,8 @@ void comets_key_event(SDLKey key, SDLMod mod)
tux_pressing = 1;
}
else if (key == SDLK_BACKSPACE ||
- key == SDLK_CLEAR ||
- key == SDLK_DELETE)
+ key == SDLK_CLEAR ||
+ key == SDLK_DELETE)
{
/* [BKSP]: Clear digits! */
for (i = 0; i < MC_MAX_DIGITS; ++i)
@@ -3107,62 +3113,62 @@ void comets_key_event(SDLKey key, SDLMod mod)
tux_pressing = 1;
}
else if (key == SDLK_RETURN ||
- key == SDLK_KP_ENTER ||
- key == SDLK_SPACE)
+ key == SDLK_KP_ENTER ||
+ key == SDLK_SPACE)
{
/* [ENTER]: Accept digits! */
doing_answer = 1;
}
- else if(key == SDLK_LSHIFT || key == SDLK_RSHIFT)
+ else if (key == SDLK_LSHIFT || key == SDLK_RSHIFT)
{
- if(smartbomb_alive)
+ if (smartbomb_alive)
{
smartbomb_activate();
smartbomb_alive = 0;
}
}
-
- /* Score */
- else if(key == SDLK_F1)
- {
- tts_announcer_switch = 2;
- }
- /* iglu alive */
- else if(key == SDLK_F2)
+ /* Score */
+ else if (key == SDLK_F1)
{
- tts_announcer_switch = 3;
- }
+ tts_announcer_switch = 2;
+ }
- /* Wave number */
- else if(key == SDLK_F3)
+ /* iglu alive */
+ else if (key == SDLK_F2)
{
- tts_announcer_switch = 4;
- }
+ tts_announcer_switch = 3;
+ }
- else if(key == SDLK_PAGEUP)
+ /* Wave number */
+ else if (key == SDLK_F3)
{
- volume = Mix_Volume(-1,-1);
- Mix_Volume(-1,volume + 10);
- }
+ tts_announcer_switch = 4;
+ }
- else if(key == SDLK_PAGEDOWN)
+ else if (key == SDLK_PAGEUP)
{
- volume = Mix_Volume(-1,-1);
- Mix_Volume(-1,volume - 10); }
+ volume = Mix_Volume(-1, -1);
+ Mix_Volume(-1, volume + 10);
+ }
- else if(key == SDLK_HOME)
+ else if (key == SDLK_PAGEDOWN)
{
- volume = Mix_VolumeMusic(-1);
- Mix_VolumeMusic(volume + 10); }
+ volume = Mix_Volume(-1, -1);
+ Mix_Volume(-1, volume - 10);
+ }
- else if(key == SDLK_END)
+ else if (key == SDLK_HOME)
{
- volume = Mix_VolumeMusic(-1);
- Mix_VolumeMusic(volume - 10);
- }
+ volume = Mix_VolumeMusic(-1);
+ Mix_VolumeMusic(volume + 10);
+ }
-
+ else if (key == SDLK_END)
+ {
+ volume = Mix_VolumeMusic(-1);
+ Mix_VolumeMusic(volume - 10);
+ }
}
/* Increment score: */
@@ -3170,17 +3176,15 @@ void comets_key_event(SDLKey key, SDLMod mod)
void add_score(int inc)
{
score += inc;
- DEBUGMSG(debug_game,"Score is now: %d\n", score);
+ DEBUGMSG(debug_game, "Score is now: %d\n", score);
/* For turn-based multiplayer game, update score in mp info: */
- if (mp_get_parameter(PLAYERS))
+ if (mp_get_parameter(PLAYERS))
{
int new_score = mp_get_player_score(mp_get_currentplayer()) + inc;
mp_set_player_score(mp_get_currentplayer(), new_score);
}
}
-
-
void reset_comets(void)
{
int i = 0;
@@ -3195,14 +3199,15 @@ void reset_comets(void)
comets[i].answer = 0;
MC_ResetFlashCard(&(comets[i].flashcard));
comets[i].bonus = 0;
- if(comets[i].formula_surf) SDL_FreeSurface(comets[i].formula_surf);
+ if (comets[i].formula_surf)
+ SDL_FreeSurface(comets[i].formula_surf);
comets[i].formula_surf = NULL;
- if(comets[i].answer_surf) SDL_FreeSurface(comets[i].answer_surf);
+ if (comets[i].answer_surf)
+ SDL_FreeSurface(comets[i].answer_surf);
comets[i].answer_surf = NULL;
}
}
-
void print_status(void)
{
int i;
@@ -3210,32 +3215,31 @@ void print_status(void)
fprintf(stderr, "\nCities:");
fprintf(stderr, "\nHits left: ");
for (i = 0; i < NUM_CITIES; i++)
- fprintf(stderr, "%02d ",cities[i].hits_left);
+ fprintf(stderr, "%02d ", cities[i].hits_left);
fprintf(stderr, "\nStatus: ");
for (i = 0; i < NUM_CITIES; i++)
- fprintf(stderr, "%02d ",cities[i].status);
+ fprintf(stderr, "%02d ", cities[i].status);
fprintf(stderr, "\nPenguins:");
fprintf(stderr, "\nStatus: ");
for (i = 0; i < NUM_CITIES; i++)
- fprintf(stderr, "%02d ",penguins[i].status);
+ fprintf(stderr, "%02d ", penguins[i].status);
fprintf(stderr, "\nCloud:");
- fprintf(stderr, "\nStatus: %d",cloud.status);
- fprintf(stderr, "\nCity: %d",cloud.city);
+ fprintf(stderr, "\nStatus: %d", cloud.status);
+ fprintf(stderr, "\nCity: %d", cloud.city);
fprintf(stderr, "\n");
}
-
void free_on_exit(void)
{
int i;
- DEBUGMSG(debug_game,"Enter free_on_exit\n");
+ DEBUGMSG(debug_game, "Enter free_on_exit\n");
for (i = 0; i < MAX_MAX_COMETS; ++i)
{
- DEBUGMSG(debug_game,"About to free surfaces for comet %d\n", i);
+ DEBUGMSG(debug_game, "About to free surfaces for comet %d\n", i);
if (comets[i].formula_surf)
{
SDL_FreeSurface(comets[i].formula_surf);
@@ -3248,31 +3252,31 @@ void free_on_exit(void)
}
}
- if(comets)
+ if (comets)
{
free(comets);
comets = NULL;
}
- if(cities)
+ if (cities)
{
free(cities);
cities = NULL;
}
- if(penguins)
+ if (penguins)
{
free(penguins);
penguins = NULL;
}
- if(steam)
+ if (steam)
{
free(steam);
steam = NULL;
}
- if(powerup_comet)
+ if (powerup_comet)
{
free(powerup_comet);
powerup_comet = NULL;
@@ -3290,15 +3294,15 @@ void free_on_exit(void)
scaled_bkgd = NULL;
}
-#ifdef HAVE_LIBSDL_NET
- if(player_left_surf)
+#ifdef HAVE_LIBSDL_NET
+ if (player_left_surf)
{
SDL_FreeSurface(player_left_surf);
player_left_surf = NULL;
}
#endif
- DEBUGMSG(debug_game,"Leave free_on_exit\n");
+ DEBUGMSG(debug_game, "Leave free_on_exit\n");
}
/* Recalculate on-screen city & comet locations when screen dimensions change */
@@ -3307,8 +3311,7 @@ void comets_recalc_positions(int xres, int yres)
int i, img;
int old_city_expl_height = city_expl_height;
- DEBUGMSG(debug_game,"Recalculating positions\n");
-
+ DEBUGMSG(debug_game, "Recalculating positions\n");
if (Opts_GetGlobalOpt(USE_IGLOOS))
img = IMG_IGLOO_INTACT;
@@ -3321,22 +3324,22 @@ void comets_recalc_positions(int xres, int yres)
if (i < NUM_CITIES / 2)
{
cities[i].x = (((xres / (NUM_CITIES + 1)) * i) +
- ((images[img] -> w) / 2));
- DEBUGMSG(debug_game,"%d,", cities[i].x);
+ ((images[img]->w) / 2));
+ DEBUGMSG(debug_game, "%d,", cities[i].x);
}
else
{
cities[i].x = xres -
- (xres / (NUM_CITIES + 1) *
- (i - NUM_CITIES / 2) +
- images[img]->w / 2);
- DEBUGMSG(debug_game,"%d,", cities[i].x);
+ (xres / (NUM_CITIES + 1) *
+ (i - NUM_CITIES / 2) +
+ images[img]->w / 2);
+ DEBUGMSG(debug_game, "%d,", cities[i].x);
}
penguins[i].x = cities[i].x;
}
- //Handle resize for comets: -------------
+ // Handle resize for comets: -------------
city_expl_height = yres - images[IMG_CITY_BLUE]->h;
comet_fontsize = (int)(BASE_COMET_FONTSIZE * get_scale());
@@ -3346,17 +3349,17 @@ void comets_recalc_positions(int xres, int yres)
if (!comets[i].alive)
continue;
- //move comets to a location 'equivalent' to where they were
- //i.e. with the same amount of time left before impact
+ // move comets to a location 'equivalent' to where they were
+ // i.e. with the same amount of time left before impact
comets[i].x = cities[comets[i].city].x;
comets[i].y = comets[i].y * city_expl_height / old_city_expl_height;
// Re-render the numbers of any living comets at the new resolution:
- if(comets[i].formula_surf != NULL) //for safety, but shouldn't occur if comet is alive
+ if (comets[i].formula_surf != NULL) // for safety, but shouldn't occur if comet is alive
{
SDL_FreeSurface(comets[i].formula_surf);
comets[i].formula_surf = T4K_BlackOutline(comets[i].flashcard.formula_string, comet_fontsize, &white);
}
- if(comets[i].answer_surf != NULL)
+ if (comets[i].answer_surf != NULL)
{
SDL_FreeSurface(comets[i].answer_surf);
comets[i].answer_surf = T4K_BlackOutline(comets[i].flashcard.answer_string, comet_fontsize, &white);
@@ -3368,29 +3371,26 @@ static int num_comets_alive()
{
int i = 0;
int living = 0;
- for(i = 0; i < MAX_MAX_COMETS; i++)
- if(comets[i].alive)
+ for (i = 0; i < MAX_MAX_COMETS; i++)
+ if (comets[i].alive)
living++;
return living;
}
-
-
/* Functions for "smart bomb" super bonus comet powerup: --------------------------------------*/
void smartbomb_activate(void)
{
- if(!smartbomb_alive)
+ if (!smartbomb_alive)
return;
smartbomb_firing = 1;
doing_answer = 1;
playsound(SND_EXPLOSION);
}
-
int powerup_initialize(void)
{
- if(powerup_comet == NULL)
+ if (powerup_comet == NULL)
return 0;
powerup_comet->comet.alive = 0;
@@ -3413,22 +3413,22 @@ int powerup_initialize(void)
PowerUp_Type powerup_gettype(void)
{
- return rand()%NPOWERUP;
+ return rand() % NPOWERUP;
}
int powerup_add_comet(void)
{
PowerUp_Type puType;
- DEBUGMSG( debug_game, "Enter powerup_add_comet()\n");
+ DEBUGMSG(debug_game, "Enter powerup_add_comet()\n");
- if(smartbomb_alive)
+ if (smartbomb_alive)
return 0;
- if(powerup_comet == NULL)
+ if (powerup_comet == NULL)
return 0;
- if(powerup_comet_running)
+ if (powerup_comet_running)
return 0;
/* add only one powerup */
@@ -3438,15 +3438,15 @@ int powerup_add_comet(void)
/* currently only smart bombs */
puType = powerup_gettype();
powerup_comet->type = puType;
- DEBUGMSG( debug_game, "Power-Up Type: %d\n", puType );
+ DEBUGMSG(debug_game, "Power-Up Type: %d\n", puType);
/* create the flashcard */
- if(!MC_NextQuestion(curr_game, &(powerup_comet->comet.flashcard)))
+ if (!MC_NextQuestion(curr_game, &(powerup_comet->comet.flashcard)))
return 0;
/* Make sure question is "sane" before we add it: */
- if((powerup_comet->comet.flashcard.answer > 999) ||
- (powerup_comet->comet.flashcard.answer < -999))
+ if ((powerup_comet->comet.flashcard.answer > 999) ||
+ (powerup_comet->comet.flashcard.answer < -999))
{
fprintf(stderr, "Warning, card with invalid answer encountered: %d\n",
powerup_comet->comet.flashcard.answer);
@@ -3457,104 +3457,113 @@ int powerup_add_comet(void)
/* Now make the powerup comet alive */
powerup_comet->comet.answer = powerup_comet->comet.flashcard.answer;
powerup_comet->comet.alive = 1;
- if(powerup_comet->comet.formula_surf)
+ if (powerup_comet->comet.formula_surf)
SDL_FreeSurface(powerup_comet->comet.formula_surf);
- if(powerup_comet->comet.answer_surf)
+ if (powerup_comet->comet.answer_surf)
SDL_FreeSurface(powerup_comet->comet.answer_surf);
powerup_comet->comet.formula_surf = T4K_BlackOutline(powerup_comet->comet.flashcard.formula_string, comet_fontsize, &white);
powerup_comet->comet.answer_surf = T4K_BlackOutline(powerup_comet->comet.flashcard.answer_string, comet_fontsize, &white);
/* Set the direction */
/* Only two direction, left or right */
- powerup_comet->direction = rand()%2;
+ powerup_comet->direction = rand() % 2;
/* Set the initial coordinates */
powerup_comet->comet.y = POWERUP_Y_POS;
- if(powerup_comet->direction == POWERUP_DIR_LEFT)
+ if (powerup_comet->direction == POWERUP_DIR_LEFT)
{
- powerup_comet->comet.x = screen->w;
+ powerup_comet->comet.x = screen->w;
powerup_comet->inc_speed = -MS_POWERUP_SPEED;
}
else
{
- powerup_comet->comet.x = 0;
+ powerup_comet->comet.x = 0;
powerup_comet->inc_speed = MS_POWERUP_SPEED;
}
powerup_comet->comet.time_started = SDL_GetTicks();
- DEBUGMSG( debug_game, "Leave powerup_add_comet()\n");
+ DEBUGMSG(debug_game, "Leave powerup_add_comet()\n");
return 1;
}
void comets_handle_powerup(void)
{
- if(powerup_comet == NULL)
+ if (powerup_comet == NULL)
return;
- if(!powerup_comet->comet.alive)
+ if (!powerup_comet->comet.alive)
return;
- powerup_comet->comet.x += powerup_comet->inc_speed*FC_time_elapsed*screen->w/640;
+ powerup_comet->comet.x += powerup_comet->inc_speed * FC_time_elapsed * screen->w / 640;
- if(powerup_comet->comet.expl >= 0)
+ if (powerup_comet->comet.expl >= 0)
{
powerup_comet->comet.expl++;
- if(powerup_comet->comet.expl >= sprites[IMG_COMET_EXPL]->num_frames * 2)
+ if (powerup_comet->comet.expl >= sprites[IMG_COMET_EXPL]->num_frames * 2)
{
powerup_comet->comet.alive = 0;
powerup_comet->comet.expl = -1;
- if(powerup_comet->comet.answer_surf)
- {SDL_FreeSurface(powerup_comet->comet.answer_surf); powerup_comet->comet.answer_surf = NULL; }
- if(powerup_comet->comet.formula_surf)
- {SDL_FreeSurface(powerup_comet->comet.formula_surf); powerup_comet->comet.formula_surf = NULL; }
- if(powerup_comet->comet.zapped)
+ if (powerup_comet->comet.answer_surf)
+ {
+ SDL_FreeSurface(powerup_comet->comet.answer_surf);
+ powerup_comet->comet.answer_surf = NULL;
+ }
+ if (powerup_comet->comet.formula_surf)
{
- switch(powerup_comet->type)
+ SDL_FreeSurface(powerup_comet->comet.formula_surf);
+ powerup_comet->comet.formula_surf = NULL;
+ }
+ if (powerup_comet->comet.zapped)
+ {
+ switch (powerup_comet->type)
+ {
+ case SMARTBOMB:
+ smartbomb_alive = 1;
+ tts_announcer_switch = 5;
+ powerup_comet_running = 0;
+ break;
+ default: // do nothing
{
- case SMARTBOMB:
- smartbomb_alive = 1;
- tts_announcer_switch = 5;
- powerup_comet_running = 0;
- break;
- default: //do nothing
- {}
+ }
}
}
- }
+ }
}
else
{
- switch(powerup_comet->direction)
+ switch (powerup_comet->direction)
{
- case POWERUP_DIR_LEFT:
- if(powerup_comet->comet.x <= 0)
- {
- powerup_comet->comet.alive = 0;
- powerup_comet_running = 0;
- }
- break;
+ case POWERUP_DIR_LEFT:
+ if (powerup_comet->comet.x <= 0)
+ {
+ powerup_comet->comet.alive = 0;
+ powerup_comet_running = 0;
+ }
+ break;
- case POWERUP_DIR_RIGHT:
- if(powerup_comet->comet.x >= screen->w)
- {
- powerup_comet->comet.alive = 0;
- powerup_comet_running = 0;
- }
- break;
+ case POWERUP_DIR_RIGHT:
+ if (powerup_comet->comet.x >= screen->w)
+ {
+ powerup_comet->comet.alive = 0;
+ powerup_comet_running = 0;
+ }
+ break;
- default: //do nothing
- {}
+ default: // do nothing
+ {
+ }
}
- //Tell MathCards user missed it:
- if(powerup_comet_running == 0)
- {
- if(Opts_LanMode())
+ // Tell MathCards user missed it:
+ if (powerup_comet_running == 0)
+ {
+ if (Opts_LanMode())
#ifdef HAVE_LIBSDL_NET
LAN_NotAnsweredCorrectly(powerup_comet->comet.flashcard.question_id);
#else
- {}
+ {
+ }
#endif
else
MC_NotAnsweredCorrectly(curr_game, powerup_comet->comet.flashcard.question_id);
@@ -3562,7 +3571,6 @@ void comets_handle_powerup(void)
}
}
-
#ifdef HAVE_LIBSDL_NET
/***************** Functions for LAN support *****************/
@@ -3573,109 +3581,110 @@ void comets_handle_net_messages(void)
{
char buf[NET_BUF_LEN];
int done = 0;
- while(!done)
+ while (!done)
{
- switch(LAN_NextMsg(buf))
+ switch (LAN_NextMsg(buf))
+ {
+ case 1: // Message received (e.g. a new question):
+ comets_handle_net_msg(buf);
+ break;
+ case 0: // No more messages:
+ done = 1;
+ break;
+ case -1: // Error in networking or server:
+ done = 1;
+ network_error = 1;
+ default:
{
- case 1: //Message received (e.g. a new question):
- comets_handle_net_msg(buf);
- break;
- case 0: //No more messages:
- done = 1;
- break;
- case -1: //Error in networking or server:
- done = 1;
- network_error = 1;
- default:
- {}
+ }
}
//"empty" buffer before next time through:
buf[0] = '\0';
}
}
-
-void comets_handle_net_msg(char* buf)
+void comets_handle_net_msg(char *buf)
{
- DEBUGMSG(debug_game|debug_lan, "Received server message: %s\n", buf);
+ DEBUGMSG(debug_game | debug_lan, "Received server message: %s\n", buf);
- if(strncmp(buf, "PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
+ if (strncmp(buf, "PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
{
- DEBUGMSG(debug_game|debug_lan, "buf is %s\n", buf);
+ DEBUGMSG(debug_game | debug_lan, "buf is %s\n", buf);
}
- else if(strncmp(buf, "ADD_QUESTION", strlen("ADD_QUESTION")) == 0)
+ else if (strncmp(buf, "ADD_QUESTION", strlen("ADD_QUESTION")) == 0)
{
- if(!add_quest_recvd(buf))
+ if (!add_quest_recvd(buf))
fprintf(stderr, "ADD_QUESTION received but could not add question\n");
- else
- DEBUGCODE(debug_game|debug_lan) print_current_quests();
+ else
+ DEBUGCODE(debug_game | debug_lan)
+ print_current_quests();
}
- else if(strncmp(buf, "REMOVE_QUESTION", strlen("REMOVE_QUESTION")) == 0)
+ else if (strncmp(buf, "REMOVE_QUESTION", strlen("REMOVE_QUESTION")) == 0)
{
- if(!remove_quest_recvd(buf)) //remove the question with id in buf
+ if (!remove_quest_recvd(buf)) // remove the question with id in buf
{
- DEBUGMSG(debug_game|debug_lan, "REMOVE_QUESTION received but could not remove question\n");
- DEBUGMSG(debug_game|debug_lan, "(this is OK if it was answered by this player, as it was removed already)\n");
+ DEBUGMSG(debug_game | debug_lan, "REMOVE_QUESTION received but could not remove question\n");
+ DEBUGMSG(debug_game | debug_lan, "(this is OK if it was answered by this player, as it was removed already)\n");
}
- else
- DEBUGCODE(debug_game|debug_lan) print_current_quests();
+ else
+ DEBUGCODE(debug_game | debug_lan)
+ print_current_quests();
}
- else if(strncmp(buf, "TOTAL_QUESTIONS", strlen("TOTAL_QUESTIONS")) == 0)
+ else if (strncmp(buf, "TOTAL_QUESTIONS", strlen("TOTAL_QUESTIONS")) == 0)
{
- sscanf(buf,"%*s %d", &total_questions_left);
- if(!total_questions_left)
+ sscanf(buf, "%*s %d", &total_questions_left);
+ if (!total_questions_left)
game_over_other = 1;
}
- else if(strncmp(buf, "WAVE", strlen("WAVE")) == 0)
+ else if (strncmp(buf, "WAVE", strlen("WAVE")) == 0)
{
wave_recvd(buf);
}
- else if(strncmp(buf, "MISSION_ACCOMPLISHED", strlen("MISSION_ACCOMPLISHED")) == 0)
+ else if (strncmp(buf, "MISSION_ACCOMPLISHED", strlen("MISSION_ACCOMPLISHED")) == 0)
{
game_over_won = 1;
}
- else if(strncmp(buf, "PLAYER_LEFT", strlen("PLAYER_LEFT")) == 0)
+ else if (strncmp(buf, "PLAYER_LEFT", strlen("PLAYER_LEFT")) == 0)
{
player_left_recvd(buf);
}
- else if(strncmp(buf, "comets_HALTED", strlen("comets_HALTED")) == 0)
+ else if (strncmp(buf, "comets_HALTED", strlen("comets_HALTED")) == 0)
{
comets_halted_recvd(buf);
}
- else if(strncmp(buf, "LAN_INTERCEPTED", strlen("LAN_INTERCEPTED")) == 0)
+ else if (strncmp(buf, "LAN_INTERCEPTED", strlen("LAN_INTERCEPTED")) == 0)
{
/* Message handled within network.c - do nothing here */
}
else
{
- DEBUGMSG(debug_game|debug_lan, "Unrecognized message from server: %s\n", buf);
- }
+ DEBUGMSG(debug_game | debug_lan, "Unrecognized message from server: %s\n", buf);
+ }
}
-
-int add_quest_recvd(char* buf)
+int add_quest_recvd(char *buf)
{
- MC_FlashCard fc;
+ MC_FlashCard fc;
- DEBUGMSG(debug_game|debug_lan, "Enter add_quest_recvd(), buf is: %s\n", buf);
+ DEBUGMSG(debug_game | debug_lan, "Enter add_quest_recvd(), buf is: %s\n", buf);
- if(!buf)
+ if (!buf)
{
fprintf(stderr, "NULL buf\n");
return 0;
}
/* function call to parse buffer and receive question */
- if(!MC_MakeFlashcard(buf, &fc))
+ if (!MC_MakeFlashcard(buf, &fc))
{
fprintf(stderr, "Unable to parse buffer into FlashCard\n");
return 0;
@@ -3683,30 +3692,27 @@ int add_quest_recvd(char* buf)
/* If we have an open comet slot, put question in: */
- if(lan_add_comet(&fc))
+ if (lan_add_comet(&fc))
{
- if(num_attackers > 0)
+ if (num_attackers > 0)
num_attackers--;
}
else
fprintf(stderr, "add_quest_recvd() - was unable to add question from server\n");
-
return 1;
}
-
/* Add a comet to a lan game: Note that in the lan game, the comets are added
* immediately when a new question comes in. It is up to the server to time
* them appropriately - DSB. */
-int lan_add_comet(MC_FlashCard* fc)
-{
- static int prev_city = -1;
+int lan_add_comet(MC_FlashCard *fc)
+{
+ static int prev_city = -1;
int i;
int com_found = -1;
-
- DEBUGCODE(debug_game|debug_lan)
+ DEBUGCODE(debug_game | debug_lan)
{
fprintf(stderr, "Entering lan_add_comet(), card is\n");
print_card(*fc);
@@ -3715,21 +3721,20 @@ int lan_add_comet(MC_FlashCard* fc)
}
/* Make sure question is "sane" before we add it: */
- if(fc->answer > 999 || fc->answer < -999)
+ if (fc->answer > 999 || fc->answer < -999)
{
fprintf(stderr, "Warning, card with invalid answer encountered: %d\n",
fc->answer);
return 0;
}
-
/* Look for a free comet slot: */
for (i = 0; i < MAX_MAX_COMETS; i++)
{
if (!comets[i].alive)
{
com_found = i;
- DEBUGMSG(debug_game|debug_lan, "lan_add_comet(): free comet slot found = %d\n", i);
+ DEBUGMSG(debug_game | debug_lan, "lan_add_comet(): free comet slot found = %d\n", i);
break;
}
}
@@ -3737,21 +3742,22 @@ int lan_add_comet(MC_FlashCard* fc)
if (-1 == com_found)
{
/* free comet slot not found - no comet added: */
- DEBUGMSG(debug_game|debug_lan, "lan_add_comet() called but no free comet slot\n");
- DEBUGCODE(debug_game|debug_lan) print_current_quests();
+ DEBUGMSG(debug_game | debug_lan, "lan_add_comet() called but no free comet slot\n");
+ DEBUGCODE(debug_game | debug_lan)
+ print_current_quests();
return 0;
}
-
-
/* Now we have a vacant comet slot at com_found and */
/* a valid question for it. */
/* If we make it to here, create a new comet!*/
MC_CopyCard(fc, &(comets[com_found].flashcard));
comets[com_found].answer = fc->answer;
comets[com_found].alive = 1;
- if(comets[com_found].formula_surf) SDL_FreeSurface(comets[com_found].formula_surf);
- if(comets[com_found].answer_surf) SDL_FreeSurface(comets[com_found].answer_surf);
+ if (comets[com_found].formula_surf)
+ SDL_FreeSurface(comets[com_found].formula_surf);
+ if (comets[com_found].answer_surf)
+ SDL_FreeSurface(comets[com_found].answer_surf);
comets[com_found].formula_surf = T4K_BlackOutline(comets[com_found].flashcard.formula_string, comet_fontsize, &white);
comets[com_found].answer_surf = T4K_BlackOutline(comets[com_found].flashcard.answer_string, comet_fontsize, &white);
// num_comets_alive++;
@@ -3761,8 +3767,7 @@ int lan_add_comet(MC_FlashCard* fc)
do
{
i = rand() % NUM_CITIES;
- }
- while (i == prev_city);
+ } while (i == prev_city);
prev_city = i;
@@ -3778,10 +3783,10 @@ int lan_add_comet(MC_FlashCard* fc)
/* Record the time at which this comet was created */
comets[com_found].time_started = SDL_GetTicks();
- DEBUGMSG(debug_game|debug_lan, "lan_add_comet(): formula string is: %s\n", comets[com_found].flashcard.formula_string);
+ DEBUGMSG(debug_game | debug_lan, "lan_add_comet(): formula string is: %s\n", comets[com_found].flashcard.formula_string);
/* No bonus comets in lan game for now: */
- //DEBUGMSG(debug_game|debug_lan, "bonus_comet_counter is %d\n",bonus_comet_counter);
+ // DEBUGMSG(debug_game|debug_lan, "bonus_comet_counter is %d\n",bonus_comet_counter);
if (bonus_comet_counter == 1)
{
@@ -3791,19 +3796,18 @@ int lan_add_comet(MC_FlashCard* fc)
// DEBUGMSG(debug_game|debug_lan, "Created bonus comet");
}
-
/* No powerup comets in lan game for now: */
- //int t=-1;
- //if(!powerup_comet_running)
+ // int t=-1;
+ // if(!powerup_comet_running)
//{
- // t = rand()%10;
- // if( t < 1 )
- // {
- // powerup_add_comet();
- // }
- //}
+ // t = rand()%10;
+ // if( t < 1 )
+ // {
+ // powerup_add_comet();
+ // }
+ // }
- DEBUGCODE(debug_game|debug_lan)
+ DEBUGCODE(debug_game | debug_lan)
{
fprintf(stderr, "Leaving lan_add_comet(), questions are:\n");
print_current_quests();
@@ -3813,88 +3817,83 @@ int lan_add_comet(MC_FlashCard* fc)
return 1;
}
-
-int remove_quest_recvd(char* buf)
+int remove_quest_recvd(char *buf)
{
int id = 0;
int answered_by = -1;
- char* p = NULL;
- comet_type* zapped_comet;
+ char *p = NULL;
+ comet_type *zapped_comet;
- if(!buf)
+ if (!buf)
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - returning because buf is NULL\n");
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - returning because buf is NULL\n");
return 0;
}
p = strchr(buf, '\t');
- if(!p)
+ if (!p)
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - returning because strchr() failed to find first tab char\n");
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - returning because strchr() failed to find first tab char\n");
return 0;
}
p++;
id = atoi(p);
- //Now get index of player who answered it:
+ // Now get index of player who answered it:
p = strchr(p, '\t');
- if(!p)
+ if (!p)
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - returning because strchr() failed to find second tab char\n");
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - returning because strchr() failed to find second tab char\n");
return 0;
}
p++;
answered_by = atoi(p);
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() for id = %d, answered by %d\n", id, answered_by);
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() for id = %d, answered by %d\n", id, answered_by);
- if(id < 1) // The question_id can never be negative or zero
+ if (id < 1) // The question_id can never be negative or zero
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - illegal question_id: %d\n", id);
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - illegal question_id: %d\n", id);
return 0;
}
- if(answered_by == LAN_MyIndex()) //If we answered, it's already removed
+ if (answered_by == LAN_MyIndex()) // If we answered, it's already removed
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - answered and already removed by this client\n");
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - answered and already removed by this client\n");
return 0;
}
zapped_comet = search_comets_by_id(id);
- if(!zapped_comet)
+ if (!zapped_comet)
{
- DEBUGMSG(debug_game|debug_lan, "remove_quest_recvd() - could not find comet with id = %d\n", id);
+ DEBUGMSG(debug_game | debug_lan, "remove_quest_recvd() - could not find comet with id = %d\n", id);
return 0;
}
- DEBUGMSG(debug_game|debug_lan, "comet on screen found with question_id = %d\n", id);
+ DEBUGMSG(debug_game | debug_lan, "comet on screen found with question_id = %d\n", id);
erase_comet_on_screen(zapped_comet, answered_by);
return 1;
}
-
-
-
-
/* Receive notification of the current wave */
-int wave_recvd(char* buf)
+int wave_recvd(char *buf)
{
int updated_wave = 0;
- char* p = NULL;
+ char *p = NULL;
- if(buf == NULL)
+ if (buf == NULL)
return 0;
// get updated_wave:
p = strchr(buf, '\t');
- if(!p)
+ if (!p)
return 0;
p++;
- updated_wave = atoi(p);
+ updated_wave = atoi(p);
DEBUGMSG(debug_lan, "wave_score_recvd() - buf is: %s\n", buf);
DEBUGMSG(debug_lan, "updated_wave is: %d\n", updated_wave);
- if(updated_wave != wave)
+ if (updated_wave != wave)
{
reset_level();
}
@@ -3902,36 +3901,33 @@ int wave_recvd(char* buf)
return 1;
}
-
-int player_left_recvd(char* buf)
+int player_left_recvd(char *buf)
{
char _tmpbuf[512];
- char* name;
- //Adjust font size for resolution:
+ char *name;
+ // Adjust font size for resolution:
int fontsize = (int)(DEFAULT_MENU_FONT_SIZE * get_scale());
- if(!buf)
+ if (!buf)
return 0;
name = buf + strlen("PLAYER_LEFT\t");
snprintf(_tmpbuf, sizeof(_tmpbuf), _("%s has left the game."), name);
- if(player_left_surf)
+ if (player_left_surf)
SDL_FreeSurface(player_left_surf);
- player_left_surf = T4K_BlackOutline( _tmpbuf, fontsize, &white);
+ player_left_surf = T4K_BlackOutline(_tmpbuf, fontsize, &white);
player_left_time = SDL_GetTicks();
player_left_pos.y = T4K_GetScreen()->h - player_left_surf->h;
return 1;
}
-
-int comets_halted_recvd(char* buf)
+int comets_halted_recvd(char *buf)
{
comets_halted_by_server = 1;
return 1;
}
-
-comet_type* search_comets_by_id(int id)
+comet_type *search_comets_by_id(int id)
{
int i;
for (i = 0; i < MAX_MAX_COMETS; i++)
@@ -3946,219 +3942,219 @@ comet_type* search_comets_by_id(int id)
return NULL;
}
-
-
-int erase_comet_on_screen(comet_type* comet, int answered_by)
+int erase_comet_on_screen(comet_type *comet, int answered_by)
{
- if(!comet)
+ if (!comet)
return 0;
- //setting expl to 0 starts comet explosion animation
+ // setting expl to 0 starts comet explosion animation
comet->expl = 0;
- //TODO consider more elaborate sound or animation
+ // TODO consider more elaborate sound or animation
playsound(SND_SIZZLE);
return 1;
}
/* For sorting of sorted_scores array */
-int compare_scores(const void* p1, const void* p2)
+int compare_scores(const void *p1, const void *p2)
{
- lan_player_type* lan1 = (lan_player_type*)p1;
- lan_player_type* lan2 = (lan_player_type*)p2;
+ lan_player_type *lan1 = (lan_player_type *)p1;
+ lan_player_type *lan2 = (lan_player_type *)p2;
return (lan2->score - lan1->score);
-}
-
-#endif //HAVE_LIBSDL_NET
+}
+#endif // HAVE_LIBSDL_NET
/* Print the current questions and the number of remaining questions: */
void print_current_quests(void)
{
int i;
fprintf(stderr, "\n------------ Current Questions: -----------\n");
- for(i = 0; i < MAX_MAX_COMETS; i++)
- {
- if(comets[i].alive == 1)
+ for (i = 0; i < MAX_MAX_COMETS; i++)
+ {
+ if (comets[i].alive == 1)
fprintf(stderr, "Comet %d - question %d:\t%s\n", i, comets[i].flashcard.question_id, comets[i].flashcard.formula_string);
-
}
- //fprintf(stderr, "--------------Question Queue-----------------\n");
- //for(i = 0; i < QUEST_QUEUE_SIZE; i++)
+ // fprintf(stderr, "--------------Question Queue-----------------\n");
+ // for(i = 0; i < QUEST_QUEUE_SIZE; i++)
//{
- // if(quest_queue[i].question_id != -1)
- // fprintf(stderr, "quest_queue %d - question %d:\t%s\n", i, quest_queue[i].question_id, quest_queue[i].formula_string);
- // else
- // fprintf(stderr, "quest_queue %d:\tEmpty\n", i);
- //}
+ // if(quest_queue[i].question_id != -1)
+ // fprintf(stderr, "quest_queue %d - question %d:\t%s\n", i, quest_queue[i].question_id, quest_queue[i].formula_string);
+ // else
+ // fprintf(stderr, "quest_queue %d:\tEmpty\n", i);
+ // }
fprintf(stderr, "------------------------------------------\n");
}
-
-wchar_t* convert_formula_to_sentence(char *formula_string)
+wchar_t *convert_formula_to_sentence(char *formula_string)
{
- wchar_t wc_formula[2000];
- wchar_t *sentence;
- wchar_t *ptr;
- wchar_t *temp;
- sentence = malloc(sizeof(wchar_t)*2000);
- mbstowcs(wc_formula,formula_string,2000);
- temp = wcstok(wc_formula,L" ",&ptr);
- sentence[0] = L'\0';
- while(temp != NULL)
- {
- if (wcscmp(temp,L"+") == 0)
- wcscat(sentence,_(L"plus "));
- else if (wcscmp(temp,L"-") == 0)
- wcscat(sentence,_(L"minus "));
- else if (wcscmp(temp,L"÷") == 0)
- wcscat(sentence,_(L"divided by "));
- else if (wcscmp(temp,L"x") == 0)
- wcscat(sentence,_(L"Times "));
- else
- {
- wcscat(sentence,temp);
- wcscat(sentence,L" ");
- }
- temp = wcstok(NULL,L" ",&ptr);
- }
- return sentence;
+ wchar_t wc_formula[2000];
+ wchar_t *sentence;
+ wchar_t *ptr;
+ wchar_t *temp;
+ sentence = malloc(sizeof(wchar_t) * 2000);
+ mbstowcs(wc_formula, formula_string, 2000);
+ temp = wcstok(wc_formula, L" ", &ptr);
+ sentence[0] = L'\0';
+ while (temp != NULL)
+ {
+ if (wcscmp(temp, L"+") == 0)
+ wcscat(sentence, _(L"plus "));
+ else if (wcscmp(temp, L"-") == 0)
+ wcscat(sentence, _(L"minus "));
+ else if (wcscmp(temp, L"÷") == 0)
+ wcscat(sentence, _(L"divided by "));
+ else if (wcscmp(temp, L"x") == 0)
+ wcscat(sentence, _(L"Times "));
+ else
+ {
+ wcscat(sentence, temp);
+ wcscat(sentence, L" ");
+ }
+ temp = wcstok(NULL, L" ", &ptr);
+ }
+ return sentence;
}
int tts_announcer(void *unused)
{
- int i,j;
-
- int order[15],iter;
- float y_axis;
-
-
- int pitch;
- int rate;
- tts_announcer_switch = 1;
-
- SDL_Delay(20);
- T4K_Tts_wait();
-
- while(1)
- {
- if (tts_announcer_switch == 0)
- {
- goto end;
- }
- else if(tts_announcer_switch == 2)
- {
-
- if (Opts_LanMode())
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"Score Board. ");
- for (i = 0; i < MAX_CLIENTS; i++)
- {
- if(LAN_PlayerConnected(i))
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %d",LAN_PlayerName(i), LAN_PlayerScore(i));
- T4K_Tts_wait();
- }
- }
- }
- else
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"Score %d!",score);
- }
- SDL_Delay(20);
- T4K_Tts_wait();
- tts_announcer_switch = 1;
- }
- else if(tts_announcer_switch == 3)
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"%d iglu alive!",num_cities_alive);
- SDL_Delay(20);
- T4K_Tts_wait();
- tts_announcer_switch = 1;
- }
- else if(tts_announcer_switch == 4)
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"on wave %d!",wave);
- SDL_Delay(20);
- T4K_Tts_wait();
- tts_announcer_switch = 1;
- }
- else if(tts_announcer_switch == 5)
- {
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"Press 'x' key to use smart bomb!");
- SDL_Delay(20);
- T4K_Tts_wait();
- tts_announcer_switch = 1;
- }
-
-
- /* Continue the process of announcing formula */
- if(powerup_comet->comet.alive){
- T4K_Tts_say(DEFAULT_VALUE,70,INTERRUPT,"%S",convert_formula_to_sentence(powerup_comet->comet.flashcard.formula_string));
- SDL_Delay(20);
- T4K_Tts_wait();
- }
- else{
- iter = 0;
- //Getting all alive comets to
- for (i = 0; i < MAX_MAX_COMETS; i++){
- if (comets[i].alive){
- order[iter] = i;
- iter++;
- }
- }
-
- /*Odering the fishes with respect to y axis
- * we only sort and announce the last three
- * comets other wise it causes segfault */
- if (iter != 0)
- {
- for (i = 0; i < 3; i++){
- for(j = 0; j < 3; j++){
- if (comets[order[j]].y < comets[order[j+1]].y){
- y_axis = order[j+1];
- order[j+1] = order[j];
- order[j] = y_axis;
- }
- }
- }
-
- /* Announces only last three comets
- * to avoid confusion for a listener*/
- for (i = 0; i < 3 ; i++)
- {
- if (tts_announcer_switch == 0)
- goto end;
-
- //Announce if comet is alive
- if (comets[order[i]].alive)
- {
- rate = (int)(comets[order[i]].y*100)/(screen->h - igloo_vertical_offset - images[IMG_IGLOO_INTACT]->h);
- if (rate < 30)
- rate = 30;
- else if (rate > 70)
- rate = 70;
-
- T4K_Tts_say(rate,rate,INTERRUPT,"%S",
- convert_formula_to_sentence(comets[order[i]].flashcard.formula_string));
- SDL_Delay(20);
- T4K_Tts_wait();
- }
- }
- }
- }
- }
- end:
- return 0;
+ int i, j;
+
+ int order[15], iter;
+ float y_axis;
+
+ int pitch;
+ int rate;
+ tts_announcer_switch = 1;
+
+ SDL_Delay(20);
+ T4K_Tts_wait();
+
+ while (1)
+ {
+ if (tts_announcer_switch == 0)
+ {
+ goto end;
+ }
+ else if (tts_announcer_switch == 2)
+ {
+
+ if (Opts_LanMode())
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "Score Board. ");
+ for (i = 0; i < MAX_CLIENTS; i++)
+ {
+ if (LAN_PlayerConnected(i))
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, APPEND, "%s %d", LAN_PlayerName(i), LAN_PlayerScore(i));
+ T4K_Tts_wait();
+ }
+ }
+ }
+ else
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "Score %d!", score);
+ }
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ tts_announcer_switch = 1;
+ }
+ else if (tts_announcer_switch == 3)
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "%d iglu alive!", num_cities_alive);
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ tts_announcer_switch = 1;
+ }
+ else if (tts_announcer_switch == 4)
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "on wave %d!", wave);
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ tts_announcer_switch = 1;
+ }
+ else if (tts_announcer_switch == 5)
+ {
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "Press 'x' key to use smart bomb!");
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ tts_announcer_switch = 1;
+ }
+
+ /* Continue the process of announcing formula */
+ if (powerup_comet->comet.alive)
+ {
+ T4K_Tts_say(DEFAULT_VALUE, 70, INTERRUPT, "%S", convert_formula_to_sentence(powerup_comet->comet.flashcard.formula_string));
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ }
+ else
+ {
+ iter = 0;
+ // Getting all alive comets to
+ for (i = 0; i < MAX_MAX_COMETS; i++)
+ {
+ if (comets[i].alive)
+ {
+ order[iter] = i;
+ iter++;
+ }
+ }
+
+ /*Odering the fishes with respect to y axis
+ * we only sort and announce the last three
+ * comets other wise it causes segfault */
+ if (iter != 0)
+ {
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ if (comets[order[j]].y < comets[order[j + 1]].y)
+ {
+ y_axis = order[j + 1];
+ order[j + 1] = order[j];
+ order[j] = y_axis;
+ }
+ }
+ }
+
+ /* Announces only last three comets
+ * to avoid confusion for a listener*/
+ for (i = 0; i < 3; i++)
+ {
+ if (tts_announcer_switch == 0)
+ goto end;
+
+ // Announce if comet is alive
+ if (comets[order[i]].alive)
+ {
+ rate = (int)(comets[order[i]].y * 100) / (screen->h - igloo_vertical_offset - images[IMG_IGLOO_INTACT]->h);
+ if (rate < 30)
+ rate = 30;
+ else if (rate > 70)
+ rate = 70;
+
+ T4K_Tts_say(rate, rate, INTERRUPT, "%S",
+ convert_formula_to_sentence(comets[order[i]].flashcard.formula_string));
+ SDL_Delay(20);
+ T4K_Tts_wait();
+ }
+ }
+ }
+ }
+ }
+end:
+ return 0;
}
-void start_tts_announcer_thread(){
- extern SDL_Thread *tts_announcer_thread;
- tts_announcer_thread = SDL_CreateThread(tts_announcer,NULL);
+void start_tts_announcer_thread()
+{
+ SDL_Thread *tts_announcer_thread;
+ tts_announcer_thread = SDL_CreateThread(tts_announcer, NULL);
}
-void stop_tts_announcer_thread(){
- tts_announcer_switch = 0;
- T4K_Tts_stop();
+void stop_tts_announcer_thread()
+{
+ tts_announcer_switch = 0;
+ T4K_Tts_stop();
}
-
-
diff --git a/src/credits.c b/src/credits.c
index c4c5b2b..d6cafff 100644
--- a/src/credits.c
+++ b/src/credits.c
@@ -24,8 +24,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-
-
#include
#include
#include
@@ -39,23 +37,23 @@ along with this program. If not, see . */
#include "credits.h"
const char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
- {"-"N_("TUX, OF MATH COMMAND")}, /* '-' at beginning makes highlighted: */
+ {"-" N_("TUX, OF MATH COMMAND")}, /* '-' at beginning makes highlighted: */
{N_("COPYRIGHT 2001-2011")},
- {N_("VERSION ")VERSION},
+ {N_("VERSION ") VERSION},
{" "},
{N_("PART OF THE 'TUX4KIDS' PROJECT")},
{"http://tux4kids.alioth.debian.org"},
{" "},
- {"-"N_("DESIGNED BY")},
+ {"-" N_("DESIGNED BY")},
{"SAM 'CRISWELL' HART"},
{" "},
- {"-"N_("LEAD PROGRAMMERS")},
+ {"-" N_("LEAD PROGRAMMERS")},
{"BILL KENDRICK,"},
{"NEW BREED SOFTWARE"},
{"DAVID BRUCE"},
{"TIM HOLY"},
{" "},
- {"-"N_("ADDITIONAL CODE")},
+ {"-" N_("ADDITIONAL CODE")},
{"GLEN DITCHFIELD"},
{"MICHAEL BEHRISCH"},
{"DONNY VISZNEKI"},
@@ -71,20 +69,20 @@ const char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
{"JOHNDHEL MACEDA"},
{"\"Neynt\""},
{" "},
- {"-"N_("LEAD ARTISTS")},
+ {"-" N_("LEAD ARTISTS")},
{"SAM HART"},
{"TEEJAY DEGUZMAN"},
{" "},
- {"-"N_("ADDITIONAL ART")},
+ {"-" N_("ADDITIONAL ART")},
{"BILL KENDRICK"},
{"KENDRA SWANSON & LINNEA HOLY"},
{"\"recKz\""},
{"\"Smu33rules\""},
{" "},
- {"-"N_("SOUND EFFECTS")},
+ {"-" N_("SOUND EFFECTS")},
{"TBA"},
{" "},
- {"-"N_("MUSIC")},
+ {"-" N_("MUSIC")},
{"BEYOND THE HORIZON"},
{"BY MYSTRA OF STONE ARTS, 1994"},
{" "},
@@ -103,15 +101,15 @@ const char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
{"GRAVITY"},
{"BY SERBERIS"},
{" "},
- {"-"N_("PACKAGERS")},
+ {"-" N_("PACKAGERS")},
{"JESSE ANDREWS"},
{"HOLGER LEVSEN"},
{"DAVID BRUCE"},
{" "},
- {"-"N_("'TUX' THE PENGUIN CREATED BY")},
+ {"-" N_("'TUX' THE PENGUIN CREATED BY")},
{"LARRY EWING"},
{" "},
- {"-"N_("TESTERS")},
+ {"-" N_("TESTERS")},
{"PETE SALZMAN"},
{"ST. CATHERINE ELEM., CINCINNATI, OH"},
{"WESTWOOD ELEMENTARY, CINCINNATI, OH"},
@@ -123,10 +121,10 @@ const char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
{"STEPHANIE CHAPIE & HOWARD NATHANSON"},
{" "},
{" "},
- {"-"N_("USER WEBSITE")},
+ {"-" N_("USER WEBSITE")},
{"http://tux4kids.alioth.debian.org"},
{" "},
- {"-"N_("TUX4KIDS DEVELOPMENT HOSTED AT ALIOTH:")},
+ {"-" N_("TUX4KIDS DEVELOPMENT HOSTED AT ALIOTH:")},
{"http://alioth.debian.org"},
{" "},
{N_("TuxMath is Free Software licensed under the GNU General Public License (GPL). As such, you are specifically granted the rights that are usually denied to users of proprietary software.")},
@@ -137,9 +135,7 @@ const char credit_text[MAX_LINES][MAX_LINEWIDTH] = {
{" "},
{N_("For more information about Free Software and the GNU GPL, visit:")},
{"http://www.fsf.org"},
- {" "}
-};
-
+ {" "}};
/* Some simple pixel-based characters we can blit quickly: */
@@ -376,38 +372,33 @@ char chars[39][5][5] = {
"..#..",
".....",
".....",
- "....."}
-};
-
-
-//void draw_text(char * str, SDL_Rect dest);
+ "....."}};
+// void draw_text(char * str, SDL_Rect dest);
int line;
-
int credits(void)
{
- int i,done, quit, scroll;
+ int i, done, quit, scroll;
SDL_Rect subscreen, dest;
-
- char credit_tts_text[MAX_LINES*MAX_LINEWIDTH];
+ char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
+
+ char credit_tts_text[MAX_LINES * MAX_LINEWIDTH];
credit_tts_text[0] = '\0';
- for (i = 0; i< MAX_LINES;i++)
- {
- strcat(credit_tts_text,credit_text[i]);
- }
- strcat(credit_tts_text,"Thaks for reading \0");
- //fprintf(stderr,"OUTPUT = %s \n LEN = %d",credit_tts_text,MAX_LINES*MAX_LINEWIDTH);
-
- T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,INTERRUPT,"%s",credit_tts_text);
-
+ for (i = 0; i < MAX_LINES; i++)
+ {
+ strcat(credit_tts_text, credit_text[i]);
+ }
+ strcat(credit_tts_text, "Thaks for reading \0");
+ // fprintf(stderr,"OUTPUT = %s \n LEN = %d",credit_tts_text,MAX_LINES*MAX_LINEWIDTH);
+
+ T4K_Tts_say(DEFAULT_VALUE, DEFAULT_VALUE, INTERRUPT, "%s", credit_tts_text);
/* Clear window: */
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
-
/* Draw title: */
dest.x = (screen->w - images[IMG_TITLE]->w) / 2;
@@ -417,7 +408,6 @@ int credits(void)
SDL_BlitSurface(images[IMG_TITLE], NULL, screen, &dest);
-
/* --- MAIN OPTIONS SCREEN LOOP: --- */
done = 0;
@@ -433,7 +423,7 @@ int credits(void)
/*convert the text array to one wrapped at 40 columns: */
T4K_LineWrapList(credit_text, wrapped_lines, 40, MAX_LINES, MAX_LINEWIDTH);
quit = scroll_text(wrapped_lines, subscreen, 2);
- fprintf(stderr,"\n%s",credit_text[10]);
+ fprintf(stderr, "\n%s", credit_text[10]);
/* Return the chosen command: */
@@ -449,17 +439,17 @@ int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int spe
line = 0;
- //Figure out how tall each line needs to be:
+ // Figure out how tall each line needs to be:
{
- SDL_Surface* s = T4K_SimpleText("A", DEFAULT_MENU_FONT_SIZE, &white);
- if(s)
- {
+ SDL_Surface *s = T4K_SimpleText("A", DEFAULT_MENU_FONT_SIZE, &white);
+ if (s)
+ {
line_height = s->h;
SDL_FreeSurface(s);
}
}
- //Now actually scroll text:
+ // Now actually scroll text:
do
{
/* Handle any incoming events: */
@@ -487,7 +477,7 @@ int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int spe
/* Scroll: */
src = dest = subscreen;
- src.y += speed; //amount to scroll by
+ src.y += speed; // amount to scroll by
SDL_BlitSurface(screen, &src, screen, &dest);
@@ -500,9 +490,9 @@ int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int spe
++scroll;
- if (clearing) //scroll/check, but don't display any more text
+ if (clearing) // scroll/check, but don't display any more text
{
- if (scroll > subscreen.h/speed)
+ if (scroll > subscreen.h / speed)
done = 1;
}
else
@@ -511,17 +501,17 @@ int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int spe
dest.y = subscreen.y + (subscreen.h - scroll * speed);
dest.w = 1;
dest.h = 1;
- draw_text(text[line], dest); // translation should have already occurred
+ draw_text(text[line], dest); // translation should have already occurred
if (scroll * speed >= line_height)
{
scroll = 0;
line++;
- if (text[line][0] == '\0') //end of text
+ if (text[line][0] == '\0') // end of text
{
- clearing = 1; //scroll to blank
- }
+ clearing = 1; // scroll to blank
+ }
else
DEBUGMSG(debug_titlescreen, "text[line]: %s\n", text[line]);
}
@@ -537,12 +527,11 @@ int scroll_text(char text[MAX_LINES][MAX_LINEWIDTH], SDL_Rect subscreen, int spe
}
last_time = SDL_GetTicks();
- }
- while (!done);
+ } while (!done);
return quit;
}
-#if 0 //really cool effect, but not translatable. I'll leave it in in case we
+#if 0 // really cool effect, but not translatable. I'll leave it in in case we
//decide to use it e.g. only for English
void draw_text(char * str, int offset)
{
@@ -624,37 +613,37 @@ void draw_text(char * str, int offset)
#else
-//FIXME it's possible that generating the surface every frame taxes
-//slower machines. If so consider returning the surface to be used
-//as long as it's needed.
-void draw_text(char* str, SDL_Rect dest)
+// FIXME it's possible that generating the surface every frame taxes
+// slower machines. If so consider returning the surface to be used
+// as long as it's needed.
+void draw_text(char *str, SDL_Rect dest)
{
SDL_Color col;
- SDL_Surface* surf = NULL;
+ SDL_Surface *surf = NULL;
if (!str || *str == '\0')
return;
DEBUGMSG(debug_titlescreen, "Entering draw_text(%s)\n", str);
- if (str[0] == '-') //highlight text
+ if (str[0] == '-') // highlight text
{
str++;
col.r = 128;
col.g = 192;
col.b = 255 - (40);
}
- else //normal color
+ else // normal color
{
col.r = 255 - (line % 256);
col.g = 255 / 2;
- col.b = (line * line * 2) % 256;
+ col.b = (line * line * 2) % 256;
}
/* This func from SDL_extras draws with SDL_Pango if avail, */
/* with SDL_ttf as fallback: */
- surf = T4K_SimpleText(str, DEFAULT_MENU_FONT_SIZE, &col);
+ surf = T4K_SimpleText(str, DEFAULT_MENU_FONT_SIZE, &col);
- dest.x -= surf->w / 2; //center text
+ dest.x -= surf->w / 2; // center text
SDL_BlitSurface(surf, NULL, screen, &dest);
SDL_FreeSurface(surf);
DEBUGMSG(debug_titlescreen, "done\n");
diff --git a/src/globals.h b/src/globals.h
index 24cc610..4bc7d04 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -26,18 +26,16 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-
-
#ifndef GLOBALS_H
#define GLOBALS_H
-// Translation stuff (now works for Mac and Win too!):
+// Translation stuff (now works for Mac and Win too!):
#include "config.h"
#include "gettext.h"
#include
-#define _(String) gettext (String)
+#define _(String) gettext(String)
#define gettext_noop(String) String
-#define N_(String) gettext_noop (String)
+#define N_(String) gettext_noop(String)
#ifdef WIN32
#define TUXLOCALE "./locale"
@@ -52,7 +50,7 @@ along with this program. If not, see . */
* if not supplied by platform:
*/
/* Somehow, configure defines HAVE_ALPHASORT and
- * HAVE_SCANDIR for mingw32 even though they are
+ * HAVE_SCANDIR for mingw32 even though they are
* not available for that build, so use our own:
*/
#if !defined HAVE_ALPHASORT || defined BUILD_MINGW32
@@ -63,7 +61,7 @@ along with this program. If not, see . */
#endif
/* debug data (now declared in libt4k_common */
-//extern int debug_status;
+// extern int debug_status;
/* bitmasks for debugging options (declared in options.c) */
extern const int debug_setup;
@@ -80,8 +78,8 @@ extern const int debug_text_and_intl;
extern const int debug_multiplayer;
/* debug macros (now in libt4k_comon) */
-//#define DEBUGCODE(mask) if((mask) & debug_status)
-//#define DEBUGMSG(mask, ...) if((mask) & debug_status){ fprintf(stderr, __VA_ARGS__); fflush(stderr); }
+// #define DEBUGCODE(mask) if((mask) & debug_status)
+// #define DEBUGMSG(mask, ...) if((mask) & debug_status){ fprintf(stderr, __VA_ARGS__); fflush(stderr); }
/* Maximum length of file path: */
#define PATH_MAX 4096
@@ -115,7 +113,7 @@ extern const int debug_multiplayer;
#define DEFAULT_MAX_COMETS 10
#define DEFAULT_USE_POWERUP_COMETS 1
#define DEFAULT_POWERUP_FREQ 10
-#define DEFAULT_SAVE_SUMMARY 1
+#define DEFAULT_SAVE_SUMMARY 1
#define DEFAULT_SOUND_HW_AVAILABLE 1
#define DEFAULT_USE_IGLOOS 1
#define DEFAULT_USE_FEEDBACK 0
@@ -130,8 +128,8 @@ extern const int debug_multiplayer;
#define DEFAULT_CUSTOM_RES 0
/* These values are hard-coded and used 'as is' by the program */
-/* (i.e. these behaviors require recompilation to change) */
-#define DEFAULT_NUM_CITIES 4 /* MUST BE AN EVEN NUMBER! */
+/* (i.e. these behaviors require recompilation to change) */
+#define DEFAULT_NUM_CITIES 4 /* MUST BE AN EVEN NUMBER! */
#define DEFAULT_MAX_CITY_COLORS 4
#define MINIMUM_SPEED 0.8
@@ -153,12 +151,13 @@ extern const int debug_multiplayer;
#define HIGH_SCORES_SAVED 10
#define HIGH_SCORE_NAME_LENGTH 32
-#define REG_RGBA 16,16,96,96
-#define SEL_RGBA 16,16,128,128
+#define REG_RGBA 16, 16, 96, 96
+#define SEL_RGBA 16, 16, 128, 128
#define PIXEL_BITS 32
-enum {
+enum
+{
CADET_HIGH_SCORE,
SCOUT_HIGH_SCORE,
RANGER_HIGH_SCORE,
@@ -167,15 +166,14 @@ enum {
NUM_MATH_COMMAND_LEVELS
};
-enum {
+enum
+{
FACTORS_HIGH_SCORE = NUM_MATH_COMMAND_LEVELS,
FRACTIONS_HIGH_SCORE,
NUM_HIGH_SCORE_LEVELS
};
-
-
-//Declared in t4k_global.h
+// Declared in t4k_global.h
extern int text_to_speech_status;
#define NAME_BUF_SIZE 200
@@ -183,11 +181,11 @@ extern int text_to_speech_status;
/* data for 'Training Academy' lessons: */
extern char **lesson_list_titles;
extern char **lesson_list_filenames;
-extern int* lesson_list_goldstars;
+extern int *lesson_list_goldstars;
extern int num_lessons;
-SDL_Thread *tts_announcer_thread;
+extern SDL_Thread *tts_announcer_thread;
#endif
-//int text_to_speech_global_switch = 1;
+// int text_to_speech_global_switch = 1;