Loading / Autogenerating Maps Fixed Playerposition

origin
stpohle 23 years ago
parent 9178c7114a
commit baa433a6d1

@ -1,4 +1,6 @@
- Added: loadable maps. (ob1kenewb)
- Changed: now the send packet option will be set for every - Changed: now the send packet option will be set for every
player directly, so if a slow player joinsit should not anymore player directly, so if a slow player joinsit should not anymore
slow down the whole network game. slow down the whole network game.
@ -7,7 +9,7 @@
Player Selection screen. Player Selection screen.
- Fixed/Add: first support for international keyboards, so the - Fixed/Add: first support for international keyboards, so the
shift key should work. (more or less) thx. to: ob1kenewb shift key will work. thanks to (ob1kenewb) !
- Fixed: SuSe could not compile the game right. - Fixed: SuSe could not compile the game right.
#include <sys/time.h> was needed. not only <time.h> #include <sys/time.h> was needed. not only <time.h>

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.7 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* $Id: bomberclone.h,v 1.8 2003/05/05 04:14:55 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_
@ -154,6 +154,7 @@ extern void game_set_playerposition();
extern void draw_field (); extern void draw_field ();
extern void draw_stone (int x, int y); extern void draw_stone (int x, int y);
extern void field_new (char *filename); extern void field_new (char *filename);
extern void field_set_playerposition (int usermap);
// everything what is declared in players.c // everything what is declared in players.c
extern void dead_playerani (); extern void dead_playerani ();

@ -24,5 +24,6 @@ extern _chat chat;
extern void chat_show (int x1, int y1, int x2, int y2); extern void chat_show (int x1, int y1, int x2, int y2);
extern void chat_addline (char *text); extern void chat_addline (char *text);
extern void chat_loop (SDL_Event *event); extern void chat_loop (SDL_Event *event);
extern void chat_drawbox ();
#endif #endif

