Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
weaponsystem.qc File Reference
Include dependency graph for weaponsystem.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void CL_ExteriorWeaponentity_Think (entity this)
void CL_SpawnWeaponentity (entity actor,.entity weaponentity)
 Spawn weaponentity for client.
vector CL_Weapon_GetShotOrg (int wpn)
bool CL_Weaponentity_CustomizeEntityForClient (entity this, entity client)
void CL_Weaponentity_Think (entity this)
void W_AttachToShotorg (entity actor,.entity weaponentity, entity flash, vector offset)
void w_clear (Weapon thiswep, entity actor,.entity weaponentity, int fire)
void W_DecreaseAmmo (Weapon wep, entity actor, float ammo_use,.entity weaponentity)
void W_DropEvent (.void(Weapon, entity actor,.entity) event, entity player, int weapon_type, entity weapon_item,.entity weaponentity)
void w_ready (Weapon thiswep, entity actor,.entity weaponentity, int fire)
void W_Reload (entity actor,.entity weaponentity, float sent_ammo_min, Sound sent_sound)
void W_ReloadedAndReady (Weapon thiswep, entity actor,.entity weaponentity, int fire)
 Finish the reloading process, and do the ammo transfer.
void W_ResetGunAlign (entity player, int preferred_alignment)
void W_WeaponFrame (Player actor,.entity weaponentity)
float W_WeaponRateFactor (entity this)
float W_WeaponSpeedFactor (entity this)
bool weapon_prepareattack (Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
bool weapon_prepareattack_check (Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
bool weapon_prepareattack_checkammo (Weapon thiswep, entity actor, bool secondary,.entity weaponentity)
void weapon_prepareattack_do (entity actor,.entity weaponentity, bool secondary, float attacktime)
void weapon_thinkf (entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
bool weaponLocked (entity player)
bool weaponUseForbidden (entity player)

Variables

bool hook_switchweapon
float m_alpha
float prevdryfire
float prevwarntime
float race_penalty
float reload_ammo_amount
float reload_ammo_min
float reload_complain
string reload_sound
float reload_time
int state
int w_deadflag
int w_dmg
string w_weaponname
float weapon_frametime

Function Documentation

◆ CL_ExteriorWeaponentity_Think()

void CL_ExteriorWeaponentity_Think ( entity this)

Definition at line 130 of file weaponsystem.qc.

131{
132 this.nextthink = time;
133 .entity weaponentity = this.weaponentity_fld;
134 entity w_ent = this.owner.(weaponentity);
135 if (this.owner.exteriorweaponentity != this)
136 {
137 delete(this);
138 return;
139 }
140 if (IS_DEAD(this.owner))
141 {
142 this.model = "";
143 return;
144 }
145 if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex || this.deadflag != w_ent.deadflag)
146 {
147 this.weaponname = w_ent.weaponname;
148 this.dmg = w_ent.modelindex;
149 this.deadflag = w_ent.deadflag;
150 if (w_ent.weaponname != "")
151 {
152 _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3")));
153 setsize(this, '0 0 0', '0 0 0');
154 }
155 else
156 this.model = "";
157
158 int tag_found = gettagindex(this.owner, "tag_weapon");
159 if (tag_found)
160 {
161 this.tag_index = tag_found;
162 this.tag_entity = this.owner;
163 }
164 else
165 setattachment(this, this.owner, "bip01 r hand");
166 }
167 this.effects = this.owner.effects;
168 this.effects |= EF_LOWPRECISION;
169 this.effects &= EFMASK_CHEAP; // eat performance
170 if (this.owner.alpha == default_player_alpha)
172 else if (this.owner.alpha != 0)
173 this.alpha = this.owner.alpha;
174 else
175 this.alpha = 1;
176
177 Weapon wep = this.owner.(weaponentity).m_weapon;
178 if (wep)
179 this.glowmod = weaponentity_glowmod(wep, this.owner.clientcolors, this.owner.(weaponentity));
180 this.colormap = this.owner.colormap;
181 this.skin = w_ent.skin;
182
184}
float dmg
Definition breakable.qc:12
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
float alpha
Definition items.qc:13
entity owner
Definition main.qh:87
#define IS_DEAD(s)
Definition player.qh:244
#define EFMASK_CHEAP
Definition constants.qh:107
float effects
float skin
float time
float nextthink
float colormap
entity tag_entity
vector glowmod
int tag_index
#define CSQCMODEL_AUTOUPDATE(e)
float EF_LOWPRECISION
#define gettagindex
model
Definition ent_cs.qc:139
string W_Model(string w_mdl)
Definition all.qc:233
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float deadflag
Definition progsdefs.qc:149
vector weaponentity_glowmod(Weapon wep, int c, entity wepent)
Definition all.qh:402
string weaponname
Definition all.qh:413
entity weaponentity_fld
Weapon m_weapon
Definition wepent.qh:26
float default_weapon_alpha
Definition world.qh:73
float default_player_alpha
Definition world.qh:72

References alpha, colormap, CSQCMODEL_AUTOUPDATE, deadflag, default_player_alpha, default_weapon_alpha, dmg, EF_LOWPRECISION, effects, EFMASK_CHEAP, entity(), gettagindex, glowmod, IS_DEAD, m_weapon, model, nextthink, owner, skin, strcat(), tag_entity, tag_index, time, W_Model(), weaponentity_fld, weaponentity_glowmod(), and weaponname.

Referenced by CL_SpawnWeaponentity().

◆ CL_SpawnWeaponentity()

void CL_SpawnWeaponentity ( entity actor,
.entity weaponentity )

Spawn weaponentity for client.

Definition at line 187 of file weaponsystem.qc.

188{
189 entity w_ent = actor.(weaponentity) = new(weaponentity);
190 w_ent.solid = SOLID_NOT;
191 w_ent.owner = actor;
192 setmodel(w_ent, MDL_Null); // precision set when changed
193 setorigin(w_ent, '0 0 0');
194 w_ent.weaponentity_fld = weaponentity;
196 w_ent.nextthink = time;
197 w_ent.viewmodelforclient = actor;
198 w_ent.draggable = drag_undraggable;
200
201 wepent_link(w_ent);
202
203 if (weaponentity == weaponentities[0]) // only one exterior model, thank you very much
204 {
205 entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity);
206 exterior.solid = SOLID_NOT;
207 exterior.owner = actor;
208 exterior.draggable = drag_undraggable;
209 exterior.weaponentity_fld = weaponentity;
210 setorigin(exterior, '0 0 0');
212 exterior.nextthink = time;
213
214 CSQCMODEL_AUTOINIT(exterior);
215 }
216}
bool drag_undraggable(entity draggee, entity dragger)
Definition cheats.qc:900
#define setmodel(this, m)
Definition model.qh:26
const float SOLID_NOT
#define CSQCMODEL_AUTOINIT(e)
#define setthink(e, f)
#define setcefc(e, f)
entity exteriorweaponentity
Definition all.qh:401
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
void CL_Weaponentity_Think(entity this)
void CL_ExteriorWeaponentity_Think(entity this)
bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client)
void wepent_link(entity wep)
Definition wepent.qc:159

