3 #include <common/effects/qc/all.qh>
5 #include "mapvoting.qh"
6 #include "mutators/events.qh"
7 #include "hud/panel/scoreboard.qh"
8 #include "hud/panel/quickmenu.qh"
9 #include "shownames.qh"
10 #include <common/t_items.qh>
12 #include "weapons/projectile.qh"
13 #include <common/deathtypes/all.qh>
14 #include <common/items/_mod.qh>
15 #include <common/mapinfo.qh>
16 #include <common/minigames/cl_minigames.qh>
17 #include <common/minigames/cl_minigames_hud.qh>
18 #include <common/net_linked.qh>
19 #include <common/net_notice.qh>
20 #include <common/triggers/include.qh>
21 #include <common/vehicles/all.qh>
22 #include <lib/csqcmodel/cl_model.qh>
23 #include <lib/csqcmodel/interpolate.qh>
24 #include <lib/warpzone/client.qh>
26 // --------------------------------------------------------------------------
27 // BEGIN REQUIRED CSQC FUNCTIONS
30 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
32 void draw_cursor(vector pos, vector ofs, string img, vector col, float a)
34 ofs = eX * (ofs.x * SIZE_CURSOR.x) + eY * (ofs.y * SIZE_CURSOR.y);
35 drawpic(pos - ofs, strcat(draw_currentSkin, img), SIZE_CURSOR, col, a, DRAWFLAG_NORMAL);
38 void draw_cursor_normal(vector pos, vector col, float a)
40 draw_cursor(pos, OFFSET_CURSOR, "/cursor", col, a);
43 void LoadMenuSkinValues()
46 if(cvar_string("menu_skin") != "")
48 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
49 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
51 if(fh < 0 && cvar_defstring("menu_skin") != "")
53 cvar_set("menu_skin", cvar_defstring("menu_skin"));
54 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
55 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
59 draw_currentSkin = "gfx/menu/default";
60 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
63 draw_currentSkin = strzone(draw_currentSkin);
68 while((s = fgets(fh)))
70 int n = tokenize_console(s);
73 if(substring(argv(0), 0, 2) == "//")
75 if(argv(0) == "SIZE_CURSOR")
76 SIZE_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
77 else if(argv(0) == "OFFSET_CURSOR")
78 OFFSET_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
84 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
85 // Useful for precaching things
87 void ConsoleCommand_macro_init();
90 prvm_language = strzone(cvar_string("prvm_language"));
93 LOG_INFOF("^4CSQC Build information: ^1%s\n", WATERMARK);
99 if (getplayerkeyvalue(i, "viewentity") == "")
104 // needs to be done so early because of the constants they create
107 static_init_precache();
109 binddb = db_create();
110 tempdb = db_create();
111 ClientProgsDB = db_load("client.db");
115 //registercommand("hud_configure");
116 //registercommand("hud_save");
117 //registercommand("menu_action");
119 ConsoleCommand_macro_init();
121 registercvar("hud_usecsqc", "1");
122 registercvar("scoreboard_columns", "default");
124 registercvar("cl_nade_type", "3");
125 registercvar("cl_pokenade_type", "zombie");
127 registercvar("cl_jumpspeedcap_min", "");
128 registercvar("cl_jumpspeedcap_max", "");
130 registercvar("cl_multijump", "1");
132 registercvar("cl_spawn_near_teammate", "1");
140 teams = Sort_Spawn();
141 players = Sort_Spawn();
143 GetTeam(NUM_SPECTATOR, true); // add specs first
147 if(autocvar_cl_reticle)
149 precache_pic("gfx/reticle_normal");
150 // weapon reticles are precached in weapon files
154 get_mi_min_max_texcoords(1); // try the CLEVER way first
155 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
156 shortmapname = mi_shortname;
158 if (precache_pic(minimapname) == "")
160 // but maybe we have a non-clever minimap
161 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
162 if (precache_pic(minimapname) == "")
163 minimapname = ""; // FAIL
165 get_mi_min_max_texcoords(0); // load new texcoords
168 mi_center = (mi_min + mi_max) * 0.5;
169 mi_scale = mi_max - mi_min;
170 minimapname = strzone(minimapname);
173 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
174 LoadMenuSkinValues();
177 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
186 if(autocvar_cl_db_saveasdump)
187 db_dump(ClientProgsDB, "client.db");
189 db_save(ClientProgsDB, "client.db");
190 db_close(ClientProgsDB);
193 cvar_set("chase_active",ftos(chase_active_backup));
195 // unset the event chasecam's chase_active
196 if(autocvar_chase_active < 0)
197 cvar_set("chase_active", "0");
199 cvar_set("slowmo", cvar_defstring("slowmo")); // reset it back to 'default'
203 if (!(calledhooks & HOOK_START))
204 localcmd("\n_cl_hook_gamestart nop\n");
205 if (!(calledhooks & HOOK_END))
206 localcmd("\ncl_hook_gameend\n");
209 deactivate_minigame();
210 HUD_MinigameMenu_Close(NULL, NULL, NULL);
214 float SetTeam(entity o, int Team)
217 devassert_once(Team);
230 if(GetTeam(Team, false) == NULL)
232 LOG_TRACEF("trying to switch to unsupported team %d", Team);
233 Team = NUM_SPECTATOR;
246 if(GetTeam(Team, false) == NULL)
248 LOG_TRACEF("trying to switch to unsupported team %d", Team);
249 Team = NUM_SPECTATOR;
254 if(Team == -1) // leave
258 tm = GetTeam(o.team, false);
269 tm = GetTeam(Team, true);
274 else if(Team != o.team)
276 tm = GetTeam(o.team, false);
279 tm = GetTeam(Team, true);
287 void Playerchecker_Think(entity this)
291 for(i = 0; i < maxclients; ++i)
294 if(entcs_GetName(i) == "")
298 // player disconnected
312 playerslots[i] = e = new_pure(playerslot);
316 e.ping_packetloss = 0;
317 e.ping_movementloss = 0;
318 //e.gotscores = 0; // we might already have the scores...
319 int t = entcs_GetScoreTeam(i);
320 if (t) SetTeam(e, t); // will not hurt; later updates come with Scoreboard_UpdatePlayerTeams
322 Scoreboard_UpdatePlayerPos(e);
326 this.nextthink = time + 0.2;
332 entity playerchecker = new_pure(playerchecker);
333 setthink(playerchecker, Playerchecker_Think);
334 playerchecker.nextthink = time + 0.2;
341 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
342 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
343 // All keys are in ascii.
344 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
345 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
346 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
347 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
348 float CSQC_InputEvent(int bInputType, float nPrimary, float nSecondary)
351 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
354 if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
357 if (HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary))
360 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
363 if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
369 // END REQUIRED CSQC FUNCTIONS
370 // --------------------------------------------------------------------------
372 // --------------------------------------------------------------------------
373 // BEGIN OPTIONAL CSQC FUNCTIONS
375 void Ent_Remove(entity this);
377 void Ent_RemovePlayerScore(entity this)
380 SetTeam(this.owner, -1);
381 this.owner.gotscores = 0;
382 FOREACH(Scores, true, {
383 this.owner.(scores(it)) = 0; // clear all scores
388 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
393 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
394 // (no I've never heard of M-x replace-string, sed, or anything like that)
395 bool isNew = !this.owner; // workaround for DP bug
396 int n = ReadByte()-1;
398 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
399 if(!isNew && n != this.sv_entnum)
401 //print("A CSQC entity changed its owner!\n");
402 LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", etof(this), this.classname);
410 o = playerslots[this.sv_entnum];
413 o = playerslots[this.sv_entnum] = new_pure(playerslot);
416 o.sv_entnum = this.sv_entnum;
420 // RegisterPlayer(o);
421 //playerchecker will do this for us later, if it has not already done so
426 FOREACH(Scores, true, {
427 int p = 1 << (i % 16);
431 o.(scores(it)) = ReadInt24_t();
433 o.(scores(it)) = ReadChar();
440 Scoreboard_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
442 this.entremove = Ent_RemovePlayerScore;
445 NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
451 this.team = ReadByte();
452 o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
455 #if MAX_TEAMSCORE <= 8
463 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
467 o.(teamscores(i)) = ReadInt24_t();
469 o.(teamscores(i)) = ReadChar();
474 Scoreboard_UpdateTeamPos(o);
477 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
480 float newspectatee_status;
484 scoreboard_showscores_force = (f & 1);
488 newspectatee_status = ReadByte();
489 if(newspectatee_status == player_localnum + 1)
490 newspectatee_status = -1; // observing
493 newspectatee_status = 0;
495 spectatorbutton_zoom = (f & 4);
499 num_spectators = ReadByte();
503 for(i = 0; i < MAX_SPECTATORS; ++i)
504 spectatorlist[i] = 0; // reset list first
506 for(i = 0; i < num_spectators; ++i)
509 spectatorlist[i] = slot - 1;
515 if(newspectatee_status != spectatee_status)
519 race_checkpointtime = 0;
520 hud_dynamic_shake_factor = -1;
522 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
524 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
525 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
528 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
531 spectatee_status = newspectatee_status;
533 // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
536 NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
541 int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
546 strunzone(vote_called_vote);
547 vote_called_vote = string_null;
557 vote_yescount = ReadByte();
558 vote_nocount = ReadByte();
559 vote_needed = ReadByte();
560 vote_highlighted = ReadChar();
566 strunzone(vote_called_vote);
567 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
572 for(j = 0; j < maxclients; ++j)
574 playerslots[j].ready = 1;
575 for(i = 1; i <= maxclients; i += 8)
578 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
581 playerslots[j].ready = 0;
587 ready_waiting = (nags & BIT(0));
588 ready_waiting_for_me = (nags & BIT(1));
589 vote_waiting = (nags & BIT(2));
590 vote_waiting_for_me = (nags & BIT(3));
591 warmup_stage = (nags & BIT(4));
594 NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
602 for(j = 0; j < maxclients; ++j)
604 playerslots[j].eliminated = 1;
605 for(i = 1; i <= maxclients; i += 8)
608 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
611 playerslots[j].eliminated = 0;
617 NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
621 float s = ReadShort();
626 NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
629 int sf = ReadInt24_t();
631 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
632 weapon_accuracy[w] = -1;
637 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
641 weapon_accuracy[w] = -1;
643 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
645 weapon_accuracy[w] = (b - 1.0) / 100.0;
647 f = (f == 0x800000) ? 1 : f * 2;
652 void Spawn_Draw(entity this)
654 __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
657 void Spawn_PreDraw(entity this)
660 vector org = getpropertyvec(VF_ORIGIN);
662 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
665 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
670 this.drawmask = MASK_NORMAL;
673 NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
675 float teamnum = (ReadByte() - 1);
677 spn_origin.x = ReadCoord();
678 spn_origin.y = ReadCoord();
679 spn_origin.z = ReadCoord();
681 this.team = (teamnum + 1);
685 this.origin = spn_origin;
686 setsize(this, PL_MIN_CONST, PL_MAX_CONST);
689 /*if(autocvar_cl_spawn_point_model) // needs a model first
691 this.mdl = "models/spawnpoint.md3";
692 this.colormod = Team_ColorRGB(teamnum);
693 precache_model(this.mdl);
694 setmodel(this, this.mdl);
695 this.drawmask = MASK_NORMAL;
696 //this.move_movetype = MOVETYPE_NOCLIP;
697 //this.draw = Spawn_Draw;
698 IL_PUSH(g_drawables, this);
700 if(autocvar_cl_spawn_point_particles)
706 case NUM_TEAM_1: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
707 case NUM_TEAM_2: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
708 case NUM_TEAM_3: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
709 case NUM_TEAM_4: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
710 default: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
713 else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
715 this.draw = Spawn_Draw;
716 if (is_new) IL_PUSH(g_drawables, this);
717 setpredraw(this, Spawn_PreDraw);
718 this.fade_start = autocvar_cl_spawn_point_dist_min;
719 this.fade_end = autocvar_cl_spawn_point_dist_max;
723 //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(this.origin), teamnum, this.cnt);
727 NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
729 // If entnum is 0, ONLY do the local spawn actions
730 // this way the server can disable the sending of
731 // spawn origin or such to clients if wanted.
732 float entnum = ReadByte();
736 this.origin_x = ReadCoord();
737 this.origin_y = ReadCoord();
738 this.origin_z = ReadCoord();
742 float teamnum = entcs_GetTeam(entnum - 1);
744 if(autocvar_cl_spawn_event_particles)
748 case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break;
749 case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break;
750 case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break;
751 case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break;
752 default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break;
755 if(autocvar_cl_spawn_event_sound)
757 sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
763 // local spawn actions
764 if(is_new && (!entnum || (entnum == player_localentnum)))
767 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
769 if(autocvar_cl_unpress_zoom_on_spawn)
775 HUD_Radar_Hide_Maximized();
776 //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum);
779 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
780 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
781 void CSQC_Ent_Update(entity this, bool isnew)
783 this.sourceLoc = __FILE__ ":" STR(__LINE__);
786 // set up the "time" global for received entities to be correct for interpolation purposes
787 float savetime = time;
794 serverprevtime = time;
795 serverdeltatime = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
796 time = serverprevtime + serverdeltatime;
799 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
802 if (t != this.enttype || isnew)
804 LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", etof(this), this.entnum, this.enttype, t);
814 LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", etof(this), this.entnum, t);
821 FOREACH(LinkedEntities, it.m_id == t, {
822 if (isnew) this.classname = it.netname;
823 if (autocvar_developer_csqcentities)
824 LOG_INFOF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
825 done = it.m_read(this, NULL, isnew);
826 MUTATOR_CALLHOOK(Ent_Update, this, isnew);
832 LOG_FATALF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
836 // Destructor, but does NOT deallocate the entity by calling remove(). Also
837 // used when an entity changes its type. For an entity that someone interacts
838 // with others, make sure it can no longer do so.
839 void Ent_Remove(entity this)
841 if(this.entremove) this.entremove(this);
843 if(this.skeletonindex)
845 skel_delete(this.skeletonindex);
846 this.skeletonindex = 0;
849 if(this.snd_looping > 0)
851 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
852 this.snd_looping = 0;
857 this.draw = func_null;
858 this.entremove = func_null;
859 // TODO possibly set more stuff to defaults
861 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(this) as well.
862 void CSQC_Ent_Remove(entity this)
864 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype);
867 LOG_WARN("CSQC_Ent_Remove called for already removed entity. Packet loss?");
870 if (this.enttype) Ent_Remove(this);
878 if(!(calledhooks & HOOK_START))
879 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
880 calledhooks |= HOOK_START;
883 // 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.
884 void CSQC_Parse_StuffCmd(string strMessage)
886 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
887 localcmd(strMessage);
889 // 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.
890 void CSQC_Parse_Print(string strMessage)
892 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
893 print(ColorTranslateRGB(strMessage));
896 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
897 void CSQC_Parse_CenterPrint(string strMessage)
899 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
900 centerprint_hud(strMessage);
903 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
904 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
905 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
906 bool CSQC_Parse_TempEntity()
909 int nTEID = ReadByte();
911 FOREACH(TempEntities, it.m_id == nTEID, {
912 if (autocvar_developer_csqcentities)
913 LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
914 return it.m_read(NULL, NULL, true);
917 if (autocvar_developer_csqcentities)
918 LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
920 // No special logic for this temporary entity; return 0 so the engine can handle it
927 if (autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
928 localcmd("\nr_drawfog 0\n");
929 else if (forcefog != "")
930 localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog));
933 void Gamemode_Init();
934 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
937 gametype = ReadRegistered(Gametypes);
938 teamplay = _MapInfo_GetTeamPlayBool(gametype);
939 HUD_ModIcons_SetFunc();
940 FOREACH(Scores, true, {
941 if (scores_label(it)) strunzone(scores_label(it));
942 scores_label(it) = strzone(ReadString());
943 scores_flags(it) = ReadByte();
945 for (int i = 0; i < MAX_TEAMSCORE; ++i)
947 if (teamscores_label(i)) strunzone(teamscores_label(i));
948 teamscores_label(i) = strzone(ReadString());
949 teamscores_flags(i) = ReadByte();
952 Scoreboard_InitScores();
956 NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
958 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
960 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
961 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
962 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
963 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
964 arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
965 arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
966 arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
967 arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
969 if (forcefog) strunzone(forcefog);
970 forcefog = strzone(ReadString());
972 armorblockpercent = ReadByte() / 255.0;
974 serverflags = ReadByte();
976 g_trueaim_minrange = ReadCoord();
980 MUTATOR_CALLHOOK(Ent_Init);
982 if (!postinit) PostInit();
985 float GetSpeedUnitFactor(int speed_unit)
997 return 0.0254 * 3.6 * 0.6213711922;
999 return 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
1003 string GetSpeedUnit(int speed_unit)
1021 NET_HANDLE(TE_CSQC_RACE, bool isNew)
1027 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1028 race_checkpoint = ReadByte();
1029 race_time = ReadInt24_t();
1030 race_previousbesttime = ReadInt24_t();
1031 if(race_previousbestname)
1032 strunzone(race_previousbestname);
1033 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1035 race_checkpointtime = time;
1037 if(race_checkpoint == 0 || race_checkpoint == 254)
1039 race_penaltyaccumulator = 0;
1040 race_laptime = time; // valid
1045 case RACE_NET_CHECKPOINT_CLEAR:
1047 race_checkpointtime = 0;
1050 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1051 race_laptime = ReadCoord();
1052 race_checkpointtime = -99999;
1054 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1055 race_nextcheckpoint = ReadByte();
1057 race_nextbesttime = ReadInt24_t();
1058 if(race_nextbestname)
1059 strunzone(race_nextbestname);
1060 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1063 case RACE_NET_CHECKPOINT_HIT_RACE:
1064 race_mycheckpoint = ReadByte();
1065 race_mycheckpointtime = time;
1066 race_mycheckpointdelta = ReadInt24_t();
1067 race_mycheckpointlapsdelta = ReadByte();
1068 if(race_mycheckpointlapsdelta >= 128)
1069 race_mycheckpointlapsdelta -= 256;
1070 if(race_mycheckpointenemy)
1071 strunzone(race_mycheckpointenemy);
1072 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1075 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1076 race_othercheckpoint = ReadByte();
1077 race_othercheckpointtime = time;
1078 race_othercheckpointdelta = ReadInt24_t();
1079 race_othercheckpointlapsdelta = ReadByte();
1080 if(race_othercheckpointlapsdelta >= 128)
1081 race_othercheckpointlapsdelta -= 256;
1082 if(race_othercheckpointenemy)
1083 strunzone(race_othercheckpointenemy);
1084 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1087 case RACE_NET_PENALTY_RACE:
1088 race_penaltyeventtime = time;
1089 race_penaltytime = ReadShort();
1090 //race_penaltyaccumulator += race_penaltytime;
1091 if(race_penaltyreason)
1092 strunzone(race_penaltyreason);
1093 race_penaltyreason = strzone(ReadString());
1096 case RACE_NET_PENALTY_QUALIFYING:
1097 race_penaltyeventtime = time;
1098 race_penaltytime = ReadShort();
1099 race_penaltyaccumulator += race_penaltytime;
1100 if(race_penaltyreason)
1101 strunzone(race_penaltyreason);
1102 race_penaltyreason = strzone(ReadString());
1105 case RACE_NET_SERVER_RECORD:
1106 race_server_record = ReadInt24_t();
1108 case RACE_NET_SPEED_AWARD:
1109 race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit);
1110 if(race_speedaward_holder)
1111 strunzone(race_speedaward_holder);
1112 race_speedaward_holder = strzone(ReadString());
1113 if(race_speedaward_unit)
1114 strunzone(race_speedaward_unit);
1115 race_speedaward_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit));
1117 case RACE_NET_SPEED_AWARD_BEST:
1118 race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit);
1119 if(race_speedaward_alltimebest_holder)
1120 strunzone(race_speedaward_alltimebest_holder);
1121 race_speedaward_alltimebest_holder = strzone(ReadString());
1122 if(race_speedaward_alltimebest_unit)
1123 strunzone(race_speedaward_alltimebest_unit);
1124 race_speedaward_alltimebest_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit));
1126 case RACE_NET_SERVER_RANKINGS:
1128 int pos = ReadShort();
1129 prevpos = ReadShort();
1132 // move other rankings out of the way
1135 for (i=prevpos-1;i>pos-1;--i) {
1136 grecordtime[i] = grecordtime[i-1];
1137 if(grecordholder[i])
1138 strunzone(grecordholder[i]);
1139 grecordholder[i] = strzone(grecordholder[i-1]);
1141 } else if (del) { // a record has been deleted by the admin
1142 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1143 if (i == RANKINGS_CNT-1) { // clear out last record
1145 if (grecordholder[i])
1146 strunzone(grecordholder[i]);
1147 grecordholder[i] = string_null;
1150 grecordtime[i] = grecordtime[i+1];
1151 if (grecordholder[i])
1152 strunzone(grecordholder[i]);
1153 grecordholder[i] = strzone(grecordholder[i+1]);
1156 } else { // player has no ranked record yet
1157 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1158 grecordtime[i] = grecordtime[i-1];
1159 if(grecordholder[i])
1160 strunzone(grecordholder[i]);
1161 grecordholder[i] = strzone(grecordholder[i-1]);
1165 // store new ranking
1166 if(grecordholder[pos-1] != "")
1167 strunzone(grecordholder[pos-1]);
1168 grecordholder[pos-1] = strzone(ReadString());
1169 grecordtime[pos-1] = ReadInt24_t();
1170 if(grecordholder[pos-1] == entcs_GetName(player_localnum))
1173 case RACE_NET_SERVER_STATUS:
1174 race_status = ReadShort();
1175 if(race_status_name)
1176 strunzone(race_status_name);
1177 race_status_name = strzone(ReadString());
1182 NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
1188 NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
1191 int pi = ReadShort();
1192 int pl = ReadByte();
1193 int ml = ReadByte();
1195 entity e = playerslots[i];
1198 e.ping_packetloss = pl / 255.0;
1199 e.ping_movementloss = ml / 255.0;
1202 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
1204 complain_weapon = ReadByte();
1205 complain_weapon_type = ReadByte();
1208 complain_weapon_time = time;
1209 weapontime = time; // ping the weapon panel
1211 switch(complain_weapon_type)
1213 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1214 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1215 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1219 string _getcommandkey(string cmd_name, string command, bool forcename)
1222 float n, j, k, l = 0;
1224 if (!autocvar_hud_showbinds)
1227 keys = db_get(binddb, command);
1230 bool joy_detected = cvar("joy_detected");
1231 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1232 for(j = 0; j < n; ++j)
1237 string key = keynumtostring(k);
1238 if(!joy_detected && substring(key, 0, 3) == "JOY")
1244 keys = strcat(keys, ", ", key);
1247 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1254 db_put(binddb, command, keys);
1257 if (keys == "NO_KEY") {
1258 if (autocvar_hud_showbinds > 1)
1259 return sprintf(_("%s (not bound)"), cmd_name);
1263 else if (autocvar_hud_showbinds > 1 || forcename)
1264 return sprintf("%s (%s)", cmd_name, keys);