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)
48 if(substring(m, -9,5) == "_lod1")
50 if(substring(m, -9,5) == "_lod2")
53 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
56 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
61 float globhandle, i, n;
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 #ifdef COMPAT_XON050_ENGINE
120 // old engine lacks implementation of player_localnum
121 player_localnum = player_localentnum - 1;
124 binddb = db_create();
125 tempdb = db_create();
126 ClientProgsDB = db_load("client.db");
127 compressShortVector_init();
129 drawfont = FONT_USER+1;
130 menu_visible = FALSE;
131 menu_show = menu_show_error;
132 menu_action = menu_sub_null;
134 for(i = 0; i < 255; ++i)
135 if(getplayerkeyvalue(i, "viewentity") == "")
139 registercommand("hud_configure");
140 registercommand("hud_save");
141 //registercommand("menu_action");
143 registercommand("+showscores");registercommand("-showscores");
144 registercommand("+showaccuracy");registercommand("-showaccuracy");
150 registercommand("+forward");registercommand("-forward");
151 registercommand("+back");registercommand("-back");
152 registercommand("+moveup");registercommand("-moveup");
153 registercommand("+movedown");registercommand("-movedown");
154 registercommand("+moveright");registercommand("-moveright");
155 registercommand("+moveleft");registercommand("-moveleft");
156 registercommand("+roll_right");registercommand("-roll_right");
157 registercommand("+roll_left");registercommand("-roll_left");
161 registercvar("hud_usecsqc", "1");
162 registercvar("scoreboard_columns", "default");
166 // hud_fields uses strunzone on the titles!
167 for(i = 0; i < MAX_HUD_FIELDS; ++i)
168 hud_title[i] = strzone("(null)");
174 teams = Sort_Spawn();
175 players = Sort_Spawn();
177 GetTeam(COLOR_SPECTATOR, true); // add specs first
181 WaypointSprite_Load();
184 precache_model("null");
185 precache_sound("misc/hit.wav");
186 precache_sound("misc/typehit.wav");
187 if (autocvar_cl_precacheplayermodels)
189 precache_all_playermodels("models/player/*.zym");
190 precache_all_playermodels("models/player/*.dpm");
191 precache_all_playermodels("models/player/*.md3");
192 precache_all_playermodels("models/player/*.psk");
193 precache_all_playermodels("models/player/*.iqm");
196 Projectile_Precache();
198 GibSplash_Precache();
200 DamageInfo_Precache();
203 Announcer_Precache();
206 if(autocvar_cl_reticle)
208 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
209 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
212 get_mi_min_max_texcoords(1); // try the CLEVER way first
213 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
214 shortmapname = mi_shortname;
216 if(precache_pic(minimapname) == "")
218 // but maybe we have a non-clever minimap
219 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
220 if(precache_pic(minimapname) == "")
221 minimapname = ""; // FAIL
223 get_mi_min_max_texcoords(0); // load new texcoords
226 mi_center = (mi_min + mi_max) * 0.5;
227 mi_scale = mi_max - mi_min;
228 minimapname = strzone(minimapname);
232 hud_configure_prev = -1;
236 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
237 void CSQC_Shutdown(void)
252 if(autocvar_cl_db_saveasdump)
253 db_dump(ClientProgsDB, "client.db");
255 db_save(ClientProgsDB, "client.db");
256 db_close(ClientProgsDB);
258 cvar_clientsettemp_restore();
261 cvar_set("chase_active",ftos(chase_active_backup));
263 // unset the event chasecam's chase_active
264 if(autocvar_chase_active < 0)
265 cvar_set("chase_active", "0");
269 if not(calledhooks & HOOK_START)
270 localcmd("\n_cl_hook_gamestart nop\n");
271 if not(calledhooks & HOOK_END)
272 localcmd("\ncl_hook_gameend\n");
277 float SetTeam(entity o, float Team)
291 if(GetTeam(Team, false) == world)
293 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
294 Team = COLOR_SPECTATOR;
307 if(GetTeam(Team, false) == world)
309 print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
310 Team = COLOR_SPECTATOR;
315 if(Team == -1) // leave
319 tm = GetTeam(o.team, false);
330 tm = GetTeam(Team, true);
335 else if(Team != o.team)
337 tm = GetTeam(o.team, false);
340 tm = GetTeam(Team, true);
348 void Playerchecker_Think()
352 for(i = 0; i < maxclients; ++i)
355 if(GetPlayerName(i) == "")
359 // player disconnected
372 playerslots[i] = e = spawn();
375 e.ping_packetloss = 0;
376 e.ping_movementloss = 0;
377 //e.gotscores = 0; // we might already have the scores...
378 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
380 HUD_UpdatePlayerPos(e);
384 self.nextthink = time + 0.2;
391 localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
393 entity playerchecker;
394 playerchecker = spawn();
395 playerchecker.think = Playerchecker_Think;
396 playerchecker.nextthink = time + 0.2;
404 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
405 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
407 void Cmd_HUD_SetFields(float);
408 void Cmd_HUD_Help(float);
409 float CSQC_ConsoleCommand(string strMessage)
413 argc = tokenize_console(strMessage);
419 if(strCmd == "hud_configure") { // config hud
420 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
422 } else if(strCmd == "hud_save") { // save hud config
423 if(argv(1) == "" || argv(2)) {
424 print(_("Usage:\n"));
425 print(_("hud_save configname (saves to hud_skinname_configname.cfg)\n"));
428 HUD_Panel_ExportCfg(argv(1));
430 } else if(strCmd == "+showscores") {
431 scoreboard_showscores = true;
433 } else if(strCmd == "-showscores") {
434 scoreboard_showscores = false;
436 } else if(strCmd == "+showaccuracy") {
437 scoreboard_showaccuracy = true;
439 } else if(strCmd == "-showaccuracy") {
440 scoreboard_showaccuracy = false;
445 if(strCmd == "+forward" || strCmd == "-back") {
446 ++camera_direction_x;
448 } else if(strCmd == "-forward" || strCmd == "+back") {
449 --camera_direction_x;
451 } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
452 --camera_direction_y;
454 } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
455 ++camera_direction_y;
457 } else if(strCmd == "+moveup" || strCmd == "-movedown") {
458 ++camera_direction_z;
460 } else if(strCmd == "-moveup" || strCmd == "+movedown") {
461 --camera_direction_z;
463 } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
466 } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
475 entity debug_shotorg;
478 self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
479 self.angles = view_angles;
480 self.angles_x = -self.angles_x;
482 self.drawmask = MASK_NORMAL;
486 void ShotOrg_Draw2D()
488 vector coord2d_topleft, coord2d_topright, coord2d;
492 s = vtos(self.view_ofs);
493 s = substring(s, 1, strlen(s) - 2);
494 if(tokenize_console(s) == 3)
495 s = strcat(argv(0), " ", argv(1), " ", argv(2));
497 coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
498 coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
500 fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
502 coord2d = coord2d_topleft;
505 coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
510 drawstring(coord2d, s, fs, '1 1 1', 1, 0);
515 debug_shotorg = spawn();
516 debug_shotorg.draw = ShotOrg_Draw;
517 debug_shotorg.draw2d = ShotOrg_Draw2D;
518 debug_shotorg.renderflags = RF_VIEWMODEL;
519 debug_shotorg.effects = EF_FULLBRIGHT;
520 precache_model("models/shotorg_adjuster.md3");
521 setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
522 debug_shotorg.scale = 2;
523 debug_shotorg.view_ofs = '25 8 -8';
526 void DrawDebugModel()
528 if(time - floor(time) > 0.5)
535 self.renderflags = 0;
536 self.drawmask = MASK_NORMAL;
540 void GameCommand(string msg)
545 argc = tokenize_console(msg);
547 if(argv(0) == "help" || argc == 0)
549 print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
550 print(_(" settemp cvar value\n"));
551 print(_(" scoreboard_columns_set ...\n"));
552 print(_(" scoreboard_columns_help\n"));
553 GameCommand_Generic("help");
557 if(GameCommand_Generic(msg))
562 if(cmd == "mv_download") {
563 Cmd_MapVote_MapDownload(argc);
565 else if(cmd == "hud_panel_radar_maximized")
568 hud_panel_radar_maximized = !hud_panel_radar_maximized;
570 hud_panel_radar_maximized = (stof(argv(1)) != 0);
572 else if(cmd == "settemp") {
573 cvar_clientsettemp(argv(1), argv(2));
575 else if(cmd == "scoreboard_columns_set") {
576 Cmd_HUD_SetFields(argc);
578 else if(cmd == "scoreboard_columns_help") {
582 else if(cmd == "blurtest") {
583 blurtest_time0 = time;
584 blurtest_time1 = time + stof(argv(1));
585 blurtest_radius = stof(argv(2));
586 blurtest_power = stof(argv(3));
589 else if(cmd == "shotorg_move") {
593 debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
594 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
596 else if(cmd == "shotorg_movez") {
600 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
601 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
603 else if(cmd == "shotorg_set") {
607 debug_shotorg.view_ofs = stov(argv(1));
608 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
610 else if(cmd == "shotorg_setz") {
614 debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
615 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
617 else if(cmd == "shotorg_toggle_hide") {
620 debug_shotorg.cnt = !debug_shotorg.cnt;
623 else if(cmd == "shotorg_end") {
626 print(vtos(debug_shotorg.view_ofs), "\n");
627 remove(debug_shotorg);
628 debug_shotorg = world;
630 localcmd("sv_cmd debug_shotorg\n");
632 else if(cmd == "sendcvar") {
633 // W_FixWeaponOrder will trash argv, so save what we need.
635 thiscvar = strzone(argv(1));
636 s = cvar_string(thiscvar);
637 if(thiscvar == "cl_weaponpriority")
638 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
639 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
640 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
641 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
644 else if(cmd == "spawn") {
649 setorigin(e, view_origin);
650 e.angles = view_angles;
651 e.draw = DrawDebugModel;
652 e.classname = "debugmodel";
654 else if(cmd == "vyes")
658 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)
660 localcmd("setreport cl_allow_uid2name 1\n");
666 localcmd("cmd vote yes\n");
669 else if(cmd == "vno")
675 localcmd("setreport cl_allow_uid2name 0\n");
681 localcmd("cmd vote no\n");
687 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
693 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
694 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
695 // All keys are in ascii.
696 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
697 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
698 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
699 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
704 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
707 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
711 if(menu_action(bInputType, nPrimary, nSecondary))
717 // END REQUIRED CSQC FUNCTIONS
718 // --------------------------------------------------------------------------
720 // --------------------------------------------------------------------------
721 // BEGIN OPTIONAL CSQC FUNCTIONS
722 void Ent_RemoveEntCS()
724 entcs_receiver[self.sv_entnum] = world;
729 InterpolateOrigin_Undo();
731 self.classname = "entcs_receiver";
735 self.sv_entnum = ReadByte();
738 self.origin_x = ReadShort();
739 self.origin_y = ReadShort();
740 self.origin_z = ReadShort();
744 self.angles_y = ReadByte() * 360.0 / 256;
745 self.angles_x = self.angles_z = 0;
748 self.healthvalue = ReadByte() * 10;
750 self.armorvalue = ReadByte() * 10;
752 entcs_receiver[self.sv_entnum] = self;
753 self.entremove = Ent_RemoveEntCS;
755 InterpolateOrigin_Note();
760 void Ent_RemovePlayerScore()
766 SetTeam(self.owner, -1);
767 self.owner.gotscores = 0;
768 for(i = 0; i < MAX_SCORE; ++i)
769 self.owner.(scores[i]) = 0; // clear all scores
773 void Ent_ReadPlayerScore()
779 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
780 // (no I've never heard of M-x replace-string, sed, or anything like that)
781 isNew = !self.owner; // workaround for DP bug
784 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
785 if(!isNew && n != self.sv_entnum)
787 //print(_("A CSQC entity changed its owner!\n"));
788 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
791 self.enttype = ENT_CLIENT_SCORES;
797 if not(playerslots[self.sv_entnum])
798 playerslots[self.sv_entnum] = spawn();
799 o = self.owner = playerslots[self.sv_entnum];
800 o.sv_entnum = self.sv_entnum;
803 //if not(o.sort_prev)
804 // RegisterPlayer(o);
805 //playerchecker will do this for us later, if it has not already done so
816 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
820 o.(scores[i]) = ReadInt24_t();
822 o.(scores[i]) = ReadChar();
826 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
828 self.entremove = Ent_RemovePlayerScore;
831 void Ent_ReadTeamScore()
836 self.team = ReadByte();
837 o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
840 #if MAX_TEAMSCORE <= 8
848 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
852 o.(teamscores[i]) = ReadInt24_t();
854 o.(teamscores[i]) = ReadChar();
857 HUD_UpdateTeamPos(o);
860 void Ent_ClientData()
863 float newspectatee_status;
867 scoreboard_showscores_force = (f & 1);
871 newspectatee_status = ReadByte();
872 if(newspectatee_status == player_localnum + 1)
873 newspectatee_status = -1; // observing
876 newspectatee_status = 0;
878 spectatorbutton_zoom = (f & 4);
882 angles_held_status = 1;
883 angles_held_x = ReadAngle();
884 angles_held_y = ReadAngle();
888 angles_held_status = 0;
890 if(newspectatee_status != spectatee_status)
894 race_checkpointtime = 0;
896 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
898 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
899 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
902 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
905 spectatee_status = newspectatee_status;
907 // non-COMPAT_XON050_ENGINE: we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
912 float nags, i, j, b, f;
914 nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
919 strunzone(vote_called_vote);
920 vote_called_vote = string_null;
930 vote_yescount = ReadByte();
931 vote_nocount = ReadByte();
932 vote_needed = ReadByte();
933 vote_highlighted = ReadChar();
939 strunzone(vote_called_vote);
940 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
945 for(j = 0; j < maxclients; ++j)
947 playerslots[j].ready = 1;
948 for(i = 1; i <= maxclients; i += 8)
951 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
954 playerslots[j].ready = 0;
958 ready_waiting = (nags & 1);
959 ready_waiting_for_me = (nags & 2);
960 vote_waiting = (nags & 4);
961 vote_waiting_for_me = (nags & 8);
962 warmup_stage = (nags & 16);
965 void Ent_RandomSeed()
973 void Ent_ReadAccuracy(void)
979 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
980 weapon_accuracy[w] = -1;
984 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
990 weapon_accuracy[w] = -1;
992 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
994 weapon_accuracy[w] = (b - 1.0) / 100.0;
999 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
1000 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
1001 void Ent_RadarLink();
1003 void Ent_ScoresInfo();
1004 void CSQC_Ent_Update(float bIsNewEntity)
1010 // set up the "time" global for received entities to be correct for interpolation purposes
1018 serverprevtime = time;
1019 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
1020 time = serverprevtime + serverdeltatime;
1023 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
1026 if(t != self.enttype || bIsNewEntity)
1028 //print(_("A CSQC entity changed its type!\n"));
1029 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));
1038 print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
1046 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
1047 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
1048 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
1049 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
1050 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
1051 case ENT_CLIENT_LASER: Ent_Laser(); break;
1052 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
1053 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
1054 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
1055 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
1056 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
1057 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
1058 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
1059 case ENT_CLIENT_INIT: Ent_Init(); break;
1060 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
1061 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
1062 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
1063 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
1064 case ENT_CLIENT_WALL: Ent_Wall(); break;
1065 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
1066 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
1067 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
1068 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
1069 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
1070 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
1071 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
1072 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
1073 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
1074 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
1075 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
1076 case ENT_CLIENT_TURRET: ent_turret(); break;
1077 case ENT_CLIENT_MODEL: CSQCModel_Read(); break;
1079 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1080 error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1086 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1087 // used when an entity changes its type. For an entity that someone interacts
1088 // with others, make sure it can no longer do so.
1095 self.classname = "";
1096 self.draw = menu_sub_null;
1097 self.entremove = menu_sub_null;
1098 // TODO possibly set more stuff to defaults
1100 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
1101 void CSQC_Ent_Remove()
1108 void Gamemode_Init()
1112 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), "\n");
1113 calledhooks |= HOOK_START;
1116 // 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.
1117 void CSQC_Parse_StuffCmd(string strMessage)
1119 localcmd(strMessage);
1121 // 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.
1122 void CSQC_Parse_Print(string strMessage)
1124 print(ColorTranslateRGB(strMessage));
1127 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1128 void CSQC_Parse_CenterPrint(string strMessage)
1130 centerprint_hud(strMessage);
1133 string notranslate_fogcmd1 = "\nfog ";
1134 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1137 // TODO somehow thwart prvm_globalset client ...
1140 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1143 void Gamemode_Init();
1144 void Ent_ScoresInfo()
1147 self.classname = "ent_client_scores_info";
1148 gametype = ReadByte();
1149 for(i = 0; i < MAX_SCORE; ++i)
1151 scores_label[i] = strzone(ReadString());
1152 scores_flags[i] = ReadByte();
1154 for(i = 0; i < MAX_TEAMSCORE; ++i)
1156 teamscores_label[i] = strzone(ReadString());
1157 teamscores_flags[i] = ReadByte();
1165 self.classname = "ent_client_init";
1167 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1169 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1170 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1171 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1172 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1173 electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1174 electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1175 electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1176 electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1177 gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1178 gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1179 gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1180 gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1183 strunzone(forcefog);
1184 forcefog = strzone(ReadString());
1186 armorblockpercent = ReadByte() / 255.0;
1188 g_weaponswitchdelay = ReadByte() / 255.0;
1190 g_balance_grenadelauncher_bouncefactor = ReadCoord();
1191 g_balance_grenadelauncher_bouncestop = ReadCoord();
1192 g_balance_electro_secondary_bouncefactor = ReadCoord();
1193 g_balance_electro_secondary_bouncestop = ReadCoord();
1195 nex_scope = !ReadByte();
1196 rifle_scope = !ReadByte();
1198 serverflags = ReadByte();
1200 minelayer_maxmines = ReadByte();
1202 hagar_maxrockets = ReadByte();
1204 g_trueaim_minrange = ReadCoord();
1218 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1219 race_checkpoint = ReadByte();
1220 race_time = ReadInt24_t();
1221 race_previousbesttime = ReadInt24_t();
1222 if(race_previousbestname)
1223 strunzone(race_previousbestname);
1224 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1226 race_checkpointtime = time;
1228 if(race_checkpoint == 0 || race_checkpoint == 254)
1230 race_penaltyaccumulator = 0;
1231 race_laptime = time; // valid
1236 case RACE_NET_CHECKPOINT_CLEAR:
1238 race_checkpointtime = 0;
1241 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1242 race_laptime = ReadCoord();
1243 race_checkpointtime = -99999;
1245 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1246 race_nextcheckpoint = ReadByte();
1248 race_nextbesttime = ReadInt24_t();
1249 if(race_nextbestname)
1250 strunzone(race_nextbestname);
1251 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1254 case RACE_NET_CHECKPOINT_HIT_RACE:
1255 race_mycheckpoint = ReadByte();
1256 race_mycheckpointtime = time;
1257 race_mycheckpointdelta = ReadInt24_t();
1258 race_mycheckpointlapsdelta = ReadByte();
1259 if(race_mycheckpointlapsdelta >= 128)
1260 race_mycheckpointlapsdelta -= 256;
1261 if(race_mycheckpointenemy)
1262 strunzone(race_mycheckpointenemy);
1263 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1266 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1267 race_othercheckpoint = ReadByte();
1268 race_othercheckpointtime = time;
1269 race_othercheckpointdelta = ReadInt24_t();
1270 race_othercheckpointlapsdelta = ReadByte();
1271 if(race_othercheckpointlapsdelta >= 128)
1272 race_othercheckpointlapsdelta -= 256;
1273 if(race_othercheckpointenemy)
1274 strunzone(race_othercheckpointenemy);
1275 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1278 case RACE_NET_PENALTY_RACE:
1279 race_penaltyeventtime = time;
1280 race_penaltytime = ReadShort();
1281 //race_penaltyaccumulator += race_penaltytime;
1282 if(race_penaltyreason)
1283 strunzone(race_penaltyreason);
1284 race_penaltyreason = strzone(ReadString());
1287 case RACE_NET_PENALTY_QUALIFYING:
1288 race_penaltyeventtime = time;
1289 race_penaltytime = ReadShort();
1290 race_penaltyaccumulator += race_penaltytime;
1291 if(race_penaltyreason)
1292 strunzone(race_penaltyreason);
1293 race_penaltyreason = strzone(ReadString());
1296 case RACE_NET_SERVER_RECORD:
1297 race_server_record = ReadInt24_t();
1299 case RACE_NET_SPEED_AWARD:
1300 race_speedaward = ReadInt24_t();
1301 if(race_speedaward_holder)
1302 strunzone(race_speedaward_holder);
1303 race_speedaward_holder = strzone(ReadString());
1305 case RACE_NET_SPEED_AWARD_BEST:
1306 race_speedaward_alltimebest = ReadInt24_t();
1307 if(race_speedaward_alltimebest_holder)
1308 strunzone(race_speedaward_alltimebest_holder);
1309 race_speedaward_alltimebest_holder = strzone(ReadString());
1311 case RACE_NET_SERVER_RANKINGS:
1312 float pos, prevpos, del;
1314 prevpos = ReadShort();
1317 // move other rankings out of the way
1320 for (i=prevpos-1;i>pos-1;--i) {
1321 grecordtime[i] = grecordtime[i-1];
1322 if(grecordholder[i])
1323 strunzone(grecordholder[i]);
1324 grecordholder[i] = strzone(grecordholder[i-1]);
1326 } else if (del) { // a record has been deleted by the admin
1327 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1328 if (i == RANKINGS_CNT-1) { // clear out last record
1330 if (grecordholder[i])
1331 strunzone(grecordholder[i]);
1332 grecordholder[i] = string_null;
1335 grecordtime[i] = grecordtime[i+1];
1336 if (grecordholder[i])
1337 strunzone(grecordholder[i]);
1338 grecordholder[i] = strzone(grecordholder[i+1]);
1341 } else { // player has no ranked record yet
1342 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1343 grecordtime[i] = grecordtime[i-1];
1344 if(grecordholder[i])
1345 strunzone(grecordholder[i]);
1346 grecordholder[i] = strzone(grecordholder[i-1]);
1350 // store new ranking
1351 if(grecordholder[pos-1] != "")
1352 strunzone(grecordholder[pos-1]);
1353 grecordholder[pos-1] = strzone(ReadString());
1354 grecordtime[pos-1] = ReadInt24_t();
1355 if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1358 case RACE_NET_SERVER_STATUS:
1359 race_status = ReadShort();
1360 if(race_status_name)
1361 strunzone(race_status_name);
1362 race_status_name = strzone(ReadString());
1366 void Net_ReadSpawn()
1369 current_viewzoom = 0.6;
1372 void Net_TeamNagger()
1377 void Net_ReadPingPLReport()
1379 float e, pi, pl, ml;
1384 if not(playerslots[e])
1386 playerslots[e].ping = pi;
1387 playerslots[e].ping_packetloss = pl / 255.0;
1388 playerslots[e].ping_movementloss = ml / 255.0;
1391 void Net_WeaponComplain() {
1392 complain_weapon = ReadByte();
1394 if(complain_weapon_name)
1395 strunzone(complain_weapon_name);
1396 complain_weapon_name = strzone(ReadString());
1398 complain_weapon_type = ReadByte();
1400 complain_weapon_time = time;
1401 weapontime = time; // ping the weapon panel
1404 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1405 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1406 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1407 float CSQC_Parse_TempEntity()
1415 // NOTE: Could just do return instead of break...
1418 case TE_CSQC_TARGET_MUSIC:
1422 case TE_CSQC_PICTURE:
1423 Net_MapVote_Picture();
1434 case TE_CSQC_ZCURVEPARTICLES:
1435 Net_ReadZCurveParticles();
1438 case TE_CSQC_NEXGUNBEAMPARTICLE:
1439 Net_ReadNexgunBeamParticle();
1442 case TE_CSQC_TEAMNAGGER:
1446 case TE_CSQC_LIGHTNINGARC:
1447 Net_ReadLightningarc();
1450 case TE_CSQC_PINGPLREPORT:
1451 Net_ReadPingPLReport();
1454 case TE_CSQC_ANNOUNCE:
1455 Announcer_Play(ReadString());
1458 case TE_CSQC_KILLNOTIFY:
1459 HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1462 case TE_CSQC_KILLCENTERPRINT:
1463 HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1466 case TE_CSQC_CENTERPRINT_GENERIC:
1471 if (id != 0 && s != "")
1472 centerprint_generic(id, s, ReadByte(), ReadByte());
1474 centerprint_generic(id, s, 0, 0);
1477 case TE_CSQC_WEAPONCOMPLAIN:
1478 Net_WeaponComplain();
1481 case TE_CSQC_VEHICLESETUP:
1486 // No special logic for this temporary entity; return 0 so the engine can handle it
1494 string getcommandkey(string text, string command)
1499 if (!autocvar_hud_showbinds)
1502 keys = db_get(binddb, command);
1505 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1506 for(j = 0; j < n; ++j)
1512 keys = keynumtostring(k);
1514 keys = strcat(keys, ", ", keynumtostring(k));
1517 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1521 db_put(binddb, command, keys);
1525 if (autocvar_hud_showbinds > 1)
1526 return sprintf(_("%s (not bound)"), text);
1530 else if (autocvar_hud_showbinds > 1)
1531 return sprintf(_("%s (%s)"), text, keys);