References CL_ExteriorWeaponentity_Think(), CL_Weaponentity_CustomizeEntityForClient(), CL_Weaponentity_Think(), CSQCMODEL_AUTOINIT, drag_undraggable(), entity(), exteriorweaponentity, setcefc, setmodel, setthink, SOLID_NOT, time, weaponentities, and wepent_link().

Referenced by PutPlayerInServer().

◆ CL_Weapon_GetShotOrg()

vector CL_Weapon_GetShotOrg ( int wpn)

Definition at line 64 of file weaponsystem.qc.

65{
66 entity wi = REGISTRY_GET(Weapons, wpn);
67 entity e = spawn();
68 CL_WeaponEntity_SetModel(e, wi.mdl, false);
69 vector ret = e.movedir;
70 CL_WeaponEntity_SetModel(e, "", false);
71 delete(e);
72 return ret;
73}
#define spawn
Weapons
Definition guide.qh:113
#define REGISTRY_GET(id, i)
Definition registry.qh:43
vector
Definition self.qh:92
void CL_WeaponEntity_SetModel(entity this, string name, bool _anim)
supported formats:
Definition all.qc:341

References CL_WeaponEntity_SetModel(), entity(), REGISTRY_GET, spawn, vector, and Weapons.

Referenced by PRECACHE().

◆ CL_Weaponentity_CustomizeEntityForClient()

bool CL_Weaponentity_CustomizeEntityForClient ( entity this,
entity client )

Definition at line 56 of file weaponsystem.qc.

57{
58 this.viewmodelforclient = this.owner;
59 if (IS_SPEC(client) && client.enemy == this.owner)
60 this.viewmodelforclient = client;
61 return false;
62}
entity viewmodelforclient
#define IS_SPEC(v)
Definition utils.qh:10

References entity(), IS_SPEC, owner, and viewmodelforclient.

Referenced by CL_SpawnWeaponentity().

◆ CL_Weaponentity_Think()

void CL_Weaponentity_Think ( entity this)

Definition at line 80 of file weaponsystem.qc.

81{
82 this.nextthink = time;
83 if (game_stopped)
84 this.frame = this.anim_idle.x;
85 .entity weaponentity = this.weaponentity_fld;
86 if (this.owner.(weaponentity) != this)
87 {
88 // owner has new gun; remove old one
89 if (this.weaponchild)
90 delete(this.weaponchild);
91 if (this.hook)
92 delete(this.hook);
93 delete(this);
94 return;
95 }
96 if (IS_DEAD(this.owner))
97 {
98 // owner died; disappear
99 this.model = "";
100 if (this.weaponchild)
101 this.weaponchild.model = "";
102 return;
103 }
104 if (this.w_weaponname != this.weaponname || this.w_dmg != this.modelindex || this.w_deadflag != this.deadflag)
105 {
106 // owner changed weapons; update appearance
107 this.w_weaponname = this.weaponname;
108 this.w_dmg = this.modelindex;
109 this.w_deadflag = this.deadflag;
110
111 CL_WeaponEntity_SetModel(this, this.weaponname, true);
112 }
113
114 this.alpha = -1; // TODO: don't render this entity at all
115
116 if (this.owner.alpha == default_player_alpha)
118 else if (this.owner.alpha != 0)
119 this.m_alpha = this.owner.alpha;
120 else
121 this.m_alpha = 1;
122
123 if (this.weaponchild)
124 {
125 this.weaponchild.alpha = this.alpha;
126 this.weaponchild.effects = this.effects;
127 }
128}
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
entity hook
Definition player.qh:238
float game_stopped
Definition stats.qh:81
float modelindex
float m_alpha
vector anim_idle
Definition all.qh:424
entity weaponchild
Definition all.qh:400
int w_deadflag
string w_weaponname
int w_dmg

References alpha, anim_idle, CL_WeaponEntity_SetModel(), deadflag, default_player_alpha, default_weapon_alpha, effects, entity(), frame, game_stopped, hook, IS_DEAD, m_alpha, model, modelindex, nextthink, owner, time, w_deadflag, w_dmg, w_weaponname, weaponchild, weaponentity_fld, and weaponname.

Referenced by CL_SpawnWeaponentity().

◆ W_AttachToShotorg()

void W_AttachToShotorg ( entity actor,
.entity weaponentity,
entity flash,
vector offset )

Definition at line 661 of file weaponsystem.qc.

662{
663 flash.owner = actor;
664 flash.angles_z = random() * 360;
665
666 entity w_ent = actor.(weaponentity);
667 entity exterior = actor.exteriorweaponentity;
668
669 setattachment(flash, w_ent, (gettagindex(w_ent, "shot") ? "shot" : "tag_shot"));
670 setorigin(flash, offset);
671
672 entity xflash = spawn();
673 copyentity_qc(flash, xflash);
674
675 flash.viewmodelforclient = actor;
676
677 if (w_ent.oldorigin.x > 0)
678 {
679 setattachment(xflash, exterior, "");
680 setorigin(xflash, w_ent.oldorigin + offset);
681 }
682 else
683 {
684 setattachment(xflash, exterior, (gettagindex(exterior, "shot") ? "shot" : "tag_shot"));
685 setorigin(xflash, offset);
686 }
687}
float random(void)
void copyentity_qc(entity src, entity dst)
Definition oo.qh:86

References copyentity_qc(), entity(), gettagindex, random(), spawn, and vector.

◆ w_clear()

void w_clear ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Definition at line 219 of file weaponsystem.qc.

