|
|
@ -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 */
|
|
|
|
/* single player */
|
|
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
#include "basic.h"
|
|
|
@ -46,17 +46,8 @@ single_game_new ()
|
|
|
|
bman.players[p].d = 0;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
bman.last_ex_nr = 1;
|
|
|
|
|
|
|
|
|
|
|
|
init_map_tileset ();
|
|
|
|
init_map_tileset ();
|
|
|
@ -66,7 +57,7 @@ single_game_new ()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
inline int
|
|
|
|
ai_checkfield (int x, int y)
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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 */
|
|
|
|
/* test the possible ways */
|
|
|
|
while (!done) {
|
|
|
|
while (!done) {
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
@ -234,11 +219,9 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
tdir = ai_runawayfrom (tpos, nbomb, 1).dir;
|
|
|
|
tdir = ai_runawayfrom (tpos, nbomb, 1).dir;
|
|
|
|
_i = ai_invertdir (i);
|
|
|
|
_i = ai_invertdir (i);
|
|
|
|
if (tdir != (1 << _i)) { // usefull direction
|
|
|
|
if (tdir != (1 << _i)) { // usefull direction
|
|
|
|
// printf ("B%d ", i);
|
|
|
|
|
|
|
|
res.dir |= (1 << i); // add this one
|
|
|
|
res.dir |= (1 << i); // add this one
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// printf ("-%d ", i);
|
|
|
|
|
|
|
|
c = -1;
|
|
|
|
c = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -246,7 +229,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
res.dir |= (1 << i);
|
|
|
|
res.dir |= (1 << i);
|
|
|
|
|
|
|
|
|
|
|
|
/* check for the best direction */
|
|
|
|
/* check for the best direction */
|
|
|
|
// if (!norecursive) printf ("pts:%d|%d ", bdirpoints, res.bestdir);
|
|
|
|
|
|
|
|
if (c != -1 && !norecursive) {
|
|
|
|
if (c != -1 && !norecursive) {
|
|
|
|
if (c < bdirpoints) {
|
|
|
|
if (c < bdirpoints) {
|
|
|
|
bdirpoints = c;
|
|
|
|
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;
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -412,9 +383,6 @@ ai_findbestbombdir (_point pos, int dir, int range)
|
|
|
|
if (dir != -1 && (bestd & (0xFF -(1 << ai_invertdir(dir)))))
|
|
|
|
if (dir != -1 && (bestd & (0xFF -(1 << ai_invertdir(dir)))))
|
|
|
|
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;
|
|
|
|
return bestd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -488,7 +456,7 @@ ai_findnearbombs (_point pos)
|
|
|
|
|
|
|
|
|
|
|
|
/* check if we are still running and fill out the position
|
|
|
|
/* check if we are still running and fill out the position
|
|
|
|
return == 0 we're still walking ... else we have reached a point */
|
|
|
|
return == 0 we're still walking ... else we have reached a point */
|
|
|
|
int
|
|
|
|
inline int
|
|
|
|
ai_checkpos (_player * pl, _point * pos)
|
|
|
|
ai_checkpos (_player * pl, _point * pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_point _p;
|
|
|
|
_point _p;
|
|
|
@ -547,7 +515,7 @@ ai_choosedir (int dir, int nearbomb, int oldpos)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
inline int
|
|
|
|
ai_invertdir (int dir)
|
|
|
|
ai_invertdir (int dir)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int idir;
|
|
|
|
int idir;
|
|
|
@ -569,7 +537,7 @@ ai_invertdir (int dir)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
inline int
|
|
|
|
ai_checknewpos (_point pos, int d)
|
|
|
|
ai_checknewpos (_point pos, int d)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_point m;
|
|
|
|
_point m;
|
|
|
@ -600,8 +568,7 @@ ai_checknewpos (_point pos, int d)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
single_create_ai (int players)
|
|
|
|
single_create_ai (int players)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int p, count, gfx_sel, i = 0;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
_player *pl;
|
|
|
|
_player *pl;
|
|
|
|
|
|
|
|
|
|
|
|
for (count = 0; count < players; count++) {
|
|
|
|
for (count = 0; count < players; count++) {
|
|
|
@ -609,8 +576,13 @@ single_create_ai (int players)
|
|
|
|
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
|
|
|
|
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
|
|
|
|
if (!(PS_IS_used (bman.players[p].state))) {
|
|
|
|
if (!(PS_IS_used (bman.players[p].state))) {
|
|
|
|
pl = &bman.players[p];
|
|
|
|
pl = &bman.players[p];
|
|
|
|
|
|
|
|
sprintf (pl->name, "AI %d", count+1);
|
|
|
|
pl->state |= PSF_used + PSF_alife + PSF_playing;
|
|
|
|
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)
|
|
|
|
if (pl == NULL)
|
|
|
@ -619,25 +591,46 @@ single_create_ai (int players)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* single player game win/point screen */
|
|
|
|
void
|
|
|
|
void
|
|
|
|
single_playergame ()
|
|
|
|
single_playergame ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int p, done = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* delete player from the game */
|
|
|
|
/* 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;
|
|
|
|
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_create_ai (bman.ai_players);
|
|
|
|
|
|
|
|
bman.state = GS_ready;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!done && bman.state != GS_quit && bman.state != GS_startup) {
|
|
|
|
single_game_new ();
|
|
|
|
single_game_new ();
|
|
|
|
game_start ();
|
|
|
|
game_start ();
|
|
|
|
game_loop ();
|
|
|
|
game_loop ();
|
|
|
|
game_end ();
|
|
|
|
game_end ();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* single player loop for calculating the ai players */
|
|
|
|
void
|
|
|
|
void
|
|
|
|
single_loop ()
|
|
|
|
single_loop ()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -679,7 +672,6 @@ single_loop ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// bombs in the near found
|
|
|
|
// bombs in the near found
|
|
|
|
// printf ("P%d,%d ", plpos.x, plpos.y);
|
|
|
|
|
|
|
|
rawdir = ai_runawayfrom (plpos, nearbomb, 0);
|
|
|
|
rawdir = ai_runawayfrom (plpos, nearbomb, 0);
|
|
|
|
if (rawdir.dir != 0 && rawdir.bestdir == -1) {
|
|
|
|
if (rawdir.dir != 0 && rawdir.bestdir == -1) {
|
|
|
|
pl->d = ai_choosedir (rawdir.dir, nearbomb, pl->d); // we have to make a choice.. do it
|
|
|
|
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->d = rawdir.bestdir;
|
|
|
|
pl->m = 1;
|
|
|
|
pl->m = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// printf (" d:%d m:%d\n", pl->d, pl->m);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player_ilness_loop (p);
|
|
|
|
player_ilness_loop (p);
|
|
|
@ -734,3 +725,10 @@ void single_menu () {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* single player selection
|
|
|
|
|
|
|
|
return value the gfx of the player or -1 for escape */
|
|
|
|
|
|
|
|
int single_select_player () {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
};
|
|
|
|