|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
/* $Id: map.c,v 1.6 2003/07/27 21:09:57 stpohle Exp $ */
|
|
|
|
|
/* $Id: map.c,v 1.7 2003/08/10 15:10:19 stpohle Exp $ */
|
|
|
|
|
/* map handling, like generate and load maps. */
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
|
|
|
|
|
|
_map map;
|
|
|
|
|
|
|
|
|
|
// put items into the field
|
|
|
|
|
// put the special items into the field
|
|
|
|
|
void
|
|
|
|
|
map_fillitems (int fieldtype, int num)
|
|
|
|
|
{
|
|
|
|
@ -16,11 +16,10 @@ map_fillitems (int fieldtype, int num)
|
|
|
|
|
/* this is the item factor we multiply it with this so we know
|
|
|
|
|
how much items we want in the game */
|
|
|
|
|
float fkt = ((float) (map.size.x * map.size.y)) / (25.0 * 17.0);
|
|
|
|
|
/* put the row special in the field */
|
|
|
|
|
|
|
|
|
|
for (d = 0; d < num * fkt; d++) {
|
|
|
|
|
x = y = 0;
|
|
|
|
|
while (map.field[x][y].type != FT_stone || map.field[x][y].special != FT_nothing) {
|
|
|
|
|
while (map.field[x][y].type != FT_tunnel && map.field[x][y].type != FT_stone && map.field[x][y].special != FT_nothing) {
|
|
|
|
|
x = ((float) rand () / (float) RAND_MAX) * (map.size.x - 1);
|
|
|
|
|
y = ((float) rand () / (float) RAND_MAX) * (map.size.y - 1);
|
|
|
|
|
nb_try--;
|
|
|
|
@ -39,12 +38,13 @@ map_new (char *filename)
|
|
|
|
|
int x,
|
|
|
|
|
y;
|
|
|
|
|
FILE *fmap;
|
|
|
|
|
signed char old_maptype = map.type;
|
|
|
|
|
|
|
|
|
|
if (filename) {
|
|
|
|
|
fmap = fopen (filename, "r");
|
|
|
|
|
|
|
|
|
|
/* 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 map*/
|
|
|
|
|
if (fmap)
|
|
|
|
|
map_load (fmap);
|
|
|
|
|
}
|
|
|
|
@ -55,6 +55,44 @@ map_new (char *filename)
|
|
|
|
|
if (fmap == NULL)
|
|
|
|
|
map_genrandom ();
|
|
|
|
|
|
|
|
|
|
map.type = 1;
|
|
|
|
|
|
|
|
|
|
if (map.type == -1)
|
|
|
|
|
map.type = s_random (MAPT_max);
|
|
|
|
|
|
|
|
|
|
if (map.type == MAPT_tunnel) {
|
|
|
|
|
/* insert tunnels */
|
|
|
|
|
for (x = 0; x < GAME_MAX_TUNNELS; x++)
|
|
|
|
|
map.tunnel[x].x = map.tunnel[x].y = -1;
|
|
|
|
|
map.field[3][3].type = FT_tunnel;
|
|
|
|
|
map.field[3][3].special = 0;
|
|
|
|
|
map.field[map.size.x - 4][map.size.y - 4].type = FT_tunnel;
|
|
|
|
|
map.field[map.size.x - 4][map.size.y - 4].special = 1;
|
|
|
|
|
|
|
|
|
|
if (map.size.y > 12) {
|
|
|
|
|
map.field[map.size.x - 4][3].type = FT_tunnel;
|
|
|
|
|
map.field[map.size.x - 4][3].special = 2;
|
|
|
|
|
map.field[3][map.size.y - 4].type = FT_tunnel;
|
|
|
|
|
map.field[3][map.size.y - 4].special = 3;
|
|
|
|
|
|
|
|
|
|
map.tunnel[0].x = map.size.x - 4;
|
|
|
|
|
map.tunnel[0].y = 3;
|
|
|
|
|
map.tunnel[1].x = 3;
|
|
|
|
|
map.tunnel[1].y = map.size.y - 4;
|
|
|
|
|
map.tunnel[2].x = map.size.x - 4;
|
|
|
|
|
map.tunnel[2].y = map.size.y - 4;
|
|
|
|
|
map.tunnel[3].x = 3;
|
|
|
|
|
map.tunnel[3].y = 3;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
map.tunnel[0].x = map.size.x - 4;
|
|
|
|
|
map.tunnel[0].y = map.size.y - 4;
|
|
|
|
|
map.tunnel[1].x = 3;
|
|
|
|
|
map.tunnel[1].y = 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* delete the bfield data */
|
|
|
|
|
for (x = 0; x < MAX_FIELDSIZE_X; x++)
|
|
|
|
|
for (y = 0; y < MAX_FIELDSIZE_Y; y++)
|
|
|
|
@ -81,6 +119,8 @@ map_new (char *filename)
|
|
|
|
|
map_fillitems (FT_sp_push, map.sp_push);
|
|
|
|
|
/* put the kick special in the field */
|
|
|
|
|
// map_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK);
|
|
|
|
|
|
|
|
|
|
map.type = old_maptype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -195,8 +235,11 @@ map_set_playerposition (int usermap)
|
|
|
|
|
|
|
|
|
|
/* make some space */
|
|
|
|
|
if (PLX != -1 && PLY != -1) {
|
|
|
|
|
if (map.field[PLX][PLY].type != FT_tunnel)
|
|
|
|
|
map.field[PLX][PLY].type = FT_nothing;
|
|
|
|
|
if (map.field[PLX + dx][PLY].type != FT_tunnel)
|
|
|
|
|
map.field[PLX + dx][PLY].type = FT_nothing;
|
|
|
|
|
if (map.field[PLX][PLY + dy].type != FT_tunnel)
|
|
|
|
|
map.field[PLX][PLY + dy].type = FT_nothing;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|