You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bomberclone/src/mapmenu.c

246 lines
6.1 KiB

/* map/tileset selection menu */
#include "bomberclone.h"
#include "gfx.h"
/* load a random map */
void map_random () {
_direntry *destart, *de, *desel;
char path[LEN_PATHFILENAME];
int max, sel;
sprintf (path, "%s/maps", bman.datapath);
desel = destart = s_getdir (path);
for (max = 0, de = destart; de != NULL; de = de->next)
if ((de->flags & DF_file) == DF_file)
max++;
sel = s_random (max);
for (max = 0, de = destart; max <= sel && de != NULL; de = de->next)
if ((de->flags & DF_file) == DF_file) {
desel = de;
max++;
}
d_printf ("Random Map %s (%d on %d)\n", desel->name, sel, max);
if (desel != NULL)
sprintf (bman.fieldpath, "%s/maps/%s", bman.datapath, desel->name);
}
/* load a random tileset */
void tileset_random () {
_direntry *destart, *de, *desel;
char path[LEN_PATHFILENAME];
int max, sel;
sprintf (path, "%s/tileset", bman.datapath);
desel = destart = s_getdir (path);
for (max = 0, de = destart; de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir)
max++;
sel = s_random (max);
for (max = 0, de = destart; max <= sel && de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) {
desel = de;
max++;
}
d_printf ("Random Tileset %s (%d on %d)\n", desel->name, sel, max);
if (desel != NULL)
strncpy (gfx.tileset, desel->name, LEN_TILESETNAME);
gfx.tileset[LEN_TILESETNAME-1] = 0;
}
/* launch the map options menu */
void mapmenu ()
{
int menuselect = 0;
char text[255], *map, pathname[LEN_PATHFILENAME], size[4];
_menu menu[] = {
{1, "Random Map:"},
{1, "Selected Map:"},
{2, " Size X:"},
{3, " Size Y:"},
{4, "Random Tileset:"},
{5, "Selected Tileset:"},
{6, "Max Players:"},
{0, ""},
{8, "Return To Previous Menu"},
{-1, ""}
};
while (menuselect != -1) {
switch (bman.random_map) {
case (0):
if(bman.fieldpath[0]==0)
sprintf (menu[1].text, "Selected Map: < undefined >");
else
sprintf (menu[1].text, "Selected Map: %s", getfilename(bman.fieldpath));
menu[1].index = 1;
sprintf (menu[0].text, "Random Map: OFF");
menu[2].text[0] = 0;
menu[2].index = 0;
menu[3].text[0] = 0;
menu[3].index = 0;
break;
case (1):
menu[1].text[0] = 0;
menu[1].index = 0;
sprintf (menu[0].text, "Random Map: random file");
menu[2].text[0] = 0;
menu[2].index = 0;
menu[3].text[0] = 0;
menu[3].index = 0;
break;
case (2):
menu[1].text[0] = 0;
menu[1].index = 0;
sprintf (menu[0].text, "Random Map: auto-generated");
sprintf (menu[2].text, " Size X: %d", bman.fieldsize.x);
menu[2].index = 2;
sprintf (menu[3].text, " Size Y: %d", bman.fieldsize.y);
menu[3].index = 3;
break;
}
if(gfx.random_tileset)
{
menu[5].text[0] = 0;
menu[5].index = 0;
}
else
{
if(gfx.tileset[0]==0)
sprintf (menu[5].text, "Selected Tileset: < undefined >");
else
sprintf (menu[5].text, "Selected Tileset: %s", gfx.tileset);
menu[5].index = 5;
}
if(gfx.random_tileset)
sprintf (menu[4].text, "Random Tileset: random file");
else
sprintf (menu[4].text, "Random Tileset: OFF");
sprintf(menu[6].text,"Max Players: %d/%d",bman.maxplayer,MAX_PLAYERS);
menuselect = menu_loop ("Map Options", menu, menuselect);
switch (menuselect) {
case (0): // Random Map
bman.random_map = (bman.random_map+2)%3;
break;
case (1): // Selected Map
sprintf (pathname , "%s/maps", bman.datapath);
map = menu_dir_select ("Select Map", pathname, DF_file);
if (map == NULL)
{
bman.fieldpath[0] = 0;
bman.random_map = 2;
}
else
sprintf (bman.fieldpath, "%s/maps/%s", bman.datapath, map);
break;
case (2): // Size X
sprintf (text, "Field Size X (%d - %d)", MIN_FIELDSIZE_X, MAX_FIELDSIZE_X);
sprintf (size, "%d", bman.fieldsize.x);
menu_get_text (text, size, 3);
bman.fieldsize.x = atoi (size) | 1;
if (bman.fieldsize.x < MIN_FIELDSIZE_X)
bman.fieldsize.x = MIN_FIELDSIZE_X;
if (bman.fieldsize.x > MAX_FIELDSIZE_X)
bman.fieldsize.x = MAX_FIELDSIZE_X;
break;
case (3): // Size Y
sprintf (text, "Field Size Y (%d - %d)", MIN_FIELDSIZE_Y, MAX_FIELDSIZE_Y);
sprintf (size, "%d", bman.fieldsize.y);
menu_get_text (text, size, 3);
bman.fieldsize.y = atoi (size) | 1;
if (bman.fieldsize.y < MIN_FIELDSIZE_Y)
bman.fieldsize.y = MIN_FIELDSIZE_Y;
if (bman.fieldsize.y > MAX_FIELDSIZE_Y)
bman.fieldsize.y = MAX_FIELDSIZE_Y;
break;
case (4): // Random Tileset
if (gfx.random_tileset == 1)
gfx.random_tileset = 0;
else
gfx.random_tileset = 1;
break;
case (5): // Selected Tileset
sprintf (pathname , "%s/tileset", bman.datapath);
map = menu_dir_select ("Select Tileset", pathname, DF_dir);
if (map == NULL)
{
gfx.tileset[0] = 0;
gfx.random_tileset = 1;
}
else
strcpy (gfx.tileset, map);
break;
case (6):
sprintf (text, "%d", bman.maxplayer);
menu_get_text ("Max Players", text, 2);
bman.maxplayer = atoi (text);
if (bman.maxplayer > MAX_PLAYERS)
bman.maxplayer = MAX_PLAYERS;
if (bman.maxplayer < 2)
bman.maxplayer = 2;
break;
case (8): // Return to previous menu
menuselect = -1;
break;
}
}
}
// Return only the file name
char* getfilename(char* path)
{
int i;
for(i=strlen(path);i>=0;i--)
if(path[i] == '\\' || path[i] == '/')
return path+i+1;
return path;
}
// Init the game according to options
void init_map_tileset()
{
switch (bman.random_map) {
case (0):
field_new (bman.fieldpath);
break;
case (1):
map_random ();
field_new (bman.fieldpath);
break;
case (2):
field_new (NULL);
break;
}
if (gfx.random_tileset)
tileset_random ();
}