Added Second Local Player, new menuhandling...

origin
stpohle 22 years ago
parent c618b51876
commit 0162f65725

@ -1,8 +1,35 @@
$Id: ChangeLog,v 1.74 2004/04/03 13:55:28 stpohle Exp $ $Id: ChangeLog,v 1.75 2004/05/20 16:55:29 stpohle Exp $
- WORKING ON: userdefined keyboad settings. read the file Still Needed to Change
src/keyb.c for the current keyboard settings. Config ======================
screen still not finished. * ingame menus, like the "Quit Game" question.
Version 0.11.3
==============
2004-05-20
- menuhandling changed some internal things,
so it is possible to create more menus at the time.
it is possible to write own menuloops.
(this is used in the new playerselection screen and
playermenu screen.)
- new playerselectionscreen, needed because of the second
local player.
- password protection for own games so they can be
listed, on the OGC but only people with the password
will be able to join.
- userdefined keyboad settings. read the file
src/keyb.c for the current keyboard settings.
- Added: the server can now kick players from the game
- Added: programm parameters for automatic joining/hosting
a game, using ogc, port configuation and debug mode.
for more informations use the parameter "-help".
- Fixed: respawning of the player will continue and - Fixed: respawning of the player will continue and
finish when we go into Hurry Mode. finish when we go into Hurry Mode.

@ -1,4 +1,4 @@
# Anjuta Version 1.2.0 # Anjuta Version 1.2.2
Compatibility Level: 1 Compatibility Level: 1
<PROJECT_DESCRIPTION_START> <PROJECT_DESCRIPTION_START>
@ -39,13 +39,13 @@ echo "T $target H $host B $buid" >cross-target.txt
props.file.type=project props.file.type=project
anjuta.version=1.2.0 anjuta.version=1.2.2
anjuta.compatibility.level=1 anjuta.compatibility.level=1
project.name=bomberclone project.name=bomberclone
project.type=GENERIC project.type=GENERIC
project.target.type=EXECUTABLE project.target.type=EXECUTABLE
project.version=0.11.2 project.version=0.11.3
project.author=steffen project.author=steffen
project.source.target=bomberclone project.source.target=bomberclone
project.has.gettext=0 project.has.gettext=0

@ -5,7 +5,7 @@ dnl Please disable it in the Anjuta project configuration
AC_INIT(configure.in) AC_INIT(configure.in)
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(bomberclone, 0.11.2) AM_INIT_AUTOMAKE(bomberclone, 0.11.3)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
@ -242,4 +242,5 @@ Makefile
src/Makefile src/Makefile
include/Makefile include/Makefile
data/Makefile data/Makefile
data/pixmaps/Makefile
]) ])

@ -4,6 +4,8 @@
## If you don't want it to overwrite it, ## If you don't want it to overwrite it,
## Please disable it in the Anjuta project configuration ## Please disable it in the Anjuta project configuration
SUBDIRS = pixmaps
install: install:
@if test ! -d player; then \ @if test ! -d player; then \
echo ""; \ echo ""; \

@ -0,0 +1,3 @@
Makefile
Makefile.in

@ -0,0 +1,12 @@
## Process this file with automake to produce Makefile.in
## Created by Anjuta - will be overwritten
## If you don't want it to overwrite it,
## Please disable it in the Anjuta project configuration
bomberclone_pixmapsdir = $(prefix)/@NO_PREFIX_PACKAGE_PIXMAPS_DIR@
bomberclone_pixmaps_DATA = \
bomberclone.png
EXTRA_DIST = $(bomberclone_pixmaps_DATA)

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.22 2004/04/03 14:48:42 stpohle Exp $ */ /* $Id: basic.h,v 1.23 2004/05/20 16:55:30 stpohle Exp $ */
/* basic types which we need everywhere */ /* basic types which we need everywhere */
#ifndef _BC_BASIC_H_ #ifndef _BC_BASIC_H_
@ -67,6 +67,7 @@
#define LEN_FILENAME 64 #define LEN_FILENAME 64
#define LEN_TILESETNAME 32 #define LEN_TILESETNAME 32
#define LEN_CHARENTRY 256 #define LEN_CHARENTRY 256
#define LEN_PASSWORD 16
#define DEFAULT_UDPPORT 11000 #define DEFAULT_UDPPORT 11000
#define DEFAULT_GAMECACHEPORT "11111" #define DEFAULT_GAMECACHEPORT "11111"

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.25 2004/04/03 14:48:42 stpohle Exp $ */ /* $Id: bomberclone.h,v 1.26 2004/05/20 16:55:30 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_
@ -66,6 +66,7 @@ struct {
int init_timeout; // gametimeout init value int init_timeout; // gametimeout init value
float timeout; // game timeout float timeout; // game timeout
char playername[LEN_PLAYERNAME]; char playername[LEN_PLAYERNAME];
char player2name[LEN_PLAYERNAME];
int players_nr_s; // number of players at the beginning int players_nr_s; // number of players at the beginning
int players_nr; // number of player who are alife int players_nr; // number of player who are alife
signed char lastwinner; // number of the last winnet signed char lastwinner; // number of the last winnet
@ -78,6 +79,8 @@ struct {
char servername[LEN_SERVERNAME + LEN_PORT + 2]; // holds the name of the current server char servername[LEN_SERVERNAME + LEN_PORT + 2]; // holds the name of the current server
char gamename[LEN_GAMENAME]; // this will hold the game name char gamename[LEN_GAMENAME]; // this will hold the game name
char ogcserver[LEN_SERVERNAME+LEN_PORT+2]; char ogcserver[LEN_SERVERNAME+LEN_PORT+2];
char password[LEN_PASSWORD]; // password for the game
int passwordenabled; // if the server use the password
char ogc_port[LEN_PORT]; char ogc_port[LEN_PORT];
int firewall; int firewall;
int notifygamemaster; int notifygamemaster;
@ -137,6 +140,7 @@ extern void config_menu ();
extern int config_read(); extern int config_read();
extern int config_write(); extern int config_write();
extern void ReadPrgArgs (int argc, char **argv); extern void ReadPrgArgs (int argc, char **argv);
extern void ReadPrgArgs_Jump (int argc, char **argv);
// debug.c // debug.c
extern void d_in_pl_detail (char *head); extern void d_in_pl_detail (char *head);

@ -15,7 +15,7 @@ struct __chat {
SDL_Surface *oldscreen; SDL_Surface *oldscreen;
short int startline; short int startline;
short int lastline; short int lastline;
short int active; // if we are in chat mode short int active;
struct { struct {
char text[255]; char text[255];
int status; int status;

@ -4,6 +4,8 @@
#ifndef _KEYB_H_ #ifndef _KEYB_H_
#define _KEYB_H_ #define _KEYB_H_
#include "menu.h"
enum _bcplayerkeys { enum _bcplayerkeys {
BCPK_up = 0, BCPK_up = 0,
BCPK_down, BCPK_down,
@ -37,10 +39,9 @@ extern BCGameKeys keyb_gamekeys;
extern void keyb_config (); extern void keyb_config ();
extern void keyb_config_reset (); extern void keyb_config_reset ();
extern void keyb_config_createkeymenu (int key, int x, int y, int menu_nr); extern void keyb_config_createkeymenu (_menu *menu, int key, int x, int y, int menu_nr);
extern void keyb_config_readkey (int key); extern void keyb_config_readkey (int key);
extern void keyb_init (); extern void keyb_init ();
extern void keyb_loop (SDL_Event *event); extern void keyb_loop (SDL_Event *event);
#endif #endif

@ -1,4 +1,4 @@
/* $Id: menu.h,v 1.9 2004/02/07 15:03:24 stpohle Exp $ /* $Id: menu.h,v 1.10 2004/05/20 16:55:30 stpohle Exp $
* GUI for menuhandling * GUI for menuhandling
*/ */
@ -14,11 +14,12 @@
#define MENU_BUTTON_FONTSIZE 0 #define MENU_BUTTON_FONTSIZE 0
#define MENU_FOCUSVIS_BLINKTO 0.25f #define MENU_FOCUSVIS_BLINKTO 0.25f
#define MENU_DATAENTRYLEN 128 #define MENU_DATAENTRYLEN 128
#define MENUOFFSET_X menu.oldscreenpos.x + menu.images[0]->w #define MENUOFFSET_X(_m_) _m_->oldscreenpos.x + menuimages[0]->w
#define MENUOFFSET_Y menu.oldscreenpos.y + menu.images[0]->h #define MENUOFFSET_Y(_m_) _m_->oldscreenpos.y + menuimages[0]->h
enum _menu_type { enum _menu_type {
MENU_label = 0, MENU_label = 0,
MENU_none, /* deleted item */
MENU_button, MENU_button,
MENU_entrytext, MENU_entrytext,
MENU_entryint32, MENU_entryint32,
@ -42,7 +43,7 @@ struct __menuitem {
char *ptrdata; // pointer to some data char *ptrdata; // pointer to some data
SDL_Rect rect; // only used for images SDL_Rect rect; // only used for images
_charlist *list; _charlist *list;
void *menu; // parent menu
struct __menuitem *next; struct __menuitem *next;
} typedef _menuitem; } typedef _menuitem;
@ -53,42 +54,49 @@ struct {
_menuitem *focus; _menuitem *focus;
SDL_Surface *oldscreen; // hold old screendata SDL_Surface *oldscreen; // hold old screendata
SDL_Rect oldscreenpos; SDL_Rect oldscreenpos;
SDL_Surface *images[9]; // holds the gfx
SDL_Surface *listimages[2][9]; // holds the gfx for the lists
SDL_Surface *buttonimages[3][3]; // holds the images for the buttons
SDL_Surface *entryimages[2][3]; // [PRESSED][Left|Center|Right]
float focusto; float focusto;
int focusvis; int focusvis;
_menuitem menuitems[MENU_MAXENTRYS];
int looprunning;
} typedef _menu; } typedef _menu;
extern _menu menu;
extern SDL_Surface *menuimages[9]; // holds the gfx
extern SDL_Surface *menulistimages[2][9]; // holds the gfx for the lists
extern SDL_Surface *menubuttonimages[3][3]; // holds the images for the buttons
extern SDL_Surface *menuentryimages[2][3]; // [PRESSED][Left|Center|Right]
extern _menu *menu_new (char *title, int x, int y);
extern void menu_delete (_menu *menu);
extern int menu_getlastitem (_menuitem *first); extern int menu_getlastitem (_menuitem *first);
extern void menu_new (char *title, int x, int y); extern _menuitem *menuitem_findfree (_menu *menu);
extern void menu_delete (); extern _menuitem *menu_create_list (_menu *menu, char *name, int x, int y, int w, int h, _charlist *data, _charlist **selected, int id);
extern void menu_create_list (char *name, int x, int y, int w, int h, _charlist *data, _charlist **selected, int id); extern _menuitem *menu_create_entry (_menu *menu, char *name, int x, int y, int w, void *data, int len, int typ, int id);
extern void menu_create_entry (char *name, int x, int y, int w, void *data, int len, int typ, int id); extern _menuitem *menu_create_label (_menu *menu, char *name, int x, int y, int fontsize, int fontcolor);
extern void menu_create_label (char *name, int x, int y, int fontsize, int fontcolor); extern void menu_create_text (_menu *menu, char *name, int x, int y, int maxlen, int maxlines, int fontcolor, char *fmt,...);
extern void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, int fontcolor, char *fmt,...); extern _menuitem *menu_create_button (_menu *menu, char *name, int x, int y, int w, int id);
extern void menu_create_button (char *name, int x, int y, int w, int id); extern _menuitem *menu_create_bool (_menu *menu, char *name, int x, int y, int w, int *data, int id);
extern void menu_create_bool (char *name, int x, int y, int w, int *data, int id); extern _menuitem *menu_create_image (_menu *menu, char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect);
extern void menu_create_image (char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect); extern int menu_loop (_menu *menu);
extern int menu_loop (); extern int menu_event_loop (_menu *menu, SDL_Event *event, int eventstate);
extern void menu_draw_border (); extern void menu_draw (_menu *menu);
extern void menu_draw_background (SDL_Rect *dest); extern void menu_draw_border (_menu *menu);
extern void menu_draw_background (_menu *menu, SDL_Rect *dest);
extern inline void menu_draw_menuitem (_menuitem *m); extern inline void menu_draw_menuitem (_menuitem *m);
extern void menu_reload (); extern void menu_reload (_menu *menu);
extern inline void menu_reload_menuitem (_menuitem *m); extern inline void menu_reload_menuitem (_menuitem *m);
extern void menu_focus_next (); extern void menu_focus_next (_menu *menu);
extern void menu_focus_prev (); extern void menu_focus_prev (_menu *menu);
extern void menu_focus_id (int id); extern void menu_focus_id (_menu *menu, int id);
extern void menu_change_focus (_menuitem *newfocus); extern void menu_change_focus (_menuitem *newfocus);
extern _menuitem *menu_get_lastid (); extern _menuitem *menu_get_lastid (_menu *menu);
extern _menuitem *menu_get_firstid (); extern _menuitem *menu_get_firstid (_menu *menu);
extern int menu_create_dirlist (char *path, signed char dirflags, _charlist *cl, int maxentry); extern int menu_create_dirlist (char *path, signed char dirflags, _charlist *cl, int maxentry);
extern char *menu_dir_select (char *title, char *path, signed char dirflags); extern char *menu_dir_select (char *title, char *path, signed char dirflags);
extern void menu_displaymessage (char *title, char *fmt,...); extern void menu_displaymessage (char *title, char *fmt,...);
extern void menu_displaytext (char *title, char *fmt,...); extern void menu_displaytext (char *title, char *fmt,...);
extern void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars, int max_lines); extern void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars, int max_lines);
extern void menu_drawborder (int x, int y, int w, int h);
#endif #endif

@ -1,4 +1,4 @@
/* $Id: network.h,v 1.18 2004/02/11 21:45:06 stpohle Exp $ /* $Id: network.h,v 1.19 2004/05/20 16:55:30 stpohle Exp $
* network.h file... for everything what have to do with the network stuff * network.h file... for everything what have to do with the network stuff
*/ */
@ -52,7 +52,8 @@
#include "udp.h" #include "udp.h"
enum _networkflags { enum _networkflags {
NETF_firewall = 1 NETF_firewall = 1, // User Behind Firewall
NETF_local2 // Lokaler 2 Player
}; };
@ -65,7 +66,7 @@ struct { // this holds the network data
struct { /* this will hold all needed data for the packet struct { /* this will hold all needed data for the packet
timeout function */ timeout function */
signed char send_to; // sending packet data (playermove) on 0 it will be send signed char send_to; // sending packet data (playermove) on 0 it will be send
signed char send_set; // start value for the packet data option (dynamic set) signed char send_set; // start value for the packet data option (dynamic set)
int to_2sec; // how many unreached packets was send int to_2sec; // how many unreached packets was send
@ -74,14 +75,15 @@ struct { /* this will hold all needed data for the packet
struct { struct {
_net_addr addr; // holds the address _net_addr addr; // holds the address
int pingreq; // just to send a ping and to save the number in here int pingreq; // just to send a ping and to save the number in here
int pingack; // just to wait for an ping reply.. it will show up here int pingack; // just to wait for an ping reply.. it will show up here
Uint32 timestamp; // time of the last incoming package Uint32 timestamp; // time of the last incoming package
signed char net_istep; signed char net_istep;
signed char net_status; signed char net_status;
unsigned char flags; // keep some flags.. like NETF_firewall unsigned char flags; // keep some flags.. like NETF_firewall
_net_pkgopt pkgopt; // packet and network controll data int firstplayer; // number of the first player (only needed if NETF_local2 is set
_net_pkgopt pkgopt; // packet and network controll data
} typedef _net_player; } typedef _net_player;
@ -111,7 +113,7 @@ extern void net_game_send_dropitems (int pl_nr, _flyingitem **fiptr, int cnt);
extern void net_game_send_respawn (int pl_nr); extern void net_game_send_respawn (int pl_nr);
extern void net_game_fillsockaddr (); extern void net_game_fillsockaddr ();
extern void net_game_send_ill (int p_nr); extern void net_game_send_ill (int p_nr);
extern void net_delplayer (int pl_nr); extern void net_game_send_delplayer (int pl_nr);
extern void draw_netupdatestate (char st); extern void draw_netupdatestate (char st);
extern void net_send_servermode (); extern void net_send_servermode ();
extern void net_send_players (); extern void net_send_players ();
@ -126,7 +128,7 @@ extern void send_ogc_update ();
extern void wait_for_players (); extern void wait_for_players ();
extern void mw_init (); extern void mw_init ();
extern void mw_shutdown (); extern void mw_shutdown ();
extern void mw_draw_gfxselect (int selgfx); extern void mw_draw_gfxselect (int pl_nr, int selgfx);
extern void mw_draw_status (); extern void mw_draw_status ();
extern void mw_wait_for_connect (); extern void mw_wait_for_connect ();
extern void mw_draw_chat (); extern void mw_draw_chat ();
@ -136,6 +138,12 @@ extern void net_getserver ();
extern void srvlist_rebuildlist (); extern void srvlist_rebuildlist ();
/* check if we can send to the player */ /* check if we can send to the player */
#define NET_CANSEND(__pl) ( GT_MP_PTPM || __pl == bman.p_servnr || (((players[__pl].net.flags & NETF_firewall) == 0) && !bman.firewall)) #define NET_CANSEND(__pl) (!PS_IS_aiplayer (players[__pl].state) \
&& PS_IS_netplayer (players[__pl].state) \
&& __pl != bman.p_nr && __pl != bman.p2_nr \
&& (players[__pl].net.flags & NETF_local2) == 0 \
&& ( GT_MP_PTPM || __pl == bman.p_servnr \
|| (((players[__pl].net.flags & NETF_firewall) == 0) \
&& !bman.firewall)))
#endif #endif

@ -1,4 +1,4 @@
/* $Id: packets.h,v 1.23 2004/04/03 14:48:42 stpohle Exp $ /* $Id: packets.h,v 1.24 2004/05/20 16:55:30 stpohle Exp $
* network packets.. */ * network packets.. */
#ifndef _PACKETS_H_ #ifndef _PACKETS_H_
@ -140,9 +140,10 @@ struct pkg_servermode {
signed char fieldsize_y; signed char fieldsize_y;
char tileset[LEN_TILESETNAME]; char tileset[LEN_TILESETNAME];
signed char p_servnr; signed char p_servnr;
signed char p_nr; /* if the server sends this to a client... signed char lplayer2; /* indicates that we mean local player 2 */
it will be the clients in_nr number signed char p_nr; /* if the server sends this to a client...
(-1) for not set */ it will be the clients in_nr number
(-1) for not set */
}; };
@ -153,6 +154,7 @@ struct pkg_joingame {
signed char ver_sub; // Version signed char ver_sub; // Version
signed char netflags; signed char netflags;
char name[LEN_PLAYERNAME]; char name[LEN_PLAYERNAME];
char password[LEN_PASSWORD];
}; };
@ -215,8 +217,7 @@ struct pkg_bombdata {
struct pkg_quit { struct pkg_quit {
struct pkgheader h; struct pkgheader h;
char host[LEN_SERVERNAME]; signed char pl_nr;
char port[LEN_PORT];
}; };
@ -359,14 +360,14 @@ extern void do_respawn (struct pkg_respawn *r_pkg, _net_addr *addr);
extern void send_pkg (struct pkg *packet, _net_addr *addr); extern void send_pkg (struct pkg *packet, _net_addr *addr);
extern void send_playerid (_net_addr *addr, char *name, char *pladdr, char *plport, int p_nr, int gfx_nr, signed char netflags); extern void send_playerid (_net_addr *addr, char *name, char *pladdr, char *plport, int p_nr, int gfx_nr, signed char netflags);
extern void send_servermode (_net_addr *addr, int pl_nr); extern void send_servermode (_net_addr *addr, int pl_nr);
extern void send_joingame (_net_addr * addr, char *name); extern void send_joingame (_net_addr * addr, char *name, int flags);
extern void send_error (_net_addr *addr, char *text); extern void send_error (_net_addr *addr, char *text);
extern void send_field (_net_addr *addr, int x, int y, _field * field); extern void send_field (_net_addr *addr, int x, int y, _field * field);
extern void send_ping (_net_addr *addr, int data, unsigned char typ); extern void send_ping (_net_addr *addr, int data, unsigned char typ);
extern void send_playerdata (_net_addr *addr, int p_nr, _player * pl); extern void send_playerdata (_net_addr *addr, int p_nr, _player * pl);
extern void send_playermove (_net_addr *addr, int p_nr, _player * pl); extern void send_playermove (_net_addr *addr, int p_nr, _player * pl);
extern void send_bombdata (_net_addr *addr, int p, int b, _bomb * bomb); extern void send_bombdata (_net_addr *addr, int p, int b, _bomb * bomb);
extern void send_quit (_net_addr *addr, char *plhost, char *plport); extern void send_quit (_net_addr *addr, int pl_nr);
extern void send_getfield (_net_addr *addr, int line); extern void send_getfield (_net_addr *addr, int line);
extern void send_fieldline (_net_addr *addr, int line); extern void send_fieldline (_net_addr *addr, int line);
extern void send_getplayerdata (_net_addr *addr, int pl); extern void send_getplayerdata (_net_addr *addr, int pl);

@ -1,4 +1,4 @@
/* $Id: player.h,v 1.1 2004/04/03 14:48:42 stpohle Exp $ /* $Id: player.h,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* playerinclude file * playerinclude file
*/ */
@ -134,6 +134,11 @@ extern int player_findfreebomb (_player *player);
extern int player_checkpos (int x, int y); extern int player_checkpos (int x, int y);
extern void player_checkdeath (int pnr); extern void player_checkdeath (int pnr);
extern void player_check (int pl_nr); extern void player_check (int pl_nr);
extern void player_delete (int pl_nr);
extern void player2_join ();
extern void player2_add (int pl_nr);
// for the playerinput handling // for the playerinput handling
extern void playerinput_loop (int pl_nr); extern void playerinput_loop (int pl_nr);
@ -141,6 +146,6 @@ extern void playerinput_keyb_loop (int pl_nr);
extern inline void playerinput_keyb_read (int pk_offset, int pl_nr); extern inline void playerinput_keyb_read (int pk_offset, int pl_nr);
/* playermenu.c */ /* playermenu.c */
extern void player_menu (); extern void playermenu ();
extern void playermenu_selgfx (int pl_nr);
#endif #endif

@ -1,10 +1,9 @@
/* $Id: single.h,v 1.1 2004/04/03 14:48:42 stpohle Exp $ /* $Id: single.h,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* single player */ * single player */
// single.c // single.c
extern void single_game_new (); extern void single_game_new ();
extern void single_create_ai (int num_players); extern void single_create_ai (int num_players);
extern void single_delete_ai (int num_players);
extern void single_loop(); extern void single_loop();
extern void single_playergame (); extern void single_playergame ();
extern void single_menu (); extern void single_menu ();

@ -1,4 +1,4 @@
/* $Id: bomb.c,v 1.56 2004/04/03 14:48:42 stpohle Exp $ */ /* $Id: bomb.c,v 1.57 2004/05/20 16:55:30 stpohle Exp $ */
/* everything what have to do with the bombs */ /* everything what have to do with the bombs */
#include "bomberclone.h" #include "bomberclone.h"
@ -423,7 +423,8 @@ int explosion_check_field (int x, int y, _bomb *bomb)
for (i = 0; pl[i] != -1; i++) { for (i = 0; pl[i] != -1; i++) {
tmpplayer = &players[pl[i]]; tmpplayer = &players[pl[i]];
if (((tmpplayer->state & PSF_alife) != 0) if (((tmpplayer->state & PSF_alife) != 0)
&& (GT_SP || (GT_MP && (&players[bman.p_nr] == tmpplayer)) && (GT_SP
|| (GT_MP && (&players[bman.p_nr] == tmpplayer || (IS_LPLAYER2 && &players[bman.p2_nr] == tmpplayer)))
|| (GT_MP_PTPM && PS_IS_aiplayer (tmpplayer->state)))) || (GT_MP_PTPM && PS_IS_aiplayer (tmpplayer->state))))
player_died (tmpplayer, bomb->id.p); player_died (tmpplayer, bomb->id.p);
} }

@ -30,6 +30,7 @@ chat_findfreeline ()
return i; return i;
} }
void void
chat_cleanup () chat_cleanup ()
{ {
@ -40,6 +41,9 @@ chat_cleanup ()
} }
} }
/*
* add a new line to the chat
*/
void void
chat_addline (char *text) chat_addline (char *text)
{ {
@ -51,6 +55,10 @@ chat_addline (char *text)
chat.lineschanged = 1; chat.lineschanged = 1;
} }
/*
* add a new line to the chat
*/
void void
chat_addstatusline (char *text) chat_addstatusline (char *text)
{ {
@ -61,6 +69,7 @@ chat_addstatusline (char *text)
chat.lineschanged = 1; chat.lineschanged = 1;
} }
void void
chat_drawbox () chat_drawbox ()
{ {
@ -99,6 +108,9 @@ chat_drawbox ()
}; };
/*
*
*/
void void
chat_deletebox () chat_deletebox ()
{ {
@ -122,6 +134,10 @@ chat_deletebox ()
}; };
/*
* set a new position for the chat window,
* or delete the chat windows if it's out of range
*/
void void
chat_show (int x1, int y1, int x2, int y2) chat_show (int x1, int y1, int x2, int y2)
{ {
@ -142,6 +158,9 @@ chat_show (int x1, int y1, int x2, int y2)
}; };
/*
* redraw the empty chat box
*/
void void
chat_clearscreen (signed char all) chat_clearscreen (signed char all)
{ {
@ -163,7 +182,7 @@ chat_clearscreen (signed char all)
else { else {
/* redraw only the textline of out input box */ /* redraw only the textline of out input box */
dest.x = chat.window.x + 2; dest.x = chat.window.x + 2;
dest.y = chat.window.y + chat.window.h - 18; dest.y = chat.window.y + chat.window.h - 17;
dest.w = src.w = chat.window.w - 4; dest.w = src.w = chat.window.w - 4;
dest.h = src.h = font[0].size.y; dest.h = src.h = font[0].size.y;
@ -183,10 +202,16 @@ chat_clearscreen (signed char all)
src.y = chat.window.y + chat.window.h - 18; src.y = chat.window.y + chat.window.h - 18;
src.w = src.x + chat.window.w - 4; src.w = src.x + chat.window.w - 4;
src.h = src.y + font[0].size.y; src.h = src.y + font[0].size.y;
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1); if (chat.active)
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK << 1);
else
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1);
}; };
/*
* loop through the chat and draw it
*/
void void
chat_loop (SDL_Event * event) chat_loop (SDL_Event * event)
{ {
@ -199,7 +224,12 @@ chat_loop (SDL_Event * event)
char text[255]; char text[255];
if (chat.active) { /* the chat mode is active */ if (chat.active) { /* the chat mode is active */
i = keybinput_loop (&chat.input, event); if (event != NULL)
i = keybinput_loop (&chat.input, event);
else {
i = 0;
chat.input.changed = 1;
}
if (i == 1 && chat.input.text[0] != 0) { if (i == 1 && chat.input.text[0] != 0) {
sprintf (text, "%s: %s", bman.playername, chat.input.text); sprintf (text, "%s: %s", bman.playername, chat.input.text);
@ -207,11 +237,14 @@ chat_loop (SDL_Event * event)
chat_addline (text); chat_addline (text);
keybinput_new (&chat.input, KEYBI_text, 255); keybinput_new (&chat.input, KEYBI_text, 255);
i = 0; i = 0;
chat.active = 0; chat.active = 0; // to let everything redraw
} }
} }
else i = 0; else i = 0;
/*
* draw everything again if it's need to
*/
if (((i == 0 && chat.input.changed == 1) || chat.changed == 1) && chat.visible == 1) { if (((i == 0 && chat.input.changed == 1) || chat.changed == 1) && chat.visible == 1) {
/* draw the new field */ /* draw the new field */
chat_clearscreen (chat.lineschanged); chat_clearscreen (chat.lineschanged);

@ -1,4 +1,4 @@
/* $Id: configuration.c,v 1.55 2004/04/05 14:10:50 stpohle Exp $ /* $Id: configuration.c,v 1.56 2004/05/20 16:55:30 stpohle Exp $
* configuration */ * configuration */
#include <SDL.h> #include <SDL.h>
@ -17,6 +17,8 @@
void void
config_init (int argc, char **argv) config_init (int argc, char **argv)
{ {
SDL_Surface *icon_img;
char text[255], icon[255];
int i; int i;
srand (((int) time (NULL))); // initialize randomgenerator srand (((int) time (NULL))); // initialize randomgenerator
@ -26,8 +28,6 @@ config_init (int argc, char **argv)
players[i].gfx_nr = -1; /* and even now in the singleplayer menu */ players[i].gfx_nr = -1; /* and even now in the singleplayer menu */
} }
menu.oldscreen = NULL;
stonelist_del (); stonelist_del ();
chat.visible = 0; chat.visible = 0;
chat.startline = 0; chat.startline = 0;
@ -40,6 +40,8 @@ config_init (int argc, char **argv)
bman.maxplayer = MAX_PLAYERS; bman.maxplayer = MAX_PLAYERS;
bman.net_ai_family = PF_INET; bman.net_ai_family = PF_INET;
bman.sock = -1; bman.sock = -1;
bman.p_nr = -1;
bman.p2_nr = -1;
bman.gamename[0] = 0; bman.gamename[0] = 0;
sprintf (bman.port, "%d", DEFAULT_UDPPORT); sprintf (bman.port, "%d", DEFAULT_UDPPORT);
sprintf (bman.ogcserver, DEFAULT_GAMECACHE); sprintf (bman.ogcserver, DEFAULT_GAMECACHE);
@ -52,6 +54,8 @@ config_init (int argc, char **argv)
gfx.res.x = 640; gfx.res.x = 640;
gfx.res.y = 480; gfx.res.y = 480;
gfx.bpp = 16; gfx.bpp = 16;
bman.password[0] = 0;
bman.passwordenabled = 0;
map.tileset[0] = 0; map.tileset[0] = 0;
map.random_tileset = 1; map.random_tileset = 1;
map.size.x = 25; map.size.x = 25;
@ -91,19 +95,36 @@ config_init (int argc, char **argv)
draw_logo (); draw_logo ();
bman.playername[LEN_PLAYERNAME - 1] = 0; bman.playername[LEN_PLAYERNAME - 1] = 0;
bman.playername[0] = 0; bman.playername[0] = 0;
player_menu (); playermenu ();
} }
else { else {
ReadPrgArgs (argc, argv); ReadPrgArgs (argc, argv);
gfx_init (); gfx_init ();
draw_logo (); draw_logo ();
if (bman.askplayername) if (bman.askplayername)
player_menu (); playermenu ();
} }
snd_init (); snd_init ();
gfx_blitdraw (); gfx_blitdraw ();
SDL_Flip (gfx.screen); SDL_Flip (gfx.screen);
sprintf (text,"Bomberclone %s", VERSION);
sprintf (icon,"%s/pixmaps/bomberclone.png", bman.datapath);
SDL_WM_SetCaption(text , NULL);
icon_img = IMG_Load(icon);
if (icon_img == NULL)
d_printf ("could not load icon. (%s)\n", icon);
#ifdef _WIN32
{
SDL_Surface *tmp = icon_img;
icon_img = scale_image (tmp, 32, 32);
SDL_FreeSurface (tmp);
}
#endif
SDL_WM_SetIcon (icon_img, NULL);
ReadPrgArgs_Jump (argc, argv);
}; };
@ -170,6 +191,16 @@ config_read ()
strcpy (bman.playername, value); strcpy (bman.playername, value);
} }
if (!strcmp (keyword, "player2name")) {
if (strlen (value) > LEN_PLAYERNAME) {
d_printf
("*** Error - playername too long (maximum size permitted is %d characters)!\n\n",
LEN_PLAYERNAME);
}
value[LEN_PLAYERNAME - 1] = 0;
strcpy (bman.player2name, value);
}
if (!strcmp (keyword, "gamename")) { if (!strcmp (keyword, "gamename")) {
if (strlen (value) > LEN_GAMENAME) { if (strlen (value) > LEN_GAMENAME) {
d_printf d_printf
@ -182,6 +213,18 @@ config_read ()
if (!strcmp (keyword, "askplayername")) { if (!strcmp (keyword, "askplayername")) {
bman.askplayername = atoi (value); bman.askplayername = atoi (value);
} }
if (!strcmp (keyword, "password")) {
if (strlen (value) > LEN_PASSWORD) {
d_printf
("*** Error - Password is too long (maximum size permitted is %d characters)!\n\n",
LEN_PASSWORD);
}
value[LEN_PASSWORD - 1] = 0;
strcpy (bman.password, value);
}
if (!strcmp (keyword, "passwordenabled")) {
bman.passwordenabled = atoi (value);
}
if (!strcmp (keyword, "resolutionx")) { if (!strcmp (keyword, "resolutionx")) {
gfx.res.x = atoi (value); gfx.res.x = atoi (value);
} }
@ -367,8 +410,11 @@ config_write ()
fprintf (config, "gametype=%d\n", bman.gametype); fprintf (config, "gametype=%d\n", bman.gametype);
fprintf (config, "maxplayer=%d\n", bman.maxplayer); fprintf (config, "maxplayer=%d\n", bman.maxplayer);
fprintf (config, "debug=%d\n", debug); fprintf (config, "debug=%d\n", debug);
fprintf (config, "password=%s\n", bman.password);
fprintf (config, "passwordenabled=%d\n", bman.passwordenabled);
fprintf (config, "askplayername=%d\n", bman.askplayername); fprintf (config, "askplayername=%d\n", bman.askplayername);
fprintf (config, "playername=%s\n", bman.playername); fprintf (config, "playername=%s\n", bman.playername);
fprintf (config, "player2name=%s\n", bman.player2name);
fprintf (config, "bitsperpixel=%d\n", gfx.bpp); fprintf (config, "bitsperpixel=%d\n", gfx.bpp);
fprintf (config, "randomtileset=%d\n", map.random_tileset); fprintf (config, "randomtileset=%d\n", map.random_tileset);
fprintf (config, "mapselection=%d\n", map.map_selection); fprintf (config, "mapselection=%d\n", map.map_selection);
@ -433,6 +479,8 @@ config_video ()
_charlist *selbpp = NULL; _charlist *selbpp = NULL;
char text[100]; char text[100];
_menu *menu;
/* set all pointers in this array */ /* set all pointers in this array */
charlist_fillarraypointer (screenres, 4); charlist_fillarraypointer (screenres, 4);
charlist_fillarraypointer (screenbpp, 3); charlist_fillarraypointer (screenbpp, 3);
@ -444,15 +492,15 @@ config_video ()
selbpp = charlist_findtext (screenbpp, text); selbpp = charlist_findtext (screenbpp, text);
while (!done && bman.state != GS_quit) { while (!done && bman.state != GS_quit) {
menu_new ("Video Setup", 325, 300); menu = menu_new ("Video Setup", 325, 300);
menu_create_label ("Resolution", 25, 70, 0, COLOR_brown); menu_create_label (menu, "Resolution", 25, 70, 0, COLOR_brown);
menu_create_list ("res", 155, 55, 150, 70, screenres, &selres, 1); menu_create_list (menu, "res", 155, 55, 150, 70, screenres, &selres, 1);
menu_create_label ("Colors", 65, 160, 0, COLOR_brown); menu_create_label (menu, "Colors", 65, 160, 0, COLOR_brown);
menu_create_list ("bpp", 195, 145, 50, 55, screenbpp, &selbpp, 2); menu_create_list (menu, "bpp", 195, 145, 50, 55, screenbpp, &selbpp, 2);
menu_create_bool ("Fullscreen", -1, 210, 150, &gfx.fullscreen, 3); menu_create_bool (menu, "Fullscreen", -1, 210, 150, &gfx.fullscreen, 3);
menu_create_button ("OK", -1, 250, 100, 0); menu_create_button (menu, "OK", -1, 250, 100, 0);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
switch (menuselect) { switch (menuselect) {
case (0): case (0):
@ -493,30 +541,31 @@ void
config_menu () config_menu ()
{ {
int menuselect = 0; int menuselect = 0;
_menu *menu;
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
menu_new ("Configuration", 400, 300); menu = menu_new ("Configuration", 400, 300);
menu_create_label ("General Option", -1, 50, 1, COLOR_brown); menu_create_label (menu, "General Option", -1, 50, 1, COLOR_brown);
menu_create_button ("Playermenu", 25, 85, 150, 1); menu_create_button (menu, "Playermenu", 25, 85, 150, 1);
menu_create_button ("Keyboard", 225, 85, 150, 2); menu_create_button (menu, "Keyboard", 225, 85, 150, 2);
menu_create_button ("Video Setup", -1, 120, 200, 3); menu_create_button (menu, "Video Setup", -1, 120, 200, 3);
menu_create_label ("Sound", 25, 154, 0, COLOR_brown); menu_create_label (menu, "Sound", 25, 154, 0, COLOR_brown);
menu_create_bool ("ON", 100, 150, 50, &snd.playsound, 4); menu_create_bool (menu, "ON", 100, 150, 50, &snd.playsound, 4);
menu_create_label ("Music", 250, 154, 0, COLOR_brown); menu_create_label (menu, "Music", 250, 154, 0, COLOR_brown);
menu_create_bool ("ON", 325, 150, 50, &snd.playmusic, 5); menu_create_bool (menu, "ON", 325, 150, 50, &snd.playmusic, 5);
menu_create_label ("Extended Option", -1, 200, 1, COLOR_brown); menu_create_label (menu, "Extended Option", -1, 200, 1, COLOR_brown);
menu_create_bool ("Debug", 25, 230, 150, &debug, 6); menu_create_bool (menu, "Debug", 25, 230, 150, &debug, 6);
menu_create_bool ("Ask Playername", 250, 230, 150, &bman.askplayername, 7); menu_create_bool (menu, "Ask Playername", 250, 230, 150, &bman.askplayername, 7);
menu_create_button ("Ok", -1, 270, 150, 0); menu_create_button (menu, "Ok", -1, 270, 150, 0);
if (bman.playername[0] == '\0') if (bman.playername[0] == '\0')
menu_focus_id (1); menu_focus_id (menu, 1);
else else
menu_focus_id (0); menu_focus_id (menu, 0);
menu_reload (); menu_reload (menu);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
switch (menuselect) { switch (menuselect) {
case (0): // Back to the Main Menu case (0): // Back to the Main Menu
if (bman.playername[0] == '\0') if (bman.playername[0] == '\0')
@ -525,7 +574,7 @@ config_menu ()
menuselect = -1; menuselect = -1;
break; break;
case (1): // player screen case (1): // player screen
player_menu (); playermenu ();
break; break;
case (2): // keyboard settings case (2): // keyboard settings
keyb_config (); keyb_config ();
@ -546,14 +595,6 @@ ReadPrgArgs (int argc, char **argv)
int i = 0; int i = 0;
while (argv[++i] != NULL) { 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);
if (!strcmp (argv[i], "-firewall"))
bman.firewall = 1;
if (!strcmp (argv[i], "-name"))
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME);
if (!strcmp (argv[i], "-help")) { if (!strcmp (argv[i], "-help")) {
printf ("BomberClone Version " VERSION "\n"); printf ("BomberClone Version " VERSION "\n");
printf (" WebPage : http://www.bomberclone.de\n"); printf (" WebPage : http://www.bomberclone.de\n");
@ -562,15 +603,56 @@ ReadPrgArgs (int argc, char **argv)
printf (" Other Comments: steffen@bomberclone.de\n"); printf (" Other Comments: steffen@bomberclone.de\n");
printf ("\nProgramm options:\n"); printf ("\nProgramm options:\n");
printf (" -name PLAYERNAME - set the Playername\n"); printf (" -name PLAYERNAME - set the Playername\n");
printf (" -port PORT - set the local BomberClone port (Def.: 11000)\n"); printf (" -name2 PLAYERNAME - set the Playername for the second player\n");
printf (" -port PORT - set the local BomberClone port\n");
printf (" (Def.: 11000)\n");
printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n"); printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n");
printf (" -ogc 0/1 - Enable/Disable OGC\n"); printf (" -ogc 0/1 - Enable/Disable OGC\n");
printf (" -firewall - Client is behind a firewall\n"); printf (" -firewall 0/1 - Enable/Disable the firewall settings\n");
printf (" Only set this if you get some problems\n"); printf (" Only set this if you get some problems\n");
printf (" with network games.\n"); printf (" with network games.\n");
printf (" -host - start a network game\n");
printf (" -join - go into the join menu\n");
printf (" -connect ADDRESS - connect to a server\n");
printf (" -debug 0/1 - enable/disable debug\n");
exit (0); exit (0);
} }
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);
if (!strcmp (argv[i], "-firewall"))
bman.firewall = atoi (argv[++i]);
if (!strcmp (argv[i], "-name"))
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME);
if (!strcmp (argv[i], "-name2"))
strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME);
if (!strcmp (argv[i], "-ogc")) if (!strcmp (argv[i], "-ogc"))
bman.notifygamemaster = atoi (argv[++i]); bman.notifygamemaster = atoi (argv[++i]);
if (!strcmp (argv[i], "-debug"))
debug = atoi (argv[++i]);
} }
}; };
/* Read Programm Parameter which will drop us in a special menu */
void
ReadPrgArgs_Jump (int argc, char **argv)
{
int i = 0;
while (argv[++i] != NULL) {
/* check for commands which will put us into a certain menu */
if (!strcmp (argv[i], "-host")) {
host_multiplayer_game ();
}
else if (!strcmp (argv[i], "-join")) {
join_multiplayer_game ();
}
else if (!strcmp (argv[i], "-connect")) {
strncpy (bman.servername, argv[++i], LEN_SERVERNAME + LEN_PORT + 2);
join_multiplayer_game ();
}
}
};

@ -85,8 +85,6 @@ void debug_ingameinfo() {
} }
font_gfxdraw (0, gfx.res.y-font[0].size.y*2, text, 0, 0, (map.size.y*256)+10); font_gfxdraw (0, gfx.res.y-font[0].size.y*2, text, 0, 0, (map.size.y*256)+10);
if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) { sprintf (text, "Move: %d | %d", players[bman.p_nr].m, players[bman.p2_nr].m);
sprintf (text, "Pos: %2.3f,%2.3f Status:%d Frame:%2.2f", players[bman.p_nr].pos.x, players[bman.p_nr].pos.y, players[bman.p_nr].state, players[bman.p_nr].frame); font_gfxdraw (350, gfx.res.y-font[0].size.y, text, 0, 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: game.c,v 1.82 2004/04/03 14:48:43 stpohle Exp $ /* $Id: game.c,v 1.83 2004/05/20 16:55:30 stpohle Exp $
game.c - procedures for the game. */ game.c - procedures for the game. */
#include <string.h> #include <string.h>
@ -126,8 +126,10 @@ game_draw_info ()
} }
} }
if (chat.visible == 0 && GT_MP) if (chat.visible == 0 && GT_MP) {
chat.active = 0;
chat_show (4, 4.5*16, gfx.res.x - 4, gfx.offset.y); chat_show (4, 4.5*16, gfx.res.x - 4, gfx.offset.y);
}
if (debug) if (debug)
debug_ingameinfo(); debug_ingameinfo();
@ -139,9 +141,12 @@ game_draw_info ()
/* /*
* keyboard handling for keys which have nothing to do with the playerkeys * keyboard handling for keys which have nothing to do with the playerkeys
* before calling this function make sure keyb_loop (); was called. * before calling this function make sure keyb_loop (); was called.
*
* chat mode: the chatmode should only be disabled in the game mode
* in the GS_wait mode the chat will always be active.
*/ */
void game_keys_loop () { void game_keys_loop () {
if (GT_MP_PTPM && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) { if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
/* Server is starting the game */ /* Server is starting the game */
bman.state = GS_running; bman.state = GS_running;
net_send_servermode (); net_send_servermode ();
@ -164,7 +169,7 @@ void game_keys_loop () {
*/ */
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
if (chat.active) { if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) {
chat.active = 0; chat.active = 0;
d_printf ("Chatmode Disabled\n"); d_printf ("Chatmode Disabled\n");
} }
@ -172,8 +177,10 @@ void game_keys_loop () {
bman.state = GS_startup; bman.state = GS_startup;
} }
if (keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) { if (GT_MP_PTPM && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) {
chat.active = 1; chat.active = 1;
chat.changed = 1;
chat.lineschanged = 1;
d_printf ("Chatmode Enabled\n"); d_printf ("Chatmode Enabled\n");
} }
}; };
@ -374,6 +381,8 @@ game_start ()
bman.timeout = bman.init_timeout; bman.timeout = bman.init_timeout;
s_calctimesync (); // to clean up the timesyc s_calctimesync (); // to clean up the timesyc
s_calctimesync (); // data run this twice s_calctimesync (); // data run this twice
if (GT_MP_PTPM)
net_send_servermode ();
}; };