220{
221 entity w_ent = actor.(weaponentity);
222 if (w_ent)
223 {
224 w_ent.m_weapon = WEP_Null;
225 w_ent.m_switchingweapon = WEP_Null;
226 w_ent.state = WS_CLEAR;
227 w_ent.effects = 0;
228 }
229}
const int WS_CLEAR
no weapon selected
Definition weapon.qh:30

References entity(), and WS_CLEAR.

Referenced by W_WeaponFrame().

◆ W_DecreaseAmmo()

void W_DecreaseAmmo ( Weapon wep,
entity actor,
float ammo_use,
.entity weaponentity )

Definition at line 689 of file weaponsystem.qc.

690{
691 if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity), ammo_use))
692 return;
693 if ((actor.items & IT_UNLIMITED_AMMO) && !wep.reloading_ammo)
694 return;
695
696 ammo_use = M_ARGV(2, float);
697
698 entity w_ent = actor.(weaponentity);
699
700 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
701 if (wep.reloading_ammo)
702 {
703 w_ent.clip_load -= ammo_use;
704 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
705 }
706 else if (wep.ammo_type != RES_NONE)
707 {
708 float ammo = GetResource(actor, wep.ammo_type);
709 if (ammo < ammo_use)
710 backtrace(sprintf(
711 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
712 "Please notify the developers immediately with a copy of this backtrace!\n",
713 ammo_use, wep.netname, wep.ammo_type.netname, actor.netname, ammo));
714
715 SetResource(actor, wep.ammo_type, ammo - ammo_use);
716 }
717}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
string netname
Definition resources.qh:27
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:56
string netname
M: refname : reference name name.
Definition weapon.qh:84
const int IT_UNLIMITED_AMMO
Definition item.qh:23
#define M_ARGV(x, type)
Definition events.qh:17
#define backtrace(msg)
Definition log.qh:99
float ammo
Definition sv_turrets.qh:43
void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use,.entity weaponentity)

References ammo, Weapon::ammo_type, backtrace, entity(), GetResource(), IT_UNLIMITED_AMMO, M_ARGV, MUTATOR_CALLHOOK, Resource::netname, Weapon::netname, SetResource(), and W_DecreaseAmmo().

Referenced by MUTATOR_HOOKABLE(), W_Crylink_Attack(), W_Crylink_Attack2(), W_DecreaseAmmo(), W_Devastator_Attack(), W_Electro_Attack_Bolt(), W_Electro_Attack_Orb(), W_Hagar_Attack(), W_Hagar_Attack2(), W_Hagar_Attack2_Load(), W_HLAC_Attack(), W_HLAC_Attack2(), W_MachineGun_Attack(), W_MachineGun_Attack_Auto(), W_MineLayer_Attack(), W_Mortar_Attack(), W_Mortar_Attack2(), W_OverkillHeavyMachineGun_Attack_Auto(), W_OverkillMachineGun_Attack_Auto(), W_OverkillNex_Attack(), W_OverkillRocketPropelledChainsaw_Attack(), W_Rifle_FireBullet(), W_Seeker_Fire_Flac(), W_Seeker_Fire_Missile(), W_Seeker_Fire_Tag(), W_Shotgun_Attack(), W_Vaporizer_Attack(), and W_Vortex_Attack().

◆ W_DropEvent()

void W_DropEvent ( .void(Weapon, entity actor,.entity) event,
entity player,
int weapon_type,
entity weapon_item,
.entity weaponentity )

Definition at line 833 of file weaponsystem.qc.

834{
835 Weapon w = REGISTRY_GET(Weapons, weapon_type);
836 weapon_dropevent_item = weapon_item;
837 w.event(w, player, weaponentity);
838}
entity weapon_dropevent_item

References entity(), REGISTRY_GET, weapon_dropevent_item, and Weapons.

Referenced by Item_GiveTo(), and W_ThrowNewWeapon().

◆ w_ready()

void w_ready ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Definition at line 231 of file weaponsystem.qc.

232{
233 entity w_ent = actor.(weaponentity);
234 if (w_ent)
235 w_ent.state = WS_READY;
236 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 1000000, w_ready);
237}
const int WS_READY
idle frame
Definition weapon.qh:38
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)

References entity(), w_ready(), weapon_thinkf(), and WS_READY.

Referenced by SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), SOUND(), W_Arc_Attack(), W_Arc_Attack_Bolt(), W_Electro_CheckAttack(), W_Fireball_Attack1_Frame4(), W_Hagar_Attack2_Load_Release(), W_Hagar_Attack_Auto(), W_HLAC_Attack_Frame(), W_MachineGun_Attack_Auto(), W_MachineGun_Attack_Burst(), W_MachineGun_Attack_Frame(), W_OverkillHeavyMachineGun_Attack_Auto(), W_OverkillMachineGun_Attack_Auto(), w_ready(), W_ReloadedAndReady(), W_Rifle_BulletHail(), W_Shotgun_Attack2(), W_Shotgun_Attack3_Frame1(), W_Shotgun_Attack3_Frame2(), W_WeaponFrame(), and weapon_thinkf().

◆ W_Reload()

void W_Reload ( entity actor,
.entity weaponentity,
float sent_ammo_min,
Sound sent_sound )

Definition at line 755 of file weaponsystem.qc.

