4 #include "../../dpdefs/progsdefs.qh"
5 #include "../../dpdefs/dpextensions.qh"
6 #include "../../common/constants.qh"
7 #include "../../common/util.qh"
8 #include "../../common/animdecide.qh"
9 #include "../../common/monsters/monsters.qh"
10 #include "../../common/weapons/weapons.qh"
11 #include "weaponsystem.qh"
12 #include "../t_items.qh"
13 #include "../autocvars.qh"
15 #include "../../common/notifications.qh"
16 #include "../mutators/mutators_include.qh"
17 #include "../command/common.qh"
18 #include "../../csqcmodellib/sv_model.qh"
19 #include "../round_handler.qh"
23 ===========================================================================
25 CLIENT WEAPONSYSTEM CODE
26 Bring back W_Weaponframe
28 ===========================================================================
31 .float weapon_frametime;
33 float W_WeaponRateFactor()
36 t = 1.0 / g_weaponratefactor;
39 MUTATOR_CALLHOOK(WeaponRateFactor);
46 void(float fr, float t, void() func) weapon_thinkf;
48 float CL_Weaponentity_CustomizeEntityForClient()
50 self.viewmodelforclient = self.owner;
52 if(other.enemy == self.owner)
53 self.viewmodelforclient = other;
60 * 1. simple animated model, muzzle flash handling on h_ model:
61 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
63 * shot = muzzle end (shot origin, also used for muzzle flashes)
64 * shell = casings ejection point (must be on the right hand side of the gun)
65 * weapon = attachment for v_tuba.md3
66 * v_tuba.md3 - first and third person model
67 * g_tuba.md3 - pickup model
69 * 2. simple animated model, muzzle flash handling on v_ model:
70 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
72 * weapon = attachment for v_tuba.md3
73 * v_tuba.md3 - first and third person model
75 * shot = muzzle end (shot origin, also used for muzzle flashes)
76 * shell = casings ejection point (must be on the right hand side of the gun)
77 * g_tuba.md3 - pickup model
79 * 3. fully animated model, muzzle flash handling on h_ model:
80 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
82 * shot = muzzle end (shot origin, also used for muzzle flashes)
83 * shell = casings ejection point (must be on the right hand side of the gun)
84 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
85 * v_tuba.md3 - third person model
86 * g_tuba.md3 - pickup model
88 * 4. fully animated model, muzzle flash handling on v_ model:
89 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
91 * shot = muzzle end (shot origin)
92 * shell = casings ejection point (must be on the right hand side of the gun)
93 * v_tuba.md3 - third person model
95 * shot = muzzle end (for muzzle flashes)
96 * g_tuba.md3 - pickup model
100 // self.origin, self.angles
102 // self.movedir, self.view_ofs
106 // call again with ""
108 void CL_WeaponEntity_SetModel(string name)
113 // if there is a child entity, hide it until we're sure we use it
114 if (self.weaponentity)
115 self.weaponentity.model = "";
116 setmodel(self, strcat("models/weapons/v_", name, ".md3")); // precision set below
117 v_shot_idx = gettagindex(self, "shot"); // used later
119 v_shot_idx = gettagindex(self, "tag_shot");
121 setmodel(self, strcat("models/weapons/h_", name, ".iqm")); // precision set below
122 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
123 self.anim_fire1 = animfixfps(self, '0 1 0.01', '0 0 0');
124 self.anim_fire2 = animfixfps(self, '1 1 0.01', '0 0 0');
125 self.anim_idle = animfixfps(self, '2 1 0.01', '0 0 0');
126 self.anim_reload = animfixfps(self, '3 1 0.01', '0 0 0');
128 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
129 // if we don't, this is a "real" animated model
130 if(gettagindex(self, "weapon"))
132 if (!self.weaponentity)
133 self.weaponentity = spawn();
134 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
135 setattachment(self.weaponentity, self, "weapon");
137 else if(gettagindex(self, "tag_weapon"))
139 if (!self.weaponentity)
140 self.weaponentity = spawn();
141 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
142 setattachment(self.weaponentity, self, "tag_weapon");
146 if(self.weaponentity)
147 remove(self.weaponentity);
148 self.weaponentity = world;
151 setorigin(self,'0 0 0');
152 self.angles = '0 0 0';
154 self.viewmodelforclient = world;
158 if(v_shot_idx) // v_ model attached to invisible h_ model
160 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
164 idx = gettagindex(self, "shot");
166 idx = gettagindex(self, "tag_shot");
168 self.movedir = gettaginfo(self, idx);
171 print("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
172 self.movedir = '0 0 0';
176 if(self.weaponentity) // v_ model attached to invisible h_ model
178 idx = gettagindex(self.weaponentity, "shell");
180 idx = gettagindex(self.weaponentity, "tag_shell");
182 self.spawnorigin = gettaginfo(self.weaponentity, idx);
188 idx = gettagindex(self, "shell");
190 idx = gettagindex(self, "tag_shell");
192 self.spawnorigin = gettaginfo(self, idx);
195 print("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
196 self.spawnorigin = self.movedir;
202 self.oldorigin = '0 0 0'; // use regular attachment
206 if(self.weaponentity)
208 idx = gettagindex(self, "weapon");
210 idx = gettagindex(self, "tag_weapon");
214 idx = gettagindex(self, "handle");
216 idx = gettagindex(self, "tag_handle");
220 self.oldorigin = self.movedir - gettaginfo(self, idx);
224 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");
225 self.oldorigin = '0 0 0'; // there is no way to recover from this
229 self.viewmodelforclient = self.owner;
234 if(self.weaponentity)
235 remove(self.weaponentity);
236 self.weaponentity = world;
237 self.movedir = '0 0 0';
238 self.spawnorigin = '0 0 0';
239 self.oldorigin = '0 0 0';
240 self.anim_fire1 = '0 1 0.01';
241 self.anim_fire2 = '0 1 0.01';
242 self.anim_idle = '0 1 0.01';
243 self.anim_reload = '0 1 0.01';
246 self.view_ofs = '0 0 0';
248 if(self.movedir.x >= 0)
252 self.movedir = shotorg_adjust(v0, false, false);
253 self.view_ofs = shotorg_adjust(v0, false, true) - v0;
255 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
256 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
258 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
260 // check if an instant weapon switch occurred
261 setorigin(self, self.view_ofs);
262 // reset animstate now
263 self.wframe = WFRAME_IDLE;
264 setanim(self, self.anim_idle, true, false, true);
267 vector CL_Weapon_GetShotOrg(float wpn)
271 wi = get_weaponinfo(wpn);
274 CL_WeaponEntity_SetModel(wi.mdl);
276 CL_WeaponEntity_SetModel("");
282 void CL_Weaponentity_Think()
285 self.nextthink = time;
286 if (intermission_running)
287 self.frame = self.anim_idle.x;
288 if (self.owner.weaponentity != self)
290 if (self.weaponentity)
291 remove(self.weaponentity);
295 if (self.owner.deadflag != DEAD_NO)
298 if (self.weaponentity)
299 self.weaponentity.model = "";
302 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
304 self.weaponname = self.owner.weaponname;
305 self.dmg = self.owner.modelindex;
306 self.deadflag = self.owner.deadflag;
308 CL_WeaponEntity_SetModel(self.owner.weaponname);
311 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
312 self.effects = self.owner.effects & EFMASK_CHEAP;
313 self.effects &= ~EF_LOWPRECISION;
314 self.effects &= ~EF_FULLBRIGHT; // can mask team color, so get rid of it
315 self.effects &= ~EF_TELEPORT_BIT;
316 self.effects &= ~EF_RESTARTANIM_BIT;
319 if(self.owner.alpha == default_player_alpha)
320 self.alpha = default_weapon_alpha;
321 else if(self.owner.alpha != 0)
322 self.alpha = self.owner.alpha;
326 self.glowmod = self.owner.weaponentity_glowmod;
327 self.colormap = self.owner.colormap;
328 if (self.weaponentity)
330 self.weaponentity.effects = self.effects;
331 self.weaponentity.alpha = self.alpha;
332 self.weaponentity.colormap = self.colormap;
333 self.weaponentity.glowmod = self.glowmod;
336 self.angles = '0 0 0';
338 float f = (self.owner.weapon_nextthink - time);
339 if (self.state == WS_RAISE && !intermission_running)
341 entity newwep = get_weaponinfo(self.owner.switchweapon);
342 f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
343 self.angles_x = -90 * f * f;
345 else if (self.state == WS_DROP && !intermission_running)
347 entity oldwep = get_weaponinfo(self.owner.weapon);
348 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
349 self.angles_x = -90 * f * f;
351 else if (self.state == WS_CLEAR)
354 self.angles_x = -90 * f * f;
358 void CL_ExteriorWeaponentity_Think()
361 self.nextthink = time;
362 if (self.owner.exteriorweaponentity != self)
367 if (self.owner.deadflag != DEAD_NO)
372 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
374 self.weaponname = self.owner.weaponname;
375 self.dmg = self.owner.modelindex;
376 self.deadflag = self.owner.deadflag;
377 if (self.owner.weaponname != "")
378 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
382 if((tag_found = gettagindex(self.owner, "tag_weapon")))
384 self.tag_index = tag_found;
385 self.tag_entity = self.owner;
388 setattachment(self, self.owner, "bip01 r hand");
390 self.effects = self.owner.effects;
391 self.effects |= EF_LOWPRECISION;
392 self.effects = self.effects & EFMASK_CHEAP; // eat performance
393 if(self.owner.alpha == default_player_alpha)
394 self.alpha = default_weapon_alpha;
395 else if(self.owner.alpha != 0)
396 self.alpha = self.owner.alpha;
400 self.glowmod = self.owner.weaponentity_glowmod;
401 self.colormap = self.owner.colormap;
403 CSQCMODEL_AUTOUPDATE();
406 // spawning weaponentity for client
407 void CL_SpawnWeaponentity()
409 self.weaponentity = spawn();
410 self.weaponentity.classname = "weaponentity";
411 self.weaponentity.solid = SOLID_NOT;
412 self.weaponentity.owner = self;
413 setmodel(self.weaponentity, ""); // precision set when changed
414 setorigin(self.weaponentity, '0 0 0');
415 self.weaponentity.angles = '0 0 0';
416 self.weaponentity.viewmodelforclient = self;
417 self.weaponentity.flags = 0;
418 self.weaponentity.think = CL_Weaponentity_Think;
419 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
420 self.weaponentity.nextthink = time;
422 self.exteriorweaponentity = spawn();
423 self.exteriorweaponentity.classname = "exteriorweaponentity";
424 self.exteriorweaponentity.solid = SOLID_NOT;
425 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
426 self.exteriorweaponentity.owner = self;
427 setorigin(self.exteriorweaponentity, '0 0 0');
428 self.exteriorweaponentity.angles = '0 0 0';
429 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
430 self.exteriorweaponentity.nextthink = time;
433 entity oldself = self;
434 self = self.exteriorweaponentity;
435 CSQCMODEL_AUTOINIT();
443 if (self.weapon != -1)
446 self.switchingweapon = 0;
448 if (self.weaponentity)
450 self.weaponentity.state = WS_CLEAR;
451 self.weaponentity.effects = 0;
457 if (self.weaponentity)
458 self.weaponentity.state = WS_READY;
459 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
464 float weapon_prepareattack_checkammo(float secondary)
466 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
467 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
469 // always keep the Mine Layer if we placed mines, so that we can detonate them
471 if(self.weapon == WEP_MINE_LAYER)
472 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
475 if(self.weapon == WEP_SHOTGUN)
476 if(!secondary && WEP_CVAR(shotgun, secondary) == 1)
477 return false; // no clicking, just allow
479 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
481 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
482 self.prevdryfire = time;
485 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
487 if(time - self.prevwarntime > 1)
493 ITEM_WEAPON_PRIMORSEC,
499 self.prevwarntime = time;
501 else // this weapon is totally unable to fire, switch to another one
503 W_SwitchToOtherWeapon(self);
511 float weapon_prepareattack_check(float secondary, float attacktime)
513 if(!weapon_prepareattack_checkammo(secondary))
516 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
517 //if all players readied up and the countdown is running
518 if(time < game_starttime || time < self.race_penalty) {
522 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
525 // do not even think about shooting if switching
526 if(self.switchweapon != self.weapon)
531 // don't fire if previous attack is not finished
532 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
534 // don't fire while changing weapon
535 if (self.weaponentity.state != WS_READY)
541 float weapon_prepareattack_do(float secondary, float attacktime)
543 self.weaponentity.state = WS_INUSE;
545 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
547 // if the weapon hasn't been firing continuously, reset the timer
550 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
552 ATTACK_FINISHED(self) = time;
553 //dprint("resetting attack finished to ", ftos(time), "\n");
555 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
557 self.bulletcounter += 1;
558 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
561 float weapon_prepareattack(float secondary, float attacktime)
563 if(weapon_prepareattack_check(secondary, attacktime))
565 weapon_prepareattack_do(secondary, attacktime);
572 void weapon_thinkf(float fr, float t, void() func)
578 if(fr == WFRAME_DONTCHANGE)
580 fr = self.weaponentity.wframe;
583 else if (fr == WFRAME_IDLE)
592 if (self.weaponentity)
594 self.weaponentity.wframe = fr;
596 if (fr == WFRAME_IDLE)
597 a = self.weaponentity.anim_idle;
598 else if (fr == WFRAME_FIRE1)
599 a = self.weaponentity.anim_fire1;
600 else if (fr == WFRAME_FIRE2)
601 a = self.weaponentity.anim_fire2;
602 else // if (fr == WFRAME_RELOAD)
603 a = self.weaponentity.anim_reload;
604 a.z *= g_weaponratefactor;
605 setanim(self.weaponentity, a, restartanim == false, restartanim, restartanim);
612 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
614 backtrace("Tried to override initial weapon think function - should this really happen?");
617 t *= W_WeaponRateFactor();
619 // VorteX: haste can be added here
620 if (self.weapon_think == w_ready)
622 self.weapon_nextthink = time;
623 //dprint("started firing at ", ftos(time), "\n");
625 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
627 self.weapon_nextthink = time;
628 //dprint("reset weapon animation timer at ", ftos(time), "\n");
630 self.weapon_nextthink = self.weapon_nextthink + t;
631 self.weapon_think = func;
632 //dprint("next ", ftos(self.weapon_nextthink), "\n");
634 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
636 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
637 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
639 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
643 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
644 self.anim_upper_action = 0;
648 float forbidWeaponUse()
650 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
652 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
654 if(self.player_blocked)
658 if(self.weapon_blocked)
668 self.weapon_frametime = frametime;
670 if (!self.weaponentity || self.health < 1)
671 return; // Dead player can't use weapons and injure impulse commands
673 if(forbidWeaponUse())
674 if(self.weaponentity.state != WS_CLEAR)
680 if(!self.switchweapon)
683 self.switchingweapon = 0;
684 self.weaponentity.state = WS_CLEAR;
685 self.weaponname = "";
686 //self.items &= ~IT_AMMO;
690 makevectors(self.v_angle);
691 fo = v_forward; // save them in case the weapon think functions change it
696 if (self.weapon != self.switchweapon)
698 if (self.weaponentity.state == WS_CLEAR)
701 self.switchingweapon = self.switchweapon;
702 entity newwep = get_weaponinfo(self.switchweapon);
704 // the two weapon entities will notice this has changed and update their models
705 self.weapon = self.switchweapon;
706 self.weaponname = newwep.mdl;
707 self.bulletcounter = 0;
708 self.ammo_field = newwep.ammo_field;
709 WEP_ACTION(self.switchweapon, WR_SETUP);
710 self.weaponentity.state = WS_RAISE;
712 // set our clip load to the load of the weapon we switched to, if it's reloadable
713 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
715 self.clip_load = self.(weapon_load[self.switchweapon]);
716 self.clip_size = newwep.reloading_ammo;
719 self.clip_load = self.clip_size = 0;
721 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
723 else if (self.weaponentity.state == WS_DROP)
725 // in dropping phase we can switch at any time
726 self.switchingweapon = self.switchweapon;
728 else if (self.weaponentity.state == WS_READY)
731 self.switchingweapon = self.switchweapon;
732 entity oldwep = get_weaponinfo(self.weapon);
734 // set up weapon switch think in the future, and start drop anim
735 #ifndef INDEPENDENT_ATTACK_FINISHED
736 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
739 sound(self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
740 self.weaponentity.state = WS_DROP;
741 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
742 #ifndef INDEPENDENT_ATTACK_FINISHED
748 // LordHavoc: network timing test code
750 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
755 // call the think code which may fire the weapon
756 // and do so multiple times to resolve framerate dependency issues if the
757 // server framerate is very low and the weapon fire rate very high
760 while (c < W_TICSPERFRAME)
763 if(w && !(self.weapons & WepSet_FromWeapon(w)))
765 if(self.weapon == self.switchweapon)
766 W_SwitchWeapon_Force(self, w_getbestweapon(self));
775 WEP_ACTION(self.weapon, WR_THINK);
777 WEP_ACTION(self.weapon, WR_GONETHINK);
779 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
781 if(self.weapon_think)
789 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
794 void W_AttachToShotorg(entity flash, vector offset)
798 flash.angles_z = random() * 360;
800 if(gettagindex(self.weaponentity, "shot"))
801 setattachment(flash, self.weaponentity, "shot");
803 setattachment(flash, self.weaponentity, "tag_shot");
804 setorigin(flash, offset);
807 copyentity(flash, xflash);
809 flash.viewmodelforclient = self;
811 if(self.weaponentity.oldorigin.x > 0)
813 setattachment(xflash, self.exteriorweaponentity, "");
814 setorigin(xflash, self.weaponentity.oldorigin + offset);
818 if(gettagindex(self.exteriorweaponentity, "shot"))
819 setattachment(xflash, self.exteriorweaponentity, "shot");
821 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
822 setorigin(xflash, offset);
826 void W_DecreaseAmmo(float ammo_use)
828 entity wep = get_weaponinfo(self.weapon);
830 if(cvar("g_overkill"))
831 if(self.ok_use_ammocharge)
833 ok_DecreaseCharge(self, self.weapon);
837 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
840 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
841 if(wep.reloading_ammo)
843 self.clip_load -= ammo_use;
844 self.(weapon_load[self.weapon]) = self.clip_load;
846 else if(wep.ammo_field != ammo_none)
848 self.(wep.ammo_field) -= ammo_use;
849 if(self.(wep.ammo_field) < 0)
852 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
853 "Please notify Samual immediately with a copy of this backtrace!\n",
856 GetAmmoPicture(wep.ammo_field),
858 self.(wep.ammo_field)
864 // weapon reloading code
866 .float reload_ammo_amount, reload_ammo_min, reload_time;
867 .float reload_complain;
868 .string reload_sound;
870 void W_ReloadedAndReady()
872 // finish the reloading process, and do the ammo transfer
874 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
876 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
877 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
878 self.clip_load = self.reload_ammo_amount;
881 // make sure we don't add more ammo than we have
882 float load = min(self.reload_ammo_amount - self.clip_load, self.(self.ammo_field));
883 self.clip_load += load;
884 self.(self.ammo_field) -= load;
886 self.(weapon_load[self.weapon]) = self.clip_load;
888 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
889 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
890 // so your weapon is disabled for a few seconds without reason
892 //ATTACK_FINISHED(self) -= self.reload_time - 1;
897 void W_Reload(float sent_ammo_min, string sent_sound)
899 // set global values to work with
901 e = get_weaponinfo(self.weapon);
903 if(cvar("g_overkill"))
904 if(self.ok_use_ammocharge)
907 self.reload_ammo_min = sent_ammo_min;
908 self.reload_ammo_amount = e.reloading_ammo;
909 self.reload_time = e.reloading_time;
910 self.reload_sound = sent_sound;
912 // don't reload weapons that don't have the RELOADABLE flag
913 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
915 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
919 // return if reloading is disabled for this weapon
920 if(!self.reload_ammo_amount)
923 // our weapon is fully loaded, no need to reload
924 if (self.clip_load >= self.reload_ammo_amount)
927 // no ammo, so nothing to load
928 if(self.ammo_field != ammo_none)
929 if(!self.(self.ammo_field) && self.reload_ammo_min)
930 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
932 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
934 play2(self, "weapons/unavailable.wav");
935 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
936 self.reload_complain = time + 1;
938 // switch away if the amount of ammo is not enough to keep using this weapon
939 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
941 self.clip_load = -1; // reload later
942 W_SwitchToOtherWeapon(self);
947 if (self.weaponentity)
949 if (self.weaponentity.wframe == WFRAME_RELOAD)
952 // allow switching away while reloading, but this will cause a new reload!
953 self.weaponentity.state = WS_READY;
956 // now begin the reloading process
958 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
960 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
961 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
962 // so your weapon is disabled for a few seconds without reason
964 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
966 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
968 if(self.clip_load < 0)
970 self.old_clip_load = self.clip_load;
971 self.clip_load = self.(weapon_load[self.weapon]) = -1;
974 void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
976 entity oldself = self;
978 weapon_dropevent_item = weapon_item;
979 WEP_ACTION(weapon_type, event);