@ -1,4 +1,4 @@
/* $Id: gfx.c,v 1.34 2004/02/07 13:35:28 stpohle Exp $ */ /* $Id: gfx.c,v 1.35 2004/05/20 16:55:30 stpohle Exp $ */
/* gfx.c */ /* gfx.c */
#include "bomberclone.h" #include "bomberclone.h"
@ -201,8 +201,8 @@ gfx_loaddata ()
/* load the menugraphics */ /* load the menugraphics */
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
sprintf (filename, "%s/gfx/menu%d.png", bman.datapath, i); sprintf (filename, "%s/gfx/menu%d.png", bman.datapath, i);
menu.images[i] = IMG_Load (filename); menuimages[i] = IMG_Load (filename);
if (menu.images[i] == NULL) { if (menuimages[i] == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ()); printf ("Can't load image: %s\n", SDL_GetError ());
exit (1); exit (1);
} }
@ -218,7 +218,7 @@ gfx_loaddata ()
exit (1); exit (1);
} }
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255)); SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.buttonimages[j][i] = SDL_DisplayFormat (tmpimage); menubuttonimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
} }
@ -232,7 +232,7 @@ gfx_loaddata ()
exit (1); exit (1);
} }
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255)); SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.entryimages[j][i] = SDL_DisplayFormat (tmpimage); menuentryimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
} }
@ -246,9 +246,18 @@ gfx_loaddata ()
exit (1); exit (1);
} }
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255)); SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 255, 255, 255));
menu.listimages[j][i] = SDL_DisplayFormat (tmpimage); menulistimages[j][i] = SDL_DisplayFormat (tmpimage);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
} }
/* load menuselect animation */
sprintf (filename, "%s/gfx/menuselect.png", bman.datapath);
gfx.menuselect.image = IMG_Load (filename);
if (gfx.menuselect.image == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
gfx.menuselect.frames = tmpimage->h / (2 * GFX_IMGSIZE);
}; };
@ -258,14 +267,14 @@ gfx_shutdown ()
int i, j; int i, j;
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
SDL_FreeSurface (menu.images[i]); SDL_FreeSurface (menuimages[i]);
if (i < 3) if (i < 3)
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
SDL_FreeSurface (menu.buttonimages[j][i]); SDL_FreeSurface (menubuttonimages[j][i]);
if (j < 2) SDL_FreeSurface (menu.entryimages[j][i]); if (j < 2) SDL_FreeSurface (menuentryimages[j][i]);
} }
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++)
SDL_FreeSurface (menu.listimages[j][i]); SDL_FreeSurface (menulistimages[j][i]);
} }

