1 // --------------------------------------------------------------------------
2 // BEGIN REQUIRED CSQC FUNCTIONS
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
9 drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
12 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
13 // Useful for precaching things
23 void precache_playermodel(string m)
27 if(substring(m, -9,5) == "_lod1")
29 if(substring(m, -9,5) == "_lod2")
32 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
35 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
40 float globhandle, i, n;
41 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
44 n = search_getsize(globhandle);
45 for (i = 0; i < n; ++i)
47 //print(search_getfilename(globhandle, i), "\n");
48 f = search_getfilename(globhandle, i);
49 PrecachePlayerSounds(f);
51 search_end(globhandle);
54 void precache_all_playermodels(string pattern)
56 float globhandle, i, n;
59 globhandle = search_begin(pattern, TRUE, FALSE);
62 n = search_getsize(globhandle);
63 for (i = 0; i < n; ++i)
65 //print(search_getfilename(globhandle, i), "\n");
66 f = search_getfilename(globhandle, i);
67 precache_playermodel(f);
69 search_end(globhandle);
73 void WaypointSprite_Load();
76 prvm_language = cvar_string("prvm_language");
80 __engine_check = checkextension("DP_SV_WRITEPICTURE");
83 print(_("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n"));
84 localcmd("\ndisconnect\n");
90 check_unacceptable_compiler_bugs();
93 print(sprintf(_("^4CSQC Build information: ^1%s\n"), WATERMARK()));
98 #ifdef COMPAT_XON050_ENGINE
99 // old engine lacks implementation of player_localnum
100 player_localnum = player_localentnum - 1;
103 binddb = db_create();
104 tempdb = db_create();
105 ClientProgsDB = db_load("client.db");
106 compressShortVector_init();
108 drawfont = FONT_USER+1;
109 menu_visible = FALSE;
110 menu_show = menu_show_error;
111 menu_action = menu_sub_null;
113 for(i = 0; i < 255; ++i)
114 if(getplayerkeyvalue(i, "viewentity") == "")
118 registercommand("hud_configure");
119 registercommand("hud_save");
120 //registercommand("menu_action");
122 registercommand("+showscores");registercommand("-showscores");
123 registercommand("+showaccuracy");registercommand("-showaccuracy");
129 registercommand("+forward");registercommand("-forward");
130 registercommand("+back");registercommand("-back");
131 registercommand("+moveup");registercommand("-moveup");
132 registercommand("+movedown");registercommand("-movedown");
133 registercommand("+moveright");registercommand("-moveright");
134 registercommand("+moveleft");registercommand("-moveleft");
135 registercommand("+roll_right");registercommand("-roll_right");
136 registercommand("+roll_left");registercommand("-roll_left");
140 registercvar("hud_usecsqc", "1");
141 registercvar("scoreboard_columns", "default");
145 // hud_fields uses strunzone on the titles!
146 for(i = 0; i < MAX_HUD_FIELDS; ++i)
147 hud_title[i] = strzone("(null)");
153 teams = Sort_Spawn();
154 players = Sort_Spawn();
156 GetTeam(COLOR_SPECTATOR, true); // add specs first
158 // needs to be done so early because of the constants they create
162 WaypointSprite_Load();
165 precache_model("null");
166 precache_sound("misc/hit.wav");
167 precache_sound("misc/typehit.wav");
168 if (autocvar_cl_precacheplayermodels)
170 precache_all_playermodels("models/player/*.zym");
171 precache_all_playermodels("models/player/*.dpm");
172 precache_all_playermodels("models/player/*.md3");
173 precache_all_playermodels("models/player/*.psk");
174 precache_all_playermodels("models/player/*.iqm");
177 Projectile_Precache();
179 GibSplash_Precache();
181 DamageInfo_Precache();
184 Announcer_Precache();
187 if(autocvar_cl_reticle)
189 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
190 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
193 get_mi_min_max_texcoords(1); // try the CLEVER way first
194 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
195 shortmapname = mi_shortname;
197 if(precache_pic(minimapname) == "")
199 // but maybe we have a non-clever minimap
200 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
201 if(precache_pic(minimapname) == "")
202 minimapname = ""; // FAIL
204 get_mi_min_max_texcoords(0); // load new texcoords
207 mi_center = (mi_min + mi_max) * 0.5;
208 mi_scale = mi_max - mi_min;
209 minimapname = strzone(minimapname);
213 hud_configure_prev = -1;
216 draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
219 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
235 if(autocvar_cl_db_saveasdump)
236 db_dump(ClientProgsDB, "client.db");
238 db_save(ClientProgsDB, "client.db");
239 db_close(ClientProgsDB);
242 cvar_set("chase_active",ftos(chase_active_backup));
244 // unset the event chasecam's chase_active
245 if(autocvar_chase_active < 0)
246 cvar_set("chase_active", "0");
250 if not(calledhooks & HOOK_START)
251 localcmd("\n_cl_hook_gamestart nop\n");
252 if not(calledhooks & HOOK_END)
253 localcmd("\ncl_hook_gameend\n");
258 float SetTeam(entity o, float Team)
272 if(GetTeam(Team, false) == world)
274 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
275 Team = COLOR_SPECTATOR;
288 if(GetTeam(Team, false) == world)
290 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
291 Team = COLOR_SPECTATOR;
296 if(Team == -1) // leave
300 tm = GetTeam(o.team, false);
311 tm = GetTeam(Team, true);
316 else if(Team != o.team)
318 tm = GetTeam(o.team, false);
321 tm = GetTeam(Team, true);
329 void Playerchecker_Think()
333 for(i = 0; i < maxclients; ++i)
336 if(GetPlayerName(i) == "")
340 // player disconnected
353 playerslots[i] = e = spawn();
356 e.ping_packetloss = 0;
357 e.ping_movementloss = 0;
358 //e.gotscores = 0; // we might already have the scores...
359 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
361 HUD_UpdatePlayerPos(e);
365 self.nextthink = time + 0.2;
372 localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
374 entity playerchecker;
375 playerchecker = spawn();
376 playerchecker.think = Playerchecker_Think;
377 playerchecker.nextthink = time + 0.2;
385 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
386 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
388 void Cmd_HUD_SetFields(float);
389 void Cmd_HUD_Help(float);
390 float CSQC_ConsoleCommand(string strMessage)
394 argc = tokenize_console(strMessage);
400 if(strCmd == "hud_configure") { // config hud
401 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
403 } else if(strCmd == "hud_save") { // save hud config
404 if(argv(1) == "" || argv(2)) {
405 print(_("Usage:\n"));
406 print(_("hud_save configname (saves to hud_skinname_configname.cfg)\n"));
409 HUD_Panel_ExportCfg(argv(1));
411 } else if(strCmd == "+showscores") {
412 scoreboard_showscores = true;
414 } else if(strCmd == "-showscores") {
415 scoreboard_showscores = false;
417 } else if(strCmd == "+showaccuracy") {
418 scoreboard_showaccuracy = true;
420 } else if(strCmd == "-showaccuracy") {
421 scoreboard_showaccuracy = false;
426 if(strCmd == "+forward" || strCmd == "-back") {
427 ++camera_direction_x;
429 } else if(strCmd == "-forward" || strCmd == "+back") {
430 --camera_direction_x;
432 } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
433 --camera_direction_y;
435 } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
436 ++camera_direction_y;
438 } else if(strCmd == "+moveup" || strCmd == "-movedown") {
439 ++camera_direction_z;
441 } else if(strCmd == "-moveup" || strCmd == "+movedown") {
442 --camera_direction_z;
444 } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
447 } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
456 entity debug_shotorg;
459 self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
460 self.angles = view_angles;
461 self.angles_x = -self.angles_x;
463 self.drawmask = MASK_NORMAL;
467 void ShotOrg_Draw2D()
469 vector coord2d_topleft, coord2d_topright, coord2d;
473 s = vtos(self.view_ofs);
474 s = substring(s, 1, strlen(s) - 2);
475 if(tokenize_console(s) == 3)
476 s = strcat(argv(0), " ", argv(1), " ", argv(2));
478 coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
479 coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
481 fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
483 coord2d = coord2d_topleft;
486 coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
491 drawstring(coord2d, s, fs, '1 1 1', 1, 0);
496 debug_shotorg = spawn();
497 debug_shotorg.draw = ShotOrg_Draw;
498 debug_shotorg.draw2d = ShotOrg_Draw2D;
499 debug_shotorg.renderflags = RF_VIEWMODEL;
500 debug_shotorg.effects = EF_FULLBRIGHT;
501 precache_model("models/shotorg_adjuster.md3");
502 setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
503 debug_shotorg.scale = 2;
504 debug_shotorg.view_ofs = '25 8 -8';
507 void DrawDebugModel()
509 if(time - floor(time) > 0.5)
516 self.renderflags = 0;
517 self.drawmask = MASK_NORMAL;
521 void GameCommand(string msg)
526 argc = tokenize_console(msg);
528 if(argv(0) == "help" || argc == 0)
530 print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
531 print(_(" scoreboard_columns_set ...\n"));
532 print(_(" scoreboard_columns_help\n"));
533 GameCommand_Generic("help");
537 if(GameCommand_Generic(msg))
542 if(cmd == "mv_download") {
543 Cmd_MapVote_MapDownload(argc);
545 else if(cmd == "hud_panel_radar_maximized")
548 hud_panel_radar_maximized = !hud_panel_radar_maximized;
550 hud_panel_radar_maximized = (stof(argv(1)) != 0);
552 else if(cmd == "scoreboard_columns_set") {
553 Cmd_HUD_SetFields(argc);
555 else if(cmd == "scoreboard_columns_help") {
559 else if(cmd == "blurtest") {
560 blurtest_time0 = time;
561 blurtest_time1 = time + stof(argv(1));
562 blurtest_radius = stof(argv(2));
563 blurtest_power = stof(argv(3));
566 else if(cmd == "shotorg_move") {
570 debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
571 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
573 else if(cmd == "shotorg_movez") {
577 debug_shotorg.view_ofs = debug_shotorg.view_ofs + stof(argv(1)) * (debug_shotorg.view_ofs * (1 / debug_shotorg.view_ofs_x)); // closer/farther, same xy pos
578 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
580 else if(cmd == "shotorg_set") {
584 debug_shotorg.view_ofs = stov(argv(1));
585 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
587 else if(cmd == "shotorg_setz") {
591 debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
592 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
594 else if(cmd == "shotorg_toggle_hide") {
597 debug_shotorg.cnt = !debug_shotorg.cnt;
600 else if(cmd == "shotorg_end") {
603 print(vtos(debug_shotorg.view_ofs), "\n");
604 remove(debug_shotorg);
605 debug_shotorg = world;
607 localcmd("sv_cmd debug_shotorg\n");
609 else if(cmd == "sendcvar") {
610 // W_FixWeaponOrder will trash argv, so save what we need.
612 thiscvar = strzone(argv(1));
613 s = cvar_string(thiscvar);
614 if(thiscvar == "cl_weaponpriority")
615 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
616 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
617 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
618 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
621 else if(cmd == "spawn") {
626 setorigin(e, view_origin);
627 e.angles = view_angles;
628 e.draw = DrawDebugModel;
629 e.classname = "debugmodel";
631 else if(cmd == "vyes")
635 vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
637 localcmd("setreport cl_allow_uid2name 1\n");
643 localcmd("cmd vote yes\n");
646 else if(cmd == "vno")
652 localcmd("setreport cl_allow_uid2name 0\n");
658 localcmd("cmd vote no\n");
664 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
670 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
671 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
672 // All keys are in ascii.
673 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
674 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
675 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
676 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
681 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
684 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
688 if(menu_action(bInputType, nPrimary, nSecondary))
694 // END REQUIRED CSQC FUNCTIONS
695 // --------------------------------------------------------------------------
697 // --------------------------------------------------------------------------
698 // BEGIN OPTIONAL CSQC FUNCTIONS
699 void Ent_RemoveEntCS()
701 entcs_receiver[self.sv_entnum] = world;
706 InterpolateOrigin_Undo();
708 self.classname = "entcs_receiver";
712 self.sv_entnum = ReadByte();
715 self.origin_x = ReadShort();
716 self.origin_y = ReadShort();
717 self.origin_z = ReadShort();
721 self.angles_y = ReadByte() * 360.0 / 256;
722 self.angles_x = self.angles_z = 0;
725 self.healthvalue = ReadByte() * 10;
727 self.armorvalue = ReadByte() * 10;
729 entcs_receiver[self.sv_entnum] = self;
730 self.entremove = Ent_RemoveEntCS;
732 InterpolateOrigin_Note();
737 void Ent_RemovePlayerScore()
743 SetTeam(self.owner, -1);
744 self.owner.gotscores = 0;
745 for(i = 0; i < MAX_SCORE; ++i)
746 self.owner.(scores[i]) = 0; // clear all scores
750 void Ent_ReadPlayerScore()
756 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
757 // (no I've never heard of M-x replace-string, sed, or anything like that)
758 isNew = !self.owner; // workaround for DP bug
761 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
762 if(!isNew && n != self.sv_entnum)
764 //print(_("A CSQC entity changed its owner!\n"));
765 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
768 self.enttype = ENT_CLIENT_SCORES;
774 if not(playerslots[self.sv_entnum])
775 playerslots[self.sv_entnum] = spawn();
776 o = self.owner = playerslots[self.sv_entnum];
777 o.sv_entnum = self.sv_entnum;
780 //if not(o.sort_prev)
781 // RegisterPlayer(o);
782 //playerchecker will do this for us later, if it has not already done so
793 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
797 o.(scores[i]) = ReadInt24_t();
799 o.(scores[i]) = ReadChar();
803 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
805 self.entremove = Ent_RemovePlayerScore;
808 void Ent_ReadTeamScore()
813 self.team = ReadByte();
814 o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
817 #if MAX_TEAMSCORE <= 8
825 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
829 o.(teamscores[i]) = ReadInt24_t();
831 o.(teamscores[i]) = ReadChar();
834 HUD_UpdateTeamPos(o);
837 void Ent_ClientData()
840 float newspectatee_status;
844 scoreboard_showscores_force = (f & 1);
848 newspectatee_status = ReadByte();
849 if(newspectatee_status == player_localnum + 1)
850 newspectatee_status = -1; // observing
853 newspectatee_status = 0;
855 spectatorbutton_zoom = (f & 4);
859 angles_held_status = 1;
860 angles_held_x = ReadAngle();
861 angles_held_y = ReadAngle();
865 angles_held_status = 0;
867 if(newspectatee_status != spectatee_status)
871 race_checkpointtime = 0;
873 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
875 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
876 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
879 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
882 spectatee_status = newspectatee_status;
884 // non-COMPAT_XON050_ENGINE: we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
889 float nags, i, j, b, f;
891 nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
896 strunzone(vote_called_vote);
897 vote_called_vote = string_null;
907 vote_yescount = ReadByte();
908 vote_nocount = ReadByte();
909 vote_needed = ReadByte();
910 vote_highlighted = ReadChar();
916 strunzone(vote_called_vote);
917 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
922 for(j = 0; j < maxclients; ++j)
924 playerslots[j].ready = 1;
925 for(i = 1; i <= maxclients; i += 8)
928 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
931 playerslots[j].ready = 0;
935 ready_waiting = (nags & 1);
936 ready_waiting_for_me = (nags & 2);
937 vote_waiting = (nags & 4);
938 vote_waiting_for_me = (nags & 8);
939 warmup_stage = (nags & 16);
942 void Ent_RandomSeed()
950 void Ent_ReadAccuracy(void)
956 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
957 weapon_accuracy[w] = -1;
961 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
967 weapon_accuracy[w] = -1;
969 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
971 weapon_accuracy[w] = (b - 1.0) / 100.0;
976 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
977 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
978 void Ent_RadarLink();
980 void Ent_ScoresInfo();
981 void CSQC_Ent_Update(float bIsNewEntity)
987 // set up the "time" global for received entities to be correct for interpolation purposes
995 serverprevtime = time;
996 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
997 time = serverprevtime + serverdeltatime;
1000 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
1003 if(t != self.enttype || bIsNewEntity)
1005 //print(_("A CSQC entity changed its type!\n"));
1006 print(sprintf(_("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n"), num_for_edict(self), self.entnum, self.enttype, t));
1015 print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
1023 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
1024 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
1025 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
1026 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
1027 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
1028 case ENT_CLIENT_LASER: Ent_Laser(); break;
1029 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
1030 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
1031 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
1032 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
1033 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
1034 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
1035 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
1036 case ENT_CLIENT_INIT: Ent_Init(); break;
1037 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
1038 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
1039 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
1040 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
1041 case ENT_CLIENT_WALL: Ent_Wall(); break;
1042 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
1043 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
1044 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
1045 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
1046 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
1047 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
1048 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
1049 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
1050 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
1051 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
1052 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
1053 case ENT_CLIENT_TURRET: ent_turret(); break;
1054 case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
1056 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1057 error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1063 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1064 // used when an entity changes its type. For an entity that someone interacts
1065 // with others, make sure it can no longer do so.
1072 self.classname = "";
1073 self.draw = menu_sub_null;
1074 self.entremove = menu_sub_null;
1075 // TODO possibly set more stuff to defaults
1077 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
1078 void CSQC_Ent_Remove()
1085 void Gamemode_Init()
1089 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
1090 calledhooks |= HOOK_START;
1093 // 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.
1094 void CSQC_Parse_StuffCmd(string strMessage)
1096 localcmd(strMessage);
1098 // 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.
1099 void CSQC_Parse_Print(string strMessage)
1101 print(ColorTranslateRGB(strMessage));
1104 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1105 void CSQC_Parse_CenterPrint(string strMessage)
1107 centerprint_hud(strMessage);
1110 string notranslate_fogcmd1 = "\nfog ";
1111 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1114 // TODO somehow thwart prvm_globalset client ...
1117 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1120 void Gamemode_Init();
1121 void Ent_ScoresInfo()
1124 self.classname = "ent_client_scores_info";
1125 gametype = ReadInt24_t();
1126 for(i = 0; i < MAX_SCORE; ++i)
1128 scores_label[i] = strzone(ReadString());
1129 scores_flags[i] = ReadByte();
1131 for(i = 0; i < MAX_TEAMSCORE; ++i)
1133 teamscores_label[i] = strzone(ReadString());
1134 teamscores_flags[i] = ReadByte();
1142 self.classname = "ent_client_init";
1144 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1146 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1147 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1148 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1149 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1150 electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1151 electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1152 electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1153 electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1154 gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1155 gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1156 gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1157 gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1160 strunzone(forcefog);
1161 forcefog = strzone(ReadString());
1163 armorblockpercent = ReadByte() / 255.0;
1165 g_weaponswitchdelay = ReadByte() / 255.0;
1167 g_balance_grenadelauncher_bouncefactor = ReadCoord();
1168 g_balance_grenadelauncher_bouncestop = ReadCoord();
1169 g_balance_electro_secondary_bouncefactor = ReadCoord();
1170 g_balance_electro_secondary_bouncestop = ReadCoord();
1172 nex_scope = !ReadByte();
1173 rifle_scope = !ReadByte();
1175 serverflags = ReadByte();
1177 minelayer_maxmines = ReadByte();
1179 hagar_maxrockets = ReadByte();
1181 g_trueaim_minrange = ReadCoord();
1195 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1196 race_checkpoint = ReadByte();
1197 race_time = ReadInt24_t();
1198 race_previousbesttime = ReadInt24_t();
1199 if(race_previousbestname)
1200 strunzone(race_previousbestname);
1201 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1203 race_checkpointtime = time;
1205 if(race_checkpoint == 0 || race_checkpoint == 254)
1207 race_penaltyaccumulator = 0;
1208 race_laptime = time; // valid
1213 case RACE_NET_CHECKPOINT_CLEAR:
1215 race_checkpointtime = 0;
1218 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1219 race_laptime = ReadCoord();
1220 race_checkpointtime = -99999;
1222 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1223 race_nextcheckpoint = ReadByte();
1225 race_nextbesttime = ReadInt24_t();
1226 if(race_nextbestname)
1227 strunzone(race_nextbestname);
1228 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1231 case RACE_NET_CHECKPOINT_HIT_RACE:
1232 race_mycheckpoint = ReadByte();
1233 race_mycheckpointtime = time;
1234 race_mycheckpointdelta = ReadInt24_t();
1235 race_mycheckpointlapsdelta = ReadByte();
1236 if(race_mycheckpointlapsdelta >= 128)
1237 race_mycheckpointlapsdelta -= 256;
1238 if(race_mycheckpointenemy)
1239 strunzone(race_mycheckpointenemy);
1240 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1243 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1244 race_othercheckpoint = ReadByte();
1245 race_othercheckpointtime = time;
1246 race_othercheckpointdelta = ReadInt24_t();
1247 race_othercheckpointlapsdelta = ReadByte();
1248 if(race_othercheckpointlapsdelta >= 128)
1249 race_othercheckpointlapsdelta -= 256;
1250 if(race_othercheckpointenemy)
1251 strunzone(race_othercheckpointenemy);
1252 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1255 case RACE_NET_PENALTY_RACE:
1256 race_penaltyeventtime = time;
1257 race_penaltytime = ReadShort();
1258 //race_penaltyaccumulator += race_penaltytime;
1259 if(race_penaltyreason)
1260 strunzone(race_penaltyreason);
1261 race_penaltyreason = strzone(ReadString());
1264 case RACE_NET_PENALTY_QUALIFYING:
1265 race_penaltyeventtime = time;
1266 race_penaltytime = ReadShort();
1267 race_penaltyaccumulator += race_penaltytime;
1268 if(race_penaltyreason)
1269 strunzone(race_penaltyreason);
1270 race_penaltyreason = strzone(ReadString());
1273 case RACE_NET_SERVER_RECORD:
1274 race_server_record = ReadInt24_t();
1276 case RACE_NET_SPEED_AWARD:
1277 race_speedaward = ReadInt24_t();
1278 if(race_speedaward_holder)
1279 strunzone(race_speedaward_holder);
1280 race_speedaward_holder = strzone(ReadString());
1282 case RACE_NET_SPEED_AWARD_BEST:
1283 race_speedaward_alltimebest = ReadInt24_t();
1284 if(race_speedaward_alltimebest_holder)
1285 strunzone(race_speedaward_alltimebest_holder);
1286 race_speedaward_alltimebest_holder = strzone(ReadString());
1288 case RACE_NET_SERVER_RANKINGS:
1289 float pos, prevpos, del;
1291 prevpos = ReadShort();
1294 // move other rankings out of the way
1297 for (i=prevpos-1;i>pos-1;--i) {
1298 grecordtime[i] = grecordtime[i-1];
1299 if(grecordholder[i])
1300 strunzone(grecordholder[i]);
1301 grecordholder[i] = strzone(grecordholder[i-1]);
1303 } else if (del) { // a record has been deleted by the admin
1304 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1305 if (i == RANKINGS_CNT-1) { // clear out last record
1307 if (grecordholder[i])
1308 strunzone(grecordholder[i]);
1309 grecordholder[i] = string_null;
1312 grecordtime[i] = grecordtime[i+1];
1313 if (grecordholder[i])
1314 strunzone(grecordholder[i]);
1315 grecordholder[i] = strzone(grecordholder[i+1]);
1318 } else { // player has no ranked record yet
1319 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1320 grecordtime[i] = grecordtime[i-1];
1321 if(grecordholder[i])
1322 strunzone(grecordholder[i]);
1323 grecordholder[i] = strzone(grecordholder[i-1]);
1327 // store new ranking
1328 if(grecordholder[pos-1] != "")
1329 strunzone(grecordholder[pos-1]);
1330 grecordholder[pos-1] = strzone(ReadString());
1331 grecordtime[pos-1] = ReadInt24_t();
1332 if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1335 case RACE_NET_SERVER_STATUS:
1336 race_status = ReadShort();
1337 if(race_status_name)
1338 strunzone(race_status_name);
1339 race_status_name = strzone(ReadString());
1343 void Net_ReadSpawn()
1346 current_viewzoom = 0.6;
1349 void Net_TeamNagger()
1354 void Net_ReadPingPLReport()
1356 float e, pi, pl, ml;
1361 if not(playerslots[e])
1363 playerslots[e].ping = pi;
1364 playerslots[e].ping_packetloss = pl / 255.0;
1365 playerslots[e].ping_movementloss = ml / 255.0;
1368 void Net_WeaponComplain() {
1369 complain_weapon = ReadByte();
1371 if(complain_weapon_name)
1372 strunzone(complain_weapon_name);
1373 complain_weapon_name = strzone(ReadString());
1375 complain_weapon_type = ReadByte();
1377 complain_weapon_time = time;
1378 weapontime = time; // ping the weapon panel
1381 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1382 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1383 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1384 float CSQC_Parse_TempEntity()
1392 // NOTE: Could just do return instead of break...
1395 case TE_CSQC_TARGET_MUSIC:
1399 case TE_CSQC_PICTURE:
1400 Net_MapVote_Picture();
1411 case TE_CSQC_ZCURVEPARTICLES:
1412 Net_ReadZCurveParticles();
1415 case TE_CSQC_NEXGUNBEAMPARTICLE:
1416 Net_ReadNexgunBeamParticle();
1419 case TE_CSQC_TEAMNAGGER:
1423 case TE_CSQC_LIGHTNINGARC:
1424 Net_ReadLightningarc();
1427 case TE_CSQC_PINGPLREPORT:
1428 Net_ReadPingPLReport();
1431 case TE_CSQC_ANNOUNCE:
1432 Announcer_Play(ReadString());
1435 case TE_CSQC_KILLNOTIFY:
1436 HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1439 case TE_CSQC_KILLCENTERPRINT:
1440 HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1443 case TE_CSQC_CENTERPRINT_GENERIC:
1448 if (id != 0 && s != "")
1449 centerprint_generic(id, s, ReadByte(), ReadByte());
1451 centerprint_generic(id, s, 0, 0);
1454 case TE_CSQC_WEAPONCOMPLAIN:
1455 Net_WeaponComplain();
1458 case TE_CSQC_VEHICLESETUP:
1463 // No special logic for this temporary entity; return 0 so the engine can handle it
1471 string getcommandkey(string text, string command)
1476 if (!autocvar_hud_showbinds)
1479 keys = db_get(binddb, command);
1482 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1483 for(j = 0; j < n; ++j)
1489 keys = keynumtostring(k);
1491 keys = strcat(keys, ", ", keynumtostring(k));
1494 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1498 db_put(binddb, command, keys);
1502 if (autocvar_hud_showbinds > 1)
1503 return sprintf(_("%s (not bound)"), text);
1507 else if (autocvar_hud_showbinds > 1)
1508 return sprintf(_("%s (%s)"), text, keys);