Some improvements to the sbar ammo code and other fixes
[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                 precache_pic("gfx/ons-cp-neutral.tga");\r
947                 precache_pic("gfx/ons-cp-red.tga");\r
948                 precache_pic("gfx/ons-cp-blue.tga");\r
949                 precache_pic("gfx/ons-frame.tga");\r
950                 precache_pic("gfx/ons-frame-team.tga");\r
951         } else if(gametype == GAME_KEYHUNT) {\r
952                 precache_pic("gfx/sb_key_carrying");\r
953                 precache_pic("gfx/sb_key_carrying_outline");\r
954         }\r
955 \r
956         if not(isdemo())\r
957         {\r
958                 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), ";");\r
959                 calledgrabbers |= GRABBER_START;\r
960         }\r
961 }\r
962 // 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
963 void CSQC_Parse_StuffCmd(string strMessage)\r
964 {\r
965         localcmd(strMessage);\r
966 }\r
967 // 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
968 void CSQC_Parse_Print(string strMessage)\r
969 {\r
970         print(ColorTranslateRGB(strMessage));\r
971 }\r
972 \r
973 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided.\r
974 void CSQC_Parse_CenterPrint(string strMessage)\r
975 {\r
976         centerprint(strMessage);\r
977 }\r
978 \r
979 string notranslate_fogcmd1 = "\nfog ";\r
980 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";\r
981 void Fog_Force()\r
982 {\r
983         // TODO somehow thwart prvm_globalset client ...\r
984 \r
985         if(forcefog != "")\r
986                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));\r
987 }\r
988 \r
989 void Gamemode_Init();\r
990 void Ent_ScoresInfo()\r
991 {\r
992         float i;\r
993         self.classname = "ent_client_scores_info";\r
994         gametype = ReadByte();\r
995         for(i = 0; i < MAX_SCORE; ++i)\r
996         {\r
997                 scores_label[i] = strzone(ReadString());\r
998                 scores_flags[i] = ReadByte();\r
999         }\r
1000         for(i = 0; i < MAX_TEAMSCORE; ++i)\r
1001         {\r
1002                 teamscores_label[i] = strzone(ReadString());\r
1003                 teamscores_flags[i] = ReadByte();\r
1004         }\r
1005         Sbar_InitScores();\r
1006         Gamemode_Init();\r
1007 }\r
1008 \r
1009 void Ent_Init()\r
1010 {\r
1011         self.classname = "ent_client_init";\r
1012 \r
1013         grabber_shotorigin_x = ReadCoord();\r
1014         grabber_shotorigin_y = ReadCoord();\r
1015         grabber_shotorigin_z = ReadCoord();\r
1016 \r
1017         if(forcefog)\r
1018                 strunzone(forcefog);\r
1019         forcefog = strzone(ReadString());\r
1020 \r
1021         armorblockpercent = ReadByte() / 255.0;\r
1022 \r
1023         g_weaponswitchdelay = ReadByte() / 255.0;\r
1024 \r
1025         g_balance_vore_swallow_limit = ReadCoord();\r
1026         g_vore_showpreyhealth = ReadCoord();\r
1027 \r
1028         if(!postinit)\r
1029                 PostInit();\r
1030 }\r
1031 \r
1032 void Net_ReadRace()\r
1033 {\r
1034         float b;\r
1035 \r
1036         b = ReadByte();\r
1037 \r
1038         switch(b)\r
1039         {\r
1040                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:\r
1041                         race_checkpoint = ReadByte();\r
1042                         race_time = ReadInt24_t();\r
1043                         race_previousbesttime = ReadInt24_t();\r
1044                         if(race_previousbestname)\r
1045                                 strunzone(race_previousbestname);\r
1046                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));\r
1047 \r
1048                         race_checkpointtime = time;\r
1049 \r
1050                         if(race_checkpoint == 0 || race_checkpoint == 254)\r
1051                         {\r
1052                                 race_penaltyaccumulator = 0;\r
1053                                 race_laptime = time; // valid\r
1054                         }\r
1055 \r
1056                         break;\r
1057 \r
1058                 case RACE_NET_CHECKPOINT_CLEAR:\r
1059                         race_laptime = 0;\r
1060                         race_checkpointtime = 0;\r
1061                         break;\r
1062 \r
1063                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:\r
1064                         race_laptime = ReadCoord();\r
1065                         race_checkpointtime = -99999;\r
1066                         // fall through\r
1067                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:\r
1068                         race_nextcheckpoint = ReadByte();\r
1069 \r
1070                         race_nextbesttime = ReadInt24_t();\r
1071                         if(race_nextbestname)\r
1072                                 strunzone(race_nextbestname);\r
1073                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));\r
1074                         break;\r
1075 \r
1076                 case RACE_NET_CHECKPOINT_HIT_RACE:\r
1077                         race_mycheckpoint = ReadByte();\r
1078                         race_mycheckpointtime = time;\r
1079                         race_mycheckpointdelta = ReadInt24_t();\r
1080                         race_mycheckpointlapsdelta = ReadByte();\r
1081                         if(race_mycheckpointlapsdelta >= 128)\r
1082                                 race_mycheckpointlapsdelta -= 256;\r
1083                         if(race_mycheckpointenemy)\r
1084                                 strunzone(race_mycheckpointenemy);\r
1085                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));\r
1086                         break;\r
1087 \r
1088                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:\r
1089                         race_othercheckpoint = ReadByte();\r
1090                         race_othercheckpointtime = time;\r
1091                         race_othercheckpointdelta = ReadInt24_t();\r
1092                         race_othercheckpointlapsdelta = ReadByte();\r
1093                         if(race_othercheckpointlapsdelta >= 128)\r
1094                                 race_othercheckpointlapsdelta -= 256;\r
1095                         if(race_othercheckpointenemy)\r
1096                                 strunzone(race_othercheckpointenemy);\r
1097                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));\r
1098                         break;\r
1099 \r
1100                 case RACE_NET_PENALTY_RACE:\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_PENALTY_QUALIFYING:\r
1110                         race_penaltyeventtime = time;\r
1111                         race_penaltytime = ReadShort();\r
1112                         race_penaltyaccumulator += race_penaltytime;\r
1113                         if(race_penaltyreason)\r
1114                                 strunzone(race_penaltyreason);\r
1115                         race_penaltyreason = strzone(ReadString());\r
1116                         break;\r
1117 \r
1118                 case RACE_NET_SERVER_RECORD:\r
1119                         race_server_record = ReadInt24_t();\r
1120                         break;\r
1121                 case RACE_NET_SPEED_AWARD:\r
1122                         race_speedaward = ReadInt24_t();\r
1123                         if(race_speedaward_holder)\r
1124                                 strunzone(race_speedaward_holder);\r
1125                         race_speedaward_holder = strzone(ReadString());\r
1126                         break;\r
1127                 case RACE_NET_SPEED_AWARD_BEST:\r
1128                         race_speedaward_alltimebest = ReadInt24_t();\r
1129                         if(race_speedaward_alltimebest_holder)\r
1130                                 strunzone(race_speedaward_alltimebest_holder);\r
1131                         race_speedaward_alltimebest_holder = strzone(ReadString());\r
1132                         break;\r
1133                 case RACE_NET_SERVER_RANKINGS:\r
1134                         float pos, prevpos, del;\r
1135                         pos = ReadShort();\r
1136                         prevpos = ReadShort();\r
1137                         del = ReadShort();\r
1138 \r
1139                         // move other rankings out of the way\r
1140                         float i;\r
1141                         if (prevpos) {\r
1142                                 for (i=prevpos-1;i>pos-1;--i) {\r
1143                                         grecordtime[i] = grecordtime[i-1];\r
1144                                         if(grecordholder[i])\r
1145                                                 strunzone(grecordholder[i]);\r
1146                                         grecordholder[i] = strzone(grecordholder[i-1]);\r
1147                                 }\r
1148                         } else if (del) { // a record has been deleted by the admin\r
1149                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {\r
1150                                         if (i == RANKINGS_CNT-1) { // clear out last record\r
1151                                                 grecordtime[i] = 0;\r
1152                                                 if (grecordholder[i])\r
1153                                                         strunzone(grecordholder[i]);\r
1154                                                 grecordholder[i] = string_null;\r
1155                                         }\r
1156                                         else {\r
1157                                                 grecordtime[i] = grecordtime[i+1];\r
1158                                                 if (grecordholder[i])\r
1159                                                         strunzone(grecordholder[i]);\r
1160                                                 grecordholder[i] = strzone(grecordholder[i+1]);\r
1161                                         }\r
1162                                 }\r
1163                         } else { // player has no ranked record yet\r
1164                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {\r
1165                                         grecordtime[i] = grecordtime[i-1];\r
1166                                         if(grecordholder[i])\r
1167                                                 strunzone(grecordholder[i]);\r
1168                                         grecordholder[i] = strzone(grecordholder[i-1]);\r
1169                                 }\r
1170                         }\r
1171 \r
1172                         // store new ranking\r
1173                         if(grecordholder[pos-1] != "")\r
1174                                 strunzone(grecordholder[pos-1]);\r
1175                         grecordholder[pos-1] = strzone(ReadString());\r
1176                         grecordtime[pos-1] = ReadInt24_t();\r
1177                         if(grecordholder[pos-1] == GetPlayerName(player_localentnum -1))\r
1178                                 race_myrank = pos;\r
1179                         break;\r
1180                 case RACE_NET_SERVER_STATUS:\r
1181                         race_status = ReadShort();\r
1182                         if(race_status_name)\r
1183                                 strunzone(race_status_name);\r
1184                         race_status_name = strzone(ReadString());\r
1185         }\r
1186 }\r
1187 \r
1188 void Net_ReadSpawn()\r
1189 {\r
1190         zoomin_effect = 1;\r
1191         current_viewzoom = 0.6;\r
1192 }\r
1193 \r
1194 void Net_TeamNagger()\r
1195 {\r
1196         teamnagger = 1;\r
1197 }\r
1198 \r
1199 void Net_ReadPingPLReport()\r
1200 {\r
1201         float e, pi, pl, ml;\r
1202         e = ReadByte();\r
1203         pi = ReadShort();\r
1204         pl = ReadByte();\r
1205         ml = ReadByte();\r
1206         if not(playerslots[e])\r
1207                 return;\r
1208         playerslots[e].ping = pi;\r
1209         playerslots[e].ping_packetloss = pl / 255.0;\r
1210         playerslots[e].ping_movementloss = ml / 255.0;\r
1211 }\r
1212 \r
1213 void Net_ReadOtherPLReport()\r
1214 {\r
1215         float e, ph, pn;\r
1216         e = ReadByte();\r
1217         ph = ReadByte();\r
1218         pn = ReadByte();\r
1219         if not(playerslots[e])\r
1220                 return;\r
1221         playerslots[e].plhealth = ph;\r
1222         playerslots[e].pleater = pn;\r
1223 }\r
1224 \r
1225 void Net_VoteDialog(float highlight) {\r
1226         if(highlight) {\r
1227                 vote_highlighted = ReadShort();\r
1228                 return;\r
1229         }\r
1230 \r
1231         vote_yescount = ReadShort();\r
1232         vote_nocount = ReadShort();\r
1233         vote_needed = ReadShort();\r
1234         vote_active = 1;\r
1235 }\r
1236 \r
1237 void Net_VoteDialogReset() {\r
1238         vote_active = 0;\r
1239 }\r
1240 \r
1241 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.\r
1242 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.\r
1243 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.\r
1244 float CSQC_Parse_TempEntity()\r
1245 {\r
1246         local float bHandled;\r
1247                 bHandled  = true;\r
1248         // Acquire TE ID\r
1249         local float nTEID;\r
1250                 nTEID = ReadByte();\r
1251 \r
1252                 // NOTE: Could just do return instead of break...\r
1253         switch(nTEID)\r
1254         {\r
1255                 case TE_CSQC_TARGET_MUSIC:\r
1256                         Net_TargetMusic();\r
1257                         bHandled = true;\r
1258                         break;\r
1259                 case TE_CSQC_PICTURE:\r
1260                         Net_MapVote_Picture();\r
1261                         bHandled = true;\r
1262                         break;\r
1263                 case TE_CSQC_RACE:\r
1264                         Net_ReadRace();\r
1265                         bHandled = true;\r
1266                         break;\r
1267                 case 13: // TE_BEAM\r
1268                         Net_Grabber();\r
1269                         bHandled = true;\r
1270                         break;\r
1271                 case TE_CSQC_SPAWN:\r
1272                         Net_ReadSpawn();\r
1273                         bHandled = true;\r
1274                         break;\r
1275                 case TE_CSQC_ZCURVEPARTICLES:\r
1276                         Net_ReadZCurveParticles();\r
1277                         bHandled = true;\r
1278                         break;\r
1279                 case TE_CSQC_TEAMNAGGER:\r
1280                         Net_TeamNagger();\r
1281                         bHandled = true;\r
1282                         break;\r
1283                 case TE_CSQC_VOTE:\r
1284                         Net_VoteDialog(ReadByte());\r
1285                         bHandled = true;\r
1286                         break;\r
1287                 case TE_CSQC_VOTERESET:\r
1288                         Net_VoteDialogReset();\r
1289                         bHandled = true;\r
1290                         break;\r
1291                 case TE_CSQC_LIGHTNINGARC:\r
1292                         Net_ReadLightningarc();\r
1293                         bHandled = true;\r
1294                         break;\r
1295                 case TE_CSQC_PINGPLREPORT:\r
1296                         Net_ReadPingPLReport();\r
1297                         bHandled = true;\r
1298                         break;\r
1299                 case TE_CSQC_OTHERPLREPORT:\r
1300                         Net_ReadOtherPLReport();\r
1301                         bHandled = true;\r
1302                         break;\r
1303                 case TE_CSQC_ANNOUNCE:\r
1304                         announce_snd = strzone(ReadString());\r
1305                         bHandled = true;\r
1306                         break;\r
1307                 default:\r
1308                         // No special logic for this temporary entity; return 0 so the engine can handle it\r
1309                         bHandled = false;\r
1310                         break;\r
1311         }\r
1312 \r
1313         return bHandled;\r
1314 }\r
1315 \r
1316 string getcommandkey(string text, string command)\r
1317 {\r
1318         string keys;\r
1319         float n, j, k, l;\r
1320 \r
1321         if (!sbar_showbinds)\r
1322                 return text;\r
1323 \r
1324         keys = db_get(binddb, command);\r
1325         if (!keys)\r
1326         {\r
1327                 n = tokenize(findkeysforcommand(command)); // uses '...' strings\r
1328                 for(j = 0; j < n; ++j)\r
1329                 {\r
1330                         k = stof(argv(j));\r
1331                         if(k != -1)\r
1332                         {\r
1333                                 if ("" == keys)\r
1334                                         keys = keynumtostring(k);\r
1335                                 else\r
1336                                         keys = strcat(keys, ", ", keynumtostring(k));\r
1337 \r
1338                                 ++l;\r
1339                                 if (sbar_showbinds_limit > 0 && sbar_showbinds_limit >= l) break;\r
1340                         }\r
1341 \r
1342                 }\r
1343                 db_put(binddb, command, keys);\r
1344         }\r
1345 \r
1346         if ("" == keys) {\r
1347                 if (sbar_showbinds > 1)\r
1348                         return strcat(text, " (not bound)");\r
1349                 else\r
1350                         return text;\r
1351         }\r
1352         else if (sbar_showbinds > 1)\r
1353                 return strcat(text, " (", keys, ")");\r
1354         else\r
1355                 return keys;\r
1356 }\r