756{
757 TC(Sound, sent_sound);
758 // set global values to work with
759 entity this = actor.(weaponentity);
760 Weapon e = this.m_weapon;
761
762 if (MUTATOR_CALLHOOK(W_Reload, actor))
763 return;
764
765 this.reload_ammo_min = sent_ammo_min;
766 this.reload_ammo_amount = e.reloading_ammo;
767 this.reload_time = e.reloading_time;
768 strcpy(actor.reload_sound, Sound_fixpath(sent_sound));
769
770 // don't reload weapons that don't have the RELOADABLE flag
771 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
772 {
773 LOG_TRACE("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
774 return;
775 }
776
777 // return if reloading is disabled for this weapon
778 if (!this.reload_ammo_amount)
779 return;
780
781 // our weapon is fully loaded, no need to reload
782 if (this.clip_load >= this.reload_ammo_amount)
783 return;
784
785 // no ammo, so nothing to load
786 if (e.ammo_type != RES_NONE
787 && !GetResource(actor, e.ammo_type) && this.reload_ammo_min
788 && !(actor.items & IT_UNLIMITED_AMMO))
789 {
790 if (autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0)
791 return; // in this case the primary weapon will do the switching when it runs out of ammo (TODO: do this same check but for other slots)
792 if (IS_REAL_CLIENT(actor) && actor.reload_complain < time)
793 {
794 play2(actor, SND(UNAVAILABLE));
795 sprint(actor, strcat("You don't have enough ammo to reload the ^2", this.m_weapon.m_name, "\n"));
796 actor.reload_complain = time + 1;
797 }
798 // switch away if the amount of ammo is not enough to keep using this weapon
799 if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity)))
800 {
801 this.clip_load = -1; // reload later
802 W_SwitchToOtherWeapon(actor, weaponentity);
803 }
804 return;
805 }
806 if (this)
807 {
808 if (this.wframe == WFRAME_RELOAD)
809 return;
810
811 // allow switching away while reloading, but this will cause a new reload!
812 this.state = WS_READY;
813 }
814
815 // now begin the reloading process
816
817 _sound(actor, CH_WEAPON_SINGLE, actor.reload_sound, VOL_BASE, ATTEN_NORM);
818
819 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
820 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
821 // so your weapon is disabled for a few seconds without reason
822
823 // ATTACK_FINISHED(actor, weaponentity) = max(time, ATTACK_FINISHED(actor, weaponentity)) + this.reload_time + 1;
824
825 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);
826
827 if (this.clip_load < 0)
828 this.clip_load = 0;
829 this.old_clip_load = this.clip_load;
830 this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1;
831}
int state
#define TC(T, sym)
Definition _all.inc:82
#define LOG_TRACE(...)
Definition log.qh:76
void sprint(float clientnum, string text,...)
void W_SwitchToOtherWeapon(entity this,.entity weaponentity)
Perform weapon to attack (weaponstate and attack_finished check is here)
Definition selection.qc:247
bool autocvar_g_weaponswitch_debug
Definition selection.qh:7
const int CH_WEAPON_SINGLE
Definition sound.qh:9
#define Sound_fixpath(this)
Definition sound.qh:141
const float VOL_BASE
Definition sound.qh:36
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
void play2(entity e, string filename)
Definition all.qc:116
#define SND(id)
Definition all.qh:35
#define strcpy(this, s)
Definition string.qh:52
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
WFRAME wframe
Definition all.qh:439
const int WEP_FLAG_RELOADABLE
Definition weapon.qh:259
int weaponslot(.entity weaponentity)
Definition weapon.qh:19
void W_Reload(entity actor,.entity weaponentity, float sent_ammo_min, Sound sent_sound)
float reload_ammo_amount
void W_ReloadedAndReady(Weapon thiswep, entity actor,.entity weaponentity, int fire)
Finish the reloading process, and do the ammo transfer.
float reload_ammo_min
float reload_time
int old_clip_load
float weapon_load[REGISTRY_MAX(Weapons)]
int clip_load
Definition wepent.qh:14

References _sound, ATTEN_NORM, autocvar_g_weaponswitch_debug, CH_WEAPON_SINGLE, clip_load, entity(), GetResource(), IS_REAL_CLIENT, IT_UNLIMITED_AMMO, LOG_TRACE, m_weapon, MUTATOR_CALLHOOK, old_clip_load, play2(), reload_ammo_amount, SND, Sound_fixpath, sprint(), state, strcat(), strcpy, TC, time, VOL_BASE, W_Reload(), W_ReloadedAndReady(), W_SwitchToOtherWeapon(), weapon_load, weapon_thinkf(), weaponslot(), WEP_FLAG_RELOADABLE, wframe, and WS_READY.

Referenced by MUTATOR_HOOKABLE(), and W_Reload().

◆ W_ReloadedAndReady()

void W_ReloadedAndReady ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Finish the reloading process, and do the ammo transfer.

Definition at line 726 of file weaponsystem.qc.

727{
728 entity w_ent = actor.(weaponentity);
729 Weapon wpn = w_ent.m_weapon;
730
731 w_ent.clip_load = w_ent.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
732
733 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
734 if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_AMMO) || wpn.ammo_type == RES_NONE)
735 w_ent.clip_load = w_ent.reload_ammo_amount;
736 else
737 {
738 // make sure we don't add more ammo than we have
739 float ammo = GetResource(actor, wpn.ammo_type);
740 float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, ammo);
741 w_ent.clip_load += load;
742 SetResource(actor, wpn.ammo_type, ammo - load);
743 }
744 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
745
746 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
747 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
748 // so your weapon is disabled for a few seconds without reason
749
750 // ATTACK_FINISHED(actor, weaponentity) -= w_ent.reload_time - 1;
751
752 w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
753}
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition player.qh:152
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition player.qh:154
float min(float f,...)

References ammo, entity(), GetResource(), IT_UNLIMITED_AMMO, min(), PHYS_INPUT_BUTTON_ATCK, PHYS_INPUT_BUTTON_ATCK2, SetResource(), and w_ready().

Referenced by W_Reload().

◆ W_ResetGunAlign()

void W_ResetGunAlign ( entity player,
int preferred_alignment )

Definition at line 446 of file weaponsystem.qc.

447{
448 if (W_DualWielding(player))
449 preferred_alignment = 3; // right align, the second gun will default to left
450
451 // clear current weapon slots' alignments so we can redo the calculations!
452 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
453 {
454 .entity weaponentity = weaponentities[slot];
455 if (player.(weaponentity))
456 player.(weaponentity).m_gunalign = 0;
457 }
458
459 // now set the new values
460 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
461 {
462 .entity weaponentity = weaponentities[slot];
463 if (player.(weaponentity))
464 player.(weaponentity).m_gunalign = W_GunAlign(player.(weaponentity), preferred_alignment);
465 }
466}
int W_GunAlign(entity this, int preferred_align)
bool W_DualWielding(entity player)
Definition common.qc:20
int m_gunalign
Definition all.qh:410
const int MAX_WEAPONSLOTS
Definition weapon.qh:16

References entity(), m_gunalign, MAX_WEAPONSLOTS, W_DualWielding(), W_GunAlign(), and weaponentities.

Referenced by PlayerThink(), and PutPlayerInServer().

◆ W_WeaponFrame()

void W_WeaponFrame ( Player actor,
.entity weaponentity )

Definition at line 470 of file weaponsystem.qc.

