3 #include "miscfunctions.qh"
4 #include <common/effects/effect.qh>
5 #include <common/effects/qc/all.qh>
6 #include <common/effects/all.qh>
7 #include <common/effects/all.inc>
9 #include "mapvoting.qh"
10 #include "mutators/events.qh"
11 #include "hud/panel/scoreboard.qh"
12 #include "hud/panel/quickmenu.qh"
13 #include "shownames.qh"
14 #include <common/t_items.qh>
16 #include "weapons/projectile.qh"
17 #include <common/deathtypes/all.qh>
18 #include <common/items/_mod.qh>
19 #include <common/mapinfo.qh>
20 #include <common/minigames/cl_minigames.qh>
21 #include <common/minigames/cl_minigames_hud.qh>
22 #include <common/net_linked.qh>
23 #include <common/net_notice.qh>
24 #include <common/scores.qh>
25 #include <common/triggers/include.qh>
26 #include <common/vehicles/all.qh>
27 #include <lib/csqcmodel/cl_model.qh>
28 #include <lib/csqcmodel/interpolate.qh>
29 #include <lib/warpzone/client.qh>
31 // --------------------------------------------------------------------------
32 // BEGIN REQUIRED CSQC FUNCTIONS
35 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
37 void draw_cursor(vector pos, vector ofs, string img, vector col, float a)
39 ofs = vec2(ofs.x * SIZE_CURSOR.x, ofs.y * SIZE_CURSOR.y);
40 drawpic(pos - ofs, strcat(draw_currentSkin, img), SIZE_CURSOR, col, a, DRAWFLAG_NORMAL);
43 void draw_cursor_normal(vector pos, vector col, float a)
45 draw_cursor(pos, OFFSET_CURSOR, "/cursor", col, a);
48 void LoadMenuSkinValues()
51 if(cvar_string("menu_skin") != "")
53 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
54 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
56 if(fh < 0 && cvar_defstring("menu_skin") != "")
58 cvar_set("menu_skin", cvar_defstring("menu_skin"));
59 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
60 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
64 draw_currentSkin = "gfx/menu/default";
65 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
68 draw_currentSkin = strzone(draw_currentSkin);
73 while((s = fgets(fh)))
75 int n = tokenize_console(s);
78 if(substring(argv(0), 0, 2) == "//")
80 if(argv(0) == "SIZE_CURSOR")
81 SIZE_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
82 else if(argv(0) == "OFFSET_CURSOR")
83 OFFSET_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
89 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
90 // Useful for precaching things
92 void ConsoleCommand_macro_init();
95 prvm_language = strzone(cvar_string("prvm_language"));
98 LOG_INFOF("^4CSQC Build information: ^1%s\n", WATERMARK);
103 for ( ; i < 255; ++i)
104 if (getplayerkeyvalue(i, "viewentity") == "")
109 // needs to be done so early because of the constants they create
112 static_init_precache();
114 binddb = db_create();
115 tempdb = db_create();
116 ClientProgsDB = db_load("client.db");
120 //registercommand("hud_configure");
121 //registercommand("hud_save");
122 //registercommand("menu_action");
124 ConsoleCommand_macro_init();
126 registercvar("hud_usecsqc", "1");
127 registercvar("scoreboard_columns", "default");
129 registercvar("cl_nade_type", "3");
130 registercvar("cl_pokenade_type", "zombie");
132 registercvar("cl_jumpspeedcap_min", "");
133 registercvar("cl_jumpspeedcap_max", "");
135 registercvar("cl_multijump", "1");
137 registercvar("cl_spawn_near_teammate", "1");
139 if(autocvar_cl_lockview)
140 cvar_set("cl_lockview", "0");
148 teams = Sort_Spawn();
149 players = Sort_Spawn();
151 GetTeam(NUM_SPECTATOR, true); // add specs first
155 if(autocvar_cl_reticle)
157 precache_pic("gfx/reticle_normal");
158 // weapon reticles are precached in weapon files
162 get_mi_min_max_texcoords(1); // try the CLEVER way first
163 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
164 shortmapname = mi_shortname;
166 if (precache_pic(minimapname) == "")
168 // but maybe we have a non-clever minimap
169 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
170 if (precache_pic(minimapname) == "")
171 minimapname = ""; // FAIL
173 get_mi_min_max_texcoords(0); // load new texcoords
176 mi_center = (mi_min + mi_max) * 0.5;
177 mi_scale = mi_max - mi_min;
178 minimapname = strzone(minimapname);
181 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
182 LoadMenuSkinValues();
185 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
194 if(autocvar_cl_db_saveasdump)
195 db_dump(ClientProgsDB, "client.db");
197 db_save(ClientProgsDB, "client.db");
198 db_close(ClientProgsDB);
201 cvar_set("chase_active",ftos(chase_active_backup));
203 // unset the event chasecam's chase_active
204 if(autocvar_chase_active < 0)
205 cvar_set("chase_active", "0");
207 cvar_set("slowmo", cvar_defstring("slowmo")); // reset it back to 'default'
211 if (!(calledhooks & HOOK_START))
212 localcmd("\n_cl_hook_gamestart nop\n");
213 if (!(calledhooks & HOOK_END))
214 localcmd("\ncl_hook_gameend\n");
217 localcmd("\ncl_hook_shutdown\n");
219 deactivate_minigame();
220 HUD_MinigameMenu_Close(NULL, NULL, NULL);
224 float SetTeam(entity o, int Team)
227 devassert_once(Team);
240 if(GetTeam(Team, false) == NULL)
242 LOG_TRACEF("trying to switch to unsupported team %d", Team);
243 Team = NUM_SPECTATOR;
256 if(GetTeam(Team, false) == NULL)
258 LOG_TRACEF("trying to switch to unsupported team %d", Team);
259 Team = NUM_SPECTATOR;
264 if(Team == -1) // leave
268 tm = GetTeam(o.team, false);
279 tm = GetTeam(Team, true);
284 else if(Team != o.team)
286 tm = GetTeam(o.team, false);
289 tm = GetTeam(Team, true);
297 void Playerchecker_Think(entity this)
301 for(i = 0; i < maxclients; ++i)
304 if(entcs_GetName(i) == "")
308 // player disconnected
322 playerslots[i] = e = new_pure(playerslot);
326 e.ping_packetloss = 0;
327 e.ping_movementloss = 0;
328 //e.gotscores = 0; // we might already have the scores...
329 int t = entcs_GetScoreTeam(i);
330 if (t) SetTeam(e, t); // will not hurt; later updates come with Scoreboard_UpdatePlayerTeams
332 Scoreboard_UpdatePlayerPos(e);
336 this.nextthink = time + 0.2;
342 entity playerchecker = new_pure(playerchecker);
343 setthink(playerchecker, Playerchecker_Think);
344 playerchecker.nextthink = time + 0.2;
351 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
352 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
353 // All keys are in ascii.
354 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
355 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
356 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
357 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
358 float CSQC_InputEvent(int bInputType, float nPrimary, float nSecondary)
361 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
364 if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
367 if (HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary))
370 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
373 if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
379 // END REQUIRED CSQC FUNCTIONS
380 // --------------------------------------------------------------------------
382 // --------------------------------------------------------------------------
383 // BEGIN OPTIONAL CSQC FUNCTIONS
385 void Ent_Remove(entity this);
387 void Ent_RemovePlayerScore(entity this)
390 SetTeam(this.owner, -1);
391 this.owner.gotscores = 0;
392 FOREACH(Scores, true, {
393 this.owner.(scores(it)) = 0; // clear all scores
398 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
403 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
404 // (no I've never heard of M-x replace-string, sed, or anything like that)
405 bool isNew = !this.owner; // workaround for DP bug
406 int n = ReadByte()-1;
408 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
409 if(!isNew && n != this.sv_entnum)
411 //print("A CSQC entity changed its owner!\n");
412 LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", etof(this), this.classname);
420 o = playerslots[this.sv_entnum];
423 o = playerslots[this.sv_entnum] = new_pure(playerslot);
426 o.sv_entnum = this.sv_entnum;
430 // RegisterPlayer(o);
431 //playerchecker will do this for us later, if it has not already done so
436 FOREACH(Scores, true, {
437 int p = 1 << (i % 16);
441 o.(scores(it)) = ReadInt24_t();
443 o.(scores(it)) = ReadChar();
450 Scoreboard_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
452 this.entremove = Ent_RemovePlayerScore;
455 NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
461 this.team = ReadByte();
462 o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
465 #if MAX_TEAMSCORE <= 8
473 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
477 o.(teamscores(i)) = ReadInt24_t();
479 o.(teamscores(i)) = ReadChar();
484 Scoreboard_UpdateTeamPos(o);
487 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
490 float newspectatee_status;
494 scoreboard_showscores_force = (f & 1);
498 newspectatee_status = ReadByte();
499 if(newspectatee_status == player_localnum + 1)
500 newspectatee_status = -1; // observing
503 newspectatee_status = 0;
505 spectatorbutton_zoom = (f & 4);
509 num_spectators = ReadByte();
513 for(i = 0; i < MAX_SPECTATORS; ++i)
514 spectatorlist[i] = 0; // reset list first
516 for(i = 0; i < num_spectators; ++i)
519 spectatorlist[i] = slot - 1;
525 if(newspectatee_status != spectatee_status)
529 race_checkpointtime = 0;
530 hud_dynamic_shake_factor = -1;
532 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
534 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
535 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
538 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
541 spectatee_status = newspectatee_status;
543 // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
546 NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
551 int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
556 strunzone(vote_called_vote);
557 vote_called_vote = string_null;
567 vote_yescount = ReadByte();
568 vote_nocount = ReadByte();
569 vote_needed = ReadByte();
570 vote_highlighted = ReadChar();
576 strunzone(vote_called_vote);
577 vote_called_vote = strzone(ReadString());
582 for(j = 0; j < maxclients; ++j)
584 playerslots[j].ready = 1;
585 for(i = 1; i <= maxclients; i += 8)
588 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
591 playerslots[j].ready = 0;
597 ready_waiting = (nags & BIT(0));
598 ready_waiting_for_me = (nags & BIT(1));
599 vote_waiting = (nags & BIT(2));
600 vote_waiting_for_me = (nags & BIT(3));
601 warmup_stage = (nags & BIT(4));
604 NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
612 for(j = 0; j < maxclients; ++j)
614 playerslots[j].eliminated = 1;
615 for(i = 1; i <= maxclients; i += 8)
618 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
621 playerslots[j].eliminated = 0;
627 NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
631 float s = ReadShort();
636 NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
639 int sf = ReadInt24_t();
641 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
642 weapon_accuracy[w] = -1;
647 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
651 weapon_accuracy[w] = -1;
653 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
655 weapon_accuracy[w] = (b - 1.0) / 100.0;
657 f = (f == 0x800000) ? 1 : f * 2;
662 void Spawn_Draw(entity this)
667 __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
670 void Spawn_PreDraw(entity this)
673 vector org = getpropertyvec(VF_ORIGIN);
676 if(vdist(org - this.origin, >, this.fade_end))
677 alph = 0; // save on some processing
678 else if(vdist(org - this.origin, <, this.fade_start))
679 alph = 1; // more processing saved
681 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
685 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
690 this.drawmask = MASK_NORMAL;
693 NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
695 float teamnum = (ReadByte() - 1);
697 spn_origin.x = ReadCoord();
698 spn_origin.y = ReadCoord();
699 spn_origin.z = ReadCoord();
701 this.team = (teamnum + 1);
705 this.origin = spn_origin;
706 setsize(this, PL_MIN_CONST, PL_MAX_CONST);
709 /*if(autocvar_cl_spawn_point_model) // needs a model first
711 this.mdl = "models/spawnpoint.md3";
712 this.colormod = Team_ColorRGB(teamnum);
713 precache_model(this.mdl);
714 setmodel(this, this.mdl);
715 this.drawmask = MASK_NORMAL;
716 //this.move_movetype = MOVETYPE_NOCLIP;
717 //this.draw = Spawn_Draw;
718 IL_PUSH(g_drawables, this);
720 if(autocvar_cl_spawn_point_particles)
726 case NUM_TEAM_1: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
727 case NUM_TEAM_2: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
728 case NUM_TEAM_3: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
729 case NUM_TEAM_4: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
730 default: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
733 else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
735 this.draw = Spawn_Draw;
736 if (is_new) IL_PUSH(g_drawables, this);
737 setpredraw(this, Spawn_PreDraw);
738 this.fade_start = autocvar_cl_spawn_point_dist_min;
739 this.fade_end = autocvar_cl_spawn_point_dist_max;
743 //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(this.origin), teamnum, this.cnt);
747 NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
749 // If entnum is 0, ONLY do the local spawn actions
750 // this way the server can disable the sending of
751 // spawn origin or such to clients if wanted.
752 float entnum = ReadByte();
756 this.origin_x = ReadCoord();
757 this.origin_y = ReadCoord();
758 this.origin_z = ReadCoord();
762 float teamnum = entcs_GetTeam(entnum - 1);
764 if(autocvar_cl_spawn_event_particles)
768 case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break;
769 case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break;
770 case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break;
771 case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break;
772 default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break;
775 if(autocvar_cl_spawn_event_sound)
777 sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
783 // local spawn actions
784 if(is_new && (!entnum || (entnum == player_localentnum)))
787 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
789 if(autocvar_cl_unpress_zoom_on_spawn)
794 HUD_Radar_Hide_Maximized();
796 //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum);
799 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
800 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
801 void CSQC_Ent_Update(entity this, bool isnew)
803 this.sourceLoc = __FILE__ ":" STR(__LINE__);
806 // set up the "time" global for received entities to be correct for interpolation purposes
807 float savetime = time;
814 serverprevtime = time;
815 serverdeltatime = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
816 time = serverprevtime + serverdeltatime;
819 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
822 if (t != this.enttype || isnew)
824 LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", etof(this), this.entnum, this.enttype, t);
834 LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", etof(this), this.entnum, t);
841 FOREACH(LinkedEntities, it.m_id == t, {
842 if (isnew) this.classname = it.netname;
843 if (autocvar_developer_csqcentities)
844 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);
845 done = it.m_read(this, NULL, isnew);
846 MUTATOR_CALLHOOK(Ent_Update, this, isnew);
852 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);
856 // Destructor, but does NOT deallocate the entity by calling remove(). Also
857 // used when an entity changes its type. For an entity that someone interacts
858 // with others, make sure it can no longer do so.
859 void Ent_Remove(entity this)
861 if(this.entremove) this.entremove(this);
863 if(this.skeletonindex)
865 skel_delete(this.skeletonindex);
866 this.skeletonindex = 0;
869 if(this.snd_looping > 0)
871 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation);
872 this.snd_looping = 0;
877 this.draw = func_null;
878 this.entremove = func_null;
879 // TODO possibly set more stuff to defaults
881 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(this) as well.
882 void CSQC_Ent_Remove(entity this)
884 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype);
887 LOG_WARN("CSQC_Ent_Remove called for already removed entity. Packet loss?");
890 if (this.enttype) Ent_Remove(this);
898 if(!(calledhooks & HOOK_START))
899 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
900 calledhooks |= HOOK_START;
903 // 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.
904 void CSQC_Parse_StuffCmd(string strMessage)
906 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
907 localcmd(strMessage);
909 // 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.
910 void CSQC_Parse_Print(string strMessage)
912 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
913 print(ColorTranslateRGB(strMessage));
916 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
917 void CSQC_Parse_CenterPrint(string strMessage)
919 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
920 centerprint_hud(strMessage);
923 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
924 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
925 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
926 bool CSQC_Parse_TempEntity()
929 int nTEID = ReadByte();
931 FOREACH(TempEntities, it.m_id == nTEID, {
932 if (autocvar_developer_csqcentities)
933 LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
934 return it.m_read(NULL, NULL, true);
937 if (autocvar_developer_csqcentities)
938 LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
940 // No special logic for this temporary entity; return 0 so the engine can handle it
947 if (autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
948 localcmd("\nr_drawfog 0\n");
949 else if (forcefog != "")
950 localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog));
953 void Gamemode_Init();
954 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
957 gametype = ReadRegistered(Gametypes);
958 teamplay = _MapInfo_GetTeamPlayBool(gametype);
959 HUD_ModIcons_SetFunc();
960 FOREACH(Scores, true, {
961 if (scores_label(it)) strunzone(scores_label(it));
962 scores_label(it) = strzone(ReadString());
963 scores_flags(it) = ReadByte();
965 for (int i = 0; i < MAX_TEAMSCORE; ++i)
967 if (teamscores_label(i)) strunzone(teamscores_label(i));
968 teamscores_label(i) = strzone(ReadString());
969 teamscores_flags(i) = ReadByte();
972 Scoreboard_InitScores();
976 NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
978 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
980 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
981 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
982 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
983 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
984 arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
985 arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
986 arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
987 arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
989 if (forcefog) strunzone(forcefog);
990 forcefog = strzone(ReadString());
992 armorblockpercent = ReadByte() / 255.0;
993 damagepush_speedfactor = ReadByte() / 255.0;
995 serverflags = ReadByte();
997 g_trueaim_minrange = ReadCoord();
1001 MUTATOR_CALLHOOK(Ent_Init);
1003 if (!postinit) PostInit();
1006 float GetSpeedUnitFactor(int speed_unit)
1016 return 0.0254 * 3.6;
1018 return 0.0254 * 3.6 * 0.6213711922;
1020 return 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
1024 string GetSpeedUnit(int speed_unit)
1042 NET_HANDLE(TE_CSQC_RACE, bool isNew)
1048 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1049 race_checkpoint = ReadByte();
1050 race_time = ReadInt24_t();
1051 race_previousbesttime = ReadInt24_t();
1052 race_mypreviousbesttime = ReadInt24_t();
1053 if(race_previousbestname)
1054 strunzone(race_previousbestname);
1055 string pbestname = ReadString();
1056 if(autocvar_cl_race_cptimes_onlyself)
1058 race_previousbesttime = race_mypreviousbesttime;
1059 race_mypreviousbesttime = 0;
1060 race_previousbestname = strzone("");
1063 race_previousbestname = strzone(pbestname);
1065 race_checkpointtime = time;
1067 if(race_checkpoint == 0 || race_checkpoint == 254)
1069 race_penaltyaccumulator = 0;
1070 race_laptime = time; // valid
1074 case RACE_NET_CHECKPOINT_CLEAR:
1076 race_checkpointtime = 0;
1079 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1080 race_laptime = ReadCoord();
1081 race_checkpointtime = -99999;
1083 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1084 race_nextcheckpoint = ReadByte();
1086 race_nextbesttime = ReadInt24_t();
1087 if(b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING) // not while spectating (matches server)
1088 race_mybesttime = ReadInt24_t();
1089 if(race_nextbestname)
1090 strunzone(race_nextbestname);
1091 string newname = ReadString();
1092 if(autocvar_cl_race_cptimes_onlyself && b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING)
1094 race_nextbesttime = race_mybesttime;
1095 race_mybesttime = 0;
1096 race_nextbestname = strzone("");
1099 race_nextbestname = strzone(newname);
1102 case RACE_NET_CHECKPOINT_HIT_RACE:
1103 race_mycheckpoint = ReadByte();
1104 race_mycheckpointtime = time;
1105 race_mycheckpointdelta = ReadInt24_t();
1106 race_mycheckpointlapsdelta = ReadByte();
1107 if(race_mycheckpointlapsdelta >= 128)
1108 race_mycheckpointlapsdelta -= 256;
1109 if(race_mycheckpointenemy)
1110 strunzone(race_mycheckpointenemy);
1111 int who = ReadByte();
1113 race_mycheckpointenemy = strzone(entcs_GetName(who - 1));
1115 race_mycheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
1118 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1119 race_othercheckpoint = ReadByte();
1120 race_othercheckpointtime = time;
1121 race_othercheckpointdelta = ReadInt24_t();
1122 race_othercheckpointlapsdelta = ReadByte();
1123 if(race_othercheckpointlapsdelta >= 128)
1124 race_othercheckpointlapsdelta -= 256;
1125 if(race_othercheckpointenemy)
1126 strunzone(race_othercheckpointenemy);
1127 int what = ReadByte();
1129 race_othercheckpointenemy = strzone(entcs_GetName(what - 1));
1131 race_othercheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
1134 case RACE_NET_PENALTY_RACE:
1135 race_penaltyeventtime = time;
1136 race_penaltytime = ReadShort();
1137 //race_penaltyaccumulator += race_penaltytime;
1138 if(race_penaltyreason)
1139 strunzone(race_penaltyreason);
1140 race_penaltyreason = strzone(ReadString());
1143 case RACE_NET_PENALTY_QUALIFYING:
1144 race_penaltyeventtime = time;
1145 race_penaltytime = ReadShort();
1146 race_penaltyaccumulator += race_penaltytime;
1147 if(race_penaltyreason)
1148 strunzone(race_penaltyreason);
1149 race_penaltyreason = strzone(ReadString());
1152 case RACE_NET_SERVER_RECORD:
1153 race_server_record = ReadInt24_t();
1155 case RACE_NET_SPEED_AWARD:
1156 race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit);
1157 if(race_speedaward_holder)
1158 strunzone(race_speedaward_holder);
1159 race_speedaward_holder = strzone(ReadString());
1160 if(race_speedaward_unit)
1161 strunzone(race_speedaward_unit);
1162 race_speedaward_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit));
1164 case RACE_NET_SPEED_AWARD_BEST:
1165 race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit);
1166 if(race_speedaward_alltimebest_holder)
1167 strunzone(race_speedaward_alltimebest_holder);
1168 race_speedaward_alltimebest_holder = strzone(ReadString());
1169 if(race_speedaward_alltimebest_unit)
1170 strunzone(race_speedaward_alltimebest_unit);
1171 race_speedaward_alltimebest_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit));
1173 case RACE_NET_SERVER_RANKINGS:
1175 int pos = ReadShort();
1176 prevpos = ReadShort();
1179 // move other rankings out of the way
1182 for (i=prevpos-1;i>pos-1;--i) {
1183 grecordtime[i] = grecordtime[i-1];
1184 if(grecordholder[i])
1185 strunzone(grecordholder[i]);
1186 grecordholder[i] = strzone(grecordholder[i-1]);
1188 } else if (del) { // a record has been deleted by the admin
1189 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1190 if (i == RANKINGS_CNT-1) { // clear out last record
1192 if (grecordholder[i])
1193 strunzone(grecordholder[i]);
1194 grecordholder[i] = string_null;
1197 grecordtime[i] = grecordtime[i+1];
1198 if (grecordholder[i])
1199 strunzone(grecordholder[i]);
1200 grecordholder[i] = strzone(grecordholder[i+1]);
1203 } else { // player has no ranked record yet
1204 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1205 grecordtime[i] = grecordtime[i-1];
1206 if(grecordholder[i])
1207 strunzone(grecordholder[i]);
1208 grecordholder[i] = strzone(grecordholder[i-1]);
1212 // store new ranking
1213 if(grecordholder[pos-1] != "")
1214 strunzone(grecordholder[pos-1]);
1215 grecordholder[pos-1] = strzone(ReadString());
1216 grecordtime[pos-1] = ReadInt24_t();
1217 if(strdecolorize(grecordholder[pos-1]) == strdecolorize(entcs_GetName(player_localnum)))
1220 case RACE_NET_SERVER_STATUS:
1221 race_status = ReadShort();
1222 if(race_status_name)
1223 strunzone(race_status_name);
1224 race_status_name = strzone(ReadString());
1229 NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
1235 NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
1238 int pi = ReadShort();
1239 int pl = ReadByte();
1240 int ml = ReadByte();
1242 entity e = playerslots[i];
1245 e.ping_packetloss = pl / 255.0;
1246 e.ping_movementloss = ml / 255.0;
1249 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
1251 complain_weapon = ReadByte();
1252 complain_weapon_type = ReadByte();
1255 complain_weapon_time = time;
1256 weapontime = time; // ping the weapon panel
1258 switch(complain_weapon_type)
1260 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1261 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1262 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1266 string _getcommandkey(string cmd_name, string command, bool forcename)
1269 float n, j, k, l = 0;
1271 if (!autocvar_hud_showbinds)
1274 keys = db_get(binddb, command);
1277 bool joy_active = cvar("joy_active");
1278 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1279 for(j = 0; j < n; ++j)
1284 string key = keynumtostring(k);
1285 if(!joy_active && substring(key, 0, 3) == "JOY")
1291 keys = strcat(keys, ", ", key);
1294 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1301 db_put(binddb, command, keys);
1304 if (keys == "NO_KEY") {
1305 if (autocvar_hud_showbinds > 1)
1306 return sprintf(_("%s (not bound)"), cmd_name);
1310 else if (autocvar_hud_showbinds > 1 || forcename)
1311 return sprintf("%s (%s)", cmd_name, keys);