Skip to content

Commit d1c6188

Browse files
committed
RACE: Only keep pacemaker records for the QW-Group#1 record
1 parent 61564b0 commit d1c6188

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed

src/race.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ static void race_update_pacemaker(void);
119119
static void race_clear_pacemaker(void);
120120
static void race_init_capture(void);
121121
static void race_save_position(void);
122-
static void race_finish_capture(qbool store, char* filename);
122+
static void race_finish_capture(qbool store);
123123
static void race_pacemaker_race_start(void);
124124
static void race_remove_pacemaker_indicator(void);
125125
static void race_make_active_racer(gedict_t* r, gedict_t* s);
126126
static qbool race_end(gedict_t* racer, qbool valid, qbool complete);
127127
static char* race_position_string(int position);
128128
static qbool race_simultaneous(void);
129129
static void race_update_closest_positions(void);
130-
static void race_match_round_end(char* demoFileName);
130+
static void race_match_round_end(void);
131131

132132
void StatsToFile ();
133133

@@ -160,15 +160,15 @@ static int get_server_port ( void )
160160
return i;
161161
}
162162

163-
static const char* race_top_filename(void)
163+
static const char* race_filename(const char* extension)
164164
{
165165
static char filename[128];
166166

167167
if (cvar("k_race_times_per_port")) {
168-
snprintf(filename, sizeof(filename), "race/race[%s_r%02d]-w%1ds%1d_%d.top", g_globalvars.mapname, race.active_route, race.weapon, race.falsestart, get_server_port());
168+
snprintf(filename, sizeof(filename), "race/race[%s_r%02d]-w%1ds%1d_%d.%s", g_globalvars.mapname, race.active_route, race.weapon, race.falsestart, get_server_port(), extension);
169169
}
170170
else {
171-
snprintf(filename, sizeof(filename), "race/race[%s_r%02d]-w%1ds%1d.top", g_globalvars.mapname, race.active_route, race.weapon, race.falsestart);
171+
snprintf(filename, sizeof(filename), "race/race[%s_r%02d]-w%1ds%1d.%s", g_globalvars.mapname, race.active_route, race.weapon, race.falsestart, extension);
172172
}
173173

174174
return filename;
@@ -1115,6 +1115,7 @@ static void race_over(void)
11151115
{
11161116
char demoFileName[MAX_OSPATH];
11171117
int i, timeposition, nameposition;
1118+
int best_time_position = 1000;
11181119
char* pos;
11191120
gedict_t* racer = NULL;
11201121
qbool keep_demo = false;
@@ -1262,7 +1263,8 @@ static void race_over(void)
12621263
race_position_string(timeposition + 1)
12631264
);
12641265

1265-
keep_demo |= timeposition == 0 || !blocked_record;
1266+
best_time_position = min(timeposition, best_time_position);
1267+
keep_demo |= !blocked_record;
12661268
}
12671269
}
12681270
else {
@@ -1279,11 +1281,11 @@ static void race_over(void)
12791281
}
12801282

12811283
if (race_match_started()) {
1282-
race_match_round_end(demoFileName);
1284+
race_match_round_end();
12831285
}
12841286
else {
12851287
// Continue match with next run
1286-
race_finish_capture(keep_demo, demoFileName);
1288+
race_finish_capture(best_time_position == 0 && !blocked_record);
12871289
race_start(!keep_demo, "");
12881290
}
12891291
}
@@ -2736,7 +2738,7 @@ qbool race_load_route( int route )
27362738
read_topscores();
27372739

27382740
if (!strnull(cvar_string("cs_address"))) {
2739-
localcmd("\nsv_web_postfile ServerApi/UploadTopFile \"\" %s\n", race_top_filename());
2741+
localcmd("\nsv_web_postfile ServerApi/UploadTopFile \"\" %s\n", race_filename("top"));
27402742
trap_executecmd();
27412743
}
27422744

