]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/race.qc
tetris: no longer switch fonts
[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 = floor(0.4 + 10 * 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 = floor(0.4 + 10 * (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 = "/ctsrecord/";
164                                         else
165                                                 rr = "/racerecord/";
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 ", mmsss(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 - t/10, t/10);
176                                         }
177                                         else if(t < grecordtime)
178                                         {
179                                                 if(grecordholder == "")
180                                                         bprint(e.netname, "^7 broke his all-time fastest lap record with ", mmsss(t), "\n");
181                                                 else
182                                                         bprint(e.netname, "^7 broke ", grecordholder, "^7's all-time fastest lap record with ", mmsss(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 - t/10, t/10);
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 ", mmsss(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 ", mmsss(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, floor(10 * (time - race_checkpoint_lasttimes[cp]) + 0.5));
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, floor(10 * (time - othtime) + 0.5));
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         self.nearestwaypoint = waypoint_spawn(trace_endpos, trace_endpos, WAYPOINTFLAG_GENERATED);
516         self.nearestwaypointtimeout = time + 1000000000;
517
518         if(!self.message)
519                 self.message = "went backwards";
520         if (!self.message2)
521                 self.message2 = "was pushed backwards by";
522         if (!self.race_penalty_reason)
523                 self.race_penalty_reason = "missing a checkpoint";
524         
525         self.race_checkpoint = self.cnt;
526
527         if(self.race_checkpoint > race_highest_checkpoint)
528         {
529                 race_highest_checkpoint = self.race_checkpoint;
530                 if(self.spawnflags & 8)
531                         race_timed_checkpoint = self.race_checkpoint;
532                 else
533                         race_timed_checkpoint = 0;
534         }
535
536         if(!self.race_penalty)
537         {
538                 if(self.race_checkpoint)
539                         WaypointSprite_SpawnFixed("race-checkpoint", o, self, sprite);
540                 else
541                         WaypointSprite_SpawnFixed("race-finish", o, self, sprite);
542         }
543
544         self.sprite.waypointsprite_visible_for_player = race_waypointsprite_visible_for_player;
545
546         InitializeEntity(self, trigger_race_checkpoint_verify, INITPRIO_FINDTARGET);
547 }
548
549 void race_AbandonRaceCheck(entity p)
550 {
551         if(race_completing && !p.race_completed)
552         {
553                 p.race_completed = 1;
554                 MAKE_INDEPENDENT_PLAYER(p);
555                 bprint(p.netname, "^7 has abandoned the race.\n");
556                 ClientData_Touch(p);
557         }
558 }
559
560 void race_StartCompleting()
561 {
562         entity p;
563         race_completing = 1;
564         FOR_EACH_PLAYER(p)
565                 if(p.deadflag != DEAD_NO)
566                         race_AbandonRaceCheck(p);
567 }
568
569 void race_PreparePlayer()
570 {
571         race_ClearTime(self);
572         self.race_place = 0;
573 }
574
575 void race_RetractPlayer()
576 {
577         if(!g_race && !g_cts)
578                 return;
579         self.race_checkpoint = race_PreviousCheckpoint(self.race_checkpoint);
580         if(self.race_checkpoint == 0)
581         {
582                 race_ClearTime(self);
583                 self.race_checkpoint = 0;
584         }
585 }
586
587 void race_PreDie()
588 {
589         if(!g_race && !g_cts)
590                 return;
591
592         race_AbandonRaceCheck(self);
593 }
594
595 void race_PreSpawn()
596 {
597         if(!g_race && !g_cts)
598                 return;
599         if(self.killcount == -666 || g_race_qualifying)
600                 race_PreparePlayer();
601
602         race_AbandonRaceCheck(self);
603 }
604
605 void race_PostSpawn(entity spot)
606 {
607         if(!g_race && !g_cts)
608                 return;
609         if(self.killcount != -666 && !g_race_qualifying)
610         {
611                 if(spot.target == "")
612                         // let the player run without timing, if he did not spawn at a targetting spawnpoint
613                         race_PreparePlayer();
614                 else
615                         race_RetractPlayer();
616         }
617
618         if(spot.target != "" && self.race_checkpoint == -1)
619                 self.race_checkpoint = 0;
620
621         self.race_place = 0;
622 }
623
624 void race_PreSpawnObserver()
625 {
626         if(!g_race && !g_cts)
627                 return;
628         race_PreparePlayer();
629 }
630
631 void spawnfunc_info_player_race (void)
632 {
633         if(!g_race && !g_cts)
634         {
635                 remove(self);
636                 return;
637         }
638         ++race_spawns;
639         spawnfunc_info_player_deathmatch();
640
641         if(self.race_place > race_highest_place_spawn)
642                 race_highest_place_spawn = self.race_place;
643         if(self.race_place < race_lowest_place_spawn)
644                 race_lowest_place_spawn = self.race_place;
645 }
646
647 void race_ClearRecords()
648 {
649         float i;
650         entity e;
651
652         for(i = 0; i < MAX_CHECKPOINTS; ++i)
653         {
654                 race_checkpoint_records[i] = 0;
655                 if(race_checkpoint_recordholders[i])
656                         strunzone(race_checkpoint_recordholders[i]);
657                 race_checkpoint_recordholders[i] = string_null;
658         }
659
660         FOR_EACH_CLIENT(e)
661                 race_ClearTime(e);
662 }
663
664 void race_ReadyRestart()
665 {
666         float s;
667
668         Score_NicePrint(world);
669
670         race_ClearRecords();
671         PlayerScore_Sort(race_place);
672
673         entity e;
674         FOR_EACH_CLIENT(e)
675         {
676                 if(e.race_place)
677                 {
678                         s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
679                         if(!s)
680                                 e.race_place = 0;
681                 }
682                 print(e.netname, " = ", ftos(e.race_place), "\n");
683         }
684
685         if(g_race_qualifying == 2)
686         {
687                 g_race_qualifying = 0;
688                 independent_players = 0;
689                 cvar_set("fraglimit", ftos(race_fraglimit));
690                 cvar_set("leadlimit", ftos(race_leadlimit));
691                 cvar_set("timelimit", ftos(race_timelimit));
692                 ScoreRules_race();
693         }
694 }
695
696 void race_ImposePenaltyTime(entity pl, float penalty, string reason)
697 {
698         if(g_race_qualifying)
699         {
700                 pl.race_penalty_accumulator += penalty;
701                 msg_entity = pl;
702                 WRITESPECTATABLE_MSG_ONE({
703                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
704                         WriteByte(MSG_ONE, TE_CSQC_RACE);
705                         WriteByte(MSG_ONE, RACE_NET_PENALTY_QUALIFYING);
706                         WriteByte(MSG_ONE, floor(0.4 + 10 * penalty));
707                         WriteString(MSG_ONE, reason);
708                 });
709         }
710         else
711         {
712                 pl.race_penalty = time + penalty;
713                 msg_entity = pl;
714                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy, {
715                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
716                         WriteByte(MSG_ONE, TE_CSQC_RACE);
717                         WriteByte(MSG_ONE, RACE_NET_PENALTY_RACE);
718                         WriteByte(MSG_ONE, floor(0.4 + 10 * penalty));
719                         WriteString(MSG_ONE, reason);
720                 });
721         }
722 }
723
724 void penalty_touch()
725 {
726         EXACTTRIGGER_TOUCH;
727         if(other.race_lastpenalty != self)
728         {
729                 other.race_lastpenalty = self;
730                 race_ImposePenaltyTime(other, self.race_penalty, self.race_penalty_reason);
731         }
732 }
733
734 void penalty_use()
735 {
736         race_ImposePenaltyTime(activator, self.race_penalty, self.race_penalty_reason);
737 }
738
739 void spawnfunc_trigger_race_penalty()
740 {
741         EXACTTRIGGER_INIT;
742
743         self.use = penalty_use;
744         if not(self.spawnflags & 1)
745                 self.touch = penalty_touch;
746
747         if (!self.race_penalty_reason)
748                 self.race_penalty_reason = "missing a checkpoint";
749         if (!self.race_penalty)
750                 self.race_penalty = 5;
751 }