//=========================================================================== // called at the start of every frame // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int AAS_StartFrame(float time) { aasworld.time = time; //unlink all entities that were not updated last frame AAS_UnlinkInvalidEntities(); //invalidate the entities AAS_InvalidateEntities(); //initialize AAS AAS_ContinueInit(time); // aasworld.frameroutingupdates = 0; // if (bot_developer) { if (LibVarGetValue("showcacheupdates")) { AAS_RoutingInfo(); LibVarSet("showcacheupdates", "0"); } //end if if (LibVarGetValue("showmemoryusage")) { PrintUsedMemorySize(); LibVarSet("showmemoryusage", "0"); } //end if if (LibVarGetValue("memorydump")) { PrintMemoryLabels(); LibVarSet("memorydump", "0"); } //end if } //end if // if (saveroutingcache->value) { AAS_WriteRouteCache(); LibVarSet("saveroutingcache", "0"); } //end if // aasworld.numframes++; return BLERR_NOERROR; } //end of the function AAS_StartFrame
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void SetCfgLibVars( void ) { int i; float value; for ( i = 0; cfg_fields[i].name; i++ ) { if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) { value = *( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ); if ( value != FLT_MAX ) { LibVarSet( cfg_fields[i].name, va( "%f", value ) ); } //end if } //end if } //end for } //end of the function SetCfgLibVars
//=========================================================================== // // 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
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int Export_BotLibVarSet( const char *var_name, const char *value ) { LibVarSet( var_name, value ); return BLERR_NOERROR; } //end of the function Export_BotLibVarSet
//=========================================================================== // // 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
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; }