|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: single.c,v 1.69 2004/09/12 21:35:32 stpohle Exp $ */
|
|
|
|
/* $Id: single.c,v 1.70 2004/09/23 13:21:44 stpohle Exp $ */
|
|
|
|
/* single player */
|
|
|
|
/* single player */
|
|
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
#include "basic.h"
|
|
|
@ -51,9 +51,10 @@ ai_checkfield (int x, int y)
|
|
|
|
* this function is even needed for the start of
|
|
|
|
* this function is even needed for the start of
|
|
|
|
* the game to place the players on a good position */
|
|
|
|
* the game to place the players on a good position */
|
|
|
|
int
|
|
|
|
int
|
|
|
|
ai_easyrunaway (_point p)
|
|
|
|
ai_easyrunaway (_point p, int range)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i,
|
|
|
|
int i,
|
|
|
|
|
|
|
|
dist = 0,
|
|
|
|
done = 0,
|
|
|
|
done = 0,
|
|
|
|
dir = 0;
|
|
|
|
dir = 0;
|
|
|
|
_point pos[4],
|
|
|
|
_point pos[4],
|
|
|
@ -86,7 +87,7 @@ ai_easyrunaway (_point p)
|
|
|
|
/* test the possible ways */
|
|
|
|
/* test the possible ways */
|
|
|
|
while (!done) {
|
|
|
|
while (!done) {
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
dist++;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
/* check if we are still in the game field */
|
|
|
|
/* check if we are still in the game field */
|
|
|
|
if (pos[i].x <= 0 || pos[i].y <= 0 || pos[i].x >= map.size.x - 1
|
|
|
|
if (pos[i].x <= 0 || pos[i].y <= 0 || pos[i].x >= map.size.x - 1
|
|
|
@ -112,6 +113,7 @@ ai_easyrunaway (_point p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
|
|
|
if (dist > range) dir |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,7 +126,7 @@ ai_easyrunaway (_point p)
|
|
|
|
/* give the run away direction
|
|
|
|
/* give the run away direction
|
|
|
|
the return value: */
|
|
|
|
the return value: */
|
|
|
|
_airunaway
|
|
|
|
_airunaway
|
|
|
|
ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i,
|
|
|
|
int i,
|
|
|
|
done = 0,
|
|
|
|
done = 0,
|
|
|
@ -133,7 +135,8 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
_i,
|
|
|
|
_i,
|
|
|
|
bdirpoints = 10,
|
|
|
|
bdirpoints = 10,
|
|
|
|
j,
|
|
|
|
j,
|
|
|
|
c;
|
|
|
|
c,
|
|
|
|
|
|
|
|
dist = 0;
|
|
|
|
_airunaway res;
|
|
|
|
_airunaway res;
|
|
|
|
_point pos[4],
|
|
|
|
_point pos[4],
|
|
|
|
m[4],
|
|
|
|
m[4],
|
|
|
@ -178,7 +181,7 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
/* test the possible ways */
|
|
|
|
/* test the possible ways */
|
|
|
|
while (!done) {
|
|
|
|
while (!done) {
|
|
|
|
done = 1;
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
dist++;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
/* check if we are still in the game field */
|
|
|
|
/* check if we are still in the game field */
|
|
|
|
if (pos[i].x <= 0 || pos[i].y <= 0 || pos[i].x >= map.size.x - 1
|
|
|
|
if (pos[i].x <= 0 || pos[i].y <= 0 || pos[i].x >= map.size.x - 1
|
|
|
@ -200,7 +203,7 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
nbomb = ai_findnearbombs (tpos);
|
|
|
|
nbomb = ai_findnearbombs (tpos);
|
|
|
|
c = s_countbits (nbomb, 5);
|
|
|
|
c = s_countbits (nbomb, 5);
|
|
|
|
if (!norecursive) {
|
|
|
|
if (!norecursive) {
|
|
|
|
tdir = ai_runawayfrom (tpos, nbomb, 1).dir;
|
|
|
|
tdir = ai_runawayfrom (tpos, nbomb, range, 1).dir;
|
|
|
|
_i = ai_invertdir (i);
|
|
|
|
_i = ai_invertdir (i);
|
|
|
|
if (tdir != (1 << _i)) { // usefull direction
|
|
|
|
if (tdir != (1 << _i)) { // usefull direction
|
|
|
|
res.dir |= (1 << i); // add this one
|
|
|
|
res.dir |= (1 << i); // add this one
|
|
|
@ -226,6 +229,10 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
|
|
|
if (dist > range && res.bestdir == -1) {
|
|
|
|
|
|
|
|
res.dir |= (1 << i);
|
|
|
|
|
|
|
|
res.bestdir = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -287,7 +294,7 @@ ai_bombpoints (_point pos, int range)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ai_easyrunaway (pos) == 0 || ai_findnearbombs (pos) != 0)
|
|
|
|
if (ai_easyrunaway (pos, range) == 0 || ai_findnearbombs (pos) != 0)
|
|
|
|
points = 0;
|
|
|
|
points = 0;
|
|
|
|
|
|
|
|
|
|
|
|
return points;
|
|
|
|
return points;
|
|
|
@ -682,7 +689,7 @@ single_loop ()
|
|
|
|
if (nearbomb == 0) { // no bombs found
|
|
|
|
if (nearbomb == 0) { // no bombs found
|
|
|
|
bestbdir = ai_findbestbombdir (plpos, pl->d, pl->range);
|
|
|
|
bestbdir = ai_findbestbombdir (plpos, pl->d, pl->range);
|
|
|
|
if (bestbdir & DIRM_under) {
|
|
|
|
if (bestbdir & DIRM_under) {
|
|
|
|
if (ai_easyrunaway (plpos) != 0)
|
|
|
|
if (ai_easyrunaway (plpos, pl->range) != 0)
|
|
|
|
player_drop_bomb (p);
|
|
|
|
player_drop_bomb (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bestbdir == 0) {
|
|
|
|
else if (bestbdir == 0) {
|
|
|
@ -698,7 +705,7 @@ single_loop ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// bombs in the near found
|
|
|
|
// bombs in the near found
|
|
|
|
rawdir = ai_runawayfrom (plpos, nearbomb, 0);
|
|
|
|
rawdir = ai_runawayfrom (plpos, nearbomb, pl->range, 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
|
|
|
|
pl->m = 1;
|
|
|
|
pl->m = 1;
|
|
|
@ -706,7 +713,11 @@ single_loop ()
|
|
|
|
else if (rawdir.bestdir != -1) {
|
|
|
|
else if (rawdir.bestdir != -1) {
|
|
|
|
pl->d = rawdir.bestdir;
|
|
|
|
pl->d = rawdir.bestdir;
|
|
|
|
pl->m = 1;
|
|
|
|
pl->m = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (rawdir.bestdir == -1 && rawdir.dir == 0) {
|
|
|
|
|
|
|
|
/* no good ways found, just run in the opposite direction of the bomb */
|
|
|
|
|
|
|
|
// ERRORRRRRRRRR;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pl->m == 0 && map.field[(int) pl->pos.x][(int) pl->pos.y].type == FT_tunnel)
|
|
|
|
if (pl->m == 0 && map.field[(int) pl->pos.x][(int) pl->pos.y].type == FT_tunnel)
|
|
|
|