X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcl_weaponsystem.qc;h=4465c190b7d8d7e6f4675ab1eb5d09fe59a99c50;hb=cad7a84d59626dceb9653c62451702843b00b334;hp=5bfad53530b8b7446c14c33ef4fdaca68510f41c;hpb=c94e06a08777b32dea9a5b3a3934da16f50803bf;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index 5bfad5353..4465c190b 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -19,13 +19,13 @@ float W_WeaponRateFactor() if(self.runes & RUNE_SPEED) { if(self.runes & CURSE_SLOW) - t = t * cvar("g_balance_rune_speed_combo_atkrate"); + t = t * autocvar_g_balance_rune_speed_combo_atkrate; else - t = t * cvar("g_balance_rune_speed_atkrate"); + t = t * autocvar_g_balance_rune_speed_atkrate; } else if(self.runes & CURSE_SLOW) { - t = t * cvar("g_balance_curse_slow_atkrate"); + t = t * autocvar_g_balance_curse_slow_atkrate; } } @@ -138,7 +138,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m local float oldsolid; vector vecs, dv; oldsolid = ent.dphitcontentsmask; - if(ent.weapon == WEP_CAMPINGRIFLE) + if(ent.weapon == WEP_SNIPERRIFLE) ent.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE; else ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; @@ -158,6 +158,10 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m v_right = vr; v_up = vu; + // un-adjust trueaim if shotend is too close + if(vlen(w_shotend - (ent.origin + ent.view_ofs)) < autocvar_g_trueaim_minrange) + w_shotend = ent.origin + ent.view_ofs + s_forward * autocvar_g_trueaim_minrange; + // track max damage if(accuracy_canbegooddamage(ent)) accuracy_add(ent, ent.weapon, maxdamage, 0); @@ -191,7 +195,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m if (antilag) if (!ent.cvar_cl_noantilag) { - if (cvar("g_antilag") == 1) // switch to "ghost" if not hitting original + if (autocvar_g_antilag == 1) // switch to "ghost" if not hitting original { traceline(w_shotorg, w_shotorg + w_shotdir * range, MOVE_NORMAL, ent); if (!trace_ent.takedamage) @@ -207,7 +211,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m } } } - else if(cvar("g_antilag") == 3) // client side hitscan + else if(autocvar_g_antilag == 3) // client side hitscan { // this part MUST use prydon cursor if (ent.cursor_trace_ent) // client was aiming at someone @@ -242,9 +246,9 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m if(ent.items & IT_STRENGTH) if(!g_minstagib) if( - (time > ent.prevstrengthsound + cvar("sv_strengthsound_antispam_time")) + (time > ent.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) || - (time > ent.prevstrengthsoundattempt + cvar("sv_strengthsound_antispam_refire_threshold")) + (time > ent.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold) ) // prevent insane sound spam { sound(ent, CHAN_AUTO, "weapons/strength_fire.wav", VOL_BASE, ATTN_NORM); @@ -603,12 +607,14 @@ void CL_Weaponentity_Think() else self.alpha = 1; + self.glowmod = self.owner.weaponentity_glowmod; self.colormap = self.owner.colormap; if (self.weaponentity) { self.weaponentity.effects = self.effects; self.weaponentity.alpha = self.alpha; self.weaponentity.colormap = self.colormap; + self.weaponentity.glowmod = self.glowmod; } self.angles = '0 0 0'; @@ -616,7 +622,7 @@ void CL_Weaponentity_Think() f = 0; if (self.state == WS_RAISE && !intermission_running) { - f = (self.owner.weapon_nextthink - time) * g_weaponratefactor / cvar("g_balance_weaponswitchdelay"); + f = (self.owner.weapon_nextthink - time) * g_weaponratefactor / autocvar_g_balance_weaponswitchdelay; self.angles_x = -90 * f * f; if (qcweaponanimation) { @@ -626,7 +632,7 @@ void CL_Weaponentity_Think() } else if (self.state == WS_DROP && !intermission_running) { - f = 1 - (self.owner.weapon_nextthink - time) * g_weaponratefactor / cvar("g_balance_weaponswitchdelay"); + f = 1 - (self.owner.weapon_nextthink - time) * g_weaponratefactor / autocvar_g_balance_weaponswitchdelay; self.angles_x = -90 * f * f; if (qcweaponanimation) { @@ -847,6 +853,7 @@ void CL_ExteriorWeaponentity_Think() self.angles = ang; } + self.glowmod = self.owner.weaponentity_glowmod; self.colormap = self.owner.colormap; }; @@ -952,7 +959,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) sprint(cl, strcat("You do not have the ^2", W_Name(wpn), "\n") ); Send_WeaponComplain (cl, wpn, W_Name(wpn), 1); - if(cvar("g_showweaponspawns")) + if(autocvar_g_showweaponspawns) { entity e; string s; @@ -1011,7 +1018,7 @@ void w_ready() void weapon_setup(float windex) { entity e; - qcweaponanimation = cvar("sv_qcweaponanimation"); + qcweaponanimation = autocvar_sv_qcweaponanimation; e = get_weaponinfo(windex); self.items &~= IT_AMMO; self.items = self.items | e.items; @@ -1275,7 +1282,7 @@ vector W_CalculateProjectileVelocity(vector pvelocity, vector mvelocity, float f mdirection = normalize(mvelocity); mspeed = vlen(mvelocity); - nstyle = cvar("g_projectiles_newton_style"); + nstyle = autocvar_g_projectiles_newton_style; if(nstyle == 0 || forceAbsolute) { // absolute velocity @@ -1312,7 +1319,7 @@ vector W_CalculateProjectileVelocity(vector pvelocity, vector mvelocity, float f //dprint("impossible shot, adjusting\n"); } - outspeed = bound(mspeed * cvar("g_projectiles_newton_style_2_minfactor"), outspeed, mspeed * cvar("g_projectiles_newton_style_2_maxfactor")); + outspeed = bound(mspeed * autocvar_g_projectiles_newton_style_2_minfactor, outspeed, mspeed * autocvar_g_projectiles_newton_style_2_maxfactor); outvelocity = mdirection * outspeed; } else if(nstyle == 3) @@ -1455,7 +1462,7 @@ vector W_CalculateProjectileSpread(vector forward, float spread) spread *= g_weaponspreadfactor; if(spread <= 0) return forward; - sstyle = cvar("g_projectiles_spread_style"); + sstyle = autocvar_g_projectiles_spread_style; if(sstyle == 0) { @@ -1580,10 +1587,10 @@ void W_SetupProjectileVelocityEx(entity missile, vector dir, vector upDir, float dir = normalize(dir); #if 0 - if(cvar("g_projectiles_spread_style") != mspercallsstyle) + if(autocvar_g_projectiles_spread_style != mspercallsstyle) { mspercallsum = mspercallcount = 0; - mspercallsstyle = cvar("g_projectiles_spread_style"); + mspercallsstyle = autocvar_g_projectiles_spread_style; } mspercallsum -= gettime(GETTIME_HIRES); #endif @@ -1604,3 +1611,105 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread) #define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"), FALSE) #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE) + +// weapon reloading code + +..float reload_ammo_player; +.float reload_ammo_amount, reload_ammo_min, reload_time; +.float reload_complain; +.string reload_sound; + +float W_ReloadCheck(float ammo_amount, float ammo_shot) +{ + // our weapon is fully loaded, no need to reload + if (self.clip_load >= self.reload_ammo_amount) + return FALSE; + + // no ammo, so nothing to load + if(!ammo_amount && ammo_shot) + { + if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time) + { + play2(self, "weapons/unavailable.wav"); + sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n")); + self.reload_complain = time + 1; + } + // switch away if the amount of ammo is not enough to keep using this weapon + if not(weapon_action(self.weapon, WR_CHECKAMMO1) + weapon_action(self.weapon, WR_CHECKAMMO2)) + { + self.clip_load = -1; // reload later + W_SwitchToOtherWeapon(self); + } + return FALSE; + } + + if (self.weaponentity) + { + if (self.weaponentity.wframe == WFRAME_RELOAD) + return FALSE; + + // allow switching away while reloading, but this will cause a new reload! + self.weaponentity.state = WS_READY; + } + + return TRUE; +} + +void W_ReloadEnd() +{ + float t; + + // now do the ammo transfer + + self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading + + // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load + if(!self.reload_ammo_min) + self.clip_load = self.reload_ammo_amount; + else + { + while(self.clip_load < self.reload_ammo_amount && self.(self.reload_ammo_player)) // make sure we don't add more ammo than we have + { + self.clip_load += 1; + self.(self.reload_ammo_player) -= 1; + } + } + self.weapon_load[self.weapon] = self.clip_load; + + t = ATTACK_FINISHED(self) - self.reload_time - 1; + ATTACK_FINISHED(self) = t; + w_ready(); +} + +void W_ReloadStart() +{ + // return if reloading is disabled for this weapon + if(!self.reload_ammo_amount) + return; + + if(!W_ReloadCheck(self.(self.reload_ammo_player), self.reload_ammo_min)) + return; + + float t; + + sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM); + + t = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1; + ATTACK_FINISHED(self) = t; + + weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadEnd); + + self.old_clip_load = self.clip_load; + self.clip_load = -1; +} + +void W_Reload(.float sent_ammo_player, float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound) +{ + self.reload_ammo_player = sent_ammo_player; + self.reload_ammo_min = sent_ammo_min; + self.reload_ammo_amount = sent_ammo_amount; + self.reload_time = sent_time; + self.reload_sound = sent_sound; + + W_ReloadStart(); +} \ No newline at end of file