Make saturation depend on the amount of armor the player has (post process effect)
[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_ReadEntCS()\r
661 {\r
662         InterpolateOrigin_Undo();\r
663 \r
664         self.classname = "entcs_receiver";\r
665         self.sv_entnum = ReadByte() - 1;\r
666         self.origin_x = ReadShort();\r
667         self.origin_y = ReadShort();\r
668         self.origin_z = ReadShort();\r
669         self.angles_y = ReadByte() * 360.0 / 256;\r
670         self.origin_z = self.angles_x = self.angles_z = 0;\r
671 \r
672         InterpolateOrigin_Note();\r
673 }\r
674 \r
675 void Ent_Remove();\r
676 \r
677 void Ent_RemovePlayerScore()\r
678 {\r
679         float i;\r
680 \r
681         if(self.owner)\r
682         {\r
683                 SetTeam(self.owner, -1);\r
684                 self.owner.gotscores = 0;\r
685                 for(i = 0; i < MAX_SCORE; ++i)\r
686                         self.owner.(scores[i]) = 0; // clear all scores\r
687         }\r
688 }\r
689 \r
690 void Ent_ReadPlayerScore()\r
691 {\r
692         float i, n;\r
693         float isNew;\r
694         entity o;\r
695 \r
696         // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN\r
697         // (no I've never heard of M-x replace-string, sed, or anything like that)\r
698         isNew = !self.owner; // workaround for DP bug\r
699         n = ReadByte()-1;\r
700 \r
701 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED\r
702         if(!isNew && n != self.sv_entnum)\r
703         {\r
704                 print("A CSQC entity changed its owner!\n");\r
705                 isNew = true;\r
706                 Ent_Remove();\r
707                 self.enttype = ENT_CLIENT_SCORES;\r
708         }\r
709 #endif\r
710 \r
711         self.sv_entnum = n;\r
712 \r
713         if not(playerslots[self.sv_entnum])\r
714                 playerslots[self.sv_entnum] = spawn();\r
715         o = self.owner = playerslots[self.sv_entnum];\r
716         o.sv_entnum = self.sv_entnum;\r
717         o.gotscores = 1;\r
718 \r
719         //if not(o.sort_prev)\r
720         //      RegisterPlayer(o);\r
721         //playerchecker will do this for us later, if it has not already done so\r
722 \r
723         float sf, lf;\r
724 #if MAX_SCORE <= 8\r
725         sf = ReadByte();\r
726         lf = ReadByte();\r
727 #else\r
728         sf = ReadShort();\r
729         lf = ReadShort();\r
730 #endif\r
731         float p;\r
732         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)\r
733                 if(sf & p)\r
734                 {\r
735                         if(lf & p)\r
736                                 o.(scores[i]) = ReadInt24_t();\r
737                         else\r
738                                 o.(scores[i]) = ReadChar();\r
739                 }\r
740 \r
741         if(o.sort_prev)\r
742                 Sbar_UpdatePlayerPos(o); // if not registered, we cannot do this yet!\r
743 \r
744         self.entremove = Ent_RemovePlayerScore;\r
745 }\r
746 \r
747 void Ent_ReadTeamScore()\r
748 {\r
749         float i;\r
750         entity o;\r
751 \r
752         self.team = ReadByte();\r
753         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted\r
754 \r
755         float sf, lf;\r
756 #if MAX_TEAMSCORE <= 8\r
757         sf = ReadByte();\r
758         lf = ReadByte();\r
759 #else\r
760         sf = ReadShort();\r
761         lf = ReadShort();\r
762 #endif\r
763         float p;\r
764         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)\r
765                 if(sf & p)\r
766                 {\r
767                         if(lf & p)\r
768                                 o.(teamscores[i]) = ReadInt24_t();\r
769                         else\r
770                                 o.(teamscores[i]) = ReadChar();\r
771                 }\r
772 \r
773         Sbar_UpdateTeamPos(o);\r
774 }\r
775 \r
776 void Net_Reset()\r
777 {\r
778 }\r
779 \r
780 void Ent_ClientData()\r
781 {\r
782         float f;\r
783         float newspectatee_status;\r
784 \r
785         f = ReadByte();\r
786 \r
787         sb_showscores_force = (f & 1);\r
788 \r
789         if(f & 2)\r
790         {\r
791                 newspectatee_status = ReadByte();\r
792                 if(newspectatee_status == player_localentnum)\r
793                         newspectatee_status = -1; // observing\r
794         }\r
795         else\r
796                 newspectatee_status = 0;\r
797 \r
798         spectatorbutton_zoom = (f & 4);\r
799 \r
800         if(f & 8)\r
801         {\r
802                 angles_held_status = 1;\r
803                 angles_held_x = ReadAngle();\r
804                 angles_held_y = ReadAngle();\r
805                 angles_held_z = 0;\r
806         }\r
807         else\r
808                 angles_held_status = 0;\r
809 \r
810         if(newspectatee_status != spectatee_status)\r
811         {\r
812                 float i;\r
813                 // clear the weapon accuracy stats\r
814                 for(i = WEP_FIRST; i <= WEP_LAST; ++i) {\r
815                         weapon_hits[i] = 0;\r
816                         weapon_fired[i] = 0;\r
817                 }\r
818 \r
819                 // clear race stuff\r
820                 race_laptime = 0;\r
821                 race_checkpointtime = 0;\r
822         }\r
823         spectatee_status = newspectatee_status;\r
824 }\r
825 \r
826 void Ent_Nagger()\r
827 {\r
828         float nags, i, j, b, f;\r
829 \r
830         nags = ReadByte();\r
831 \r
832         if(nags & 128)\r
833         {\r
834                 if(vote_called_vote)\r
835                         strunzone(vote_called_vote);\r
836                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));\r
837         }\r
838 \r
839         if(nags & 1)\r
840         {\r
841                 for(j = 0; j < maxclients; ++j)\r
842                         if(playerslots[j])\r
843                                 playerslots[j].ready = 1;\r
844                 for(i = 1; i <= maxclients; i += 8)\r
845                 {\r
846                         f = ReadByte();\r
847                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)\r
848                                 if not(f & b)\r
849                                         if(playerslots[j])\r
850                                                 playerslots[j].ready = 0;\r
851                 }\r
852         }\r
853 \r
854         ready_waiting = (nags & 1);\r
855         ready_waiting_for_me = (nags & 2);\r
856         vote_waiting = (nags & 4);\r
857         vote_waiting_for_me = (nags & 8);\r
858         warmup_stage = (nags & 16);\r
859 }\r
860 \r
861 void Ent_RandomSeed()\r
862 {\r
863         float s;\r
864         prandom_debug();\r
865         s = ReadShort();\r
866         psrandom(s);\r
867 }\r
868 \r
869 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.\r
870 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.\r
871 void Ent_RadarLink();\r
872 void Ent_Init();\r
873 void Ent_ScoresInfo();\r
874 void(float bIsNewEntity) CSQC_Ent_Update =\r
875 {\r
876         float t;\r
877         float savetime;\r
878         t = ReadByte();\r
879 \r
880         // set up the "time" global for received entities to be correct for interpolation purposes\r
881         savetime = time;\r
882         if(servertime)\r
883         {\r
884                 time = servertime;\r
885         }\r
886         else\r
887         {\r
888                 serverprevtime = time;\r
889                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);\r
890                 time = serverprevtime + serverdeltatime;\r
891         }\r
892 \r
893 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED\r
894         if(self.enttype)\r
895                 if(t != self.enttype)\r
896                 {\r
897                         print("A CSQC entity changed its type!\n");\r
898                         Ent_Remove();\r
899                         bIsNewEntity = 1;\r
900                 }\r
901 #endif\r
902         self.enttype = t;\r
903         switch(t)\r
904         {\r
905                 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;\r
906                 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;\r
907                 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;\r
908                 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;\r
909                 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;\r
910                 case ENT_CLIENT_LASER: Ent_Laser(); break;\r
911                 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;\r
912                 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;\r
913                 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;\r
914                 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;\r
915                 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;\r
916                 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;\r
917                 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;\r
918                 case ENT_CLIENT_INIT: Ent_Init(); break;\r
919                 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;\r
920                 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;\r
921                 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;\r
922                 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;\r
923                 case ENT_CLIENT_WALL: Ent_Wall(); break;\r
924                 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;\r
925                 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;\r
926                 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;\r
927                 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;\r
928                 default:\r
929                         error(strcat("unknown entity type in CSQC_Ent_Update: ", ftos(self.enttype), "\n"));\r
930                         break;\r
931         }\r
932 \r
933         time = savetime;\r
934 };\r
935 // Destructor, but does NOT deallocate the entity by calling remove(). Also\r
936 // used when an entity changes its type. For an entity that someone interacts\r
937 // with others, make sure it can no longer do so.\r
938 void Ent_Remove()\r
939 {\r
940         if(self.entremove)\r
941                 self.entremove();\r
942 \r
943         self.enttype = 0;\r
944         self.classname = "";\r
945         self.draw = menu_sub_null;\r
946         self.entremove = menu_sub_null;\r
947         // TODO possibly set more stuff to defaults\r
948 }\r
949 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.\r
950 void CSQC_Ent_Remove()\r
951 {\r
952         if(self.enttype)\r
953                 Ent_Remove();\r
954         remove(self);\r
955 }\r
956 \r
957 void Gamemode_Init()\r
958 {\r
959         if(gametype == GAME_ONSLAUGHT)\r
960                 print(strcat("Using ", minimapname, " as minimap.\n"));\r
961 \r
962         if not(isdemo())\r
963         {\r
964                 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), ";");\r
965                 if(g_campaign)\r
966                         localcmd("\n_cl_hook_campaign_gamestart ", GametypeNameFromType(gametype), ";");\r
967                 calledhooks |= HOOK_START;\r
968         }\r
969 }\r
970 // 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
971 void CSQC_Parse_StuffCmd(string strMessage)\r
972 {\r
973         localcmd(strMessage);\r
974 }\r
975 // 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
976 void CSQC_Parse_Print(string strMessage)\r
977 {\r
978         print(ColorTranslateRGB(strMessage));\r
979 }\r
980 \r
981 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided.\r
982 void CSQC_Parse_CenterPrint(string strMessage)\r
983 {\r
984         centerprint(strMessage);\r
985 }\r
986 \r
987 string notranslate_fogcmd1 = "\nfog ";\r
988 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";\r
989 void Fog_Force()\r
990 {\r
991         // TODO somehow thwart prvm_globalset client ...\r
992 \r
993         if(forcefog != "")\r
994                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));\r
995 }\r
996 \r
997 void Gamemode_Init();\r
998 void Ent_ScoresInfo()\r
999 {\r
1000         float i;\r
1001         self.classname = "ent_client_scores_info";\r
1002         gametype = ReadByte();\r
1003         for(i = 0; i < MAX_SCORE; ++i)\r
1004         {\r
1005                 scores_label[i] = strzone(ReadString());\r
1006                 scores_flags[i] = ReadByte();\r
1007         }\r
1008         for(i = 0; i < MAX_TEAMSCORE; ++i)\r
1009         {\r
1010                 teamscores_label[i] = strzone(ReadString());\r
1011                 teamscores_flags[i] = ReadByte();\r
1012         }\r
1013         Sbar_InitScores();\r
1014         Gamemode_Init();\r
1015 }\r
1016 \r
1017 void Ent_Init()\r
1018 {\r
1019         self.classname = "ent_client_init";\r
1020 \r
1021         grabber_shotorigin_x = ReadCoord();\r
1022         grabber_shotorigin_y = ReadCoord();\r
1023         grabber_shotorigin_z = ReadCoord();\r
1024 \r
1025         if(forcefog)\r
1026                 strunzone(forcefog);\r
1027         forcefog = strzone(ReadString());\r
1028 \r
1029         g_campaign = ReadCoord();\r
1030 \r
1031         armorblockpercent = ReadByte() / 255.0;\r
1032 \r
1033         g_weaponswitchdelay = ReadByte() / 255.0;\r
1034 \r
1035         g_vore = ReadCoord();\r
1036         g_balance_vore_swallow_limit = ReadCoord();\r
1037 \r
1038         armor_enabled = ReadByte();\r
1039 \r
1040         if(!postinit)\r
1041                 PostInit();\r
1042 }\r
1043 \r
1044 void Net_ReadRace()\r
1045 {\r
1046         float b;\r
1047 \r
1048         b = ReadByte();\r
1049 \r
1050         switch(b)\r
1051         {\r
1052                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:\r
1053                         race_checkpoint = ReadByte();\r
1054                         race_time = ReadInt24_t();\r
1055                         race_previousbesttime = ReadInt24_t();\r
1056                         if(race_previousbestname)\r
1057                                 strunzone(race_previousbestname);\r
1058                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));\r
1059 \r
1060                         race_checkpointtime = time;\r
1061 \r
1062                         if(race_checkpoint == 0 || race_checkpoint == 254)\r
1063                         {\r
1064                                 race_penaltyaccumulator = 0;\r
1065                                 race_laptime = time; // valid\r
1066                         }\r
1067 \r
1068                         break;\r
1069 \r
1070                 case RACE_NET_CHECKPOINT_CLEAR:\r
1071                         race_laptime = 0;\r
1072                         race_checkpointtime = 0;\r
1073                         break;\r
1074 \r
1075                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:\r
1076                         race_laptime = ReadCoord();\r
1077                         race_checkpointtime = -99999;\r
1078                         // fall through\r
1079                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:\r
1080                         race_nextcheckpoint = ReadByte();\r
1081 \r
1082                         race_nextbesttime = ReadInt24_t();\r
1083                         if(race_nextbestname)\r
1084                                 strunzone(race_nextbestname);\r
1085                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));\r
1086                         break;\r
1087 \r
1088                 case RACE_NET_CHECKPOINT_HIT_RACE:\r
1089                         race_mycheckpoint = ReadByte();\r
1090                         race_mycheckpointtime = time;\r
1091                         race_mycheckpointdelta = ReadInt24_t();\r
1092                         race_mycheckpointlapsdelta = ReadByte();\r
1093                         if(race_mycheckpointlapsdelta >= 128)\r
1094                                 race_mycheckpointlapsdelta -= 256;\r
1095                         if(race_mycheckpointenemy)\r
1096                                 strunzone(race_mycheckpointenemy);\r
1097                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));\r
1098                         break;\r
1099 \r
1100                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:\r
1101                         race_othercheckpoint = ReadByte();\r
1102                         race_othercheckpointtime = time;\r
1103                         race_othercheckpointdelta = ReadInt24_t();\r
1104                         race_othercheckpointlapsdelta = ReadByte();\r
1105                         if(race_othercheckpointlapsdelta >= 128)\r
1106                                 race_othercheckpointlapsdelta -= 256;\r
1107                         if(race_othercheckpointenemy)\r
1108                                 strunzone(race_othercheckpointenemy);\r
1109                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));\r
1110                         break;\r
1111 \r
1112                 case RACE_NET_PENALTY_RACE:\r
1113                         race_penaltyeventtime = time;\r
1114                         race_penaltytime = ReadShort();\r
1115                         //race_penaltyaccumulator += race_penaltytime;\r
1116                         if(race_penaltyreason)\r
1117                                 strunzone(race_penaltyreason);\r
1118                         race_penaltyreason = strzone(ReadString());\r
1119                         break;\r
1120 \r
1121                 case RACE_NET_PENALTY_QUALIFYING:\r
1122                         race_penaltyeventtime = time;\r
1123                         race_penaltytime = ReadShort();\r
1124                         race_penaltyaccumulator += race_penaltytime;\r
1125                         if(race_penaltyreason)\r
1126                                 strunzone(race_penaltyreason);\r
1127                         race_penaltyreason = strzone(ReadString());\r
1128                         break;\r
1129 \r
1130                 case RACE_NET_SERVER_RECORD:\r
1131                         race_server_record = ReadInt24_t();\r
1132                         break;\r
1133                 case RACE_NET_SPEED_AWARD:\r
1134                         race_speedaward = ReadInt24_t();\r
1135                         if(race_speedaward_holder)\r
1136                                 strunzone(race_speedaward_holder);\r
1137                         race_speedaward_holder = strzone(ReadString());\r
1138                         break;\r
1139                 case RACE_NET_SPEED_AWARD_BEST:\r
1140                         race_speedaward_alltimebest = ReadInt24_t();\r
1141                         if(race_speedaward_alltimebest_holder)\r
1142                                 strunzone(race_speedaward_alltimebest_holder);\r
1143                         race_speedaward_alltimebest_holder = strzone(ReadString());\r
1144                         break;\r
1145                 case RACE_NET_SERVER_RANKINGS:\r
1146                         float pos, prevpos, del;\r
1147                         pos = ReadShort();\r
1148                         prevpos = ReadShort();\r
1149                         del = ReadShort();\r
1150 \r
1151                         // move other rankings out of the way\r
1152                         float i;\r
1153                         if (prevpos) {\r
1154                                 for (i=prevpos-1;i>pos-1;--i) {\r
1155                                         grecordtime[i] = grecordtime[i-1];\r
1156                                         if(grecordholder[i])\r
1157                                                 strunzone(grecordholder[i]);\r
1158                                         grecordholder[i] = strzone(grecordholder[i-1]);\r
1159                                 }\r
1160                         } else if (del) { // a record has been deleted by the admin\r
1161                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {\r
1162                                         if (i == RANKINGS_CNT-1) { // clear out last record\r
1163                                                 grecordtime[i] = 0;\r
1164                                                 if (grecordholder[i])\r
1165                                                         strunzone(grecordholder[i]);\r
1166                                                 grecordholder[i] = string_null;\r
1167                                         }\r
1168                                         else {\r
1169                                                 grecordtime[i] = grecordtime[i+1];\r
1170                                                 if (grecordholder[i])\r
1171                                                         strunzone(grecordholder[i]);\r
1172                                                 grecordholder[i] = strzone(grecordholder[i+1]);\r
1173                                         }\r
1174                                 }\r
1175                         } else { // player has no ranked record yet\r
1176                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {\r
1177                                         grecordtime[i] = grecordtime[i-1];\r
1178                                         if(grecordholder[i])\r
1179                                                 strunzone(grecordholder[i]);\r
1180                                         grecordholder[i] = strzone(grecordholder[i-1]);\r
1181                                 }\r
1182                         }\r
1183 \r
1184                         // store new ranking\r
1185                         if(grecordholder[pos-1] != "")\r
1186                                 strunzone(grecordholder[pos-1]);\r
1187                         grecordholder[pos-1] = strzone(ReadString());\r
1188                         grecordtime[pos-1] = ReadInt24_t();\r
1189                         if(grecordholder[pos-1] == GetPlayerName(player_localentnum -1))\r
1190                                 race_myrank = pos;\r
1191                         break;\r
1192                 case RACE_NET_SERVER_STATUS:\r
1193                         race_status = ReadShort();\r
1194                         if(race_status_name)\r
1195                                 strunzone(race_status_name);\r
1196                         race_status_name = strzone(ReadString());\r
1197         }\r
1198 }\r
1199 \r
1200 void Net_ReadSpawn()\r
1201 {\r
1202         zoomin_effect = 1;\r
1203         current_viewzoom = 0.6;\r
1204 }\r
1205 \r
1206 void Net_TeamNagger()\r
1207 {\r
1208         teamnagger = 1;\r
1209 }\r
1210 \r
1211 void Net_ReadPingPLReport()\r
1212 {\r
1213         float e, pi, pl, ml;\r
1214         e = ReadByte();\r
1215         pi = ReadShort();\r
1216         pl = ReadByte();\r
1217         ml = ReadByte();\r
1218         if not(playerslots[e])\r
1219                 return;\r
1220         playerslots[e].ping = pi;\r
1221         playerslots[e].ping_packetloss = pl / 255.0;\r
1222         playerslots[e].ping_movementloss = ml / 255.0;\r
1223 }\r
1224 \r
1225 void Net_ReadOtherPLReport()\r
1226 {\r
1227         float e, ph, pn;\r
1228         e = ReadByte();\r
1229         ph = ReadByte();\r
1230         pn = ReadByte();\r
1231         if not(playerslots[e])\r
1232                 return;\r
1233         playerslots[e].plhealth = ph;\r
1234         playerslots[e].plpredator = pn;\r
1235 }\r
1236 \r
1237 void Net_VoteDialog(float highlight) {\r
1238         if(highlight) {\r
1239                 vote_highlighted = ReadShort();\r
1240                 return;\r
1241         }\r
1242 \r
1243         vote_yescount = ReadShort();\r
1244         vote_nocount = ReadShort();\r
1245         vote_needed = ReadShort();\r
1246         vote_active = 1;\r
1247 }\r
1248 \r
1249 void Net_VoteDialogReset() {\r
1250         vote_active = 0;\r
1251 }\r
1252 \r
1253 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.\r
1254 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.\r
1255 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.\r
1256 float CSQC_Parse_TempEntity()\r
1257 {\r
1258         local float bHandled;\r
1259                 bHandled  = true;\r
1260         // Acquire TE ID\r
1261         local float nTEID;\r
1262                 nTEID = ReadByte();\r
1263 \r
1264                 // NOTE: Could just do return instead of break...\r
1265         switch(nTEID)\r
1266         {\r
1267                 case TE_CSQC_TARGET_MUSIC:\r
1268                         Net_TargetMusic();\r
1269                         bHandled = true;\r
1270                         break;\r
1271                 case TE_CSQC_PICTURE:\r
1272                         Net_MapVote_Picture();\r
1273                         bHandled = true;\r
1274                         break;\r
1275                 case TE_CSQC_RACE:\r
1276                         Net_ReadRace();\r
1277                         bHandled = true;\r
1278                         break;\r
1279                 case 13: // TE_BEAM\r
1280                         Net_Grabber();\r
1281                         bHandled = true;\r
1282                         break;\r
1283                 case TE_CSQC_SPAWN:\r
1284                         Net_ReadSpawn();\r
1285                         bHandled = true;\r
1286                         break;\r
1287                 case TE_CSQC_ZCURVEPARTICLES:\r
1288                         Net_ReadZCurveParticles();\r
1289                         bHandled = true;\r
1290                         break;\r
1291                 case TE_CSQC_TEAMNAGGER:\r
1292                         Net_TeamNagger();\r
1293                         bHandled = true;\r
1294                         break;\r
1295                 case TE_CSQC_VOTE:\r
1296                         Net_VoteDialog(ReadByte());\r
1297                         bHandled = true;\r
1298                         break;\r
1299                 case TE_CSQC_VOTERESET:\r
1300                         Net_VoteDialogReset();\r
1301                         bHandled = true;\r
1302                         break;\r
1303                 case TE_CSQC_LIGHTNINGARC:\r
1304                         Net_ReadLightningarc();\r
1305                         bHandled = true;\r
1306                         break;\r
1307                 case TE_CSQC_PINGPLREPORT:\r
1308                         Net_ReadPingPLReport();\r
1309                         bHandled = true;\r
1310                         break;\r
1311                 case TE_CSQC_OTHERPLREPORT:\r
1312                         Net_ReadOtherPLReport();\r
1313                         bHandled = true;\r
1314                         break;\r
1315                 case TE_CSQC_ANNOUNCE:\r
1316                         announce_snd = strzone(ReadString());\r
1317                         bHandled = true;\r
1318                         break;\r
1319                 default:\r
1320                         // No special logic for this temporary entity; return 0 so the engine can handle it\r
1321                         bHandled = false;\r
1322                         break;\r
1323         }\r
1324 \r
1325         return bHandled;\r
1326 }\r
1327 \r
1328 string getcommandkey(string text, string command)\r
1329 {\r
1330         string keys;\r
1331         float n, j, k, l;\r
1332 \r
1333         if (!sbar_showbinds)\r
1334                 return text;\r
1335 \r
1336         keys = db_get(binddb, command);\r
1337         if (!keys)\r
1338         {\r
1339                 n = tokenize(findkeysforcommand(command)); // uses '...' strings\r
1340                 for(j = 0; j < n; ++j)\r
1341                 {\r
1342                         k = stof(argv(j));\r
1343                         if(k != -1)\r
1344                         {\r
1345                                 if ("" == keys)\r
1346                                         keys = keynumtostring(k);\r
1347                                 else\r
1348                                         keys = strcat(keys, ", ", keynumtostring(k));\r
1349 \r
1350                                 ++l;\r
1351                                 if (sbar_showbinds_limit > 0 && sbar_showbinds_limit >= l) break;\r
1352                         }\r
1353 \r
1354                 }\r
1355                 db_put(binddb, command, keys);\r
1356         }\r
1357 \r
1358         if ("" == keys) {\r
1359                 if (sbar_showbinds > 1)\r
1360                         return strcat(text, " (not bound)");\r
1361                 else\r
1362                         return text;\r
1363         }\r
1364         else if (sbar_showbinds > 1)\r
1365                 return strcat(text, " (", keys, ")");\r
1366         else\r
1367                 return keys;\r
1368 }\r