Display failure messages
This commit is contained in:
parent
94df5eb6dd
commit
9aee736978
2
Makefile
2
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
|
||||
|
||||
|
2
bomber.h
2
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
|
||||
|
||||
|
24
draw.c
24
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
draw.h
2
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 */
|
||||
|
63
game.c
63
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<gountil) {
|
||||
++mycount;
|
||||
if(network) {
|
||||
if(NETWORK_NONE != network) {
|
||||
i=gountil-mycount;
|
||||
if(i>=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);
|
||||
}
|
||||
|
1
game.h
1
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;
|
||||
|
||||
|
203
menu.c
203
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<MAXNETNODES;++i)
|
||||
{
|
||||
if(!netnodes[i].used) continue;
|
||||
memmove(name,netnodes[i].name,16);
|
||||
name[16]=0;
|
||||
sprintf(temp," %d %s",i+1,name);
|
||||
drawbigstring(JX,JY+(i+1)*bigfontyspace,temp);
|
||||
}
|
||||
}
|
||||
|
||||
static int tryjoin(int which) {
|
||||
int res;
|
||||
|
||||
if (0 == (res = send_join(&gamelistentries[which].netname, playername)))
|
||||
return 0;
|
||||
|
||||
for ( ;; ) {
|
||||
switch (res) {
|
||||
case 1: return 0;
|
||||
case 2:
|
||||
drawjoinscreen();
|
||||
copyup();
|
||||
break;
|
||||
case 3: return 1;
|
||||
default: break;
|
||||
}
|
||||
scaninput();
|
||||
while(anydown()) {
|
||||
switch(takedown()) {
|
||||
case 0x1b:
|
||||
send_quit();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
res=scaninvite(200);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void main_menu(void) {
|
||||
int sel;
|
||||
|
||||
while(!exitflag) {
|
||||
menustart();
|
||||
additem("BOMBER MAIN MENU");
|
||||
additem("EXIT GAME");
|
||||
additem("START SINGLE PLAYER GAME");
|
||||
additem("OPTIONS");
|
||||
// additem("REMAP MOVEMENT KEYS");
|
||||
additem("START NETWORK GAME");
|
||||
additem("JOIN NETWORK GAME");
|
||||
sel=domenu(MENU_MAIN, NULL);
|
||||
if(!sel) {exitflag=1;break;}
|
||||
if(sel==1) {gamemode=1;break;}
|
||||
if(sel==2) {gamemode=2;break;}
|
||||
if(sel==3) {gamemode=3;break;}
|
||||
if(sel==4) {gamemode=4;break;}
|
||||
}
|
||||
}
|
||||
|
||||
char *densities[]={"PACKED","HIGH","MEDIUM","LOW"};
|
||||
char *generosities[]={"LOW","MEDIUM","HIGH","RIDICULOUS"};
|
||||
|
||||
static void config_menu(void) {
|
||||
int sel;
|
||||
|
||||
for(;;) {
|
||||
while (!exitflag) {
|
||||
menustart();
|
||||
additem("GAME OPTIONS");
|
||||
additem("RETURN TO MAIN MENU");
|
||||
@ -258,30 +188,29 @@ static void config_menu(void) {
|
||||
additem("INITIAL FLAME LENGTH: %d",configopts.flames+1);
|
||||
additem("INITIAL NUMBER OF BOMBS: %d",configopts.bombs+1);
|
||||
sel=domenu(MENU_CONFIG, NULL);
|
||||
if(!sel) {gamemode=0;break;}
|
||||
if(sel==1) {
|
||||
switch (sel) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
configopts.density+=menudelta;
|
||||
configopts.density&=3;
|
||||
}
|
||||
if(sel==2) {
|
||||
break;
|
||||
case 2:
|
||||
configopts.generosity+=menudelta;
|
||||
configopts.generosity&=3;
|
||||
}
|
||||
if(sel==3) {
|
||||
break;
|
||||
case 3:
|
||||
configopts.flames+=menudelta;
|
||||
configopts.flames&=7;
|
||||
}
|
||||
if(sel==4) {
|
||||
break;
|
||||
case 4:
|
||||
configopts.bombs+=menudelta;
|
||||
configopts.bombs&=7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void failure(char *str,...) {
|
||||
gamemode=0;
|
||||
}
|
||||
|
||||
static void draw_host_game(void) {
|
||||
int i;
|
||||
char *name;
|
||||
@ -319,13 +248,12 @@ static void host_game(void) {
|
||||
case 0x1b:
|
||||
unregistergame();
|
||||
cancel_network_game();
|
||||
gamemode=0;
|
||||
return;
|
||||
case ' ':
|
||||
case 13:
|
||||
unregistergame();
|
||||
if (begin_network_game()) {
|
||||
gamemode=5;
|
||||
run_network_game();
|
||||
return;
|
||||
}
|
||||
send_invites();
|
||||
@ -338,8 +266,58 @@ static void host_game(void) {
|
||||
send_invites();
|
||||
draw_host_game();
|
||||
}
|
||||
}
|
||||
|
||||
gamemode=0;
|
||||
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 < MAXNETNODES; ++i) {
|
||||
if(!netnodes[i].used) continue;
|
||||
memmove(name,netnodes[i].name,16);
|
||||
name[16]=0;
|
||||
sprintf(temp," %d %s",i+1,name);
|
||||
drawbigstring(JX,JY+(i+1)*bigfontyspace,temp);
|
||||
}
|
||||
}
|
||||
|
||||
static int tryjoin(int which) {
|
||||
int res;
|
||||
|
||||
if (0 == (res = send_join(&gamelistentries[which].netname, playername))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!exitflag) {
|
||||
switch (res) {
|
||||
case 1:
|
||||
failure("Game closed");
|
||||
return 0;
|
||||
case 2:
|
||||
drawjoinscreen();
|
||||
copyup();
|
||||
break;
|
||||
case 3: return 1;
|
||||
default: break;
|
||||
}
|
||||
scaninput();
|
||||
while(anydown()) {
|
||||
switch(takedown()) {
|
||||
case 0x1b:
|
||||
send_quit();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
res=scaninvite(200);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int join_game_pause(void) {
|
||||
@ -353,7 +331,6 @@ static void join_game(void) {
|
||||
int sel = -1;
|
||||
|
||||
if (!searchgames()) {
|
||||
gamemode = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -372,33 +349,49 @@ static void join_game(void) {
|
||||
addexit("EXIT");
|
||||
}
|
||||
sel = domenu(MENU_JOIN, join_game_pause);
|
||||
if (menudelta < 0) sel = -1;
|
||||
}
|
||||
stop_search();
|
||||
|
||||
if(menuexit == sel || !gamelistsize) {
|
||||
gamemode=0;
|
||||
return;
|
||||
}
|
||||
if(!tryjoin(sel)) {
|
||||
gamemode=0;
|
||||
return;
|
||||
}
|
||||
network = NETWORK_SLAVE;
|
||||
gamemode=5;
|
||||
run_network_game();
|
||||
}
|
||||
|
||||
void (*modefunctions[])()= {
|
||||
main_menu,
|
||||
run_single_player,
|
||||
config_menu,
|
||||
host_game,
|
||||
join_game,
|
||||
run_network_game,
|
||||
};
|
||||
|
||||
|
||||
void mainloop(void) {
|
||||
int sel;
|
||||
|
||||
exitflag = 0;
|
||||
while(!exitflag)
|
||||
modefunctions[gamemode]();
|
||||
while(!exitflag) {
|
||||
menustart();
|
||||
additem("BOMBER MAIN MENU");
|
||||
additem("EXIT GAME");
|
||||
additem("START SINGLE PLAYER GAME");
|
||||
additem("OPTIONS");
|
||||
// additem("REMAP MOVEMENT KEYS");
|
||||
additem("START NETWORK GAME");
|
||||
additem("JOIN NETWORK GAME");
|
||||
sel=domenu(MENU_MAIN, NULL);
|
||||
if (menudelta < 0) sel = -1;
|
||||
switch (sel) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
run_single_player();
|
||||
break;
|
||||
case 2:
|
||||
config_menu();
|
||||
break;
|
||||
case 3:
|
||||
host_game();
|
||||
break;
|
||||
case 4:
|
||||
join_game();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
menu.h
2
menu.h
@ -3,8 +3,6 @@
|
||||
|
||||
void mainloop(void);
|
||||
|
||||
int iterate(void); /* bomber.c */
|
||||
|
||||
extern struct GameOptions configopts;
|
||||
|
||||
#endif
|
||||
|
18
network.c
18
network.c
@ -5,13 +5,14 @@
|
||||
#include "menu.h"
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
#include "draw.h"
|
||||
|
||||
#define MAXMSG 4096
|
||||
|
||||
int udpsocket;
|
||||
const unsigned char gameversion[4]={0xda,0x01,0x00,0x05};
|
||||
|
||||
struct netnode netnodes[64];
|
||||
struct netnode netnodes[MAXNETNODES];
|
||||
|
||||
static int informsize;
|
||||
static unsigned char regpacket[64];
|
||||
@ -63,6 +64,13 @@ enum reject_reason {
|
||||
/* TODO: password? */
|
||||
};
|
||||
|
||||
#define _REJECT_LAST REJECT_VERSION
|
||||
|
||||
const char *reject_reason_str[] = {
|
||||
"Server full",
|
||||
"Version mismatch"
|
||||
};
|
||||
|
||||
/* all bytes stored MSB first */
|
||||
|
||||
/*
|
||||
@ -671,6 +679,7 @@ int scaninvite(int msec) {
|
||||
}
|
||||
|
||||
if (*mesg == PKT_BEGIN) {
|
||||
network = NETWORK_SLAVE;
|
||||
return 3;
|
||||
} else {
|
||||
return 2;
|
||||
@ -708,12 +717,17 @@ int send_join(struct sockaddr_in *netname, char playername[16]) {
|
||||
if (!read_inform(&buf,&size)) return 0;
|
||||
return 2;
|
||||
case PKT_REJECT:
|
||||
/* TODO: print reject message */
|
||||
if (size < 10 || mesg[9] > _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;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,15 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user