@ -1,4 +1,4 @@
/* $Id: help.c,v 1.10 2004/04/05 14:10:50 stpohle Exp $ /* $Id: help.c,v 1.11 2004/05/20 16:55:30 stpohle Exp $
* Display complex help text and information screen about the game * Display complex help text and information screen about the game
*/ */
@ -22,6 +22,7 @@ void help () {
int page = 0, menuselect = 2, y = 0; int page = 0, menuselect = 2, y = 0;
char title[255]; char title[255];
SDL_Rect rect; SDL_Rect rect;
_menu *menu;
menu_displaytext ("Please Wait", "Loading GFX Data"); menu_displaytext ("Please Wait", "Loading GFX Data");
tileset_load ("default", 32, 32); tileset_load ("default", 32, 32);
@ -30,8 +31,8 @@ void help () {
while (menuselect != -1 && menuselect != 1 && bman.state != GS_quit) { while (menuselect != -1 && menuselect != 1 && bman.state != GS_quit) {
if (page == HP_howto0) { if (page == HP_howto0) {
sprintf (title, "How To Play (%d/%d)", page + 1, HP_max); sprintf (title, "How To Play (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
menu_create_text ("help", 5, 55, 53, 20, COLOR_brown, menu_create_text (menu, "help", 5, 55, 53, 20, COLOR_brown,
"The goal of the game is to be the last one, " "The goal of the game is to be the last one, "
"who is alive. You can drop bombs which will explode after " "who is alive. You can drop bombs which will explode after "
"a certain time and destroy everything in horizontal and vertical " "a certain time and destroy everything in horizontal and vertical "
@ -45,16 +46,16 @@ void help () {
rect.y = 15*gfx.players[0].ani.h; rect.y = 15*gfx.players[0].ani.h;
rect.w = gfx.players[0].ani.w; rect.w = gfx.players[0].ani.w;
rect.h = gfx.players[0].ani.h; rect.h = gfx.players[0].ani.h;
menu_create_image ("img", 450, 255, 0, gfx.players[0].ani.image, &rect); menu_create_image (menu, "img", 450, 255, 0, gfx.players[0].ani.image, &rect);
menu_create_text ("help", 5, 255, 45, 10, COLOR_brown, menu_create_text (menu, "help", 5, 255, 45, 10, COLOR_brown,
"You will get points for every player you have killed. " "You will get points for every player you have killed. "
"If you win the game, you can earn additional points " "If you win the game, you can earn additional points "
"depending on how many players played the game. "); "depending on how many players played the game. ");
} }
else if (page == HP_powerup0) { else if (page == HP_powerup0) {
sprintf (title, "Powerups (%d/%d)", page + 1, HP_max); sprintf (title, "Powerups (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
y = 50; y = 50;
@ -63,34 +64,34 @@ void help () {
rect.h = gfx.block.y; rect.h = gfx.block.y;
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"In the game you will find some diffend kind of powerups. " "In the game you will find some diffend kind of powerups. "
"There are the powerups who give you more power for the whole game " "There are the powerups who give you more power for the whole game "
"and the special powerups which will hold only for a certain time."); "and the special powerups which will hold only for a certain time.");
y += 75; y += 75;
menu_create_label ("Permanent Powerups", -1, y, 2, COLOR_yellow); menu_create_label (menu, "Permanent Powerups", -1, y, 2, COLOR_yellow);
y += (5 + font[2].size.y); y += (5 + font[2].size.y);
menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[0].image, &rect);
menu_create_image ("bomb", 5, y, 1, gfx.field[FT_bomb].image, &rect); menu_create_image (menu, "bomb", 5, y, 1, gfx.field[FT_bomb].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"Give you another bomb to drop. Maximum number of bombs is %d.", MAX_BOMBS); "Give you another bomb to drop. Maximum number of bombs is %d.", MAX_BOMBS);
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[0].image, &rect);
menu_create_image ("fire", 5, y, 1, gfx.field[FT_fire].image, &rect); menu_create_image (menu, "fire", 5, y, 1, gfx.field[FT_fire].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"The range of your bombs will be increased. Maximum range is %d.", MAX_RANGE); "The range of your bombs will be increased. Maximum range is %d.", MAX_RANGE);
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[0].image, &rect);
menu_create_image ("shoe", 5, y, 1, gfx.field[FT_shoe].image, &rect); menu_create_image (menu, "shoe", 5, y, 1, gfx.field[FT_shoe].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"This will make your player run faster. The maximum speed will be %1.2f.", MAX_SPEED); "This will make your player run faster. The maximum speed will be %1.2f.", MAX_SPEED);
y += 40; y += 40;
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"Depends how the game is set up, you'll lose " "Depends how the game is set up, you'll lose "
"these powerups if you die. Other players can collect them. " "these powerups if you die. Other players can collect them. "
"In the deathmatch mode you can keep the powerups you collected, " "In the deathmatch mode you can keep the powerups you collected, "
@ -99,7 +100,7 @@ void help () {
} }
else if (page == HP_powerup1) { else if (page == HP_powerup1) {
sprintf (title, "Powerups (%d/%d)", page + 1, HP_max); sprintf (title, "Powerups (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
y = 45; y = 45;
@ -107,44 +108,44 @@ void help () {
rect.w = gfx.block.x; rect.w = gfx.block.x;
rect.h = gfx.block.y; rect.h = gfx.block.y;
menu_create_label ("Special Powerups", -1, y, 2, COLOR_yellow); menu_create_label (menu, "Special Powerups", -1, y, 2, COLOR_yellow);
y += (5 + font[2].size.y); y += (5 + font[2].size.y);
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("kick", 5, y, 1, gfx.field[FT_sp_kick].image, &rect); menu_create_image (menu, "kick", 5, y, 1, gfx.field[FT_sp_kick].image, &rect);
menu_create_text ("help", 55, y, 48, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 48, 10, COLOR_brown,
"Allowes you to kick some bombs around the level. This will hold " "Allowes you to kick some bombs around the level. This will hold "
"just a short time of %d seconds. The maximum distance you can " "just a short time of %d seconds. The maximum distance you can "
"kick the bombs is %d fields.", SPECIAL_KICK_TIME, SPECIAL_KICK_MAXDIST); "kick the bombs is %d fields.", SPECIAL_KICK_TIME, SPECIAL_KICK_MAXDIST);
y += 70; y += 70;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("push", 5, y, 1, gfx.field[FT_sp_push].image, &rect); menu_create_image (menu, "push", 5, y, 1, gfx.field[FT_sp_push].image, &rect);
menu_create_text ("help", 55, y, 48, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 48, 10, COLOR_brown,
"Push bombs one field, as long as nothing is behind this bomb."); "Push bombs one field, as long as nothing is behind this bomb.");
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("droprow", 5, y, 1, gfx.field[FT_sp_row].image, &rect); menu_create_image (menu, "droprow", 5, y, 1, gfx.field[FT_sp_row].image, &rect);
menu_create_text ("help", 55, y, 48, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 48, 10, COLOR_brown,
"You can drop a row of that many bombs you have still left to drop."); "You can drop a row of that many bombs you have still left to drop.");
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("dropliquid", 5, y, 1, gfx.field[FT_sp_liquid].image, &rect); menu_create_image (menu, "dropliquid", 5, y, 1, gfx.field[FT_sp_liquid].image, &rect);
menu_create_text ("help", 55, y, 48, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 48, 10, COLOR_brown,
"The bomb you push now won't stop moving untill they explode."); "The bomb you push now won't stop moving untill they explode.");
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("dropliquid", 5, y, 1, gfx.field[FT_sp_moved].image, &rect); menu_create_image (menu, "dropliquid", 5, y, 1, gfx.field[FT_sp_moved].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"The bomb you push will stop moving on the next border or bomb."); "The bomb you push will stop moving on the next border or bomb.");
y += 40; y += 40;
menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); menu_create_image (menu, "pwback", 5, y, 0, gfx.powerup[2].image, &rect);
menu_create_image ("dropltrigger", 5, y, 1, gfx.field[FT_sp_trigger].image, &rect); menu_create_image (menu, "dropltrigger", 5, y, 1, gfx.field[FT_sp_trigger].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"You will be able to drop triggered bombs. Use " "You will be able to drop triggered bombs. Use "
"the special key to let all your bombs explode. " "the special key to let all your bombs explode. "
"at the time where you want it."); "at the time where you want it.");
@ -152,7 +153,7 @@ void help () {
} }
else if (page == HP_powerup2) { else if (page == HP_powerup2) {
sprintf (title, "Powerups (%d/%d)", page + 1, HP_max); sprintf (title, "Powerups (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
y = 45; y = 45;
@ -160,10 +161,10 @@ void help () {
rect.w = gfx.block.x; rect.w = gfx.block.x;
rect.h = gfx.block.y; rect.h = gfx.block.y;
menu_create_label ("Death Item", -1, y, 2, COLOR_yellow); menu_create_label (menu, "Death Item", -1, y, 2, COLOR_yellow);
y += (5 + font[2].size.y); y += (5 + font[2].size.y);
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"In the game you will find another type of item to collect. " "In the game you will find another type of item to collect. "
"This item is not a powerup at all. If you collect it you will " "This item is not a powerup at all. If you collect it you will "
"get a random illness. This illness will hold for %dseconds. " "get a random illness. This illness will hold for %dseconds. "
@ -171,31 +172,31 @@ void help () {
"get all the illnesses you have too.", ILL_TIMEOUT); "get all the illnesses you have too.", ILL_TIMEOUT);
y += 110; y += 110;
menu_create_image ("pwback", 12, y+8, 0, gfx.powerup[1].image, &rect); menu_create_image (menu, "pwback", 12, y+8, 0, gfx.powerup[1].image, &rect);
menu_create_image ("pwdeath", 12, y+8, 1, gfx.field[FT_death].image, &rect); menu_create_image (menu, "pwdeath", 12, y+8, 1, gfx.field[FT_death].image, &rect);
menu_create_text ("help", 55, y, 45, 10, COLOR_brown, menu_create_text (menu, "help", 55, y, 45, 10, COLOR_brown,
"This will make your player ill. We have at the moment %d diffrent " "This will make your player ill. We have at the moment %d diffrent "
"types of illnesses for you to collect. To make the game more", PI_max); "types of illnesses for you to collect. To make the game more", PI_max);
y += 3*font[0].size.y; y += 3*font[0].size.y;
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"interesting we won't put here a list of all types there are."); "interesting we won't put here a list of all types there are.");
} }
else if (page == HP_keyboard0) { else if (page == HP_keyboard0) {
sprintf (title, "Keyboard (%d/%d)", page + 1, HP_max); sprintf (title, "Keyboard (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
y = 50; y = 50;
menu_create_label ("During a Game", -1, y, 2, COLOR_yellow); menu_create_label (menu, "During a Game", -1, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
rect.x = 3*gfx.players[7].ani.w; rect.x = 3*gfx.players[7].ani.w;
rect.y = 10*gfx.players[7].ani.h; rect.y = 10*gfx.players[7].ani.h;
rect.h = gfx.players[7].ani.h; rect.h = gfx.players[7].ani.h;
rect.w = gfx.players[7].ani.w; rect.w = gfx.players[7].ani.w;
menu_create_image ("img", 450, 100, 0, gfx.players[7].ani.image, &rect); menu_create_image (menu, "img", 450, 100, 0, gfx.players[7].ani.image, &rect);
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"Arrow Keys - Moving of the Player\n" "Arrow Keys - Moving of the Player\n"
"STRG/CTRL - Dropping bombs\n" "STRG/CTRL - Dropping bombs\n"
"Shift - Special Use Key\n" "Shift - Special Use Key\n"
@ -205,10 +206,10 @@ void help () {
"ESC - Exit Game\n"); "ESC - Exit Game\n");
y += 7*font[0].size.y; y += 7*font[0].size.y;
menu_create_label ("Player Selection", -1, y, 2, COLOR_yellow); menu_create_label (menu, "Player Selection", -1, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
menu_create_text ("help", 5, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 5, y, 53, 10, COLOR_brown,
"Left/Right - Select and Deselect a Player\n" "Left/Right - Select and Deselect a Player\n"
"F1 - Mini Help Screen\n" "F1 - Mini Help Screen\n"
"F2 - Player Screen\n" "F2 - Player Screen\n"
@ -220,65 +221,65 @@ void help () {
} }
else if (page == HP_credit0) { else if (page == HP_credit0) {
sprintf (title, "About BomberClone (%d/%d)", page + 1, HP_max); sprintf (title, "About BomberClone (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
rect.x = 1*gfx.players[4].ani.w; rect.x = 1*gfx.players[4].ani.w;
rect.y = 5*gfx.players[4].ani.h; rect.y = 5*gfx.players[4].ani.h;
rect.h = gfx.players[4].ani.h; rect.h = gfx.players[4].ani.h;
rect.w = gfx.players[4].ani.w; rect.w = gfx.players[4].ani.w;
menu_create_image ("img", 15, 60, 0, gfx.players[4].ani.image, &rect); menu_create_image (menu, "img", 15, 60, 0, gfx.players[4].ani.image, &rect);
menu_create_text ("help", 75, 50, 45, 10, COLOR_brown, menu_create_text (menu, "help", 75, 50, 45, 10, COLOR_brown,
"If you have any problems or questions with the game you can send your questions " "If you have any problems or questions with the game you can send your questions "
"to the mailinglist or directly to me. Bugfixes should be send to the SourceForge " "to the mailinglist or directly to me. Bugfixes should be send to the SourceForge "
"Projects page about BomberClone."); "Projects page about BomberClone.");
menu_create_label ("WWW",-1, 140, 2, COLOR_yellow); menu_create_label (menu, "WWW",-1, 140, 2, COLOR_yellow);
menu_create_text ("help", -1, 165, 53, 10, COLOR_brown, "http://www.bomberclone.de"); menu_create_text (menu, "help", -1, 165, 53, 10, COLOR_brown, "http://www.bomberclone.de");
menu_create_label ("EMail",-1, 185, 2, COLOR_yellow); menu_create_label (menu, "EMail",-1, 185, 2, COLOR_yellow);
menu_create_text ("help", -1, 210, 53, 10, COLOR_brown, "steffen@bomberclone.de"); menu_create_text (menu, "help", -1, 210, 53, 10, COLOR_brown, "steffen@bomberclone.de");
menu_create_label ("Project Page",-1, 230, 2, COLOR_yellow); menu_create_label (menu, "Project Page",-1, 230, 2, COLOR_yellow);
menu_create_text ("help", -1, 255, 53, 10, COLOR_brown, "http://sourceforge.net/projects/bomberclone"); menu_create_text (menu, "help", -1, 255, 53, 10, COLOR_brown, "http://sourceforge.net/projects/bomberclone");
} }
else if (page == HP_credit1) { else if (page == HP_credit1) {
sprintf (title, "People (%d/%d)", page + 1, HP_max); sprintf (title, "People (%d/%d)", page + 1, HP_max);
menu_new (title, 500, 400); menu = menu_new (title, 500, 400);
rect.x = 3*gfx.players[6].ani.w; rect.x = 3*gfx.players[6].ani.w;
rect.y = 10*gfx.players[6].ani.h; rect.y = 10*gfx.players[6].ani.h;
rect.h = gfx.players[6].ani.h; rect.h = gfx.players[6].ani.h;
rect.w = gfx.players[6].ani.w; rect.w = gfx.players[6].ani.w;
menu_create_image ("img", 250, 100, 0, gfx.players[6].ani.image, &rect); menu_create_image (menu, "img", 250, 100, 0, gfx.players[6].ani.image, &rect);
y = 50; y = 50;
menu_create_label ("Coding:", 5, y, 2, COLOR_yellow); menu_create_label (menu, "Coding:", 5, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
menu_create_text ("help", 50, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 50, y, 53, 10, COLOR_brown,
" Steffen Pohle\n" " Steffen Pohle\n"
"Patrick Wilczek\n"); "Patrick Wilczek\n");
y = 100; y = 100;
menu_create_label ("GFX:", 425, y, 2, COLOR_yellow); menu_create_label (menu, "GFX:", 425, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
menu_create_text ("help", 325, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 325, y, 53, 10, COLOR_brown,
"TekkRat\n" "TekkRat\n"
"Martijn de Boer\n" "Martijn de Boer\n"
"Steffen Pohle\n" "Steffen Pohle\n"
"Patrick Wilczek\n"); "Patrick Wilczek\n");
y = 150; y = 150;
menu_create_label ("Sound/Music:", 5, y, 2, COLOR_yellow); menu_create_label (menu, "Sound/Music:", 5, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
menu_create_text ("help", 50, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", 50, y, 53, 10, COLOR_brown,
"Henrik_Enqvist\n" "Henrik_Enqvist\n"
"Cerror\n" "Cerror\n"
"Martijn de Boer\n"); "Martijn de Boer\n");
y = 250; y = 250;
menu_create_label ("Thanks To:", -1, y, 2, COLOR_yellow); menu_create_label (menu, "Thanks To:", -1, y, 2, COLOR_yellow);
y += font[2].size.y; y += font[2].size.y;
menu_create_text ("help", -1, y, 53, 10, COLOR_brown, menu_create_text (menu, "help", -1, y, 53, 10, COLOR_brown,
"kitutou(coding/fixing) thaphool(tilesets) ob1kenewb(coding/fixing) " "kitutou(coding/fixing) thaphool(tilesets) ob1kenewb(coding/fixing) "
"TeKkraT(website,gfx) caccola(tilesets) Digital_D(music) " "TeKkraT(website,gfx) caccola(tilesets) Digital_D(music) "
"dcdillon(coding) Psycho(music)"); "dcdillon(coding) Psycho(music)");
@ -286,19 +287,19 @@ void help () {
} }
else break; else break;
if (page > 0) menu_create_button ("Previous Page", 20, 370, 150, 0); if (page > 0) menu_create_button (menu, "Previous Page", 20, 370, 150, 0);
else if (menuselect == 0) else if (menuselect == 0)
menuselect = 2; menuselect = 2;
menu_create_button ("Main Menu", -1, 370, 150, 1); menu_create_button (menu, "Main Menu", -1, 370, 150, 1);
if (page < HP_max-1) menu_create_button ("Next Page", 350, 370, 150, 2); if (page < HP_max-1) menu_create_button (menu, "Next Page", 350, 370, 150, 2);
menu_focus_id (menuselect); menu_focus_id (menu, menuselect);
menuselect = menu_loop (); menuselect = menu_loop (menu);
if (menuselect == 0 && page > 0) if (menuselect == 0 && page > 0)
page--; page--;
if (menuselect == 2 && page < HP_max - 1) if (menuselect == 2 && page < HP_max - 1)
page++; page++;
menu_delete (); menu_delete (menu);
} }
gfx_free_players (); gfx_free_players ();
tileset_free (); tileset_free ();

@ -1,12 +1,12 @@
/* $Id: keyb.c,v 1.3 2004/04/05 14:10:50 stpohle Exp $ /* $Id: keyb.c,v 1.4 2004/05/20 16:55:30 stpohle Exp $
* keyb.c * keyb.c
*/ */
#include "bomberclone.h" #include "bomberclone.h"
#include "network.h" #include "network.h"
#include "ogcache-client.h" #include "ogcache-client.h"
#include "keyb.h"
#include "menu.h" #include "menu.h"
#include "keyb.h"
BCGameKeys keyb_gamekeys; BCGameKeys keyb_gamekeys;
@ -17,7 +17,7 @@ const struct _key_codes key_codetab [] = {
{ SDLK_RSHIFT, "RSHIFT" }, { SDLK_RSHIFT, "RSHIFT" },
{ SDLK_LSHIFT, "LSHIFT" }, { SDLK_LSHIFT, "LSHIFT" },
{ SDLK_RCTRL, "RCTRL" }, { SDLK_RCTRL, "RCTRL" },
{ SDLK_LCTRL, "RCTRL" }, { SDLK_LCTRL, "LCTRL" },
{ SDLK_UP, "CurUP" }, { SDLK_UP, "CurUP" },
{ SDLK_DOWN, "CurDOWN" }, { SDLK_DOWN, "CurDOWN" },
{ SDLK_LEFT, "CurLEFT" }, { SDLK_LEFT, "CurLEFT" },
@ -106,7 +106,7 @@ void keyb_code2text (int keycode, char *keytext) {
/* /*
* create a small menu with all informations * create a small menu with all informations
*/ */
void keyb_config_createkeymenu (int key, int x, int y, int menu_nr) { void keyb_config_createkeymenu (_menu *menu, int key, int x, int y, int menu_nr) {
int key_id; int key_id;
char keyname [32]; char keyname [32];
char keytext [50]; char keytext [50];
@ -154,9 +154,9 @@ void keyb_config_createkeymenu (int key, int x, int y, int menu_nr) {
break; */ break; */
} }
menu_create_label (keyname, x, y + 2, 0, COLOR_brown); menu_create_label (menu, keyname, x, y + 2, 0, COLOR_brown);
keyb_code2text (keyb_gamekeys.keycode[key], keytext); keyb_code2text (keyb_gamekeys.keycode[key], keytext);
menu_create_button (keytext, x + 50, y, 100, menu_nr + key); menu_create_button (menu, keytext, x + 50, y, 100, menu_nr + key);
} }
@ -223,24 +223,25 @@ void keyb_config_readkey (int key) {
*/ */
void keyb_config () { void keyb_config () {
int menuselect = 1; int menuselect = 1;
_menu *menu;
do { do {
menu_new ("Keyboard Config", 420, 400); menu = menu_new ("Keyboard Config", 420, 400);
menu_create_label ("Player 1", 10, 50, 2, COLOR_brown); menu_create_label (menu, "Player 1", 10, 50, 2, COLOR_brown);
keyb_config_createkeymenu (BCPK_up, 25, 90, 10); keyb_config_createkeymenu (menu, BCPK_up, 25, 90, 10);
keyb_config_createkeymenu (BCPK_down, 25, 120, 10); keyb_config_createkeymenu (menu, BCPK_down, 25, 120, 10);
keyb_config_createkeymenu (BCPK_left, 25, 150, 10); keyb_config_createkeymenu (menu, BCPK_left, 25, 150, 10);
keyb_config_createkeymenu (BCPK_right, 25, 180, 10); keyb_config_createkeymenu (menu, BCPK_right, 25, 180, 10);
keyb_config_createkeymenu (BCPK_drop, 25, 210, 10); keyb_config_createkeymenu (menu, BCPK_drop, 25, 210, 10);
keyb_config_createkeymenu (BCPK_special, 25, 240, 10); keyb_config_createkeymenu (menu, BCPK_special, 25, 240, 10);
menu_create_label ("Player 2", 200, 50, 2, COLOR_brown); menu_create_label (menu, "Player 2", 200, 50, 2, COLOR_brown);
keyb_config_createkeymenu (BCPK_max + BCPK_up, 225, 90, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_up, 225, 90, 10);
keyb_config_createkeymenu (BCPK_max + BCPK_down, 225, 120, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_down, 225, 120, 10);
keyb_config_createkeymenu (BCPK_max + BCPK_left, 225, 150, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_left, 225, 150, 10);
keyb_config_createkeymenu (BCPK_max + BCPK_right, 225, 180, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_right, 225, 180, 10);
keyb_config_createkeymenu (BCPK_max + BCPK_drop, 225, 210, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_drop, 225, 210, 10);
keyb_config_createkeymenu (BCPK_max + BCPK_special, 225, 240, 10); keyb_config_createkeymenu (menu, BCPK_max + BCPK_special, 225, 240, 10);
/*menu_create_label ("Other Keys", -1, 270, 2, COLOR_brown); /*menu_create_label ("Other Keys", -1, 270, 2, COLOR_brown);
keyb_config_createkeymenu (BCK_help, 25, 300, 10); keyb_config_createkeymenu (BCK_help, 25, 300, 10);
@ -250,11 +251,11 @@ void keyb_config () {
keyb_config_createkeymenu (BCK_playermenu, 225, 330, 10); keyb_config_createkeymenu (BCK_playermenu, 225, 330, 10);
keyb_config_createkeymenu (BCK_pause, 225, 360, 10); */ keyb_config_createkeymenu (BCK_pause, 225, 360, 10); */
menu_create_button ("Default", 50, 280, 150, 2); menu_create_button (menu, "Default", 50, 280, 150, 2);
menu_create_button ("OK", 250, 280, 150, 1); menu_create_button (menu, "OK", 250, 280, 150, 1);
menu_focus_id (menuselect); menu_focus_id (menu, menuselect);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
if (menuselect ==2) if (menuselect ==2)
keyb_config_reset (); keyb_config_reset ();
if (menuselect >= 10 && menuselect < 10+BCK_max) if (menuselect >= 10 && menuselect < 10+BCK_max)

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.24 2004/04/03 14:48:43 stpohle Exp $ */ /* $Id: main.c,v 1.25 2004/05/20 16:55:30 stpohle Exp $ */
#include "basic.h" #include "basic.h"
#include "bomberclone.h" #include "bomberclone.h"
@ -9,19 +9,20 @@
#include "single.h" #include "single.h"
_bomberclone bman; // Holds GameData _bomberclone bman; // Holds GameData
_player *players; // holds all Playerdata _player *players; // holds all Playerdata
Uint32 timestamp; // timestamp Uint32 timestamp; // timestamp
float timefactor = 0.0f; /* factor for the time time of the last loop float timefactor = 0.0f; /* factor for the time time of the last loop
1.0f would be 20ms */ 1.0f would be 20ms */
float timediff = 0.0f; /* last loop timedifference in seconds */ float timediff = 0.0f; /* last loop timedifference in seconds */
int firstrun = 1; // flag for the first menuloop
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
char text[255]; char text[255];
int menuselect = 0; int menuselect = 0;
_menu *menu;
players = malloc (sizeof (_player) * MAX_PLAYERS); players = malloc (sizeof (_player) * MAX_PLAYERS);
gfxengine_init (); gfxengine_init ();
@ -31,22 +32,19 @@ main (int argc, char **argv)
return (1); return (1);
} }
sprintf (text,"Bomberclone %s", VERSION);
SDL_WM_SetCaption(text , NULL);
SDL_EnableUNICODE(1); SDL_EnableUNICODE(1);
config_init (argc, argv); config_init (argc, argv);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
menu_new (text, 400, 230); menu = menu_new ("Bomberclone", 400, 230);
menu_create_button ("Single Game", -1, 70, 200, 0); menu_create_button (menu, "Single Game", -1, 70, 200, 0);
menu_create_button ("Multiplayer Game", -1, 100, 200, 1); menu_create_button (menu, "Multiplayer Game", -1, 100, 200, 1);
menu_create_button ("Options", -1, 130, 200, 2); menu_create_button (menu, "Options", -1, 130, 200, 2);
menu_create_button ("Manual", -1, 160, 200, 3); menu_create_button (menu, "Manual", -1, 160, 200, 3);
menu_create_button ("Quit Game", -1, 190, 200, 4); menu_create_button (menu, "Quit Game", -1, 190, 200, 4);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
switch (menuselect) { switch (menuselect) {
case (0) : // Singleplayer case (0) : // Singleplayer
single_menu (); single_menu ();

@ -1,4 +1,4 @@
/* $Id: mapmenu.c,v 1.22 2004/02/07 15:03:25 stpohle Exp $ */ /* $Id: mapmenu.c,v 1.23 2004/05/20 16:55:30 stpohle Exp $ */
/* map/tileset selection menu */ /* map/tileset selection menu */
#include "bomberclone.h" #include "bomberclone.h"
@ -25,14 +25,14 @@ mapmenu ()
"tunnel"}, { "tunnel"}, {
"random"},}, *selmt = NULL, *selts = NULL, *seltt = NULL; "random"},}, *selmt = NULL, *selts = NULL, *seltt = NULL;
char mname[100]; char mname[100];
_menu *menu;
charlist_fillarraypointer (maptypes, 3); charlist_fillarraypointer (maptypes, 3);
charlist_fillarraypointer (tiletypes, 2); charlist_fillarraypointer (tiletypes, 2);
charlist_fillarraypointer (tunneltypes, 3); charlist_fillarraypointer (tunneltypes, 3);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
menu_new ("Map Options", 420, 400); menu = menu_new ("Map Options", 420, 400);
switch (map.map_selection) { switch (map.map_selection) {
case (MAPS_select): // Selected Map case (MAPS_select): // Selected Map
selmt = charlist_findtext (maptypes, "selected file"); selmt = charlist_findtext (maptypes, "selected file");
@ -40,8 +40,8 @@ mapmenu ()
sprintf (mname, "< undefined >"); sprintf (mname, "< undefined >");
else else
sprintf (mname, "%s", getfilename (map.map)); sprintf (mname, "%s", getfilename (map.map));
menu_create_label ("Selected Map:", 20, 160, 0, COLOR_brown); menu_create_label (menu, "Selected Map:", 20, 160, 0, COLOR_brown);
menu_create_button (mname, 10, 180, 170, 2); menu_create_button (menu, mname, 10, 180, 170, 2);
break; break;
case (MAPS_randmap): // Random Map case (MAPS_randmap): // Random Map
selmt = charlist_findtext (maptypes, "random file"); selmt = charlist_findtext (maptypes, "random file");
@ -49,10 +49,8 @@ mapmenu ()
case (MAPS_randgen): // Random Generated Map case (MAPS_randgen): // Random Generated Map
selmt = charlist_findtext (maptypes, "autogenerated"); selmt = charlist_findtext (maptypes, "autogenerated");
d_printf ("autogen\n"); d_printf ("autogen\n");
menu_create_entry ("X Size:", 20, 160, 120, &map.size.x, MAX_FIELDSIZE_X, MENU_entryint16, menu_create_entry (menu, "X Size:", 20, 160, 120, &map.size.x, MAX_FIELDSIZE_X, MENU_entryint16, 2);
2); menu_create_entry (menu, "Y Size:", 20, 180, 120, &map.size.y, MAX_FIELDSIZE_Y, MENU_entryint16, 3);
menu_create_entry ("Y Size:", 20, 180, 120, &map.size.y, MAX_FIELDSIZE_Y, MENU_entryint16,
3);
break; break;
} }
if (map.random_tileset) if (map.random_tileset)
@ -63,8 +61,8 @@ mapmenu ()
sprintf (mname, "< undefined >"); sprintf (mname, "< undefined >");
else else
sprintf (mname, "%s", map.tileset); sprintf (mname, "%s", map.tileset);
menu_create_label ("Selected Tileset:", 250, 140, 0, COLOR_brown); menu_create_label (menu, "Selected Tileset:", 250, 140, 0, COLOR_brown);
menu_create_button (mname, 250, 160, 170, 5); menu_create_button (menu, mname, 250, 160, 170, 5);
switch (map.type) { switch (map.type) {
case (MAPT_normal): case (MAPT_normal):
@ -78,30 +76,30 @@ mapmenu ()
break; break;
} }
menu_create_label ("Map Type:", 10, 50, 1, COLOR_brown); menu_create_label (menu, "Map Type:", 10, 50, 1, COLOR_brown);
menu_create_label ("Tileset:", 250, 50, 1, COLOR_brown); menu_create_label (menu, "Tileset:", 250, 50, 1, COLOR_brown);
menu_create_label ("Items:", 220, 200, 1, COLOR_brown); menu_create_label (menu, "Items:", 220, 200, 1, COLOR_brown);
menu_create_list ("mt", 10, 85, 170, 60, maptypes, &selmt, 1); menu_create_list (menu, "mt", 10, 85, 170, 60, maptypes, &selmt, 1);
menu_create_list ("ts", 250, 85, 170, 40, tiletypes, &selts, 4); menu_create_list (menu, "ts", 250, 85, 170, 40, tiletypes, &selts, 4);
menu_create_list ("tt", 10, 220, 100, 60, tunneltypes, &seltt, 6); menu_create_list (menu, "tt", 10, 220, 100, 60, tunneltypes, &seltt, 6);
menu_create_entry ("Bombs:", 140, 240, 110, &map.bombs, 100, MENU_entryint32, 7); menu_create_entry (menu, "Bombs:", 140, 240, 110, &map.bombs, 100, MENU_entryint32, 7);
menu_create_entry ("Fire: ", 140, 260, 110, &map.fire, 100, MENU_entryint32, 8); menu_create_entry (menu, "Fire: ", 140, 260, 110, &map.fire, 100, MENU_entryint32, 8);
menu_create_entry ("Shoes:", 140, 280, 110, &map.shoes, 100, MENU_entryint32, 9); menu_create_entry (menu, "Shoes:", 140, 280, 110, &map.shoes, 100, MENU_entryint32, 9);
menu_create_entry ("Mixed:", 140, 300, 110, &map.mixed, 100, MENU_entryint32, 10); menu_create_entry (menu, "Mixed:", 140, 300, 110, &map.mixed, 100, MENU_entryint32, 10);
menu_create_entry ("Death:", 140, 320, 110, &map.death, 100, MENU_entryint32, 11); menu_create_entry (menu, "Death:", 140, 320, 110, &map.death, 100, MENU_entryint32, 11);
menu_create_entry ("Trigger:", 280, 240, 120, &map.sp_trigger, 30, MENU_entryint32, 12); menu_create_entry (menu, "Trigger:", 280, 240, 120, &map.sp_trigger, 30, MENU_entryint32, 12);
menu_create_entry ("Push: ", 280, 260, 120, &map.sp_push, 30, MENU_entryint32, 13); menu_create_entry (menu, "Push: ", 280, 260, 120, &map.sp_push, 30, MENU_entryint32, 13);
menu_create_entry ("Row: ", 280, 280, 120, &map.sp_row, 30, MENU_entryint32, 14); menu_create_entry (menu, "Row: ", 280, 280, 120, &map.sp_row, 30, MENU_entryint32, 14);
menu_create_entry ("Kick: ", 280, 300, 120, &map.sp_kick, 30, MENU_entryint32, 15); menu_create_entry (menu, "Kick: ", 280, 300, 120, &map.sp_kick, 30, MENU_entryint32, 15);
menu_create_button ("Game Options", -1, 350, 150, 16); menu_create_button (menu, "Game Options", -1, 350, 150, 16);
menu_create_button ("Ok", -1, 380, 150, 0); menu_create_button (menu, "Ok", -1, 380, 150, 0);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
switch (menuselect) { switch (menuselect) {
case (0): case (0):
menuselect = -1; menuselect = -1;
@ -327,29 +325,30 @@ void mapgamesetting () {
{"Deathmatch", NULL}, {"Deathmatch", NULL},
}; };
_charlist *gametype_sel = &gametype[bman.gametype]; _charlist *gametype_sel = &gametype[bman.gametype];
_menu *menu;
charlist_fillarraypointer (gametype, 2); charlist_fillarraypointer (gametype, 2);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
menu_new ("Game Options", 420, 400); menu = menu_new ("Game Options", 420, 400);
menu_create_label ("Start Values", 25, 50, 0, COLOR_brown); menu_create_label (menu, "Start Values", 25, 50, 0, COLOR_brown);
menu_create_entry ("Bombs:", 25, 80, 150, &bman.start_bombs, MAX_BOMBS, MENU_entryint32, 1); menu_create_entry (menu, "Bombs:", 25, 80, 150, &bman.start_bombs, MAX_BOMBS, MENU_entryint32, 1);
menu_create_entry ("Speed:", 25,110, 150, &bman.start_speed, MAX_SPEED, MENU_entryfloat, 2); menu_create_entry (menu, "Speed:", 25,110, 150, &bman.start_speed, MAX_SPEED, MENU_entryfloat, 2);
menu_create_entry ("Range:", 25,140, 150, &bman.start_range, MAX_RANGE, MENU_entryint32, 3); menu_create_entry (menu, "Range:", 25,140, 150, &bman.start_range, MAX_RANGE, MENU_entryint32, 3);
menu_create_label ("Other Values", 200, 50, 0, COLOR_brown); menu_create_label (menu, "Other Values", 200, 50, 0, COLOR_brown);
menu_create_entry ("Gametime:", 200, 80, 150, &bman.init_timeout, 1200, MENU_entryint32, 4); menu_create_entry (menu, "Gametime:", 200, 80, 150, &bman.init_timeout, 1200, MENU_entryint32, 4);
menu_create_label ("Game Parameter", 25, 180, 1, COLOR_brown); menu_create_label (menu, "Game Parameter", 25, 180, 1, COLOR_brown);
menu_create_entry ("Bomb Time:", 25, 220, 200, &bman.bomb_tickingtime, 1200, MENU_entryfloat, 5); menu_create_entry (menu, "Bomb Time:", 25, 220, 200, &bman.bomb_tickingtime, 1200, MENU_entryfloat, 5);
menu_create_label ("Gametype", 25, 250, 0, COLOR_brown); menu_create_label (menu, "Gametype", 25, 250, 0, COLOR_brown);
menu_create_list ("GameType", 25, 280, 150, 50, gametype, &gametype_sel, 6); menu_create_list (menu, "GameType", 25, 280, 150, 50, gametype, &gametype_sel, 6);
menu_create_bool ("Drop Items", 200, 280, 150, &bman.dropitemsondeath, 7); menu_create_bool (menu, "Drop Items", 200, 280, 150, &bman.dropitemsondeath, 7);
menu_create_button ("Ok", -1, 380, 150, 0); menu_create_button (menu, "Ok", -1, 380, 150, 0);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
if (menuselect == 0) { if (menuselect == 0) {
bman.gametype = gametype_sel- &gametype[0]; bman.gametype = gametype_sel- &gametype[0];

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.42 2004/02/07 15:03:25 stpohle Exp $ /* $Id: menu.c,v 1.43 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling */ * Menuhandling */
#include "basic.h" #include "basic.h"
@ -12,52 +12,53 @@
#define MENU_MESSAGES_MAXLINELEN 50 #define MENU_MESSAGES_MAXLINELEN 50
_menuitem menuitems[MENU_MAXENTRYS]; SDL_Surface *menuimages[9]; // holds the gfx
_menu menu; SDL_Surface *menulistimages[2][9]; // holds the gfx for the lists
int menu_looprunning = 0; SDL_Surface *menubuttonimages[3][3]; // holds the images for the buttons
SDL_Surface *menuentryimages[2][3]; // [PRESSED][Left|Center|Right]
/* delete all informations and create a totally new menuscreen */ /* delete all informations and create a totally new menuscreen */
void _menu *
menu_new (char *title, int x, int y) menu_new (char *title, int x, int y)
{ {
_menu *menu = malloc (sizeof (_menu));
int i; int i;
if (menu.oldscreen != NULL)
menu_delete ();
strncpy (menu.title, title, MENU_TITLELEN); strncpy (menu->title, title, MENU_TITLELEN);
menu.items = NULL; menu->items = NULL;
menu.focus = NULL; menu->focus = NULL;
for (i = 0; i < MENU_MAXENTRYS; i++) { for (i = 0; i < MENU_MAXENTRYS; i++) {
menuitems[i].id = -1; menu->menuitems[i].id = -1;
menuitems[i].type = -1; menu->menuitems[i].type = -1;
menuitems[i].next = NULL; menu->menuitems[i].next = NULL;
menu->menuitems[i].menu = menu;
} }
/* save the old background screen */ /* save the old background screen */
x = (1 + (int) (x / menu.images[1]->w)) * menu.images[1]->w; x = (1 + (int) (x / menuimages[1]->w)) * menuimages[1]->w;
y = (1 + (int) (y / menu.images[3]->h)) * menu.images[3]->h; y = (1 + (int) (y / menuimages[3]->h)) * menuimages[3]->h;
menu.oldscreenpos.x = ((gfx.res.x - (x + 2 * menu.images[0]->w)) / 2); menu->oldscreenpos.x = ((gfx.res.x - (x + 2 * menuimages[0]->w)) / 2);
menu.oldscreenpos.y = ((gfx.res.y - (y + 2 * menu.images[0]->h)) / 2); menu->oldscreenpos.y = ((gfx.res.y - (y + 2 * menuimages[0]->h)) / 2);
menu.oldscreenpos.w = x + 2 * menu.images[0]->w; menu->oldscreenpos.w = x + 2 * menuimages[0]->w;
menu.oldscreenpos.h = y + 2 * menu.images[0]->h; menu->oldscreenpos.h = y + 2 * menuimages[0]->h;
menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos); menu->oldscreen = gfx_copyscreen (&menu->oldscreenpos);
menu.focus = NULL; menu->focus = NULL;
menu_looprunning = 0; menu->looprunning = 0;
return menu;
}; };
/* restore the screen and reset all needed informations, free the old screen */ /* restore the screen and reset all needed informations, free the old screen */
void void
menu_delete () menu_delete (_menu * menu)
{ {
gfx_restorescreen (menu.oldscreen, &menu.oldscreenpos); gfx_restorescreen (menu->oldscreen, &menu->oldscreenpos);
gfx_blitdraw (); gfx_blitdraw ();
SDL_FreeSurface (menu.oldscreen); SDL_FreeSurface (menu->oldscreen);
menu.oldscreen = NULL;
free (menu);
menuitems[0].next = NULL;
menu.items = NULL;
menu_looprunning = 0;
if (GS_RUNNING) if (GS_RUNNING)
draw_field (); draw_field ();
}; };
@ -65,7 +66,7 @@ menu_delete ()
/* draw only a part of the Screen */ /* draw only a part of the Screen */
void void
menu_draw_background (SDL_Rect * updaterect) menu_draw_background (_menu * menu, SDL_Rect * updaterect)
{ {
int x, int x,
y, y,
@ -78,42 +79,42 @@ menu_draw_background (SDL_Rect * updaterect)
window; window;
y = 0; // start at the updaterect. start pos y = 0; // start at the updaterect. start pos
for (; y <= (menu.oldscreenpos.h - 2 * menu.images[0]->h - 1) / menu.images[4]->h; y++) { for (; y <= (menu->oldscreenpos.h - 2 * menuimages[0]->h - 1) / menuimages[4]->h; y++) {
x = 0; // start at the updaterect. start pos x = 0; // start at the updaterect. start pos
for (; x <= (menu.oldscreenpos.w - 2 * menu.images[0]->w - 1) / menu.images[4]->w; x++) { for (; x <= (menu->oldscreenpos.w - 2 * menuimages[0]->w - 1) / menuimages[4]->w; x++) {
dest.x = x * menu.images[4]->w; // start pos dest.x = x * menuimages[4]->w; // start pos
dest.y = y * menu.images[4]->h; dest.y = y * menuimages[4]->h;
dx = (1 + x) * menu.images[4]->w; // end pos dx = (1 + x) * menuimages[4]->w; // end pos
if (dx >= (menu.oldscreenpos.w - 2 * menu.images[0]->w)) if (dx >= (menu->oldscreenpos.w - 2 * menuimages[0]->w))
dest.w = menu.images[4]->w - (dx - (menu.oldscreenpos.w - 2 * menu.images[0]->w)); dest.w = menuimages[4]->w - (dx - (menu->oldscreenpos.w - 2 * menuimages[0]->w));
else else
dest.w = menu.images[4]->w; dest.w = menuimages[4]->w;
dy = (1 + y) * menu.images[4]->h; dy = (1 + y) * menuimages[4]->h;
if (dy >= (menu.oldscreenpos.h - 2 * menu.images[0]->h)) if (dy >= (menu->oldscreenpos.h - 2 * menuimages[0]->h))
dest.h = menu.images[4]->h - (dy - (menu.oldscreenpos.h - 2 * menu.images[0]->h)); dest.h = menuimages[4]->h - (dy - (menu->oldscreenpos.h - 2 * menuimages[0]->h));
else else
dest.h = menu.images[4]->h; dest.h = menuimages[4]->h;
if (dest.w > 0 || dest.h > 0) { if (dest.w > 0 || dest.h > 0) {
dest.x += MENUOFFSET_X; dest.x += MENUOFFSET_X (menu);
dest.y += MENUOFFSET_Y; dest.y += MENUOFFSET_Y (menu);
src.x = 0; src.x = 0;
src.y = 0; src.y = 0;
src.h = dest.h; src.h = dest.h;
src.w = dest.w; src.w = dest.w;
if (updaterect == NULL) if (updaterect == NULL)
gfx_blit (menu.images[4], &src, gfx.screen, &dest, 10000); gfx_blit (menuimages[4], &src, gfx.screen, &dest, 10000);
else { else {
window = *updaterect; window = *updaterect;
window.x += MENUOFFSET_X; window.x += MENUOFFSET_X (menu);
window.y += MENUOFFSET_Y; window.y += MENUOFFSET_Y (menu);
rect_clipping (&src, &dest, &window, &csrc, &cdest); rect_clipping (&src, &dest, &window, &csrc, &cdest);
if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF
&& cdest.h < UINT16_HALF) && cdest.h < UINT16_HALF)
gfx_blit (menu.images[4], &csrc, gfx.screen, &cdest, 10000); gfx_blit (menuimages[4], &csrc, gfx.screen, &cdest, 10000);
} }
} }
} }
@ -123,68 +124,68 @@ menu_draw_background (SDL_Rect * updaterect)
/* draws the menuborders, this function does not save the background */ /* draws the menuborders, this function does not save the background */
void void
menu_draw_border () menu_draw_border (_menu * menu)
{ {
SDL_Rect dest; SDL_Rect dest;
int i, int i,
dx; dx;
// draw top left // draw top left
dest.x = menu.oldscreenpos.x; dest.x = menu->oldscreenpos.x;
dest.y = menu.oldscreenpos.y; dest.y = menu->oldscreenpos.y;
dest.w = menu.images[0]->w; dest.w = menuimages[0]->w;
dest.h = menu.images[0]->h; dest.h = menuimages[0]->h;
gfx_blit (menu.images[0], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[0], NULL, gfx.screen, &dest, 10000);
// draw top and below // draw top and below
for (i = 0; i < ((menu.oldscreenpos.w - (2 * menu.images[0]->w)) / menu.images[1]->w); i++) { for (i = 0; i < ((menu->oldscreenpos.w - (2 * menuimages[0]->w)) / menuimages[1]->w); i++) {
dest.x = menu.oldscreenpos.x + menu.images[0]->w + (i * menu.images[1]->w); dest.x = menu->oldscreenpos.x + menuimages[0]->w + (i * menuimages[1]->w);
dest.y = menu.oldscreenpos.y; dest.y = menu->oldscreenpos.y;
dest.w = menu.images[1]->w; dest.w = menuimages[1]->w;
dest.h = menu.images[1]->h; dest.h = menuimages[1]->h;
gfx_blit (menu.images[1], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[1], NULL, gfx.screen, &dest, 10000);
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[7]->h; dest.y = menu->oldscreenpos.y + menu->oldscreenpos.h - menuimages[7]->h;
gfx_blit (menu.images[7], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[7], NULL, gfx.screen, &dest, 10000);
} }
// draw top right // draw top right
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[2]->w; dest.x = menu->oldscreenpos.x + menu->oldscreenpos.w - menuimages[2]->w;
dest.y = menu.oldscreenpos.y; dest.y = menu->oldscreenpos.y;
dest.w = menu.images[2]->w; dest.w = menuimages[2]->w;
dest.h = menu.images[2]->h; dest.h = menuimages[2]->h;
gfx_blit (menu.images[2], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[2], NULL, gfx.screen, &dest, 10000);
// draw left and right // draw left and right
for (i = 0; i < ((menu.oldscreenpos.h - (2 * menu.images[0]->h)) / menu.images[3]->h); i++) { for (i = 0; i < ((menu->oldscreenpos.h - (2 * menuimages[0]->h)) / menuimages[3]->h); i++) {
dest.x = menu.oldscreenpos.x; dest.x = menu->oldscreenpos.x;
dest.y = menu.oldscreenpos.y + menu.images[0]->h + menu.images[3]->h * i; dest.y = menu->oldscreenpos.y + menuimages[0]->h + menuimages[3]->h * i;
dest.w = menu.images[1]->w; dest.w = menuimages[1]->w;
dest.h = menu.images[1]->h; dest.h = menuimages[1]->h;
gfx_blit (menu.images[3], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[3], NULL, gfx.screen, &dest, 10000);
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[5]->w; dest.x = menu->oldscreenpos.x + menu->oldscreenpos.w - menuimages[5]->w;
gfx_blit (menu.images[5], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[5], NULL, gfx.screen, &dest, 10000);
} }
// draw below left // draw below left
dest.x = menu.oldscreenpos.x; dest.x = menu->oldscreenpos.x;
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[7]->h; dest.y = menu->oldscreenpos.y + menu->oldscreenpos.h - menuimages[7]->h;
dest.w = menu.images[6]->w; dest.w = menuimages[6]->w;
dest.h = menu.images[6]->h; dest.h = menuimages[6]->h;
gfx_blit (menu.images[6], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[6], NULL, gfx.screen, &dest, 10000);
// draw below right // draw below right
dest.x = menu.oldscreenpos.x + menu.oldscreenpos.w - menu.images[8]->w; dest.x = menu->oldscreenpos.x + menu->oldscreenpos.w - menuimages[8]->w;
dest.y = menu.oldscreenpos.y + menu.oldscreenpos.h - menu.images[8]->h; dest.y = menu->oldscreenpos.y + menu->oldscreenpos.h - menuimages[8]->h;
dest.w = menu.images[8]->w; dest.w = menuimages[8]->w;
dest.h = menu.images[8]->h; dest.h = menuimages[8]->h;
gfx_blit (menu.images[8], NULL, gfx.screen, &dest, 10000); gfx_blit (menuimages[8], NULL, gfx.screen, &dest, 10000);
menu_draw_background (NULL); menu_draw_background (menu, NULL);
// draw title // draw title
dx = menu.oldscreenpos.x + (menu.oldscreenpos.w - font[2].size.x * strlen (menu.title)) / 2; 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, font_gfxdrawbold (dx, menu->oldscreenpos.y + menuimages[0]->h + 8, menu->title, 2, COLOR_brown,
2, 10000); 2, 10000);
font_gfxdraw (dx, menu.oldscreenpos.y + menu.images[0]->h + 8, menu.title, 2, COLOR_yellow, font_gfxdraw (dx, menu->oldscreenpos.y + menuimages[0]->h + 8, menu->title, 2, COLOR_yellow,
10000); 10000);
}; };
@ -192,15 +193,15 @@ menu_draw_border ()
/* draw the menu, even it is only put into the gfx_blitlist. gfx_blitdraw needs /* 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 */ * to be called before the menu is drawed on the screen */
void void
menu_draw () menu_draw (_menu * menu)
{ {
_menuitem *m; _menuitem *m;
if (!menu_looprunning) if (!menu->looprunning)
return; return;
menu_draw_border (); menu_draw_border (menu);
for (m = menu.items; m != NULL; m = m->next) for (m = menu->items; m != NULL; m = m->next)
menu_draw_menuitem (m); menu_draw_menuitem (m);
}; };
@ -210,7 +211,14 @@ menu_draw ()
inline void inline void
menu_draw_menuitem (_menuitem * m) menu_draw_menuitem (_menuitem * m)
{ {
if (!menu_looprunning) _menu *menu;
if (m == NULL)
return;
menu = (_menu *) m->menu;
if (!menu->looprunning)
return; return;
switch (m->type) { switch (m->type) {
case (MENU_label): case (MENU_label):
@ -231,20 +239,20 @@ menu_draw_menuitem (_menuitem * m)
case (MENU_list): case (MENU_list):
menu_draw_list (m); menu_draw_list (m);
break; break;
case (MENU_image): case (MENU_image):
menu_draw_image (m); menu_draw_image (m);
break; break;
} }
}; };
/* reload all variables into all menuelements */ /* reload all variables into all menuelements */
void void
menu_reload () menu_reload (_menu * menu)
{ {
_menuitem *m; _menuitem *m;
for (m = menu.items; m != NULL; m = m->next) for (m = menu->items; m != NULL; m = m->next)
menu_reload_menuitem (m); menu_reload_menuitem (m);
}; };
@ -287,21 +295,22 @@ menu_getlastitem (_menuitem * first)
/* get the last and the first id number */ /* get the last and the first id number */
_menuitem * _menuitem *
menu_get_firstid () menu_get_firstid (_menu * menu)
{ {
_menuitem *result = NULL, _menuitem *result = NULL,
*mi = menu.items; *mi = menu->items;
for (mi = menu.items; mi != NULL; mi = mi->next) for (mi = menu->items; mi != NULL; mi = mi->next)
if ((result == NULL || mi->id < result->id) && mi->id != -1) if ((result == NULL || mi->id < result->id) && mi->id != -1)
result = mi; result = mi;
return result; return result;
}; };
_menuitem * _menuitem *
menu_get_lastid () menu_get_lastid (_menu * menu)
{ {
_menuitem *result = NULL, _menuitem *result = NULL,
*mi = menu.items; *mi = menu->items;
for (mi = menu.items; mi != NULL; mi = mi->next) for (mi = menu->items; mi != NULL; mi = mi->next)
if ((result == NULL || mi->id > result->id) && mi->id != -1) if ((result == NULL || mi->id > result->id) && mi->id != -1)
result = mi; result = mi;
return result; return result;
@ -314,49 +323,50 @@ void
menu_change_focus (_menuitem * newfocus) menu_change_focus (_menuitem * newfocus)
{ {
_menuitem *oldmi; _menuitem *oldmi;
_menu *menu = (_menu *) newfocus->menu;
if (newfocus == menu.focus) // no focus change if (newfocus == menu->focus) // no focus change
return; return;
/* lose focus */ /* lose focus */
if (menu.focus != NULL) { if (menu->focus != NULL) {
switch (menu.focus->type) { switch (menu->focus->type) {
case (MENU_entryfloat): case (MENU_entryfloat):
case (MENU_entryint16): case (MENU_entryint16):
case (MENU_entryint32): case (MENU_entryint32):
case (MENU_entrytext): case (MENU_entrytext):
menu_entry_lose_focus (menu.focus); menu_entry_lose_focus (menu->focus);
break; break;
} }
} }
/* draw the old and the new element */ /* draw the old and the new element */
oldmi = menu.focus; oldmi = menu->focus;
menu.focus = newfocus; menu->focus = newfocus;
if (oldmi != NULL) if (oldmi != NULL)
menu_draw_menuitem (oldmi); menu_draw_menuitem (oldmi);
menu_draw_menuitem (menu.focus); menu_draw_menuitem (menu->focus);
/* get focus ... no function yet */ /* get focus ... no function yet */
d_printf ("menu_change_focus: ID:%d Name:%s\n", menu.focus->id, menu.focus->label); d_printf ("menu_change_focus: ID:%d Name:%s\n", menu->focus->id, menu->focus->label);
}; };
/* focus next element, order by ID */ /* focus next element, order by ID */
void void
menu_focus_next () menu_focus_next (_menu * menu)
{ {
_menuitem *newmi = menu.focus, _menuitem *newmi = menu->focus,
*mi, *mi,
*oldmi = menu.focus; *oldmi = menu->focus;
for (mi = menu.items; mi != NULL; mi = mi->next) for (mi = menu->items; mi != NULL; mi = mi->next)
if (mi->id != oldmi->id && mi->id > menu.focus->id if (mi->id != oldmi->id && mi->id > menu->focus->id
&& (mi->id < newmi->id || newmi == oldmi)) && (mi->id < newmi->id || newmi == oldmi))
newmi = mi; newmi = mi;
if (newmi == oldmi) if (newmi == oldmi)
menu_change_focus (menu_get_firstid ()); menu_change_focus (menu_get_firstid (menu));
else else
menu_change_focus (newmi); menu_change_focus (newmi);
}; };
@ -364,18 +374,18 @@ menu_focus_next ()
/* focus previous element, order by ID */ /* focus previous element, order by ID */
void void
menu_focus_prev () menu_focus_prev (_menu * menu)
{ {
_menuitem *newmi = menu.focus, _menuitem *newmi = menu->focus,
*mi, *mi,
*oldmi = menu.focus; *oldmi = menu->focus;
for (mi = menu.items; mi != NULL; mi = mi->next) for (mi = menu->items; mi != NULL; mi = mi->next)
if (mi->id != -1 && mi->id != oldmi->id && mi->id < oldmi->id if (mi->id != -1 && mi->id != oldmi->id && mi->id < oldmi->id
&& (mi->id > newmi->id || newmi == oldmi)) && (mi->id > newmi->id || newmi == oldmi))
newmi = mi; newmi = mi;
if (newmi == oldmi) if (newmi == oldmi)
menu_change_focus (menu_get_lastid ()); menu_change_focus (menu_get_lastid (menu));
else else
menu_change_focus (newmi); menu_change_focus (newmi);
}; };
@ -383,54 +393,115 @@ menu_focus_prev ()
/* focus element with id ID */ /* focus element with id ID */
void void
menu_focus_id (int id) menu_focus_id (_menu * menu, int id)
{ {
_menuitem *mi, _menuitem *mi,
*oldmi = menu.focus; *oldmi = menu->focus;
for (mi = menu.items; mi != NULL; mi = mi->next) for (mi = menu->items; mi != NULL; mi = mi->next)
if (mi->id == id) if (mi->id == id)
menu_change_focus (mi); menu_change_focus (mi);
menu_draw_menuitem (oldmi); menu_draw_menuitem (oldmi);
if (menu.focus != oldmi) if (menu->focus != oldmi)
menu_draw_menuitem (menu.focus); menu_draw_menuitem (menu->focus);
};
/*
* do the evenhandling and forward all events to the menuitems
* menusingle loop, this function can be called from outside or from there
* menu_loop () functions.
*
* the return value will hole the done value if the menu closed
* RETURN: -1 - ESCAPE pressed
* 0 - menu is still running
* 1 - got SDL_Quit message
*/
int
menu_event_loop (_menu * menu, SDL_Event * event, int eventstate)
{
Uint8 *keys;
int done = 0;
if (eventstate >= 1) {
switch (event->type) {
case (SDL_QUIT):
bman.state = GS_quit;
done = 1;
return 1;
break;
case (SDL_KEYDOWN): /* focus next element */
if (event->key.keysym.sym == SDLK_TAB) {
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])
menu_focus_prev (menu);
else
menu_focus_next (menu);
break;
}
else if (event->key.keysym.sym == SDLK_ESCAPE) {
return -1;
break;
}
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_entrytext):
case (MENU_entryfloat):
case (MENU_entryint16):
case (MENU_entryint32):
done = menu_event_entry (menu->focus, event);
break;
case (MENU_label):
break;
case (MENU_list):
done = menu_event_list (menu->focus, event);
break;
}
}
}
menu->focusto -= timediff;
if (menu->focusto <= 0.0f) {
menu->focusto = MENU_FOCUSVIS_BLINKTO;
menu->focusvis = !menu->focusvis;
menu_draw_menuitem (menu->focus);
}
return done;
}; };
/* menu loop, programm will stay in here as long as no ESCAPE is pressed /* 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 */ * and as long as no Button is clicked. Return of -2 means something needs to reordered */
int int
menu_loop () menu_loop (_menu * menu)
{ {
SDL_Event event; SDL_Event event;
Uint8 *keys; int done = 0, eventstate = 0, reorder = 0;
int keypressed = 0,
done = 0,
eventstate = 0,
reorder = 0;
menu_looprunning = 1; menu->looprunning = 1;
/* check if the focus is set to something, if not /* check if the focus is set to something, if not
* set the focus to the first item */ * set the focus to the first item */
if (menu.focus == NULL) { if (menu->focus == NULL) {
menu.focus = menu.items; menu->focus = menu->items;
menu_focus_id (0); menu_focus_id (menu, 0);
} }
if (menu.focus == NULL) { if (menu->focus == NULL) {
d_fatal ("menu_loop: focus == NULL, something went wrong\n"); d_fatal ("menu_loop: focus == NULL, something went wrong\n");
menu_looprunning = 0; menu->looprunning = 0;
return -1; return -1;
} }
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE])
keypressed = 1;
timestamp = SDL_GetTicks (); // needed for time sync. timestamp = SDL_GetTicks (); // needed for time sync.
menu_draw (); menu_draw (menu);
while (!reorder && !done && bman.state != GS_quit) { while (!reorder && !done && bman.state != GS_quit) {
gfx_blitdraw (); gfx_blitdraw ();
@ -446,66 +517,18 @@ menu_loop ()
eventstate = SDL_PollEvent (&event); eventstate = SDL_PollEvent (&event);
if (eventstate >= 1) { done = menu_event_loop (menu, &event, eventstate);
switch (event.type) {
case (SDL_QUIT):
bman.state = GS_quit;
done = 1;
return -1;
break;
case (SDL_KEYDOWN): /* focus next element */
if (event.key.keysym.sym == SDLK_TAB) {
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])
menu_focus_prev ();
else
menu_focus_next ();
break;
}
else if (event.key.keysym.sym == SDLK_ESCAPE) {
return -1;
break;
}
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_entrytext):
case (MENU_entryfloat):
case (MENU_entryint16):
case (MENU_entryint32):
done = menu_event_entry (menu.focus, &event);
break;
case (MENU_label):
break;
case (MENU_list):
done = menu_event_list (menu.focus, &event);
break;
}
}
}
menu.focusto -= timediff;
if (menu.focusto <= 0.0f) {
menu.focusto = MENU_FOCUSVIS_BLINKTO;
menu.focusvis = !menu.focusvis;
menu_draw_menuitem (menu.focus);
}
s_calctimesync (); s_calctimesync ();
} }
menu_looprunning = 0; menu->looprunning = 0;
if (reorder) { if (reorder) {
menu.focus->changed = 1; menu->focus->changed = 1;
return -2; return -2;
} }
return menu.focus->id; return (done == -1) ? -1 : menu->focus->id;
}; };
@ -544,14 +567,15 @@ menu_dir_select (char *title, char *path, signed char dirflags)
int flcnt, int flcnt,
menuselect; menuselect;
_charlist *selfile = NULL; _charlist *selfile = NULL;
_menu *menu;
flcnt = menu_create_dirlist (path, dirflags, flist, MAX_DIRENTRYS); flcnt = menu_create_dirlist (path, dirflags, flist, MAX_DIRENTRYS);
menu_new (title, 300, 300); menu = menu_new (title, 300, 300);
menu_create_list ("Dir", -1, 50, 200, 200, flist, &selfile, 1); menu_create_list (menu, "Dir", -1, 50, 200, 200, flist, &selfile, 1);
menu_create_button ("OK", -1, 270, 150, 0); menu_create_button (menu, "OK", -1, 270, 150, 0);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
if (menuselect < 0 || selfile - &flist[0] < 0 || selfile - &flist[0] >= flcnt) if (menuselect < 0 || selfile - &flist[0] < 0 || selfile - &flist[0] >= flcnt)
return NULL; return NULL;
@ -563,35 +587,37 @@ menu_dir_select (char *title, char *path, signed char dirflags)
/* display a message on the screen and wait untill ESC is pressed */ /* display a message on the screen and wait untill ESC is pressed */
void void
menu_displaymessage (char *title, char *fmt,...) menu_displaymessage (char *title, char *fmt, ...)
{ {
va_list args; va_list args;
int maxlinelen = 0, // max y size for the window int maxlinelen = 0, // max y size for the window
i, i,
linenr; linenr;
char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)]; char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)];
char *lines[MENU_MESSAGES_MAXLINES+1]; // textlines for the screen char *lines[MENU_MESSAGES_MAXLINES + 1]; // textlines for the screen
char text[512]; char text[512];
_menu *menu;
/* read the whole text and convert it to a normal char text */
memset (text, 0, sizeof (text)); /* read the whole text and convert it to a normal char text */
memset (out, 0, sizeof (out)); memset (text, 0, sizeof (text));
va_start (args, fmt); memset (out, 0, sizeof (out));
vsprintf (text, fmt, args); va_start (args, fmt);
va_end (args); vsprintf (text, fmt, args);
va_end (args);
menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN, MENU_MESSAGES_MAXLINES);
menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN,
i = maxlinelen * font[0].size.x + 32; MENU_MESSAGES_MAXLINES);
if (i < (strlen (title) * font[2].size.x + 16))
i = strlen (title) * font[2].size.x + 16; i = maxlinelen * font[0].size.x + 32;
menu_new (title, i , linenr * font[0].size.y + 75); if (i < (strlen (title) * font[2].size.x + 16))
i = strlen (title) * font[2].size.x + 16;
for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++) menu = menu_new (title, i, linenr * font[0].size.y + 75);
menu_create_label (lines[i], -1, 55 + i * font[0].size.y, 0, COLOR_brown);
menu_loop (); for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++)
menu_delete (); menu_create_label (menu, lines[i], -1, 55 + i * font[0].size.y, 0, COLOR_brown);
menu_loop (menu);
menu_delete (menu);
}; };
/* format messages to seperated lines /* format messages to seperated lines
@ -602,85 +628,128 @@ menu_displaymessage (char *title, char *fmt,...)
* maxlinelen - returen the max lenght of chars used in one line * maxlinelen - returen the max lenght of chars used in one line
* max_chars - max number of chars in one line * max_chars - max number of chars in one line
* max_lines - max number of lines to use (start must olh one pointer more) */ * max_lines - max number of lines to use (start must olh one pointer more) */
void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars, int max_lines) { void
int i, pos, outpos; menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars,
char *tmpchar1, *tmpchar2; int max_lines)
*maxlinelen = i = pos = outpos = *lines = 0; {
start[0] = out; int i,
pos,
/* create all lines and do some word wrapping */ outpos;
do { char *tmpchar1,
if (input[i] == ' ') { // new word check if there is still space left for another word *tmpchar2;
/* check what will be found first #13 or space */ *maxlinelen = i = pos = outpos = *lines = 0;
tmpchar1 = strchr (&input[i+1], ' '); start[0] = out;
tmpchar2 = strchr (&input[i+1], '\n');
if (tmpchar2 != NULL && tmpchar2 < tmpchar1) /* create all lines and do some word wrapping */
tmpchar1 = tmpchar2; do {
if (tmpchar1 == NULL) if (input[i] == ' ') { // new word check if there is still space left for another word
tmpchar1 = input + strlen (input); /* check what will be found first #13 or space */
tmpchar1 = strchr (&input[i + 1], ' ');
if (tmpchar1 - (&input[i] - pos) >= max_chars) { /* new line */ tmpchar2 = strchr (&input[i + 1], '\n');
out[outpos++] = 0; if (tmpchar2 != NULL && tmpchar2 < tmpchar1)
start[++(*lines)] = &out[outpos]; tmpchar1 = tmpchar2;
if (pos > *maxlinelen) if (tmpchar1 == NULL)
*maxlinelen = pos; tmpchar1 = input + strlen (input);
pos = 0;
} if (tmpchar1 - (&input[i] - pos) >= max_chars) { /* new line */
else /* add this to the line */ out[outpos++] = 0;
out[outpos++] = input[i]; start[++(*lines)] = &out[outpos];
pos++; if (pos > *maxlinelen)
} *maxlinelen = pos;
else if (input[i] == '\n') { pos = 0;
out[outpos++] = 0; }
start[++(*lines)] = &out[outpos]; else /* add this to the line */
if (pos > *maxlinelen) out[outpos++] = input[i];
*maxlinelen = pos; pos++;
pos = 0; }
} else if (input[i] == '\n') {
else { /* copy the text */ out[outpos++] = 0;
out[outpos++] = input[i]; start[++(*lines)] = &out[outpos];
pos++; if (pos > *maxlinelen)
} *maxlinelen = pos;
i++; pos = 0;
} while (i < strlen (input) && i < max_lines * (max_chars + 1) && *lines < max_lines); }
else { /* copy the text */
out[outpos++] = input[i];
pos++;
}
i++;
} while (i < strlen (input) && i < max_lines * (max_chars + 1) && *lines < max_lines);
}; };
/* display a text on the screen and return */ /* display a text on the screen and return */
void void
menu_displaytext (char *title, char *fmt,...) menu_displaytext (char *title, char *fmt, ...)
{ {
va_list args; va_list args;
int maxlinelen = 0, // max y size for the window int maxlinelen = 0, // max y size for the window
i, i,
linenr; linenr;
char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)]; char out[MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1)];
char *lines[MENU_MESSAGES_MAXLINES+1]; // textlines for the screen char *lines[MENU_MESSAGES_MAXLINES + 1]; // textlines for the screen
char text[512]; char text[512];
_menu *menu;
/* read the whole text and convert it to a normal char text */
memset (text, 0, sizeof (text)); /* read the whole text and convert it to a normal char text */
memset (out, 0, sizeof (out)); memset (text, 0, sizeof (text));
va_start (args, fmt); memset (out, 0, sizeof (out));
vsprintf (text, fmt, args); va_start (args, fmt);
va_end (args); vsprintf (text, fmt, args);
va_end (args);
menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN, MENU_MESSAGES_MAXLINES);
menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN,
i = maxlinelen * font[0].size.x + 32; MENU_MESSAGES_MAXLINES);
if (i < (strlen (title) * font[2].size.x + 16))
i = strlen (title) * font[2].size.x + 16; i = maxlinelen * font[0].size.x + 32;
menu_new (title, i , linenr * font[0].size.y + 75); if (i < (strlen (title) * font[2].size.x + 16))
for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++) i = strlen (title) * font[2].size.x + 16;
menu_create_label (lines[i], -1, 55 + i * font[0].size.y, 0, COLOR_brown); menu = menu_new (title, i, linenr * font[0].size.y + 75);
menu_looprunning = 1; for (i = 0; (i <= linenr && i < MENU_MESSAGES_MAXLINES); i++)
menu_draw (); menu_create_label (menu, lines[i], -1, 55 + i * font[0].size.y, 0, COLOR_brown);
menu->looprunning = 1;
menu_draw (menu);
gfx_blitdraw (); gfx_blitdraw ();
SDL_FreeSurface (menu.oldscreen); SDL_FreeSurface (menu->oldscreen);
menu.oldscreen = NULL; menu->oldscreen = NULL;
menuitems[0].next = NULL; menu->menuitems[0].next = NULL;
menu.items = NULL; menu->items = NULL;
menu_looprunning = 0; menu->looprunning = 0;
gfx_blitdraw (); gfx_blitdraw ();
}; };
/*
* find the first free item
*/
_menuitem *
menuitem_findfree (_menu * menu)
{
_menuitem *menuitems = menu->items;
if (menuitems == NULL) { /* this is the first element */
menu->items = &menu->menuitems[0];
menuitems = menu->items;
menuitems->type = MENU_none;
menuitems->next = NULL;
}
else {
/* find first empty element or the last one */
for (;
(menuitems->type != MENU_none) && (menuitems->next != NULL)
&& ((menuitems - menu->items) < MENU_MAXENTRYS); menuitems++);
if (menuitems - menu->items >= MENU_MAXENTRYS) {
d_fatal ("menu_create_label: MENU_MAXENTRYS reached. Item Ignored\n");
return NULL;
}
else if (menuitems->type != MENU_none) {
/* letzte Element */
menuitems->next = menuitems + 1;
menuitems++;
menuitems->next = NULL;
menuitems->type = MENU_none;
}
}
return menuitems;
};

