]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_grenadelauncher.qc
Merge remote-tracking branch 'origin/samual/no_dead_airshots'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_grenadelauncher.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "gl", "grenadelauncher", _("Mortar"))
3 #else
4 #ifdef SVQC
5 .float gl_detonate_later;
6 .float gl_bouncecnt;
7
8 void W_Grenade_Explode (void)
9 {
10         if(other.takedamage == DAMAGE_AIM)
11                 if(other.classname == "player")
12                         if(IsDifferentTeam(self.owner, other))
13                                 if(other.deadflag == DEAD_NO)
14                                         if(IsFlying(other))
15                                                 AnnounceTo(self.owner, "airshot");
16
17         self.event_damage = SUB_Null;
18         self.takedamage = DAMAGE_NO;
19
20         if(self.movetype == MOVETYPE_NONE)
21                 self.velocity = self.oldvelocity;
22
23         RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_primary_damage, autocvar_g_balance_grenadelauncher_primary_edgedamage, autocvar_g_balance_grenadelauncher_primary_radius, world, autocvar_g_balance_grenadelauncher_primary_force, self.projectiledeathtype, other);
24
25         remove (self);
26 }
27
28 void W_Grenade_Explode2 (void)
29 {
30         if(other.takedamage == DAMAGE_AIM)
31                 if(other.classname == "player")
32                         if(IsDifferentTeam(self.owner, other))
33                                 if(other.deadflag == DEAD_NO)
34                                         if(IsFlying(other))
35                                                 AnnounceTo(self.owner, "airshot");
36
37         self.event_damage = SUB_Null;
38         self.takedamage = DAMAGE_NO;
39
40         if(self.movetype == MOVETYPE_NONE)
41                 self.velocity = self.oldvelocity;
42
43         RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_secondary_damage, autocvar_g_balance_grenadelauncher_secondary_edgedamage, autocvar_g_balance_grenadelauncher_secondary_radius, world, autocvar_g_balance_grenadelauncher_secondary_force, self.projectiledeathtype, other);
44
45         remove (self);
46 }
47
48 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
49 {
50         if (self.health <= 0)
51                 return;
52         self.health = self.health - damage;
53         if (self.health <= 0)
54         {
55                 W_PrepareExplosionByDamage(attacker, self.think);
56         }
57 }
58
59 void W_Grenade_Think1 (void)
60 {
61         self.nextthink = time;
62         if (time > self.cnt)
63         {
64                 other = world;
65                 self.projectiledeathtype |= HITTYPE_BOUNCE;
66                 W_Grenade_Explode ();
67                 return;
68         }
69         if(self.gl_detonate_later && self.gl_bouncecnt >= autocvar_g_balance_grenadelauncher_primary_remote_minbouncecnt)
70                 W_Grenade_Explode();
71 }
72
73 void W_Grenade_Touch1 (void)
74 {
75         PROJECTILE_TOUCH;
76         if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_primary_type == 0) // always explode when hitting a player, or if normal mortar projectile
77         {
78                 self.use ();
79         }
80         else if (autocvar_g_balance_grenadelauncher_primary_type == 1) // bounce
81         {
82                 float r;
83                 r = random() * 6;
84                 if(r < 1)
85                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
86                 else if(r < 2)
87                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
88                 else if(r < 3)
89                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
90                 else if(r < 4)
91                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
92                 else if(r < 5)
93                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
94                 else
95                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
96                 self.projectiledeathtype |= HITTYPE_BOUNCE;
97                 self.gl_bouncecnt += 1;
98         }
99         else if(autocvar_g_balance_grenadelauncher_primary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
100         {
101                 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
102
103                 // let it stick whereever it is
104                 self.oldvelocity = self.velocity;
105                 self.velocity = '0 0 0';
106                 self.movetype = MOVETYPE_NONE; // also disables gravity
107                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
108                 UpdateCSQCProjectile(self);
109
110                 // do not respond to any more touches
111                 self.solid = SOLID_NOT;
112
113                 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_primary_lifetime2);
114         }
115 }
116
117 void W_Grenade_Touch2 (void)
118 {
119         PROJECTILE_TOUCH;
120         if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_secondary_type == 0) // always explode when hitting a player, or if normal mortar projectile
121         {
122                 self.use ();
123         }
124         else if (autocvar_g_balance_grenadelauncher_secondary_type == 1) // bounce
125         {
126                 float r;
127                 r = random() * 6;
128                 if(r < 1)
129                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
130                 else if(r < 2)
131                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
132                 else if(r < 3)
133                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
134                 else if(r < 4)
135                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
136                 else if(r < 5)
137                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
138                 else
139                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
140                 self.projectiledeathtype |= HITTYPE_BOUNCE;
141                 self.gl_bouncecnt += 1;
142         }
143         else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
144         {
145                 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
146
147                 // let it stick whereever it is
148                 self.oldvelocity = self.velocity;
149                 self.velocity = '0 0 0';
150                 self.movetype = MOVETYPE_NONE; // also disables gravity
151                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
152                 UpdateCSQCProjectile(self);
153
154                 // do not respond to any more touches
155                 self.solid = SOLID_NOT;
156
157                 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime2);
158         }
159 }
160
161 void W_Grenade_Attack (void)
162 {
163         local entity gren;
164
165         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
166
167         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_primary_damage);
168         w_shotdir = v_forward; // no TrueAim for grenades please
169
170         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
171
172         gren = spawn ();
173         gren.owner = self;
174         gren.classname = "grenade";
175         gren.bot_dodge = TRUE;
176         gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
177         gren.movetype = MOVETYPE_BOUNCE;
178         gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
179         gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
180         PROJECTILE_MAKETRIGGER(gren);
181         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
182         setorigin(gren, w_shotorg);
183         setsize(gren, '-3 -3 -3', '3 3 3');
184
185         gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
186         gren.nextthink = time;
187         gren.think = W_Grenade_Think1;
188         gren.use = W_Grenade_Explode;
189         gren.touch = W_Grenade_Touch1;
190
191         gren.takedamage = DAMAGE_YES;
192         gren.health = autocvar_g_balance_grenadelauncher_primary_health;
193         gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
194         gren.event_damage = W_Grenade_Damage;
195         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
196
197         gren.angles = vectoangles (gren.velocity);
198         gren.flags = FL_PROJECTILE;
199
200         if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
201                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
202         else
203                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
204
205         other = gren; MUTATOR_CALLHOOK(EditProjectile);
206 }
207
208 void W_Grenade_Attack2 (void)
209 {
210         local entity gren;
211
212         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_secondary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
213
214         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_secondary_damage);
215         w_shotdir = v_forward; // no TrueAim for grenades please
216
217         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
218
219         gren = spawn ();
220         gren.owner = self;
221         gren.classname = "grenade";
222         gren.bot_dodge = TRUE;
223         gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
224         gren.movetype = MOVETYPE_BOUNCE;
225         gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
226         gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
227         PROJECTILE_MAKETRIGGER(gren);
228         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
229         setorigin(gren, w_shotorg);
230         setsize(gren, '-3 -3 -3', '3 3 3');
231
232         gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
233         gren.think = adaptor_think2use_hittype_splash;
234         gren.use = W_Grenade_Explode2;
235         gren.touch = W_Grenade_Touch2;
236
237         gren.takedamage = DAMAGE_YES;
238         gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
239         gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
240         gren.event_damage = W_Grenade_Damage;
241         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
242
243         gren.angles = vectoangles (gren.velocity);
244         gren.flags = FL_PROJECTILE;
245
246         if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
247                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
248         else
249                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
250
251         other = gren; MUTATOR_CALLHOOK(EditProjectile);
252 }
253
254 void spawnfunc_weapon_grenadelauncher (void)
255 {
256         weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
257 }
258
259 .float bot_secondary_grenademooth;
260 float w_glauncher(float req)
261 {
262         entity nade;
263         float nadefound;
264         float ammo_amount;
265
266         if (req == WR_AIM)
267         {
268                 self.BUTTON_ATCK = FALSE;
269                 self.BUTTON_ATCK2 = FALSE;
270                 if (self.bot_secondary_grenademooth == 0)
271                 {
272                         if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
273                         {
274                                 self.BUTTON_ATCK = TRUE;
275                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
276                         }
277                 }
278                 else
279                 {
280                         if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
281                         {
282                                 self.BUTTON_ATCK2 = TRUE;
283                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
284                         }
285                 }
286         }
287         else if (req == WR_THINK)
288         {
289                 if(autocvar_g_balance_grenadelauncher_reload_ammo && self.clip_load < min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo)) // forced reload
290                         weapon_action(self.weapon, WR_RELOAD);
291                 else if (self.BUTTON_ATCK)
292                 {
293                         if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
294                         {
295                                 W_Grenade_Attack();
296                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
297                         }
298                 }
299                 else if (self.BUTTON_ATCK2)
300                 {
301                         if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
302                         {
303                                 nadefound = 0;
304                                 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
305                                 {
306                                         if(!nade.gl_detonate_later)
307                                         {
308                                                 nade.gl_detonate_later = TRUE;
309                                                 nadefound = 1;
310                                         }
311                                 }
312                                 if(nadefound)
313                                         sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
314                         }
315                         else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
316                         {
317                                 W_Grenade_Attack2();
318                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
319                         }
320                 }
321         }
322         else if (req == WR_PRECACHE)
323         {
324                 precache_model ("models/weapons/g_gl.md3");
325                 precache_model ("models/weapons/v_gl.md3");
326                 precache_model ("models/weapons/h_gl.iqm");
327                 precache_sound ("weapons/grenade_bounce1.wav");
328                 precache_sound ("weapons/grenade_bounce2.wav");
329                 precache_sound ("weapons/grenade_bounce3.wav");
330                 precache_sound ("weapons/grenade_bounce4.wav");
331                 precache_sound ("weapons/grenade_bounce5.wav");
332                 precache_sound ("weapons/grenade_bounce6.wav");
333                 precache_sound ("weapons/grenade_stick.wav");
334                 precache_sound ("weapons/grenade_fire.wav");
335                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
336         }
337         else if (req == WR_SETUP)
338         {
339                 weapon_setup(WEP_GRENADE_LAUNCHER);
340                 self.current_ammo = ammo_rockets;
341         }
342         else if (req == WR_CHECKAMMO1)
343         {
344                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
345                 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_primary_ammo;
346                 return ammo_amount;
347         }
348         else if (req == WR_CHECKAMMO2)
349         {
350                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
351                 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_secondary_ammo;
352                 return ammo_amount;
353         }
354         else if (req == WR_RELOAD)
355         {
356                 W_Reload(min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo), autocvar_g_balance_grenadelauncher_reload_ammo, autocvar_g_balance_grenadelauncher_reload_time, "weapons/reload.wav");
357         }
358         return TRUE;
359 };
360 #endif
361 #ifdef CSQC
362 float w_glauncher(float req)
363 {
364         if(req == WR_IMPACTEFFECT)
365         {
366                 vector org2;
367                 org2 = w_org + w_backoff * 12;
368                 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
369                 if(!w_issilent)
370                         sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
371         }
372         else if(req == WR_PRECACHE)
373         {
374                 precache_sound("weapons/grenade_impact.wav");
375         }
376         else if (req == WR_SUICIDEMESSAGE)
377         {
378                 if(w_deathtype & HITTYPE_SECONDARY)
379                         w_deathtypestring = _("%s tried out his own grenade");
380                 else
381                         w_deathtypestring = _("%s detonated");
382         }
383         else if (req == WR_KILLMESSAGE)
384         {
385                 if(w_deathtype & HITTYPE_SPLASH)
386                         if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
387                                 w_deathtypestring = _("%s didn't see %s's grenade");
388                         else // unchecked: SECONDARY
389                                 w_deathtypestring = _("%s almost dodged %s's grenade");
390                 else // unchecked: SECONDARY, BOUNCE
391                         w_deathtypestring = _("%s ate %s's grenade");
392         }
393         return TRUE;
394 }
395 #endif
396 #endif