diff --git a/include/basic.h b/include/basic.h index befc61c..3437e37 100644 --- a/include/basic.h +++ b/include/basic.h @@ -1,4 +1,4 @@ -/* $Id: basic.h,v 1.9 2003/12/24 02:38:15 stpohle Exp $ */ +/* $Id: basic.h,v 1.10 2003/12/28 01:21:42 stpohle Exp $ */ /* basic types which we need everywhere */ #ifndef _BC_BASIC_H_ @@ -14,8 +14,8 @@ #define GAME_SPECIAL_ITEMSROW 3 #define GAME_SPECIAL_ITEMSPUSH 3 #define GAME_MAX_TUNNELS 4 // number of tunnel entrys -#define GAME_TIMEOUT 30000 // game timeout 10min) -#define GAME_TIMEOUTHURRY 3000 // game timeout for hurry and dropping mode (1min) +#define GAME_TIMEOUT 600.0 // game timeout 10min) +#define GAME_OVERTIMEOUT 5.0 // second of remaining the last player #define GAME_TUNNEL_TO 0.5 // wait 0.5 seconds #define EXPLOSION_SAVE_DISTANCE 0.25 diff --git a/include/map.h b/include/map.h index 81f47af..f2e74dc 100644 --- a/include/map.h +++ b/include/map.h @@ -1,9 +1,17 @@ -/* $Id: map.h,v 1.5 2003/11/08 20:14:31 stpohle Exp $ */ +/* $Id: map.h,v 1.6 2003/12/28 01:21:42 stpohle Exp $ */ /* map.h */ #ifndef _MAP_H_ #define _MAP_H_ +#define FIELDCHECK_TIMEOUT 2.0 /* timeout for the field check function */ +#define FIELDHURRYWARN 5.0 /* hurry warning */ +#define FIELDHURRYDROPTO 0.5 /* timeout when to put in some special items */ +#define FIELDHURRYSIZE 0.25 /* timeout forresizeing the game */ +#define FIELDHURRYSIZEMIN 5 /* min size for the field */ +#define FIELDHURRYTIMEOUT 120.0 // game timeout for hurry and dropping mode (1min) + + struct __ex_field { unsigned char count; float frame; @@ -32,14 +40,14 @@ struct __map { char map [LEN_PATHFILENAME]; signed char map_selection; signed char type; // type of the map (MAPT_*); - unsigned char bombs; - unsigned char fire; - unsigned char shoes; - unsigned char mixed; - unsigned char death; - unsigned char sp_trigger; - unsigned char sp_push; - unsigned char sp_row; + int bombs; + int fire; + int shoes; + int mixed; + int death; + int sp_trigger; + int sp_push; + int sp_row; unsigned char state; // state of the map } typedef _map; diff --git a/include/menu.h b/include/menu.h index 980aacb..1725562 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,4 +1,4 @@ -/* $Id: menu.h,v 1.1 2003/12/24 02:42:05 stpohle Exp $ +/* $Id: menu.h,v 1.2 2003/12/28 01:21:42 stpohle Exp $ * GUI for menuhandling */ @@ -21,7 +21,8 @@ enum _menu_type { MENU_label = 0, MENU_button, MENU_entrytext, - MENU_entryint, + MENU_entryint32, + MENU_entryint16, MENU_entryfloat, MENU_bool, MENU_list diff --git a/src/field.c b/src/field.c index 4902cab..9aef8ba 100644 --- a/src/field.c +++ b/src/field.c @@ -1,19 +1,14 @@ -/* $Id: field.c,v 1.50 2003/11/08 20:14:32 stpohle Exp $ */ +/* $Id: field.c,v 1.51 2003/12/28 01:21:43 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ #include "bomberclone.h" - -#define FIELDECHECK_TIMEOUT 500 /* timeout for the field check function */ -#define FIELDHURRYWARN 500 /* hurry warning */ -#define FIELDHURRYDROPTO 50 /* timeout when to put in some special items */ -#define FIELDHURRYSIZE 25 /* timeout when to put in some special items */ -#define FIELDHURRYSIZEMIN 5 /* min size for the field */ +#include "map.h" static _point fieldani[MAX_FIELDANIMATION]; static _point stonelist[MAX_STONESTODRAW]; // keep all stones to draw -static int fieldcheck_to; // timeout for the next fieldcheck FIELDCHECK_TIMEOUT -static int fieldhurry_to; +static float fieldcheck_to; // timeout for the next fieldcheck FIELDCHECK_TIMEOUT +static float fieldhurry_to; // in warning mode set the blinking time static _point fieldhurrypos; // x,y for the hurry static int fieldhurryd; // direction for the hurry @@ -336,24 +331,28 @@ field_loop () if ((GT_MP_PTPM || GT_SP) && bman.state == GS_running) { /* timeout for rechecking every 5 secs the field */ + fieldcheck_to -= timediff; if (map.state == MS_normal && map.map_selection == MAPS_randgen - && (fieldcheck_to-- > FIELDECHECK_TIMEOUT || fieldcheck_to <= 0)) { + && (fieldcheck_to > FIELDCHECK_TIMEOUT || fieldcheck_to <= 0) + && bman.timeout > FIELDHURRYTIMEOUT) { if (field_checkisempty ()) - bman.timeout = 0; // set the gametimeout to 0 + bman.timeout = FIELDHURRYTIMEOUT; // let the hurry time begin + fieldcheck_to = FIELDCHECK_TIMEOUT; } - /* to show the warning */ - if (map.state == MS_normal && bman.timeout-- <= 0) { - bman.timeout = FIELDHURRYWARN; + /* set the map_state to the right setting and send the information to all clients */ + if (map.state == MS_normal + && bman.timeout <= FIELDHURRYTIMEOUT + && bman.timeout > (FIELDHURRYTIMEOUT-FIELDHURRYWARN)) { map.state = MS_hurrywarn; bman.updatestatusbar = 1; if (GT_MP_PTPM) net_send_servermode (); } - /* gametimeout is 0 and we are still at more normal set randomly a - way to end the game */ - if (bman.timeout-- <= 0 && map.state == MS_hurrywarn) { + /* after the end of the warning set the new flag */ + if (map.state == MS_hurrywarn + && bman.timeout <= (FIELDHURRYTIMEOUT-FIELDHURRYWARN)) { int rndmax; if (map.map_selection == MAPS_randgen) @@ -363,9 +362,11 @@ field_loop () map.state = 2 + s_random (rndmax); d_printf ("Game Timeout 1 over: Random map.state = %d\n", map.state); - bman.timeout = GAME_TIMEOUTHURRY; fieldhurrypos.x = fieldhurrypos.y = 0; + + if (GT_MP_PTPM) + net_send_servermode (); } /* check if we need to small down the map */ @@ -387,7 +388,9 @@ field_hurrydropitems () y = 0, try = 100; - if (fieldhurry_to-- <= 0 || fieldhurry_to > FIELDHURRYDROPTO) { + fieldhurry_to -= timediff; + + if (fieldhurry_to <= 0 || fieldhurry_to > FIELDHURRYDROPTO) { fieldhurry_to = FIELDHURRYDROPTO; while (map.field[x][y].type != FT_nothing && (try--)) { @@ -413,7 +416,8 @@ field_hurrysize () int i; _point old; - if (fieldhurry_to-- <= 0 || fieldhurry_to > FIELDHURRYSIZE) { + fieldhurry_to -= timediff; + if (fieldhurry_to <= 0 || fieldhurry_to > FIELDHURRYSIZE) { fieldhurry_to = FIELDHURRYSIZE; if (fieldhurrypos.x == 0) { @@ -421,7 +425,6 @@ field_hurrysize () fieldhurryd = right; } else if (fieldhurrypos.x > 0) { - bman.timeout = GAME_TIMEOUTHURRY-1; old = fieldhurrypos; /* save old value in case that there is an explosion or a bomb */ switch (fieldhurryd) { diff --git a/src/game.c b/src/game.c index ffa6941..bf21b7e 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.61 2003/12/24 02:38:15 stpohle Exp $ +/* $Id: game.c,v 1.62 2003/12/28 01:21:43 stpohle Exp $ game.c - procedures for the game. */ #include @@ -117,8 +117,6 @@ game_loop () SDL_Event event; Uint8 *keys; int done = 0; -// Uint32 timeloop1; - float gameovertimeout = 5.0; // gameovertimeout unsigned char key_bomb = 0; // last state of the bomb key gfx_blitupdaterectclear (); @@ -203,11 +201,10 @@ game_loop () if ((players[bman.p_nr].state & PSFM_alife) == PSFM_alife) move_player (bman.p_nr); - if (GT_MP) + if (GT_MP) { player_calcpos (); - - if (GT_MP) network_loop (); + } if (bman.state == GS_running) single_loop (); @@ -221,21 +218,21 @@ game_loop () /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ - if ((bman.players_nr < 2 + if (((bman.players_nr < 2 && (GT_MP || (GT_SP && bman.ai_players > 0))) - || (GT_SP && bman.ai_players == 0 && bman.players_nr < 1) - || (bman.timeout <= 0.0f && map.state != MS_normal)) - gameovertimeout -= timediff; + || (GT_SP && bman.ai_players == 0 && bman.players_nr < 1)) + && bman.timeout >= 0.0) + bman.timeout = 0.0f; - if (gameovertimeout <= 0) { + if (bman.timeout < -GAME_OVERTIMEOUT) { d_printf ("GAME: Game Over\n"); done = 1; } - stonelist_draw (); gfx_blitdraw (); s_calctimesync (); + bman.timeout -= timediff; } chat_show (-1, -1, -1, -1); @@ -245,7 +242,7 @@ game_loop () }; -/* check which player won and unload all data */ +/* check which player won and free all unnneded data */ void game_end () { @@ -337,6 +334,8 @@ game_start () snd_music_start (); map.state = MS_normal; bman.timeout = bman.init_timeout; + s_calctimesync (); /* to clean up the timesyc + s_calctimesync (); * data run this twice */ }; diff --git a/src/mapmenu.c b/src/mapmenu.c index 01aeb15..a4ad9ef 100644 --- a/src/mapmenu.c +++ b/src/mapmenu.c @@ -1,4 +1,4 @@ -/* $Id: mapmenu.c,v 1.14 2003/12/26 02:20:10 stpohle Exp $ */ +/* $Id: mapmenu.c,v 1.15 2003/12/28 01:21:43 stpohle Exp $ */ /* map/tileset selection menu */ #include "bomberclone.h" @@ -50,9 +50,9 @@ mapmenu () case (MAPS_randgen): // Random Generated Map selmt = charlist_findtext (maptypes, "autogenerated"); d_printf ("autogen\n"); - menu_create_entry ("X Size:", 20, 160, 120, &map.size.x, MAX_FIELDSIZE_X, MENU_entryint, + menu_create_entry ("X Size:", 20, 160, 120, &map.size.x, MAX_FIELDSIZE_X, MENU_entryint16, 2); - menu_create_entry ("Y Size:", 20, 180, 120, &map.size.y, MAX_FIELDSIZE_Y, MENU_entryint, + menu_create_entry ("Y Size:", 20, 180, 120, &map.size.y, MAX_FIELDSIZE_Y, MENU_entryint16, 3); break; } @@ -88,17 +88,17 @@ mapmenu () menu_create_list ("ts", 250, 85, 170, 40, tiletypes, &selts, 4); menu_create_list ("tt", 10, 220, 100, 60, tunneltypes, &seltt, 6); - menu_create_entry ("Bombs:", 140, 240, 110, &map.bombs, 100, MENU_entryint, 7); - menu_create_entry ("Fire: ", 140, 260, 110, &map.fire, 100, MENU_entryint, 8); - menu_create_entry ("Shoes:", 140, 280, 110, &map.shoes, 100, MENU_entryint, 9); - menu_create_entry ("Mixed:", 140, 300, 110, &map.mixed, 100, MENU_entryint, 10); - menu_create_entry ("Death:", 140, 320, 110, &map.death, 100, MENU_entryint, 11); + menu_create_entry ("Bombs:", 140, 240, 110, &map.bombs, 100, MENU_entryint32, 7); + menu_create_entry ("Fire: ", 140, 260, 110, &map.fire, 100, MENU_entryint32, 8); + menu_create_entry ("Shoes:", 140, 280, 110, &map.shoes, 100, MENU_entryint32, 9); + menu_create_entry ("Mixed:", 140, 300, 110, &map.mixed, 100, MENU_entryint32, 10); + menu_create_entry ("Death:", 140, 320, 110, &map.death, 100, MENU_entryint32, 11); - menu_create_entry ("Trigger:", 280, 240, 120, &map.sp_trigger, 30, MENU_entryint, 12); - menu_create_entry ("Push: ", 280, 260, 120, &map.sp_push, 30, MENU_entryint, 13); - menu_create_entry ("Row: ", 280, 280, 120, &map.sp_row, 30, MENU_entryint, 14); + menu_create_entry ("Trigger:", 280, 240, 120, &map.sp_trigger, 30, MENU_entryint32, 12); + menu_create_entry ("Push: ", 280, 260, 120, &map.sp_push, 30, MENU_entryint32, 13); + menu_create_entry ("Row: ", 280, 280, 120, &map.sp_row, 30, MENU_entryint32, 14); - menu_create_entry ("Game Timeout:", -1, 350, 180, &bman.init_timeout, 900, MENU_entryint, 15); + menu_create_entry ("Game Timeout:", -1, 350, 180, &bman.init_timeout, 1200, MENU_entryint32, 15); menu_create_button ("Ok", -1, 380, 150, 0); diff --git a/src/menu.c b/src/menu.c index 20eecae..1324a2d 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.31 2003/12/24 02:38:15 stpohle Exp $ +/* $Id: menu.c,v 1.32 2003/12/28 01:21:43 stpohle Exp $ * Menuhandling */ #include "basic.h" @@ -185,8 +185,10 @@ inline void menu_draw_menuitem (_menuitem *m) { case (MENU_bool): menu_draw_bool (m); break; - case (MENU_entryint): case (MENU_entrytext): + case (MENU_entryint16): + case (MENU_entryint32): + case (MENU_entryfloat): menu_draw_entry (m); break; case (MENU_list): @@ -238,7 +240,9 @@ void menu_change_focus (_menuitem *newfocus) { /* lose focus */ switch (menu.focus->type) { - case (MENU_entryint): + case (MENU_entryfloat): + case (MENU_entryint16): + case (MENU_entryint32): case (MENU_entrytext): menu_entry_lose_focus (menu.focus); break; @@ -364,8 +368,10 @@ int menu_loop () { case (MENU_bool): done = menu_event_bool (menu.focus, &event); break; - case (MENU_entryint): case (MENU_entrytext): + case (MENU_entryfloat): + case (MENU_entryint16): + case (MENU_entryint32): done = menu_event_entry (menu.focus, &event); break; case (MENU_label): diff --git a/src/menuentrys.c b/src/menuentrys.c index e2052c6..39589f8 100644 --- a/src/menuentrys.c +++ b/src/menuentrys.c @@ -1,4 +1,4 @@ -/* $Id: menuentrys.c,v 1.2 2003/12/26 00:54:28 stpohle Exp $ +/* $Id: menuentrys.c,v 1.3 2003/12/28 01:21:43 stpohle Exp $ * Menuhandling: entry */ @@ -10,15 +10,20 @@ /* save the data into the pointer */ void menu_entry_save (_menuitem *mi) { + int tmp; switch (mi->type) { - case (MENU_entryint): - sscanf (mi->keybi.text, "%d", (int *) mi->ptrdata); + case (MENU_entryint16): + sscanf (mi->keybi.text, "%d", &tmp); + *(Sint16*)mi->ptrdata = (Sint16) tmp; + break; + case (MENU_entryint32): + sscanf (mi->keybi.text, "%d", (Sint32*)mi->ptrdata); break; case (MENU_entrytext): strncpy (mi->ptrdata, mi->keybi.text, mi->len); break; case (MENU_entryfloat): - sscanf (mi->keybi.text, "%f", (float *) mi->ptrdata); + sscanf (mi->keybi.text, "%f", (float*)mi->ptrdata); break; } }; @@ -27,14 +32,17 @@ void menu_entry_save (_menuitem *mi) { /* restore the data into the pointer */ void menu_entry_restore (_menuitem *mi) { switch (mi->type) { - case (MENU_entryint): - sprintf (mi->keybi.text, "%d", (int) *mi->ptrdata); + case (MENU_entryint16): + sprintf (mi->keybi.text, "%d", *(Sint16*)mi->ptrdata); + break; + case (MENU_entryint32): + sprintf (mi->keybi.text, "%d", *(Sint32*)mi->ptrdata); break; case (MENU_entrytext): - sprintf (mi->keybi.text, "%s", (char*) mi->ptrdata); + sprintf (mi->keybi.text, "%s", (char*)mi->ptrdata); break; case (MENU_entryfloat): - sprintf (mi->keybi.text, "%f", (float) *mi->ptrdata); + sprintf (mi->keybi.text, "%f", *(float*)mi->ptrdata); break; } mi->keybi.curpos = strlen (mi->keybi.text); @@ -46,10 +54,8 @@ void menu_entry_restore (_menuitem *mi) { void menu_create_entry (char *name, int x, int y, int w, void *data, int len, int typ, int id) { int i = menu_getlastitem(menu.items); - if (typ != MENU_entryint && typ != MENU_entryfloat && typ != MENU_entrytext) { - d_fatal ("menu_create_entry: wrong typ\n"); + if (typ != MENU_entrytext && typ != MENU_entryint16 && typ != MENU_entryint32 && typ != MENU_entryfloat) return; - } if (i == -1) { /* first entry in the itemslist */ menu.items = &menuitems[0]; @@ -79,7 +85,9 @@ void menu_create_entry (char *name, int x, int y, int w, void *data, int len, in if (typ == MENU_entrytext) keybinput_new (&menuitems[i].keybi, KEYBI_text, len); - else if (typ == MENU_entryint) + else if (typ == MENU_entryint16) + keybinput_new (&menuitems[i].keybi, KEYBI_int, len); + else if (typ == MENU_entryint32) keybinput_new (&menuitems[i].keybi, KEYBI_int, len); else keybinput_new (&menuitems[i].keybi, KEYBI_float, 10); @@ -96,7 +104,7 @@ void menu_draw_entry (_menuitem *mi) { int px, py, i; SDL_Rect dest; - if (mi->type != MENU_entrytext && mi->type != MENU_entryint && mi->type != MENU_entryfloat) + if (mi->type != MENU_entrytext && mi->type != MENU_entryint16 && mi->type != MENU_entryint32 && mi->type != MENU_entryfloat) return; dest.x = mi->pos.x; diff --git a/src/sysfunc.c b/src/sysfunc.c index 8d0e3c9..fe97a61 100644 --- a/src/sysfunc.c +++ b/src/sysfunc.c @@ -1,4 +1,4 @@ -/* $Id: sysfunc.c,v 1.21 2003/12/24 02:38:16 stpohle Exp $ +/* $Id: sysfunc.c,v 1.22 2003/12/28 01:21:43 stpohle Exp $ sysfunc.c - this file hold some routines for the system functions.. like d_delay */ @@ -238,20 +238,20 @@ extern Uint32 game_timediff, game_timediff1; inline void s_calctimesync () { Uint32 timeloop1; - // calculate time sync. - timeloop1 = SDL_GetTicks (); - game_timediff = timeloop1 - timestamp; // only for debugging needed + // calculate time sync. + timeloop1 = SDL_GetTicks (); + game_timediff = timeloop1 - timestamp; // only for debugging needed - while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < 20) { - s_delay (20 - (timeloop1 - timestamp) - 1); - timeloop1 = SDL_GetTicks (); - } + while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < 20) { + s_delay (20 - (timeloop1 - timestamp) - 1); + timeloop1 = SDL_GetTicks (); + } - game_timediff1 = timeloop1 - timestamp; - timestamp = timeloop1; + game_timediff1 = timeloop1 - timestamp; + timestamp = timeloop1; - timefactor = ((float)game_timediff1) / 20.0f; - timediff = ((float)game_timediff1) / 1000.0f; + timefactor = ((float)game_timediff1) / 20.0f; + timediff = ((float)game_timediff1) / 1000.0f; }