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 Weapon info = Weapons_from(wpn);
38 var .int ammotype = info.ammo_field;
40 entity wep = new(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(Weapons_from(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)
61 WepSet set = WepSet_FromWeapon(Weapons_from(i));
62 if ((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons;
66 wep.superweapons_finished = own.superweapons_finished;
67 own.superweapons_finished = 0;
71 float timeleft = own.superweapons_finished - time;
72 float weptimeleft = timeleft / superweapons;
73 wep.superweapons_finished = time + weptimeleft;
74 own.superweapons_finished -= weptimeleft;
79 weapon_defaultspawnfunc(wep, info);
82 wep.glowmod = own.weaponentity_glowmod;
83 wep.think = thrown_wep_think;
84 wep.savenextthink = wep.nextthink;
85 wep.nextthink = min(wep.nextthink, time + 0.5);
86 wep.pickup_anyway = true; // these are ALWAYS pickable
88 //wa = W_AmmoItemCode(wpn);
89 if(ammotype == ammo_none)
97 if(doreduce && g_weapon_stay == 2)
99 // if our weapon is loaded, give its load back to the player
100 int i = PS(self).m_weapon.m_id;
101 if(self.(weapon_load[i]) > 0)
103 own.(ammotype) += self.(weapon_load[i]);
104 self.(weapon_load[i]) = -1; // schedule the weapon for reloading
111 // if our weapon is loaded, give its load back to the player
112 int i = PS(self).m_weapon.m_id;
113 if(self.(weapon_load[i]) > 0)
115 own.(ammotype) += self.(weapon_load[i]);
116 self.(weapon_load[i]) = -1; // schedule the weapon for reloading
119 thisammo = min(own.(ammotype), wep.(ammotype));
120 wep.(ammotype) = thisammo;
121 own.(ammotype) -= thisammo;
125 case ammo_shells: s = sprintf("%s and %d shells", s, thisammo); break;
126 case ammo_nails: s = sprintf("%s and %d nails", s, thisammo); break;
127 case ammo_rockets: s = sprintf("%s and %d rockets", s, thisammo); break;
128 case ammo_cells: s = sprintf("%s and %d cells", s, thisammo); break;
129 case ammo_plasma: s = sprintf("%s and %d plasma", s, thisammo); break;
130 case ammo_fuel: s = sprintf("%s and %d fuel", s, thisammo); break;
133 s = substring(s, 5, -1);
139 bool W_IsWeaponThrowable(bool w)
141 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon))
143 if (!autocvar_g_pickup_items)
149 if(w == WEP_Null.m_id)
153 if(start_weapons & WepSet_FromWeapon(Weapons_from(w)))
155 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
156 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
158 if((Weapons_from(w)).ammo_field == ammo_none)
163 return (Weapons_from(w)).weaponthrowable;
167 // toss current weapon
168 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
170 Weapon w = PS(self).m_weapon;
172 return; // just in case
173 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
175 if(!autocvar_g_weapon_throwable)
177 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
178 if(self.(weaponentity).state != WS_READY)
180 if(!W_IsWeaponThrowable(w.m_id))
183 WepSet set = WepSet_FromWeapon(w);
184 if(!(self.weapons & set)) return;
185 self.weapons &= ~set;
187 W_SwitchWeapon_Force(self, w_getbestweapon(self));
188 string a = W_ThrowNewWeapon(self, w.m_id, doreduce, self.origin + delta, velo);
191 Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id);
194 void SpawnThrownWeapon(vector org, float w)
196 if(self.weapons & WepSet_FromWeapon(PS(self).m_weapon))
197 if(W_IsWeaponThrowable(PS(self).m_weapon.m_id))
198 W_ThrowNewWeapon(self, PS(self).m_weapon.m_id, false, org, randomvec() * 125 + '0 0 200');