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