single player first wort to a full single player game

origin
stpohle 23 years ago
parent 26062e089d
commit c4eedcf3c6

@ -1,15 +1,26 @@
$Id: ChangeLog,v 1.29 2003/07/23 23:45:51 stpohle Exp $
$Id: ChangeLog,v 1.30 2003/07/24 01:47:48 stpohle Exp $
Version 0.9.10
==============
- TekKRat made two new players, the first two
tilesets with the pseudo 3D effect
(64x96 pixel tileset) and another tileset.
(cemetery, sheep, hell and farm)
- caccola made another Tileset (supermario)
- Added: Switch to enable/disable broadcasted chats.
So the confusing will stop why there are unknown people
talking. You can enable it in the Network Options.
- fixed: chat_findfreeline, there was a bug in the
source and destination of copying the chatlines.
Thats why the chat got mixed up after 255 lines.
- maps have more options to set and it will be displayed
in the multiplayer menu, this options can be saved for
every map seperated
- Added: maps have more options to set and it will be
displayed in the multiplayer menu, this options can be
saved for every map seperated.
- gfx, source cleanup. player will now drawn in order they
stay tileset will change we can support 64x64pixel size

@ -1,4 +1,4 @@
$Id: TODO,v 1.15 2003/07/23 23:43:34 stpohle Exp $
$Id: TODO,v 1.16 2003/07/24 01:47:48 stpohle Exp $
next version (0.9.10):
======================
@ -7,11 +7,6 @@ next version (0.9.10):
- more specials (Kicking Bomb, Pushing Bomb Ver.2)
- Switch to enable/disable broadcasting chat messages to the bomberclone
mserv
- chat screen
- network joining menu Add: information about the playernames and
the point list.

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.39 2003/07/22 18:29:08 stpohle Exp $ */
/* $Id: basic.h,v 1.40 2003/07/24 01:47:48 stpohle Exp $ */
/* basic types which we need everywhere */
#ifndef _BC_BASIC_H_
@ -78,6 +78,9 @@
#define MENU_BG_SHADE_DARK -64
#define MENU_BG_SHADE_BRIGHT 64
#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (bman.players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--);
enum _networkflags {
NETF_firewall = 1
};

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.45 2003/07/22 18:29:08 stpohle Exp $ */
/* $Id: bomberclone.h,v 1.46 2003/07/24 01:47:48 stpohle Exp $ */
/* bomberclone.h */
#ifndef _BOMBERCLONE_H_
@ -147,7 +147,8 @@ struct __bomberclone {
char gamemaster[LEN_SERVERNAME + LEN_PORT + 2]; // ** CONFIG ... GameMaster Address
unsigned char firewall;
unsigned char notifygamemaster;
unsigned char askplayername; // ask player for name at startup
unsigned char broadcasted_chat; // 1 if the chat should be send to the bc server
unsigned char askplayername; // ask player for name at startup
unsigned char ai_players; // number of ai players
signed char debug; // 0 = off 1 = on
@ -250,9 +251,10 @@ extern void single_create_ai (int players);
extern void single_loop();
extern void single_playergame ();
extern void single_menu ();
extern int single_select_player ();
extern int ai_choosedir (int dir, int nearbomb, int oldpos);
extern int ai_invertdir (int dir);
extern int ai_checkpos (_player * pl, _point * pos);
extern inline int ai_invertdir (int dir);
extern inline int ai_checkpos (_player * pl, _point * pos);
extern int ai_findnearbombs (_point pos);
extern int ai_findbestbombdir (_point pos, int dir, int range);
extern int ai_bombpoints (_point pos, int range);

@ -57,6 +57,7 @@ game_init (int argc, char **argv)
map.map[0] = 0;
map.map_selection = 2;
bman.firewall = 0;
bman.broadcasted_chat = 0;
bman.ai_players = 1;
snd.inited = 0;
map.bombs = GAME_SPECIAL_ITEMBOMB;
@ -181,6 +182,9 @@ ReadConfig ()
if (!strcmp (keyword, "firewall")) {
bman.firewall = atoi (value);
}
if (!strcmp (keyword, "broadcasted_chat")) {
bman.broadcasted_chat = atoi (value);
}
if (!strcmp (keyword, "udpport")) {
if (strlen (value) > LEN_PORT) {
d_printf
@ -256,6 +260,7 @@ WriteConfig ()
fprintf (config, "tileset=%s\n", map.tileset);
fprintf (config, "mapname=%s\n", map.map);
fprintf (config, "firewall=%d\n", bman.firewall);
fprintf (config, "broadcasted_chat=%d\n", bman.broadcasted_chat);
fprintf (config, "udpport=%s\n", bman.port);
fprintf (config, "ai_players=%d\n", bman.ai_players);
fprintf (config, "fieldsizex=%d\n", map.size.x);

@ -9,7 +9,8 @@
#include "packets.h"
#include "chat.h"
extern int blitdb_nr, blitrects_nr;
extern int blitdb_nr,
blitrects_nr;
static Uint32 timediff,
timediff1;
@ -26,76 +27,70 @@ game_draw_info ()
dest;
if (bman.updatestatusbar) {
redraw_logo (0, 0, gfx.res.x, 3 * 16);
redraw_logo (0, 0, gfx.res.x, 3 * 16);
bman.updatestatusbar = 0;
dest.x = dest.y = 0;
dest.h = 3*16;
dest.w = gfx.res.x;
dest.x = dest.y = 0;
dest.h = 3 * 16;
dest.w = gfx.res.x;
gfx_blitupdaterectadd (&dest);
bman.players_nr = 0;
if (GT_MP_PTP) {
/* In Multiplayer mode draw Player names and
count the players who are still alife. */
for (x = 0, j = 0, i = 0; i < MAX_PLAYERS; i++)
if ((bman.players[i].state & PSFM_used) != 0) {
if (bman.players[i].gfx_nr != -1 && PS_IS_used (bman.players[i].state)) {
src.x = 3 * bman.players[i].gfx->smal_size.x;
src.y = 0;
src.w = dest.w = bman.players[i].gfx->smal_size.x;
src.h = dest.h = bman.players[i].gfx->smal_size.y;
dest.x = x;
dest.y = j - 4;
SDL_BlitSurface (bman.players[i].gfx->smal_image, &src, gfx.screen, &dest);
}
sprintf (scrtext, "%10s:%2d", bman.players[i].name, bman.players[i].points);
if (!PS_IS_alife(bman.players[i].state)) { // Player is dead
if ((bman.players[i].state & PSF_used) != PSF_used)
font_setcolor (128,128,128,0);
else
font_setcolor (0,0,128,0);
}
else { // players is alife
font_setcolor (128,128,255, 0);
bman.players_nr++;
}
font_draw (x, j, scrtext, 0);
x = x + 170;
if (x >= gfx.res.x - (120 + 170)) {
x = 0;
j = j + font[0].size.x;
}
/* In Multiplayer mode draw Player names and
count the players who are still alife. */
for (x = 0, j = 0, i = 0; i < MAX_PLAYERS; i++)
if ((bman.players[i].state & PSFM_used) != 0) {
if (bman.players[i].gfx_nr != -1 && PS_IS_used (bman.players[i].state)) {
src.x = 3 * bman.players[i].gfx->smal_size.x;
src.y = 0;
src.w = dest.w = bman.players[i].gfx->smal_size.x;
src.h = dest.h = bman.players[i].gfx->smal_size.y;
dest.x = x;
dest.y = j - 4;
SDL_BlitSurface (bman.players[i].gfx->smal_image, &src, gfx.screen, &dest);
}
}
else
/* in single mode count the player's who are still alife */
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_alife (bman.players[i].state))
sprintf (scrtext, "%10s:%2d", bman.players[i].name, bman.players[i].points);
if (!PS_IS_alife (bman.players[i].state)) { // Player is dead
if ((bman.players[i].state & PSF_used) != PSF_used)
font_setcolor (128, 128, 128, 0);
else
font_setcolor (0, 0, 128, 0);
}
else { // players is alife
font_setcolor (128, 128, 255, 0);
bman.players_nr++;
}
font_setcolor (255,255,255, 0);
font_draw (x, j, scrtext, 0);
x = x + 170;
if (x >= gfx.res.x - (120 + 170)) {
x = 0;
j = j + font[0].size.x;
}
}
font_setcolor (255, 255, 255, 0);
x = gfx.res.x - 120;
sprintf (text, "Bombs: %2d", bman.players[bman.p_nr].bombs_n);
font_draw (x, 0, text, 0);
sprintf (text, "Range: %2d", bman.players[bman.p_nr].range);
font_draw (x, 16, text, 0);
sprintf (text, "Speed: %2d", bman.players[bman.p_nr].speed);
font_draw (x, 32, text, 0);
if (bman.players[bman.p_nr].special.type != 0) {
dest.x = x - 32;
dest.y = 16;
dest.w = gfx.smal_special[bman.players[bman.p_nr].special.type - 1]->w;
dest.h = gfx.smal_special[bman.players[bman.p_nr].special.type - 1]->h;
SDL_BlitSurface (gfx.smal_special[bman.players[bman.p_nr].special.type - 1], NULL, gfx.screen, &dest);
}
sprintf (text, "Speed: %2d", bman.players[bman.p_nr].speed);
font_draw (x, 32, text, 0);
if (bman.players[bman.p_nr].special.type != 0) {
dest.x = x - 32;
dest.y = 16;
dest.w = gfx.smal_special[bman.players[bman.p_nr].special.type - 1]->w;
dest.h = gfx.smal_special[bman.players[bman.p_nr].special.type - 1]->h;
SDL_BlitSurface (gfx.smal_special[bman.players[bman.p_nr].special.type - 1], NULL,
gfx.screen, &dest);
}
if (bman.state == GS_ready && GT_MP_PTPM)
font_draw (100, 32, "Press F4 to start the game", 0);
@ -122,9 +117,9 @@ game_loop ()
draw_field ();
if (GT_MP_PTP)
net_game_fillsockaddr ();
SDL_Flip (gfx.screen);
SDL_Flip (gfx.screen);
bman.updatestatusbar = 1; // force an update
bman.updatestatusbar = 1; // force an update
timestamp = SDL_GetTicks (); // needed for time sync.
d_gamedetail ("GAME START");
draw_players ();
@ -174,7 +169,7 @@ game_loop ()
/* Server is starting the game */
bman.state = GS_running;
net_send_servermode ();
bman.updatestatusbar = 1; // force an update
bman.updatestatusbar = 1; // force an update
}
if (event.key.keysym.sym == SDLK_ESCAPE && event.type == SDL_KEYDOWN) {
@ -186,13 +181,13 @@ game_loop ()
restore_players_screen ();
dead_playerani ();
player_ilness_loop (bman.p_nr);
special_loop();
special_loop ();
if ((bman.players[bman.p_nr].state & PSFM_alife) == PSFM_alife)
move_player (bman.p_nr);
if (GT_MP_PTP)
player_calcpos ();
if (GT_MP_PTP)
player_calcpos ();
if (bman.gametype != GT_single)
network_loop ();
@ -202,13 +197,15 @@ game_loop ()
/* this will even set the variable "bman.player_nr"
to let us know how much Players are still left */
bomb_loop ();
field_animation ();
field_animation ();
draw_players ();
game_draw_info ();
/* check if there is only one player left and the game is in multiplayer mode
and if there the last dieing animation is done */
if ((bman.players_nr < 2 && (GT_MP_PTP || (bman.gametype == GT_single && bman.ai_players > 0))) || (bman.gametype == GT_single && bman.ai_players == 0 && bman.players_nr < 1))
if ((bman.players_nr < 2
&& (GT_MP_PTP || (bman.gametype == GT_single && bman.ai_players > 0)))
|| (bman.gametype == GT_single && bman.ai_players == 0 && bman.players_nr < 1))
gameovertimeout--;
if (gameovertimeout <= 0) {
@ -217,9 +214,9 @@ game_loop ()
}
stonelist_draw ();
gfx_blitdraw ();
stonelist_draw ();
gfx_blitdraw ();
// calculate time sync.
timeloop1 = SDL_GetTicks ();
timediff = timeloop1 - timestamp; // only for debugging needed
@ -249,8 +246,8 @@ game_end ()
menu_displaytext ("Freeing..", "Please Wait", 32, 128, 32);
gfx_free_players ();
tileset_free ();
snd_free ();
snd_free ();
/* count the points */
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_used (bman.players[i].state)) {

@ -10,8 +10,6 @@
#include "gfx.h"
#include "chat.h"
#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (bman.players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--);
extern int UpdateRects_nr;
static int mw_player = 0,

@ -78,10 +78,11 @@ networkmenu_options ()
{1, "Max Players:"},
{2, "Network"},
{3, "UDP Port"},
{4, "Notify Masterserver"},
{5, "Masterserver"},
{6, "Behind a Firewall"},
{7, "Return To Multiplayer Menu"},
{4, "Behind a Firewall"},
{5, "Notify Masterserver"},
{6, "Masterserver"},
{7, "Broadcastes Chat"},
{8, "Return To Multiplayer Menu"},
{-1, ""}
};
#ifdef _WIN32
@ -99,17 +100,33 @@ networkmenu_options ()
sprintf (menu[3].text, "UDP Port: %s", bman.port);
if (bman.notifygamemaster)
sprintf (menu[4].text, "Notify MasterServer: Yes");
if (bman.firewall)
sprintf (menu[4].text, "Firewall: ON");
else
sprintf (menu[4].text, "Notify MasterServer: No");
sprintf (menu[5].text, "MasterServer %s", bman.gamemaster);
sprintf (menu[4].text, "Firewall: OFF");
if (bman.firewall)
sprintf (menu[6].text, "Firewall: ON");
if (bman.notifygamemaster)
sprintf (menu[5].text, "Notify MasterServer: Yes");
else
sprintf (menu[6].text, "Firewall: OFF");
sprintf (menu[5].text, "Notify MasterServer: No");
if (bman.notifygamemaster) {
sprintf (menu[6].text, "MasterServer %s", bman.gamemaster);
menu[6].index = 6;
}
else
menu[6].text[0] = menu[6].index = 0;
if (bman.broadcasted_chat && bman.notifygamemaster) {
sprintf (menu[7].text, "Broadcasted Chat: ON");
menu[7].index = 7;
}
else if (bman.notifygamemaster) {
sprintf (menu[7].text, "Broadcasted Chat: OFF");
menu[7].index = 7;
}
else
menu[7].index = menu[7].text[0] = 0;
menuselect = menu_loop ("Multiplayer Options", menu, menuselect);
@ -143,26 +160,24 @@ networkmenu_options ()
LEN_PORT + 1);
break;
case (4): // Change the Notification
if (bman.notifygamemaster)
bman.notifygamemaster = 0;
else
bman.notifygamemaster = 1;
case (4): // Firewall Option
bman.firewall = 1 - bman.firewall ;
break;
case (5): // Change the Notification
bman.notifygamemaster = 1 - bman.notifygamemaster;
break;
case (5): // Masterserver Address
case (6): // Masterserver Address
menu_get_text ("Address of the MasterServer", bman.gamemaster,
LEN_SERVERNAME + LEN_PORT + 2);
break;
case (6): // Firewall Option
if (bman.firewall)
bman.firewall = 0;
else
bman.firewall = 1;
break;
case (7):
case (7):
bman.broadcasted_chat = 1 - bman.broadcasted_chat;
break;
case (8):
menuselect = -1;
break;
}

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.36 2003/07/22 18:29:08 stpohle Exp $ */
/* $Id: network.c,v 1.37 2003/07/24 01:47:48 stpohle Exp $ */
/*
network routines.
*/
@ -711,7 +711,7 @@ net_send_chat (char *text, signed char notigamesrv)
if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_chat (&bman.players[i].net.addr, text);
if (GT_MP_PTPM && bman.notifygamemaster && notigamesrv == 1) /* send notification the the gamemaster */
if (GT_MP_PTPM && bman.notifygamemaster && notigamesrv == 1 && bman.broadcasted_chat) /* send notification the the gamemaster */
gamesrv_sendchat (text);
};

