|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: field.c,v 1.21 2003/05/18 14:06:29 patty21 Exp $ */
|
|
|
|
/* $Id: field.c,v 1.22 2003/06/01 22:06:30 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>
|
|
|
@ -13,7 +13,7 @@ draw_stone (int x, int y)
|
|
|
|
_field *stone = &bman.field[x][y];
|
|
|
|
_field *stone = &bman.field[x][y];
|
|
|
|
SDL_Rect dest,
|
|
|
|
SDL_Rect dest,
|
|
|
|
src;
|
|
|
|
src;
|
|
|
|
SDL_Surface *srcimg;
|
|
|
|
SDL_Surface *srcimg = NULL;
|
|
|
|
int i,
|
|
|
|
int i,
|
|
|
|
d;
|
|
|
|
d;
|
|
|
|
|
|
|
|
|
|
|
@ -25,51 +25,75 @@ draw_stone (int x, int y)
|
|
|
|
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
src.x = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frame == 0 || stone->type != FT_stone) {
|
|
|
|
/* draw background if we have a stone, block or nothing */
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
if (stone->type <= FT_block) {
|
|
|
|
src.y = 0;
|
|
|
|
SDL_Rect srcbg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srcbg.w = dest.w;
|
|
|
|
|
|
|
|
srcbg.h = dest.h;
|
|
|
|
|
|
|
|
srcbg.x = (x % gfx.field[FT_nothing].frames) * gfx.block.x;
|
|
|
|
|
|
|
|
srcbg.y = (y % gfx.field[FT_nothing].frames) * gfx.block.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SDL_BlitSurface (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (stone->frameto == 0) {
|
|
|
|
/* animate the stone if needed only for exploding stone */
|
|
|
|
|
|
|
|
if (stone->type == FT_stone && stone->frame > 0) {
|
|
|
|
|
|
|
|
if (stone->frameto == 0)
|
|
|
|
if (stone->frame < gfx.field[stone->type].frames) {
|
|
|
|
if (stone->frame < gfx.field[stone->type].frames) {
|
|
|
|
stone->frame++;
|
|
|
|
stone->frame++;
|
|
|
|
stone->frameto = ANI_STONETIMEOUT;
|
|
|
|
stone->frameto = ANI_STONETIMEOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stone->frameto > 0)
|
|
|
|
if (stone->frameto > 0)
|
|
|
|
stone->frameto--;
|
|
|
|
stone->frameto--;
|
|
|
|
if (stone->frame < gfx.field[stone->type].frames) {
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frame < gfx.field[FT_stone].frames) {
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
srcimg = gfx.field[FT_stone].image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
src.y = 0;
|
|
|
|
src.y = 0;
|
|
|
|
srcimg = gfx.field[FT_nothing].image;
|
|
|
|
srcimg = gfx.field[FT_nothing].image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (stone->type == FT_stone || stone->type == FT_block) {
|
|
|
|
|
|
|
|
src.y = 0;
|
|
|
|
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frame > 0 || stone->type == FT_nothing) {
|
|
|
|
/* some powerup so we need to animate this too */
|
|
|
|
SDL_Rect srcbg;
|
|
|
|
else if (stone->type >= FT_death) {
|
|
|
|
|
|
|
|
if (stone->frameto-- <= 0 || stone->frameto > ANI_STONETIMEOUT) {
|
|
|
|
|
|
|
|
stone->frameto = ANI_STONETIMEOUT;
|
|
|
|
|
|
|
|
stone->frame++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
srcbg.w = dest.w;
|
|
|
|
if (stone->frame >= gfx.powerup.frames)
|
|
|
|
srcbg.h = dest.h;
|
|
|
|
stone->frame = 0;
|
|
|
|
srcbg.x = (x % gfx.field[FT_nothing].frames) * gfx.block.x;
|
|
|
|
|
|
|
|
srcbg.y = (y % gfx.field[FT_nothing].frames) * gfx.block.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SDL_BlitSurface (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest);
|
|
|
|
srcimg = gfx.powerup.image;
|
|
|
|
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->type != FT_nothing)
|
|
|
|
if (srcimg != NULL)
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->type >= FT_death) { /* draw now the powerup itself */
|
|
|
|
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
|
|
|
|
src.y = 0;
|
|
|
|
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// draw explosions if there is any
|
|
|
|
// draw explosions if there is any
|
|
|
|
for (d = 0, i = 0; d < 4; d++)
|
|
|
|
for (d = 0, i = 0; d < 4; d++)
|
|
|
|
if (stone->ex[d].count > 0) {
|
|
|
|
if (stone->ex[d].count > 0) {
|
|
|
|
i = 1; // mark that there is already an explosion
|
|
|
|
i = 1; // mark that there is already an explosion
|
|
|
|
draw_fire (x, y, d, -1);
|
|
|
|
draw_fire (x, y, d, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -135,20 +159,29 @@ 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 */
|
|
|
|
/* darw the border so we know everything is right */
|
|
|
|
for (i = 0; i < bman.fieldsize.x; i++)
|
|
|
|
for (i = 0; i < bman.fieldsize.x; i++)
|
|
|
|
bman.field[i][0].type = bman.field[i][bman.fieldsize.y-1].type = FT_block;
|
|
|
|
bman.field[i][0].type = bman.field[i][bman.fieldsize.y - 1].type = FT_block;
|
|
|
|
for (i = 0; i < bman.fieldsize.y; i++)
|
|
|
|
for (i = 0; i < bman.fieldsize.y; i++)
|
|
|
|
bman.field[0][i].type = bman.field[bman.fieldsize.x-1][i].type = FT_block;
|
|
|
|
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 */
|
|
|
|
/* 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 */
|
|
|
|
/* i am just too lazy to write this all again and again */
|
|
|
|
#define PLX bman.players[i].pos.x
|
|
|
|
#define PLX bman.players[i].pos.x
|
|
|
|
#define PLY bman.players[i].pos.y
|
|
|
|
#define PLY bman.players[i].pos.y
|
|
|
|
void field_set_playerposition (int usermap) {
|
|
|
|
void
|
|
|
|
int p, dist, i,j , mx, my, dx = 0, dy = 0;
|
|
|
|
field_set_playerposition (int usermap)
|
|
|
|
char txt[255];
|
|
|
|
{
|
|
|
|
|
|
|
|
int p,
|
|
|
|
|
|
|
|
dist,
|
|
|
|
|
|
|
|
i,
|
|
|
|
|
|
|
|
j,
|
|
|
|
|
|
|
|
mx,
|
|
|
|
|
|
|
|
my,
|
|
|
|
|
|
|
|
dx = 0,
|
|
|
|
|
|
|
|
dy = 0;
|
|
|
|
|
|
|
|
char txt[255];
|
|
|
|
|
|
|
|
|
|
|
|
p = 50;
|
|
|
|
p = 50;
|
|
|
|
dist = 8;
|
|
|
|
dist = 8;
|
|
|
@ -156,84 +189,87 @@ void field_set_playerposition (int usermap) {
|
|
|
|
p = 0;
|
|
|
|
p = 0;
|
|
|
|
dist--;
|
|
|
|
dist--;
|
|
|
|
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
|
|
|
|
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
|
|
|
|
if (usermap) {
|
|
|
|
if (usermap) {
|
|
|
|
int maxloop = 0;
|
|
|
|
int maxloop = 0;
|
|
|
|
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
|
|
|
|
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
|
|
|
|
maxloop++;
|
|
|
|
maxloop++;
|
|
|
|
PLX = s_random (bman.fieldsize.x - 2) + 1;
|
|
|
|
PLX = s_random (bman.fieldsize.x - 2) + 1;
|
|
|
|
PLY = s_random (bman.fieldsize.y - 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 */
|
|
|
|
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;
|
|
|
|
dx = PLX - bman.players[j].pos.x;
|
|
|
|
if (dx < 0) dx = - dx;
|
|
|
|
if (dx < 0)
|
|
|
|
dy = PLY - bman.players[j].pos.y;
|
|
|
|
dx = -dx;
|
|
|
|
if (dy < 0) dy = - dy;
|
|
|
|
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)) {
|
|
|
|
/* check if there is no block */
|
|
|
|
/* get (up or down) dx and (left or right) dy */
|
|
|
|
if ((dx > 1 || dy > 1)
|
|
|
|
dx = s_random (2);
|
|
|
|
&& ((bman.field[PLX][PLY].type != FT_block && maxloop > 100)
|
|
|
|
if (dx == 0)
|
|
|
|
|| bman.field[PLX][PLY].type == FT_nothing)) {
|
|
|
|
dx = -1;
|
|
|
|
/* get (up or down) dx and (left or right) dy */
|
|
|
|
dy = s_random (2);
|
|
|
|
dx = s_random (2);
|
|
|
|
if (dy == 0)
|
|
|
|
if (dx == 0)
|
|
|
|
dy = -1;
|
|
|
|
dx = -1;
|
|
|
|
|
|
|
|
dy = s_random (2);
|
|
|
|
/* first check if there is and free place for us */
|
|
|
|
if (dy == 0)
|
|
|
|
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
dy = -1;
|
|
|
|
bman.field[PLX+dx][PLY].type == FT_nothing))
|
|
|
|
|
|
|
|
dx = -dx;
|
|
|
|
/* first check if there is and free place for us */
|
|
|
|
if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
bman.field[PLX+dx][PLY].type == FT_nothing))
|
|
|
|
bman.field[PLX + dx][PLY].type == FT_nothing))
|
|
|
|
PLX = -1;
|
|
|
|
dx = -dx;
|
|
|
|
|
|
|
|
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
|
|
|
|
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
|
|
|
|
bman.field[PLX + dx][PLY].type == FT_nothing))
|
|
|
|
bman.field[PLX][PLY+dy].type == FT_nothing))
|
|
|
|
PLX = -1;
|
|
|
|
dy = -dy;
|
|
|
|
|
|
|
|
if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) ||
|
|
|
|
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
|
|
|
|
bman.field[PLX][PLY+dy].type == FT_nothing))
|
|
|
|
bman.field[PLX][PLY + dy].type == FT_nothing))
|
|
|
|
PLY = -1;
|
|
|
|
dy = -dy;
|
|
|
|
}
|
|
|
|
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
|
|
|
|
else {
|
|
|
|
bman.field[PLX][PLY + dy].type == FT_nothing))
|
|
|
|
PLX = -1;
|
|
|
|
PLY = -1;
|
|
|
|
PLY = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
PLX = -1;
|
|
|
|
/* make some space */
|
|
|
|
PLY = -1;
|
|
|
|
if (PLX != -1 && PLY != -1) {
|
|
|
|
}
|
|
|
|
bman.field[PLX][PLY].type = FT_nothing;
|
|
|
|
|
|
|
|
bman.field[PLX+dx][PLY].type = FT_nothing;
|
|
|
|
/* make some space */
|
|
|
|
bman.field[PLX][PLY+dy].type = FT_nothing;
|
|
|
|
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);
|
|
|
|
if (PLX == -1 || PLY == -1) {
|
|
|
|
menu_displaymessage ("MAP - ERROR",txt);
|
|
|
|
/* 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);
|
|
|
|
/* now there will be some fields deleted */
|
|
|
|
menu_displaymessage ("MAP - ERROR", txt);
|
|
|
|
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
|
|
|
|
}
|
|
|
|
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* now there will be some fields deleted */
|
|
|
|
bman.field[PLX][PLY].type = FT_nothing;
|
|
|
|
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
|
|
|
|
|
|
|
|
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
|
|
|
|
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
|
|
|
|
|
|
|
|
/* up and down */
|
|
|
|
bman.field[PLX][PLY].type = FT_nothing;
|
|
|
|
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
|
|
|
|
|
|
|
|
bman.field[PLX-1][PLY].type = FT_nothing;
|
|
|
|
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
|
|
|
|
else
|
|
|
|
/* up and down */
|
|
|
|
bman.field[PLX+1][PLY].type = FT_nothing;
|
|
|
|
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
|
|
|
|
/* left and right */
|
|
|
|
bman.field[PLX - 1][PLY].type = FT_nothing;
|
|
|
|
if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2)
|
|
|
|
else
|
|
|
|
bman.field[PLX][PLY-1].type = FT_nothing;
|
|
|
|
bman.field[PLX + 1][PLY].type = FT_nothing;
|
|
|
|
else
|
|
|
|
/* left and right */
|
|
|
|
bman.field[PLX][PLY+1].type = FT_nothing;
|
|
|
|
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;
|
|
|
|
mx = my = 100;
|
|
|
|
for (j = 0; j <= i; j++) { /* search smalest distance */
|
|
|
|
for (j = 0; j <= i; j++) { /* search smalest distance */
|
|
|
|
dy = PLY - bman.players[j].pos.y;
|
|
|
|
dy = PLY - bman.players[j].pos.y;
|
|
|
@ -256,46 +292,49 @@ void field_set_playerposition (int usermap) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
|
|
PLX = PLX << 8;
|
|
|
|
PLX = PLX << 8;
|
|
|
|
PLY = PLY << 8;
|
|
|
|
PLY = PLY << 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#undef PLX
|
|
|
|
#undef PLX
|
|
|
|
#undef PLY
|
|
|
|
#undef PLY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear field and send this to all netplayers
|
|
|
|
// clear field and send this to all netplayers
|
|
|
|
void
|
|
|
|
void
|
|
|
|
field_clear(int x, int y)
|
|
|
|
field_clear (int x, int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bman.field[x][y].type = FT_nothing;
|
|
|
|
bman.field[x][y].type = FT_nothing;
|
|
|
|
if (bman.gametype != GT_single)
|
|
|
|
if (bman.gametype != GT_single)
|
|
|
|
net_game_send_field (x, y);
|
|
|
|
net_game_send_field (x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
field_update(int x, int y)
|
|
|
|
field_update (int x, int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gfx_AddUpdateRect (x * gfx.block.x + gfx.offset.x, y * gfx.block.y + gfx.offset.y,
|
|
|
|
gfx_AddUpdateRect (x * gfx.block.x + gfx.offset.x, y * gfx.block.y + gfx.offset.y,
|
|
|
|
gfx.block.x, gfx.block.y);
|
|
|
|
gfx.block.x, gfx.block.y);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// put items into the field
|
|
|
|
// put items into the field
|
|
|
|
void
|
|
|
|
void
|
|
|
|
field_fillitems (int fieldtype, int num)
|
|
|
|
field_fillitems (int fieldtype, int num)
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int nb_try=100,d,x,y;
|
|
|
|
int nb_try = 100,
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
d,
|
|
|
|
how much items we want in the game */
|
|
|
|
x,
|
|
|
|
float fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
|
|
|
|
y;
|
|
|
|
/* put the row special in the field */
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
|
|
|
|
how much items we want in the game */
|
|
|
|
for (d = 0; d < num * fkt; d++) {
|
|
|
|
float fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (25.0 * 17.0);
|
|
|
|
x=y=0;
|
|
|
|
/* put the row special in the field */
|
|
|
|
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {
|
|
|
|
|
|
|
|
|
|
|
|
for (d = 0; d < num * fkt; d++) {
|
|
|
|
|
|
|
|
x = y = 0;
|
|
|
|
|
|
|
|
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {
|
|
|
|
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
|
|
|
|
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
|
|
|
|
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
|
|
|
|
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
|
|
|
|
nb_try--;
|
|
|
|
nb_try--;
|
|
|
@ -303,7 +342,7 @@ field_fillitems (int fieldtype, int num)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bman.field[x][y].special = fieldtype;
|
|
|
|
bman.field[x][y].special = fieldtype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -319,27 +358,25 @@ field_new (char *filename)
|
|
|
|
d;
|
|
|
|
d;
|
|
|
|
FILE *fmap;
|
|
|
|
FILE *fmap;
|
|
|
|
|
|
|
|
|
|
|
|
if(filename)
|
|
|
|
if (filename) {
|
|
|
|
{
|
|
|
|
fmap = fopen (filename, "r");
|
|
|
|
fmap = fopen (filename, "r");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else {
|
|
|
|
{
|
|
|
|
fmap = NULL;
|
|
|
|
fmap = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
how much items we want in the game */
|
|
|
|
how much items we want in the game */
|
|
|
|
// fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
|
|
|
|
// fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
|
|
|
|
|
|
|
|
|
|
|
|
// Clean and create the field //
|
|
|
|
// Clean and create the field //
|
|
|
|
if (fmap == NULL) {
|
|
|
|
if (fmap == NULL) {
|
|
|
|
/* if we can't load the map check first the fieldsize settings */
|
|
|
|
/* if we can't load the map check first the fieldsize settings */
|
|
|
|
if (bman.fieldsize.x < MIN_FIELDSIZE_X)
|
|
|
|
if (bman.fieldsize.x < MIN_FIELDSIZE_X)
|
|
|
|
bman.fieldsize.x = MIN_FIELDSIZE_X;
|
|
|
|
bman.fieldsize.x = MIN_FIELDSIZE_X;
|
|
|
|
if (bman.fieldsize.x > MAX_FIELDSIZE_X)
|
|
|
|
if (bman.fieldsize.x > MAX_FIELDSIZE_X)
|
|
|
@ -370,32 +407,30 @@ field_new (char *filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* delete the bfield data */
|
|
|
|
/* delete the bfield data */
|
|
|
|
for (x = 0; x < MAX_FIELDSIZE_X; x++)
|
|
|
|
for (x = 0; x < MAX_FIELDSIZE_X; x++)
|
|
|
|
for (y = 0; y < MAX_FIELDSIZE_Y; y++)
|
|
|
|
for (y = 0; y < MAX_FIELDSIZE_Y; y++)
|
|
|
|
bman.bfield[x][y] = 0;
|
|
|
|
bman.bfield[x][y] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the Playerinformation */
|
|
|
|
/* Set the Playerinformation */
|
|
|
|
field_set_playerposition (fmap != NULL);
|
|
|
|
field_set_playerposition (fmap != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* put the fire powerups in the field */
|
|
|
|
/* put the fire powerups in the field */
|
|
|
|
field_fillitems (FT_fire, GAME_SPECIAL_ITEMFIRE);
|
|
|
|
field_fillitems (FT_fire, GAME_SPECIAL_ITEMFIRE);
|
|
|
|
/* put the bomb powerups in the field */
|
|
|
|
/* put the bomb powerups in the field */
|
|
|
|
field_fillitems (FT_bomb, GAME_SPECIAL_ITEMBOMB);
|
|
|
|
field_fillitems (FT_bomb, GAME_SPECIAL_ITEMBOMB);
|
|
|
|
/* put the shoe powerup in the field */
|
|
|
|
/* put the shoe powerup in the field */
|
|
|
|
field_fillitems (FT_shoe, GAME_SPECIAL_ITEMSHOE);
|
|
|
|
field_fillitems (FT_shoe, GAME_SPECIAL_ITEMSHOE);
|
|
|
|
/* put the death ?powerups? in the field */
|
|
|
|
/* put the death ?powerups? in the field */
|
|
|
|
field_fillitems (FT_death, GAME_SPECIAL_ITEMDEATH);
|
|
|
|
field_fillitems (FT_death, GAME_SPECIAL_ITEMDEATH);
|
|
|
|
/* put the mixed powerrup in the field */
|
|
|
|
/* put the mixed powerrup in the field */
|
|
|
|
field_fillitems (FT_mixed, GAME_SPECIAL_ITEMMIXED);
|
|
|
|
field_fillitems (FT_mixed, GAME_SPECIAL_ITEMMIXED);
|
|
|
|
/* put the trigger special in the field */
|
|
|
|
/* put the trigger special in the field */
|
|
|
|
field_fillitems (FT_sp_trigger, GAME_SPECIAL_ITEMSTRIGGER);
|
|
|
|
field_fillitems (FT_sp_trigger, GAME_SPECIAL_ITEMSTRIGGER);
|
|
|
|
/* put the row special in the field */
|
|
|
|
/* put the row special in the field */
|
|
|
|
field_fillitems (FT_sp_row, GAME_SPECIAL_ITEMSROW);
|
|
|
|
field_fillitems (FT_sp_row, GAME_SPECIAL_ITEMSROW);
|
|
|
|
/* put the push special in the field */
|
|
|
|
/* put the push special in the field */
|
|
|
|
field_fillitems (FT_sp_push, GAME_SPECIAL_ITEMSPUSH);
|
|
|
|
field_fillitems (FT_sp_push, GAME_SPECIAL_ITEMSPUSH);
|
|
|
|
/* put the kick special in the field */
|
|
|
|
/* put the kick special in the field */
|
|
|
|
field_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK);
|
|
|
|
field_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|