1 #include "weaponsystem.qh"
4 #include "selection.qh"
6 #include "../command/common.qh"
7 #include "../mutators/mutators_include.qh"
8 #include "../round_handler.qh"
9 #include "../t_items.qh"
10 #include "../../common/animdecide.qh"
11 #include "../../common/constants.qh"
12 #include "../../common/monsters/all.qh"
13 #include "../../common/notifications.qh"
14 #include "../../common/util.qh"
15 #include "../../common/weapons/all.qh"
16 #include "../../csqcmodellib/sv_model.qh"
19 ===========================================================================
21 CLIENT WEAPONSYSTEM CODE
22 Bring back W_Weaponframe
24 ===========================================================================
27 .float weapon_frametime;
29 float W_WeaponRateFactor()
32 t = 1.0 / g_weaponratefactor;
35 MUTATOR_CALLHOOK(WeaponRateFactor);
41 float W_WeaponSpeedFactor()
44 t = 1.0 * g_weaponspeedfactor;
47 MUTATOR_CALLHOOK(WeaponSpeedFactor);
54 void(float fr, float t, void() func) weapon_thinkf;
56 float CL_Weaponentity_CustomizeEntityForClient()
58 self.viewmodelforclient = self.owner;
60 if(other.enemy == self.owner)
61 self.viewmodelforclient = other;
68 * 1. simple animated model, muzzle flash handling on h_ model:
69 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
71 * shot = muzzle end (shot origin, also used for muzzle flashes)
72 * shell = casings ejection point (must be on the right hand side of the gun)
73 * weapon = attachment for v_tuba.md3
74 * v_tuba.md3 - first and third person model
75 * g_tuba.md3 - pickup model
77 * 2. simple animated model, muzzle flash handling on v_ model:
78 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
80 * weapon = attachment for v_tuba.md3
81 * v_tuba.md3 - first and third person model
83 * shot = muzzle end (shot origin, also used for muzzle flashes)
84 * shell = casings ejection point (must be on the right hand side of the gun)
85 * g_tuba.md3 - pickup model
87 * 3. fully animated model, muzzle flash handling on h_ model:
88 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
90 * shot = muzzle end (shot origin, also used for muzzle flashes)
91 * shell = casings ejection point (must be on the right hand side of the gun)
92 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
93 * v_tuba.md3 - third person model
94 * g_tuba.md3 - pickup model
96 * 4. fully animated model, muzzle flash handling on v_ model:
97 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
99 * shot = muzzle end (shot origin)
100 * shell = casings ejection point (must be on the right hand side of the gun)
101 * v_tuba.md3 - third person model
103 * shot = muzzle end (for muzzle flashes)
104 * g_tuba.md3 - pickup model
108 // self.origin, self.angles
110 // self.movedir, self.view_ofs
114 // call again with ""
116 void CL_WeaponEntity_SetModel(string name)
121 // if there is a child entity, hide it until we're sure we use it
122 if (self.weaponentity)
123 self.weaponentity.model = "";
124 setmodel(self, strcat("models/weapons/v_", name, ".md3")); // precision set below
125 v_shot_idx = gettagindex(self, "shot"); // used later
127 v_shot_idx = gettagindex(self, "tag_shot");
129 setmodel(self, strcat("models/weapons/h_", name, ".iqm")); // precision set below
130 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
131 self.anim_fire1 = animfixfps(self, '0 1 0.01', '0 0 0');
132 self.anim_fire2 = animfixfps(self, '1 1 0.01', '0 0 0');
133 self.anim_idle = animfixfps(self, '2 1 0.01', '0 0 0');
134 self.anim_reload = animfixfps(self, '3 1 0.01', '0 0 0');
136 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
137 // if we don't, this is a "real" animated model
138 if(gettagindex(self, "weapon"))
140 if (!self.weaponentity)
141 self.weaponentity = spawn();
142 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
143 setattachment(self.weaponentity, self, "weapon");
145 else if(gettagindex(self, "tag_weapon"))
147 if (!self.weaponentity)
148 self.weaponentity = spawn();
149 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
150 setattachment(self.weaponentity, self, "tag_weapon");
154 if(self.weaponentity)
155 remove(self.weaponentity);
156 self.weaponentity = world;
159 setorigin(self,'0 0 0');
160 self.angles = '0 0 0';
162 self.viewmodelforclient = world;
166 if(v_shot_idx) // v_ model attached to invisible h_ model
168 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
172 idx = gettagindex(self, "shot");
174 idx = gettagindex(self, "tag_shot");
176 self.movedir = gettaginfo(self, idx);
179 print("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
180 self.movedir = '0 0 0';
184 if(self.weaponentity) // v_ model attached to invisible h_ model
186 idx = gettagindex(self.weaponentity, "shell");
188 idx = gettagindex(self.weaponentity, "tag_shell");
190 self.spawnorigin = gettaginfo(self.weaponentity, idx);
196 idx = gettagindex(self, "shell");
198 idx = gettagindex(self, "tag_shell");
200 self.spawnorigin = gettaginfo(self, idx);
203 print("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
204 self.spawnorigin = self.movedir;
210 self.oldorigin = '0 0 0'; // use regular attachment
214 if(self.weaponentity)
216 idx = gettagindex(self, "weapon");
218 idx = gettagindex(self, "tag_weapon");
222 idx = gettagindex(self, "handle");
224 idx = gettagindex(self, "tag_handle");
228 self.oldorigin = self.movedir - gettaginfo(self, idx);
232 print("WARNING: weapon model ", self.model, " does not support the 'handle' tag and neither does the v_ model support the 'shot' tag, will display muzzle flashes TOTALLY wrong\n");
233 self.oldorigin = '0 0 0'; // there is no way to recover from this
237 self.viewmodelforclient = self.owner;
242 if(self.weaponentity)
243 remove(self.weaponentity);
244 self.weaponentity = world;
245 self.movedir = '0 0 0';
246 self.spawnorigin = '0 0 0';
247 self.oldorigin = '0 0 0';
248 self.anim_fire1 = '0 1 0.01';
249 self.anim_fire2 = '0 1 0.01';
250 self.anim_idle = '0 1 0.01';
251 self.anim_reload = '0 1 0.01';
254 self.view_ofs = '0 0 0';
256 if(self.movedir.x >= 0)
260 self.movedir = shotorg_adjust(v0, false, false);
261 self.view_ofs = shotorg_adjust(v0, false, true) - v0;
263 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
264 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
266 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
268 // check if an instant weapon switch occurred
269 setorigin(self, self.view_ofs);
270 // reset animstate now
271 self.wframe = WFRAME_IDLE;
272 setanim(self, self.anim_idle, true, false, true);
275 vector CL_Weapon_GetShotOrg(float wpn)
279 wi = get_weaponinfo(wpn);
282 CL_WeaponEntity_SetModel(wi.mdl);
284 CL_WeaponEntity_SetModel("");
290 void CL_Weaponentity_Think()
293 self.nextthink = time;
294 if (intermission_running)
295 self.frame = self.anim_idle.x;
296 if (self.owner.weaponentity != self)
298 if (self.weaponentity)
299 remove(self.weaponentity);
303 if (self.owner.deadflag != DEAD_NO)
306 if (self.weaponentity)
307 self.weaponentity.model = "";
310 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
312 self.weaponname = self.owner.weaponname;
313 self.dmg = self.owner.modelindex;
314 self.deadflag = self.owner.deadflag;
316 CL_WeaponEntity_SetModel(self.owner.weaponname);
319 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
320 self.effects = self.owner.effects & EFMASK_CHEAP;
321 self.effects &= ~EF_LOWPRECISION;
322 self.effects &= ~EF_FULLBRIGHT; // can mask team color, so get rid of it
323 self.effects &= ~EF_TELEPORT_BIT;
324 self.effects &= ~EF_RESTARTANIM_BIT;
327 if(self.owner.alpha == default_player_alpha)
328 self.alpha = default_weapon_alpha;
329 else if(self.owner.alpha != 0)
330 self.alpha = self.owner.alpha;
334 self.glowmod = self.owner.weaponentity_glowmod;
335 self.colormap = self.owner.colormap;
336 if (self.weaponentity)
338 self.weaponentity.effects = self.effects;
339 self.weaponentity.alpha = self.alpha;
340 self.weaponentity.colormap = self.colormap;
341 self.weaponentity.glowmod = self.glowmod;
344 self.angles = '0 0 0';
346 float f = (self.owner.weapon_nextthink - time);
347 if (self.state == WS_RAISE && !intermission_running)
349 entity newwep = get_weaponinfo(self.owner.switchweapon);
350 f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
351 self.angles_x = -90 * f * f;
353 else if (self.state == WS_DROP && !intermission_running)
355 entity oldwep = get_weaponinfo(self.owner.weapon);
356 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
357 self.angles_x = -90 * f * f;
359 else if (self.state == WS_CLEAR)
362 self.angles_x = -90 * f * f;
366 void CL_ExteriorWeaponentity_Think()
369 self.nextthink = time;
370 if (self.owner.exteriorweaponentity != self)
375 if (self.owner.deadflag != DEAD_NO)
380 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
382 self.weaponname = self.owner.weaponname;
383 self.dmg = self.owner.modelindex;
384 self.deadflag = self.owner.deadflag;
385 if (self.owner.weaponname != "")
386 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
390 if((tag_found = gettagindex(self.owner, "tag_weapon")))
392 self.tag_index = tag_found;
393 self.tag_entity = self.owner;
396 setattachment(self, self.owner, "bip01 r hand");
398 self.effects = self.owner.effects;
399 self.effects |= EF_LOWPRECISION;
400 self.effects = self.effects & EFMASK_CHEAP; // eat performance
401 if(self.owner.alpha == default_player_alpha)
402 self.alpha = default_weapon_alpha;
403 else if(self.owner.alpha != 0)
404 self.alpha = self.owner.alpha;
408 self.glowmod = self.owner.weaponentity_glowmod;
409 self.colormap = self.owner.colormap;
411 CSQCMODEL_AUTOUPDATE();
414 // spawning weaponentity for client
415 void CL_SpawnWeaponentity()
417 self.weaponentity = spawn();
418 self.weaponentity.classname = "weaponentity";
419 self.weaponentity.solid = SOLID_NOT;
420 self.weaponentity.owner = self;
421 setmodel(self.weaponentity, ""); // precision set when changed
422 setorigin(self.weaponentity, '0 0 0');
423 self.weaponentity.angles = '0 0 0';
424 self.weaponentity.viewmodelforclient = self;
425 self.weaponentity.flags = 0;
426 self.weaponentity.think = CL_Weaponentity_Think;
427 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
428 self.weaponentity.nextthink = time;
430 self.exteriorweaponentity = spawn();
431 self.exteriorweaponentity.classname = "exteriorweaponentity";
432 self.exteriorweaponentity.solid = SOLID_NOT;
433 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
434 self.exteriorweaponentity.owner = self;
435 setorigin(self.exteriorweaponentity, '0 0 0');
436 self.exteriorweaponentity.angles = '0 0 0';
437 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
438 self.exteriorweaponentity.nextthink = time;
441 entity oldself = self;
442 self = self.exteriorweaponentity;
443 CSQCMODEL_AUTOINIT();
451 if (self.weapon != -1)
454 self.switchingweapon = 0;
456 if (self.weaponentity)
458 self.weaponentity.state = WS_CLEAR;
459 self.weaponentity.effects = 0;
465 if (self.weaponentity)
466 self.weaponentity.state = WS_READY;
467 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
472 float weapon_prepareattack_checkammo(float secondary)
474 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
475 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
477 // always keep the Mine Layer if we placed mines, so that we can detonate them
479 if(self.weapon == WEP_MINE_LAYER)
480 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
483 if(self.weapon == WEP_SHOTGUN)
484 if(!secondary && WEP_CVAR(shotgun, secondary) == 1)
485 return false; // no clicking, just allow
487 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
489 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
490 self.prevdryfire = time;
493 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
495 if(time - self.prevwarntime > 1)
501 ITEM_WEAPON_PRIMORSEC,
507 self.prevwarntime = time;
509 else // this weapon is totally unable to fire, switch to another one
511 W_SwitchToOtherWeapon(self);
519 float weapon_prepareattack_check(float secondary, float attacktime)
521 if(!weapon_prepareattack_checkammo(secondary))
524 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
525 //if all players readied up and the countdown is running
526 if(time < game_starttime || time < self.race_penalty) {
530 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
533 // do not even think about shooting if switching
534 if(self.switchweapon != self.weapon)
539 // don't fire if previous attack is not finished
540 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
542 // don't fire while changing weapon
543 if (self.weaponentity.state != WS_READY)
549 float weapon_prepareattack_do(float secondary, float attacktime)
551 self.weaponentity.state = WS_INUSE;
553 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
555 // if the weapon hasn't been firing continuously, reset the timer
558 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
560 ATTACK_FINISHED(self) = time;
561 //dprint("resetting attack finished to ", ftos(time), "\n");
563 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
565 self.bulletcounter += 1;
566 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
569 float weapon_prepareattack(float secondary, float attacktime)
571 if(weapon_prepareattack_check(secondary, attacktime))
573 weapon_prepareattack_do(secondary, attacktime);
580 void weapon_thinkf(float fr, float t, void() func)
586 if(fr == WFRAME_DONTCHANGE)
588 fr = self.weaponentity.wframe;
591 else if (fr == WFRAME_IDLE)
600 if (self.weaponentity)
602 self.weaponentity.wframe = fr;
604 if (fr == WFRAME_IDLE)
605 a = self.weaponentity.anim_idle;
606 else if (fr == WFRAME_FIRE1)
607 a = self.weaponentity.anim_fire1;
608 else if (fr == WFRAME_FIRE2)
609 a = self.weaponentity.anim_fire2;
610 else // if (fr == WFRAME_RELOAD)
611 a = self.weaponentity.anim_reload;
612 a.z *= g_weaponratefactor;
613 setanim(self.weaponentity, a, restartanim == false, restartanim, restartanim);
620 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
622 backtrace("Tried to override initial weapon think function - should this really happen?");
625 t *= W_WeaponRateFactor();
627 // VorteX: haste can be added here
628 if (self.weapon_think == w_ready)
630 self.weapon_nextthink = time;
631 //dprint("started firing at ", ftos(time), "\n");
633 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
635 self.weapon_nextthink = time;
636 //dprint("reset weapon animation timer at ", ftos(time), "\n");
638 self.weapon_nextthink = self.weapon_nextthink + t;
639 self.weapon_think = func;
640 //dprint("next ", ftos(self.weapon_nextthink), "\n");
642 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
644 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
645 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
647 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
651 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
652 self.anim_upper_action = 0;
656 float forbidWeaponUse()
658 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
660 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
662 if(self.player_blocked)
666 if(self.weapon_blocked)
676 self.weapon_frametime = frametime;
678 if (!self.weaponentity || self.health < 1)
679 return; // Dead player can't use weapons and injure impulse commands
681 if(forbidWeaponUse())
682 if(self.weaponentity.state != WS_CLEAR)
688 if(!self.switchweapon)
691 self.switchingweapon = 0;
692 self.weaponentity.state = WS_CLEAR;
693 self.weaponname = "";
694 //self.items &= ~IT_AMMO;
698 makevectors(self.v_angle);
699 fo = v_forward; // save them in case the weapon think functions change it
704 if (self.weapon != self.switchweapon)
706 if (self.weaponentity.state == WS_CLEAR)
709 self.switchingweapon = self.switchweapon;
710 entity newwep = get_weaponinfo(self.switchweapon);
712 // the two weapon entities will notice this has changed and update their models
713 self.weapon = self.switchweapon;
714 self.weaponname = newwep.mdl;
715 self.bulletcounter = 0;
716 self.ammo_field = newwep.ammo_field;
717 WEP_ACTION(self.switchweapon, WR_SETUP);
718 self.weaponentity.state = WS_RAISE;
720 // set our clip load to the load of the weapon we switched to, if it's reloadable
721 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
723 self.clip_load = self.(weapon_load[self.switchweapon]);
724 self.clip_size = newwep.reloading_ammo;
727 self.clip_load = self.clip_size = 0;
729 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
731 else if (self.weaponentity.state == WS_DROP)
733 // in dropping phase we can switch at any time
734 self.switchingweapon = self.switchweapon;
736 else if (self.weaponentity.state == WS_READY)
739 self.switchingweapon = self.switchweapon;
740 entity oldwep = get_weaponinfo(self.weapon);
742 // set up weapon switch think in the future, and start drop anim
743 #ifndef INDEPENDENT_ATTACK_FINISHED
744 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
747 sound(self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
748 self.weaponentity.state = WS_DROP;
749 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
750 #ifndef INDEPENDENT_ATTACK_FINISHED
756 // LordHavoc: network timing test code
758 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
763 // call the think code which may fire the weapon
764 // and do so multiple times to resolve framerate dependency issues if the
765 // server framerate is very low and the weapon fire rate very high
768 while (c < W_TICSPERFRAME)
771 if(w && !(self.weapons & WepSet_FromWeapon(w)))
773 if(self.weapon == self.switchweapon)
774 W_SwitchWeapon_Force(self, w_getbestweapon(self));
783 WEP_ACTION(self.weapon, WR_THINK);
785 WEP_ACTION(self.weapon, WR_GONETHINK);
787 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
789 if(self.weapon_think)
797 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
802 void W_AttachToShotorg(entity flash, vector offset)
806 flash.angles_z = random() * 360;
808 if(gettagindex(self.weaponentity, "shot"))
809 setattachment(flash, self.weaponentity, "shot");
811 setattachment(flash, self.weaponentity, "tag_shot");
812 setorigin(flash, offset);
815 copyentity(flash, xflash);
817 flash.viewmodelforclient = self;
819 if(self.weaponentity.oldorigin.x > 0)
821 setattachment(xflash, self.exteriorweaponentity, "");
822 setorigin(xflash, self.weaponentity.oldorigin + offset);
826 if(gettagindex(self.exteriorweaponentity, "shot"))
827 setattachment(xflash, self.exteriorweaponentity, "shot");
829 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
830 setorigin(xflash, offset);
834 void W_DecreaseAmmo(float ammo_use)
836 entity wep = get_weaponinfo(self.weapon);
838 if(cvar("g_overkill"))
839 if(self.ok_use_ammocharge)
841 ok_DecreaseCharge(self, self.weapon);
845 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
848 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
849 if(wep.reloading_ammo)
851 self.clip_load -= ammo_use;
852 self.(weapon_load[self.weapon]) = self.clip_load;
854 else if(wep.ammo_field != ammo_none)
856 self.(wep.ammo_field) -= ammo_use;
857 if(self.(wep.ammo_field) < 0)
860 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
861 "Please notify Samual immediately with a copy of this backtrace!\n",
864 GetAmmoPicture(wep.ammo_field),
866 self.(wep.ammo_field)
872 // weapon reloading code
874 .float reload_ammo_amount, reload_ammo_min, reload_time;
875 .float reload_complain;
876 .string reload_sound;
878 void W_ReloadedAndReady()
880 // finish the reloading process, and do the ammo transfer
882 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
884 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
885 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
886 self.clip_load = self.reload_ammo_amount;
889 // make sure we don't add more ammo than we have
890 float load = min(self.reload_ammo_amount - self.clip_load, self.(self.ammo_field));
891 self.clip_load += load;
892 self.(self.ammo_field) -= load;
894 self.(weapon_load[self.weapon]) = self.clip_load;
896 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
897 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
898 // so your weapon is disabled for a few seconds without reason
900 //ATTACK_FINISHED(self) -= self.reload_time - 1;
905 void W_Reload(float sent_ammo_min, string sent_sound)
907 // set global values to work with
909 e = get_weaponinfo(self.weapon);
911 if(cvar("g_overkill"))
912 if(self.ok_use_ammocharge)
915 self.reload_ammo_min = sent_ammo_min;
916 self.reload_ammo_amount = e.reloading_ammo;
917 self.reload_time = e.reloading_time;
918 self.reload_sound = sent_sound;
920 // don't reload weapons that don't have the RELOADABLE flag
921 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
923 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
927 // return if reloading is disabled for this weapon
928 if(!self.reload_ammo_amount)
931 // our weapon is fully loaded, no need to reload
932 if (self.clip_load >= self.reload_ammo_amount)
935 // no ammo, so nothing to load
936 if(self.ammo_field != ammo_none)
937 if(!self.(self.ammo_field) && self.reload_ammo_min)
938 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
940 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
942 play2(self, "weapons/unavailable.wav");
943 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
944 self.reload_complain = time + 1;
946 // switch away if the amount of ammo is not enough to keep using this weapon
947 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
949 self.clip_load = -1; // reload later
950 W_SwitchToOtherWeapon(self);
955 if (self.weaponentity)
957 if (self.weaponentity.wframe == WFRAME_RELOAD)
960 // allow switching away while reloading, but this will cause a new reload!
961 self.weaponentity.state = WS_READY;
964 // now begin the reloading process
966 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
968 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
969 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
970 // so your weapon is disabled for a few seconds without reason
972 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
974 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
976 if(self.clip_load < 0)
978 self.old_clip_load = self.clip_load;
979 self.clip_load = self.(weapon_load[self.weapon]) = -1;
982 void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
984 entity oldself = self;
986 weapon_dropevent_item = weapon_item;
987 WEP_ACTION(weapon_type, event);