From 9aee736978d6c283e9a9b83fdbf5789a40503e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Mon, 10 Aug 2009 00:02:13 +0200 Subject: [PATCH] Display failure messages --- Makefile | 2 +- bomber.h | 2 +- draw.c | 24 +++++++ draw.h | 2 + game.c | 63 +++++++---------- game.h | 1 - menu.c | 205 ++++++++++++++++++++++++++---------------------------- menu.h | 2 - network.c | 18 ++++- network.h | 9 +-- 10 files changed, 173 insertions(+), 155 deletions(-) diff --git a/Makefile b/Makefile index 61d1ee1..6bd384f 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ list.o: list.c bomber.h list.h utils.h menu.o: menu.c announce.h bomber.h draw.h game.h gfx.h list.h menu.h network.h sound.h utils.h -network.o: network.c announce.h bomber.h game.h menu.h network.h utils.h +network.o: network.c announce.h bomber.h draw.h game.h menu.h network.h utils.h sound.o: sound.c sound.h diff --git a/bomber.h b/bomber.h index b3cb963..8d1ccb4 100644 --- a/bomber.h +++ b/bomber.h @@ -204,7 +204,7 @@ typedef struct bonustile { #define MAXTHINGS 500 #define MAXSETS 8 -#define MAXSPRITES 128 +#define MAXSPRITES 256 #define MAXDAMAGES 512 #define MAXBOMBSDETONATED 32 diff --git a/draw.c b/draw.c index 5963e77..c6439e1 100644 --- a/draw.c +++ b/draw.c @@ -446,3 +446,27 @@ void loadgfx() { free(gs); bigscrprintf("Done loading graphics\n"); } + +void failure(char *str,...) { + char output[256]; + va_list ap; + int len; + long now; + + va_start(ap, str); + + len = vsnprintf(output, sizeof(output), str, ap); + if (len >= 256) len = 255; /* truncated string */ + clear(); + drawbigstring((IXSIZE - len*bigfontxsize) / 2, (IYSIZE-bigfontysize) / 2, output); + copyup(); + + now = longtime(); + while (!exitflag && longtime()-now < 3) { + scaninput(); + if (anydown()) { + takedown(); + return; + } + } +} diff --git a/draw.h b/draw.h index ecc8e93..89eb65e 100644 --- a/draw.h +++ b/draw.h @@ -21,6 +21,8 @@ int screentoarrayy(int y); int arraytoscreenx(int x); int arraytoscreeny(int y); +void failure(char *str,...); + extern int bigfontxsize,bigfontysize,bigfontyspace; /* On screen array variables */ diff --git a/game.c b/game.c index 18e4115..e331c4c 100644 --- a/game.c +++ b/game.c @@ -23,8 +23,6 @@ static int detonatetake=0; static list activeflames; static list activeplayers; -#define REGISTERLEN (1+4+4+4+16+1) - figure walking[MAXSETS][NUMWALKFRAMES]; solid background,backgroundoriginal; @@ -32,7 +30,6 @@ solid background,backgroundoriginal; unsigned char field[32][32]; void *info[32][32]; -int gamemode = 0; char exitflag = 0; static int framecount = 0; @@ -53,7 +50,7 @@ TILE_NONE,160 static GameOptions gameoptions; -static const unsigned char playerpositions[] = { /* color, x, y */ +static const unsigned char playerpositions[MAXNETNODES*3] = { /* color, x, y */ 2,0,0, 3,14,10, 4,14,0, @@ -94,7 +91,7 @@ static void initplayers(void) { const unsigned char *p; int c,x,y; - if(!network) { + if(NETWORK_NONE == network) { initplayer(2,0,0,-1); return; } @@ -173,33 +170,6 @@ static void initgame() { copyup(); } - -void run_single_player(void) { - int code; - network=0; - - firstzero(); - do { - initgame(); - while(!(code=iterate())) ++framecount; - } while (code != CODE_QUIT); - - gamemode=0; -} - -void run_network_game(void) { - int code; - - firstzero(); - do { - initgame(); - while(!(code=iterate())) ++framecount; - } while (code != CODE_QUIT); - - network = 0; - gamemode = 0; -} - static void addflame(player *owner,int px,int py) { flame *fl,*fl2; @@ -863,7 +833,7 @@ static int getaction(void) { return what; } -int iterate(void) { +static int iterate(void) { int i; static int deathcount=0; @@ -875,7 +845,7 @@ int iterate(void) { gfxunlock(); myaction=getaction(); - if(!network && myaction==ACT_QUIT) return CODE_QUIT; + if(NETWORK_NONE == network && myaction==ACT_QUIT) return CODE_QUIT; i=networktraffic(); if(i<0) gountil=mycount+1; @@ -884,7 +854,7 @@ int iterate(void) { while(mycount=ACTIONHIST) // too far behind return CODE_QUIT; @@ -928,7 +898,7 @@ int iterate(void) { deadplayers++; pl=pl->next; } - if (deadplayers > 0 && (!i || (network && i==1))) { + if (deadplayers > 0 && (!i || (NETWORK_NONE != network && i==1))) { ++deathcount; if(deathcount==25) return CODE_ALLDEAD; @@ -941,3 +911,24 @@ int iterate(void) { void set_game_options(GameOptions *options) { gameoptions = *options; } + +void run_single_player(void) { + int code; + network = NETWORK_NONE; + + firstzero(); + do { + initgame(); + while(!(code=iterate()) && !exitflag) ++framecount; + } while (code != CODE_QUIT && !exitflag); +} + +void run_network_game(void) { + int code; + + firstzero(); + do { + initgame(); + while (!(code=iterate()) && !exitflag) ++framecount; + } while (code != CODE_QUIT && !exitflag); +} diff --git a/game.h b/game.h index f66409d..084feb5 100644 --- a/game.h +++ b/game.h @@ -21,7 +21,6 @@ void run_network_game(void); void set_game_options(GameOptions *options); extern char playername[16]; -extern int gamemode; extern solid background,backgroundoriginal; diff --git a/menu.c b/menu.c index 2675245..4bb5bcc 100644 --- a/menu.c +++ b/menu.c @@ -118,7 +118,8 @@ static int domenu(menuname whichmenu, int (*pause)(void)) { } } } - return 0; + menudelta = 0; + return menuexit; } static void menustart() { @@ -172,84 +173,13 @@ static void addexit(char *item,...) { /* game menues */ -static void drawjoinscreen(void) { -int i; -char name[17]; -char temp[64]; - -#define JX (IXSIZE/3) -#define JY (IYSIZE/4) - - clear(); - centerbig(20,"JOIN NETWORK GAME"); - drawbigstring(JX,JY,"SLOT NAME"); - for(i=0;i _REJECT_LAST) { + failure("Couldn't connect"); + } else { + failure("Couldn't connect: %s", reject_reason_str[mesg[9]]); + } return 0; default: break; } } + failure("Could not connect - Timeout"); return 0; } diff --git a/network.h b/network.h index 3fa5628..7ac98dd 100644 --- a/network.h +++ b/network.h @@ -5,13 +5,15 @@ #include #include +#define MAXNETNODES 8 + struct netnode { struct sockaddr_in netname; char name[16]; char used; }; -extern struct netnode netnodes[64]; +extern struct netnode netnodes[MAXNETNODES]; void getsocket(void); void freesocket(void); @@ -27,11 +29,6 @@ int begin_network_game(); void send_invites(); void cancel_network_game(); -#define MAXNETNODES 10 - -extern struct netnode netnodes[64]; - -extern int udpsocket; extern const unsigned char gameversion[4]; typedef enum { NETWORK_NONE = 0, NETWORK_MASTER, NETWORK_SLAVE } network_type;