471{
472 TC(Player, actor);
473 TC(PlayerState, PS(actor));
474 entity this = actor.(weaponentity);
475 if (frametime)
477
478 if (!this || GetResource(actor, RES_HEALTH) < 1)
479 return; // Dead player can't use weapons and injure impulse commands
480
481 int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
482 int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
483
484 if (weaponUseForbidden(actor))
485 button_atck = button_atck2 = 0; // forbid primary and secondary fire, switching is allowed
486
487 if (weaponLocked(actor)
488 && this.state != WS_CLEAR)
489 {
490 Weapon wpn = this.m_weapon;
491 w_ready(wpn, actor, weaponentity, button_atck | (button_atck2 << 1));
492 return;
493 }
494
495 if (autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0)
496 {
497 .entity wepe1 = weaponentities[0];
498 entity wep1 = actor.(wepe1);
499 this.m_switchweapon = wep1.m_switchweapon;
500 entity store = IS_PLAYER(actor) ? PS(actor) : actor;
501 if (!(this.m_switchweapon.spawnflags & WEP_FLAG_DUALWIELD) && !(store.dual_weapons & wep1.m_switchweapon.m_wepset))
502 {
503 this.m_weapon = WEP_Null;
504 this.m_switchingweapon = WEP_Null;
505 this.m_switchweapon = WEP_Null;
506 this.state = WS_CLEAR;
507 this.weaponname = "";
508 this.clip_load = this.clip_size = this.old_clip_load = 0;
509 return;
510 }
511 }
512
513 if (this.m_switchweapon == WEP_Null)
514 {
515 if (this.state != WS_CLEAR)
516 w_ready(this.m_weapon, actor, weaponentity, button_atck | (button_atck2 << 1));
517 this.m_weapon = WEP_Null;
518 this.m_switchingweapon = WEP_Null;
519 this.state = WS_CLEAR;
520 this.weaponname = "";
521 this.clip_load = this.clip_size = this.old_clip_load = 0;
522 return;
523 }
524
525 vector fo, ri, up;
526 MAKE_VECTORS(actor.v_angle, fo, ri, up);
527
528 // Change weapon
529 if (this.m_weapon != this.m_switchweapon)
530 {
531 switch (this.state)
532 {
533 default:
534 LOG_WARNF("unhandled weaponentity (%i) state for player (%i): %d", this, actor, this.state);
535 break;
536 case WS_INUSE:
537 case WS_RAISE:
538 break;
539 case WS_CLEAR:
540 {
541 // end switching!
542 Weapon newwep = this.m_switchweapon;
543 this.m_switchingweapon = newwep;
544
545 // the two weapon entities will notice this has changed and update their models
546 this.m_weapon = newwep;
547 this.weaponname = newwep.mdl;
548 this.bulletcounter = 0;
549 newwep.wr_setup(newwep, actor, weaponentity);
550 this.state = WS_RAISE;
551
552 // set our clip load to the load of the weapon we switched to, if it's reloadable
553 if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo) // prevent accessing undefined cvars
554 {
555 this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]);
556 this.clip_size = newwep.reloading_ammo;
557 }
558 else
559 this.clip_load = this.clip_size = 0;
560
561 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, newwep.switchdelay_raise, w_ready);
562 break;
563 }
564 case WS_DROP:
565 // in dropping phase we can switch at any time
566 this.m_switchingweapon = this.m_switchweapon;
567 break;
568 case WS_READY:
569 {
570 // start switching!
571 this.m_switchingweapon = this.m_switchweapon;
572 entity oldwep = this.m_weapon;
573
574 // set up weapon switch think in the future, and start drop anim
575 if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponentity) <= time + this.weapon_frametime * 0.5)
576 {
577 sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
578 this.state = WS_DROP;
579 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
580 }
581 break;
582 }
583 }
584 }
585
586 // LordHavoc: network timing test code
587 // if (actor.button0)
588 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, weaponentity)), " >= ", ftos(this.weapon_nextthink), "\n");
589
590 Weapon w = this.m_weapon;
591
592 // call the think code which may fire the weapon
593 // and do so multiple times to resolve framerate dependency issues if the
594 // server framerate is very low and the weapon fire rate very high
595 for (int c = 0; c < W_TICSPERFRAME; ++c)
596 {
597 if (w != WEP_Null && !(STAT(WEAPONS, actor) & WepSet_FromWeapon(w)))
598 {
599 if (this.m_weapon == this.m_switchweapon)
600 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
601 w = WEP_Null;
602 }
603
604 v_forward = fo;
605 v_right = ri;
606 v_up = up;
607
608 bool block_weapon = false;
609 {
610 bool key_pressed = (PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle);
611 if (weaponUseForbidden(actor))
612 key_pressed = false;
613
614 Weapon off = actor.offhand;
615 if (off && (!(STAT(WEAPONS, actor) & WEPSET(HOOK)) || off != OFFHAND_HOOK))
616 {
617 if (off.offhand_think)
618 off.offhand_think(off, actor, key_pressed);
619 }
620 else
621 {
622 if (key_pressed && this.m_switchweapon != WEP_HOOK && !actor.hook_switchweapon)
623 W_SwitchWeapon(actor, WEP_HOOK, weaponentity);
624 actor.hook_switchweapon = key_pressed;
625 Weapon h = WEP_HOOK;
626 block_weapon = (this.m_weapon == h && (button_atck || key_pressed));
627 h.wr_think(h, actor, weaponentity, block_weapon ? 1 : 0);
628 }
629 }
630
631 v_forward = fo;
632 v_right = ri;
633 v_up = up;
634
635 if (!block_weapon)
636 {
637 Weapon e = this.m_weapon;
638 TC(Weapon, e);
639 if (w != WEP_Null)
640 e.wr_think(e, actor, weaponentity, button_atck | (button_atck2 << 1));
641 else if (e)
642 e.wr_gonethink(e, actor, weaponentity);
643 }
644
645 if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink)
646 {
647 if (this.weapon_think)
648 {
649 v_forward = fo;
650 v_right = ri;
651 v_up = up;
652 Weapon wpn = this.m_weapon;
653 this.weapon_think(wpn, actor, weaponentity, button_atck | (button_atck2 << 1));
654 }
655 else
656 bprint("\{1}^1ERROR: undefined weapon think function for ", actor.netname, "\n");
657 }
658 }
659}
string netname
Client name.
Definition client.qh:91
vector v_angle
Definition client.qh:145
Purpose: common player state, usable on client and server Client: singleton representing the viewed p...
Definition state.qh:8
virtual void wr_setup()
(SERVER) setup weapon data
Definition weapon.qh:96
virtual void wr_think()
(SERVER) logic to run every frame
Definition weapon.qh:98
string mdl
M: modelname : name of model (without g_ v_ or h_ prefixes)
Definition weapon.qh:65
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:60
virtual void wr_gonethink()
(SERVER) logic to run when weapon is lost
Definition weapon.qh:136
#define PHYS_INPUT_BUTTON_HOOK(s)
Definition player.qh:157
#define IS_PLAYER(s)
Definition player.qh:242
OffhandHook OFFHAND_HOOK
Definition hook.qh:83
vector v_up
float frametime
vector v_right
vector v_forward
const float ATTN_NORM
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:237
#define MAKE_VECTORS(angles, forward, right, up)
Same as the makevectors builtin but uses the provided locals instead of the v_* globals.
#define STAT(...)
Definition stats.qh:82
#define LOG_WARNF(...)
Definition log.qh:62
void bprint(string text,...)
bool W_SwitchWeapon(entity this, Weapon w,.entity weaponentity)
Definition selection.qc:265
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
#define sound(e, c, s, v, a)
Definition sound.qh:52
#define PS(this)
Definition state.qh:18
float weapon_nextthink
Definition view.qc:288
#define WEPSET(id)
Definition all.qh:47
#define WepSet_FromWeapon(it)
Definition all.qh:48
const int WS_RAISE
raise frame
Definition weapon.qh:32
const int WS_INUSE
fire state
Definition weapon.qh:36
const int WEP_FLAG_DUALWIELD
Definition weapon.qh:264
const int WS_DROP
deselecting frame
Definition weapon.qh:34
bool weaponUseForbidden(entity player)
void w_clear(Weapon thiswep, entity actor,.entity weaponentity, int fire)
float weapon_frametime
bool weaponLocked(entity player)
#define ATTACK_FINISHED(ent, w)
float bulletcounter
const int W_TICSPERFRAME
#define INDEPENDENT_ATTACK_FINISHED
Weapon m_switchweapon
Definition wepent.qh:25
Weapon m_switchingweapon
Definition wepent.qh:27
int clip_size
Definition wepent.qh:15

