X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=data%2Fqcsrc%2Fserver%2Fcl_weaponsystem.qc;h=100c4f8f618e08f98f13e9368f2fc457d4265d78;hb=dec59284d2680f03706822b2b94067cbb10d9813;hp=76ea196e3baaa9ad721f580c98d69613ed7fc54e;hpb=cc148bf19700d380a18d7f51a706f9bbe959811b;p=voretournament%2Fvoretournament.git diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index 76ea196e..100c4f8f 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,32 @@ 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")); + + self.effects &~= EF_NODEPTHTEST; + 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 +368,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 +397,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,17 +582,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'; @@ -736,7 +755,19 @@ 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 + self.weaponentity.scale = self.scale; + self.weaponentity.origin = self.origin; + } }; void CL_ExteriorWeaponentity_Think() @@ -755,6 +786,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; @@ -788,6 +820,7 @@ void CL_ExteriorWeaponentity_Think() self.alpha = self.owner.alpha; else self.alpha = 1; + self.colormod = self.owner.colormod; // used by the regurgitating colors ang_x = bound(sv_pitch_min, self.owner.v_angle_x, sv_pitch_max); ang_y = 0; @@ -818,7 +851,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; }; @@ -853,8 +895,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; @@ -870,7 +913,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) { @@ -889,12 +933,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) @@ -933,7 +977,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; }; @@ -969,30 +1013,48 @@ void weapon_setup(float windex) // the two weapon entities will notice this has changed and update their models self.weapon = windex; self.weaponname = e.mdl; - self.bulletcounter = 0; }; // 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; } @@ -1012,6 +1074,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 @@ -1026,10 +1093,19 @@ float weapon_prepareattack(float secondary, float attacktime) } ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor(); } - self.bulletcounter += 1; //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 +1585,251 @@ 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_DisplayDigitThink() +{ + self.nextthink = time; + + // the owner has switched to another weapon, remove the digits + if(self.weapon != self.owner.weapon || self.owner.classname != "player" || self.deadflag != DEAD_NO) + { + self.nextthink = 0; + remove(self); + self = world; + return; + } + + entity gun; + if(self.dmg) // exterior weapon + { + // keep the digit attached to the same bone as the gun + setattachment(self, self.owner, "bip01 r hand"); + gun = self.owner.exteriorweaponentity; + } + else // view weapon + { + // keep the digit attached to the same bone as the gun + // TODO: Does this work with self-animated weapons too? + if(gettagindex(self.owner.weaponentity, "weapon")) + setattachment(self, self.owner.weaponentity, "weapon"); + else if(gettagindex(self.owner.weaponentity, "tag_weapon")) + setattachment(self, self.owner.weaponentity, "tag_weapon"); + gun = self.owner.weaponentity; + } + + // copy all properties of the weapon to the digit + self.origin = gun.origin; + self.angles = gun.angles; + self.scale = gun.scale; + self.effects = gun.effects; + self.alpha = gun.alpha; + self.colormap = gun.colormap; + self.colormod = gun.colormod; // used by the regurgitating colors + self.glowmod = gun.glowmod; + + string txt; + if(self.team) // weapon load display + { + if(self.owner.weapon_load[self.owner.weapon] <= 0) + { + self.skin = 11; // unavailable digit + return; + } + else + { + txt = ftos(floor(self.owner.weapon_load[self.owner.weapon])); + txt = substring(txt, self.cnt - 1, 1); + } + } + else // ammo display + { + txt = ftos(floor(self.owner.(self.owner.current_ammo))); + txt = substring(txt, self.cnt - 1, 1); + } + + if((!txt || txt == "")) + self.skin = 10; // empty digit + else + self.skin = stof(txt); +} + +void W_DisplayDigitSetup(entity own, float num, float load, float exterior) +{ + entity digit, e; + digit = spawn(); + digit.owner = own; + digit.weapon = own.weapon; + digit.dmg = exterior; + digit.team = load; + digit.cnt = num; + e = get_weaponinfo(digit.weapon); + + if(load) + { + // weapon load digit + setmodel(digit, strcat("models/weapons/v_", e.netname, "_digit1-", ftos(num) , ".md3")); + } + else + { + // ammo count digit + setmodel(digit, strcat("models/weapons/v_", e.netname, "_digit2-", ftos(num) , ".md3")); + } + digit.think = W_DisplayDigitThink; + digit.nextthink = time; +} + +void W_Display(entity own, float load_num, float ammo_num) +{ + float i; + for(i = 1; i <= load_num; i++) + { + W_DisplayDigitSetup(own, i, TRUE, FALSE); // weapon load digit, view model + W_DisplayDigitSetup(own, i, TRUE, TRUE); // weapon load digit, exterior model + } + for(i = 1; i <= ammo_num; i++) + { + W_DisplayDigitSetup(own, i, FALSE, FALSE); // ammo count digit, view model + W_DisplayDigitSetup(own, i, FALSE, TRUE); // ammo count digit, exterior model + } +} + +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