@ -1,4 +1,4 @@
/* $Id: menubools.c,v 1.1 2003/12/24 02:42:05 stpohle Exp $ /* $Id: menubools.c,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: bools */ * Menuhandling: bools */
#include "basic.h" #include "basic.h"
@ -9,33 +9,24 @@
/* create a bool only in the menudatas.. darf all this only when menu_loop /* create a bool only in the menudatas.. darf all this only when menu_loop
* is called */ * is called */
void menu_create_bool (char *name, int x, int y, int w, int *data, int id) { _menuitem *menu_create_bool (_menu *menu, char *name, int x, int y, int w, int *data, int id) {
int i = menu_getlastitem(menu.items); _menuitem *m = menuitem_findfree (menu);
if (m == NULL) return NULL;
if (i == -1) { /* first entry in the itemslist */
menu.items = &menuitems[0];
i = 0;
}
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */
d_fatal ("menu_create_button: MENU_MAXENTRYS reached. Item Ignored\n");
return;
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].type = MENU_bool; m->type = MENU_bool;
menuitems[i].pos.w = (1 + (int)((w - menu.buttonimages[0][0]->w - menu.buttonimages[0][2]->w) / menu.buttonimages[0][1]->w)) * menu.buttonimages[0][1]->w + menu.buttonimages[0][0]->w + menu.buttonimages[0][2]->w; m->pos.w = (1 + (int)((w - menubuttonimages[0][0]->w - menubuttonimages[0][2]->w) / menubuttonimages[0][1]->w)) * menubuttonimages[0][1]->w + menubuttonimages[0][0]->w + menubuttonimages[0][2]->w;
if (x != -1) if (x != -1)
menuitems[i].pos.x = x; m->pos.x = x;
else else
menuitems[i].pos.x = (menu.oldscreenpos.w - 2 * menu.images[0]->w - menuitems[i].pos.w) / 2; m->pos.x = (menu->oldscreenpos.w - 2 * menuimages[0]->w - m->pos.w) / 2;
menuitems[i].pos.y = y; m->pos.y = y;
menuitems[i].state = 0; m->state = 0;
menuitems[i].id = id; m->id = id;
menuitems[i].ptrdata = (char *)data; m->ptrdata = (char *)data;
strncpy (menuitems[i].label, name, MENU_TITLELEN); strncpy (m->label, name, MENU_TITLELEN);
return m;
}; };
@ -46,9 +37,9 @@ int menu_event_bool (_menuitem *mi, SDL_Event *event) {
switch (event->type) { switch (event->type) {
case (SDL_KEYDOWN): /* key was pressed */ case (SDL_KEYDOWN): /* key was pressed */
if (event->key.keysym.sym == SDLK_LEFT || event->key.keysym.sym == SDLK_UP) if (event->key.keysym.sym == SDLK_LEFT || event->key.keysym.sym == SDLK_UP)
menu_focus_prev (); menu_focus_prev ((_menu *) mi->menu);
else if (event->key.keysym.sym == SDLK_RIGHT || event->key.keysym.sym == SDLK_DOWN) else if (event->key.keysym.sym == SDLK_RIGHT || event->key.keysym.sym == SDLK_DOWN)
menu_focus_next (); menu_focus_next ((_menu *) mi->menu);
else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_LCTRL || event->key.keysym.sym == SDLK_RCTRL) { else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_LCTRL || event->key.keysym.sym == SDLK_RCTRL) {
*(int *)mi->ptrdata = !(*(int *)mi->ptrdata); *(int *)mi->ptrdata = !(*(int *)mi->ptrdata);
menu_draw_bool (mi); menu_draw_bool (mi);

@ -1,4 +1,4 @@
/* $Id: menubuttons.c,v 1.1 2003/12/24 02:42:05 stpohle Exp $ /* $Id: menubuttons.c,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: buttons */ * Menuhandling: buttons */
#include "basic.h" #include "basic.h"
@ -9,32 +9,22 @@
/* create a button only in the menudatas.. darf all this only when menu_loop /* create a button only in the menudatas.. darf all this only when menu_loop
* is called */ * is called */
void menu_create_button (char *name, int x, int y, int w, int id) { _menuitem *menu_create_button (_menu *menu, char *name, int x, int y, int w, int id) {
int i = menu_getlastitem(menu.items); _menuitem *m = menuitem_findfree (menu);
if (m == NULL) return NULL;
if (i == -1) { /* first entry in the itemslist */
menu.items = &menuitems[0]; m->type = MENU_button;
i = 0; m->pos.w = (1 + (int)((w - menubuttonimages[0][0]->w - menubuttonimages[0][2]->w) / menubuttonimages[0][1]->w)) * menubuttonimages[0][1]->w + menubuttonimages[0][0]->w + menubuttonimages[0][2]->w;
}
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */
d_fatal ("menu_create_button: MENU_MAXENTRYS reached. Item Ignored\n");
return;
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].type = MENU_button;
menuitems[i].pos.w = (1 + (int)((w - menu.buttonimages[0][0]->w - menu.buttonimages[0][2]->w) / menu.buttonimages[0][1]->w)) * menu.buttonimages[0][1]->w + menu.buttonimages[0][0]->w + menu.buttonimages[0][2]->w;
if (x != -1) if (x != -1)
menuitems[i].pos.x = x; m->pos.x = x;
else else
menuitems[i].pos.x = (menu.oldscreenpos.w - 2 * menu.images[0]->w - menuitems[i].pos.w) / 2; m->pos.x = (menu->oldscreenpos.w - 2 * menuimages[0]->w - m->pos.w) / 2;
menuitems[i].pos.y = y; m->pos.y = y;
menuitems[i].state = 0; m->state = 0;
menuitems[i].id = id; m->id = id;
strncpy (menuitems[i].label, name, MENU_TITLELEN); strncpy (m->label, name, MENU_TITLELEN);
return m;
}; };
@ -52,11 +42,11 @@ void menu_draw_button (_menuitem *mi) {
dest.x = mi->pos.x; dest.x = mi->pos.x;
dest.y = mi->pos.y; dest.y = mi->pos.y;
dest.w = mi->pos.w; dest.w = mi->pos.w;
dest.h = menu.buttonimages[0][0]->h; dest.h = menubuttonimages[0][0]->h;
menu_draw_background (&dest); menu_draw_background ((_menu *)mi->menu, &dest);
/* check the focus of the button */ /* check the focus of the button */
if (menu.focusvis && mi == menu.focus) if (((_menu *)mi->menu)->focusvis && mi == ((_menu *)mi->menu)->focus)
mi->state = 1; mi->state = 1;
else if (mi->type == MENU_bool && (*((int*) mi->ptrdata)) > 0) else if (mi->type == MENU_bool && (*((int*) mi->ptrdata)) > 0)
mi->state = 2; // bool mi->state = 2; // bool
@ -64,34 +54,34 @@ void menu_draw_button (_menuitem *mi) {
mi->state = 0; // button or bool == FALSE mi->state = 0; // button or bool == FALSE
// draw the left side of the button // draw the left side of the button
dest.x = MENUOFFSET_X + mi->pos.x; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.buttonimages[mi->state][0]->w; dest.w = menubuttonimages[mi->state][0]->w;
dest.h = menu.buttonimages[mi->state][0]->h; dest.h = menubuttonimages[mi->state][0]->h;
gfx_blit (menu.buttonimages[mi->state][0], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[mi->state][0], NULL, gfx.screen, &dest, 10000);
// draw the center of the button // draw the center of the button
for (i = 0; i < ((mi->pos.w - (menu.buttonimages[mi->state][0]->w + menu.buttonimages[mi->state][2]->w)) / menu.buttonimages[mi->state][1]->w); i++) { for (i = 0; i < ((mi->pos.w - (menubuttonimages[mi->state][0]->w + menubuttonimages[mi->state][2]->w)) / menubuttonimages[mi->state][1]->w); i++) {
dest.x = MENUOFFSET_X + mi->pos.x + menu.buttonimages[mi->state][0]->w + (i * menu.buttonimages[mi->state][1]->w); dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + menubuttonimages[mi->state][0]->w + (i * menubuttonimages[mi->state][1]->w);
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.buttonimages[mi->state][1]->w; dest.w = menubuttonimages[mi->state][1]->w;
dest.h = menu.buttonimages[mi->state][1]->h; dest.h = menubuttonimages[mi->state][1]->h;
gfx_blit (menu.buttonimages[mi->state][1], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[mi->state][1], NULL, gfx.screen, &dest, 10000);
} }
// draw the right side of the button // draw the right side of the button
dest.x = MENUOFFSET_X + mi->pos.x + mi->pos.w - menu.buttonimages[mi->state][2]->w; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + mi->pos.w - menubuttonimages[mi->state][2]->w;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.buttonimages[mi->state][2]->w; dest.w = menubuttonimages[mi->state][2]->w;
dest.h = menu.buttonimages[mi->state][2]->h; dest.h = menubuttonimages[mi->state][2]->h;
gfx_blit (menu.buttonimages[mi->state][2], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[mi->state][2], NULL, gfx.screen, &dest, 10000);
// calculate the center of the button // calculate the center of the button
px = (mi->pos.w - (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x)) / 2 + mi->pos.x; px = (mi->pos.w - (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x)) / 2 + mi->pos.x;
py = (menu.buttonimages[mi->state][0]->h - font[MENU_BUTTON_FONTSIZE].size.y) / 2 + mi->pos.y; py = (menubuttonimages[mi->state][0]->h - font[MENU_BUTTON_FONTSIZE].size.y) / 2 + mi->pos.y;
if (mi->type == MENU_bool && mi->state == 2) // disabled bool == FALSE if (mi->type == MENU_bool && mi->state == 2) // disabled bool == FALSE
font_gfxdraw (MENUOFFSET_X + px, MENUOFFSET_Y + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_black, 10000); font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + px, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_black, 10000);
else else
font_gfxdraw (MENUOFFSET_X + px, MENUOFFSET_Y + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000); font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + px, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000);
}; };
@ -102,9 +92,9 @@ int menu_event_button (_menuitem *mi, SDL_Event *event) {
switch (event->type) { switch (event->type) {
case (SDL_KEYDOWN): /* key was pressed */ case (SDL_KEYDOWN): /* key was pressed */
if (event->key.keysym.sym == SDLK_LEFT || event->key.keysym.sym == SDLK_UP) if (event->key.keysym.sym == SDLK_LEFT || event->key.keysym.sym == SDLK_UP)
menu_focus_prev (); menu_focus_prev ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_RIGHT || event->key.keysym.sym == SDLK_DOWN) else if (event->key.keysym.sym == SDLK_RIGHT || event->key.keysym.sym == SDLK_DOWN)
menu_focus_next (); menu_focus_next ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_LCTRL || event->key.keysym.sym == SDLK_RCTRL) else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_LCTRL || event->key.keysym.sym == SDLK_RCTRL)
return 1; return 1;
break; break;

