]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/race.qc
- do not crash on "disconnect" or "quit" in CTF
[divverent/nexuiz.git] / data / qcsrc / server / race.qc
1 #define MAX_CHECKPOINTS 255
2
3 .float race_penalty;
4 .float race_penalty_accumulator;
5 .string race_penalty_reason;
6 .float race_checkpoint; // player: next checkpoint that has to be reached
7 .float race_laptime;
8 .entity race_lastpenalty;
9
10 .entity sprite;
11
12 float race_checkpoint_records[MAX_CHECKPOINTS];
13 string race_checkpoint_recordholders[MAX_CHECKPOINTS];
14 float race_checkpoint_lasttimes[MAX_CHECKPOINTS];
15 float race_checkpoint_lastlaps[MAX_CHECKPOINTS];
16 entity race_checkpoint_lastplayers[MAX_CHECKPOINTS];
17
18 float race_highest_checkpoint;
19 float race_timed_checkpoint;
20
21 float race_NextCheckpoint(float f)
22 {
23         if(f >= race_highest_checkpoint)
24                 return 0;
25         else
26                 return f + 1;
27 }
28
29 float race_PreviousCheckpoint(float f)
30 {
31         if(f == -1)
32                 return 0;
33         else if(f == 0)
34                 return race_highest_checkpoint;
35         else
36                 return f - 1;
37 }
38
39 // encode as:
40 //   0 = common start/finish
41 // 254 = start
42 // 255 = finish
43 float race_CheckpointNetworkID(float f)
44 {
45         if(race_timed_checkpoint)
46         {
47                 if(f == 0)
48                         return 254; // start
49                 else if(f == race_timed_checkpoint)
50                         return 255; // finish
51         }
52         return f;
53 }
54
55 void race_SendNextCheckpoint(entity e, float spec)
56 {
57         float recordtime;
58         string recordholder;
59         float cp;
60
61         if(!e.race_laptime)
62                 return;
63
64         cp = e.race_checkpoint;
65         recordtime = race_checkpoint_records[cp];
66         recordholder = race_checkpoint_recordholders[cp];
67         if(recordholder == e.netname)
68                 recordholder = "";
69
70         if(!spec)
71                 msg_entity = e;
72         WRITESPECTATABLE_MSG_ONE({
73                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
74                 WriteByte(MSG_ONE, TE_CSQC_RACE);
75                 if(spec)
76                 {
77                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING);
78                         WriteCoord(MSG_ONE, e.race_laptime - e.race_penalty_accumulator);
79                 }
80                 else
81                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_QUALIFYING);
82                 WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player will be at next
83                 WriteShort(MSG_ONE, recordtime);
84                 WriteString(MSG_ONE, recordholder);
85         });
86 }
87
88 void race_InitSpectator()
89 {
90         if(g_race_qualifying)
91                 if(msg_entity.enemy.race_laptime)
92                         race_SendNextCheckpoint(msg_entity.enemy, 1);
93 }
94
95 void race_SendTime(entity e, float cp, float t, float tvalid)
96 {
97         float snew, l;
98         entity p;
99
100         if(g_race_qualifying)
101                 t += e.race_penalty_accumulator;
102
103         t = TIME_ENCODE(t); // make integer
104         // adding just 0.4 so it rounds down in the .5 case (matching the timer display)
105
106         if(tvalid)
107         if(cp == race_timed_checkpoint) // finish line
108         if not(e.race_completed)
109         {
110                 float s;
111                 if(g_race_qualifying)
112                 {
113                         s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
114                         if(!s || t < s)
115                                 PlayerScore_Add(e, SP_RACE_FASTEST, t - s);
116                 }
117                 else
118                 {
119                         s = PlayerScore_Add(e, SP_RACE_TIME, 0);
120                         snew = TIME_ENCODE(time - game_starttime);
121                         PlayerScore_Add(e, SP_RACE_TIME, snew - s);
122                         l = PlayerTeamScore_Add(e, SP_RACE_LAPS, ST_RACE_LAPS, 1);
123
124                         if(cvar("fraglimit"))
125                                 if(l >= cvar("fraglimit"))
126                                         race_StartCompleting();
127
128                         if(race_completing)
129                         {
130                                 e.race_completed = 1;
131                                 MAKE_INDEPENDENT_PLAYER(e);
132                                 bprint(e.netname, "^7 has finished the race.\n");
133                                 ClientData_Touch(e);
134                         }
135                 }
136         }
137
138         float recordtime;
139         string recordholder;
140
141         if(g_race_qualifying)
142         {
143                 if(tvalid)
144                 {
145                         recordtime = race_checkpoint_records[cp];
146                         recordholder = strcat1(race_checkpoint_recordholders[cp]); // make a tempstring copy, as we'll possibly strunzone it!
147                         if(recordholder == e.netname)
148                                 recordholder = "";
149
150                         if(t != 0)
151                         if(t < recordtime || recordtime == 0)
152                         {
153                                 race_checkpoint_records[cp] = t;
154                                 if(race_checkpoint_recordholders[cp])
155                                         strunzone(race_checkpoint_recordholders[cp]);
156                                 race_checkpoint_recordholders[cp] = strzone(e.netname);
157                                 if(cp == race_timed_checkpoint)
158                                 {
159                                         float grecordtime;
160                                         string grecordholder;
161                                         string rr;
162                                         if(g_cts)
163                                                 rr = CTS_RECORD;
164                                         else
165                                                 rr = RACE_RECORD;
166                                         grecordtime = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
167                                         grecordholder = db_get(ServerProgsDB, strcat(GetMapname(), rr, "netname"));
168                                         if(grecordholder == e.netname)
169                                                 grecordholder = "";
170                                         if(grecordtime == 0)
171                                         {
172                                                 bprint(e.netname, "^7 set the all-time fastest lap record with ", TIME_ENCODED_TOSTRING(t), "\n");
173                                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t));
174                                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname);
175                                                 write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t));
176                                         }
177                                         else if(t < grecordtime)
178                                         {
179                                                 if(grecordholder == "")
180                                                         bprint(e.netname, "^7 broke his all-time fastest lap record with ", TIME_ENCODED_TOSTRING(t), "\n");
181                                                 else
182                                                         bprint(e.netname, "^7 broke ", grecordholder, "^7's all-time fastest lap record with ", TIME_ENCODED_TOSTRING(t), "\n");
183                                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t));
184                                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname);
185                                                 write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t));
186                                         }
187                                         else
188                                         {
189                                                 if(grecordholder == "")
190                                                         bprint(e.netname, "^7's new fastest lap could not break his all-time fastest lap record of ", TIME_ENCODED_TOSTRING(grecordtime), "\n");
191                                                 else
192                                                         bprint(e.netname, "^7's new fastest lap could not break ", grecordholder, "^7's all-time fastest lap record of ", TIME_ENCODED_TOSTRING(grecordtime), "\n");
193                                         }
194                                 }
195
196                                 if(g_race_qualifying)
197                                 {
198                                         FOR_EACH_REALPLAYER(p)
199                                                 if(p.race_checkpoint == cp)
200                                                         race_SendNextCheckpoint(p, 0);
201                                 }
202                         }
203                 }
204                 else
205                 {
206                         // dummies
207                         t = 0;
208                         recordtime = 0;
209                         recordholder = "";
210                 }
211
212                 msg_entity = e;
213                 if(g_race_qualifying)
214                 {
215                         WRITESPECTATABLE_MSG_ONE_VARNAME(dummy1, {
216                                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
217                                 WriteByte(MSG_ONE, TE_CSQC_RACE);
218                                 WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_QUALIFYING);
219                                 WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
220                                 WriteShort(MSG_ONE, t); // time to that intermediate
221                                 WriteShort(MSG_ONE, recordtime); // previously best time
222                                 WriteString(MSG_ONE, recordholder); // record holder
223                         });
224                 }
225         }
226         else // RACE! Not Qualifying
227         {
228                 float lself, lother, othtime;
229                 entity oth;
230                 oth = race_checkpoint_lastplayers[cp];
231                 if(oth)
232                 {
233                         lself = PlayerScore_Add(e, SP_RACE_LAPS, 0);
234                         lother = race_checkpoint_lastlaps[cp];
235                         othtime = race_checkpoint_lasttimes[cp];
236                 }
237                 else
238                         lself = lother = othtime = 0;
239
240                 msg_entity = e;
241                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy2, {
242                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
243                         WriteByte(MSG_ONE, TE_CSQC_RACE);
244                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE);
245                         WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
246                         if(e == oth)
247                         {
248                                 WriteShort(MSG_ONE, 0);
249                                 WriteByte(MSG_ONE, 0);
250                                 WriteString(MSG_ONE, "");
251                         }
252                         else
253                         {
254                                 WriteShort(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp]));
255                                 WriteByte(MSG_ONE, lself - lother);
256                                 WriteString(MSG_ONE, oth.netname); // record holder
257                         }
258                 });
259
260                 race_checkpoint_lastplayers[cp] = e;
261                 race_checkpoint_lasttimes[cp] = time;
262                 race_checkpoint_lastlaps[cp] = lself;
263
264                 msg_entity = oth;
265                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
266                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
267                         WriteByte(MSG_ONE, TE_CSQC_RACE);
268                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT);
269                         WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
270                         if(e == oth)
271                         {
272                                 WriteShort(MSG_ONE, 0);
273                                 WriteByte(MSG_ONE, 0);
274                                 WriteString(MSG_ONE, "");
275                         }
276                         else
277                         {
278                                 WriteShort(MSG_ONE, TIME_ENCODE(time - othtime));
279                                 WriteByte(MSG_ONE, lother - lself);
280                                 WriteString(MSG_ONE, e.netname); // record holder
281                         }
282                 });
283         }
284 }
285
286 void race_ClearTime(entity e)
287 {
288         e.race_checkpoint = -1;
289         e.race_laptime = 0;
290         e.race_penalty_accumulator = 0;
291         e.race_lastpenalty = world;
292
293         msg_entity = e;
294         WRITESPECTATABLE_MSG_ONE({
295                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
296                 WriteByte(MSG_ONE, TE_CSQC_RACE);
297                 WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_CLEAR); // next
298         });
299 }
300
301 void dumpsurface(entity e)
302 {
303         float n, si, ni;
304         vector norm, vec;
305         print("Surfaces of ", etos(e), ":\n");
306
307         print("TEST = ", ftos(getsurfacenearpoint(e, '0 0 0')), "\n");
308
309         for(si = 0; ; ++si)
310         {
311                 n = getsurfacenumpoints(e, si);
312                 if(n <= 0)
313                         break;
314                 print("  Surface ", ftos(si), ":\n");
315                 norm = getsurfacenormal(e, si);
316                 print("    Normal = ", vtos(norm), "\n");
317                 for(ni = 0; ni < n; ++ni)
318                 {
319                         vec = getsurfacepoint(e, si, ni);
320                         print("    Point ", ftos(ni), " = ", vtos(vec), " (", ftos(norm * vec), ")\n");
321                 }
322         }
323 }
324
325 void checkpoint_passed()
326 {
327         string oldmsg;
328
329         if(other.classname == "porto")
330         {
331                 // do not allow portalling through checkpoints
332                 trace_plane_normal = normalize(-1 * other.velocity);
333                 self = other;
334                 W_Porto_Fail(0);
335                 return;
336         }
337
338         /*
339          * Trigger targets
340          */
341         if not(self.spawnflags & 2)
342         {
343                 activator = other;
344                 oldmsg = self.message;
345                 self.message = "";
346                 SUB_UseTargets();
347                 self.message = oldmsg;
348         }
349
350         if(other.classname != "player")
351                 return;
352
353         /*
354          * Remove unauthorized equipment
355          */
356         Portal_ClearAll(other);
357
358         other.porto_forbidden = 2; // decreased by 1 each StartFrame
359
360         if(other.race_checkpoint == -1 || other.race_checkpoint == self.race_checkpoint)
361         {
362                 if(self.race_penalty)
363                 {
364                         if(other.race_lastpenalty != self)
365                         {
366                                 other.race_lastpenalty = self;
367                                 race_ImposePenaltyTime(other, self.race_penalty, self.race_penalty_reason);
368                         }
369                 }
370
371                 if(other.race_penalty)
372                         return;
373
374                 /*
375                  * Trigger targets
376                  */
377                 if(self.spawnflags & 2)
378                 {
379                         activator = other;
380                         oldmsg = self.message;
381                         self.message = "";
382                         SUB_UseTargets();
383                         self.message = oldmsg;
384                 }
385
386                 other.race_checkpoint = race_NextCheckpoint(self.race_checkpoint);
387
388                 race_SendTime(other, self.race_checkpoint, time - other.race_laptime, !!other.race_laptime);
389
390                 if(!self.race_checkpoint) // start line
391                 {
392                         other.race_laptime = time;
393                         other.race_penalty_accumulator = 0;
394                         other.race_lastpenalty = world;
395                 }
396
397                 if(g_race_qualifying)
398                         race_SendNextCheckpoint(other, 0);
399         }
400         else if(other.race_checkpoint == race_NextCheckpoint(self.race_checkpoint))
401         {
402                 // ignored
403         }
404         else
405         {
406                 if(self.spawnflags & 4)
407                         Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
408         }
409 }
410
411 void checkpoint_touch()
412 {
413         EXACTTRIGGER_TOUCH;
414         checkpoint_passed();
415 }
416
417 void checkpoint_use()
418 {
419         if(other.classname == "info_player_deathmatch") // a spawn, a spawn
420                 return;
421
422         other = activator;
423         checkpoint_passed();
424 }
425
426 float race_waypointsprite_visible_for_player(entity e)
427 {
428         if(e.race_checkpoint == -1)
429                 return TRUE;
430         else if(e.race_checkpoint == self.owner.race_checkpoint)
431                 return TRUE;
432         else
433                 return FALSE;
434 }
435
436 float have_verified;
437 void trigger_race_checkpoint_verify()
438 {
439         entity oldself, cp;
440         float i, p;
441         float qual;
442
443         if(have_verified)
444                 return;
445         have_verified = 1;
446         
447         qual = g_race_qualifying;
448
449         oldself = self;
450         self = spawn();
451         self.classname = "player";
452
453         for(i = 0; i <= race_highest_checkpoint; ++i)
454         {
455                 self.race_checkpoint = race_NextCheckpoint(i);
456
457                 // race only (middle of the race)
458                 g_race_qualifying = 0;
459                 self.race_place = 0;
460                 if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
461                         error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for respawning in race) - bailing out"));
462
463                 if(i == 0)
464                 {
465                         // qualifying only
466                         g_race_qualifying = 1;
467                         self.race_place = race_lowest_place_spawn;
468                         if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
469                                 error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for qualifying) - bailing out"));
470                         
471                         // race only (initial spawn)
472                         g_race_qualifying = 0;
473                         for(p = 1; p <= race_highest_place_spawn; ++p)
474                         {
475                                 self.race_place = p;
476                                 if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
477                                         error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for initially spawning in race) - bailing out"));
478                         }
479                 }
480         }
481
482         g_race_qualifying = qual;
483
484         if(race_timed_checkpoint)
485                 for(cp = world; (cp = find(cp, classname, "trigger_race_checkpoint")); )
486                         if(cp.sprite)
487                         {
488                                 if(cp.race_checkpoint == 0)
489                                         WaypointSprite_UpdateSprites(cp.sprite, "race-start", "", "");
490                                 else if(cp.race_checkpoint == race_timed_checkpoint)
491                                         WaypointSprite_UpdateSprites(cp.sprite, "race-finish", "", "");
492                         }
493
494         remove(self);
495         self = oldself;
496 }
497
498 void spawnfunc_trigger_race_checkpoint()
499 {
500         vector o;
501         if(!g_race && !g_cts)
502         {
503                 remove(self);
504                 return;
505         }
506
507         EXACTTRIGGER_INIT;
508
509         self.use = checkpoint_use;
510         if not(self.spawnflags & 1)
511                 self.touch = checkpoint_touch;
512
513         o = (self.absmin + self.absmax) * 0.5;
514         tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o_z - self.absmin_z), MOVE_NORMAL, self);
515         waypoint_spawnforitem_force(self, trace_endpos);
516
517         if(!self.message)
518                 self.message = "went backwards";
519         if (!self.message2)
520                 self.message2 = "was pushed backwards by";
521         if (!self.race_penalty_reason)
522                 self.race_penalty_reason = "missing a checkpoint";
523         
524         self.race_checkpoint = self.cnt;
525
526         if(self.race_checkpoint > race_highest_checkpoint)
527         {
528                 race_highest_checkpoint = self.race_checkpoint;
529                 if(self.spawnflags & 8)
530                         race_timed_checkpoint = self.race_checkpoint;
531                 else
532                         race_timed_checkpoint = 0;
533         }
534
535         if(!self.race_penalty)
536         {
537                 if(self.race_checkpoint)
538                         WaypointSprite_SpawnFixed("race-checkpoint", o, self, sprite);
539                 else
540                         WaypointSprite_SpawnFixed("race-finish", o, self, sprite);
541         }
542
543         self.sprite.waypointsprite_visible_for_player = race_waypointsprite_visible_for_player;
544
545         InitializeEntity(self, trigger_race_checkpoint_verify, INITPRIO_FINDTARGET);
546 }
547
548 void race_AbandonRaceCheck(entity p)
549 {
550         if(race_completing && !p.race_completed)
551         {
552                 p.race_completed = 1;
553                 MAKE_INDEPENDENT_PLAYER(p);
554                 bprint(p.netname, "^7 has abandoned the race.\n");
555                 ClientData_Touch(p);
556         }
557 }
558
559 void race_StartCompleting()
560 {
561         entity p;
562         race_completing = 1;
563         FOR_EACH_PLAYER(p)
564                 if(p.deadflag != DEAD_NO)
565                         race_AbandonRaceCheck(p);
566 }
567
568 void race_PreparePlayer()
569 {
570         race_ClearTime(self);
571         self.race_place = 0;
572 }
573
574 void race_RetractPlayer()
575 {
576         if(!g_race && !g_cts)
577                 return;
578         self.race_checkpoint = race_PreviousCheckpoint(self.race_checkpoint);
579         if(self.race_checkpoint == 0)
580         {
581                 race_ClearTime(self);
582                 self.race_checkpoint = 0;
583         }
584 }
585
586 void race_PreDie()
587 {
588         if(!g_race && !g_cts)
589                 return;
590
591         race_AbandonRaceCheck(self);
592 }
593
594 void race_PreSpawn()
595 {
596         if(!g_race && !g_cts)
597                 return;
598         if(self.killcount == -666 || g_race_qualifying)
599                 race_PreparePlayer();
600
601         race_AbandonRaceCheck(self);
602 }
603
604 void race_PostSpawn(entity spot)
605 {
606         if(!g_race && !g_cts)
607                 return;
608         if(self.killcount != -666 && !g_race_qualifying)
609         {
610                 if(spot.target == "")
611                         // let the player run without timing, if he did not spawn at a targetting spawnpoint
612                         race_PreparePlayer();
613                 else
614                         race_RetractPlayer();
615         }
616
617         if(spot.target != "" && self.race_checkpoint == -1)
618                 self.race_checkpoint = 0;
619
620         self.race_place = 0;
621 }
622
623 void race_PreSpawnObserver()
624 {
625         if(!g_race && !g_cts)
626                 return;
627         race_PreparePlayer();
628 }
629
630 void spawnfunc_info_player_race (void)
631 {
632         if(!g_race && !g_cts)
633         {
634                 remove(self);
635                 return;
636         }
637         ++race_spawns;
638         spawnfunc_info_player_deathmatch();
639
640         if(self.race_place > race_highest_place_spawn)
641                 race_highest_place_spawn = self.race_place;
642         if(self.race_place < race_lowest_place_spawn)
643                 race_lowest_place_spawn = self.race_place;
644 }
645
646 void race_ClearRecords()
647 {
648         float i;
649         entity e;
650
651         for(i = 0; i < MAX_CHECKPOINTS; ++i)
652         {
653                 race_checkpoint_records[i] = 0;
654                 if(race_checkpoint_recordholders[i])
655                         strunzone(race_checkpoint_recordholders[i]);
656                 race_checkpoint_recordholders[i] = string_null;
657         }
658
659         FOR_EACH_CLIENT(e)
660                 race_ClearTime(e);
661 }
662
663 void race_ReadyRestart()
664 {
665         float s;
666
667         Score_NicePrint(world);
668
669         race_ClearRecords();
670         PlayerScore_Sort(race_place);
671
672         entity e;
673         FOR_EACH_CLIENT(e)
674         {
675                 if(e.race_place)
676                 {
677                         s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
678                         if(!s)
679                                 e.race_place = 0;
680                 }
681                 print(e.netname, " = ", ftos(e.race_place), "\n");
682         }
683
684         if(g_race_qualifying == 2)
685         {
686                 g_race_qualifying = 0;
687                 independent_players = 0;
688                 cvar_set("fraglimit", ftos(race_fraglimit));
689                 cvar_set("leadlimit", ftos(race_leadlimit));
690                 cvar_set("timelimit", ftos(race_timelimit));
691                 ScoreRules_race();
692         }
693 }
694
695 void race_ImposePenaltyTime(entity pl, float penalty, string reason)
696 {
697         if(g_race_qualifying)
698         {
699                 pl.race_penalty_accumulator += penalty;
700                 msg_entity = pl;
701                 WRITESPECTATABLE_MSG_ONE({
702                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
703                         WriteByte(MSG_ONE, TE_CSQC_RACE);
704                         WriteByte(MSG_ONE, RACE_NET_PENALTY_QUALIFYING);
705                         WriteShort(MSG_ONE, TIME_ENCODE(penalty));
706                         WriteString(MSG_ONE, reason);
707                 });
708         }
709         else
710         {
711                 pl.race_penalty = time + penalty;
712                 msg_entity = pl;
713                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy, {
714                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
715                         WriteByte(MSG_ONE, TE_CSQC_RACE);
716                         WriteByte(MSG_ONE, RACE_NET_PENALTY_RACE);
717                         WriteShort(MSG_ONE, TIME_ENCODE(penalty));
718                         WriteString(MSG_ONE, reason);
719                 });
720         }
721 }
722
723 void penalty_touch()
724 {
725         EXACTTRIGGER_TOUCH;
726         if(other.race_lastpenalty != self)
727         {
728                 other.race_lastpenalty = self;
729                 race_ImposePenaltyTime(other, self.race_penalty, self.race_penalty_reason);
730         }
731 }
732
733 void penalty_use()
734 {
735         race_ImposePenaltyTime(activator, self.race_penalty, self.race_penalty_reason);
736 }
737
738 void spawnfunc_trigger_race_penalty()
739 {
740         EXACTTRIGGER_INIT;
741
742         self.use = penalty_use;
743         if not(self.spawnflags & 1)
744                 self.touch = penalty_touch;
745
746         if (!self.race_penalty_reason)
747                 self.race_penalty_reason = "missing a checkpoint";
748         if (!self.race_penalty)
749                 self.race_penalty = 5;
750 }