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()
31 float t = 1.0 / g_weaponratefactor;
33 MUTATOR_CALLHOOK(WeaponRateFactor, t);
39 float W_WeaponSpeedFactor()
41 float t = 1.0 * g_weaponspeedfactor;
43 MUTATOR_CALLHOOK(WeaponSpeedFactor, t);
50 void(float fr, float t, void() func) weapon_thinkf;
52 float CL_Weaponentity_CustomizeEntityForClient()
54 self.viewmodelforclient = self.owner;
56 if(other.enemy == self.owner)
57 self.viewmodelforclient = other;
64 * 1. simple animated model, muzzle flash handling on h_ model:
65 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
67 * shot = muzzle end (shot origin, also used for muzzle flashes)
68 * shell = casings ejection point (must be on the right hand side of the gun)
69 * weapon = attachment for v_tuba.md3
70 * v_tuba.md3 - first and third person model
71 * g_tuba.md3 - pickup model
73 * 2. simple animated model, muzzle flash handling on v_ model:
74 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
76 * weapon = attachment for v_tuba.md3
77 * v_tuba.md3 - first and third person model
79 * shot = muzzle end (shot origin, also used for muzzle flashes)
80 * shell = casings ejection point (must be on the right hand side of the gun)
81 * g_tuba.md3 - pickup model
83 * 3. fully animated model, muzzle flash handling on h_ model:
84 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
86 * shot = muzzle end (shot origin, also used for muzzle flashes)
87 * shell = casings ejection point (must be on the right hand side of the gun)
88 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
89 * v_tuba.md3 - third person model
90 * g_tuba.md3 - pickup model
92 * 4. fully animated model, muzzle flash handling on v_ model:
93 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
95 * shot = muzzle end (shot origin)
96 * shell = casings ejection point (must be on the right hand side of the gun)
97 * v_tuba.md3 - third person model
99 * shot = muzzle end (for muzzle flashes)
100 * g_tuba.md3 - pickup model
104 // self.origin, self.angles
106 // self.movedir, self.view_ofs
110 // call again with ""
112 void CL_WeaponEntity_SetModel(string name)
117 // if there is a child entity, hide it until we're sure we use it
118 if (self.weaponentity)
119 self.weaponentity.model = "";
120 setmodel(self, W_Model(strcat("v_", name, ".md3")));
121 v_shot_idx = gettagindex(self, "shot"); // used later
123 v_shot_idx = gettagindex(self, "tag_shot");
125 setmodel(self, W_Model(strcat("h_", name, ".iqm")));
126 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
127 self.anim_fire1 = animfixfps(self, '0 1 0.01', '0 0 0');
128 self.anim_fire2 = animfixfps(self, '1 1 0.01', '0 0 0');
129 self.anim_idle = animfixfps(self, '2 1 0.01', '0 0 0');
130 self.anim_reload = animfixfps(self, '3 1 0.01', '0 0 0');
132 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
133 // if we don't, this is a "real" animated model
134 if(gettagindex(self, "weapon"))
136 if (!self.weaponentity)
137 self.weaponentity = spawn();
138 setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
139 setattachment(self.weaponentity, self, "weapon");
141 else if(gettagindex(self, "tag_weapon"))
143 if (!self.weaponentity)
144 self.weaponentity = spawn();
145 setmodel(self.weaponentity, W_Model(strcat("v_", name, ".md3")));
146 setattachment(self.weaponentity, self, "tag_weapon");
150 if(self.weaponentity)
151 remove(self.weaponentity);
152 self.weaponentity = world;
155 setorigin(self,'0 0 0');
156 self.angles = '0 0 0';
158 self.viewmodelforclient = world;
162 if(v_shot_idx) // v_ model attached to invisible h_ model
164 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
168 idx = gettagindex(self, "shot");
170 idx = gettagindex(self, "tag_shot");
172 self.movedir = gettaginfo(self, idx);
175 LOG_INFO("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
176 self.movedir = '0 0 0';
180 if(self.weaponentity) // v_ model attached to invisible h_ model
182 idx = gettagindex(self.weaponentity, "shell");
184 idx = gettagindex(self.weaponentity, "tag_shell");
186 self.spawnorigin = gettaginfo(self.weaponentity, idx);
192 idx = gettagindex(self, "shell");
194 idx = gettagindex(self, "tag_shell");
196 self.spawnorigin = gettaginfo(self, idx);
199 LOG_INFO("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
200 self.spawnorigin = self.movedir;
206 self.oldorigin = '0 0 0'; // use regular attachment
210 if(self.weaponentity)
212 idx = gettagindex(self, "weapon");
214 idx = gettagindex(self, "tag_weapon");
218 idx = gettagindex(self, "handle");
220 idx = gettagindex(self, "tag_handle");
224 self.oldorigin = self.movedir - gettaginfo(self, idx);
228 LOG_INFO("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");
229 self.oldorigin = '0 0 0'; // there is no way to recover from this
233 self.viewmodelforclient = self.owner;
238 if(self.weaponentity)
239 remove(self.weaponentity);
240 self.weaponentity = world;
241 self.movedir = '0 0 0';
242 self.spawnorigin = '0 0 0';
243 self.oldorigin = '0 0 0';
244 self.anim_fire1 = '0 1 0.01';
245 self.anim_fire2 = '0 1 0.01';
246 self.anim_idle = '0 1 0.01';
247 self.anim_reload = '0 1 0.01';
250 self.view_ofs = '0 0 0';
252 if(self.movedir.x >= 0)
256 self.movedir = shotorg_adjust(v0, false, false);
257 self.view_ofs = shotorg_adjust(v0, false, true) - v0;
259 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
260 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
262 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
264 // check if an instant weapon switch occurred
265 setorigin(self, self.view_ofs);
266 // reset animstate now
267 self.wframe = WFRAME_IDLE;
268 setanim(self, self.anim_idle, true, false, true);
271 vector CL_Weapon_GetShotOrg(float wpn)
275 wi = get_weaponinfo(wpn);
278 CL_WeaponEntity_SetModel(wi.mdl);
280 CL_WeaponEntity_SetModel("");
286 void CL_Weaponentity_Think()
289 self.nextthink = time;
290 if (intermission_running)
291 self.frame = self.anim_idle.x;
292 if (self.owner.weaponentity != self)
294 if (self.weaponentity)
295 remove(self.weaponentity);
299 if (self.owner.deadflag != DEAD_NO)
302 if (self.weaponentity)
303 self.weaponentity.model = "";
306 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
308 self.weaponname = self.owner.weaponname;
309 self.dmg = self.owner.modelindex;
310 self.deadflag = self.owner.deadflag;
312 CL_WeaponEntity_SetModel(self.owner.weaponname);
315 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
316 self.effects = self.owner.effects & EFMASK_CHEAP;
317 self.effects &= ~EF_LOWPRECISION;
318 self.effects &= ~EF_FULLBRIGHT; // can mask team color, so get rid of it
319 self.effects &= ~EF_TELEPORT_BIT;
320 self.effects &= ~EF_RESTARTANIM_BIT;
323 if(self.owner.alpha == default_player_alpha)
324 self.alpha = default_weapon_alpha;
325 else if(self.owner.alpha != 0)
326 self.alpha = self.owner.alpha;
330 self.glowmod = self.owner.weaponentity_glowmod;
331 self.colormap = self.owner.colormap;
332 if (self.weaponentity)
334 self.weaponentity.effects = self.effects;
335 self.weaponentity.alpha = self.alpha;
336 self.weaponentity.colormap = self.colormap;
337 self.weaponentity.glowmod = self.glowmod;
340 self.angles = '0 0 0';
342 float f = (self.owner.weapon_nextthink - time);
343 if (self.state == WS_RAISE && !intermission_running)
345 entity newwep = get_weaponinfo(self.owner.switchweapon);
346 f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
347 self.angles_x = -90 * f * f;
349 else if (self.state == WS_DROP && !intermission_running)
351 entity oldwep = get_weaponinfo(self.owner.weapon);
352 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
353 self.angles_x = -90 * f * f;
355 else if (self.state == WS_CLEAR)
358 self.angles_x = -90 * f * f;
362 void CL_ExteriorWeaponentity_Think()
365 self.nextthink = time;
366 if (self.owner.exteriorweaponentity != self)
371 if (self.owner.deadflag != DEAD_NO)
376 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
378 self.weaponname = self.owner.weaponname;
379 self.dmg = self.owner.modelindex;
380 self.deadflag = self.owner.deadflag;
381 if (self.owner.weaponname != "")
382 setmodel(self, W_Model(strcat("v_", self.owner.weaponname, ".md3")));
386 if((tag_found = gettagindex(self.owner, "tag_weapon")))
388 self.tag_index = tag_found;
389 self.tag_entity = self.owner;
392 setattachment(self, self.owner, "bip01 r hand");
394 self.effects = self.owner.effects;
395 self.effects |= EF_LOWPRECISION;
396 self.effects = self.effects & EFMASK_CHEAP; // eat performance
397 if(self.owner.alpha == default_player_alpha)
398 self.alpha = default_weapon_alpha;
399 else if(self.owner.alpha != 0)
400 self.alpha = self.owner.alpha;
404 self.glowmod = self.owner.weaponentity_glowmod;
405 self.colormap = self.owner.colormap;
407 CSQCMODEL_AUTOUPDATE(self);
410 // spawning weaponentity for client
411 void CL_SpawnWeaponentity(entity e)
413 entity view = e.weaponentity = spawn();
414 view.classname = "weaponentity";
415 view.solid = SOLID_NOT;
417 setmodel(view, ""); // precision set when changed
418 setorigin(view, '0 0 0');
419 view.angles = '0 0 0';
420 view.viewmodelforclient = e;
422 view.think = CL_Weaponentity_Think;
423 view.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
424 view.nextthink = time;
426 entity exterior = e.exteriorweaponentity = spawn();
427 exterior.classname = "exteriorweaponentity";
428 exterior.solid = SOLID_NOT;
429 exterior.exteriorweaponentity = exterior;
431 setorigin(exterior, '0 0 0');
432 exterior.angles = '0 0 0';
433 exterior.think = CL_ExteriorWeaponentity_Think;
434 exterior.nextthink = time;
436 CSQCMODEL_AUTOINIT(exterior);
442 if (self.weapon != -1)
445 self.switchingweapon = 0;
447 if (self.weaponentity)
449 self.weaponentity.state = WS_CLEAR;
450 self.weaponentity.effects = 0;
456 if (self.weaponentity)
457 self.weaponentity.state = WS_READY;
458 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
463 float weapon_prepareattack_checkammo(float secondary)
465 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
466 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
468 // always keep the Mine Layer if we placed mines, so that we can detonate them
470 if(self.weapon == WEP_MINE_LAYER.m_id)
471 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
474 if(self.weapon == WEP_SHOTGUN.m_id)
475 if(!secondary && WEP_CVAR(shotgun, secondary) == 1)
476 return false; // no clicking, just allow
478 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
480 sound (self, CH_WEAPON_A, W_Sound("dryfire"), VOL_BASE, ATTEN_NORM);
481 self.prevdryfire = time;
484 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
486 if(time - self.prevwarntime > 1)
492 ITEM_WEAPON_PRIMORSEC,
498 self.prevwarntime = time;
500 else // this weapon is totally unable to fire, switch to another one
502 W_SwitchToOtherWeapon(self);
510 float weapon_prepareattack_check(float secondary, float attacktime)
512 if(!weapon_prepareattack_checkammo(secondary))
515 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
516 //if all players readied up and the countdown is running
517 if(time < game_starttime || time < self.race_penalty) {
521 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
524 // do not even think about shooting if switching
525 if(self.switchweapon != self.weapon)
530 // don't fire if previous attack is not finished
531 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
533 // don't fire while changing weapon
534 if (self.weaponentity.state != WS_READY)
540 float weapon_prepareattack_do(float secondary, float attacktime)
542 self.weaponentity.state = WS_INUSE;
544 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
546 // if the weapon hasn't been firing continuously, reset the timer
549 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
551 ATTACK_FINISHED(self) = time;
552 //dprint("resetting attack finished to ", ftos(time), "\n");
554 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
556 self.bulletcounter += 1;
557 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
560 float weapon_prepareattack(float secondary, float attacktime)
562 if(weapon_prepareattack_check(secondary, attacktime))
564 weapon_prepareattack_do(secondary, attacktime);
571 void weapon_thinkf(float fr, float t, void() func)
577 if(fr == WFRAME_DONTCHANGE)
579 fr = self.weaponentity.wframe;
582 else if (fr == WFRAME_IDLE)
591 if (self.weaponentity)
593 self.weaponentity.wframe = fr;
595 if (fr == WFRAME_IDLE)
596 a = self.weaponentity.anim_idle;
597 else if (fr == WFRAME_FIRE1)
598 a = self.weaponentity.anim_fire1;
599 else if (fr == WFRAME_FIRE2)
600 a = self.weaponentity.anim_fire2;
601 else // if (fr == WFRAME_RELOAD)
602 a = self.weaponentity.anim_reload;
603 a.z *= g_weaponratefactor;
604 setanim(self.weaponentity, a, restartanim == false, restartanim, restartanim);
611 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
613 backtrace("Tried to override initial weapon think function - should this really happen?");
616 t *= W_WeaponRateFactor();
618 // VorteX: haste can be added here
619 if (self.weapon_think == w_ready)
621 self.weapon_nextthink = time;
622 //dprint("started firing at ", ftos(time), "\n");
624 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
626 self.weapon_nextthink = time;
627 //dprint("reset weapon animation timer at ", ftos(time), "\n");
629 self.weapon_nextthink = self.weapon_nextthink + t;
630 self.weapon_think = func;
631 //dprint("next ", ftos(self.weapon_nextthink), "\n");
633 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
635 if((self.weapon == WEP_SHOCKWAVE.m_id || self.weapon == WEP_SHOTGUN.m_id) && fr == WFRAME_FIRE2)
636 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
638 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
642 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
643 self.anim_upper_action = 0;
647 float forbidWeaponUse(entity player)
649 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
651 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
653 if(player.player_blocked)
657 if(player.weapon_blocked)
667 self.weapon_frametime = frametime;
669 if (!self.weaponentity || self.health < 1)
670 return; // Dead player can't use weapons and injure impulse commands
672 if(forbidWeaponUse(self))
673 if(self.weaponentity.state != WS_CLEAR)
679 if(!self.switchweapon)
682 self.switchingweapon = 0;
683 self.weaponentity.state = WS_CLEAR;
684 self.weaponname = "";
685 //self.items &= ~IT_AMMO;
689 makevectors(self.v_angle);
690 fo = v_forward; // save them in case the weapon think functions change it
695 if (self.weapon != self.switchweapon)
697 if (self.weaponentity.state == WS_CLEAR)
700 self.switchingweapon = self.switchweapon;
701 entity newwep = get_weaponinfo(self.switchweapon);
703 // the two weapon entities will notice this has changed and update their models
704 self.weapon = self.switchweapon;
705 self.weaponname = newwep.mdl;
706 self.bulletcounter = 0;
707 self.ammo_field = newwep.ammo_field;
708 WEP_ACTION(self.switchweapon, WR_SETUP);
709 self.weaponentity.state = WS_RAISE;
711 // set our clip load to the load of the weapon we switched to, if it's reloadable
712 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
714 self.clip_load = self.(weapon_load[self.switchweapon]);
715 self.clip_size = newwep.reloading_ammo;
718 self.clip_load = self.clip_size = 0;
720 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
722 else if (self.weaponentity.state == WS_DROP)
724 // in dropping phase we can switch at any time
725 self.switchingweapon = self.switchweapon;
727 else if (self.weaponentity.state == WS_READY)
730 self.switchingweapon = self.switchweapon;
731 entity oldwep = get_weaponinfo(self.weapon);
733 // set up weapon switch think in the future, and start drop anim
734 #ifndef INDEPENDENT_ATTACK_FINISHED
735 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
738 sound(self, CH_WEAPON_SINGLE, W_Sound("weapon_switch"), VOL_BASE, ATTN_NORM);
739 self.weaponentity.state = WS_DROP;
740 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
741 #ifndef INDEPENDENT_ATTACK_FINISHED
747 // LordHavoc: network timing test code
749 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
754 // call the think code which may fire the weapon
755 // and do so multiple times to resolve framerate dependency issues if the
756 // server framerate is very low and the weapon fire rate very high
759 while (c < W_TICSPERFRAME)
762 if(w && !(self.weapons & WepSet_FromWeapon(w)))
764 if(self.weapon == self.switchweapon)
765 W_SwitchWeapon_Force(self, w_getbestweapon(self));
774 WEP_ACTION(self.weapon, WR_THINK);
776 WEP_ACTION(self.weapon, WR_GONETHINK);
778 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
780 if(self.weapon_think)
788 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
793 void W_AttachToShotorg(entity flash, vector offset)
797 flash.angles_z = random() * 360;
799 if(gettagindex(self.weaponentity, "shot"))
800 setattachment(flash, self.weaponentity, "shot");
802 setattachment(flash, self.weaponentity, "tag_shot");
803 setorigin(flash, offset);
806 copyentity(flash, xflash);
808 flash.viewmodelforclient = self;
810 if(self.weaponentity.oldorigin.x > 0)
812 setattachment(xflash, self.exteriorweaponentity, "");
813 setorigin(xflash, self.weaponentity.oldorigin + offset);
817 if(gettagindex(self.exteriorweaponentity, "shot"))
818 setattachment(xflash, self.exteriorweaponentity, "shot");
820 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
821 setorigin(xflash, offset);
825 void W_DecreaseAmmo(float ammo_use)
827 entity wep = get_weaponinfo(self.weapon);
829 if(cvar("g_overkill"))
830 if(self.ok_use_ammocharge)
832 ok_DecreaseCharge(self, self.weapon);
836 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
839 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
840 if(wep.reloading_ammo)
842 self.clip_load -= ammo_use;
843 self.(weapon_load[self.weapon]) = self.clip_load;
845 else if(wep.ammo_field != ammo_none)
847 self.(wep.ammo_field) -= ammo_use;
848 if(self.(wep.ammo_field) < 0)
851 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
852 "Please notify Samual immediately with a copy of this backtrace!\n",
855 GetAmmoPicture(wep.ammo_field),
857 self.(wep.ammo_field)
863 // weapon reloading code
865 .float reload_ammo_amount, reload_ammo_min, reload_time;
866 .float reload_complain;
867 .string reload_sound;
869 void W_ReloadedAndReady()
871 // finish the reloading process, and do the ammo transfer
873 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
875 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
876 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
877 self.clip_load = self.reload_ammo_amount;
880 // make sure we don't add more ammo than we have
881 float load = min(self.reload_ammo_amount - self.clip_load, self.(self.ammo_field));
882 self.clip_load += load;
883 self.(self.ammo_field) -= load;
885 self.(weapon_load[self.weapon]) = self.clip_load;
887 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
888 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
889 // so your weapon is disabled for a few seconds without reason
891 //ATTACK_FINISHED(self) -= self.reload_time - 1;
896 void W_Reload(float sent_ammo_min, string sent_sound)
898 // set global values to work with
900 e = get_weaponinfo(self.weapon);
902 if(cvar("g_overkill"))
903 if(self.ok_use_ammocharge)
906 self.reload_ammo_min = sent_ammo_min;
907 self.reload_ammo_amount = e.reloading_ammo;
908 self.reload_time = e.reloading_time;
909 self.reload_sound = sent_sound;
911 // don't reload weapons that don't have the RELOADABLE flag
912 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
914 LOG_TRACE("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
918 // return if reloading is disabled for this weapon
919 if(!self.reload_ammo_amount)
922 // our weapon is fully loaded, no need to reload
923 if (self.clip_load >= self.reload_ammo_amount)
926 // no ammo, so nothing to load
927 if(self.ammo_field != ammo_none)
928 if(!self.(self.ammo_field) && self.reload_ammo_min)
929 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
931 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
933 play2(self, W_Sound("unavailable"));
934 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
935 self.reload_complain = time + 1;
937 // switch away if the amount of ammo is not enough to keep using this weapon
938 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
940 self.clip_load = -1; // reload later
941 W_SwitchToOtherWeapon(self);
946 if (self.weaponentity)
948 if (self.weaponentity.wframe == WFRAME_RELOAD)
951 // allow switching away while reloading, but this will cause a new reload!
952 self.weaponentity.state = WS_READY;
955 // now begin the reloading process
957 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
959 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
960 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
961 // so your weapon is disabled for a few seconds without reason
963 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
965 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
967 if(self.clip_load < 0)
969 self.old_clip_load = self.clip_load;
970 self.clip_load = self.(weapon_load[self.weapon]) = -1;
973 void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
975 entity oldself = self;
977 weapon_dropevent_item = weapon_item;
978 WEP_ACTION(weapon_type, event);