ai fixed, suicide death 1. var dir_change added so we won't have anymore so many switch cases

origin
stpohle 21 years ago
parent 0f63a474e4
commit 77e68d6870

@ -1,4 +1,4 @@
$Id: ChangeLog,v 1.83 2004/09/23 13:31:50 stpohle Exp $
$Id: ChangeLog,v 1.84 2004/10/18 18:30:09 stpohle Exp $
* NEED TO FIX: Server starts the game soo fast that the
client's ignore the gamestat for a running game.
@ -6,6 +6,17 @@ $Id: ChangeLog,v 1.83 2004/09/23 13:31:50 stpohle Exp $
* FINISH TEAM MODE.
2004-10-18
- AI won't have anymore so many suicide deaths.
- Variable dir_change added so we won't have anymore
so many suicides.
- Playermenu (Playerselection changed again)
- New Team menu Handling.
2004-09-23
- little work on the AI, there are still some kind of

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.27 2004/09/26 02:28:05 stpohle Exp $ */
/* $Id: basic.h,v 1.28 2004/10/18 18:27:02 stpohle Exp $ */
/* basic types which we need everywhere */
#ifndef _BC_BASIC_H_
@ -190,5 +190,6 @@ struct __charlist {
struct __charlist *next;
} typedef _charlist;
extern _point dir_change[];
#endif