@ -53,8 +53,8 @@ int
ReadConfig () ReadConfig ()
{ {
FILE *config; FILE *config;
char buf[200], char buf[1024],
key2[50]; key2[1024];
char *findit, char *findit,
*keyword, *keyword,
*value; *value;

@ -1,4 +1,4 @@
/* $Id: field.c,v 1.7 2003/05/05 00:22:21 stpohle Exp $ */ /* $Id: field.c,v 1.8 2003/05/05 04:14:55 stpohle Exp $ */
/* field.c - procedures which are needed to control the field */ /* field.c - procedures which are needed to control the field */
#include <stdlib.h> #include <stdlib.h>
@ -84,7 +84,6 @@ draw_field ()
(# correspond to a bloc and @ correspond to a stone, (# correspond to a bloc and @ correspond to a stone,
an espace is nothing ' ' an espace is nothing ' '
% are commentary at the beginning of the map */ % are commentary at the beginning of the map */
void void
field_load (FILE * map) field_load (FILE * map)
{ {
@ -130,8 +129,136 @@ field_load (FILE * map)
bman.fieldsize.x = sizex - 1; bman.fieldsize.x = sizex - 1;
bman.fieldsize.y = sizey; bman.fieldsize.y = sizey;
/* darw the border so we know everything is right */
for (i = 0; i < bman.fieldsize.x; i++)
bman.field[i][0].type = bman.field[i][bman.fieldsize.y-1].type = FT_block;
for (i = 0; i < bman.fieldsize.y; i++)
bman.field[0][i].type = bman.field[bman.fieldsize.x-1][i].type = FT_block;
} }
/* will set the playerposition but in a way that we won't start on a block */
/* i am just too lazy to write this all again and again */
#define PLX bman.players[i].pos.x
#define PLY bman.players[i].pos.y
void field_set_playerposition (int usermap) {
int p, dist, i,j , mx, my, dx = 0, dy = 0;
char txt[255];
p = 50;
dist = 8;
while (p == 50) {
p = 0;
dist--;
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
if (usermap) {
int maxloop = 0;
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
maxloop++;
PLX = s_random (bman.fieldsize.x - 2) + 1;
PLY = s_random (bman.fieldsize.y - 2) + 1;
for (dx = 10, dy = 10, j = 0; (j < i && j < MAX_PLAYERS && (dx > 1 || dy > 1)); j++) { /* is ther any other player */
dx = PLX - bman.players[j].pos.x;
if (dx < 0) dx = - dx;
dy = PLY - bman.players[j].pos.y;
if (dy < 0) dy = - dy;
}
/* check if there is no block */
if ((dx > 1 || dy > 1) && ((bman.field[PLX][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY].type == FT_nothing)) {
/* get (up or down) dx and (left or right) dy */
dx = s_random (2);
if (dx == 0)
dx = -1;
dy = s_random (2);
if (dy == 0)
dy = -1;
/* first check if there is and free place for us */
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX+dx][PLY].type == FT_nothing))
dx = -dx;
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX+dx][PLY].type == FT_nothing))
PLX = -1;
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY+dy].type == FT_nothing))
dy = -dy;
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY+dy].type == FT_nothing))
PLY = -1;
}
else {
PLX = -1;
PLY = -1;
}
/* make some space */
if (PLX != -1 && PLY != -1) {
bman.field[PLX][PLY].type = FT_nothing;
bman.field[PLX+dx][PLY].type = FT_nothing;
bman.field[PLX][PLY+dy].type = FT_nothing;
}
}
}
if (PLX == -1 || PLY == -1) {
/* we could not set all fields or we don't run on a usermap */
if (usermap) {
sprintf (txt,"Not all players could be set (Pl:%d)", i);
menu_displaymessage ("MAP - ERROR",txt);
}
/* now there will be some fields deleted */
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
bman.field[PLX][PLY].type = FT_nothing;
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
/* up and down */
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
bman.field[PLX-1][PLY].type = FT_nothing;
else
bman.field[PLX+1][PLY].type = FT_nothing;
/* left and right */
if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2)
bman.field[PLX][PLY-1].type = FT_nothing;
else
bman.field[PLX][PLY+1].type = FT_nothing;
}
mx = my = 100;
for (j = 0; j <= i; j++) { /* search smalest distance */
dy = PLY - bman.players[j].pos.y;
dx = PLX - bman.players[j].pos.x;
if (dy < 0)
dy = -dy;
if (dx < 0)
dx = -dx;
if (mx > dx && i != j)
mx = dx;
if (my > dy && i != j)
my = dy;
}
if (mx > dist || my > dist)
i++;
else
p++;
}
}
for (i = 0; i < MAX_PLAYERS; i++) {
PLX = PLX << 8;
PLY = PLY << 8;
}
};
#undef PLX
#undef PLY
void void
field_new (char *filename) field_new (char *filename)
@ -146,14 +273,14 @@ field_new (char *filename)
/* if we can't open the given filename for any reason, reverting /* if we can't open the given filename for any reason, reverting
to default value else, load the file */ to default value else, load the file */
if (fmap) if (fmap)
field_load (fmap); field_load (fmap);
fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (bman.fieldsize.x * bman.fieldsize.y); /* this is the item factor we multiply it with this so we know
how much items we want in the game */
// Clean the field // fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
// Clean and create the field //
if (fmap == NULL) { if (fmap == NULL) {
for (x = 0; x < bman.fieldsize.x; x++) for (x = 0; x < bman.fieldsize.x; x++)
for (y = 0; y < bman.fieldsize.y; y++) { for (y = 0; y < bman.fieldsize.y; y++) {
@ -180,23 +307,6 @@ field_new (char *filename)
} }
} }
/* get some free space for the playerstart position */
for (d = 0; d < MAX_PLAYERS; d++)
if ((PS_IS_alife (bman.players[d].state)) != 0) {
x = bman.players[d].pos.x >> 8;
y = bman.players[d].pos.y >> 8;
bman.field[x][y].type = FT_nothing;
if (x > 1)
bman.field[x - 1][y].type = FT_nothing;
if (x < bman.fieldsize.x - 2)
bman.field[x + 1][y].type = FT_nothing;
if (y > 1)
bman.field[x][y - 1].type = FT_nothing;
if (y < bman.fieldsize.y - 2)
bman.field[x][y + 1].type = FT_nothing;
}
nb_try = 100; // to prevent infinite loops (maybe there are no stones) nb_try = 100; // to prevent infinite loops (maybe there are no stones)
/* put the fire powerups in the field */ /* put the fire powerups in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) { for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) {
@ -252,4 +362,6 @@ field_new (char *filename)
bman.field[x][y].special = FT_death; bman.field[x][y].special = FT_death;
x = y = 0; x = y = 0;
} }
field_set_playerposition (fmap != NULL);
} }

@ -81,15 +81,16 @@ game_draw_info ()
redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y); redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y);
for (x = 0; x < bman.fieldsize.x; x++) for (x = 0; x < bman.fieldsize.x; x++)
draw_stone (x, bman.fieldsize.y-1); draw_stone (x, bman.fieldsize.y-1);
sprintf (text, "Net Option: ["); if (debug) { /* do some debug informations on the screen */
for (i = 0 ; i < MAX_PLAYERS; i++) sprintf (text, "Net Option: [");
sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set); for (i = 0 ; i < MAX_PLAYERS; i++)
text[strlen(text)+1] = 0; sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set);
text[strlen(text)] = ']'; text[strlen(text)+1] = 0;
text[strlen(text)] = ']';
draw_text (0, gfx.res.y - gfx.font.size.y, text, 1); draw_text (0, gfx.res.y - gfx.font.size.y, text, 1);
gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y); gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y);
}
if (chat.visible == 0) { if (chat.visible == 0) {
SDL_Flip (gfx.screen); SDL_Flip (gfx.screen);
@ -226,41 +227,6 @@ game_loop ()
}; };
void game_set_playerposition () {
int p, dist, i,j , mx, my, dx, dy;
p = 50;
dist = 8;
while (p == 50) {
p = 0;
dist--;
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
bman.players[i].pos.x = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
bman.players[i].pos.y = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
mx = my = 100;
for (j = 0; j <= i; j++) { /* search smalest distance */
dy = bman.players[i].pos.y - bman.players[j].pos.y;
dx = bman.players[i].pos.x - bman.players[j].pos.x;
if (dy < 0)
dy = -dy;
if (dx < 0)
dx = -dx;
if (mx > dx && i != j)
mx = dx;
if (my > dy && i != j)
my = dy;
}
if (mx > dist || my > dist)
i++;
else
p++;
}
}
};
/* check which player won */ /* check which player won */
void void
game_end () game_end ()

