3 #include "weaponsystem.qh"
4 #include "../mutators/all.qh"
5 #include "../t_items.qh"
6 #include "../g_damage.qh"
7 #include "../../common/items/item.qh"
8 #include "../../common/mapinfo.qh"
9 #include "../../common/notifications.qh"
10 #include "../../common/triggers/subs.qh"
11 #include "../../common/util.qh"
12 #include "../../common/weapons/all.qh"
14 void thrown_wep_think()
16 self.nextthink = time;
17 if(self.oldorigin != self.origin)
19 self.SendFlags |= ISF_LOCATION;
20 self.oldorigin = self.origin;
23 float timeleft = self.savenextthink - time;
25 SUB_SetFade(self, self.savenextthink - 1, 1);
27 SUB_SetFade(self, time, timeleft);
29 SUB_VanishOrRemove(self);
32 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
33 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
37 var .int ammotype = (get_weaponinfo(wpn)).ammo_field;
42 wep.classname = "droppedweapon";
44 wep.owner = wep.enemy = own;
45 wep.flags |= FL_TOSSED;
46 wep.colormap = own.colormap;
48 W_DropEvent(wr_drop,own,wpn,wep);
50 if(WepSet_FromWeapon(wpn) & WEPSET_SUPERWEAPONS)
52 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
54 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
58 float superweapons = 1;
59 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
60 if(WepSet_FromWeapon(i) & WEPSET_SUPERWEAPONS)
61 if(own.weapons & WepSet_FromWeapon(i))
65 wep.superweapons_finished = own.superweapons_finished;
66 own.superweapons_finished = 0;
70 float timeleft = own.superweapons_finished - time;
71 float weptimeleft = timeleft / superweapons;
72 wep.superweapons_finished = time + weptimeleft;
73 own.superweapons_finished -= weptimeleft;
78 WITH(entity, self, wep, weapon_defaultspawnfunc(wpn));
81 wep.glowmod = own.weaponentity_glowmod;
82 wep.think = thrown_wep_think;
83 wep.savenextthink = wep.nextthink;
84 wep.nextthink = min(wep.nextthink, time + 0.5);
85 wep.pickup_anyway = true; // these are ALWAYS pickable
87 //wa = W_AmmoItemCode(wpn);
88 if(ammotype == ammo_none)
96 if(doreduce && g_weapon_stay == 2)
98 // if our weapon is loaded, give its load back to the player
99 if(self.(weapon_load[self.weapon]) > 0)
101 own.(ammotype) += self.(weapon_load[self.weapon]);
102 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
109 // if our weapon is loaded, give its load back to the player
110 if(self.(weapon_load[self.weapon]) > 0)
112 own.(ammotype) += self.(weapon_load[self.weapon]);
113 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
116 thisammo = min(own.(ammotype), wep.(ammotype));
117 wep.(ammotype) = thisammo;
118 own.(ammotype) -= thisammo;
122 case ammo_shells: s = sprintf("%s and %d shells", s, thisammo); break;
123 case ammo_nails: s = sprintf("%s and %d nails", s, thisammo); break;
124 case ammo_rockets: s = sprintf("%s and %d rockets", s, thisammo); break;
125 case ammo_cells: s = sprintf("%s and %d cells", s, thisammo); break;
126 case ammo_plasma: s = sprintf("%s and %d plasma", s, thisammo); break;
127 case ammo_fuel: s = sprintf("%s and %d fuel", s, thisammo); break;
130 s = substring(s, 5, -1);
136 bool W_IsWeaponThrowable(bool w)
138 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon))
140 if (!autocvar_g_pickup_items)
146 if(w == WEP_Null.m_id)
150 if(start_weapons & WepSet_FromWeapon(w))
152 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
153 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
155 if((get_weaponinfo(w)).ammo_field == ammo_none)
160 return (get_weaponinfo(w)).weaponthrowable;
164 // toss current weapon
165 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
168 if (w == WEP_Null.m_id)
169 return; // just in case
170 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
172 if(!autocvar_g_weapon_throwable)
174 int slot = 0; // TODO: unhardcode
175 if(self.weaponentity[slot].state != WS_READY)
177 if(!W_IsWeaponThrowable(w))
180 if(!(self.weapons & WepSet_FromWeapon(w)))
182 self.weapons &= ~WepSet_FromWeapon(w);
184 W_SwitchWeapon_Force(self, w_getbestweapon(self));
185 string a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
188 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w);
191 void SpawnThrownWeapon(vector org, float w)
193 if(self.weapons & WepSet_FromWeapon(self.weapon))
194 if(W_IsWeaponThrowable(self.weapon))
195 W_ThrowNewWeapon(self, self.weapon, false, org, randomvec() * 125 + '0 0 200');