[Tux4kids-commits] r592 - in tuxmath/trunk: mingw src
cheezmeister-guest at alioth.debian.org
cheezmeister-guest at alioth.debian.org
Wed Aug 6 23:31:27 UTC 2008
Author: cheezmeister-guest
Date: 2008-08-06 23:31:26 +0000 (Wed, 06 Aug 2008)
New Revision: 592
Modified:
tuxmath/trunk/mingw/tuxmath.cbp
tuxmath/trunk/src/campaign.c
tuxmath/trunk/src/campaign.h
tuxmath/trunk/src/fileops.c
tuxmath/trunk/src/game.c
tuxmath/trunk/src/highscore.c
tuxmath/trunk/src/highscore.h
tuxmath/trunk/src/options.h
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/tuxmath.h
Log:
A minor segfault fix and basic code for multiplayer. There are some
extremely strange memory issues seemingly with multiplayer only so it's
not used at the moment.
Modified: tuxmath/trunk/mingw/tuxmath.cbp
===================================================================
--- tuxmath/trunk/mingw/tuxmath.cbp 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/mingw/tuxmath.cbp 2008-08-06 23:31:26 UTC (rev 592)
@@ -131,6 +131,10 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="../src/mathcards.h" />
+ <Unit filename="../src/multiplayer.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="../src/multiplayer.h" />
<Unit filename="../src/options.c">
<Option compilerVar="CC" />
</Unit>
Modified: tuxmath/trunk/src/campaign.c
===================================================================
--- tuxmath/trunk/src/campaign.c 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/campaign.c 2008-08-06 23:31:26 UTC (rev 592)
@@ -15,7 +15,7 @@
char* stagenames[NUM_STAGES] = {"cadet", "scout", "ranger", "ace", "commando"};
-void start_campaign()
+int start_campaign()
{
int i, j;
int gameresult = 0, endcampaign = 0;
@@ -54,7 +54,14 @@
{
tmdprintf("Error!\n");
endcampaign = 1;
- }
+ }
+#ifndef TESTING_CAMPAIGN
+ else if (gameresult == GAME_OVER_ESCAPE)
+ {
+ tmdprintf("hit escape\n");
+ endcampaign = 1;
+ }
+#endif
else
{
printf("gameresult = %d\n", gameresult);
@@ -62,7 +69,7 @@
}
if (endcampaign)
- return;
+ return 0;
}
//if we've beaten the last stage, there is no bonus, skip to win sequence
@@ -77,7 +84,8 @@
game_set_start_message("Bonus", "", "", "");
game();
}
- scroll_text(endtext, screen->clip_rect, 3);
+ scroll_text(endtext, screen->clip_rect, 3);
+ return 0;
}
void briefPlayer(int stage)
Modified: tuxmath/trunk/src/campaign.h
===================================================================
--- tuxmath/trunk/src/campaign.h 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/campaign.h 2008-08-06 23:31:26 UTC (rev 592)
@@ -249,6 +249,6 @@
},
};
-void start_campaign();
+int start_campaign();
#endif // CAMPAIGN_H
Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/fileops.c 2008-08-06 23:31:26 UTC (rev 592)
@@ -2108,7 +2108,10 @@
if (write_column_names) {
fprintf(fp,"\"User\",\"Mission\",\"Date\",\"Completed?\",\"Number answered\",\"Percent correct\",\"Time per question\"\n");
}
- mission_name = strdup(last_config_file_name);
+ if (last_config_file_name)
+ mission_name = strdup(last_config_file_name);
+ else
+ mission_name = strdup("[NONE]");
fprintf(fp,"\"%s\",\"%s\",%d/%d/%d,%d,%d,%d,%g\n", get_user_name(), get_file_name(mission_name), datetime.tm_year+1900, datetime.tm_mon+1, datetime.tm_mday, MC_MissionAccomplished(), total_answered, ((MC_NumAnsweredCorrectly() * 100)/ total_answered), median_time);
fclose(fp);
free(mission_name);
Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/game.c 2008-08-06 23:31:26 UTC (rev 592)
@@ -671,7 +671,10 @@
SDL_FreeSurface(scaled_bkgd);
scaled_bkgd = NULL;
}
-
+
+ /* clear start message */
+ start_message_chosen = 0;
+
/* Free dynamically-allocated items */
free_on_exit();
@@ -914,10 +917,13 @@
void game_set_message(game_message *msg,const char *txt,int x,int y)
{
- msg->x = x;
- msg->y = y;
- msg->alpha = SDL_ALPHA_OPAQUE;
- strncpy(msg->message,txt,GAME_MESSAGE_LENGTH);
+ if (msg && txt)
+ {
+ msg->x = x;
+ msg->y = y;
+ msg->alpha = SDL_ALPHA_OPAQUE;
+ strncpy(msg->message,txt,GAME_MESSAGE_LENGTH);
+ }
}
void game_clear_message(game_message *msg)
Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/highscore.c 2008-08-06 23:31:26 UTC (rev 592)
@@ -347,6 +347,11 @@
/* multibyte encoding. */
void HighScoreNameEntry(unsigned char* pl_name)
{
+ NameEntry(pl_name, "You Are In The Hall of Fame!", "Enter Your Name:");
+}
+
+void NameEntry(unsigned char* pl_name, const char* heading, const char* sub)
+{
unsigned char UTF8_buf[HIGH_SCORE_NAME_LENGTH * 3] = {'\0'};
SDL_Rect loc;
@@ -425,7 +430,7 @@
/* Draw heading: */
{
- SDL_Surface* s = BlackOutline(_("You Are In The Hall of Fame!"),
+ SDL_Surface* s = BlackOutline(_(heading),
default_font, &white);
if (s)
{
@@ -435,7 +440,7 @@
SDL_FreeSurface(s);
}
- s = BlackOutline(_("Enter Your Name:"),
+ s = BlackOutline(_(sub),
default_font, &white);
if (s)
{
Modified: tuxmath/trunk/src/highscore.h
===================================================================
--- tuxmath/trunk/src/highscore.h 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/highscore.h 2008-08-06 23:31:26 UTC (rev 592)
@@ -18,8 +18,8 @@
void DisplayHighScores(int level);
void HighScoreNameEntry(unsigned char* pl_name);
+void NameEntry(unsigned char* pl_name, const char* heading, const char* sub);
-
int check_score_place(int diff_level, int new_score);
int insert_score(char* playername, int diff_level, int new_score);
void initialize_scores(void);
Modified: tuxmath/trunk/src/options.h
===================================================================
--- tuxmath/trunk/src/options.h 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/options.h 2008-08-06 23:31:26 UTC (rev 592)
@@ -57,7 +57,11 @@
float danger_level_speedup;
float danger_level_max;
float city_expl_handicap;
-
+
+ int mp_multiplayer;
+ int mp_round;
+ int mp_playernum;
+
/* whether sound system is successfully initialized and sound files loaded: */
/* this flag is set by the program, not the user, and is not in the config file. */
int sound_hw_available;
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/titlescreen.c 2008-08-06 23:31:26 UTC (rev 592)
@@ -32,6 +32,7 @@
#include "fileops.h"
#include "game.h"
#include "campaign.h"
+#include "multiplayer.h"
#include "mathcards.h"
#include "setup.h" //for cleanup()
#include "credits.h"
@@ -84,6 +85,9 @@
SPRITE_NO_GOLDSTAR,
SPRITE_TROPHY,
SPRITE_CREDITS,
+ SPRITE_ALONE,
+ SPRITE_FRIENDS,
+ SPRITE_CAMPAIGN,
N_SPRITES};
const unsigned char* menu_sprite_files[N_SPRITES] =
@@ -102,7 +106,10 @@
"goldstar",
"no_goldstar",
"trophy",
- "credits"
+ "credits",
+ "alone", //TODO give these two their own sprites
+ "tux_config_brown",
+ "tux_helmet_red"
};
sprite **sprite_list = NULL;
@@ -153,10 +160,14 @@
SDL_Rect*, SDL_Rect*);
void set_buttons_max_width(SDL_Rect *, SDL_Rect *, int);
int run_main_menu(void);
+int run_game_menu(void);
+int run_multiplay_menu(void);
+int run_lessons_menu(void);
int run_arcade_menu(void);
+int run_campaign_menu(void);
+int run_activities_menu(void);
int run_custom_menu(void);
int run_options_menu(void);
-int run_lessons_menu(void);
int handle_easter_egg(const SDL_Event* evt);
@@ -236,8 +247,9 @@
}
SDL_Delay(50);
}
-
+#ifndef TUXMATH_DEBUG //in case of a freeze, this traps the cursor
SDL_WM_GrabInput(SDL_GRAB_ON); // User input goes to TuxMath, not window manager
+#endif
SDL_ShowCursor(1);
@@ -636,9 +648,9 @@
int run_main_menu(void)
{
const unsigned char* menu_text[6] =
- {(const unsigned char*)N_("Math Command Training Academy"),
- (const unsigned char*)N_("Play Arcade Game"),
- (const unsigned char*)N_("Play Custom Game"),
+ {(const unsigned char*)N_("Play Alone"),
+ (const unsigned char*)N_("Play With Friends"),
+ (const unsigned char*)N_("Other Math Command Activities"),
(const unsigned char*)N_("Help"),
(const unsigned char*)N_("More Options"),
(const unsigned char*)N_("Quit")};
@@ -648,9 +660,9 @@
int choice,ret;
// Set up the sprites
- sprites[0] = sprite_list[SPRITE_TRAINING];
- sprites[1] = sprite_list[SPRITE_ARCADE];
- sprites[2] = sprite_list[SPRITE_CUSTOM];
+ sprites[0] = sprite_list[SPRITE_ALONE];
+ sprites[1] = sprite_list[SPRITE_FRIENDS];
+ sprites[2] = sprite_list[SPRITE_CADET];
sprites[3] = sprite_list[SPRITE_HELP];
sprites[4] = sprite_list[SPRITE_OPTIONS];
sprites[5] = sprite_list[SPRITE_QUIT];
@@ -667,18 +679,18 @@
while (choice >= 0) {
switch (choice) {
case 0: {
- // Training academy lessons
- ret = run_lessons_menu();
+ // All single player modes
+ ret = run_game_menu();
break;
}
case 1: {
- // Arcade games
- ret = run_arcade_menu();
+ // Multiplayer games
+ ret = run_multiplay_menu();
break;
}
case 2: {
- // Custom game
- ret = run_custom_menu();
+ // Factroids et. al.
+ ret = run_activities_menu();
break;
}
case 3: {
@@ -711,6 +723,95 @@
return 0;
}
+#define NUM_GAME_MENU_ITEMS 5
+int run_game_menu(void)
+{
+ const unsigned char* menu_text[NUM_GAME_MENU_ITEMS] =
+ {(const unsigned char*)N_("Math Command Training Academy"),
+ (const unsigned char*)N_("Math Command Fleet Missions"),
+ (const unsigned char*)N_("Play Arcade Game"),
+ (const unsigned char*)N_("Play Custom Game"),
+ (const unsigned char*)N_("Main menu")};
+
+ sprite* sprites[NUM_GAME_MENU_ITEMS] = {NULL, NULL, NULL, NULL, NULL};
+
+ int ret, choice = 0;
+
+ sprites[0] = sprite_list[SPRITE_TRAINING];
+ sprites[1] = sprite_list[SPRITE_CAMPAIGN];
+ sprites[2] = sprite_list[SPRITE_ARCADE];
+ sprites[3] = sprite_list[SPRITE_CUSTOM];
+ sprites[4] = sprite_list[SPRITE_MAIN];
+
+ while (choice >= 0) {
+ choice = choose_menu_item(menu_text,sprites,NUM_GAME_MENU_ITEMS,NULL,NULL);
+ switch (choice) {
+ case 0:
+ ret = run_lessons_menu();
+ break;
+ case 1:
+ ret = start_campaign();
+ break;
+ case 2:
+ ret = run_arcade_menu();
+ break;
+ case 3:
+ ret = run_custom_menu();
+ break;
+ case 4:
+ return 0;
+ default:
+ tmdprintf("choose_menu_item() returned %d--returning\n", choice);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+/*
+Set up and start a turn-based multiplayer game. Some funky heap issues so
+quarantine it behind the return for the time being.
+*/
+int run_multiplay_menu(void)
+{
+ int i;
+ int nplayers = 0;
+ int mode = 0;
+ char npstr[HIGH_SCORE_NAME_LENGTH];
+
+ char* menu_text[2] = {"Score Sweep", "Elimination"};
+ sprite* sprites = {NULL, NULL};
+
+ NotImplemented();
+ return 0;
+
+ //choose mode
+ mode = choose_menu_item(menu_text,sprites,2,NULL,NULL);
+
+ //ask how many players
+ while (nplayers <= 0)
+ {
+ NameEntry(npstr, "How many kids are playing?",
+ "(Between 2 and 4 players)");
+ nplayers = atoi(npstr);
+ }
+
+
+ mp_set_parameter(PLAYERS, nplayers);
+ mp_set_parameter(MODE, mode);
+ mp_set_parameter(DIFFICULTY, 0);
+
+ //RUN!
+ mp_run_multiplayer();
+
+ return 0;
+}
+
+int run_activities_menu(void)
+{
+ NotImplemented();
+}
+
int run_arcade_menu(void)
{
const unsigned char* menu_text[7] =
@@ -1323,17 +1424,24 @@
for (i = 0; i < n_entries_per_screen; ++i)
{
- back_button_rect[i] = menu_button_rect[i];
- back_button_rect[i].x -= Backrect.x;
- back_button_rect[i].y -= Backrect.y;
-
- back_text_rect[i] = menu_text_rect[i];
- back_text_rect[i].x -= Backrect.x;
- back_text_rect[i].y -= Backrect.y;
-
- back_sprite_rect[i] = menu_sprite_rect[i];
- back_sprite_rect[i].x -= Backrect.x;
- back_sprite_rect[i].y -= Backrect.y;
+ if (menu_button_rect)
+ {
+ back_button_rect[i] = menu_button_rect[i];
+ back_button_rect[i].x -= Backrect.x;
+ back_button_rect[i].y -= Backrect.y;
+ }
+ if (menu_text_rect)
+ {
+ back_text_rect[i] = menu_text_rect[i];
+ back_text_rect[i].x -= Backrect.x;
+ back_text_rect[i].y -= Backrect.y;
+ }
+ if (menu_sprite_rect)
+ {
+ back_sprite_rect[i] = menu_sprite_rect[i];
+ back_sprite_rect[i].x -= Backrect.x;
+ back_sprite_rect[i].y -= Backrect.y;
+ }
}
/**** Draw background, title, and Tux: ****/
Modified: tuxmath/trunk/src/tuxmath.h
===================================================================
--- tuxmath/trunk/src/tuxmath.h 2008-08-06 21:59:30 UTC (rev 591)
+++ tuxmath/trunk/src/tuxmath.h 2008-08-06 23:31:26 UTC (rev 592)
@@ -44,7 +44,7 @@
//#define NOSOUND
/* for conditional compilation of debugging output */
-//#define TUXMATH_DEBUG
+#define TUXMATH_DEBUG
/* for Tim's feedback speed control code */
//#define FEEDBACK_DEBUG
/* nice inline debugging macro */
More information about the Tux4kids-commits
mailing list