@ -1,4 +1,4 @@
/* $Id: bomb.c,v 1.59 2004/08/30 20:01:32 stpohle Exp $ */
/* $Id: bomb.c,v 1.60 2004/10/18 18:27:19 stpohle Exp $ */
/* everything what have to do with the bombs */
#include "bomberclone.h"
@ -343,11 +343,6 @@ void explosion_restore (_bomb *bomb) {
d,
_x,
_y;
_point dir_ch [] ={ { -1, 0 },
{ 1, 0 },
{ 0, -1 },
{ 0, 1 } };
// printf ("342: bomb (%d,%d)\n", (int) bomb->pos.x, (int) bomb->pos.y);
for (d = 0; d < 4; d++) {
@ -363,8 +358,8 @@ void explosion_restore (_bomb *bomb) {
/* with every field where was an fire on it decrease the ex[].count value
* and force an drawing of this field */
for (i = 0; i < bomb->firer[d]; i++) { // lower the number of explosions
_x = _x + dir_ch[d].x;
_y = _y + dir_ch[d].y;
_x = _x + dir_change[d].x;
_y = _y + dir_change[d].y;
if (map.field[_x][_y].ex[d].count > 0)
map.field[_x][_y].ex[d].count--;
@ -415,30 +410,10 @@ void
explosion_draw (_bomb * bomb)
{
int d,
r,
dx,
dy;
r;
_point p;
for (d = 0; d < 4; d++) {
switch (d) {
case (left):
dx = -1;
dy = 0;
break;
case (right):
dx = 1;
dy = 0;
break;
case (up):
dx = 0;
dy = -1;
break;
default:
dx = 0;
dy = 1;
break;
}
p.x = bomb->pos.x;
p.y = bomb->pos.y;
@ -449,8 +424,8 @@ explosion_draw (_bomb * bomb)
if (map.field[p.x][p.y].ex[d].frame >= gfx.fire.frames)
map.field[p.x][p.y].ex[d].frame = 0.0f;
stonelist_add (p.x, p.y);
p.x += dx;
p.y += dy;
p.x += dir_change[d].x;
p.y += dir_change[d].y;
}
}
}
@ -467,10 +442,6 @@ explosion_draw (_bomb * bomb)
*
*/
void explosion_do (_bomb *bomb) {
_point dir_ch [] ={ { -1, 0 },
{ 1, 0 },
{ 0, -1 },
{ 0, 1 } };
int d, dx, dy, ftype;
float range_grow = (timediff * (float) MAX_RANGE)/EXPLOSION_GROW_SPEED;
float range;
@ -483,16 +454,16 @@ void explosion_do (_bomb *bomb) {
bomb->firer[d] += range_grow;
if (bomb->firer[d] > bomb->r) bomb->firer[d] = bomb->r;
dx = bomb->pos.x + (dir_ch[d].x * rintf (range));
dy = bomb->pos.y + (dir_ch[d].y * rintf (range));
dx = bomb->pos.x + (dir_change[d].x * rintf (range));
dy = bomb->pos.y + (dir_change[d].y * rintf (range));
/* check all fields between [dx,dy] and [odx,ody] */
while (bomb->firemaxr[d] == 0 && (rintf (range) < rintf (bomb->firer[d]))) {
if (rintf (range) < rintf(bomb->firer[d])) {
range += 1.0f;
dx += dir_ch[d].x;
dy += dir_ch[d].y;
dx += dir_change[d].x;
dy += dir_change[d].y;
}
ftype = explosion_check_field (dx, dy, bomb);

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.29 2004/09/26 02:28:06 stpohle Exp $ */
/* $Id: main.c,v 1.30 2004/10/18 18:27:20 stpohle Exp $ */
#include "basic.h"
#include "bomberclone.h"
@ -12,6 +12,11 @@ _bomberclone bman; // Holds GameData
_player *players; // holds all Playerdata
_team *teams; // team stuff
_point dir_change[] ={ { -1, 0 }, // changes for directions
{ 1, 0 },
{ 0, -1 },
{ 0, 1 } };
Uint32 timestamp; // timestamp
float timefactor = 0.0f; /* factor for the time time of the last loop
1.0f would be 20ms */

@ -1,4 +1,4 @@
/* $Id: player.c,v 1.90 2004/10/06 18:16:14 stpohle Exp $
/* $Id: player.c,v 1.91 2004/10/18 18:27:20 stpohle Exp $
* player.c - everything what have to do with the player */
#include <SDL.h>
@ -299,7 +299,6 @@ stepmove_player (int pl_nr)
d; // distance to move
float speed = 0.0f;
if (p->m == 1) {
_pos.x = CUTINT(p->pos.x);
_pos.y = CUTINT(p->pos.y);

@ -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,35 +357,11 @@ 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) {
@ -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;
}
}

@ -1,4 +1,4 @@
/* $Id: special.c,v 1.35 2004/05/20 16:55:30 stpohle Exp $ */
/* $Id: special.c,v 1.36 2004/10/18 18:27:20 stpohle Exp $ */
/* special.c - procedues to control the specials */
#include "bomberclone.h"
@ -46,20 +46,10 @@ special_row (int p_nr)
dy = 0,
t = 0,
i;
switch (p->d) {
case left:
dx = -1;
break;
case right:
dx = 1;
break;
case up:
dy = -1;
break;
case down:
dy = +1;
break;
}
dx = dir_change[p->d].x;
dy = dir_change[p->d].y;
x += dx;
y += dy;
while (map.bfield[x][y]) {
@ -108,22 +98,8 @@ special_liquidmoved (int p_nr)
if ((CUTINT (p->pos.x) != 0.0f) || (CUTINT (p->pos.y) != 0.0f))
return;
switch (p->d) {
case left:
dx = -1;
break;
case right:
dx = 1;
break;
case up:
dy = -1;
break;
case down:
dy = +1;
break;
}
x += dx;
y += dy;
dx = dir_change[p->d].x;
dy = dir_change[p->d].y;
// check that player is beside a bomb
if (!map.bfield[x][y])
@ -178,20 +154,9 @@ special_push (int p_nr)
if ((CUTINT (p->pos.x) != 0.0f) || (CUTINT (p->pos.y) != 0.0f))
return;
switch (p->d) {
case left:
dx = -1;
break;
case right:
dx = 1;
break;
case up:
dy = -1;
break;
case down:
dy = +1;
break;
}
dx = dir_change[p->d].x;
dy = dir_change[p->d].y;
x += dx;
y += dy;
@ -246,20 +211,9 @@ special_kick (int p_nr)
if ((CUTINT (p->pos.x) != 0.0f) || (CUTINT (p->pos.y) != 0.0f))
return;
switch (p->d) {
case left:
dx = -1;
break;
case right:
dx = 1;
break;
case up:
dy = -1;
break;
case down:
dy = 1;
break;
}
dx = dir_change[p->d].x;
dy = dir_change[p->d].y;
x += dx;
y += dy;

Loading…
Cancel
Save