All pastes #471546 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-04 23:11 UTC
rendered paste body
/*
==================
RandomMap

Returns a random map from the maps\ directory
==================
*/
char RandomMap (char *mfilter)
{
	dir_t		dir;
	file_t		*list;
	int			i, q;
	int			ps = 0, pi = 0;
	char		*key, *end, *pmap;
	char		*mapname[1024];

	dir = Sys_listdir(va("%s/maps", fs_gamedir), ".bsp", SORT_BY_NAME);
	key = mfilter;

	list = dir.files;
	strncat(mapname[0],"none",sizeof(mapname[0]));
	if (!list->name[0]) 
	{
		return *mapname[0];
	}

	for (i = 0; list->name[0]; i++, list++)
	{
		if (Q_stristr(list->name, key))
		{ 
			// use case-insensitive search
			pmap = list->name;
			end = strstr (pmap, ".bsp");
			//mapname[i] = pmap;
			strncat(mapname[i],pmap,sizeof(mapname[i]));

			if (strcmp(key, ""))
			{
				ps += list->size;
				pi++;
			}
		}
	}
	q = rand() % i;
	return *mapname[q];
}