Exemple #1
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
int LoadCfgFile( char *filename ) {
	source_t *source;
	token_t token;
	int settingsdefined;

	source = LoadSourceFile( filename );
	if ( !source ) {
		Log_Print( "couldn't open cfg file %s\n", filename );
		return false;
	} //end if

	settingsdefined = false;
	memset( &cfg, 0, sizeof( cfg_t ) );

	while ( PC_ReadToken( source, &token ) )
	{
		if ( !stricmp( token.string, "bbox" ) ) {
			if ( cfg.numbboxes >= AAS_MAX_BBOXES ) {
				SourceError( source, "too many bounding box volumes defined" );
			} //end if
			if ( !ReadStructure( source, &bbox_struct, (char *) &cfg.bboxes[cfg.numbboxes] ) ) {
				FreeSource( source );
				return false;
			} //end if
			cfg.allpresencetypes |= cfg.bboxes[cfg.numbboxes].presencetype;
			cfg.numbboxes++;
		} //end if
		else if ( !stricmp( token.string, "settings" ) ) {
			if ( settingsdefined ) {
				SourceWarning( source, "settings already defined\n" );
			} //end if
			settingsdefined = true;
			if ( !ReadStructure( source, &cfg_struct, (char *) &cfg ) ) {
				FreeSource( source );
				return false;
			} //end if
		} //end else if
	} //end while
	if ( VectorLength( cfg.phys_gravitydirection ) < 0.9 || VectorLength( cfg.phys_gravitydirection ) > 1.1 ) {
		SourceError( source, "invalid gravity direction specified" );
	} //end if
	if ( cfg.numbboxes <= 0 ) {
		SourceError( source, "no bounding volumes specified" );
	} //end if
	FreeSource( source );
	SetCfgLibVars();
	Log_Print( "using cfg file %s\n", filename );
	return true;
} //end of the function LoadCfgFile
Exemple #2
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
weaponconfig_t *LoadWeaponConfig(char *filename)
{
	int max_weaponinfo, max_projectileinfo;
	token_t token;
	char path[MAX_PATH];
	int i, j;
	source_t *source;
	weaponconfig_t *wc;
	weaponinfo_t weaponinfo;

	max_weaponinfo = (int) LibVarValue("max_weaponinfo", "32");
	if (max_weaponinfo < 0)
	{
		botimport.Print(PRT_ERROR, "max_weaponinfo = %d\n", max_weaponinfo);
		max_weaponinfo = 32;
		LibVarSet("max_weaponinfo", "32");
	} //end if
	max_projectileinfo = (int) LibVarValue("max_projectileinfo", "32");
	if (max_projectileinfo < 0)
	{
		botimport.Print(PRT_ERROR, "max_projectileinfo = %d\n", max_projectileinfo);
		max_projectileinfo = 32;
		LibVarSet("max_projectileinfo", "32");
	} //end if
	strncpy(path, filename, MAX_PATH);
	PC_SetBaseFolder(BOTFILESBASEFOLDER);
	source = LoadSourceFile(path);
	if (!source)
	{
		botimport.Print(PRT_ERROR, "counldn't load %s\n", path);
		return NULL;
	} //end if
	//initialize weapon config
	wc = (weaponconfig_t *) GetClearedHunkMemory(sizeof(weaponconfig_t) +
										max_weaponinfo * sizeof(weaponinfo_t) +
										max_projectileinfo * sizeof(projectileinfo_t));
	wc->weaponinfo = (weaponinfo_t *) ((char *) wc + sizeof(weaponconfig_t));
	wc->projectileinfo = (projectileinfo_t *) ((char *) wc->weaponinfo +
										max_weaponinfo * sizeof(weaponinfo_t));
	wc->numweapons = max_weaponinfo;
	wc->numprojectiles = 0;
	//parse the source file
	while(PC_ReadToken(source, &token))
	{
		if (!strcmp(token.string, "weaponinfo"))
		{
			Com_Memset(&weaponinfo, 0, sizeof(weaponinfo_t));
			if (!ReadStructure(source, &weaponinfo_struct, (char *) &weaponinfo))
			{
				FreeMemory(wc);
				FreeSource(source);
				return NULL;
			} //end if
			if (weaponinfo.number < 0 || weaponinfo.number >= max_weaponinfo)
			{
				botimport.Print(PRT_ERROR, "weapon info number %d out of range in %s\n", weaponinfo.number, path);
				FreeMemory(wc);
				FreeSource(source);
				return NULL;
			} //end if
			Com_Memcpy(&wc->weaponinfo[weaponinfo.number], &weaponinfo, sizeof(weaponinfo_t));
			wc->weaponinfo[weaponinfo.number].valid = qtrue;
		} //end if
		else if (!strcmp(token.string, "projectileinfo"))
		{
			if (wc->numprojectiles >= max_projectileinfo)
			{
				botimport.Print(PRT_ERROR, "more than %d projectiles defined in %s\n", max_projectileinfo, path);
				FreeMemory(wc);
				FreeSource(source);
				return NULL;
			} //end if
			Com_Memset(&wc->projectileinfo[wc->numprojectiles], 0, sizeof(projectileinfo_t));
			if (!ReadStructure(source, &projectileinfo_struct, (char *) &wc->projectileinfo[wc->numprojectiles]))
			{
				FreeMemory(wc);
				FreeSource(source);
				return NULL;
			} //end if
			wc->numprojectiles++;
		} //end if
		else
		{
			botimport.Print(PRT_ERROR, "unknown definition %s in %s\n", token.string, path);
			FreeMemory(wc);
			FreeSource(source);
			return NULL;
		} //end else
	} //end while
	FreeSource(source);
	//fix up weapons
	for (i = 0; i < wc->numweapons; i++)
	{
		if (!wc->weaponinfo[i].valid) continue;
		if (!wc->weaponinfo[i].name[0])
		{
			botimport.Print(PRT_ERROR, "weapon %d has no name in %s\n", i, path);
			FreeMemory(wc);
			return NULL;
		} //end if
		if (!wc->weaponinfo[i].projectile[0])
		{
			botimport.Print(PRT_ERROR, "weapon %s has no projectile in %s\n", wc->weaponinfo[i].name, path);
			FreeMemory(wc);
			return NULL;
		} //end if
		//find the projectile info and copy it to the weapon info
		for (j = 0; j < wc->numprojectiles; j++)
		{
			if (!strcmp(wc->projectileinfo[j].name, wc->weaponinfo[i].projectile))
			{
				Com_Memcpy(&wc->weaponinfo[i].proj, &wc->projectileinfo[j], sizeof(projectileinfo_t));
				break;
			} //end if
		} //end for
		if (j == wc->numprojectiles)
		{
			botimport.Print(PRT_ERROR, "weapon %s uses undefined projectile in %s\n", wc->weaponinfo[i].name, path);
			FreeMemory(wc);
			return NULL;
		} //end if
	} //end for
	if (!wc->numweapons) botimport.Print(PRT_WARNING, "no weapon info loaded\n");
	botimport.Print(PRT_MESSAGE, "loaded %s\n", path);
	return wc;
} //end of the function LoadWeaponConfig
Exemple #3
0
/*
=======================================================================================================================================
ReadStructure
=======================================================================================================================================
*/
int ReadStructure(source_t *source, structdef_t *def, char *structure) {
	token_t token;
	fielddef_t *fd;
	void *p;
	int num;

	if (!PC_ExpectTokenString(source, "{")) {
		return 0;
	}

	while (1) {
		if (!PC_ExpectAnyToken(source, &token)) {
			return qfalse;
		}
		// if end of structure
		if (!strcmp(token.string, "}")) {
			break;
		}
		// find the field with the name
		fd = FindField(def->fields, token.string);

		if (!fd) {
			SourceError(source, "unknown structure field %s", token.string);
			return qfalse;
		}

		if (fd->type & FT_ARRAY) {
			num = fd->maxarray;

			if (!PC_ExpectTokenString(source, "{")) {
				return qfalse;
			}
		} else {
			num = 1;
		}

		p = (void *)(structure + fd->offset);

		while (num-- > 0) {
			if (fd->type & FT_ARRAY) {
				if (PC_CheckTokenString(source, "}")) {
					break;
				}
			}

			switch (fd->type & FT_TYPE) {
				case FT_CHAR:
				{
					if (!ReadChar(source, fd, p)) {
						return qfalse;
					}

					p = (char *)p + sizeof(char);
					break;
				}
				case FT_INT:
				{
					if (!ReadNumber(source, fd, p)) {
						return qfalse;
					}

					p = (char *)p + sizeof(int);
					break;
				}
				case FT_FLOAT:
				{
					if (!ReadNumber(source, fd, p)) {
						return qfalse;
					}

					p = (char *)p + sizeof(float);
					break;
				}
				case FT_STRING:
				{
					if (!ReadString(source, fd, p)) {
						return qfalse;
					}

					p = (char *)p + MAX_STRINGFIELD;
					break;
				}
				case FT_STRUCT:
				{
					if (!fd->substruct) {
						SourceError(source, "BUG: no sub structure defined");
						return qfalse;
					}

					ReadStructure(source, fd->substruct, (char *)p);

					p = (char *)p + fd->substruct->size;
					break;
				}
			}

			if (fd->type & FT_ARRAY) {
				if (!PC_ExpectAnyToken(source, &token)) {
					return qfalse;
				}

				if (!strcmp(token.string, "}")) {
					break;
				}

				if (strcmp(token.string, ",")) {
					SourceError(source, "expected a comma, found %s", token.string);
					return qfalse;
				}
			}
		}
	}

	return qtrue;
}
Exemple #4
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
itemconfig_t *LoadItemConfig( char *filename ) {
	int max_iteminfo;
	token_t token;
	char path[MAX_PATH];
	source_t *source;
	itemconfig_t *ic;
	iteminfo_t *ii;

	max_iteminfo = (int) LibVarValue( "max_iteminfo", "256" );
	if ( max_iteminfo < 0 ) {
		botimport.Print( PRT_ERROR, "max_iteminfo = %d\n", max_iteminfo );
		max_iteminfo = 128;
		LibVarSet( "max_iteminfo", "128" );
	}

	strncpy( path, filename, MAX_PATH );
	source = LoadSourceFile( path );
	if ( !source ) {
		botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
		return NULL;
	} //end if
	  //initialize item config
	ic = (itemconfig_t *) GetClearedHunkMemory( sizeof( itemconfig_t ) +
												max_iteminfo * sizeof( iteminfo_t ) );
	ic->iteminfo = ( iteminfo_t * )( (char *) ic + sizeof( itemconfig_t ) );
	ic->numiteminfo = 0;
	//parse the item config file
	while ( PC_ReadToken( source, &token ) )
	{
		if ( !strcmp( token.string, "iteminfo" ) ) {
			if ( ic->numiteminfo >= max_iteminfo ) {
				SourceError( source, "more than %d item info defined\n", max_iteminfo );
				FreeMemory( ic );
				FreeSource( source );
				return NULL;
			} //end if
			ii = &ic->iteminfo[ic->numiteminfo];
			memset( ii, 0, sizeof( iteminfo_t ) );
			if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) {
				FreeMemory( ic );
				FreeMemory( source );
				return NULL;
			} //end if
			StripDoubleQuotes( token.string );
			strncpy( ii->classname, token.string, sizeof( ii->classname ) - 1 );
			if ( !ReadStructure( source, &iteminfo_struct, (char *) ii ) ) {
				FreeMemory( ic );
				FreeSource( source );
				return NULL;
			} //end if
			ii->number = ic->numiteminfo;
			ic->numiteminfo++;
		} //end if
		else
		{
			SourceError( source, "unknown definition %s\n", token.string );
			FreeMemory( ic );
			FreeSource( source );
			return NULL;
		} //end else
	} //end while
	FreeSource( source );
	//
	if ( !ic->numiteminfo ) {
		botimport.Print( PRT_WARNING, "no item info loaded\n" );
	}
	botimport.Print( PRT_MESSAGE, "loaded %s\n", path );
	return ic;
} //end of the function LoadItemConfig
Exemple #5
0
//===========================================================================
//
// Parameter:               -
// Returns:                 -
// Changes Globals:     -
//===========================================================================
int ReadStructure(structdef_t * def, char *structure)
{
	idToken         token;
	idLexer         parser;
	fielddef_t     *fd;
	void           *p;
	int             num;

	if(!parser.ExpectTokenString("{"))
	{
		return 0;
	}
	while(1)
	{
		if(!parser.ExpectAnyToken(&token))
		{
			return false;
		}
		//if end of structure
		if(!strcmp(token.string, "}"))
		{
			break;
		}
		//find the field with the name
		fd = FindField(def->fields, token.string);
		if(!fd)
		{
			parser.Error("unknown structure field %s", token.string);
			return false;
		}						//end if
		if(fd->type & FT_ARRAY)
		{
			num = fd->maxarray;
			if(!parser.ExpectTokenString("{"))
			{
				return false;
			}
		}						//end if
		else
		{
			num = 1;
		}						//end else
		p = (void *)(structure + fd->offset);
		while(num-- > 0)
		{
			if(fd->type & FT_ARRAY)
			{
				if(parser.CheckTokenString("}"))
				{
					break;
				}
			}					//end if
			switch (fd->type & FT_TYPE)
			{
				case FT_CHAR:
				{
					if(!ReadChar(fd, p))
					{
						return false;
					}
					p = (char *)p + sizeof(char);
					break;
				}				//end case
				case FT_INT:
				{
					if(!ReadNumber(fd, p))
					{
						return false;
					}
					p = (char *)p + sizeof(int);
					break;
				}				//end case
				case FT_FLOAT:
				{
					if(!ReadNumber(fd, p))
					{
						return false;
					}
					p = (char *)p + sizeof(float);
					break;
				}				//end case
				case FT_STRING:
				{
					if(!ReadString(fd, p))
					{
						return false;
					}
					p = (char *)p + MAX_STRINGFIELD;
					break;
				}				//end case
				case FT_STRUCT:
				{
					if(!fd->substruct)
					{
						parser.Error("BUG: no sub structure defined");
						return false;
					}			//end if
					ReadStructure(fd->substruct, (char *)p);
					p = (char *)p + fd->substruct->size;
					break;
				}				//end case
			}					//end switch
			if(fd->type & FT_ARRAY)
			{
				if(!parser.ExpectAnyToken(&token))
				{
					return false;
				}
				if(!strcmp(token.string, "}"))
				{
					break;
				}
				if(strcmp(token.string, ","))
				{
					parser.Error("expected a comma, found %s", token.string);
					return false;
				}				//end if
			}					//end if
		}						//end while
	}							//end while
	return true;
}								//end of the function ReadStructure
Exemple #6
0
static itemconfig_t* LoadItemConfig( const char* filename ) {
	int max_iteminfo = ( int )LibVarValue( "max_iteminfo", "256" );
	if ( max_iteminfo < 0 ) {
		BotImport_Print( PRT_ERROR, "max_iteminfo = %d\n", max_iteminfo );
		max_iteminfo = 256;
		LibVarSet( "max_iteminfo", "256" );
	}

	if ( GGameType & GAME_Quake3 ) {
		PC_SetBaseFolder( BOTFILESBASEFOLDER );
	}
	char path[ MAX_QPATH ];
	String::NCpyZ( path, filename, MAX_QPATH );
	source_t* source = LoadSourceFile( path );
	if ( !source ) {
		BotImport_Print( PRT_ERROR, "counldn't load %s\n", path );
		return NULL;
	}
	//initialize item config
	itemconfig_t* ic = ( itemconfig_t* )Mem_ClearedAlloc( sizeof ( itemconfig_t ) +
		max_iteminfo * sizeof ( iteminfo_t ) );
	ic->iteminfo = ( iteminfo_t* )( ( char* )ic + sizeof ( itemconfig_t ) );
	ic->numiteminfo = 0;
	//parse the item config file
	token_t token;
	while ( PC_ReadToken( source, &token ) ) {
		if ( !String::Cmp( token.string, "iteminfo" ) ) {
			if ( ic->numiteminfo >= max_iteminfo ) {
				SourceError( source, "more than %d item info defined\n", max_iteminfo );
				Mem_Free( ic );
				FreeSource( source );
				return NULL;
			}
			iteminfo_t* ii = &ic->iteminfo[ ic->numiteminfo ];
			Com_Memset( ii, 0, sizeof ( iteminfo_t ) );
			if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) {
				Mem_Free( ic );
				FreeSource( source );
				return NULL;
			}
			StripDoubleQuotes( token.string );
			String::NCpy( ii->classname, token.string, sizeof ( ii->classname ) - 1 );
			if ( !ReadStructure( source, &iteminfo_struct, ( char* )ii ) ) {
				Mem_Free( ic );
				FreeSource( source );
				return NULL;
			}
			ii->number = ic->numiteminfo;
			ic->numiteminfo++;
		} else {
			SourceError( source, "unknown definition %s\n", token.string );
			Mem_Free( ic );
			FreeSource( source );
			return NULL;
		}
	}
	FreeSource( source );

	if ( !ic->numiteminfo ) {
		BotImport_Print( PRT_WARNING, "no item info loaded\n" );
	}
	BotImport_Print( PRT_MESSAGE, "loaded %s\n", path );
	return ic;
}