2 void thrown_wep_think()
5 float timeleft = self.savenextthink - time;
7 SUB_SetFade(self, self.savenextthink - 1, 1);
9 SUB_SetFade(self, time, timeleft);
11 SUB_VanishOrRemove(self);
14 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
15 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
18 float wa, thisammo, i, j;
25 wep.classname = "droppedweapon";
27 wep.owner = wep.enemy = own;
28 wep.flags |= FL_TOSSED;
29 wep.colormap = own.colormap;
31 if(WEPSET_CONTAINS_AW(WEPBIT_SUPERWEAPONS, wpn))
33 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
35 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
39 float superweapons = 1;
40 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
41 if(WEPSET_CONTAINS_AW(WEPBIT_SUPERWEAPONS, i))
42 if(WEPSET_CONTAINS_EW(own, i))
46 wep.superweapons_finished = own.superweapons_finished;
47 own.superweapons_finished = 0;
51 float timeleft = own.superweapons_finished - time;
52 float weptimeleft = timeleft / superweapons;
53 wep.superweapons_finished = time + weptimeleft;
54 own.superweapons_finished -= weptimeleft;
59 wa = W_AmmoItemCode(wpn);
64 weapon_defaultspawnfunc(wpn);
68 wep.glowmod = own.weaponentity_glowmod;
69 wep.think = thrown_wep_think;
70 wep.savenextthink = wep.nextthink;
71 wep.nextthink = min(wep.nextthink, time + 0.5);
72 wep.pickup_anyway = TRUE; // these are ALWAYS pickable
80 weapon_defaultspawnfunc(wpn);
84 if(doreduce && g_weapon_stay == 2)
86 for(i = 0, j = 1; i < 24; ++i, j *= 2)
90 ammofield = Item_CounterField(j);
92 // if our weapon is loaded, give its load back to the player
93 if(self.(weapon_load[self.weapon]) > 0)
95 own.ammofield += self.(weapon_load[self.weapon]);
96 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
105 for(i = 0, j = 1; i < 24; ++i, j *= 2)
109 ammofield = Item_CounterField(j);
111 // if our weapon is loaded, give its load back to the player
112 if(self.(weapon_load[self.weapon]) > 0)
114 own.ammofield += self.(weapon_load[self.weapon]);
115 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
118 thisammo = min(own.ammofield, wep.ammofield);
119 wep.ammofield = thisammo;
120 own.ammofield -= thisammo;
121 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
124 s = substring(s, 5, -1);
126 wep.glowmod = own.weaponentity_glowmod;
127 wep.think = thrown_wep_think;
128 wep.savenextthink = wep.nextthink;
129 wep.nextthink = min(wep.nextthink, time + 0.5);
130 wep.pickup_anyway = TRUE; // these are ALWAYS pickable
136 float W_IsWeaponThrowable(float w)
140 if (!autocvar_g_pickup_items)
146 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
151 wa = W_AmmoItemCode(w);
152 if(WEPSET_CONTAINS_AW(start_weapons, w))
154 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
155 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
164 // toss current weapon
165 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
172 return; // just in case
173 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
175 if(!autocvar_g_weapon_throwable)
177 if(self.weaponentity.state != WS_READY)
179 if(!W_IsWeaponThrowable(w))
182 if(!WEPSET_CONTAINS_EW(self, w))
184 WEPSET_ANDNOT_EW(self, w);
186 W_SwitchWeapon_Force(self, w_getbestweapon(self));
187 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
190 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w);