References ATTACK_FINISHED, ATTN_NORM, autocvar_g_weaponswitch_debug, bprint(), bulletcounter, CH_WEAPON_SINGLE, clip_load, clip_size, entity(), frametime, GetResource(), INDEPENDENT_ATTACK_FINISHED, IS_PLAYER, LOG_WARNF, m_switchingweapon, m_switchweapon, m_weapon, MAKE_VECTORS, Weapon::mdl, Client::netname, OFFHAND_HOOK, old_clip_load, PHYS_INPUT_BUTTON_ATCK, PHYS_INPUT_BUTTON_ATCK2, PHYS_INPUT_BUTTON_HOOK, PS, sound, Weapon::spawnflags, STAT, state, TC, time, Client::v_angle, v_forward, v_right, v_up, vector, VOL_BASE, w_clear(), w_getbestweapon, w_ready(), W_SwitchWeapon(), W_SwitchWeapon_Force(), W_TICSPERFRAME, weapon_frametime, weapon_load, weapon_nextthink, weapon_thinkf(), weaponentities, weaponLocked(), weaponname, weaponslot(), weaponUseForbidden(), WEP_FLAG_DUALWIELD, WEP_FLAG_RELOADABLE, WEPSET, WepSet_FromWeapon, Weapon::wr_gonethink(), Weapon::wr_setup(), Weapon::wr_think(), WS_CLEAR, WS_DROP, WS_INUSE, WS_RAISE, and WS_READY.

Referenced by PlayerThink(), and PutPlayerInServer().

◆ W_WeaponRateFactor()

◆ W_WeaponSpeedFactor()

float W_WeaponSpeedFactor ( entity this)

Definition at line 45 of file weaponsystem.qc.

46{
48
49 MUTATOR_CALLHOOK(WeaponSpeedFactor, t, this);
50 t = M_ARGV(0, float);
51
52 return t;
53}
float autocvar_g_weaponspeedfactor

References autocvar_g_weaponspeedfactor, entity(), M_ARGV, and MUTATOR_CALLHOOK.

Referenced by bot_aim(), W_CalculateProjectileVelocity(), and W_Devastator_Think().

◆ weapon_prepareattack()

bool weapon_prepareattack ( Weapon thiswep,
entity actor,
.entity weaponentity,
bool secondary,
float attacktime )

Definition at line 357 of file weaponsystem.qc.

358{
359 if (weapon_prepareattack_check(thiswep, actor, weaponentity, secondary, attacktime))
360 {
361 weapon_prepareattack_do(actor, weaponentity, secondary, attacktime);
362 return true;
363 }
364 return false;
365}
void weapon_prepareattack_do(entity actor,.entity weaponentity, bool secondary, float attacktime)
bool weapon_prepareattack_check(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)

References entity(), weapon_prepareattack_check(), and weapon_prepareattack_do().

Referenced by SOUND(), SOUND(), W_Electro_CheckAttack(), and W_Rifle_BulletHail_Continue().

◆ weapon_prepareattack_check()

bool weapon_prepareattack_check ( Weapon thiswep,
entity actor,
.entity weaponentity,
bool secondary,
float attacktime )

Definition at line 281 of file weaponsystem.qc.

282{
283 if (actor.weaponentity == NULL)
284 return true;
285 if (!weapon_prepareattack_checkammo(thiswep, actor, secondary, weaponentity))
286 return false;
287
288 // if sv_ready_restart_after_countdown is set, don't allow the player to shoot
289 // if all players readied up and the countdown is running
290 if (time < game_starttime || time < actor.race_penalty)
291 return false;
292
293 if (timeout_status == TIMEOUT_ACTIVE) // don't allow the player to shoot while game is paused
294 return false;
295
296 // do not even think about shooting if switching
297 if (actor.(weaponentity).m_switchweapon != actor.(weaponentity).m_weapon)
298 return false;
299
300 if (attacktime >= 0)
301 {
302 // don't fire if previous attack is not finished
303 if (ATTACK_FINISHED(actor, weaponentity) > time + actor.(weaponentity).weapon_frametime * 0.5)
304 return false;
305 entity this = actor.(weaponentity);
306 // don't fire while changing weapon
307 if (!actor.vehicle && this.state != WS_READY)
308 return false;
309 }
310 return true;
311}
int timeout_status
Definition stats.qh:87
float game_starttime
Definition stats.qh:82
#define NULL
Definition post.qh:14
const float TIMEOUT_ACTIVE
Definition common.qh:49
bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary,.entity weaponentity)

