2 ===========================================================================
4 CLIENT WEAPONSYSTEM CODE
5 Bring back W_Weaponframe
7 ===========================================================================
10 .float weapon_frametime;
12 float W_WeaponRateFactor()
15 t = 1.0 / g_weaponratefactor;
18 MUTATOR_CALLHOOK(WeaponRateFactor);
24 // VorteX: static frame globals
25 const float WFRAME_DONTCHANGE = -1;
26 const float WFRAME_FIRE1 = 0;
27 const float WFRAME_FIRE2 = 1;
28 const float WFRAME_IDLE = 2;
29 const float WFRAME_RELOAD = 3;
32 void(float fr, float t, void() func) weapon_thinkf;
34 float CL_Weaponentity_CustomizeEntityForClient()
36 self.viewmodelforclient = self.owner;
38 if(other.enemy == self.owner)
39 self.viewmodelforclient = other;
46 * 1. simple animated model, muzzle flash handling on h_ model:
47 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
49 * shot = muzzle end (shot origin, also used for muzzle flashes)
50 * shell = casings ejection point (must be on the right hand side of the gun)
51 * weapon = attachment for v_tuba.md3
52 * v_tuba.md3 - first and third person model
53 * g_tuba.md3 - pickup model
55 * 2. simple animated model, muzzle flash handling on v_ model:
56 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
58 * weapon = attachment for v_tuba.md3
59 * v_tuba.md3 - first and third person model
61 * shot = muzzle end (shot origin, also used for muzzle flashes)
62 * shell = casings ejection point (must be on the right hand side of the gun)
63 * g_tuba.md3 - pickup model
65 * 3. fully animated model, muzzle flash handling on h_ model:
66 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
68 * shot = muzzle end (shot origin, also used for muzzle flashes)
69 * shell = casings ejection point (must be on the right hand side of the gun)
70 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
71 * v_tuba.md3 - third person model
72 * g_tuba.md3 - pickup model
74 * 4. fully animated model, muzzle flash handling on v_ model:
75 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
77 * shot = muzzle end (shot origin)
78 * shell = casings ejection point (must be on the right hand side of the gun)
79 * v_tuba.md3 - third person model
81 * shot = muzzle end (for muzzle flashes)
82 * g_tuba.md3 - pickup model
86 // self.origin, self.angles
88 // self.movedir, self.view_ofs
94 void CL_WeaponEntity_SetModel(string name)
99 // if there is a child entity, hide it until we're sure we use it
100 if (self.weaponentity)
101 self.weaponentity.model = "";
102 setmodel(self, strcat("models/weapons/v_", name, ".md3")); // precision set below
103 v_shot_idx = gettagindex(self, "shot"); // used later
105 v_shot_idx = gettagindex(self, "tag_shot");
107 setmodel(self, strcat("models/weapons/h_", name, ".iqm")); // precision set below
108 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
109 self.anim_fire1 = animfixfps(self, '0 1 0.01', '0 0 0');
110 self.anim_fire2 = animfixfps(self, '1 1 0.01', '0 0 0');
111 self.anim_idle = animfixfps(self, '2 1 0.01', '0 0 0');
112 self.anim_reload = animfixfps(self, '3 1 0.01', '0 0 0');
114 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
115 // if we don't, this is a "real" animated model
116 if(gettagindex(self, "weapon"))
118 if (!self.weaponentity)
119 self.weaponentity = spawn();
120 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
121 setattachment(self.weaponentity, self, "weapon");
123 else if(gettagindex(self, "tag_weapon"))
125 if (!self.weaponentity)
126 self.weaponentity = spawn();
127 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
128 setattachment(self.weaponentity, self, "tag_weapon");
132 if(self.weaponentity)
133 remove(self.weaponentity);
134 self.weaponentity = world;
137 setorigin(self,'0 0 0');
138 self.angles = '0 0 0';
140 self.viewmodelforclient = world;
144 if(v_shot_idx) // v_ model attached to invisible h_ model
146 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
150 idx = gettagindex(self, "shot");
152 idx = gettagindex(self, "tag_shot");
154 self.movedir = gettaginfo(self, idx);
157 print("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
158 self.movedir = '0 0 0';
162 if(self.weaponentity) // v_ model attached to invisible h_ model
164 idx = gettagindex(self.weaponentity, "shell");
166 idx = gettagindex(self.weaponentity, "tag_shell");
168 self.spawnorigin = gettaginfo(self.weaponentity, idx);
174 idx = gettagindex(self, "shell");
176 idx = gettagindex(self, "tag_shell");
178 self.spawnorigin = gettaginfo(self, idx);
181 print("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
182 self.spawnorigin = self.movedir;
188 self.oldorigin = '0 0 0'; // use regular attachment
192 if(self.weaponentity)
194 idx = gettagindex(self, "weapon");
196 idx = gettagindex(self, "tag_weapon");
200 idx = gettagindex(self, "handle");
202 idx = gettagindex(self, "tag_handle");
206 self.oldorigin = self.movedir - gettaginfo(self, idx);
210 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");
211 self.oldorigin = '0 0 0'; // there is no way to recover from this
215 self.viewmodelforclient = self.owner;
220 if(self.weaponentity)
221 remove(self.weaponentity);
222 self.weaponentity = world;
223 self.movedir = '0 0 0';
224 self.spawnorigin = '0 0 0';
225 self.oldorigin = '0 0 0';
226 self.anim_fire1 = '0 1 0.01';
227 self.anim_fire2 = '0 1 0.01';
228 self.anim_idle = '0 1 0.01';
229 self.anim_reload = '0 1 0.01';
232 self.view_ofs = '0 0 0';
234 if(self.movedir_x >= 0)
238 self.movedir = shotorg_adjust(v0, FALSE, FALSE);
239 self.view_ofs = shotorg_adjust(v0, FALSE, TRUE) - v0;
241 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
242 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
244 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
246 // check if an instant weapon switch occurred
247 setorigin(self, self.view_ofs);
248 // reset animstate now
249 self.wframe = WFRAME_IDLE;
250 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
253 vector CL_Weapon_GetShotOrg(float wpn)
257 wi = get_weaponinfo(wpn);
260 CL_WeaponEntity_SetModel(wi.mdl);
262 CL_WeaponEntity_SetModel("");
268 void CL_Weaponentity_Think()
271 self.nextthink = time;
272 if (intermission_running)
273 self.frame = self.anim_idle_x;
274 if (self.owner.weaponentity != self)
276 if (self.weaponentity)
277 remove(self.weaponentity);
281 if (self.owner.deadflag != DEAD_NO)
284 if (self.weaponentity)
285 self.weaponentity.model = "";
288 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
290 self.weaponname = self.owner.weaponname;
291 self.dmg = self.owner.modelindex;
292 self.deadflag = self.owner.deadflag;
294 CL_WeaponEntity_SetModel(self.owner.weaponname);
297 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
298 self.effects = self.owner.effects & EFMASK_CHEAP;
299 self.effects &= ~EF_LOWPRECISION;
300 self.effects &= ~EF_FULLBRIGHT; // can mask team color, so get rid of it
301 self.effects &= ~EF_TELEPORT_BIT;
302 self.effects &= ~EF_RESTARTANIM_BIT;
305 if(self.owner.alpha == default_player_alpha)
306 self.alpha = default_weapon_alpha;
307 else if(self.owner.alpha != 0)
308 self.alpha = self.owner.alpha;
312 self.glowmod = self.owner.weaponentity_glowmod;
313 self.colormap = self.owner.colormap;
314 if (self.weaponentity)
316 self.weaponentity.effects = self.effects;
317 self.weaponentity.alpha = self.alpha;
318 self.weaponentity.colormap = self.colormap;
319 self.weaponentity.glowmod = self.glowmod;
322 self.angles = '0 0 0';
324 float f = (self.owner.weapon_nextthink - time);
325 if (self.state == WS_RAISE && !intermission_running)
327 entity newwep = get_weaponinfo(self.owner.switchweapon);
328 f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
329 self.angles_x = -90 * f * f;
331 else if (self.state == WS_DROP && !intermission_running)
333 entity oldwep = get_weaponinfo(self.owner.weapon);
334 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
335 self.angles_x = -90 * f * f;
337 else if (self.state == WS_CLEAR)
340 self.angles_x = -90 * f * f;
344 void CL_ExteriorWeaponentity_Think()
347 self.nextthink = time;
348 if (self.owner.exteriorweaponentity != self)
353 if (self.owner.deadflag != DEAD_NO)
358 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
360 self.weaponname = self.owner.weaponname;
361 self.dmg = self.owner.modelindex;
362 self.deadflag = self.owner.deadflag;
363 if (self.owner.weaponname != "")
364 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
368 if((tag_found = gettagindex(self.owner, "tag_weapon")))
370 self.tag_index = tag_found;
371 self.tag_entity = self.owner;
374 setattachment(self, self.owner, "bip01 r hand");
376 self.effects = self.owner.effects;
377 self.effects |= EF_LOWPRECISION;
378 self.effects = self.effects & EFMASK_CHEAP; // eat performance
379 if(self.owner.alpha == default_player_alpha)
380 self.alpha = default_weapon_alpha;
381 else if(self.owner.alpha != 0)
382 self.alpha = self.owner.alpha;
386 self.glowmod = self.owner.weaponentity_glowmod;
387 self.colormap = self.owner.colormap;
389 CSQCMODEL_AUTOUPDATE();
392 // spawning weaponentity for client
393 void CL_SpawnWeaponentity()
395 self.weaponentity = spawn();
396 self.weaponentity.classname = "weaponentity";
397 self.weaponentity.solid = SOLID_NOT;
398 self.weaponentity.owner = self;
399 setmodel(self.weaponentity, ""); // precision set when changed
400 setorigin(self.weaponentity, '0 0 0');
401 self.weaponentity.angles = '0 0 0';
402 self.weaponentity.viewmodelforclient = self;
403 self.weaponentity.flags = 0;
404 self.weaponentity.think = CL_Weaponentity_Think;
405 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
406 self.weaponentity.nextthink = time;
408 self.exteriorweaponentity = spawn();
409 self.exteriorweaponentity.classname = "exteriorweaponentity";
410 self.exteriorweaponentity.solid = SOLID_NOT;
411 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
412 self.exteriorweaponentity.owner = self;
413 setorigin(self.exteriorweaponentity, '0 0 0');
414 self.exteriorweaponentity.angles = '0 0 0';
415 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
416 self.exteriorweaponentity.nextthink = time;
419 entity oldself = self;
420 self = self.exteriorweaponentity;
421 CSQCMODEL_AUTOINIT();
429 if (self.weapon != -1)
432 self.switchingweapon = 0;
434 if (self.weaponentity)
436 self.weaponentity.state = WS_CLEAR;
437 self.weaponentity.effects = 0;
443 if (self.weaponentity)
444 self.weaponentity.state = WS_READY;
445 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
450 float weapon_prepareattack_checkammo(float secondary)
452 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
453 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
455 // always keep the Mine Layer if we placed mines, so that we can detonate them
457 if(self.weapon == WEP_MINE_LAYER)
458 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
461 if(self.weapon == WEP_SHOTGUN)
462 if(!secondary && WEP_CVAR(shotgun, secondary) == 1)
463 return FALSE; // no clicking, just allow
465 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
467 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
468 self.prevdryfire = time;
471 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
473 if(time - self.prevwarntime > 1)
479 ITEM_WEAPON_PRIMORSEC,
485 self.prevwarntime = time;
487 else // this weapon is totally unable to fire, switch to another one
489 W_SwitchToOtherWeapon(self);
497 float weapon_prepareattack_check(float secondary, float attacktime)
499 if(!weapon_prepareattack_checkammo(secondary))
502 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
503 //if all players readied up and the countdown is running
504 if(time < game_starttime || time < self.race_penalty) {
508 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
511 // do not even think about shooting if switching
512 if(self.switchweapon != self.weapon)
517 // don't fire if previous attack is not finished
518 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
520 // don't fire while changing weapon
521 if (self.weaponentity.state != WS_READY)
527 float weapon_prepareattack_do(float secondary, float attacktime)
529 self.weaponentity.state = WS_INUSE;
531 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
533 // if the weapon hasn't been firing continuously, reset the timer
536 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
538 ATTACK_FINISHED(self) = time;
539 //dprint("resetting attack finished to ", ftos(time), "\n");
541 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
543 self.bulletcounter += 1;
544 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
547 float weapon_prepareattack(float secondary, float attacktime)
549 if(weapon_prepareattack_check(secondary, attacktime))
551 weapon_prepareattack_do(secondary, attacktime);
558 void weapon_thinkf(float fr, float t, void() func)
564 if(fr == WFRAME_DONTCHANGE)
566 fr = self.weaponentity.wframe;
569 else if (fr == WFRAME_IDLE)
578 if (self.weaponentity)
580 self.weaponentity.wframe = fr;
582 if (fr == WFRAME_IDLE)
583 a = self.weaponentity.anim_idle;
584 else if (fr == WFRAME_FIRE1)
585 a = self.weaponentity.anim_fire1;
586 else if (fr == WFRAME_FIRE2)
587 a = self.weaponentity.anim_fire2;
588 else // if (fr == WFRAME_RELOAD)
589 a = self.weaponentity.anim_reload;
590 a_z *= g_weaponratefactor;
591 setanim(self.weaponentity, a, restartanim == FALSE, restartanim, restartanim);
598 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
600 backtrace("Tried to override initial weapon think function - should this really happen?");
603 t *= W_WeaponRateFactor();
605 // VorteX: haste can be added here
606 if (self.weapon_think == w_ready)
608 self.weapon_nextthink = time;
609 //dprint("started firing at ", ftos(time), "\n");
611 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
613 self.weapon_nextthink = time;
614 //dprint("reset weapon animation timer at ", ftos(time), "\n");
616 self.weapon_nextthink = self.weapon_nextthink + t;
617 self.weapon_think = func;
618 //dprint("next ", ftos(self.weapon_nextthink), "\n");
620 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
622 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
623 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
625 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
629 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
630 self.anim_upper_action = 0;
634 float forbidWeaponUse()
636 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
638 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
640 if(self.player_blocked)
644 if(self.weapon_blocked)
654 self.weapon_frametime = frametime;
656 if (!self.weaponentity || self.health < 1)
657 return; // Dead player can't use weapons and injure impulse commands
659 if(forbidWeaponUse())
660 if(self.weaponentity.state != WS_CLEAR)
666 if(!self.switchweapon)
669 self.switchingweapon = 0;
670 self.weaponentity.state = WS_CLEAR;
671 self.weaponname = "";
672 //self.items &= ~IT_AMMO;
676 makevectors(self.v_angle);
677 fo = v_forward; // save them in case the weapon think functions change it
682 if (self.weapon != self.switchweapon)
684 if (self.weaponentity.state == WS_CLEAR)
687 self.switchingweapon = self.switchweapon;
688 entity newwep = get_weaponinfo(self.switchweapon);
690 // the two weapon entities will notice this has changed and update their models
691 self.weapon = self.switchweapon;
692 self.weaponname = newwep.mdl;
693 self.bulletcounter = 0;
694 self.ammo_field = newwep.ammo_field;
695 WEP_ACTION(self.switchweapon, WR_SETUP);
696 self.weaponentity.state = WS_RAISE;
698 // set our clip load to the load of the weapon we switched to, if it's reloadable
699 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
701 self.clip_load = self.(weapon_load[self.switchweapon]);
702 self.clip_size = newwep.reloading_ammo;
705 self.clip_load = self.clip_size = 0;
707 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
709 else if (self.weaponentity.state == WS_DROP)
711 // in dropping phase we can switch at any time
712 self.switchingweapon = self.switchweapon;
714 else if (self.weaponentity.state == WS_READY)
717 self.switchingweapon = self.switchweapon;
718 entity oldwep = get_weaponinfo(self.weapon);
720 // set up weapon switch think in the future, and start drop anim
721 #ifndef INDEPENDENT_ATTACK_FINISHED
722 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
725 sound(self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
726 self.weaponentity.state = WS_DROP;
727 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
728 #ifndef INDEPENDENT_ATTACK_FINISHED
734 // LordHavoc: network timing test code
736 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
741 // call the think code which may fire the weapon
742 // and do so multiple times to resolve framerate dependency issues if the
743 // server framerate is very low and the weapon fire rate very high
746 while (c < W_TICSPERFRAME)
749 if(w && !(self.weapons & WepSet_FromWeapon(w)))
751 if(self.weapon == self.switchweapon)
752 W_SwitchWeapon_Force(self, w_getbestweapon(self));
761 WEP_ACTION(self.weapon, WR_THINK);
763 WEP_ACTION(self.weapon, WR_GONETHINK);
765 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
767 if(self.weapon_think)
775 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
780 void W_AttachToShotorg(entity flash, vector offset)
784 flash.angles_z = random() * 360;
786 if(gettagindex(self.weaponentity, "shot"))
787 setattachment(flash, self.weaponentity, "shot");
789 setattachment(flash, self.weaponentity, "tag_shot");
790 setorigin(flash, offset);
793 copyentity(flash, xflash);
795 flash.viewmodelforclient = self;
797 if(self.weaponentity.oldorigin_x > 0)
799 setattachment(xflash, self.exteriorweaponentity, "");
800 setorigin(xflash, self.weaponentity.oldorigin + offset);
804 if(gettagindex(self.exteriorweaponentity, "shot"))
805 setattachment(xflash, self.exteriorweaponentity, "shot");
807 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
808 setorigin(xflash, offset);
812 void W_DecreaseAmmo(float ammo_use)
814 entity wep = get_weaponinfo(self.weapon);
816 if(cvar("g_overkill"))
817 if(self.ok_use_ammocharge)
819 ok_DecreaseCharge(self, self.weapon);
823 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
826 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
827 if(wep.reloading_ammo)
829 self.clip_load -= ammo_use;
830 self.(weapon_load[self.weapon]) = self.clip_load;
832 else if(wep.ammo_field != ammo_none)
834 self.(wep.ammo_field) -= ammo_use;
835 if(self.(wep.ammo_field) < 0)
838 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
839 "Please notify Samual immediately with a copy of this backtrace!\n",
842 GetAmmoPicture(wep.ammo_field),
844 self.(wep.ammo_field)
850 // weapon reloading code
852 .float reload_ammo_amount, reload_ammo_min, reload_time;
853 .float reload_complain;
854 .string reload_sound;
856 void W_ReloadedAndReady()
858 // finish the reloading process, and do the ammo transfer
860 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
862 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
863 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
864 self.clip_load = self.reload_ammo_amount;
867 // make sure we don't add more ammo than we have
868 float load = min(self.reload_ammo_amount - self.clip_load, self.(self.ammo_field));
869 self.clip_load += load;
870 self.(self.ammo_field) -= load;
872 self.(weapon_load[self.weapon]) = self.clip_load;
874 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
875 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
876 // so your weapon is disabled for a few seconds without reason
878 //ATTACK_FINISHED(self) -= self.reload_time - 1;
883 void W_Reload(float sent_ammo_min, string sent_sound)
885 // set global values to work with
887 e = get_weaponinfo(self.weapon);
889 if(cvar("g_overkill"))
890 if(self.ok_use_ammocharge)
893 self.reload_ammo_min = sent_ammo_min;
894 self.reload_ammo_amount = e.reloading_ammo;;
895 self.reload_time = e.reloading_time;
896 self.reload_sound = sent_sound;
898 // don't reload weapons that don't have the RELOADABLE flag
899 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
901 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
905 // return if reloading is disabled for this weapon
906 if(!self.reload_ammo_amount)
909 // our weapon is fully loaded, no need to reload
910 if (self.clip_load >= self.reload_ammo_amount)
913 // no ammo, so nothing to load
914 if(self.ammo_field != ammo_none)
915 if(!self.(self.ammo_field) && self.reload_ammo_min)
916 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
918 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
920 play2(self, "weapons/unavailable.wav");
921 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
922 self.reload_complain = time + 1;
924 // switch away if the amount of ammo is not enough to keep using this weapon
925 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
927 self.clip_load = -1; // reload later
928 W_SwitchToOtherWeapon(self);
933 if (self.weaponentity)
935 if (self.weaponentity.wframe == WFRAME_RELOAD)
938 // allow switching away while reloading, but this will cause a new reload!
939 self.weaponentity.state = WS_READY;
942 // now begin the reloading process
944 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
946 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
947 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
948 // so your weapon is disabled for a few seconds without reason
950 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
952 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
954 if(self.clip_load < 0)
956 self.old_clip_load = self.clip_load;
957 self.clip_load = self.(weapon_load[self.weapon]) = -1;
960 entity weapon_dropevent_item;
961 void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
963 entity oldself = self;
965 weapon_dropevent_item = weapon_item;
966 WEP_ACTION(weapon_type, event);