@ -1,4 +1,4 @@
/* $Id: game.c,v 1.11 1 2005/04/10 00:22:17 stpohle Exp $
/* $Id: game.c,v 1.11 2 2005/07/06 13:11:55 stpohle Exp $
game . c - procedures for the game . */
# include <string.h>
@ -17,7 +17,8 @@
extern int blitdb_nr ,
blitrects_nr ;
Uint32 game_timediff , game_timediff1 ;
Uint32 game_timediff ,
game_timediff1 ;
static float hurrywarn_to ;
static int hurrywarn_state ;
static _menu * menu ;
@ -34,15 +35,15 @@ game_draw_info ()
SDL_Rect src ,
dest ;
if ( GT_MP & & ( chat . oldscreen = = NULL | | chat . window . x ! = 4 | | chat . window . y ! = 4.5 * 16 ) ) {
chat_show ( 4 , 4.5 * 16 , gfx . res . x - 8 , gfx . offset . y - 4.5 * 16 ) ;
if ( GT_MP & & ( chat . oldscreen = = NULL | | chat . window . x ! = 4 | | chat . window . y ! = 4.5 * 16 ) ) {
chat_show ( 4 , 4.5 * 16 , gfx . res . x - 8 , gfx . offset . y - 4.5 * 16 ) ;
chat_setactive ( 0 , 0 ) ;
}
if ( bman . updatestatusbar ) {
redraw_logo ( 0 , 0 , gfx . res . x , ( 4.5 * 16 ) ) ;
dest . x = dest . y = 0 ;
dest . h = 4.5 * 16 ;
dest . h = 4.5 * 16 ;
dest . w = gfx . res . x ;
gfx_blitupdaterectadd ( & dest ) ;
@ -91,12 +92,13 @@ game_draw_info ()
font_draw ( x , 0 , text , 0 , 0 ) ;
sprintf ( text , " Range: %2d " , players [ bman . p_nr ] . range ) ;
font_draw ( x , 16 , text , 0 , 0 ) ;
sprintf ( text , " Speed: %1.1f " , players [ bman . p_nr ] . speed * 10 ) ;
sprintf ( text , " Speed: %1.1f " , players [ bman . p_nr ] . speed * 10 ) ;
font_draw ( x , 32 , text , 0 , 0 ) ;
if ( players [ bman . p_nr ] . special . type ! = 0 ) {
col = players [ bman . p_nr ] . special . type + FT_sp_trigger - 1 ;
dest . x = x - 32 ;
dest . y = 16 ;
dest . w = gfx . menu_field [ col ] - > w ;
dest . h = gfx . menu_field [ col ] - > h ;
@ -119,22 +121,26 @@ game_draw_info ()
hurrywarn_state = ! hurrywarn_state ;
if ( hurrywarn_state ) {
font_drawbold ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 , " HURRY HURRY " , 1 , 0 , 2 ) ;
font_draw ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 , " HURRY HURRY " , 1 , 1 ) ;
font_drawbold ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 ,
" HURRY HURRY " , 1 , 0 , 2 ) ;
font_draw ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 ,
" HURRY HURRY " , 1 , 1 ) ;
}
else {
font_drawbold ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 , " HURRY HURRY " , 1 , 1 , 2 ) ;
font_draw ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 , " HURRY HURRY " , 1 , 0 ) ;
font_drawbold ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 ,
" HURRY HURRY " , 1 , 1 , 2 ) ;
font_draw ( ( gfx . res . x - strlen ( " HURRY HURRY " ) * font [ 1 ] . size . x ) / 2 , 40 ,
" HURRY HURRY " , 1 , 0 ) ;
}
dest . x = dest . y = 0 ;
dest . h = 4.5 * 16 ;
dest . h = 4.5 * 16 ;
dest . w = gfx . res . x ;
gfx_blitupdaterectadd ( & dest ) ;
}
}
if ( debug )
debug_ingameinfo ( ) ;
debug_ingameinfo ( ) ;
bman . updatestatusbar = 0 ;
} ;
@ -147,10 +153,11 @@ game_draw_info ()
* chat mode : the chatmode should only be disabled in the game mode
* in the GS_wait mode the chat will always be active .
*/
void game_keys_loop ( ) {
void
game_keys_loop ( )
{
if ( menu ! = NULL ) {
/* delete all movement keys */
int i ;
@ -161,11 +168,13 @@ void game_keys_loop () {
/* 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 ] ) {
if ( GT_MP_PTPM & & bman . state = = GS_ready & & keyb_gamekeys . state [ BCK_pause ]
& & ! keyb_gamekeys . old [ BCK_pause ] ) {
/* Server is starting the game
* check in multiplayer if all players are ready for the game
*/
int i , ready = 1 ;
int i ,
ready = 1 ;
for ( i = 0 ; i < MAX_PLAYERS ; i + + )
if ( NET_CANSEND ( i ) & & ! players [ i ] . ready )
@ -182,7 +191,7 @@ void game_keys_loop () {
if ( keyb_gamekeys . state [ BCK_fullscreen ] & & ! keyb_gamekeys . old [ BCK_fullscreen ] ) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen ( gfx . screen ) ;
SDL_WM_ToggleFullScreen ( gfx . screen ) ;
gfx . fullscreen = ! gfx . fullscreen ;
bman . updatestatusbar = 1 ; // force an update
}
@ -204,7 +213,8 @@ void game_keys_loop () {
game_menu_create ( ) ;
}
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 . changed = 1 ;
d_printf ( " Chatmode Enabled \n " ) ;
@ -218,8 +228,8 @@ void
game_loop ( )
{
SDL_Event event ;
int done = 0 , eventstate ;
int ready_timestamp = 0 ;
int done = 0 ,
eventstate ;
if ( GT_MP )
net_game_fillsockaddr ( ) ;
@ -229,13 +239,11 @@ game_loop ()
timestamp = SDL_GetTicks ( ) ; // needed for time sync.
d_gamedetail ( " GAME START " ) ;
if ( ! bman . dedicated ) {
gfx_blitupdaterectclear ( ) ;
draw_logo ( ) ;
draw_field ( ) ;
SDL_Flip ( gfx . screen ) ;
draw_players ( ) ;
}
if ( bman . p_nr > = 0 & & bman . p_nr < MAX_PLAYERS ) {
players [ bman . p_nr ] . ready = 1 ;
@ -249,8 +257,6 @@ game_loop ()
}
while ( ! done & & ( bman . state = = GS_running | | bman . state = = GS_ready ) ) {
if ( ! bman . dedicated ) {
if ( ( eventstate = SDL_PollEvent ( & event ) ) ! = 0 )
switch ( event . type ) {
case ( SDL_QUIT ) :
@ -272,31 +278,11 @@ game_loop ()
chat_setactive ( 1 , 1 ) ;
restore_players_screen ( ) ;
}
/* check if we have a dedicated server */
if ( bman . dedicated & & bman . state = = GS_ready ) {
int i , ready = 1 ;
for ( i = 0 ; i < MAX_PLAYERS ; i + + )
if ( NET_CANSEND ( i ) & & ! players [ i ] . ready )
ready = 0 ;
if ( ready & & ready_timestamp = = 0 )
ready_timestamp = timestamp ;
if ( ready & & ( timestamp - ready_timestamp ) > 2500 ) {
bman . state = GS_running ;
net_send_servermode ( ) ;
}
}
player_check ( bman . p_nr ) ;
if ( IS_LPLAYER2 )
player_check ( bman . p2_nr ) ;
if ( ! bman . dedicated )
dead_playerani ( ) ;
special_loop ( ) ;
@ -317,10 +303,8 @@ game_loop ()
field_loop ( ) ;
flitems_loop ( ) ;
if ( ! bman . dedicated ) {
draw_players ( ) ;
game_draw_info ( ) ; // will set the var bman.player_nr
}
/* check if there is only one player left and the game is in multiplayer mode
and if there the last dieing animation is done */
@ -332,7 +316,6 @@ game_loop ()
done = 1 ;
}
if ( ! bman . dedicated ) {
stonelist_draw ( ) ;
/* if there is any menu displayed do so */
@ -340,23 +323,23 @@ game_loop ()
game_menu_loop ( & event , eventstate ) ;
gfx_blitdraw ( ) ;
}
s_calctimesync ( ) ;
bman . timeout - = timediff ;
}
if ( menu ! = NULL )
if ( menu ! = NULL ) {
menu_delete ( menu ) ;
menu = NULL ;
}
if ( ! bman . dedicated ) {
gfx_blitdraw ( ) ;
chat_show ( - 1 , - 1 , - 1 , - 1 ) ;
draw_logo ( ) ;
gfx_blitupdaterectclear ( ) ;
SDL_Flip ( gfx . screen ) ;
}
d_gamedetail ( " GAME END " ) ;
d_printf ( " done = %d \n " , done ) ;
@ -368,13 +351,16 @@ game_loop ()
* check also if we there is only one team alife
*/
# define ENDGAME_CHECK_AGAIN 1.0f
int game_check_endgame ( ) {
int
game_check_endgame ( )
{
int res = 0 ;
static float loop ;
loop - = timediff ;
if ( loop > 0.0f & & loop < ENDGAME_CHECK_AGAIN ) return 0 ;
if ( loop > 0.0f & & loop < ENDGAME_CHECK_AGAIN )
return 0 ;
loop = ENDGAME_CHECK_AGAIN ;
if ( bman . gametype = = GT_team ) {
@ -389,7 +375,8 @@ int game_check_endgame () {
int team_last = - 1 ; // last teams which was alift
_player * p ;
for ( t_nr = 0 ; t_nr < MAX_TEAMS ; t_nr + + ) for ( p_nr = 0 ; p_nr < MAX_PLAYERS ; p_nr + + )
for ( t_nr = 0 ; t_nr < MAX_TEAMS ; t_nr + + )
for ( p_nr = 0 ; p_nr < MAX_PLAYERS ; p_nr + + )
if ( teams [ t_nr ] . players [ p_nr ] ! = NULL ) {
p = teams [ t_nr ] . players [ p_nr ] ;
if ( PS_IS_used ( p - > state ) & & PS_IS_alife ( p - > state ) ) {
@ -407,7 +394,8 @@ int game_check_endgame () {
if ( h_team < 1 | | ateam < 2 )
res = 1 ;
}
else if ( ( bman . gametype = = GT_bomberman ) | | ( map . state ! = MS_normal & & bman . gametype = = GT_deathmatch ) ) {
else if ( ( bman . gametype = = GT_bomberman )
| | ( map . state ! = MS_normal & & bman . gametype = = GT_deathmatch ) ) {
int p_nr ; // playernumber
int h_alife = 0 ; // human players who are alife
int alife = 0 ; // ai players who are alife
@ -427,6 +415,7 @@ int game_check_endgame () {
return res ;
} ;
# undef ENDGAME_CHECK_AGAIN
/* check which player won and free all unnneded data */
@ -454,7 +443,8 @@ game_end ()
}
if ( cnt_left = = 1 )
players [ bman . lastwinner ] . points + = bman . players_nr_s ;
else bman . lastwinner = - 1 ;
else
bman . lastwinner = - 1 ;
/* check which team was alife */
if ( bman . gametype = = GT_team ) {
@ -463,9 +453,10 @@ game_end ()
bman . lastwinner = - 1 ;
cnt_left = 0 ;
for ( t_nr = 0 ; t_nr < MAX_TEAMS ; t_nr + + ) for ( i = 0 ; i < MAX_PLAYERS ; i + + ) {
for ( t_nr = 0 ; t_nr < MAX_TEAMS ; t_nr + + )
for ( i = 0 ; i < MAX_PLAYERS ; i + + ) {
if ( teams [ t_nr ] . players [ i ] ! = NULL )
if ( PS_IS_alife ( teams [ t_nr ] . players [ i ] - > state ) ) {
if ( PS_IS_alife ( teams [ t_nr ] . players [ i ] - > state ) ) {
if ( bman . lastwinner ! = t_nr ) {
teams [ t_nr ] . wins + + ;
cnt_left + + ;
@ -502,9 +493,10 @@ game_end ()
void
game_start ( )
{
int p , i ;
int p ,
i ;
if ( ! bman . dedicated ) menu_displaytext ( " Loading.. " , " Please Wait " ) ;
menu_displaytext ( " Loading.. " , " Please Wait " ) ;
bman . players_nr_s = 0 ;
@ -531,7 +523,7 @@ game_start ()
players [ p ] . m = 0 ;
players [ p ] . old . x = 0 ;
players [ p ] . old . y = 0 ;
bman . updatestatusbar = 1 ;
bman . updatestatusbar = 1 ;
players [ p ] . frame = 0.0f ;
players [ p ] . d = 0 ;
players [ p ] . pos . x = 0.0 ;
@ -561,15 +553,12 @@ game_start ()
flitems_reset ( ) ;
init_map_tileset ( ) ;
if ( ! bman . dedicated )
tileset_load ( map . tileset , - 1 , - 1 ) ;
gfx_load_players ( gfx . block . x , gfx . block . y ) ;
if ( ! bman . dedicated ) {
snd_load ( map . tileset ) ;
snd_music_start ( ) ;
}
map . state = MS_normal ;
bman . timeout = bman . init_timeout ;
@ -588,16 +577,30 @@ game_start ()
# define SHOWRESULT_TEAMHEAD 24
# define SHOWRESULT_TEAMPLAYER 16
# define SHOWRESULT_TEAMPLAYERWIDTH 150
void game_showresultteam ( int pos_x , int pos_y , int pos_w , int pos_h ) {
int i , t_nr , p_nr ; // counter for teams and players
void
game_showresultteam ( int pos_x , int pos_y , int pos_w , int pos_h )
{
int i ,
t_nr ,
p_nr ; // counter for teams and players
struct {
_team * team ; // pointer to the team
_player * pl [ MAX_PLAYERS ] ; // players in the team (sorted)
int cnt ;
} tdata [ MAX_TEAMS ] ; // hold some team informations (sorted)
int t_count = 0 , p_maxcount = 0 , p_sumcount = 0 ;
int sx , sy , p_y , p_x , dx , dy , col , x ;
SDL_Rect dest , src ;
int t_count = 0 ,
p_maxcount = 0 ,
p_sumcount = 0 ;
int sx ,
sy ,
p_y ,
p_x ,
dx ,
dy ,
col ,
x ;
SDL_Rect dest ,
src ;
char text [ 255 ] ;
/* sort all teams */
@ -613,10 +616,10 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
tdata [ t_count ] . team = & teams [ t_nr ] ;
i = t_count ;
while ( i > 0 & & ( tdata [ i - 1 ] . team - > wins < teams [ t_nr ] . wins
| | ( tdata [ i - 1 ] . team - > wins = = teams [ t_nr ] . wins
& & tdata [ i - 1 ] . team - > points < teams [ t_nr ] . points ) ) ) {
tdata [ i ] . team = tdata [ i - 1 ] . team ;
while ( i > 0 & & ( tdata [ i - 1 ] . team - > wins < teams [ t_nr ] . wins
| | ( tdata [ i - 1 ] . team - > wins = = teams [ t_nr ] . wins
& & tdata [ i - 1 ] . team - > points < teams [ t_nr ] . points ) ) ) {
tdata [ i ] . team = tdata [ i - 1 ] . team ;
i - - ;
tdata [ i ] . team = & teams [ t_nr ] ;
}
@ -625,16 +628,21 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
}
/* sort all players dependsing on the number of wins they have */
for ( t_nr = 0 ; t_nr < t_count ; t_nr + + ) for ( p_nr = 0 , tdata [ t_nr ] . cnt = 0 ; p_nr < MAX_PLAYERS ; p_nr + + ) {
for ( t_nr = 0 ; t_nr < t_count ; t_nr + + )
for ( p_nr = 0 , tdata [ t_nr ] . cnt = 0 ; p_nr < MAX_PLAYERS ; p_nr + + ) {
if ( t_nr < t_count ) {
if ( tdata [ t_nr ] . team - > players [ p_nr ] ! = NULL & & PS_IS_used ( tdata [ t_nr ] . team - > players [ p_nr ] - > state ) ) {
if ( tdata [ t_nr ] . team - > players [ p_nr ] ! = NULL
& & PS_IS_used ( tdata [ t_nr ] . team - > players [ p_nr ] - > state ) ) {
tdata [ t_nr ] . pl [ tdata [ t_nr ] . cnt ] = tdata [ t_nr ] . team - > players [ p_nr ] ;
i = tdata [ t_nr ] . cnt ;
while ( i > 0 & & ( tdata [ t_nr ] . pl [ i - 1 ] - > wins < tdata [ t_nr ] . team - > players [ p_nr ] - > wins
| | ( tdata [ t_nr ] . pl [ i - 1 ] - > wins = = tdata [ t_nr ] . team - > players [ p_nr ] - > wins
& & tdata [ t_nr ] . pl [ i - 1 ] - > points < tdata [ t_nr ] . team - > players [ p_nr ] - > points ) ) ) {
tdata [ t_nr ] . pl [ i ] = tdata [ t_nr ] . pl [ i - 1 ] ;
while ( i > 0
& & ( tdata [ t_nr ] . pl [ i - 1 ] - > wins < tdata [ t_nr ] . team - > players [ p_nr ] - > wins
| | ( tdata [ t_nr ] . pl [ i - 1 ] - > wins = =
tdata [ t_nr ] . team - > players [ p_nr ] - > wins
& & tdata [ t_nr ] . pl [ i - 1 ] - > points <
tdata [ t_nr ] . team - > players [ p_nr ] - > points ) ) ) {
tdata [ t_nr ] . pl [ i ] = tdata [ t_nr ] . pl [ i - 1 ] ;
i - - ;
tdata [ t_nr ] . pl [ i ] = tdata [ t_nr ] . team - > players [ p_nr ] ;
}
@ -645,10 +653,12 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
/* check the max number of players in one team and number of all players */
for ( t_nr = 0 , p_maxcount = 0 ; t_nr < t_count ; t_nr + + ) /* t_count + 1 */
if ( p_maxcount < tdata [ t_nr ] . cnt ) p_maxcount = tdata [ t_nr ] . cnt ;
if ( p_maxcount < tdata [ t_nr ] . cnt )
p_maxcount = tdata [ t_nr ] . cnt ;
for ( p_sumcount = 0 , p_nr = 0 ; p_nr < MAX_PLAYERS ; p_nr + + )
if ( PS_IS_used ( players [ p_nr ] . state ) ) p_sumcount + + ;
if ( PS_IS_used ( players [ p_nr ] . state ) )
p_sumcount + + ;
/* calculate the best view */
p_x = dx = dy = 0 ;
@ -656,28 +666,32 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
p_x + + ;
p_y = 0 ; // calc. again for this setting
for ( t_nr = 0 ; t_nr < t_count ; t_nr + + ) {
p_y + = ceil ( ( float ) ( ( ( float ) tdata [ t_nr ] . cnt ) / ( ( float ) p_x ) ) ) ;
p_y + = ceil ( ( float ) ( ( ( float ) tdata [ t_nr ] . cnt ) / ( ( float ) p_x ) ) ) ;
}
if ( p_y = = 0 ) p_y = 1 ;
if ( p_y = = 0 )
p_y = 1 ;
dy = ( pos_h - ( SHOWRESULT_TEAMHEAD * t_count ) ) / p_y ;
} while ( dy < SHOWRESULT_TEAMPLAYER ) ;
if ( dy > 2 * SHOWRESULT_TEAMPLAYER ) dy = 2 * SHOWRESULT_TEAMPLAYER ;
if ( dy > 2 * SHOWRESULT_TEAMPLAYER )
dy = 2 * SHOWRESULT_TEAMPLAYER ;
/* draw everything */
sy = ( pos_h - ( SHOWRESULT_TEAMHEAD * t_count + dy * p_y ) ) / 2 ;
for ( t_nr = 0 ; t_nr < t_count ; t_nr + + ) {
sprintf ( text , " %s Victorys %d (%d) " , tdata [ t_nr ] . team - > name , tdata [ t_nr ] . team - > wins , tdata [ t_nr ] . team - > points ) ;
sprintf ( text , " %s Victorys %d (%d) " , tdata [ t_nr ] . team - > name , tdata [ t_nr ] . team - > wins ,
tdata [ t_nr ] . team - > points ) ;
sx = ( pos_w - strlen ( text ) * font [ 0 ] . size . x ) / 2 ;
font_gfxdrawbold ( 10 + pos_x + sx , pos_y + sy + 3 , text , 0 , COLOR_brown , 1 , 1 ) ;
font_gfxdraw ( 10 + pos_x + sx , pos_y + sy + 3 , text , 0 , COLOR_yellow , 2 ) ;
font_gfxdrawbold ( 10 + pos_x + sx , pos_y + sy + 3 , text , 0 , COLOR_brown , 1 , 1 ) ;
font_gfxdraw ( 10 + pos_x + sx , pos_y + sy + 3 , text , 0 , COLOR_yellow , 2 ) ;
sy + = SHOWRESULT_TEAMHEAD ;
dx = pos_w / p_x ;
sx = ( dx - SHOWRESULT_TEAMPLAYERWIDTH ) / 2 ;
sx = ( dx - SHOWRESULT_TEAMPLAYERWIDTH ) / 2 ;
for ( col = 0 , p_nr = 0 ; p_nr < tdata [ t_nr ] . cnt ; p_nr + + ) {
if ( col = = 0 | | col > = p_x ) {
if ( col > = p_x ) sy + = dy ;
if ( col > = p_x )
sy + = dy ;
col = 0 ;
x = sx ;
}
@ -700,14 +714,17 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
src . y = 0 ;
gfx_blit ( gfx . ghost_small , & src , gfx . screen , & dest , 1 ) ;
}
sprintf ( text , " %s(%d/%d) " , tdata [ t_nr ] . pl [ p_nr ] - > name , tdata [ t_nr ] . pl [ p_nr ] - > wins , tdata [ t_nr ] . pl [ p_nr ] - > points ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_SMALLPLAYERIMGSIZE_X * 2 , pos_y + sy + 2 , text , 0 , 0 , 2 ) ;
sprintf ( text , " %s(%d/%d) " , tdata [ t_nr ] . pl [ p_nr ] - > name , tdata [ t_nr ] . pl [ p_nr ] - > wins ,
tdata [ t_nr ] . pl [ p_nr ] - > points ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_SMALLPLAYERIMGSIZE_X * 2 , pos_y + sy + 2 , text , 0 , 0 ,
2 ) ;
x + = dx ;
col + + ;
}
sy + = dy ;
}
}
# undef SHOWRESULT_TEAMHEAD
# undef SHOWRESULT_TEAMPLAYER
# undef SHOWRESULT_TEAMPLAYERWIDTH
@ -716,14 +733,25 @@ void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
/* Bomberman/Deathmatch Version Play */
# define SHOWRESULT_WIDTH 150
# define SHOWRESULT_HEIGHT 60
void game_showresultnormal ( int pos_x , int pos_y , int pos_w , int pos_h ) {
void
game_showresultnormal ( int pos_x , int pos_y , int pos_w , int pos_h )
{
char text [ 255 ] ;
int i , p , x , y , pl_cnt = 0 ,
pl_x , pl_y , // player in a row/col
dx , dy , // distance
sx , sy , px ; // start view and position
SDL_Rect dest , src ;
int i ,
p ,
x ,
y ,
pl_cnt = 0 ,
pl_x ,
pl_y , // player in a row/col
dx ,
dy , // distance
sx ,
sy ,
px ; // start view and position
SDL_Rect dest ,
src ;
_player * pl [ MAX_PLAYERS ] ;
@ -733,10 +761,10 @@ void game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h) {
pl [ pl_cnt ] = & players [ p ] ;
i = pl_cnt ;
while ( i > 0 & & ( pl [ i - 1 ] - > wins < players [ p ] . wins
| | ( pl [ i - 1 ] - > wins = = players [ p ] . wins
& & pl [ i - 1 ] - > points < players [ p ] . points ) ) ) {
pl [ i ] = pl [ i - 1 ] ;
while ( i > 0 & & ( pl [ i - 1 ] - > wins < players [ p ] . wins
| | ( pl [ i - 1 ] - > wins = = players [ p ] . wins
& & pl [ i - 1 ] - > points < players [ p ] . points ) ) ) {
pl [ i ] = pl [ i - 1 ] ;
i - - ;
pl [ i ] = & players [ p ] ;
}
@ -751,14 +779,15 @@ void game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h) {
pl_x = 0 ;
do {
pl_x + + ;
pl_y = ceil ( ( float ) ( ( ( float ) pl_cnt ) / ( ( float ) pl_x ) ) ) ;
if ( pl_y = = 0 ) pl_y + + ;
pl_y = ceil ( ( float ) ( ( ( float ) pl_cnt ) / ( ( float ) pl_x ) ) ) ;
if ( pl_y = = 0 )
pl_y + + ;
dy = pos_h / pl_y ;
} while ( dy < SHOWRESULT_HEIGHT ) ;
dx = pos_w / pl_x ;
x = sx = ( dx - SHOWRESULT_WIDTH ) / 2 ;
y = sy = ( dy - SHOWRESULT_HEIGHT ) / 2 ;
x = sx = ( dx - SHOWRESULT_WIDTH ) / 2 ;
y = sy = ( dy - SHOWRESULT_HEIGHT ) / 2 ;
px = 0 ;
d_printf ( " game_showresultnormal: pl_x:%d, pl_y:%d, dx:%d, dy:%d \n " , pl_x , pl_y , dx , dy ) ;
@ -767,14 +796,17 @@ void game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h) {
for ( i = 1 , p = 0 ; p < pl_cnt ; p + + ) {
if ( PS_IS_used ( pl [ p ] - > state ) ) {
if ( PS_IS_alife ( pl [ p ] - > state ) ) {
font_gfxdrawbold ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8 , pos_y + y - 10 , pl [ p ] - > name , 0 , COLOR_brown , 1 , 1 ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8 , pos_y + y - 10 , pl [ p ] - > name , 0 , COLOR_yellow , 1 ) ;
font_gfxdrawbold ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8 , pos_y + y - 10 ,
pl [ p ] - > name , 0 , COLOR_brown , 1 , 1 ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8 , pos_y + y - 10 ,
pl [ p ] - > name , 0 , COLOR_yellow , 1 ) ;
}
else
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X , pos_y + y - 10 , pl [ p ] - > name , 0 , COLOR_gray , 1 ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X , pos_y + y - 10 , pl [ p ] - > name ,
0 , COLOR_gray , 1 ) ;
sprintf ( text , " %3d (%3d) " , pl [ p ] - > wins , pl [ p ] - > points ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X , pos_y + y + 6 , text , 0 , 0 , 1 ) ;
font_gfxdraw ( 10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X , pos_y + y + 6 , text , 0 , 0 , 1 ) ;
if ( pl [ p ] - > gfx ! = NULL ) {
dest . x = pos_x + x ;
@ -805,15 +837,21 @@ void game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h) {
}
}
}
# undef SHOWRESULT_HEIGHT
# undef SHOWRESULT_WIDTH
void game_showresult ( ) {
void
game_showresult ( )
{
char text [ 255 ] ;
SDL_Event event ;
Uint8 * keys ;
int done = 0 , keypressed = 0 , x , y ;
int done = 0 ,
keypressed = 0 ,
x ,
y ;
gfx_blitdraw ( ) ;
@ -828,8 +866,8 @@ void game_showresult () {
strcpy ( text , " [CTRL],[RETURN] or [STRG] for another game " ) ;
x = ( gfx . res . x - ( font [ 1 ] . size . x * strlen ( text ) ) - 64 ) / 2 ;
font_drawbold ( x , gfx . res . y - ( 2 * font [ 0 ] . size . y ) - 2 , text , 0 , COLOR_brown , 1 ) ;
font_draw ( x , gfx . res . y - ( 2 * font [ 0 ] . size . y ) - 2 , text , 0 , COLOR_yellow ) ;
font_drawbold ( x , gfx . res . y - ( 2 * font [ 0 ] . size . y ) - 2 , text , 0 , COLOR_brown , 1 ) ;
font_draw ( x , gfx . res . y - ( 2 * font [ 0 ] . size . y ) - 2 , text , 0 , COLOR_yellow ) ;
strcpy ( text , " or [ESC] to leave the game. " ) ;
x = ( gfx . res . x - ( font [ 1 ] . size . x * strlen ( text ) ) - 64 ) / 2 ;
@ -837,9 +875,9 @@ void game_showresult () {
font_draw ( x , gfx . res . y - font [ 0 ] . size . y - 2 , text , 0 , COLOR_yellow ) ;
if ( bman . gametype = = GT_team )
game_showresultteam ( 10 , 50 , gfx . res . x - 20 , gfx . res . y - 100 ) ;
game_showresultteam ( 10 , 50 , gfx . res . x - 20 , gfx . res . y - 100 ) ;
else
game_showresultnormal ( 10 , 50 , gfx . res . x - 20 , gfx . res . y - 100 ) ;
game_showresultnormal ( 10 , 50 , gfx . res . x - 20 , gfx . res . y - 100 ) ;
gfx_blitdraw ( ) ;
SDL_Flip ( gfx . screen ) ;
@ -864,14 +902,15 @@ void game_showresult () {
bman . state = GS_startup ;
}
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 ;
keypressed = 1 ;
}
if ( keys [ SDLK_F8 ] & & event . type = = SDL_KEYDOWN ) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen ( gfx . screen ) ;
SDL_WM_ToggleFullScreen ( gfx . screen ) ;
gfx . fullscreen = ! gfx . fullscreen ;
bman . updatestatusbar = 1 ; // force an update
}
@ -892,7 +931,9 @@ void game_showresult () {
/*
* create the in game menu
*/
void game_menu_create ( ) {
void
game_menu_create ( )
{
if ( menu ! = NULL )
return ;
@ -917,7 +958,9 @@ void game_menu_create () {
*
* Pressing ESC will bring you back to the game .
*/
void game_menu_loop ( SDL_Event * event , int eventstate ) {
void
game_menu_loop ( SDL_Event * event , int eventstate )
{
int done ;
if ( menu = = NULL )
@ -937,7 +980,8 @@ void game_menu_loop (SDL_Event *event, int eventstate) {
else if ( menu - > focus - > id = = 3 ) { /* End Game */
/* send network update */
if ( GT_MP ) net_game_send_delplayer ( bman . p_nr ) ;
if ( GT_MP )
net_game_send_delplayer ( bman . p_nr ) ;
bman . state = GS_quit ;
}