View Single Post
Old 09-20-2006, 05:36 PM   #138
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
Now for an updated TeamplayInfoMessage.

This is going to be slightly longer because we need to add a new sorted client list to level_locals

add this to level_locals_t struct (g_local.h):

Code:
int			sortedSlots[MAX_CLIENTS];		// sorted by clientnum
now above CalculateRanks add this function (g_main.c):

Code:
/*
=============
SortSlots

=============
*/
int QDECL SortSlots( const void *a, const void *b ) {
	return *(int *)a - *(int *)b;
}
Okay now in CalculateRanks,

below this line:

Code:
level.sortedClients[level.numConnectedClients] = i;
add:

Code:
level.sortedSlots[level.numConnectedClients] = i;
now look for this line:

Code:
qsort( level.sortedClients, level.numConnectedClients, 
		sizeof(level.sortedClients[0]), SortRanks );
below it add:

Code:
qsort( level.sortedSlots, level.numConnectedClients, 
		sizeof(level.sortedSlots[0]), SortSlots );
now g_team.c

A replacement for TeamplayInfoMessage.

Code:
// G_SendTeamInfo_Add
// 
// Add teaminfo with clientNum at index i of level.sortedSlots[]
// to the string buf.
// 
// returns qtrue if the info was appended to buf, qfalse otherwise.
qboolean G_SendTeamInfo_Add(gentity_t *ent, gentity_t *player, int idnum, char *buf, int bufsize) 
{
	int		h, a;
	char	entry[128];

	entry[0] = '\0';

	h = player->client->ps.stats[STAT_HEALTH];
	a = player->client->ps.stats[STAT_ARMOR];
	if (h < 0) h = 0;
	if (a < 0) a = 0;

	Com_sprintf (entry, sizeof(entry),
		" %i %i %i %i %i %i", 
		idnum, player->client->pers.teamState.location, h, a, 
		player->client->ps.weapon, player->s.powerups);
	if((strlen(buf) + strlen(entry) + 1) > bufsize) {
		return qfalse;
	}
	Q_strcat(buf, bufsize, entry);
	return qtrue;
}

/*
==================
G_SendTeamInfo

==================
*/
void G_SendTeamInfo( gentity_t *ent ) {
	int			i, idnum;
	int			numSorted;
	int			count;
	gentity_t	*player = NULL;
	// tjw: commands over 1022 will crash the client so they're
	//      pruned in trap_SendServerCommand()
	//      1022 -32 for the startbuffer
	char		buffer[990];
	char		startbuffer[32];

	if ( !ent->client->pers.teamInfo )
		return;

	numSorted = level.numConnectedClients;
	
	if (numSorted > MAX_CLIENTS)
	{
		numSorted = MAX_CLIENTS;
	}

	count = 0;
	*buffer = '\0';
	*startbuffer = '\0';

	// tjw: keep adding teaminfos to the tinfo command until we fill 
	//      up the buffer.  
	for(i=0 ; i < numSorted && count < TEAM_MAXOVERLAY; i++) {
		// tjw: the old version of SendScore() did this.  I removed it
		//      originally because it seemed like an unneccessary hack.
		//      perhaps it is necessary for compat with CG_Argv()?
		idnum = level.sortedSlots[i];
		player = g_entities + idnum;
		if ( !player->inuse || player->client->sess.sessionTeam != ent->client->sess.sessionTeam )
			continue;
		if(!G_SendTeamInfo_Add(ent, player, idnum, buffer, sizeof(buffer))) {
			break;
		}
		count++;
	}
	if(!count) {
		return;
	}
	Q_strncpyz(startbuffer, va(
		"tinfo %i",
		count),
		sizeof(startbuffer));

	trap_SendServerCommand(ent-g_entities, va(
		"%s%s", startbuffer, buffer));
}
Now just replace any instances of TeamplayInfoMessage with G_SendTeamInfo.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,