|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: game.c,v 1.86 2004/06/11 20:29:10 stpohle Exp $
|
|
|
|
/* $Id: game.c,v 1.87 2004/06/15 15:04:37 stpohle Exp $
|
|
|
|
game.c - procedures for the game. */
|
|
|
|
game.c - procedures for the game. */
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
@ -20,6 +20,7 @@ extern int blitdb_nr,
|
|
|
|
Uint32 game_timediff, game_timediff1;
|
|
|
|
Uint32 game_timediff, game_timediff1;
|
|
|
|
static float hurrywarn_to;
|
|
|
|
static float hurrywarn_to;
|
|
|
|
static int hurrywarn_state;
|
|
|
|
static int hurrywarn_state;
|
|
|
|
|
|
|
|
static _menu *menu;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
game_draw_info ()
|
|
|
|
game_draw_info ()
|
|
|
@ -148,41 +149,55 @@ game_draw_info ()
|
|
|
|
* in the GS_wait mode the chat will always be active.
|
|
|
|
* in the GS_wait mode the chat will always be active.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void game_keys_loop () {
|
|
|
|
void game_keys_loop () {
|
|
|
|
if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
|
|
|
|
|
|
|
|
/* Server is starting the game */
|
|
|
|
if (menu != NULL) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* delete all movement keys */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < BCPK_max * 2; i++)
|
|
|
|
|
|
|
|
keyb_gamekeys.state[i] = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* don't go into the game_keys if there is no menu displayed */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
|
|
|
|
|
|
|
|
/* Server is starting the game */
|
|
|
|
bman.state = GS_running;
|
|
|
|
bman.state = GS_running;
|
|
|
|
net_send_servermode ();
|
|
|
|
net_send_servermode ();
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) {
|
|
|
|
if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) {
|
|
|
|
/* Switch Fullscreen */
|
|
|
|
/* Switch Fullscreen */
|
|
|
|
SDL_WM_ToggleFullScreen(gfx.screen);
|
|
|
|
SDL_WM_ToggleFullScreen(gfx.screen);
|
|
|
|
gfx.fullscreen = !gfx.fullscreen;
|
|
|
|
gfx.fullscreen = !gfx.fullscreen;
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) {
|
|
|
|
if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) {
|
|
|
|
// Switch Debugmode
|
|
|
|
// Switch Debugmode
|
|
|
|
debug = !debug;
|
|
|
|
debug = !debug;
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
|
|
|
|
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
|
|
|
|
if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) {
|
|
|
|
if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) {
|
|
|
|
chat.active = 0;
|
|
|
|
chat.active = 0;
|
|
|
|
d_printf ("Chatmode Disabled\n");
|
|
|
|
d_printf ("Chatmode Disabled\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
game_menu_create ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
bman.state = GS_startup;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) {
|
|
|
|
if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) {
|
|
|
|
chat_setactive (1, 0);
|
|
|
|
chat_setactive (1, 0);
|
|
|
|
chat.changed = 1;
|
|
|
|
chat.changed = 1;
|
|
|
|
d_printf ("Chatmode Enabled\n");
|
|
|
|
d_printf ("Chatmode Enabled\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -192,7 +207,7 @@ void
|
|
|
|
game_loop ()
|
|
|
|
game_loop ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
SDL_Event event;
|
|
|
|
int done = 0, i;
|
|
|
|
int done = 0, i, eventstate;
|
|
|
|
|
|
|
|
|
|
|
|
gfx_blitupdaterectclear ();
|
|
|
|
gfx_blitupdaterectclear ();
|
|
|
|
|
|
|
|
|
|
|
@ -202,13 +217,15 @@ game_loop ()
|
|
|
|
net_game_fillsockaddr ();
|
|
|
|
net_game_fillsockaddr ();
|
|
|
|
SDL_Flip (gfx.screen);
|
|
|
|
SDL_Flip (gfx.screen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
timestamp = SDL_GetTicks (); // needed for time sync.
|
|
|
|
timestamp = SDL_GetTicks (); // needed for time sync.
|
|
|
|
d_gamedetail ("GAME START");
|
|
|
|
d_gamedetail ("GAME START");
|
|
|
|
draw_players ();
|
|
|
|
draw_players ();
|
|
|
|
|
|
|
|
|
|
|
|
while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
|
|
|
|
while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
|
|
|
|
if (SDL_PollEvent (&event) != 0)
|
|
|
|
if ((eventstate = SDL_PollEvent (&event)) != 0)
|
|
|
|
switch (event.type) {
|
|
|
|
switch (event.type) {
|
|
|
|
case (SDL_QUIT):
|
|
|
|
case (SDL_QUIT):
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
@ -269,6 +286,11 @@ game_loop ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stonelist_draw ();
|
|
|
|
stonelist_draw ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if there is any menu displayed do so */
|
|
|
|
|
|
|
|
if (menu != NULL)
|
|
|
|
|
|
|
|
game_menu_loop (&event, eventstate);
|
|
|
|
|
|
|
|
|
|
|
|
gfx_blitdraw ();
|
|
|
|
gfx_blitdraw ();
|
|
|
|
s_calctimesync ();
|
|
|
|
s_calctimesync ();
|
|
|
|
bman.timeout -= timediff;
|
|
|
|
bman.timeout -= timediff;
|
|
|
@ -495,7 +517,6 @@ void game_showresult () {
|
|
|
|
if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN)) {
|
|
|
|
if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN)) {
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
|
keypressed = 1;
|
|
|
|
keypressed = 1;
|
|
|
|
bman.state = GS_running;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) {
|
|
|
|
if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) {
|
|
|
@ -512,4 +533,66 @@ void game_showresult () {
|
|
|
|
|
|
|
|
|
|
|
|
s_delay (25);
|
|
|
|
s_delay (25);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bman.state != GS_quit && bman.state != GS_startup)
|
|
|
|
|
|
|
|
bman.state = GS_running;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* create the in game menu
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void game_menu_create () {
|
|
|
|
|
|
|
|
if (menu != NULL)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu = menu_new ("Gamemenu", 300, 150);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu_create_button (menu, "Back to the Game", -1, 50, 200, 1);
|
|
|
|
|
|
|
|
if (GT_SP || GT_MP_PTPM)
|
|
|
|
|
|
|
|
menu_create_button (menu, "End this Round", -1, 80, 200, 2);
|
|
|
|
|
|
|
|
menu_create_button (menu, "Quit the Game", -1, 110, 200, 3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu_focus_id (menu, 1);
|
|
|
|
|
|
|
|
menu->looprunning = 1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* in game menu_loop, will called every game loop.
|
|
|
|
|
|
|
|
* As long as this menu is displayed the gamekeys will not work.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* the drawings will be done from the main loop. So we won't
|
|
|
|
|
|
|
|
* have to draw anything on our own.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Pressing ESC will bring you back to the game.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void game_menu_loop (SDL_Event *event, int eventstate) {
|
|
|
|
|
|
|
|
int done;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (menu == NULL)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menu_draw (menu);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done = menu_event_loop (menu, event, eventstate);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* check if one of the buttons was pressed
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (done != 0) {
|
|
|
|
|
|
|
|
if (menu->focus->id == 2 && (GT_MP_PTPM || GT_SP)) { /* End Round */
|
|
|
|
|
|
|
|
bman.timeout = -GAME_OVERTIMEOUT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (menu->focus->id == 3) /* End Game */
|
|
|
|
|
|
|
|
bman.state = GS_startup;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else { /* Quit Menu */
|
|
|
|
|
|
|
|
menu_delete (menu);
|
|
|
|
|
|
|
|
menu = NULL;
|
|
|
|
|
|
|
|
gfx_blitdraw ();
|
|
|
|
|
|
|
|
draw_field ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|