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