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