Esempio n. 1
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
void BotInitInfoEntities( void ) {
	char classname[MAX_EPAIRKEY];
	maplocation_t *ml;
	campspot_t *cs;
	int ent, numlocations, numcampspots;

	BotFreeInfoEntities();
	//
	numlocations = 0;
	numcampspots = 0;
	for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) )
	{
		if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) {
			continue;
		}

		//map locations
		if ( !strcmp( classname, "target_location" ) ) {
			ml = (maplocation_t *) GetClearedMemory( sizeof( maplocation_t ) );
			AAS_VectorForBSPEpairKey( ent, "origin", ml->origin );
			AAS_ValueForBSPEpairKey( ent, "message", ml->name, sizeof( ml->name ) );
			ml->areanum = AAS_PointAreaNum( ml->origin );
			ml->next = maplocations;
			maplocations = ml;
			numlocations++;
		} //end if
		  //camp spots
		else if ( !strcmp( classname, "info_camp" ) ) {
			cs = (campspot_t *) GetClearedMemory( sizeof( campspot_t ) );
			AAS_VectorForBSPEpairKey( ent, "origin", cs->origin );
			//cs->origin[2] += 16;
			AAS_ValueForBSPEpairKey( ent, "message", cs->name, sizeof( cs->name ) );
			AAS_FloatForBSPEpairKey( ent, "range", &cs->range );
			AAS_FloatForBSPEpairKey( ent, "weight", &cs->weight );
			AAS_FloatForBSPEpairKey( ent, "wait", &cs->wait );
			AAS_FloatForBSPEpairKey( ent, "random", &cs->random );
			cs->areanum = AAS_PointAreaNum( cs->origin );
			if ( !cs->areanum ) {
				botimport.Print( PRT_MESSAGE, "camp spot at %1.1f %1.1f %1.1f in solid\n", cs->origin[0], cs->origin[1], cs->origin[2] );
				FreeMemory( cs );
				continue;
			} //end if
			cs->next = campspots;
			campspots = cs;
			//AAS_DrawPermanentCross(cs->origin, 4, LINECOLOR_YELLOW);
			numcampspots++;
		} //end else if
	} //end for
	if ( bot_developer ) {
		botimport.Print( PRT_MESSAGE, "%d map locations\n", numlocations );
		botimport.Print( PRT_MESSAGE, "%d camp spots\n", numcampspots );
	} //end if
} //end of the function BotInitInfoEntities
Esempio n. 2
0
//===========================================================================
// allocate memory and read a lump of a AAS file
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
char *AAS_LoadAASLump( FILE *fp, int offset, int length, void *buf ) {
	if ( !length ) {
		printf( "lump size 0\n" );
		return buf;
	} //end if
	  //seek to the data
	if ( fseek( fp, offset, SEEK_SET ) ) {
		AAS_Error( "can't seek to lump\n" );
		AAS_DumpAASData();
		fclose( fp );
		return 0;
	} //end if
	  //allocate memory
	if ( !buf ) {
		buf = (void *) GetClearedMemory( length );
	}
	//read the data
	if ( fread( (char *) buf, 1, length, fp ) != length ) {
		AAS_Error( "can't read lump\n" );
		FreeMemory( buf );
		AAS_DumpAASData();
		fclose( fp );
		return NULL;
	} //end if
	return buf;
} //end of the function AAS_LoadAASLump
Esempio n. 3
0
//============================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//============================================================================
script_t *LoadScriptMemory(char *ptr, int length, char *name)
{
	void *buffer;
	script_t *script;

	buffer = GetClearedMemory(sizeof(script_t) + length + 1);
	script = (script_t *) buffer;
	Com_Memset(script, 0, sizeof(script_t));
	Q_strncpyz(script->filename, name, sizeof(script->filename));
	script->buffer = (char *) buffer + sizeof(script_t);
	script->buffer[length] = 0;
	script->length = length;
	//pointer in script buffer
	script->script_p = script->buffer;
	//pointer in script buffer before reading token
	script->lastscript_p = script->buffer;
	//pointer to end of script buffer
	script->end_p = &script->buffer[length];
	//set if there's a token available in script->token
	script->tokenavailable = 0;
	//
	script->line = 1;
	script->lastline = 1;
	//
	SetScriptPunctuations(script, NULL);
	//
	Com_Memcpy(script->buffer, ptr, length);
	//
	return script;
} //end of the function LoadScriptMemory
Esempio n. 4
0
//============================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//============================================================================
script_t *LoadScriptFile( char *filename ) {
#ifdef BOTLIB
	fileHandle_t fp;
	char pathname[MAX_QPATH];
#else
	FILE *fp;
#endif
	int length;
	void *buffer;
	script_t *script;

#ifdef BOTLIB
	Com_sprintf( pathname, MAX_QPATH, "botfiles/%s", filename );
	length = botimport.FS_FOpenFile( pathname, &fp, FS_READ );
	if ( !fp ) {
		return NULL;
	}
#else
	fp = fopen( filename, "rb" );
	if ( !fp ) {
		return NULL;
	}

	length = FileLength( fp );
#endif

	buffer = GetClearedMemory( sizeof( script_t ) + length + 1 );
	script = (script_t *) buffer;
	memset( script, 0, sizeof( script_t ) );
	strcpy( script->filename, filename );
	script->buffer = (char *) buffer + sizeof( script_t );
	script->buffer[length] = 0;
	script->length = length;
	//pointer in script buffer
	script->script_p = script->buffer;
	//pointer in script buffer before reading token
	script->lastscript_p = script->buffer;
	//pointer to end of script buffer
	script->end_p = &script->buffer[length];
	//set if there's a token available in script->token
	script->tokenavailable = 0;
	//
	script->line = 1;
	script->lastline = 1;
	//
	SetScriptPunctuations( script, NULL );
	//
#ifdef BOTLIB
	botimport.FS_Read( script->buffer, length, fp );
	botimport.FS_FCloseFile( fp );
#else
	if ( fread( script->buffer, length, 1, fp ) != 1 ) {
		FreeMemory( buffer );
		script = NULL;
	} //end if
	fclose( fp );
#endif
	//
	return script;
} //end of the function LoadScriptFile
Esempio n. 5
0
void AAS_FloodAreas(vector3 *origin) {
	int areanum, cluster, *done;

	done = (int *) GetClearedMemory(aasworld.numareas * sizeof(int));
	areanum = AAS_PointAreaNum(origin);
	cluster = AAS_AreaCluster(areanum);
	AAS_FloodAreas_r(areanum, cluster, done);
}
Esempio n. 6
0
//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int BotInterpolateCharacters( int handle1, int handle2, int desiredskill )
{
    bot_character_t *ch1, *ch2, *out;
    int             i, handle;
    float           scale;

    ch1 = BotCharacterFromHandle( handle1 );
    ch2 = BotCharacterFromHandle( handle2 );

    if ( !ch1 || !ch2 )
    {
        return 0;
    }

    //find a free spot for a character
    for ( handle = 1; handle <= MAX_CLIENTS; handle++ )
    {
        if ( !botcharacters[ handle ] )
        {
            break;
        }
    } //end for

    if ( handle > MAX_CLIENTS )
    {
        return 0;
    }

    out = ( bot_character_t * ) GetClearedMemory( sizeof( bot_character_t ) + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) );
    out->skill = desiredskill;
    strcpy( out->filename, ch1->filename );
    botcharacters[ handle ] = out;

    scale = ( float )( desiredskill - 1 ) / ( ch2->skill - ch1->skill );

    for ( i = 0; i < MAX_CHARACTERISTICS; i++ )
    {
        //
        if ( ch1->c[ i ].type == CT_FLOAT && ch2->c[ i ].type == CT_FLOAT )
        {
            out->c[ i ].type = CT_FLOAT;
            out->c[ i ].value._float = ch1->c[ i ].value._float + ( ch2->c[ i ].value._float - ch1->c[ i ].value._float ) * scale;
        } //end if
        else if ( ch1->c[ i ].type == CT_INTEGER )
        {
            out->c[ i ].type = CT_INTEGER;
            out->c[ i ].value.integer = ch1->c[ i ].value.integer;
        } //end else if
        else if ( ch1->c[ i ].type == CT_STRING )
        {
            out->c[ i ].type = CT_STRING;
            out->c[ i ].value.string = ( char * ) GetMemory( strlen( ch1->c[ i ].value.string ) + 1 );
            strcpy( out->c[ i ].value.string, ch1->c[ i ].value.string );
        } //end else if
    } //end for

    return handle;
} //end of the function BotInterpolateCharacters
Esempio n. 7
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
quakefile_t *FindQuakeFilesInZip( char *zipfile, char *filter ) {
	unzFile uf;
	int err;
	unz_global_info gi;
	char filename_inzip[MAX_PATH];
	unz_file_info file_info;
	int i;
	quakefile_t     *qfiles, *lastqf, *qf;

	uf = unzOpen( zipfile );
	err = unzGetGlobalInfo( uf, &gi );

	if ( err != UNZ_OK ) {
		return NULL;
	}

	unzGoToFirstFile( uf );

	qfiles = NULL;
	lastqf = NULL;
	for ( i = 0; i < gi.number_entry; i++ )
	{
		err = unzGetCurrentFileInfo( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL,0,NULL,0 );
		if ( err != UNZ_OK ) {
			break;
		}

		ConvertPath( filename_inzip );
		if ( FileFilter( filter, filename_inzip, false ) ) {
			qf = GetClearedMemory( sizeof( quakefile_t ) );
			if ( !qf ) {
				Error( "out of memory" );
			}
			memset( qf, 0, sizeof( quakefile_t ) );
			strcpy( qf->pakfile, zipfile );
			strcpy( qf->filename, zipfile );
			strcpy( qf->origname, filename_inzip );
			qf->zipfile = true;
			//memcpy( &buildBuffer[i].zipfileinfo, (unz_s*)uf, sizeof(unz_s));
			memcpy( &qf->zipinfo, (unz_s*)uf, sizeof( unz_s ) );
			qf->offset = 0;
			qf->length = file_info.uncompressed_size;
			qf->type = QuakeFileType( filename_inzip );
			//add the file ot the list
			qf->next = NULL;
			if ( lastqf ) {
				lastqf->next = qf;
			} else { qfiles = qf;}
			lastqf = qf;
		} //end if
		unzGoToNextFile( uf );
	} //end for

	unzClose( uf );

	return qfiles;
} //end of the function FindQuakeFilesInZip
Esempio n. 8
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AAS_CreateAreaSettings(void)
{
	int i, flags, side, numgrounded, numladderareas, numliquidareas;
	tmp_face_t *face;
	tmp_area_t *tmparea;

	numgrounded = 0;
	numladderareas = 0;
	numliquidareas = 0;
	Log_Write("AAS_CreateAreaSettings\r\n");
	i = 0;
	qprintf("%6d areas provided with settings", i);
	for (tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next)
	{
		//if the area is invalid there no need to create settings for it
		if (tmparea->invalid) continue;

		tmparea->settings = (tmp_areasettings_t *) GetClearedMemory(sizeof(tmp_areasettings_t));
		tmparea->settings->contents = tmparea->contents;
		tmparea->settings->modelnum = tmparea->modelnum;
		flags = 0;
		for (face = tmparea->tmpfaces; face; face = face->next[side])
		{
			side = face->frontarea != tmparea;
			flags |= face->faceflags;
		} //end for
		tmparea->settings->areaflags = 0;
		if (flags & FACE_GROUND)
		{
			tmparea->settings->areaflags |= AREA_GROUNDED;
			numgrounded++;
		} //end if
		if (flags & FACE_LADDER)
		{
			tmparea->settings->areaflags |= AREA_LADDER;
			numladderareas++;
		} //end if
		if (tmparea->contents & (AREACONTENTS_WATER |
											AREACONTENTS_SLIME |
											AREACONTENTS_LAVA))
		{
			tmparea->settings->areaflags |= AREA_LIQUID;
			numliquidareas++;
		} //end if
		//presence type of the area
		tmparea->settings->presencetype = tmparea->presencetype;
		//
		qprintf("\r%6d", ++i);
	} //end for
	qprintf("\n");
#ifdef AASINFO
	Log_Print("%6d grounded areas\n", numgrounded);
	Log_Print("%6d ladder areas\n", numladderareas);
	Log_Print("%6d liquid areas\n", numliquidareas);
#endif //AASINFO
} //end of the function AAS_CreateAreaSettings
Esempio n. 9
0
//========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//========================================================================
int BotAllocWeaponState( void ) {
	int i;

	for ( i = 1; i <= MAX_CLIENTS; i++ )
	{
		if ( !botweaponstates[i] ) {
			botweaponstates[i] = GetClearedMemory( sizeof( bot_weaponstate_t ) );
			return i;
		} //end if
	} //end for
	return 0;
} //end of the function BotAllocWeaponState
Esempio n. 10
0
int *WeaponWeightIndex(weightconfig_t *wwc, weaponconfig_t *wc) {
	int *index, i;

	//initialize item weight index
	index = (int *) GetClearedMemory(sizeof(int) * wc->numweapons);

	for (i = 0; i < wc->numweapons; i++)
	{
		index[i] = FindFuzzyWeight(wwc, wc->weaponinfo[i].name);
	}
	return index;
}
Esempio n. 11
0
/*
=======================================================================================================================================
AAS_OptimizeAlloc
=======================================================================================================================================
*/
void AAS_OptimizeAlloc(optimized_t *optimized) {

	optimized->vertexes = (aas_vertex_t *)GetClearedMemory(aasworld.numvertexes * sizeof(aas_vertex_t));
	optimized->numvertexes = 0;
	optimized->edges = (aas_edge_t *)GetClearedMemory(aasworld.numedges * sizeof(aas_edge_t));
	optimized->numedges = 1; // edge zero is a dummy
	optimized->edgeindex = (aas_edgeindex_t *)GetClearedMemory(aasworld.edgeindexsize * sizeof(aas_edgeindex_t));
	optimized->edgeindexsize = 0;
	optimized->faces = (aas_face_t *)GetClearedMemory(aasworld.numfaces * sizeof(aas_face_t));
	optimized->numfaces = 1; // face zero is a dummy
	optimized->faceindex = (aas_faceindex_t *)GetClearedMemory(aasworld.faceindexsize * sizeof(aas_faceindex_t));
	optimized->faceindexsize = 0;
	optimized->areas = (aas_area_t *)GetClearedMemory(aasworld.numareas * sizeof(aas_area_t));
	optimized->numareas = aasworld.numareas;
	optimized->vertexoptimizeindex = (int *)GetClearedMemory(aasworld.numvertexes * sizeof(int));
	optimized->edgeoptimizeindex = (int *)GetClearedMemory(aasworld.numedges * sizeof(int));
	optimized->faceoptimizeindex = (int *)GetClearedMemory(aasworld.numfaces * sizeof(int));
}
Esempio n. 12
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
tmp_face_t *AAS_AllocTmpFace(void)
{
	tmp_face_t *tmpface;

	tmpface = (tmp_face_t *) GetClearedMemory(sizeof(tmp_face_t));
	tmpface->num = tmpaasworld.facenum++;
	tmpface->l_prev = NULL;
	tmpface->l_next = tmpaasworld.faces;
	if (tmpaasworld.faces) tmpaasworld.faces->l_prev = tmpface;
	tmpaasworld.faces = tmpface;
	tmpaasworld.numfaces++;
	return tmpface;
} //end of the function AAS_AllocTmpFace
Esempio n. 13
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
tmp_area_t *AAS_AllocTmpArea(void)
{
	tmp_area_t *tmparea;

	tmparea = (tmp_area_t *) GetClearedMemory(sizeof(tmp_area_t));
	tmparea->areanum = tmpaasworld.areanum++;
	tmparea->l_prev = NULL;
	tmparea->l_next = tmpaasworld.areas;
	if (tmpaasworld.areas) tmpaasworld.areas->l_prev = tmparea;
	tmpaasworld.areas = tmparea;
	tmpaasworld.numareas++;
	return tmparea;
} //end of the function AAS_AllocTmpArea
Esempio n. 14
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
tmp_node_t *AAS_AllocTmpNode( void ) {
	tmp_nodebuf_t *nodebuf;

	if ( !tmpaasworld.nodebuffer ||
		 tmpaasworld.nodebuffer->numnodes >= NODEBUF_SIZE ) {
		nodebuf = (tmp_nodebuf_t *) GetClearedMemory( sizeof( tmp_nodebuf_t ) );
		nodebuf->next = tmpaasworld.nodebuffer;
		nodebuf->numnodes = 0;
		tmpaasworld.nodebuffer = nodebuf;
	} //end if
	tmpaasworld.numnodes++;
	return &tmpaasworld.nodebuffer->nodes[tmpaasworld.nodebuffer->numnodes++];
} //end of the function AAS_AllocTmpNode
Esempio n. 15
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
int BotAllocGoalState( int client ) {
	int i;

	for ( i = 1; i <= MAX_CLIENTS; i++ )
	{
		if ( !botgoalstates[i] ) {
			botgoalstates[i] = GetClearedMemory( sizeof( bot_goalstate_t ) );
			botgoalstates[i]->client = client;
			return i;
		} //end if
	} //end for
	return 0;
} //end of the function BotAllocGoalState
Esempio n. 16
0
//===========================================================================
// index to find the weight function of an iteminfo
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
int *ItemWeightIndex( weightconfig_t *iwc, itemconfig_t *ic ) {
	int *index, i;

	//initialize item weight index
	index = (int *) GetClearedMemory( sizeof( int ) * ic->numiteminfo );

	for ( i = 0; i < ic->numiteminfo; i++ )
	{
		index[i] = FindFuzzyWeight( iwc, ic->iteminfo[i].classname );
		if ( index[i] < 0 ) {
			Log_Write( "item info %d \"%s\" has no fuzzy weight\r\n", i, ic->iteminfo[i].classname );
		} //end if
	} //end for
	return index;
} //end of the function ItemWeightIndex
Esempio n. 17
0
script_t *LoadScriptFile(const char *filename)
{
	fileHandle_t fp;
	char         pathname[MAX_QPATH];
	int          length;
	void         *buffer;
	script_t     *script;

	if (strlen(basefolder))
	{
		Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename);
	}
	else
	{
		Com_sprintf(pathname, sizeof(pathname), "%s", filename);
	}
	length = botimport.FS_FOpenFile(pathname, &fp, FS_READ);
	if (!fp)
	{
		return NULL;
	}

	buffer = GetClearedMemory(sizeof(script_t) + length + 1);
	script = (script_t *) buffer;
	memset(script, 0, sizeof(script_t));
	strcpy(script->filename, filename);
	script->buffer         = (char *) buffer + sizeof(script_t);
	script->buffer[length] = 0;
	script->length         = length;
	//pointer in script buffer
	script->script_p = script->buffer;
	//pointer in script buffer before reading token
	script->lastscript_p = script->buffer;
	//pointer to end of script buffer
	script->end_p = &script->buffer[length];
	//set if there's a token available in script->token
	script->tokenavailable = 0;

	script->line     = 1;
	script->lastline = 1;

	SetScriptPunctuations(script, NULL);

	botimport.FS_Read(script->buffer, length, fp);
	botimport.FS_FCloseFile(fp);

	return script;
} //end of the function LoadScriptFile
Esempio n. 18
0
void Q3_CreatePlanarSurfacePlanes(void)
{
    int i;
    dsurface_t *surface;

    Log_Print("creating planar surface planes...\n");
    q3_surfaceplanes = (dplane_t *) GetClearedMemory(q3_numDrawSurfaces * sizeof(dplane_t));

    for (i = 0; i < q3_numDrawSurfaces; i++)
    {
        surface = &drawSurfaces[i];
        if (surface->surfaceType != MST_PLANAR) continue;
        Q3_SurfacePlane(surface, q3_surfaceplanes[i].normal, &q3_surfaceplanes[i].dist);
        //Log_Print("normal = %f %f %f, dist = %f\n", q3_surfaceplanes[i].normal[0],
        //											q3_surfaceplanes[i].normal[1],
        //											q3_surfaceplanes[i].normal[2], q3_surfaceplanes[i].dist);
    } //end for
} //end of the function Q3_CreatePlanarSurfacePlanes
Esempio n. 19
0
//===========================================================================
//
// Parameter:               -
// Returns:                 -
// Changes Globals:     -
//===========================================================================
void AAS_RemoveNonReachabilityAlloc(optimized_t * optimized)
{
	optimized->areas = (aas_area_t *) GetClearedMemory((*aasworld).numareas * sizeof(aas_area_t));
	//
	optimized->areasettings = (aas_areasettings_t *) GetClearedMemory((*aasworld).numareas * sizeof(aas_areasettings_t));
	//
	optimized->reachability = (aas_reachability_t *) GetClearedMemory((*aasworld).reachabilitysize * sizeof(aas_reachability_t));
	optimized->reachabilitysize = (*aasworld).reachabilitysize;
/*	//
	optimized->nodes = (aas_node_t *) GetClearedMemory((*aasworld).numnodes * sizeof(aas_node_t));
	optimized->numnodes = (*aasworld).numnodes;
	//
	optimized->portals = (aas_portals_t *) GetClearedMemory((*aasworld).numportals * sizeof(aas_portal_t));
	optimized->numportals = (*aasworld).numportals;
	//
	optimized->clusters = (aas_cluster_t *) GetClearedMemory((*aasworld).numclusters * sizeof(aas_cluster_t));
						optimized->numclusters = (*aasworld).numclusters;
*///
	optimized->areakeep = (int *)GetClearedMemory((*aasworld).numareas * sizeof(int));
	optimized->arearemap = (int *)GetClearedMemory((*aasworld).numareas * sizeof(int));
	optimized->removedareas = (int *)GetClearedMemory((*aasworld).numareas * sizeof(int));
	optimized->reachabilityremap = (int *)GetClearedMemory((*aasworld).reachabilitysize * sizeof(int));
}								//end of the function AAS_OptimizeAlloc
Esempio n. 20
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
quakefile_t *FindQuakeFilesWithPakFilter( char *pakfilter, char *filter ) {
#if defined( WIN32 ) | defined( _WIN32 )
	WIN32_FIND_DATA filedata;
	HWND handle;
	struct _stat statbuf;
#else
	glob_t globbuf;
	struct stat statbuf;
	int j;
#endif
	quakefile_t *qfiles, *lastqf, *qf;
	char pakfile[_MAX_PATH], filename[_MAX_PATH], *str;
	int done;

	qfiles = NULL;
	lastqf = NULL;
	if ( pakfilter && strlen( pakfilter ) ) {
#if defined( WIN32 ) | defined( _WIN32 )
		handle = FindFirstFile( pakfilter, &filedata );
		done = ( handle == INVALID_HANDLE_VALUE );
		while ( !done )
		{
			_splitpath( pakfilter, pakfile, NULL, NULL, NULL );
			_splitpath( pakfilter, NULL, &pakfile[strlen( pakfile )], NULL, NULL );
			AppendPathSeperator( pakfile, _MAX_PATH );
			strcat( pakfile, filedata.cFileName );
			_stat( pakfile, &statbuf );
#else
		glob( pakfilter, 0, NULL, &globbuf );
		for ( j = 0; j < globbuf.gl_pathc; j++ )
		{
			strcpy( pakfile, globbuf.gl_pathv[j] );
			stat( pakfile, &statbuf );
#endif
			//if the file with .pak or .pk3 is a folder
			if ( statbuf.st_mode & S_IFDIR ) {
				strcpy( filename, pakfilter );
				AppendPathSeperator( filename, _MAX_PATH );
				strcat( filename, filter );
				qf = FindQuakeFilesWithPakFilter( NULL, filename );
				if ( lastqf ) {
					lastqf->next = qf;
				} else { qfiles = qf;}
				lastqf = qf;
				while ( lastqf->next ) lastqf = lastqf->next;
			} //end if
			else
			{
#if defined( WIN32 ) | defined( _WIN32 )
				str = StringContains( pakfile, ".pk3", false );
#else
				str = StringContains( pakfile, ".pk3", true );
#endif
				if ( str && str == pakfile + strlen( pakfile ) - strlen( ".pk3" ) ) {
					qf = FindQuakeFilesInZip( pakfile, filter );
				} //end if
				else
				{
					qf = FindQuakeFilesInPak( pakfile, filter );
				} //end else
				  //
				if ( qf ) {
					if ( lastqf ) {
						lastqf->next = qf;
					} else { qfiles = qf;}
					lastqf = qf;
					while ( lastqf->next ) lastqf = lastqf->next;
				} //end if
			} //end else
			  //
#if defined( WIN32 ) | defined( _WIN32 )
			//find the next file
			done = !FindNextFile( handle, &filedata );
		} //end while
#else
		} //end for
		globfree( &globbuf );
#endif
	} //end if
	else
	{
#if defined( WIN32 ) | defined( _WIN32 )
		handle = FindFirstFile( filter, &filedata );
		done = ( handle == INVALID_HANDLE_VALUE );
		while ( !done )
		{
			_splitpath( filter, filename, NULL, NULL, NULL );
			_splitpath( filter, NULL, &filename[strlen( filename )], NULL, NULL );
			AppendPathSeperator( filename, _MAX_PATH );
			strcat( filename, filedata.cFileName );
#else
		glob( filter, 0, NULL, &globbuf );
		for ( j = 0; j < globbuf.gl_pathc; j++ )
		{
			strcpy( filename, globbuf.gl_pathv[j] );
#endif
			//
			qf = GetClearedMemory( sizeof( quakefile_t ) );
			if ( !qf ) {
				Error( "out of memory" );
			}
			memset( qf, 0, sizeof( quakefile_t ) );
			strcpy( qf->pakfile, "" );
			strcpy( qf->filename, filename );
			strcpy( qf->origname, filename );
			qf->offset = 0;
			qf->length = 0;
			qf->type = QuakeFileType( filename );
			//add the file ot the list
			qf->next = NULL;
			if ( lastqf ) {
				lastqf->next = qf;
			} else { qfiles = qf;}
			lastqf = qf;
#if defined( WIN32 ) | defined( _WIN32 )
			//find the next file
			done = !FindNextFile( handle, &filedata );
		} //end while
#else
		} //end for
		globfree( &globbuf );
#endif
	} //end else
	return qfiles;
} //end of the function FindQuakeFilesWithPakFilter
Esempio n. 21
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AAS_AllocMaxAAS( void ) {
	int i;

	AAS_InitMaxAAS();
	//bounding boxes
	( *aasworld ).numbboxes = 0;
	( *aasworld ).bboxes = (aas_bbox_t *) GetClearedMemory( max_aas.max_bboxes * sizeof( aas_bbox_t ) );
	allocatedaasmem += max_aas.max_bboxes * sizeof( aas_bbox_t );
	//vertexes
	( *aasworld ).numvertexes = 0;
	( *aasworld ).vertexes = (aas_vertex_t *) GetClearedMemory( max_aas.max_vertexes * sizeof( aas_vertex_t ) );
	allocatedaasmem += max_aas.max_vertexes * sizeof( aas_vertex_t );
	//planes
	( *aasworld ).numplanes = 0;
	( *aasworld ).planes = (aas_plane_t *) GetClearedMemory( max_aas.max_planes * sizeof( aas_plane_t ) );
	allocatedaasmem += max_aas.max_planes * sizeof( aas_plane_t );
	//edges
	( *aasworld ).numedges = 0;
	( *aasworld ).edges = (aas_edge_t *) GetClearedMemory( max_aas.max_edges * sizeof( aas_edge_t ) );
	allocatedaasmem += max_aas.max_edges * sizeof( aas_edge_t );
	//edge index
	( *aasworld ).edgeindexsize = 0;
	( *aasworld ).edgeindex = (aas_edgeindex_t *) GetClearedMemory( max_aas.max_edgeindexsize * sizeof( aas_edgeindex_t ) );
	allocatedaasmem += max_aas.max_edgeindexsize * sizeof( aas_edgeindex_t );
	//faces
	( *aasworld ).numfaces = 0;
	( *aasworld ).faces = (aas_face_t *) GetClearedMemory( max_aas.max_faces * sizeof( aas_face_t ) );
	allocatedaasmem += max_aas.max_faces * sizeof( aas_face_t );
	//face index
	( *aasworld ).faceindexsize = 0;
	( *aasworld ).faceindex = (aas_faceindex_t *) GetClearedMemory( max_aas.max_faceindexsize * sizeof( aas_faceindex_t ) );
	allocatedaasmem += max_aas.max_faceindexsize * sizeof( aas_faceindex_t );
	//convex areas
	( *aasworld ).numareas = 0;
	( *aasworld ).areas = (aas_area_t *) GetClearedMemory( max_aas.max_areas * sizeof( aas_area_t ) );
	allocatedaasmem += max_aas.max_areas * sizeof( aas_area_t );
	//convex area settings
	( *aasworld ).numareasettings = 0;
	( *aasworld ).areasettings = (aas_areasettings_t *) GetClearedMemory( max_aas.max_areasettings * sizeof( aas_areasettings_t ) );
	allocatedaasmem += max_aas.max_areasettings * sizeof( aas_areasettings_t );
	//reachablity list
	( *aasworld ).reachabilitysize = 0;
	( *aasworld ).reachability = (aas_reachability_t *) GetClearedMemory( max_aas.max_reachabilitysize * sizeof( aas_reachability_t ) );
	allocatedaasmem += max_aas.max_reachabilitysize * sizeof( aas_reachability_t );
	//nodes of the bsp tree
	( *aasworld ).numnodes = 0;
	( *aasworld ).nodes = (aas_node_t *) GetClearedMemory( max_aas.max_nodes * sizeof( aas_node_t ) );
	allocatedaasmem += max_aas.max_nodes * sizeof( aas_node_t );
	//cluster portals
	( *aasworld ).numportals = 0;
	( *aasworld ).portals = (aas_portal_t *) GetClearedMemory( max_aas.max_portals * sizeof( aas_portal_t ) );
	allocatedaasmem += max_aas.max_portals * sizeof( aas_portal_t );
	//cluster portal index
	( *aasworld ).portalindexsize = 0;
	( *aasworld ).portalindex = (aas_portalindex_t *) GetClearedMemory( max_aas.max_portalindexsize * sizeof( aas_portalindex_t ) );
	allocatedaasmem += max_aas.max_portalindexsize * sizeof( aas_portalindex_t );
	//cluster
	( *aasworld ).numclusters = 0;
	( *aasworld ).clusters = (aas_cluster_t *) GetClearedMemory( max_aas.max_clusters * sizeof( aas_cluster_t ) );
	allocatedaasmem += max_aas.max_clusters * sizeof( aas_cluster_t );
	//
	Log_Print( "allocated " );
	PrintMemorySize( allocatedaasmem );
	Log_Print( " of AAS memory\n" );
	//reset the has stuff
	aas_vertexchain = (int *) GetClearedMemory( max_aas.max_vertexes * sizeof( int ) );
	aas_planechain = (int *) GetClearedMemory( max_aas.max_planes * sizeof( int ) );
	aas_edgechain = (int *) GetClearedMemory( max_aas.max_edges * sizeof( int ) );
	//
	for ( i = 0; i < max_aas.max_vertexes; i++ ) aas_vertexchain[i] = -1;
	for ( i = 0; i < VERTEX_HASH_SIZE * VERTEX_HASH_SIZE; i++ ) aas_hashverts[i] = -1;
	//
	for ( i = 0; i < max_aas.max_planes; i++ ) aas_planechain[i] = -1;
	for ( i = 0; i < PLANE_HASH_SIZE; i++ ) aas_hashplanes[i] = -1;
	//
	for ( i = 0; i < max_aas.max_edges; i++ ) aas_edgechain[i] = -1;
	for ( i = 0; i < EDGE_HASH_SIZE; i++ ) aas_hashedges[i] = -1;
} //end of the function AAS_AllocMaxAAS
Esempio n. 22
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AAS_InitClustering(void)
{
	int i, removedPortalAreas;
	int n, total, numreachabilityareas;

	if (!aasworld.loaded) return;
	//if there are clusters
	if (aasworld.numclusters >= 1)
	{
#ifndef BSPC
		//if clustering isn't forced
		if (!((int)LibVarGetValue("forceclustering")) &&
			!((int)LibVarGetValue("forcereachability"))) return;
#endif
	} //end if
	//set all view portals as cluster portals in case we re-calculate the reachabilities and clusters (with -reach)
	AAS_SetViewPortalsAsClusterPortals();
	//count the number of forced cluster portals
	AAS_CountForcedClusterPortals();
	//remove all area cluster marks
	AAS_RemoveClusterAreas();
	//find possible cluster portals
	AAS_FindPossiblePortals();
	//craete portals to for the bot view
	AAS_CreateViewPortals();
	//remove all portals that are not closing a cluster
	//AAS_RemoveNotClusterClosingPortals();
	//initialize portal memory
	if (aasworld.portals) FreeMemory(aasworld.portals);
	aasworld.portals = (aas_portal_t *) GetClearedMemory(AAS_MAX_PORTALS * sizeof(aas_portal_t));
	//initialize portal index memory
	if (aasworld.portalindex) FreeMemory(aasworld.portalindex);
	aasworld.portalindex = (aas_portalindex_t *) GetClearedMemory(AAS_MAX_PORTALINDEXSIZE * sizeof(aas_portalindex_t));
	//initialize cluster memory
	if (aasworld.clusters) FreeMemory(aasworld.clusters);
	aasworld.clusters = (aas_cluster_t *) GetClearedMemory(AAS_MAX_CLUSTERS * sizeof(aas_cluster_t));
	//
	removedPortalAreas = 0;
	botimport.Print(PRT_MESSAGE, "\r%6d removed portal areas", removedPortalAreas);
	while(1)
	{
		botimport.Print(PRT_MESSAGE, "\r%6d", removedPortalAreas);
		//initialize the number of portals and clusters
		aasworld.numportals = 1;		//portal 0 is a dummy
		aasworld.portalindexsize = 0;
		aasworld.numclusters = 1;		//cluster 0 is a dummy
		//create the portals from the portal areas
		AAS_CreatePortals();
		//
		removedPortalAreas++;
		//find the clusters
		if (!AAS_FindClusters())
			continue;
		//test the portals
		if (!AAS_TestPortals())
			continue;
		//
		break;
	} //end while
	botimport.Print(PRT_MESSAGE, "\n");
	//the AAS file should be saved
	aasworld.savefile = qtrue;
	//write the portal areas to the log file
	for (i = 1; i < aasworld.numportals; i++)
	{
		Log_Write("portal %d: area %d\r\n", i, aasworld.portals[i].areanum);
	} //end for
	// report cluster info
	botimport.Print(PRT_MESSAGE, "%6d portals created\n", aasworld.numportals);
	botimport.Print(PRT_MESSAGE, "%6d clusters created\n", aasworld.numclusters);
	for (i = 1; i < aasworld.numclusters; i++)
	{
		botimport.Print(PRT_MESSAGE, "cluster %d has %d reachability areas\n", i,
				aasworld.clusters[i].numreachabilityareas);
	} //end for
	// report AAS file efficiency
	numreachabilityareas = 0;
	total = 0;
	for (i = 0; i < aasworld.numclusters; i++) {
		n = aasworld.clusters[i].numreachabilityareas;
		numreachabilityareas += n;
		total += n * n;
	}
	total += numreachabilityareas * aasworld.numportals;
	//
	botimport.Print(PRT_MESSAGE, "%6i total reachability areas\n", numreachabilityareas);
	botimport.Print(PRT_MESSAGE, "%6i AAS memory/CPU usage (the lower the better)\n", total * 3);
} //end of the function AAS_InitClustering
Esempio n. 23
0
void Q2_AllocMaxBSP(void)
{
	//models
	nummodels = 0;
	dmodels = (dmodel_t *) GetClearedMemory(MAX_MAP_MODELS * sizeof(dmodel_t));
	allocatedbspmem += MAX_MAP_MODELS * sizeof(dmodel_t);
	//vis data
	visdatasize = 0;
	dvisdata = (byte *) GetClearedMemory(MAX_MAP_VISIBILITY * sizeof(byte));
	dvis = (dvis_t *) dvisdata;
	allocatedbspmem += MAX_MAP_VISIBILITY * sizeof(byte);
	//light data
	lightdatasize = 0;
	dlightdata = (byte *) GetClearedMemory(MAX_MAP_LIGHTING * sizeof(byte));
	allocatedbspmem += MAX_MAP_LIGHTING * sizeof(byte);
	//entity data
	entdatasize = 0;
	dentdata = (char *) GetClearedMemory(MAX_MAP_ENTSTRING * sizeof(char));
	allocatedbspmem += MAX_MAP_ENTSTRING * sizeof(char);
	//leafs
	numleafs = 0;
	dleafs = (dleaf_t *) GetClearedMemory(MAX_MAP_LEAFS * sizeof(dleaf_t));
	allocatedbspmem += MAX_MAP_LEAFS * sizeof(dleaf_t);
	//planes
	numplanes = 0;
	dplanes = (dplane_t *) GetClearedMemory(MAX_MAP_PLANES * sizeof(dplane_t));
	allocatedbspmem += MAX_MAP_PLANES * sizeof(dplane_t);
	//vertexes
	numvertexes = 0;
	dvertexes = (dvertex_t *) GetClearedMemory(MAX_MAP_VERTS * sizeof(dvertex_t));
	allocatedbspmem += MAX_MAP_VERTS * sizeof(dvertex_t);
	//nodes
	numnodes = 0;
	dnodes = (dnode_t *) GetClearedMemory(MAX_MAP_NODES * sizeof(dnode_t));
	allocatedbspmem += MAX_MAP_NODES * sizeof(dnode_t);
	/*
	//texture info
	numtexinfo = 0;
	texinfo = (texinfo_t *) GetClearedMemory(MAX_MAP_TEXINFO * sizeof(texinfo_t));
	allocatedbspmem += MAX_MAP_TEXINFO * sizeof(texinfo_t);
	//*/
	//faces
	numfaces = 0;
	dfaces = (dface_t *) GetClearedMemory(MAX_MAP_FACES * sizeof(dface_t));
	allocatedbspmem += MAX_MAP_FACES * sizeof(dface_t);
	//edges
	numedges = 0;
	dedges = (dedge_t *) GetClearedMemory(MAX_MAP_EDGES * sizeof(dedge_t));
	allocatedbspmem += MAX_MAP_EDGES * sizeof(dedge_t);
	//leaf faces
	numleaffaces = 0;
	dleaffaces = (unsigned short *) GetClearedMemory(MAX_MAP_LEAFFACES * sizeof(unsigned short));
	allocatedbspmem += MAX_MAP_LEAFFACES * sizeof(unsigned short);
	//leaf brushes
	numleafbrushes = 0;
	dleafbrushes = (unsigned short *) GetClearedMemory(MAX_MAP_LEAFBRUSHES * sizeof(unsigned short));
	allocatedbspmem += MAX_MAP_LEAFBRUSHES * sizeof(unsigned short);
	//surface edges
	numsurfedges = 0;
	dsurfedges = (int *) GetClearedMemory(MAX_MAP_SURFEDGES * sizeof(int));
	allocatedbspmem += MAX_MAP_SURFEDGES * sizeof(int);
	//brushes
	numbrushes = 0;
	dbrushes = (dbrush_t *) GetClearedMemory(MAX_MAP_BRUSHES * sizeof(dbrush_t));
	allocatedbspmem += MAX_MAP_BRUSHES * sizeof(dbrush_t);
	//brushsides
	numbrushsides = 0;
	dbrushsides = (dbrushside_t *) GetClearedMemory(MAX_MAP_BRUSHSIDES * sizeof(dbrushside_t));
	allocatedbspmem += MAX_MAP_BRUSHSIDES * sizeof(dbrushside_t);
	//areas
	numareas = 0;
	dareas = (darea_t *) GetClearedMemory(MAX_MAP_AREAS * sizeof(darea_t));
	allocatedbspmem += MAX_MAP_AREAS * sizeof(darea_t);
	//area portals
	numareaportals = 0;
	dareaportals = (dareaportal_t *) GetClearedMemory(MAX_MAP_AREAPORTALS * sizeof(dareaportal_t));
	allocatedbspmem += MAX_MAP_AREAPORTALS * sizeof(dareaportal_t);
	//print allocated memory
	Log_Print("allocated ");
	PrintMemorySize(allocatedbspmem);
	Log_Print(" of BSP memory\n");
} //end of the function Q2_AllocMaxBSP
Esempio n. 24
0
//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
bot_character_t *BotLoadCharacterFromFile( char *charfile, int skill )
{
    int             indent, index, foundcharacter;
    bot_character_t *ch;
    source_t        *source;
    token_t         token;

    foundcharacter = qfalse;
    //a bot character is parsed in two phases
    PS_SetBaseFolder( "botfiles" );
    source = LoadSourceFile( charfile );
    PS_SetBaseFolder( "" );

    if ( !source )
    {
        botimport.Print( PRT_ERROR, "counldn't load %s\n", charfile );
        return NULL;
    } //end if

    ch = ( bot_character_t * ) GetClearedMemory( sizeof( bot_character_t ) + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) );
    strcpy( ch->filename, charfile );

    while ( PC_ReadToken( source, &token ) )
    {
        if ( !strcmp( token.string, "skill" ) )
        {
            if ( !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) )
            {
                FreeSource( source );
                BotFreeCharacterStrings( ch );
                FreeMemory( ch );
                return NULL;
            } //end if

            if ( !PC_ExpectTokenString( source, "{" ) )
            {
                FreeSource( source );
                BotFreeCharacterStrings( ch );
                FreeMemory( ch );
                return NULL;
            } //end if

            //if it's the correct skill
            if ( skill < 0 || token.intvalue == skill )
            {
                foundcharacter = qtrue;
                ch->skill = token.intvalue;

                while ( PC_ExpectAnyToken( source, &token ) )
                {
                    if ( !strcmp( token.string, "}" ) )
                    {
                        break;
                    }

                    if ( token.type != TT_NUMBER || !( token.subtype & TT_INTEGER ) )
                    {
                        SourceError( source, "expected integer index, found %s\n", token.string );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    index = token.intvalue;

                    if ( index < 0 || index > MAX_CHARACTERISTICS )
                    {
                        SourceError( source, "characteristic index out of range [0, %d]\n", MAX_CHARACTERISTICS );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( ch->c[ index ].type )
                    {
                        SourceError( source, "characteristic %d already initialized\n", index );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( !PC_ExpectAnyToken( source, &token ) )
                    {
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( token.type == TT_NUMBER )
                    {
                        if ( token.subtype & TT_FLOAT )
                        {
                            ch->c[ index ].value._float = token.floatvalue;
                            ch->c[ index ].type = CT_FLOAT;
                        } //end if
                        else
                        {
                            ch->c[ index ].value.integer = token.intvalue;
                            ch->c[ index ].type = CT_INTEGER;
                        } //end else
                    } //end if
                    else if ( token.type == TT_STRING )
                    {
                        StripDoubleQuotes( token.string );
                        ch->c[ index ].value.string = GetMemory( strlen( token.string ) + 1 );
                        strcpy( ch->c[ index ].value.string, token.string );
                        ch->c[ index ].type = CT_STRING;
                    } //end else if
                    else
                    {
                        SourceError( source, "expected integer, float or string, found %s\n", token.string );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end else
                } //end if

                break;
            } //end if
            else
            {
                indent = 1;

                while ( indent )
                {
                    if ( !PC_ExpectAnyToken( source, &token ) )
                    {
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( !strcmp( token.string, "{" ) )
                    {
                        indent++;
                    }
                    else if ( !strcmp( token.string, "}" ) )
                    {
                        indent--;
                    }
                } //end while
            } //end else
        } //end if
        else
        {
            SourceError( source, "unknown definition %s\n", token.string );
            FreeSource( source );
            BotFreeCharacterStrings( ch );
            FreeMemory( ch );
            return NULL;
        } //end else
    } //end while

    FreeSource( source );

    //
    if ( !foundcharacter )
    {
        BotFreeCharacterStrings( ch );
        FreeMemory( ch );
        return NULL;
    } //end if

    return ch;
} //end of the function BotLoadCharacterFromFile
Esempio n. 25
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
quakefile_t *FindQuakeFilesInPak( char *pakfile, char *filter ) {
	FILE *fp;
	dpackheader_t packheader;
	dsinpackfile_t *packfiles;
	dpackfile_t *idpackfiles;
	quakefile_t *qfiles, *lastqf, *qf;
	int numpackdirs, i;

	qfiles = NULL;
	lastqf = NULL;
	//open the pak file
	fp = fopen( pakfile, "rb" );
	if ( !fp ) {
		Warning( "can't open pak file %s", pakfile );
		return NULL;
	} //end if
	  //read pak header, check for valid pak id and seek to the dir entries
	if ( ( fread( &packheader, 1, sizeof( dpackheader_t ), fp ) != sizeof( dpackheader_t ) )
		 || ( packheader.ident != IDPAKHEADER && packheader.ident != SINPAKHEADER )
		 ||  ( fseek( fp, LittleLong( packheader.dirofs ), SEEK_SET ) )
		 ) {
		fclose( fp );
		Warning( "invalid pak file %s", pakfile );
		return NULL;
	} //end if
	  //if it is a pak file from id software
	if ( packheader.ident == IDPAKHEADER ) {
		//number of dir entries in the pak file
		numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dpackfile_t );
		idpackfiles = (dpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dpackfile_t ) );
		if ( !idpackfiles ) {
			Error( "out of memory" );
		}
		//read the dir entry
		if ( fread( idpackfiles, sizeof( dpackfile_t ), numpackdirs, fp ) != numpackdirs ) {
			fclose( fp );
			FreeMemory( idpackfiles );
			Warning( "can't read the Quake pak file dir entries from %s", pakfile );
			return NULL;
		} //end if
		fclose( fp );
		//convert to sin pack files
		packfiles = (dsinpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dsinpackfile_t ) );
		if ( !packfiles ) {
			Error( "out of memory" );
		}
		for ( i = 0; i < numpackdirs; i++ )
		{
			strcpy( packfiles[i].name, idpackfiles[i].name );
			packfiles[i].filepos = LittleLong( idpackfiles[i].filepos );
			packfiles[i].filelen = LittleLong( idpackfiles[i].filelen );
		} //end for
		FreeMemory( idpackfiles );
	} //end if
	else //its a Sin pack file
	{
		//number of dir entries in the pak file
		numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dsinpackfile_t );
		packfiles = (dsinpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dsinpackfile_t ) );
		if ( !packfiles ) {
			Error( "out of memory" );
		}
		//read the dir entry
		if ( fread( packfiles, sizeof( dsinpackfile_t ), numpackdirs, fp ) != numpackdirs ) {
			fclose( fp );
			FreeMemory( packfiles );
			Warning( "can't read the Sin pak file dir entries from %s", pakfile );
			return NULL;
		} //end if
		fclose( fp );
		for ( i = 0; i < numpackdirs; i++ )
		{
			packfiles[i].filepos = LittleLong( packfiles[i].filepos );
			packfiles[i].filelen = LittleLong( packfiles[i].filelen );
		} //end for
	} //end else
	  //
	for ( i = 0; i < numpackdirs; i++ )
	{
		ConvertPath( packfiles[i].name );
		if ( FileFilter( filter, packfiles[i].name, false ) ) {
			qf = GetClearedMemory( sizeof( quakefile_t ) );
			if ( !qf ) {
				Error( "out of memory" );
			}
			memset( qf, 0, sizeof( quakefile_t ) );
			strcpy( qf->pakfile, pakfile );
			strcpy( qf->filename, pakfile );
			strcpy( qf->origname, packfiles[i].name );
			qf->zipfile = false;
			qf->offset = packfiles[i].filepos;
			qf->length = packfiles[i].filelen;
			qf->type = QuakeFileType( packfiles[i].name );
			//add the file ot the list
			qf->next = NULL;
			if ( lastqf ) {
				lastqf->next = qf;
			} else { qfiles = qf;}
			lastqf = qf;
		} //end if
	} //end for
	FreeMemory( packfiles );
	return qfiles;
} //end of the function FindQuakeFilesInPak
Esempio n. 26
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
fuzzyseperator_t *ReadFuzzySeperators_r( source_t *source ) {
	int newindent, index, def, founddefault;
	token_t token;
	fuzzyseperator_t *fs, *lastfs, *firstfs;

	founddefault = qfalse;
	firstfs = NULL;
	lastfs = NULL;
	if ( !PC_ExpectTokenString( source, "(" ) ) {
		return NULL;
	}
	if ( !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) {
		return NULL;
	}
	index = token.intvalue;
	if ( !PC_ExpectTokenString( source, ")" ) ) {
		return NULL;
	}
	if ( !PC_ExpectTokenString( source, "{" ) ) {
		return NULL;
	}
	if ( !PC_ExpectAnyToken( source, &token ) ) {
		return NULL;
	}
	do
	{
		def = !strcmp( token.string, "default" );
		if ( def || !strcmp( token.string, "case" ) ) {
			fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) );
			fs->index = index;
			if ( lastfs ) {
				lastfs->next = fs;
			} else { firstfs = fs;}
			lastfs = fs;
			if ( def ) {
				if ( founddefault ) {
					SourceError( source, "switch already has a default" );
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
				fs->value = MAX_INVENTORYVALUE;
				founddefault = qtrue;
			} //end if
			else
			{
				if ( !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) {
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
				fs->value = token.intvalue;
			} //end else
			if ( !PC_ExpectTokenString( source, ":" ) || !PC_ExpectAnyToken( source, &token ) ) {
				FreeFuzzySeperators_r( firstfs );
				return NULL;
			} //end if
			newindent = qfalse;
			if ( !strcmp( token.string, "{" ) ) {
				newindent = qtrue;
				if ( !PC_ExpectAnyToken( source, &token ) ) {
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
			} //end if
			if ( !strcmp( token.string, "return" ) ) {
				if ( !ReadFuzzyWeight( source, fs ) ) {
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
			} //end if
			else if ( !strcmp( token.string, "switch" ) ) {
				fs->child = ReadFuzzySeperators_r( source );
				if ( !fs->child ) {
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
			} //end else if
			else
			{
				SourceError( source, "invalid name %s", token.string );
				return NULL;
			} //end else
			if ( newindent ) {
				if ( !PC_ExpectTokenString( source, "}" ) ) {
					FreeFuzzySeperators_r( firstfs );
					return NULL;
				} //end if
			} //end if
		} //end if
		else
		{
			FreeFuzzySeperators_r( firstfs );
			SourceError( source, "invalid name %s", token.string );
			return NULL;
		} //end else
		if ( !PC_ExpectAnyToken( source, &token ) ) {
			FreeFuzzySeperators_r( firstfs );
			return NULL;
		} //end if
	} while ( strcmp( token.string, "}" ) );
	//
	if ( !founddefault ) {
		SourceWarning( source, "switch without default" );
		fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) );
		fs->index = index;
		fs->value = MAX_INVENTORYVALUE;
		fs->weight = 0;
		fs->next = NULL;
		fs->child = NULL;
		if ( lastfs ) {
			lastfs->next = fs;
		} else { firstfs = fs;}
	} //end if
	  //
	return firstfs;
} //end of the function ReadFuzzySeperators_r
Esempio n. 27
0
void Sin_AllocMaxBSP( void ) {
	//models
	sin_nummodels = 0;
	sin_dmodels = (sin_dmodel_t *) GetClearedMemory( SIN_MAX_MAP_MODELS * sizeof( sin_dmodel_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_MODELS * sizeof( sin_dmodel_t );
	//vis data
	sin_visdatasize = 0;
	sin_dvisdata = (byte *) GetClearedMemory( SIN_MAX_MAP_VISIBILITY * sizeof( byte ) );
	sin_dvis = (sin_dvis_t *) sin_dvisdata;
	sin_allocatedbspmem += SIN_MAX_MAP_VISIBILITY * sizeof( byte );
	//light data
	sin_lightdatasize = 0;
	sin_dlightdata = (byte *) GetClearedMemory( SIN_MAX_MAP_LIGHTING * sizeof( byte ) );
	sin_allocatedbspmem += SIN_MAX_MAP_LIGHTING * sizeof( byte );
	//entity data
	sin_entdatasize = 0;
	sin_dentdata = (char *) GetClearedMemory( SIN_MAX_MAP_ENTSTRING * sizeof( char ) );
	sin_allocatedbspmem += SIN_MAX_MAP_ENTSTRING * sizeof( char );
	//leafs
	sin_numleafs = 0;
	sin_dleafs = (sin_dleaf_t *) GetClearedMemory( SIN_MAX_MAP_LEAFS * sizeof( sin_dleaf_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_LEAFS * sizeof( sin_dleaf_t );
	//planes
	sin_numplanes = 0;
	sin_dplanes = (sin_dplane_t *) GetClearedMemory( SIN_MAX_MAP_PLANES * sizeof( sin_dplane_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_PLANES * sizeof( sin_dplane_t );
	//vertexes
	sin_numvertexes = 0;
	sin_dvertexes = (sin_dvertex_t *) GetClearedMemory( SIN_MAX_MAP_VERTS * sizeof( sin_dvertex_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_VERTS * sizeof( sin_dvertex_t );
	//nodes
	sin_numnodes = 0;
	sin_dnodes = (sin_dnode_t *) GetClearedMemory( SIN_MAX_MAP_NODES * sizeof( sin_dnode_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_NODES * sizeof( sin_dnode_t );
	//texture info
	sin_numtexinfo = 0;
	sin_texinfo = (sin_texinfo_t *) GetClearedMemory( SIN_MAX_MAP_TEXINFO * sizeof( sin_texinfo_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_TEXINFO * sizeof( sin_texinfo_t );
	//faces
	sin_numfaces = 0;
	sin_dfaces = (sin_dface_t *) GetClearedMemory( SIN_MAX_MAP_FACES * sizeof( sin_dface_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_FACES * sizeof( sin_dface_t );
	//edges
	sin_numedges = 0;
	sin_dedges = (sin_dedge_t *) GetClearedMemory( SIN_MAX_MAP_EDGES * sizeof( sin_dedge_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_EDGES * sizeof( sin_dedge_t );
	//leaf faces
	sin_numleaffaces = 0;
	sin_dleaffaces = (unsigned short *) GetClearedMemory( SIN_MAX_MAP_LEAFFACES * sizeof( unsigned short ) );
	sin_allocatedbspmem += SIN_MAX_MAP_LEAFFACES * sizeof( unsigned short );
	//leaf brushes
	sin_numleafbrushes = 0;
	sin_dleafbrushes = (unsigned short *) GetClearedMemory( SIN_MAX_MAP_LEAFBRUSHES * sizeof( unsigned short ) );
	sin_allocatedbspmem += SIN_MAX_MAP_LEAFBRUSHES * sizeof( unsigned short );
	//surface edges
	sin_numsurfedges = 0;
	sin_dsurfedges = (int *) GetClearedMemory( SIN_MAX_MAP_SURFEDGES * sizeof( int ) );
	sin_allocatedbspmem += SIN_MAX_MAP_SURFEDGES * sizeof( int );
	//brushes
	sin_numbrushes = 0;
	sin_dbrushes = (sin_dbrush_t *) GetClearedMemory( SIN_MAX_MAP_BRUSHES * sizeof( sin_dbrush_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_BRUSHES * sizeof( sin_dbrush_t );
	//brushsides
	sin_numbrushsides = 0;
	sin_dbrushsides = (sin_dbrushside_t *) GetClearedMemory( SIN_MAX_MAP_BRUSHSIDES * sizeof( sin_dbrushside_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_BRUSHSIDES * sizeof( sin_dbrushside_t );
	//areas
	sin_numareas = 0;
	sin_dareas = (sin_darea_t *) GetClearedMemory( SIN_MAX_MAP_AREAS * sizeof( sin_darea_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_AREAS * sizeof( sin_darea_t );
	//area portals
	sin_numareaportals = 0;
	sin_dareaportals = (sin_dareaportal_t *) GetClearedMemory( SIN_MAX_MAP_AREAPORTALS * sizeof( sin_dareaportal_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_AREAPORTALS * sizeof( sin_dareaportal_t );
	//light info
	sin_numlightinfo = 0;
	sin_lightinfo = (sin_lightvalue_t *) GetClearedMemory( SIN_MAX_MAP_LIGHTINFO * sizeof( sin_lightvalue_t ) );
	sin_allocatedbspmem += SIN_MAX_MAP_LIGHTINFO * sizeof( sin_lightvalue_t );
	//print allocated memory
	Log_Print( "allocated " );
	PrintMemorySize( sin_allocatedbspmem );
	Log_Print( " of BSP memory\n" );
} //end of the function Sin_AllocMaxBSP
Esempio n. 28
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void *GetClearedHunkMemory(unsigned long size)
{
	return GetClearedMemory(size);
} //end of the function GetClearedHunkMemory
Esempio n. 29
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
weightconfig_t *ReadWeightConfig( char *filename ) {
	int newindent, avail = 0, n;
	token_t token;
	source_t *source;
	fuzzyseperator_t *fs;
	weightconfig_t *config = NULL;
#ifdef DEBUG
	int starttime;

	starttime = Sys_MilliSeconds();
#endif //DEBUG

	if ( !LibVarGetValue( "bot_reloadcharacters" ) ) {
		avail = -1;
		for ( n = 0; n < MAX_WEIGHT_FILES; n++ )
		{
			config = weightFileList[n];
			if ( !config ) {
				if ( avail == -1 ) {
					avail = n;
				} //end if
				continue;
			} //end if
			if ( strcmp( filename, config->filename ) == 0 ) {
				//botimport.Print( PRT_MESSAGE, "retained %s\n", filename );
				return config;
			} //end if
		} //end for

		if ( avail == -1 ) {
			botimport.Print( PRT_ERROR, "weightFileList was full trying to load %s\n", filename );
			return NULL;
		} //end if
	} //end if

	source = LoadSourceFile( filename );
	if ( !source ) {
		botimport.Print( PRT_ERROR, "counldn't load %s\n", filename );
		return NULL;
	} //end if
	  //
	config = (weightconfig_t *) GetClearedMemory( sizeof( weightconfig_t ) );
	config->numweights = 0;
	Q_strncpyz( config->filename, filename, sizeof( config->filename ) );
	//parse the item config file
	while ( PC_ReadToken( source, &token ) )
	{
		if ( !strcmp( token.string, "weight" ) ) {
			if ( config->numweights >= MAX_WEIGHTS ) {
				SourceWarning( source, "too many fuzzy weights" );
				break;
			} //end if
			if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) {
				FreeWeightConfig( config );
				FreeSource( source );
				return NULL;
			} //end if
			StripDoubleQuotes( token.string );
			config->weights[config->numweights].name = (char *) GetClearedMemory( strlen( token.string ) + 1 );
			strcpy( config->weights[config->numweights].name, token.string );
			if ( !PC_ExpectAnyToken( source, &token ) ) {
				FreeWeightConfig( config );
				FreeSource( source );
				return NULL;
			} //end if
			newindent = qfalse;
			if ( !strcmp( token.string, "{" ) ) {
				newindent = qtrue;
				if ( !PC_ExpectAnyToken( source, &token ) ) {
					FreeWeightConfig( config );
					FreeSource( source );
					return NULL;
				} //end if
			} //end if
			if ( !strcmp( token.string, "switch" ) ) {
				fs = ReadFuzzySeperators_r( source );
				if ( !fs ) {
					FreeWeightConfig( config );
					FreeSource( source );
					return NULL;
				} //end if
				config->weights[config->numweights].firstseperator = fs;
			} //end if
			else if ( !strcmp( token.string, "return" ) ) {
				fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) );
				fs->index = 0;
				fs->value = MAX_INVENTORYVALUE;
				fs->next = NULL;
				fs->child = NULL;
				if ( !ReadFuzzyWeight( source, fs ) ) {
					FreeMemory( fs );
					FreeWeightConfig( config );
					FreeSource( source );
					return NULL;
				} //end if
				config->weights[config->numweights].firstseperator = fs;
			} //end else if
			else
			{
				SourceError( source, "invalid name %s", token.string );
				FreeWeightConfig( config );
				FreeSource( source );
				return NULL;
			} //end else
			if ( newindent ) {
				if ( !PC_ExpectTokenString( source, "}" ) ) {
					FreeWeightConfig( config );
					FreeSource( source );
					return NULL;
				} //end if
			} //end if
			config->numweights++;
		} //end if
		else
		{
			SourceError( source, "invalid name %s", token.string );
			FreeWeightConfig( config );
			FreeSource( source );
			return NULL;
		} //end else
	} //end while
	  //free the source at the end of a pass
	FreeSource( source );
	//if the file was located in a pak file
	botimport.Print( PRT_MESSAGE, "loaded %s\n", filename );
#ifdef DEBUG
	if ( botDeveloper ) {
		botimport.Print( PRT_MESSAGE, "weights loaded in %d msec\n", Sys_MilliSeconds() - starttime );
	} //end if
#endif //DEBUG
	   //
	if ( !LibVarGetValue( "bot_reloadcharacters" ) ) {
		weightFileList[avail] = config;
	} //end if
	  //
	return config;
} //end of the function ReadWeightConfig
Esempio n. 30
0
script_t *LoadScriptFile(const char *filename) {
	fileHandle_t h_up, h_patch;
	char pathname[MAX_QPATH], pathpatch[MAX_QPATH];
	unsigned long inhash = 0;
	int inlength, outlength, plength;
	char *inbuffer, *outbuffer, *pbuffer;
	script_t *script;

	if (strlen(basefolder)) {
		Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename);
		Com_sprintf(pathpatch, sizeof(pathpatch), "%s/%s_patch", basefolder, filename);
	} else {
		Com_sprintf(pathname, sizeof(pathname), "%s", filename);
		Com_sprintf(pathpatch, sizeof(pathpatch), "%s_patch", filename);
	}
	inlength = botimport.FS_FOpenFileHash(pathname, &h_up, FS_READ, &inhash);
	if (!h_up) return NULL;
	plength = botimport.FS_FOpenFile(pathpatch, &h_patch, FS_READ);

	inbuffer = (char *)GetClearedMemory(inlength + 1);
	botimport.FS_Read(inbuffer, inlength, h_up);
	botimport.FS_FCloseFile(h_up);

	if (h_patch) {
		pbuffer = (char *)GetClearedMemory(plength + 1);
		botimport.FS_Read(pbuffer, plength, h_patch);
		botimport.FS_FCloseFile(h_patch);

		Com_Printf("patching menu file %s...\n", pathname);
		outlength = MV_MenuPatchFile(inbuffer, inhash, pbuffer, &outbuffer);
		if (outlength < 0) {
			if (outlength == ERROR_SYNTAX) {
				Com_Printf("patching failed: syntax error in patchfile\n");
			} else if (outlength == ERROR_HASH) {
				Com_Printf("patching skipped: hash mismatch\n");
			}

			outbuffer = inbuffer;
			outlength = inlength;
		}

		FreeMemory(pbuffer);

		// uncomment to dump patched file with _patched suffix; menu_patch

		/*
		char patchedName[MAX_QPATH];
		fileHandle_t patchedFile;
		Com_sprintf(patchedName, sizeof(patchedName), "%s_patched", pathname);
		botimport.FS_FOpenFile(patchedName, &patchedFile, FS_WRITE);
		botimport.FS_Write(outbuffer, outlength, patchedFile);
		botimport.FS_FCloseFile(patchedFile);
		*/
	} else {
		outbuffer = inbuffer;
		outlength = inlength;
	}

	script = (script_t *)GetClearedMemory(sizeof(script_t) + outlength + 1);
	Com_Memset(script, 0, sizeof(script_t));
	strcpy(script->filename, filename);
	script->buffer = (char *)script + sizeof(script_t);
	script->buffer[outlength] = 0;
	script->length = outlength;
	script->script_p = script->buffer;
	script->lastscript_p = script->buffer;
	script->end_p = &script->buffer[outlength];
	script->tokenavailable = 0;
	script->line = 1;
	script->lastline = 1;
	SetScriptPunctuations(script, NULL);

	Com_Memcpy(script->buffer, outbuffer, outlength);
	FreeMemory(outbuffer);

	if (outbuffer != inbuffer)
		FreeMemory(inbuffer);

	script->length = COM_Compress(script->buffer);
	return script;
} //end of the function LoadScriptFile