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