X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fweaponsystem.qc;h=6139f2879cbf8e04718e18f7fc7848710c654532;hb=cd4892b9fcd32bd4887f0b3bc2503894520945c7;hp=3b8047efa19184abedfa0da26394ec0fdb0797f9;hpb=931d24d4337e58557fa82a68aa8a740e523c2f22;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 3b8047efa..6139f2879 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -8,12 +8,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include .int state; @@ -60,7 +62,6 @@ vector CL_Weapon_GetShotOrg(int wpn) return ret; } -..entity weaponentity_fld; .float m_alpha; .string w_weaponname; .int w_dmg; @@ -108,15 +109,13 @@ void CL_Weaponentity_Think(entity this) this.weaponchild.alpha = this.alpha; this.weaponchild.effects = this.effects; } - - wepent_update(this); } void CL_ExteriorWeaponentity_Think(entity this) { this.nextthink = time; .entity weaponentity = this.weaponentity_fld; - entity wepent = this.owner.(weaponentity); + entity w_ent = this.owner.(weaponentity); if (this.owner.exteriorweaponentity != this) { delete(this); @@ -127,15 +126,15 @@ void CL_ExteriorWeaponentity_Think(entity this) this.model = ""; return; } - if (this.weaponname != wepent.weaponname || this.dmg != wepent.modelindex - || this.deadflag != wepent.deadflag) + if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex + || this.deadflag != w_ent.deadflag) { - this.weaponname = wepent.weaponname; - this.dmg = wepent.modelindex; - this.deadflag = wepent.deadflag; - if (wepent.weaponname != "") + this.weaponname = w_ent.weaponname; + this.dmg = w_ent.modelindex; + this.deadflag = w_ent.deadflag; + if (w_ent.weaponname != "") { - _setmodel(this, W_Model(strcat("v_", wepent.weaponname, ".md3"))); + _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3"))); setsize(this, '0 0 0', '0 0 0'); } else this.model = ""; @@ -159,7 +158,7 @@ void CL_ExteriorWeaponentity_Think(entity this) else this.alpha = 1; Weapon wep = this.owner.(weaponentity).m_weapon; - if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors); + if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity)); this.colormap = this.owner.colormap; CSQCMODEL_AUTOUPDATE(this); @@ -181,7 +180,7 @@ void CL_SpawnWeaponentity(entity actor, .entity weaponentity) wepent_link(view); - if (weaponentity == weaponentities[0]) + if (weaponentity == weaponentities[0]) // only one exterior model, thank you very much { entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity); exterior.solid = SOLID_NOT; @@ -221,13 +220,13 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary { if ((actor.items & IT_UNLIMITED_WEAPON_AMMO)) return true; bool ammo = false; - if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor); - else ammo = thiswep.wr_checkammo1(thiswep, actor); + if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor, weaponentity); + else ammo = thiswep.wr_checkammo1(thiswep, actor, weaponentity); if (ammo) return true; // always keep the Mine Layer if we placed mines, so that we can detonate them if (thiswep == WEP_MINE_LAYER) { - IL_EACH(g_mines, it.owner == actor, + IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity, { return false; }); @@ -244,8 +243,8 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary // check if the other firing mode has enough ammo bool ammo_other = false; - if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor); - else ammo_other = thiswep.wr_checkammo2(thiswep, actor); + if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor, weaponentity); + else ammo_other = thiswep.wr_checkammo2(thiswep, actor, weaponentity); if (ammo_other) { if (time - actor.prevwarntime > 1) @@ -290,7 +289,7 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti { int slot = weaponslot(weaponentity); // don't fire if previous attack is not finished - if (ATTACK_FINISHED(actor, slot) > time + actor.weapon_frametime * 0.5) return false; + if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false; entity this = actor.(weaponentity); // don't fire while changing weapon if (this.state != WS_READY) return false; @@ -310,14 +309,14 @@ void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, if (attacktime >= 0) { int slot = weaponslot(weaponentity); - if (ATTACK_FINISHED(actor, slot) < time - actor.weapon_frametime * 1.5) + if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5) { ATTACK_FINISHED(actor, slot) = time; // dprint("resetting attack finished to ", ftos(time), "\n"); } ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor); } - actor.bulletcounter += 1; + this.bulletcounter += 1; // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n"); } @@ -381,8 +380,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void( this.weapon_nextthink = time; // dprint("started firing at ", ftos(time), "\n"); } - if (this.weapon_nextthink < time - actor.weapon_frametime * 1.5 - || this.weapon_nextthink > time + actor.weapon_frametime * 1.5) + if (this.weapon_nextthink < time - this.weapon_frametime * 1.5 + || this.weapon_nextthink > time + this.weapon_frametime * 1.5) { this.weapon_nextthink = time; // dprint("reset weapon animation timer at ", ftos(time), "\n"); @@ -401,8 +400,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void( if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t) { - bool primary_melee = boolean(fr == WFRAME_FIRE1 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_PRI)); - bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_SEC)); + bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI)); + bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC)); int act = (primary_melee || secondary_melee) ? ANIMACTION_MELEE : ANIMACTION_SHOOT @@ -434,14 +433,14 @@ void W_WeaponFrame(Player actor, .entity weaponentity) TC(Player, actor); TC(PlayerState, PS(actor)); entity this = actor.(weaponentity); - if (frametime) actor.weapon_frametime = frametime; + if (frametime) this.weapon_frametime = frametime; if (!this || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands if (forbidWeaponUse(actor)) { - if (actor.(weaponentity).state != WS_CLEAR) + if (this.state != WS_CLEAR) { Weapon wpn = this.m_weapon; w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1)); @@ -484,20 +483,19 @@ void W_WeaponFrame(Player actor, .entity weaponentity) // the two weapon entities will notice this has changed and update their models this.m_weapon = newwep; this.weaponname = newwep.mdl; - actor.bulletcounter = 0; - actor.ammo_field = newwep.ammo_field; - newwep.wr_setup(newwep, actor); + this.bulletcounter = 0; + newwep.wr_setup(newwep, actor, weaponentity); this.state = WS_RAISE; // set our clip load to the load of the weapon we switched to, if it's reloadable if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo) // prevent accessing undefined cvars { - actor.clip_load = actor.(weapon_load[this.m_switchweapon.m_id]); - actor.clip_size = newwep.reloading_ammo; + this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]); + this.clip_size = newwep.reloading_ammo; } else { - actor.clip_load = actor.clip_size = 0; + this.clip_load = this.clip_size = 0; } weapon_thinkf(actor, weaponentity, WFRAME_IDLE, newwep.switchdelay_raise, w_ready); @@ -516,7 +514,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) entity oldwep = this.m_weapon; // set up weapon switch think in the future, and start drop anim - if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + actor.weapon_frametime * 0.5) + if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5) { sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM); this.state = WS_DROP; @@ -540,7 +538,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) { if (w != WEP_Null && !(actor.weapons & WepSet_FromWeapon(w))) { - if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor), weaponentity); + if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); w = WEP_Null; } @@ -585,7 +583,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) } } - if (time + actor.weapon_frametime * 0.5 >= this.weapon_nextthink) + if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink) { if (this.weapon_think) { @@ -636,15 +634,15 @@ void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponentity) { - if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor)) return; + if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity))) return; if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return; // if this weapon is reloadable, decrease its load. Else decrease the player's ammo if (wep.reloading_ammo) { - actor.clip_load -= ammo_use; - actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.clip_load; + actor.(weaponentity).clip_load -= ammo_use; + actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).clip_load; } else if (wep.ammo_field != ammo_none) { @@ -674,29 +672,30 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int { // finish the reloading process, and do the ammo transfer - actor.clip_load = actor.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading + Weapon wpn = actor.(weaponentity).m_weapon; + + actor.(weaponentity).clip_load = actor.(weaponentity).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 (!actor.reload_ammo_min || actor.items & IT_UNLIMITED_WEAPON_AMMO || actor.ammo_field == ammo_none) + if (!actor.(weaponentity).reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none) { - actor.clip_load = actor.reload_ammo_amount; + actor.(weaponentity).clip_load = actor.(weaponentity).reload_ammo_amount; } else { // make sure we don't add more ammo than we have - float load = min(actor.reload_ammo_amount - actor.clip_load, actor.(actor.ammo_field)); - actor.clip_load += load; - actor.(actor.ammo_field) -= load; + float load = min(actor.(weaponentity).reload_ammo_amount - actor.(weaponentity).clip_load, actor.(wpn.ammo_field)); + actor.(weaponentity).clip_load += load; + actor.(wpn.ammo_field) -= load; } - actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.clip_load; + actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).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(actor, slot) -= actor.reload_time - 1; + // ATTACK_FINISHED(actor, slot) -= actor.(weaponentity).reload_time - 1; - Weapon wpn = Weapons_from(actor.(weaponentity).m_weapon.m_id); w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1)); } @@ -708,9 +707,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen if (MUTATOR_CALLHOOK(W_Reload, actor)) return; - actor.reload_ammo_min = sent_ammo_min; - actor.reload_ammo_amount = e.reloading_ammo; - actor.reload_time = e.reloading_time; + actor.(weaponentity).reload_ammo_min = sent_ammo_min; + actor.(weaponentity).reload_ammo_amount = e.reloading_ammo; + actor.(weaponentity).reload_time = e.reloading_time; if (actor.reload_sound) strunzone(actor.reload_sound); actor.reload_sound = strzone(Sound_fixpath(sent_sound)); @@ -723,15 +722,15 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen } // return if reloading is disabled for this weapon - if (!actor.reload_ammo_amount) return; + if (!actor.(weaponentity).reload_ammo_amount) return; // our weapon is fully loaded, no need to reload - if (actor.clip_load >= actor.reload_ammo_amount) return; + if (actor.(weaponentity).clip_load >= actor.(weaponentity).reload_ammo_amount) return; // no ammo, so nothing to load - if (actor.ammo_field != ammo_none) + if (e.ammo_field != ammo_none) { - if (!actor.(actor.ammo_field) && actor.reload_ammo_min) + if (!actor.(e.ammo_field) && actor.(weaponentity).reload_ammo_min) { if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { @@ -742,10 +741,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen actor.reload_complain = time + 1; } // switch away if the amount of ammo is not enough to keep using this weapon - Weapon w = actor.(weaponentity).m_weapon; - if (!(w.wr_checkammo1(w, actor) + w.wr_checkammo2(w, actor))) + if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity))) { - actor.clip_load = -1; // reload later + actor.(weaponentity).clip_load = -1; // reload later W_SwitchToOtherWeapon(actor, weaponentity); } return; @@ -770,18 +768,18 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen // 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(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + actor.reload_time + 1; + // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + actor.(weaponentity).reload_time + 1; - weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, actor.reload_time, W_ReloadedAndReady); + weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady); - if (actor.clip_load < 0) actor.clip_load = 0; - actor.old_clip_load = actor.clip_load; - actor.clip_load = actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = -1; + if (this.clip_load < 0) this.clip_load = 0; + this.old_clip_load = this.clip_load; + this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1; } -void W_DropEvent(.void(Weapon, entity actor) event, entity player, float weapon_type, entity weapon_item) +void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity) { Weapon w = Weapons_from(weapon_type); weapon_dropevent_item = weapon_item; - w.event(w, player); + w.event(w, player, weaponentity); }