@@ -2908,7 +2910,7 @@ void write_topscores( void )
29082910
if ( !race.active_route )
29092911
return;
29102912

2911-
race_fwopen("%s", race_top_filename());
2913+
race_fwopen("%s", race_filename("top"));
29122914
if ( race_fhandle < 0 )
29132915
return;
29142916

@@ -2972,7 +2974,7 @@ void read_topscores( void )
29722974
if ( !race.active_route )
29732975
return;
29742976

2975-
race_fropen("%s", race_top_filename());
2977+
race_fropen("%s", race_filename("top"));
29762978
if ( race_fhandle >= 0 )
29772979
{
29782980
race_fgets( line, MAX_TXTLEN );
@@ -3550,29 +3552,13 @@ void race_pacemaker(void)
35503552
}
35513553
else {
35523554
position = 0;
3553-
if (trap_CmdArgc() == 2) {
3554-
position = atoi(buffer);
3555-
3556-
if (position == 0 && buffer[0] != '0') {
3557-
G_sprint(self, PRINT_HIGH, "Unknown pacemaker command '%s'.\n", buffer);
3558-
return;
3559-
}
3560-
3561-
--position;
3562-
}
3563-
3564-
if (position < 0 || position >= sizeof(race.records) / sizeof(race.records[0]) || race.records[position].time >= RACE_INVALID_RECORD_TIME)
3565-
{
3566-
G_sprint(self, PRINT_HIGH, "No race record #%2d.\n", position + 1);
3567-
return;
3568-
}
35693555
}
35703556

35713557
// Try and load
3572-
race_fropen("race/%s.pos", race.records[position].demoname);
3558+
race_fropen("%s", race_filename("pos"));
35733559
if (race_fhandle < 0)
35743560
{
3575-
G_sprint(self, PRINT_HIGH, "Unable to load positions for record #%2d.\n", position + 1);
3561+
G_sprint(self, PRINT_HIGH, "Unable to load pacemaker record.\n", position + 1);
35763562
return;
35773563
}
35783564

@@ -3763,13 +3749,13 @@ static void race_init_capture(void)
37633749
}
37643750
}
37653751

3766-
static void race_finish_capture(qbool store, char* filename)
3752+
static void race_finish_capture(qbool store)
37673753
{
37683754
// Multi-racing: only store positions for those setting a record?
37693755
gedict_t* racer;
37703756

37713757
if (store && race.race_recording) {
3772-
race_fwopen("race/%s.pos", filename);
3758+
race_fwopen("%s", race_filename("pos"));
37733759
race_fprintf("version %d\n", POS_FILE_VERSION);
37743760

37753761
for (racer = world; (racer = race_find_race_participants(racer)); /**/) {
@@ -4519,7 +4505,7 @@ void race_switch_usermode(const char* displayName, int players_per_team)
45194505
}
45204506

45214507
// Return true if new countdown should be started
4522-
static void race_match_round_end(char* demoFileName)
4508+
static void race_match_round_end(void)
45234509
{
45244510
gedict_t* racer;
45254511

@@ -4581,7 +4567,7 @@ static void race_match_round_end(char* demoFileName)
45814567
}
45824568
else {
45834569
// We have a winner, end the race
4584-
race_finish_capture(true, demoFileName);
4570+
race_finish_capture(false);
45854571
EndMatch(false);
45864572
return;
45874573
}
@@ -4595,7 +4581,7 @@ static void race_match_round_end(char* demoFileName)
45954581
if (system->round_max_diff && rounds_remaining * system->round_max_diff < sc) {
45964582
// We have winner, end the race
45974583
G_bprint(PRINT_HIGH, "%d points (%d rounds) available... ending match\n", rounds_remaining * system->round_max_diff, rounds_remaining);
4598-
race_finish_capture(true, demoFileName);
4584+
race_finish_capture(false);
45994585
EndMatch(false);
46004586
return;
46014587
}

0 commit comments

Comments
 (0)