1 // --------------------------------------------------------------------------
2 // BEGIN REQUIRED CSQC FUNCTIONS
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
7 void cvar_clientsettemp(string cv, string val)
10 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
14 e.classname = "saved_cvar_value";
15 e.netname = strzone(cv);
16 e.message = strzone(cvar_string(cv));
21 void cvar_clientsettemp_restore()
24 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
25 cvar_set(e.netname, e.message);
28 void menu_show_error()
30 drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
33 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
34 // Useful for precaching things
44 void precache_playermodel(string m)
46 float globhandle, i, n;
49 if(substring(m, -9,5) == "_lod1")
51 if(substring(m, -9,5) == "_lod2")
54 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
57 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
62 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
65 n = search_getsize(globhandle);
66 for (i = 0; i < n; ++i)
68 //print(search_getfilename(globhandle, i), "\n");
69 f = search_getfilename(globhandle, i);
70 PrecachePlayerSounds(f);
72 search_end(globhandle);
75 void precache_all_playermodels(string pattern)
77 float globhandle, i, n;
80 globhandle = search_begin(pattern, TRUE, FALSE);
83 n = search_getsize(globhandle);
84 for (i = 0; i < n; ++i)
86 //print(search_getfilename(globhandle, i), "\n");
87 f = search_getfilename(globhandle, i);
88 precache_playermodel(f);
90 search_end(globhandle);
94 void WaypointSprite_Load();
97 prvm_language = cvar_string("prvm_language");
101 __engine_check = checkextension("DP_SV_WRITEPICTURE");
104 print(_("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n"));
105 localcmd("\ndisconnect\n");
111 check_unacceptable_compiler_bugs();
114 print(sprintf(_("^4CSQC Build information: ^1%s\n"), WATERMARK()));
119 binddb = db_create();
120 tempdb = db_create();
121 ClientProgsDB = db_load("client.db");
122 compressShortVector_init();
124 drawfont = FONT_USER+1;
125 menu_visible = FALSE;
126 menu_show = menu_show_error;
127 menu_action = menu_sub_null;
129 for(i = 0; i < 255; ++i)
130 if(getplayerkeyvalue(i, "viewentity") == "")
134 registercommand("hud_configure");
135 registercommand("hud_save");
136 //registercommand("menu_action");
138 registercommand("+showscores");registercommand("-showscores");
139 registercommand("+showaccuracy");registercommand("-showaccuracy");
145 registercommand("+forward");registercommand("-forward");
146 registercommand("+back");registercommand("-back");
147 registercommand("+moveup");registercommand("-moveup");
148 registercommand("+movedown");registercommand("-movedown");
149 registercommand("+moveright");registercommand("-moveright");
150 registercommand("+moveleft");registercommand("-moveleft");
151 registercommand("+roll_right");registercommand("-roll_right");
152 registercommand("+roll_left");registercommand("-roll_left");
156 registercvar("hud_usecsqc", "1");
157 registercvar("scoreboard_columns", "default");
161 // hud_fields uses strunzone on the titles!
162 for(i = 0; i < MAX_HUD_FIELDS; ++i)
163 hud_title[i] = strzone("(null)");
169 teams = Sort_Spawn();
170 players = Sort_Spawn();
172 GetTeam(COLOR_SPECTATOR, true); // add specs first
176 WaypointSprite_Load();
179 precache_model("null");
180 precache_sound("misc/hit.wav");
181 precache_sound("misc/typehit.wav");
182 if (autocvar_cl_precacheplayermodels)
184 precache_all_playermodels("models/player/*.zym");
185 precache_all_playermodels("models/player/*.dpm");
186 precache_all_playermodels("models/player/*.md3");
187 precache_all_playermodels("models/player/*.psk");
188 precache_all_playermodels("models/player/*.iqm");
191 Projectile_Precache();
193 GibSplash_Precache();
195 DamageInfo_Precache();
198 Announcer_Precache();
201 if(autocvar_cl_reticle)
203 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
204 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
207 get_mi_min_max_texcoords(1); // try the CLEVER way first
208 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
209 shortmapname = mi_shortname;
211 if(precache_pic(minimapname) == "")
213 // but maybe we have a non-clever minimap
214 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
215 if(precache_pic(minimapname) == "")
216 minimapname = ""; // FAIL
218 get_mi_min_max_texcoords(0); // load new texcoords
221 mi_center = (mi_min + mi_max) * 0.5;
222 mi_scale = mi_max - mi_min;
223 minimapname = strzone(minimapname);
227 hud_configure_prev = -1;
231 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
232 void CSQC_Shutdown(void)
247 if(autocvar_cl_db_saveasdump)
248 db_dump(ClientProgsDB, "client.db");
250 db_save(ClientProgsDB, "client.db");
251 db_close(ClientProgsDB);
253 cvar_clientsettemp_restore();
256 cvar_set("chase_active",ftos(chase_active_backup));
258 // unset the event chasecam's chase_active
259 if(autocvar_chase_active < 0)
260 cvar_set("chase_active", "0");
264 if not(calledhooks & HOOK_START)
265 localcmd("\n_cl_hook_gamestart nop\n");
266 if not(calledhooks & HOOK_END)
267 localcmd("\ncl_hook_gameend\n");
272 float SetTeam(entity o, float Team)
286 if(GetTeam(Team, false) == world)
288 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
289 Team = COLOR_SPECTATOR;
302 if(GetTeam(Team, false) == world)
304 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
305 Team = COLOR_SPECTATOR;
310 if(Team == -1) // leave
314 tm = GetTeam(o.team, false);
325 tm = GetTeam(Team, true);
330 else if(Team != o.team)
332 tm = GetTeam(o.team, false);
335 tm = GetTeam(Team, true);
343 void Playerchecker_Think()
347 for(i = 0; i < maxclients; ++i)
350 if(GetPlayerName(i) == "")
354 // player disconnected
367 playerslots[i] = e = spawn();
370 e.ping_packetloss = 0;
371 e.ping_movementloss = 0;
372 //e.gotscores = 0; // we might already have the scores...
373 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
375 HUD_UpdatePlayerPos(e);
379 self.nextthink = time + 0.2;
386 localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
388 entity playerchecker;
389 playerchecker = spawn();
390 playerchecker.think = Playerchecker_Think;
391 playerchecker.nextthink = time + 0.2;
399 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
400 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
402 void Cmd_HUD_SetFields(float);
403 void Cmd_HUD_Help(float);
404 float CSQC_ConsoleCommand(string strMessage)
408 argc = tokenize_console(strMessage);
414 if(strCmd == "hud_configure") { // config hud
415 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
417 } else if(strCmd == "hud_save") { // save hud config
418 if(argv(1) == "" || argv(2)) {
419 print(_("Usage:\n"));
420 print(_("hud_save configname (saves to hud_skinname_configname.cfg)\n"));
423 HUD_Panel_ExportCfg(argv(1));
425 } else if(strCmd == "+showscores") {
426 scoreboard_showscores = true;
428 } else if(strCmd == "-showscores") {
429 scoreboard_showscores = false;
431 } else if(strCmd == "+showaccuracy") {
432 scoreboard_showaccuracy = true;
434 } else if(strCmd == "-showaccuracy") {
435 scoreboard_showaccuracy = false;
440 if(strCmd == "+forward" || strCmd == "-back") {
441 ++camera_direction_x;
443 } else if(strCmd == "-forward" || strCmd == "+back") {
444 --camera_direction_x;
446 } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
447 --camera_direction_y;
449 } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
450 ++camera_direction_y;
452 } else if(strCmd == "+moveup" || strCmd == "-movedown") {
453 ++camera_direction_z;
455 } else if(strCmd == "-moveup" || strCmd == "+movedown") {
456 --camera_direction_z;
458 } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
461 } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
470 entity debug_shotorg;
473 self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
474 self.angles = view_angles;
475 self.angles_x = -self.angles_x;
477 self.drawmask = MASK_NORMAL;
481 void ShotOrg_Draw2D()
483 vector coord2d_topleft, coord2d_topright, coord2d;
487 s = vtos(self.view_ofs);
488 s = substring(s, 1, strlen(s) - 2);
489 if(tokenize_console(s) == 3)
490 s = strcat(argv(0), " ", argv(1), " ", argv(2));
492 coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
493 coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
495 fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
497 coord2d = coord2d_topleft;
500 coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
505 drawstring(coord2d, s, fs, '1 1 1', 1, 0);
510 debug_shotorg = spawn();
511 debug_shotorg.draw = ShotOrg_Draw;
512 debug_shotorg.draw2d = ShotOrg_Draw2D;
513 debug_shotorg.renderflags = RF_VIEWMODEL;
514 debug_shotorg.effects = EF_FULLBRIGHT;
515 precache_model("models/shotorg_adjuster.md3");
516 setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
517 debug_shotorg.scale = 2;
518 debug_shotorg.view_ofs = '25 8 -8';
521 void DrawDebugModel()
523 if(time - floor(time) > 0.5)
530 self.renderflags = 0;
531 self.drawmask = MASK_NORMAL;
535 void GameCommand(string msg)
540 argc = tokenize_console(msg);
542 if(argv(0) == "help" || argc == 0)
544 print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
545 print(_(" settemp cvar value\n"));
546 print(_(" scoreboard_columns_set ...\n"));
547 print(_(" scoreboard_columns_help\n"));
548 GameCommand_Generic("help");
552 if(GameCommand_Generic(msg))
557 if(cmd == "mv_download") {
558 Cmd_MapVote_MapDownload(argc);
560 else if(cmd == "hud_panel_radar_maximized")
563 hud_panel_radar_maximized = !hud_panel_radar_maximized;
565 hud_panel_radar_maximized = (stof(argv(1)) != 0);
567 else if(cmd == "settemp") {
568 cvar_clientsettemp(argv(1), argv(2));
570 else if(cmd == "scoreboard_columns_set") {
571 Cmd_HUD_SetFields(argc);
573 else if(cmd == "scoreboard_columns_help") {
577 else if(cmd == "blurtest") {
578 blurtest_time0 = time;
579 blurtest_time1 = time + stof(argv(1));
580 blurtest_radius = stof(argv(2));
581 blurtest_power = stof(argv(3));
584 else if(cmd == "shotorg_move") {
588 debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
589 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
591 else if(cmd == "shotorg_movez") {
595 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
596 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
598 else if(cmd == "shotorg_set") {
602 debug_shotorg.view_ofs = stov(argv(1));
603 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
605 else if(cmd == "shotorg_setz") {
609 debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
610 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
612 else if(cmd == "shotorg_toggle_hide") {
615 debug_shotorg.cnt = !debug_shotorg.cnt;
618 else if(cmd == "shotorg_end") {
621 print(vtos(debug_shotorg.view_ofs), "\n");
622 remove(debug_shotorg);
623 debug_shotorg = world;
625 localcmd("sv_cmd debug_shotorg\n");
627 else if(cmd == "sendcvar") {
628 // W_FixWeaponOrder will trash argv, so save what we need.
630 thiscvar = strzone(argv(1));
631 s = cvar_string(thiscvar);
632 if(thiscvar == "cl_weaponpriority")
633 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
634 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
635 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
636 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
639 else if(cmd == "spawn") {
644 setorigin(e, view_origin);
645 e.angles = view_angles;
646 e.draw = DrawDebugModel;
647 e.classname = "debugmodel";
649 else if(cmd == "vyes")
653 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)
655 localcmd("setreport cl_allow_uid2name 1\n");
661 localcmd("cmd vote yes\n");
664 else if(cmd == "vno")
670 localcmd("setreport cl_allow_uid2name 0\n");
676 localcmd("cmd vote no\n");
682 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
688 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
689 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
690 // All keys are in ascii.
691 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
692 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
693 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
694 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
699 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
702 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
706 if(menu_action(bInputType, nPrimary, nSecondary))
712 // END REQUIRED CSQC FUNCTIONS
713 // --------------------------------------------------------------------------
715 // --------------------------------------------------------------------------
716 // BEGIN OPTIONAL CSQC FUNCTIONS
717 void Ent_RemoveEntCS()
719 entcs_receiver[self.sv_entnum] = world;
724 InterpolateOrigin_Undo();
726 self.classname = "entcs_receiver";
730 self.sv_entnum = ReadByte();
733 self.origin_x = ReadShort();
734 self.origin_y = ReadShort();
735 self.origin_z = ReadShort();
739 self.angles_y = ReadByte() * 360.0 / 256;
740 self.angles_x = self.angles_z = 0;
743 self.healthvalue = ReadByte() * 10;
745 self.armorvalue = ReadByte() * 10;
747 entcs_receiver[self.sv_entnum] = self;
748 self.entremove = Ent_RemoveEntCS;
750 InterpolateOrigin_Note();
755 void Ent_RemovePlayerScore()
761 SetTeam(self.owner, -1);
762 self.owner.gotscores = 0;
763 for(i = 0; i < MAX_SCORE; ++i)
764 self.owner.(scores[i]) = 0; // clear all scores
768 void Ent_ReadPlayerScore()
774 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
775 // (no I've never heard of M-x replace-string, sed, or anything like that)
776 isNew = !self.owner; // workaround for DP bug
779 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
780 if(!isNew && n != self.sv_entnum)
782 //print(_("A CSQC entity changed its owner!\n"));
783 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
786 self.enttype = ENT_CLIENT_SCORES;
792 if not(playerslots[self.sv_entnum])
793 playerslots[self.sv_entnum] = spawn();
794 o = self.owner = playerslots[self.sv_entnum];
795 o.sv_entnum = self.sv_entnum;
798 //if not(o.sort_prev)
799 // RegisterPlayer(o);
800 //playerchecker will do this for us later, if it has not already done so
811 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
815 o.(scores[i]) = ReadInt24_t();
817 o.(scores[i]) = ReadChar();
821 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
823 self.entremove = Ent_RemovePlayerScore;
826 void Ent_ReadTeamScore()
831 self.team = ReadByte();
832 o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
835 #if MAX_TEAMSCORE <= 8
843 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
847 o.(teamscores[i]) = ReadInt24_t();
849 o.(teamscores[i]) = ReadChar();
852 HUD_UpdateTeamPos(o);
855 void Ent_ClientData()
858 float newspectatee_status;
862 scoreboard_showscores_force = (f & 1);
866 newspectatee_status = ReadByte();
867 if(newspectatee_status == player_localentnum)
868 newspectatee_status = -1; // observing
871 newspectatee_status = 0;
873 spectatorbutton_zoom = (f & 4);
877 angles_held_status = 1;
878 angles_held_x = ReadAngle();
879 angles_held_y = ReadAngle();
883 angles_held_status = 0;
885 if(newspectatee_status != spectatee_status)
889 race_checkpointtime = 0;
891 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
893 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
894 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
897 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
900 spectatee_status = newspectatee_status;
905 float nags, i, j, b, f;
907 nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
912 strunzone(vote_called_vote);
913 vote_called_vote = string_null;
923 vote_yescount = ReadByte();
924 vote_nocount = ReadByte();
925 vote_needed = ReadByte();
926 vote_highlighted = ReadChar();
932 strunzone(vote_called_vote);
933 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
938 for(j = 0; j < maxclients; ++j)
940 playerslots[j].ready = 1;
941 for(i = 1; i <= maxclients; i += 8)
944 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
947 playerslots[j].ready = 0;
951 ready_waiting = (nags & 1);
952 ready_waiting_for_me = (nags & 2);
953 vote_waiting = (nags & 4);
954 vote_waiting_for_me = (nags & 8);
955 warmup_stage = (nags & 16);
958 void Ent_RandomSeed()
966 void Ent_ReadAccuracy(void)
972 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
973 weapon_accuracy[w] = -1;
977 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
983 weapon_accuracy[w] = -1;
985 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
987 weapon_accuracy[w] = (b - 1.0) / 100.0;
992 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
993 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
994 void Ent_RadarLink();
996 void Ent_ScoresInfo();
997 void CSQC_Ent_Update(float bIsNewEntity)
1003 // set up the "time" global for received entities to be correct for interpolation purposes
1011 serverprevtime = time;
1012 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
1013 time = serverprevtime + serverdeltatime;
1016 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
1019 if(t != self.enttype || bIsNewEntity)
1021 //print(_("A CSQC entity changed its type!\n"));
1022 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));
1031 print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
1039 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
1040 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
1041 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
1042 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
1043 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
1044 case ENT_CLIENT_LASER: Ent_Laser(); break;
1045 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
1046 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
1047 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
1048 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
1049 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
1050 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
1051 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
1052 case ENT_CLIENT_INIT: Ent_Init(); break;
1053 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
1054 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
1055 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
1056 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
1057 case ENT_CLIENT_WALL: Ent_Wall(); break;
1058 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
1059 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
1060 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
1061 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
1062 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
1063 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
1064 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
1065 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
1066 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
1067 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
1068 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
1069 case ENT_CLIENT_TURRET: ent_turret(); break;
1070 case ENT_CLIENT_MODEL: CSQCModel_Read(); break;
1072 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1073 error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1079 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1080 // used when an entity changes its type. For an entity that someone interacts
1081 // with others, make sure it can no longer do so.
1088 self.classname = "";
1089 self.draw = menu_sub_null;
1090 self.entremove = menu_sub_null;
1091 // TODO possibly set more stuff to defaults
1093 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
1094 void CSQC_Ent_Remove()
1101 void Gamemode_Init()
1105 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), "\n");
1106 calledhooks |= HOOK_START;
1109 // 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.
1110 void CSQC_Parse_StuffCmd(string strMessage)
1112 localcmd(strMessage);
1114 // 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.
1115 void CSQC_Parse_Print(string strMessage)
1117 print(ColorTranslateRGB(strMessage));
1120 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1121 void CSQC_Parse_CenterPrint(string strMessage)
1123 centerprint_hud(strMessage);
1126 string notranslate_fogcmd1 = "\nfog ";
1127 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1130 // TODO somehow thwart prvm_globalset client ...
1133 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1136 void Gamemode_Init();
1137 void Ent_ScoresInfo()
1140 self.classname = "ent_client_scores_info";
1141 gametype = ReadByte();
1142 for(i = 0; i < MAX_SCORE; ++i)
1144 scores_label[i] = strzone(ReadString());
1145 scores_flags[i] = ReadByte();
1147 for(i = 0; i < MAX_TEAMSCORE; ++i)
1149 teamscores_label[i] = strzone(ReadString());
1150 teamscores_flags[i] = ReadByte();
1158 self.classname = "ent_client_init";
1160 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1162 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1163 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1164 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1165 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1166 electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1167 electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1168 electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1169 electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1170 gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1171 gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1172 gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1173 gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1176 strunzone(forcefog);
1177 forcefog = strzone(ReadString());
1179 armorblockpercent = ReadByte() / 255.0;
1181 g_weaponswitchdelay = ReadByte() / 255.0;
1183 g_balance_grenadelauncher_bouncefactor = ReadCoord();
1184 g_balance_grenadelauncher_bouncestop = ReadCoord();
1185 g_balance_electro_secondary_bouncefactor = ReadCoord();
1186 g_balance_electro_secondary_bouncestop = ReadCoord();
1188 nex_scope = !ReadByte();
1189 rifle_scope = !ReadByte();
1191 serverflags = ReadByte();
1193 minelayer_maxmines = ReadByte();
1195 hagar_maxrockets = ReadByte();
1197 g_trueaim_minrange = ReadCoord();
1211 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1212 race_checkpoint = ReadByte();
1213 race_time = ReadInt24_t();
1214 race_previousbesttime = ReadInt24_t();
1215 if(race_previousbestname)
1216 strunzone(race_previousbestname);
1217 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1219 race_checkpointtime = time;
1221 if(race_checkpoint == 0 || race_checkpoint == 254)
1223 race_penaltyaccumulator = 0;
1224 race_laptime = time; // valid
1229 case RACE_NET_CHECKPOINT_CLEAR:
1231 race_checkpointtime = 0;
1234 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1235 race_laptime = ReadCoord();
1236 race_checkpointtime = -99999;
1238 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1239 race_nextcheckpoint = ReadByte();
1241 race_nextbesttime = ReadInt24_t();
1242 if(race_nextbestname)
1243 strunzone(race_nextbestname);
1244 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1247 case RACE_NET_CHECKPOINT_HIT_RACE:
1248 race_mycheckpoint = ReadByte();
1249 race_mycheckpointtime = time;
1250 race_mycheckpointdelta = ReadInt24_t();
1251 race_mycheckpointlapsdelta = ReadByte();
1252 if(race_mycheckpointlapsdelta >= 128)
1253 race_mycheckpointlapsdelta -= 256;
1254 if(race_mycheckpointenemy)
1255 strunzone(race_mycheckpointenemy);
1256 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1259 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1260 race_othercheckpoint = ReadByte();
1261 race_othercheckpointtime = time;
1262 race_othercheckpointdelta = ReadInt24_t();
1263 race_othercheckpointlapsdelta = ReadByte();
1264 if(race_othercheckpointlapsdelta >= 128)
1265 race_othercheckpointlapsdelta -= 256;
1266 if(race_othercheckpointenemy)
1267 strunzone(race_othercheckpointenemy);
1268 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1271 case RACE_NET_PENALTY_RACE:
1272 race_penaltyeventtime = time;
1273 race_penaltytime = ReadShort();
1274 //race_penaltyaccumulator += race_penaltytime;
1275 if(race_penaltyreason)
1276 strunzone(race_penaltyreason);
1277 race_penaltyreason = strzone(ReadString());
1280 case RACE_NET_PENALTY_QUALIFYING:
1281 race_penaltyeventtime = time;
1282 race_penaltytime = ReadShort();
1283 race_penaltyaccumulator += race_penaltytime;
1284 if(race_penaltyreason)
1285 strunzone(race_penaltyreason);
1286 race_penaltyreason = strzone(ReadString());
1289 case RACE_NET_SERVER_RECORD:
1290 race_server_record = ReadInt24_t();
1292 case RACE_NET_SPEED_AWARD:
1293 race_speedaward = ReadInt24_t();
1294 if(race_speedaward_holder)
1295 strunzone(race_speedaward_holder);
1296 race_speedaward_holder = strzone(ReadString());
1298 case RACE_NET_SPEED_AWARD_BEST:
1299 race_speedaward_alltimebest = ReadInt24_t();
1300 if(race_speedaward_alltimebest_holder)
1301 strunzone(race_speedaward_alltimebest_holder);
1302 race_speedaward_alltimebest_holder = strzone(ReadString());
1304 case RACE_NET_SERVER_RANKINGS:
1305 float pos, prevpos, del;
1307 prevpos = ReadShort();
1310 // move other rankings out of the way
1313 for (i=prevpos-1;i>pos-1;--i) {
1314 grecordtime[i] = grecordtime[i-1];
1315 if(grecordholder[i])
1316 strunzone(grecordholder[i]);
1317 grecordholder[i] = strzone(grecordholder[i-1]);
1319 } else if (del) { // a record has been deleted by the admin
1320 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1321 if (i == RANKINGS_CNT-1) { // clear out last record
1323 if (grecordholder[i])
1324 strunzone(grecordholder[i]);
1325 grecordholder[i] = string_null;
1328 grecordtime[i] = grecordtime[i+1];
1329 if (grecordholder[i])
1330 strunzone(grecordholder[i]);
1331 grecordholder[i] = strzone(grecordholder[i+1]);
1334 } else { // player has no ranked record yet
1335 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1336 grecordtime[i] = grecordtime[i-1];
1337 if(grecordholder[i])
1338 strunzone(grecordholder[i]);
1339 grecordholder[i] = strzone(grecordholder[i-1]);
1343 // store new ranking
1344 if(grecordholder[pos-1] != "")
1345 strunzone(grecordholder[pos-1]);
1346 grecordholder[pos-1] = strzone(ReadString());
1347 grecordtime[pos-1] = ReadInt24_t();
1348 if(grecordholder[pos-1] == GetPlayerName(player_localentnum -1))
1351 case RACE_NET_SERVER_STATUS:
1352 race_status = ReadShort();
1353 if(race_status_name)
1354 strunzone(race_status_name);
1355 race_status_name = strzone(ReadString());
1359 void Net_ReadSpawn()
1362 current_viewzoom = 0.6;
1365 void Net_TeamNagger()
1370 void Net_ReadPingPLReport()
1372 float e, pi, pl, ml;
1377 if not(playerslots[e])
1379 playerslots[e].ping = pi;
1380 playerslots[e].ping_packetloss = pl / 255.0;
1381 playerslots[e].ping_movementloss = ml / 255.0;
1384 void Net_WeaponComplain() {
1385 complain_weapon = ReadByte();
1387 if(complain_weapon_name)
1388 strunzone(complain_weapon_name);
1389 complain_weapon_name = strzone(ReadString());
1391 complain_weapon_type = ReadByte();
1393 complain_weapon_time = time;
1394 weapontime = time; // ping the weapon panel
1397 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1398 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1399 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1400 float CSQC_Parse_TempEntity()
1408 // NOTE: Could just do return instead of break...
1411 case TE_CSQC_TARGET_MUSIC:
1415 case TE_CSQC_PICTURE:
1416 Net_MapVote_Picture();
1427 case TE_CSQC_ZCURVEPARTICLES:
1428 Net_ReadZCurveParticles();
1431 case TE_CSQC_NEXGUNBEAMPARTICLE:
1432 Net_ReadNexgunBeamParticle();
1435 case TE_CSQC_TEAMNAGGER:
1439 case TE_CSQC_LIGHTNINGARC:
1440 Net_ReadLightningarc();
1443 case TE_CSQC_PINGPLREPORT:
1444 Net_ReadPingPLReport();
1447 case TE_CSQC_ANNOUNCE:
1448 Announcer_Play(ReadString());
1451 case TE_CSQC_KILLNOTIFY:
1452 HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1455 case TE_CSQC_KILLCENTERPRINT:
1456 HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1459 case TE_CSQC_CENTERPRINT_GENERIC:
1464 if (id != 0 && s != "")
1465 centerprint_generic(id, s, ReadByte(), ReadByte());
1467 centerprint_generic(id, s, 0, 0);
1470 case TE_CSQC_WEAPONCOMPLAIN:
1471 Net_WeaponComplain();
1474 case TE_CSQC_VEHICLESETUP:
1479 // No special logic for this temporary entity; return 0 so the engine can handle it
1487 string getcommandkey(string text, string command)
1492 if (!autocvar_hud_showbinds)
1495 keys = db_get(binddb, command);
1498 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1499 for(j = 0; j < n; ++j)
1505 keys = keynumtostring(k);
1507 keys = strcat(keys, ", ", keynumtostring(k));
1510 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1514 db_put(binddb, command, keys);
1518 if (autocvar_hud_showbinds > 1)
1519 return sprintf(_("%s (not bound)"), text);
1523 else if (autocvar_hud_showbinds > 1)
1524 return sprintf(_("%s (%s)"), text, keys);