Prevent an infinit loop if there is not

enough stone block on the map or if the map
is too little
origin
ob1kenewb 23 years ago
parent 19af4f0e00
commit 9c57577783

@ -1,4 +1,4 @@
/* $Id: field.c,v 1.4 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* $Id: field.c,v 1.5 2003/05/04 20:26:16 ob1kenewb 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>
@ -146,7 +146,7 @@ field_new (char *filename)
d; d;
FILE *fmap; FILE *fmap;
float fkt; float fkt;
int nb_try;
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
@ -204,41 +204,57 @@ field_new (char *filename)
bman.field[x][y+1].type = FT_nothing; bman.field[x][y+1].type = FT_nothing;
} }
nb_try=100;
/* 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++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) { 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--;
if(nb_try<0)
break;
} }
bman.field[x][y].special = FT_fire; bman.field[x][y].special = FT_fire;
x = y = 0; x = y = 0;
} }
nb_try=100;
/* put the bomb powerups in the field */ /* put the bomb powerups in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMBOMB * fkt; d++) { for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMBOMB * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) { 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--;
if(nb_try<0)
break;
} }
bman.field[x][y].special = FT_bomb; bman.field[x][y].special = FT_bomb;
x = y = 0; x = y = 0;
} }
nb_try=100;
/* put the shoe powerup in the field */ /* put the shoe powerup in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMSHOE * fkt; d++) { for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMSHOE * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) { 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--;
if(nb_try<0)
break;
} }
bman.field[x][y].special = FT_shoe; bman.field[x][y].special = FT_shoe;
x = y = 0; x = y = 0;
} }
nb_try=100;
/* put the death ?powerups? in the field */ /* put the death ?powerups? in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMDEATH * fkt; d++) { for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMDEATH * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) { 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--;
if(nb_try<0)
break;
} }
bman.field[x][y].special = FT_death; bman.field[x][y].special = FT_death;
x = y = 0; x = y = 0;

Loading…
Cancel
Save