3 #include "weaponsystem.qh"
4 #include "../resources.qh"
5 #include "../mutators/_mod.qh"
6 #include <common/t_items.qh>
7 #include "../g_damage.qh"
8 #include <common/items/item.qh>
9 #include <common/mapinfo.qh>
10 #include <common/notifications/all.qh>
11 #include <common/triggers/subs.qh>
12 #include <common/util.qh>
13 #include <common/weapons/_all.qh>
14 #include <common/state.qh>
15 #include <common/wepent.qh>
17 void thrown_wep_think(entity this)
19 this.nextthink = time;
20 if(this.oldorigin != this.origin)
22 this.SendFlags |= ISF_LOCATION;
23 this.oldorigin = this.origin;
26 float timeleft = this.savenextthink - time;
28 SUB_SetFade(this, this.savenextthink - 1, 1);
30 SUB_SetFade(this, time, timeleft);
32 SUB_VanishOrRemove(this);
35 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
36 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity)
40 Weapon info = Weapons_from(wpn);
41 int ammotype = info.ammo_type;
43 entity wep = new(droppedweapon);
47 wep.owner = wep.enemy = own;
48 wep.flags |= FL_TOSSED;
49 wep.colormap = own.colormap;
50 wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors, own.(weaponentity));
51 navigation_dynamicgoal_init(wep, false);
53 W_DropEvent(wr_drop,own,wpn,wep,weaponentity);
55 if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS)
57 if(own.items & IT_UNLIMITED_SUPERWEAPONS)
59 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
64 FOREACH(Weapons, it != WEP_Null, {
65 WepSet set = it.m_wepset;
66 if((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons;
70 wep.superweapons_finished = own.superweapons_finished;
71 own.superweapons_finished = 0;
75 float timeleft = own.superweapons_finished - time;
76 float weptimeleft = timeleft / superweapons;
77 wep.superweapons_finished = time + weptimeleft;
78 own.superweapons_finished -= weptimeleft;
83 weapon_defaultspawnfunc(wep, info);
86 setthink(wep, thrown_wep_think);
87 wep.savenextthink = wep.nextthink;
88 wep.nextthink = min(wep.nextthink, time + 0.5);
89 wep.pickup_anyway = true; // these are ALWAYS pickable
91 //wa = W_AmmoItemCode(wpn);
92 if(ammotype == RESOURCE_NONE)
100 if(doreduce && g_weapon_stay == 2)
102 // if our weapon is loaded, give its load back to the player
103 int i = own.(weaponentity).m_weapon.m_id;
104 if(own.(weaponentity).(weapon_load[i]) > 0)
106 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
107 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
109 SetResourceAmount(wep, ammotype, 0);
113 // if our weapon is loaded, give its load back to the player
114 int i = own.(weaponentity).m_weapon.m_id;
115 if(own.(weaponentity).(weapon_load[i]) > 0)
117 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
118 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
121 float ownderammo = GetResourceAmount(own, ammotype);
122 thisammo = min(ownderammo, GetResourceAmount(wep, ammotype));
123 SetResourceAmount(wep, ammotype, thisammo);
124 SetResourceAmount(own, ammotype, ownderammo - thisammo);
128 case RESOURCE_SHELLS: s = sprintf("%s and %d shells", s, thisammo); break;
129 case RESOURCE_BULLETS: s = sprintf("%s and %d nails", s, thisammo); break;
130 case RESOURCE_ROCKETS: s = sprintf("%s and %d rockets", s, thisammo); break;
131 case RESOURCE_CELLS: s = sprintf("%s and %d cells", s, thisammo); break;
132 case RESOURCE_PLASMA: s = sprintf("%s and %d plasma", s, thisammo); break;
133 case RESOURCE_FUEL: s = sprintf("%s and %d fuel", s, thisammo); break;
136 s = substring(s, 5, -1);
142 bool W_IsWeaponThrowable(entity this, int w)
144 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
146 if (!autocvar_g_pickup_items)
150 if(w == WEP_Null.m_id)
154 if(start_weapons & WepSet_FromWeapon(Weapons_from(w)))
156 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
157 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
159 if((Weapons_from(w)).ammo_type == RESOURCE_NONE)
164 return (Weapons_from(w)).weaponthrowable;
168 // toss current weapon
169 void W_ThrowWeapon(entity this, .entity weaponentity, vector velo, vector delta, float doreduce)
171 Weapon w = this.(weaponentity).m_weapon;
173 return; // just in case
174 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this, this.(weaponentity)))
176 if(!autocvar_g_weapon_throwable)
178 if(this.(weaponentity).state != WS_READY)
180 if(!W_IsWeaponThrowable(this, w.m_id))
183 WepSet set = WepSet_FromWeapon(w);
184 if(!(this.weapons & set)) return;
185 this.weapons &= ~set;
187 W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity);
188 string a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity);
191 Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id);
194 void SpawnThrownWeapon(entity this, vector org, Weapon wep, .entity weaponentity)
196 //entity wep = this.(weaponentity).m_weapon;
198 if(this.weapons & WepSet_FromWeapon(wep))
199 if(W_IsWeaponThrowable(this, wep.m_id))
200 W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);