Ejemplo n.º 1
0
/*
==============
G_Script_ParseSpawnbot

  Parses "Spawnbot" command, precaching a custom character if specified
==============
*/
void G_Script_ParseSpawnbot(char **ppScript, char params[], int paramsize)
{
	qboolean parsingCharacter = qfalse;
	char     *token;

	token = COM_ParseExt(ppScript, qfalse);
	while (token[0])
	{
		// if we are currently parsing a spawnbot command, check the parms for
		// a custom character, which we will need to precache on the client

		// did we just see a '/character' parm?
		if (parsingCharacter)
		{

			parsingCharacter = qfalse;

			G_CharacterIndex(token);

			if (!BG_FindCharacter(token))
			{
				bg_character_t *character = BG_FindFreeCharacter(token);

				Q_strncpyz(character->characterFile, token, sizeof(character->characterFile));

				if (!G_RegisterCharacter(token, character))
				{
					G_Error("ERROR: G_Script_ParseSpawnbot: failed to load character file '%s'\n", token);
				}
			}

#ifdef DEBUG
			G_DPrintf("precached character %s\n", token);
#endif
		}
		else if (!Q_stricmp(token, "/character"))
		{
			parsingCharacter = qtrue;
		}

		if (strlen(params))          // add a space between each param
		{
			Q_strcat(params, paramsize, " ");
		}

		if (strrchr(token, ' '))      // need to wrap this param in quotes since it has more than one word
		{
			Q_strcat(params, paramsize, "\"");
		}

		Q_strcat(params, paramsize, token);

		if (strrchr(token, ' '))      // need to wrap this param in quotes since it has more than one word
		{
			Q_strcat(params, paramsize, "\"");
		}

		token = COM_ParseExt(ppScript, qfalse);
	}
}
Ejemplo n.º 2
0
/*
=================
G_UpdateCharacter
=================
*/
void G_UpdateCharacter( gclient_t *client )
{
	char			infostring[MAX_INFO_STRING];
	char			*s;
	int				characterIndex;
	bg_character_t	*character;

	trap_GetUserinfo( client - level.clients, infostring,
		sizeof( infostring ) );
	s = Info_ValueForKey( infostring, "ch" );
	if( *s ) {
		characterIndex = atoi(s);
		if( characterIndex < 0 || characterIndex >= MAX_CHARACTERS ) {
			goto set_default_character;
		}

		if( client->pers.characterIndex != characterIndex ) {
			client->pers.characterIndex = characterIndex;
			trap_GetConfigstring( CS_CHARACTERS + characterIndex, infostring, MAX_INFO_STRING );
			if( !(client->pers.character = BG_FindCharacter( infostring ) ) ) {
				// not found - create it (this should never happen as we should have everything precached)
				client->pers.character = BG_FindFreeCharacter( infostring );

				if ( !client->pers.character ) {
					goto set_default_character;
				}

				Q_strncpyz( client->pers.character->characterFile, infostring, sizeof(client->pers.character->characterFile) );

				if( !G_RegisterCharacter( infostring, client->pers.character ) ) {
					G_Printf( S_COLOR_YELLOW "WARNING: G_UpdateCharacter: failed to load character file '%s' for %s\n", infostring,
						client->pers.netname);

					goto set_default_character;
				}
			}

			// RF, reset anims so client's dont freak out

			// xkan: this can only be done if the model really changed - otherwise, the
			// animation may get screwed up if we are in the middle of some animation
			// and we come into this function; 
			// plus, also reset the timer so we can properly start the next animation

			client->ps.legsAnim = 0;
			client->ps.torsoAnim = 0;
			client->ps.legsTimer = 0;
			client->ps.torsoTimer = 0;
		}
		return;
	}

  set_default_character:
	// set default character
	character = BG_GetCharacter( client->sess.sessionTeam, client->sess.playerType );
	if( client->pers.character != character ) {
		client->pers.characterIndex = -1;
		client->pers.character = character;

		client->ps.legsAnim = 0;
		client->ps.torsoAnim = 0;
		client->ps.legsTimer = 0;
		client->ps.torsoTimer = 0;
	}
}