]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/main.qc
Merge branch 'master' into Mario/turrets
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
1 #include "main.qh"
2 #include "_all.qh"
3
4 #include "casings.qh"
5 #include "csqcmodel_hooks.qh"
6 #include "damage.qh"
7 #include "effects.qh"
8 #include "gibs.qh"
9 #include "hook.qh"
10 #include "hud.qh"
11 #include "hud_config.qh"
12 #include "laser.qh"
13 #include "mapvoting.qh"
14 #include "modeleffects.qh"
15 #include "particles.qh"
16 #include "prandom.qh"
17 #include "scoreboard.qh"
18 #include "shownames.qh"
19 #include "sortlist.qh"
20 #include "tuba.qh"
21 #include "t_items.qh"
22 #include "wall.qh"
23 #include "waypointsprites.qh"
24
25 #include "../common/vehicles/all.qh"
26
27 #include "mutators/events.qh"
28
29 #include "weapons/projectile.qh"
30
31 #include "../common/buffs.qh"
32 #include "../common/deathtypes.qh"
33 #include "../common/effects.qh"
34 #include "../common/mapinfo.qh"
35 #include "../common/monsters/all.qh"
36 #include "../common/nades.qh"
37 #include "../common/net_notice.qh"
38 #include "../common/notifications.qh"
39 #include "../common/stats.qh"
40 #include "../common/teams.qh"
41
42 #include "../common/items/all.qh"
43
44 #include "../common/mutators/base.qh"
45
46 #include "../common/weapons/all.qh"
47
48 #include "../csqcmodellib/cl_model.qh"
49 #include "../csqcmodellib/interpolate.qh"
50
51 #include "../common/triggers/include.qh"
52
53 #include "../common/turrets/cl_turrets.qh"
54 #include "../common/turrets/turrets.qh"
55
56 #include "../warpzonelib/client.qh"
57
58 // --------------------------------------------------------------------------
59 // BEGIN REQUIRED CSQC FUNCTIONS
60 //include "main.qh"
61
62 entity clearentity_ent;
63 void clearentity(entity e)
64 {
65         if (!clearentity_ent)
66         {
67                 clearentity_ent = spawn();
68                 clearentity_ent.classname = "clearentity";
69         }
70         int n = e.entnum;
71         copyentity(clearentity_ent, e);
72         e.entnum = n;
73 }
74
75 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
76 void menu_show_error()
77 {
78         drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
79 }
80
81 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
82 // Useful for precaching things
83
84 void menu_sub_null()
85 {
86 }
87
88 string forcefog;
89 void WaypointSprite_Load();
90 void ConsoleCommand_macro_init();
91 void CSQC_Init(void)
92 {
93         prvm_language = cvar_string("prvm_language");
94
95 #ifdef WATERMARK
96         dprintf("^4CSQC Build information: ^1%s\n", WATERMARK);
97 #endif
98
99         int i;
100
101         binddb = db_create();
102         tempdb = db_create();
103         ClientProgsDB = db_load("client.db");
104         compressShortVector_init();
105
106         draw_endBoldFont();
107         menu_visible = false;
108         menu_show = menu_show_error;
109         menu_action = func_null;
110
111         for(i = 0; i < 255; ++i)
112                 if(getplayerkeyvalue(i, "viewentity") == "")
113                         break;
114         maxclients = i;
115
116         //registercommand("hud_configure");
117         //registercommand("hud_save");
118         //registercommand("menu_action");
119
120         ConsoleCommand_macro_init();
121
122         registercvar("hud_usecsqc", "1");
123         registercvar("scoreboard_columns", "default");
124
125         registercvar("cl_nade_type", "3");
126         registercvar("cl_pokenade_type", "zombie");
127
128         registercvar("cl_jumpspeedcap_min", "");
129         registercvar("cl_jumpspeedcap_max", "");
130
131         gametype = 0;
132
133         // hud_fields uses strunzone on the titles!
134         for(i = 0; i < MAX_HUD_FIELDS; ++i)
135                 hud_title[i] = strzone("(null)");
136
137         Cmd_HUD_SetFields(0);
138
139         postinit = false;
140
141         calledhooks = 0;
142
143         teams = Sort_Spawn();
144         players = Sort_Spawn();
145
146         GetTeam(NUM_SPECTATOR, true); // add specs first
147
148         // needs to be done so early because of the constants they create
149         static_init();
150         CALL_ACCUMULATED_FUNCTION(RegisterTurrets);
151         CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
152         CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
153         CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
154         CALL_ACCUMULATED_FUNCTION(RegisterEffects);
155
156         WaypointSprite_Load();
157
158         // precaches
159         precache_model("null");
160         precache_sound("misc/hit.wav");
161         precache_sound("misc/typehit.wav");
162
163         Projectile_Precache();
164         Hook_Precache();
165         GibSplash_Precache();
166         Casings_Precache();
167         Tuba_Precache();
168         CSQCPlayer_Precache();
169
170         if(autocvar_cl_reticle)
171         {
172                 precache_pic("gfx/reticle_normal");
173                 // weapon reticles are precached in weapon files
174         }
175
176         get_mi_min_max_texcoords(1); // try the CLEVER way first
177         minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
178         shortmapname = mi_shortname;
179
180         if(precache_pic(minimapname) == "")
181         {
182                 // but maybe we have a non-clever minimap
183                 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
184                 if(precache_pic(minimapname) == "")
185                         minimapname = ""; // FAIL
186                 else
187                         get_mi_min_max_texcoords(0); // load new texcoords
188         }
189
190         mi_center = (mi_min + mi_max) * 0.5;
191         mi_scale = mi_max - mi_min;
192         minimapname = strzone(minimapname);
193
194         WarpZone_Init();
195
196         hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
197         draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
198 }
199
200 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
201 void Shutdown(void)
202 {
203         WarpZone_Shutdown();
204
205         remove(teams);
206         remove(players);
207         db_close(binddb);
208         db_close(tempdb);
209         if(autocvar_cl_db_saveasdump)
210                 db_dump(ClientProgsDB, "client.db");
211         else
212                 db_save(ClientProgsDB, "client.db");
213         db_close(ClientProgsDB);
214
215         if(camera_active)
216                 cvar_set("chase_active",ftos(chase_active_backup));
217
218         // unset the event chasecam's chase_active
219         if(autocvar_chase_active < 0)
220                 cvar_set("chase_active", "0");
221
222         if (!isdemo())
223         {
224                 if (!(calledhooks & HOOK_START))
225                         localcmd("\n_cl_hook_gamestart nop\n");
226                 if (!(calledhooks & HOOK_END))
227                         localcmd("\ncl_hook_gameend\n");
228         }
229 }
230
231 .float has_team;
232 float SetTeam(entity o, int Team)
233 {
234         entity tm;
235         if(teamplay)
236         {
237                 switch(Team)
238                 {
239                         case -1:
240                         case NUM_TEAM_1:
241                         case NUM_TEAM_2:
242                         case NUM_TEAM_3:
243                         case NUM_TEAM_4:
244                                 break;
245                         default:
246                                 if(GetTeam(Team, false) == world)
247                                 {
248                                         dprintf("trying to switch to unsupported team %d\n", Team);
249                                         Team = NUM_SPECTATOR;
250                                 }
251                                 break;
252                 }
253         }
254         else
255         {
256                 switch(Team)
257                 {
258                         case -1:
259                         case 0:
260                                 break;
261                         default:
262                                 if(GetTeam(Team, false) == world)
263                                 {
264                                         dprintf("trying to switch to unsupported team %d\n", Team);
265                                         Team = NUM_SPECTATOR;
266                                 }
267                                 break;
268                 }
269         }
270         if(Team == -1) // leave
271         {
272                 if(o.has_team)
273                 {
274                         tm = GetTeam(o.team, false);
275                         tm.team_size -= 1;
276                         o.has_team = 0;
277                         return true;
278                 }
279         }
280         else
281         {
282                 if (!o.has_team)
283                 {
284                         o.team = Team;
285                         tm = GetTeam(Team, true);
286                         tm.team_size += 1;
287                         o.has_team = 1;
288                         return true;
289                 }
290                 else if(Team != o.team)
291                 {
292                         tm = GetTeam(o.team, false);
293                         tm.team_size -= 1;
294                         o.team = Team;
295                         tm = GetTeam(Team, true);
296                         tm.team_size += 1;
297                         return true;
298                 }
299         }
300         return false;
301 }
302
303 void Playerchecker_Think()
304 {
305     int i;
306         entity e;
307         for(i = 0; i < maxclients; ++i)
308         {
309                 e = playerslots[i];
310                 if(GetPlayerName(i) == "")
311                 {
312                         if(e.sort_prev)
313                         {
314                                 // player disconnected
315                                 SetTeam(e, -1);
316                                 RemovePlayer(e);
317                                 e.sort_prev = world;
318                                 //e.gotscores = 0;
319                         }
320                 }
321                 else
322                 {
323                         if (!e.sort_prev)
324                         {
325                                 // player connected
326                                 if (!e)
327                                         playerslots[i] = e = spawn();
328                                 e.sv_entnum = i;
329                                 e.ping = 0;
330                                 e.ping_packetloss = 0;
331                                 e.ping_movementloss = 0;
332                                 //e.gotscores = 0; // we might already have the scores...
333                                 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
334                                 RegisterPlayer(e);
335                                 HUD_UpdatePlayerPos(e);
336                         }
337                 }
338         }
339         self.nextthink = time + 0.2;
340 }
341
342 void Porto_Init();
343 void TrueAim_Init();
344 void PostInit(void)
345 {
346         entity playerchecker;
347         playerchecker = spawn();
348         playerchecker.think = Playerchecker_Think;
349         playerchecker.nextthink = time + 0.2;
350
351         Porto_Init();
352         TrueAim_Init();
353
354         postinit = true;
355 }
356
357 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
358 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
359 // All keys are in ascii.
360 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
361 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
362 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
363 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
364 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
365 {
366         float bSkipKey;
367         bSkipKey = false;
368
369         if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
370                 return true;
371
372         if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
373                 return true;
374
375         if(menu_visible && menu_action)
376                 if(menu_action(bInputType, nPrimary, nSecondary))
377                         return true;
378
379         return bSkipKey;
380 }
381
382 // END REQUIRED CSQC FUNCTIONS
383 // --------------------------------------------------------------------------
384
385 // --------------------------------------------------------------------------
386 // BEGIN OPTIONAL CSQC FUNCTIONS
387
388 void Ent_RemoveEntCS()
389 {
390         entcs_receiver[self.sv_entnum] = world;
391 }
392 void Ent_ReadEntCS()
393 {
394     int sf;
395         InterpolateOrigin_Undo();
396
397         self.classname = "entcs_receiver";
398         sf = ReadByte();
399
400         if(sf & 1)
401                 self.sv_entnum = ReadByte();
402         if(sf & 2)
403         {
404                 self.origin_x = ReadShort();
405                 self.origin_y = ReadShort();
406                 self.origin_z = ReadShort();
407                 setorigin(self, self.origin);
408         }
409         if(sf & 4)
410         {
411                 self.angles_y = ReadByte() * 360.0 / 256;
412                 self.angles_x = self.angles_z = 0;
413         }
414         if(sf & 8)
415                 self.healthvalue = ReadByte() * 10;
416         if(sf & 16)
417                 self.armorvalue = ReadByte() * 10;
418
419         entcs_receiver[self.sv_entnum] = self;
420         self.entremove = Ent_RemoveEntCS;
421         self.iflags |= IFLAG_ORIGIN;
422
423         InterpolateOrigin_Note();
424 }
425
426 void Ent_Remove();
427
428 void Ent_RemovePlayerScore()
429 {
430         if(self.owner) {
431                 SetTeam(self.owner, -1);
432                 self.owner.gotscores = 0;
433                 for(int i = 0; i < MAX_SCORE; ++i) {
434                         self.owner.(scores[i]) = 0; // clear all scores
435                 }
436         }
437 }
438
439 void Ent_ReadPlayerScore()
440 {
441         int i, n;
442         bool isNew;
443         entity o;
444
445         // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
446         // (no I've never heard of M-x replace-string, sed, or anything like that)
447         isNew = !self.owner; // workaround for DP bug
448         n = ReadByte()-1;
449
450 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
451         if(!isNew && n != self.sv_entnum)
452         {
453                 //print("A CSQC entity changed its owner!\n");
454                 printf("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(self), self.classname);
455                 isNew = true;
456                 Ent_Remove();
457                 self.enttype = ENT_CLIENT_SCORES;
458         }
459 #endif
460
461         self.sv_entnum = n;
462
463         if (!(playerslots[self.sv_entnum]))
464                 playerslots[self.sv_entnum] = spawn();
465         o = self.owner = playerslots[self.sv_entnum];
466         o.sv_entnum = self.sv_entnum;
467         o.gotscores = 1;
468
469         //if (!o.sort_prev)
470         //      RegisterPlayer(o);
471         //playerchecker will do this for us later, if it has not already done so
472
473     int sf, lf;
474 #if MAX_SCORE <= 8
475         sf = ReadByte();
476         lf = ReadByte();
477 #else
478         sf = ReadShort();
479         lf = ReadShort();
480 #endif
481     int p;
482         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
483                 if(sf & p)
484                 {
485                         if(lf & p)
486                                 o.(scores[i]) = ReadInt24_t();
487                         else
488                                 o.(scores[i]) = ReadChar();
489                 }
490
491         if(o.sort_prev)
492                 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
493
494         self.entremove = Ent_RemovePlayerScore;
495 }
496
497 void Ent_ReadTeamScore()
498 {
499         int i;
500         entity o;
501
502         self.team = ReadByte();
503         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
504
505     int sf, lf;
506 #if MAX_TEAMSCORE <= 8
507         sf = ReadByte();
508         lf = ReadByte();
509 #else
510         sf = ReadShort();
511         lf = ReadShort();
512 #endif
513         int p;
514         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
515                 if(sf & p)
516                 {
517                         if(lf & p)
518                                 o.(teamscores[i]) = ReadInt24_t();
519                         else
520                                 o.(teamscores[i]) = ReadChar();
521                 }
522
523         HUD_UpdateTeamPos(o);
524 }
525
526 void Ent_ClientData()
527 {
528         float newspectatee_status;
529
530     int f = ReadByte();
531
532         scoreboard_showscores_force = (f & 1);
533
534         if(f & 2)
535         {
536                 newspectatee_status = ReadByte();
537                 if(newspectatee_status == player_localnum + 1)
538                         newspectatee_status = -1; // observing
539         }
540         else
541                 newspectatee_status = 0;
542
543         spectatorbutton_zoom = (f & 4);
544
545         if(f & 8)
546         {
547                 angles_held_status = 1;
548                 angles_held.x = ReadAngle();
549                 angles_held.y = ReadAngle();
550                 angles_held.z = 0;
551         }
552         else
553                 angles_held_status = 0;
554
555         if(newspectatee_status != spectatee_status)
556         {
557                 // clear race stuff
558                 race_laptime = 0;
559                 race_checkpointtime = 0;
560         }
561         if (autocvar_hud_panel_healtharmor_progressbar_gfx)
562         {
563                 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
564                   || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
565                 )
566                         prev_p_health = -1;
567                 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
568                         prev_health = -1;
569         }
570         spectatee_status = newspectatee_status;
571
572         // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
573 }
574
575 void Ent_Nagger()
576 {
577     int i, j, b, f;
578
579     int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
580
581         if(!(nags & 4))
582         {
583                 if(vote_called_vote)
584                         strunzone(vote_called_vote);
585                 vote_called_vote = string_null;
586                 vote_active = 0;
587         }
588         else
589         {
590                 vote_active = 1;
591         }
592
593         if(nags & 64)
594         {
595                 vote_yescount = ReadByte();
596                 vote_nocount = ReadByte();
597                 vote_needed = ReadByte();
598                 vote_highlighted = ReadChar();
599         }
600
601         if(nags & 128)
602         {
603                 if(vote_called_vote)
604                         strunzone(vote_called_vote);
605                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
606         }
607
608         if(nags & 1)
609         {
610                 for(j = 0; j < maxclients; ++j)
611                         if(playerslots[j])
612                                 playerslots[j].ready = 1;
613                 for(i = 1; i <= maxclients; i += 8)
614                 {
615                         f = ReadByte();
616                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
617                                 if (!(f & b))
618                                         if(playerslots[j])
619                                                 playerslots[j].ready = 0;
620                 }
621         }
622
623         ready_waiting = (nags & 1);
624         ready_waiting_for_me = (nags & 2);
625         vote_waiting = (nags & 4);
626         vote_waiting_for_me = (nags & 8);
627         warmup_stage = (nags & 16);
628 }
629
630 void Ent_EliminatedPlayers()
631 {
632     int i, j, b, f;
633
634     int sf = ReadByte();
635         if(sf & 1)
636         {
637                 for(j = 0; j < maxclients; ++j)
638                         if(playerslots[j])
639                                 playerslots[j].eliminated = 1;
640                 for(i = 1; i <= maxclients; i += 8)
641                 {
642                         f = ReadByte();
643                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
644                                 if (!(f & b))
645                                         if(playerslots[j])
646                                                 playerslots[j].eliminated = 0;
647                 }
648         }
649 }
650
651 void Ent_RandomSeed()
652 {
653         float s;
654         prandom_debug();
655         s = ReadShort();
656         psrandom(s);
657 }
658
659 void Ent_ReadAccuracy(void)
660 {
661     int f, w;
662     int sf = ReadInt24_t();
663         if(sf == 0)
664         {
665                 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
666                         weapon_accuracy[w] = -1;
667                 return;
668         }
669
670         for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
671         {
672                 if(sf & f)
673                 {
674             int b = ReadByte();
675                         if(b == 0)
676                                 weapon_accuracy[w] = -1;
677                         else if(b == 255)
678                                 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
679                         else
680                                 weapon_accuracy[w] = (b - 1.0) / 100.0;
681                 }
682                 if(f == 0x800000)
683                         f = 1;
684                 else
685                         f *= 2;
686         }
687 }
688
689 void Spawn_Draw(void)
690 {
691         pointparticles(self.cnt, self.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
692 }
693
694 void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
695 {
696         float teamnum = (ReadByte() - 1);
697         vector spn_origin;
698         spn_origin.x = ReadShort();
699         spn_origin.y = ReadShort();
700         spn_origin.z = ReadShort();
701
702         if(is_new)
703         {
704                 self.origin = spn_origin;
705                 setsize(self, PL_MIN_CONST, PL_MAX_CONST);
706                 droptofloor();
707
708                 /*if(autocvar_cl_spawn_point_model) // needs a model first
709                 {
710                         self.mdl = "models/spawnpoint.md3";
711                         self.colormod = Team_ColorRGB(teamnum);
712                         precache_model(self.mdl);
713                         setmodel(self, self.mdl);
714                         self.drawmask = MASK_NORMAL;
715                         //self.movetype = MOVETYPE_NOCLIP;
716                         //self.draw = Spawn_Draw;
717                 }*/
718                 if(autocvar_cl_spawn_point_particles)
719                 {
720                         if((serverflags & SERVERFLAG_TEAMPLAY))
721                         {
722                                 switch(teamnum)
723                                 {
724                                         case NUM_TEAM_1: self.cnt = particleeffectnum("spawn_point_red"); break;
725                                         case NUM_TEAM_2: self.cnt = particleeffectnum("spawn_point_blue"); break;
726                                         case NUM_TEAM_3: self.cnt = particleeffectnum("spawn_point_yellow"); break;
727                                         case NUM_TEAM_4: self.cnt = particleeffectnum("spawn_point_pink"); break;
728                                         default: self.cnt = particleeffectnum("spawn_point_neutral"); break;
729                                 }
730                         }
731                         else { self.cnt = particleeffectnum("spawn_point_neutral"); }
732
733                         self.draw = Spawn_Draw;
734                 }
735         }
736
737         //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(self.origin), teamnum, self.cnt);
738 }
739
740 void Ent_ReadSpawnEvent(float is_new)
741 {
742         // If entnum is 0, ONLY do the local spawn actions
743         // this way the server can disable the sending of
744         // spawn origin or such to clients if wanted.
745         float entnum = ReadByte();
746
747         if(entnum)
748         {
749                 self.origin_x = ReadShort();
750                 self.origin_y = ReadShort();
751                 self.origin_z = ReadShort();
752
753                 if(is_new)
754                 {
755                         float teamnum = GetPlayerColor(entnum - 1);
756
757                         if(autocvar_cl_spawn_event_particles)
758                         {
759                                 switch(teamnum)
760                                 {
761                                         case NUM_TEAM_1: pointparticles(particleeffectnum("spawn_event_red"), self.origin, '0 0 0', 1); break;
762                                         case NUM_TEAM_2: pointparticles(particleeffectnum("spawn_event_blue"), self.origin, '0 0 0', 1); break;
763                                         case NUM_TEAM_3: pointparticles(particleeffectnum("spawn_event_yellow"), self.origin, '0 0 0', 1); break;
764                                         case NUM_TEAM_4: pointparticles(particleeffectnum("spawn_event_pink"), self.origin, '0 0 0', 1); break;
765                                         default: pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1); break;
766                                 }
767                         }
768                         if(autocvar_cl_spawn_event_sound)
769                         {
770                                 sound(self, CH_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTEN_NORM);
771                         }
772                 }
773         }
774
775         // local spawn actions
776         if(is_new && (!entnum || (entnum == player_localentnum)))
777         {
778                 zoomin_effect = 1;
779                 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
780
781                 if(autocvar_cl_unpress_zoom_on_spawn)
782                 {
783                         localcmd("-zoom\n");
784                         button_zoom = false;
785                 }
786         }
787
788         //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum);
789 }
790
791 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
792 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
793 void Ent_RadarLink();
794 void Ent_Init();
795 void Ent_ScoresInfo();
796 void CSQC_Ent_Update(float bIsNewEntity)
797 {
798         float t;
799         float savetime;
800         t = ReadByte();
801
802         if(autocvar_developer_csqcentities)
803                 printf("CSQC_Ent_Update(%d) with self=%i self.entnum=%d self.enttype=%d t=%d\n", bIsNewEntity, self, self.entnum, self.enttype, t);
804
805         // set up the "time" global for received entities to be correct for interpolation purposes
806         savetime = time;
807         if(servertime)
808         {
809                 time = servertime;
810         }
811         else
812         {
813                 serverprevtime = time;
814                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
815                 time = serverprevtime + serverdeltatime;
816         }
817
818 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
819         if(self.enttype)
820         {
821                 if(t != self.enttype || bIsNewEntity)
822                 {
823                         //print("A CSQC entity changed its type!\n");
824                         printf("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(self), self.entnum, self.enttype, t);
825                         Ent_Remove();
826                         clearentity(self);
827                         bIsNewEntity = 1;
828                 }
829         }
830         else
831         {
832                 if(!bIsNewEntity)
833                 {
834                         printf("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(self), self.entnum, t);
835                         bIsNewEntity = 1;
836                 }
837         }
838 #endif
839         self.enttype = t;
840         switch(t)
841         {
842                 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
843                 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
844                 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
845                 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
846                 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
847                 case ENT_CLIENT_LASER: Ent_Laser(); break;
848                 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
849                 case ENT_CLIENT_ELIMINATEDPLAYERS: Ent_EliminatedPlayers(); break;
850                 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
851                 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
852                 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
853                 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
854                 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
855                 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
856                 case ENT_CLIENT_INIT: Ent_Init(); break;
857                 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
858                 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
859                 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
860                 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
861                 case ENT_CLIENT_WALL: Ent_Wall(); break;
862                 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
863                 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
864                 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
865                 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
866                 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
867                 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
868                 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
869                 case ENT_CLIENT_INVENTORY: Inventory_Read(self); break;
870                 case ENT_CLIENT_ARC_BEAM: Ent_ReadArcBeam(bIsNewEntity); break;
871                 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
872                 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
873                 case ENT_CLIENT_TURRET: ent_turret(); break;
874                 case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
875                 case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;
876                 case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;
877                 case ENT_CLIENT_SPAWNPOINT: Ent_ReadSpawnPoint(bIsNewEntity); break;
878                 case ENT_CLIENT_SPAWNEVENT: Ent_ReadSpawnEvent(bIsNewEntity); break;
879                 case ENT_CLIENT_NOTIFICATION: Read_Notification(bIsNewEntity); break;
880                 case ENT_CLIENT_HEALING_ORB: ent_healer(); break;
881                 case ENT_CLIENT_VIEWLOC: ent_viewloc(); break;
882                 case ENT_CLIENT_VIEWLOC_TRIGGER: ent_viewloc_trigger(); break;
883                 case ENT_CLIENT_LADDER: ent_func_ladder(); break;
884                 case ENT_CLIENT_TRIGGER_PUSH: ent_trigger_push(); break;
885                 case ENT_CLIENT_TARGET_PUSH: ent_target_push(); break;
886                 case ENT_CLIENT_CONVEYOR: ent_conveyor(); break;
887                 case ENT_CLIENT_DOOR: ent_door(); break;
888                 case ENT_CLIENT_PLAT: ent_plat(); break;
889                 case ENT_CLIENT_SWAMP: ent_swamp(); break;
890                 case ENT_CLIENT_CORNER: ent_corner(); break;
891                 case ENT_CLIENT_KEYLOCK: ent_keylock(); break;
892                 case ENT_CLIENT_TRAIN: ent_train(); break;
893                 case ENT_CLIENT_TRIGGER_IMPULSE: ent_trigger_impulse(); break;
894                 case ENT_CLIENT_EFFECT: Read_Effect(bIsNewEntity); break;
895
896                 default:
897                         //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
898                         error(sprintf("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n", self.enttype, num_for_edict(self), self.classname));
899                         break;
900         }
901
902         time = savetime;
903 }
904 // Destructor, but does NOT deallocate the entity by calling remove(). Also
905 // used when an entity changes its type. For an entity that someone interacts
906 // with others, make sure it can no longer do so.
907 void Ent_Remove()
908 {
909         if(self.entremove)
910                 self.entremove();
911
912         if(self.skeletonindex)
913         {
914                 skel_delete(self.skeletonindex);
915                 self.skeletonindex = 0;
916         }
917
918         if(self.snd_looping > 0)
919         {
920                 sound(self, self.snd_looping, "misc/null.wav", VOL_BASE, autocvar_g_jetpack_attenuation);
921                 self.snd_looping = 0;
922         }
923
924         self.enttype = 0;
925         self.classname = "";
926         self.draw = menu_sub_null;
927         self.entremove = menu_sub_null;
928         // TODO possibly set more stuff to defaults
929 }
930 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
931 void CSQC_Ent_Remove()
932 {
933         if(autocvar_developer_csqcentities)
934                 printf("CSQC_Ent_Remove() with self=%i self.entnum=%d self.enttype=%d\n", self, self.entnum, self.enttype);
935
936         if(wasfreed(self))
937         {
938                 print("WARNING: CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
939                 return;
940         }
941         if(self.enttype)
942                 Ent_Remove();
943         remove(self);
944 }
945
946 void Gamemode_Init()
947 {
948         if (!isdemo())
949         {
950                 if(!(calledhooks & HOOK_START))
951                         localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
952                 calledhooks |= HOOK_START;
953         }
954 }
955 // 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.
956 void CSQC_Parse_StuffCmd(string strMessage)
957 {
958         if(autocvar_developer_csqcentities)
959                 printf("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
960
961         localcmd(strMessage);
962 }
963 // 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.
964 void CSQC_Parse_Print(string strMessage)
965 {
966         if(autocvar_developer_csqcentities)
967                 printf("CSQC_Parse_Print(\"%s\")\n", strMessage);
968
969         print(ColorTranslateRGB(strMessage));
970 }
971
972 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
973 void CSQC_Parse_CenterPrint(string strMessage)
974 {
975         if(autocvar_developer_csqcentities)
976                 printf("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
977
978         centerprint_hud(strMessage);
979 }
980
981 string notranslate_fogcmd1 = "\nfog ";
982 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
983 void Fog_Force()
984 {
985         // TODO somehow thwart prvm_globalset client ...
986
987         if(autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
988                 { localcmd("\nr_drawfog 0\n"); }
989         else if(forcefog != "")
990                 { localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2)); }
991 }
992
993 void Gamemode_Init();
994 void Ent_ScoresInfo()
995 {
996     int i;
997         self.classname = "ent_client_scores_info";
998         gametype = ReadInt24_t();
999         HUD_ModIcons_SetFunc();
1000         for(i = 0; i < MAX_SCORE; ++i)
1001         {
1002                 if(scores_label[i])
1003                         strunzone(scores_label[i]);
1004                 scores_label[i] = strzone(ReadString());
1005                 scores_flags[i] = ReadByte();
1006         }
1007         for(i = 0; i < MAX_TEAMSCORE; ++i)
1008         {
1009                 if(teamscores_label[i])
1010                         strunzone(teamscores_label[i]);
1011                 teamscores_label[i] = strzone(ReadString());
1012                 teamscores_flags[i] = ReadByte();
1013         }
1014         HUD_InitScores();
1015         Gamemode_Init();
1016 }
1017
1018 void Ent_Init()
1019 {
1020         self.classname = "ent_client_init";
1021
1022         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1023
1024         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1025         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1026         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1027         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1028         arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1029         arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1030         arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1031         arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1032
1033         if(forcefog)
1034                 strunzone(forcefog);
1035         forcefog = strzone(ReadString());
1036
1037         armorblockpercent = ReadByte() / 255.0;
1038
1039         g_balance_mortar_bouncefactor = ReadCoord();
1040         g_balance_mortar_bouncestop = ReadCoord();
1041         g_balance_electro_secondary_bouncefactor = ReadCoord();
1042         g_balance_electro_secondary_bouncestop = ReadCoord();
1043
1044         vortex_scope = !ReadByte();
1045         rifle_scope = !ReadByte();
1046
1047         serverflags = ReadByte();
1048
1049         minelayer_maxmines = ReadByte();
1050
1051         hagar_maxrockets = ReadByte();
1052
1053         g_trueaim_minrange = ReadCoord();
1054         g_balance_porto_secondary = 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 prevpos, del;
1163             int pos = ReadShort();
1164                         prevpos = ReadShort();
1165                         del = ReadShort();
1166
1167                         // move other rankings out of the way
1168             int 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_localnum))
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_TeamNagger()
1217 {
1218         teamnagger = 1;
1219 }
1220
1221 void Net_ReadPingPLReport()
1222 {
1223         int e, pi, pl, ml;
1224         e = ReadByte();
1225         pi = ReadShort();
1226         pl = ReadByte();
1227         ml = ReadByte();
1228         if (!(playerslots[e]))
1229                 return;
1230         playerslots[e].ping = pi;
1231         playerslots[e].ping_packetloss = pl / 255.0;
1232         playerslots[e].ping_movementloss = ml / 255.0;
1233 }
1234
1235 void Net_WeaponComplain()
1236 {
1237         complain_weapon = ReadByte();
1238
1239         if(complain_weapon_name)
1240                 strunzone(complain_weapon_name);
1241         complain_weapon_name = strzone(WEP_NAME(complain_weapon));
1242
1243         complain_weapon_type = ReadByte();
1244
1245         complain_weapon_time = time;
1246         weapontime = time; // ping the weapon panel
1247
1248         switch(complain_weapon_type)
1249         {
1250                 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1251                 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1252                 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1253         }
1254 }
1255
1256 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1257 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1258 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1259 float CSQC_Parse_TempEntity()
1260 {
1261         // Acquire TE ID
1262         int nTEID = ReadByte();
1263
1264         if (autocvar_developer_csqcentities)
1265                 printf("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
1266
1267         switch (nTEID)
1268         {
1269                 case TE_CSQC_MUTATOR:
1270                         int mutID = ReadMutator();
1271                         if (MUTATOR_CALLHOOK(CSQC_Parse_TempEntity, mutID))
1272                         return true;
1273                 case TE_CSQC_TARGET_MUSIC:
1274                         Net_TargetMusic();
1275                         return true;
1276                 case TE_CSQC_PICTURE:
1277                         Net_MapVote_Picture();
1278                         return true;
1279                 case TE_CSQC_RACE:
1280                         Net_ReadRace();
1281                         return true;
1282                 case TE_CSQC_VORTEXBEAMPARTICLE:
1283                         Net_ReadVortexBeamParticle();
1284                         return true;
1285                 case TE_CSQC_TEAMNAGGER:
1286                         Net_TeamNagger();
1287                         return true;
1288                 case TE_CSQC_ARC:
1289                         Net_ReadArc();
1290                         return true;
1291                 case TE_CSQC_PINGPLREPORT:
1292                         Net_ReadPingPLReport();
1293                         return true;
1294                 case TE_CSQC_WEAPONCOMPLAIN:
1295                         Net_WeaponComplain();
1296                         return true;
1297                 case TE_CSQC_VEHICLESETUP:
1298                         Net_VehicleSetup();
1299                         return true;
1300                 case TE_CSQC_SVNOTICE:
1301                         cl_notice_read();
1302                         return true;
1303                 case TE_CSQC_SHOCKWAVEPARTICLE:
1304                         Net_ReadShockwaveParticle();
1305                         return true;
1306                 default:
1307                         // No special logic for this temporary entity; return 0 so the engine can handle it
1308                         return false;
1309         }
1310 }
1311
1312 string getcommandkey(string text, string command)
1313 {
1314         string keys;
1315         float n, j, k, l = 0;
1316
1317         if (!autocvar_hud_showbinds)
1318                 return text;
1319
1320         keys = db_get(binddb, command);
1321         if (keys == "")
1322         {
1323                 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1324                 for(j = 0; j < n; ++j)
1325                 {
1326                         k = stof(argv(j));
1327                         if(k != -1)
1328                         {
1329                                 if ("" == keys)
1330                                         keys = keynumtostring(k);
1331                                 else
1332                                         keys = strcat(keys, ", ", keynumtostring(k));
1333
1334                                 ++l;
1335                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1336                                         break;
1337                         }
1338
1339                 }
1340                 if (keys == "")
1341                         keys = "NO_KEY";
1342                 db_put(binddb, command, keys);
1343         }
1344
1345         if (keys == "NO_KEY") {
1346                 if (autocvar_hud_showbinds > 1)
1347                         return sprintf(_("%s (not bound)"), text);
1348                 else
1349                         return text;
1350         }
1351         else if (autocvar_hud_showbinds > 1)
1352                 return sprintf("%s (%s)", text, keys);
1353         else
1354                 return keys;
1355 }