|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: single.c,v 1.17 2003/05/25 02:24:18 stpohle Exp $ */
|
|
|
|
/* $Id: single.c,v 1.18 2003/05/25 22:06:33 stpohle Exp $ */
|
|
|
|
/* single player */
|
|
|
|
/* single player */
|
|
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
#include "basic.h"
|
|
|
@ -117,7 +117,7 @@ ai_checkrunaway (_point pos, int range, int direction)
|
|
|
|
if (i >= range)
|
|
|
|
if (i >= range)
|
|
|
|
ok = 1;
|
|
|
|
ok = 1;
|
|
|
|
|
|
|
|
|
|
|
|
d_printf ("Check Run away (pos %d,%d , direction %d) %d\n", pos.x, pos.y, direction, ok);
|
|
|
|
d_printf ("ai_runaway (pos %d,%d , direction %d) %d\n", pos.x, pos.y, direction, ok);
|
|
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
return ok;
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -134,8 +134,6 @@ ai_runawayfrom (_point p, int range)
|
|
|
|
if (ai_checkrunaway (p, range, d))
|
|
|
|
if (ai_checkrunaway (p, range, d))
|
|
|
|
dir = d;
|
|
|
|
dir = d;
|
|
|
|
|
|
|
|
|
|
|
|
d_printf ("ai_runawayfrom (%d)\n", dir);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
return dir;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -192,11 +190,11 @@ ai_bombpoints (_point pos, int range)
|
|
|
|
|
|
|
|
|
|
|
|
/* find the best position to go for dropping a bomb */
|
|
|
|
/* find the best position to go for dropping a bomb */
|
|
|
|
int
|
|
|
|
int
|
|
|
|
ai_findbestbombdir (_player * pl)
|
|
|
|
ai_findbestbombdir (_point pos, int dir, int range)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int points[5] = { 0, 0, 0, 0 };
|
|
|
|
int points[5] = { 0, 0, 0, 0 };
|
|
|
|
int d,
|
|
|
|
int d,
|
|
|
|
bestd = pl->d;
|
|
|
|
bestd = dir;
|
|
|
|
_point m,
|
|
|
|
_point m,
|
|
|
|
p;
|
|
|
|
p;
|
|
|
|
|
|
|
|
|
|
|
@ -224,10 +222,10 @@ ai_findbestbombdir (_player * pl)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p.x = (pl->pos.x >> 8) + m.x;
|
|
|
|
p.x = pos.x + m.x;
|
|
|
|
p.y = (pl->pos.y >> 8) + m.y;
|
|
|
|
p.y = pos.y + m.y;
|
|
|
|
|
|
|
|
|
|
|
|
points[d] = ai_bombpoints (p, pl->range);
|
|
|
|
points[d] = ai_bombpoints (p, range);
|
|
|
|
if (points[d] > points[bestd])
|
|
|
|
if (points[d] > points[bestd])
|
|
|
|
bestd = d;
|
|
|
|
bestd = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -245,13 +243,12 @@ ai_findbestbombdir (_player * pl)
|
|
|
|
/* check if is there is a bom in the near
|
|
|
|
/* check if is there is a bom in the near
|
|
|
|
returns the directions (bits 0(left)-3(down) bit4 bomb under us) where a bomb is */
|
|
|
|
returns the directions (bits 0(left)-3(down) bit4 bomb under us) where a bomb is */
|
|
|
|
int
|
|
|
|
int
|
|
|
|
ai_findnearbombs (_player * pl)
|
|
|
|
ai_findnearbombs (_point pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int d,
|
|
|
|
int d,
|
|
|
|
res = 0, // result if there is a bomb
|
|
|
|
res = 0, // result if there is a bomb
|
|
|
|
|
|
|
|
|
|
|
|
done = 0,
|
|
|
|
done = 0;
|
|
|
|
row;
|
|
|
|
|
|
|
|
_point m[4]; // direction addition
|
|
|
|
_point m[4]; // direction addition
|
|
|
|
_point dist[4]; // to check every direction (on three ways)
|
|
|
|
_point dist[4]; // to check every direction (on three ways)
|
|
|
|
|
|
|
|
|
|
|
@ -260,38 +257,38 @@ ai_findnearbombs (_player * pl)
|
|
|
|
case (left):
|
|
|
|
case (left):
|
|
|
|
m[d].x = -1;
|
|
|
|
m[d].x = -1;
|
|
|
|
m[d].y = 0;
|
|
|
|
m[d].y = 0;
|
|
|
|
dist[d].x = (pl->pos.x >> 8) + 1;
|
|
|
|
dist[d].x = pos.x + 1;
|
|
|
|
dist[d].y = (pl->pos.y >> 8);
|
|
|
|
dist[d].y = pos.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case (right):
|
|
|
|
case (right):
|
|
|
|
m[d].x = 1;
|
|
|
|
m[d].x = 1;
|
|
|
|
m[d].y = 0;
|
|
|
|
m[d].y = 0;
|
|
|
|
dist[d].x = (pl->pos.x >> 8) - 1;
|
|
|
|
dist[d].x = pos.x - 1;
|
|
|
|
dist[d].y = (pl->pos.y >> 8);
|
|
|
|
dist[d].y = pos.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case (up):
|
|
|
|
case (up):
|
|
|
|
m[d].x = 0;
|
|
|
|
m[d].x = 0;
|
|
|
|
m[d].y = -1;
|
|
|
|
m[d].y = -1;
|
|
|
|
dist[d].x = (pl->pos.x >> 8);
|
|
|
|
dist[d].x = pos.x;
|
|
|
|
dist[d].y = (pl->pos.y >> 8) - 1;
|
|
|
|
dist[d].y = pos.y - 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case (down):
|
|
|
|
case (down):
|
|
|
|
m[d].x = 0;
|
|
|
|
m[d].x = 0;
|
|
|
|
m[d].y = 1;
|
|
|
|
m[d].y = 1;
|
|
|
|
dist[d].x = (pl->pos.x >> 8);
|
|
|
|
dist[d].x = pos.x;
|
|
|
|
dist[d].y = (pl->pos.y >> 8) + 1;
|
|
|
|
dist[d].y = pos.y + 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
while (!done) {
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
printf (" c ");
|
|
|
|
/* check every direction again */
|
|
|
|
/* check every direction again */
|
|
|
|
for (d = 0; d < 4; d++)
|
|
|
|
for (d = 0; d < 4; d++)
|
|
|
|
if (dist[d].x >= 0 && dist[d].x < bman.fieldsize.x &&
|
|
|
|
if (dist[d].x >= 0 && dist[d].x < bman.fieldsize.x &&
|
|
|
|
dist[d].y >= 0 && dist[d].y < bman.fieldsize.y) {
|
|
|
|
dist[d].y >= 0 && dist[d].y < bman.fieldsize.y) {
|
|
|
|
if (bman.bfield[dist[d].x][dist[d].y] != 0) {
|
|
|
|
if (bman.bfield[dist[d].x][dist[d].y] != 0) {
|
|
|
|
res |= 1 << d; // set the bit for the direction;
|
|
|
|
res |= (1 << d); // set the bit for the direction;
|
|
|
|
dist[d].x = dist[d].y = -1; // don't check no more.
|
|
|
|
dist[d].x = dist[d].y = -1; // don't check no more.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bman.field[dist[d].x][dist[d].y].type != FT_nothing)
|
|
|
|
if (bman.field[dist[d].x][dist[d].y].type != FT_nothing)
|
|
|
@ -304,7 +301,7 @@ ai_findnearbombs (_player * pl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bman.bfield[pl->pos.x >> 8][pl->pos.y >> 8] != 0)
|
|
|
|
if (bman.bfield[pos.x][pos.y] != 0)
|
|
|
|
res |= 16; // set the 4th. bit
|
|
|
|
res |= 16; // set the 4th. bit
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
@ -313,73 +310,38 @@ ai_findnearbombs (_player * pl)
|
|
|
|
|
|
|
|
|
|
|
|
/* flee from a bomb in the near */
|
|
|
|
/* flee from a bomb in the near */
|
|
|
|
int
|
|
|
|
int
|
|
|
|
ai_fleefrombomb (_player * pl, int nearbomb)
|
|
|
|
ai_fleefrombomb (_point pos, int nearbomb, int range)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int posdir[4]; // possibvle directions to run away
|
|
|
|
|
|
|
|
int d = 0,
|
|
|
|
int d = 0,
|
|
|
|
i,
|
|
|
|
dir = -1;
|
|
|
|
dir = -1;
|
|
|
|
|
|
|
|
_point pos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pos.x = pl->pos.x >> 8;
|
|
|
|
|
|
|
|
pos.y = pl->pos.y >> 8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nearbomb == 4)
|
|
|
|
|
|
|
|
dir = ai_runawayfrom (pos, pl->range);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dir == -1) {
|
|
|
|
|
|
|
|
if ((nearbomb & 3) != 0) { // bomb is in the same row.. try to go up down
|
|
|
|
|
|
|
|
if (s_random (2) == 0 || (nearbomb & 4) != 0)
|
|
|
|
|
|
|
|
d = 1;
|
|
|
|
|
|
|
|
if (bman.field[pos.x][pos.y + d].type == FT_nothing) {
|
|
|
|
|
|
|
|
if (d == 1)
|
|
|
|
|
|
|
|
dir = down;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dir = up;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (bman.field[pos.x][pos.y - d].type == FT_nothing) {
|
|
|
|
|
|
|
|
if (d == 1)
|
|
|
|
|
|
|
|
dir = up;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dir = down;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((nearbomb & 1) == 0)
|
|
|
|
|
|
|
|
dir = left;
|
|
|
|
|
|
|
|
else if ((nearbomb & 2) == 0)
|
|
|
|
|
|
|
|
dir = right;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if ((nearbomb & 12) != 0) { // bomb is updown from us
|
|
|
|
if (nearbomb != 0)
|
|
|
|
if (s_random (2) == 0 || (nearbomb & 1) != 0)
|
|
|
|
dir = ai_runawayfrom (pos, range);
|
|
|
|
d = 1;
|
|
|
|
|
|
|
|
if (bman.field[pos.x + d][pos.y].type == FT_nothing) {
|
|
|
|
|
|
|
|
if (d == 1)
|
|
|
|
|
|
|
|
dir = right;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dir = left;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (bman.field[pos.x - d][pos.y].type == FT_nothing) {
|
|
|
|
|
|
|
|
if (d == 1)
|
|
|
|
|
|
|
|
dir = left;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dir = right;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((nearbomb & 4) == 0)
|
|
|
|
|
|
|
|
dir = up;
|
|
|
|
|
|
|
|
else if ((nearbomb & 8) == 0)
|
|
|
|
|
|
|
|
dir = down;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dir == -1)
|
|
|
|
if (dir == -1)
|
|
|
|
dir = s_random (4);
|
|
|
|
dir = s_random (4);
|
|
|
|
|
|
|
|
|
|
|
|
if ((pl->pos.x & 255) != 0 || (pl->pos.y & 255) != 0)
|
|
|
|
return dir;
|
|
|
|
dir = pl->d;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* check if we are still running and fill out the position
|
|
|
|
|
|
|
|
return == 0 we're still walking ... else we have reached a point */
|
|
|
|
|
|
|
|
int ai_checkpos (_player *pl, _point *pos) {
|
|
|
|
|
|
|
|
_point _p;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_p.x = pl->pos.x & 255;
|
|
|
|
|
|
|
|
_p.y = pl->pos.y & 255;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pos->x = pl->pos.x >> 8;
|
|
|
|
|
|
|
|
pos->y = pl->pos.y >> 8;
|
|
|
|
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
if (_p.x > 128)
|
|
|
|
|
|
|
|
(pos->x)++;
|
|
|
|
|
|
|
|
if (_p.y > 128)
|
|
|
|
|
|
|
|
(pos->y)++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ((_p.x < 42 || _p.x > 213) && (_p.y < 42 || _p.y > 213));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -388,36 +350,34 @@ single_loop ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int p;
|
|
|
|
_player *pl;
|
|
|
|
_player *pl;
|
|
|
|
int nearbomb,
|
|
|
|
_point plpos;
|
|
|
|
bestbombdir;
|
|
|
|
int nearbomb = 0,
|
|
|
|
|
|
|
|
bestbombdir = 0,
|
|
|
|
|
|
|
|
i;
|
|
|
|
|
|
|
|
|
|
|
|
for (p = 0; p < MAX_PLAYERS; p++)
|
|
|
|
for (p = 0; p < MAX_PLAYERS; p++)
|
|
|
|
if (p != bman.p_nr && PS_IS_alife (bman.players[p].state)) {
|
|
|
|
if (p != bman.p_nr && PS_IS_alife (bman.players[p].state)) {
|
|
|
|
pl = &bman.players[p];
|
|
|
|
pl = &bman.players[p];
|
|
|
|
|
|
|
|
|
|
|
|
bestbombdir = ai_findbestbombdir (pl);
|
|
|
|
i = ai_checkpos (pl, &plpos);
|
|
|
|
nearbomb = ai_findnearbombs (pl);
|
|
|
|
|
|
|
|
|
|
|
|
d_printf ("single_loop pos:%d,%d nearbomb:%d bestbombdir:%d, checkpos: %d\n", plpos.x, plpos.y, nearbomb, bestbombdir, i);
|
|
|
|
if (((pl->pos.x & 255) >= 64 && (pl->pos.x & 255) <= 255 && pl->d == left) ||
|
|
|
|
|
|
|
|
((pl->pos.x & 255) > 0 && (pl->pos.x & 255) <= 192 && pl->d == right) ||
|
|
|
|
if (!i) {
|
|
|
|
((pl->pos.y & 255) >= 64 && (pl->pos.y & 255) <= 255 && pl->d == up) ||
|
|
|
|
/* we're still moving */
|
|
|
|
((pl->pos.y & 255) > 0 && (pl->pos.y & 255) <= 192 && pl->d == down)) {
|
|
|
|
|
|
|
|
pl->m = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (bestbombdir == 4 && nearbomb == 0) // best position is here
|
|
|
|
|
|
|
|
player_drop_bomb (p);
|
|
|
|
|
|
|
|
else if (nearbomb != 0) { // there is a bomb in the near
|
|
|
|
|
|
|
|
pl->m = 1;
|
|
|
|
|
|
|
|
pl->d = ai_fleefrombomb (pl, nearbomb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (bestbombdir == -1) { // no good position found
|
|
|
|
|
|
|
|
pl->d = s_random (4);
|
|
|
|
|
|
|
|
pl->m = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else { // go into this direction
|
|
|
|
|
|
|
|
pl->d = bestbombdir;
|
|
|
|
|
|
|
|
pl->m = 1;
|
|
|
|
pl->m = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
nearbomb = ai_findnearbombs (plpos);
|
|
|
|
|
|
|
|
if (nearbomb == 0) { // no bombs found
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// bombs in the near found
|
|
|
|
|
|
|
|
pl->m = 1;
|
|
|
|
|
|
|
|
pl->d = ai_fleefrombomb (plpos, nearbomb, pl->range + 1);
|
|
|
|
|
|
|
|
printf (" %d ", pl->d);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
player_ilness_loop (p);
|
|
|
|
player_ilness_loop (p);
|
|
|
|
move_player (p);
|
|
|
|
move_player (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -456,7 +416,7 @@ single_playergame ()
|
|
|
|
for (p = 0; p < MAX_PLAYERS; p++)
|
|
|
|
for (p = 0; p < MAX_PLAYERS; p++)
|
|
|
|
bman.players[p].state = 0;
|
|
|
|
bman.players[p].state = 0;
|
|
|
|
|
|
|
|
|
|
|
|
single_create_ai (6);
|
|
|
|
single_create_ai (1);
|
|
|
|
single_game_new ();
|
|
|
|
single_game_new ();
|
|
|
|
gfx_game_init ();
|
|
|
|
gfx_game_init ();
|
|
|
|
game_loop ();
|
|
|
|
game_loop ();
|
|
|
|