Exemple #1
0
void G_xpsave_writeconfig() 
{
	fileHandle_t f;
	int len, i, j;
	time_t t;
	int age = 0;
	int eff_XPSaveMaxAge_xp = G_getXPSaveMaxAge_xp();
	int eff_XPSaveMaxAge = G_getXPSaveMaxAge();

	if(!(g_XPSave.integer & XPSF_ENABLE))
		return;	
	if(!g_XPSaveFile.string[0])
		return;
	time(&t);
	len = trap_FS_FOpenFile(g_XPSaveFile.string, &f, FS_WRITE);
	if(len < 0) {
		G_Printf("G_xpsave_writeconfig: could not open %s\n",
				g_XPSaveFile.string);
 	}
 
 	trap_FS_Write("[serverstat]\n", 13, f);
	trap_FS_Write("rating            = ", 20, f);
 	G_shrubbot_writeconfig_float(g_serverstat.rating, f);
	trap_FS_Write("rating_variance   = ", 20, f);
 	G_shrubbot_writeconfig_float(g_serverstat.rating_variance, f);
	trap_FS_Write("distance_rating   = ", 20, f);
 	G_shrubbot_writeconfig_float(g_serverstat.distance_rating, f);
	trap_FS_Write("distance_variance = ", 20, f);
 	G_shrubbot_writeconfig_float(g_serverstat.distance_variance, f);
 	trap_FS_Write("\n", 1, f);
 	G_Printf("xpsave: wrote server rating: %f\n", g_serverstat.rating);
 
 	for(i=0; g_mapstats[i]; i++) {
 		trap_FS_Write("[mapstat]\n", 10, f);
		trap_FS_Write("name              = ", 20, f);
 		G_shrubbot_writeconfig_string(g_mapstats[i]->name, f);
		trap_FS_Write("rating            = ", 20, f);
 		G_shrubbot_writeconfig_float(g_mapstats[i]->rating, f);
		trap_FS_Write("rating_variance   = ", 20, f);
 		G_shrubbot_writeconfig_float(g_mapstats[i]->rating_variance, f);
		trap_FS_Write("spree_record      = ", 20, f);
 		G_shrubbot_writeconfig_int(g_mapstats[i]->spreeRecord, f);
		trap_FS_Write("spree_name        = ", 20, f);
 		G_shrubbot_writeconfig_string(g_mapstats[i]->spreeName, f);
 		trap_FS_Write("\n", 1, f);
 	}
	G_Printf("xpsave: wrote %d mapstats\n", i);

	for(i=0; g_xpsaves[i]; i++) {
		if(!g_xpsaves[i]->time)
			continue;
		age = t - g_xpsaves[i]->time;
		if(age > eff_XPSaveMaxAge) {
			continue;
 		}
 
 		trap_FS_Write("[xpsave]\n", 9, f);
		trap_FS_Write("guid              = ", 20, f);
 		G_shrubbot_writeconfig_string(g_xpsaves[i]->guid, f);
		trap_FS_Write("name              = ", 20, f);
 		G_shrubbot_writeconfig_string(g_xpsaves[i]->name, f);
		trap_FS_Write("time              = ", 20, f);
 		G_shrubbot_writeconfig_int(g_xpsaves[i]->time, f);
 		if(age <= eff_XPSaveMaxAge_xp) {
 			for(j=0; j<SK_NUM_SKILLS; j++) {
 				if(g_xpsaves[i]->skill[j] == 0.0f)
 					continue;
				trap_FS_Write(va("skill[%i]          = ", j),
					20, f);
 				G_shrubbot_writeconfig_float(
 					g_xpsaves[i]->skill[j], f);
 			}
 		}
 		if(g_xpsaves[i]->kill_rating != 0.0f) { 
			trap_FS_Write("kill_rating       = ", 20, f);
 			G_shrubbot_writeconfig_float(g_xpsaves[i]->kill_rating,
 				f);
 		}
 		if(g_xpsaves[i]->kill_variance != SIGMA2_DELTA) { 
			trap_FS_Write("kill_variance     = ", 20, f);
 			G_shrubbot_writeconfig_float(g_xpsaves[i]->kill_variance,
 				f);
 		}
 		if(g_xpsaves[i]->rating != 0) { 
			trap_FS_Write("rating            = ", 20, f);
 			G_shrubbot_writeconfig_float(
 				g_xpsaves[i]->rating, f);
 		}
 		if(g_xpsaves[i]->rating_variance != SIGMA2_THETA) { 
			trap_FS_Write("rating_variance   = ", 20, f);
 			G_shrubbot_writeconfig_float(
 				g_xpsaves[i]->rating_variance, f);
 		}
 		if(g_xpsaves[i]->mutetime) {
			trap_FS_Write("mutetime          = ", 20, f);
 			G_shrubbot_writeconfig_int(g_xpsaves[i]->mutetime, f);
 		}
 		if(g_playerRating.integer & PLAYER_RATING_SKILLS) {
 			for(j=0; j<SK_NUM_SKILLS; j++) {
				trap_FS_Write(va("pr_skill[%i]       = ", j),
					20, f);
 				G_shrubbot_writeconfig_string(
 					va("%i %f %i %f %i %f %i %f %i %f",
 					g_xpsaves[i]->pr_skill_updates[j][0],
					g_xpsaves[i]->pr_skill[j][0],
					g_xpsaves[i]->pr_skill_updates[j][1],
					g_xpsaves[i]->pr_skill[j][1],
					g_xpsaves[i]->pr_skill_updates[j][2],
					g_xpsaves[i]->pr_skill[j][2],
					g_xpsaves[i]->pr_skill_updates[j][3],
					g_xpsaves[i]->pr_skill[j][3],
					g_xpsaves[i]->pr_skill_updates[j][4],
					g_xpsaves[i]->pr_skill[j][4]),
					f);
			}
		}
		trap_FS_Write("\n", 1, f);
	}
	G_Printf("xpsave: wrote %d xpsaves\n", i);
	trap_FS_FCloseFile(f);
}
Exemple #2
0
void Load_Autosaves(void)
{//load in our autosave from the .autosp
	char			*s;
	int				len;
	fileHandle_t	f;
	char			buf[MAX_AUTOSAVE_FILESIZE];
	char			loadPath[MAX_QPATH];
	vec3_t			positionData;
	int				sizeData;
	//[RawMapName]
	//vmCvar_t		mapname;
	//[/RawMapName]
	qboolean		teleportPlayers = qfalse;

	G_Printf("^5Loading Autosave File Data...");

	//[RawMapName]
	//trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );

	//Com_sprintf(loadPath, MAX_QPATH, "maps/%s.autosp", mapname.string);
	Com_sprintf(loadPath, sizeof(loadPath), "maps/%s.autosp", level.rawmapname);
	//[/RawMapName]

	len = trap_FS_FOpenFile( loadPath, &f, FS_READ );
	if ( !f )
	{
		G_Printf("^5No autosave file found.\n");
		return;
	}
	if ( !len )
	{ //empty file
		G_Printf("^5Empty autosave file!\n");
		trap_FS_FCloseFile( f );
		return;
	}

	trap_FS_Read( buf, len, f );
	trap_FS_FCloseFile( f );

	s = buf;

	while(*s != '\0' && s-buf < len)
	{
		if(*s == '\n')
		{//hop over newlines
			s++;
			continue;
		}

		sscanf(s, "%f %f %f %i %i", &positionData[0], &positionData[1], &positionData[2], &sizeData, &teleportPlayers);

		Create_Autosave( positionData, sizeData, teleportPlayers );

		//advance to the end of the line
		while(*s != '\n' && *s != '\0' && s-buf < len)
		{
			s++;
		}
	}

	G_Printf("^5Done.\n");
}
Exemple #3
0
/*
=============
G_Script_ScriptLoad

  Loads the script for the current level into the buffer
=============
*/
void G_Script_ScriptLoad(void) {
	char         filename[MAX_QPATH];
	vmCvar_t     mapname;
	fileHandle_t f     = 0;
	int          len   = 0;
	qboolean     found = qfalse;

	trap_Cvar_Register(&g_scriptDebug, "g_scriptDebug", "0", 0);
	trap_Cvar_VariableStringBuffer("g_scriptName", filename, sizeof (filename));
	if (filename[0] != '\0') {
		trap_Cvar_Register(&mapname, "g_scriptName", "", CVAR_CHEAT);
	} else {
		trap_Cvar_Register(&mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM);
	}

	// Nico, if API is used and if a mapscript was sent for this map don't load any local script
	if (g_useAPI.integer && level.useAPImapscript) {
		G_Printf("%s: using custom mapscript from API!\n", GAME_VERSION);
		return;
	}

	// Nico, API is not in use, check if this map a special mapscript in local mapscript directory
	if (!g_useAPI.integer && g_mapScriptDirectory.string[0]) {
		G_Printf("%s: checking for local custom mapscript...\n", GAME_VERSION);
		Q_strncpyz(filename, g_mapScriptDirectory.string, sizeof (filename));
		Q_strcat(filename, sizeof (filename), "/");
		Q_strcat(filename, sizeof (filename), mapname.string);
		Q_strcat(filename, sizeof (filename), ".script");
		len = trap_FS_FOpenFile(filename, &f, FS_READ);
		if (len > 0) {
			found = qtrue;
			G_Printf("%s: found local file '%s'!\n", GAME_VERSION, filename);
		} else {
			G_Printf("%s: no local file found!\n", GAME_VERSION);
		}
	}

	// Nico, should we use default map script or custom one?
	if (!found) {
		Q_strncpyz(filename, "maps/", sizeof (filename));
		Q_strcat(filename, sizeof (filename), mapname.string);
		Q_strcat(filename, sizeof (filename), ".script");
		len = trap_FS_FOpenFile(filename, &f, FS_READ);
		G_Printf("%s: using default mapscript!\n", GAME_VERSION);
	}

	// make sure we clear out the temporary scriptname
	trap_Cvar_Set("g_scriptName", "");

	if (len < 0) {
		return;
	}

	// END Mad Doc - TDF
	// Arnout: make sure we terminate the script with a '\0' to prevent parser from choking
	level.scriptEntity = NULL;
	level.scriptEntity = G_Alloc(len + 1);
	trap_FS_Read(level.scriptEntity, len, f);
	*(level.scriptEntity + len) = '\0';

	// Gordon: and make sure ppl haven't put stuff with uppercase in the string table..
	G_Script_EventStringInit();

	trap_FS_FCloseFile(f);
}
Exemple #4
0
void CG_InitSiegeMode(void)
{
	char			levelname[MAX_QPATH];
	char			btime[1024];
	char			teams[2048];
	char			teamInfo[MAX_SIEGE_INFO_SIZE];
	int				len = 0;
	int				i = 0;
	int				j = 0;
	siegeClass_t		*cl;
	siegeTeam_t		*sTeam;
	fileHandle_t	f;
	char			teamIcon[128];

	if (cgs.gametype != GT_SIEGE)
	{
		goto failure;
	}

	Com_sprintf(levelname, sizeof(levelname), "%s\0", cgs.mapname);

	i = strlen(levelname)-1;

	while (i > 0 && levelname[i] && levelname[i] != '.')
	{
		i--;
	}

	if (!i)
	{
		goto failure;
	}

	levelname[i] = '\0'; //kill the ".bsp"

	Com_sprintf(levelname, sizeof(levelname), "%s.siege\0", levelname); 

	if (!levelname || !levelname[0])
	{
		goto failure;
	}

	len = trap_FS_FOpenFile(levelname, &f, FS_READ);

	if (!f || len >= MAX_SIEGE_INFO_SIZE)
	{
		goto failure;
	}

	trap_FS_Read(siege_info, len, f);

	trap_FS_FCloseFile(f);

	siege_valid = 1;

	if (BG_SiegeGetValueGroup(siege_info, "Teams", teams))
	{
		char buf[1024];

		//[SIEGECVARFIX]
		siege_Cvar_VariableStringBuffer("cg_siegeTeam1", buf, 1024);
		//trap_Cvar_VariableStringBuffer("cg_siegeTeam1", buf, 1024);
		//[SIEGECVARFIX]
		if (buf[0] && Q_stricmp(buf, "none"))
		{
			strcpy(team1, buf);
		}
		else
		{
			BG_SiegeGetPairedValue(teams, "team1", team1);
		}

		if (team1[0] == '@')
		{ //it's a damn stringed reference.
			char b[256];
			trap_SP_GetStringTextString(team1+1, b, 256);
			trap_Cvar_Set("cg_siegeTeam1Name", b);
		}
		else
		{
			trap_Cvar_Set("cg_siegeTeam1Name", team1);
		}

		//[SIEGECVARFIX]
		siege_Cvar_VariableStringBuffer("cg_siegeTeam2", buf, 1024);
		//trap_Cvar_VariableStringBuffer("cg_siegeTeam2", buf, 1024);
		//[/SIEGECVARFIX]
		if (buf[0] && Q_stricmp(buf, "none"))
		{
			strcpy(team2, buf);
		}
		else
		{
			BG_SiegeGetPairedValue(teams, "team2", team2);
		}

		if (team2[0] == '@')
		{ //it's a damn stringed reference.
			char b[256];
			trap_SP_GetStringTextString(team2+1, b, 256);
			trap_Cvar_Set("cg_siegeTeam2Name", b);
		}
		else
		{
			trap_Cvar_Set("cg_siegeTeam2Name", team2);
		}
	}
	else
	{
		CG_Error("Siege teams not defined");
	}

	if (BG_SiegeGetValueGroup(siege_info, team1, teamInfo))
	{
		if (BG_SiegeGetPairedValue(teamInfo, "TeamIcon", teamIcon))
		{
			trap_Cvar_Set( "team1_icon", teamIcon);
		}

		if (BG_SiegeGetPairedValue(teamInfo, "Timed", btime))
		{
			team1Timed = atoi(btime)*1000;
			CG_SetSiegeTimerCvar ( team1Timed );
		}
		else
		{
			team1Timed = 0;
		}
	}
	else
	{
		CG_Error("No team entry for '%s'\n", team1);
	}

	if (BG_SiegeGetPairedValue(siege_info, "mapgraphic", teamInfo))
	{
		trap_Cvar_Set("siege_mapgraphic", teamInfo);
	}
	else
	{
		trap_Cvar_Set("siege_mapgraphic", "gfx/mplevels/siege1_hoth");
	}

	if (BG_SiegeGetPairedValue(siege_info, "missionname", teamInfo))
	{
		trap_Cvar_Set("siege_missionname", teamInfo);
	}
	else
	{
		trap_Cvar_Set("siege_missionname", " ");
	}

	if (BG_SiegeGetValueGroup(siege_info, team2, teamInfo))
	{
		if (BG_SiegeGetPairedValue(teamInfo, "TeamIcon", teamIcon))
		{
			trap_Cvar_Set( "team2_icon", teamIcon);
		}

		if (BG_SiegeGetPairedValue(teamInfo, "Timed", btime))
		{
			team2Timed = atoi(btime)*1000;
			CG_SetSiegeTimerCvar ( team2Timed );
		}
		else
		{
			team2Timed = 0;
		}
	}
	else
	{
		CG_Error("No team entry for '%s'\n", team2);
	}

	//Load the player class types
	BG_SiegeLoadClasses(NULL);

	if (!bgNumSiegeClasses)
	{ //We didn't find any?!
		CG_Error("Couldn't find any player classes for Siege");
	}

	//Now load the teams since we have class data.
	BG_SiegeLoadTeams();

	if (!bgNumSiegeTeams)
	{ //React same as with classes.
		CG_Error("Couldn't find any player teams for Siege");
	}

	//Get and set the team themes for each team. This will control which classes can be
	//used on each team.
	if (BG_SiegeGetValueGroup(siege_info, team1, teamInfo))
	{
		if (BG_SiegeGetPairedValue(teamInfo, "UseTeam", btime))
		{
			BG_SiegeSetTeamTheme(SIEGETEAM_TEAM1, btime);
		}
		if (BG_SiegeGetPairedValue(teamInfo, "FriendlyShader", btime))
		{
			cgSiegeTeam1PlShader = trap_R_RegisterShaderNoMip(btime);
		}
		else
		{
			cgSiegeTeam1PlShader = 0;
		}
	}
	if (BG_SiegeGetValueGroup(siege_info, team2, teamInfo))
	{
		if (BG_SiegeGetPairedValue(teamInfo, "UseTeam", btime))
		{
			BG_SiegeSetTeamTheme(SIEGETEAM_TEAM2, btime);
		}
		if (BG_SiegeGetPairedValue(teamInfo, "FriendlyShader", btime))
		{
			cgSiegeTeam2PlShader = trap_R_RegisterShaderNoMip(btime);
		}
		else
		{
			cgSiegeTeam2PlShader = 0;
		}
	}

	//Now go through the classes used by the loaded teams and try to precache
	//any forced models or forced skins.
	i = SIEGETEAM_TEAM1;

	while (i <= SIEGETEAM_TEAM2)
	{
		j = 0;
		sTeam = BG_SiegeFindThemeForTeam(i);

		if (!sTeam)
		{
			i++;
			continue;
		}

		//Get custom team shaders while we're at it.
		if (i == SIEGETEAM_TEAM1)
		{
			cgSiegeTeam1PlShader = sTeam->friendlyShader;
		}
		else if (i == SIEGETEAM_TEAM2)
		{
			cgSiegeTeam2PlShader = sTeam->friendlyShader;
		}

		while (j < sTeam->numClasses)
		{
			cl = sTeam->classes[j];

			if (cl->forcedModel[0])
			{ //This class has a forced model, so precache it.
				trap_R_RegisterModel(va("models/players/%s/model.glm", cl->forcedModel));

				if (cl->forcedSkin[0])
				{ //also has a forced skin, precache it.
					char *useSkinName;

					if (strchr(cl->forcedSkin, '|'))
					{//three part skin
						useSkinName = va("models/players/%s/|%s", cl->forcedModel, cl->forcedSkin);
					}
					else
					{
						useSkinName = va("models/players/%s/model_%s.skin", cl->forcedModel, cl->forcedSkin);
					}

					trap_R_RegisterSkin(useSkinName);
				}
			}
			
			j++;
		}
		i++;
	}

	//precache saber data for classes that use sabers on both teams
	BG_PrecacheSabersForSiegeTeam(SIEGETEAM_TEAM1);
	BG_PrecacheSabersForSiegeTeam(SIEGETEAM_TEAM2);

	CG_PrecachePlayersForSiegeTeam(SIEGETEAM_TEAM1);
	CG_PrecachePlayersForSiegeTeam(SIEGETEAM_TEAM2);

	CG_PrecachePlayersForSiegeTeam(SIEGETEAM_TEAM1);
	CG_PrecachePlayersForSiegeTeam(SIEGETEAM_TEAM2);

	CG_PrecacheSiegeObjectiveAssetsForTeam(SIEGETEAM_TEAM1);
	CG_PrecacheSiegeObjectiveAssetsForTeam(SIEGETEAM_TEAM2);

	return;
failure:
	siege_valid = 0;
}
/*
======================
CG_ParseBuildableAnimationFile

Read a configuration file containing animation counts and rates
models/buildables/hivemind/animation.cfg, etc
======================
*/
static qboolean CG_ParseBuildableAnimationFile( const char *filename, buildable_t buildable )
{
  char          *text_p;
  int           len;
  int           i;
  char          *token;
  float         fps;
  char          text[ 20000 ];
  fileHandle_t  f;
  animation_t   *animations;

  animations = cg_buildables[ buildable ].animations;

  // load the file
  len = trap_FS_FOpenFile( filename, &f, FS_READ );
  if( len <= 0 )
    return qfalse;

  if( len >= sizeof( text ) - 1 )
  {
    CG_Printf( "File %s too long\n", filename );
    return qfalse;
  }

  trap_FS_Read( text, len, f );
  text[ len ] = 0;
  trap_FS_FCloseFile( f );

  // parse the text
  text_p = text;

  // read information for each frame
  for( i = BANIM_NONE + 1; i < MAX_BUILDABLE_ANIMATIONS; i++ )
  {

    token = COM_Parse( &text_p );
    if( !*token )
      break;

    animations[ i ].firstFrame = atoi( token );

    token = COM_Parse( &text_p );
    if( !*token )
      break;

    animations[ i ].numFrames = atoi( token );
    animations[ i ].reversed = qfalse;
    animations[ i ].flipflop = qfalse;

    // if numFrames is negative the animation is reversed
    if( animations[ i ].numFrames < 0 )
    {
      animations[ i ].numFrames = -animations[ i ].numFrames;
      animations[ i ].reversed = qtrue;
    }

    token = COM_Parse( &text_p );
    if ( !*token )
      break;

    animations[i].loopFrames = atoi( token );

    token = COM_Parse( &text_p );
    if( !*token )
      break;

    fps = atof( token );
    if( fps == 0 )
      fps = 1;

    animations[ i ].frameLerp = 1000 / fps;
    animations[ i ].initialLerp = 1000 / fps;
  }

  if( i != MAX_BUILDABLE_ANIMATIONS )
  {
    CG_Printf( "Error parsing animation file: %s\n", filename );
    return qfalse;
  }

  return qtrue;
}
Exemple #6
0
/*
* CG_vWeap_ParseAnimationScript
* 
* script:
* 0 = first frame
* 1 = lastframe/number of frames
* 2 = looping frames
* 3 = frame time
* 
* keywords:
* "islastframe":Will read the second value of each animation as lastframe (usually means numframes)
* "rotationscale": value witch will scale the barrel rotation speed
*/
static bool CG_vWeap_ParseAnimationScript( weaponinfo_t *weaponinfo, char *filename )
{
	qbyte *buf;
	char *ptr, *token;
	int rounder, counter, i;
	bool debug = true;
	int anim_data[4][VWEAP_MAXANIMS];
	int length, filenum;

	rounder = 0;
	counter = 1; // reserve 0 for 'no animation'

	// set some defaults
	weaponinfo->barrelSpeed = 0;
	weaponinfo->flashFade = true;

	if( !cg_debugWeaponModels->integer )
		debug = false;

	// load the file
	length = trap_FS_FOpenFile( filename, &filenum, FS_READ );
	if( length == -1 )
		return false;
	if( !length )
	{
		trap_FS_FCloseFile( filenum );
		return false;
	}
	buf = ( qbyte * )CG_Malloc( length + 1 );
	trap_FS_Read( buf, length, filenum );
	trap_FS_FCloseFile( filenum );

	if( !buf )
	{
		CG_Free( buf );
		return false;
	}

	if( debug )
		CG_Printf( "%sLoading weapon animation script:%s%s\n", S_COLOR_BLUE, filename, S_COLOR_WHITE );

	memset( anim_data, 0, sizeof( anim_data ) );

	//proceed
	ptr = ( char * )buf;
	while( ptr )
	{
		token = COM_ParseExt( &ptr, qtrue );
		if( !token[0] )
			break;

		//see if it is keyword or number
		if( *token < '0' || *token > '9' )
		{
			if( !Q_stricmp( token, "barrel" ) )
			{
				if( debug )
					CG_Printf( "%sScript: barrel:%s", S_COLOR_BLUE, S_COLOR_WHITE );

				// time
				i = atoi( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->barrelTime = (unsigned int)( i > 0 ? i : 0 );

				// speed
				weaponinfo->barrelSpeed = atof( COM_ParseExt( &ptr, qfalse ) );

				if( debug )
					CG_Printf( "%s time:%i, speed:%.2f\n", S_COLOR_BLUE, (int)weaponinfo->barrelTime, weaponinfo->barrelSpeed, S_COLOR_WHITE );
			}
			else if( !Q_stricmp( token, "flash" ) )
			{
				if( debug )
					CG_Printf( "%sScript: flash:%s", S_COLOR_BLUE, S_COLOR_WHITE );

				// time
				i = atoi( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->flashTime = (unsigned int)( i > 0 ? i : 0 );

				// radius
				i = atoi( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->flashRadius = (float)( i > 0 ? i : 0 );

				// fade
				token = COM_ParseExt( &ptr, qfalse );
				if( !Q_stricmp( token, "no" ) )
					weaponinfo->flashFade = false;

				if( debug )
					CG_Printf( "%s time:%i, radius:%i, fade:%s%s\n", S_COLOR_BLUE, (int)weaponinfo->flashTime, (int)weaponinfo->flashRadius, weaponinfo->flashFade ? "YES" : "NO", S_COLOR_WHITE );
			}
			else if( !Q_stricmp( token, "flashColor" ) )
			{
				if( debug )
					CG_Printf( "%sScript: flashColor:%s", S_COLOR_BLUE, S_COLOR_WHITE );

				weaponinfo->flashColor[0] = atof( token = COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->flashColor[1] = atof( token = COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->flashColor[2] = atof( token = COM_ParseExt( &ptr, qfalse ) );

				if( debug )
					CG_Printf( "%s%f %f %f%s\n", S_COLOR_BLUE,
					weaponinfo->flashColor[0], weaponinfo->flashColor[1], weaponinfo->flashColor[2],
					S_COLOR_WHITE );
			}
			else if( !Q_stricmp( token, "handOffset" ) )
			{
				if( debug )
					CG_Printf( "%sScript: handPosition:%s", S_COLOR_BLUE, S_COLOR_WHITE );

				weaponinfo->handpositionOrigin[FORWARD] = atof( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->handpositionOrigin[RIGHT] = atof( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->handpositionOrigin[UP] = atof( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->handpositionAngles[PITCH] = atof( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->handpositionAngles[YAW] = atof( COM_ParseExt( &ptr, qfalse ) );
				weaponinfo->handpositionAngles[ROLL] = atof( COM_ParseExt( &ptr, qfalse ) );

				if( debug )
					CG_Printf( "%s%f %f %f %f %f %f%s\n", S_COLOR_BLUE,
					weaponinfo->handpositionOrigin[0], weaponinfo->handpositionOrigin[1], weaponinfo->handpositionOrigin[2],
					weaponinfo->handpositionAngles[0], weaponinfo->handpositionAngles[1], weaponinfo->handpositionAngles[2],
					S_COLOR_WHITE );

			}
			else if( !Q_stricmp( token, "firesound" ) )
			{
				if( debug )
					CG_Printf( "%sScript: firesound:%s", S_COLOR_BLUE, S_COLOR_WHITE );
				if( weaponinfo->num_fire_sounds >= WEAPONINFO_MAX_FIRE_SOUNDS )
				{
					if( debug )
						CG_Printf( S_COLOR_BLUE "too many firesounds defined. Max is %i" S_COLOR_WHITE "\n", WEAPONINFO_MAX_FIRE_SOUNDS );
					break;
				}

				token = COM_ParseExt( &ptr, qfalse );
				if( Q_stricmp( token, "NULL" ) )
				{
					weaponinfo->sound_fire[weaponinfo->num_fire_sounds] = trap_S_RegisterSound( token );
					if( weaponinfo->sound_fire[weaponinfo->num_fire_sounds] != NULL )
						weaponinfo->num_fire_sounds++;
				}
				if( debug )
					CG_Printf( "%s%s%s\n", S_COLOR_BLUE, token, S_COLOR_WHITE );
			}
			else if( !Q_stricmp( token, "strongfiresound" ) )
			{
				if( debug )
					CG_Printf( "%sScript: strongfiresound:%s", S_COLOR_BLUE, S_COLOR_WHITE );
				if( weaponinfo->num_strongfire_sounds >= WEAPONINFO_MAX_FIRE_SOUNDS )
				{
					if( debug )
						CG_Printf( S_COLOR_BLUE "too many strongfiresound defined. Max is %i" S_COLOR_WHITE "\n", WEAPONINFO_MAX_FIRE_SOUNDS );
					break;
				}

				token = COM_ParseExt( &ptr, qfalse );
				if( Q_stricmp( token, "NULL" ) )
				{
					weaponinfo->sound_strongfire[weaponinfo->num_strongfire_sounds] = trap_S_RegisterSound( token );
					if( weaponinfo->sound_strongfire[weaponinfo->num_strongfire_sounds] != NULL )
						weaponinfo->num_strongfire_sounds++;
				}
				if( debug )
					CG_Printf( "%s%s%s\n", S_COLOR_BLUE, token, S_COLOR_WHITE );
			}
			else if( token[0] && debug )
				CG_Printf( "%signored: %s%s\n", S_COLOR_YELLOW, token, S_COLOR_WHITE );
		}
		else
		{
			//frame & animation values
			i = (int)atoi( token );
			if( debug )
			{
				if( rounder == 0 )
					CG_Printf( "%sScript: %s", S_COLOR_BLUE, S_COLOR_WHITE );
				CG_Printf( "%s%i - %s", S_COLOR_BLUE, i, S_COLOR_WHITE );
			}
			anim_data[rounder][counter] = i;
			rounder++;
			if( rounder > 3 )
			{
				rounder = 0;
				if( debug )
					CG_Printf( "%s anim: %i%s\n", S_COLOR_BLUE, counter, S_COLOR_WHITE );
				counter++;
				if( counter == VWEAP_MAXANIMS )
					break;
			}
		}
	}

	CG_Free( buf );

	if( counter < VWEAP_MAXANIMS )
	{
		CG_Printf( "%sERROR: incomplete WEAPON script: %s - Using default%s\n", S_COLOR_YELLOW, filename, S_COLOR_WHITE );
		return false;
	}

	//reorganize to make my life easier
	for( i = 0; i < VWEAP_MAXANIMS; i++ )
	{
		weaponinfo->firstframe[i] = anim_data[0][i];
		weaponinfo->lastframe[i] = anim_data[1][i];
		weaponinfo->loopingframes[i] = anim_data[2][i];

		if( anim_data[3][i] < 10 )  //never allow less than 10 fps
			anim_data[3][i] = 10;

		weaponinfo->frametime[i] = 1000/anim_data[3][i];
	}

	return true;
}
Exemple #7
0
/*
======================
UI_ParseAnimationFile
======================
*/
static qboolean UI_ParseAnimationFile( const char *filename, playerInfo_t *pi )
{
	char         *text_p, *prev;
	int          len;
	int          i;
	char         *token;
	float        fps;
	int          skip;
	char         text[ 20000 ];
	fileHandle_t f;

	token = NULL;
	i = 0;
	fps = 0;
	prev = 0;

	memset( pi->animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS );

	// load the file
	len = trap_FS_FOpenFile( filename, &f, FS_READ );

	if ( len <= 0 )
	{
		return qfalse;
	}

	if ( len >= ( sizeof( text ) - 1 ) )
	{
		Com_Printf( "File %s too long\n", filename );
		return qfalse;
	}

	trap_FS_Read( text, len, f );
	text[ len ] = 0;
	trap_FS_FCloseFile( f );

	// parse the text
	text_p = text;
	skip = 0; // quite the compiler warning

	// NERVE - SMF - new!!!!
	AnimParseAnimConfig( pi, filename, text );
	return qtrue;

	// -NERVE - SMF - This does not work with wolf's new animation system

	/*
	        // read optional parameters
	        while ( 1 ) {
	                prev = text_p;  // so we can unget
	                token = COM_Parse( &text_p );
	                if ( !token ) {
	                        break;
	                }
	                if ( !Q_stricmp( token, "footsteps" ) ) {
	                        token = COM_Parse( &text_p );
	                        if ( !token ) {
	                                break;
	                        }
	                        continue;
	                } else if ( !Q_stricmp( token, "headoffset" ) ) {
	                        for ( i = 0 ; i < 3 ; i++ ) {
	                                token = COM_Parse( &text_p );
	                                if ( !token ) {
	                                        break;
	                                }
	                        }
	                        continue;
	                } else if ( !Q_stricmp( token, "sex" ) ) {
	                        token = COM_Parse( &text_p );
	                        if ( !token ) {
	                                break;
	                        }
	                        continue;
	                }

	                // if it is a number, start parsing animations
	                if ( token[0] >= '0' && token[0] <= '9' ) {
	                        text_p = prev;  // unget the token
	                        break;
	                }

	                Com_Printf( "unknown token '%s' is %s\n", token, filename );
	        }

	        // read information for each frame
	        for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) {

	                token = COM_Parse( &text_p );
	                if ( !token ) {
	                        break;
	                }
	                animations[i].firstFrame = atoi( token );
	                // leg only frames are adjusted to not count the upper body only frames
	                if ( i == LEGS_WALKCR ) {
	                        skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame;
	                }
	                if ( i >= LEGS_WALKCR ) {
	                        animations[i].firstFrame -= skip;
	                }

	                token = COM_Parse( &text_p );
	                if ( !token ) {
	                        break;
	                }
	                animations[i].numFrames = atoi( token );

	                token = COM_Parse( &text_p );
	                if ( !token ) {
	                        break;
	                }
	                animations[i].loopFrames = atoi( token );

	                token = COM_Parse( &text_p );
	                if ( !token ) {
	                        break;
	                }
	                fps = atof( token );
	                if ( fps == 0 ) {
	                        fps = 1;
	                }
	                animations[i].frameLerp = 1000 / fps;
	                animations[i].initialLerp = 1000 / fps;
	        }

	        if ( i != MAX_ANIMATIONS ) {
	                Com_Printf( "Error parsing animation file: %s", filename );
	                return qfalse;
	        }

	        return qtrue;
	*/
}
Exemple #8
0
/*
===============
G_ParseMapRotationFile

Load the map rotations from a map rotation file
===============
*/
static qboolean G_ParseMapRotationFile( const char *fileName )
{
	char         *text_p;
	int          i, j;
	int          len;
	char         *token;
	char         text[ 20000 ];
	char         mrName[ MAX_QPATH ];
	qboolean     mrNameSet = qfalse;
	fileHandle_t f;

	// load the file
	len = trap_FS_FOpenFile( fileName, &f, FS_READ );

	if ( len < 0 )
	{
		return qfalse;
	}

	if ( len == 0 || len >= sizeof( text ) - 1 )
	{
		trap_FS_FCloseFile( f );
		G_Printf( S_COLOR_RED "ERROR: map rotation file %s is %s\n", fileName,
		          len == 0 ? "empty" : "too long" );
		return qfalse;
	}

	trap_FS_Read( text, len, f );
	text[ len ] = 0;
	trap_FS_FCloseFile( f );

	// parse the text
	text_p = text;

	// read optional parameters
	while ( 1 )
	{
		token = COM_Parse( &text_p );

		if ( !*token )
		{
			break;
		}

		if ( !Q_stricmp( token, "" ) )
		{
			break;
		}

		if ( !Q_stricmp( token, "{" ) )
		{
			if ( mrNameSet )
			{
				//check for name space clashes
				if ( G_RotationExists( mrName ) )
				{
					G_Printf( S_COLOR_RED "ERROR: a map rotation is already named %s\n", mrName );
					return qfalse;
				}

				if ( mapRotations.numRotations == MAX_MAP_ROTATIONS )
				{
					G_Printf( S_COLOR_RED "ERROR: maximum number of map rotations (%d) reached\n",
					          MAX_MAP_ROTATIONS );
					return qfalse;
				}

				Q_strncpyz( mapRotations.rotations[ mapRotations.numRotations ].name, mrName, MAX_QPATH );

				if ( !G_ParseMapRotation( &mapRotations.rotations[ mapRotations.numRotations ], &text_p ) )
				{
					G_Printf( S_COLOR_RED "ERROR: %s: failed to parse map rotation %s\n", fileName, mrName );
					return qfalse;
				}

				mapRotations.numRotations++;

				//start parsing map rotations again
				mrNameSet = qfalse;

				continue;
			}
			else
			{
				G_Printf( S_COLOR_RED "ERROR: unnamed map rotation\n" );
				return qfalse;
			}
		}

		if ( !mrNameSet )
		{
			Q_strncpyz( mrName, token, sizeof( mrName ) );
			mrNameSet = qtrue;
		}
		else
		{
			G_Printf( S_COLOR_RED "ERROR: map rotation already named\n" );
			return qfalse;
		}
	}

	for ( i = 0; i < mapRotations.numRotations; i++ )
	{
		mapRotation_t *mr = &mapRotations.rotations[ i ];
		int           mapCount = 0;

		for ( j = 0; j < mr->numNodes; j++ )
		{
			node_t *node = mr->nodes[ j ];

			if ( node->type == NT_MAP )
			{
				mapCount++;

				if ( !G_MapExists( node->u.map.name ) )
				{
					G_Printf( S_COLOR_RED "ERROR: rotation map \"%s\" doesn't exist\n",
					          node->u.map.name );
					return qfalse;
				}

				continue;
			}
			else if ( node->type == NT_RETURN )
			{
				continue;
			}
			else if ( node->type == NT_LABEL )
			{
				continue;
			}
			else
			{
				while ( node->type == NT_CONDITION )
				{
					node = node->u.condition.target;
				}
			}

			if ( ( node->type == NT_GOTO || node->type == NT_RESUME ) &&
			     !G_LabelExists( i, node->u.label.name ) &&
			     !G_RotationExists( node->u.label.name ) )
			{
				G_Printf( S_COLOR_RED "ERROR: goto destination named \"%s\" doesn't exist\n",
				          node->u.label.name );
				return qfalse;
			}
		}

		if ( mapCount == 0 )
		{
			G_Printf( S_COLOR_RED "ERROR: rotation \"%s\" needs at least one map entry\n",
			          mr->name );
			return qfalse;
		}
	}

	return qtrue;
}
Exemple #9
0
void Script_ConditionalScript(itemDef_t *item, qboolean *bAbort, char **args)
{
	const char *cvar;
	const char *script1;
	const char *script2;
	const char *token;
	int        testtype;  // 0: check val not 0
	// 1: check cvar not empty
	int testval;

	if (String_Parse(args, &cvar) &&
	    Int_Parse(args, &testtype) &&
	    String_Parse(args, &token) && (token && *token == '(') &&
	    String_Parse(args, &script1) &&
	    String_Parse(args, &token) && (token && *token == ')') &&
	    String_Parse(args, &token) && (token && *token == '(') &&
	    String_Parse(args, &script2) &&
	    String_Parse(args, &token) && (token && *token == ')'))
	{
		float val;

		switch (testtype)
		{
		default:
		case 0:
			val = DC->getCVarValue(cvar);
			if (val == 0.f)
			{
				Item_RunScript(item, bAbort, script2);
			}
			else
			{
				Item_RunScript(item, bAbort, script1);
			}
			break;
		case 1:
		{
			char buff[1024];

			DC->getCVarString(cvar, buff, sizeof(buff));
			if (!buff[0])
			{
				Item_RunScript(item, bAbort, script2);
			}
			else
			{
				Item_RunScript(item, bAbort, script1);
			}
		}
		break;
		case 3:
			if (Int_Parse(args, &testval))
			{
				int testVal;

				val     = DC->getCVarValue(cvar);
				testVal = (int)val;
				if (testVal != testval)
				{
					Item_RunScript(item, bAbort, script2);
				}
				else
				{
					Item_RunScript(item, bAbort, script1);
				}
			}
			break;
		case 2:
			// special tests
			if (!Q_stricmp(cvar, "UIProfileIsActiveProfile"))
			{
				char ui_profileStr[256];
				char cl_profileStr[256];

				DC->getCVarString("ui_profile", ui_profileStr, sizeof(ui_profileStr));
				Q_CleanStr(ui_profileStr);
				Q_CleanDirName(ui_profileStr);

				DC->getCVarString("cl_profile", cl_profileStr, sizeof(cl_profileStr));

				if (!Q_stricmp(ui_profileStr, cl_profileStr))
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
			}
			else if (!Q_stricmp(cvar, "UIProfileValidName"))
			{
				char ui_profileStr[256];
				char ui_profileCleanedStr[256];

				DC->getCVarString("ui_profile", ui_profileStr, sizeof(ui_profileStr));
				Q_strncpyz(ui_profileCleanedStr, ui_profileStr, sizeof(ui_profileCleanedStr));
				Q_CleanStr(ui_profileCleanedStr);
				Q_CleanDirName(ui_profileCleanedStr);

				if (*ui_profileStr && *ui_profileCleanedStr)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}

			}
			else if (!Q_stricmp(cvar, "UIProfileAlreadyExists"))
			{
				char         ui_profileCleanedStr[256];
				qboolean     alreadyExists = qfalse;
				fileHandle_t f;

				DC->getCVarString("ui_profile", ui_profileCleanedStr, sizeof(ui_profileCleanedStr));
				Q_CleanStr(ui_profileCleanedStr);
				Q_CleanDirName(ui_profileCleanedStr);

				if (trap_FS_FOpenFile(va("profiles/%s/profile.dat", ui_profileCleanedStr), &f, FS_READ) >= 0)
				{
					alreadyExists = qtrue;
					trap_FS_FCloseFile(f);
				}

				if (alreadyExists)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
			}
			else if (!Q_stricmp(cvar, "UIProfileAlreadyExists_Rename"))
			{
				char         ui_profileCleanedStr[256];
				qboolean     alreadyExists = qfalse;
				fileHandle_t f;

				DC->getCVarString("ui_profile_renameto", ui_profileCleanedStr, sizeof(ui_profileCleanedStr));
				Q_CleanStr(ui_profileCleanedStr);
				Q_CleanDirName(ui_profileCleanedStr);

				if (trap_FS_FOpenFile(va("profiles/%s/profile.dat", ui_profileCleanedStr), &f, FS_READ) >= 0)
				{
					alreadyExists = qtrue;
					trap_FS_FCloseFile(f);
				}

				if (alreadyExists)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
			}
			else if (!Q_stricmp(cvar, "ReadyToCreateProfile"))
			{
				char         ui_profileStr[256], ui_profileCleanedStr[256];
				int          ui_rate;
				qboolean     alreadyExists = qfalse;
				fileHandle_t f;

				DC->getCVarString("ui_profile", ui_profileStr, sizeof(ui_profileStr));

				Q_strncpyz(ui_profileCleanedStr, ui_profileStr, sizeof(ui_profileCleanedStr));
				Q_CleanStr(ui_profileCleanedStr);
				Q_CleanDirName(ui_profileCleanedStr);

				if (trap_FS_FOpenFile(va("profiles/%s/profile.dat", ui_profileCleanedStr), &f, FS_READ) >= 0)
				{
					alreadyExists = qtrue;
					trap_FS_FCloseFile(f);
				}

				ui_rate = (int)DC->getCVarValue("ui_rate");

				if (!alreadyExists && *ui_profileStr && ui_rate > 0)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
			}
			else if (!Q_stricmp(cvar, "vidrestartIsRequired"))
			{
				int  ui_r_mode                           = DC->getCVarValue("ui_r_mode");
				int  ui_r_colorbits                      = DC->getCVarValue("ui_r_colorbits");
				int  ui_r_fullscreen                     = DC->getCVarValue("ui_r_fullscreen");
				int  ui_r_noborder                       = DC->getCVarValue("ui_r_noborder");
				int  ui_r_texturebits                    = DC->getCVarValue("ui_r_texturebits");
				int  ui_r_depthbits                      = DC->getCVarValue("ui_r_depthbits");
				int  ui_r_ext_compressed_textures        = DC->getCVarValue("ui_r_ext_compressed_textures");
				int  ui_r_allowextensions                = DC->getCVarValue("ui_r_allowextensions");
				int  ui_s_khz                            = DC->getCVarValue("ui_s_khz");
				int  ui_r_detailtextures                 = DC->getCVarValue("ui_r_detailtextures");
				int  ui_r_subdivisions                   = DC->getCVarValue("ui_r_subdivisions");
				int  ui_r_ext_texture_filter_anisotropic = DC->getCVarValue("ui_r_ext_texture_filter_anisotropic");
				int  ui_cg_shadows                       = DC->getCVarValue("ui_cg_shadows");
				char ui_r_texturemode[MAX_CVAR_VALUE_STRING];

				int  r_mode                           = DC->getCVarValue("r_mode");
				int  r_colorbits                      = DC->getCVarValue("r_colorbits");
				int  r_fullscreen                     = DC->getCVarValue("r_fullscreen");
				int  r_noborder                       = DC->getCVarValue("r_noborder");
				int  r_texturebits                    = DC->getCVarValue("r_texturebits");
				int  r_depthbits                      = DC->getCVarValue("r_depthbits");
				int  r_ext_compressed_textures        = DC->getCVarValue("r_ext_compressed_textures");
				int  r_allowextensions                = DC->getCVarValue("r_allowextensions");
				int  s_khz                            = DC->getCVarValue("s_khz");
				int  r_detailtextures                 = DC->getCVarValue("r_detailtextures");
				int  r_subdivisions                   = DC->getCVarValue("r_subdivisions");
				int  r_ext_texture_filter_anisotropic = DC->getCVarValue("r_ext_texture_filter_anisotropic");
				int  cg_shadows                       = DC->getCVarValue("cg_shadows");
				char r_texturemode[MAX_CVAR_VALUE_STRING];

				trap_Cvar_VariableStringBuffer("ui_r_texturemode", ui_r_texturemode, sizeof(ui_r_texturemode));
				trap_Cvar_VariableStringBuffer("r_texturemode", r_texturemode, sizeof(r_texturemode));

				if (ui_r_subdivisions != r_subdivisions ||
				    ui_r_mode != r_mode ||
				    ui_r_colorbits != r_colorbits ||
				    ui_r_fullscreen != r_fullscreen ||
				    ui_r_noborder != r_noborder ||
				    ui_r_texturebits != r_texturebits ||
				    ui_r_depthbits != r_depthbits ||
				    ui_r_ext_compressed_textures != r_ext_compressed_textures ||
				    ui_r_allowextensions != r_allowextensions ||
				    ui_s_khz != s_khz ||
				    ui_r_detailtextures != r_detailtextures ||
				    ui_r_ext_texture_filter_anisotropic != r_ext_texture_filter_anisotropic ||
				    ui_cg_shadows != cg_shadows ||
				    Q_stricmp(r_texturemode, ui_r_texturemode))
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
				/*} else if( !Q_stricmpn( cvar, "voteflags", 9 ) ) {
				char info[MAX_INFO_STRING];
				int voteflags = atoi(cvar + 9);

				trap_Cvar_VariableStringBuffer( "cg_ui_voteFlags", info, sizeof(info) );

				if( (atoi(info) & item->voteFlag) != item->voteFlag ) {
				Item_RunScript( item, bAbort, script1 );
				} else {
				Item_RunScript( item, bAbort, script2 );
				}*/
#ifndef CGAMEDLL
			}
			else if (!Q_stricmpn(cvar, "serversort_", 11))
			{
				int sorttype = atoi(cvar + 11);

				if (sorttype != uiInfo.serverStatus.sortKey)
				{
					Item_RunScript(item, bAbort, script2);
				}
				else
				{
					Item_RunScript(item, bAbort, script1);
				}
			}
			else if (!Q_stricmp(cvar, "ValidReplaySelected"))
			{
				if (uiInfo.demoIndex >= 0 && uiInfo.demoIndex < uiInfo.demoCount)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					Item_RunScript(item, bAbort, script2);
				}
#endif // !CGAMEDLL
			}
			else if (!Q_stricmp(cvar, "ROldModeCheck"))
			{
				char r_oldModeStr[256];
				int  r_oldMode;
				int  r_mode = DC->getCVarValue("r_mode");

				DC->getCVarString("r_oldMode", r_oldModeStr, sizeof(r_oldModeStr));
				r_oldMode = atoi(r_oldModeStr);

				if (*r_oldModeStr && r_oldMode != r_mode)
				{
					Item_RunScript(item, bAbort, script1);
				}
				else
				{
					if (r_oldMode == r_mode)
					{
						trap_Cvar_Set("r_oldMode", "");   // clear it
					}

					Item_RunScript(item, bAbort, script2);
				}
			}

			break;
		}
	}
}
Exemple #10
0
/*
* CG_SaveRecamScriptFile
*/
void CG_SaveRecamScriptFile( const char *filename ) {
	cg_democam_t *cam;
	cg_subtitle_t *sub;
	int filehandle;
	char str[256];

	if( !cg_cams_headnode && !cg_subs_headnode ) {
		CG_Printf( "CG_SaveRecamScriptFile: no cameras nor subtitles to save\n" );
		return;
	}

	if( !filename ) {
		filename = demoscriptname;
		if( !filename ) {
			return;
		}
	}

	if( trap_FS_FOpenFile( filename, &filehandle, FS_WRITE ) == -1 ) {
		CG_Printf( "CG_SaveRecamScriptFile: Couldn't create the file %s\n", demoscriptname );
		return;
	}

	Q_snprintfz( str, sizeof( str ), "// cam script file generated by %s\n", trap_Cvar_String( "gamename" ) );
	trap_FS_Print( filehandle, str );

	Q_snprintfz( str, sizeof( str ), "// demo start time: %" PRIi64 "\n", demo_initial_timestamp );
	trap_FS_Print( filehandle, str );

	cam = cg_cams_headnode;
	while( cam != NULL ) {
		Q_snprintfz( str, sizeof( str ), "%i %" PRIi64" %.2f %.2f %.2f %.2f %.2f %.2f %i %i\n",
					 cam->type,
					 cam->timeStamp,
					 cam->origin[0],
					 cam->origin[1],
					 cam->origin[2],
					 cam->angles[0],
					 cam->angles[1],
					 cam->angles[2],
					 cam->trackEnt,
					 cam->fov
					 );
		trap_FS_Print( filehandle, str );
		cam = cam->next;
	}

	sub = cg_subs_headnode;
	while( sub != NULL ) {
		Q_snprintfz( str, sizeof( str ), "%s %" PRIi64 " %" PRIi64 " ",
					 sub->highprint ? "print" : "subtitle",
					 sub->timeStamp,
					 sub->maxDuration
					 );
		trap_FS_Print( filehandle, str );
		trap_FS_Print( filehandle, "\"" );
		trap_FS_Print( filehandle, sub->text ? sub->text : "" );
		trap_FS_Print( filehandle, "\"\n" );
		sub = sub->next;
	}

	trap_FS_FCloseFile( filehandle );
	CG_Printf( "cam file saved\n" );
}
Exemple #11
0
/*
* S_ReadPlaylistFile
*/
static bgTrack_t *S_ReadPlaylistFile( const char *filename, bool shuffle, bool loop )
{
	int filenum, length;
	char *tmpname = 0;
	size_t tmpname_size = 0;
	char *data, *line, *entry;
	playlistItem_t items[MAX_PLAYLIST_ITEMS];
	int i, numItems = 0;

	length = trap_FS_FOpenFile( filename, &filenum, FS_READ );
	if( length < 0 )
		return NULL;

	// load the playlist into memory
	data = S_Malloc( length + 1 );
	trap_FS_Read( data, length, filenum );
	trap_FS_FCloseFile( filenum );

	srand( time( NULL ) );

	while( *data )
	{
		size_t s;

		entry = data;

		// read the whole line
		for( line = data; *line != '\0' && *line != '\n'; line++ );

		// continue reading from the next character, if possible
		data = (*line == '\0' ? line : line + 1);

		*line = '\0';

		// trim whitespaces, tabs, etc
		entry = Q_trim( entry );

		// special M3U entry or comment
		if( !*entry || *entry == '#' )
			continue;

		if( trap_FS_IsUrl( entry ) )
		{
			items[numItems].track = S_AllocTrack( entry );
		}
		else
		{
			// append the entry name to playlist path
			s = strlen( filename ) + 1 + strlen( entry ) + 1;
			if( s > tmpname_size )
			{
				if( tmpname )
					S_Free( tmpname );
				tmpname_size = s;
				tmpname = S_Malloc( tmpname_size );
			}

			Q_strncpyz( tmpname, filename, tmpname_size );
			COM_StripFilename( tmpname );
			Q_strncatz( tmpname, "/", tmpname_size );
			Q_strncatz( tmpname, entry, tmpname_size );
			COM_SanitizeFilePath( tmpname );

			items[numItems].track = S_AllocTrack( tmpname );
		}

		if( ++numItems == MAX_PLAYLIST_ITEMS )
			break;
	}

	if( tmpname )
	{
		S_Free( tmpname );
		tmpname = NULL;
	}

	if( !numItems )
		return NULL;

	// set the playing order
	for( i = 0; i < numItems; i++ )
		items[i].order = (shuffle ? (rand() % numItems) : i);

	// sort the playlist
	R_SortPlaylistItems( numItems, items );

	// link the playlist
	for( i = 1; i < numItems; i++ )
	{
		items[i-1].track->next = items[i].track;
		items[i].track->prev = items[i-1].track;
		items[i].track->loop = loop;
	}
	items[numItems-1].track->next = items[0].track;
	items[0].track->prev = items[numItems-1].track;
	items[0].track->loop = loop;

	return items[0].track;
}
Exemple #12
0
/*
* CG_LoadRecamScriptFile
*/
bool CG_LoadRecamScriptFile( char *filename ) {
	int filelen, filehandle;
	uint8_t *buf = NULL;
	char *ptr, *token;
	int linecount;
	cg_democam_t *cam = NULL;

	if( !filename ) {
		CG_Printf( "CG_LoadRecamScriptFile: no filename\n" );
		return false;
	}

	filelen = trap_FS_FOpenFile( filename, &filehandle, FS_READ );
	if( !filehandle || filelen < 1 ) {
		trap_FS_FCloseFile( filehandle );
	} else {
		buf = ( uint8_t * )CG_Malloc( filelen + 1 );
		filelen = trap_FS_Read( buf, filelen, filehandle );
		trap_FS_FCloseFile( filehandle );
	}

	if( !buf ) {
		return false;
	}

	// parse the script
	linecount = 0;
	ptr = ( char * )buf;
	while( ptr ) {
		token = COM_ParseExt( &ptr, true );
		if( !token[0] ) {
			break;
		}

		if( !Q_stricmp( token, "subtitle" ) || !Q_stricmp( token, "print" ) ) {
			cg_subtitle_t *sub;

			sub = CG_Democam_RegisterSubtitle();
			sub->highprint = ( Q_stricmp( token, "print" ) == 0 );

			token = COM_ParseExt( &ptr, true );
			if( !token[0] ) {
				break;
			}
			sub->timeStamp = (unsigned int)atoi( token );
			token = COM_ParseExt( &ptr, true );
			if( !token[0] ) {
				break;
			}
			sub->maxDuration = (unsigned int)atoi( token );
			sub->text = CG_CopyString( COM_ParseExt( &ptr, true ) );

			linecount = 0;
		} else {
			switch( linecount ) {
				case 0:
					cam = CG_Democam_RegisterCam( atoi( token ) );
					break;
				case 1:
					cam->timeStamp = (unsigned int)atoi( token );
					break;
				case 2:
					cam->origin[0] = atof( token );
					break;
				case 3:
					cam->origin[1] = atof( token );
					break;
				case 4:
					cam->origin[2] = atof( token );
					break;
				case 5:
					cam->angles[0] = atof( token );
					break;
				case 6:
					cam->angles[1] = atof( token );
					break;
				case 7:
					cam->angles[2] = atof( token );
					break;
				case 8:
					cam->trackEnt = atoi( token );
					break;
				case 9:
					cam->fov = atoi( token );
					break;
				default:
					CG_Error( "CG_LoadRecamScriptFile: bad switch\n" );
			}

			linecount++;
			if( linecount == 10 ) {
				linecount = 0;
			}
		}
	}

	CG_Free( buf );
	if( linecount != 0 ) {
		CG_Printf( "CG_LoadRecamScriptFile: Invalid script. Ignored\n" );
		CG_Democam_FreeCams();
		CG_Democam_FreeSubtitles();
		return false;
	}

	CG_Democam_ExecutePathAnalysis();
	return true;
}
Exemple #13
0
qboolean G_ParseMapSettings(int handle, config_t *config)
{
	pc_token_t token;
	char       serverinfo[MAX_INFO_STRING];
	char       *mapname;

	trap_GetServerinfo(serverinfo, sizeof(serverinfo));
	mapname = Info_ValueForKey(serverinfo, "mapname");

	if (!trap_PC_ReadToken(handle, &token))
	{
		G_Printf("Malformed map config\n");
	}

	G_Printf("Map settings for: %s\n", token.string);
	G_Printf("Current map: %s\n", mapname);

	if (!Q_stricmp(token.string, "default"))
	{
		G_Printf("Setting rules for map: %s\n", token.string);
		return G_ParseSettings(handle, qtrue, config);
	}
	else if (!Q_stricmp(token.string, mapname))
	{
		fileHandle_t f;
		char         *code, *signature;
		qboolean     res;

		G_Printf("Setting rules for map: %s\n", token.string);
		res = G_ParseSettings(handle, qtrue, config);
		if (res && strlen(config->mapscripthash))
		{
			char sdir[MAX_QPATH];
			int  flen = 0;

			trap_Cvar_VariableStringBuffer("g_mapScriptDirectory", sdir, sizeof(sdir));

			flen = trap_FS_FOpenFile(va("%s/%s.script", sdir, mapname), &f, FS_READ);
			if (flen < 0)
			{
				// FIXME: handle this properly..
				//return G_ConfigError(handle, "Cannot open mapscript file for hash verification: %s/%s.script", sdir, mapname);
				G_Printf("Cannot open mapscript file for hash verification: %s/%s.script", sdir, mapname);
				return res;
			}

			code = malloc(flen + 1);
			trap_FS_Read(code, flen, f);
			*(code + flen) = '\0';
			trap_FS_FCloseFile(f);
			signature = G_SHA1(code);

			free(code);

			if (Q_stricmp(config->mapscripthash, signature))
			{
				return G_ConfigError(handle, "Invalid mapscript hash for map: %s hash given in config: \"%s\" scripts actual hash \"%s\"", mapname, config->mapscripthash, signature);
			}

			G_Printf("Hash is valid for map: %s\n", mapname);
		}

		return res;
	}
	else
	{
		G_Printf("Ignoring rules for map: %s\n", token.string);
		return G_ParseSettings(handle, qfalse, config);
	}
}
/*
===============
CG_ParseTrailFile

Load the trail systems from a trail file
===============
*/
static bool CG_ParseTrailFile( const char *fileName )
{
	const char         *text_p;
	int          i;
	int          len;
	char         *token;
	char         text[ 32000 ];
	char         tsName[ MAX_QPATH ];
	bool     tsNameSet = false;
	fileHandle_t f;

	// load the file
	len = trap_FS_FOpenFile( fileName, &f, fsMode_t::FS_READ );

	if ( len <= 0 )
	{
		return false;
	}

	if ( len == 0 || len + 1 >= (int) sizeof( text ) )
	{
		trap_FS_FCloseFile( f );
		Log::Warn( len ? "trail file %s is too long" : "trail file %s is empty", fileName );
		return false;
	}

	trap_FS_Read( text, len, f );
	text[ len ] = 0;
	trap_FS_FCloseFile( f );

	// parse the text
	text_p = text;

	// read optional parameters
	while ( 1 )
	{
		token = COM_Parse( &text_p );

		if ( !*token )
		{
			break;
		}

		if ( !Q_stricmp( token, "{" ) )
		{
			if ( tsNameSet )
			{
				//check for name space clashes
				for ( i = 0; i < numBaseTrailSystems; i++ )
				{
					if ( !Q_stricmp( baseTrailSystems[ i ].name, tsName ) )
					{
						Log::Warn( "a trail system is already named %s", tsName );
						return false;
					}
				}

				Q_strncpyz( baseTrailSystems[ numBaseTrailSystems ].name, tsName, MAX_QPATH );

				if ( !CG_ParseTrailSystem( &baseTrailSystems[ numBaseTrailSystems ], &text_p, tsName ) )
				{
					Log::Warn( "%s: failed to parse trail system %s", fileName, tsName );
					return false;
				}

				//start parsing trail systems again
				tsNameSet = false;

				if ( numBaseTrailSystems == MAX_BASETRAIL_SYSTEMS )
				{
					Log::Warn( "maximum number of trail systems (%d) reached",
					           MAX_BASETRAIL_SYSTEMS );
					return false;
				}
				else
				{
					numBaseTrailSystems++;
				}

				continue;
			}
			else
			{
				Log::Warn( "unnamed trail system" );
				return false;
			}
		}

		if ( !tsNameSet )
		{
			Q_strncpyz( tsName, token, sizeof( tsName ) );
			tsNameSet = true;
		}
		else
		{
			Log::Warn( "trail system already named" );
			return false;
		}
	}

	return true;
}
Exemple #15
0
void UI_SaberLoadParms( void ) 
{
	int			len, totallen, saberExtFNLen, fileCnt, i;
	char		*holdChar, *marker;
	char		saberExtensionListBuf[2048];			//	The list of file names read in
	fileHandle_t f;
	char buffer[MAX_MENUFILE];
	
	//[DynamicMemory_Sabers]
#ifdef DYNAMICMEMORY_SABERS
	int maxLen;
#endif
	//[/DynamicMemory_Sabers]

	//ui.Printf( "UI Parsing *.sab saber definitions\n" );
	
	ui_saber_parms_parsed = qtrue;
	UI_CacheSaberGlowGraphics();

//[DynamicMemory_Sabers] moved down lower
	/*
	//set where to store the first one
	totallen = 0;
	marker = SaberParms;
	marker[0] = '\0';
	*/

	//we werent initilizing saberExtFNLen, which is Bad
	//this is just a general bug fix, not for the purpose of [DynamicMemory_Sabers]
	saberExtFNLen = 0;
///[DynamicMemory_Sabers]


	//now load in the extra .npc extensions
	fileCnt = trap_FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) );

	holdChar = saberExtensionListBuf;

//[DynamicMemory_Sabers]
#ifdef DYNAMICMEMORY_SABERS
	maxLen = 0;
	saberExtFNLen = -1;
	for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) {
		saberExtFNLen = strlen( holdChar );
		len = trap_FS_FOpenFile( va( "ext_data/sabers/%s", holdChar), &f, FS_READ );
		if(!f)
			continue;
		trap_FS_FCloseFile(f);
		maxLen += len;
	}
	//what do we do if totallen is zero?  will never happen, but COULD happen in theory...
	//trap_TrueMalloc(&SaberParms, totallen+1); //+1 for null char, needed?
	maxLen++; //for ending null char
	UI_AllocMem(&SaberParms, maxLen);
	if(!SaberParms)
		//ERR_FATAL or any level isnt used with Com_Error
		Com_Error(ERR_FATAL, "Saber parsing: Out of memory!");
	holdChar = saberExtensionListBuf;
#endif
//[/DynamicMemory_Sabers]

//[DynamicMemory_Sabers] moved to here
	//set where to store the first one
	totallen = 0;
	marker = SaberParms;
	marker[0] = '\0';

	saberExtFNLen = -1;
///[DynamicMemory_Sabers]

	for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) 
	{
		saberExtFNLen = strlen( holdChar );

		len = trap_FS_FOpenFile( va( "ext_data/sabers/%s", holdChar), &f, FS_READ );

		if (!f)
		{
			continue;
		}

		if ( len == -1 ) 
		{
			Com_Printf( "UI_SaberLoadParms: error reading %s\n", holdChar );
		}
		else
		{
			if (len > sizeof(buffer) )
			{
				Com_Error( ERR_FATAL, "UI_SaberLoadParms: file %s too large to read (max=%d)", holdChar, sizeof(buffer) );
			}
			trap_FS_Read( buffer, len, f );
			trap_FS_FCloseFile( f );
			buffer[len] = 0;

			if ( totallen && *(marker-1) == '}' )
			{//don't let it end on a } because that should be a stand-alone token
				strcat( marker, " " );
				totallen++;
				marker++; 
			}
			len = COM_Compress( buffer );

//[DynamicMemory_Sabers]
#ifndef DYNAMICMEMORY_SABERS
			if ( totallen + len >= MAX_SABER_DATA_SIZE ) {
				Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .sab files smaller)", holdChar );
			}
#else
			if ( totallen + len >= maxLen ) {
				Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(This should never happen)", holdChar );
			}
#endif
//[/DynamicMemory_Sabers]
			strcat( marker, buffer );

			totallen += len;
			marker += len;
		}
	}
}
Exemple #16
0
/*
===============
G_ParseMapRotationFile

Load the map rotations from a map rotation file
===============
*/
static qboolean G_ParseMapRotationFile( const char *fileName )
{
  char          *text_p;
  int           i, j, k;
  int           len;
  char          *token;
  char          text[ 20000 ];
  char          mrName[ MAX_QPATH ];
  qboolean      mrNameSet = qfalse;
  fileHandle_t  f;

  // load the file
  len = trap_FS_FOpenFile( fileName, &f, FS_READ );
  if( len < 0 )
    return qfalse;

  if( len == 0 || len >= sizeof( text ) - 1 )
  {
    trap_FS_FCloseFile( f );
    G_Printf( S_COLOR_RED "ERROR: map rotation file %s is %s\n", fileName,
      len == 0 ? "empty" : "too long" );
    return qfalse;
  }

  trap_FS_Read( text, len, f );
  text[ len ] = 0;
  trap_FS_FCloseFile( f );

  // parse the text
  text_p = text;

  // read optional parameters
  while( 1 )
  {
    token = COM_Parse( &text_p );

    if( !token )
      break;

    if( !Q_stricmp( token, "" ) )
      break;

    if( !Q_stricmp( token, "{" ) )
    {
      if( mrNameSet )
      {
        //check for name space clashes
        for( i = 0; i < mapRotations.numRotations; i++ )
        {
          if( !Q_stricmp( mapRotations.rotations[ i ].name, mrName ) )
          {
            G_Printf( S_COLOR_RED "ERROR: a map rotation is already named %s\n", mrName );
            return qfalse;
          }
        }

        if( mapRotations.numRotations == MAX_MAP_ROTATIONS )
        {
          G_Printf( S_COLOR_RED "ERROR: maximum number of map rotations (%d) reached\n",
                    MAX_MAP_ROTATIONS );
          return qfalse;
        }

        Q_strncpyz( mapRotations.rotations[ mapRotations.numRotations ].name, mrName, MAX_QPATH );

        if( !G_ParseMapRotation( &mapRotations.rotations[ mapRotations.numRotations ], &text_p ) )
        {
          G_Printf( S_COLOR_RED "ERROR: %s: failed to parse map rotation %s\n", fileName, mrName );
          return qfalse;
        }

        mapRotations.numRotations++;

        //start parsing map rotations again
        mrNameSet = qfalse;

        continue;
      }
      else
      {
        G_Printf( S_COLOR_RED "ERROR: unnamed map rotation\n" );
        return qfalse;
      }
    }

    if( !mrNameSet )
    {
      Q_strncpyz( mrName, token, sizeof( mrName ) );
      mrNameSet = qtrue;
    }
    else
    {
      G_Printf( S_COLOR_RED "ERROR: map rotation already named\n" );
      return qfalse;
    }
  }

  for( i = 0; i < mapRotations.numRotations; i++ )
  {
    for( j = 0; j < mapRotations.rotations[ i ].numMaps; j++ )
    {
      if( !G_MapExists( mapRotations.rotations[ i ].maps[ j ].name ) )
      {
        G_Printf( S_COLOR_RED "ERROR: map \"%s\" doesn't exist\n",
          mapRotations.rotations[ i ].maps[ j ].name );
        return qfalse;
      }

      for( k = 0; k < mapRotations.rotations[ i ].maps[ j ].numConditions; k++ )
      {
        if( !G_MapExists( mapRotations.rotations[ i ].maps[ j ].conditions[ k ].dest ) &&
            !G_RotationExists( mapRotations.rotations[ i ].maps[ j ].conditions[ k ].dest ) )
        {
          G_Printf( S_COLOR_RED "ERROR: conditional destination \"%s\" doesn't exist\n",
            mapRotations.rotations[ i ].maps[ j ].conditions[ k ].dest );
          return qfalse;
        }

      }

    }
  }

  return qtrue;
}
Exemple #17
0
void CG_LoadLensFlareEntities(void) {
	char name[256];
	fileHandle_t f;
	int len;
	char* p;

#if LFDEBUG
	CG_LoadingString("LF: CG_LoadLensFlareEntities()");
#endif
	cgs.numLensFlareEntities = 0;
	memset(&cgs.lensFlareEntities, 0, sizeof(cgs.lensFlareEntities));

	if (cgs.sunFlareEffect[0]) {
		lensFlareEntity_t* lfent;
		vec3_t angles;
		vec3_t sunDir;

		lfent = &cgs.sunFlare;

		lfent->lfeff = CG_FindLensFlareEffect(cgs.sunFlareEffect);
		if (!lfent->lfeff) {
			CG_Printf(S_COLOR_YELLOW "undefined sun flare effect '%s'\n", cgs.sunFlareEffect);
		}

		angles[YAW] = cgs.sunFlareYaw;
		angles[PITCH] = -cgs.sunFlarePitch;
		angles[ROLL] = 0;
		AngleVectors(angles, sunDir, NULL, NULL);
		VectorScale(sunDir, cgs.sunFlareDistance, lfent->origin);

		lfent->radius = 150;
		lfent->lightRadius = 100;
		lfent->angle = -1;

		CG_ComputeMaxVisAngle(lfent);

		CG_Printf("sun flare entity created\n");
	}

	Com_sprintf(name, sizeof(name), "maps/%s.lfe", Info_ValueForKey(CG_ConfigString(CS_SERVERINFO), "mapname"));

	len = trap_FS_FOpenFile(name, &f, FS_READ);
	if (!f) {
		CG_Printf("'%s' not found\n", name);
		return;
	}
	if (len >= sizeof(lfbuf)) {
		CG_Printf(S_COLOR_YELLOW "file too large: '%s' > %d\n", name, sizeof(lfbuf)-1);
		return;
	}
	CG_Printf("reading '%s'...\n", name);
#if LFDEBUG
	CG_LoadingString(va("%s", name));
#endif

	trap_FS_Read(lfbuf, len, f);
	lfbuf[len] = 0;
	trap_FS_FCloseFile(f);

	COM_Compress(lfbuf);

	p = lfbuf;

	// parse all lens flare entities
	while (cgs.numLensFlareEntities < MAX_LIGHTS_PER_MAP && p) {
		if (!CG_ParseLensFlareEntity(&p, &cgs.lensFlareEntities[cgs.numLensFlareEntities])) {
			break;
		}
		cgs.numLensFlareEntities++;
	}

	CG_Printf("%d lens flare entities loaded\n", cgs.numLensFlareEntities);
#if LFDEBUG
	CG_LoadingString("LF: CG_LoadLensFlareEntities() ready");
#endif
}
Exemple #18
0
void BotUtilizePersonality(bot_state_t *bs)
{
	fileHandle_t f;
	int len, rlen;
	int failed;
	int i;
	//char buf[131072];
	char *buf = (char *)B_TempAlloc(131072);
	char *readbuf, *group;

	len = trap_FS_FOpenFile(bs->settings.personalityfile, &f, FS_READ);

	failed = 0;

	if (!f)
	{
		G_Printf(S_COLOR_RED "Error: Specified personality not found\n");
		B_TempFree(131072); //buf
		return;
	}

	if (len >= 131072)
	{
		G_Printf(S_COLOR_RED "Personality file exceeds maximum length\n");
		B_TempFree(131072); //buf
		return;
	}

	trap_FS_Read(buf, len, f);

	rlen = len;

	while (len < 131072)
	{ //kill all characters after the file length, since sometimes FS_Read doesn't do that entirely (or so it seems)
		buf[len] = '\0';
		len++;
	}

	len = rlen;

	readbuf = (char *)B_TempAlloc(1024);
	group = (char *)B_TempAlloc(65536);

	if (!GetValueGroup(buf, "GeneralBotInfo", group))
	{
		G_Printf(S_COLOR_RED "Personality file contains no GeneralBotInfo group\n");
		failed = 1; //set failed so we know to set everything to default values
	}

	if (!failed && GetPairedValue(group, "reflex", readbuf))
	{
		bs->skills.reflex = atoi(readbuf);
	}
	else
	{
		bs->skills.reflex = 100; //default
	}

	if (!failed && GetPairedValue(group, "accuracy", readbuf))
	{
		bs->skills.accuracy = atof(readbuf);
	}
	else
	{
		bs->skills.accuracy = 10; //default
	}

	if (!failed && GetPairedValue(group, "turnspeed", readbuf))
	{
		bs->skills.turnspeed = atof(readbuf);
	}
	else
	{
		bs->skills.turnspeed = 0.01f; //default
	}

	if (!failed && GetPairedValue(group, "turnspeed_combat", readbuf))
	{
		bs->skills.turnspeed_combat = atof(readbuf);
	}
	else
	{
		bs->skills.turnspeed_combat = 0.05f; //default
	}

	if (!failed && GetPairedValue(group, "maxturn", readbuf))
	{
		bs->skills.maxturn = atof(readbuf);
	}
	else
	{
		bs->skills.maxturn = 360; //default
	}

	if (!failed && GetPairedValue(group, "perfectaim", readbuf))
	{
		bs->skills.perfectaim = atoi(readbuf);
	}
	else
	{
		bs->skills.perfectaim = 0; //default
	}

	if (!failed && GetPairedValue(group, "chatability", readbuf))
	{
		bs->canChat = atoi(readbuf);
	}
	else
	{
		bs->canChat = 0; //default
	}

	if (!failed && GetPairedValue(group, "chatfrequency", readbuf))
	{
		bs->chatFrequency = atoi(readbuf);
	}
	else
	{
		bs->chatFrequency = 5; //default
	}

	if (!failed && GetPairedValue(group, "hatelevel", readbuf))
	{
		bs->loved_death_thresh = atoi(readbuf);
	}
	else
	{
		bs->loved_death_thresh = 3; //default
	}

	if (!failed && GetPairedValue(group, "camper", readbuf))
	{
		bs->isCamper = atoi(readbuf);
	}
	else
	{
		bs->isCamper = 0; //default
	}

	if (!failed && GetPairedValue(group, "saberspecialist", readbuf))
	{
		bs->saberSpecialist = atoi(readbuf);
	}
	else
	{
		bs->saberSpecialist = 0; //default
	}

	if (!failed && GetPairedValue(group, "forceinfo", readbuf))
	{
		Com_sprintf(bs->forceinfo, sizeof(bs->forceinfo), "%s\0", readbuf);
	}
	else
	{
		Com_sprintf(bs->forceinfo, sizeof(bs->forceinfo), "%s\0", DEFAULT_FORCEPOWERS);
	}

	i = 0;

	while (i < MAX_CHAT_BUFFER_SIZE)
	{ //clear out the chat buffer for this bot
		gBotChatBuffer[bs->client][i] = '\0';
		i++;
	}

	if (bs->canChat)
	{
		if (!ReadChatGroups(bs, buf))
		{
			bs->canChat = 0;
		}
	}

	if (GetValueGroup(buf, "BotWeaponWeights", group))
	{
		if (GetPairedValue(group, "WP_STUN_BATON", readbuf))
		{
			bs->botWeaponWeights[WP_STUN_BATON] = atoi(readbuf);
			bs->botWeaponWeights[WP_MELEE] = bs->botWeaponWeights[WP_STUN_BATON];
		}

		if (GetPairedValue(group, "WP_SABER", readbuf))
		{
			bs->botWeaponWeights[WP_SABER] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_BRYAR_PISTOL", readbuf))
		{
			bs->botWeaponWeights[WP_BRYAR_PISTOL] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_BLASTER", readbuf))
		{
			bs->botWeaponWeights[WP_BLASTER] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_DISRUPTOR", readbuf))
		{
			bs->botWeaponWeights[WP_DISRUPTOR] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_BOWCASTER", readbuf))
		{
			bs->botWeaponWeights[WP_BOWCASTER] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_REPEATER", readbuf))
		{
			bs->botWeaponWeights[WP_REPEATER] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_DEMP2", readbuf))
		{
			bs->botWeaponWeights[WP_DEMP2] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_FLECHETTE", readbuf))
		{
			bs->botWeaponWeights[WP_FLECHETTE] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_ROCKET_LAUNCHER", readbuf))
		{
			bs->botWeaponWeights[WP_ROCKET_LAUNCHER] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_THERMAL", readbuf))
		{
			bs->botWeaponWeights[WP_THERMAL] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_TRIP_MINE", readbuf))
		{
			bs->botWeaponWeights[WP_TRIP_MINE] = atoi(readbuf);
		}

		if (GetPairedValue(group, "WP_DET_PACK", readbuf))
		{
			bs->botWeaponWeights[WP_DET_PACK] = atoi(readbuf);
		}
	}

	bs->lovednum = 0;

	if (GetValueGroup(buf, "EmotionalAttachments", group))
	{
		ParseEmotionalAttachments(bs, group);
	}

	B_TempFree(131072); //buf
	B_TempFree(1024); //readbuf
	B_TempFree(65536); //group
	trap_FS_FCloseFile(f);
}
Exemple #19
0
static void UI_ManageDeckLoading( void )
{
	char			fileRoute[MAX_QPATH];
	char			mapRoute[MAX_QPATH];
	char			info[MAX_TOKEN_CHARS];
	fileHandle_t	f;
	int				file_len;
	char			*textPtr;
	char			buffer[20000];
	char			*token;

	//get the map name
	trap_GetConfigString( CS_SERVERINFO, info, sizeof( info ) );
	Com_sprintf( mapRoute, sizeof( fileRoute ), "maps/%s", Info_ValueForKey( info, "mapname" ) );

	//check for language
	UI_LanguageFilename( mapRoute, "turbolift", fileRoute );

	file_len = trap_FS_FOpenFile( fileRoute, &f, FS_READ );

	if ( file_len <= 1 )
	{
		//Com_Printf( S_COLOR_YELLOW "WARNING: Attempted to load %s, but wasn't found.\n", fileRoute );
		UI_TurboliftMenu_LoadDecks();
		return;
	}

	trap_FS_Read( buffer, file_len, f );
	trap_FS_FCloseFile( f );

	if ( !buffer[0] )
	{
		Com_Printf( S_COLOR_RED "ERROR: Attempted to load %s, but no data was read.\n", fileRoute );
		UI_TurboliftMenu_LoadDecks();
		return;
	}

	s_turbolift.numDecks = 0;
	memset( &s_turbolift.deckData, 0, sizeof( s_turbolift.deckData ) );
	buffer[file_len] = '\0';

	COM_BeginParseSession();
	textPtr = buffer;

	//Com_Printf( S_COLOR_RED "Beginning Parse\n" );

	//expected format is 'decknum' <space> 'deck Desc'
	while( 1 )
	{
		token = COM_Parse( &textPtr );
		if ( !token[0] )
			break;

		//Com_Printf( S_COLOR_RED "First Token: %s\n", token );

		//in case of Scooter's EF SP style DAT files, which require 'DECK' in front of the number
		if ( !Q_strncmp( token, "DECK", 4 ) )
			token += 4;

		//grab the deck number
		s_turbolift.deckData[s_turbolift.numDecks].deckNum = atoi( token );

		token = COM_ParseExt( &textPtr, qfalse );
		if (!token[0])
			continue;

		//Com_Printf( S_COLOR_RED "Second Token: %s\n", token );

		Q_strncpyz( s_turbolift.deckData[s_turbolift.numDecks].deckDesc, 
					token,
					sizeof( s_turbolift.deckData[s_turbolift.numDecks].deckDesc ) );

		s_turbolift.numDecks++;

		//if this is an EF SP style script, there may be more data after these two. ignore them
		if ( COM_ParseExt( &textPtr, qfalse ) == NULL )
			SkipRestOfLine( &textPtr );
	}

	qsort( s_turbolift.deckData, s_turbolift.numDecks, sizeof( deckData_t ), SortDecks );
}
Exemple #20
0
char* BG_RegisterRace( const char *name ) {
	char	*text_p;
	char	*token;
	int		len;
	fileHandle_t	f;
	char	text[MAX_GROUP_FILE_SIZE];
	gender_t theSex;

	memset (races, 0, sizeof(races));
	memset (text, 0, sizeof(text));

	// load and parse the skin file
	len = trap_FS_FOpenFile( name, &f, FS_READ );
	if ( !f ) {
		// if we didn't get a races file, use an empty one.
		Com_sprintf(races, sizeof(races), "unknown");
		return races;
	}
	if ( len >= sizeof( text ) - 1) 
	{
		Com_Printf( S_COLOR_RED "file too large: %s is %i, max allowed is %i", name, len, sizeof( text ) );
		trap_FS_FCloseFile( f );
		return races;
	}

	trap_FS_Read( text, len, f );
	trap_FS_FCloseFile( f );
	
	theSex = G_ParseAnimationFileSex(name);
	if (theSex == GENDER_MALE) {
		strcat(races, "Male,");
	} else if (theSex == GENDER_FEMALE) {
		strcat(races, "Female,");
	}

	text_p = text;
	while ( *text_p ) {
		// get surface name
		token = COM_Parse( &text_p );

		if ( !token[0] ) {
			break;
		}

		// if we about to break the races size list then dump us out
		if (strlen(races) + strlen(token) > 256) {
			break;
		}

		// add it into the race list
		strcat(races, token);
		// put a comma between the names
		strcat(races, ",");

		if ( *text_p == ',' ) {
			text_p++;
		}

		if (!Q_stricmp ("borg", token) ) {
			if (theSex == GENDER_MALE) {
				// add it into the race list
				strcat(races, "BorgMale,");
			} else if (theSex == GENDER_FEMALE) {
				strcat(races, "BorgFemale,");
			} else {
			}
		}

	}

	// just in case
	if (!races[0])
	{
		Com_sprintf(races, sizeof(races), "unknown");
	}
	else
	{	//lose the last comma
		races[strlen(races)-1] = 0;
	}

	return races;
}
Exemple #21
0
void CG_LoadHolsterData (clientInfo_t *ci)
{//adjusts the manual holster positional data based on the holster.cfg file associated with the model or simply
	//use the default values

	int				i;
	fileHandle_t	f;
	int				fLen = 0;
	char			fileBuffer[MAX_HOLSTER_INFO_SIZE];
	char			holsterTypeValue[MAX_QPATH];
	char			holsterTypeGroup[MAX_HOLSTER_INFO_SIZE];
	char			*s;
	vec3_t			vectorData;

	InitHolsterData(ci);

	if ( !ci->skinName || !Q_stricmp( "default", ci->skinName ) )
	{//try default holster.cfg first
		fLen = trap_FS_FOpenFile(va("models/players/%s/holster.cfg", ci->modelName), &f, FS_READ);

		if( !f )
		{//no file, use kyle's then.
			fLen = trap_FS_FOpenFile("models/players/kyle/holster.cfg", &f, FS_READ);
		}
	}
	else
	{//use the holster.cfg associated with this skin
		fLen = trap_FS_FOpenFile(va("models/players/%s/holster_%s.cfg", ci->modelName, ci->skinName), &f, FS_READ);
		if ( !f )
		{//fall back to default holster.cfg
			fLen = trap_FS_FOpenFile(va("models/players/%s/holster.cfg", ci->modelName), &f, FS_READ);
		}

		if( !f )
		{//still no dice, use kyle's then.
			fLen = trap_FS_FOpenFile("models/players/kyle/holster.cfg", &f, FS_READ);
		}
	}

	if ( !f || !fLen )
	{//couldn't open file or it was empty, just use the defaults
		return;
	}

	if( fLen >= MAX_HOLSTER_INFO_SIZE )
	{
		CG_Printf("Error: holster.cfg for %s is over the holster.cfg filesize limit.\n", ci->modelName);
		trap_FS_FCloseFile( f );
		return;
	}

	trap_FS_Read(fileBuffer, fLen, f);

	trap_FS_FCloseFile( f );

	s = fileBuffer;

	//parse file
	while( (s = BG_GetNextValueGroup(s, holsterTypeGroup)) != NULL )
	{
		if( !BG_SiegeGetPairedValue(holsterTypeGroup, "holsterType", holsterTypeValue) )
		{//couldn't find holster type in group
			CG_Printf("Error:  The holster.cfg for %s appears to be missing a holsterType in one of its define groups.\n", 
				ci->modelName);
			continue;
		}

		i = GetIDForString(holsterTypeTable, holsterTypeValue);

		if( i == -1 )
		{//bad holster type
			CG_Printf("Error:  The holster.cfg for %s has a bad holsterType in one of the define groups.\n", 
				ci->modelName);
			continue;
		}

		if( BG_SiegeGetPairedValue(holsterTypeGroup, "boneIndex", holsterTypeValue) )
		{//have bone index data for this holster type, use it
			if(!Q_stricmp(holsterTypeValue, "disabled") )
			{//disable the rendering of this holster type on this model
				ci->holsterData[i].boneIndex = HOLSTER_NONE;
			}
			else
			{
				ci->holsterData[i].boneIndex = GetIDForString(holsterBoneTable, holsterTypeValue);
			}
		}

		if( BG_SiegeGetPairedValue(holsterTypeGroup, "posOffset", holsterTypeValue) )
		{//parsing positional offset data
			sscanf (holsterTypeValue, "%f, %f, %f", &vectorData[0], &vectorData[1], &vectorData[2]);
			VectorCopy(vectorData, ci->holsterData[i].posOffset);
				
				//&ci->holsterData[i].posOffset[0], &ci->holsterData[i].posOffset[1], 
				//&ci->holsterData[i].posOffset[2]);
		}

		if( BG_SiegeGetPairedValue(holsterTypeGroup, "angOffset", holsterTypeValue) )
		{//parsing angular offset
			sscanf (holsterTypeValue, "%f, %f, %f", &vectorData[0], &vectorData[1], &vectorData[2]);
			VectorCopy(vectorData, ci->holsterData[i].angOffset);
		}
	}
#ifdef _DEBUG
	//CG_Printf("Holstered Weapon Data Loaded for %s.\n", ci->modelName);
#endif
}
Exemple #22
0
qboolean BG_ParseRankNames( char* fileName, rankNames_t rankNames[] ) {
	fileHandle_t	f;
	int				file_len;
	char			charText[20000];
	char*			textPtr;
	char*			token;
	int				i = 0;

	file_len = trap_FS_FOpenFile( fileName, &f, FS_READ );

	if ( file_len<= 0 ) {
		return qfalse;
	}

	if ( file_len >= ( sizeof(charText) - 1) ) {
		Com_Printf( S_COLOR_RED "File length of %s is too long.\n", fileName );
	}

	memset( &charText, 0, sizeof( charText ) );
	memset( rankNames, 0, sizeof( rankNames ) );

	trap_FS_Read( charText, file_len, f );

	charText[file_len] = 0;

	trap_FS_FCloseFile( f );

	COM_BeginParseSession();

	textPtr = charText;

	token = COM_Parse( &textPtr );

	if ( !token[0] ) {
		Com_Printf( S_COLOR_RED "No data found in buffer: %s\n", fileName );
		return qfalse;
	}

	if ( Q_stricmpn( token, "{", 1 ) ) {
		Com_Printf( S_COLOR_RED "No beginning { found in %s\n", fileName );
		return qfalse;
	}

	//Parse out the default cell.  Default has no names anyway,
	//but in case a n00bie modder put names in anyway.
	SkipBracedSection( &textPtr );

	while( 1 ) {
		//lastPtr = textPtr;
		token = COM_Parse( &textPtr );
		if( !token[0] ) {
			break;
		}

		if ( i >= MAX_RANKS ) {
			break;
		}

		//If we hit an open brace (ie, assuming we hit the start of a new rank cell)
		if ( !Q_stricmpn( token, "{", 1 ) ) {
			while ( 1 ) {
				token = COM_Parse( &textPtr );
				if( !token[0] ) {
					break;
				}

				//We hit a MenuTexture entry, since this uses { symbols, we'll skip these to stop errors.
				if ( !Q_stricmpn( token, "MenuTexture", 11 ) ) {
					SkipRestOfLine( &textPtr );
					continue;
				}

				if ( !Q_stricmpn( token, "ConsoleName", 11) ) {
					if ( COM_ParseString( &textPtr, &token ) ) {
						continue;
					}

					Q_strncpyz( rankNames[i].consoleName, token, sizeof( rankNames[i].consoleName ) );

					continue;
				}
				else if ( !Q_stricmpn( token, "FormalName", 10) ) {
					if ( COM_ParseString( &textPtr, &token ) ) {
						continue;
					}

					Q_strncpyz( rankNames[i].formalName, token, sizeof( rankNames[i].formalName ) );

					continue;
				}
				//We hit the end of the cell.
				else if ( !Q_stricmpn( token, "}", 1 ) ) {
					break;
				}
			}

			//Error check.  If we didn't get both a formal and console name, pwn the caller. ;P
			if ( !rankNames[i].consoleName[0] || !rankNames[i].formalName[0] ) {
				Com_Printf( S_COLOR_RED "One or more rank names were not found in rank#: %i\n", i );
				return qfalse;
			}
			else {
				i++;
			}
		}
	}
	return qtrue;
}
Exemple #23
0
/*
======================
UI_ParseAnimationFile
======================
*/
static qbool UI_ParseAnimationFile( const char *filename, animation_t *animations ) {
    char		*text_p, *prev;
    int			len;
    int			i;
    char		*token;
    float		fps;
    int			skip;
    char		text[20000];
    fileHandle_t	f;

    memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS );

    // load the file
    len = trap_FS_FOpenFile( filename, &f, FS_READ );
    if ( len <= 0 ) {
        return qfalse;
    }
    if ( len >= ( sizeof( text ) - 1 ) ) {
        Com_Printf( "File %s too long\n", filename );
        trap_FS_FCloseFile( f );
        return qfalse;
    }
    trap_FS_Read( text, len, f );
    text[len] = 0;
    trap_FS_FCloseFile( f );

    COM_Compress(text);

    // parse the text
    text_p = text;
    skip = 0;	// quite the compiler warning

    // read optional parameters
    while ( 1 ) {
        prev = text_p;	// so we can unget
        token = COM_Parse( &text_p );
        if ( !token ) {
            break;
        }
        if ( !Q_stricmp( token, "footsteps" ) ) {
            token = COM_Parse( &text_p );
            if ( !token ) {
                break;
            }
            continue;
        } else if ( !Q_stricmp( token, "headoffset" ) ) {
            for ( i = 0 ; i < 3 ; i++ ) {
                token = COM_Parse( &text_p );
                if ( !token ) {
                    break;
                }
            }
            continue;
        } else if ( !Q_stricmp( token, "sex" ) ) {
            token = COM_Parse( &text_p );
            if ( !token ) {
                break;
            }
            continue;
        }

        // if it is a number, start parsing animations
        if ( token[0] >= '0' && token[0] <= '9' ) {
            text_p = prev;	// unget the token
            break;
        }

        Com_Printf( "unknown token '%s' is %s\n", token, filename );
    }

    // read information for each frame
    for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) {

        token = COM_Parse( &text_p );
        if ( !token ) {
            break;
        }
        animations[i].firstFrame = atoi( token );

        token = COM_Parse( &text_p );
        if ( !token ) {
            break;
        }
        animations[i].numFrames = atoi( token );

        token = COM_Parse( &text_p );
        if ( !token ) {
            break;
        }
        animations[i].loopFrames = atoi( token );

        token = COM_Parse( &text_p );
        if ( !token ) {
            break;
        }
        fps = atof( token );
        if ( fps == 0 ) {
            fps = 1;
        }
        animations[i].frameLerp = 1000 / fps;
        animations[i].initialLerp = 1000 / fps;
    }

    if ( i != MAX_ANIMATIONS ) {
        Com_Printf( "Error parsing animation file: %s", filename );
        return qfalse;
    }

    return qtrue;
}
Exemple #24
0
void G_LogWeaponOutput(void)
{
#ifdef LOGGING_WEAPONS
	int i,j,curwp;
	float pershot;
	fileHandle_t weaponfile;
	char string[1024];

	int totalpickups[WP_NUM_WEAPONS];
	int totaltime[WP_NUM_WEAPONS];
	int totaldeaths[WP_NUM_WEAPONS];
	int totaldamageMOD[MOD_MAX];
	int totalkillsMOD[MOD_MAX];
	int totaldamage[WP_NUM_WEAPONS];
	int totalkills[WP_NUM_WEAPONS];
	int totalshots[WP_NUM_WEAPONS];
	int percharacter[WP_NUM_WEAPONS];
	char info[1024];
	char mapname[128];
	char *nameptr, *unknownname="<Unknown>";

	if (!g_statLog.integer)
	{
		return;
	}

	G_LogPrintf("*****************************Weapon Log:\n" );

	memset(totalpickups, 0, sizeof(totalpickups));
	memset(totaltime, 0, sizeof(totaltime));
	memset(totaldeaths, 0, sizeof(totaldeaths));
	memset(totaldamageMOD, 0, sizeof(totaldamageMOD));
	memset(totalkillsMOD, 0, sizeof(totalkillsMOD));
	memset(totaldamage, 0, sizeof(totaldamage));
	memset(totalkills, 0, sizeof(totalkills));
	memset(totalshots, 0, sizeof(totalshots));

	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				totalpickups[j] += G_WeaponLogPickups[i][j];
				totaltime[j] += G_WeaponLogTime[i][j];
				totaldeaths[j] += G_WeaponLogDeaths[i][j];
				totalshots[j] += G_WeaponLogFired[i][j];
			}

			for (j=0;j<MOD_MAX;j++)
			{
				totaldamageMOD[j] += G_WeaponLogDamage[i][j];
				totalkillsMOD[j] += G_WeaponLogKills[i][j];
			}
		}
	}

	// Now total the weapon data from the MOD data.
	for (j=0; j<MOD_MAX; j++)
	{
		if (j <= MOD_SENTRY)
		{
			curwp = weaponFromMOD[j];
			totaldamage[curwp] += totaldamageMOD[j];
			totalkills[curwp] += totalkillsMOD[j];
		}
	}

	G_LogPrintf(  "\n****Data by Weapon:\n" );
	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		G_LogPrintf("%15s:  Pickups: %4d,  Time:  %5d,  Deaths: %5d\n", 
				weaponNameFromIndex[j], totalpickups[j], (int)(totaltime[j]/1000), totaldeaths[j]);
	}

	G_LogPrintf(  "\n****Combat Data by Weapon:\n" );
	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		if (totalshots[j] > 0)
		{
			pershot = (float)(totaldamage[j])/(float)(totalshots[j]);
		}
		else
		{
			pershot = 0;
		}
		G_LogPrintf("%15s:  Damage: %6d,  Kills: %5d,  Dmg per Shot: %f\n", 
				weaponNameFromIndex[j], totaldamage[j], totalkills[j], pershot);
	}

	G_LogPrintf(  "\n****Combat Data By Damage Type:\n" );
	for (j=0; j<MOD_MAX; j++)
	{
		G_LogPrintf("%25s:  Damage: %6d,  Kills: %5d\n", 
				modNames[j], totaldamageMOD[j], totalkillsMOD[j]);
	}

	G_LogPrintf("\n");



	// Write the whole weapon statistic log out to a file.
	trap_FS_FOpenFile( g_statLogFile.string, &weaponfile, FS_APPEND );
	if (!weaponfile) {	//failed to open file, let's not crash, shall we?
		return;
	}

	// Write out the level name
	trap_GetServerinfo(info, sizeof(info));
	strncpy(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname)-1);
	mapname[sizeof(mapname)-1] = '\0';

	Com_sprintf(string, sizeof(string), "\n\n\nLevel:\t%s\n\n\n", mapname);
	trap_FS_Write( string, strlen( string ), weaponfile);


	// Combat data per character
	
	// Start with Pickups per character
	Com_sprintf(string, sizeof(string), "Weapon Pickups per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogPickups[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totalpickups[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	
	// Weapon fires per character
	Com_sprintf(string, sizeof(string), "Weapon Shots per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogFired[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totalshots[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	// Weapon time per character
	Com_sprintf(string, sizeof(string), "Weapon Use Time per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogTime[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totaltime[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	
	// Weapon deaths per character
	Com_sprintf(string, sizeof(string), "Weapon Deaths per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogDeaths[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totaldeaths[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);



	
	// Weapon damage per character

	Com_sprintf(string, sizeof(string), "Weapon Damage per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!

			// We must grab the totals from the damage types for the player and map them to the weapons.
			memset(percharacter, 0, sizeof(percharacter));
			for (j=0; j<MOD_MAX; j++)
			{
				if (j <= MOD_SENTRY)
				{
					curwp = weaponFromMOD[j];
					percharacter[curwp] += G_WeaponLogDamage[i][j];
				}
			}

			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", percharacter[j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totaldamage[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	
	// Weapon kills per character

	Com_sprintf(string, sizeof(string), "Weapon Kills per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<WP_NUM_WEAPONS; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!

			// We must grab the totals from the damage types for the player and map them to the weapons.
			memset(percharacter, 0, sizeof(percharacter));
			for (j=0; j<MOD_MAX; j++)
			{
				if (j <= MOD_SENTRY)
				{
					curwp = weaponFromMOD[j];
					percharacter[curwp] += G_WeaponLogKills[i][j];
				}
			}

			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<WP_NUM_WEAPONS;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", percharacter[j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<WP_NUM_WEAPONS;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totalkills[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	
	// Damage type damage per character
	Com_sprintf(string, sizeof(string), "Typed Damage per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<MOD_MAX; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", modNames[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<MOD_MAX;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogDamage[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<MOD_MAX;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totaldamageMOD[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	
	// Damage type kills per character
	Com_sprintf(string, sizeof(string), "Damage-Typed Kills per Player:\n\n");
	trap_FS_Write( string, strlen( string ), weaponfile);

	Com_sprintf(string, sizeof(string), "Player");
	trap_FS_Write(string, strlen(string), weaponfile);

	for (j=0; j<MOD_MAX; j++)
	{
		Com_sprintf(string, sizeof(string), "\t%s", modNames[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}
	Com_sprintf(string, sizeof(string), "\n");
	trap_FS_Write(string, strlen(string), weaponfile);

	// Cycle through each player, give their name and the number of times they picked up each weapon.
	for (i=0; i<MAX_CLIENTS; i++)
	{
		if (G_WeaponLogClientTouch[i])
		{	// Ignore any entity/clients we don't care about!
			if ( g_entities[i].client ) 
			{
				nameptr = g_entities[i].client->pers.netname;
			} 
			else 
			{
				nameptr = unknownname;
			}
			trap_FS_Write(nameptr, strlen(nameptr), weaponfile);

			for (j=0;j<MOD_MAX;j++)
			{
				Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogKills[i][j]);
				trap_FS_Write(string, strlen(string), weaponfile);
			}

			Com_sprintf(string, sizeof(string), "\n");
			trap_FS_Write(string, strlen(string), weaponfile);
		}
	}

	// Sum up the totals.
	Com_sprintf(string, sizeof(string), "\n***TOTAL:");
	trap_FS_Write(string, strlen(string), weaponfile);
	
	for (j=0;j<MOD_MAX;j++)
	{
		Com_sprintf(string, sizeof(string), "\t%d", totalkillsMOD[j]);
		trap_FS_Write(string, strlen(string), weaponfile);
	}

	Com_sprintf(string, sizeof(string), "\n\n\n");
	trap_FS_Write(string, strlen(string), weaponfile);


	trap_FS_FCloseFile(weaponfile);


#endif //LOGGING_WEAPONS
}
/*
===============
CG_InitBuildables

Initialises the animation db
===============
*/
void CG_InitBuildables( void )
{
  char          filename[ MAX_QPATH ];
  char          soundfile[ MAX_QPATH ];
  char          *buildableName;
  char          *modelFile;
  int           i;
  int           j;
  fileHandle_t  f;

  memset( cg_buildables, 0, sizeof( cg_buildables ) );

  //default sounds
  for( j = BANIM_NONE + 1; j < MAX_BUILDABLE_ANIMATIONS; j++ )
  {
    strcpy( soundfile, cg_buildableSoundNames[ j - 1 ] );

    Com_sprintf( filename, sizeof( filename ), "sound/buildables/alien/%s", soundfile );
    defaultAlienSounds[ j ] = trap_S_RegisterSound( filename, qfalse );

    Com_sprintf( filename, sizeof( filename ), "sound/buildables/human/%s", soundfile );
    defaultHumanSounds[ j ] = trap_S_RegisterSound( filename, qfalse );
  }

  cg.buildablesFraction = 0.0f;

  for( i = BA_NONE + 1; i < BA_NUM_BUILDABLES; i++ )
  {
    buildableName = BG_FindNameForBuildable( i );

    //animation.cfg
    Com_sprintf( filename, sizeof( filename ), "models/buildables/%s/animation.cfg", buildableName );
    if ( !CG_ParseBuildableAnimationFile( filename, i ) )
      Com_Printf( S_COLOR_YELLOW "WARNING: failed to load animation file %s\n", filename );

    //sound.cfg
    Com_sprintf( filename, sizeof( filename ), "sound/buildables/%s/sound.cfg", buildableName );
    if ( !CG_ParseBuildableSoundFile( filename, i ) )
      Com_Printf( S_COLOR_YELLOW "WARNING: failed to load sound file %s\n", filename );

    //models
    for( j = 0; j <= 3; j++ )
    {
      if( ( modelFile = BG_FindModelsForBuildable( i, j ) ) )
        cg_buildables[ i ].models[ j ] = trap_R_RegisterModel( modelFile );
    }

    //sounds
    for( j = BANIM_NONE + 1; j < MAX_BUILDABLE_ANIMATIONS; j++ )
    {
      strcpy( soundfile, cg_buildableSoundNames[ j - 1 ] );
      Com_sprintf( filename, sizeof( filename ), "sound/buildables/%s/%s", buildableName, soundfile );

      if( cg_buildables[ i ].sounds[ j ].enabled )
      {
        if( trap_FS_FOpenFile( filename, &f, FS_READ ) > 0 )
        {
          //file exists so close it
          trap_FS_FCloseFile( f );

          cg_buildables[ i ].sounds[ j ].sound = trap_S_RegisterSound( filename, qfalse );
        }
        else
        {
          //file doesn't exist - use default
          if( BG_FindTeamForBuildable( i ) == BIT_ALIENS )
            cg_buildables[ i ].sounds[ j ].sound = defaultAlienSounds[ j ];
          else
            cg_buildables[ i ].sounds[ j ].sound = defaultHumanSounds[ j ];
        }
      }
    }

    cg.buildablesFraction = (float)i / (float)( BA_NUM_BUILDABLES - 1 );
    trap_UpdateScreen( );
  }

  cgs.media.teslaZapTS = CG_RegisterTrailSystem( "models/buildables/tesla/zap" );
}
Exemple #26
0
int G_LoadRoff( const char *fileName )
{
	char	file[MAX_QPATH];
	char	data[ROFF_INFO_SIZE];
	fileHandle_t	f;
	roff_hdr2_t *header;
	int		len, i, roff_id = 0;

	// Before even bothering with all of this, make sure we have a place to store it.
	if ( num_roffs >= MAX_ROFFS )
	{
		Com_Printf( S_COLOR_RED"MAX_ROFFS count exceeded.  Skipping load of .ROF '%s'\n", fileName );
		return roff_id;
	}

	// The actual path
	sprintf( file, "%s/%s.rof", Q3_SCRIPT_DIR, fileName );

	// See if I'm already precached
	for ( i = 0; i < num_roffs; i++ )
	{
		if ( stricmp( file, roffs[i].fileName ) == 0 )
		{
			// Good, just return me...avoid zero index
			return i + 1;
		}
	}

#ifdef _DEBUG
//	Com_Printf( S_COLOR_GREEN"Caching ROF: '%s'\n", file );
#endif

	// Read the file in one fell swoop
	len = trap_FS_FOpenFile(file, &f, FS_READ);

	if ( len <= 0 )
	{
		Com_Printf( S_COLOR_RED"Could not open .ROF file '%s'\n", fileName );
		return roff_id;
	}

	if ( len >= ROFF_INFO_SIZE )
	{
		Com_Printf( S_COLOR_RED".ROF file '%s': Too large for file buffer.\n", fileName );
		return roff_id;
	}

	trap_FS_Read(data, len, f);	//read data in buffer

	trap_FS_FCloseFile(f);	//close file

	// Now let's check the header info...
	header = (roff_hdr2_t *)data;

	// ..and make sure it's reasonably valid
	if ( !G_ValidRoff( header ))
	{
		Com_Printf( S_COLOR_RED"Invalid roff format '%s'\n", fileName );
	}
	else
	{
		G_InitRoff( file, data );

		// Done loading this roff, so save off an id to it..increment first to avoid zero index
		roff_id = ++num_roffs;
	}

	//trap_FS_FCloseFile( data );

	return roff_id;
}
Exemple #27
0
void Save_Autosaves(void)
{//save the autosaves
	fileHandle_t	f;
	char			lineBuf[MAX_QPATH];
	char			fileBuf[MAX_AUTOSAVE_FILESIZE];
	char			loadPath[MAX_QPATH];
	int				len;
	//[RawMapName]
	//vmCvar_t		mapname;
	//[/RawMapName]
	gentity_t*		autosavePoint;

	fileBuf[0] = '\0';

	G_Printf("^5Saving Autosave File Data...");

	//[RawMapName]
	//trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );

	//Com_sprintf(loadPath, MAX_QPATH, "maps/%s.autosp", mapname.string);
	Com_sprintf(loadPath, sizeof(loadPath), "maps/%s.autosp", level.rawmapname);
	//[/RawMapName]

	len = trap_FS_FOpenFile( loadPath, &f, FS_WRITE );
	if ( !f )
	{
		G_Printf("^5Couldn't create autosave file.\n");
		return;
	}

	//find all the manually created autosave points.
	autosavePoint = NULL;
	while ( (autosavePoint = G_Find (autosavePoint, FOFS(classname), "trigger_autosave")) != NULL )
	{
		Com_sprintf(lineBuf, MAX_QPATH, "%f %f %f %i %i\n", 
			autosavePoint->r.currentOrigin[0], autosavePoint->r.currentOrigin[1],
			autosavePoint->r.currentOrigin[2], (int) autosavePoint->r.maxs[0],
			(autosavePoint->spawnflags & AUTOSAVE_TELE) );
		strcat(fileBuf, lineBuf);
	}

	//find all the manually added spawnpoints
	autosavePoint = NULL;
	while ( (autosavePoint = G_Find (autosavePoint, FOFS(classname), "info_player_deathmatch")) != NULL )
	{
		if(!(autosavePoint->spawnflags & 1))
		{//not a manually placed spawnpoint
			continue;
		}
		Com_sprintf(lineBuf, MAX_QPATH, "%f %f %f %i %i\n", 
			autosavePoint->r.currentOrigin[0], autosavePoint->r.currentOrigin[1],
			autosavePoint->r.currentOrigin[2], -1, 0 );
		strcat(fileBuf, lineBuf);
	}

	if(fileBuf[0] != '\0')
	{//actually written something
		trap_FS_Write( fileBuf, strlen(fileBuf), f );
	}
	trap_FS_FCloseFile( f );
	G_Printf("^5Done.\n");
}
Exemple #28
0
/*
=======================
UI_CalcPostGameStats
=======================
*/
static void UI_CalcPostGameStats( void )
{
    char map[MAX_QPATH];
    char fileName[MAX_QPATH];
    char info[MAX_INFO_STRING];
    fileHandle_t f;
    int size, game, time, adjustedTime;
    postGameInfo_t oldInfo;
    postGameInfo_t newInfo;
    qboolean newHigh = qfalse;

    trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
    Q_strncpyz(map, Info_ValueForKey(info, "mapname"), sizeof(map));
    game = atoi(Info_ValueForKey(info, "g_gametype"));

    // compose file name
    Com_sprintf(fileName, MAX_QPATH, "games/%s_%i.game", map, game);
    // see if we have one already
    memset(&oldInfo, 0, sizeof(postGameInfo_t));
    if (trap_FS_FOpenFile(fileName, &f, FS_READ) >= 0) {
        // if so load it
        size = 0;
        trap_FS_Read(&size, sizeof(int), f);
        if (size == sizeof(postGameInfo_t)) {
            trap_FS_Read(&oldInfo, sizeof(postGameInfo_t), f);
        }
        trap_FS_FCloseFile(f);
    }

    newInfo.accuracy = atoi(UI_Argv(3));
    newInfo.impressives = atoi(UI_Argv(4));
    newInfo.excellents = atoi(UI_Argv(5));
    newInfo.defends = atoi(UI_Argv(6));
    newInfo.assists = atoi(UI_Argv(7));
    newInfo.gauntlets = atoi(UI_Argv(8));
    newInfo.baseScore = atoi(UI_Argv(9));
    newInfo.perfects = atoi(UI_Argv(10));
    newInfo.redScore = atoi(UI_Argv(11));
    newInfo.blueScore = atoi(UI_Argv(12));
    time = atoi(UI_Argv(13));
    newInfo.captures = atoi(UI_Argv(14));

    newInfo.time = (time - trap_Cvar_VariableValue("ui_matchStartTime")) / 1000;
    adjustedTime = uiInfo.mapList[ui_currentMap.integer].timeToBeat[game];
    if (newInfo.time < adjustedTime) {
        newInfo.timeBonus = (adjustedTime - newInfo.time) * 10;
    } else {
        newInfo.timeBonus = 0;
    }

    if (newInfo.redScore > newInfo.blueScore && newInfo.blueScore <= 0) {
        newInfo.shutoutBonus = 100;
    } else {
        newInfo.shutoutBonus = 0;
    }

    newInfo.skillBonus = trap_Cvar_VariableValue("g_spSkill");
    if (newInfo.skillBonus <= 0) {
        newInfo.skillBonus = 1;
    }
    newInfo.score = newInfo.baseScore + newInfo.shutoutBonus + newInfo.timeBonus;
    newInfo.score *= newInfo.skillBonus;

    // see if the score is higher for this one
    newHigh = (newInfo.redScore > newInfo.blueScore && newInfo.score > oldInfo.score);

    if (newHigh) {
        // if so write out the new one
        uiInfo.newHighScoreTime = uiInfo.uiDC.realTime + 20000;
        if (trap_FS_FOpenFile(fileName, &f, FS_WRITE) >= 0) {
            size = sizeof(postGameInfo_t);
            trap_FS_Write(&size, sizeof(int), f);
            trap_FS_Write(&newInfo, sizeof(postGameInfo_t), f);
            trap_FS_FCloseFile(f);
        }
    }

    if (newInfo.time < oldInfo.time) {
        uiInfo.newBestTime = uiInfo.uiDC.realTime + 20000;
    }
    // put back all the ui overrides
    trap_Cvar_Set("capturelimit", UI_Cvar_VariableString("ui_saveCaptureLimit"));
    trap_Cvar_Set("fraglimit", UI_Cvar_VariableString("ui_saveFragLimit"));
    trap_Cvar_Set("cg_drawTimer", UI_Cvar_VariableString("ui_drawTimer"));
    trap_Cvar_Set("g_doWarmup", UI_Cvar_VariableString("ui_doWarmup"));
    trap_Cvar_Set("g_Warmup", UI_Cvar_VariableString("ui_Warmup"));
    trap_Cvar_Set("sv_pure", UI_Cvar_VariableString("ui_pure"));
    trap_Cvar_Set("g_friendlyFire", UI_Cvar_VariableString("ui_friendlyFire"));

    UI_SetBestScores(&newInfo, qtrue);
    UI_ShowPostGame(newHigh);

}
Exemple #29
0
/*
=================
CG_ParseVoiceChats
=================
*/
int CG_ParseVoiceChats(const char *filename, voiceChatList_t * voiceChatList, int maxVoiceChats)
{
	int             len, i;
	fileHandle_t    f;
	char            buf[MAX_VOICEFILESIZE];
	char          **p, *ptr;
	char           *token;
	voiceChat_t    *voiceChats;
	qboolean        compress;
	sfxHandle_t     sound;

	compress = qtrue;
	if(cg_buildScript.integer)
	{
		compress = qfalse;
	}

	len = trap_FS_FOpenFile(filename, &f, FS_READ);
	if(!f)
	{
		trap_Print(va(S_COLOR_RED "voice chat file not found: %s\n", filename));
		return qfalse;
	}
	if(len >= MAX_VOICEFILESIZE)
	{
		trap_Print(va(S_COLOR_RED "voice chat file too large: %s is %i, max allowed is %i", filename, len, MAX_VOICEFILESIZE));
		trap_FS_FCloseFile(f);
		return qfalse;
	}

	trap_FS_Read(buf, len, f);
	buf[len] = 0;
	trap_FS_FCloseFile(f);

	ptr = buf;
	p = &ptr;

	Com_sprintf(voiceChatList->name, sizeof(voiceChatList->name), "%s", filename);
	voiceChats = voiceChatList->voiceChats;
	for(i = 0; i < maxVoiceChats; i++)
	{
		voiceChats[i].id[0] = 0;
	}
	token = Com_ParseExt(p, qtrue);
	if(!token || token[0] == 0)
	{
		return qtrue;
	}
	if(!Q_stricmp(token, "female"))
	{
		voiceChatList->gender = GENDER_FEMALE;
	}
	else if(!Q_stricmp(token, "male"))
	{
		voiceChatList->gender = GENDER_MALE;
	}
	else if(!Q_stricmp(token, "neuter"))
	{
		voiceChatList->gender = GENDER_NEUTER;
	}
	else
	{
		trap_Print(va(S_COLOR_RED "expected gender not found in voice chat file: %s\n", filename));
		return qfalse;
	}

	voiceChatList->numVoiceChats = 0;
	while(1)
	{
		token = Com_ParseExt(p, qtrue);
		if(!token || token[0] == 0)
		{
			return qtrue;
		}
		Com_sprintf(voiceChats[voiceChatList->numVoiceChats].id, sizeof(voiceChats[voiceChatList->numVoiceChats].id), "%s",
					token);
		token = Com_ParseExt(p, qtrue);
		if(Q_stricmp(token, "{"))
		{
			trap_Print(va(S_COLOR_RED "expected { found %s in voice chat file: %s\n", token, filename));
			return qfalse;
		}
		voiceChats[voiceChatList->numVoiceChats].numSounds = 0;
		while(1)
		{
			token = Com_ParseExt(p, qtrue);
			if(!token || token[0] == 0)
			{
				return qtrue;
			}

			if(!Q_stricmp(token, "}"))
				break;

			sound = trap_S_RegisterSound(token);

			voiceChats[voiceChatList->numVoiceChats].sounds[voiceChats[voiceChatList->numVoiceChats].numSounds] = sound;
			token = Com_ParseExt(p, qtrue);
			if(!token || token[0] == 0)
			{
				return qtrue;
			}
			Com_sprintf(voiceChats[voiceChatList->numVoiceChats].chats[voiceChats[voiceChatList->numVoiceChats].numSounds],
						MAX_CHATSIZE, "%s", token);
			if(sound)
				voiceChats[voiceChatList->numVoiceChats].numSounds++;
			if(voiceChats[voiceChatList->numVoiceChats].numSounds >= MAX_VOICESOUNDS)
				break;
		}
		voiceChatList->numVoiceChats++;
		if(voiceChatList->numVoiceChats >= maxVoiceChats)
			return qtrue;
	}
	return qtrue;
}
Exemple #30
0
void G_xpsave_readconfig() 
{
	g_xpsave_t *x = g_xpsaves[0];
	g_mapstat_t *m = g_mapstats[0];
	int xc = 0;
	int mc = 0;
	fileHandle_t f;
	int i, j;
	int len;
	char *cnf, *cnf2;
	char *t;
	qboolean xpsave_open;
	qboolean mapstat_open;
	qboolean serverstat_open;
	qboolean found_serverstat = qfalse;
	float skill;
	char buffer[MAX_STRING_CHARS];

	if(!(g_XPSave.integer & XPSF_ENABLE))
		return;	
	if(!g_XPSaveFile.string[0])
		return;
	len = trap_FS_FOpenFile(g_XPSaveFile.string, &f, FS_READ) ; 
	if(len < 0) {
		G_Printf("readconfig: could not open xpsave file %s\n",
			g_XPSaveFile.string);
		return;
	}
	cnf = malloc(len+1);
	cnf2 = cnf;
	trap_FS_Read(cnf, len, f);
	*(cnf + len) = '\0';
	trap_FS_FCloseFile(f);

	G_xpsave_cleanup();
	
	t = COM_Parse(&cnf);
	xpsave_open = qfalse;
	mapstat_open = qfalse;
	serverstat_open = qfalse;
	while(*t) {
		if(!Q_stricmp(t, "[xpsave]") ||
			!Q_stricmp(t, "[mapstat]") ||
			!Q_stricmp(t, "[serverstat]")
			) {

			if(xpsave_open)
				g_xpsaves[xc++] = x;
			if(mapstat_open)
				g_mapstats[mc++] = m;
			xpsave_open = qfalse;
			mapstat_open = qfalse;
			serverstat_open = qfalse;
		}

		if(xpsave_open) {
			if(!Q_stricmp(t, "guid")) {
				G_shrubbot_readconfig_string(&cnf, 
					x->guid, sizeof(x->guid)); 
			}
			else if(!Q_stricmp(t, "name")) {
				G_shrubbot_readconfig_string(&cnf, 
					x->name, sizeof(x->name)); 
			}
			else if(!Q_stricmp(t, "time")) {
				G_shrubbot_readconfig_int(&cnf, &x->time);
			}
			else if(!Q_stricmpn(t, "skill[", 6)) {
				for(i=0; i<SK_NUM_SKILLS; i++) {
					if(Q_stricmp(t, va("skill[%i]", i)))
						continue;		
					G_shrubbot_readconfig_float(&cnf,
						&skill);
					x->skill[i] = skill;
					break;
				}
			}
			else if(!Q_stricmp(t, "kill_rating")) {
				G_shrubbot_readconfig_float(&cnf, &x->kill_rating);
			}
			else if(!Q_stricmp(t, "kill_variance")) {
				G_shrubbot_readconfig_float(&cnf, &x->kill_variance);
			}
			else if(!Q_stricmp(t, "rating")) {
				G_shrubbot_readconfig_float(&cnf,
					&x->rating);
			}
			else if(!Q_stricmp(t, "rating_variance")) {
				G_shrubbot_readconfig_float(&cnf,
					&x->rating_variance);
			}
			else if(!Q_stricmp(t, "mutetime")) {
				G_shrubbot_readconfig_int(&cnf, &x->mutetime);
			}
			else if(!Q_stricmpn(t, "pr_skill[", 9)) {
				for(i=0; i<SK_NUM_SKILLS; i++) {
					if(Q_stricmp(t, va("pr_skill[%i]", i)))
						continue;		
					G_shrubbot_readconfig_string(&cnf,
						buffer, sizeof(buffer));
					sscanf(buffer,
						"%i %f %i %f %i %f %i %f %i %f",
						&x->pr_skill_updates[i][0],
						&x->pr_skill[i][0],
						&x->pr_skill_updates[i][1],
						&x->pr_skill[i][1],
						&x->pr_skill_updates[i][2],
						&x->pr_skill[i][2],
						&x->pr_skill_updates[i][3],
						&x->pr_skill[i][3],
						&x->pr_skill_updates[i][4],
						&x->pr_skill[i][4]);
					break;
				}
			}
			else {
				G_Printf("xpsave: [xpsave] parse error near "
					"%s on line %d\n", 
					t, 
					COM_GetCurrentParseLine());
			}
		}
		else if(mapstat_open) {
			if(!Q_stricmp(t, "name")) {
				G_shrubbot_readconfig_string(&cnf, 
					m->name, sizeof(m->name)); 
			}
			else if(!Q_stricmp(t, "rating")) {
				G_shrubbot_readconfig_float(&cnf,
					&m->rating);
			}
			else if(!Q_stricmp(t, "rating_variance")) {
				G_shrubbot_readconfig_float(&cnf,
					&m->rating_variance);
			}
			else if(!Q_stricmp(t, "spree_record")) {
				G_shrubbot_readconfig_int(&cnf,
					&m->spreeRecord);
			}
			else if(!Q_stricmp(t, "spree_name")) {
				G_shrubbot_readconfig_string(&cnf, 
					m->spreeName, sizeof(m->spreeName)); 
			}
			else {
				G_Printf("xpsave: [mapstat] parse error near "
					"%s on line %d\n", 
					t, 
					COM_GetCurrentParseLine());
			}
		}
		else if(serverstat_open) {
			if(!Q_stricmp(t, "rating")) {
				G_shrubbot_readconfig_float(&cnf,
					&g_serverstat.rating);
			}
			else if(!Q_stricmp(t, "rating_variance")) {
				G_shrubbot_readconfig_float(&cnf,
					&g_serverstat.rating_variance);
			}
			else if(!Q_stricmp(t, "distance_rating")) {
				G_shrubbot_readconfig_float(&cnf,
					&g_serverstat.distance_rating);
			}
			else if(!Q_stricmp(t, "distance_variance")) {
				G_shrubbot_readconfig_float(&cnf,
					&g_serverstat.distance_variance);
			}
			else {
				G_Printf("xpsave: [serverstat] parse error near "
					"%s on line %d\n", 
					t, 
					COM_GetCurrentParseLine());
			}
		}

		if(!Q_stricmp(t, "[xpsave]")) {
			if(xc >= MAX_XPSAVES) {
				G_Printf("xpsave: error MAX_XPSAVES exceeded");
				return;
			}
			x = malloc(sizeof(g_xpsave_t));
			x->guid[0] = '\0';
			x->name[0] = '\0';
			x->kill_rating = 0.0f;
			x->kill_variance = SIGMA2_DELTA;
			x->rating = 0.0f;
			x->rating_variance = SIGMA2_THETA;
			for(i=0; i<SK_NUM_SKILLS; i++) {
				x->skill[i] = 0.0f;
				for(j=0; j<NUM_SKILL_LEVELS; j++) {
					x->pr_skill_updates[i][j] = 0;
					x->pr_skill[i][j] = 0.0f;
				}
			}
			x->mutetime = 0;
			x->hits = 0;
			x->team_hits = 0;
			x->time = 0;
			xpsave_open = qtrue;
		}
		if(!Q_stricmp(t, "[mapstat]")) {
			if(mc >= MAX_MAPSTATS) {
				G_Printf("xpsave: error MAX_MAPSTATS exceeded");
				return;
			}
			m = malloc(sizeof(g_mapstat_t));
			m->name[0] = '\0';
			m->rating = 0.0f;
			m->rating_variance = SIGMA2_GAMMA;
			m->spreeRecord = 0;
			m->spreeName[0] = '\0';
			mapstat_open = qtrue;
		}
		if(!Q_stricmp(t, "[serverstat]")) {
			// server prior = 2.6, NOT 0
			g_serverstat.rating = 2.6f;
			g_serverstat.rating_variance = SIGMA2_PSI;
			g_serverstat.distance_rating = 0.0f;
			g_serverstat.distance_variance = SIGMA2_DELTA;
			serverstat_open = qtrue;
			found_serverstat = qtrue;
		}
		t = COM_Parse(&cnf);
	}
	if(xpsave_open)
		g_xpsaves[xc++] = x;
	else if(mapstat_open)
		g_mapstats[mc++] = m;

	free(cnf2);
	if (!found_serverstat) {
		// server prior = 2.6, NOT 0
		g_serverstat.rating = 2.6f;
		g_serverstat.rating_variance = SIGMA2_PSI;
	}
	G_Printf("xpsave: loaded %d mapstats, %d xpsaves\n", mc, xc);
}