|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: map.c,v 1.21 2004/02/07 23:51:17 stpohle Exp $ */
|
|
|
|
|
/* $Id: map.c,v 1.22 2004/02/08 00:40:20 stpohle Exp $ */
|
|
|
|
|
/* map handling, like generate and load maps. */
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
@ -128,9 +128,6 @@ map_new (char *filename)
|
|
|
|
|
|
|
|
|
|
map_find_and_add_start_points(pl_cnt - map_num_defined_start_points(), MAP_POSITION_TOLERENCE);
|
|
|
|
|
|
|
|
|
|
/* Set the Playerinformation */
|
|
|
|
|
map_set_playerposition (fmap != NULL);
|
|
|
|
|
|
|
|
|
|
/* put the fire powerups in the field */
|
|
|
|
|
map_fillitems (FT_fire, map.fire);
|
|
|
|
|
/* put the bomb powerups in the field */
|
|
|
|
@ -197,274 +194,6 @@ map_genrandom ()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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(__i) players[__i].pos.x
|
|
|
|
|
#define PLY(__i) players[__i].pos.y
|
|
|
|
|
|
|
|
|
|
/* check if there is another player in the near if so delete player pos for another try */
|
|
|
|
|
void map_playerpos_check (int pl) {
|
|
|
|
|
int i, d = MAX_FIELDSIZE_X, dx, dy;
|
|
|
|
|
for (i = 0; (i < MAX_PLAYERS && d > 1); i++)
|
|
|
|
|
if (i != pl) {
|
|
|
|
|
dx = PLX(i) - PLX(pl);
|
|
|
|
|
if (dx < 0)
|
|
|
|
|
dx = -dx;
|
|
|
|
|
dy = PLY(i) - PLY(pl);
|
|
|
|
|
if (dy < 0)
|
|
|
|
|
dy = -dy;
|
|
|
|
|
if (dx < dy) // save the biggest distance in there
|
|
|
|
|
dx = dy;
|
|
|
|
|
if (dx < d)
|
|
|
|
|
d = dx;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d < 2) {
|
|
|
|
|
PLX(pl) = -1;
|
|
|
|
|
PLY(pl) = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
map_set_player_way1 (int pl)
|
|
|
|
|
{
|
|
|
|
|
_point p, t[4];
|
|
|
|
|
int i, j, ok = 0;
|
|
|
|
|
|
|
|
|
|
p.x = s_random (map.size.x - 2) + 1;
|
|
|
|
|
p.y = s_random (map.size.y - 2) + 1;
|
|
|
|
|
|
|
|
|
|
/* check if there is no block */
|
|
|
|
|
if (map.field[p.x][p.y].type != FT_nothing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* check if we can run away somewhere */
|
|
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
|
t[j].x = p.x;
|
|
|
|
|
t[j].y = p.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; (i < 10 && ok == 0); i++) {
|
|
|
|
|
t[left].x -= 1;
|
|
|
|
|
t[right].x += 1;
|
|
|
|
|
t[up].y = -1;
|
|
|
|
|
t[down].y += 1;
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
|
if (t[j].x > 0 && t[j].x < map.size.x
|
|
|
|
|
&& t[j].y > 0 && t[j].y < map.size.y) {
|
|
|
|
|
if (map.field[t[j].x][t[j].y].type == FT_nothing) {
|
|
|
|
|
if ((j == left || j == right)
|
|
|
|
|
&& map.field[t[j].x][t[j].y - 1].type == FT_nothing
|
|
|
|
|
&& map.field[t[j].x][t[j].y + 1].type == FT_nothing)
|
|
|
|
|
ok = 1;
|
|
|
|
|
if ((j == up || j == down)
|
|
|
|
|
&& map.field[t[j].x - 1][t[j].y].type == FT_nothing
|
|
|
|
|
&& map.field[t[j].x + 1][t[j].y].type == FT_nothing)
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
else { /* this field is not free anymore */
|
|
|
|
|
t[j].x = -1;
|
|
|
|
|
t[j].y = -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
t[j].x = -1;
|
|
|
|
|
t[j].y = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok) {
|
|
|
|
|
PLX(pl) = p.x;
|
|
|
|
|
PLY(pl) = p.y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
map_set_player_way2 (int pl, int hardway)
|
|
|
|
|
{
|
|
|
|
|
_point p, t[4];
|
|
|
|
|
int i, j, ok = 0;
|
|
|
|
|
|
|
|
|
|
p.x = s_random (map.size.x - 2) + 1;
|
|
|
|
|
p.y = s_random (map.size.y - 2) + 1;
|
|
|
|
|
|
|
|
|
|
/* check if there is no block */
|
|
|
|
|
if ((map.field[p.x][p.y].type != FT_nothing && (!hardway || map.field[p.x][p.y].type != FT_stone))
|
|
|
|
|
|| map.field[p.x][p.y].special == FT_tunnel)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* delete the stone under the player, only in hardway mode */
|
|
|
|
|
if (map.field[p.x][p.y].type != FT_stone && hardway) {
|
|
|
|
|
map.field[p.x][p.y].type = FT_nothing;
|
|
|
|
|
map.field[p.x][p.y].special = FT_nothing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* check if we can run away somewhere */
|
|
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
|
t[j].x = p.x;
|
|
|
|
|
t[j].y = p.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hardway) // if we using the hard way for playerposition
|
|
|
|
|
hardway = s_random (4)+1; // then select a side which we use
|
|
|
|
|
|
|
|
|
|
for (i = 0; (i < 10 && ok == 0); i++) {
|
|
|
|
|
t[left].x -= 1;
|
|
|
|
|
t[right].x += 1;
|
|
|
|
|
t[up].y = -1;
|
|
|
|
|
t[down].y += 1;
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
|
if (t[j].x > 0 && t[j].x < map.size.x
|
|
|
|
|
&& t[j].y > 0 && t[j].y < map.size.y) {
|
|
|
|
|
|
|
|
|
|
if (hardway && (hardway - 1) == j && map.field[t[j].x][t[j].y].type == FT_stone) {
|
|
|
|
|
map.field[t[j].x][t[j].y].type = FT_nothing;
|
|
|
|
|
map.field[t[j].x][t[j].y].special = FT_nothing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (map.field[t[j].x][t[j].y].type == FT_nothing) {
|
|
|
|
|
if (ok == 0 && (j == left || j == right)
|
|
|
|
|
&& (map.field[t[j].x][t[j].y - 1].type == FT_stone || map.field[t[j].x][t[j].y - 1].type == FT_nothing)) {
|
|
|
|
|
map.field[t[j].x][t[j].y - 1].type = FT_nothing;
|
|
|
|
|
map.field[t[j].x][t[j].y - 1].special = FT_nothing;
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
if (ok == 0 && (j == left || j == right)
|
|
|
|
|
&& (map.field[t[j].x][t[j].y + 1].type == FT_stone || map.field[t[j].x][t[j].y + 1].type == FT_nothing)) {
|
|
|
|
|
map.field[t[j].x][t[j].y + 1].type = FT_nothing;
|
|
|
|
|
map.field[t[j].x][t[j].y + 1].special = FT_nothing;
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
if (ok == 0 && (j == up || j == down)
|
|
|
|
|
&& (map.field[t[j].x + 1][t[j].y].type == FT_stone || map.field[t[j].x + 1][t[j].y].type == FT_nothing)) {
|
|
|
|
|
map.field[t[j].x + 1][t[j].y].type = FT_nothing;
|
|
|
|
|
map.field[t[j].x + 1][t[j].y].special = FT_nothing;
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
if (ok == 0 && (j == up || j == down)
|
|
|
|
|
&& (map.field[t[j].x - 1][t[j].y].type == FT_stone || map.field[t[j].x - 1][t[j].y].type == FT_nothing)) {
|
|
|
|
|
map.field[t[j].x - 1][t[j].y].type = FT_nothing;
|
|
|
|
|
map.field[t[j].x - 1][t[j].y].special = FT_nothing;
|
|
|
|
|
ok = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { /* this field is not free anymore */
|
|
|
|
|
t[j].x = -1;
|
|
|
|
|
t[j].y = -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
t[j].x = -1;
|
|
|
|
|
t[j].y = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok) {
|
|
|
|
|
PLX(pl) = p.x;
|
|
|
|
|
PLY(pl) = p.y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
map_set_playerposition (int usermap)
|
|
|
|
|
{
|
|
|
|
|
int pl,
|
|
|
|
|
ready,
|
|
|
|
|
maxtry;
|
|
|
|
|
int all_players_set = 1;
|
|
|
|
|
|
|
|
|
|
d_printf ("map_set_playerposition\n");
|
|
|
|
|
|
|
|
|
|
/* This is the new code that will set every player in a starting point
|
|
|
|
|
* It should never fail, but if it does, it will fall through to the old method
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++) {
|
|
|
|
|
if (PS_IS_used(players[pl].state)) {
|
|
|
|
|
map_place_player(pl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test to see if all players are placed */
|
|
|
|
|
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++) {
|
|
|
|
|
|
|
|
|
|
if ((PS_IS_used(players[pl].state))
|
|
|
|
|
&& ((players[pl].pos.x < 0) || (players[pl].pos.y < 0))) {
|
|
|
|
|
|
|
|
|
|
all_players_set = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if a used player is not set at a valid start point, fall into the old mode */
|
|
|
|
|
|
|
|
|
|
if (!all_players_set) {
|
|
|
|
|
|
|
|
|
|
d_fatal("Using old player set method. This should not happen.\n");
|
|
|
|
|
|
|
|
|
|
/* try to set every player on a good place */
|
|
|
|
|
maxtry = 300;
|
|
|
|
|
ready = 0;
|
|
|
|
|
while (!ready && maxtry-- > 0) {
|
|
|
|
|
ready = 1;
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++)
|
|
|
|
|
if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) {
|
|
|
|
|
/* set player */
|
|
|
|
|
ready = 0;
|
|
|
|
|
map_set_player_way1 (pl);
|
|
|
|
|
map_playerpos_check (pl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* every player which is still not set .. set now and delete some normal stones */
|
|
|
|
|
maxtry = 200;
|
|
|
|
|
ready = 0;
|
|
|
|
|
while (!ready && maxtry-- > 0) {
|
|
|
|
|
ready = 1;
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++)
|
|
|
|
|
if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) {
|
|
|
|
|
/* set player */
|
|
|
|
|
ready = 0;
|
|
|
|
|
map_set_player_way2 (pl, 0);
|
|
|
|
|
if (maxtry > 50)
|
|
|
|
|
map_playerpos_check (pl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* try another way for setting the players */
|
|
|
|
|
maxtry = 200;
|
|
|
|
|
ready = 0;
|
|
|
|
|
while (!ready && maxtry-- > 0) {
|
|
|
|
|
ready = 1;
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++)
|
|
|
|
|
if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) {
|
|
|
|
|
/* set player */
|
|
|
|
|
ready = 0;
|
|
|
|
|
map_set_player_way2 (pl, 1);
|
|
|
|
|
if (maxtry > 50)
|
|
|
|
|
map_playerpos_check (pl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* every player who is still not set ... let them die before they
|
|
|
|
|
* can play put a warning on the screen */
|
|
|
|
|
maxtry = 0; // mark our warning
|
|
|
|
|
for (pl = 0; pl < MAX_PLAYERS; pl++)
|
|
|
|
|
if (PS_IS_used (players[pl].state) && (PLX (pl) < 0 || PLY (pl) < 0)) {
|
|
|
|
|
PLX (pl) = 0.0;
|
|
|
|
|
PLY (pl) = 0.0;
|
|
|
|
|
maxtry = 1;
|
|
|
|
|
}
|
|
|
|
|
if (maxtry)
|
|
|
|
|
d_fatal ("Not All Player could been set\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#undef PLX
|
|
|
|
|
#undef PLY
|
|
|
|
|
|
|
|
|
|
/* load a random map */
|
|
|
|
|
void
|
|
|
|
|
map_random ()
|
|
|
|
|