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 == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
463 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
464 self.prevdryfire = time;
467 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
469 if(time - self.prevwarntime > 1)
475 ITEM_WEAPON_PRIMORSEC,
481 self.prevwarntime = time;
483 else // this weapon is totally unable to fire, switch to another one
485 W_SwitchToOtherWeapon(self);
493 float weapon_prepareattack_check(float secondary, float attacktime)
495 if(!weapon_prepareattack_checkammo(secondary))
498 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
499 //if all players readied up and the countdown is running
500 if(time < game_starttime || time < self.race_penalty) {
504 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
507 // do not even think about shooting if switching
508 if(self.switchweapon != self.weapon)
513 // don't fire if previous attack is not finished
514 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
516 // don't fire while changing weapon
517 if (self.weaponentity.state != WS_READY)
523 float weapon_prepareattack_do(float secondary, float attacktime)
525 self.weaponentity.state = WS_INUSE;
527 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
529 // if the weapon hasn't been firing continuously, reset the timer
532 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
534 ATTACK_FINISHED(self) = time;
535 //dprint("resetting attack finished to ", ftos(time), "\n");
537 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
539 self.bulletcounter += 1;
540 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
543 float weapon_prepareattack(float secondary, float attacktime)
545 if(weapon_prepareattack_check(secondary, attacktime))
547 weapon_prepareattack_do(secondary, attacktime);
554 void weapon_thinkf(float fr, float t, void() func)
560 if(fr == WFRAME_DONTCHANGE)
562 fr = self.weaponentity.wframe;
565 else if (fr == WFRAME_IDLE)
574 if (self.weaponentity)
576 self.weaponentity.wframe = fr;
578 if (fr == WFRAME_IDLE)
579 a = self.weaponentity.anim_idle;
580 else if (fr == WFRAME_FIRE1)
581 a = self.weaponentity.anim_fire1;
582 else if (fr == WFRAME_FIRE2)
583 a = self.weaponentity.anim_fire2;
584 else // if (fr == WFRAME_RELOAD)
585 a = self.weaponentity.anim_reload;
586 a_z *= g_weaponratefactor;
587 setanim(self.weaponentity, a, restartanim == FALSE, restartanim, restartanim);
594 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
596 backtrace("Tried to override initial weapon think function - should this really happen?");
599 t *= W_WeaponRateFactor();
601 // VorteX: haste can be added here
602 if (self.weapon_think == w_ready)
604 self.weapon_nextthink = time;
605 //dprint("started firing at ", ftos(time), "\n");
607 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
609 self.weapon_nextthink = time;
610 //dprint("reset weapon animation timer at ", ftos(time), "\n");
612 self.weapon_nextthink = self.weapon_nextthink + t;
613 self.weapon_think = func;
614 //dprint("next ", ftos(self.weapon_nextthink), "\n");
616 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
618 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
619 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
621 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
625 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
626 self.anim_upper_action = 0;
630 float forbidWeaponUse()
632 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
634 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
636 if(self.player_blocked)
648 self.weapon_frametime = frametime;
650 if (!self.weaponentity || self.health < 1)
651 return; // Dead player can't use weapons and injure impulse commands
653 if(forbidWeaponUse())
654 if(self.weaponentity.state != WS_CLEAR)
660 if(!self.switchweapon)
663 self.switchingweapon = 0;
664 self.weaponentity.state = WS_CLEAR;
665 self.weaponname = "";
666 //self.items &= ~IT_AMMO;
670 makevectors(self.v_angle);
671 fo = v_forward; // save them in case the weapon think functions change it
676 if (self.weapon != self.switchweapon)
678 if (self.weaponentity.state == WS_CLEAR)
681 self.switchingweapon = self.switchweapon;
682 entity newwep = get_weaponinfo(self.switchweapon);
684 // the two weapon entities will notice this has changed and update their models
685 self.weapon = self.switchweapon;
686 self.weaponname = newwep.mdl;
687 self.bulletcounter = 0;
688 //self.ammo_field = newwep.ammo_field;
689 WEP_ACTION(self.switchweapon, WR_SETUP);
690 self.weaponentity.state = WS_RAISE;
692 // set our clip load to the load of the weapon we switched to, if it's reloadable
693 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
695 self.clip_load = self.(weapon_load[self.switchweapon]);
696 self.clip_size = newwep.reloading_ammo;
699 self.clip_load = self.clip_size = 0;
701 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
703 else if (self.weaponentity.state == WS_DROP)
705 // in dropping phase we can switch at any time
706 self.switchingweapon = self.switchweapon;
708 else if (self.weaponentity.state == WS_READY)
711 self.switchingweapon = self.switchweapon;
712 entity oldwep = get_weaponinfo(self.weapon);
714 // set up weapon switch think in the future, and start drop anim
715 #ifndef INDEPENDENT_ATTACK_FINISHED
716 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
719 sound(self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
720 self.weaponentity.state = WS_DROP;
721 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
722 #ifndef INDEPENDENT_ATTACK_FINISHED
728 // LordHavoc: network timing test code
730 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
735 // call the think code which may fire the weapon
736 // and do so multiple times to resolve framerate dependency issues if the
737 // server framerate is very low and the weapon fire rate very high
740 while (c < W_TICSPERFRAME)
743 if(w && !(self.weapons & WepSet_FromWeapon(w)))
745 if(self.weapon == self.switchweapon)
746 W_SwitchWeapon_Force(self, w_getbestweapon(self));
755 WEP_ACTION(self.weapon, WR_THINK);
757 WEP_ACTION(self.weapon, WR_GONETHINK);
759 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
761 if(self.weapon_think)
769 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
774 void W_AttachToShotorg(entity flash, vector offset)
778 flash.angles_z = random() * 360;
780 if(gettagindex(self.weaponentity, "shot"))
781 setattachment(flash, self.weaponentity, "shot");
783 setattachment(flash, self.weaponentity, "tag_shot");
784 setorigin(flash, offset);
787 copyentity(flash, xflash);
789 flash.viewmodelforclient = self;
791 if(self.weaponentity.oldorigin_x > 0)
793 setattachment(xflash, self.exteriorweaponentity, "");
794 setorigin(xflash, self.weaponentity.oldorigin + offset);
798 if(gettagindex(self.exteriorweaponentity, "shot"))
799 setattachment(xflash, self.exteriorweaponentity, "shot");
801 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
802 setorigin(xflash, offset);
806 void W_DecreaseAmmo(float ammo_use)
808 entity wep = get_weaponinfo(self.weapon);
810 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
813 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
814 if(wep.reloading_ammo)
816 self.clip_load -= ammo_use;
817 self.(weapon_load[self.weapon]) = self.clip_load;
819 else if(wep.ammo_field != ammo_none)
821 self.(wep.ammo_field) -= ammo_use;
822 if(self.(wep.ammo_field) < 0)
825 "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
826 "Please notify Samual immediately with a copy of this backtrace!\n",
829 GetAmmoPicture(wep.ammo_field),
831 self.(wep.ammo_field)
837 // weapon reloading code
839 .float reload_ammo_amount, reload_ammo_min, reload_time;
840 .float reload_complain;
841 .string reload_sound;
843 void W_ReloadedAndReady()
845 // finish the reloading process, and do the ammo transfer
847 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
849 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
850 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
851 self.clip_load = self.reload_ammo_amount;
854 while(self.clip_load < self.reload_ammo_amount && self.(self.ammo_field)) // make sure we don't add more ammo than we have
857 self.(self.ammo_field) -= 1;
860 self.(weapon_load[self.weapon]) = self.clip_load;
862 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
863 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
864 // so your weapon is disabled for a few seconds without reason
866 //ATTACK_FINISHED(self) -= self.reload_time - 1;
871 void W_Reload(float sent_ammo_min, string sent_sound)
873 // set global values to work with
875 e = get_weaponinfo(self.weapon);
877 self.reload_ammo_min = sent_ammo_min;
878 self.reload_ammo_amount = e.reloading_ammo;;
879 self.reload_time = e.reloading_time;
880 self.reload_sound = sent_sound;
882 // don't reload weapons that don't have the RELOADABLE flag
883 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
885 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
889 // return if reloading is disabled for this weapon
890 if(!self.reload_ammo_amount)
893 // our weapon is fully loaded, no need to reload
894 if (self.clip_load >= self.reload_ammo_amount)
897 // no ammo, so nothing to load
898 if(self.ammo_field != ammo_none)
899 if(!self.(self.ammo_field) && self.reload_ammo_min)
900 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
902 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
904 play2(self, "weapons/unavailable.wav");
905 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
906 self.reload_complain = time + 1;
908 // switch away if the amount of ammo is not enough to keep using this weapon
909 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
911 self.clip_load = -1; // reload later
912 W_SwitchToOtherWeapon(self);
917 if (self.weaponentity)
919 if (self.weaponentity.wframe == WFRAME_RELOAD)
922 // allow switching away while reloading, but this will cause a new reload!
923 self.weaponentity.state = WS_READY;
926 // now begin the reloading process
928 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
930 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
931 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
932 // so your weapon is disabled for a few seconds without reason
934 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
936 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
938 if(self.clip_load < 0)
940 self.old_clip_load = self.clip_load;
941 self.clip_load = self.(weapon_load[self.weapon]) = -1;