X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Fmain.qc;h=7ad10879f7ac23b05a69a96ae7d4f7441ea51c2d;hb=e98ed192eac2c7983d5395418f3e9396024fa9ba;hp=bb1cf9b4aab3ea5b47c0c4837709fd24836f071a;hpb=834fed09016056ff2cd32d1980f0719d09c403a2;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index bb1cf9b4a..7ad10879f 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1,21 +1,29 @@ #include "main.qh" -#include -#include "hud/all.qh" +#include "defs.qh" +#include +#include "miscfunctions.qh" +#include +#include +#include +#include +#include "hud/_mod.qh" #include "mapvoting.qh" #include "mutators/events.qh" +#include "hud/panel/scoreboard.qh" #include "hud/panel/quickmenu.qh" -#include "scoreboard.qh" #include "shownames.qh" #include #include "wall.qh" #include "weapons/projectile.qh" #include -#include +#include #include #include #include +#include #include +#include #include #include #include @@ -30,7 +38,7 @@ void draw_cursor(vector pos, vector ofs, string img, vector col, float a) { - ofs = eX * (ofs.x * SIZE_CURSOR.x) + eY * (ofs.y * SIZE_CURSOR.y); + ofs = vec2(ofs.x * SIZE_CURSOR.x, ofs.y * SIZE_CURSOR.y); drawpic(pos - ofs, strcat(draw_currentSkin, img), SIZE_CURSOR, col, a, DRAWFLAG_NORMAL); } @@ -108,7 +116,6 @@ void CSQC_Init() binddb = db_create(); tempdb = db_create(); ClientProgsDB = db_load("client.db"); - compressShortVector_init(); draw_endBoldFont(); @@ -131,13 +138,10 @@ void CSQC_Init() registercvar("cl_spawn_near_teammate", "1"); - gametype = 0; + if(autocvar_cl_lockview) + cvar_set("cl_lockview", "0"); - // hud_fields uses strunzone on the titles! - for(int i = 0; i < MAX_HUD_FIELDS; ++i) - hud_title[i] = strzone("(null)"); - - Cmd_HUD_SetFields(0); + gametype = NULL; postinit = false; @@ -148,6 +152,9 @@ void CSQC_Init() GetTeam(NUM_SPECTATOR, true); // add specs first + for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) + weapon_accuracy[w] = -1; + // precaches if(autocvar_cl_reticle) @@ -185,8 +192,8 @@ void Shutdown() { WarpZone_Shutdown(); - remove(teams); - remove(players); + delete(teams); + delete(players); db_close(binddb); db_close(tempdb); if(autocvar_cl_db_saveasdump) @@ -212,8 +219,10 @@ void Shutdown() localcmd("\ncl_hook_gameend\n"); } + localcmd("\ncl_hook_shutdown\n"); + deactivate_minigame(); - HUD_MinigameMenu_Close(); + HUD_MinigameMenu_Close(NULL, NULL, NULL); } .float has_team; @@ -233,9 +242,9 @@ float SetTeam(entity o, int Team) case NUM_TEAM_4: break; default: - if(GetTeam(Team, false) == world) + if(GetTeam(Team, false) == NULL) { - LOG_TRACEF("trying to switch to unsupported team %d\n", Team); + LOG_TRACEF("trying to switch to unsupported team %d", Team); Team = NUM_SPECTATOR; } break; @@ -249,9 +258,9 @@ float SetTeam(entity o, int Team) case 0: break; default: - if(GetTeam(Team, false) == world) + if(GetTeam(Team, false) == NULL) { - LOG_TRACEF("trying to switch to unsupported team %d\n", Team); + LOG_TRACEF("trying to switch to unsupported team %d", Team); Team = NUM_SPECTATOR; } break; @@ -290,9 +299,8 @@ float SetTeam(entity o, int Team) return false; } -void Playerchecker_Think() +void Playerchecker_Think(entity this) { - SELFPARAM(); int i; entity e; for(i = 0; i < maxclients; ++i) @@ -305,7 +313,7 @@ void Playerchecker_Think() // player disconnected SetTeam(e, -1); RemovePlayer(e); - e.sort_prev = world; + e.sort_prev = NULL; //e.gotscores = 0; } } @@ -324,9 +332,9 @@ void Playerchecker_Think() e.ping_movementloss = 0; //e.gotscores = 0; // we might already have the scores... int t = entcs_GetScoreTeam(i); - if (t) SetTeam(e, t); // will not hurt; later updates come with HUD_UpdatePlayerTeams + if (t) SetTeam(e, t); // will not hurt; later updates come with Scoreboard_UpdatePlayerTeams RegisterPlayer(e); - HUD_UpdatePlayerPos(e); + Scoreboard_UpdatePlayerPos(e); } } } @@ -337,7 +345,7 @@ void TrueAim_Init(); void PostInit() { entity playerchecker = new_pure(playerchecker); - playerchecker.think = Playerchecker_Think; + setthink(playerchecker, Playerchecker_Think); playerchecker.nextthink = time + 0.2; TrueAim_Init(); @@ -379,19 +387,6 @@ float CSQC_InputEvent(int bInputType, float nPrimary, float nSecondary) // -------------------------------------------------------------------------- // BEGIN OPTIONAL CSQC FUNCTIONS -.void(entity) predraw_qc; -void PreDraw_self() -{ - SELFPARAM(); - if (this.predraw_qc) this.predraw_qc(this); -} - -void setpredraw(entity this, void(entity) pdfunc) -{ - this.predraw = PreDraw_self; - this.predraw_qc = pdfunc; -} - void Ent_Remove(entity this); void Ent_RemovePlayerScore(entity this) @@ -399,23 +394,21 @@ void Ent_RemovePlayerScore(entity this) if(this.owner) { SetTeam(this.owner, -1); this.owner.gotscores = 0; - for(int i = 0; i < MAX_SCORE; ++i) { - this.owner.(scores[i]) = 0; // clear all scores - } + FOREACH(Scores, true, { + this.owner.(scores(it)) = 0; // clear all scores + }); } } NET_HANDLE(ENT_CLIENT_SCORES, bool isnew) { make_pure(this); - int i, n; - bool isNew; entity o; // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN // (no I've never heard of M-x replace-string, sed, or anything like that) - isNew = !this.owner; // workaround for DP bug - n = ReadByte()-1; + bool isNew = !this.owner; // workaround for DP bug + int n = ReadByte()-1; #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED if(!isNew && n != this.sv_entnum) @@ -443,27 +436,23 @@ NET_HANDLE(ENT_CLIENT_SCORES, bool isnew) //playerchecker will do this for us later, if it has not already done so int sf, lf; -#if MAX_SCORE <= 8 - sf = ReadByte(); - lf = ReadByte(); -#else sf = ReadShort(); lf = ReadShort(); -#endif - int p; - for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2) - if(sf & p) + FOREACH(Scores, true, { + int p = 1 << (i % 16); + if (sf & p) { - if(lf & p) - o.(scores[i]) = ReadInt24_t(); + if (lf & p) + o.(scores(it)) = ReadInt24_t(); else - o.(scores[i]) = ReadChar(); + o.(scores(it)) = ReadChar(); } + }); return = true; if(o.sort_prev) - HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet! + Scoreboard_UpdatePlayerPos(o); // if not registered, we cannot do this yet! this.entremove = Ent_RemovePlayerScore; } @@ -490,14 +479,14 @@ NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew) if(sf & p) { if(lf & p) - o.(teamscores[i]) = ReadInt24_t(); + o.(teamscores(i)) = ReadInt24_t(); else - o.(teamscores[i]) = ReadChar(); + o.(teamscores(i)) = ReadChar(); } return = true; - HUD_UpdateTeamPos(o); + Scoreboard_UpdateTeamPos(o); } NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) @@ -507,9 +496,9 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) int f = ReadByte(); - scoreboard_showscores_force = (f & 1); + scoreboard_showscores_force = (f & BIT(0)); - if(f & 2) + if(f & BIT(1)) { newspectatee_status = ReadByte(); if(newspectatee_status == player_localnum + 1) @@ -518,17 +507,23 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) else newspectatee_status = 0; - spectatorbutton_zoom = (f & 4); + spectatorbutton_zoom = (f & BIT(2)); - if(f & 8) + if(f & BIT(4)) { - angles_held_status = 1; - angles_held.x = ReadAngle(); - angles_held.y = ReadAngle(); - angles_held.z = 0; + num_spectators = ReadByte(); + + float i, slot; + + for(i = 0; i < MAX_SPECTATORS; ++i) + spectatorlist[i] = 0; // reset list first + + for(i = 0; i < num_spectators; ++i) + { + slot = ReadByte(); + spectatorlist[i] = slot - 1; + } } - else - angles_held_status = 0; return = true; @@ -584,7 +579,7 @@ NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew) { if(vote_called_vote) strunzone(vote_called_vote); - vote_called_vote = strzone(ColorTranslateRGB(ReadString())); + vote_called_vote = strzone(ReadString()); } if(nags & 1) @@ -671,6 +666,9 @@ NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew) void Spawn_Draw(entity this) { + if(this.alpha <= 0) + return; + __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1)); } @@ -679,7 +677,14 @@ void Spawn_PreDraw(entity this) float alph; vector org = getpropertyvec(VF_ORIGIN); if(this.fade_start) - alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); + { + if(vdist(org - this.origin, >, this.fade_end)) + alph = 0; // save on some processing + else if(vdist(org - this.origin, <, this.fade_start)) + alph = 1; // more processing saved + else + alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); + } else alph = 1; //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); @@ -698,6 +703,8 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new) spn_origin.y = ReadCoord(); spn_origin.z = ReadCoord(); + this.team = (teamnum + 1); + //if(is_new) //{ this.origin = spn_origin; @@ -711,12 +718,13 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new) precache_model(this.mdl); setmodel(this, this.mdl); this.drawmask = MASK_NORMAL; - //this.movetype = MOVETYPE_NOCLIP; + //this.move_movetype = MOVETYPE_NOCLIP; //this.draw = Spawn_Draw; + IL_PUSH(g_drawables, this); }*/ if(autocvar_cl_spawn_point_particles) { - if((serverflags & SERVERFLAG_TEAMPLAY)) + if(teamplay) { switch(teamnum) { @@ -730,6 +738,7 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new) else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); } this.draw = Spawn_Draw; + if (is_new) IL_PUSH(g_drawables, this); setpredraw(this, Spawn_PreDraw); this.fade_start = autocvar_cl_spawn_point_dist_min; this.fade_end = autocvar_cl_spawn_point_dist_max; @@ -787,16 +796,15 @@ NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new) localcmd("-zoom\n"); button_zoom = false; } + HUD_Radar_Hide_Maximized(); } - HUD_Radar_Hide_Maximized(); //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum); } // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured. // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS. -void CSQC_Ent_Update(bool isnew) +void CSQC_Ent_Update(entity this, bool isnew) { - SELFPARAM(); this.sourceLoc = __FILE__ ":" STR(__LINE__); int t = ReadByte(); @@ -840,12 +848,13 @@ void CSQC_Ent_Update(bool isnew) if (autocvar_developer_csqcentities) 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); done = it.m_read(this, NULL, isnew); + MUTATOR_CALLHOOK(Ent_Update, this, isnew); break; }); time = savetime; if (!done) { - LOG_FATALF("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); + 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); } } @@ -864,7 +873,7 @@ void Ent_Remove(entity this) if(this.snd_looping > 0) { - sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation); + sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_cl_jetpack_attenuation); this.snd_looping = 0; } @@ -875,17 +884,16 @@ void Ent_Remove(entity this) // TODO possibly set more stuff to defaults } // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(this) as well. -void CSQC_Ent_Remove() +void CSQC_Ent_Remove(entity this) { - SELFPARAM(); if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype); if (wasfreed(this)) { - LOG_WARNING("CSQC_Ent_Remove called for already removed entity. Packet loss?\n"); + LOG_WARN("CSQC_Ent_Remove called for already removed entity. Packet loss?"); return; } if (this.enttype) Ent_Remove(this); - remove(this); + delete(this); } void Gamemode_Init() @@ -951,22 +959,22 @@ void Gamemode_Init(); NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew) { make_pure(this); - gametype = ReadInt24_t(); + gametype = ReadRegistered(Gametypes); + teamplay = _MapInfo_GetTeamPlayBool(gametype); HUD_ModIcons_SetFunc(); - for (int i = 0; i < MAX_SCORE; ++i) - { - if (scores_label[i]) strunzone(scores_label[i]); - scores_label[i] = strzone(ReadString()); - scores_flags[i] = ReadByte(); - } + FOREACH(Scores, true, { + if (scores_label(it)) strunzone(scores_label(it)); + scores_label(it) = strzone(ReadString()); + scores_flags(it) = ReadByte(); + }); for (int i = 0; i < MAX_TEAMSCORE; ++i) { - if (teamscores_label[i]) strunzone(teamscores_label[i]); - teamscores_label[i] = strzone(ReadString()); - teamscores_flags[i] = ReadByte(); + if (teamscores_label(i)) strunzone(teamscores_label(i)); + teamscores_label(i) = strzone(ReadString()); + teamscores_flags(i) = ReadByte(); } return = true; - HUD_InitScores(); + Scoreboard_InitScores(); Gamemode_Init(); } @@ -987,6 +995,7 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew) forcefog = strzone(ReadString()); armorblockpercent = ReadByte() / 255.0; + damagepush_speedfactor = ReadByte() / 255.0; serverflags = ReadByte(); @@ -999,6 +1008,42 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew) if (!postinit) PostInit(); } +float GetSpeedUnitFactor(int speed_unit) +{ + switch(speed_unit) + { + default: + case 1: + return 1.0; + case 2: + return 0.0254; + case 3: + return 0.0254 * 3.6; + case 4: + return 0.0254 * 3.6 * 0.6213711922; + case 5: + return 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h + } +} + +string GetSpeedUnit(int speed_unit) +{ + switch(speed_unit) + { + default: + case 1: + return _(" qu/s"); + case 2: + return _(" m/s"); + case 3: + return _(" km/h"); + case 4: + return _(" mph"); + case 5: + return _(" knots"); + } +} + NET_HANDLE(TE_CSQC_RACE, bool isNew) { int b = ReadByte(); @@ -1009,9 +1054,18 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_checkpoint = ReadByte(); race_time = ReadInt24_t(); race_previousbesttime = ReadInt24_t(); + race_mypreviousbesttime = ReadInt24_t(); if(race_previousbestname) strunzone(race_previousbestname); - race_previousbestname = strzone(ColorTranslateRGB(ReadString())); + string pbestname = ReadString(); + if(autocvar_cl_race_cptimes_onlyself) + { + race_previousbesttime = race_mypreviousbesttime; + race_mypreviousbesttime = 0; + race_previousbestname = strzone(""); + } + else + race_previousbestname = strzone(pbestname); race_checkpointtime = time; @@ -1020,7 +1074,6 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_penaltyaccumulator = 0; race_laptime = time; // valid } - break; case RACE_NET_CHECKPOINT_CLEAR: @@ -1036,9 +1089,19 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_nextcheckpoint = ReadByte(); race_nextbesttime = ReadInt24_t(); + if(b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING) // not while spectating (matches server) + race_mybesttime = ReadInt24_t(); if(race_nextbestname) strunzone(race_nextbestname); - race_nextbestname = strzone(ColorTranslateRGB(ReadString())); + string newname = ReadString(); + if(autocvar_cl_race_cptimes_onlyself && b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING) + { + race_nextbesttime = race_mybesttime; + race_mybesttime = 0; + race_nextbestname = strzone(""); + } + else + race_nextbestname = strzone(newname); break; case RACE_NET_CHECKPOINT_HIT_RACE: @@ -1050,7 +1113,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_mycheckpointlapsdelta -= 256; if(race_mycheckpointenemy) strunzone(race_mycheckpointenemy); - race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString())); + int who = ReadByte(); + if(who) + race_mycheckpointenemy = strzone(entcs_GetName(who - 1)); + else + race_mycheckpointenemy = strzone(""); // TODO: maybe string_null works fine here? break; case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT: @@ -1062,7 +1129,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_othercheckpointlapsdelta -= 256; if(race_othercheckpointenemy) strunzone(race_othercheckpointenemy); - race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString())); + int what = ReadByte(); + if(what) + race_othercheckpointenemy = strzone(entcs_GetName(what - 1)); + else + race_othercheckpointenemy = strzone(""); // TODO: maybe string_null works fine here? break; case RACE_NET_PENALTY_RACE: @@ -1087,16 +1158,22 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_server_record = ReadInt24_t(); break; case RACE_NET_SPEED_AWARD: - race_speedaward = ReadInt24_t(); + race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); if(race_speedaward_holder) strunzone(race_speedaward_holder); race_speedaward_holder = strzone(ReadString()); + if(race_speedaward_unit) + strunzone(race_speedaward_unit); + race_speedaward_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_SPEED_AWARD_BEST: - race_speedaward_alltimebest = ReadInt24_t(); + race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); if(race_speedaward_alltimebest_holder) strunzone(race_speedaward_alltimebest_holder); race_speedaward_alltimebest_holder = strzone(ReadString()); + if(race_speedaward_alltimebest_unit) + strunzone(race_speedaward_alltimebest_unit); + race_speedaward_alltimebest_unit = strzone(GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_SERVER_RANKINGS: float prevpos, del; @@ -1142,7 +1219,7 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) strunzone(grecordholder[pos-1]); grecordholder[pos-1] = strzone(ReadString()); grecordtime[pos-1] = ReadInt24_t(); - if(grecordholder[pos-1] == entcs_GetName(player_localnum)) + if(strdecolorize(grecordholder[pos-1]) == strdecolorize(entcs_GetName(player_localnum))) race_myrank = pos; break; case RACE_NET_SERVER_STATUS: @@ -1191,27 +1268,32 @@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) } } -string getcommandkey(string text, string command) +string _getcommandkey(string cmd_name, string command, bool forcename) { string keys; float n, j, k, l = 0; if (!autocvar_hud_showbinds) - return text; + return cmd_name; keys = db_get(binddb, command); if (keys == "") { + bool joy_active = cvar("joy_active"); n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings for(j = 0; j < n; ++j) { k = stof(argv(j)); if(k != -1) { - if ("" == keys) - keys = keynumtostring(k); + string key = keynumtostring(k); + if(!joy_active && substring(key, 0, 3) == "JOY") + continue; + + if (keys == "") + keys = key; else - keys = strcat(keys, ", ", keynumtostring(k)); + keys = strcat(keys, ", ", key); ++l; if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l) @@ -1226,12 +1308,12 @@ string getcommandkey(string text, string command) if (keys == "NO_KEY") { if (autocvar_hud_showbinds > 1) - return sprintf(_("%s (not bound)"), text); + return sprintf(_("%s (not bound)"), cmd_name); else - return text; + return cmd_name; } - else if (autocvar_hud_showbinds > 1) - return sprintf("%s (%s)", text, keys); + else if (autocvar_hud_showbinds > 1 || forcename) + return sprintf("%s (%s)", cmd_name, keys); else return keys; }