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 self.angles_x = -90 * f * f;
327 else if (self.state == WS_DROP && !intermission_running)
329 entity oldwep = get_weaponinfo(self.owner.weapon);
330 f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
331 self.angles_x = -90 * f * f;
333 else if (self.state == WS_CLEAR)
336 self.angles_x = -90 * f * f;
340 void CL_ExteriorWeaponentity_Think()
343 self.nextthink = time;
344 if (self.owner.exteriorweaponentity != self)
349 if (self.owner.deadflag != DEAD_NO)
354 if (self.weaponname != self.owner.weaponname || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
356 self.weaponname = self.owner.weaponname;
357 self.dmg = self.owner.modelindex;
358 self.deadflag = self.owner.deadflag;
359 if (self.owner.weaponname != "")
360 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
364 if((tag_found = gettagindex(self.owner, "tag_weapon")))
366 self.tag_index = tag_found;
367 self.tag_entity = self.owner;
370 setattachment(self, self.owner, "bip01 r hand");
372 self.effects = self.owner.effects;
373 self.effects |= EF_LOWPRECISION;
374 self.effects = self.effects & EFMASK_CHEAP; // eat performance
375 if(self.owner.alpha == default_player_alpha)
376 self.alpha = default_weapon_alpha;
377 else if(self.owner.alpha != 0)
378 self.alpha = self.owner.alpha;
382 self.glowmod = self.owner.weaponentity_glowmod;
383 self.colormap = self.owner.colormap;
385 CSQCMODEL_AUTOUPDATE();
388 // spawning weaponentity for client
389 void CL_SpawnWeaponentity()
391 self.weaponentity = spawn();
392 self.weaponentity.classname = "weaponentity";
393 self.weaponentity.solid = SOLID_NOT;
394 self.weaponentity.owner = self;
395 setmodel(self.weaponentity, ""); // precision set when changed
396 setorigin(self.weaponentity, '0 0 0');
397 self.weaponentity.angles = '0 0 0';
398 self.weaponentity.viewmodelforclient = self;
399 self.weaponentity.flags = 0;
400 self.weaponentity.think = CL_Weaponentity_Think;
401 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
402 self.weaponentity.nextthink = time;
404 self.exteriorweaponentity = spawn();
405 self.exteriorweaponentity.classname = "exteriorweaponentity";
406 self.exteriorweaponentity.solid = SOLID_NOT;
407 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
408 self.exteriorweaponentity.owner = self;
409 setorigin(self.exteriorweaponentity, '0 0 0');
410 self.exteriorweaponentity.angles = '0 0 0';
411 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
412 self.exteriorweaponentity.nextthink = time;
415 entity oldself = self;
416 self = self.exteriorweaponentity;
417 CSQCMODEL_AUTOINIT();
425 if (self.weapon != -1)
428 self.switchingweapon = 0;
430 if (self.weaponentity)
432 self.weaponentity.state = WS_CLEAR;
433 self.weaponentity.effects = 0;
439 if (self.weaponentity)
440 self.weaponentity.state = WS_READY;
441 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
446 float weapon_prepareattack_checkammo(float secondary)
448 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
449 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1 + secondary))
451 // always keep the Mine Layer if we placed mines, so that we can detonate them
453 if(self.weapon == WEP_MINE_LAYER)
454 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
457 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
459 sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
460 self.prevdryfire = time;
463 if(WEP_ACTION(self.weapon, WR_CHECKAMMO2 - secondary)) // check if the other firing mode has enough ammo
465 if(time - self.prevwarntime > 1)
471 ITEM_WEAPON_PRIMORSEC,
477 self.prevwarntime = time;
479 else // this weapon is totally unable to fire, switch to another one
481 W_SwitchToOtherWeapon(self);
489 float weapon_prepareattack_check(float secondary, float attacktime)
491 if(!weapon_prepareattack_checkammo(secondary))
494 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
495 //if all players readied up and the countdown is running
496 if(time < game_starttime || time < self.race_penalty) {
500 if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
503 // do not even think about shooting if switching
504 if(self.switchweapon != self.weapon)
509 // don't fire if previous attack is not finished
510 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
512 // don't fire while changing weapon
513 if (self.weaponentity.state != WS_READY)
519 float weapon_prepareattack_do(float secondary, float attacktime)
521 self.weaponentity.state = WS_INUSE;
523 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
525 // if the weapon hasn't been firing continuously, reset the timer
528 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
530 ATTACK_FINISHED(self) = time;
531 //dprint("resetting attack finished to ", ftos(time), "\n");
533 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
535 self.bulletcounter += 1;
536 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
539 float weapon_prepareattack(float secondary, float attacktime)
541 if(weapon_prepareattack_check(secondary, attacktime))
543 weapon_prepareattack_do(secondary, attacktime);
550 void weapon_thinkf(float fr, float t, void() func)
556 if(fr == WFRAME_DONTCHANGE)
558 fr = self.weaponentity.wframe;
561 else if (fr == WFRAME_IDLE)
570 if (self.weaponentity)
572 self.weaponentity.wframe = fr;
574 if (fr == WFRAME_IDLE)
575 a = self.weaponentity.anim_idle;
576 else if (fr == WFRAME_FIRE1)
577 a = self.weaponentity.anim_fire1;
578 else if (fr == WFRAME_FIRE2)
579 a = self.weaponentity.anim_fire2;
580 else // if (fr == WFRAME_RELOAD)
581 a = self.weaponentity.anim_reload;
582 a_z *= g_weaponratefactor;
583 setanim(self.weaponentity, a, restartanim == FALSE, restartanim, restartanim);
590 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
592 backtrace("Tried to override initial weapon think function - should this really happen?");
595 t *= W_WeaponRateFactor();
597 // VorteX: haste can be added here
598 if (self.weapon_think == w_ready)
600 self.weapon_nextthink = time;
601 //dprint("started firing at ", ftos(time), "\n");
603 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
605 self.weapon_nextthink = time;
606 //dprint("reset weapon animation timer at ", ftos(time), "\n");
608 self.weapon_nextthink = self.weapon_nextthink + t;
609 self.weapon_think = func;
610 //dprint("next ", ftos(self.weapon_nextthink), "\n");
612 if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
614 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
615 animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
617 animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
621 if(self.anim_upper_action == ANIMACTION_SHOOT || self.anim_upper_action == ANIMACTION_MELEE)
622 self.anim_upper_action = 0;
626 float forbidWeaponUse()
628 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
630 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
632 if(self.player_blocked)
634 if(self.freezetag_frozen)
644 self.weapon_frametime = frametime;
646 if (!self.weaponentity || self.health < 1)
647 return; // Dead player can't use weapons and injure impulse commands
649 if(forbidWeaponUse())
650 if(self.weaponentity.state != WS_CLEAR)
656 if(!self.switchweapon)
659 self.switchingweapon = 0;
660 self.weaponentity.state = WS_CLEAR;
661 self.weaponname = "";
662 //self.items &= ~IT_AMMO;
666 makevectors(self.v_angle);
667 fo = v_forward; // save them in case the weapon think functions change it
672 if (self.weapon != self.switchweapon)
674 if (self.weaponentity.state == WS_CLEAR)
677 self.switchingweapon = self.switchweapon;
678 entity newwep = get_weaponinfo(self.switchweapon);
680 //self.items &= ~IT_AMMO;
681 //self.items = self.items | (newwep.items & IT_AMMO);
683 // the two weapon entities will notice this has changed and update their models
684 self.weapon = self.switchweapon;
685 self.weaponname = newwep.mdl;
686 self.bulletcounter = 0; // WEAPONTODO
687 //self.ammo_field = newwep.ammo_field;
688 WEP_ACTION(self.switchweapon, WR_SETUP);
689 self.weaponentity.state = WS_RAISE;
691 // set our clip load to the load of the weapon we switched to, if it's reloadable
692 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && newwep.reloading_ammo) // prevent accessing undefined cvars
694 self.clip_load = self.(weapon_load[self.switchweapon]);
695 self.clip_size = newwep.reloading_ammo;
698 self.clip_load = self.clip_size = 0;
700 // VorteX: add player model weapon select frame here
701 // setcustomframe(PlayerWeaponRaise);
702 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
703 //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))));
705 else if (self.weaponentity.state == WS_DROP)
707 // in dropping phase we can switch at any time
708 self.switchingweapon = self.switchweapon;
710 else if (self.weaponentity.state == WS_READY)
713 self.switchingweapon = self.switchweapon;
715 entity oldwep = get_weaponinfo(self.weapon);
717 #ifndef INDEPENDENT_ATTACK_FINISHED
718 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
721 sound (self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
722 self.weaponentity.state = WS_DROP;
723 // set up weapon switch think in the future, and start drop anim
724 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
725 //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))));
726 #ifndef INDEPENDENT_ATTACK_FINISHED
732 // LordHavoc: network timing test code
734 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
739 // call the think code which may fire the weapon
740 // and do so multiple times to resolve framerate dependency issues if the
741 // server framerate is very low and the weapon fire rate very high
744 while (c < W_TICSPERFRAME)
747 if(w && !(self.weapons & WepSet_FromWeapon(w)))
749 if(self.weapon == self.switchweapon)
750 W_SwitchWeapon_Force(self, w_getbestweapon(self));
759 WEP_ACTION(self.weapon, WR_THINK);
761 WEP_ACTION(self.weapon, WR_GONETHINK);
763 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
765 if(self.weapon_think)
773 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
778 void W_AttachToShotorg(entity flash, vector offset)
782 flash.angles_z = random() * 360;
784 if(gettagindex(self.weaponentity, "shot"))
785 setattachment(flash, self.weaponentity, "shot");
787 setattachment(flash, self.weaponentity, "tag_shot");
788 setorigin(flash, offset);
791 copyentity(flash, xflash);
793 flash.viewmodelforclient = self;
795 if(self.weaponentity.oldorigin_x > 0)
797 setattachment(xflash, self.exteriorweaponentity, "");
798 setorigin(xflash, self.weaponentity.oldorigin + offset);
802 if(gettagindex(self.exteriorweaponentity, "shot"))
803 setattachment(xflash, self.exteriorweaponentity, "shot");
805 setattachment(xflash, self.exteriorweaponentity, "tag_shot");
806 setorigin(xflash, offset);
810 void W_DecreaseAmmo(float ammo_use)
812 entity wep = get_weaponinfo(self.weapon);
814 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
817 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
818 if(wep.reloading_ammo)
820 self.clip_load -= ammo_use;
821 self.(weapon_load[self.weapon]) = self.clip_load;
824 self.(wep.ammo_field) -= ammo_use;
827 // weapon reloading code
829 .float reload_ammo_amount, reload_ammo_min, reload_time;
830 .float reload_complain;
831 .string reload_sound;
833 void W_ReloadedAndReady()
835 // finish the reloading process, and do the ammo transfer
837 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
839 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
840 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
841 self.clip_load = self.reload_ammo_amount;
844 while(self.clip_load < self.reload_ammo_amount && self.(self.ammo_field)) // make sure we don't add more ammo than we have
847 self.(self.ammo_field) -= 1;
850 self.(weapon_load[self.weapon]) = self.clip_load;
852 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
853 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
854 // so your weapon is disabled for a few seconds without reason
856 //ATTACK_FINISHED(self) -= self.reload_time - 1;
861 void W_Reload(float sent_ammo_min, string sent_sound)
863 // set global values to work with
865 e = get_weaponinfo(self.weapon);
867 self.reload_ammo_min = sent_ammo_min;
868 self.reload_ammo_amount = e.reloading_ammo;;
869 self.reload_time = e.reloading_time;
870 self.reload_sound = sent_sound;
872 // don't reload weapons that don't have the RELOADABLE flag
873 if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
875 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
879 // return if reloading is disabled for this weapon
880 if(!self.reload_ammo_amount)
883 // our weapon is fully loaded, no need to reload
884 if (self.clip_load >= self.reload_ammo_amount)
887 // no ammo, so nothing to load
888 if(self.ammo_field != ammo_none)
889 if(!self.(self.ammo_field) && self.reload_ammo_min)
890 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
892 if(IS_REAL_CLIENT(self) && self.reload_complain < time)
894 play2(self, "weapons/unavailable.wav");
895 sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
896 self.reload_complain = time + 1;
898 // switch away if the amount of ammo is not enough to keep using this weapon
899 if (!(WEP_ACTION(self.weapon, WR_CHECKAMMO1) + WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
901 self.clip_load = -1; // reload later
902 W_SwitchToOtherWeapon(self);
907 if (self.weaponentity)
909 if (self.weaponentity.wframe == WFRAME_RELOAD)
912 // allow switching away while reloading, but this will cause a new reload!
913 self.weaponentity.state = WS_READY;
916 // now begin the reloading process
918 sound(self, CH_WEAPON_SINGLE, self.reload_sound, VOL_BASE, ATTEN_NORM);
920 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
921 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
922 // so your weapon is disabled for a few seconds without reason
924 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
926 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
928 if(self.clip_load < 0)
930 self.old_clip_load = self.clip_load;
931 self.clip_load = self.(weapon_load[self.weapon]) = -1;