@ -1,4 +1,4 @@
/* $Id: menuentrys.c,v 1.3 2003/12/28 01:21:43 stpohle Exp $ /* $Id: menuentrys.c,v 1.4 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: entry */ * Menuhandling: entry */
@ -51,48 +51,35 @@ void menu_entry_restore (_menuitem *mi) {
/* create a entryimages only in the menudatas.. darf all this only when menu_loop /* create a entryimages only in the menudatas.. darf all this only when menu_loop
* is called */ * is called */
void menu_create_entry (char *name, int x, int y, int w, void *data, int len, int typ, int id) { _menuitem *menu_create_entry (_menu *menu, char *name, int x, int y, int w, void *data, int len, int typ, int id) {
int i = menu_getlastitem(menu.items); _menuitem *m = menuitem_findfree (menu);
if (m == NULL) return NULL;
if (typ != MENU_entrytext && typ != MENU_entryint16 && typ != MENU_entryint32 && typ != MENU_entryfloat)
return;
if (i == -1) { /* first entry in the itemslist */
menu.items = &menuitems[0];
i = 0;
}
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */
d_fatal ("menu_create_entry: MENU_MAXENTRYS reached. Item Ignored\n");
return;
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].type = typ; m->type = typ;
menuitems[i].pos.w = (1 + (int)((w - (strlen (name) * font[MENU_BUTTON_FONTSIZE].size.x) - 8 - menu.entryimages[0][0]->w - menu.entryimages[0][2]->w) / menu.entryimages[0][1]->w)) * menu.entryimages[0][1]->w + menu.entryimages[0][0]->w + menu.entryimages[0][2]->w + (strlen (name) * font[MENU_BUTTON_FONTSIZE].size.x) + 8; m->pos.w = (1 + (int)((w - (strlen (name) * font[MENU_BUTTON_FONTSIZE].size.x) - 8 - menuentryimages[0][0]->w - menuentryimages[0][2]->w) / menuentryimages[0][1]->w)) * menuentryimages[0][1]->w + menuentryimages[0][0]->w + menuentryimages[0][2]->w + (strlen (name) * font[MENU_BUTTON_FONTSIZE].size.x) + 8;
if (x != -1) if (x != -1)
menuitems[i].pos.x = x; m->pos.x = x;
else else
menuitems[i].pos.x = (menu.oldscreenpos.w - 2 * menu.images[0]->w - menuitems[i].pos.w) / 2; m->pos.x = (menu->oldscreenpos.w - 2 * menuimages[0]->w - m->pos.w) / 2;
menuitems[i].pos.y = y; m->pos.y = y;
menuitems[i].len = len; m->len = len;
menuitems[i].ptrdata = (char *) data; m->ptrdata = (char *) data;
menuitems[i].id = id; m->id = id;
strncpy (menuitems[i].label, name, MENU_TITLELEN); strncpy (m->label, name, MENU_TITLELEN);
if (typ == MENU_entrytext) if (typ == MENU_entrytext)
keybinput_new (&menuitems[i].keybi, KEYBI_text, len); keybinput_new (&m->keybi, KEYBI_text, len);
else if (typ == MENU_entryint16) else if (typ == MENU_entryint16)
keybinput_new (&menuitems[i].keybi, KEYBI_int, len); keybinput_new (&m->keybi, KEYBI_int, len);
else if (typ == MENU_entryint32) else if (typ == MENU_entryint32)
keybinput_new (&menuitems[i].keybi, KEYBI_int, len); keybinput_new (&m->keybi, KEYBI_int, len);
else else
keybinput_new (&menuitems[i].keybi, KEYBI_float, 10); keybinput_new (&m->keybi, KEYBI_float, 10);
menu_entry_restore (m);
menu_entry_restore (&menuitems[i]); return m;
}; };
@ -110,45 +97,45 @@ void menu_draw_entry (_menuitem *mi) {
dest.x = mi->pos.x; dest.x = mi->pos.x;
dest.y = mi->pos.y; dest.y = mi->pos.y;
dest.w = mi->pos.w; dest.w = mi->pos.w;
dest.h = menu.entryimages[0][0]->h; dest.h = menuentryimages[0][0]->h;
menu_draw_background (&dest); menu_draw_background (((_menu *) mi->menu), &dest);
/* check the focus of the button */ /* check the focus of the button */
if (menu.focusvis && mi == menu.focus) if (((_menu *) mi->menu)->focusvis && mi == ((_menu *) mi->menu)->focus)
mi->state = 1; mi->state = 1;
else else
mi->state = 0; mi->state = 0;
// draw the left side of the button // draw the left side of the button
dest.x = MENUOFFSET_X + mi->pos.x + (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.entryimages[mi->state][0]->w; dest.w = menuentryimages[mi->state][0]->w;
dest.h = menu.entryimages[mi->state][0]->h; dest.h = menuentryimages[mi->state][0]->h;
gfx_blit (menu.entryimages[mi->state][0], NULL, gfx.screen, &dest, 10000); gfx_blit (menuentryimages[mi->state][0], NULL, gfx.screen, &dest, 10000);
/* draw the center of the button /* draw the center of the button
* checkt first if there is something wrong */ * checkt first if there is something wrong */
if (mi->pos.w < ((strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8) - (menu.entryimages[mi->state][0]->w + menu.entryimages[mi->state][2]->w)) if (mi->pos.w < ((strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8) - (menuentryimages[mi->state][0]->w + menuentryimages[mi->state][2]->w))
d_fatal ("menuentry Error with Element: %s\n", mi->label); d_fatal ("menuentry Error with Element: %s\n", mi->label);
else else
for (i = 0; i < ((mi->pos.w - ((strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8) - (menu.entryimages[mi->state][0]->w + menu.entryimages[mi->state][2]->w)) / menu.entryimages[mi->state][1]->w); i++) { for (i = 0; i < ((mi->pos.w - ((strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8) - (menuentryimages[mi->state][0]->w + menuentryimages[mi->state][2]->w)) / menuentryimages[mi->state][1]->w); i++) {
dest.x = MENUOFFSET_X + mi->pos.x + (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8 + menu.entryimages[mi->state][0]->w + (i * menu.entryimages[mi->state][1]->w); dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8 + menuentryimages[mi->state][0]->w + (i * menuentryimages[mi->state][1]->w);
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.entryimages[mi->state][1]->w; dest.w = menuentryimages[mi->state][1]->w;
dest.h = menu.entryimages[mi->state][1]->h; dest.h = menuentryimages[mi->state][1]->h;
gfx_blit (menu.entryimages[mi->state][1], NULL, gfx.screen, &dest, 10000); gfx_blit (menuentryimages[mi->state][1], NULL, gfx.screen, &dest, 10000);
} }
// draw the right side of the button // draw the right side of the button
dest.x = MENUOFFSET_X + mi->pos.x + mi->pos.w - menu.entryimages[mi->state][2]->w; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + mi->pos.w - menuentryimages[mi->state][2]->w;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.entryimages[mi->state][2]->w; dest.w = menuentryimages[mi->state][2]->w;
dest.h = menu.entryimages[mi->state][2]->h; dest.h = menuentryimages[mi->state][2]->h;
gfx_blit (menu.entryimages[mi->state][2], NULL, gfx.screen, &dest, 10000); gfx_blit (menuentryimages[mi->state][2], NULL, gfx.screen, &dest, 10000);
// calculate the center of the button // calculate the center of the button
px = (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8 + (mi->pos.w - (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) - 8 - (strlen (mi->keybi.text) * font[MENU_BUTTON_FONTSIZE].size.x)) / 2 + mi->pos.x; px = (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) + 8 + (mi->pos.w - (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x) - 8 - (strlen (mi->keybi.text) * font[MENU_BUTTON_FONTSIZE].size.x)) / 2 + mi->pos.x;
py = (menu.entryimages[mi->state][0]->h - font[MENU_BUTTON_FONTSIZE].size.y) / 2 + mi->pos.y; py = (menuentryimages[mi->state][0]->h - font[MENU_BUTTON_FONTSIZE].size.y) / 2 + mi->pos.y;
font_gfxdraw (MENUOFFSET_X + px, MENUOFFSET_Y + py, mi->keybi.text, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000); font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + px, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->keybi.text, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000);
font_gfxdraw (MENUOFFSET_X + mi->pos.x, MENUOFFSET_Y + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000); font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000);
}; };
@ -160,9 +147,9 @@ int menu_event_entry (_menuitem *mi, SDL_Event *event) {
switch (event->type) { switch (event->type) {
case (SDL_KEYDOWN): /* key was pressed */ case (SDL_KEYDOWN): /* key was pressed */
if (event->key.keysym.sym == SDLK_UP) if (event->key.keysym.sym == SDLK_UP)
menu_focus_prev (); menu_focus_prev ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_DOWN) else if (event->key.keysym.sym == SDLK_DOWN)
menu_focus_next (); menu_focus_next ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_RCTRL || event->key.keysym.sym == SDLK_RCTRL) else if (event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_RCTRL || event->key.keysym.sym == SDLK_RCTRL)
menu_entry_save (mi); menu_entry_save (mi);
else if (event->key.keysym.sym == SDLK_ESCAPE) else if (event->key.keysym.sym == SDLK_ESCAPE)

@ -1,4 +1,4 @@
/* $Id: menuimages.c,v 1.1 2004/02/07 13:35:28 stpohle Exp $ /* $Id: menuimages.c,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: labels */ * Menuhandling: labels */
#include "basic.h" #include "basic.h"
@ -14,16 +14,17 @@
*/ */
void menu_draw_image (_menuitem *mi) { void menu_draw_image (_menuitem *mi) {
SDL_Rect src, dest; SDL_Rect src, dest;
_menu *menu = (_menu *) mi->menu;
if (mi->type != MENU_image) if (mi->type != MENU_image)
return; return;
if (mi->pos.x == -1) if (mi->pos.x == -1)
dest.x = (menu.oldscreenpos.w - 2*menu.images[0]->w - mi->rect.w) / 2; dest.x = (menu->oldscreenpos.w - 2*menuimages[0]->w - mi->rect.w) / 2;
else else
dest.x = mi->pos.x; dest.x = mi->pos.x;
if (mi->pos.y == -1) if (mi->pos.y == -1)
dest.y = (menu.oldscreenpos.h - 2*menu.images[0]->h - mi->rect.h) / 2; dest.y = (menu->oldscreenpos.h - 2*menuimages[0]->h - mi->rect.h) / 2;
else else
dest.y = mi->pos.y; dest.y = mi->pos.y;
@ -31,34 +32,24 @@ void menu_draw_image (_menuitem *mi) {
src.h = dest.h = mi->rect.h; src.h = dest.h = mi->rect.h;
src.x = mi->rect.x; src.x = mi->rect.x;
src.y = mi->rect.y; src.y = mi->rect.y;
dest.x += menu.oldscreenpos.x + menu.images[0]->w; dest.x += menu->oldscreenpos.x + menuimages[0]->w;
dest.y += menu.oldscreenpos.y + menu.images[0]->h; dest.y += menu->oldscreenpos.y + menuimages[0]->h;
gfx_blit ((SDL_Surface *) mi->ptrdata, &src, gfx.screen, &dest, 10000+mi->pos.w); gfx_blit ((SDL_Surface *) mi->ptrdata, &src, gfx.screen, &dest, 10000+mi->pos.w);
}; };
void menu_create_image (char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect) { _menuitem *menu_create_image (_menu *menu, char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect) {
int i = menu_getlastitem(menu.items); _menuitem *menuitems = menuitem_findfree (menu);
if (menuitems == NULL) return NULL;
if (i == -1) { /* first entry in the itemslist */
menu.items = &menuitems[0]; menuitems->pos.x = x;
i = 0; menuitems->pos.y = y;
} menuitems->pos.w = layer;
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */ menuitems->type = MENU_image;
d_fatal ("menu_create_image: MENU_MAXENTRYS reached. Item Ignored\n"); menuitems->ptrdata = (char *) img;
return; menuitems->rect = *rect;
} strncpy (menuitems->label, name, MENU_TITLELEN);
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1]; return menuitems;
i++;
}
menuitems[i].pos.x = x;
menuitems[i].pos.y = y;
menuitems[i].pos.w = layer;
menuitems[i].type = MENU_image;
menuitems[i].ptrdata = (char *) img;
menuitems[i].rect = *rect;
strncpy (menuitems[i].label, name, MENU_TITLELEN);
}; };

@ -1,4 +1,4 @@
/* $Id: menulabels.c,v 1.4 2004/02/07 15:03:25 stpohle Exp $ /* $Id: menulabels.c,v 1.5 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: labels */ * Menuhandling: labels */
#include "basic.h" #include "basic.h"
@ -14,50 +14,45 @@
*/ */
void menu_draw_label (_menuitem *mi) { void menu_draw_label (_menuitem *mi) {
int dx, dy; int dx, dy;
_menu *menu = (_menu *)mi->menu;
if (mi->type != MENU_label) if (mi->type != MENU_label)
return; return;
if (mi->pos.x == -1) if (mi->pos.x == -1)
dx = (menu.oldscreenpos.w - 2*menu.images[0]->w - (strlen (mi->label) * font[mi->pos.w].size.x)) / 2; dx = (menu->oldscreenpos.w - 2*menuimages[0]->w - (strlen (mi->label) * font[mi->pos.w].size.x)) / 2;
else else
dx = mi->pos.x; dx = mi->pos.x;
if (mi->pos.y == -1) if (mi->pos.y == -1)
dy = (menu.oldscreenpos.h - 2*menu.images[0]->h - font[mi->pos.w].size.y) / 2; dy = (menu->oldscreenpos.h - 2*menuimages[0]->h - font[mi->pos.w].size.y) / 2;
else else
dy = mi->pos.y; dy = mi->pos.y;
font_gfxdraw (menu.oldscreenpos.x + menu.images[0]->w + dx, menu.oldscreenpos.y + menu.images[0]->h + dy, mi->label, mi->pos.w, mi->pos.h, 10000); font_gfxdraw (menu->oldscreenpos.x + menuimages[0]->w + dx, menu->oldscreenpos.y + menuimages[0]->h + dy, mi->label, mi->pos.w, mi->pos.h, 10000);
}; };
void menu_create_label (char *name, int x, int y, int fontsize, int fontcolor) { _menuitem *menu_create_label (_menu *menu, char *name, int x, int y, int fontsize, int fontcolor) {
int i = menu_getlastitem(menu.items); _menuitem *menuitems = menuitem_findfree (menu);
if (menuitems == NULL) return NULL;
if (i == -1) { /* first entry in the itemslist */
menu.items = &menuitems[0]; menuitems->pos.x = x;
i = 0; menuitems->pos.y = y;
} menuitems->pos.w = fontsize;
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */ menuitems->pos.h = fontcolor;
d_fatal ("menu_create_label: MENU_MAXENTRYS reached. Item Ignored\n"); menuitems->type = MENU_label;
return; strncpy (menuitems->label, name, MENU_TITLELEN);
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].pos.x = x; return menuitems;
menuitems[i].pos.y = y;
menuitems[i].pos.w = fontsize;
menuitems[i].pos.h = fontcolor;
menuitems[i].type = MENU_label;
strncpy (menuitems[i].label, name, MENU_TITLELEN);
}; };
/* this will wrap a text into more labels */ /*
void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, int fontcolor, char *fmt,...) { * this will wrap a text into more labels,
* in this function we are not able to return
* any pointer
*/
void menu_create_text (_menu *menu, char *name, int x, int y, int maxlen, int maxlines, int fontcolor, char *fmt,...) {
char text[1024]; char text[1024];
char out[1024]; char out[1024];
char *lineptr[maxlines+1]; char *lineptr[maxlines+1];
@ -73,5 +68,5 @@ void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, int f
menu_formattext (text, out, lineptr, &linecnt, &maxchar, maxlen, maxlines); menu_formattext (text, out, lineptr, &linecnt, &maxchar, maxlen, maxlines);
for (i = 0; (i <= linecnt && i < maxlines); i++) for (i = 0; (i <= linecnt && i < maxlines); i++)
menu_create_label (lineptr[i], x, y + i * font[0].size.y, 0, fontcolor); menu_create_label (menu, lineptr[i], x, y + i * font[0].size.y, 0, fontcolor);
}; };

@ -1,4 +1,4 @@
/* $Id: menulists.c,v 1.3 2004/02/02 23:30:35 patty21 Exp $ /* $Id: menulists.c,v 1.4 2004/05/20 16:55:30 stpohle Exp $
* Menuhandling: lists */ * Menuhandling: lists */
@ -11,39 +11,30 @@
/* create a entryimages only in the menudatas.. darf all this only when menu_loop /* create a entryimages only in the menudatas.. darf all this only when menu_loop
* is called */ * is called */
void menu_create_list (char *name, int x, int y, int w, int h, _charlist *data, _charlist **selected, int id) { _menuitem *menu_create_list (_menu *menu, char *name, int x, int y, int w, int h, _charlist *data, _charlist **selected, int id) {
int i = menu_getlastitem(menu.items); _menuitem *menuitems = menuitem_findfree (menu);
if (i == -1) { /* first entry in the itemslist */ if (menuitems == NULL) return NULL;
menu.items = &menuitems[0];
i = 0;
}
else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */
d_fatal ("menu_create_entry: MENU_MAXENTRYS reached. Item Ignored\n");
return;
}
else { /* add new item to the list */
menuitems[i].next = &menuitems[i+1];
i++;
}
menuitems[i].type = MENU_list; menuitems->type = MENU_list;
menuitems[i].pos.w = (1 + (int) menuitems->pos.w = (1 + (int)
((w - menu.listimages[0][0]->w - menu.listimages[0][2]->w) / menu.listimages[0][1]->w)) ((w - menulistimages[0][0]->w - menulistimages[0][2]->w) / menulistimages[0][1]->w))
* menu.listimages[0][1]->w + menu.listimages[0][0]->w + menu.listimages[0][2]->w; * menulistimages[0][1]->w + menulistimages[0][0]->w + menulistimages[0][2]->w;
menuitems[i].pos.h = (1 + (int) menuitems->pos.h = (1 + (int)
((h - menu.listimages[0][0]->h - menu.listimages[0][6]->h) / menu.listimages[0][3]->h)) ((h - menulistimages[0][0]->h - menulistimages[0][6]->h) / menulistimages[0][3]->h))
* menu.listimages[0][3]->h + menu.listimages[0][0]->h + menu.listimages[0][6]->h; * menulistimages[0][3]->h + menulistimages[0][0]->h + menulistimages[0][6]->h;
if (x != -1) if (x != -1)
menuitems[i].pos.x = x; menuitems->pos.x = x;
else else
menuitems[i].pos.x = (menu.oldscreenpos.w - 2 * menu.images[0]->w - menuitems[i].pos.w) / 2; menuitems->pos.x = (menu->oldscreenpos.w - 2 * menuimages[0]->w - menuitems->pos.w) / 2;
menuitems[i].pos.y = y; menuitems->pos.y = y;
menuitems[i].ptrdata = (char *) selected; menuitems->ptrdata = (char *) selected;
menuitems[i].list = data; menuitems->list = data;
menuitems[i].id = id; menuitems->id = id;
menuitems[i].changed=1; menuitems->changed=1;
strncpy (menuitems[i].label, name, MENU_TITLELEN); strncpy (menuitems->label, name, MENU_TITLELEN);
return menuitems;
}; };
@ -54,38 +45,38 @@ void menu_draw_listbackground (_menuitem *mi, SDL_Rect *updaterect) {
SDL_Rect dest, cdest, src, csrc, window; SDL_Rect dest, cdest, src, csrc, window;
y = 0; // start at the updaterect. start pos y = 0; // start at the updaterect. start pos
for (; y <= (mi->pos.h - 2*menu.listimages[0][0]->h - 1)/menu.listimages[0][4]->h; y++) { for (; y <= (mi->pos.h - 2*menulistimages[0][0]->h - 1)/menulistimages[0][4]->h; y++) {
x = 0; // start at the updaterect. start pos x = 0; // start at the updaterect. start pos
for (; x <= (mi->pos.w - 2*menu.listimages[0][0]->w - 1)/menu.listimages[0][4]->w; x++) { for (; x <= (mi->pos.w - 2*menulistimages[0][0]->w - 1)/menulistimages[0][4]->w; x++) {
dest.x = x * menu.listimages[0][4]->w; // start pos dest.x = x * menulistimages[0][4]->w; // start pos
dest.y = y * menu.listimages[0][4]->h; dest.y = y * menulistimages[0][4]->h;
dx = (1+x) * menu.listimages[0][4]->w; // end pos dx = (1+x) * menulistimages[0][4]->w; // end pos
if (dx >= (mi->pos.w - 2*menu.listimages[0][0]->w)) if (dx >= (mi->pos.w - 2*menulistimages[0][0]->w))
dest.w = menu.listimages[0][4]->w - (dx - (mi->pos.w - 2*menu.listimages[0][0]->w)); dest.w = menulistimages[0][4]->w - (dx - (mi->pos.w - 2*menulistimages[0][0]->w));
else else
dest.w = menu.listimages[0][4]->w; dest.w = menulistimages[0][4]->w;
dy = (1+y) * menu.listimages[0][4]->h; dy = (1+y) * menulistimages[0][4]->h;
if (dy >= (mi->pos.h - 2*menu.listimages[0][0]->h)) if (dy >= (mi->pos.h - 2*menulistimages[0][0]->h))
dest.h = menu.listimages[0][4]->h - (dy - (mi->pos.h - 2*menu.listimages[0][0]->h)); dest.h = menulistimages[0][4]->h - (dy - (mi->pos.h - 2*menulistimages[0][0]->h));
else else
dest.h = menu.listimages[0][4]->h; dest.h = menulistimages[0][4]->h;
if (dest.w > 0 || dest.h > 0) { if (dest.w > 0 || dest.h > 0) {
dest.x += MENUOFFSET_X + mi->pos.x + menu.listimages[0][0]->w; dest.x += MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + menulistimages[0][0]->w;
dest.y += MENUOFFSET_Y + mi->pos.y + menu.listimages[0][0]->h; dest.y += MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + menulistimages[0][0]->h;
src.x = 0; src.y = 0; src.h = dest.h; src.w = dest.w; src.x = 0; src.y = 0; src.h = dest.h; src.w = dest.w;
if (updaterect == NULL) if (updaterect == NULL)
gfx_blit (menu.listimages[0][4], &src, gfx.screen, &dest, 10000); gfx_blit (menulistimages[0][4], &src, gfx.screen, &dest, 10000);
else { else {
window = *updaterect; window = *updaterect;
window.x += MENUOFFSET_X + mi->pos.x + menu.listimages[0][0]->w; window.x += MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + menulistimages[0][0]->w;
window.y += MENUOFFSET_Y + mi->pos.y + menu.listimages[0][0]->h; window.y += MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + menulistimages[0][0]->h;
rect_clipping (&src, &dest, &window, &csrc, &cdest); rect_clipping (&src, &dest, &window, &csrc, &cdest);
if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF && cdest.h < UINT16_HALF) if (csrc.w < UINT16_HALF && csrc.h < UINT16_HALF && cdest.w < UINT16_HALF && cdest.h < UINT16_HALF)
gfx_blit (menu.listimages[1][4], &csrc, gfx.screen, &cdest, 10000); gfx_blit (menulistimages[1][4], &csrc, gfx.screen, &cdest, 10000);
} }
} }
} }
@ -163,8 +154,7 @@ void menu_list_select_next (_menuitem *mi) {
void menu_draw_listtext (_menuitem *mi) { void menu_draw_listtext (_menuitem *mi) {
int count = menu_list_getcount (mi); int count = menu_list_getcount (mi);
int selected = menu_list_getselected (mi); int selected = menu_list_getselected (mi);
int countvis = (mi->pos.h - menu.listimages[0][0]->h - menu.listimages[0][6]->h) int countvis = (mi->pos.h - menulistimages[0][0]->h - menulistimages[0][6]->h) / font[MENU_BUTTON_FONTSIZE].size.y; // number of visible elements
/ font[MENU_BUTTON_FONTSIZE].size.y; // number of visible elements
_charlist *list; _charlist *list;
int maxx, // max chars in X int maxx, // max chars in X
dy, // current y position dy, // current y position
@ -185,23 +175,24 @@ void menu_draw_listtext (_menuitem *mi) {
list = &mi->list[start]; list = &mi->list[start];
/* calculate the max numbers of chars to draw */ /* calculate the max numbers of chars to draw */
maxx = (mi->pos.w - menu.listimages[0][0]->w - menu.listimages[0][2]->w) / font[MENU_BUTTON_FONTSIZE].size.x; maxx = (mi->pos.w - menulistimages[0][0]->w - menulistimages[0][2]->w) / font[MENU_BUTTON_FONTSIZE].size.x;
/* calculate start point (y) */ /* calculate start point (y) */
dy = MENUOFFSET_Y + mi->pos.y + ((mi->pos.h - countvis*font[MENU_BUTTON_FONTSIZE].size.y) / 2); dy = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + ((mi->pos.h - countvis*font[MENU_BUTTON_FONTSIZE].size.y) / 2);
/* draw the elements */ /* draw the elements */
for (;countvis > 0 && list != NULL; countvis--, list = list->next) { for (;countvis > 0 && list != NULL; countvis--, list = list->next) {
/* calculate dx and print only the text which fixs in the list */ /* calculate dx and print only the text which fixs in the list */
strncpy (text, list->text, maxx); strncpy (text, list->text, maxx);
dx = MENUOFFSET_X + mi->pos.x + ((mi->pos.w - strlen (text)*font[MENU_BUTTON_FONTSIZE].size.x) / 2); text[maxx] = 0;
dx = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + ((mi->pos.w - strlen (text)*font[MENU_BUTTON_FONTSIZE].size.x) / 2);
if (mi->ptrdata != NULL && list == *(_charlist **)mi->ptrdata) { if (mi->ptrdata != NULL && list == *(_charlist **)mi->ptrdata) {
// this is the selected element // this is the selected element
wnd.x = menu.listimages[0][0]->w; wnd.x = menulistimages[0][0]->w;
wnd.y = dy - (MENUOFFSET_Y + mi->pos.y + menu.listimages[0][0]->h); wnd.y = dy - (MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + menulistimages[0][0]->h);
wnd.w = mi->pos.w - menu.listimages[0][0]->w - menu.listimages[0][2]->w; wnd.w = mi->pos.w - menulistimages[0][0]->w - menulistimages[0][2]->w;
wnd.h = font[MENU_BUTTON_FONTSIZE].size.y; wnd.h = font[MENU_BUTTON_FONTSIZE].size.y;
menu_draw_listbackground (mi, &wnd); menu_draw_listbackground (mi, &wnd);
font_gfxdraw (dx, dy, text, MENU_BUTTON_FONTSIZE, COLOR_black, 10000); font_gfxdraw (dx, dy, text, MENU_BUTTON_FONTSIZE, COLOR_black, 10000);
@ -229,58 +220,56 @@ void menu_draw_list (_menuitem *mi) {
dest.x = mi->pos.x; dest.x = mi->pos.x;
dest.y = mi->pos.y; dest.y = mi->pos.y;
dest.w = mi->pos.w; dest.w = mi->pos.w;
dest.h = menu.listimages[0][0]->h; dest.h = menulistimages[0][0]->h;
menu_draw_background (&dest); menu_draw_background ((((_menu *)mi->menu)),&dest);
/* check the focus of the button */ /* check the focus of the button */
if (menu.focusvis && mi == menu.focus) if (((_menu *)mi->menu)->focusvis && mi == ((_menu *)mi->menu)->focus)
focus = 1; focus = 1;
else else
focus = 0; focus = 0;
// draw the top left and right of the list // draw the top left and right of the list
dest.x = MENUOFFSET_X + mi->pos.x; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.w = menu.listimages[focus][0]->w; dest.w = menulistimages[focus][0]->w;
dest.h = menu.listimages[focus][0]->h; dest.h = menulistimages[focus][0]->h;
gfx_blit (menu.listimages[focus][0], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[focus][0], NULL, gfx.screen, &dest, 10000);
dest.x = MENUOFFSET_X + mi->pos.x + mi->pos.w - menu.listimages[focus][2]->w; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + mi->pos.w - menulistimages[focus][2]->w;
gfx_blit (menu.listimages[focus][2], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[focus][2], NULL, gfx.screen, &dest, 10000);
// draw the bottom left and right of the list // draw the bottom left and right of the list
dest.y = MENUOFFSET_Y + mi->pos.y + mi->pos.h - menu.listimages[focus][8]->h; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + mi->pos.h - menulistimages[focus][8]->h;
gfx_blit (menu.listimages[focus][8], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[focus][8], NULL, gfx.screen, &dest, 10000);
dest.x = MENUOFFSET_X + mi->pos.x; dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x;
gfx_blit (menu.listimages[focus][6], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[focus][6], NULL, gfx.screen, &dest, 10000);
// draw the top and blow center of the list // draw the top and blow center of the list
for (i = 0; i < ((mi->pos.w - for (i = 0; i < ((mi->pos.w -
(menu.listimages[focus][0]->w + menu.listimages[focus][2]->w)) (menulistimages[focus][0]->w + menulistimages[focus][2]->w)) / menulistimages[focus][1]->w); i++) {
/ menu.listimages[focus][1]->w); i++) { dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + menulistimages[focus][0]->w + (i * menulistimages[focus][1]->w);
dest.x = MENUOFFSET_X + mi->pos.x + menu.listimages[focus][0]->w + (i * menu.listimages[focus][1]->w); dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
dest.y = MENUOFFSET_Y + mi->pos.y; dest.w = menulistimages[focus][1]->w;
dest.w = menu.listimages[focus][1]->w; dest.h = menulistimages[focus][1]->h;
dest.h = menu.listimages[focus][1]->h; gfx_blit (menulistimages[focus][1], NULL, gfx.screen, &dest, 10000);
gfx_blit (menu.listimages[focus][1], NULL, gfx.screen, &dest, 10000); dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + mi->pos.h - menulistimages[focus][7]->h;
dest.y = MENUOFFSET_Y + mi->pos.y + mi->pos.h - menu.listimages[focus][7]->h; gfx_blit (menulistimages[focus][7], NULL, gfx.screen, &dest, 10000);
gfx_blit (menu.listimages[focus][7], NULL, gfx.screen, &dest, 10000);
} }
// draw the left and the right side of the list // draw the left and the right side of the list
for (i = 0; i < ((mi->pos.h - for (i = 0; i < ((mi->pos.h -
(menu.listimages[focus][0]->h + menu.listimages[focus][6]->h)) (menulistimages[focus][0]->h + menulistimages[focus][6]->h)) / menulistimages[focus][3]->h); i++) {
/ menu.listimages[focus][3]->h); i++) { dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x;
dest.x = MENUOFFSET_X + mi->pos.x; dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y + menulistimages[focus][0]->h + (i * menulistimages[focus][3]->h);
dest.y = MENUOFFSET_Y + mi->pos.y + menu.listimages[focus][0]->h + (i * menu.listimages[focus][3]->h); dest.w = menulistimages[focus][3]->w;
dest.w = menu.listimages[focus][3]->w; dest.h = menulistimages[focus][3]->h;
dest.h = menu.listimages[focus][3]->h; gfx_blit (menulistimages[focus][3], NULL, gfx.screen, &dest, 10000);
gfx_blit (menu.listimages[focus][3], NULL, gfx.screen, &dest, 10000); dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + mi->pos.w - menulistimages[focus][5]->w;
dest.x = MENUOFFSET_X + mi->pos.x + mi->pos.w - menu.listimages[focus][5]->w; gfx_blit (menulistimages[focus][5], NULL, gfx.screen, &dest, 10000);
gfx_blit (menu.listimages[focus][5], NULL, gfx.screen, &dest, 10000);
} }
if (mi->changed) { if (mi->changed) {
menu_draw_listbackground (mi, NULL); menu_draw_listbackground (mi, NULL);
menu_draw_listtext (mi); menu_draw_listtext (mi);
mi->changed=0; mi->changed=0;
} }
}; };
@ -294,9 +283,9 @@ int menu_event_list (_menuitem *mi, SDL_Event *event) {
case (SDL_KEYDOWN): /* key was pressed */ case (SDL_KEYDOWN): /* key was pressed */
mi->changed=1; mi->changed=1;
if (event->key.keysym.sym == SDLK_LEFT) if (event->key.keysym.sym == SDLK_LEFT)
menu_focus_prev (); menu_focus_prev ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_RIGHT) else if (event->key.keysym.sym == SDLK_RIGHT)
menu_focus_next (); menu_focus_next ((_menu *)mi->menu);
else if (event->key.keysym.sym == SDLK_UP) else if (event->key.keysym.sym == SDLK_UP)
menu_list_select_prev (mi); menu_list_select_prev (mi);
else if (event->key.keysym.sym == SDLK_DOWN) else if (event->key.keysym.sym == SDLK_DOWN)

@ -1,4 +1,4 @@
/* /* $Id: multiwait.c,v 1.41 2004/05/20 16:55:30 stpohle Exp $
multiwait.c - this manages only the network screen where multiwait.c - this manages only the network screen where
everyone have to select it's players and where even the basic chat is inside everyone have to select it's players and where even the basic chat is inside
*/ */
@ -10,414 +10,247 @@
#include "chat.h" #include "chat.h"
#include "menu.h" #include "menu.h"
#include "single.h" #include "single.h"
#include "keyb.h"
extern int UpdateRects_nr; extern int UpdateRects_nr;
extern int blitdb_nr; extern int blitdb_nr;
static int mw_player = 0, static int mw_num_readyplayers; // number of players who are ready
mw_chat = 0, static int mw_num_players_x; // number of players in the x
mw_frame = 0, static int mw_num_players_y; // number of players in the y
mw_frameto = 0;
static SDL_Surface *mw_plgfx[MAX_PLAYERS];
#define MW_PLAYERSCR_X 250
#define MW_PLAYERSCR_Y 64
#define MW_TITLE_Y 50
/* this will load some graphics and so other stuff */ /* this will load some graphics and so other stuff */
void void
mw_init () mw_init ()
{ {
int i;
SDL_Surface *tmp;
draw_logo (); draw_logo ();
menu_displaytext ("Please Wait", "Loading GFX Data"); menu_displaytext ("Please Wait", "Loading GFX Data");
gfx_load_players (32, 32); gfx_load_players (32, 32);
network_loop (); network_loop ();
for (i = 0; i < MAX_PLAYERS; i++) { mw_num_readyplayers = 0;
network_loop ();
tmp = makegray_image (gfx.players[i].ani.image);
network_loop ();
mw_plgfx[i] = SDL_DisplayFormat (tmp);
network_loop ();
SDL_FreeSurface (tmp);
network_loop ();
}
bman.updatestatusbar = 1; bman.updatestatusbar = 1;
gfx_blitdraw ();
draw_logo ();
/*
* do some calculations to setup everything on the screen
*/
mw_num_players_x = gfx.res.x / MW_PLAYERSCR_X;
mw_num_players_y = MAX_PLAYERS / mw_num_players_x;
d_printf ("mw_num_players_x : %d, mw_num_players_y : %d\n", mw_num_players_x, mw_num_players_y);
chat_show (8, MW_TITLE_Y + MW_PLAYERSCR_Y * mw_num_players_y, gfx.res.x - 8, gfx.res.y - 8);
chat.active = 1;
}; };
/* free all grafics */ /* free all grafics */
void void mw_shutdown () {
mw_shutdown ()
{
int i;
chat_show (-1, -1, -1, -1); chat_show (-1, -1, -1, -1);
chat_cleanup(); chat_cleanup();
gfx_blitdraw ();
draw_logo ();
gfx_free_players (); gfx_free_players ();
for (i = 0; i < MAX_PLAYERS; i++) SDL_Flip (gfx.screen);
SDL_FreeSurface (mw_plgfx[i]);
}; };
void /*
mw_wait_for_connect () * check if the players are ready
{ */
menu_displaytext ("Please Wait", "Wait For connection"); void mw_check_players () {
}; int i;
void mw_num_readyplayers = 0;
mw_draw_status ()
{
int pnr,
x,
x1,
y,
px;
char text[255];
SDL_Rect src,
dest;
/* Draw Player List */
/* 1. the head */
px = gfx.res.x / 320;
x = (gfx.res.x - px * 320) / 2;
gfx_blitupdaterectclear ();
for (pnr = 0; pnr < px; pnr++) { if (GT_MP_PTPS) /* only the master can start the game */
font_gfxdrawbold (pnr * 320 + x, 23, " Wins Points", 0, COLOR_gray,1, 0xFF); return;
font_gfxdraw (pnr * 320 + x, 23, " Wins Points", 0, COLOR_white, 0xFF);
} for (i = 0; i < MAX_PLAYERS; i++) {
if (players[i].gfx_nr >= 0 && players[i].gfx_nr < MAX_PLAYERS)
mw_num_readyplayers++;
}
}
/* 2. the names with points */
for (x1 = pnr = 0, y = 48; pnr < MAX_PLAYERS; pnr++) {
redraw_logo (x1 * 320, y - 4, 320, 32);
if (players[pnr].gfx_nr != -1 && PS_IS_used (players[pnr].state)) {
src.x = 3 * players[pnr].gfx->smal_size.x;
src.y = 0;
src.w = dest.w = players[pnr].gfx->smal_size.x;
src.h = dest.h = players[pnr].gfx->smal_size.y;
dest.x = x1 * 320;
dest.y = y - 4;
gfx_blit (players[pnr].gfx->smal_image, &src, gfx.screen, &dest, 0xFFFF);
}
sprintf (text, " %10s %2d %2d", players[pnr].name, players[pnr].wins,
players[pnr].points);
if (PS_IS_used (players[pnr].state)) {
if (bman.lastwinner == pnr)
font_draw (x + x1 * 320, y, text, 0, 0);
else
font_draw (x + x1 * 320, y, text, 0, 4);
}
x1++;
if (x1 >= px) {
y += 32;
x1 = 0;
}
if (pnr == MAX_PLAYERS - 1 && x1 != 0)
y += 32;
}
/* add to update rect list */ /*
dest.x = dest.y = 0; * draw only the givin player
dest.h = y; */
dest.w = gfx.res.y; void mw_draw_player (_player *player, int pos) {
gfx_blitupdaterectadd (&dest); _point p;
mw_player = y; char text[255];
SDL_Rect src;
SDL_Rect dest;
p.x = ((pos % mw_num_players_x) * MW_PLAYERSCR_X) + (gfx.res.x - mw_num_players_x * MW_PLAYERSCR_X) / 2;
p.y = (pos / mw_num_players_x) * MW_PLAYERSCR_Y + MW_TITLE_Y;
if (PS_IS_used (player->state)) {
/*
* player is used
*/
if (player->gfx_nr >= 0 && player->gfx_nr < MAX_PLAYERS) {
/* player is used and selected a gfx */
dest.x = p.x;
dest.y = p.y + (MW_PLAYERSCR_Y - GFX_IMGSIZE) / 2;
src.w = dest.w = gfx.players[player->gfx_nr].ani.w;
src.h = dest.h = gfx.players[player->gfx_nr].ani.h;
src.x = down * gfx.players[player->gfx_nr].ani.w;
src.y = 0;
gfx_blit (gfx.players[player->gfx_nr].ani.image, &src, gfx.screen, &dest, 10001);
}
font_gfxdraw (p.x + GFX_IMGSIZE, p.y, player->name, 2, COLOR_yellow, 10002);
sprintf (text,"Victorys:%2d(%d)", player->wins, player->points);
font_gfxdraw (p.x + GFX_IMGSIZE, p.y + font[2].size.y - 4, text, 0, COLOR_white, 10002);
if (debug && PS_IS_used (player->state)) {
sprintf (text, "%s:%s [%d]", player->net.addr.host, player->net.addr.port, player->state);
if (player->net.flags & NETF_firewall)
sprintf (text,"%s Firewall", text);
font_gfxdraw (p.x + GFX_IMGSIZE, p.y + font[0].size.y + font[2].size.y - 4, text, 0, COLOR_white, 10002);
}
}
else {
/*
* player is free
*/
font_gfxdraw (p.x + GFX_IMGSIZE, p.y, "No Player" , 0, COLOR_gray, 10002);
}
}; };
/* draws all aviable players for selection, /*
* if the selgfx player is selected this player will not be animated */ * clear the player screen
void */
mw_draw_gfxselect (int selgfx) void mw_clear_playerscreen () {
{ SDL_Rect src, dest;
int i,
select, src.x = dest.x = 0;
xstep; src.y = dest.y = MW_TITLE_Y;
SDL_Rect src, src.w = dest.w = gfx.res.x;
dest; src.h = dest.h = mw_num_players_y * MW_PLAYERSCR_Y;
gfx_blit (gfx.logo, &src, gfx.screen, &dest, 1);
xstep = gfx.res.x / MAX_PLAYERS; };
if (players[bman.p_nr].gfx_nr == -1) {
/* draw selection */
for (i = 0; i < MAX_PLAYERS; i++) {
dest.w = src.w = gfx.players[i].ani.w;
dest.h = src.h = gfx.players[i].ani.h;
dest.x = i * xstep + (xstep >> 1) - (gfx.players[i].ani.w >> 1);
dest.y = mw_player + 8;
redraw_logo (dest.x, dest.y, dest.w, dest.h);
src.x = 3 * gfx.players[i].ani.w;
if (i == selgfx)
src.y = mw_frame * gfx.players[i].ani.h;
else
src.y = 0;
MW_IS_GFX_SELECT (i, select);
if (select >= MAX_PLAYERS || select < 0) {
/* this player have not been selected */
if (selgfx == i) {
mw_frameto--;
if (mw_frameto <= 0 || mw_frameto > ANI_PLAYERTIMEOUT) {
mw_frameto = ANI_PLAYERTIMEOUT;
mw_frame++;
}
if (mw_frame >= gfx.players[i].ani.frames || mw_frame < 0) {
mw_frameto = ANI_PLAYERTIMEOUT;
mw_frame = 0;
}
gfx_blit (gfx.players[i].ani.image, &src, gfx.screen, &dest, 0xFFFF);
}
else
gfx_blit (mw_plgfx[i], &src, gfx.screen, &dest, 0xFFFF);
}
}
}
else {
/* draw selected players */
for (i = 0; i < MAX_PLAYERS; i++) {
dest.w = src.w = gfx.players[i].ani.w;
dest.h = src.h = gfx.players[i].ani.h;
dest.x = i * xstep + (xstep >> 1) - (gfx.players[i].ani.w >> 1);
dest.y = mw_player + 8;
redraw_logo (dest.x, dest.y, dest.w, dest.h);
src.x = 3 * gfx.players[i].ani.w;
if (i == selgfx)
src.y = mw_frame * gfx.players[i].ani.h;
else
src.y = 0;
MW_IS_GFX_SELECT (i, select);
if (select < MAX_PLAYERS && select >= 0) {
/* this player have been selected */
if (players[bman.p_nr].gfx_nr == i)
gfx_blit (gfx.players[i].ani.image, &src, gfx.screen, &dest, 0xFFFF);
else
gfx_blit (mw_plgfx[i], &src, gfx.screen, &dest, 0xFFFF);
}
}
}
dest.x = 0;
dest.y = mw_player;
dest.w = gfx.res.x;
dest.h = 32 + gfx.players[0].ani.h;
gfx_blitupdaterectadd (&dest);
mw_chat = mw_player + gfx.players[0].ani.h; /*
} * draw all player informations
*/
void mw_draw_all_player () {
int i;
mw_clear_playerscreen ();
for (i = 0; i < MAX_PLAYERS; i++) { /* we do not sort the players */
mw_draw_player (&players[i], i);
}
};
void /*
mw_draw_chat () * check if one key is pressed
{ */
if (chat.visible == 0) { void mw_keys_loop () {
chat_show (16, mw_chat + 16, gfx.res.x - 16, gfx.res.y - 32); if (GT_MP_PTPM && mw_num_readyplayers >= 2 && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
chat_addstatusline ("Press [STRG] or [CTRL] - to select a player"); /* min 2 players are ready for the game and
chat_addstatusline ("F1 - for the Help Screen"); * the start key has pressed */
if (GT_MP_PTPM) bman.state = GS_ready;
chat_addstatusline ("F4 - to start the game"); bman.updatestatusbar = 1; // force an update
} }
if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen(gfx.screen);
gfx.fullscreen = !gfx.fullscreen;
bman.updatestatusbar = 1; // force an update
}
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
/* ESCAPE key was pressed */
bman.state = GS_startup;
}
if ((keyb_gamekeys.state[BCPK_drop] && !keyb_gamekeys.old[BCPK_drop])
|| ((!IS_LPLAYER2) && keyb_gamekeys.state[BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_drop])) {
/* player 1 want to select a new gfx */
playermenu_selgfx (bman.p_nr);
net_change_playerid (bman.p_nr, 1);
keyb_loop (NULL); // to reload the current keys
}
if (IS_LPLAYER2 && keyb_gamekeys.state[BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_drop]) {
/* player 2 want to select a new gfx */
playermenu_selgfx (bman.p2_nr);
net_change_playerid (bman.p2_nr, 1);
keyb_loop (NULL); // to reload the current keys
}
if (keyb_gamekeys.state[BCK_mapmenu] && !keyb_gamekeys.old[BCK_mapmenu] && GT_MP_PTPM) {
/* mapmenu */
mapmenu ();
keyb_loop (NULL); // to reload the current keys
}
if (keyb_gamekeys.state[BCK_playermenu] && !keyb_gamekeys.old[BCK_playermenu]) {
/* playermenu */
playermenu ();
keyb_loop (NULL); // to reload the current keys
}
}; };
/* the loop itself */ /* the loop itself */
void void wait_for_players () {
wait_for_players ()
{
SDL_Event event; SDL_Event event;
Uint8 *keys;
int done = 0,
ready = 0,
keypressed = 0,
i,
selgfx = 0,
drawgfx=1;
mw_init ();
draw_logo ();
SDL_Flip (gfx.screen);
while (!done && bman.state == GS_wait) {
i = bman.p_nr;
if (network_loop () < 0) {
done = 1;
bman.p_nr = -1;
bman.state = GS_startup;
}
if (i != bman.p_nr) /* clean the screen after we got our playernumber */
draw_logo ();
/* check if all players are ready, and more as one player is connected */
if (GT_MP_PTPM)
for (ready = 0, i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_playing (players[i].state))
ready++;
if (ready > 1)
ready = 1;
else
ready = 0;
/* draw the screeninformations */
if (bman.p_nr == -1) { /* we have no connect yet */
mw_wait_for_connect ();
SDL_Flip (gfx.screen);
}
else { /* we have a connect so draw status */
if (bman.updatestatusbar) {
mw_draw_status ();
bman.updatestatusbar = 0;
}
if (!--drawgfx) {
mw_draw_gfxselect (selgfx);
mw_draw_chat ();
drawgfx=5;
}
}
gfx_blitdraw ();
/* do the keyboard handling */ mw_init ();
do {
if (SDL_PollEvent (&event) != 0) if (SDL_PollEvent (&event) != 0)
switch (event.type) { switch (event.type) {
case (SDL_QUIT): case (SDL_QUIT):
bman.state = GS_quit; bman.state = GS_quit;
bman.p_nr = -1; break;
done = 1;
}
keys = SDL_GetKeyState (NULL);
if (event.key.keysym.sym == SDLK_ESCAPE && event.type == SDL_KEYDOWN) {
/* we want to quit */
done = 1;
bman.p_nr = -1;
keypressed = 1;
bman.state = GS_startup;
}
if (event.key.keysym.sym == SDLK_F8 && event.type == SDL_KEYDOWN) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen(gfx.screen);
gfx.fullscreen = !gfx.fullscreen;
bman.updatestatusbar = 1; // force an update
}
if (bman.p_nr != -1) {
if (event.key.keysym.sym == SDLK_LEFT && event.type == SDL_KEYDOWN && (!keypressed) && players[bman.p_nr].gfx_nr == -1) {
i = 0;
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
selgfx--;
if (selgfx < 0)
selgfx = MAX_PLAYERS - 1;
MW_IS_GFX_SELECT (selgfx, i);
}
}
if (event.key.keysym.sym == SDLK_RIGHT && event.type == SDL_KEYDOWN && (!keypressed) && players[bman.p_nr].gfx_nr == -1) {
i = 0;
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
selgfx++;
if (selgfx >= MAX_PLAYERS)
selgfx = 0;
MW_IS_GFX_SELECT (selgfx, i);
}
}
/* just make sure this player is not selected twice */
if (players[bman.p_nr].gfx_nr == -1) {
MW_IS_GFX_SELECT (selgfx, i);
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
selgfx++;
if (selgfx >= MAX_PLAYERS)
selgfx = 0;
MW_IS_GFX_SELECT (selgfx, i);
}
}
if ((event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL) && event.type == SDL_KEYDOWN && (!keypressed)) {
if (players[bman.p_nr].gfx_nr == -1)
/* select player */
player_set_gfx (&players[bman.p_nr],selgfx);
else
/* deselect player */
player_set_gfx (&players[bman.p_nr],-1);
net_change_playerid (bman.p_nr, 1);
bman.updatestatusbar = 1;
keypressed = 1;
}
if ((GT_MP_PTPM) && ready && event.key.keysym.sym == SDLK_F4 && event.type == SDL_KEYDOWN && (!keypressed)) {
done = 1;
bman.updatestatusbar = 1;
} }
if (event.key.keysym.sym == SDLK_F2 && (!keypressed)) { /*
/* Map modification or setting display */ * check some little things and do the network stuff
if (GT_MP_PTPM) { */
mapmenu (); mw_check_players ();
net_send_mapinfo (); network_loop ();
}
else
mapinfo ();
draw_logo ();
mw_draw_status ();
mw_draw_gfxselect (selgfx);
chat.changed = 1;
chat.lineschanged = 1;
chat_drawbox ();
mw_draw_chat ();
}
if ((GT_MP_PTPM) && (!keypressed) && event.key.keysym.sym == SDLK_F3 && event.type == SDL_KEYDOWN) {
if (!keys[SDLK_RSHIFT] && !keys[SDLK_LSHIFT] )
single_create_ai (1);
else
single_delete_ai (1);
for (i = 0; i < MAX_PLAYERS; i++) /*
net_change_playerid (i, GT_MP_PTPM); * the drawing stuff
bman.updatestatusbar = 1; */
} mw_draw_all_player ();
gfx_blitdraw ();
if (event.key.keysym.sym == SDLK_F1 && event.type == SDL_KEYDOWN && (!keypressed)) /* open help screen */
network_helpscreen (); /*
* input handling
chat_loop (&event); */
} keyb_loop (&event);
mw_keys_loop ();
if (event.type == SDL_KEYUP)
keypressed = 0; chat_loop (&event);
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym != SDLK_RSHIFT && event.key.keysym.sym != SDLK_LSHIFT) chat.active = 1;
keypressed = 1;
s_calctimesync ();
s_delay (5); } while (bman.state == GS_wait);
}
gfx_blitdraw (); // to clean the gfx blit data
draw_logo ();
SDL_Flip (gfx.screen);
mw_shutdown (); mw_shutdown ();
}; };

@ -13,17 +13,18 @@ void
netmenu () netmenu ()
{ {
int menuselect = 0; int menuselect = 0;
_menu *menu;
if (bman.gamename[0] == 0) if (bman.gamename[0] == 0)
sprintf (bman.gamename, "%s's Game", bman.playername); sprintf (bman.gamename, "%s's Game", bman.playername);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
menu_new ("Multiplayer", 250, 200); menu = menu_new ("Multiplayer", 250, 200);
menu_create_button ("Host a Game", -1, 70, 200, 0); menu_create_button (menu, "Host a Game", -1, 70, 200, 0);
menu_create_button ("Join a Game", -1, 110, 200, 1); menu_create_button (menu, "Join a Game", -1, 110, 200, 1);
menu_create_button ("Network Options", -1, 150, 200, 2); menu_create_button (menu, "Network Options", -1, 150, 200, 2);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
switch (menuselect) { switch (menuselect) {
case (0): // Create a Game case (0): // Create a Game
@ -31,6 +32,7 @@ netmenu ()
host_multiplayer_game (); host_multiplayer_game ();
break; break;
case (1): // Join a Game case (1): // Join a Game
bman.servername[0] = 0; // make sure no old server is in here
join_multiplayer_game (); join_multiplayer_game ();
break; break;
case (2): // Options case (2): // Options
@ -47,6 +49,7 @@ network_options ()
int menuselect = 0, done = 0, net_ai_typ, i; int menuselect = 0, done = 0, net_ai_typ, i;
_charlist nrplayerlist[MAX_PLAYERS]; _charlist nrplayerlist[MAX_PLAYERS];
_charlist *selnrplayer = &nrplayerlist[bman.maxplayer-1]; _charlist *selnrplayer = &nrplayerlist[bman.maxplayer-1];
_menu *menu;
/* fill in the nrplayerlist */ /* fill in the nrplayerlist */
for (i = 0; i < MAX_PLAYERS; i++) { for (i = 0; i < MAX_PLAYERS; i++) {
@ -60,22 +63,25 @@ network_options ()
while (menuselect != -1 && !done && bman.state != GS_quit) { while (menuselect != -1 && !done && bman.state != GS_quit) {
/* fill in net_ai_typ */ /* fill in net_ai_typ */
net_ai_typ = (PF_INET != bman.net_ai_family); net_ai_typ = (PF_INET != bman.net_ai_family);
menu_new ("Network Options", 400, 380); menu = menu_new ("Network Options", 400, 380);
menu_create_label ("Number Of Players", 60, 75, 0, COLOR_brown); menu_create_label (menu, "Max Players", 30, 75, 0, COLOR_brown);
menu_create_list ("Players", 270, 55, 55, 70, nrplayerlist, &selnrplayer, 1); menu_create_list (menu, "Players", 150, 55, 55, 70, nrplayerlist, &selnrplayer, 1);
menu_create_entry ("Gamename", -1, 150, 300, &bman.gamename, LEN_GAMENAME, MENU_entrytext, 2); menu_create_entry (menu, "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_entry (menu, "UDP Port:", -1, 180, 200, &bman.port, LEN_PORT, MENU_entrytext,3);
#ifndef _WIN32 #ifndef _WIN32
menu_create_bool ("IPV6", 50, 215, 100, &net_ai_typ, 4); menu_create_bool (menu, "IPV6", 260, 60, 100, &net_ai_typ, 4);
#endif #endif
menu_create_bool ("Firewall", 270, 215, 100, &bman.firewall, 5); menu_create_bool (menu, "Firewall", 260, 100, 100, &bman.firewall, 5);
menu_create_bool ("Use OpenGameCache", -1, 250, 350, &bman.notifygamemaster, 6); menu_create_bool (menu, "Private Game", 20, 220, 150, &bman.passwordenabled, 6);
menu_create_entry ("OpenGameCache:", -1, 280, 350, &bman.ogcserver, LEN_SERVERNAME, MENU_entrytext, 7); menu_create_entry (menu, "Password:", 190, 220, 210, &bman.password, LEN_PASSWORD, 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); menu_create_bool (menu, "Use OpenGameCache", -1, 250, 350, &bman.notifygamemaster, 8);
menuselect = menu_loop (); menu_create_entry (menu, "OpenGameCache:", -1, 280, 350, &bman.ogcserver, LEN_SERVERNAME, MENU_entrytext, 9);
menu_create_entry (menu, "Local OGC Port", -1, 310, 350, &bman.ogc_port, LEN_PORT, MENU_entrytext, 10);
menu_create_button (menu, "Ok", -1, 350, 150, 0);
menuselect = menu_loop (menu);
bman.maxplayer = (selnrplayer - &nrplayerlist[0]) + 1; bman.maxplayer = (selnrplayer - &nrplayerlist[0]) + 1;
menu_delete (); menu_delete (menu);
/* fix net_ai_typ */ /* fix net_ai_typ */
#ifndef _WIN32 // fix for windows i don't know how to get there ipv6 mode. #ifndef _WIN32 // fix for windows i don't know how to get there ipv6 mode.
@ -240,7 +246,7 @@ join_multiplayer_game ()
i = 0; i = 0;
bman.p_nr = -1; bman.p_nr = -1;
send_joingame (&players[0].net.addr, bman.playername); send_joingame (&players[0].net.addr, bman.playername, i);
/* go into the normal multiplayer loop */ /* go into the normal multiplayer loop */
multiplayer_game (); multiplayer_game ();
@ -252,22 +258,24 @@ join_multiplayer_game ()
/* Network Help Screen */ /* Network Help Screen */
void network_helpscreen () { void network_helpscreen () {
menu_new ("Network Help Screen", 400, 380); _menu *menu;
menu_create_label ("F1", 60, 50, 1, COLOR_brown);
menu_create_label ("Display this Helpscreen", 180, 54, 0, COLOR_brown); menu = menu_new ("Network Help Screen", 400, 380);
menu_create_label (menu, "F1", 60, 50, 1, COLOR_brown);
menu_create_label (menu, "Display this Helpscreen", 180, 54, 0, COLOR_brown);
menu_create_label ("F2", 60, 80, 1, COLOR_brown); menu_create_label (menu, "F2", 60, 80, 1, COLOR_brown);
menu_create_label ("Change/Show Mapsettings", 180, 84, 0, COLOR_brown); menu_create_label (menu, "Change/Show Mapsettings", 180, 84, 0, COLOR_brown);
menu_create_label ("F3", 60, 110, 1, COLOR_brown); menu_create_label (menu, "F3", 60, 110, 1, COLOR_brown);
menu_create_label ("Add one AI Player", 180, 114, 0, COLOR_brown); menu_create_label (menu, "Add one AI Player", 180, 114, 0, COLOR_brown);
menu_create_label ("Shift-F3", 10, 140, 1, COLOR_brown); menu_create_label (menu, "Shift-F3", 10, 140, 1, COLOR_brown);
menu_create_label ("Delete one AI P.", 180, 144, 0, COLOR_brown); menu_create_label (menu, "Delete one AI P.", 180, 144, 0, COLOR_brown);
menu_create_label ("F4", 60, 170, 1, COLOR_brown); menu_create_label (menu, "F4", 60, 170, 1, COLOR_brown);
menu_create_label ("Start the Game", 180, 174, 0, COLOR_brown); menu_create_label (menu, "Start the Game", 180, 174, 0, COLOR_brown);
menu_loop (); menu_loop (menu);
menu_delete (); menu_delete (menu);
}; };

@ -1,4 +1,4 @@
/* $Id: netsrvlist.c,v 1.8 2004/01/06 19:52:02 stpohle Exp $ /* $Id: netsrvlist.c,v 1.9 2004/05/20 16:55:30 stpohle Exp $
* netsrvlist.c - shows a list of possible servers.*/ * netsrvlist.c - shows a list of possible servers.*/
#include "basic.h" #include "basic.h"
@ -86,23 +86,25 @@ void srvlist_rebuildlist () {
void net_getserver () { void net_getserver () {
int menuselect = 0, entry = 0; int menuselect = 0, entry = 0;
_charlist *sel_entry = &srvlst_text[0]; _charlist *sel_entry = &srvlst_text[0];
_menu *menu;
d_printf ("net_getserver\n"); d_printf ("net_getserver\n");
bman.servername[0] = 0; if (bman.servername[0] == 0)
return; // a server has already been selected
if (bman.notifygamemaster) if (bman.notifygamemaster)
ogc_browsestart (); ogc_browsestart ();
menu_new ("Join a Game", 500, 400); menu = menu_new ("Join a Game", 500, 400);
menu_create_list ("Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1); menu_create_list (menu, "Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1);
menu_create_entry ("IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2); menu_create_entry (menu, "IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2);
menu_create_button ("OK", -1, 350, 150, 0); menu_create_button (menu, "OK", -1, 350, 150, 0);
menu_focus_id (1); menu_focus_id (menu, 1);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
srvlist_rebuildlist (); srvlist_rebuildlist ();
menu_reload (); menu_reload (menu);
menuselect = menu_loop (); menuselect = menu_loop (menu);
switch (menuselect) { switch (menuselect) {
case (0): // Ok Join Selected Game case (0): // Ok Join Selected Game
@ -116,7 +118,7 @@ void net_getserver () {
&& srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */ && srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */
bman.net_ai_family = srvlst_dat[entry].ai_family; bman.net_ai_family = srvlst_dat[entry].ai_family;
sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port); sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port);
menu_focus_id (0); menu_focus_id (menu, 0);
} }
break; break;
} }
@ -124,5 +126,5 @@ void net_getserver () {
if (bman.notifygamemaster) if (bman.notifygamemaster)
ogc_browsestop (); ogc_browsestop ();
menu_delete (); menu_delete (menu);
}; };

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.62 2004/02/11 21:46:48 stpohle Exp $ */ /* $Id: network.c,v 1.63 2004/05/20 16:55:30 stpohle Exp $ */
/* /*
network routines. network routines.
*/ */
@ -140,7 +140,7 @@ network_init ()
/* /*
shutdown the network part shutdown the network part
*/ */
void void
network_shutdown () network_shutdown ()
@ -153,10 +153,13 @@ network_shutdown ()
d_printf ("Server Quit Send information\n"); d_printf ("Server Quit Send information\n");
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && PS_IS_netplayer (players[i].state) && !PS_IS_aiplayer (players[i].state)) if (i != bman.p_servnr && PS_IS_netplayer (players[i].state) && !PS_IS_aiplayer (players[i].state))
send_quit (&players[i].net.addr, NULL, NULL); send_quit (&players[i].net.addr, bman.p_servnr);
} }
else if (players[bman.p_servnr].net.addr.host[0] != 0) else if (players[bman.p_servnr].net.addr.host[0] != 0) {
send_quit (&players[bman.p_servnr].net.addr, NULL, NULL); send_quit (&players[bman.p_servnr].net.addr, bman.p_nr);
if (IS_LPLAYER2)
send_quit (&players[bman.p_servnr].net.addr, bman.p2_nr);
}
if (bman.notifygamemaster) { if (bman.notifygamemaster) {
ogc_sendgamequit (bman.sock); ogc_sendgamequit (bman.sock);
@ -185,6 +188,7 @@ net_check_timeout (int pl_nr)
int timeout = UDP_TIMEOUT; int timeout = UDP_TIMEOUT;
if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net) if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net)
&& ((players[pl_nr].net.flags & NETF_local2) == 0)
&& timestamp - players[pl_nr].net.timestamp > timeout && timestamp - players[pl_nr].net.timestamp > timeout
&& players[pl_nr].net.pingreq != players[pl_nr].net.pingack) { && players[pl_nr].net.pingreq != players[pl_nr].net.pingack) {
d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr, d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr,
@ -196,6 +200,7 @@ net_check_timeout (int pl_nr)
PKG_pingreq); PKG_pingreq);
} }
if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net) if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net)
&& ((players[pl_nr].net.flags & NETF_local2) == 0)
&& timestamp - players[pl_nr].net.timestamp > timeout && timestamp - players[pl_nr].net.timestamp > timeout
&& players[pl_nr].net.pingreq == players[pl_nr].net.pingack) { && players[pl_nr].net.pingreq == players[pl_nr].net.pingack) {
d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr, d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr,
@ -258,7 +263,7 @@ network_loop ()
for (i = 1; i < MAX_PLAYERS; i++) for (i = 1; i < MAX_PLAYERS; i++)
if (i != bman.p_nr && net_check_timeout (i)) { if (i != bman.p_nr && net_check_timeout (i)) {
d_printf ("Player %d Timed Out\n", i); d_printf ("Player %d Timed Out\n", i);
net_delplayer (i); player_delete (i);
} }
} }
} }
@ -316,29 +321,29 @@ draw_netupdatestate (char st)
dest.x = zx; dest.x = zx;
dest.y = y; dest.y = y;
dest.w = menu.listimages[1][0]->w; dest.w = menulistimages[1][0]->w;
dest.h = menu.listimages[1][0]->h; dest.h = menulistimages[1][0]->h;
gfx_blit (menu.listimages[1][0], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][0], NULL, gfx.screen, &dest, 10000);
dest.x = z+zx+4; dest.x = z+zx+4;
gfx_blit (menu.listimages[1][2], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][2], NULL, gfx.screen, &dest, 10000);
// draw the bottom left and right of the list // draw the bottom left and right of the list
dest.y = y+29; dest.y = y+29;
gfx_blit (menu.listimages[1][8], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][8], NULL, gfx.screen, &dest, 10000);
dest.x = zx; dest.x = zx;
gfx_blit (menu.listimages[1][6], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][6], NULL, gfx.screen, &dest, 10000);
//top & bottom //top & bottom
for (j=4;j<z+4;j+=4) { for (j=4;j<z+4;j+=4) {
dest.x=j+zx;dest.y=y; dest.x=j+zx;dest.y=y;
gfx_blit (menu.listimages[1][1], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][1], NULL, gfx.screen, &dest, 10000);
dest.y = y+29; dest.y = y+29;
gfx_blit (menu.listimages[1][7], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][7], NULL, gfx.screen, &dest, 10000);
} }
//left &right //left &right
for (j=4;j<29;j+=4) { for (j=4;j<29;j+=4) {
dest.x=zx;dest.y=y+j; dest.x=zx;dest.y=y+j;
gfx_blit (menu.listimages[1][3], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][3], NULL, gfx.screen, &dest, 10000);
dest.x = z+zx+4; dest.x = z+zx+4;
gfx_blit (menu.listimages[1][5], NULL, gfx.screen, &dest, 10000); gfx_blit (menulistimages[1][5], NULL, gfx.screen, &dest, 10000);
} }
sprintf (text, "%s", players[i].name); sprintf (text, "%s", players[i].name);
font_draw (80, y, text, 0, 4); font_draw (80, y, text, 0, 4);
@ -370,21 +375,21 @@ draw_netupdatestate (char st)
b1=b*z/255; b1=b*z/255;
dest.x = zx+4; dest.x = zx+4;
dest.y = y+4; dest.y = y+4;
dest.w = menu.buttonimages[2][0]->w; dest.w = menubuttonimages[2][0]->w;
dest.h = menu.buttonimages[2][0]->h; dest.h = menubuttonimages[2][0]->h;
gfx_blit (menu.buttonimages[2][0], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[2][0], NULL, gfx.screen, &dest, 10000);
dest.x = zx+4+b1-menu.buttonimages[1][2]->w; dest.x = zx+4+b1-menubuttonimages[1][2]->w;
if (dest.x<zx+4) dest.x=zx+4; if (dest.x<zx+4) dest.x=zx+4;
dest.w = menu.buttonimages[2][2]->w; dest.w = menubuttonimages[2][2]->w;
dest.h = menu.buttonimages[2][2]->h; dest.h = menubuttonimages[2][2]->h;
gfx_blit (menu.buttonimages[2][2], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[2][2], NULL, gfx.screen, &dest, 10000);
if (b1>menu.buttonimages[2][0]->w+menu.buttonimages[2][2]->w) { if (b1>menubuttonimages[2][0]->w+menubuttonimages[2][2]->w) {
dest.w = menu.buttonimages[2][1]->w; dest.w = menubuttonimages[2][1]->w;
dest.h = menu.buttonimages[2][1]->h; dest.h = menubuttonimages[2][1]->h;
for(j=menu.buttonimages[2][0]->w;j<b1-menu.buttonimages[2][2]->w; for(j=menubuttonimages[2][0]->w;j<b1-menubuttonimages[2][2]->w;
j+=menu.buttonimages[2][1]->w) { j+=menubuttonimages[2][1]->w) {
dest.x=j+zx+4; dest.x=j+zx+4;
gfx_blit (menu.buttonimages[2][1], NULL, gfx.screen, &dest, 10000); gfx_blit (menubuttonimages[2][1], NULL, gfx.screen, &dest, 10000);
} }
} }
} }
@ -423,7 +428,7 @@ net_change_playerid (int pl_nr, unsigned char senddata)
/* /*
Send only to the Server the update and only if in_nr == bman.in_nr Send only to the Server the update and only if in_nr == bman.in_nr
*/ */
if (pl_nr == bman.p_nr && senddata) if ((pl_nr == bman.p_nr || (IS_LPLAYER2 && pl_nr == bman.p2_nr)) && senddata)
send_playerid (&players[bman.p_servnr].net.addr, players[pl_nr].name, send_playerid (&players[bman.p_servnr].net.addr, players[pl_nr].name,
players[pl_nr].net.addr.host, players[pl_nr].net.addr.port, players[pl_nr].net.addr.host, players[pl_nr].net.addr.port,
pl_nr, players[pl_nr].gfx_nr, players[pl_nr].net.flags); pl_nr, players[pl_nr].gfx_nr, players[pl_nr].net.flags);
@ -465,7 +470,7 @@ net_transmit_gamedata ()
for (x = 0; x < MAX_PLAYERS; x++) { for (x = 0; x < MAX_PLAYERS; x++) {
players[x].net.timestamp = 0; players[x].net.timestamp = 0;
players[x].net.net_status = -1; players[x].net.net_status = -1;
if ((PS_IS_aiplayer (players[x].state)) || (x==bman.p_servnr)) if ((PS_IS_aiplayer (players[x].state)) || (x==bman.p_servnr) || (x == bman.p2_nr) || (players[x].net.flags & NETF_local2) == NETF_local2)
players[x].net.net_istep = 0; players[x].net.net_istep = 0;
else else
players[x].net.net_istep = 3; players[x].net.net_istep = 3;
@ -625,12 +630,12 @@ net_game_send_player (int p_nr)
if (GT_MP_PTPM) { if (GT_MP_PTPM) {
for (p = 0; p < MAX_PLAYERS; p++) for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (players[p].state) && p != bman.p_nr) if (PS_IS_netplayer (players[p].state) && p != bman.p_nr && p != bman.p2_nr)
send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]); send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]);
} }
else if (p_nr == bman.p_nr) { else if (p_nr == bman.p_nr || p_nr == bman.p2_nr) {
for (p = 0; p < MAX_PLAYERS; p++) for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (players[p].state) && p != bman.p_nr && NET_CANSEND(p)) if (NET_CANSEND(p))
send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]); send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]);
} }
}; };
@ -643,11 +648,11 @@ net_game_send_playermove (int p_nr, int mustsend)
_player *pl; _player *pl;
for (p = 0; p < MAX_PLAYERS; p++) for (p = 0; p < MAX_PLAYERS; p++)
if (!PS_IS_aiplayer (players[p].state) && PS_IS_netplayer (players[p].state) && p != bman.p_nr) { if (NET_CANSEND(p)) {
pl = &players[p_nr]; pl = &players[p_nr];
pl->net.pkgopt.send_to--; pl->net.pkgopt.send_to--;
if ((pl->net.pkgopt.send_to <= 0 || mustsend) && NET_CANSEND(p)) if ((pl->net.pkgopt.send_to <= 0 || mustsend))
send_playermove (&players[p].net.addr, p_nr, pl); send_playermove (&players[p].net.addr, p_nr, pl);
/* network packet send control */ /* network packet send control */
@ -671,7 +676,7 @@ net_game_send_bomb (int p, int b)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (!PS_IS_aiplayer (players[pl].state) && PS_IS_netplayer (players[pl].state) && pl != bman.p_nr && NET_CANSEND(pl)) if (NET_CANSEND(pl))
send_bombdata (&players[pl].net.addr, p, b, &players[p].bombs[b]); send_bombdata (&players[pl].net.addr, p, b, &players[p].bombs[b]);
}; };
@ -687,54 +692,32 @@ net_game_send_field (int x, int y)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (!PS_IS_aiplayer (players[pl].state) && PS_IS_netplayer (players[pl].state) && pl != bman.p_nr && NET_CANSEND(pl)) if (NET_CANSEND(pl))
send_field (&players[pl].net.addr, x, y, &map.field[x][y]); send_field (&players[pl].net.addr, x, y, &map.field[x][y]);
}; };
/*
* send the information about the deleted player to all clients
*/
void void
net_delplayer (int pl_nr) net_game_send_delplayer (int pl_nr) {
{
char host[LEN_SERVERNAME];
char port[LEN_PORT];
int i; int i;
d_printf ("net_delplayer (%d)\n", pl_nr); d_printf ("net_game_send_delplayer (%d)\n", pl_nr);
bman.updatestatusbar = 1; // force an update
if (pl_nr == bman.p_nr) {
/* we're not wanted */
network_shutdown ();
bman.state = GS_startup;
}
else {
strncpy (host, players[pl_nr].net.addr.host, LEN_SERVERNAME);
strncpy (port, players[pl_nr].net.addr.port, LEN_PORT);
players[pl_nr].state &= (0xFF - (PSF_used + PSF_net + PSF_alife)); /* delete if (GT_MP_PTPM && (GS_WAITRUNNING || bman.state == GS_update)) {
player flags */ for (i = 0; i < MAX_PLAYERS; i++)
players[pl_nr].net.net_istep = 0; // needed for disconnect during the update if (NET_CANSEND(i) || pl_nr == i)
bman.players_nr_s--; send_quit (&players[i].net.addr, pl_nr);
players[pl_nr].gfx_nr = -1; if (bman.notifygamemaster)
send_ogc_update ();
if (GT_MP_PTPM && (GS_WAITRUNNING || bman.state == GS_update)) { bman.updatestatusbar=1;
for (i = 1; i < MAX_PLAYERS; i++) }
if (!PS_IS_aiplayer (players[i].state) && PS_IS_netplayer (players[i].state))
send_quit (&players[i].net.addr, host, port);
if (bman.notifygamemaster)
send_ogc_update ();
bman.updatestatusbar=1;
}
}
if (GT_MP_PTPS && pl_nr == bman.p_servnr) /* server quit */
bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster) if (GT_MP_PTPM && bman.notifygamemaster)
send_ogc_update (); send_ogc_update ();
d_playerdetail (" Player Left ... Playerlist\n");
inpkg_delplayer (pl_nr); inpkg_delplayer (pl_nr);
}; };
@ -759,7 +742,7 @@ net_send_servermode ()
int i; int i;
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_servermode (&players[i].net.addr, i); send_servermode (&players[i].net.addr, i);
if (bman.notifygamemaster && GT_MP_PTPM) if (bman.notifygamemaster && GT_MP_PTPM)
@ -775,7 +758,7 @@ net_send_players ()
j; j;
for (j = 0; j < MAX_PLAYERS; j++) for (j = 0; j < MAX_PLAYERS; j++)
if (!PS_IS_aiplayer (players[j].state) && PS_IS_netplayer (players[j].state) && j != bman.p_nr) if (NET_CANSEND (j))
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (&players[j].net.addr, players[i].name, send_playerid (&players[j].net.addr, players[i].name,
players[i].net.addr.host, players[i].net.addr.port, i, players[i].net.addr.host, players[i].net.addr.port, i,
@ -791,7 +774,7 @@ net_send_chat (char *text, signed char notigamesrv)
int i; int i;
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_chat (&players[i].net.addr, text); send_chat (&players[i].net.addr, text);
}; };
@ -804,7 +787,7 @@ net_game_send_ill (int p_nr)
d_printf ("net_game_send_ill (%d)\n", p_nr); d_printf ("net_game_send_ill (%d)\n", p_nr);
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_ill (&players[i].net.addr, p_nr, &players[p_nr]); send_ill (&players[i].net.addr, p_nr, &players[p_nr]);
}; };
@ -817,7 +800,7 @@ void net_game_send_dropitems (int pl_nr, _flyingitem **fiptr, int cnt) {
d_printf ("net_game_send_dropitems (%d): %d items droppped\n", pl_nr, cnt); d_printf ("net_game_send_dropitems (%d): %d items droppped\n", pl_nr, cnt);
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_dropitems (&players[i].net.addr, pl_nr, fiptr, cnt); send_dropitems (&players[i].net.addr, pl_nr, fiptr, cnt);
}; };
@ -863,7 +846,7 @@ net_game_send_special (int pl_nr, int ex_nr, int type)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (!PS_IS_aiplayer (players[pl].state) && PS_IS_netplayer (players[pl].state) && pl != pl_nr && NET_CANSEND(pl)) if (NET_CANSEND(pl))
send_special (&players[pl].net.addr, pl_nr, type, ex_nr); send_special (&players[pl].net.addr, pl_nr, type, ex_nr);
}; };
@ -880,7 +863,7 @@ net_send_updateinfo ()
d_printf ("Send Updateinfo\n"); d_printf ("Send Updateinfo\n");
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_updateinfo (&players[i].net.addr); send_updateinfo (&players[i].net.addr);
}; };
@ -897,7 +880,7 @@ net_send_mapinfo ()
d_printf ("Send Mapinfo\n"); d_printf ("Send Mapinfo\n");
for (i = 0; i < MAX_PLAYERS; i++) 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)) if (NET_CANSEND(i))
send_mapinfo (&players[i].net.addr); send_mapinfo (&players[i].net.addr);
}; };
@ -947,6 +930,6 @@ void net_game_send_respawn (int pl_nr) {
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (!PS_IS_aiplayer (players[pl].state) && PS_IS_netplayer (players[pl].state) && pl != pl_nr && NET_CANSEND(pl)) if (NET_CANSEND(pl))
send_respawn (&players[pl].net.addr, pl_nr); send_respawn (&players[pl].net.addr, pl_nr);
}; };

