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