1 #include "weaponsystem.qh"
3 #include "selection.qh"
5 #include "../command/common.qh"
6 #include <server/mutators/_mod.qh>
7 #include "../round_handler.qh"
8 #include <server/cheats.qh>
9 #include <server/resources.qh>
10 #include <common/t_items.qh>
11 #include <common/animdecide.qh>
12 #include <common/constants.qh>
13 #include <common/net_linked.qh>
14 #include <common/monsters/_mod.qh>
15 #include <common/notifications/all.qh>
16 #include <common/util.qh>
17 #include <common/weapons/_all.qh>
18 #include <common/state.qh>
19 #include <lib/csqcmodel/sv_model.qh>
20 #include <common/wepent.qh>
24 .float weapon_frametime;
26 float W_WeaponRateFactor(entity this)
29 if(g_weaponratefactor > 0)
30 t = 1.0 / g_weaponratefactor;
32 MUTATOR_CALLHOOK(WeaponRateFactor, t, this);
38 float W_WeaponSpeedFactor(entity this)
40 float t = 1.0 * g_weaponspeedfactor;
42 MUTATOR_CALLHOOK(WeaponSpeedFactor, t, this);
49 bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client)
51 this.viewmodelforclient = this.owner;
52 if (IS_SPEC(client) && client.enemy == this.owner) this.viewmodelforclient = client;
56 vector CL_Weapon_GetShotOrg(int wpn)
58 entity wi = Weapons_from(wpn);
60 CL_WeaponEntity_SetModel(e, wi.mdl, false);
61 vector ret = e.movedir;
62 CL_WeaponEntity_SetModel(e, "", false);
72 void CL_Weaponentity_Think(entity this)
74 this.nextthink = time;
75 if (game_stopped) this.frame = this.anim_idle.x;
76 .entity weaponentity = this.weaponentity_fld;
77 if (this.owner.(weaponentity) != this)
79 // owner has new gun; remove old one
80 if (this.weaponchild) delete(this.weaponchild);
81 if (this.hook) delete(this.hook);
85 if (IS_DEAD(this.owner))
87 // owner died; disappear
89 if (this.weaponchild) this.weaponchild.model = "";
92 if (this.w_weaponname != this.weaponname
93 || this.w_dmg != this.modelindex
94 || this.w_deadflag != this.deadflag)
96 // owner changed weapons; update appearance
97 this.w_weaponname = this.weaponname;
98 this.w_dmg = this.modelindex;
99 this.w_deadflag = this.deadflag;
101 CL_WeaponEntity_SetModel(this, this.weaponname, true);
104 this.alpha = -1; // TODO: don't render this entity at all
106 if (this.owner.alpha == default_player_alpha) this.m_alpha = default_weapon_alpha;
107 else if (this.owner.alpha != 0) this.m_alpha = this.owner.alpha;
108 else this.m_alpha = 1;
110 if (this.weaponchild)
112 this.weaponchild.alpha = this.alpha;
113 this.weaponchild.effects = this.effects;
117 void CL_ExteriorWeaponentity_Think(entity this)
119 this.nextthink = time;
120 .entity weaponentity = this.weaponentity_fld;
121 entity w_ent = this.owner.(weaponentity);
122 if (this.owner.exteriorweaponentity != this)
127 if (IS_DEAD(this.owner))
132 if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex
133 || this.deadflag != w_ent.deadflag)
135 this.weaponname = w_ent.weaponname;
136 this.dmg = w_ent.modelindex;
137 this.deadflag = w_ent.deadflag;
138 if (w_ent.weaponname != "")
140 _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3")));
141 setsize(this, '0 0 0', '0 0 0');
143 else this.model = "";
146 if ((tag_found = gettagindex(this.owner, "tag_weapon")))
148 this.tag_index = tag_found;
149 this.tag_entity = this.owner;
153 setattachment(this, this.owner, "bip01 r hand");
156 this.effects = this.owner.effects;
157 this.effects |= EF_LOWPRECISION;
158 this.effects = this.effects & EFMASK_CHEAP; // eat performance
159 if (this.owner.alpha == default_player_alpha) this.alpha = default_weapon_alpha;
160 else if (this.owner.alpha != 0) this.alpha = this.owner.alpha;
163 Weapon wep = this.owner.(weaponentity).m_weapon;
164 if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity));
165 this.colormap = this.owner.colormap;
167 CSQCMODEL_AUTOUPDATE(this);
170 // spawning weaponentity for client
171 void CL_SpawnWeaponentity(entity actor, .entity weaponentity)
173 entity view = actor.(weaponentity) = new(weaponentity);
174 view.solid = SOLID_NOT;
176 setmodel(view, MDL_Null); // precision set when changed
177 setorigin(view, '0 0 0');
178 view.weaponentity_fld = weaponentity;
179 setthink(view, CL_Weaponentity_Think);
180 view.nextthink = time;
181 view.viewmodelforclient = actor;
182 view.draggable = drag_undraggable;
183 setcefc(view, CL_Weaponentity_CustomizeEntityForClient);
187 if (weaponentity == weaponentities[0]) // only one exterior model, thank you very much
189 entity exterior = actor.exteriorweaponentity = new(exteriorweaponentity);
190 exterior.solid = SOLID_NOT;
191 exterior.owner = actor;
192 exterior.draggable = drag_undraggable;
193 exterior.weaponentity_fld = weaponentity;
194 setorigin(exterior, '0 0 0');
195 setthink(exterior, CL_ExteriorWeaponentity_Think);
196 exterior.nextthink = time;
198 CSQCMODEL_AUTOINIT(exterior);
203 void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire)
205 actor.(weaponentity).m_weapon = WEP_Null;
206 actor.(weaponentity).m_switchingweapon = WEP_Null;
207 entity this = actor.(weaponentity);
210 this.state = WS_CLEAR;
215 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire)
217 entity this = actor.(weaponentity);
218 if (this) this.state = WS_READY;
219 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 1000000, w_ready);
224 bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary, .entity weaponentity)
226 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO)) return true;
228 if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
229 else ammo = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
230 if (ammo) return true;
231 // always keep the Mine Layer if we placed mines, so that we can detonate them
232 if (thiswep == WEP_MINE_LAYER)
234 IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity,
240 if (thiswep == WEP_SHOTGUN)
241 if (!secondary && WEP_CVAR(shotgun, secondary) == 1) return false; // no clicking, just allow
243 if (thiswep == actor.(weaponentity).m_switchweapon && time - actor.prevdryfire > 1) // only play once BEFORE starting to switch weapons
245 sound(actor, CH_WEAPON_A, SND_DRYFIRE, VOL_BASE, ATTEN_NORM);
246 actor.prevdryfire = time;
249 // check if the other firing mode has enough ammo
250 bool ammo_other = false;
251 if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
252 else ammo_other = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
255 if (time - actor.prevwarntime > 1)
261 ITEM_WEAPON_PRIMORSEC,
267 actor.prevwarntime = time;
269 else // this weapon is totally unable to fire, switch to another one
271 W_SwitchToOtherWeapon(actor, weaponentity);
278 bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
280 if (actor.weaponentity == NULL) return true;
281 if (!weapon_prepareattack_checkammo(thiswep, actor, secondary, weaponentity)) return false;
283 // if sv_ready_restart_after_countdown is set, don't allow the player to shoot
284 // if all players readied up and the countdown is running
285 if (time < game_starttime || time < actor.race_penalty) return false;
287 if (timeout_status == TIMEOUT_ACTIVE) // don't allow the player to shoot while game is paused
290 // do not even think about shooting if switching
291 if (actor.(weaponentity).m_switchweapon != actor.(weaponentity).m_weapon) return false;
295 int slot = weaponslot(weaponentity);
296 // don't fire if previous attack is not finished
297 if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
298 entity this = actor.(weaponentity);
299 // don't fire while changing weapon
300 if (this.state != WS_READY) return false;
305 void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, float attacktime)
307 entity this = actor.(weaponentity);
308 if (this == NULL) return;
309 this.state = WS_INUSE;
311 actor.spawnshieldtime = min(actor.spawnshieldtime, time); // kill spawn shield when you fire
313 // if the weapon hasn't been firing continuously, reset the timer
316 int slot = weaponslot(weaponentity);
317 if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5)
319 ATTACK_FINISHED(actor, slot) = time;
320 // dprint("resetting attack finished to ", ftos(time), "\n");
322 ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor);
324 this.bulletcounter += 1;
325 // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n");
328 bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bool secondary, float attacktime)
330 if (weapon_prepareattack_check(thiswep, actor, weaponentity, secondary, attacktime))
332 weapon_prepareattack_do(actor, weaponentity, secondary, attacktime);
339 * @param t defer thinking until time + t
340 * @param func next think function
342 void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,
343 .entity weaponentity, int fire) func)
345 entity this = actor.(weaponentity);
346 if (this == NULL) return;
348 if (fr == WFRAME_DONTCHANGE)
355 restartanim = fr != WFRAME_IDLE;
358 vector of = v_forward;
364 if (fr == WFRAME_IDLE) a = this.anim_idle;
365 else if (fr == WFRAME_FIRE1) a = this.anim_fire1;
366 else if (fr == WFRAME_FIRE2) a = this.anim_fire2;
367 else // if (fr == WFRAME_RELOAD)
368 a = this.anim_reload;
369 a.z *= g_weaponratefactor;
375 if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE) backtrace(
376 "Tried to override initial weapon think function - should this really happen?");
378 t *= W_WeaponRateFactor(actor);
380 // VorteX: haste can be added here
381 if (this.weapon_think == w_ready)
383 this.weapon_nextthink = time;
384 // dprint("started firing at ", ftos(time), "\n");
386 if (this.weapon_nextthink < time - this.weapon_frametime * 1.5
387 || this.weapon_nextthink > time + this.weapon_frametime * 1.5)
389 this.weapon_nextthink = time;
390 // dprint("reset weapon animation timer at ", ftos(time), "\n");
392 this.weapon_nextthink += t;
393 this.weapon_think = func;
394 // dprint("next ", ftos(this.weapon_nextthink), "\n");
398 FOREACH_CLIENT(true, {
399 if(it == actor || (IS_SPEC(it) && it.enemy == actor))
400 wframe_send(it, this, a, restartanim);
404 if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
406 bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
407 bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
408 int act = (primary_melee || secondary_melee)
412 animdecide_setaction(actor, act, restartanim);
414 else if (actor.anim_upper_action == ANIMACTION_SHOOT || actor.anim_upper_action == ANIMACTION_MELEE)
416 actor.anim_upper_action = 0;
420 bool forbidWeaponUse(entity player)
422 if (time < game_starttime && !sv_ready_restart_after_countdown) return true;
423 if (player.player_blocked) return true;
424 if (game_stopped) return true;
425 if (STAT(FROZEN, player)) return true;
426 if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
430 .bool hook_switchweapon;
432 void W_WeaponFrame(Player actor, .entity weaponentity)
435 TC(PlayerState, PS(actor));
436 entity this = actor.(weaponentity);
437 if (frametime) this.weapon_frametime = frametime;
439 if (!this || GetResourceAmount(actor, RESOURCE_HEALTH) < 1) return; // Dead player can't use weapons and injure impulse commands
441 int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
442 int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
444 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
445 button_atck = button_atck2 = 0; // forbid primary and secondary fire, switching is allowed
447 if (forbidWeaponUse(actor))
449 if (this.state != WS_CLEAR)
451 Weapon wpn = this.m_weapon;
452 w_ready(wpn, actor, weaponentity, button_atck | (button_atck2 << 1));
457 if(autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0)
459 .entity wepe1 = weaponentities[0];
460 entity wep1 = actor.(wepe1);
461 this.m_switchweapon = wep1.m_switchweapon;
462 entity store = IS_PLAYER(actor) ? PS(actor) : actor;
463 if(!(this.m_switchweapon.spawnflags & WEP_FLAG_DUALWIELD) && !(store.dual_weapons & wep1.m_switchweapon.m_wepset))
465 this.m_weapon = WEP_Null;
466 this.m_switchingweapon = WEP_Null;
467 this.m_switchweapon = WEP_Null;
468 this.state = WS_CLEAR;
469 this.weaponname = "";
474 if (this.m_switchweapon == WEP_Null)
476 if (this.state != WS_CLEAR)
477 w_ready(this.m_weapon, actor, weaponentity, button_atck | (button_atck2 << 1));
478 this.m_weapon = WEP_Null;
479 this.m_switchingweapon = WEP_Null;
480 this.state = WS_CLEAR;
481 this.weaponname = "";
485 makevectors(actor.v_angle);
486 vector fo = v_forward; // save them in case the weapon think functions change it
491 if (this.m_weapon != this.m_switchweapon)
496 LOG_WARNF("unhandled weaponentity (%i) state for player (%i): %d", this, actor, this.state);
504 Weapon newwep = this.m_switchweapon;
505 this.m_switchingweapon = newwep;
507 // the two weapon entities will notice this has changed and update their models
508 this.m_weapon = newwep;
509 this.weaponname = newwep.mdl;
510 this.bulletcounter = 0;
511 newwep.wr_setup(newwep, actor, weaponentity);
512 this.state = WS_RAISE;
514 // set our clip load to the load of the weapon we switched to, if it's reloadable
515 if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo) // prevent accessing undefined cvars
517 this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]);
518 this.clip_size = newwep.reloading_ammo;
522 this.clip_load = this.clip_size = 0;
525 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, newwep.switchdelay_raise, w_ready);
530 // in dropping phase we can switch at any time
531 this.m_switchingweapon = this.m_switchweapon;
537 this.m_switchingweapon = this.m_switchweapon;
538 entity oldwep = this.m_weapon;
540 // set up weapon switch think in the future, and start drop anim
541 if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5)
543 sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
544 this.state = WS_DROP;
545 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
552 // LordHavoc: network timing test code
553 // if (actor.button0)
554 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(this.weapon_nextthink), "\n");
556 Weapon w = this.m_weapon;
558 // call the think code which may fire the weapon
559 // and do so multiple times to resolve framerate dependency issues if the
560 // server framerate is very low and the weapon fire rate very high
561 for (int c = 0; c < W_TICSPERFRAME; ++c)
563 if (w != WEP_Null && !(STAT(WEAPONS, actor) & WepSet_FromWeapon(w)))
565 if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
573 bool block_weapon = false;
575 bool key_pressed = PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle;
576 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
579 Weapon off = actor.offhand;
580 if (off && (!(STAT(WEAPONS, actor) & WEPSET(HOOK)) || off != OFFHAND_HOOK))
582 if (off.offhand_think) off.offhand_think(off, actor, key_pressed);
586 if (key_pressed && this.m_switchweapon != WEP_HOOK && !actor.hook_switchweapon)
587 W_SwitchWeapon(actor, WEP_HOOK, weaponentity);
588 actor.hook_switchweapon = key_pressed;
590 block_weapon = (this.m_weapon == h && (button_atck || key_pressed));
591 h.wr_think(h, actor, weaponentity, block_weapon ? 1 : 0);
601 Weapon e = this.m_weapon;
605 e.wr_think(e, actor, weaponentity, button_atck | (button_atck2 << 1));
609 e.wr_gonethink(e, actor, weaponentity);
613 if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink)
615 if (this.weapon_think)
620 Weapon wpn = this.m_weapon;
621 this.weapon_think(wpn, actor, weaponentity,
622 button_atck | (button_atck2 << 1));
626 bprint("\{1}^1ERROR: undefined weapon think function for ", actor.netname, "\n");
632 void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector offset)
635 flash.angles_z = random() * 360;
637 entity view = actor.(weaponentity);
638 entity exterior = actor.exteriorweaponentity;
640 if (gettagindex(view, "shot")) setattachment(flash, view, "shot");
641 else setattachment(flash, view, "tag_shot");
642 setorigin(flash, offset);
644 entity xflash = spawn();
645 copyentity(flash, xflash);
647 flash.viewmodelforclient = actor;
649 if (view.oldorigin.x > 0)
651 setattachment(xflash, exterior, "");
652 setorigin(xflash, view.oldorigin + offset);
656 if (gettagindex(exterior, "shot")) setattachment(xflash, exterior, "shot");
657 else setattachment(xflash, exterior, "tag_shot");
658 setorigin(xflash, offset);
662 void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponentity)
664 if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity), ammo_use)) return;
665 if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return;
667 ammo_use = M_ARGV(2, float);
669 entity w_ent = actor.(weaponentity);
671 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
672 if (wep.reloading_ammo)
674 w_ent.clip_load -= ammo_use;
675 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
677 else if (wep.ammo_type != RESOURCE_NONE)
679 float ammo = GetResourceAmount(actor, wep.ammo_type);
683 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
684 "Please notify Samual immediately with a copy of this backtrace!\n",
687 GetAmmoPicture(wep.ammo_type),
692 SetResourceAmount(actor, wep.ammo_type, ammo - ammo_use);
696 // weapon reloading code
698 .float reload_ammo_amount, reload_ammo_min, reload_time;
699 .float reload_complain;
700 .string reload_sound;
702 void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int fire)
704 // finish the reloading process, and do the ammo transfer
706 entity w_ent = actor.(weaponentity);
707 Weapon wpn = w_ent.m_weapon;
709 w_ent.clip_load = w_ent.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
711 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
712 if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_type == RESOURCE_NONE)
714 w_ent.clip_load = w_ent.reload_ammo_amount;
718 // make sure we don't add more ammo than we have
719 float ammo = GetResourceAmount(actor, wpn.ammo_type);
720 float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, ammo);
721 w_ent.clip_load += load;
722 SetResourceAmount(actor, wpn.ammo_type, ammo - load);
724 w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
726 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
727 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
728 // so your weapon is disabled for a few seconds without reason
730 // ATTACK_FINISHED(actor, slot) -= w_ent.reload_time - 1;
732 w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
735 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound)
737 TC(Sound, sent_sound);
738 // set global values to work with
739 entity this = actor.(weaponentity);
740 Weapon e = this.m_weapon;
742 if (MUTATOR_CALLHOOK(W_Reload, actor)) return;
744 this.reload_ammo_min = sent_ammo_min;
745 this.reload_ammo_amount = e.reloading_ammo;
746 this.reload_time = e.reloading_time;
747 strcpy(actor.reload_sound, Sound_fixpath(sent_sound));
749 // don't reload weapons that don't have the RELOADABLE flag
750 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
753 "Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
757 // return if reloading is disabled for this weapon
758 if (!this.reload_ammo_amount) return;
760 // our weapon is fully loaded, no need to reload
761 if (this.clip_load >= this.reload_ammo_amount) return;
763 // no ammo, so nothing to load
764 if (e.ammo_type != RESOURCE_NONE)
766 if (!GetResourceAmount(actor, e.ammo_type) && this.reload_ammo_min)
768 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
770 if (IS_REAL_CLIENT(actor) && actor.reload_complain < time)
772 play2(actor, SND(UNAVAILABLE));
773 sprint(actor, strcat("You don't have enough ammo to reload the ^2", this.m_weapon.m_name, "\n"));
774 actor.reload_complain = time + 1;
776 // switch away if the amount of ammo is not enough to keep using this weapon
777 if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity)))
779 this.clip_load = -1; // reload later
780 W_SwitchToOtherWeapon(actor, weaponentity);
789 if (this.wframe == WFRAME_RELOAD) return;
791 // allow switching away while reloading, but this will cause a new reload!
792 this.state = WS_READY;
795 // now begin the reloading process
797 _sound(actor, CH_WEAPON_SINGLE, actor.reload_sound, VOL_BASE, ATTEN_NORM);
799 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
800 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
801 // so your weapon is disabled for a few seconds without reason
803 // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + this.reload_time + 1;
805 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);
807 if (this.clip_load < 0) this.clip_load = 0;
808 this.old_clip_load = this.clip_load;
809 this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1;
812 void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)
814 Weapon w = Weapons_from(weapon_type);
815 weapon_dropevent_item = weapon_item;
816 w.event(w, player, weaponentity);