- network changed, AI Player can join.

- sound fixed some crashs.
- menu handling rewritten
- gamemaster server changed to opengamecache.
- players and all this are now float

  and a lot more changes
origin
stpohle 22 years ago
parent 70a03c02c3
commit 7ec27d9fc5

@ -1,11 +1,30 @@
$Id: ChangeLog,v 1.43 2003/09/16 20:04:31 stpohle Exp $
$Id: ChangeLog,v 1.44 2003/12/24 02:38:14 stpohle Exp $
- Menuhandling complete rewritten and changed.
GUI created for menus: lists, buttons, check boxes
labels and other things created.
new menugraphics made by DJ Mirage.
- FullScreen switching from within the game
by pressing F8
- first perfect BomberClone music file "cinderella_clown.mod"
- AI Players can join network games.
- Changed all positions and framenumbers to float.
Together with this i can drop the hard 20ms
gameloop limitation. So the game will be able to
run on slower systems and compare the loss of
frames.
- some more music tracks added to the game.
DJ Mirage made a page where people could
upload some songs.
- BomberClone music file "cinderella_clown.mod"
thanks to Psycho (http://www.moods.2xs.de/)
Version 0.10.1
==============
2003-09-13

@ -1,6 +1,6 @@
$Id: TODO,v 1.24 2003/11/05 12:15:12 stpohle Exp $
$Id: TODO,v 1.25 2003/12/24 02:38:15 stpohle Exp $
- new menudesign
- changing bcmserv to a new protocoll
- multiplayer broadcast in the local network
ip: 10.*.*.* and 192.168.*.*
@ -28,3 +28,7 @@ $Id: TODO,v 1.24 2003/11/05 12:15:12 stpohle Exp $
- we need some more sound for picking up items.
- ranking system, done by the bomberclonemserv
About BC CVS Problem.. trying with
" cvs update -PAd .. "

@ -89,7 +89,6 @@ module.include.files=\
basic.h\
bomberclone.h\
chat.h\
gamesrv.h\
font.h\
gfx.h\
keybinput.h\
@ -97,7 +96,11 @@ module.include.files=\
network.h\
packets.h\
sound.h\
sysfunc.h
sysfunc.h\
menu.h\
menugui.h\
ogcache-client.h\
udp.h
module.source.name=src
module.source.type=
@ -114,7 +117,6 @@ module.source.files=\
font.c\
bomb.c\
game.c\
gamesrv.c\
gfx.c\
gfxengine.c\
gfxpixelimage.c\
@ -129,7 +131,14 @@ module.source.files=\
packets.c\
pkgcache.c\
player.c\
single.c
single.c\
menulabels.c\
menubuttons.c\
menubools.c\
menuentrys.c\
menulists.c\
ogcache-client.c\
netsrvlist.c
module.pixmap.name=pixmaps
module.pixmap.type=

@ -11,12 +11,15 @@ bomberclone_include_DATA = \
bomberclone.h \
chat.h \
font.h \
gamesrv.h \
gfx.h \
keybinput.h \
map.h \
menu.h \
menugui.h \
network.h \
packets.h \
sysfunc.h
sysfunc.h \
sound.h \
ogcache-client.h
EXTRA_DIST = $(bomberclone_include_DATA)

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.8 2003/11/09 03:56:56 stpohle Exp $ */
/* $Id: basic.h,v 1.9 2003/12/24 02:38:15 stpohle Exp $ */
/* basic types which we need everywhere */
#ifndef _BC_BASIC_H_
@ -33,8 +33,7 @@
#define MAX_PLAYERS 8
#define MAX_BOMBS 12
#define MAX_RANGE 10
#define MAX_SPEED 2
#define MAX_BLITRECTS 4096
#define MAX_SPEED 0.4
#define MAX_STONESTODRAW 2048
#define MAX_SERVERENTRYS 8 /* number of entrys in the server tab */
#define MAX_GAMESRVENTRYS 255 /* number of entry which can be get */
@ -52,7 +51,6 @@
#define ANI_PLAYERILLTIMEOUT 1
#define ANI_STONETIMEOUT 5
// #define TIME_FACTOR 50
#define BOMB_TIMEOUT 5
#define ILL_TIMEOUT 20
#define ILL_SLOWSPEED 0.01
@ -65,29 +63,24 @@
#define LEN_PATHFILENAME 512
#define LEN_FILENAME 64
#define LEN_TILESETNAME 32
#define LEN_CHARENTRY 256
#define DEFAULT_UDPPORT 11000
#define DEFAULT_GMUDPPORT "11100"
#define DEFAULT_GAMEMASTER "x.yz.to:11100"
#define DEFAULT_GAMECACHEPORT "11111"
#define DEFAULT_GAMECACHE "localhost:11111"
#define GAMESRV_TIMEOUT 2000 /* Timeout of the GameSrv_GetEntry */
#define UDP_TIMEOUT 15000
#define BUF_SIZE 1024
#define MENU_BG_SHADE_DARK -64
#define MENU_BG_SHADE_BRIGHT 64
#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--);
#define CUTINT(__x) (__x-floorf(__x)) // cut the integer part off
#define postofield(__x) ((int)(rintf(__x))) // position to int with rounding
#include <SDL.h>
enum _networkflags {
NETF_firewall = 1
};
#define UINT16_HALF 32767
#include <SDL.h>
enum _backgound { // to load some diffrent logos..
BG_start = 0,
@ -209,14 +202,6 @@ enum _direction { // to handle directions better
down
};
enum _dirbitmask { // bit mask for the directions
DIRM_left = 1,
DIRM_right = 2,
DIRM_up = 4,
DIRM_down = 8,
DIRM_under = 16
};
enum _mapselection {
MAPS_select = 0,
MAPS_randmap,
@ -243,4 +228,11 @@ struct {
float y;
} typedef _pointf;
struct __charlist {
char text[LEN_CHARENTRY];
struct __charlist *next;
} typedef _charlist;
#endif

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.8 2003/11/09 23:56:34 stpohle Exp $ */
/* $Id: bomberclone.h,v 1.9 2003/12/24 02:38:15 stpohle Exp $ */
/* bomberclone.h */
#ifndef _BOMBERCLONE_H_
@ -141,29 +141,20 @@ struct {
int maxplayer; // number of max players for the server
int sock; // the server socket
unsigned char net_ai_family;
int net_ai_family;
char port[LEN_PORT]; // what port we're using
char servername[LEN_SERVERNAME + LEN_PORT + 2]; // holds the name of the current server
_serverlist serverlist[MAX_SERVERENTRYS]; // ** CONFIG name of the server we are connected to
char gamename[LEN_GAMENAME]; // this will hold the game name
char gamemaster[LEN_SERVERNAME + LEN_PORT + 2]; // ** CONFIG ... GameMaster Address
unsigned char firewall;
unsigned char notifygamemaster;
unsigned char broadcasted_chat; // 1 if the chat should be send to the bc server
unsigned char askplayername; // ask player for name at startup
char ogcserver[LEN_SERVERNAME+LEN_PORT+2];
char ogc_port[LEN_PORT];
int firewall;
int notifygamemaster;
int askplayername; // ask player for name at startup
unsigned char ai_players; // number of ai players
signed char debug; // 0 = off 1 = on
} typedef _bomberclone;
struct {
int index;
char text[255];
// int type; // could be visible / disabled / grayed ?? should avoid -2 trick
} typedef _menu;
struct {
signed char dir;
signed char bestdir;
@ -219,7 +210,6 @@ extern void player_check_powerup (int p_nr);
extern void player_set_gfx (_player *p, signed char gfx_nr);
extern int player_findfreebomb (_player *player);
extern int player_checkpos (int x, int y);
// extern inline int postofield (int pos);
// for the bomb..
extern int bomb_loop ();
@ -233,21 +223,21 @@ extern void restore_explosion (_bomb * bomb);
extern int explosion_check_field (int x, int y, int p, int b);
// menus
extern void draw_select (int select, _menu menu[], int x, int y);
extern int menu_loop (char *menutitle, _menu menu[], int lastselect);
extern void draw_menu (char *text, _menu menu[], int *x, int *y);
extern void menu_get_text (char *title, char *text, int len);
extern void menu_displaymessage (char *title, char *text);
extern void menu_displaytext (char *title, char *text, Uint8 r, Uint8 g, Uint8 b);
extern char *menu_dir_select (char *title, char *path, signed char dirflags);
void menu_clearkeybuff();
void draw_menubox (int x, int y);
//extern void draw_select (int select, _menu menu[], int x, int y);
//extern int menu_loop (char *menutitle, _menu menu[], int lastselect);
//extern void draw_menu (char *text, _menu menu[], int *x, int *y);
//extern void menu_get_text (char *title, char *text, int len);
//extern void menu_displaymessage (char *title, char *text);
//extern void menu_displaytext (char *title, char *text, Uint8 r, Uint8 g, Uint8 b);
//extern char *menu_dir_select (char *title, char *path, signed char dirflags);
//void menu_clearkeybuff();
//void draw_menubox (int x, int y);
// configuration
extern void configuration ();
extern void game_init (int argc, char **argv);
extern int ReadConfig();
extern int WriteConfig();
extern void config_init (int argc, char **argv);
extern void config_menu ();
extern int config_read();
extern int config_write();
extern void ReadPrgArgs (int argc, char **argv);
// debug.c
@ -258,6 +248,7 @@ extern void d_printf (char *fmt,...);
extern void d_bitprint (int bits, int nr);
extern void d_fatal (char *fmt,...);
extern void debug_ingameinfo();
extern void d_printsdlrect (char *text, SDL_Rect *rect);
// single.c

@ -4,20 +4,32 @@
#include "basic.h"
enum _color {
COLOR_white = 0,
COLOR_red,
COLOR_green,
COLOR_blue,
COLOR_yellow,
COLOR_brown,
COLOR_gray,
COLOR_black,
COLOR_max
};
struct __font {
SDL_Surface *image;
SDL_Surface *raw;
SDL_Surface *image[COLOR_max];
_point size;
} typedef _font;
extern _point font_lastsize;
extern _font font[3];
extern void font_setcolor (unsigned char r, unsigned char g, unsigned char b, int size);
extern void font_draw (int x, int y, char *text, int size);
extern void font_gfxdraw (int x, int y, char *text, int size, int ypos);
extern void font_drawbold (int x, int y, char *text, int size, int bold);
extern void font_draw (int x, int y, char *text, int size, int color);
extern void font_drawbold (int x, int y, char *text, int size, int color, int bold);
extern void font_load ();
extern void font_free ();
extern void font_gfxdraw (int x, int y, char *text, int size, int color, int ypos);
extern void font_gfxdrawbold (int x, int y, char *text, int size, int color, int bold, int ypos);
#endif

@ -1,9 +1,10 @@
/* $Id: gfx.h,v 1.3 2003/09/23 20:28:24 stpohle Exp $ */
/* $Id: gfx.h,v 1.4 2003/12/24 02:38:15 stpohle Exp $ */
#ifndef _GFX_H_
#define _GFX_H_
#define SCALE_MAXRES 10000
#define MAX_BLITRECTS 32000
#define GFX_IMGSIZE 64
#define GFX_IMGBIGSIZE 96
#define GFX_PLAYERIMGSIZE_Y 128
@ -42,7 +43,7 @@ struct __gfx {
_point block; // block size
short int bpp; // bits per pixel
unsigned char fullscreen;
int fullscreen;
_point offset; // where the game field starts
@ -88,6 +89,7 @@ extern SDL_Surface *scale_image (SDL_Surface * orginal, int newx, int newy);
extern void shade_pixel(SDL_Surface *s, int x, int y, int c);
extern SDL_Surface *makegray_image (SDL_Surface *org);
extern SDL_Surface *gfx_copyscreen (SDL_Rect *wnd);
extern void gfx_restorescreen (SDL_Surface *img, SDL_Rect *wnd);
// gfxengine.c
@ -100,4 +102,3 @@ extern void gfx_blitupdaterectdraw ();
extern void gfx_blitupdaterectadd (SDL_Rect *rect);
#endif

@ -2,14 +2,22 @@
#ifndef _KEYBINPUT_H_
#define _KEYBINPUT_H_
enum _keybinputtype {
KEYBI_text = 0,
KEYBI_int,
KEYBI_float
};
struct __keybinput {
char text[255];
short int curpos;
short int len;
char changed;
int type;
int maxlen;
} typedef _keybinput;
extern void keybinput_new (_keybinput *ki);
extern void keybinput_new (_keybinput *ki, int type, int maxlen);
extern int keybinput_loop (_keybinput *ki, SDL_Event *event);
#endif

@ -1,5 +1,5 @@
/*
network.h file... for everything what have to do with the network stuff
/* $Id: network.h,v 1.8 2003/12/24 02:38:15 stpohle Exp $
* network.h file... for everything what have to do with the network stuff
*/
#include <SDL.h>
@ -17,6 +17,7 @@ network.h file... for everything what have to do with the network stuff
#define DYN_PKG_MAX_MISSING 4
#define DYN_PKG_MIN_MISSING 1
#define PKG_SENDSETOPT 2
#define MAX_SRVLIST 512
#define GT_MP_PTPM (bman.p_nr == bman.p_servnr && bman.sock >= 0)
#define GT_MP_PTPS (bman.p_nr != bman.p_servnr && bman.sock >= 0)
@ -24,6 +25,7 @@ network.h file... for everything what have to do with the network stuff
#define GT_SP (bman.sock <= 0)
#define GS_WAITRUNNING (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running)
#define GS_RUNNING (bman.state == GS_ready || bman.state == GS_running)
#define NET_CANSEND(__pl) (( __pl == 0 || GT_MP_PTPM || (players[__pl].net.flags & NETF_firewall) == 0))
@ -47,11 +49,12 @@ network.h file... for everything what have to do with the network stuff
#define I16TOF(__x) (((float)__x) / 256.0f)
#define I32TOF(__x) (((float)__x) / 4096.0f)
#ifdef _WIN32
#define _sockaddr sockaddr
#else
#define _sockaddr sockaddr_in6
#endif
#include "udp.h"
enum _networkflags {
NETF_firewall = 1
};
struct { // this holds the network data
char host[LEN_SERVERNAME];
@ -84,11 +87,11 @@ struct {
// network menu
extern void netmenu();
extern void networkmenu_joingame ();
extern void networkmenu_options ();
extern void network_options ();
extern void join_multiplayer_game ();
extern void host_multiplayer_game ();
extern void multiplayer_firstrun ();
extern void multiplayer_game ();
// network.c
extern int network_server_port (char *server, char *host, int hostlen, char *port, int portlen);
@ -113,6 +116,7 @@ extern int net_check_timeout (int pl_nr);
extern void net_dyn_pkgoption ();
extern void net_send_chat (char *text, signed char notigamesrv);
extern void net_send_mapinfo ();
extern void send_ogc_update ();
// multiwait.c
extern void wait_for_players ();
@ -123,12 +127,9 @@ extern void mw_draw_status ();
extern void mw_wait_for_connect ();
extern void mw_draw_chat ();
// udp.c
extern char *dns_net_getip (char *host);
extern int dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family, struct _sockaddr *sAddr);
extern int udp_get (int sock, char *text, int len, struct _sockaddr *sAddr, int ai_family);
extern int udp_server (char *port, int ai_family);
extern void udp_send (int sock, char *text, int len, struct _sockaddr *sAddr, int ai_family);
extern void udp_close (int sock);
// netsrvlist.c
extern void net_getserver ();
extern void srvlist_rebuildlist ();
#endif

@ -21,9 +21,7 @@ enum _network_data {
PKG_ill,
PKG_special,
PKG_mapinfo,
PKG_tunneldata,
PKG_bcmservchat = 90
PKG_tunneldata
};

@ -1,4 +1,4 @@
/* $Id: sound.h,v 1.3 2003/09/23 20:28:24 stpohle Exp $ */
/* $Id: sound.h,v 1.4 2003/12/24 02:38:15 stpohle Exp $ */
/* include file for the sound */
#ifndef _SOUND_H_
@ -30,8 +30,8 @@ struct __snd {
int audio_rate;
Uint16 audio_format;
int audio_channels;
signed char playmusic;
signed char playsound;
int playmusic;
int playsound;
} typedef _snd;

@ -1,4 +1,4 @@
/* $Id: sysfunc.h,v 1.4 2003/11/09 16:35:10 stpohle Exp $ */
/* $Id: sysfunc.h,v 1.5 2003/12/24 02:38:15 stpohle Exp $ */
/* include some system near functions */
#ifndef _SYSFUNC_H_
@ -11,6 +11,14 @@ enum _dirflags {
DF_file = 2
};
enum _dirbitmask { // bit mask for the directions
DIRM_left = 1,
DIRM_right = 2,
DIRM_up = 4,
DIRM_down = 8,
DIRM_under = 16
};
struct __direntry {
unsigned char flags;
char name[LEN_FILENAME];
@ -45,4 +53,9 @@ extern _direntry *s_dirfilter (_direntry *dirstart, signed char dirflags);
#endif
#endif
extern inline void s_calctimesync ();
extern void rect_clipping (SDL_Rect *src, SDL_Rect *dest, SDL_Rect *window, SDL_Rect *csrc, SDL_Rect *cdest);
extern void charlist_fillarraypointer (_charlist *list, int c);
extern _charlist *charlist_findtext (_charlist *list, char *text);
#endif

@ -16,8 +16,14 @@ bomberclone_SOURCES = \
game.c\
netmenu.c\
network.c\
netsrvlist.c\
udp.c\
menu.c\
menubools.c\
menubuttons.c\
menuentrys.c\
menulabels.c\
menulists.c\
map.c\
mapmenu.c\
tileset.c\
@ -25,12 +31,12 @@ bomberclone_SOURCES = \
sysfunc.c\
configuration.c\
pkgcache.c\
gamesrv.c \
chat.c \
multiwait.c \
keybinput.c \
single.c \
special.c \
sound.c
sound.c\
ogcache-client.c
## bomberclone_LDADD =

@ -204,7 +204,7 @@ chat_loop (SDL_Event * event)
sprintf (text, "%s: %s", bman.playername, chat.input.text);
net_send_chat (text, 1);
chat_addline (text);
keybinput_new (&chat.input);
keybinput_new (&chat.input, KEYBI_text, 255);
i = 0;
}
@ -214,7 +214,7 @@ chat_loop (SDL_Event * event)
p1 = p2 = 0;
maxchar = (chat.window.w - 4) / font[0].size.x;
if (chat.lineschanged) {
font_setcolor (255, 255, 255, 0);
// font_setcolor (255, 255, 255, 0);
y = chat.window.y + 4;
l = chat.startline;
while (y < (chat.window.y + chat.window.h - 32) && chat.lines[l].text[0] != 0) {
@ -225,7 +225,7 @@ chat_loop (SDL_Event * event)
for (p1 = 0; (p1 < maxchar && chat.lines[l].text[p2] != 0); p1++)
text[p1] = chat.lines[l].text[p2++];
text[p1] = 0;
font_draw (chat.window.x + 4, y, text, 0);
// font_draw (chat.window.x + 4, y, text, 0);
if (chat.lines[l].text[p2] == 0) { // the end of the line
l++;
p2 = 0;
@ -253,7 +253,7 @@ chat_loop (SDL_Event * event)
for (p1 = 0; (p1 < maxchar && chat.input.text[p2] != 0); p1++)
text[p1] = chat.input.text[p2++];
text[p1] = 0;
font_draw (chat.window.x + 4, (chat.window.y + chat.window.h) - 4 - font[0].size.y,
text, 0);
// font_draw (chat.window.x + 4, (chat.window.y + chat.window.h) - 4 - font[0].size.y,
// text, 0);
}
};

@ -9,27 +9,26 @@
#include "gfx.h"
#include "chat.h"
#include "sound.h"
#include "menu.h"
void
game_init (int argc, char **argv)
config_init (int argc, char **argv)
{
int i;
srand (((int) time (NULL))); // initialize randomgenerator
// do some init stuff
for (i = 0; i < MAX_SERVERENTRYS; i++)
bman.serverlist[i].name[0] = 0;
for (i = 0; i < MAX_PLAYERS; i++) {
players[i].gfx = NULL; /* we will select them in the wait_for_players loop */
players[i].gfx_nr = -1; /* and even now in the singleplayer menu */
}
menu.oldscreen = NULL;
stonelist_del ();
chat.visible = 0;
chat.startline = 0;
keybinput_new (&chat.input);
keybinput_new (&chat.input, KEYBI_text, 255);
for (i = 0; i < CHAT_MAX_LINES; i++)
chat.lines[i].text[0] = 0;
@ -39,7 +38,8 @@ game_init (int argc, char **argv)
bman.sock = -1;
bman.gamename[0] = 0;
sprintf (bman.port, "%d", DEFAULT_UDPPORT);
sprintf (bman.gamemaster, DEFAULT_GAMEMASTER);
sprintf (bman.ogcserver, DEFAULT_GAMECACHE);
sprintf (bman.ogc_port, DEFAULT_GAMECACHEPORT);
resend_cache.data = NULL;
resend_cache.fill = -1;
bman.notifygamemaster = 1;
@ -57,7 +57,6 @@ game_init (int argc, char **argv)
map.map_selection = 2;
map.type = -1;
bman.firewall = 0;
bman.broadcasted_chat = 1;
bman.init_timeout = GAME_TIMEOUT;
bman.ai_players = 1;
snd.inited = 0;
@ -76,29 +75,32 @@ game_init (int argc, char **argv)
map.sp_push = GAME_SPECIAL_ITEMSPUSH;
d_printf ("\n\n ***** Bomberclone Version %s \n\n",VERSION);
if (ReadConfig()) {
if (config_read()) { /* error on reading the config file */
ReadPrgArgs (argc, argv);
gfx_init ();
draw_logo ();
menu_get_text ("Your Playername", bman.playername, LEN_PLAYERNAME);
bman.playername[LEN_PLAYERNAME-1] = 0;
bman.playername[0] = 0;
config_menu ();
} else {
ReadPrgArgs (argc, argv);
gfx_init ();
draw_logo ();
if (bman.askplayername)
menu_get_text ("Your Playername", bman.playername, LEN_PLAYERNAME);
else menu_clearkeybuff();
config_menu ();
}
ReadPrgArgs (argc, argv);
snd_init ();
gfx_blitdraw ();
SDL_Flip (gfx.screen);
};
int
ReadConfig ()
{
/* read the configuration file
* return -1 if something went wrong and 0 if no problem */
int config_read () {
FILE *config;
char buf[1024],
key2[1024];
char buf[1024];
char *findit,
*keyword,
*value;
@ -188,9 +190,6 @@ ReadConfig ()
if (!strcmp (keyword, "firewall")) {
bman.firewall = atoi (value);
}
if (!strcmp (keyword, "broadcasted_chat")) {
bman.broadcasted_chat = atoi (value);
}
if (!strcmp (keyword, "udpport")) {
if (strlen (value) > LEN_PORT) {
d_printf
@ -224,8 +223,11 @@ ReadConfig ()
if (!strcmp (keyword, "notify")) {
bman.notifygamemaster = atoi (value);
}
if (!strcmp (keyword, "masterserver")) {
strcpy (bman.gamemaster, value);
if (!strcmp (keyword, "ogcserver")) {
strcpy (bman.ogcserver, value);
}
if (!strcmp (keyword, "ogc_port")) {
strcpy (bman.ogc_port, value);
}
if (!strcmp (keyword, "maxplayer")) {
bman.maxplayer = atoi (value);
@ -254,22 +256,16 @@ ReadConfig ()
if (!strcmp (keyword, "sndplaysound")) {
snd.playsound = atoi (value);
}
for (i = 0; i < MAX_SERVERENTRYS; i++) {
sprintf (key2, "ip%d", i);
if (!strcmp (keyword, key2)) {
strcpy (bman.serverlist[i].name, value);
}
}
}
fclose (config);
return 0;
}
};
int
WriteConfig ()
config_write ()
{
FILE *config;
int i;
char filename[512];
#ifdef _WIN32
sprintf (filename, "%sbomberclone.cfg", s_gethomedir ());
@ -284,19 +280,17 @@ WriteConfig ()
fprintf (config, "tileset=%s\n", map.tileset);
fprintf (config, "mapname=%s\n", map.map);
fprintf (config, "firewall=%d\n", bman.firewall);
fprintf (config, "broadcasted_chat=%d\n", bman.broadcasted_chat);
fprintf (config, "udpport=%s\n", bman.port);
fprintf (config, "ai_players=%d\n", bman.ai_players);
fprintf (config, "fieldsizex=%d\n", map.size.x);
fprintf (config, "fieldsizey=%d\n", map.size.y);
fprintf (config, "notify=%d\n", bman.notifygamemaster);
fprintf (config, "ai_family=%d\n", bman.net_ai_family);
fprintf (config, "masterserver=%s\n", bman.gamemaster);
fprintf (config, "ogcserver=%s\n", bman.ogcserver);
fprintf (config, "ogc_port=%s\n", bman.ogc_port);
fprintf (config, "gamename=%s\n", bman.gamename);
fprintf (config, "gametimeout=%d\n", bman.init_timeout);
fprintf (config, "maxplayer=%d\n", bman.maxplayer);
for (i = 0; i < MAX_SERVERENTRYS; i++)
fprintf (config, "ip%d=%s\n", i, bman.serverlist[i].name);
fprintf (config, "debug=%d\n", debug);
fprintf (config, "askplayername=%d\n", bman.askplayername);
fprintf (config, "playername=%s\n", bman.playername);
@ -315,169 +309,110 @@ WriteConfig ()
void
change_res ()
config_video ()
{
int menuselect = 0;
_menu menu[] = {
{1, "Full Screen"},
{1, "640x480"},
{2, "800x600"},
{3, "1024x768"},
{4, "1280x1024"},
{5, "BPP"},
{6, "Return To Configuration Menu"},
{-1, ""}
int done = 0, menuselect, x, y;
_charlist screenres[] = {
{"640x480", NULL},
{"800x600", NULL},
{"1024x768", NULL},
{"1280x1024", NULL}
};
while (1) {
if (gfx.fullscreen)
sprintf (menu[0].text, "Disable Fullscreen");
else
sprintf (menu[0].text, "Enable Full Screen");
if (gfx.bpp == 16)
sprintf (menu[5].text, "16 Bit Per Pixel");
else if (gfx.bpp == 24)
sprintf (menu[5].text, "24 Bit Per Pixel");
else
sprintf (menu[5].text, "32 Bit Per Pixel");
menuselect = menu_loop ("Video Options", menu, menuselect);
_charlist screenbpp[] = {
{"16", NULL},
{"24", NULL},
{"32", NULL}
};
_charlist *selres = NULL;
_charlist *selbpp = NULL;
char text[100];
/* set all pointers in this array */
charlist_fillarraypointer (screenres, 4);
charlist_fillarraypointer (screenbpp, 3);
/* select the current settings */
sprintf (text, "%dx%d", gfx.res.x, gfx.res.y);
selres = charlist_findtext (screenres, text);
sprintf (text, "%d", gfx.bpp);
selbpp = charlist_findtext (screenbpp, text);
while (!done && bman.state != GS_quit) {
menu_new ("Video Setup", 325, 300);
menu_create_label ("Resolution", 25, 70, 0);
menu_create_list ("res", 155, 55, 150, 70, screenres, &selres, 1);
menu_create_label ("Colors", 65, 160, 0);
menu_create_list ("bpp", 195, 145, 50, 55, screenbpp, &selbpp, 2);
menu_create_bool ("Fullscreen", -1, 210, 150, &gfx.fullscreen, 3);
menu_create_button ("OK", -1, 250, 100, 0);
menuselect = menu_loop ();
menu_delete ();
switch (menuselect) {
case (0): // Fullscreen
if (gfx.fullscreen)
gfx.fullscreen = 0;
else
gfx.fullscreen = 1;
break;
case (1): // 640x480
gfx.res.x = 640;
gfx.res.y = 480;
break;
case (2): // 800x600
gfx.res.x = 800;
gfx.res.y = 600;
break;
case (3): // 1024x768
gfx.res.x = 1024;
gfx.res.y = 768;
break;
case (4): // 1280x1024
gfx.res.x = 1280;
gfx.res.y = 1024;
break;
case (5):
if (gfx.bpp == 16)
gfx.bpp = 24;
else if (gfx.bpp == 24)
gfx.bpp = 32;
else
gfx.bpp = 16;
case (0):
done = 1;
gfx_shutdown ();
gfx_init ();
break;
case (6): // Return
menuselect = -1;
case (1): // new resolution
gfx_shutdown ();
sscanf (selres->text, "%dx%d", &x, &y);
gfx.res.x = x; gfx.res.y = y;
gfx_init ();
break;
}
if (menuselect != -1) {
case (2): // new color depth
gfx_shutdown ();
sscanf (selbpp->text, "%d", &x);
gfx.bpp = x;
gfx_init ();
}
else
return;
break;
default:
done = 1;
break;
}
};
};
/* Configuration Menu */
void
configuration ()
config_menu ()
{
int menuselect = 0;
_menu menu[] = {
{1, "Player Name:"},
{1, "Video Options"},
{2, "Sound Options"},
{3, "Map Options"},
{4, "Customize Keyboard"},
{5, "Prompt For Player Name"},
{6, "Debug"},
{7, "Save Config"},
{8, "Return To Main Manu"},
{-1, ""}
};
while (menuselect != -1) {
sprintf (menu[0].text, "Player Name: %s", bman.playername);
if (bman.askplayername == 1)
sprintf (menu[5].text, "Prompt For Name: YES");
else
sprintf (menu[5].text, "Prompt For Name: NO");
if (debug == 1)
sprintf (menu[6].text, "Debug Messages ON");
else
sprintf (menu[6].text, "Debug Messages OFF");
menuselect = menu_loop ("Configuration", menu, menuselect);
while (menuselect != -1 && bman.state != GS_quit) {
menu_new ("Configuration", 400, 300);
menu_create_label ("General Option", -1, 50, 1);
menu_create_entry ("Name", -1, 85, 200, bman.playername, LEN_PLAYERNAME, MENU_entrytext, 1);
menu_create_button ("Video Setup", -1, 120, 200, 2);
menu_create_label ("Sound", 25 , 154, 0);
menu_create_bool ("ON", 100, 150, 50, &snd.playsound, 3);
menu_create_label ("Music", 250 , 154, 0);
menu_create_bool ("ON", 325, 150, 50, &snd.playmusic, 4);
menu_create_label ("Extended Option", -1, 200, 1);
menu_create_bool ("Debug", 25, 230, 150, &debug, 5);
menu_create_bool ("Ask Playername", 250, 230, 150, &bman.askplayername, 6);
menu_create_button ("Ok", -1, 270, 150, 0);
menuselect = menu_loop ();
menu_delete ();
switch (menuselect) {
case (0): // Playername
menu_get_text ("Enter Playername", bman.playername, LEN_PLAYERNAME - 1);
bman.playername[LEN_PLAYERNAME - 1] = 0;
break;
case (1): // Screen Options
change_res ();
break;
case (2): // Sound Options
snd_options ();
break;
case (3): // Map Options
mapmenu();
break;
case (4): // Customize Keyboard
break;
case (5): // Prompt For Player Name
if (bman.askplayername == 1)
bman.askplayername = 0;
else
bman.askplayername = 1;
break;
case (6): // Debugging On / Off
if (debug == 1)
debug = 0;
else {
debug = 1;
d_printf ("BomberClone ver.%s\n", VERSION);
}
break;
case (7): // Save Configuration
WriteConfig ();
break;
case (8): // Return to main menu
case (0): // Back to the Main Menu
menuselect = -1;
break;
case (2): // Screen Options
config_video ();
break;
}
}
config_write ();
};
/* Read Programm parameter */
void
ReadPrgArgs (int argc, char **argv)
{
@ -486,5 +421,9 @@ ReadPrgArgs (int argc, char **argv)
while (argv[++i] != NULL) {
if (!strcmp (argv[i], "-port"))
strncpy (bman.port, argv[++i], LEN_PORT);
if (!strcmp (argv[i], "-ogcport"))
strncpy (bman.ogc_port, argv[++i], LEN_PORT);
}
};

@ -18,6 +18,10 @@ void d_gamedetail (char *head) {
};
void d_printsdlrect (char *text, SDL_Rect *rect) {
d_printf ("%s [%4d,%4d] [%4d,%4d]\n", text, rect->x, rect->w, rect->y, rect->h);
};
void d_printf (char *fmt,...) {
va_list args;
@ -72,10 +76,10 @@ void debug_ingameinfo() {
redraw_logo (0, gfx.res.y-font[0].size.y, gfx.res.y, gfx.res.x);
sprintf (text, "TDiff: %2.3f TFactor: %2.3f", timediff, timefactor);
font_gfxdraw (0, gfx.res.y-font[0].size.y, text, 0, (map.size.y*256)+10);
font_gfxdraw (0, gfx.res.y-font[0].size.y, text, 0, 0, (map.size.y*256)+10);
if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) {
sprintf (text, "Pos: %2.3f,%2.3f", players[bman.p_nr].pos.x, players[bman.p_nr].pos.y);
font_gfxdraw (350, gfx.res.y-font[0].size.y, text, 0, (map.size.y*256)+10);
font_gfxdraw (350, gfx.res.y-font[0].size.y, text, 0, 0, (map.size.y*256)+10);
}
};

@ -1,4 +1,4 @@
/* $Id: font.c,v 1.10 2003/11/08 06:27:58 stpohle Exp $ */
/* $Id: font.c,v 1.11 2003/12/24 02:38:15 stpohle Exp $ */
// Using Fonts in SDL
#include <string.h>
@ -10,7 +10,7 @@ _point font_lastsize; // so we can get the last size of the drawn font
_font font[3];
void
font_draw (int x, int y, char *text, int size)
font_draw (int x, int y, char *text, int size, int color)
{
int i,
c;
@ -27,7 +27,7 @@ font_draw (int x, int y, char *text, int size)
c = text[i];
src.x = font[size].size.x * (c & 15);
src.y = font[size].size.y * ((c & 240) >> 4);
SDL_BlitSurface (font[size].image, &src, gfx.screen, &dest);
SDL_BlitSurface (font[size].image[color], &src, gfx.screen, &dest);
dest.x += font[size].size.x;
}
@ -36,7 +36,7 @@ font_draw (int x, int y, char *text, int size)
void
font_gfxdraw (int x, int y, char *text, int size, int ypos)
font_gfxdraw (int x, int y, char *text, int size, int color, int ypos)
{
int i,
c;
@ -53,7 +53,7 @@ font_gfxdraw (int x, int y, char *text, int size, int ypos)
c = text[i];
src.x = font[size].size.x * (c & 15);
src.y = font[size].size.y * ((c & 240) >> 4);
gfx_blit (font[size].image, &src, gfx.screen, &dest, ypos);
gfx_blit (font[size].image[color], &src, gfx.screen, &dest, ypos);
dest.x += font[size].size.x;
}
@ -63,46 +63,105 @@ font_gfxdraw (int x, int y, char *text, int size, int ypos)
void font_load () {
int i;
int c,i,r,g,b;
char filename[LEN_PATHFILENAME];
SDL_Surface *raw, *tmp;
/* load the font */
for (i = 0; i < 3; i++) {
sprintf (filename, "%s/gfx/font%d.bmp", bman.datapath, i);
font[i].raw = SDL_LoadBMP (filename);
if (font[i].raw == NULL) {
tmp = SDL_LoadBMP (filename);
if (tmp == NULL) {
printf ("Could not load font.\n");
exit (1);
}
SDL_SetColorKey (font[i].raw , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].raw->format, 255, 255, 255));
font[i].image = SDL_DisplayFormat (font[i].raw);
SDL_SetColorKey (font[i].image , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].image->format, 0,0,0));
font[i].size.x = font[i].raw->w / 16;
font[i].size.y = font[i].raw->h / 16;
SDL_SetColorKey (tmp , SDL_SRCCOLORKEY, SDL_MapRGB (tmp->format, 255, 255, 255));
raw = SDL_DisplayFormat (tmp);
for (c = 0; c < COLOR_max; c++) {
switch (c) {
case COLOR_white: // color white
r = 255;
g = 255;
b = 255;
break;
case COLOR_red: // color Red
r = 255;
g = 0;
b = 0;
break;
case COLOR_green: // color Green
r = 0;
g = 255;
b = 0;
break;
case COLOR_blue: // color Blue
r = 0;
g = 0;
b = 255;
break;
case COLOR_yellow: // color Yellow
r = 255;
g = 255;
b = 0;
break;
case COLOR_brown: // color Brown
r = 255;
g = 128;
b = 0;
break;
case COLOR_black: // color Black
r = 8;
g = 8;
b = 8;
break;
default: // color Gray
r = 128;
g = 128;
b = 128;
break;
}
font[i].image[c] = SDL_DisplayFormat (tmp);
SDL_SetColorKey (font[i].image[c] , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].image[c]->format, 0,0,0));
SDL_FillRect (font[i].image[c], NULL, SDL_MapRGB (font[i].image[c]->format, r,g,b));
SDL_BlitSurface (raw, NULL, font[i].image[c], NULL);
}
font[i].size.x = raw->w / 16;
font[i].size.y = raw->h / 16;
SDL_FreeSurface (raw);
SDL_FreeSurface (tmp);
}
};
void font_setcolor (unsigned char r, unsigned char g, unsigned char b, int size) {
SDL_FillRect (font[size].image, NULL, SDL_MapRGB (font[size].image->format, r,g,b));
SDL_BlitSurface (font[size].raw, NULL, font[size].image, NULL);
};
void font_free() {
int i;
int i, c;
for (i = 0; i < 3; i++) {
SDL_FreeSurface (font[i].image);
SDL_FreeSurface (font[i].raw);
font[i].image = NULL;
for (i = 0; i < 3; i++) for (c = 0; c < 7; c++) {
SDL_FreeSurface (font[i].image[c]);
font[i].image[c] = NULL;
}
};
void font_drawbold (int x, int y, char *text, int size, int bold) {
font_draw (x - bold, y, text, size);
font_draw (x + bold, y, text, size);
font_draw (x, y - bold, text, size);
font_draw (x, y + bold, text, size);
void font_drawbold (int x, int y, char *text, int size, int color, int bold) {
font_draw (x - bold, y, text, size, color);
font_draw (x + bold, y, text, size, color);
font_draw (x, y - bold, text, size, color);
font_draw (x, y + bold, text, size, color);
};
void font_gfxdrawbold (int x, int y, char *text, int size, int color, int bold, int ypos) {
font_gfxdraw (x - bold, y, text, size, color, ypos);
font_gfxdraw (x + bold, y, text, size, color, ypos);
font_gfxdraw (x, y - bold, text, size, color, ypos);
font_gfxdraw (x, y + bold, text, size, color, ypos);
};

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.60 2003/11/12 00:28:04 stpohle Exp $
/* $Id: game.c,v 1.61 2003/12/24 02:38:15 stpohle Exp $
game.c - procedures for the game. */
#include <string.h>
@ -13,14 +13,15 @@
extern int blitdb_nr,
blitrects_nr;
static Uint32 game_timediff, game_timediff1;
Uint32 game_timediff, game_timediff1;
void
game_draw_info ()
{
int i,
x,
j;
j,
col;
char text[255];
char scrtext[255];
SDL_Rect src,
@ -56,16 +57,16 @@ game_draw_info ()
sprintf (scrtext, "%10s:%2d", players[i].name, players[i].points);
if (!PS_IS_alife (players[i].state)) { // Player is dead
if ((players[i].state & PSF_used) != PSF_used)
font_setcolor (128, 128, 128, 0);
col = 4;
else
font_setcolor (0, 0, 128, 0);
col = 3;
}
else { // players is alife
font_setcolor (128, 128, 255, 0);
col = 0;
bman.players_nr++;
}
font_draw (x, j, scrtext, 0);
font_draw (x, j, scrtext, 0, col);
x = x + 170;
if (x >= gfx.res.x - (120 + 170)) {
@ -74,14 +75,13 @@ game_draw_info ()
}
}
font_setcolor (255, 255, 255, 0);
x = gfx.res.x - 120;
sprintf (text, "Bombs: %2d", players[bman.p_nr].bombs_n);
font_draw (x, 0, text, 0);
font_draw (x, 0, text, 0, 0);
sprintf (text, "Range: %2d", players[bman.p_nr].range);
font_draw (x, 16, text, 0);
font_draw (x, 16, text, 0, 0);
sprintf (text, "Speed: %1.1f", players[bman.p_nr].speed*10);
font_draw (x, 32, text, 0);
font_draw (x, 32, text, 0, 0);
if (players[bman.p_nr].special.type != 0) {
dest.x = x - 32;
dest.y = 16;
@ -93,15 +93,13 @@ game_draw_info ()
}
if (bman.state == GS_ready && GT_MP_PTPM)
font_draw (100, 32, "Press F4 to start the game", 0);
font_draw (100, 32, "Press F4 to start the game", 0, 0);
else if (bman.state == GS_ready)
font_draw (100, 32, "Waiting for the Server to Start", 0);
font_draw (100, 32, "Waiting for the Server to Start", 0, 0);
if (map.state == MS_hurrywarn) {
font_setcolor (255,255,255,1);
font_drawbold ((gfx.res.x - strlen ("HURRY HURRY")*font[1].size.x)/2, 32, "HURRY HURRY", 1, 2);
font_setcolor (255,128, 128,1);
font_draw ((gfx.res.x - strlen ("HURRY HURRY")*font[1].size.x)/2, 32, "HURRY HURRY", 1);
font_drawbold ((gfx.res.x - strlen ("HURRY HURRY")*font[1].size.x)/2, 32, "HURRY HURRY", 1, 0, 2);
font_draw ((gfx.res.x - strlen ("HURRY HURRY")*font[1].size.x)/2, 32, "HURRY HURRY", 1, 1);
}
}
@ -119,7 +117,7 @@ game_loop ()
SDL_Event event;
Uint8 *keys;
int done = 0;
Uint32 timeloop1;
// Uint32 timeloop1;
float gameovertimeout = 5.0; // gameovertimeout
unsigned char key_bomb = 0; // last state of the bomb key
@ -237,21 +235,7 @@ game_loop ()
stonelist_draw ();
gfx_blitdraw ();
// 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 ();
}
game_timediff1 = timeloop1 - timestamp;
timestamp = timeloop1;
timefactor = ((float)game_timediff1) / 20.0f;
timediff = ((float)game_timediff1) / 1000.0f;
s_calctimesync ();
}
chat_show (-1, -1, -1, -1);
@ -298,7 +282,7 @@ game_start ()
{
int p, i;
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
// menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
bman.players_nr_s = 0;
@ -365,7 +349,7 @@ void game_showresult () {
Uint8 *keys;
int done = 0, keypressed = 0, x, y, i, p;
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
// menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
dest.x = dest.y = 0;
dest.w = gfx.res.x;
dest.h = gfx.res.y;
@ -375,10 +359,8 @@ void game_showresult () {
strcpy (text, "Game Result");
x = (gfx.res.x - (font[2].size.x * strlen (text)) - 64) / 2;
y = 0;
font_setcolor (128, 128, 0, 2);
font_drawbold (x, y, text, 2, 2);
font_setcolor (255, 255, 128, 2);
font_draw (x, y, text, 2);
font_drawbold (x, y, text, 2, 6, 2);
font_draw (x, y, text, 2, 5);
y += font[2].size.x;
for (i = 0, p = 0; p < MAX_PLAYERS; p++)
@ -391,25 +373,19 @@ void game_showresult () {
strcpy (text, "Draw Game");
x = (gfx.res.x - (font[2].size.x * strlen (text)) - 64) / 2;
font_setcolor (128, 128, 0, 2);
font_drawbold (x, y, text, 2, 2);
font_setcolor (255, 255, 128, 2);
font_draw (x, y, text, 2);
font_drawbold (x, y, text, 2, 6, 2);
font_draw (x, y, text, 2, 5);
y += font[2].size.x + 8;
strcpy (text, "[CTRL],[RETURN] or [STRG] for another game");
x = (gfx.res.x - (font[1].size.x * strlen (text)) - 64) / 2;
font_setcolor (128, 128, 0, 0);
font_drawbold (x, gfx.res.y - (2*font[0].size.y) - 2, text, 0, 2);
font_setcolor (255, 255, 128, 0);
font_draw (x, gfx.res.y - (2*font[0].size.y) - 2, text, 0);
font_drawbold (x, gfx.res.y - (2*font[0].size.y) - 2, text, 0, 6, 2);
font_draw (x, gfx.res.y - (2*font[0].size.y) - 2, text, 0, 5);
strcpy (text, "or [ESC] to leave the game.");
x = (gfx.res.x - (font[1].size.x * strlen (text)) - 64) / 2;
font_setcolor (128, 128, 0, 0);
font_drawbold (x, gfx.res.y - font[0].size.y - 2, text, 0, 2);
font_setcolor (255, 255, 128, 0);
font_draw (x, gfx.res.y - font[0].size.y - 2, text, 0);
font_drawbold (x, gfx.res.y - font[0].size.y - 2, text, 0, 6, 2);
font_draw (x, gfx.res.y - font[0].size.y - 2, text, 0, 5);
for (i = 1, p = 0; p < MAX_PLAYERS; p++) {
if (PS_IS_used (players[p].state)) {
@ -423,18 +399,16 @@ void game_showresult () {
x = 16;
}
font_setcolor (128, 128, 128, 0);
font_drawbold (x + 80, y + 4, players[p].name, 0, 2);
font_drawbold (x + 80, y + 4, players[p].name, 0, 4, 2);
if (PS_IS_alife (players[p].state))
font_setcolor (255, 255, 0, 0);
font_draw (x + 80, y + 4, players[p].name, 0, 0);
else
font_setcolor (196, 196, 196, 0);
font_draw (x + 80, y + 4, players[p].name, 0);
font_draw (x + 80, y + 4, players[p].name, 0, 4);
sprintf (text, "%3d", players[p].wins);
font_draw (x + 80 + (LEN_PLAYERNAME+2) * font[0].size.x, y + 4, text, 0);
font_draw (x + 80 + (LEN_PLAYERNAME+2) * font[0].size.x, y + 4, text, 0, 0);
sprintf (text, "%3d", players[p].points);
font_draw (x + 80 + (LEN_PLAYERNAME+5) * font[0].size.x, y + 4, text, 0);
font_draw (x + 80 + (LEN_PLAYERNAME+5) * font[0].size.x, y + 4, text, 0, 0);
dest.x = x;
dest.y = y - 32;

@ -1,7 +1,8 @@
/* $Id: gfx.c,v 1.27 2003/07/27 21:33:39 stpohle Exp $ */
/* $Id: gfx.c,v 1.28 2003/12/24 02:38:15 stpohle Exp $ */
/* gfx.c */
#include "bomberclone.h"
#include "menu.h"
_gfx gfx;
@ -156,9 +157,7 @@ gfx_init ()
void
gfx_loaddata ()
{
int r,
g,
b;
int i, j;
char filename[255];
SDL_Surface *tmpimage,
*tmpimage1;
@ -183,26 +182,80 @@ gfx_loaddata ()
font_load ();
/* load the menuselector */
sprintf (filename, "%s/gfx/menuselect.bmp", bman.datapath);
/* load the menugraphics */
for (i = 0; i < 9; i++) {
sprintf (filename, "%s/gfx/menu%d.bmp", bman.datapath, i);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
gfx.menuselect.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, font[0].size.y, gfx.menuselect.frames * font[0].size.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.menuselect.image = SDL_DisplayFormat (tmpimage1);
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.images[i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
}
/* load menu buttongraphic */
for (j = 0; j < 3; j++)
for (i = 0; i < 3; i++) {
sprintf (filename, "%s/gfx/menubutton%d_%d.bmp", bman.datapath, j, i);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.buttonimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage);
}
/* load menu buttongraphic */
for (j = 0; j < 2; j++)
for (i = 0; i < 3; i++) {
sprintf (filename, "%s/gfx/menuentry%d_%d.bmp", bman.datapath, j, i);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.entryimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage);
}
/* load menu listgraphic */
for (j = 0; j < 2; j++)
for (i = 0; i < 9; i++) {
sprintf (filename, "%s/gfx/menulist%d_%d.bmp", bman.datapath, j, i);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.listimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage);
}
};
void
gfx_shutdown ()
{
int i, j;
for (i = 0; i < 9; i++) {
SDL_FreeSurface (menu.images[i]);
if (i < 3)
for (j = 0; j < 3; j++) {
SDL_FreeSurface (menu.buttonimages[j][i]);
if (j < 2) SDL_FreeSurface (menu.entryimages[j][i]);
}
for (j = 0; j < 2; j++)
SDL_FreeSurface (menu.listimages[j][i]);
}
SDL_FreeSurface (gfx.logo);
SDL_FreeSurface (gfx.menuselect.image);
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

@ -1,4 +1,4 @@
/* $Id: gfxengine.c,v 1.2 2003/07/25 12:28:50 stpohle Exp $ */
/* $Id: gfxengine.c,v 1.3 2003/12/24 02:38:15 stpohle Exp $ */
/* GFX Game Engine */
#include "bomberclone.h"
@ -120,6 +120,23 @@ void
gfx_blit (SDL_Surface *srci, SDL_Rect *srcr, SDL_Surface *desti, SDL_Rect *destr, int y)
{
int i;
SDL_Rect r_src, r_dest;
if (srcr == NULL) {
srcr = &r_src;
r_src.x = 0;
r_src.y = 0;
r_src.h = srci->h;
r_src.w = srci->w;
};
if (destr == NULL) {
destr = &r_dest;
r_dest.x = 0;
r_dest.y = 0;
r_dest.h = desti->h;
r_dest.w = desti->w;
};
/* check if the rects are out of the images and drop this blitting */
if (srcr->x > srci->w || srcr->y > srci->h ||

@ -1,4 +1,4 @@
/* $Id: gfxpixelimage.c,v 1.3 2003/07/24 13:04:50 stpohle Exp $ */
/* $Id: gfxpixelimage.c,v 1.4 2003/12/24 02:38:15 stpohle Exp $ */
/* gfx pixel manipulation and image manipulation */
#include "bomberclone.h"
@ -480,6 +480,7 @@ gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SD
};
/* save a part of a screen so we can restore it later */
SDL_Surface *
gfx_copyscreen (SDL_Rect * wnd)
{
@ -496,3 +497,17 @@ gfx_copyscreen (SDL_Rect * wnd)
SDL_BlitSurface (gfx.screen, wnd, res, &dest);
return res;
};
/* restore screen from copy */
void gfx_restorescreen (SDL_Surface *img, SDL_Rect *wnd)
{
SDL_Rect dest;
dest.x = 0;
dest.y = 0;
dest.w = wnd->w;
dest.h = wnd->h;
gfx_blit (img, &dest, gfx.screen, wnd, 0);
return;
};

@ -6,13 +6,15 @@
static int keybinput_oldkey = 0;
void keybinput_new (_keybinput *ki) {
void keybinput_new (_keybinput *ki, int type, int maxlen) {
int i;
for (i = 0; i < 255; i++)
ki->text[i] = 0;
ki->curpos = 0;
ki->len = 0;
ki->type = type;
ki->maxlen = maxlen;
}
@ -32,7 +34,24 @@ int keybinput_loop (_keybinput *ki, SDL_Event *event) {
ki->changed = 1;
}
}
else if ((keyu >= 32 && keyu <= 126) || (keyu >= 128 && keyu <= 255)) { // International keyboard support
else if (ki->type == KEYBI_text && ((keyu >= 32 && keyu <= 126) || (keyu >= 128 && keyu <= 255))) {
/* text keys will be read */
if (ki->curpos < ki->maxlen) {
ki->text[ki->curpos++] = event->key.keysym.unicode;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
else if (ki->type == KEYBI_int && (keyu == '-' || (keyu >= '0' && keyu <= '9'))) {
/* only integers will be read */
if (ki->curpos < 255) {
ki->text[ki->curpos++] = event->key.keysym.unicode;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
else if (ki->type == KEYBI_float && (keyu == '-' || keyu == '.' || (keyu >= '0' && keyu <= '9'))) {
/* only floats will be read */
if (ki->curpos < 255) {
ki->text[ki->curpos++] = event->key.keysym.unicode;
ki->text[ki->curpos] = 0;

@ -1,11 +1,10 @@
/* $Id: main.c,v 1.17 2003/11/08 06:27:59 stpohle Exp $ */
/* $Id: main.c,v 1.18 2003/12/24 02:38:15 stpohle Exp $ */
#include "basic.h"
#include "bomberclone.h"
#include "network.h"
#include "gfx.h"
#ifndef _WIN32
#include "../config.h"
#endif
#include "menu.h"
_bomberclone bman; // Holds GameData
@ -16,18 +15,12 @@ float timefactor = 0.0f; /* factor for the time time of the last loop
1.0f would be 20ms */
float timediff = 0.0f; /* last loop timedifference in seconds */
int
main (int argc, char **argv)
{
int menuselect = 0;
_menu menu[] = {
{1, "Singleplayer"},
{1, "Multiplayer"},
{1, "Configuration"},
{1, "Quit Game"},
{-1, ""}
};
char text[255];
int menuselect = 0;
if (SDL_Init (SDL_INIT_VIDEO) != 0) {
d_printf ("Unable to init SDL: %s\n", SDL_GetError ());
@ -38,13 +31,16 @@ main (int argc, char **argv)
SDL_WM_SetCaption(text , NULL);
SDL_EnableUNICODE(1);
game_init (argc, argv);
sprintf(text,"Welcome to BomberClone");
config_init (argc, argv);
while (menuselect != -1 && bman.state != GS_quit) {
menuselect = menu_loop (text , menu, menuselect);
menu_new (text, 400, 200);
menu_create_button ("Single Game", -1, 70, 200, 0);
menu_create_button ("Multiplayer Game", -1, 100, 200, 1);
menu_create_button ("Options", -1, 130, 200, 2);
menu_create_button ("Quit Game", -1, 160, 200, 3);
menuselect = menu_loop ();
menu_delete ();
switch (menuselect) {
case (0) : // Singleplayer
single_menu ();
@ -53,7 +49,7 @@ main (int argc, char **argv)
netmenu();
break;
case (2) : // Options
configuration ();
config_menu ();
break;
case (3) : // Quit
bman.state = GS_quit;

@ -1,4 +1,4 @@
/* $Id: map.c,v 1.13 2003/11/08 06:27:59 stpohle Exp $ */
/* $Id: map.c,v 1.14 2003/12/24 02:38:15 stpohle Exp $ */
/* map handling, like generate and load maps. */
#include "bomberclone.h"
@ -246,7 +246,7 @@ map_set_playerposition (int usermap)
/* we could not set all fields or we don't run on a usermap */
if (usermap) {
sprintf (txt, "Not all players could be set (Pl:%d)", i);
menu_displaymessage ("MAP - ERROR", txt);
// menu_displaymessage ("MAP - ERROR", txt);
}
/* now there will be some fields deleted */

@ -1,7 +1,8 @@
/* $Id: mapmenu.c,v 1.12 2003/11/08 06:27:59 stpohle Exp $ */
/* $Id: mapmenu.c,v 1.13 2003/12/24 02:38:15 stpohle Exp $ */
/* map/tileset selection menu */
#include "bomberclone.h"
#include "menu.h"
/* launch the map options menu */
void
@ -9,11 +10,11 @@ mapmenu ()
{
int menuselect = 0;
char text[255],
*mapname,
*mapname = NULL,
pathname[LEN_PATHFILENAME],
size[4];
_menu menu[] = {
/* _menu menu[] = {
{1, "Random Map:"},
{1, "Selected Map:"},
{2, " Size X:"},
@ -35,9 +36,9 @@ mapmenu ()
{15, "Return To Previous Menu"},
{-1, ""}
};
*/
while (menuselect != -1) {
/*
switch (map.map_selection) {
case (MAPS_select): // Selected Map
if (map.map[0] == 0)
@ -112,8 +113,8 @@ mapmenu ()
sprintf (menu[16].text, "Maptype: RANDOM");
break;
}
menuselect = menu_loop ("Map Options", menu, menuselect);
*/
menuselect = menu_loop ();
switch (menuselect) {
case (0): // Random Map
@ -122,7 +123,7 @@ mapmenu ()
case (1): // Selected Map
sprintf (pathname, "%s/maps", bman.datapath);
mapname = menu_dir_select ("Select Map", pathname, DF_file);
// mapname = menu_dir_select ("Select Map", pathname, DF_file);
if (mapname == NULL) {
map.map[0] = 0;
map.map_selection = 2;
@ -139,7 +140,7 @@ mapmenu ()
case (2): // Size X
sprintf (text, "Field Size X (%d - %d)", MIN_FIELDSIZE_X, MAX_FIELDSIZE_X);
sprintf (size, "%d", map.size.x);
menu_get_text (text, size, 3);
// menu_get_text (text, size, 3);
map.size.x = atoi (size) | 1;
if (map.size.x < MIN_FIELDSIZE_X)
map.size.x = MIN_FIELDSIZE_X;
@ -150,7 +151,7 @@ mapmenu ()
case (3): // Size Y
sprintf (text, "Field Size Y (%d - %d)", MIN_FIELDSIZE_Y, MAX_FIELDSIZE_Y);
sprintf (size, "%d", map.size.y);
menu_get_text (text, size, 3);
// menu_get_text (text, size, 3);
map.size.y = atoi (size) | 1;
if (map.size.y < MIN_FIELDSIZE_Y)
map.size.y = MIN_FIELDSIZE_Y;
@ -167,7 +168,7 @@ mapmenu ()
case (5): // Selected Tileset
sprintf (pathname, "%s/tileset", bman.datapath);
mapname = menu_dir_select ("Select Tileset", pathname, DF_dir);
// mapname = menu_dir_select ("Select Tileset", pathname, DF_dir);
if (mapname == NULL) {
map.tileset[0] = 0;
map.random_tileset = 1;
@ -177,7 +178,7 @@ mapmenu ()
break;
case (6):
sprintf (text, "%d", bman.maxplayer);
menu_get_text ("Max Players", text, 2);
// menu_get_text ("Max Players", text, 2);
bman.maxplayer = atoi (text);
if (bman.maxplayer > MAX_PLAYERS)
bman.maxplayer = MAX_PLAYERS;
@ -186,47 +187,47 @@ mapmenu ()
break;
case (7):
sprintf (text, "%d", map.bombs);
menu_get_text ("Bomb Powerups", text, 2);
// menu_get_text ("Bomb Powerups", text, 2);
map.bombs = atoi (text);
break;
case (8):
sprintf (text, "%d", map.fire);
menu_get_text ("Fire/Range Powerup", text, 2);
// menu_get_text ("Fire/Range Powerup", text, 2);
map.fire = atoi (text);
break;
case (9):
sprintf (text, "%d", map.shoes);
menu_get_text ("Shoes Powerup", text, 2);
// menu_get_text ("Shoes Powerup", text, 2);
map.shoes = atoi (text);
break;
case (10):
sprintf (text, "%d", map.mixed);
menu_get_text ("Mixed Powerup", text, 2);
// menu_get_text ("Mixed Powerup", text, 2);
map.mixed = atoi (text);
break;
case (11):
sprintf (text, "%d", map.death);
menu_get_text ("Death Powerup", text, 2);
// menu_get_text ("Death Powerup", text, 2);
map.death = atoi (text);
break;
case (12):
sprintf (text, "%d", map.sp_trigger);
menu_get_text ("Trigger Specials", text, 2);
// menu_get_text ("Trigger Specials", text, 2);
map.sp_trigger = atoi (text);
break;
case (13):
sprintf (text, "%d", map.sp_push);
menu_get_text ("Push Specials", text, 2);
// menu_get_text ("Push Specials", text, 2);
map.sp_push = atoi (text);
break;
case (14):
sprintf (text, "%d", map.sp_row);
menu_get_text ("Row Specials", text, 2);
// menu_get_text ("Row Specials", text, 2);
map.sp_row = atoi (text);
break;
case (15):
sprintf (text, "%d", bman.init_timeout);
menu_get_text ("Game Timeout", text, 7);
// menu_get_text ("Game Timeout", text, 7);
bman.init_timeout = atoi (text);
break;
case (16):
@ -255,24 +256,24 @@ mapinfo ()
int x, y, eventstate, done = 0;
char text[255];
draw_menubox (WIN_X, WIN_Y);
// draw_menubox (WIN_X, WIN_Y);
x = gfx.res.x / 2;
y = gfx.res.y / 2 - WIN_Y / 2;
sprintf (text, "Map Settings");
font_setcolor (128,128,0,1);
font_draw (x - (font[1].size.x * strlen (text) / 2), y, text, 1);
font_setcolor (255,255,0,1);
font_draw (1 + x - (font[1].size.x * strlen (text) / 2),1 + y, text, 1);
// font_setcolor (128,128,0,1);
// font_draw (x - (font[1].size.x * strlen (text) / 2), y, text, 1);
// font_setcolor (255,255,0,1);
// font_draw (1 + x - (font[1].size.x * strlen (text) / 2),1 + y, text, 1);
y = y + 2 + (font[1].size.y << 1);
/* MapSize */
sprintf (text, "Fieldsize: %d,%d", map.size.x, map.size.y);
font_setcolor (128,128,128,0);
font_draw (x - (font[0].size.x * strlen (text) / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (1 + x - (font[0].size.x * strlen (text) / 2),1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (x - (font[0].size.x * strlen (text) / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (1 + x - (font[0].size.x * strlen (text) / 2),1 + y, text, 0);
y = y + 2 + font[0].size.y;
/* Tileset */
@ -280,10 +281,10 @@ mapinfo ()
sprintf (text, "Random Tileset");
else
sprintf (text, "Tileset: %s", map.tileset);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Mapselection */
if (map.map_selection == 0)
@ -292,64 +293,64 @@ mapinfo ()
sprintf (text, "Random Map");
else
sprintf (text, "Random Generated Map");
font_setcolor (128,128,128,0);
font_draw (x , y, text, 0);
font_setcolor (255,255,255,0);
font_draw (1 + x, 1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (x , y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (1 + x, 1 + y, text, 0);
y = y + 2 + (font[0].size.y << 1);
/* Bomb Powerups */
sprintf (text, "Bomb Powerup: %d", map.bombs);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Trigger */
sprintf (text, "Trigger Specials: %d", map.sp_trigger);
font_setcolor (128,128,128,0);
font_draw (x , y, text, 0);
font_setcolor (255,255,255,0);
font_draw (1 + x, 1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (x , y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (1 + x, 1 + y, text, 0);
y = y + 2 + font[0].size.y;
/* Fire Powerups */
sprintf (text, "Fire Powerup: %d", map.fire);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Push */
sprintf (text, "Push Specials: %d", map.sp_push);
font_setcolor (128,128,128,0);
font_draw (x , y, text, 0);
font_setcolor (255,255,255,0);
font_draw (1 + x, 1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (x , y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (1 + x, 1 + y, text, 0);
y = y + 2 + font[0].size.y;
/* Shoe Powerups */
sprintf (text, "Shoe Powerup: %d", map.shoes);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Row */
sprintf (text, "Row Specials: %d", map.sp_row);
font_setcolor (128,128,128,0);
font_draw (x , y, text, 0);
font_setcolor (255,255,255,0);
font_draw (1 + x, 1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (x , y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (1 + x, 1 + y, text, 0);
y = y + 2 + font[0].size.y;
/* Mixed Powerups */
sprintf (text, "Mixed Powerup: %d", map.mixed);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Special FREE
sprintf (text, "Push Specials: %d", map.sp_push);
@ -361,10 +362,10 @@ mapinfo ()
/* Death Powerups */
sprintf (text, "Death Powerup: %d", map.death);
font_setcolor (128,128,128,0);
font_draw (2 + x - (WIN_X / 2), y, text, 0);
font_setcolor (255,255,255,0);
font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
// font_setcolor (128,128,128,0);
// font_draw (2 + x - (WIN_X / 2), y, text, 0);
// font_setcolor (255,255,255,0);
// font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0);
/* Special FREE
sprintf (text, "Row Specials: %d", map.sp_row);
@ -375,7 +376,7 @@ mapinfo ()
y = y + 2 + font[0].size.y;
SDL_Flip (gfx.screen);
keybinput_new (&ki);
keybinput_new (&ki, KEYBI_text, 10);
while (!done && bman.state == GS_wait) {
if (GT_MP && bman.sock != -1) {

@ -1,596 +1,394 @@
/* $Id: menu.c,v 1.30 2003/11/08 06:27:59 stpohle Exp $ */
/* menu's for the game */
/* $Id: menu.c,v 1.31 2003/12/24 02:38:15 stpohle Exp $
* Menuhandling */
#include <SDL.h>
#include "basic.h"
#include "bomberclone.h"
#include "gfx.h"
/* draws a box size (x,y) */
void
draw_menubox (int x, int y)
{
int x1,
x2,
y1,
y2,
i;
SDL_Rect src,
dest;
x1 = gfx.res.x / 2 - x / 2;
x2 = gfx.res.x / 2 + x / 2;
y1 = gfx.res.y / 2 - y / 2;
y2 = gfx.res.y / 2 + y / 2;
if (gfx_locksurface (gfx.screen))
return;
for (i = 0; i < 2; i++) {
src.x = x1 + i;
src.w = x2 + i;
src.y = y1 + i;
src.h = y2 + i;
draw_shadefield (gfx.screen, &src, MENU_BG_SHADE_BRIGHT);
}
#include "menu.h"
#include "menugui.h"
#include "network.h"
#include "ogcache-client.h"
gfx_unlocksurface (gfx.screen);
dest.w = src.w = x - 2;
dest.h = src.h = y - 2;
dest.x = src.x = x1 + 2;
dest.y = src.y = y1 + 2;
redraw_logo_shaded (x1 + 2, y1 + 2, x - 2, y - 2, MENU_BG_SHADE_DARK);
}
_menuitem menuitems[MENU_MAXENTRYS];
_menu menu;
void
draw_menu (char *text, _menu menu[], int *x, int *y)
{
int last,
maxlen,
y1,
i;
char vers[20];
// count the number of entrys
for (last = 0, maxlen = 0; menu[last].index != -1; last++)
if (((3+strlen (menu[last].text))*font[0].size.x) > maxlen) {
*x = gfx.res.x / 2 - (3+strlen (menu[last].text))*font[0].size.x / 2;
maxlen = (3+strlen (menu[last].text))*font[0].size.x;
}
if ((1+strlen (text))*font[2].size.x > maxlen)
maxlen = (1 + strlen (text))*font[2].size.x;
y1 = 2 * font[2].size.y + (last) * font[0].size.y;
draw_menubox (maxlen + 8, y1);
y1 = gfx.res.y / 2 - y1 / 2;
font_setcolor (128,128,0, 2);
font_draw ((gfx.res.x / 2) - ((font[2].size.x * strlen (text))/2) - 2, y1 - 2, text, 2);
font_setcolor (255,255,0, 2);
font_draw ((gfx.res.x / 2) - ((font[2].size.x * strlen (text))/2), y1, text, 2);
*y = y1 = y1 + (font[2].size.y * 2);
font_setcolor (255,255,255,0);
for (i = 0; i < last; i++) {
font_draw ((gfx.res.x / 2) - ((font[0].size.x * strlen (menu[i].text))/2) , y1, menu[i].text, 0);
y1 = y1 + font[0].size.y;
}
font_setcolor (255,255,255,0);
sprintf (vers, "v%s", VERSION);
font_draw (gfx.res.x - font[0].size.x * strlen (vers), gfx.res.y - font[0].size.y, vers, 0);
/* delete all informations and create a totally new menuscreen */
void menu_new (char *title, int x, int y) {
int i;
if (menu.oldscreen != NULL)
menu_delete();
strncpy (menu.title, title, MENU_TITLELEN);
menu.items = NULL;
menu.focus = NULL;
for (i = 0; i < MENU_MAXENTRYS; i++) {
menuitems[i].id = -1;
menuitems[i].type = -1;
menuitems[i].next = NULL;
}
/* save the old background screen */
x = (1 + (int)(x / menu.images[1]->w)) * menu.images[1]->w;
y = (1 + (int)(y / menu.images[3]->h)) * menu.images[3]->h;
menu.oldscreenpos.x = ((gfx.res.x - (x + 2*menu.images[0]->w)) / 2);
menu.oldscreenpos.y = ((gfx.res.y - (y + 2*menu.images[0]->h)) / 2);
menu.oldscreenpos.w = x + 2*menu.images[0]->w;
menu.oldscreenpos.h = y + 2*menu.images[0]->h;
menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos);
};
void
draw_select (int select, _menu menu[], int x, int y)
{
SDL_Rect dest,
src;
int last;
for (last = 0; menu[last].index != -1; last++)
redraw_logo_shaded (x, y + last * font[0].size.y, gfx.menuselect.image->w,
gfx.menuselect.image->h, MENU_BG_SHADE_DARK);
/* restore the screen and reset all needed informations, free the old screen */
void menu_delete () {
gfx_restorescreen (menu.oldscreen, &menu.oldscreenpos);
gfx_blitdraw ();
SDL_FreeSurface (menu.oldscreen);
menu.oldscreen = NULL;
dest.x = x;
dest.y = y + select * font[0].size.y;
menuitems[0].next = NULL;
menu.items = NULL;
src.x = 0;
src.y = 0;
src.w = font[0].size.y;
src.h = font[0].size.y;
SDL_BlitSurface (gfx.menuselect.image, &src, gfx.screen, &dest);
if (GS_RUNNING)
draw_field ();
};
int
menu_loop (char *menutitle, _menu menu[], int lastselect)
{
int menuselect = lastselect,
done = 0,
ds = 0,
lastentry,
eventstate;
SDL_Event event;
Uint8 *keys;
int keypressed = 0,
bx,
by;
draw_logo ();
draw_menu (menutitle, menu, &bx, &by);
for (lastentry = 0; menu[lastentry].index != -1; lastentry++);
draw_select (menuselect, menu, bx, by);
SDL_Flip (gfx.screen);
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE])
keypressed = 1;
/* draw only a part of the Screen */
void menu_draw_background (SDL_Rect *updaterect) {
int x,y, dx, dy;
SDL_Rect dest, cdest, src, csrc, window;
while (menuselect != -1 && done == 0) {
/* do the network loop if we have to */
if (GT_MP) {
network_loop ();
eventstate = SDL_PollEvent (&event);
}
else
eventstate = SDL_WaitEvent (&event);
if ( eventstate != 0)
switch (event.type) {
case (SDL_QUIT):
menuselect = -1;
bman.state = GS_quit;
done = 1;
break;
}
/* keyboard handling */
keys = SDL_GetKeyState (NULL);
y = 0; // start at the updaterect. start pos
for (; y <= (menu.oldscreenpos.h - 2*menu.images[0]->h - 1)/menu.images[4]->h; y++) {
x = 0; // start at the updaterect. start pos
for (; x <= (menu.oldscreenpos.w - 2*menu.images[0]->w - 1)/menu.images[4]->w; x++) {
dest.x = x * menu.images[4]->w; // start pos
dest.y = y * menu.images[4]->h;
if (keys[SDLK_ESCAPE] && (!keypressed)) {
/* we want to quit */
keypressed = 1;
menuselect = -1;
}
dx = (1+x) * menu.images[4]->w; // end pos
if (dx >= (menu.oldscreenpos.w - 2*menu.images[0]->w))
dest.w = menu.images[4]->w - (dx - (menu.oldscreenpos.w - 2*menu.images[0]->w));
else
dest.w = menu.images[4]->w;
if (keys[SDLK_DOWN] && (!keypressed)) {
menuselect++;
while (menu[menuselect].index == 0)
menuselect++;
if (menu[menuselect].index == -1) {
menuselect = 0;
while (menu[menuselect].index == 0)
menuselect++;
}
keypressed = 1;
ds = 1;
}
dy = (1+y) * menu.images[4]->h;
if (dy >= (menu.oldscreenpos.h - 2*menu.images[0]->h))
dest.h = menu.images[4]->h - (dy - (menu.oldscreenpos.h - 2*menu.images[0]->h));
else
dest.h = menu.images[4]->h;
if (keys[SDLK_UP] && (!keypressed)) {
menuselect--;
while (menu[menuselect].index == 0 && menuselect >= 0)
menuselect--;
if (menuselect == -1)
menuselect = lastentry - 1;
keypressed = 1;
ds = 1;
}
if (dest.w > 0 || dest.h > 0) {
dest.x += MENUOFFSET_X;
dest.y += MENUOFFSET_Y;
src.x = 0; src.y = 0; src.h = dest.h; src.w = dest.w;
if ((keys[SDLK_LCTRL] || keys[SDLK_RCTRL] || keys[SDLK_RETURN]) && (!keypressed) && (event.type = SDL_KEYDOWN)) {
done = 1;
keypressed = 1;
// d_printf("return pressed - done=1\n");
if (updaterect == NULL)
gfx_blit (menu.images[4], &src, gfx.screen, &dest, 10000);
else {
window = *updaterect;
window.x += MENUOFFSET_X;
window.y += MENUOFFSET_Y;
rect_clipping (&src, &dest, &window, &csrc, &cdest);
if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF && cdest.h < UINT16_HALF)
gfx_blit (menu.images[4], &csrc, gfx.screen, &cdest, 10000);
}
if (event.type == SDL_KEYUP) { // d_printf("keyup\n");
keypressed = 0;
}
else if (event.type == SDL_KEYDOWN) {
// d_printf("keydown\n");
keypressed = 1;
}
if (ds) {
draw_select (menuselect, menu, bx, by);
ds = 0;
SDL_Flip (gfx.screen);
}
s_delay (25);
};
return menuselect;
};
void
menu_get_text (char *title, char *text, int len)
{
char t[255];
int done = 0,
keypressed = 0,
curpos,
x,
y,
i,
len_,
eventstate,
maxwidth;
SDL_Event event;
Uint8 *keys;
text[len] = 0;
curpos = strlen (text);
if (curpos >= len)
curpos = len - 1;
strcpy (t, text);
maxwidth = len * font[0].size.x;
if (maxwidth < font[1].size.x * strlen (title))
maxwidth = font[1].size.x * strlen (title);
draw_menubox (maxwidth + 8, font[1].size.y + font[0].size.y + 8);
x = gfx.res.x / 2 - maxwidth / 2;
y = gfx.res.y / 2 - (font[1].size.y + font[0].size.y) / 2;
font_setcolor (128,64,0,1);
font_draw (x - 2, y - 2, title, 1);
font_setcolor (192,128,0,1);
font_draw (x, y, title, 1);
/* draws the menuborders, this function does not save the background */
void menu_draw_border () {
SDL_Rect dest;
int i, dx;
// draw top left
dest.x = menu.oldscreenpos.x;
dest.y = menu.oldscreenpos.y;
dest.w = menu.images[0]->w;
dest.h = menu.images[0]->h;
gfx_blit (menu.images[0], NULL, gfx.screen, &dest, 10000);
// draw top and below
for (i = 0; i < ((menu.oldscreenpos.w - (2*menu.images[0]->w)) / menu.images[1]->w); i++) {
dest.x = menu.oldscreenpos.x + menu.images[0]->w + (i * menu.images[1]->w);
dest.y = menu.oldscreenpos.y;
dest.w = menu.images[1]->w;
dest.h = menu.images[1]->h;
gfx_blit (menu.images[1], NULL, gfx.screen, &dest, 10000);
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[7]->h;
gfx_blit (menu.images[7], NULL, gfx.screen, &dest, 10000);
}
// draw top right
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[2]->w;
dest.y = menu.oldscreenpos.y;
dest.w = menu.images[2]->w;
dest.h = menu.images[2]->h;
gfx_blit (menu.images[2], NULL, gfx.screen, &dest, 10000);
// draw left and right
for (i = 0; i < ((menu.oldscreenpos.h - (2*menu.images[0]->h)) / menu.images[3]->h); i++) {
dest.x = menu.oldscreenpos.x;
dest.y = menu.oldscreenpos.y + menu.images[0]->h + menu.images[3]->h * i;
dest.w = menu.images[1]->w;
dest.h = menu.images[1]->h;
gfx_blit (menu.images[3], NULL, gfx.screen, &dest, 10000);
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[5]->w;
gfx_blit (menu.images[5], NULL, gfx.screen, &dest, 10000);
}
// draw below left
dest.x = menu.oldscreenpos.x;
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[7]->h;
dest.w = menu.images[6]->w;
dest.h = menu.images[6]->h;
gfx_blit (menu.images[6], NULL, gfx.screen, &dest, 10000);
// draw below right
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[8]->w;
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[8]->h;
dest.w = menu.images[8]->w;
dest.h = menu.images[8]->h;
gfx_blit (menu.images[8], NULL, gfx.screen, &dest, 10000);
menu_draw_background (NULL);
// draw title
dx = menu.oldscreenpos.x + (menu.oldscreenpos.w - font[2].size.x*strlen (menu.title)) / 2;
font_gfxdrawbold (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_brown, 2, 10000);
font_gfxdraw (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_yellow, 10000);
};
font_setcolor (192,192,192,0);
y = y + font[1].size.y;
if ((len - 1) * (font[0].size.x) > gfx.res.x)
len_ = 40;
else
len_ = len;
/* draw the menu, even it is only put into the gfx_blitlist. gfx_blitdraw needs
* to be called before the menu is drawed on the screen */
void menu_draw () {
_menuitem *m;
while (!done || keypressed == 1) {
menu_draw_border ();
redraw_logo_shaded (x, y, font[0].size.x * len_, font[0].size.y,
MENU_BG_SHADE_DARK);
font_draw (x, y, t, 0);
font_draw (x + font[0].size.x * curpos, y, "_", 0);
SDL_Flip (gfx.screen);
for (m = menu.items; m != NULL; m = m->next)
menu_draw_menuitem (m);
};
/* do the network loop if we have to */
if (GT_MP) {
network_loop ();
eventstate = SDL_PollEvent (&event);
}
else
eventstate = SDL_WaitEvent (&event);
if ( eventstate != 0)
switch (event.type) {
case (SDL_QUIT):
bman.state = GS_quit;
done = 1;
/* draw an item on the screen */
inline void menu_draw_menuitem (_menuitem *m) {
switch (m->type) {
case (MENU_label):
menu_draw_label (m);
break;
case (MENU_button):
menu_draw_button (m);
break;
case (MENU_bool):
menu_draw_bool (m);
break;
case (MENU_entryint):
case (MENU_entrytext):
menu_draw_entry (m);
break;
case (MENU_list):
menu_draw_list (m);
break;
}
};
keys = SDL_GetKeyState (NULL);
if (!keypressed && keys[SDLK_LEFT] && event.type == SDL_KEYDOWN) {
if (curpos > 0)
curpos--;
keypressed = 1;
}
if (!keypressed && keys[SDLK_RIGHT] && event.type == SDL_KEYDOWN) {
if (curpos < strlen (text) && curpos < len - 1)
curpos++;
keypressed = 1;
}
if (!keypressed && keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
done = 1;
keypressed = 1;
}
/* find the last menuitem in the list. */
int menu_getlastitem (_menuitem *first) {
int i = 0;
_menuitem *result = first;
if (!keypressed && keys[SDLK_RETURN] && event.type == SDL_KEYDOWN) {
done = 1;
keypressed = 1;
strcpy (text, t);
}
if (first == NULL) // no first item there
return -1;
if (!keypressed && keys[8] && event.type == SDL_KEYDOWN)
if (curpos > 0) {
curpos--;
t[curpos] = t[curpos + 1];
t[curpos + 1] = t[curpos + 2];
keypressed = 1;
}
for (;result->next != NULL; result = result->next)
i++;
for (i = ' '; i <= 255; i++)
if (i != 127 && !keypressed && keys[i] && event.type == SDL_KEYDOWN) {
if (t[curpos] == 0)
t[curpos + 1] = 0;
t[curpos] = event.key.keysym.unicode;
if (curpos < strlen (t) && curpos < len - 1)
curpos++;
keypressed = 1;
return i;
}
if (event.type == SDL_KEYUP)
keypressed = 0;
s_delay (25);
}
/* get the last and the first id number */
_menuitem *menu_get_firstid () {
_menuitem *result = NULL, *mi = menu.items;
for (mi = menu.items; mi != NULL; mi = mi->next)
if ((result == NULL || mi->id < result->id) && mi->id != -1)
result = mi;
return result;
};
_menuitem *menu_get_lastid () {
_menuitem *result = NULL, *mi = menu.items;
for (mi = menu.items; mi != NULL; mi = mi->next)
if ((result == NULL || mi->id > result->id) && mi->id != -1)
result = mi;
return result;
};
void
menu_displaytext (char *title, char *text, Uint8 r, Uint8 g, Uint8 b)
{
int x,
x1,
y,
y1,
len,
maxwidth;
SDL_Rect dest;
len = strlen (title);
if (len < strlen (text))
len = strlen (text);
/* change the focus to the givin element */
void menu_change_focus (_menuitem *newfocus) {
_menuitem *oldmi;
maxwidth = strlen(title) * font[1].size.x;
if (maxwidth < font[0].size.x * strlen (text))
maxwidth = font[0].size.x * strlen (text);
if (newfocus == menu.focus) // no focus change
return;
y = (gfx.res.y - (font[1].size.y + font[1].size.y)) / 2;
x = (gfx.res.x - maxwidth) / 2;
/* lose focus */
switch (menu.focus->type) {
case (MENU_entryint):
case (MENU_entrytext):
menu_entry_lose_focus (menu.focus);
break;
}
y1 = font[0].size.y + font[1].size.y;
x1 = maxwidth + 8;
/* draw the old and the new element */
oldmi = menu.focus;
menu.focus = newfocus;
menu_draw_menuitem (oldmi);
menu_draw_menuitem (menu.focus);
dest.x = x - 4;
dest.y = y - 4;
dest.h = y1 + 8;
dest.w = x1 + 8;
SDL_FillRect (gfx.screen, &dest, SDL_MapRGB (gfx.screen->format, r, g, b));
/* get focus ... no function yet */
font_setcolor (128,128,128, 1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2 - 2, y - 2, title, 1);
font_setcolor (255,255,255, 1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2, y, title, 1);
d_printf ("menu_change_focus: ID:%d Name:%s\n", menu.focus->id, menu.focus->label);
};
font_setcolor (255,255,0, 1);
font_draw ((gfx.res.x - font[0].size.x * strlen (text)) / 2, y + font[1].size.y + 2, text,
0);
SDL_Flip (gfx.screen);
};
/* focus next element, order by ID */
void menu_focus_next () {
_menuitem *newmi = menu.focus, *mi, *oldmi = menu.focus;
for (mi = menu.items; mi != NULL; mi = mi->next)
if (mi->id != oldmi->id && mi->id > menu.focus->id && (mi->id < newmi->id || newmi == oldmi))
newmi = mi;
if (newmi == oldmi)
menu_change_focus (menu_get_firstid());
else
menu_change_focus (newmi);
};
void
menu_displaymessage (char *title, char *text)
{
SDL_Event event;
Uint8 *keys;
int done = 0,
keypressed = 0,
eventstate;
menu_displaytext (title, text, 64, 0, 0);
/* focus previous element, order by ID */
void menu_focus_prev () {
_menuitem *newmi = menu.focus, *mi, *oldmi = menu.focus;
while (done == 0 || (done == 1 && keypressed == 1)) {
/* do the network loop if we have to */
if (GT_MP) {
network_loop ();
eventstate = SDL_PollEvent (&event);
}
for (mi = menu.items; mi != NULL; mi = mi->next)
if (mi->id != -1 && mi->id != oldmi->id && mi->id < oldmi->id && (mi->id > newmi->id || newmi == oldmi))
newmi = mi;
if (newmi == oldmi)
menu_change_focus (menu_get_lastid());
else
eventstate = SDL_WaitEvent (&event);
if ( eventstate != 0)
switch (event.type) {
case (SDL_QUIT):
done = 1;
bman.state = GS_quit;
}
keys = SDL_GetKeyState (NULL);
menu_change_focus (newmi);
};
if (!keypressed && keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
done = 1;
keypressed = 1;
}
if (!keypressed && keys[SDLK_RETURN] && event.type == SDL_KEYDOWN) {
done = 1;
keypressed = 1;
}
/* focus element with id ID */
void menu_focus_id (int id) {
_menuitem *mi, *oldmi = menu.focus;
if (event.type == SDL_KEYUP)
keypressed = 0;
for (mi = menu.items; mi != NULL; mi = mi->next)
if (mi->id == id)
menu_change_focus (mi);
s_delay (100);
}
menu_draw_menuitem (oldmi);
if (menu.focus != oldmi)
menu_draw_menuitem (menu.focus);
};
void
menu_clearkeybuff ()
{
/* menu loop, programm will stay in here as long as no ESCAPE is pressed
* and as long as no Button is clicked. Return of -2 means something needs to reordered */
int menu_loop () {
SDL_Event event;
Uint8 *keys;
int i;
int keypressed = 0, done = 0, eventstate = 0, reorder = 0;
SDL_PollEvent (&event);
keys = SDL_GetKeyState (NULL);
if (!(keys[SDLK_RETURN]))
return;
for (i = 0; i < 20; i++) {
s_delay (25);
SDL_PollEvent (&event);
keys = SDL_GetKeyState (NULL);
if (!(keys[SDLK_RETURN]))
return;
/* check if the focus is set to something, if not
* set the focus to the first item */
if (menu.focus == NULL)
menu.focus = menu.items;
if (menu.focus == NULL) {
d_fatal ("menu_loop: focus == NULL, something went wrong\n");
return -1;
}
menu_focus_id (0);
menu_displaytext ("", " Press Return ", 64, 0, 0);
while (keys[SDLK_RETURN]) {
s_delay (25);
SDL_PollEvent (&event);
keys = SDL_GetKeyState (NULL);
}
}
if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE])
keypressed = 1;
timestamp = SDL_GetTicks (); // needed for time sync.
menu_draw();
/***
*** Menu Selection of a file ior a directory
***/
#define DIRSCRMAX 10
/* draws the selection on the screen..
dirstart - first entry do display
flags - flags what should be shown directorys or files
selected - Selected file in the list
*/
int
menu_dir_draw (char *title, _direntry * dirstart, int start, int selected)
{
_direntry *de = dirstart;
int maxlen = 0, maxchar = 0,
pos = 0;
SDL_Rect wnd;
/* look for the longest name */
maxlen = font[1].size.x * strlen (title);
for (; de != NULL; de = de->next)
if (maxlen < font[0].size.x * strlen (de->name))
maxlen = font[0].size.x * strlen (de->name);
if (maxlen > gfx.res.x - 32)
maxchar = (gfx.res.x - 40) / font[0].size.x;
else
maxchar = maxlen / font[0].size.x;
wnd.h = DIRSCRMAX * font[0].size.y * 2;
wnd.w = maxlen;
wnd.x = (gfx.res.x - wnd.w) / 2;
wnd.y = (gfx.res.y - wnd.h) / 2;
draw_menubox (wnd.w + 8, wnd.h + 8);
font_setcolor (128,64,0,1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2 - 2, wnd.y - 2, title, 1);
font_setcolor (192,128,0,1);
font_draw ((gfx.res.x - font[1].size.x * strlen (title)) / 2, wnd.y, title, 1);
for (de = dirstart, pos = 0; de != NULL && pos < start + DIRSCRMAX - 1; de = de->next, pos++) {
if (pos >= start && pos < (start + DIRSCRMAX - 1)) {
if (pos == selected)
font_setcolor (255,255,255, 0);
else
font_setcolor (128,128,128, 0);
font_draw (wnd.x + gfx.menuselect.image->w + 2,
8 + wnd.y + (1 + pos - start) * font[0].size.y * 2, de->name, 0);
}
}
return (de == NULL);
}
char *
menu_dir_select (char *title, char *path, signed char dirflags)
{
_direntry *destart,
*de;
SDL_Event event;
Uint8 *keys;
int max = 0,
sel = 0,
keypressed = 0,
done = 0,
listend = 0,
liststart = 0,
oldsel = -1,
eventstate;
/* get the directory list and count the numbers */
destart = s_getdir (path);
destart = s_dirfilter (destart, dirflags);
for (max = 0, de = destart; de != NULL; de = de->next)
max++;
if (max <= 0)
return NULL;
while (done == 0 || (done == 1 && keypressed == 1)) {
if (sel != oldsel) {
listend = menu_dir_draw (title, destart, liststart, sel);
SDL_Flip (gfx.screen);
oldsel = sel;
}
while (!reorder && !done && bman.state != GS_quit) {
gfx_blitdraw ();
/* do the network loop if we have to */
if (GT_MP) {
if (bman.sock > 0) {
network_loop ();
eventstate = SDL_PollEvent (&event);
if (bman.notifygamemaster)
reorder = ogc_loop ();
}
else
eventstate = SDL_WaitEvent (&event);
if ( eventstate != 0)
eventstate = SDL_PollEvent (&event);
if (eventstate >= 1) {
switch (event.type) {
case (SDL_QUIT):
sel = -1;
bman.state = GS_quit;
done = 1;
}
/* keyboard handling */
return -1;
break;
case (SDL_KEYDOWN): /* focus next element */
if (event.key.keysym.sym == SDLK_TAB) {
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_DOWN] && event.type == SDL_KEYDOWN && keypressed == 0) {
keypressed = 1;
sel++;
if (!(listend)) /* if we can move this list down */
liststart++;
if (sel >= max) {
liststart = 0;
sel = 0;
if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])
menu_focus_prev ();
else
menu_focus_next ();
break;
}
else if (event.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
return -1;
break;
}
if (keys[SDLK_UP] && event.type == SDL_KEYDOWN && keypressed == 0) {
keypressed = 1;
sel--;
if (liststart > 0)
liststart--;
if (sel < 0) {
sel = max - 1;
if (sel > (DIRSCRMAX / 2))
liststart = sel - (DIRSCRMAX / 2);
default: /* push events to the menu items */
switch (menu.focus->type) {
case (MENU_button):
done = menu_event_button (menu.focus, &event);
break;
case (MENU_bool):
done = menu_event_bool (menu.focus, &event);
break;
case (MENU_entryint):
case (MENU_entrytext):
done = menu_event_entry (menu.focus, &event);
break;
case (MENU_label):
break;
case (MENU_list):
done = menu_event_list (menu.focus, &event);
break;
}
}
if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
keypressed = 1;
return NULL;
}
if (!keys[SDLK_ESCAPE] && event.type == SDL_KEYUP)
keypressed = 0;
if (keys[SDLK_RETURN] && event.type == SDL_KEYDOWN) {
done = 1;
keypressed = 1;
menu.focusto -= timediff;
if (menu.focusto <= 0.0f) {
menu.focusto = MENU_FOCUSVIS_BLINKTO;
menu.focusvis = !menu.focusvis;
menu_draw_menuitem (menu.focus);
}
if (!keys[SDLK_RETURN] && event.type == SDL_KEYUP)
keypressed = 0;
s_delay (25);
s_calctimesync ();
}
for (max = 0, de = destart; max != sel && de != NULL; de = de->next)
max++;
if (reorder)
return -2;
if (de == NULL)
return NULL;
return de->name;
return menu.focus->id;
};
#undef DIRSCRMAX

@ -6,7 +6,6 @@
#include "bomberclone.h"
#include "network.h"
#include "packets.h"
#include "gamesrv.h"
#include "gfx.h"
#include "chat.h"
@ -28,7 +27,7 @@ mw_init ()
draw_logo ();
menu_displaytext ("Please Wait", "Loading GFX Data", 64, 128, 64);
// menu_displaytext ("Please Wait", "Loading GFX Data", 64, 128, 64);
gfx_load_players (32, 32);
network_loop ();
@ -64,7 +63,7 @@ mw_shutdown ()
void
mw_wait_for_connect ()
{
menu_displaytext ("Please Wait", "Wait For connection", 64, 128, 64);
// menu_displaytext ("Please Wait", "Wait For connection", 64, 128, 64);
};
@ -86,13 +85,13 @@ mw_draw_status ()
x = (gfx.res.x - px * 320) / 2;
gfx_blitupdaterectclear ();
for (pnr = 0; pnr < px; pnr++) {
/* for (pnr = 0; pnr < px; pnr++) {
font_setcolor (128, 128, 128, 0);
font_draw (pnr * 320 + x - 2, 22, " Wins Points", 0);
font_setcolor (192, 192, 255, 0);
font_draw (pnr * 320 + x, 24, " Wins Points", 0);
}
*/
/* 2. the names with points */
for (x1 = pnr = 0, y = 48; pnr < MAX_PLAYERS; pnr++) {
redraw_logo (x1 * 320, y - 4, 320, 32);
@ -113,10 +112,9 @@ mw_draw_status ()
if (PS_IS_used (players[pnr].state)) {
if (bman.lastwinner == pnr)
font_setcolor (255, 255, 192, 0);
font_draw (x + x1 * 320, y, text, 0, 0);
else
font_setcolor (192, 192, 192, 0);
font_draw (x + x1 * 320, y, text, 0);
font_draw (x + x1 * 320, y, text, 0, 4);
}
x1++;
if (x1 >= px) {

@ -3,178 +3,90 @@
#include "bomberclone.h"
#include "network.h"
#include "packets.h"
#include "gamesrv.h"
#include "gfx.h"
#include "menu.h"
extern int UpdateRects_nr;
void
networkmenu_joingame ()
{
int i;
gamesrv_getserver ();
for (i = 0; bman.servername[i] != 0; i++)
if (bman.servername[i] == ' ')
bman.servername[i] = ':';
/* connect if we have an Servername */
if (bman.servername[0] != 0) {
bman.sock = -1;
join_multiplayer_game ();
bman.servername[0] = 0;
}
};
void
netmenu ()
{
int menuselect = 0;
_menu menu[] = {
{1, "Join A Netgame"},
{1, "Create A New Netgame"},
{2, "Options"},
{3, "Return To Main Menu"},
{-1, ""}
};
if (bman.gamename[0] == 0)
sprintf (bman.gamename, "%s's Game", bman.playername);
while (menuselect != -1 && bman.state != GS_quit) {
menuselect = menu_loop ("Multiplayer", menu, menuselect);
menu_new ("Multiplayer", 250, 200);
menu_create_button ("Host a Game", -1, 70, 200, 0);
menu_create_button ("Join a Game", -1, 110, 200, 1);
menu_create_button ("Network Options", -1, 150, 200, 2);
menuselect = menu_loop ();
menu_delete ();
switch (menuselect) {
case (0): // Join a Game
networkmenu_joingame ();
break;
case (1): // Create a new Game
case (0): // Create a Game
bman.sock = -1;
host_multiplayer_game ();
break;
case (2): // Options
networkmenu_options ();
case (1): // Join a Game
join_multiplayer_game ();
break;
case (3):
menuselect = -1;
case (2): // Options
network_options ();
break;
}
}
}
void
networkmenu_options ()
network_options ()
{
int menuselect = 0;
char text[255];
_menu menu[] = {
{1, "Game Name:"},
{1, "Max Players:"},
{2, "Network"},
{3, "UDP Port"},
{4, "Behind a Firewall"},
{5, "Notify Masterserver"},
{6, "Masterserver"},
{7, "Broadcastes Chat"},
{8, "Return To Multiplayer Menu"},
{-1, ""}
};
#ifdef _WIN32
menu[2].index=0;
#endif
while (menuselect != -1 && bman.state != GS_quit) {
sprintf (menu[0].text, "Gamename: %s", bman.gamename);
sprintf (menu[1].text, "Max Players: %d/%d", bman.maxplayer, MAX_PLAYERS);
if (bman.net_ai_family == PF_INET)
sprintf (menu[2].text, "Network: IPv4");
else
sprintf (menu[2].text, "Network: IPv6");
sprintf (menu[3].text, "UDP Port: %s", bman.port);
int menuselect = 0, done = 0, net_ai_typ, i;
_charlist nrplayerlist[MAX_PLAYERS];
_charlist *selnrplayer = &nrplayerlist[bman.maxplayer-1];
if (bman.firewall)
sprintf (menu[4].text, "Firewall: ON");
else
sprintf (menu[4].text, "Firewall: OFF");
if (bman.notifygamemaster)
sprintf (menu[5].text, "Notify MasterServer: Yes");
else
sprintf (menu[5].text, "Notify MasterServer: No");
if (bman.notifygamemaster) {
sprintf (menu[6].text, "MasterServer %s", bman.gamemaster);
menu[6].index = 6;
}
else
menu[6].text[0] = menu[6].index = 0;
if (bman.broadcasted_chat && bman.notifygamemaster) {
sprintf (menu[7].text, "Broadcasted Chat: ON");
menu[7].index = 7;
}
else if (bman.notifygamemaster) {
sprintf (menu[7].text, "Broadcasted Chat: OFF");
menu[7].index = 7;
}
/* fill in the nrplayerlist */
for (i = 0; i < MAX_PLAYERS; i++) {
sprintf (nrplayerlist[i].text, "%d", (i+1));
if (i < MAX_PLAYERS-1)
nrplayerlist[i].next = &nrplayerlist[i+1];
else
menu[7].index = menu[7].text[0] = 0;
menuselect = menu_loop ("Multiplayer Options", menu, menuselect);
switch (menuselect) {
case (0): // change the game name
menu_get_text ("Name of the Game:", bman.gamename, 32);
break;
case (1): // Max Number of Players
sprintf (text, "%d", bman.maxplayer);
menu_get_text ("Max Players", text, 2);
bman.maxplayer = atoi (text);
if (bman.maxplayer > MAX_PLAYERS)
bman.maxplayer = MAX_PLAYERS;
if (bman.maxplayer < 2)
bman.maxplayer = 2;
break;
case (2):
#ifndef _WIN32
if (bman.net_ai_family == PF_INET)
nrplayerlist[i].next = NULL;
}
while (menuselect != -1 && !done && bman.state != GS_quit) {
/* fill in net_ai_typ */
net_ai_typ = (PF_INET != bman.net_ai_family);
menu_new ("Network Options", 400, 380);
menu_create_label ("Number Of Players", 60, 75, 0);
menu_create_list ("Players", 270, 55, 55, 70, nrplayerlist, &selnrplayer, 1);
menu_create_entry ("Gamename", -1, 150, 300, &bman.gamename, LEN_GAMENAME, MENU_entrytext, 2);
menu_create_entry ("UDP Port:", -1, 180, 200, &bman.port, LEN_PORT, MENU_entrytext,3);
menu_create_bool ("IPV6", 50, 215, 100, &net_ai_typ, 4);
menu_create_bool ("Firewall", 270, 215, 100, &bman.firewall, 5);
menu_create_bool ("Use OpenGameCache", -1, 250, 350, &bman.notifygamemaster, 6);
menu_create_entry ("OpenGameCache:", -1, 280, 350, &bman.ogcserver, LEN_SERVERNAME, MENU_entrytext, 7);
menu_create_entry ("Local OGC Port", -1, 310, 350, &bman.ogc_port, LEN_PORT, MENU_entrytext, 8);
menu_create_button ("Ok", -1, 350, 150, 0);
menuselect = menu_loop ();
bman.maxplayer = (selnrplayer - &nrplayerlist[0]) + 1;
menu_delete ();
/* fix net_ai_typ */
#ifndef _WIN32 // fix for windows i don't know how to get there ipv6 mode.
if (net_ai_typ)
bman.net_ai_family = PF_INET6;
else
bman.net_ai_family = PF_INET;
#endif
break;
case (3): // UDP Port
menu_get_text ("UDP Port", bman.port,
LEN_PORT + 1);
break;
case (4): // Firewall Option
bman.firewall = 1 - bman.firewall ;
break;
case (5): // Change the Notification
bman.notifygamemaster = 1 - bman.notifygamemaster;
break;
case (6): // Masterserver Address
menu_get_text ("Address of the MasterServer", bman.gamemaster,
LEN_SERVERNAME + LEN_PORT + 2);
break;
case (7):
bman.broadcasted_chat = 1 - bman.broadcasted_chat;
break;
bman.net_ai_family = PF_INET;
case (8):
menuselect = -1;
switch (menuselect) {
case (0): // all options made Save Config
done = 1;
config_write ();
break;
}
}
@ -192,47 +104,69 @@ multiplayer_firstrun ()
bman.state = GS_wait;
for (i = 0; i < MAX_PLAYERS; i++) {
players[i].net.addr.host[0] = 0;
players[i].net.addr.port[0] = 0;
players[i].name[0] = 0;
players[i].gfx_nr = -1;
players[i].gfx = NULL;
players[i].net.timestamp = timestamp;
players[i].points = 0;
players[i].wins = 0;
players[i].net.pingreq = 20;
players[i].net.pingack = 22;
players[i].state = 0;
}
/*
init the network
*/
if (network_init () < 0) {
d_printf ("network_init () FAILED\n");
return;
}
bman.lastwinner = -1;
bman.players_nr_s = 1;
};
/*
We will host a network game
* We will host a network game
*/
void
host_multiplayer_game ()
{
void host_multiplayer_game () {
if (bman.firewall) {
menu_displaymessage ("Firewall Option", "You can't start a game with Firewall enabled.");
return;
}
bman.servername[0] = 0; // delete servername
multiplayer_firstrun ();
if (network_init () < 0) {
d_printf ("network_init () FAILED\n");
return;
}
/* prepare the server */
strncpy (players[0].name, bman.playername, LEN_PLAYERNAME);
bman.p_nr = bman.p_servnr = 0;
players[0].state = PSF_used;
if (bman.notifygamemaster)
send_ogc_update (); /* send the information that we started an server */
multiplayer_game ();
network_shutdown ();
};
/* the loop for the multiplayer games */
void multiplayer_game () {
while (bman.state != GS_startup && bman.state != GS_quit) {
/* check players and in_pl lists */
wait_for_players ();
if (bman.p_nr != -1) {
if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) {
bman.state = GS_update;
net_new_game ();
if (GT_MP_PTPM)
net_send_servermode ();
game_start ();
net_transmit_gamedata ();
if (bman.state == GS_ready || bman.state == GS_running) {
if (GT_MP_PTPM)
net_send_servermode ();
game_loop ();
@ -240,46 +174,57 @@ host_multiplayer_game ()
bman.state = GS_wait;
bman.lastwinner = -1;
game_end ();
if (GT_MP_PTPM) {
net_send_servermode ();
net_send_players ();
}
}
else
game_end ();
}
}
network_shutdown ();
};
/*
We will join a network game
*/
/* We will join a network game */
void
join_multiplayer_game ()
{
int i;
multiplayer_firstrun ();
if (network_init () < 0) {
d_printf ("network_init () FAILED\n");
return;
}
while (bman.state != GS_startup && bman.state != GS_quit) {
wait_for_players ();
/* do the serverlist menu and join a server */
net_getserver ();
if (bman.servername[0] != 0) {
/* join the server, convert to a usable sockaddr first */
network_server_port (bman.servername, players[0].net.addr.host,
LEN_SERVERNAME, players[0].net.addr.port, LEN_PORT);
if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) {
net_new_game ();
game_start ();
bman.state = GS_update;
net_transmit_gamedata ();
d_printf ("Connect To: %s[:%s]\n", players[0].net.addr.host,
players[0].net.addr.port);
if (bman.state == GS_ready || bman.state == GS_running)
game_loop ();
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
players[0].net.addr.port[0] = players[0].net.addr.host[0] = 0;
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
game_end ();
}
else {
bman.state = GS_startup;
}
/* and join the server */
if (bman.firewall)
i = NETF_firewall;
else
i = 0;
send_joingame (&players[0].net.addr, bman.playername);
/* go into the normal multiplayer loop */
multiplayer_game ();
}
network_shutdown ();

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.45 2003/11/09 23:56:35 stpohle Exp $ */
/* $Id: network.c,v 1.46 2003/12/24 02:38:16 stpohle Exp $ */
/*
network routines.
*/
@ -7,7 +7,7 @@
#include "network.h"
#include "chat.h"
#include "packets.h"
#include "gamesrv.h"
#include "ogcache-client.h"
int
network_server_port (char *server, char *host, int hostlen, char *port, int portlen)
@ -88,10 +88,10 @@ net_dyn_pkgoption ()
int
network_init ()
{
int i;
/*
we need it for the windows winsock
*/
char host[LEN_SERVERNAME];
char port[LEN_PORT];
/* we need it for the windows winsock */
#ifdef _WIN32
WSADATA wsaData;
@ -102,36 +102,8 @@ network_init ()
#endif
bman.sock = -1;
/* set playernumber and server playernumber */
if (bman.servername[0] == 0) { // we are the server
bman.p_servnr = 0;
bman.p_nr = 0;
}
else {
bman.p_servnr = 0; // to make sure GT_MP_PTPM/S is working right
bman.p_nr = -1;
}
timestamp = SDL_GetTicks ();
// reset playernumber and number of connected players
for (i = 0; i < MAX_PLAYERS; i++) {
players[i].net.addr.host[0] = 0;
players[i].net.addr.port[0] = 0;
players[i].name[0] = 0;
players[i].gfx_nr = -1;
players[i].net.timestamp = timestamp;
players[i].points = 0;
players[i].wins = 0;
players[i].net.pingreq = 20;
players[i].net.pingack = 22;
players[i].state = 0;
}
bman.lastwinner = -1;
bman.players_nr_s = 1;
// start the udp server
bman.sock = udp_server (bman.port, bman.net_ai_family);
@ -142,36 +114,16 @@ network_init ()
return -1;
}
if (bman.notifygamemaster) {
network_server_port (bman.ogcserver, host, LEN_SERVERNAME, port, LEN_PORT);
if (ogc_init (bman.ogc_port, host, port, "BomberClone", bman.net_ai_family) == 0)
bman.notifygamemaster = 0;
}
// we have got our socket.. so now allocate the memory for the resend_cache
resend_cache.data = (char *) malloc (PKG_RESENDCACHE_SIZE);
resend_cache.fill = 0;
// if we are the server set up my data
if (GT_MP_PTPM) {
strncpy (players[0].name, bman.playername, LEN_PLAYERNAME);
bman.p_nr = 0;
players[0].state = PSF_used;
if (bman.notifygamemaster)
gamesrv_sendmode (bman.maxplayer, 1);
} else {
network_server_port (bman.servername, players[0].net.addr.host,
LEN_SERVERNAME, players[0].net.addr.port, LEN_PORT);
d_printf ("Connect To: %s[:%s]\n", players[0].net.addr.host,
players[0].net.addr.port);
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
players[0].net.addr.port[0] = players[0].net.addr.host[0] = 0;
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
if (bman.firewall)
i = NETF_firewall;
else
i = 0;
send_joingame (&players[0].net.addr, bman.playername);
}
return 0;
};
@ -188,12 +140,15 @@ network_shutdown ()
for (i = 1; i < MAX_PLAYERS; i++)
if (players[i].net.addr.host[0] != 0)
send_quit (&players[i].net.addr, NULL, NULL);
if (bman.notifygamemaster)
gamesrv_quit ();
}
else if (players[bman.p_servnr].net.addr.host[0] != 0)
send_quit (&players[bman.p_servnr].net.addr, NULL, NULL);
if (bman.notifygamemaster) {
ogc_sendgamequit (bman.sock);
ogc_shutdown ();
}
udp_close (bman.sock);
if (resend_cache.data != NULL)
@ -343,7 +298,7 @@ draw_netupdatestate ()
sprintf (text, "%s - State : READY", players[i].name);
else
sprintf (text, "%s - State : DOWNLOAD", players[i].name);
font_draw (70, y, text, 0);
font_draw (70, y, text, 0, 4);
text[0] = 0;
if (players[i].net.net_istep == 3)
@ -357,7 +312,7 @@ draw_netupdatestate ()
sprintf (text, "Getting Player Data %d of %d.", players[i].net.net_status,
MAX_PLAYERS);
font_draw (70, y + 32, text, 0);
font_draw (70, y + 32, text, 0, 4);
}
return;
}
@ -416,9 +371,9 @@ net_transmit_gamedata ()
draw_logo ();
if (GT_MP_PTPM)
font_draw (100, 0, "Waiting for the Clients", 1);
font_draw (100, 0, "Waiting for the Clients", 1, 0);
else
font_draw (100, 0, "Downloading Data", 1);
font_draw (100, 0, "Downloading Data", 1, 0);
SDL_Flip (gfx.screen);
@ -655,8 +610,7 @@ net_delplayer (int pl_nr)
{
char host[LEN_SERVERNAME];
char port[LEN_PORT];
int i,
j = 1;
int i;
d_printf ("net_delplayer (%d)\n", pl_nr);
bman.updatestatusbar = 1; // force an update
@ -678,12 +632,10 @@ net_delplayer (int pl_nr)
if (GT_MP_PTPM && (GS_WAITRUNNING || bman.state == GS_update)) {
for (i = 1; i < MAX_PLAYERS; i++)
if (!PS_IS_aiplayer (players[i].state) && PS_IS_netplayer (players[i].state)) {
if (!PS_IS_aiplayer (players[i].state) && PS_IS_netplayer (players[i].state))
send_quit (&players[i].net.addr, host, port);
j++;
}
if (bman.notifygamemaster)
gamesrv_sendmode (bman.maxplayer, j);
send_ogc_update ();
bman.updatestatusbar=1;
}
}
@ -692,7 +644,7 @@ net_delplayer (int pl_nr)
bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster)
gamesrv_sendmode (bman.maxplayer, bman.players_nr_s);
send_ogc_update ();
};
@ -719,8 +671,8 @@ net_send_servermode ()
if (!PS_IS_aiplayer (players[i].state) && PS_IS_netplayer (players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_servermode (&players[i].net.addr, i);
if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */
gamesrv_sendmode (bman.maxplayer, bman.players_nr_s);
if (bman.notifygamemaster && GT_MP_PTPM)
send_ogc_update ();
};
@ -750,9 +702,6 @@ net_send_chat (char *text, signed char notigamesrv)
for (i = 0; i < MAX_PLAYERS; i++)
if ((!PS_IS_aiplayer (players[i].state)) && PS_IS_netplayer (players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_chat (&players[i].net.addr, text);
if (GT_MP_PTPM && bman.notifygamemaster && notigamesrv == 1 && bman.broadcasted_chat) /* send notification the the gamemaster */
gamesrv_sendchat (text);
};
@ -828,3 +777,29 @@ net_send_mapinfo ()
if (!PS_IS_aiplayer (players[i].state) && PS_IS_netplayer (players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_mapinfo (&players[i].net.addr);
};
/* send an update about the game to all clients */
void send_ogc_update () {
int i, j;
char status[10];
if (!bman.notifygamemaster || GT_MP_PTPS)
return;
for (j = 0, i = 0; i < bman.maxplayer; i++)
if (PS_IS_used (players[i].state))
j++;
if (bman.state == GS_running)
sprintf (status, "running");
if (bman.state == GS_ready)
sprintf (status, "ready");
if (bman.state == GS_wait)
sprintf (status, "wait");
if (bman.state == GS_update)
sprintf (status, "update");
ogc_sendgamestatus (bman.sock, "BomberClone", VERSION, bman.gamename, j, bman.maxplayer, status);
};

@ -3,7 +3,6 @@
#include "basic.h"
#include "bomberclone.h"
#include "network.h"
#include "gamesrv.h"
#include "packets.h"
#include "chat.h"
#include "sound.h"
@ -62,7 +61,7 @@ int
do_error (struct pkg_error *data, _net_addr * addr)
{
d_printf ("Network Error : '%s'\n", data->text);
menu_displaymessage ("Network Error", data->text);
// menu_displaymessage ("Network Error", data->text);
if (data->nr == 1)
return -1;
else
@ -79,7 +78,6 @@ void
do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
_player *pl;
int i,
j,
vma,
vmi,
vsu;
@ -144,19 +142,11 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
send_mapinfo (addr);
addr->pl_nr = i;
for (j = 0, i = 0; i < bman.maxplayer; i++)
if (PS_IS_used (players[i].state))
j++;
if (bman.notifygamemaster)
gamesrv_sendmode (bman.maxplayer, j);
/* Send all connected players the new PlayerID */
for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && i != pl->net.addr.pl_nr && PS_IS_netplayer (players[i].state))
send_playerid (&players[i].net.addr, pl->name, pl->net.addr.host, pl->net.addr.port, pl->net.addr.pl_nr, pl->gfx_nr, pl->net.flags);
}
else if (GS_WAITRUNNING) {
@ -347,7 +337,7 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
/* the server changed */
if (bman.p_servnr != s_mod->p_servnr) {
menu_displaymessage ("Server Quit", "FIXME: Server Quit the game and code is not finished");
// menu_displaymessage ("Server Quit", "FIXME: Server Quit the game and code is not finished");
}
/* do the normal update */
@ -396,6 +386,7 @@ send_servermode (_net_addr * addr, int pl_nr)
};
/***
*** Packettype: field
***/
@ -1083,9 +1074,6 @@ do_chat (struct pkg_chat *chat_pkg, _net_addr * addr)
addr->port, addr->pl_nr, chat_pkg->text);
chat_addline (chat_pkg->text);
if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */
gamesrv_sendchat (chat_pkg->text);
};
@ -1175,23 +1163,6 @@ send_special (_net_addr * addr, int p_nr, int typ, int ex_nr)
};
/***
*** Packettype: bcmservchat
***/
void
do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr * addr)
{
packet->data[127] = 0;
if (strstr (packet->data, "BC:BC:") == packet->data)
return; // ignore packet
if (bman.notifygamemaster && bman.broadcasted_chat) {
chat_addline (packet->data);
net_send_chat (packet->data, 0);
}
};
/***
*** Packettype: mapinfo
***/
@ -1337,9 +1308,8 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
int
do_pkg (struct pkg *packet, _net_addr * addr)
{
if ((((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET)
|| ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET))
&& packet->h.typ != PKG_bcmservchat) {
if (((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET)
|| ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) {
d_printf ("do_pkg: packet comes from the wrong network type\n");
return 0;
}
@ -1349,11 +1319,11 @@ do_pkg (struct pkg *packet, _net_addr * addr)
players[addr->pl_nr].net.pingreq = players[addr->pl_nr].net.pingack + 5;
/* test if we have any important packet */
if (packet->h.flags & PKGF_ackreq && packet->h.typ != PKG_bcmservchat)
if (packet->h.flags & PKGF_ackreq)
send_pkgack (addr, packet->h.typ, NTOH16 (packet->h.id));
/* check the packet with the index */
if (packet->h.typ != PKG_bcmservchat && inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) {
if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) {
/* we have got this packet already */
d_printf ("do_pkg: double packet ignoring\n");
if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
@ -1419,9 +1389,6 @@ do_pkg (struct pkg *packet, _net_addr * addr)
case (PKG_playermove):
do_playermove ((struct pkg_playermove *) packet, addr);
break;
case (PKG_bcmservchat):
do_bcmservchat ((struct pkg_bcmservchat *) packet, addr);
break;
case (PKG_ill):
do_ill ((struct pkg_ill *) packet, addr);
break;

@ -1,8 +1,9 @@
/* $Id: single.c,v 1.50 2003/11/12 00:28:04 stpohle Exp $ */
/* $Id: single.c,v 1.51 2003/12/24 02:38:16 stpohle Exp $ */
/* single player */
#include "basic.h"
#include "bomberclone.h"
#include "menu.h"
void
single_game_new ()
@ -681,36 +682,48 @@ single_loop ()
void
single_menu ()
{
int menuselect = 0;
_menu menu[] = {
{1, "Start Game"},
{2, "Number Of Players"},
{3, "Map Option"},
{4, "Return To Main Menu"},
{-1, ""}
};
int menuselect = 0, i, p, done = 0;
_charlist nrplayerlist[MAX_PLAYERS+1];
_charlist *selnrplayer = &nrplayerlist[bman.ai_players];
/* fill in the nrplayerlist */
if (debug) p = 0; else p = 1;
for (i = 0; p < MAX_PLAYERS+1; i++) {
sprintf (nrplayerlist[i].text, "%d", p);
if (p < MAX_PLAYERS-1)
nrplayerlist[i].next = &nrplayerlist[i+1];
else
nrplayerlist[i].next = NULL;
p++;
}
while (!done && bman.state != GS_quit) {
menu_new ("Single Player", 300, 250);
menu_create_label ("Number Of AI Players", -1, 55, 0);
menu_create_list ("Players", -1, 80, 70, 70, nrplayerlist, &selnrplayer, 1);
menu_create_button ("Map Setting", -1, 180, 150, 2);
menu_create_button ("OK", -1, 220, 150, 0);
menuselect = menu_loop ();
menu_delete ();
/* read the current number of AI Players */
bman.ai_players = (selnrplayer - &nrplayerlist[0]);
if (!debug)
bman.ai_players++;
if (bman.ai_players > MAX_PLAYERS) {
d_fatal ("single_menu: bman.ai_players selection out of range (%d)\n", bman.ai_players);
bman.ai_players = 5;
}
while (menuselect != -1 && bman.state != GS_quit) {
sprintf (menu[1].text, "%d AI Player", bman.ai_players);
menuselect = menu_loop ("Single Player", menu, menuselect);
switch (menuselect) {
case (0): // Start Game
single_playergame ();
break;
case (1): // Change number of Player
bman.ai_players++;
if (bman.ai_players >= MAX_PLAYERS) {
if (debug)
bman.ai_players = 0; // null players with debugging on
else
bman.ai_players = 1;
}
break;
case (2): // Map Options
mapmenu ();
break;
case (3):
menuselect = -1;
case (-1):
done = 1;
break;
}
}
@ -740,7 +753,7 @@ single_select_player ()
Uint8 *keys;
Uint32 timeloop1;
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
// menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
dest.x = dest.y = 0;
dest.w = gfx.res.x;
@ -754,15 +767,9 @@ single_select_player ()
strcpy (text, "Select your Player");
x = (gfx.res.x - (font[2].size.x * strlen (text)) - 64) / 2;
y = (gfx.res.y - font[2].size.y - 64 - 128) / 2;
font_setcolor (128, 128, 0, 2);
font_draw (x - 2, y, text, 2);
font_draw (x + 2, y, text, 2);
font_draw (x, y - 2, text, 2);
font_draw (x, y + 2, text, 2);
font_setcolor (255, 255, 128, 2);
font_draw (x, y, text, 2);
gfx_blitupdaterectadd (&dest);
font_gfxdrawbold (x, y, text, 2, COLOR_gray, 3, 10000);
font_gfxdrawbold (x, y, text, 2, COLOR_brown, 2, 10000);
font_gfxdraw (x, y, text, 2, COLOR_yellow, 10000);
while (!done) {

@ -1,4 +1,4 @@
/* $Id: sound.c,v 1.5 2003/08/11 18:25:19 stpohle Exp $ */
/* $Id: sound.c,v 1.6 2003/12/24 02:38:16 stpohle Exp $ */
/* sound */
#include "sound.h"
@ -9,7 +9,7 @@ _snd snd;
/* display the sound options */
void
snd_options () {
int menuselect = 0;
/* int menuselect = 0;
_menu menu[] = {
{1, "Music Play"},
{1, "Sound Play"},
@ -40,7 +40,7 @@ snd_options () {
menuselect = -1;
break;
}
}
} */
};
@ -102,7 +102,10 @@ snd_init ()
void
snd_shutdown () {
#if HAVE_SDL_MIXER
if (snd.inited) {
snd.inited = 0;
Mix_CloseAudio ();
}
#endif
return;
};

@ -1,4 +1,4 @@
/* $Id: sysfunc.c,v 1.20 2003/11/09 16:35:10 stpohle Exp $
/* $Id: sysfunc.c,v 1.21 2003/12/24 02:38:16 stpohle Exp $
sysfunc.c - this file hold some routines for the system functions..
like d_delay
*/
@ -231,3 +231,86 @@ inline float rintf (float f) {
return (floorf (f + 1.0f));
};
#endif
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
while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < 20) {
s_delay (20 - (timeloop1 - timestamp) - 1);
timeloop1 = SDL_GetTicks ();
}
game_timediff1 = timeloop1 - timestamp;
timestamp = timeloop1;
timefactor = ((float)game_timediff1) / 20.0f;
timediff = ((float)game_timediff1) / 1000.0f;
}
/* clipping of a rectangle before blitting
* src - Source Image
* dest - Destination Image
* window - Window in the Destination
*/
void rect_clipping (SDL_Rect *src, SDL_Rect *dest, SDL_Rect *window, SDL_Rect *csrc, SDL_Rect *cdest) {
/* X - Position */
if (dest->x > window->x)
cdest->x = dest->x;
else
cdest->x = window->x;
if ((dest->x + dest->w)<(window->x + window->w))
cdest->w = (dest->x + dest->w) - cdest->x;
else
cdest->w = (window->x + window->w) - cdest->x;
/* X - Position */
if (dest->y > window->y)
cdest->y = dest->y;
else
cdest->y = window->y;
if ((dest->y + dest->h)<(window->y + window->h))
cdest->h = (dest->y + dest->h) - cdest->y;
else
cdest->h = (window->y + window->h) - cdest->y;
/* setup the clipping source */
csrc->x = src->x + (cdest->x - dest->x);
csrc->w = cdest->w;
csrc->y = src->y + (cdest->y - dest->y);
csrc->h = cdest->h;
};
/* fills the list->next pointer with the next element
* as it would be with an array */
void charlist_fillarraypointer (_charlist *list, int c) {
int i = 0;
if (c <= 0) return;
do {
if (i < c - 1)
list[i].next = &list[i+1];
else
list[i].next = NULL;
i++;
} while (i < c);
};
/* find the text in the list */
_charlist *charlist_findtext (_charlist *list, char *text) {
_charlist *result;
for (result = list; result != NULL && (strncmp (result->text, text, 255) != 0); result = result->next);
return result;
};

Loading…
Cancel
Save