References ATTACK_FINISHED, entity(), game_starttime, NULL, time, TIMEOUT_ACTIVE, timeout_status, weapon_prepareattack_checkammo(), and WS_READY.

Referenced by W_Arc_Beam_Think(), W_Hagar_Attack_Auto(), W_MachineGun_Attack_Auto(), W_MachineGun_Attack_Frame(), and weapon_prepareattack().

◆ weapon_prepareattack_checkammo()

bool weapon_prepareattack_checkammo ( Weapon thiswep,
entity actor,
bool secondary,
.entity weaponentity )

Definition at line 241 of file weaponsystem.qc.

242{
243 if (actor.items & IT_UNLIMITED_AMMO)
244 return true;
245 bool ammo = (secondary)
246 ? thiswep.wr_checkammo2(thiswep, actor, weaponentity)
247 : thiswep.wr_checkammo1(thiswep, actor, weaponentity);
248 if (ammo)
249 return true;
250 // always keep the Mine Layer if we placed mines, so that we can detonate them
251 if (thiswep == WEP_MINE_LAYER)
252 IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity, return false);
253
254 if (thiswep == WEP_SHOTGUN
255 && !secondary && WEP_CVAR(WEP_SHOTGUN, secondary) == 1)
256 return false; // no clicking, just allow
257
258 if (thiswep == actor.(weaponentity).m_switchweapon && time - actor.prevdryfire > 1) // only play once BEFORE starting to switch weapons
259 {
260 sound(actor, CH_WEAPON_A, SND_DRYFIRE, VOL_BASE, ATTEN_NORM);
261 actor.prevdryfire = time;
262 }
263
264 // check if the other firing mode has enough ammo
265 bool ammo_other = (secondary)
266 ? thiswep.wr_checkammo1(thiswep, actor, weaponentity)
267 : thiswep.wr_checkammo2(thiswep, actor, weaponentity);
268 if (ammo_other)
269 {
270 if (time - actor.prevwarntime > 1)
271 Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_WEAPON_PRIMORSEC, thiswep.m_id, secondary, (1 - secondary));
272 actor.prevwarntime = time;
273 }
274 else // this weapon is totally unable to fire, switch to another one
275 W_SwitchToOtherWeapon(actor, weaponentity);
276
277 return false;
278}
int m_id
Definition weapon.qh:43
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:105
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:100
#define IL_EACH(this, cond, body)
IntrusiveList g_mines
Definition minelayer.qh:87
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1573
const int CH_WEAPON_A
Definition sound.qh:7
#define WEP_CVAR(wep, name)
Definition all.qh:337

References ammo, ATTEN_NORM, CH_WEAPON_A, entity(), g_mines, IL_EACH, IT_UNLIMITED_AMMO, Weapon::m_id, Send_Notification(), sound, time, VOL_BASE, W_SwitchToOtherWeapon(), WEP_CVAR, Weapon::wr_checkammo1(), and Weapon::wr_checkammo2().

Referenced by weapon_prepareattack_check().

◆ weapon_prepareattack_do()

void weapon_prepareattack_do ( entity actor,
.entity weaponentity,
bool secondary,
float attacktime )

Definition at line 313 of file weaponsystem.qc.

314{
315 entity this = actor.(weaponentity);
316 if (this == NULL)
317 return;
318 this.state = WS_INUSE;
319
320 if (StatusEffects_active(STATUSEFFECT_SpawnShield, actor)) // given this is performed often, perform a lighter check first
321 StatusEffects_remove(STATUSEFFECT_SpawnShield, actor, STATUSEFFECT_REMOVE_CLEAR); // kill spawn shield when you fire
322
323 // if the weapon hasn't been firing continuously, reset the timer
324 if (attacktime >= 0)
325 {
326 if (ATTACK_FINISHED(actor, weaponentity) < time - this.weapon_frametime * 1.5)
327 {
328 ATTACK_FINISHED(actor, weaponentity) = time;
329 // dprint("resetting attack finished to ", ftos(time), "\n");
330 }
331 float arate = W_WeaponRateFactor(actor);
332 ATTACK_FINISHED(actor, weaponentity) = ATTACK_FINISHED(actor, weaponentity) + attacktime * arate;
333
335 {
336 int slot = weaponslot(weaponentity);
337 for (int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot)
338 {
339 if (slot == wepslot)
340 continue;
341 .entity wepent = weaponentities[wepslot];
342 if (actor.(wepent) && actor.(wepent).m_weapon != WEP_Null)
343 {
344 if (ATTACK_FINISHED(actor, wepent) > time + actor.(wepent).weapon_frametime * 0.5)
345 continue; // still cooling down!
346 if (ATTACK_FINISHED(actor, wepent) < time - actor.(wepent).weapon_frametime * 1.5)
347 ATTACK_FINISHED(actor, wepent) = time;
348 ATTACK_FINISHED(actor, wepent) = ATTACK_FINISHED(actor, wepent) + (attacktime * arate) / MAX_WEAPONSLOTS;
349 }
350 }
351 }
352 }
353 ++this.bulletcounter;
354 // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, weaponentity)), "\n");
355}
@ STATUSEFFECT_REMOVE_CLEAR
Effect is being forcibly removed without calling any additional mechanics.
Definition all.qh:30
bool autocvar_g_weaponswitch_debug_alternate
Definition selection.qh:8
void StatusEffects_remove(StatusEffect this, entity actor, int removal_type)
bool StatusEffects_active(StatusEffect this, entity actor)
float W_WeaponRateFactor(entity this)

References ATTACK_FINISHED, autocvar_g_weaponswitch_debug_alternate, bulletcounter, entity(), MAX_WEAPONSLOTS, NULL, state, STATUSEFFECT_REMOVE_CLEAR, StatusEffects_active(), StatusEffects_remove(), time, W_DualWielding(), W_WeaponRateFactor(), weapon_frametime, weaponentities, weaponslot(), and WS_INUSE.

Referenced by W_Hagar_Attack2_Load_Release(), and weapon_prepareattack().

◆ weapon_thinkf()

void weapon_thinkf ( entity actor,
.entity weaponentity,
WFRAME fr,
float t,
void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func )
Parameters
tdefer thinking until time + t
funcnext think function

