]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/race.qc
fix race penalties
[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         /*
68         recordtime = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/racerecord/", ftos(cp), "/time")));
69         recordholder = db_get(ServerProgsDB, strcat(GetMapname(), "/racerecord/", ftos(cp), "/netname"));
70         */
71         if(recordholder == e.netname)
72                 recordholder = "";
73
74         if(!spec)
75                 msg_entity = e;
76         WRITESPECTATABLE_MSG_ONE({
77                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
78                 WriteByte(MSG_ONE, TE_CSQC_RACE);
79                 if(spec)
80                 {
81                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING);
82                         WriteCoord(MSG_ONE, e.race_laptime - e.race_penalty_accumulator);
83                 }
84                 else
85                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_QUALIFYING);
86                 WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player will be at next
87                 WriteShort(MSG_ONE, recordtime);
88                 WriteString(MSG_ONE, recordholder);
89         });
90 }
91
92 void race_InitSpectator()
93 {
94         if(g_race_qualifying)
95                 if(msg_entity.enemy.race_laptime)
96                         race_SendNextCheckpoint(msg_entity.enemy, 1);
97 }
98
99 void race_SendTime(entity e, float cp, float t, float tvalid)
100 {
101         float snew, l;
102         entity p;
103
104         if(g_race_qualifying)
105                 t += e.race_penalty_accumulator;
106
107         t = floor(0.4 + 10 * t); // make integer
108         // adding just 0.4 so it rounds down in the .5 case (matching the timer display)
109
110         if(tvalid)
111         if(cp == race_timed_checkpoint) // finish line
112         if not(e.race_completed)
113         {
114                 float s;
115                 if(g_race_qualifying)
116                 {
117                         s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
118                         if(!s || t < s)
119                                 PlayerScore_Add(e, SP_RACE_FASTEST, t - s);
120                 }
121                 else
122                 {
123                         s = PlayerScore_Add(e, SP_RACE_TIME, 0);
124                         snew = floor(0.4 + 10 * (time - game_starttime));
125                         PlayerScore_Add(e, SP_RACE_TIME, snew - s);
126                         l = PlayerTeamScore_Add(e, SP_RACE_LAPS, ST_RACE_LAPS, 1);
127
128                         if(cvar("fraglimit"))
129                                 if(l >= cvar("fraglimit"))
130                                         race_StartCompleting();
131
132                         if(race_completing)
133                         {
134                                 e.race_completed = 1;
135                                 MAKE_INDEPENDENT_PLAYER(e);
136                                 bprint(e.netname, "^7 has finished the race.\n");
137                                 ClientData_Touch(e);
138                         }
139                 }
140         }
141
142         float recordtime;
143         string recordholder;
144
145         if(g_race_qualifying)
146         {
147                 if(tvalid)
148                 {
149                         recordtime = race_checkpoint_records[cp];
150                         recordholder = strcat1(race_checkpoint_recordholders[cp]); // make a tempstring copy, as we'll possibly strunzone it!
151                         if(recordholder == e.netname)
152                                 recordholder = "";
153
154                         if(t != 0)
155                         if(t < recordtime || recordtime == 0)
156                         {
157                                 race_checkpoint_records[cp] = t;
158                                 if(race_checkpoint_recordholders[cp])
159                                         strunzone(race_checkpoint_recordholders[cp]);
160                                 race_checkpoint_recordholders[cp] = strzone(e.netname);
161                                 if(cp == race_timed_checkpoint)
162                                 {
163                                         float grecordtime;
164                                         string grecordholder;
165                                         grecordtime = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/racerecord/time")));
166                                         grecordholder = db_get(ServerProgsDB, strcat(GetMapname(), "/racerecord/netname"));
167                                         if(grecordholder == e.netname)
168                                                 grecordholder = "";
169                                         if(grecordtime == 0)
170                                         {
171                                                 bprint(e.netname, "^7 set the all-time fastest lap record with ", mmsss(t), "\n");
172                                                 db_put(ServerProgsDB, strcat(GetMapname(), "/racerecord/time"), ftos(t));
173                                                 db_put(ServerProgsDB, strcat(GetMapname(), "/racerecord/netname"), e.netname);
174                                                 write_recordmarker(e, time - t/10, t/10);
175                                         }
176                                         else if(t < grecordtime)
177                                         {
178                                                 if(grecordholder == "")
179                                                         bprint(e.netname, "^7 broke his all-time fastest lap record with ", mmsss(t), "\n");
180                                                 else
181                                                         bprint(e.netname, "^7 broke ", grecordholder, "^7's all-time fastest lap record with ", mmsss(t), "\n");
182                                                 db_put(ServerProgsDB, strcat(GetMapname(), "/racerecord/time"), ftos(t));
183                                                 db_put(ServerProgsDB, strcat(GetMapname(), "/racerecord/netname"), e.netname);
184                                                 write_recordmarker(e, time - t/10, t/10);
185                                         }
186                                         else
187                                         {
188                                                 if(grecordholder == "")
189                                                         bprint(e.netname, "^7's new fastest lap could not break his all-time fastest lap record of ", mmsss(grecordtime), "\n");
190                                                 else
191                                                         bprint(e.netname, "^7's new fastest lap could not break ", grecordholder, "^7's all-time fastest lap record of ", mmsss(grecordtime), "\n");
192                                         }
193                                 }
194
195                                 if(g_race_qualifying)
196                                 {
197                                         FOR_EACH_REALPLAYER(p)
198                                                 if(p.race_checkpoint == cp)
199                                                         race_SendNextCheckpoint(p, 0);
200                                 }
201                         }
202                 }
203                 else
204                 {
205                         // dummies
206                         t = 0;
207                         recordtime = 0;
208                         recordholder = "";
209                 }
210
211                 msg_entity = e;
212                 if(g_race_qualifying)
213                 {
214                         WRITESPECTATABLE_MSG_ONE_VARNAME(dummy1, {
215                                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
216                                 WriteByte(MSG_ONE, TE_CSQC_RACE);
217                                 WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_QUALIFYING);
218                                 WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
219                                 WriteShort(MSG_ONE, t); // time to that intermediate
220                                 WriteShort(MSG_ONE, recordtime); // previously best time
221                                 WriteString(MSG_ONE, recordholder); // record holder
222                         });
223                 }
224         }
225         else // RACE! Not Qualifying
226         {
227                 float lself, lother, othtime;
228                 entity oth;
229                 oth = race_checkpoint_lastplayers[cp];
230                 if(oth)
231                 {
232                         lself = PlayerScore_Add(e, SP_RACE_LAPS, 0);
233                         lother = race_checkpoint_lastlaps[cp];
234                         othtime = race_checkpoint_lasttimes[cp];
235                 }
236                 else
237                         lself = lother = othtime = 0;
238
239                 msg_entity = e;
240                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy2, {
241                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
242                         WriteByte(MSG_ONE, TE_CSQC_RACE);
243                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE);
244                         WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
245                         if(e == oth)
246                         {
247                                 WriteShort(MSG_ONE, 0);
248                                 WriteByte(MSG_ONE, 0);
249                                 WriteString(MSG_ONE, "");
250                         }
251                         else
252                         {
253                                 WriteShort(MSG_ONE, floor(10 * (time - race_checkpoint_lasttimes[cp]) + 0.5));
254                                 WriteByte(MSG_ONE, lself - lother);
255                                 WriteString(MSG_ONE, oth.netname); // record holder
256                         }
257                 });
258
259                 race_checkpoint_lastplayers[cp] = e;
260                 race_checkpoint_lasttimes[cp] = time;
261                 race_checkpoint_lastlaps[cp] = lself;
262
263                 msg_entity = oth;
264                 WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
265                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
266                         WriteByte(MSG_ONE, TE_CSQC_RACE);
267                         WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT);
268                         WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
269                         if(e == oth)
270                         {
271                                 WriteShort(MSG_ONE, 0);
272                                 WriteByte(MSG_ONE, 0);
273                                 WriteString(MSG_ONE, "");
274                         }
275                         else
276                         {
277                                 WriteShort(MSG_ONE, floor(10 * (time - othtime) + 0.5));
278                                 WriteByte(MSG_ONE, lother - lself);
279                                 WriteString(MSG_ONE, e.netname); // record holder
280                         }
281                 });
282         }
283 }
284
285 void race_ClearTime(entity e)
286 {
287         e.race_checkpoint = -1;
288         e.race_laptime = 0;
289         e.race_penalty_accumulator = 0;
290         e.race_lastpenalty = world;
291
292         msg_entity = e;
293         WRITESPECTATABLE_MSG_ONE({
294                 WriteByte(MSG_ONE, SVC_TEMPENTITY);
295                 WriteByte(MSG_ONE, TE_CSQC_RACE);
296                 WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_CLEAR); // next
297         });
298 }
299
300 void dumpsurface(entity e)
301 {
302         float n, si, ni;
303         vector norm, vec;
304         print("Surfaces of ", etos(e), ":\n");
305
306         print("TEST = ", ftos(getsurfacenearpoint(e, '0 0 0')), "\n");
307
308         for(si = 0; ; ++si)
309         {
310                 n = getsurfacenumpoints(e, si);
311                 if(n <= 0)
312                         break;
313                 print("  Surface ", ftos(si), ":\n");
314                 norm = getsurfacenormal(e, si);
315                 print("    Normal = ", vtos(norm), "\n");
316                 for(ni = 0; ni < n; ++ni)
317                 {
318                         vec = getsurfacepoint(e, si, ni);
319                         print("    Point ", ftos(ni), " = ", vtos(vec), " (", ftos(norm * vec), ")\n");
320                 }
321         }
322 }
323
324 void checkpoint_passed()
325 {
326         string oldmsg;
327
328         if(other.classname == "porto")
329         {
330                 // do not allow portalling through checkpoints
331                 trace_plane_normal = normalize(-1 * other.velocity);
332                 self = other;
333                 W_Porto_Fail(0);
334                 return;
335         }
336
337         /*
338          * Trigger targets
339          */
340         if not(self.spawnflags & 2)
341         {
342                 activator = other;
343                 oldmsg = self.message;
344                 self.message = "";
345                 SUB_UseTargets();
346                 self.message = oldmsg;
347         }
348
349         if(other.classname != "player")
350                 return;
351
352         /*
353          * Remove unauthorized equipment
354          */
355         Portal_ClearAll(other);
356
357         other.porto_forbidden = 2; // decreased by 1 each StartFrame
358
359         if(other.race_checkpoint == -1 || other.race_checkpoint == self.race_checkpoint)
360         {
361                 if(self.race_penalty)
362                 {
363                         if(other.race_lastpenalty != self)
364                         {
365                                 other.race_lastpenalty = self;
366                                 race_ImposePenaltyTime(other, self.race_penalty, self.race_penalty_reason);
367                         }
368                 }
369
370                 if(other.race_penalty)
371                         return;
372
373                 /*
374                  * Trigger targets
375                  */
376                 if(self.spawnflags & 2)
377                 {
378                         activator = other;
379                         oldmsg = self.message;
380                         self.message = "";
381                         SUB_UseTargets();
382                         self.message = oldmsg;
383                 }
384
385                 other.race_checkpoint = race_NextCheckpoint(self.race_checkpoint);
386
387                 race_SendTime(other, self.race_checkpoint, time - other.race_laptime, !!other.race_laptime);
388
389                 if(!self.race_checkpoint) // start line
390                 {
391                         other.race_laptime = time;
392                         other.race_penalty_accumulator = 0;
393                         other.race_lastpenalty = world;
394                 }
395
396                 if(g_race_qualifying)
397                         race_SendNextCheckpoint(other, 0);
398         }
399         else if(other.race_checkpoint == race_NextCheckpoint(self.race_checkpoint))
400         {
401                 // ignored
402         }
403         else
404         {
405                 if(self.spawnflags & 4)
406                         Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
407         }
408 }
409
410 void checkpoint_touch()
411 {
412         EXACTTRIGGER_TOUCH;
413         checkpoint_passed();
414 }
415
416 void checkpoint_use()
417 {
418         if(other.classname == "info_player_deathmatch") // a spawn, a spawn
419                 return;
420
421         other = activator;
422         checkpoint_passed();
423 }
424
425 float race_waypointsprite_visible_for_player(entity e)
426 {
427         if(e.race_checkpoint == -1)
428                 return TRUE;
429         else if(e.race_checkpoint == self.owner.race_checkpoint)
430                 return TRUE;
431         else
432                 return FALSE;
433 }
434
435 float have_verified;
436 void trigger_race_checkpoint_verify()
437 {
438         entity oldself, cp;
439         float i, p;
440         float qual;
441
442         if(have_verified)
443                 return;
444         have_verified = 1;
445         
446         qual = g_race_qualifying;
447
448         oldself = self;
449         self = spawn();
450         self.classname = "player";
451
452         for(i = 0; i <= race_highest_checkpoint; ++i)
453         {
454                 self.race_checkpoint = race_NextCheckpoint(i);
455
456                 // race only (middle of the race)
457                 g_race_qualifying = 0;
458                 self.race_place = 0;
459                 if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
460                         error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for respawning in race) - bailing out"));
461
462                 if(i == 0)
463                 {
464                         // qualifying only
465                         g_race_qualifying = 1;
466                         self.race_place = race_lowest_place_spawn;
467                         if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
468                                 error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for qualifying) - bailing out"));
469                         
470                         // race only (initial spawn)
471                         g_race_qualifying = 0;
472                         for(p = 1; p <= race_highest_place_spawn; ++p)
473                         {
474                                 self.race_place = p;
475                                 if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), world, 0, FALSE))
476                                         error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for initially spawning in race) - bailing out"));
477                         }
478                 }
479         }
480
481         g_race_qualifying = qual;
482
483         if(race_timed_checkpoint)
484                 for(cp = world; (cp = find(cp, classname, "trigger_race_checkpoint")); )
485                         if(cp.sprite)
486                         {
487                                 if(cp.race_checkpoint == 0)
488                                         WaypointSprite_UpdateSprites(cp.sprite, "race-start", "", "");
489                                 else if(cp.race_checkpoint == race_timed_checkpoint)
490                                         WaypointSprite_UpdateSprites(cp.sprite, "race-finish", "", "");
491                         }
492
493         remove(self);
494         self = oldself;
495 }
496
497 void spawnfunc_trigger_race_checkpoint()
498 {
499         vector o;
500         if(!g_race && !g_cts)
501         {
502                 remove(self);
503                 return;
504         }
505
506         EXACTTRIGGER_INIT;
507
508         self.use = checkpoint_use;
509         if not(self.spawnflags & 1)
510                 self.touch = checkpoint_touch;
511
512         o = (self.absmin + self.absmax) * 0.5;
513         tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o_z - self.absmin_z), MOVE_NORMAL, self);
514         self.nearestwaypoint = waypoint_spawn(trace_endpos, trace_endpos, WAYPOINTFLAG_GENERATED);
515         self.nearestwaypointtimeout = time + 1000000000;
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                         WriteByte(MSG_ONE, floor(0.4 + 10 * 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                         WriteByte(MSG_ONE, floor(0.4 + 10 * 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 }