diff --git a/src/single.c b/src/single.c index d928f27..26a62bb 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.18 2003/05/25 22:06:33 stpohle Exp $ */ +/* $Id: single.c,v 1.19 2003/05/25 22:24:47 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -222,9 +222,9 @@ ai_findbestbombdir (_point pos, int dir, int range) break; } - p.x = pos.x + m.x; - p.y = pos.y + m.y; - + p.x = pos.x + m.x; + p.y = pos.y + m.y; + points[d] = ai_bombpoints (p, range); if (points[d] > points[bestd]) bestd = d; @@ -282,7 +282,7 @@ ai_findnearbombs (_point pos) while (!done) { done = 1; - printf (" c "); + printf (" c "); /* check every direction again */ for (d = 0; d < 4; d++) if (dist[d].x >= 0 && dist[d].x < bman.fieldsize.x && @@ -313,10 +313,49 @@ int ai_fleefrombomb (_point pos, int nearbomb, int range) { int d = 0, - dir = -1; + 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; + } - if (nearbomb != 0) - dir = ai_runawayfrom (pos, range); + else if ((nearbomb & 12) != 0) { // bomb is updown from us + if (s_random (2) == 0 || (nearbomb & 1) != 0) + 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) dir = s_random (4); @@ -327,21 +366,23 @@ ai_fleefrombomb (_point pos, int nearbomb, int range) /* 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; - - 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)); +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; + + 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)); }; @@ -350,34 +391,35 @@ single_loop () { int p; _player *pl; - _point plpos; + _point plpos; int nearbomb = 0, bestbombdir = 0, - i; + i; for (p = 0; p < MAX_PLAYERS; p++) if (p != bman.p_nr && PS_IS_alife (bman.players[p].state)) { pl = &bman.players[p]; - i = ai_checkpos (pl, &plpos); - - d_printf ("single_loop pos:%d,%d nearbomb:%d bestbombdir:%d, checkpos: %d\n", plpos.x, plpos.y, nearbomb, bestbombdir, i); - + i = ai_checkpos (pl, &plpos); + + d_printf ("single_loop pos:%d,%d nearbomb:%d bestbombdir:%d, checkpos: %d\n", plpos.x, + plpos.y, nearbomb, bestbombdir, i); + if (!i) { - /* we're still moving */ + /* we're still moving */ 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); - } - } + 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); move_player (p); }