|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: field.c,v 1.7 2003/05/05 00:22:21 stpohle Exp $ */
|
|
|
|
/* $Id: field.c,v 1.8 2003/05/05 04:14:55 stpohle Exp $ */
|
|
|
|
/* field.c - procedures which are needed to control the field */
|
|
|
|
/* field.c - procedures which are needed to control the field */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
@ -84,7 +84,6 @@ draw_field ()
|
|
|
|
(# correspond to a bloc and @ correspond to a stone,
|
|
|
|
(# correspond to a bloc and @ correspond to a stone,
|
|
|
|
an espace is nothing ' '
|
|
|
|
an espace is nothing ' '
|
|
|
|
% are commentary at the beginning of the map */
|
|
|
|
% are commentary at the beginning of the map */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
field_load (FILE * map)
|
|
|
|
field_load (FILE * map)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -130,8 +129,136 @@ field_load (FILE * map)
|
|
|
|
|
|
|
|
|
|
|
|
bman.fieldsize.x = sizex - 1;
|
|
|
|
bman.fieldsize.x = sizex - 1;
|
|
|
|
bman.fieldsize.y = sizey;
|
|
|
|
bman.fieldsize.y = sizey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* darw the border so we know everything is right */
|
|
|
|
|
|
|
|
for (i = 0; i < bman.fieldsize.x; i++)
|
|
|
|
|
|
|
|
bman.field[i][0].type = bman.field[i][bman.fieldsize.y-1].type = FT_block;
|
|
|
|
|
|
|
|
for (i = 0; i < bman.fieldsize.y; i++)
|
|
|
|
|
|
|
|
bman.field[0][i].type = bman.field[bman.fieldsize.x-1][i].type = FT_block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* will set the playerposition but in a way that we won't start on a block */
|
|
|
|
|
|
|
|
/* i am just too lazy to write this all again and again */
|
|
|
|
|
|
|
|
#define PLX bman.players[i].pos.x
|
|
|
|
|
|
|
|
#define PLY bman.players[i].pos.y
|
|
|
|
|
|
|
|
void field_set_playerposition (int usermap) {
|
|
|
|
|
|
|
|
int p, dist, i,j , mx, my, dx = 0, dy = 0;
|
|
|
|
|
|
|
|
char txt[255];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = 50;
|
|
|
|
|
|
|
|
dist = 8;
|
|
|
|
|
|
|
|
while (p == 50) {
|
|
|
|
|
|
|
|
p = 0;
|
|
|
|
|
|
|
|
dist--;
|
|
|
|
|
|
|
|
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
|
|
|
|
|
|
|
|
if (usermap) {
|
|
|
|
|
|
|
|
int maxloop = 0;
|
|
|
|
|
|
|
|
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
|
|
|
|
|
|
|
|
maxloop++;
|
|
|
|
|
|
|
|
PLX = s_random (bman.fieldsize.x - 2) + 1;
|
|
|
|
|
|
|
|
PLY = s_random (bman.fieldsize.y - 2) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (dx = 10, dy = 10, j = 0; (j < i && j < MAX_PLAYERS && (dx > 1 || dy > 1)); j++) { /* is ther any other player */
|
|
|
|
|
|
|
|
dx = PLX - bman.players[j].pos.x;
|
|
|
|
|
|
|
|
if (dx < 0) dx = - dx;
|
|
|
|
|
|
|
|
dy = PLY - bman.players[j].pos.y;
|
|
|
|
|
|
|
|
if (dy < 0) dy = - dy;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* check if there is no block */
|
|
|
|
|
|
|
|
if ((dx > 1 || dy > 1) && ((bman.field[PLX][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
|
|
|
|
bman.field[PLX][PLY].type == FT_nothing)) {
|
|
|
|
|
|
|
|
/* get (up or down) dx and (left or right) dy */
|
|
|
|
|
|
|
|
dx = s_random (2);
|
|
|
|
|
|
|
|
if (dx == 0)
|
|
|
|
|
|
|
|
dx = -1;
|
|
|
|
|
|
|
|
dy = s_random (2);
|
|
|
|
|
|
|
|
if (dy == 0)
|
|
|
|
|
|
|
|
dy = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* first check if there is and free place for us */
|
|
|
|
|
|
|
|
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
|
|
|
|
bman.field[PLX+dx][PLY].type == FT_nothing))
|
|
|
|
|
|
|
|
dx = -dx;
|
|
|
|
|
|
|
|
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
|
|
|
|
bman.field[PLX+dx][PLY].type == FT_nothing))
|
|
|
|
|
|
|
|
PLX = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
|
|
|
|
|
|
|
|
bman.field[PLX][PLY+dy].type == FT_nothing))
|
|
|
|
|
|
|
|
dy = -dy;
|
|
|
|
|
|
|
|
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
|
|
|
|
|
|
|
|
bman.field[PLX][PLY+dy].type == FT_nothing))
|
|
|
|
|
|
|
|
PLY = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
PLX = -1;
|
|
|
|
|
|
|
|
PLY = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* make some space */
|
|
|
|
|
|
|
|
if (PLX != -1 && PLY != -1) {
|
|
|
|
|
|
|
|
bman.field[PLX][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
bman.field[PLX+dx][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
bman.field[PLX][PLY+dy].type = FT_nothing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PLX == -1 || PLY == -1) {
|
|
|
|
|
|
|
|
/* we could not set all fields or we don't run on a usermap */
|
|
|
|
|
|
|
|
if (usermap) {
|
|
|
|
|
|
|
|
sprintf (txt,"Not all players could be set (Pl:%d)", i);
|
|
|
|
|
|
|
|
menu_displaymessage ("MAP - ERROR",txt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* now there will be some fields deleted */
|
|
|
|
|
|
|
|
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
|
|
|
|
|
|
|
|
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bman.field[PLX][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
|
|
|
|
|
|
|
|
/* up and down */
|
|
|
|
|
|
|
|
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
|
|
|
|
|
|
|
|
bman.field[PLX-1][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
bman.field[PLX+1][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
/* left and right */
|
|
|
|
|
|
|
|
if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2)
|
|
|
|
|
|
|
|
bman.field[PLX][PLY-1].type = FT_nothing;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
bman.field[PLX][PLY+1].type = FT_nothing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mx = my = 100;
|
|
|
|
|
|
|
|
for (j = 0; j <= i; j++) { /* search smalest distance */
|
|
|
|
|
|
|
|
dy = PLY - bman.players[j].pos.y;
|
|
|
|
|
|
|
|
dx = PLX - bman.players[j].pos.x;
|
|
|
|
|
|
|
|
if (dy < 0)
|
|
|
|
|
|
|
|
dy = -dy;
|
|
|
|
|
|
|
|
if (dx < 0)
|
|
|
|
|
|
|
|
dx = -dx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mx > dx && i != j)
|
|
|
|
|
|
|
|
mx = dx;
|
|
|
|
|
|
|
|
if (my > dy && i != j)
|
|
|
|
|
|
|
|
my = dy;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mx > dist || my > dist)
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
p++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
|
|
|
|
|
|
PLX = PLX << 8;
|
|
|
|
|
|
|
|
PLY = PLY << 8;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef PLX
|
|
|
|
|
|
|
|
#undef PLY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
field_new (char *filename)
|
|
|
|
field_new (char *filename)
|
|
|
@ -146,14 +273,14 @@ field_new (char *filename)
|
|
|
|
|
|
|
|
|
|
|
|
/* if we can't open the given filename for any reason, reverting
|
|
|
|
/* if we can't open the given filename for any reason, reverting
|
|
|
|
to default value else, load the file */
|
|
|
|
to default value else, load the file */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fmap)
|
|
|
|
if (fmap)
|
|
|
|
field_load (fmap);
|
|
|
|
field_load (fmap);
|
|
|
|
|
|
|
|
|
|
|
|
fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (bman.fieldsize.x * bman.fieldsize.y);
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
|
|
|
|
how much items we want in the game */
|
|
|
|
// Clean the field //
|
|
|
|
fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clean and create the field //
|
|
|
|
if (fmap == NULL) {
|
|
|
|
if (fmap == NULL) {
|
|
|
|
for (x = 0; x < bman.fieldsize.x; x++)
|
|
|
|
for (x = 0; x < bman.fieldsize.x; x++)
|
|
|
|
for (y = 0; y < bman.fieldsize.y; y++) {
|
|
|
|
for (y = 0; y < bman.fieldsize.y; y++) {
|
|
|
@ -180,23 +307,6 @@ field_new (char *filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get some free space for the playerstart position */
|
|
|
|
|
|
|
|
for (d = 0; d < MAX_PLAYERS; d++)
|
|
|
|
|
|
|
|
if ((PS_IS_alife (bman.players[d].state)) != 0) {
|
|
|
|
|
|
|
|
x = bman.players[d].pos.x >> 8;
|
|
|
|
|
|
|
|
y = bman.players[d].pos.y >> 8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bman.field[x][y].type = FT_nothing;
|
|
|
|
|
|
|
|
if (x > 1)
|
|
|
|
|
|
|
|
bman.field[x - 1][y].type = FT_nothing;
|
|
|
|
|
|
|
|
if (x < bman.fieldsize.x - 2)
|
|
|
|
|
|
|
|
bman.field[x + 1][y].type = FT_nothing;
|
|
|
|
|
|
|
|
if (y > 1)
|
|
|
|
|
|
|
|
bman.field[x][y - 1].type = FT_nothing;
|
|
|
|
|
|
|
|
if (y < bman.fieldsize.y - 2)
|
|
|
|
|
|
|
|
bman.field[x][y + 1].type = FT_nothing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nb_try = 100; // to prevent infinite loops (maybe there are no stones)
|
|
|
|
nb_try = 100; // to prevent infinite loops (maybe there are no stones)
|
|
|
|
/* put the fire powerups in the field */
|
|
|
|
/* put the fire powerups in the field */
|
|
|
|
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) {
|
|
|
|
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) {
|
|
|
@ -252,4 +362,6 @@ field_new (char *filename)
|
|
|
|
bman.field[x][y].special = FT_death;
|
|
|
|
bman.field[x][y].special = FT_death;
|
|
|
|
x = y = 0;
|
|
|
|
x = y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
field_set_playerposition (fmap != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|