@ -22,6 +22,8 @@ int inpkg_index_pos = 0;
/*** /***
*** help function to get the playernumber from the address. *** help function to get the playernumber from the address.
*** this function does not indicate which player it is, this function only checks
*** if the packet comed from a known player
***/ ***/
int int
get_player_nr (char *host, char *port) get_player_nr (char *host, char *port)
@ -31,8 +33,8 @@ get_player_nr (char *host, char *port)
for (i = 0, res = -1; (i < MAX_PLAYERS && res == -1); i++) { for (i = 0, res = -1; (i < MAX_PLAYERS && res == -1); i++) {
if (players[i].net.addr.host[0] != 0) if (players[i].net.addr.host[0] != 0)
if ((strcmp (players[i].net.addr.host, host) == 0) && if ((strcmp (players[i].net.addr.host, host) == 0)
(strcmp (players[i].net.addr.port, port) == 0)) && (strcmp (players[i].net.addr.port, port) == 0))
res = i; res = i;
} }
return res; return res;
@ -75,6 +77,12 @@ do_error (struct pkg_error *data, _net_addr * addr)
/*** /***
*** Packettype: joingame *** Packettype: joingame
*** client sends this to the server if he want's to join *** client sends this to the server if he want's to join
***
*** 1) check if this package comes from a already joined and known player
*** if so: just send the current playerlist back.
*** else:
*** 2) find free playerslot and add the player there
*** 3) send to all players the new playerid
***/ ***/
void void
do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
@ -90,26 +98,39 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
if (p_jg->ver_sub != vsu || p_jg->ver_major != vma || p_jg->ver_minor != vmi) { /* Do some basic checks befor we accept this data packet
sprintf (text, "Version Error - Host/Server Version: %s", VERSION); * 1) check if we are a server */
if (GT_MP_PTPS) {
sprintf (text, "Sorry this is a client and not a server.");
send_error (addr, text); send_error (addr, text);
return; return;
} }
if (GT_MP_PTPS) { /* 2) check the version */
sprintf (text, "Sorry this is a client and not a server."); if (p_jg->ver_sub != vsu || p_jg->ver_major != vma || p_jg->ver_minor != vmi) {
sprintf (text, "Version Error - Host/Server Version: %s", VERSION);
send_error (addr, text); send_error (addr, text);
return; return;
} }
/* 3) check if we have a password */
if (bman.passwordenabled && !strncmp (bman.password, p_jg->password, LEN_PASSWORD)) {
send_error (addr, "This game is Password protected. Your Password is wrong.");
return;
}
/* find a free place for the player and add the player to the game */ /* find a free place for the player and add the player to the game */
if (GS_WAITRUNNING && GT_MP_PTPM) { if (GS_WAITRUNNING && GT_MP_PTPM) {
/* find free player slot */ int j, freeslot;
if (addr->pl_nr == -1) /* find a free playerslot and check if this player isn't already in the list */
for (i = 0; (i < MAX_PLAYERS && PS_IS_used (players[i].state)); i++); for (i = -1, freeslot = -1, j = 0; j < MAX_PLAYERS; j++) {
else if (!PS_IS_used (players[j].state) && freeslot == -1) freeslot = j;
i = addr->pl_nr; if (strncmp (players[j].net.addr.host, addr->host, LEN_SERVERNAME) == 0
&& strncmp (players[j].net.addr.port, addr->port, LEN_PORT) == 0
if ((i < MAX_PLAYERS) && (i < bman.maxplayer)) { && p_jg->netflags == players[j].net.flags) i = j;
}
if (i == -1) i = freeslot;
if ((i >= 0) && (i < MAX_PLAYERS) && (i < bman.maxplayer)) {
/* free player slot found ... fill in data */ /* free player slot found ... fill in data */
pl = &players[i]; pl = &players[i];
@ -141,14 +162,13 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
/* send to the new client the servermode and the complete playerlist */ /* send to the new client the servermode and the complete playerlist */
send_mapinfo (addr); send_mapinfo (addr);
send_servermode (addr, i); send_servermode (addr, i); // with this packet the client know it'S pl_nr
addr->pl_nr = i; addr->pl_nr = i;
/* Send all connected players the new PlayerID */ /* Send all connected players the new PlayerID */
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && i != pl->net.addr.pl_nr if (NET_CANSEND(i))
&& PS_IS_netplayer (players[i].state))
send_playerid (&players[i].net.addr, pl->name, pl->net.addr.host, 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.addr.port, pl->net.addr.pl_nr, pl->gfx_nr,
pl->net.flags); pl->net.flags);
@ -171,7 +191,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
void void
send_joingame (_net_addr * addr, char *name) send_joingame (_net_addr * addr, char *name, int flags)
{ {
struct pkg_joingame p_jg; struct pkg_joingame p_jg;
int vmi, int vmi,
@ -188,11 +208,9 @@ send_joingame (_net_addr * addr, char *name)
p_jg.ver_sub = vsu; p_jg.ver_sub = vsu;
p_jg.ver_major = vma; p_jg.ver_major = vma;
p_jg.ver_minor = vmi; p_jg.ver_minor = vmi;
if (bman.firewall) p_jg.netflags = flags;
p_jg.netflags = NETF_firewall; strncpy (p_jg.name, name, LEN_PLAYERNAME);
else strncpy (p_jg.password, bman.password, LEN_PASSWORD);
p_jg.netflags = 0;
strncpy (p_jg.name, bman.playername, LEN_PLAYERNAME);
send_pkg ((struct pkg *) &p_jg, addr); send_pkg ((struct pkg *) &p_jg, addr);
}; };
@ -201,6 +219,9 @@ send_joingame (_net_addr * addr, char *name)
/*** /***
*** Packettype: pingack/pingreq *** Packettype: pingack/pingreq
*** Update Playerinformation, add players into the current game *** Update Playerinformation, add players into the current game
***
*** if : the pl_nr == -1 send the whole list to the sender
*** else: set the new values for this player
***/ ***/
void void
do_playerid (struct pkg_playerid *p_id, _net_addr * addr) do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
@ -212,10 +233,19 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
("do_playerid (From:%s:%s pl_nr=%d) Player(name:%s [%s:%s], pl_nr:%d)\n", ("do_playerid (From:%s:%s pl_nr=%d) Player(name:%s [%s:%s], pl_nr:%d)\n",
addr->host, addr->port, addr->pl_nr, p_id->name, p_id->host, p_id->port, p_id->pl_nr); addr->host, addr->port, addr->pl_nr, p_id->name, p_id->host, p_id->port, p_id->pl_nr);
/* As Server/Master Only change settings */ /*
if (((GT_MP_PTPM && (bman.state == GS_wait && addr->pl_nr != -1)) || // PTPM change setting * check if we have to send the whole playerlist to a client
(GT_MP_PTPS && addr->pl_nr == bman.p_servnr)) && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS) { // PTPS and information send by PTPM */
if (GT_MP_PTPM && p_id->pl_nr == -1) {
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (addr, players[i].name, players[i].net.addr.host, players[i].net.addr.port, i, players[i].gfx_nr, players[i].net.flags);
}
/*
* check if we have to update someones data
*/
else if ((GT_MP_PTPM && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS && p_id->pl_nr != bman.p_nr && p_id->pl_nr != bman.p2_nr)
|| (GT_MP_PTPS && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS)) {
pl = &players[p_id->pl_nr]; pl = &players[p_id->pl_nr];
pl->state = p_id->state; pl->state = p_id->state;
@ -236,24 +266,24 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, dns_filladdr (pl->net.addr.host, LEN_SERVERNAME,
pl->net.addr.port, LEN_PORT, bman.net_ai_family, &pl->net.addr.sAddr); pl->net.addr.port, LEN_PORT, bman.net_ai_family, &pl->net.addr.sAddr);
} }
/* player is used, we need to check if it's the second player from the server
* to set it's host and port name */
else if (PS_IS_used (p_id->state)) {
strncpy (pl->net.addr.host, players[bman.p_servnr].net.addr.host, LEN_SERVERNAME);
strncpy (pl->net.addr.port, players[bman.p_servnr].net.addr.port, LEN_PORT);
memcpy (&pl->net.addr.sAddr, &players[bman.p_servnr].net.addr.sAddr, sizeof (struct _sockaddr));
}
if (GT_MP_PTPS) { if (GT_MP_PTPS) {
pl->points = NTOH16 (p_id->points); pl->points = NTOH16 (p_id->points);
pl->wins = NTOH16 (p_id->wins); pl->wins = NTOH16 (p_id->wins);
} }
/* Send all connected players the new PlayerID */ /* Send all connected players the new PlayerID */
if (GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) if (GT_MP_PTPM && GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
net_change_playerid (addr->pl_nr, (GT_MP_PTPM)); net_change_playerid (addr->pl_nr, (GT_MP_PTPM));
} }
/* send the whole playerlist to the client to update the playerlist */
else if (p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) {
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (addr, players[i].name, players[i].net.addr.host,
players[i].net.addr.port, i, players[i].gfx_nr, players[i].net.flags);
}
d_playerdetail ("*** PLAYER List ***"); d_playerdetail ("*** PLAYER List ***");
bman.updatestatusbar = 1; bman.updatestatusbar = 1;
}; };
@ -322,7 +352,7 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
/* if we just have connected the bman.p_nr is still -1, so we handle the /* if we just have connected the bman.p_nr is still -1, so we handle the
servermode packet still alittle diffrent */ servermode packet still alittle diffrent */
if (bman.p_nr == -1) { if ((!s_mod->lplayer2 && bman.p_nr == -1) || (s_mod->lplayer2 && bman.p2_nr == -1)) {
d_printf (" Server gave us: p_nr: %d, p_servnr: %d\n", s_mod->p_nr, s_mod->p_servnr); d_printf (" Server gave us: p_nr: %d, p_servnr: %d\n", s_mod->p_nr, s_mod->p_servnr);
/* set the p_servnr to the playerslot which is the server */ /* set the p_servnr to the playerslot which is the server */
@ -332,11 +362,16 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
} }
/* set now the new p_nr number */ /* set now the new p_nr number */
if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1) { if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1 && s_mod->lplayer2 == 0) {
bman.p_nr = s_mod->p_nr; bman.p_nr = s_mod->p_nr;
players[bman.p_nr].state &= (0xFF - PSF_net); players[bman.p_nr].state &= (0xFF - PSF_net);
strncpy (players[s_mod->p_nr].name, bman.playername, LEN_PLAYERNAME); strncpy (players[s_mod->p_nr].name, bman.playername, LEN_PLAYERNAME);
} }
else if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p2_nr == -1 && s_mod->lplayer2 == 1) {
bman.p2_nr = s_mod->p_nr;
players[bman.p2_nr].state &= (0xFF - PSF_net);
strncpy (players[s_mod->p_nr].name, bman.player2name, LEN_PLAYERNAME);
}
/* send playerid with p_nr -1 so we get the whole playerlist */ /* send playerid with p_nr -1 so we get the whole playerlist */
send_playerid (addr, NULL, NULL, NULL, -1, -1, 0); send_playerid (addr, NULL, NULL, NULL, -1, -1, 0);
@ -386,6 +421,9 @@ send_servermode (_net_addr * addr, int pl_nr)
s_mod.players = bman.players_nr_s; s_mod.players = bman.players_nr_s;
s_mod.maxplayer = bman.maxplayer; s_mod.maxplayer = bman.maxplayer;
s_mod.p_nr = pl_nr; s_mod.p_nr = pl_nr;
if (pl_nr >= 0 && pl_nr < MAX_PLAYERS && (players[pl_nr].net.flags & NETF_local2) == NETF_local2)
s_mod.lplayer2 = 1;
else s_mod.lplayer2 = 0;
s_mod.p_servnr = bman.p_servnr; s_mod.p_servnr = bman.p_servnr;
s_mod.last_winner = bman.lastwinner; s_mod.last_winner = bman.lastwinner;
s_mod.fieldsize_x = map.size.x; s_mod.fieldsize_x = map.size.x;
@ -717,10 +755,11 @@ do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
if (p_dat->p_nr == -1) if (p_dat->p_nr == -1)
return; return;
if (addr->pl_nr == -1) // unknown player
return;
/* check if the right player is sending the information */ /* check if the right player is sending the information */
pl = &players[p_dat->p_nr]; pl = &players[p_dat->p_nr];
if (addr->pl_nr != bman.p_servnr && addr->pl_nr != p_dat->p_nr)
return;
pl->m = p_dat->m; pl->m = p_dat->m;
pl->d = p_dat->d; pl->d = p_dat->d;
@ -876,24 +915,16 @@ send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
*** Packettype: quit *** Packettype: quit
***/ ***/
void void
send_quit (_net_addr * addr, char *plhost, char *plport) send_quit (_net_addr * addr, int pl_nr)
{ {
struct pkg_quit q_dat; struct pkg_quit q_dat;
d_printf ("send_quit (%s:%s) plhost (%s:%s)\n", addr->host, addr->port, plhost, plport); d_printf ("send_quit (%s:%s) pl_nr: %d\n", addr->host, addr->port, pl_nr);
q_dat.h.typ = PKG_quit; q_dat.h.typ = PKG_quit;
q_dat.h.flags = 0; q_dat.h.flags = 0;
q_dat.h.len = HTON16 (sizeof (struct pkg_quit)); q_dat.h.len = HTON16 (sizeof (struct pkg_quit));
q_dat.pl_nr = pl_nr;
if (plhost == NULL) {
q_dat.host[0] = 0;
q_dat.port[0] = 0;
}
else {
strncpy (q_dat.host, plhost, LEN_SERVERNAME);
strncpy (q_dat.port, plport, LEN_PORT);
}
send_pkg ((struct pkg *) &q_dat, addr); send_pkg ((struct pkg *) &q_dat, addr);
}; };
@ -902,23 +933,13 @@ send_quit (_net_addr * addr, char *plhost, char *plport)
void void
do_quit (struct pkg_quit *q_dat, _net_addr * addr) do_quit (struct pkg_quit *q_dat, _net_addr * addr)
{ {
d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, addr->pl_nr); d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, q_dat->pl_nr);
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
return; return;
if (q_dat->host[0] == 0) /* the player who send this quit */
/* the player who send this quit */ player_delete (q_dat->pl_nr);
net_delplayer (addr->pl_nr);
else {
/* delete the player with the giving address */
int pl_nr = get_player_nr (q_dat->host, q_dat->port);
if (pl_nr == -1)
return;
net_delplayer (pl_nr);
}
}; };
@ -1264,11 +1285,7 @@ void
do_special (struct pkg_special *sp_pkg, _net_addr * addr) do_special (struct pkg_special *sp_pkg, _net_addr * addr)
{ {
d_printf ("do_special (addr %d, pl_nr %d, typ %d)\n", addr->pl_nr, sp_pkg->pl_nr, sp_pkg->typ); d_printf ("do_special (addr %d, pl_nr %d, typ %d)\n", addr->pl_nr, sp_pkg->pl_nr, sp_pkg->typ);
if (addr->pl_nr == -1 || sp_pkg->pl_nr == -1) if (addr->pl_nr == -1 || sp_pkg->pl_nr == -1 || sp_pkg->pl_nr == bman.p_nr || sp_pkg->pl_nr == bman.p2_nr)
return;
/* check if the right player is sending the information */
if (addr->pl_nr != bman.p_servnr && addr->pl_nr != sp_pkg->pl_nr)
return; return;
/* set or use special */ /* set or use special */
@ -1504,7 +1521,8 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
if ((!PS_IS_aiplayer (players[pl].state)) && PS_IS_netplayer (players[pl].state) if ((!PS_IS_aiplayer (players[pl].state)) && PS_IS_netplayer (players[pl].state)
&& ((players[addr->pl_nr].net.flags & NETF_firewall) == NETF_firewall && ((players[addr->pl_nr].net.flags & NETF_firewall) == NETF_firewall
|| (players[pl].net.flags & NETF_firewall) == NETF_firewall) || (players[pl].net.flags & NETF_firewall) == NETF_firewall)
&& pl != addr->pl_nr) && pl != addr->pl_nr
&& (players[pl].net.flags & NETF_local2) == 0)
send_pkg (packet, &players[pl].net.addr); send_pkg (packet, &players[pl].net.addr);
} }
else if (packet->h.typ > PKG_quit) else if (packet->h.typ > PKG_quit)

