]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/Main.qc
Merge remote branch 'origin/master' into mirceakitsune/preview_images
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / Main.qc
1 // --------------------------------------------------------------------------
2 // BEGIN REQUIRED CSQC FUNCTIONS
3 //include "main.qh"
4
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
6
7 void menu_show_error()
8 {
9         drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
10 }
11
12 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
13 // Useful for precaching things
14
15 void menu_sub_null()
16 {
17 }
18
19 #ifdef USE_FTE
20 float __engine_check;
21 #endif
22
23 void precache_playermodel(string m)
24 {
25         string f;
26
27         if(substring(m, -9,5) == "_lod1")
28                 return;
29         if(substring(m, -9,5) == "_lod2")
30                 return;
31         precache_model(m);
32         f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
33         if(fexists(f))
34                 precache_model(f);
35         f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
36         if(fexists(f))
37                 precache_model(f);
38
39         /*
40         float globhandle, i, n;
41         globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
42         if (globhandle < 0)
43                 return;
44         n = search_getsize(globhandle);
45         for (i = 0; i < n; ++i)
46         {
47                 //print(search_getfilename(globhandle, i), "\n");
48                 f = search_getfilename(globhandle, i);
49                 PrecachePlayerSounds(f);
50         }
51         search_end(globhandle);
52         */
53 }
54 void precache_all_playermodels(string pattern)
55 {
56         float globhandle, i, n;
57         string f;
58
59         globhandle = search_begin(pattern, TRUE, FALSE);
60         if (globhandle < 0)
61                 return;
62         n = search_getsize(globhandle);
63         for (i = 0; i < n; ++i)
64         {
65                 //print(search_getfilename(globhandle, i), "\n");
66                 f = search_getfilename(globhandle, i);
67                 precache_playermodel(f);
68         }
69         search_end(globhandle);
70 }
71
72 string forcefog;
73 void WaypointSprite_Load();
74 void CSQC_Init(void)
75 {
76         prvm_language = cvar_string("prvm_language");
77
78 #ifdef USE_FTE
79 #pragma target ID
80         __engine_check = checkextension("DP_SV_WRITEPICTURE");
81         if(!__engine_check)
82         {
83                 print(_("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n"));
84                 localcmd("\ndisconnect\n");
85                 return;
86         }
87 #pragma target FTE
88 #endif
89
90         check_unacceptable_compiler_bugs();
91
92 #ifdef WATERMARK
93         print(sprintf(_("^4CSQC Build information: ^1%s\n"), WATERMARK()));
94 #endif
95
96         float i;
97
98 #ifdef COMPAT_XON050_ENGINE
99         // old engine lacks implementation of player_localnum
100         player_localnum = player_localentnum - 1;
101 #endif
102
103         binddb = db_create();
104         tempdb = db_create();
105         ClientProgsDB = db_load("client.db");
106         compressShortVector_init();
107
108         drawfont = FONT_USER+1;
109         menu_visible = FALSE;
110         menu_show = menu_show_error;
111         menu_action = menu_sub_null;
112
113         for(i = 0; i < 255; ++i)
114                 if(getplayerkeyvalue(i, "viewentity") == "")
115                         break;
116         maxclients = i;
117
118         registercommand("hud_configure");
119         registercommand("hud_save");
120         //registercommand("menu_action");
121
122         registercommand("+showscores");registercommand("-showscores");
123         registercommand("+showaccuracy");registercommand("-showaccuracy");
124
125 #ifndef CAMERATEST
126         if(isdemo())
127         {
128 #endif
129                 registercommand("+forward");registercommand("-forward");
130                 registercommand("+back");registercommand("-back");
131                 registercommand("+moveup");registercommand("-moveup");
132                 registercommand("+movedown");registercommand("-movedown");
133                 registercommand("+moveright");registercommand("-moveright");
134                 registercommand("+moveleft");registercommand("-moveleft");
135                 registercommand("+roll_right");registercommand("-roll_right");
136                 registercommand("+roll_left");registercommand("-roll_left");
137 #ifndef CAMERATEST
138         }
139 #endif
140         registercvar("hud_usecsqc", "1");
141         registercvar("scoreboard_columns", "default");
142
143         gametype = 0;
144
145         // hud_fields uses strunzone on the titles!
146         for(i = 0; i < MAX_HUD_FIELDS; ++i)
147                 hud_title[i] = strzone("(null)");
148
149         postinit = false;
150
151         calledhooks = 0;
152
153         teams = Sort_Spawn();
154         players = Sort_Spawn();
155
156         GetTeam(COLOR_SPECTATOR, true); // add specs first
157
158         // needs to be done so early because of the constants they create
159         RegisterWeapons();
160         RegisterGametypes();
161
162         WaypointSprite_Load();
163
164         // precaches
165         precache_model("null");
166         precache_sound("misc/hit.wav");
167         precache_sound("misc/typehit.wav");
168         if (autocvar_cl_precacheplayermodels)
169         {
170                 precache_all_playermodels("models/player/*.zym");
171                 precache_all_playermodels("models/player/*.dpm");
172                 precache_all_playermodels("models/player/*.md3");
173                 precache_all_playermodels("models/player/*.psk");
174                 precache_all_playermodels("models/player/*.iqm");
175         }
176
177         Projectile_Precache();
178         Hook_Precache();
179         GibSplash_Precache();
180         Casings_Precache();
181         DamageInfo_Precache();
182         Vehicles_Precache();
183         turrets_precache();
184   Announcer_Precache();
185         Tuba_Precache();
186         
187         if(autocvar_cl_reticle)
188         {
189                 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
190                 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
191         }
192         
193         get_mi_min_max_texcoords(1); // try the CLEVER way first
194         minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
195         shortmapname = mi_shortname;
196
197         if(precache_pic(minimapname) == "")
198         {
199                 // but maybe we have a non-clever minimap
200                 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
201                 if(precache_pic(minimapname) == "")
202                         minimapname = ""; // FAIL
203                 else
204                         get_mi_min_max_texcoords(0); // load new texcoords
205         }
206
207         mi_center = (mi_min + mi_max) * 0.5;
208         mi_scale = mi_max - mi_min;
209         minimapname = strzone(minimapname);
210
211         WarpZone_Init();
212
213         hud_configure_prev = -1;
214         tab_panel = -1;
215
216         draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
217 }
218
219 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
220 void Shutdown(void)
221 {
222 #ifdef USE_FTE
223 #pragma TARGET id
224         if(!__engine_check)
225                 return 0;
226 #pragma TARGET fte
227 #endif
228
229         WarpZone_Shutdown();
230
231         remove(teams);
232         remove(players);
233         db_close(binddb);
234         db_close(tempdb);
235         if(autocvar_cl_db_saveasdump)
236                 db_dump(ClientProgsDB, "client.db");
237         else
238                 db_save(ClientProgsDB, "client.db");
239         db_close(ClientProgsDB);
240
241         if(camera_active)
242                 cvar_set("chase_active",ftos(chase_active_backup));
243
244         // unset the event chasecam's chase_active
245         if(autocvar_chase_active < 0)
246                 cvar_set("chase_active", "0");
247
248         if not(isdemo())
249         {
250                 if not(calledhooks & HOOK_START)
251                         localcmd("\n_cl_hook_gamestart nop\n");
252                 if not(calledhooks & HOOK_END)
253                         localcmd("\ncl_hook_gameend\n");
254         }
255 }
256
257 .float has_team;
258 float SetTeam(entity o, float Team)
259 {
260         entity tm;
261         if(teamplay)
262         {
263                 switch(Team)
264                 {
265                         case -1:
266                         case COLOR_TEAM1:
267                         case COLOR_TEAM2:
268                         case COLOR_TEAM3:
269                         case COLOR_TEAM4:
270                                 break;
271                         default:
272                                 if(GetTeam(Team, false) == world)
273                                 {
274                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
275                                         Team = COLOR_SPECTATOR;
276                                 }
277                                 break;
278                 }
279         }
280         else
281         {
282                 switch(Team)
283                 {
284                         case -1:
285                         case 0:
286                                 break;
287                         default:
288                                 if(GetTeam(Team, false) == world)
289                                 {
290                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
291                                         Team = COLOR_SPECTATOR;
292                                 }
293                                 break;
294                 }
295         }
296         if(Team == -1) // leave
297         {
298                 if(o.has_team)
299                 {
300                         tm = GetTeam(o.team, false);
301                         tm.team_size -= 1;
302                         o.has_team = 0;
303                         return TRUE;
304                 }
305         }
306         else
307         {
308                 if not(o.has_team)
309                 {
310                         o.team = Team;
311                         tm = GetTeam(Team, true);
312                         tm.team_size += 1;
313                         o.has_team = 1;
314                         return TRUE;
315                 }
316                 else if(Team != o.team)
317                 {
318                         tm = GetTeam(o.team, false);
319                         tm.team_size -= 1;
320                         o.team = Team;
321                         tm = GetTeam(Team, true);
322                         tm.team_size += 1;
323                         return TRUE;
324                 }
325         }
326         return FALSE;
327 }
328
329 void Playerchecker_Think()
330 {
331         float i;
332         entity e;
333         for(i = 0; i < maxclients; ++i)
334         {
335                 e = playerslots[i];
336                 if(GetPlayerName(i) == "")
337                 {
338                         if(e.sort_prev)
339                         {
340                                 // player disconnected
341                                 SetTeam(e, -1);
342                                 RemovePlayer(e);
343                                 e.sort_prev = world;
344                                 //e.gotscores = 0;
345                         }
346                 }
347                 else
348                 {
349                         if not(e.sort_prev)
350                         {
351                                 // player connected
352                                 if not(e)
353                                         playerslots[i] = e = spawn();
354                                 e.sv_entnum = i;
355                                 e.ping = 0;
356                                 e.ping_packetloss = 0;
357                                 e.ping_movementloss = 0;
358                                 //e.gotscores = 0; // we might already have the scores...
359                                 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
360                                 RegisterPlayer(e);
361                                 HUD_UpdatePlayerPos(e);
362                         }
363                 }
364         }
365         self.nextthink = time + 0.2;
366 }
367
368 void Porto_Init();
369 void TrueAim_Init();
370 void PostInit(void)
371 {
372         localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
373
374         entity playerchecker;
375         playerchecker = spawn();
376         playerchecker.think = Playerchecker_Think;
377         playerchecker.nextthink = time + 0.2;
378
379         Porto_Init();
380         TrueAim_Init();
381
382         postinit = true;
383 }
384
385 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
386 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
387 float button_zoom;
388 void Cmd_HUD_SetFields(float);
389 void Cmd_HUD_Help(float);
390 float CSQC_ConsoleCommand(string strMessage)
391 {
392         float argc;
393         // Tokenize String
394         argc = tokenize_console(strMessage);
395
396         // Acquire Command
397         string strCmd;
398         strCmd = argv(0);
399
400         if(strCmd == "hud_configure") { // config hud
401                 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
402                 return true;
403         } else if(strCmd == "hud_save") { // save hud config
404                 if(argv(1) == "" || argv(2)) {
405                         print(_("Usage:\n"));
406                         print(_("hud_save configname   (saves to hud_skinname_configname.cfg)\n"));
407                 }
408                 else
409                         HUD_Panel_ExportCfg(argv(1));
410                 return true;
411         } else if(strCmd == "+showscores") {
412                 scoreboard_showscores = true;
413                 return true;
414         } else if(strCmd == "-showscores") {
415                 scoreboard_showscores = false;
416                 return true;
417         } else if(strCmd == "+showaccuracy") {
418                 scoreboard_showaccuracy = true;
419                 return true;
420         } else if(strCmd == "-showaccuracy") {
421                 scoreboard_showaccuracy = false;
422                 return true;
423         }
424
425         if(camera_active)
426         if(strCmd == "+forward" || strCmd == "-back") {
427                 ++camera_direction_x;
428                 return true;
429         } else if(strCmd == "-forward" || strCmd == "+back") {
430                 --camera_direction_x;
431                 return true;
432         } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
433                 --camera_direction_y;
434                 return true;
435         } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
436                 ++camera_direction_y;
437                 return true;
438         } else if(strCmd == "+moveup" || strCmd == "-movedown") {
439                 ++camera_direction_z;
440                 return true;
441         } else if(strCmd == "-moveup" || strCmd == "+movedown") {
442                 --camera_direction_z;
443                 return true;
444         } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
445                 ++camera_roll;
446                 return true;
447         } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
448                 --camera_roll;
449                 return true;
450         }
451
452         return false;
453 }
454
455 .vector view_ofs;
456 entity debug_shotorg;
457 void ShotOrg_Draw()
458 {
459         self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
460         self.angles = view_angles;
461         self.angles_x = -self.angles_x;
462         if not(self.cnt)
463                 self.drawmask = MASK_NORMAL;
464         else
465                 self.drawmask = 0;
466 }
467 void ShotOrg_Draw2D()
468 {
469         vector coord2d_topleft, coord2d_topright, coord2d;
470         string s;
471         vector fs;
472
473         s = vtos(self.view_ofs);
474         s = substring(s, 1, strlen(s) - 2);
475         if(tokenize_console(s) == 3)
476                 s = strcat(argv(0), " ", argv(1), " ", argv(2));
477
478         coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
479         coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
480
481         fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
482
483         coord2d = coord2d_topleft;
484         if(fs_x < 8)
485         {
486                 coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
487                 fs = '8 8 0';
488         }
489         coord2d_y -= fs_y;
490         coord2d_z = 0;
491         drawstring(coord2d, s, fs, '1 1 1', 1, 0);
492 }
493
494 void ShotOrg_Spawn()
495 {
496         debug_shotorg = spawn();
497         debug_shotorg.draw = ShotOrg_Draw;
498         debug_shotorg.draw2d = ShotOrg_Draw2D;
499         debug_shotorg.renderflags = RF_VIEWMODEL;
500         debug_shotorg.effects = EF_FULLBRIGHT;
501         precache_model("models/shotorg_adjuster.md3");
502         setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
503         debug_shotorg.scale = 2;
504         debug_shotorg.view_ofs = '25 8 -8';
505 }
506
507 void DrawDebugModel()
508 {
509         if(time - floor(time) > 0.5)
510         {
511                 PolyDrawModel(self);
512                 self.drawmask = 0;
513         }
514         else
515         {
516                 self.renderflags = 0;
517                 self.drawmask = MASK_NORMAL;
518         }
519 }
520
521 void GameCommand(string msg)
522 {
523         string s;
524         float argc;
525         entity e;
526         argc = tokenize_console(msg);
527
528         if(argv(0) == "help" || argc == 0)
529         {
530                 print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
531                 print(_("  scoreboard_columns_set ...\n"));
532                 print(_("  scoreboard_columns_help\n"));
533                 GameCommand_Generic("help");
534                 return;
535         }
536
537         if(GameCommand_Generic(msg))
538                 return;
539
540         string cmd;
541         cmd = argv(0);
542         if(cmd == "mv_download") {
543                 Cmd_MapVote_MapDownload(argc);
544         }
545         else if(cmd == "hud_panel_radar_maximized")
546         {
547                 if(argc == 1)
548                         hud_panel_radar_maximized = !hud_panel_radar_maximized;
549                 else
550                         hud_panel_radar_maximized = (stof(argv(1)) != 0);
551         }
552         else if(cmd == "scoreboard_columns_set") {
553                 Cmd_HUD_SetFields(argc);
554         }
555         else if(cmd == "scoreboard_columns_help") {
556                 Cmd_HUD_Help(argc);
557         }
558 #ifdef BLURTEST
559         else if(cmd == "blurtest") {
560                 blurtest_time0 = time;
561                 blurtest_time1 = time + stof(argv(1));
562                 blurtest_radius = stof(argv(2));
563                 blurtest_power = stof(argv(3));
564         }
565 #endif
566         else if(cmd == "shotorg_move") {
567                 if(!debug_shotorg)
568                         ShotOrg_Spawn();
569                 else
570                         debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
571                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
572         }
573         else if(cmd == "shotorg_movez") {
574                 if(!debug_shotorg)
575                         ShotOrg_Spawn();
576                 else
577                         debug_shotorg.view_ofs = debug_shotorg.view_ofs + stof(argv(1)) * (debug_shotorg.view_ofs * (1 / debug_shotorg.view_ofs_x)); // closer/farther, same xy pos
578                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
579         }
580         else if(cmd == "shotorg_set") {
581                 if(!debug_shotorg)
582                         ShotOrg_Spawn();
583                 else
584                         debug_shotorg.view_ofs = stov(argv(1));
585                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
586         }
587         else if(cmd == "shotorg_setz") {
588                 if(!debug_shotorg)
589                         ShotOrg_Spawn();
590                 else
591                         debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
592                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
593         }
594         else if(cmd == "shotorg_toggle_hide") {
595                 if(debug_shotorg)
596                 {
597                         debug_shotorg.cnt = !debug_shotorg.cnt;
598                 }
599         }
600         else if(cmd == "shotorg_end") {
601                 if(debug_shotorg)
602                 {
603                         print(vtos(debug_shotorg.view_ofs), "\n");
604                         remove(debug_shotorg);
605                         debug_shotorg = world;
606                 }
607                 localcmd("sv_cmd debug_shotorg\n");
608         }
609         else if(cmd == "sendcvar") {
610                 // W_FixWeaponOrder will trash argv, so save what we need.
611                 string thiscvar;
612                 thiscvar = strzone(argv(1));
613                 s = cvar_string(thiscvar);
614                 if(thiscvar == "cl_weaponpriority")
615                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
616                 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
617                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
618                 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
619                 strunzone(thiscvar);
620         }
621         else if(cmd == "spawn") {
622                 s = argv(1);
623                 e = spawn();
624                 precache_model(s);
625                 setmodel(e, s);
626                 setorigin(e, view_origin);
627                 e.angles = view_angles;
628                 e.draw = DrawDebugModel;
629                 e.classname = "debugmodel";
630         }
631     else if(cmd == "vyes")
632     {
633         if(uid2name_dialog)
634         {
635             vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
636             vote_prev = 0;
637             localcmd("setreport cl_allow_uid2name 1\n");
638             vote_change = -9999;
639                         uid2name_dialog = 0;
640         }
641         else
642         {
643             localcmd("cmd vote yes\n");
644         }
645     }
646     else if(cmd == "vno")
647     {
648         if(uid2name_dialog)
649         {
650             vote_active = 0;
651             vote_prev = 0;
652             localcmd("setreport cl_allow_uid2name 0\n");
653             vote_change = -9999;
654                         uid2name_dialog = 0;
655         }
656         else
657         {
658             localcmd("cmd vote no\n");
659         }
660     }
661
662         else
663         {
664                 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
665         }
666
667         return;
668 }
669
670 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
671 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
672 // All keys are in ascii.
673 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
674 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
675 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
676 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
677 {
678         float bSkipKey;
679         bSkipKey = false;
680
681         if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
682                 return true;
683
684         if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
685                 return true;
686
687         if(menu_visible)
688                 if(menu_action(bInputType, nPrimary, nSecondary))
689                         return TRUE;
690
691         return bSkipKey;
692 }
693
694 // END REQUIRED CSQC FUNCTIONS
695 // --------------------------------------------------------------------------
696
697 // --------------------------------------------------------------------------
698 // BEGIN OPTIONAL CSQC FUNCTIONS
699 void Ent_RemoveEntCS()
700 {
701         entcs_receiver[self.sv_entnum] = world;
702 }
703 void Ent_ReadEntCS()
704 {
705         float sf;
706         InterpolateOrigin_Undo();
707
708         self.classname = "entcs_receiver";
709         sf = ReadByte();
710
711         if(sf & 1)
712                 self.sv_entnum = ReadByte();
713         if(sf & 2)
714         {
715                 self.origin_x = ReadShort();
716                 self.origin_y = ReadShort();
717                 self.origin_z = ReadShort();
718         }
719         if(sf & 4)
720         {
721                 self.angles_y = ReadByte() * 360.0 / 256;
722                 self.angles_x = self.angles_z = 0;
723         }
724         if(sf & 8)
725                 self.healthvalue = ReadByte() * 10;
726         if(sf & 16)
727                 self.armorvalue = ReadByte() * 10;
728
729         entcs_receiver[self.sv_entnum] = self;
730         self.entremove = Ent_RemoveEntCS;
731
732         InterpolateOrigin_Note();
733 }
734
735 void Ent_Remove();
736
737 void Ent_RemovePlayerScore()
738 {
739         float i;
740
741         if(self.owner)
742         {
743                 SetTeam(self.owner, -1);
744                 self.owner.gotscores = 0;
745                 for(i = 0; i < MAX_SCORE; ++i)
746                         self.owner.(scores[i]) = 0; // clear all scores
747         }
748 }
749
750 void Ent_ReadPlayerScore()
751 {
752         float i, n;
753         float isNew;
754         entity o;
755
756         // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
757         // (no I've never heard of M-x replace-string, sed, or anything like that)
758         isNew = !self.owner; // workaround for DP bug
759         n = ReadByte()-1;
760
761 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
762         if(!isNew && n != self.sv_entnum)
763         {
764                 //print(_("A CSQC entity changed its owner!\n"));
765                 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
766                 isNew = true;
767                 Ent_Remove();
768                 self.enttype = ENT_CLIENT_SCORES;
769         }
770 #endif
771
772         self.sv_entnum = n;
773
774         if not(playerslots[self.sv_entnum])
775                 playerslots[self.sv_entnum] = spawn();
776         o = self.owner = playerslots[self.sv_entnum];
777         o.sv_entnum = self.sv_entnum;
778         o.gotscores = 1;
779
780         //if not(o.sort_prev)
781         //      RegisterPlayer(o);
782         //playerchecker will do this for us later, if it has not already done so
783
784         float sf, lf;
785 #if MAX_SCORE <= 8
786         sf = ReadByte();
787         lf = ReadByte();
788 #else
789         sf = ReadShort();
790         lf = ReadShort();
791 #endif
792         float p;
793         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
794                 if(sf & p)
795                 {
796                         if(lf & p)
797                                 o.(scores[i]) = ReadInt24_t();
798                         else
799                                 o.(scores[i]) = ReadChar();
800                 }
801
802         if(o.sort_prev)
803                 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
804
805         self.entremove = Ent_RemovePlayerScore;
806 }
807
808 void Ent_ReadTeamScore()
809 {
810         float i;
811         entity o;
812
813         self.team = ReadByte();
814         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
815
816         float sf, lf;
817 #if MAX_TEAMSCORE <= 8
818         sf = ReadByte();
819         lf = ReadByte();
820 #else
821         sf = ReadShort();
822         lf = ReadShort();
823 #endif
824         float p;
825         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
826                 if(sf & p)
827                 {
828                         if(lf & p)
829                                 o.(teamscores[i]) = ReadInt24_t();
830                         else
831                                 o.(teamscores[i]) = ReadChar();
832                 }
833
834         HUD_UpdateTeamPos(o);
835 }
836
837 void Ent_ClientData()
838 {
839         float f;
840         float newspectatee_status;
841
842         f = ReadByte();
843
844         scoreboard_showscores_force = (f & 1);
845
846         if(f & 2)
847         {
848                 newspectatee_status = ReadByte();
849                 if(newspectatee_status == player_localnum + 1)
850                         newspectatee_status = -1; // observing
851         }
852         else
853                 newspectatee_status = 0;
854
855         spectatorbutton_zoom = (f & 4);
856
857         if(f & 8)
858         {
859                 angles_held_status = 1;
860                 angles_held_x = ReadAngle();
861                 angles_held_y = ReadAngle();
862                 angles_held_z = 0;
863         }
864         else
865                 angles_held_status = 0;
866
867         if(newspectatee_status != spectatee_status)
868         {
869                 // clear race stuff
870                 race_laptime = 0;
871                 race_checkpointtime = 0;
872         }
873         if (autocvar_hud_panel_healtharmor_progressbar_gfx)
874         {
875                 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
876                   || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
877                 )
878                         prev_p_health = -1;
879                 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
880                         prev_health = -1;
881         }
882         spectatee_status = newspectatee_status;
883
884         // non-COMPAT_XON050_ENGINE: we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
885 }
886
887 void Ent_Nagger()
888 {
889         float nags, i, j, b, f;
890
891         nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
892
893         if(!(nags & 4))
894         {
895                 if(vote_called_vote)
896                         strunzone(vote_called_vote);
897                 vote_called_vote = string_null;
898                 vote_active = 0;
899         }
900         else
901         {
902                 vote_active = 1;
903         }
904
905         if(nags & 64)
906         {
907                 vote_yescount = ReadByte();
908                 vote_nocount = ReadByte();
909                 vote_needed = ReadByte();
910                 vote_highlighted = ReadChar();
911         }
912
913         if(nags & 128)
914         {
915                 if(vote_called_vote)
916                         strunzone(vote_called_vote);
917                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
918         }
919
920         if(nags & 1)
921         {
922                 for(j = 0; j < maxclients; ++j)
923                         if(playerslots[j])
924                                 playerslots[j].ready = 1;
925                 for(i = 1; i <= maxclients; i += 8)
926                 {
927                         f = ReadByte();
928                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
929                                 if not(f & b)
930                                         if(playerslots[j])
931                                                 playerslots[j].ready = 0;
932                 }
933         }
934
935         ready_waiting = (nags & 1);
936         ready_waiting_for_me = (nags & 2);
937         vote_waiting = (nags & 4);
938         vote_waiting_for_me = (nags & 8);
939         warmup_stage = (nags & 16);
940 }
941
942 void Ent_RandomSeed()
943 {
944         float s;
945         prandom_debug();
946         s = ReadShort();
947         psrandom(s);
948 }
949
950 void Ent_ReadAccuracy(void)
951 {
952         float sf, f, w, b;
953         sf = ReadInt24_t();
954         if(sf == 0)
955         {
956                 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
957                         weapon_accuracy[w] = -1;
958                 return;
959         }
960
961         for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
962         {
963                 if(sf & f)
964                 {
965                         b = ReadByte();
966                         if(b == 0)
967                                 weapon_accuracy[w] = -1;
968                         else if(b == 255)
969                                 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
970                         else
971                                 weapon_accuracy[w] = (b - 1.0) / 100.0;
972                 }
973         }
974 }
975
976 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
977 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
978 void Ent_RadarLink();
979 void Ent_Init();
980 void Ent_ScoresInfo();
981 void CSQC_Ent_Update(float bIsNewEntity)
982 {
983         float t;
984         float savetime;
985         t = ReadByte();
986
987         // set up the "time" global for received entities to be correct for interpolation purposes
988         savetime = time;
989         if(servertime)
990         {
991                 time = servertime;
992         }
993         else
994         {
995                 serverprevtime = time;
996                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
997                 time = serverprevtime + serverdeltatime;
998         }
999
1000 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
1001         if(self.enttype)
1002         {
1003                 if(t != self.enttype || bIsNewEntity)
1004                 {
1005                         //print(_("A CSQC entity changed its type!\n"));
1006                         print(sprintf(_("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n"), num_for_edict(self), self.entnum, self.enttype, t));
1007                         Ent_Remove();
1008                         bIsNewEntity = 1;
1009                 }
1010         }
1011         else
1012         {
1013                 if(!bIsNewEntity)
1014                 {
1015                         print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
1016                         bIsNewEntity = 1;
1017                 }
1018         }
1019 #endif
1020         self.enttype = t;
1021         switch(t)
1022         {
1023                 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
1024                 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
1025                 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
1026                 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
1027                 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
1028                 case ENT_CLIENT_LASER: Ent_Laser(); break;
1029                 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
1030                 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
1031                 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
1032                 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
1033                 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
1034                 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
1035                 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
1036                 case ENT_CLIENT_INIT: Ent_Init(); break;
1037                 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
1038                 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
1039                 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
1040                 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
1041                 case ENT_CLIENT_WALL: Ent_Wall(); break;
1042                 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
1043                 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
1044                 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
1045                 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
1046                 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
1047                 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
1048                 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
1049                 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
1050                 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
1051                 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
1052                 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
1053                 case ENT_CLIENT_TURRET: ent_turret(); break; 
1054                 case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break; 
1055                 default:
1056                         //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1057                         error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1058                         break;
1059         }
1060
1061         time = savetime;
1062 }
1063 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1064 // used when an entity changes its type. For an entity that someone interacts
1065 // with others, make sure it can no longer do so.
1066 void Ent_Remove()
1067 {
1068         if(self.entremove)
1069                 self.entremove();
1070
1071         self.enttype = 0;
1072         self.classname = "";
1073         self.draw = menu_sub_null;
1074         self.entremove = menu_sub_null;
1075         // TODO possibly set more stuff to defaults
1076 }
1077 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
1078 void CSQC_Ent_Remove()
1079 {
1080         if(self.enttype)
1081                 Ent_Remove();
1082         remove(self);
1083 }
1084
1085 void Gamemode_Init()
1086 {
1087         if not(isdemo())
1088         {
1089                 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
1090                 calledhooks |= HOOK_START;
1091         }
1092 }
1093 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided.  To execute standard behavior, simply execute localcmd with the string.
1094 void CSQC_Parse_StuffCmd(string strMessage)
1095 {
1096         localcmd(strMessage);
1097 }
1098 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided.  To execute standard behavior, simply execute print with the string.
1099 void CSQC_Parse_Print(string strMessage)
1100 {
1101         print(ColorTranslateRGB(strMessage));
1102 }
1103
1104 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1105 void CSQC_Parse_CenterPrint(string strMessage)
1106 {
1107         centerprint_hud(strMessage);
1108 }
1109
1110 string notranslate_fogcmd1 = "\nfog ";
1111 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1112 void Fog_Force()
1113 {
1114         // TODO somehow thwart prvm_globalset client ...
1115
1116         if(forcefog != "")
1117                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1118 }
1119
1120 void Gamemode_Init();
1121 void Ent_ScoresInfo()
1122 {
1123         float i;
1124         self.classname = "ent_client_scores_info";
1125         gametype = ReadInt24_t();
1126         for(i = 0; i < MAX_SCORE; ++i)
1127         {
1128                 scores_label[i] = strzone(ReadString());
1129                 scores_flags[i] = ReadByte();
1130         }
1131         for(i = 0; i < MAX_TEAMSCORE; ++i)
1132         {
1133                 teamscores_label[i] = strzone(ReadString());
1134                 teamscores_flags[i] = ReadByte();
1135         }
1136         HUD_InitScores();
1137         Gamemode_Init();
1138 }
1139
1140 void Ent_Init()
1141 {
1142         self.classname = "ent_client_init";
1143
1144         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1145
1146         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1147         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1148         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1149         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1150         electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1151         electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1152         electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1153         electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1154         gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1155         gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1156         gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1157         gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1158
1159         if(forcefog)
1160                 strunzone(forcefog);
1161         forcefog = strzone(ReadString());
1162
1163         armorblockpercent = ReadByte() / 255.0;
1164
1165         g_weaponswitchdelay = ReadByte() / 255.0;
1166
1167         g_balance_grenadelauncher_bouncefactor = ReadCoord();
1168         g_balance_grenadelauncher_bouncestop = ReadCoord();
1169         g_balance_electro_secondary_bouncefactor = ReadCoord();
1170         g_balance_electro_secondary_bouncestop = ReadCoord();
1171
1172         nex_scope = !ReadByte();
1173         rifle_scope = !ReadByte();
1174
1175         serverflags = ReadByte();
1176
1177         minelayer_maxmines = ReadByte();
1178
1179         hagar_maxrockets = ReadByte();
1180
1181         g_trueaim_minrange = ReadCoord();
1182
1183         if(!postinit)
1184                 PostInit();
1185 }
1186
1187 void Net_ReadRace()
1188 {
1189         float b;
1190
1191         b = ReadByte();
1192
1193         switch(b)
1194         {
1195                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1196                         race_checkpoint = ReadByte();
1197                         race_time = ReadInt24_t();
1198                         race_previousbesttime = ReadInt24_t();
1199                         if(race_previousbestname)
1200                                 strunzone(race_previousbestname);
1201                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1202
1203                         race_checkpointtime = time;
1204
1205                         if(race_checkpoint == 0 || race_checkpoint == 254)
1206                         {
1207                                 race_penaltyaccumulator = 0;
1208                                 race_laptime = time; // valid
1209                         }
1210
1211                         break;
1212
1213                 case RACE_NET_CHECKPOINT_CLEAR:
1214                         race_laptime = 0;
1215                         race_checkpointtime = 0;
1216                         break;
1217
1218                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1219                         race_laptime = ReadCoord();
1220                         race_checkpointtime = -99999;
1221                         // fall through
1222                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1223                         race_nextcheckpoint = ReadByte();
1224
1225                         race_nextbesttime = ReadInt24_t();
1226                         if(race_nextbestname)
1227                                 strunzone(race_nextbestname);
1228                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1229                         break;
1230
1231                 case RACE_NET_CHECKPOINT_HIT_RACE:
1232                         race_mycheckpoint = ReadByte();
1233                         race_mycheckpointtime = time;
1234                         race_mycheckpointdelta = ReadInt24_t();
1235                         race_mycheckpointlapsdelta = ReadByte();
1236                         if(race_mycheckpointlapsdelta >= 128)
1237                                 race_mycheckpointlapsdelta -= 256;
1238                         if(race_mycheckpointenemy)
1239                                 strunzone(race_mycheckpointenemy);
1240                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1241                         break;
1242
1243                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1244                         race_othercheckpoint = ReadByte();
1245                         race_othercheckpointtime = time;
1246                         race_othercheckpointdelta = ReadInt24_t();
1247                         race_othercheckpointlapsdelta = ReadByte();
1248                         if(race_othercheckpointlapsdelta >= 128)
1249                                 race_othercheckpointlapsdelta -= 256;
1250                         if(race_othercheckpointenemy)
1251                                 strunzone(race_othercheckpointenemy);
1252                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1253                         break;
1254
1255                 case RACE_NET_PENALTY_RACE:
1256                         race_penaltyeventtime = time;
1257                         race_penaltytime = ReadShort();
1258                         //race_penaltyaccumulator += race_penaltytime;
1259                         if(race_penaltyreason)
1260                                 strunzone(race_penaltyreason);
1261                         race_penaltyreason = strzone(ReadString());
1262                         break;
1263
1264                 case RACE_NET_PENALTY_QUALIFYING:
1265                         race_penaltyeventtime = time;
1266                         race_penaltytime = ReadShort();
1267                         race_penaltyaccumulator += race_penaltytime;
1268                         if(race_penaltyreason)
1269                                 strunzone(race_penaltyreason);
1270                         race_penaltyreason = strzone(ReadString());
1271                         break;
1272
1273                 case RACE_NET_SERVER_RECORD:
1274                         race_server_record = ReadInt24_t();
1275                         break;
1276                 case RACE_NET_SPEED_AWARD:
1277                         race_speedaward = ReadInt24_t();
1278                         if(race_speedaward_holder)
1279                                 strunzone(race_speedaward_holder);
1280                         race_speedaward_holder = strzone(ReadString());
1281                         break;
1282                 case RACE_NET_SPEED_AWARD_BEST:
1283                         race_speedaward_alltimebest = ReadInt24_t();
1284                         if(race_speedaward_alltimebest_holder)
1285                                 strunzone(race_speedaward_alltimebest_holder);
1286                         race_speedaward_alltimebest_holder = strzone(ReadString());
1287                         break;
1288                 case RACE_NET_SERVER_RANKINGS:
1289                         float pos, prevpos, del;
1290                         pos = ReadShort();
1291                         prevpos = ReadShort();
1292                         del = ReadShort();
1293
1294                         // move other rankings out of the way
1295                         float i;
1296                         if (prevpos) {
1297                                 for (i=prevpos-1;i>pos-1;--i) {
1298                                         grecordtime[i] = grecordtime[i-1];
1299                                         if(grecordholder[i])
1300                                                 strunzone(grecordholder[i]);
1301                                         grecordholder[i] = strzone(grecordholder[i-1]);
1302                                 }
1303                         } else if (del) { // a record has been deleted by the admin
1304                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1305                                         if (i == RANKINGS_CNT-1) { // clear out last record
1306                                                 grecordtime[i] = 0;
1307                                                 if (grecordholder[i])
1308                                                         strunzone(grecordholder[i]);
1309                                                 grecordholder[i] = string_null;
1310                                         }
1311                                         else {
1312                                                 grecordtime[i] = grecordtime[i+1];
1313                                                 if (grecordholder[i])
1314                                                         strunzone(grecordholder[i]);
1315                                                 grecordholder[i] = strzone(grecordholder[i+1]);
1316                                         }
1317                                 }
1318                         } else { // player has no ranked record yet
1319                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1320                                         grecordtime[i] = grecordtime[i-1];
1321                                         if(grecordholder[i])
1322                                                 strunzone(grecordholder[i]);
1323                                         grecordholder[i] = strzone(grecordholder[i-1]);
1324                                 }
1325                         }
1326
1327                         // store new ranking
1328                         if(grecordholder[pos-1] != "")
1329                                 strunzone(grecordholder[pos-1]);
1330                         grecordholder[pos-1] = strzone(ReadString());
1331                         grecordtime[pos-1] = ReadInt24_t();
1332                         if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1333                                 race_myrank = pos;
1334                         break;
1335                 case RACE_NET_SERVER_STATUS:
1336                         race_status = ReadShort();
1337                         if(race_status_name)
1338                                 strunzone(race_status_name);
1339                         race_status_name = strzone(ReadString());
1340         }
1341 }
1342
1343 void Net_ReadSpawn()
1344 {
1345         zoomin_effect = 1;
1346         current_viewzoom = 0.6;
1347 }
1348
1349 void Net_TeamNagger()
1350 {
1351         teamnagger = 1;
1352 }
1353
1354 void Net_ReadPingPLReport()
1355 {
1356         float e, pi, pl, ml;
1357         e = ReadByte();
1358         pi = ReadShort();
1359         pl = ReadByte();
1360         ml = ReadByte();
1361         if not(playerslots[e])
1362                 return;
1363         playerslots[e].ping = pi;
1364         playerslots[e].ping_packetloss = pl / 255.0;
1365         playerslots[e].ping_movementloss = ml / 255.0;
1366 }
1367
1368 void Net_WeaponComplain() {
1369         complain_weapon = ReadByte();
1370
1371         if(complain_weapon_name)
1372                 strunzone(complain_weapon_name);
1373         complain_weapon_name = strzone(ReadString());
1374
1375         complain_weapon_type = ReadByte();
1376
1377         complain_weapon_time = time;
1378         weapontime = time; // ping the weapon panel
1379 }
1380
1381 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1382 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1383 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1384 float CSQC_Parse_TempEntity()
1385 {
1386         float bHandled;
1387                 bHandled  = true;
1388         // Acquire TE ID
1389         float nTEID;
1390                 nTEID = ReadByte();
1391
1392                 // NOTE: Could just do return instead of break...
1393         switch(nTEID)
1394         {
1395                 case TE_CSQC_TARGET_MUSIC:
1396                         Net_TargetMusic();
1397                         bHandled = true;
1398                         break;
1399                 case TE_CSQC_PICTURE:
1400                         Net_MapVote_Picture();
1401                         bHandled = true;
1402                         break;
1403                 case TE_CSQC_RACE:
1404                         Net_ReadRace();
1405                         bHandled = true;
1406                         break;
1407                 case TE_CSQC_SPAWN:
1408                         Net_ReadSpawn();
1409                         bHandled = true;
1410                         break;
1411                 case TE_CSQC_ZCURVEPARTICLES:
1412                         Net_ReadZCurveParticles();
1413                         bHandled = true;
1414                         break;
1415                 case TE_CSQC_NEXGUNBEAMPARTICLE:
1416                         Net_ReadNexgunBeamParticle();
1417                         bHandled = true;
1418                         break;
1419                 case TE_CSQC_TEAMNAGGER:
1420                         Net_TeamNagger();
1421                         bHandled = true;
1422                         break;
1423                 case TE_CSQC_LIGHTNINGARC:
1424                         Net_ReadLightningarc();
1425                         bHandled = true;
1426                         break;
1427                 case TE_CSQC_PINGPLREPORT:
1428                         Net_ReadPingPLReport();
1429                         bHandled = true;
1430                         break;
1431                 case TE_CSQC_ANNOUNCE:
1432                         Announcer_Play(ReadString());
1433                         bHandled = true;
1434                         break;
1435                 case TE_CSQC_KILLNOTIFY:
1436                         HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1437                         bHandled = true;
1438                         break;
1439                 case TE_CSQC_KILLCENTERPRINT:
1440                         HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1441                         bHandled = true;
1442                         break;
1443                 case TE_CSQC_CENTERPRINT_GENERIC:
1444                         float id;
1445                         string s;
1446                         id = ReadByte();
1447                         s = ReadString();
1448                         if (id != 0 && s != "")
1449                                 centerprint_generic(id, s, ReadByte(), ReadByte());
1450                         else
1451                                 centerprint_generic(id, s, 0, 0);
1452                         bHandled = true;
1453                         break;
1454                 case TE_CSQC_WEAPONCOMPLAIN:
1455                         Net_WeaponComplain();
1456                         bHandled = true;
1457                         break;
1458                 case TE_CSQC_VEHICLESETUP:
1459                         Net_VehicleSetup();
1460                         bHandled = true;
1461                         break;
1462                 default:
1463                         // No special logic for this temporary entity; return 0 so the engine can handle it
1464                         bHandled = false;
1465                         break;
1466         }
1467
1468         return bHandled;
1469 }
1470
1471 string getcommandkey(string text, string command)
1472 {
1473         string keys;
1474         float n, j, k, l;
1475
1476         if (!autocvar_hud_showbinds)
1477                 return text;
1478
1479         keys = db_get(binddb, command);
1480         if (!keys)
1481         {
1482                 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1483                 for(j = 0; j < n; ++j)
1484                 {
1485                         k = stof(argv(j));
1486                         if(k != -1)
1487                         {
1488                                 if ("" == keys)
1489                                         keys = keynumtostring(k);
1490                                 else
1491                                         keys = strcat(keys, ", ", keynumtostring(k));
1492
1493                                 ++l;
1494                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1495                         }
1496
1497                 }
1498                 db_put(binddb, command, keys);
1499         }
1500
1501         if ("" == keys) {
1502                 if (autocvar_hud_showbinds > 1)
1503                         return sprintf(_("%s (not bound)"), text);
1504                 else
1505                         return text;
1506         }
1507         else if (autocvar_hud_showbinds > 1)
1508                 return sprintf(_("%s (%s)"), text, keys);
1509         else
1510                 return keys;
1511 }