3 #include "weaponsystem.qh"
4 #include "../resources.qh"
6 #include "../mutators/_mod.qh"
7 #include <common/t_items.qh>
8 #include "../g_damage.qh"
9 #include <common/items/item.qh>
10 #include <common/mapinfo.qh>
11 #include <common/notifications/all.qh>
12 #include <common/triggers/subs.qh>
13 #include <common/util.qh>
14 #include <common/weapons/_all.qh>
15 #include <common/state.qh>
16 #include <common/wepent.qh>
18 void thrown_wep_think(entity this)
20 this.nextthink = time;
21 if(this.oldorigin != this.origin)
23 this.SendFlags |= ISF_LOCATION;
24 this.oldorigin = this.origin;
27 float timeleft = this.savenextthink - time;
29 SUB_SetFade(this, this.savenextthink - 1, 1);
31 SUB_SetFade(this, time, timeleft);
33 SUB_VanishOrRemove(this);
36 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
37 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity)
41 Weapon info = Weapons_from(wpn);
42 int ammotype = info.ammo_type;
44 entity wep = new(droppedweapon);
45 Item_SetLoot(wep, true);
48 wep.owner = wep.enemy = own;
49 wep.flags |= FL_TOSSED;
50 wep.colormap = own.colormap;
51 wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors, own.(weaponentity));
52 navigation_dynamicgoal_init(wep, false);
54 W_DropEvent(wr_drop,own,wpn,wep,weaponentity);
56 if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS)
58 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
60 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
65 FOREACH(Weapons, it != WEP_Null, {
66 WepSet set = it.m_wepset;
67 if((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons;
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;
84 weapon_defaultspawnfunc(wep, info);
87 setthink(wep, thrown_wep_think);
88 wep.savenextthink = wep.nextthink;
89 wep.nextthink = min(wep.nextthink, time + 0.5);
90 wep.pickup_anyway = true; // these are ALWAYS pickable
92 //wa = W_AmmoItemCode(wpn);
93 if(ammotype == RESOURCE_NONE)
101 if(doreduce && g_weapon_stay == 2)
103 // if our weapon is loaded, give its load back to the player
104 int i = own.(weaponentity).m_weapon.m_id;
105 if(own.(weaponentity).(weapon_load[i]) > 0)
107 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
108 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
110 SetResourceAmount(wep, ammotype, 0);
114 // if our weapon is loaded, give its load back to the player
115 int i = own.(weaponentity).m_weapon.m_id;
116 if(own.(weaponentity).(weapon_load[i]) > 0)
118 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
119 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
122 float ownderammo = GetResourceAmount(own, ammotype);
123 thisammo = min(ownderammo, GetResourceAmount(wep, ammotype));
124 SetResourceAmount(wep, ammotype, thisammo);
125 SetResourceAmount(own, ammotype, ownderammo - thisammo);
129 case RESOURCE_SHELLS: s = sprintf("%s and %d shells", s, thisammo); break;
130 case RESOURCE_BULLETS: s = sprintf("%s and %d nails", s, thisammo); break;
131 case RESOURCE_ROCKETS: s = sprintf("%s and %d rockets", s, thisammo); break;
132 case RESOURCE_CELLS: s = sprintf("%s and %d cells", s, thisammo); break;
133 case RESOURCE_PLASMA: s = sprintf("%s and %d plasma", s, thisammo); break;
134 case RESOURCE_FUEL: s = sprintf("%s and %d fuel", s, thisammo); break;
137 s = substring(s, 5, -1);
143 bool W_IsWeaponThrowable(entity this, int w)
145 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
147 if (!autocvar_g_pickup_items)
151 if(w == WEP_Null.m_id)
155 if(start_weapons & WepSet_FromWeapon(Weapons_from(w)))
157 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
158 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
160 if((Weapons_from(w)).ammo_type == RESOURCE_NONE)
165 return (Weapons_from(w)).weaponthrowable;
169 // toss current weapon
170 void W_ThrowWeapon(entity this, .entity weaponentity, vector velo, vector delta, float doreduce)
172 Weapon w = this.(weaponentity).m_weapon;
174 return; // just in case
175 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this, this.(weaponentity)))
177 if(!autocvar_g_weapon_throwable)
179 if(this.(weaponentity).state != WS_READY)
181 if(!W_IsWeaponThrowable(this, w.m_id))
184 WepSet set = WepSet_FromWeapon(w);
185 if(!(this.weapons & set)) return;
186 this.weapons &= ~set;
188 W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity);
189 string a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity);
192 Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id);
195 void SpawnThrownWeapon(entity this, vector org, Weapon wep, .entity weaponentity)
197 //entity wep = this.(weaponentity).m_weapon;
199 if(this.weapons & WepSet_FromWeapon(wep))
200 if(W_IsWeaponThrowable(this, wep.m_id))
201 W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);