void G_PlayerAward( edict_t *ent, const char *awardMsg ) { edict_t *other; char cmd[MAX_STRING_CHARS]; gameaward_t *ga; int i, size; score_stats_t *stats; if( !awardMsg || !awardMsg[0] || !ent->r.client ) return; Q_snprintfz( cmd, sizeof( cmd ), "aw \"%s\"", awardMsg ); trap_GameCmd( ent, cmd ); if( dedicated->integer ) G_Printf( "%s", COM_RemoveColorTokens( va( "%s receives a '%s' award.\n", ent->r.client->netname, awardMsg ) ) ); ent->r.client->level.stats.awards++; teamlist[ent->s.team].stats.awards++; G_Gametype_ScoreEvent( ent->r.client, "award", awardMsg ); stats = &ent->r.client->level.stats; if( !stats->awardAllocator ) stats->awardAllocator = LinearAllocator( sizeof( gameaward_t ), 0, _G_LevelMalloc, _G_LevelFree ); // ch : this doesnt work for race right? if( GS_MatchState() == MATCH_STATE_PLAYTIME || GS_MatchState() == MATCH_STATE_POSTMATCH ) { // ch : we store this locally to send to MM // first check if we already have this one on the clients list size = LA_Size( stats->awardAllocator ); ga = NULL; for( i = 0; i < size; i++ ) { ga = ( gameaward_t * )LA_Pointer( stats->awardAllocator, i ); if( !strncmp( ga->name, awardMsg, sizeof(ga->name)-1 ) ) break; } if( i >= size ) { ga = ( gameaward_t * )LA_Alloc( stats->awardAllocator ); memset( ga, 0, sizeof(*ga) ); ga->name = G_RegisterLevelString( awardMsg ); } if( ga ) ga->count++; } // add it to every player who's chasing this player for( other = game.edicts + 1; PLAYERNUM( other ) < gs.maxclients; other++ ) { if( !other->r.client || !other->r.inuse || !other->r.client->resp.chase.active ) continue; if( other->r.client->resp.chase.target == ENTNUM( ent ) ) trap_GameCmd( other, cmd ); } }
// from AS void G_SetRaceTime( edict_t *ent, int sector, unsigned int time ) { gclient_t *cl; raceRun_t *rr; cl = ent->r.client; if( ! ent->r.inuse || cl == NULL ) return; rr = &cl->level.stats.currentRun; if( sector < -1 || sector >= rr->numSectors ) return; // normal sector if( sector >= 0 ) rr->times[sector] = time; else if (rr->numSectors > 0) { raceRun_t *nrr; // new global racerun rr->times[rr->numSectors] = time; rr->timestamp = trap_Milliseconds(); // validate the client // no bots for race, at all if( ent->r.svflags & SVF_FAKECLIENT /* && mm_debug_reportbots->value == 0 */ ) { G_Printf("G_SetRaceTime: not reporting fakeclients\n"); return; } if( cl->mm_session <= 0 ) { G_Printf("G_SetRaceTime: not reporting non-registered clients\n"); return; } if( !game.raceruns ) game.raceruns = LinearAllocator( sizeof( raceRun_t ), 0, _G_LevelMalloc, _G_LevelFree ); // push new run nrr = ( raceRun_t * )LA_Alloc( game.raceruns ); memcpy( nrr, rr, sizeof( raceRun_t ) ); // reuse this one in nrr rr->times = 0; // see if we have to push intermediate result if( LA_Size( game.raceruns ) >= RACERUN_BATCH_SIZE ) { G_Match_SendReport(); // double-check this for memory-leaks if( game.raceruns != 0 ) LinearAllocator_Free( game.raceruns ); game.raceruns = 0; } } }
void G_ListRaces_f( void ) { int i, j, size; raceRun_t *run; if( !game.raceruns || !LA_Size( game.raceruns ) ) { G_Printf("No races to report\n"); return; } G_Printf(S_COLOR_RED " session " S_COLOR_YELLOW "times\n"); size = LA_Size( game.raceruns ); for( i = 0; i < size; i++ ) { run = (raceRun_t*)LA_Pointer( game.raceruns, i ); G_Printf(S_COLOR_RED " %d " S_COLOR_YELLOW, run->owner ); for( j = 0; j < run->numSectors; j++ ) G_Printf("%d ", run->times[j] ); G_Printf(S_COLOR_GREEN "%d\n", run->times[run->numSectors]); // SAFE! } }
void G_PlayerMetaAward( edict_t *ent, const char *awardMsg ) { int i, size; gameaward_t *ga; score_stats_t *stats; /* * ch : meta-award is an award that isn't announced but * it is sent to MM */ if( !awardMsg || !awardMsg[0] || !ent->r.client ) return; stats = &ent->r.client->level.stats; if( !stats->awardAllocator ) stats->awardAllocator = LinearAllocator( sizeof( gameaward_t ), 0, _G_LevelMalloc, _G_LevelFree ); // ch : this doesnt work for race right? if( GS_MatchState() == MATCH_STATE_PLAYTIME ) { // ch : we store this locally to send to MM // first check if we already have this one on the clients list size = LA_Size( stats->awardAllocator ); ga = NULL; for( i = 0; i < size; i++ ) { ga = LA_Pointer( stats->awardAllocator, i ); if( !strncmp( ga->name, awardMsg, sizeof(ga->name)-1 ) ) break; } if( i >= size ) { ga = LA_Alloc( stats->awardAllocator ); memset( ga, 0, sizeof(*ga) ); ga->name = G_RegisterLevelString( awardMsg ); } if( ga ) ga->count++; } }
/* * Cmd_Awards_f */ static void Cmd_Awards_f ( edict_t *ent ) { gclient_t *client; gameaward_t *ga; int i, size; static char entry[MAX_TOKEN_CHARS]; assert( ent && ent->r.client ); client = ent->r.client; Q_snprintfz ( entry, sizeof( entry ), "Awards for %s \n", client->netname ); if ( client->level.stats.awardAllocator ) { size = LA_Size( client->level.stats.awardAllocator ); for( i = 0; i < size; i++ ) { ga = ( gameaward_t * )LA_Pointer( client->level.stats.awardAllocator, i ); Q_strncatz( entry, va( "\t%dx %s\n", ga->count, ga->name ), sizeof( entry ) ); } G_PrintMsg( ent, entry ); } }