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