Definition at line 371 of file weaponsystem.qc.

373{
374 entity this = actor.(weaponentity);
375 if (this == NULL)
376 return;
377 bool restartanim;
378 if (fr == WFRAME_DONTCHANGE)
379 {
380 // this can happen when the weapon entity is newly spawned, since it has a clear state and no previous weapon frame
381 if (this.wframe == WFRAME_DONTCHANGE)
382 this.wframe = WFRAME_IDLE;
383 fr = this.wframe;
384 restartanim = false;
385 }
386 else
387 restartanim = fr != WFRAME_IDLE;
388
389 this.wframe = fr;
390
391 if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE)
392 backtrace("Tried to override initial weapon think function - should this really happen?");
393
394 t *= W_WeaponRateFactor(actor);
395
396 // VorteX: haste can be added here
397 if (this.weapon_think == w_ready)
398 {
399 this.weapon_nextthink = time;
400 // dprint("started firing at ", ftos(time), "\n");
401 }
402 float w_frametime_limit = this.weapon_frametime * 1.5;
404 {
405 this.weapon_nextthink = time;
406 // dprint("reset weapon animation timer at ", ftos(time), "\n");
407 }
408 this.weapon_nextthink += t;
409 this.weapon_think = func;
410 // dprint("next ", ftos(this.weapon_nextthink), "\n");
411
412 if (this)
413 FOREACH_CLIENT(it == actor || (IS_SPEC(it) && it.enemy == actor), wframe_send(it, this, fr, autocvar_g_weaponratefactor, restartanim));
414
415 if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
416 {
417 bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
418 bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
419 int act = (primary_melee || secondary_melee) ? ANIMACTION_MELEE : ANIMACTION_SHOOT;
420 animdecide_setaction(actor, act, restartanim);
421 }
422 else if (actor.anim_upper_action == ANIMACTION_SHOOT || actor.anim_upper_action == ANIMACTION_MELEE)
423 actor.anim_upper_action = 0;
424}
void animdecide_setaction(entity e, float action, float restart)
const int ANIMACTION_MELEE
const int ANIMACTION_SHOOT
#define boolean(value)
Definition bool.qh:9
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52
void wframe_send(entity actor, entity weaponentity, int wepframe, float attackrate, bool restartanim)
Definition all.qc:577
const int WEP_TYPE_MELEE_PRI
Definition weapon.qh:262
const int WEP_TYPE_MELEE_SEC
Definition weapon.qh:263

References ANIMACTION_MELEE, ANIMACTION_SHOOT, animdecide_setaction(), autocvar_g_weaponratefactor, backtrace, boolean, entity(), FOREACH_CLIENT, IS_SPEC, m_weapon, NULL, state, time, w_ready(), W_WeaponRateFactor(), weapon_frametime, weapon_nextthink, WEP_TYPE_MELEE_PRI, WEP_TYPE_MELEE_SEC, wframe, wframe_send(), and WS_RAISE.

Referenced by W_Arc_Attack(), W_Arc_Attack_Bolt(), W_Electro_CheckAttack(), W_Fireball_Attack1_Frame0(), W_Fireball_Attack1_Frame1(), W_Fireball_Attack1_Frame2(), W_Fireball_Attack1_Frame3(), W_Fireball_Attack1_Frame4(), W_Hagar_Attack2_Load_Release(), W_Hagar_Attack_Auto(), W_HLAC_Attack_Frame(), W_MachineGun_Attack_Auto(), W_MachineGun_Attack_Burst(), W_MachineGun_Attack_Frame(), W_OverkillHeavyMachineGun_Attack_Auto(), W_OverkillMachineGun_Attack_Auto(), w_ready(), W_Reload(), W_Rifle_BulletHail(), W_Rifle_BulletHail_Continue(), W_Shotgun_Attack2(), W_Shotgun_Attack3_Frame1(), W_Shotgun_Attack3_Frame2(), and W_WeaponFrame().

◆ weaponLocked()

bool weaponLocked ( entity player)

◆ weaponUseForbidden()

bool weaponUseForbidden ( entity player)

Definition at line 426 of file weaponsystem.qc.

427{
429 return true;
430 if (MUTATOR_CALLHOOK(ForbidWeaponUse, player))
431 return true;
432 return false;
433}
#define round_handler_IsActive()
#define round_handler_IsRoundStarted()

References entity(), MUTATOR_CALLHOOK, round_handler_IsActive, and round_handler_IsRoundStarted.

Referenced by bumblebee_gunner_frame(), bumblebee_pilot_frame(), racer_frame(), raptor_frame(), spiderbot_frame(), spiderbot_rocket_do(), W_Hagar_Attack2_Load(), and W_WeaponFrame().

Variable Documentation

◆ hook_switchweapon

bool hook_switchweapon

Definition at line 468 of file weaponsystem.qc.

◆ m_alpha

float m_alpha

Definition at line 75 of file weaponsystem.qc.

◆ prevdryfire

float prevdryfire

Definition at line 239 of file weaponsystem.qc.

◆ prevwarntime

float prevwarntime

Definition at line 240 of file weaponsystem.qc.

◆ race_penalty

float race_penalty

Definition at line 280 of file weaponsystem.qc.

◆ reload_ammo_amount

float reload_ammo_amount

Definition at line 721 of file weaponsystem.qc.

Referenced by W_Reload().

◆ reload_ammo_min

float reload_ammo_min

Definition at line 721 of file weaponsystem.qc.

◆ reload_complain

float reload_complain

Definition at line 722 of file weaponsystem.qc.

◆ reload_sound

string reload_sound

Definition at line 723 of file weaponsystem.qc.

◆ reload_time

float reload_time

Definition at line 721 of file weaponsystem.qc.

Referenced by X().

◆ state

int state

Definition at line 29 of file weaponsystem.qc.

◆ w_deadflag

int w_deadflag

Definition at line 78 of file weaponsystem.qc.

Referenced by CL_Weaponentity_Think().

◆ w_dmg

int w_dmg

Definition at line 77 of file weaponsystem.qc.

Referenced by CL_Weaponentity_Think().

◆ w_weaponname

string w_weaponname

Definition at line 76 of file weaponsystem.qc.

Referenced by CL_Weaponentity_Think().

◆ weapon_frametime

float weapon_frametime

Definition at line 31 of file weaponsystem.qc.

Referenced by W_WeaponFrame(), weapon_prepareattack_do(), and weapon_thinkf().