@ -344,11 +344,11 @@ wait_for_players ()
done = 1; done = 1;
} }
if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) { if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) {
/* Map modification */ /* Map modification */
menu_get_text ("Enter the path of a field file", bman.fieldpath, 30); menu_get_text ("Enter the path of a field file", bman.fieldpath, 30);
draw_logo(); draw_logo ();
chat_drawbox(); chat_drawbox ();
} }
chat_loop (&event); chat_loop (&event);

@ -186,6 +186,8 @@ host_multiplayer_game ()
if (bman.p_nr != -1) { if (bman.p_nr != -1) {
bman.state = GS_update; bman.state = GS_update;
net_new_game ();
field_new (bman.fieldpath);
net_send_servermode (); net_send_servermode ();
gfx_game_init (); gfx_game_init ();
net_new_gamedata (); net_new_gamedata ();
@ -226,8 +228,8 @@ join_multiplayer_game ()
if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) { if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) {
gfx_game_init (); gfx_game_init ();
bman.state = GS_update;
bman.state = GS_update; net_new_game ();
net_new_gamedata (); net_new_gamedata ();
if (bman.state == GS_ready || bman.state == GS_running) if (bman.state == GS_ready || bman.state == GS_running)

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.10 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* $Id: network.c,v 1.11 2003/05/05 04:14:55 stpohle Exp $ */
/* /*
network routines. network routines.
*/ */
@ -400,7 +400,6 @@ net_new_gamedata ()
Uint8 *keys; Uint8 *keys;
Uint32 downtimestamp = 0; Uint32 downtimestamp = 0;
net_host_new_game (); // we do it to for the clients 'cause we need to reset the clients
draw_logo (); draw_logo ();
if (GT_MP_PTPM) if (GT_MP_PTPM)
@ -727,7 +726,7 @@ net_game_send_ill (int p_nr)
after this the data should be transfered to the other clients. after this the data should be transfered to the other clients.
*/ */
void void
net_host_new_game () net_new_game ()
{ {
int p, int p,
i; i;
@ -737,8 +736,6 @@ net_host_new_game ()
bman.players[i].pos.y = bman.players[i].pos.x = -1; bman.players[i].pos.y = bman.players[i].pos.x = -1;
bman.players_nr = 0; bman.players_nr = 0;
game_set_playerposition ();
bman.players_nr_s = 0; bman.players_nr_s = 0;
for (p = 0; p < MAX_PLAYERS; p++) { for (p = 0; p < MAX_PLAYERS; p++) {
bman.players[p].pos.x = bman.players[p].pos.x << 8; bman.players[p].pos.x = bman.players[p].pos.x << 8;
@ -777,8 +774,6 @@ net_host_new_game ()
} }
} }
field_new (bman.fieldpath);
bman.players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player bman.players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player
bman.last_ex_nr = 1; bman.last_ex_nr = 1;
}; };

@ -68,6 +68,7 @@ extern void network_shutdown ();
extern int network_init (); extern int network_init ();
extern int network_loop (); extern int network_loop ();
extern void net_change_playerid (int pl_nr, unsigned char senddata); extern void net_change_playerid (int pl_nr, unsigned char senddata);
extern void net_new_game ();
extern void net_new_gamedata (); extern void net_new_gamedata ();
extern void net_game_send_player (int p_nr); extern void net_game_send_player (int p_nr);
extern void net_game_send_playermove (int p_nr, int mustsend); extern void net_game_send_playermove (int p_nr, int mustsend);
@ -82,8 +83,6 @@ extern void net_send_players ();
extern int net_check_timeout (int pl_nr); extern int net_check_timeout (int pl_nr);
extern void net_dyn_pkgoption (); extern void net_dyn_pkgoption ();
extern void net_send_chat (char *text, signed char notigamesrv); extern void net_send_chat (char *text, signed char notigamesrv);
extern void net_host_new_game ();
// multiwait.c // multiwait.c
extern void wait_for_players (); extern void wait_for_players ();

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.3 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* $Id: single.c,v 1.4 2003/05/05 04:14:56 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -12,8 +12,8 @@ single_game_new (int ai_players)
// set players on field 1,1 // set players on field 1,1
for (p = 0; p < MAX_PLAYERS; p++) { for (p = 0; p < MAX_PLAYERS; p++) {
bman.players[p].pos.x = 1 << 8; bman.players[p].pos.x = -1;
bman.players[p].pos.y = 1 << 8; bman.players[p].pos.y = -1;
bman.players[p].state = 0; bman.players[p].state = 0;
// reset bombs // reset bombs

Loading…
Cancel
Save