1 void thrown_wep_think()
4 if(self.oldorigin != self.origin)
6 self.SendFlags |= ISF_LOCATION;
7 self.oldorigin = self.origin;
10 float timeleft = self.savenextthink - time;
12 SUB_SetFade(self, self.savenextthink - 1, 1);
14 SUB_SetFade(self, time, timeleft);
16 SUB_VanishOrRemove(self);
19 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
20 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
23 float wa, thisammo, i, j;
30 wep.classname = "droppedweapon";
32 wep.owner = wep.enemy = own;
33 wep.flags |= FL_TOSSED;
34 wep.colormap = own.colormap;
36 if(WepSet_FromWeapon(wpn) & WEPSET_SUPERWEAPONS)
38 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
40 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
44 float superweapons = 1;
45 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
46 if(WepSet_FromWeapon(i) & WEPSET_SUPERWEAPONS)
47 if(own.weapons & WepSet_FromWeapon(i))
51 wep.superweapons_finished = own.superweapons_finished;
52 own.superweapons_finished = 0;
56 float timeleft = own.superweapons_finished - time;
57 float weptimeleft = timeleft / superweapons;
58 wep.superweapons_finished = time + weptimeleft;
59 own.superweapons_finished -= weptimeleft;
64 wa = W_AmmoItemCode(wpn);
69 weapon_defaultspawnfunc(wpn);
73 wep.glowmod = own.weaponentity_glowmod;
74 wep.think = thrown_wep_think;
75 wep.savenextthink = wep.nextthink;
76 wep.nextthink = min(wep.nextthink, time + 0.5);
77 wep.pickup_anyway = TRUE; // these are ALWAYS pickable
85 weapon_defaultspawnfunc(wpn);
89 if(doreduce && g_weapon_stay == 2)
91 for(i = 0, j = 1; i < 24; ++i, j *= 2)
95 ammofield = Item_CounterField(j);
97 // if our weapon is loaded, give its load back to the player
98 if(self.(weapon_load[self.weapon]) > 0)
100 own.ammofield += self.(weapon_load[self.weapon]);
101 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
110 for(i = 0, j = 1; i < 24; ++i, j *= 2)
114 ammofield = Item_CounterField(j);
116 // if our weapon is loaded, give its load back to the player
117 if(self.(weapon_load[self.weapon]) > 0)
119 own.ammofield += self.(weapon_load[self.weapon]);
120 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
123 thisammo = min(own.ammofield, wep.ammofield);
124 wep.ammofield = thisammo;
125 own.ammofield -= thisammo;
126 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
129 s = substring(s, 5, -1);
131 wep.glowmod = own.weaponentity_glowmod;
132 wep.think = thrown_wep_think;
133 wep.savenextthink = wep.nextthink;
134 wep.nextthink = min(wep.nextthink, time + 0.5);
135 wep.pickup_anyway = TRUE; // these are ALWAYS pickable
141 float W_IsWeaponThrowable(float w)
145 if (!autocvar_g_pickup_items)
151 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
156 wa = W_AmmoItemCode(w);
157 if(start_weapons & WepSet_FromWeapon(w))
159 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
160 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
169 // toss current weapon
170 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
177 return; // just in case
178 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
180 if(!autocvar_g_weapon_throwable)
182 if(self.weaponentity.state != WS_READY)
184 if(!W_IsWeaponThrowable(w))
187 if(!(self.weapons & WepSet_FromWeapon(w)))
189 self.weapons &= ~WepSet_FromWeapon(w);
191 W_SwitchWeapon_Force(self, w_getbestweapon(self));
192 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
195 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w);