4 #include "../../dpdefs/progsdefs.qh"
5 #include "../../dpdefs/dpextensions.qh"
6 #include "../../common/util.qh"
7 #include "../../common/weapons/weapons.qh"
9 #include "weaponsystem.qh"
10 #include "../t_items.qh"
11 #include "../autocvars.qh"
12 #include "../constants.qh"
14 #include "../../common/notifications.qh"
15 #include "../mutators/mutators_include.qh"
16 #include "../../common/mapinfo.qh"
19 void thrown_wep_think()
21 self.nextthink = time;
22 if(self.oldorigin != self.origin)
24 self.SendFlags |= ISF_LOCATION;
25 self.oldorigin = self.origin;
28 float timeleft = self.savenextthink - time;
30 SUB_SetFade(self, self.savenextthink - 1, 1);
32 SUB_SetFade(self, time, timeleft);
34 SUB_VanishOrRemove(self);
37 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
38 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
43 var .float ammotype = (get_weaponinfo(wpn)).ammo_field;
48 wep.classname = "droppedweapon";
50 wep.owner = wep.enemy = own;
51 wep.flags |= FL_TOSSED;
52 wep.colormap = own.colormap;
54 W_DropEvent(WR_DROP,own,wpn,wep);
56 if(WepSet_FromWeapon(wpn) & WEPSET_SUPERWEAPONS)
58 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
60 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
64 float superweapons = 1;
65 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
66 if(WepSet_FromWeapon(i) & WEPSET_SUPERWEAPONS)
67 if(own.weapons & WepSet_FromWeapon(i))
71 wep.superweapons_finished = own.superweapons_finished;
72 own.superweapons_finished = 0;
76 float timeleft = own.superweapons_finished - time;
77 float weptimeleft = timeleft / superweapons;
78 wep.superweapons_finished = time + weptimeleft;
79 own.superweapons_finished -= weptimeleft;
86 weapon_defaultspawnfunc(wpn);
90 wep.glowmod = own.weaponentity_glowmod;
91 wep.think = thrown_wep_think;
92 wep.savenextthink = wep.nextthink;
93 wep.nextthink = min(wep.nextthink, time + 0.5);
94 wep.pickup_anyway = true; // these are ALWAYS pickable
96 //wa = W_AmmoItemCode(wpn);
97 if(ammotype == ammo_none)
105 if(doreduce && g_weapon_stay == 2)
107 // if our weapon is loaded, give its load back to the player
108 if(self.(weapon_load[self.weapon]) > 0)
110 own.ammotype += self.(weapon_load[self.weapon]);
111 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
118 // if our weapon is loaded, give its load back to the player
119 if(self.(weapon_load[self.weapon]) > 0)
121 own.ammotype += self.(weapon_load[self.weapon]);
122 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
125 thisammo = min(own.ammotype, wep.ammotype);
126 wep.ammotype = thisammo;
127 own.ammotype -= thisammo;
131 case ammo_shells: s = sprintf("%s and %d shells", s, thisammo); break;
132 case ammo_nails: s = sprintf("%s and %d nails", s, thisammo); break;
133 case ammo_rockets: s = sprintf("%s and %d rockets", s, thisammo); break;
134 case ammo_cells: s = sprintf("%s and %d cells", s, thisammo); break;
135 case ammo_plasma: s = sprintf("%s and %d plasma", s, thisammo); break;
136 case ammo_fuel: s = sprintf("%s and %d fuel", s, thisammo); break;
139 s = substring(s, 5, -1);
145 float W_IsWeaponThrowable(float w)
147 if (!autocvar_g_pickup_items)
153 if (g_nexball && w == WEP_MORTAR)
159 if(start_weapons & WepSet_FromWeapon(w))
161 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
162 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
164 if((get_weaponinfo(w)).ammo_field == ammo_none)
169 return (get_weaponinfo(w)).weaponthrowable;
173 // toss current weapon
174 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
181 return; // just in case
182 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
184 if(!autocvar_g_weapon_throwable)
186 if(self.weaponentity.state != WS_READY)
188 if(!W_IsWeaponThrowable(w))
191 if(!(self.weapons & WepSet_FromWeapon(w)))
193 self.weapons &= ~WepSet_FromWeapon(w);
195 W_SwitchWeapon_Force(self, w_getbestweapon(self));
196 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
199 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w);
202 void SpawnThrownWeapon(vector org, float w)
204 if(self.weapons & WepSet_FromWeapon(self.weapon))
205 if(W_IsWeaponThrowable(self.weapon))
206 W_ThrowNewWeapon(self, self.weapon, false, org, randomvec() * 125 + '0 0 200');