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;
20 // VorteX: static frame globals
21 const float WFRAME_DONTCHANGE = -1;
22 const float WFRAME_FIRE1 = 0;
23 const float WFRAME_FIRE2 = 1;
24 const float WFRAME_IDLE = 2;
25 const float WFRAME_RELOAD = 3;
28 void(float fr, float t, void() func) weapon_thinkf;
30 float CL_Weaponentity_CustomizeEntityForClient()
32 self.viewmodelforclient = self.owner;
34 if(other.enemy == self.owner)
35 self.viewmodelforclient = other;
42 * 1. simple animated model, muzzle flash handling on h_ model:
43 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
45 * shot = muzzle end (shot origin, also used for muzzle flashes)
46 * shell = casings ejection point (must be on the right hand side of the gun)
47 * weapon = attachment for v_tuba.md3
48 * v_tuba.md3 - first and third person model
49 * g_tuba.md3 - pickup model
51 * 2. simple animated model, muzzle flash handling on v_ model:
52 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
54 * weapon = attachment for v_tuba.md3
55 * v_tuba.md3 - first and third person model
57 * shot = muzzle end (shot origin, also used for muzzle flashes)
58 * shell = casings ejection point (must be on the right hand side of the gun)
59 * g_tuba.md3 - pickup model
61 * 3. fully animated model, muzzle flash handling on h_ model:
62 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
64 * shot = muzzle end (shot origin, also used for muzzle flashes)
65 * shell = casings ejection point (must be on the right hand side of the gun)
66 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
67 * v_tuba.md3 - third person model
68 * g_tuba.md3 - pickup model
70 * 4. fully animated model, muzzle flash handling on v_ model:
71 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
73 * shot = muzzle end (shot origin)
74 * shell = casings ejection point (must be on the right hand side of the gun)
75 * v_tuba.md3 - third person model
77 * shot = muzzle end (for muzzle flashes)
78 * g_tuba.md3 - pickup model
82 // self.origin, self.angles
84 // self.movedir, self.view_ofs
90 void CL_WeaponEntity_SetModel(string name)
95 // if there is a child entity, hide it until we're sure we use it
96 if (self.weaponentity)
97 self.weaponentity.model = "";
98 setmodel(self, strcat("models/weapons/v_", name, ".md3")); // precision set below
99 v_shot_idx = gettagindex(self, "shot"); // used later
101 v_shot_idx = gettagindex(self, "tag_shot");
103 setmodel(self, strcat("models/weapons/h_", name, ".iqm")); // precision set below
104 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
105 self.anim_fire1 = animfixfps(self, '0 1 0.01', '0 0 0');
106 self.anim_fire2 = animfixfps(self, '1 1 0.01', '0 0 0');
107 self.anim_idle = animfixfps(self, '2 1 0.01', '0 0 0');
108 self.anim_reload = animfixfps(self, '3 1 0.01', '0 0 0');
110 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
111 // if we don't, this is a "real" animated model
112 if(gettagindex(self, "weapon"))
114 if (!self.weaponentity)
115 self.weaponentity = spawn();
116 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
117 setattachment(self.weaponentity, self, "weapon");
119 else if(gettagindex(self, "tag_weapon"))
121 if (!self.weaponentity)
122 self.weaponentity = spawn();
123 setmodel(self.weaponentity, strcat("models/weapons/v_", name, ".md3")); // precision does not matter
124 setattachment(self.weaponentity, self, "tag_weapon");
128 if(self.weaponentity)
129 remove(self.weaponentity);
130 self.weaponentity = world;
133 setorigin(self,'0 0 0');
134 self.angles = '0 0 0';
136 self.viewmodelforclient = world;
140 if(v_shot_idx) // v_ model attached to invisible h_ model
142 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
146 idx = gettagindex(self, "shot");
148 idx = gettagindex(self, "tag_shot");
150 self.movedir = gettaginfo(self, idx);
153 print("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
154 self.movedir = '0 0 0';
158 if(self.weaponentity) // v_ model attached to invisible h_ model
160 idx = gettagindex(self.weaponentity, "shell");
162 idx = gettagindex(self.weaponentity, "tag_shell");
164 self.spawnorigin = gettaginfo(self.weaponentity, idx);
170 idx = gettagindex(self, "shell");
172 idx = gettagindex(self, "tag_shell");
174 self.spawnorigin = gettaginfo(self, idx);
177 print("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
178 self.spawnorigin = self.movedir;
184 self.oldorigin = '0 0 0'; // use regular attachment
188 if(self.weaponentity)
190 idx = gettagindex(self, "weapon");
192 idx = gettagindex(self, "tag_weapon");
196 idx = gettagindex(self, "handle");
198 idx = gettagindex(self, "tag_handle");
202 self.oldorigin = self.movedir - gettaginfo(self, idx);
206 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");
207 self.oldorigin = '0 0 0'; // there is no way to recover from this
211 self.viewmodelforclient = self.owner;
216 if(self.weaponentity)
217 remove(self.weaponentity);
218 self.weaponentity = world;
219 self.movedir = '0 0 0';
220 self.spawnorigin = '0 0 0';
221 self.oldorigin = '0 0 0';
222 self.anim_fire1 = '0 1 0.01';
223 self.anim_fire2 = '0 1 0.01';
224 self.anim_idle = '0 1 0.01';
225 self.anim_reload = '0 1 0.01';
228 self.view_ofs = '0 0 0';
230 if(self.movedir_x >= 0)
234 self.movedir = shotorg_adjust(v0, FALSE, FALSE);
235 self.view_ofs = shotorg_adjust(v0, FALSE, TRUE) - v0;
237 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
238 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
240 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
242 // check if an instant weapon switch occurred
243 setorigin(self, self.view_ofs);
244 // reset animstate now
245 self.wframe = WFRAME_IDLE;
246 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
249 vector CL_Weapon_GetShotOrg(float wpn)
253 wi = get_weaponinfo(wpn);
256 CL_WeaponEntity_SetModel(wi.mdl);
258 CL_WeaponEntity_SetModel("");
264 void CL_Weaponentity_Think()
267 self.nextthink = time;
268 if (intermission_running)
269 self.frame = self.anim_idle_x;
270 if (self.owner.weaponentity != self)
272 if (self.weaponentity)
273 remove(self.weaponentity);
277 if (self.owner.deadflag != DEAD_NO)
280 if (self.weaponentity)
281 self.weaponentity.model = "";
284 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
286 self.weaponname = self.owner.weaponname;
287 self.dmg = self.owner.modelindex;
288 self.deadflag = self.owner.deadflag;
290 CL_WeaponEntity_SetModel(self.owner.weaponname);
293 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
294 self.effects = self.owner.effects & EFMASK_CHEAP;
295 self.effects &= ~EF_LOWPRECISION;
296 self.effects &= ~EF_FULLBRIGHT; // can mask team color, so get rid of it
297 self.effects &= ~EF_TELEPORT_BIT;
298 self.effects &= ~EF_RESTARTANIM_BIT;
301 if(self.owner.alpha == default_player_alpha)
302 self.alpha = default_weapon_alpha;
303 else if(self.owner.alpha != 0)
304 self.alpha = self.owner.alpha;
308 self.glowmod = self.owner.weaponentity_glowmod;
309 self.colormap = self.owner.colormap;
310 if (self.weaponentity)
312 self.weaponentity.effects = self.effects;
313 self.weaponentity.alpha = self.alpha;
314 self.weaponentity.colormap = self.colormap;
315 self.weaponentity.glowmod = self.glowmod;
318 self.angles = '0 0 0';
320 float f = (self.owner.weapon_nextthink - time);
321 if (self.state == WS_RAISE && !intermission_running)
323 entity newwep = get_weaponinfo(self.owner.switchweapon);
324 f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
325 //print(sprintf("CL_Weaponentity_Think(): cvar: %s, value: %f, nextthink: %f\n", sprintf("g_balance_%s_switchdelay_raise", newwep.netname), cvar(sprintf("g_balance_%s_switchdelay_raise", newwep.netname)), (self.owner.weapon_nextthink - time)));
326 self.angles_x = -90 * f * f;
328 else if (self.state == WS_DROP && !intermission_running)
330 entity oldwep = get_weaponinfo(self.owner.weapon);
331 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
332 //print(sprintf("CL_Weaponentity_Think(): cvar: %s, value: %f, nextthink: %f\n", sprintf("g_balance_%s_switchdelay_drop", oldwep.netname), cvar(sprintf("g_balance_%s_switchdelay_drop", oldwep.netname)), (self.owner.weapon_nextthink - time)));
333 self.angles_x = -90 * f * f;
335 else if (self.state == WS_CLEAR)
338 self.angles_x = -90 * f * f;
342 void CL_ExteriorWeaponentity_Think()
345 self.nextthink = time;
346 if (self.owner.exteriorweaponentity != self)
351 if (self.owner.deadflag != DEAD_NO)
356 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
358 self.weaponname = self.owner.weaponname;
359 self.dmg = self.owner.modelindex;
360 self.deadflag = self.owner.deadflag;
361 if (self.owner.weaponname != "")
362 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
366 if((tag_found = gettagindex(self.owner, "tag_weapon")))
368 self.tag_index = tag_found;
369 self.tag_entity = self.owner;
372 setattachment(self, self.owner, "bip01 r hand");
374 self.effects = self.owner.effects;
375 self.effects |= EF_LOWPRECISION;
376 self.effects = self.effects & EFMASK_CHEAP; // eat performance
377 if(self.owner.alpha == default_player_alpha)
378 self.alpha = default_weapon_alpha;
379 else if(self.owner.alpha != 0)
380 self.alpha = self.owner.alpha;
384 self.glowmod = self.owner.weaponentity_glowmod;
385 self.colormap = self.owner.colormap;
387 CSQCMODEL_AUTOUPDATE();
390 // spawning weaponentity for client
391 void CL_SpawnWeaponentity()
393 self.weaponentity = spawn();
394 self.weaponentity.classname = "weaponentity";
395 self.weaponentity.solid = SOLID_NOT;
396 self.weaponentity.owner = self;
397 setmodel(self.weaponentity, ""); // precision set when changed
398 setorigin(self.weaponentity, '0 0 0');
399 self.weaponentity.angles = '0 0 0';
400 self.weaponentity.viewmodelforclient = self;
401 self.weaponentity.flags = 0;
402 self.weaponentity.think = CL_Weaponentity_Think;
403 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
404 self.weaponentity.nextthink = time;
406 self.exteriorweaponentity = spawn();
407 self.exteriorweaponentity.classname = "exteriorweaponentity";
408 self.exteriorweaponentity.solid = SOLID_NOT;
409 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
410 self.exteriorweaponentity.owner = self;
411 setorigin(self.exteriorweaponentity, '0 0 0');
412 self.exteriorweaponentity.angles = '0 0 0';
413 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
414 self.exteriorweaponentity.nextthink = time;
417 entity oldself = self;
418 self = self.exteriorweaponentity;
419 CSQCMODEL_AUTOINIT();
427 if (self.weapon != -1)
430 self.switchingweapon = 0;
432 if (self.weaponentity)
434 self.weaponentity.state = WS_CLEAR;
435 self.weaponentity.effects = 0;
441 if (self.weaponentity)
442 self.weaponentity.state = WS_READY;
443 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
448 float weapon_prepareattack_checkammo(float secondary)
450 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
451 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
453 // always keep the Mine Layer if we placed mines, so that we can detonate them
455 if(self.weapon == WEP_MINE_LAYER)
456 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
459 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
461 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
462 self.prevdryfire = time;
465 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
467 if(time - self.prevwarntime > 1)
473 ITEM_WEAPON_PRIMORSEC,
479 self.prevwarntime = time;
481 else // this weapon is totally unable to fire, switch to another one
483 W_SwitchToOtherWeapon(self);
491 float weapon_prepareattack_check(float secondary, float attacktime)
493 if(!weapon_prepareattack_checkammo(secondary))
496 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
497 //if all players readied up and the countdown is running
498 if(time < game_starttime || time < self.race_penalty) {
502 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
505 // do not even think about shooting if switching
506 if(self.switchweapon != self.weapon)
511 // don't fire if previous attack is not finished
512 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
514 // don't fire while changing weapon
515 if (self.weaponentity.state != WS_READY)
521 float weapon_prepareattack_do(float secondary, float attacktime)
523 self.weaponentity.state = WS_INUSE;
525 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
527 // if the weapon hasn't been firing continuously, reset the timer
530 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
532 ATTACK_FINISHED(self) = time;
533 //dprint("resetting attack finished to ", ftos(time), "\n");
535 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
537 self.bulletcounter += 1;
538 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
541 float weapon_prepareattack(float secondary, float attacktime)
543 if(weapon_prepareattack_check(secondary, attacktime))
545 weapon_prepareattack_do(secondary, attacktime);
552 void weapon_thinkf(float fr, float t, void() func)
558 if(fr == WFRAME_DONTCHANGE)
560 fr = self.weaponentity.wframe;
563 else if (fr == WFRAME_IDLE)
572 if (self.weaponentity)
574 self.weaponentity.wframe = fr;
576 if (fr == WFRAME_IDLE)
577 a = self.weaponentity.anim_idle;
578 else if (fr == WFRAME_FIRE1)
579 a = self.weaponentity.anim_fire1;
580 else if (fr == WFRAME_FIRE2)
581 a = self.weaponentity.anim_fire2;
582 else // if (fr == WFRAME_RELOAD)
583 a = self.weaponentity.anim_reload;
584 a_z *= g_weaponratefactor;
585 setanim(self.weaponentity, a, restartanim == FALSE, restartanim, restartanim);
592 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
594 backtrace("Tried to override initial weapon think function - should this really happen?");
597 t *= W_WeaponRateFactor();
599 // VorteX: haste can be added here
600 if (self.weapon_think == w_ready)
602 self.weapon_nextthink = time;
603 //dprint("started firing at ", ftos(time), "\n");
605 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
607 self.weapon_nextthink = time;
608 //dprint("reset weapon animation timer at ", ftos(time), "\n");
610 self.weapon_nextthink = self.weapon_nextthink + t;
611 self.weapon_think = func;
612 //dprint("next ", ftos(self.weapon_nextthink), "\n");
614 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
616 if(self.weapon == WEP_SHOCKWAVE && fr == WFRAME_FIRE2)
617 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
619 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
623 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
624 self.anim_upper_action = 0;
628 float forbidWeaponUse()
630 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
632 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
634 if(self.player_blocked)
636 if(self.freezetag_frozen)
646 self.weapon_frametime = frametime;
648 if (!self.weaponentity || self.health < 1)
649 return; // Dead player can't use weapons and injure impulse commands
651 if(forbidWeaponUse())
652 if(self.weaponentity.state != WS_CLEAR)
658 if(!self.switchweapon)
661 self.switchingweapon = 0;
662 self.weaponentity.state = WS_CLEAR;
663 self.weaponname = "";
664 //self.items &= ~IT_AMMO;
668 makevectors(self.v_angle);
669 fo = v_forward; // save them in case the weapon think functions change it
674 if (self.weapon != self.switchweapon)
676 if (self.weaponentity.state == WS_CLEAR)
679 self.switchingweapon = self.switchweapon;
680 entity newwep = get_weaponinfo(self.switchweapon);
682 //self.items &= ~IT_AMMO;
683 //self.items = self.items | (newwep.items & IT_AMMO);
685 // the two weapon entities will notice this has changed and update their models
686 self.weapon = self.switchweapon;
687 self.weaponname = newwep.mdl;
688 self.bulletcounter = 0; // WEAPONTODO
689 //self.current_ammo = newwep.current_ammo;
690 WEP_ACTION(self.switchweapon, WR_SETUP);
691 self.weaponentity.state = WS_RAISE;
693 // set our clip load to the load of the weapon we switched to, if it's reloadable
694 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
696 self.clip_load = self.(weapon_load[self.switchweapon]);
697 self.clip_size = newwep.reloading_ammo;
700 self.clip_load = self.clip_size = 0;
702 // VorteX: add player model weapon select frame here
703 // setcustomframe(PlayerWeaponRaise);
704 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
705 //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_raise", newwep.netname), cvar(sprintf("g_balance_%s_switchdelay_raise", newwep.netname))));
707 else if (self.weaponentity.state == WS_DROP)
709 // in dropping phase we can switch at any time
710 self.switchingweapon = self.switchweapon;
712 else if (self.weaponentity.state == WS_READY)
715 self.switchingweapon = self.switchweapon;
717 entity oldwep = get_weaponinfo(self.weapon);
719 #ifndef INDEPENDENT_ATTACK_FINISHED
720 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
723 sound (self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
724 self.weaponentity.state = WS_DROP;
725 // set up weapon switch think in the future, and start drop anim
726 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
727 //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_drop", oldwep.netname), cvar(sprintf("g_balance_%s_switchdelay_drop", oldwep.netname))));
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((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
819 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
820 if(wep.reloading_ammo)
822 self.clip_load -= ammo_use;
823 self.(weapon_load[self.weapon]) = self.clip_load;
826 self.(wep.current_ammo) -= ammo_use;
829 // weapon reloading code
831 .float reload_ammo_amount, reload_ammo_min, reload_time;
832 .float reload_complain;
833 .string reload_sound;
835 void W_ReloadedAndReady()
837 // finish the reloading process, and do the ammo transfer
839 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
841 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
842 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO)
843 self.clip_load = self.reload_ammo_amount;
846 while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have
849 self.(self.current_ammo) -= 1;
852 self.(weapon_load[self.weapon]) = self.clip_load;
854 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
855 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
856 // so your weapon is disabled for a few seconds without reason
858 //ATTACK_FINISHED(self) -= self.reload_time - 1;
863 void W_Reload(float sent_ammo_min, string sent_sound)
865 // set global values to work with
867 e = get_weaponinfo(self.weapon);
869 self.reload_ammo_min = sent_ammo_min;
870 self.reload_ammo_amount = e.reloading_ammo;;
871 self.reload_time = e.reloading_time;
872 self.reload_sound = sent_sound;
874 // don't reload weapons that don't have the RELOADABLE flag
875 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
877 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
881 // return if reloading is disabled for this weapon
882 if(!self.reload_ammo_amount)
885 // our weapon is fully loaded, no need to reload
886 if (self.clip_load >= self.reload_ammo_amount)
889 // no ammo, so nothing to load
890 if(!self.(self.current_ammo) && self.reload_ammo_min)
891 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
893 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
895 play2(self, "weapons/unavailable.wav");
896 sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n"));
897 self.reload_complain = time + 1;
899 // switch away if the amount of ammo is not enough to keep using this weapon
900 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
902 self.clip_load = -1; // reload later
903 W_SwitchToOtherWeapon(self);
908 if (self.weaponentity)
910 if (self.weaponentity.wframe == WFRAME_RELOAD)
913 // allow switching away while reloading, but this will cause a new reload!
914 self.weaponentity.state = WS_READY;
917 // now begin the reloading process
919 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
921 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
922 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
923 // so your weapon is disabled for a few seconds without reason
925 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
927 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
929 if(self.clip_load < 0)
931 self.old_clip_load = self.clip_load;
932 self.clip_load = self.(weapon_load[self.weapon]) = -1;