|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: single.c,v 1.77 2004/10/06 18:16:15 stpohle Exp $ */
|
|
|
|
|
/* $Id: single.c,v 1.78 2004/10/18 18:27:20 stpohle Exp $ */
|
|
|
|
|
/* single player */
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
@ -102,31 +102,12 @@ ai_easyrunaway (_point p, int range)
|
|
|
|
|
dist = 0,
|
|
|
|
|
done = 0,
|
|
|
|
|
dir = 0;
|
|
|
|
|
_point pos[4],
|
|
|
|
|
m[4];
|
|
|
|
|
_point pos[4];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
pos[i] = p;
|
|
|
|
|
switch (i) {
|
|
|
|
|
case (left):
|
|
|
|
|
m[i].x = -1;
|
|
|
|
|
m[i].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m[i].x = 1;
|
|
|
|
|
m[i].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m[i].x = 0;
|
|
|
|
|
m[i].y = -1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m[i].x = 0;
|
|
|
|
|
m[i].y = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
pos[i].x += dir_change[i].x;
|
|
|
|
|
pos[i].y += dir_change[i].y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test the possible ways */
|
|
|
|
@ -156,8 +137,8 @@ ai_easyrunaway (_point p, int range)
|
|
|
|
|
|| ai_checkfield (pos[i].x + 1, pos[i].y)))
|
|
|
|
|
dir |= (1 << i);
|
|
|
|
|
}
|
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
pos[i].x += dir_change[i].x;
|
|
|
|
|
pos[i].y += dir_change[i].y;
|
|
|
|
|
if (dist > range) dir |= (1 << i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -184,7 +165,6 @@ ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive)
|
|
|
|
|
dist = 0;
|
|
|
|
|
_airunaway res;
|
|
|
|
|
_point pos[4],
|
|
|
|
|
m[4],
|
|
|
|
|
tpos;
|
|
|
|
|
|
|
|
|
|
res.dir = 0;
|
|
|
|
@ -192,26 +172,8 @@ ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive)
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
pos[i] = p;
|
|
|
|
|
switch (i) {
|
|
|
|
|
case (left):
|
|
|
|
|
m[i].x = -1;
|
|
|
|
|
m[i].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m[i].x = 1;
|
|
|
|
|
m[i].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m[i].x = 0;
|
|
|
|
|
m[i].y = -1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m[i].x = 0;
|
|
|
|
|
m[i].y = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
pos[i].x += dir_change[i].x;
|
|
|
|
|
pos[i].y += dir_change[i].y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test if we just have to move to the side */
|
|
|
|
@ -242,8 +204,8 @@ ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive)
|
|
|
|
|
if (((i == left || i == right) && (j == up || j == down)) ||
|
|
|
|
|
((j == left || j == right) && (i == up || i == down))) {
|
|
|
|
|
c = 10;
|
|
|
|
|
tpos.x = pos[i].x + m[j].x;
|
|
|
|
|
tpos.y = pos[i].y + m[j].y;
|
|
|
|
|
tpos.x = pos[i].x + dir_change[j].x;
|
|
|
|
|
tpos.y = pos[i].y + dir_change[j].y;
|
|
|
|
|
if (ai_checkfield (tpos.x, tpos.y)) {
|
|
|
|
|
nbomb = ai_findnearbombs (tpos);
|
|
|
|
|
c = s_countbits (nbomb, 5);
|
|
|
|
@ -272,8 +234,8 @@ ai_runawayfrom (_point p, int nearbomb, int range, signed char norecursive)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pos[i].x += m[i].x;
|
|
|
|
|
pos[i].y += m[i].y;
|
|
|
|
|
pos[i].x += dir_change[i].x;
|
|
|
|
|
pos[i].y += dir_change[i].y;
|
|
|
|
|
if (dist > range && res.bestdir == -1) {
|
|
|
|
|
res.dir |= (1 << i);
|
|
|
|
|
res.bestdir = i;
|
|
|
|
@ -294,39 +256,19 @@ ai_bombpoints (_point pos, int range)
|
|
|
|
|
int points = 0,
|
|
|
|
|
d,
|
|
|
|
|
r;
|
|
|
|
|
_point p,
|
|
|
|
|
m;
|
|
|
|
|
_point p;
|
|
|
|
|
|
|
|
|
|
if (map.field[pos.x][pos.y].type != FT_block && map.field[pos.x][pos.y].type != FT_stone
|
|
|
|
|
&& ai_checkfield (pos.x, pos.y)) {
|
|
|
|
|
for (d = 0; d < 4; d++) {
|
|
|
|
|
switch (d) {
|
|
|
|
|
case (left):
|
|
|
|
|
m.x = -1;
|
|
|
|
|
m.y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m.x = 1;
|
|
|
|
|
m.y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m.x = 0;
|
|
|
|
|
m.y = -1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m.x = 0;
|
|
|
|
|
m.y = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = pos;
|
|
|
|
|
|
|
|
|
|
for (r = 0;
|
|
|
|
|
(r < range
|
|
|
|
|
&& (map.field[p.x][p.y].type == FT_nothing
|
|
|
|
|
|| map.field[p.x][p.y].type == FT_tunnel)); r++) {
|
|
|
|
|
p.x += m.x;
|
|
|
|
|
p.y += m.y;
|
|
|
|
|
p.x += dir_change[d].x;
|
|
|
|
|
p.y += dir_change[d].y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (map.field[p.x][p.y].type != FT_nothing && map.field[p.x][p.y].type != FT_tunnel
|
|
|
|
@ -356,33 +298,13 @@ ai_findbestbombdir (_point pos, int dir, int range)
|
|
|
|
|
j,
|
|
|
|
|
maxpoints = 0,
|
|
|
|
|
bestd;
|
|
|
|
|
_point m[4],
|
|
|
|
|
p[4];
|
|
|
|
|
_point p[4];
|
|
|
|
|
|
|
|
|
|
points[4] = ai_bombpoints (pos, range);
|
|
|
|
|
|
|
|
|
|
/* fill in the positions */
|
|
|
|
|
for (d = 0; d < 4; d++) {
|
|
|
|
|
p[d] = pos;
|
|
|
|
|
|
|
|
|
|
switch (d) {
|
|
|
|
|
case (left):
|
|
|
|
|
m[d].x = -1;
|
|
|
|
|
m[d].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m[d].x = 1;
|
|
|
|
|
m[d].y = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m[d].x = 0;
|
|
|
|
|
m[d].y = -1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m[d].x = 0;
|
|
|
|
|
m[d].y = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
@ -391,8 +313,8 @@ ai_findbestbombdir (_point pos, int dir, int range)
|
|
|
|
|
for (d = 0; d < 5; d++) {
|
|
|
|
|
|
|
|
|
|
if (d < 4) {
|
|
|
|
|
p[d].x += m[d].x;
|
|
|
|
|
p[d].y += m[d].y;
|
|
|
|
|
p[d].x += dir_change[d].x;
|
|
|
|
|
p[d].y += dir_change[d].y;
|
|
|
|
|
if (p[d].x > 0 && p[d].y > 0 && p[d].x < map.size.x - 1 && p[d].y < map.size.y - 1) {
|
|
|
|
|
if (ai_checkfield (p[d].x, p[d].y)) {
|
|
|
|
|
/* we are opn a empty field go on with the test */
|
|
|
|
@ -435,37 +357,13 @@ ai_findnearbombs (_point pos)
|
|
|
|
|
int d,
|
|
|
|
|
res = 0, // result if there is a bomb
|
|
|
|
|
done = 0;
|
|
|
|
|
_point m[4]; // direction addition
|
|
|
|
|
_point dist[4]; // to check every direction (on three ways)
|
|
|
|
|
|
|
|
|
|
for (d = 0; d < 4; d++)
|
|
|
|
|
switch (d) {
|
|
|
|
|
case (left):
|
|
|
|
|
m[d].x = -1;
|
|
|
|
|
m[d].y = 0;
|
|
|
|
|
dist[d].x = pos.x - 1;
|
|
|
|
|
dist[d].y = pos.y;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m[d].x = 1;
|
|
|
|
|
m[d].y = 0;
|
|
|
|
|
dist[d].x = pos.x + 1;
|
|
|
|
|
dist[d].y = pos.y;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m[d].x = 0;
|
|
|
|
|
m[d].y = -1;
|
|
|
|
|
dist[d].x = pos.x;
|
|
|
|
|
dist[d].y = pos.y - 1;
|
|
|
|
|
break;
|
|
|
|
|
case (down):
|
|
|
|
|
m[d].x = 0;
|
|
|
|
|
m[d].y = 1;
|
|
|
|
|
dist[d].x = pos.x;
|
|
|
|
|
dist[d].y = pos.y + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (d = 0; d < 4; d++) {
|
|
|
|
|
dist[d].x = pos.x + dir_change[d].x;
|
|
|
|
|
dist[d].y = pos.y + dir_change[d].y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
|
done = 1;
|
|
|
|
|
/* check every direction again */
|
|
|
|
@ -479,8 +377,8 @@ ai_findnearbombs (_point pos)
|
|
|
|
|
if (map.field[dist[d].x][dist[d].y].type != FT_nothing)
|
|
|
|
|
dist[d].x = dist[d].y = -1; // don't check no more.
|
|
|
|
|
else if (dist[d].x != -1 && dist[d].y != -1) {
|
|
|
|
|
dist[d].x += m[d].x;
|
|
|
|
|
dist[d].y += m[d].y;
|
|
|
|
|
dist[d].x += dir_change[d].x;
|
|
|
|
|
dist[d].y += dir_change[d].y;
|
|
|
|
|
done = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -575,24 +473,9 @@ inline int
|
|
|
|
|
ai_checknewpos (_point pos, int d)
|
|
|
|
|
{
|
|
|
|
|
_point m;
|
|
|
|
|
switch (d) {
|
|
|
|
|
case (left):
|
|
|
|
|
m.x = pos.x - 1;
|
|
|
|
|
m.y = pos.y;
|
|
|
|
|
break;
|
|
|
|
|
case (right):
|
|
|
|
|
m.x = pos.x + 1;
|
|
|
|
|
m.y = pos.y;
|
|
|
|
|
break;
|
|
|
|
|
case (up):
|
|
|
|
|
m.x = pos.x;
|
|
|
|
|
m.y = pos.y - 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m.x = pos.x;
|
|
|
|
|
m.y = pos.y + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m.x = pos.x + dir_change[d].x;
|
|
|
|
|
m.y = pos.y + dir_change[d].y;
|
|
|
|
|
|
|
|
|
|
return (ai_findnearbombs (m) == 0);
|
|
|
|
|
};
|
|
|
|
@ -782,7 +665,9 @@ single_loop ()
|
|
|
|
|
}
|
|
|
|
|
else if (rawdir.bestdir == -1 && rawdir.dir == 0) {
|
|
|
|
|
/* no good ways found, just run in the opposite direction of the bomb */
|
|
|
|
|
// ERRORRRRRRRRR;
|
|
|
|
|
if (map.field[(int) pl->pos.x][(int) pl->pos.y].type == FT_nothing ||
|
|
|
|
|
map.field[(int) pl->pos.x][(int) pl->pos.y].type >= FT_tunnel)
|
|
|
|
|
pl->m = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|