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