@ -1,13 +1,15 @@
/* $Id: player.c,v 1.83 2004/04/03 14:48:43 stpohle Exp $ /* $Id: player.c,v 1.84 2004/05/20 16:55:30 stpohle Exp $
* player.c - everything what have to do with the player */ * player.c - everything what have to do with the player */
#include <SDL.h> #include <SDL.h>
#include "bomberclone.h" #include "bomberclone.h"
#include "network.h" #include "network.h"
#include "packets.h"
#include "sound.h" #include "sound.h"
#include "flyingitems.h" #include "flyingitems.h"
#include "player.h" #include "player.h"
#include "bomb.h" #include "bomb.h"
#include "menu.h"
void void
draw_player (_player * player) draw_player (_player * player)
@ -171,7 +173,7 @@ player_check_powerup (int p_nr)
int ft, int ft,
i; i;
if (PS_IS_netplayer (p->state)) if (PS_IS_netplayer (p->state) && (bman.p2_nr != p_nr || bman.p2_nr == -1))
return; return;
/* Get the right field position */ /* Get the right field position */
@ -232,8 +234,8 @@ player_check_powerup (int p_nr)
case FT_death: case FT_death:
player_set_ilness (p, -1, ILL_TIMEOUT); player_set_ilness (p, -1, ILL_TIMEOUT);
bman.updatestatusbar = 1; bman.updatestatusbar = 1;
if (GT_MP) if (GT_MP) /* maybe we have to check if it is our player */
net_game_send_ill (bman.p_nr); net_game_send_ill (p_nr);
field_clear (fx, fy); field_clear (fx, fy);
break; break;
/* we found a special */ /* we found a special */
@ -428,11 +430,11 @@ player_move (int pl_nr)
p->tunnelto -= timediff; p->tunnelto -= timediff;
p->m = 0; p->m = 0;
if (p->tunnelto <= 0.0f && GT_MP) if (p->tunnelto <= 0.0f && GT_MP)
net_game_send_playermove (bman.p_nr, 1); net_game_send_playermove (pl_nr, 1);
} }
else { else {
if (p->m) { if (p->m) {
/* prepade playervariables for the moving */ /* prepare playervariables for the moving */
player_animation (p); player_animation (p);
oldd = p->d; oldd = p->d;
p->stepsleft = p->speed * timefactor; p->stepsleft = p->speed * timefactor;
@ -453,13 +455,13 @@ player_move (int pl_nr)
p->m = 0; p->m = 0;
/* check the players position */ /* check the players position */
if ((CUTINT(p->pos.x) > EXPLOSION_SAVE_DISTANCE && (p->d == left || p->d == right)) if (PS_IS_alife (p->state) && (CUTINT(p->pos.x) > EXPLOSION_SAVE_DISTANCE && (p->d == left || p->d == right))
&& (!check_exfield (p->pos.x + 1.0f, p->pos.y))) && (!check_exfield (p->pos.x + 1.0f, p->pos.y)))
player_died (p, -1); player_died (p, -1);
if ((CUTINT(p->pos.y) > EXPLOSION_SAVE_DISTANCE && (p->d == up || p->d == down)) if (PS_IS_alife (p->state) && (CUTINT(p->pos.y) > EXPLOSION_SAVE_DISTANCE && (p->d == up || p->d == down))
&& (!check_exfield (p->pos.x, p->pos.y + 1.0f))) && (!check_exfield (p->pos.x, p->pos.y + 1.0f)))
player_died (p, -1); player_died (p, -1);
if (((CUTINT(p->pos.x) < (1.0f - EXPLOSION_SAVE_DISTANCE) && (p->d == left || p->d == right)) if (PS_IS_alife (p->state) && ((CUTINT(p->pos.x) < (1.0f - EXPLOSION_SAVE_DISTANCE) && (p->d == left || p->d == right))
|| (CUTINT(p->pos.y) < (1.0f - EXPLOSION_SAVE_DISTANCE) || (CUTINT(p->pos.y) < (1.0f - EXPLOSION_SAVE_DISTANCE)
&& (p->d == up || p->d == down))) && (p->d == up || p->d == down)))
&& (!check_exfield (p->pos.x, p->pos.y))) && (!check_exfield (p->pos.x, p->pos.y)))
@ -540,11 +542,11 @@ player_died (_player * player, signed char dead_by)
{ {
// player die ! // player die !
d_printf ("player_died (%10s)\n", player->name); d_printf ("player_died (%10s) current state: %d\n", player->name, player->state);
bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; // force an update
if (PS_IS_alife (player->state) && dead_by >= 0 && dead_by < MAX_PLAYERS) if (PS_IS_alife (player->state) && dead_by >= 0 && dead_by < MAX_PLAYERS)
if (bman.p_nr != dead_by) if (player - players != dead_by)
players[dead_by].points++; players[dead_by].points++;
player->frame = 0; player->frame = 0;
player->state &= (0xFF - PSF_alife); player->state &= (0xFF - PSF_alife);
@ -554,7 +556,7 @@ player_died (_player * player, signed char dead_by)
net_game_send_player (player - players); net_game_send_player (player - players);
snd_play (SND_dead); snd_play (SND_dead);
if ((GT_SP || player == &players[bman.p_nr] if ((GT_SP || player == &players[bman.p_nr] || (IS_LPLAYER2 && player == &players[bman.p2_nr])
|| (PS_IS_aiplayer (player->state) && GT_MP_PTPM)) && bman.dropitemsondeath) { || (PS_IS_aiplayer (player->state) && GT_MP_PTPM)) && bman.dropitemsondeath) {
flitems_dropitems ((player - players), player->pos, player->collect_shoes, flitems_dropitems ((player - players), player->pos, player->collect_shoes,
player->bombs_n - bman.start_bombs, player->range - bman.start_range); player->bombs_n - bman.start_bombs, player->range - bman.start_range);
@ -579,6 +581,9 @@ player_animation (_player * player)
if (player->gfx == NULL) if (player->gfx == NULL)
return; return;
/*
* animation for the movement
*/
if (PS_IS_alife (player->state)) { if (PS_IS_alife (player->state)) {
player->frame += (timefactor * ANI_PLAYERTIMEOUT * 15 * player->speed); player->frame += (timefactor * ANI_PLAYERTIMEOUT * 15 * player->speed);
while ((int)player->frame >= player->gfx->ani.frames) while ((int)player->frame >= player->gfx->ani.frames)
@ -587,11 +592,17 @@ player_animation (_player * player)
player->frame += player->gfx->ani.frames; player->frame += player->gfx->ani.frames;
} }
/*
* dead player animation
*/
if (PS_IS_dead (player->state)) { if (PS_IS_dead (player->state)) {
if ((int)player->frame < gfx.dead.frames) if ((int)player->frame < gfx.dead.frames)
player->frame += (timefactor * ANI_PLAYERTIMEOUT); player->frame += (timefactor * ANI_PLAYERTIMEOUT);
} }
/*
* respawning animation
*/
if (PS_IS_respawn (player->state)) { if (PS_IS_respawn (player->state)) {
if ((int)player->frame < 2*gfx.respawn.frames) if ((int)player->frame < 2*gfx.respawn.frames)
player->frame += (timefactor * ANI_PLAYERTIMEOUT); player->frame += (timefactor * ANI_PLAYERTIMEOUT);
@ -940,7 +951,6 @@ void player_check (int pl_nr) {
if (players[pl_nr].keyf_special) if (players[pl_nr].keyf_special)
special_use (pl_nr); special_use (pl_nr);
players[pl_nr].keyf_special = 0; players[pl_nr].keyf_special = 0;
player_move (pl_nr);
} }
else { else {
players[pl_nr].m = 0; players[pl_nr].m = 0;
@ -948,3 +958,109 @@ void player_check (int pl_nr) {
player_checkdeath (pl_nr); player_checkdeath (pl_nr);
}; };
/*
* delete a player from the game
*/
void
player_delete (int pl_nr) {
char host[LEN_SERVERNAME];
char port[LEN_PORT];
d_printf ("player_delete (%d)\n", pl_nr);
bman.updatestatusbar = 1; // force an update
if (pl_nr == bman.p_nr) {
/* we're not wanted */
network_shutdown ();
menu_displaymessage ("Kicked", "You have been kicked from the server.");
bman.state = GS_startup;
}
else {
strncpy (host, players[pl_nr].net.addr.host, LEN_SERVERNAME);
strncpy (port, players[pl_nr].net.addr.port, LEN_PORT);
player_set_gfx (&players[pl_nr], -1);
players[pl_nr].state &= (0xFF - (PSF_used + PSF_net + PSF_alife + PSF_ai)); /* delete
player flags */
players[pl_nr].net.net_istep = 0; // needed for disconnect during the update
bman.players_nr_s--;
players[pl_nr].gfx_nr = -1;
/* send network update */
net_game_send_delplayer (pl_nr);
}
if (GT_MP_PTPS && pl_nr == bman.p_servnr) /* server quit */
bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster)
send_ogc_update ();
if (bman.p_nr == pl_nr)
bman.p_nr = -1;
if (bman.p2_nr == pl_nr)
bman.p2_nr = -1;
d_playerdetail (" Player Left ... Playerlist\n");
};
/*** player2_join ()
* the second local player wants to join the game
* - check if we are the host of the game , if we are the client
* or if we are in single mode.
* host: add second local player and send update to the clients
* client: send the information that a second local player wants
* to play too, do_playerid will add the player then and
* add the player finaly to the game over the function
* player2_add (pl_nr).
* single: add the second player.
*/
void player2_join () {
int i;
if (IS_LPLAYER2) {
menu_displaymessage ("Sorry", "Sorry there is already a second player from this computer.");
return;
}
if (GT_MP_PTPM) { /* multiplayer master/host */
for (i = 0; PS_IS_used (players[i].state) && i < MAX_PLAYERS; i++);
if (i < MAX_PLAYERS) { /* free player found */
player2_add (i);
net_send_players ();
} else {
menu_displaymessage ("Sorry", "There is no free playerslot left\n");
}
}
else if (GT_MP_PTPS) { /* multiplayer client, send only the request */
int flags = NETF_local2;
if (bman.firewall)
flags |= NETF_firewall;
send_joingame (&players[bman.p_servnr].net.addr, bman.player2name, flags);
}
else { /* single mode */
for (i = 0; !PS_IS_used (players[i].state) && i < MAX_PLAYERS; i++);
if (i < MAX_PLAYERS) { /* free player found */
player2_add (i);
}
}
};
/*
* add the second player to the game and set all variables
*/
void player2_add (int pl_nr) {
bman.p2_nr = pl_nr;
strncpy (players[pl_nr].name, bman.player2name, LEN_PLAYERNAME);
players[pl_nr].state += PSF_used;
players[pl_nr].gfx_nr = -1;
players[pl_nr].gfx = NULL;
players[pl_nr].points = 0;
players[pl_nr].wins = 0;
d_printf ("player2_add: Local Player Added with pl_nr: %d\n", pl_nr);
};

@ -1,12 +1,359 @@
/* $Id: playermenu.c,v 1.1 2004/04/03 15:47:13 stpohle Exp $ /* $Id: playermenu.c,v 1.2 2004/05/20 16:55:30 stpohle Exp $
* *
*/ */
#include "bomberclone.h" #include "bomberclone.h"
#include "menu.h" #include "menu.h"
#include "menugui.h"
#include "player.h"
#include "network.h"
#include "keyb.h"
#include "single.h"
#include "ogcache-client.h"
void player_menu () {
menu_new ("Playermenu", 420, 400); /*
menu_loop (); * prototype definitions
menu_delete (); */
static int playermenu_gfxaviable (int gfx);
static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu);
#define PLAYERMENU_GFXSEL_Y 130
/*
* check if the gfx is still aviable
*/
static int playermenu_gfxaviable (int gfx) {
int i;
for (i = 0; i < MAX_PLAYERS && gfx != players[i].gfx_nr; i++);
if (i == MAX_PLAYERS)
return 1;
return 0;
};
/*
* draw a list of all stil aviable players and the
* selection border of where we are at the moment
* ! menu == NULL, in this case just delete the gfx_aviable
* buffer to force an repaint of all gfx.
*/
static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu) {
static int gfx_aviable[2][MAX_PLAYERS]; // old and new state, 1 if gfx is aviable
static int old_gfxsel = -1;
static int changed = 0;
SDL_Rect rect, srcrect;
int i;
/*
* delete old state, to force an update of all playergfx
*/
if (menu == NULL) {
for (i = 0; i < MAX_PLAYERS; i++)
gfx_aviable[1][i] = -1;
changed = 1;
return;
}
/*
* check changes in the playerselections
* 1. copy current state into the old state and set all
* gfx as aviable.
*/
for (i = 0; i < MAX_PLAYERS; i++) {
gfx_aviable[0][i] = gfx_aviable[1][i] & 1;
gfx_aviable[1][i] = 1;
}
/*
* 2. delete the aviable flag from all selected player gfx
* set another bit to mark our selection, set the changedc flag if
* there was any change
*/
for (i = 0; i < MAX_PLAYERS; i++) {
if (PS_IS_used (players[i].state) && players[i].gfx_nr >= 0 && players[i].gfx_nr < MAX_PLAYERS)
gfx_aviable[1][players[i].gfx_nr] = 0;
}
for (i = 0; i < MAX_PLAYERS && changed == 0; i++) if (players[i].gfx_nr >= 0) changed = 1;
if (selgfx >= 0 && selgfx < MAX_PLAYERS) // do the selection
gfx_aviable[1][selgfx] += 2;
if (selgfx != old_gfxsel)
changed = 1;
old_gfxsel = selgfx;
/*
* 3. draw changes from the last loop
*/
if (changed) {
rect.x = 0;
rect.w = menu->oldscreenpos.w - 2 * menuimages[0]->w;
rect.y = PLAYERMENU_GFXSEL_Y;
rect.h = 4 * GFX_IMGSIZE;
menu_draw_background (menu, &rect);
for (i = 0; i < MAX_PLAYERS; i++) {
srcrect.h = rect.h = gfx.players[i].ani.h;
srcrect.w = rect.w = gfx.players[i].ani.w;
rect.x = GFX_IMGSIZE * (i % 4) + ((menu->oldscreenpos.w - 2 * menuimages[0]->w) -(4 * GFX_IMGSIZE)) / 2 ;
rect.y = GFX_IMGSIZE * (i / 4) + PLAYERMENU_GFXSEL_Y;
if (gfx_aviable[1][i] & 1) {
/* gfx is aviable */
srcrect.x = gfx.players[i].ani.w * down;
srcrect.y = 0;
rect.x += menu->oldscreenpos.x + menuimages[0]->w;
rect.y += menu->oldscreenpos.y + menuimages[0]->h;
gfx_blit (gfx.players[i].ani.image, &srcrect, gfx.screen, &rect, 10002);
}
if (gfx_aviable[1][i] & 2) {
/* draw the select border */
srcrect.x = 0;
srcrect.y = 0;
srcrect.h = rect.h = GFX_IMGSIZE;
srcrect.w = rect.w = GFX_IMGSIZE;
rect.x = GFX_IMGSIZE * (i % 4) + ((menu->oldscreenpos.w - 2 * menuimages[0]->w) -(4 * GFX_IMGSIZE)) / 2;
rect.y = GFX_IMGSIZE * (i / 4) + PLAYERMENU_GFXSEL_Y;
rect.x += (gfx.players[i].ani.w - gfx.menuselect.image->w) / 2; // center the playergfx
rect.x += menu->oldscreenpos.x + menuimages[0]->w;
rect.y += menu->oldscreenpos.y + menuimages[0]->h;
gfx_blit (gfx.menuselect.image, &srcrect, gfx.screen, &rect, 10001);
}
}
}
}
/*
+------------------------------------------------+
| Name Lokaler Player 1 : ________________ |
| Name Lokaler Player 2 : ________________ |
| |
| Button USE Lok. Pl.2 <--- if this is pressed a second local
| Button Add AI Player player will join.. still working on
| |
| List of Connected Players |
| | | Button Kick |
| | | |
| | | Button Info |
| | | |
| | | Button OK |
| +-----------------------+ |
+------------------------------------------------+
*/
void playermenu () {
_menu *menu;
_menuitem *btn_SecondPlayer;
_menuitem *list_PlayerList;
_charlist playerlist[MAX_PLAYERS + 1];
_charlist *playerlist_sel = &playerlist[0];
int i, menuselect = 0, done = 0, eventstate, pl_nr;
SDL_Event event;
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_used(players[i].state))
sprintf (playerlist[i].text, "%2d. %15s", i+1, players[i].name);
else
sprintf (playerlist[i].text, "%2d. %15s", i+1, "");
charlist_fillarraypointer (playerlist, MAX_PLAYERS);
menu = menu_new ("Playermenu", 400, 350);
menu_create_entry (menu, " Player 1 Name: ", -1, 50, 350, &bman.playername, LEN_PLAYERNAME, MENU_entrytext, 2);
menu_create_entry (menu, " Player 2 Name: ", -1, 80, 350, &bman.player2name, LEN_PLAYERNAME, MENU_entrytext, 3);
if (IS_LPLAYER2)
btn_SecondPlayer = menu_create_button (menu, "Quit Second Player", 25, 130, 190, 4);
else
btn_SecondPlayer = menu_create_button (menu, "Use Second Player", 25, 130, 190, 4);
if (GT_SP || GT_MP_PTPM)
menu_create_button (menu, "Add AI Player", 25, 160, 190, 5);
menu_create_label (menu, "Connected Players", 20, 210, 0, COLOR_brown);
list_PlayerList = menu_create_list (menu, "playerlist", 15, 230, 200, 120, playerlist, &playerlist_sel, 6);
if (GT_SP || GT_MP_PTPM)
menu_create_button (menu, "Kick Player", 240, 230, 150, 7);
// menu_create_button (menu, "Playerinfo", 240, 275, 150, 8);
menu_create_button (menu, "OK", 240, 320, 150, 1);
/* prepare everything for the menu_loop */
menu_focus_id (menu, 1);
menu->looprunning = 1;
menu_draw (menu);
/* the menu loop */
do {
for (i = 0; i < MAX_PLAYERS; i++) {
if (PS_IS_used(players[i].state))
sprintf (playerlist[i].text, "%2d. %15s", i+1, players[i].name);
else
sprintf (playerlist[i].text, "%2d. %15s", i+1, "");
}
list_PlayerList->changed = 1;
menu_draw_menuitem (list_PlayerList);
gfx_blitdraw ();
eventstate = SDL_PollEvent (&event);
if (bman.sock != -1)
network_loop ();
done = menu_event_loop (menu, &event, eventstate);
/*
* check if one of the buttons was pressed
*/
if (done == 1 && menu->focus->id == 4) { /* second local player want to join */
if (IS_LPLAYER2)
player_delete (bman.p2_nr);
else
player2_join ();
if (IS_LPLAYER2)
sprintf (btn_SecondPlayer->label, "Quit Second Player");
else
sprintf (btn_SecondPlayer->label,"Use Second Player");
menu_draw_button (btn_SecondPlayer);
}
if (done == 1 && menu->focus->id == 5) { /* create ai player */
single_create_ai (1);
done = 0;
}
if (done == 1 && menu->focus->id == 6) /* playerlist */
done = 0;
if (done == 1 && menu->focus->id == 7) { /* kick player */
pl_nr = playerlist_sel - &playerlist[0];
if (pl_nr >= 0 && pl_nr < MAX_PLAYERS && pl_nr != bman.p_servnr)
player_delete (pl_nr);
else
menu_displaymessage ("No", "You can't kick yourself from the game.\n");
done = 0;
}
if (done == 1 && menu->focus->id == 8) { /* player info */
// playermenu_info ();
done = 0;
}
s_calctimesync ();
} while ((done == 0 || menu->focus->id != 1) && done != -1 && menuselect != -1 && menuselect != 1);
if (menu->focus->id == 1 && done == 1) {
/*
* ok button pressed, so save all settings
*/
config_write ();
}
menu_delete (menu);
};
/*
* draw a small menu where the player has to select his gfx
*/
void playermenu_selgfx (int pl_nr) {
_menu *menu;
int selgfx, eventstate;
SDL_Event event;
Uint8 *keys;
int done = 0;
if (pl_nr < 0 || pl_nr >= MAX_PLAYERS)
return;
selgfx = players[pl_nr].gfx_nr;
if (selgfx < 0)
selgfx = 1;
playermenu_selgfx_drawplayer (-1, NULL);
player_set_gfx (&players[pl_nr], -1);
menu = menu_new ("Player Selection", 400, 270);
menu_create_text (menu, "playergfxsel", -1, 50, 40, 5, COLOR_yellow, "%s, please select your Player and press ENTER/RETURN or press ESCAPE for no player (that means you will only watch the next game).", players[pl_nr].name);
menu->looprunning = 1;
menu_draw (menu);
while (!done && bman.state != GS_quit) {
/* do the network loop if we have to */
if (bman.sock > 0) {
network_loop ();
if (bman.notifygamemaster)
ogc_loop ();
}
eventstate = SDL_PollEvent (&event);
if (eventstate) {
switch (event.type) {
case (SDL_QUIT):
bman.state = GS_quit;
done = 1;
menu_delete (menu);
return;
break;
case (SDL_KEYDOWN):
/*
* go to the next gfx or the preview one
*/
if (event.key.keysym.sym == SDLK_TAB) {
keys = SDL_GetKeyState (NULL);
if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) {
if ((--selgfx) < 0)
selgfx = MAX_PLAYERS-1;
}
else {
if ((++selgfx) >= MAX_PLAYERS)
selgfx = 0;
}
break;
}
/*
* cursor keys for gfx selection
*/
if (event.key.keysym.sym == SDLK_UP && selgfx >= 4)
selgfx -= 4;
if (event.key.keysym.sym == SDLK_DOWN && selgfx < MAX_PLAYERS-4)
selgfx += 4;
if (event.key.keysym.sym == SDLK_RIGHT && selgfx < MAX_PLAYERS-1)
selgfx++;
if (event.key.keysym.sym == SDLK_LEFT && selgfx > 0)
selgfx--;
/*
* do not select any gfx
*/
else if (event.key.keysym.sym == SDLK_ESCAPE) {
selgfx = -1;
done = 1;
break;
}
/*
* select the current gfx if aviable
*/
else if (event.key.keysym.sym == SDLK_RETURN
|| event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL
|| event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_special]
|| event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_special]) {
if (playermenu_gfxaviable (selgfx))
done = 1;
break;
}
}
}
playermenu_selgfx_drawplayer (selgfx, menu);
gfx_blitdraw ();
s_calctimesync ();
};
menu_delete (menu);
player_set_gfx (&players[pl_nr], selgfx);
}; };

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.62 2004/04/03 14:48:43 stpohle Exp $ */ /* $Id: single.c,v 1.63 2004/05/20 16:55:30 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -544,26 +544,6 @@ ai_checknewpos (_point pos, int d)
}; };
/* delete single players from the game */
void
single_delete_ai (int num_players)
{
int p,
count;
for (p = 0, count = 0; p < MAX_PLAYERS && count < num_players; p++) {
if (PS_IS_aiplayer (players[p].state)) {
/* ai player found... delete */
player_set_gfx (&players[p], -1);
players[p].state = 0;
players[p].net.addr.host[0] = 0;
players[p].net.addr.port[0] = 0;
count++;
}
}
};
/* create a giving number of ai players */ /* create a giving number of ai players */
void void
single_create_ai (int num_players) single_create_ai (int num_players)
@ -622,8 +602,12 @@ single_playergame ()
exit (1); exit (1);
} }
if ((players[bman.p_nr].gfx_nr = single_select_player ()) == -1) strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);
return; gfx_load_players (32, 32);
playermenu_selgfx (bman.p_nr);
gfx_free_players ();
if (players[bman.p_nr].gfx_nr == -1)
return;
players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing; players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing;
strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME); strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);
@ -721,7 +705,8 @@ single_menu ()
done = 0; done = 0;
_charlist nrplayerlist[MAX_PLAYERS + 1]; _charlist nrplayerlist[MAX_PLAYERS + 1];
_charlist *selnrplayer = &nrplayerlist[bman.ai_players]; _charlist *selnrplayer = &nrplayerlist[bman.ai_players];
_menu *menu;
/* fill in the nrplayerlist */ /* fill in the nrplayerlist */
if (debug) if (debug)
p = 0; p = 0;
@ -737,13 +722,13 @@ single_menu ()
} }
while (!done && bman.state != GS_quit) { while (!done && bman.state != GS_quit) {
menu_new ("Single Player", 300, 250); menu = menu_new ("Single Player", 300, 250);
menu_create_label ("Number Of AI Players", -1, 55, 0, COLOR_brown); menu_create_label (menu, "Number Of AI Players", -1, 55, 0, COLOR_brown);
menu_create_list ("Players", -1, 80, 70, 70, nrplayerlist, &selnrplayer, 1); menu_create_list (menu, "Players", -1, 80, 70, 70, nrplayerlist, &selnrplayer, 1);
menu_create_button ("Map Setting", -1, 180, 150, 2); menu_create_button (menu, "Map Setting", -1, 180, 150, 2);
menu_create_button ("OK", -1, 220, 150, 0); menu_create_button (menu, "OK", -1, 220, 150, 0);
menuselect = menu_loop (); menuselect = menu_loop (menu);
menu_delete (); menu_delete (menu);
/* read the current number of AI Players */ /* read the current number of AI Players */
bman.ai_players = (selnrplayer - &nrplayerlist[0]); bman.ai_players = (selnrplayer - &nrplayerlist[0]);

@ -1,4 +1,4 @@
/* $Id: special.c,v 1.34 2004/04/03 14:48:43 stpohle Exp $ */ /* $Id: special.c,v 1.35 2004/05/20 16:55:30 stpohle Exp $ */
/* special.c - procedues to control the specials */ /* special.c - procedues to control the specials */
#include "bomberclone.h" #include "bomberclone.h"
@ -23,7 +23,7 @@ special_trigger (int p_nr)
z++; // count the bombs which will explode z++; // count the bombs which will explode
} }
if (p_nr == bman.p_nr && GT_MP && z) if ((p_nr == bman.p_nr || p_nr == bman.p2_nr) && GT_MP && z)
net_game_send_special (p_nr, ex_nr, p->special.type); net_game_send_special (p_nr, ex_nr, p->special.type);
if (z) { if (z) {
@ -365,7 +365,7 @@ special_clear (int p_nr)
players[p_nr].special.type = 0; players[p_nr].special.type = 0;
bman.updatestatusbar = 1; bman.updatestatusbar = 1;
if (bman.p_nr == p_nr) if (bman.p_nr == p_nr || bman.p2_nr == p_nr)
net_game_send_special (p_nr, -1, SP_clear); net_game_send_special (p_nr, -1, SP_clear);
} }

Loading…
Cancel
Save