X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=data%2Fqcsrc%2Fserver%2Fcl_weaponsystem.qc;h=48058cca9e23864607b36b7c0aef2052aa229df1;hb=8cafc5adad92ae3d4f6c75260a1a1d509942447a;hp=3430c1a961ad6d0f4f656728756f064cfafcc01e;hpb=0f724021d43895ff01bd13ee1072dd0caf11996e;p=voretournament%2Fvoretournament.git diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index 3430c1a9..48058cca 100644 --- a/data/qcsrc/server/cl_weaponsystem.qc +++ b/data/qcsrc/server/cl_weaponsystem.qc @@ -223,15 +223,18 @@ void W_SetupShot_Dir_ProjectileSize(entity ent, vector s_forward, vector mi, vec ent.dphitcontentsmask = oldsolid; // restore solid type (generally SOLID_SLIDEBOX) if (!g_norecoil) - ent.punchangle_x = recoil * -1; + { + ent.punchangle_x += crandom() * recoil; + ent.punchangle_y += crandom() * recoil; + } if (snd != "") { sound (ent, CHAN_WEAPON, snd, VOL_BASE, ATTN_NORM); } - if (ent.items & IT_STRENGTH) - sound (ent, CHAN_AUTO, "weapons/strength_fire.wav", VOL_BASE, ATTN_NORM); + if (ent.items & IT_STRENGTH && maxdamage) + sound (ent, CHAN_AUTO, "weapons/strength_fire.wav", VOL_BASE, ATTN_NORM); }; #define W_SetupShot_ProjectileSize(ent,mi,ma,antilag,recoil,snd,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, v_forward, mi, ma, antilag, recoil, snd, maxdamage) @@ -253,21 +256,38 @@ float CL_ExteriorWeaponentity_CustomizeEntityForClient() { // hide the exterior weapon entity of a predator from their prey // otherwise, the stomach model the predator is transformed in (see Client_customizeentityforclient) will have a weapon model attached to it - if(self.owner.weaponname == "") - return TRUE; - if(other.cvar_chase_active > 0 || other.classname == "observer") // the classname check prevents a bug - { - setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); + if(self.owner.weaponname == "" || self.owner.deadflag != DEAD_NO) return TRUE; - } - if(other.spectatee_status) + + float chase; + chase = other.cvar_chase_active; + + if(other.spectatee_status && other.spectatee_status == num_for_edict(other.enemy)) other = other.enemy; // also do this for the player we are spectating - if(other.eater == self.owner) + + if not(chase || other.classname == "observer") // the observer check prevents a bug + if(other.predator == self.owner) { setmodel(self, ""); return TRUE; } - setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); + + if(cvar("g_nodepthtestplayers")) + self.effects |= EF_NODEPTHTEST; + else + self.effects &~= EF_NODEPTHTEST; + if(cvar("g_fullbrightplayers")) + self.effects |= EF_FULLBRIGHT; + + if not(self.owner.stat_eaten) + setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); + else if(cvar("g_vore_neighborprey_distance") && other.predator == self.owner.predator && !(chase || other.classname == "observer")) + { + setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // allow seeing neighboring prey's weapon model + self.effects |= EF_NODEPTHTEST; // don't hide behind the stomach's own EF_NODEPTHTEST + } + else + setmodel(self, ""); // hide prey's weapon model return TRUE; } @@ -354,6 +374,7 @@ void CL_Weaponentity_Think() return; } if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag) + if (substring(self.owner.model, -4, 4) != ".md3") // not a stomach model { self.cnt = self.owner.weapon; self.dmg = self.owner.modelindex; @@ -382,8 +403,8 @@ void CL_Weaponentity_Think() } else { - setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".dpm")); // precision set below - animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".dpm.animinfo"); + setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".iqm")); // precision set below + animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".iqm.animinfo"); animfile = fopen(animfilename, FILE_READ); // preset some defaults that work great for renamed zym files (which don't need an animinfo) self.anim_fire1 = '0 1 0.01'; @@ -567,18 +588,21 @@ void CL_Weaponentity_Think() if(self.owner.alpha == default_player_alpha) self.alpha = default_weapon_alpha; - else if(self.owner.alpha != 0) + else if(self.owner.alpha != 0 && !self.owner.stat_eaten) self.alpha = self.owner.alpha; else self.alpha = 1; self.colormap = self.owner.colormap; + self.colormod = self.owner.colormod; + self.glowmod = self.owner.weaponentity_glowmod; if (self.weaponentity) { self.weaponentity.effects = self.effects; self.weaponentity.alpha = self.alpha; self.weaponentity.colormap = self.colormap; self.weaponentity.colormod = self.owner.colormod; // used by the regurgitating colors + self.weaponentity.glowmod = self.glowmod; } self.angles = '0 0 0'; @@ -737,7 +761,22 @@ void CL_Weaponentity_Think() } - // create or update the lasertarget entity + // if we are a micro or macro, size the weapon model accordingly + if(cvar("g_healthsize") && cvar("g_healthsize_weapon_scalefactor")) + if(self.owner.scale) // prevents some exceptions + { + self.scale = pow(1 / self.owner.scale, cvar("g_healthsize_weapon_scalefactor")); + if(self.scale < 0.1) + self.scale = 0.1; // stuff breaks if scale is smaller than this + self.origin_z = (1 - self.scale) * cvar("g_healthsize_weapon_scalefactor_pos"); + + // copy properties to the static weapon entity as well + if(self.weaponentity != world) // prevents assignment to world + { + self.weaponentity.scale = self.scale; + self.weaponentity.origin = self.origin; + } + } }; void CL_ExteriorWeaponentity_Think() @@ -756,6 +795,7 @@ void CL_ExteriorWeaponentity_Think() return; } if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag) + if (substring(self.owner.model, -4, 4) != ".md3") // not a stomach model { self.cnt = self.owner.weapon; self.dmg = self.owner.modelindex; @@ -820,7 +860,16 @@ void CL_ExteriorWeaponentity_Think() self.angles = ang; } + // if we are a micro or macro, size the weapon model accordingly + if(self.owner.scale && cvar("g_healthsize_exteriorweapon_scalefactor")) + if(self.model != "") + { + self.scale = 1 / self.owner.scale; // for some reason, the exterior weapon entity copies the player's scale somewhere else, so undo that first + self.scale = (1 - cvar("g_healthsize_exteriorweapon_scalefactor")) + cvar("g_healthsize_exteriorweapon_scalefactor") * self.scale; + } + self.colormap = self.owner.colormap; + self.glowmod = self.owner.weaponentity_glowmod; self.customizeentityforclient = CL_ExteriorWeaponentity_CustomizeEntityForClient; }; @@ -855,8 +904,9 @@ void CL_SpawnWeaponentity() float client_hasweapon(entity cl, float wpn, float andammo, float complain) { - local float weaponbit, f; - local entity oldself; + local float weaponbit; + //local float weaponbit, f; + //local entity oldself; if(time < self.hasweapon_complain_spam) complain = 0; @@ -872,7 +922,8 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) weaponbit = W_WeaponBit(wpn); if (cl.weapons & weaponbit) { - if (andammo) + // since we don't have an infinite ammo weapon in vore tournament, allow switching to the grabber even when it has no ammo + /*if (andammo) { if(cl.items & IT_UNLIMITED_WEAPON_AMMO) { @@ -891,12 +942,12 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) if (complain) if(clienttype(cl) == CLIENTTYPE_REAL) { - play2(cl, "weapons/unavailable.wav"); + play2(cl, "misc/unavailable.wav"); sprint(cl, strcat("You don't have any ammo for the ^2", W_Name(wpn), "\n")); } return FALSE; } - } + }*/ return TRUE; } if (complain) @@ -935,7 +986,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) else sprint(cl, strcat("The ^2", W_Name(wpn), "^7 is ^1NOT AVAILABLE^7 in this map\n") ); - play2(cl, "weapons/unavailable.wav"); + play2(cl, "misc/unavailable.wav"); } return FALSE; }; @@ -974,26 +1025,45 @@ void weapon_setup(float windex) }; // perform weapon to attack (weaponstate and attack_finished check is here) -.float race_penalty; -float weapon_prepareattack(float secondary, float attacktime) +void W_SwitchToOtherWeapon(entity pl) { - //if sv_ready_restart_after_countdown is set, don't allow the player to shoot - //if all players readied up and the countdown is running - if(time < game_starttime || time < self.race_penalty) { - return FALSE; - } + // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway) + float w, ww; + w = W_WeaponBit(pl.weapon); + pl.weapons &~= w; + ww = w_getbestweapon(pl); + pl.weapons |= w; + if(ww) + W_SwitchWeapon_Force(pl, ww); +} +.float prevdryfire; +float weapon_prepareattack_checkammo(float secondary) +{ if not(self.items & IT_UNLIMITED_WEAPON_AMMO) if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary)) { - // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway) - float w, ww; - w = W_WeaponBit(self.weapon); - self.weapons &~= w; - ww = w_getbestweapon(self); - self.weapons |= w; - if(ww) - W_SwitchWeapon_Force(self, ww); + if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons + { + sound (self, CHAN_AUTO, "misc/unavailable.wav", VOL_BASE, ATTN_NORM); + self.prevdryfire = time; + } + + // since we don't have an infinite ammo weapon in vore tournament, allow switching to the grabber even when it has no ammo + //W_SwitchToOtherWeapon(self); + return FALSE; + } + return TRUE; +} +.float race_penalty; +float weapon_prepareattack_check(float secondary, float attacktime) +{ + if(!weapon_prepareattack_checkammo(secondary)) + return FALSE; + + //if sv_ready_restart_after_countdown is set, don't allow the player to shoot + //if all players readied up and the countdown is running + if(time < game_starttime || time < self.race_penalty) { return FALSE; } @@ -1013,6 +1083,11 @@ float weapon_prepareattack(float secondary, float attacktime) if (self.weaponentity.state != WS_READY) return FALSE; } + + return TRUE; +} +float weapon_prepareattack_do(float secondary, float attacktime) +{ self.weaponentity.state = WS_INUSE; self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire @@ -1029,7 +1104,17 @@ float weapon_prepareattack(float secondary, float attacktime) } //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n"); return TRUE; -}; +} +float weapon_prepareattack(float secondary, float attacktime) +{ + if(weapon_prepareattack_check(secondary, attacktime)) + { + weapon_prepareattack_do(secondary, attacktime); + return TRUE; + } + else + return FALSE; +} void weapon_thinkf(float fr, float t, void() func) { @@ -1509,3 +1594,144 @@ 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")) #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread")) + +void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload) +{ + if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !ammo_reload) + return; + + // if this weapon is reloadable, decrease its load. Else decrease the player's ammo + if(ammo_reload) + { + self.clip_load -= ammo_use; + self.(weapon_load[self.weapon]) = self.clip_load; + } + else + self.(self.current_ammo) -= ammo_use; +} + +// weapon reloading code + +.float reload_ammo_amount, reload_ammo_min, reload_time; +.float reload_complain; +.string reload_sound; + +void W_ReloadedAndReady() +{ + // if we are inside the stomach, don't allow reloading, and schedule the weapon to reload once when we're out + if(self.stat_eaten) + { + self.clip_load = self.(weapon_load[self.weapon]) = -1; + w_ready(); // don't keep executing each frame + return; + } + + // finish the reloading process, and 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.items & IT_UNLIMITED_WEAPON_AMMO) + self.clip_load = self.reload_ammo_amount; + else + { + while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo) >= 1) // make sure we don't add more ammo than we have + { + self.clip_load += 1; + self.(self.current_ammo) -= 1; + } + } + self.(weapon_load[self.weapon]) = self.clip_load; + + // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon, + // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there, + // so your weapon is disabled for a few seconds without reason + + //ATTACK_FINISHED(self) -= self.reload_time - 1; + + w_ready(); +} + +void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound) +{ + // if we are inside the stomach, don't allow reloading + if(self.stat_eaten) + return; + + // set global values to work with + self.reload_ammo_min = sent_ammo_min; + self.reload_ammo_amount = sent_ammo_amount; + self.reload_time = sent_time; + self.reload_sound = sent_sound; + + // check if we meet the necessary conditions to reload + + entity e; + e = get_weaponinfo(self.weapon); + + // don't reload weapons that don't have the RELOADABLE flag + if not(e.spawnflags & WEP_FLAG_RELOADABLE) + { + dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n"); + return; + } + // return if reloading is disabled for this weapon + if(!self.reload_ammo_amount) + return; + // our weapon is fully loaded, no need to reload + if (self.clip_load >= self.reload_ammo_amount) + return; + // no ammo, so nothing to load + if(self.(self.current_ammo) < 1 && self.reload_ammo_min) + if not(self.items & IT_UNLIMITED_WEAPON_AMMO) + { + if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time) + { + play2(self, "misc/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 + // disabled since we only have one weapon in VT, so nothing else to switch to if we're out of ammo + /*if not(weapon_action(self.weapon, WR_CHECKAMMO1) + weapon_action(self.weapon, WR_CHECKAMMO2)) + { + self.clip_load = -1; // reload later + W_SwitchToOtherWeapon(self); + }*/ + return; + } + + if (self.weaponentity) + { + if (self.weaponentity.wframe == WFRAME_RELOAD) + return; + + // allow switching away while reloading, but this will cause a new reload! + self.weaponentity.state = WS_READY; + } + + // now begin the reloading process + + // weapon reload effects + if(self.weapon == WEP_GRABBER && self.clip_load >= 0) // only when we first begin reloading + { + vector org; + org = self.origin + self.view_ofs + self.weaponentity.spawnorigin_x * v_forward - self.weaponentity.spawnorigin_y * v_right + self.weaponentity.spawnorigin_z * v_up; + SpawnCasing (org, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self); + pointparticles(particleeffectnum("grabber_reload"), org, '0 0 0', 1); + } + sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM); + + // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon, + // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there, + // so your weapon is disabled for a few seconds without reason + + //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1; + + weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady); + + if(self.clip_load < 0) + self.clip_load = 0; + self.old_clip_load = self.clip_load; + self.clip_load = self.(weapon_load[self.weapon]) = -1; +} \ No newline at end of file