3 #include "controlpoint.qh"
6 #include "generator.qh"
11 #include "mapvoting.qh"
12 #include "modeleffects.qh"
13 #include "mutators/events.qh"
14 #include "particles.qh"
15 #include "quickmenu.qh"
16 #include "scoreboard.qh"
17 #include "shownames.qh"
21 #include "weapons/projectile.qh"
22 #include "../common/deathtypes/all.qh"
23 #include "../common/items/all.qh"
24 #include "../common/mapinfo.qh"
25 #include "../common/minigames/cl_minigames.qh"
26 #include "../common/minigames/cl_minigames_hud.qh"
27 #include "../common/net_notice.qh"
28 #include "../common/triggers/include.qh"
29 #include "../common/turrets/cl_turrets.qh"
30 #include "../common/vehicles/all.qh"
31 #include "../lib/csqcmodel/cl_model.qh"
32 #include "../lib/csqcmodel/interpolate.qh"
33 #include "../lib/warpzone/client.qh"
35 // --------------------------------------------------------------------------
36 // BEGIN REQUIRED CSQC FUNCTIONS
39 entity clearentity_ent;
40 void clearentity(entity e)
44 clearentity_ent = new(clearentity);
47 copyentity(clearentity_ent, e);
51 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
52 void menu_show_error()
54 drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
57 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
58 // Useful for precaching things
64 void draw_null(entity this) { }
67 void ConsoleCommand_macro_init();
70 prvm_language = strzone(cvar_string("prvm_language"));
73 LOG_TRACEF("^4CSQC Build information: ^1%s\n", WATERMARK);
80 ClientProgsDB = db_load("client.db");
81 compressShortVector_init();
85 menu_show = menu_show_error;
86 menu_action = func_null;
88 for(i = 0; i < 255; ++i)
89 if(getplayerkeyvalue(i, "viewentity") == "")
93 //registercommand("hud_configure");
94 //registercommand("hud_save");
95 //registercommand("menu_action");
97 ConsoleCommand_macro_init();
99 registercvar("hud_usecsqc", "1");
100 registercvar("scoreboard_columns", "default");
102 registercvar("cl_nade_type", "3");
103 registercvar("cl_pokenade_type", "zombie");
105 registercvar("cl_jumpspeedcap_min", "");
106 registercvar("cl_jumpspeedcap_max", "");
108 registercvar("cl_multijump", "0");
110 registercvar("cl_spawn_near_teammate", "1");
114 // hud_fields uses strunzone on the titles!
115 for(i = 0; i < MAX_HUD_FIELDS; ++i)
116 hud_title[i] = strzone("(null)");
118 Cmd_HUD_SetFields(0);
124 teams = Sort_Spawn();
125 players = Sort_Spawn();
127 GetTeam(NUM_SPECTATOR, true); // add specs first
129 // needs to be done so early because of the constants they create
132 static_init_precache();
136 Projectile_Precache();
139 if(autocvar_cl_reticle)
141 precache_pic("gfx/reticle_normal");
142 // weapon reticles are precached in weapon files
145 get_mi_min_max_texcoords(1); // try the CLEVER way first
146 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
147 shortmapname = mi_shortname;
149 if(precache_pic(minimapname) == "")
151 // but maybe we have a non-clever minimap
152 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
153 if(precache_pic(minimapname) == "")
154 minimapname = ""; // FAIL
156 get_mi_min_max_texcoords(0); // load new texcoords
159 mi_center = (mi_min + mi_max) * 0.5;
160 mi_scale = mi_max - mi_min;
161 minimapname = strzone(minimapname);
165 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
166 draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
169 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
178 if(autocvar_cl_db_saveasdump)
179 db_dump(ClientProgsDB, "client.db");
181 db_save(ClientProgsDB, "client.db");
182 db_close(ClientProgsDB);
185 cvar_set("chase_active",ftos(chase_active_backup));
187 // unset the event chasecam's chase_active
188 if(autocvar_chase_active < 0)
189 cvar_set("chase_active", "0");
193 if (!(calledhooks & HOOK_START))
194 localcmd("\n_cl_hook_gamestart nop\n");
195 if (!(calledhooks & HOOK_END))
196 localcmd("\ncl_hook_gameend\n");
199 deactivate_minigame();
200 HUD_MinigameMenu_Close();
204 float SetTeam(entity o, int Team)
218 if(GetTeam(Team, false) == world)
220 LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
221 Team = NUM_SPECTATOR;
234 if(GetTeam(Team, false) == world)
236 LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
237 Team = NUM_SPECTATOR;
242 if(Team == -1) // leave
246 tm = GetTeam(o.team, false);
257 tm = GetTeam(Team, true);
262 else if(Team != o.team)
264 tm = GetTeam(o.team, false);
267 tm = GetTeam(Team, true);
275 void Playerchecker_Think()
279 for(i = 0; i < maxclients; ++i)
282 if(GetPlayerName(i) == "")
286 // player disconnected
300 playerslots[i] = e = new(playerslot);
305 e.ping_packetloss = 0;
306 e.ping_movementloss = 0;
307 //e.gotscores = 0; // we might already have the scores...
308 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
310 HUD_UpdatePlayerPos(e);
314 self.nextthink = time + 0.2;
321 entity playerchecker = new(playerchecker);
322 make_pure(playerchecker);
323 playerchecker.think = Playerchecker_Think;
324 playerchecker.nextthink = time + 0.2;
332 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
333 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
334 // All keys are in ascii.
335 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
336 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
337 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
338 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
339 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
344 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
347 if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
350 if ( HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary) )
353 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
356 if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
359 if(menu_visible && menu_action)
360 if(menu_action(bInputType, nPrimary, nSecondary))
366 // END REQUIRED CSQC FUNCTIONS
367 // --------------------------------------------------------------------------
369 // --------------------------------------------------------------------------
370 // BEGIN OPTIONAL CSQC FUNCTIONS
372 void Ent_RemoveEntCS()
374 entcs_receiver[self.sv_entnum] = NULL;
379 this.classname = "entcs_receiver";
380 InterpolateOrigin_Undo();
384 self.sv_entnum = ReadByte();
387 self.origin_x = ReadShort();
388 self.origin_y = ReadShort();
389 self.origin_z = ReadShort();
390 setorigin(self, self.origin);
394 self.angles_y = ReadByte() * 360.0 / 256;
395 self.angles_x = self.angles_z = 0;
398 self.healthvalue = ReadByte() * 10;
400 self.armorvalue = ReadByte() * 10;
402 entcs_receiver[self.sv_entnum] = self;
403 self.entremove = Ent_RemoveEntCS;
404 self.iflags |= IFLAG_ORIGIN;
406 InterpolateOrigin_Note();
411 void Ent_RemovePlayerScore()
414 SetTeam(self.owner, -1);
415 self.owner.gotscores = 0;
416 for(int i = 0; i < MAX_SCORE; ++i) {
417 self.owner.(scores[i]) = 0; // clear all scores
422 void Ent_ReadPlayerScore()
429 // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
430 // (no I've never heard of M-x replace-string, sed, or anything like that)
431 isNew = !self.owner; // workaround for DP bug
434 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
435 if(!isNew && n != self.sv_entnum)
437 //print("A CSQC entity changed its owner!\n");
438 LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(self), self.classname);
446 o = playerslots[self.sv_entnum];
449 o = playerslots[self.sv_entnum] = new(playerslot);
453 o.sv_entnum = self.sv_entnum;
457 // RegisterPlayer(o);
458 //playerchecker will do this for us later, if it has not already done so
469 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
473 o.(scores[i]) = ReadInt24_t();
475 o.(scores[i]) = ReadChar();
479 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
481 self.entremove = Ent_RemovePlayerScore;
484 void Ent_ReadTeamScore()
490 self.team = ReadByte();
491 o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
494 #if MAX_TEAMSCORE <= 8
502 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
506 o.(teamscores[i]) = ReadInt24_t();
508 o.(teamscores[i]) = ReadChar();
511 HUD_UpdateTeamPos(o);
514 void Ent_ClientData()
517 float newspectatee_status;
521 scoreboard_showscores_force = (f & 1);
525 newspectatee_status = ReadByte();
526 if(newspectatee_status == player_localnum + 1)
527 newspectatee_status = -1; // observing
530 newspectatee_status = 0;
532 spectatorbutton_zoom = (f & 4);
536 angles_held_status = 1;
537 angles_held.x = ReadAngle();
538 angles_held.y = ReadAngle();
542 angles_held_status = 0;
544 if(newspectatee_status != spectatee_status)
548 race_checkpointtime = 0;
550 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
552 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
553 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
556 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
559 spectatee_status = newspectatee_status;
561 // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
569 int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
574 strunzone(vote_called_vote);
575 vote_called_vote = string_null;
585 vote_yescount = ReadByte();
586 vote_nocount = ReadByte();
587 vote_needed = ReadByte();
588 vote_highlighted = ReadChar();
594 strunzone(vote_called_vote);
595 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
600 for(j = 0; j < maxclients; ++j)
602 playerslots[j].ready = 1;
603 for(i = 1; i <= maxclients; i += 8)
606 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
609 playerslots[j].ready = 0;
613 ready_waiting = (nags & BIT(0));
614 ready_waiting_for_me = (nags & BIT(1));
615 vote_waiting = (nags & BIT(2));
616 vote_waiting_for_me = (nags & BIT(3));
617 warmup_stage = (nags & BIT(4));
620 void Ent_EliminatedPlayers()
628 for(j = 0; j < maxclients; ++j)
630 playerslots[j].eliminated = 1;
631 for(i = 1; i <= maxclients; i += 8)
634 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
637 playerslots[j].eliminated = 0;
642 void Ent_RandomSeed()
646 float s = ReadShort();
650 void Ent_ReadAccuracy()
653 int sf = ReadInt24_t();
655 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
656 weapon_accuracy[w] = -1;
661 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
665 weapon_accuracy[w] = -1;
667 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
669 weapon_accuracy[w] = (b - 1.0) / 100.0;
671 f = (f == 0x800000) ? 1 : f * 2;
675 void Spawn_Draw(entity this)
677 __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
680 void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
682 float teamnum = (ReadByte() - 1);
684 spn_origin.x = ReadShort();
685 spn_origin.y = ReadShort();
686 spn_origin.z = ReadShort();
690 self.origin = spn_origin;
691 setsize(self, PL_MIN_CONST, PL_MAX_CONST);
694 /*if(autocvar_cl_spawn_point_model) // needs a model first
696 self.mdl = "models/spawnpoint.md3";
697 self.colormod = Team_ColorRGB(teamnum);
698 precache_model(self.mdl);
699 setmodel(self, self.mdl);
700 self.drawmask = MASK_NORMAL;
701 //self.movetype = MOVETYPE_NOCLIP;
702 //self.draw = Spawn_Draw;
704 if(autocvar_cl_spawn_point_particles)
706 if((serverflags & SERVERFLAG_TEAMPLAY))
710 case NUM_TEAM_1: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
711 case NUM_TEAM_2: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
712 case NUM_TEAM_3: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
713 case NUM_TEAM_4: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
714 default: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
717 else { self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
719 self.draw = Spawn_Draw;
723 //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(self.origin), teamnum, self.cnt);
726 void Ent_ReadSpawnEvent(float is_new)
728 // If entnum is 0, ONLY do the local spawn actions
729 // this way the server can disable the sending of
730 // spawn origin or such to clients if wanted.
731 float entnum = ReadByte();
735 self.origin_x = ReadShort();
736 self.origin_y = ReadShort();
737 self.origin_z = ReadShort();
741 float teamnum = GetPlayerColor(entnum - 1);
743 if(autocvar_cl_spawn_event_particles)
747 case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, self.origin, '0 0 0', 1); break;
748 case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, self.origin, '0 0 0', 1); break;
749 case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, self.origin, '0 0 0', 1); break;
750 case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, self.origin, '0 0 0', 1); break;
751 default: pointparticles(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1); break;
754 if(autocvar_cl_spawn_event_sound)
756 sound(self, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
761 // local spawn actions
762 if(is_new && (!entnum || (entnum == player_localentnum)))
765 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
767 if(autocvar_cl_unpress_zoom_on_spawn)
773 HUD_Radar_Hide_Maximized();
774 //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum);
777 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
778 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
779 void Ent_RadarLink();
781 void Ent_ScoresInfo();
782 void CSQC_Ent_Update(float bIsNewEntity)
785 this.sourceLocLine = __LINE__;
786 this.sourceLocFile = __FILE__;
789 // set up the "time" global for received entities to be correct for interpolation purposes
790 float savetime = time;
797 serverprevtime = time;
798 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
799 time = serverprevtime + serverdeltatime;
802 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
805 if(t != this.enttype || bIsNewEntity)
807 LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(this), this.entnum, this.enttype, t);
817 LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(this), this.entnum, t);
824 FOREACH(LinkedEntities, it.m_id == t, LAMBDA(
825 this.classname = it.netname;
826 if (autocvar_developer_csqcentities)
827 LOG_INFOF("CSQC_Ent_Update(%d) with self=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", bIsNewEntity, this, this.entnum, this.enttype, it.netname, t);
828 done = it.m_read(this, bIsNewEntity);
834 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), this.enttype));
835 error(sprintf("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n", this.enttype, num_for_edict(this), this.classname));
838 NET_HANDLE(ENT_CLIENT_ENTCS, bool isnew)
843 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
845 Ent_ReadPlayerScore();
848 NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
853 NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew)
855 Ent_PointParticles();
858 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
863 NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
868 NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
873 NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
875 Ent_EliminatedPlayers();
878 NET_HANDLE(ENT_CLIENT_RADARLINK, bool isnew)
883 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
888 NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isnew)
890 Ent_DamageInfo(isnew);
893 NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
898 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
903 NET_HANDLE(ENT_CLIENT_MAPVOTE, bool isnew)
908 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
913 NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
918 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
923 NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew)
925 Ent_ModelEffect(isnew);
928 NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isnew)
933 NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew)
935 WarpZone_Read(isnew);
938 NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew)
940 WarpZone_Camera_Read(isnew);
943 NET_HANDLE(ENT_CLIENT_WARPZONE_TELEPORTED, bool isnew)
945 WarpZone_Teleported_Read(isnew);
948 NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
950 Ent_ReadTriggerMusic();
953 NET_HANDLE(ENT_CLIENT_HOOK, bool isnew)
955 Ent_ReadHook(isnew, NET_ENT_CLIENT_HOOK);
958 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
960 Inventory_Read(this);
963 NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew)
965 Ent_ReadArcBeam(isnew);
968 NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
973 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
978 NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
983 NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
988 NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
993 NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
995 CSQCModel_Read(isnew);
998 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
1003 NET_HANDLE(ENT_CLIENT_BUMBLE_RAYGUN, bool isnew)
1005 bumble_raygun_read(isnew);
1008 NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool isnew)
1010 Ent_ReadSpawnPoint(isnew);
1013 NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool isnew)
1015 Ent_ReadSpawnEvent(isnew);
1018 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool isnew)
1020 Read_Notification(isnew);
1023 NET_HANDLE(ENT_CLIENT_MINIGAME, bool isnew)
1025 ent_read_minigame();
1028 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
1033 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
1035 ent_viewloc_trigger();
1038 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
1043 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
1048 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
1053 NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
1058 NET_HANDLE(ENT_CLIENT_DOOR, bool isnew)
1063 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
1068 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
1073 NET_HANDLE(ENT_CLIENT_CORNER, bool isnew)
1078 NET_HANDLE(ENT_CLIENT_KEYLOCK, bool isnew)
1083 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
1088 NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew)
1090 ent_trigger_impulse();
1094 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1095 // used when an entity changes its type. For an entity that someone interacts
1096 // with others, make sure it can no longer do so.
1102 if(self.skeletonindex)
1104 skel_delete(self.skeletonindex);
1105 self.skeletonindex = 0;
1108 if(self.snd_looping > 0)
1110 sound(self, self.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
1111 self.snd_looping = 0;
1115 self.classname = "";
1116 self.draw = draw_null;
1117 self.entremove = menu_sub_null;
1118 // TODO possibly set more stuff to defaults
1120 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
1121 void CSQC_Ent_Remove()
1123 if(autocvar_developer_csqcentities)
1124 LOG_INFOF("CSQC_Ent_Remove() with self=%i self.entnum=%d self.enttype=%d\n", self, self.entnum, self.enttype);
1128 LOG_INFO("WARNING: CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
1136 void Gamemode_Init()
1140 if(!(calledhooks & HOOK_START))
1141 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
1142 calledhooks |= HOOK_START;
1145 // 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.
1146 void CSQC_Parse_StuffCmd(string strMessage)
1148 if(autocvar_developer_csqcentities)
1149 LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
1151 localcmd(strMessage);
1153 // 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.
1154 void CSQC_Parse_Print(string strMessage)
1156 if(autocvar_developer_csqcentities)
1157 LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
1159 print(ColorTranslateRGB(strMessage));
1162 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1163 void CSQC_Parse_CenterPrint(string strMessage)
1165 if(autocvar_developer_csqcentities)
1166 LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
1168 centerprint_hud(strMessage);
1171 string notranslate_fogcmd1 = "\nfog ";
1172 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1175 // TODO somehow thwart prvm_globalset client ...
1177 if(autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
1178 { localcmd("\nr_drawfog 0\n"); }
1179 else if(forcefog != "")
1180 { localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2)); }
1183 void Gamemode_Init();
1184 void Ent_ScoresInfo()
1188 gametype = ReadInt24_t();
1189 HUD_ModIcons_SetFunc();
1190 for(i = 0; i < MAX_SCORE; ++i)
1193 strunzone(scores_label[i]);
1194 scores_label[i] = strzone(ReadString());
1195 scores_flags[i] = ReadByte();
1197 for(i = 0; i < MAX_TEAMSCORE; ++i)
1199 if(teamscores_label[i])
1200 strunzone(teamscores_label[i]);
1201 teamscores_label[i] = strzone(ReadString());
1202 teamscores_flags[i] = ReadByte();
1212 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1214 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1215 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1216 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1217 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1218 arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1219 arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1220 arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1221 arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1224 strunzone(forcefog);
1225 forcefog = strzone(ReadString());
1227 armorblockpercent = ReadByte() / 255.0;
1229 g_balance_mortar_bouncefactor = ReadCoord();
1230 g_balance_mortar_bouncestop = ReadCoord();
1231 g_balance_electro_secondary_bouncefactor = ReadCoord();
1232 g_balance_electro_secondary_bouncestop = ReadCoord();
1234 vortex_scope = !ReadByte();
1235 rifle_scope = !ReadByte();
1237 serverflags = ReadByte();
1239 minelayer_maxmines = ReadByte();
1241 hagar_maxrockets = ReadByte();
1243 g_trueaim_minrange = ReadCoord();
1244 g_balance_porto_secondary = ReadByte();
1246 MUTATOR_CALLHOOK(Ent_Init);
1260 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1261 race_checkpoint = ReadByte();
1262 race_time = ReadInt24_t();
1263 race_previousbesttime = ReadInt24_t();
1264 if(race_previousbestname)
1265 strunzone(race_previousbestname);
1266 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1268 race_checkpointtime = time;
1270 if(race_checkpoint == 0 || race_checkpoint == 254)
1272 race_penaltyaccumulator = 0;
1273 race_laptime = time; // valid
1278 case RACE_NET_CHECKPOINT_CLEAR:
1280 race_checkpointtime = 0;
1283 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1284 race_laptime = ReadCoord();
1285 race_checkpointtime = -99999;
1287 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1288 race_nextcheckpoint = ReadByte();
1290 race_nextbesttime = ReadInt24_t();
1291 if(race_nextbestname)
1292 strunzone(race_nextbestname);
1293 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1296 case RACE_NET_CHECKPOINT_HIT_RACE:
1297 race_mycheckpoint = ReadByte();
1298 race_mycheckpointtime = time;
1299 race_mycheckpointdelta = ReadInt24_t();
1300 race_mycheckpointlapsdelta = ReadByte();
1301 if(race_mycheckpointlapsdelta >= 128)
1302 race_mycheckpointlapsdelta -= 256;
1303 if(race_mycheckpointenemy)
1304 strunzone(race_mycheckpointenemy);
1305 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1308 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1309 race_othercheckpoint = ReadByte();
1310 race_othercheckpointtime = time;
1311 race_othercheckpointdelta = ReadInt24_t();
1312 race_othercheckpointlapsdelta = ReadByte();
1313 if(race_othercheckpointlapsdelta >= 128)
1314 race_othercheckpointlapsdelta -= 256;
1315 if(race_othercheckpointenemy)
1316 strunzone(race_othercheckpointenemy);
1317 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1320 case RACE_NET_PENALTY_RACE:
1321 race_penaltyeventtime = time;
1322 race_penaltytime = ReadShort();
1323 //race_penaltyaccumulator += race_penaltytime;
1324 if(race_penaltyreason)
1325 strunzone(race_penaltyreason);
1326 race_penaltyreason = strzone(ReadString());
1329 case RACE_NET_PENALTY_QUALIFYING:
1330 race_penaltyeventtime = time;
1331 race_penaltytime = ReadShort();
1332 race_penaltyaccumulator += race_penaltytime;
1333 if(race_penaltyreason)
1334 strunzone(race_penaltyreason);
1335 race_penaltyreason = strzone(ReadString());
1338 case RACE_NET_SERVER_RECORD:
1339 race_server_record = ReadInt24_t();
1341 case RACE_NET_SPEED_AWARD:
1342 race_speedaward = ReadInt24_t();
1343 if(race_speedaward_holder)
1344 strunzone(race_speedaward_holder);
1345 race_speedaward_holder = strzone(ReadString());
1347 case RACE_NET_SPEED_AWARD_BEST:
1348 race_speedaward_alltimebest = ReadInt24_t();
1349 if(race_speedaward_alltimebest_holder)
1350 strunzone(race_speedaward_alltimebest_holder);
1351 race_speedaward_alltimebest_holder = strzone(ReadString());
1353 case RACE_NET_SERVER_RANKINGS:
1355 int pos = ReadShort();
1356 prevpos = ReadShort();
1359 // move other rankings out of the way
1362 for (i=prevpos-1;i>pos-1;--i) {
1363 grecordtime[i] = grecordtime[i-1];
1364 if(grecordholder[i])
1365 strunzone(grecordholder[i]);
1366 grecordholder[i] = strzone(grecordholder[i-1]);
1368 } else if (del) { // a record has been deleted by the admin
1369 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1370 if (i == RANKINGS_CNT-1) { // clear out last record
1372 if (grecordholder[i])
1373 strunzone(grecordholder[i]);
1374 grecordholder[i] = string_null;
1377 grecordtime[i] = grecordtime[i+1];
1378 if (grecordholder[i])
1379 strunzone(grecordholder[i]);
1380 grecordholder[i] = strzone(grecordholder[i+1]);
1383 } else { // player has no ranked record yet
1384 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1385 grecordtime[i] = grecordtime[i-1];
1386 if(grecordholder[i])
1387 strunzone(grecordholder[i]);
1388 grecordholder[i] = strzone(grecordholder[i-1]);
1392 // store new ranking
1393 if(grecordholder[pos-1] != "")
1394 strunzone(grecordholder[pos-1]);
1395 grecordholder[pos-1] = strzone(ReadString());
1396 grecordtime[pos-1] = ReadInt24_t();
1397 if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1400 case RACE_NET_SERVER_STATUS:
1401 race_status = ReadShort();
1402 if(race_status_name)
1403 strunzone(race_status_name);
1404 race_status_name = strzone(ReadString());
1408 NET_HANDLE(TE_CSQC_RACE, bool isNew)
1414 NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
1420 void Net_ReadPingPLReport()
1427 if (!(playerslots[e]))
1429 playerslots[e].ping = pi;
1430 playerslots[e].ping_packetloss = pl / 255.0;
1431 playerslots[e].ping_movementloss = ml / 255.0;
1433 NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
1435 Net_ReadPingPLReport();
1439 void Net_WeaponComplain()
1441 complain_weapon = ReadByte();
1443 if(complain_weapon_name)
1444 strunzone(complain_weapon_name);
1445 complain_weapon_name = strzone(WEP_NAME(complain_weapon));
1447 complain_weapon_type = ReadByte();
1449 complain_weapon_time = time;
1450 weapontime = time; // ping the weapon panel
1452 switch(complain_weapon_type)
1454 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1455 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1456 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1459 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
1461 Net_WeaponComplain();
1465 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1466 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1467 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1468 bool CSQC_Parse_TempEntity()
1471 int nTEID = ReadByte();
1473 FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
1474 if (autocvar_developer_csqcentities)
1475 LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
1476 return it.m_read(NULL, true);
1479 if (autocvar_developer_csqcentities)
1480 LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
1482 // No special logic for this temporary entity; return 0 so the engine can handle it
1486 string getcommandkey(string text, string command)
1489 float n, j, k, l = 0;
1491 if (!autocvar_hud_showbinds)
1494 keys = db_get(binddb, command);
1497 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1498 for(j = 0; j < n; ++j)
1504 keys = keynumtostring(k);
1506 keys = strcat(keys, ", ", keynumtostring(k));
1509 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1516 db_put(binddb, command, keys);
1519 if (keys == "NO_KEY") {
1520 if (autocvar_hud_showbinds > 1)
1521 return sprintf(_("%s (not bound)"), text);
1525 else if (autocvar_hud_showbinds > 1)
1526 return sprintf("%s (%s)", text, keys);