@ -981,8 +981,11 @@ do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr * addr)
packet->data[127] = 0;
if (strstr (packet->data, "BC:BC:") == packet->data)
return; // ignore packet
chat_addline (packet->data);
net_send_chat (packet->data, 0);
if (bman.notifygamemaster && bman.broadcasted_chat) {
chat_addline (packet->data);
net_send_chat (packet->data, 0);
}
};

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.36 2003/07/23 18:14:04 stpohle Exp $ */
/* $Id: single.c,v 1.37 2003/07/24 01:47:48 stpohle Exp $ */
/* single player */
#include "basic.h"
@ -46,17 +46,8 @@ single_game_new ()
bman.players[p].d = 0;
}
for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state)))
bman.p_nr = p;
if (bman.p_nr >= MAX_PLAYERS) {
printf ("ERROR in function (single_game_new): couldn't find any free player\n");
exit (1);
}
bman.players[bman.p_nr].state = PSFM_alife;
player_set_gfx (&bman.players[bman.p_nr], 7);
player_set_gfx (&bman.players[bman.p_nr], bman.players[bman.p_nr].gfx_nr);
bman.last_ex_nr = 1;
init_map_tileset ();
@ -66,7 +57,7 @@ single_game_new ()
};
int
inline int
ai_checkfield (int x, int y)
{
return ((map.field[x][y].type == FT_nothing || map.field[x][y].type == FT_fire || map.field[x][y].type == FT_shoe || map.field[x][y].type == FT_bomb ) && map.bfield[x][y] == 0);
@ -200,12 +191,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
res.dir |= (1 << i);
}
/* if (!norecursive) {
printf ("%d,%d NB:", p.x, p.y);
d_bitprint (nearbomb, 5);
d_bitprint (res.dir, 4);
}
*/
/* test the possible ways */
while (!done) {
done = 1;
@ -234,11 +219,9 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
tdir = ai_runawayfrom (tpos, nbomb, 1).dir;
_i = ai_invertdir (i);
if (tdir != (1 << _i)) { // usefull direction
// printf ("B%d ", i);
res.dir |= (1 << i); // add this one
}
else {
// printf ("-%d ", i);
c = -1;
}
}
@ -246,7 +229,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
res.dir |= (1 << i);
/* check for the best direction */
// if (!norecursive) printf ("pts:%d|%d ", bdirpoints, res.bestdir);
if (c != -1 && !norecursive) {
if (c < bdirpoints) {
bdirpoints = c;
@ -264,17 +246,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
}
}
}
/* if (!norecursive) {
d_bitprint (res.dir, 4);
printf ("%d ] ", res.bestdir);
} else {
printf ("(%d,%d NB ", p.x, p.y);
d_bitprint (nearbomb, 5);
d_bitprint (res.dir, 4);
printf (")");
}
*/
return res;
};
@ -412,9 +383,6 @@ ai_findbestbombdir (_point pos, int dir, int range)
if (dir != -1 && (bestd & (0xFF -(1 << ai_invertdir(dir)))))
bestd &= (0xFF - (1 << ai_invertdir(dir)));
// d_printf ("ai_bestbombdir (%d,%d) [%d, %d, %d, %d, %d]\n", pos.x, pos.y, points[0],
// points[1], points[2], points[3], points[4]);
return bestd;
}
@ -488,7 +456,7 @@ ai_findnearbombs (_point pos)
/* check if we are still running and fill out the position
return == 0 we're still walking ... else we have reached a point */
int
inline int
ai_checkpos (_player * pl, _point * pos)
{
_point _p;
@ -547,7 +515,7 @@ ai_choosedir (int dir, int nearbomb, int oldpos)
};
int
inline int
ai_invertdir (int dir)
{
int idir;
@ -569,7 +537,7 @@ ai_invertdir (int dir)
};
int
inline int
ai_checknewpos (_point pos, int d)
{
_point m;
@ -600,8 +568,7 @@ ai_checknewpos (_point pos, int d)
void
single_create_ai (int players)
{
int p;
int count;
int p, count, gfx_sel, i = 0;
_player *pl;
for (count = 0; count < players; count++) {
@ -609,35 +576,61 @@ single_create_ai (int players)
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state))) {
pl = &bman.players[p];
sprintf (pl->name, "AI %d", count+1);
pl->state |= PSF_used + PSF_alife + PSF_playing;
player_set_gfx (pl, s_random (MAX_PLAYERS));
do {
gfx_sel = s_random (MAX_PLAYERS);
MW_IS_GFX_SELECT (gfx_sel, i);
} while (i != -1);
player_set_gfx (pl, gfx_sel);
}
if (pl == NULL)
return;
}
};
/* single player game win/point screen */
void
single_playergame ()
{
int p;
int p, done = 0;
/* delete player from the game */
for (p = 0; p < MAX_PLAYERS; p++)
for (p = 0; p < MAX_PLAYERS; p++) {
bman.players[p].points = 0;
bman.players[p].wins = 0;
bman.players[p].state = 0;
}
for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state)))
bman.p_nr = p;
if (bman.p_nr >= MAX_PLAYERS) {
printf ("ERROR in function (single_game_new): couldn't find any free player\n");
exit (1);
}
if ((bman.players[bman.p_nr].gfx_nr = single_select_player ()) == -1)
return;
bman.players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing;
strncpy (bman.players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);
single_create_ai (bman.ai_players);
single_game_new ();
game_start ();
game_loop ();
game_end ();
bman.state = GS_ready;
while (!done && bman.state != GS_quit && bman.state != GS_startup) {
single_game_new ();
game_start ();
game_loop ();
game_end ();
}
};
/* single player loop for calculating the ai players */
void
single_loop ()
{
@ -679,7 +672,6 @@ single_loop ()
}
else {
// bombs in the near found
// printf ("P%d,%d ", plpos.x, plpos.y);
rawdir = ai_runawayfrom (plpos, nearbomb, 0);
if (rawdir.dir != 0 && rawdir.bestdir == -1) {
pl->d = ai_choosedir (rawdir.dir, nearbomb, pl->d); // we have to make a choice.. do it
@ -689,7 +681,6 @@ single_loop ()
pl->d = rawdir.bestdir;
pl->m = 1;
}
// printf (" d:%d m:%d\n", pl->d, pl->m);
}
}
player_ilness_loop (p);
@ -733,4 +724,11 @@ void single_menu () {
break;
}
}
};
};
/* single player selection
return value the gfx of the player or -1 for escape */
int single_select_player () {
return 0;
};

Loading…
Cancel
Save