]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/mortar.qc
5fbacc7ba4b958cffef6f406d7b1ce53d76853d9
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / mortar.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Mortar, Weapon)
3 /* ammotype  */ ATTRIB(Mortar, ammo_field, .int, ammo_rockets)
4 /* impulse   */ ATTRIB(Mortar, impulse, int, 4)
5 /* flags     */ ATTRIB(Mortar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
6 /* rating    */ ATTRIB(Mortar, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color     */ ATTRIB(Mortar, wpcolor, vector, '1 0 0');
8 /* modelname */ ATTRIB(Mortar, mdl, string, "gl");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(Mortar, m_model, Model, MDL_MORTAR_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(Mortar, w_crosshair, string, "gfx/crosshairgrenadelauncher");
13 /* crosshair */ ATTRIB(Mortar, w_crosshair_size, float, 0.7);
14 /* wepimg    */ ATTRIB(Mortar, model2, string, "weapongrenadelauncher");
15 /* refname   */ ATTRIB(Mortar, netname, string, "mortar");
16 /* wepname   */ ATTRIB(Mortar, m_name, string, _("Mortar"));
17
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, ammo, float, BOTH) \
21                 P(class, prefix, animtime, float, BOTH) \
22                 P(class, prefix, bouncefactor, float, NONE) \
23                 P(class, prefix, bouncestop, float, NONE) \
24                 P(class, prefix, damageforcescale, float, BOTH) \
25                 P(class, prefix, damage, float, BOTH) \
26                 P(class, prefix, edgedamage, float, BOTH) \
27                 P(class, prefix, force, float, BOTH) \
28                 P(class, prefix, health, float, BOTH) \
29                 P(class, prefix, lifetime, float, BOTH) \
30                 P(class, prefix, lifetime_bounce, float, SEC) \
31                 P(class, prefix, lifetime_stick, float, BOTH) \
32                 P(class, prefix, radius, float, BOTH) \
33                 P(class, prefix, refire, float, BOTH) \
34                 P(class, prefix, reload_ammo, float, NONE) \
35                 P(class, prefix, reload_time, float, NONE) \
36                 P(class, prefix, remote_detonateprimary, float, SEC) \
37                 P(class, prefix, remote_minbouncecnt, float, PRI) \
38                 P(class, prefix, speed, float, BOTH) \
39                 P(class, prefix, speed_up, float, BOTH) \
40                 P(class, prefix, speed_z, float, BOTH) \
41                 P(class, prefix, spread, float, BOTH) \
42                 P(class, prefix, switchdelay_drop, float, NONE) \
43                 P(class, prefix, switchdelay_raise, float, NONE) \
44                 P(class, prefix, type, float, BOTH) \
45                 P(class, prefix, weaponreplace, string, NONE) \
46                 P(class, prefix, weaponstartoverride, float, NONE) \
47                 P(class, prefix, weaponstart, float, NONE) \
48                 P(class, prefix, weaponthrowable, float, NONE) \
49         END()
50     W_PROPS(X, Mortar, mortar)
51 #undef X
52 ENDCLASS(Mortar)
53 REGISTER_WEAPON(MORTAR, mortar, NEW(Mortar));
54
55
56 #ifdef SVQC
57 .float gl_detonate_later;
58 .float gl_bouncecnt;
59 #endif
60 #endif
61 #ifdef IMPLEMENTATION
62 #ifdef SVQC
63
64 spawnfunc(weapon_mortar) { weapon_defaultspawnfunc(this, WEP_MORTAR); }
65 spawnfunc(weapon_grenadelauncher) { spawnfunc_weapon_mortar(this); }
66
67 void W_Mortar_Grenade_Explode()
68 {SELFPARAM();
69         if(other.takedamage == DAMAGE_AIM)
70                 if(IS_PLAYER(other))
71                         if(DIFF_TEAM(self.realowner, other))
72                                 if(!IS_DEAD(other))
73                                         if(IsFlying(other))
74                                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
75
76         self.event_damage = func_null;
77         self.takedamage = DAMAGE_NO;
78
79         if(self.movetype == MOVETYPE_NONE)
80                 self.velocity = self.oldvelocity;
81
82         RadiusDamage(self, self.realowner, WEP_CVAR_PRI(mortar, damage), WEP_CVAR_PRI(mortar, edgedamage), WEP_CVAR_PRI(mortar, radius), world, world, WEP_CVAR_PRI(mortar, force), self.projectiledeathtype, other);
83
84         remove(self);
85 }
86
87 void W_Mortar_Grenade_Explode_use(entity this, entity actor, entity trigger)
88 {
89         WITHSELF(this, W_Mortar_Grenade_Explode());
90 }
91
92 void W_Mortar_Grenade_Explode2()
93 {SELFPARAM();
94         if(other.takedamage == DAMAGE_AIM)
95                 if(IS_PLAYER(other))
96                         if(DIFF_TEAM(self.realowner, other))
97                                 if(!IS_DEAD(other))
98                                         if(IsFlying(other))
99                                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
100
101         self.event_damage = func_null;
102         self.takedamage = DAMAGE_NO;
103
104         if(self.movetype == MOVETYPE_NONE)
105                 self.velocity = self.oldvelocity;
106
107         RadiusDamage(self, self.realowner, WEP_CVAR_SEC(mortar, damage), WEP_CVAR_SEC(mortar, edgedamage), WEP_CVAR_SEC(mortar, radius), world, world, WEP_CVAR_SEC(mortar, force), self.projectiledeathtype, other);
108
109         remove(self);
110 }
111
112 void W_Mortar_Grenade_Explode2_use(entity this, entity actor, entity trigger)
113 {
114         WITHSELF(this, W_Mortar_Grenade_Explode2());
115 }
116
117 void W_Mortar_Grenade_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
118 {
119         if(this.health <= 0)
120                 return;
121
122         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
123                 return; // g_projectiles_damage says to halt
124
125         this.health = this.health - damage;
126
127         if(this.health <= 0)
128                 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
129 }
130
131 void W_Mortar_Grenade_Think1()
132 {SELFPARAM();
133         self.nextthink = time;
134         if(time > self.cnt)
135         {
136                 other = world;
137                 self.projectiledeathtype |= HITTYPE_BOUNCE;
138                 W_Mortar_Grenade_Explode();
139                 return;
140         }
141         if(self.gl_detonate_later && self.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
142                 W_Mortar_Grenade_Explode();
143 }
144
145 void W_Mortar_Grenade_Touch1()
146 {SELFPARAM();
147         PROJECTILE_TOUCH;
148         if(other.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
149         {
150                 this.use(this, NULL, NULL);
151         }
152         else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
153         {
154                 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
155                 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
156                 self.projectiledeathtype |= HITTYPE_BOUNCE;
157                 self.gl_bouncecnt += 1;
158         }
159         else if(WEP_CVAR_PRI(mortar, type) == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
160         {
161                 spamsound(self, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
162
163                 // let it stick whereever it is
164                 self.oldvelocity = self.velocity;
165                 self.velocity = '0 0 0';
166                 self.movetype = MOVETYPE_NONE; // also disables gravity
167                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
168                 UpdateCSQCProjectile(self);
169
170                 // do not respond to any more touches
171                 self.solid = SOLID_NOT;
172
173                 self.nextthink = min(self.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
174         }
175 }
176
177 void W_Mortar_Grenade_Touch2()
178 {SELFPARAM();
179         PROJECTILE_TOUCH;
180         if(other.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
181         {
182                 this.use(this, NULL, NULL);
183         }
184         else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
185         {
186                 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
187                 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
188                 self.projectiledeathtype |= HITTYPE_BOUNCE;
189                 self.gl_bouncecnt += 1;
190
191                 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && self.gl_bouncecnt == 1)
192                         self.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
193
194         }
195         else if(WEP_CVAR_SEC(mortar, type) == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
196         {
197                 spamsound(self, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
198
199                 // let it stick whereever it is
200                 self.oldvelocity = self.velocity;
201                 self.velocity = '0 0 0';
202                 self.movetype = MOVETYPE_NONE; // also disables gravity
203                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
204                 UpdateCSQCProjectile(self);
205
206                 // do not respond to any more touches
207                 self.solid = SOLID_NOT;
208
209                 self.nextthink = min(self.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
210         }
211 }
212
213 void W_Mortar_Attack(Weapon thiswep)
214 {SELFPARAM();
215         entity gren;
216
217         W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(mortar, ammo));
218
219         W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(mortar, damage));
220         w_shotdir = v_forward; // no TrueAim for grenades please
221
222         Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
223
224         gren = new(grenade);
225         gren.owner = gren.realowner = self;
226         gren.bot_dodge = true;
227         gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
228         gren.movetype = MOVETYPE_BOUNCE;
229         gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
230         gren.bouncestop = WEP_CVAR(mortar, bouncestop);
231         PROJECTILE_MAKETRIGGER(gren);
232         gren.projectiledeathtype = WEP_MORTAR.m_id;
233         setorigin(gren, w_shotorg);
234         setsize(gren, '-3 -3 -3', '3 3 3');
235
236         gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
237         gren.nextthink = time;
238         gren.think = W_Mortar_Grenade_Think1;
239         gren.use = W_Mortar_Grenade_Explode_use;
240         gren.touch = W_Mortar_Grenade_Touch1;
241
242         gren.takedamage = DAMAGE_YES;
243         gren.health = WEP_CVAR_PRI(mortar, health);
244         gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
245         gren.event_damage = W_Mortar_Grenade_Damage;
246         gren.damagedbycontents = true;
247         gren.missile_flags = MIF_SPLASH | MIF_ARC;
248         W_SetupProjVelocity_UP_PRI(gren, mortar);
249
250         gren.angles = vectoangles(gren.velocity);
251         gren.flags = FL_PROJECTILE;
252
253         if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
254                 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
255         else
256                 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
257
258         MUTATOR_CALLHOOK(EditProjectile, self, gren);
259 }
260
261 void W_Mortar_Attack2(Weapon thiswep)
262 {SELFPARAM();
263         entity gren;
264
265         W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(mortar, ammo));
266
267         W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(mortar, damage));
268         w_shotdir = v_forward; // no TrueAim for grenades please
269
270         Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
271
272         gren = new(grenade);
273         gren.owner = gren.realowner = self;
274         gren.bot_dodge = true;
275         gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
276         gren.movetype = MOVETYPE_BOUNCE;
277         gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
278         gren.bouncestop = WEP_CVAR(mortar, bouncestop);
279         PROJECTILE_MAKETRIGGER(gren);
280         gren.projectiledeathtype = WEP_MORTAR.m_id | HITTYPE_SECONDARY;
281         setorigin(gren, w_shotorg);
282         setsize(gren, '-3 -3 -3', '3 3 3');
283
284         gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
285         gren.think = adaptor_think2use_hittype_splash;
286         gren.use = W_Mortar_Grenade_Explode2_use;
287         gren.touch = W_Mortar_Grenade_Touch2;
288
289         gren.takedamage = DAMAGE_YES;
290         gren.health = WEP_CVAR_SEC(mortar, health);
291         gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
292         gren.event_damage = W_Mortar_Grenade_Damage;
293         gren.damagedbycontents = true;
294         gren.missile_flags = MIF_SPLASH | MIF_ARC;
295         W_SetupProjVelocity_UP_SEC(gren, mortar);
296
297         gren.angles = vectoangles(gren.velocity);
298         gren.flags = FL_PROJECTILE;
299
300         if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
301                 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
302         else
303                 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
304
305         MUTATOR_CALLHOOK(EditProjectile, self, gren);
306 }
307
308 .float bot_secondary_grenademooth;
309
310 METHOD(Mortar, wr_aim, void(entity thiswep))
311 {
312     SELFPARAM();
313     PHYS_INPUT_BUTTON_ATCK(self) = false;
314     PHYS_INPUT_BUTTON_ATCK2(self) = false;
315     if(self.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
316     {
317         if(bot_aim(self, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
318         {
319             PHYS_INPUT_BUTTON_ATCK(self) = true;
320             if(random() < 0.01) self.bot_secondary_grenademooth = 1;
321         }
322     }
323     else
324     {
325         if(bot_aim(self, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
326         {
327             PHYS_INPUT_BUTTON_ATCK2(self) = true;
328             if(random() < 0.02) self.bot_secondary_grenademooth = 0;
329         }
330     }
331 }
332 /*case WR_CALCINFO:
333 {
334     wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
335     wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
336     wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
337
338     // for the range calculation, closer to 1 is better
339     wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
340     wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
341
342     wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
343     wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
344
345     wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
346     wepinfo_ter_dps = 0;
347     */
348 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
349 {
350     if(autocvar_g_balance_mortar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
351         thiswep.wr_reload(thiswep, actor, weaponentity);
352     } else if(fire & 1)
353     {
354         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
355         {
356             W_Mortar_Attack(thiswep);
357             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
358         }
359     }
360     else if(fire & 2)
361     {
362         if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
363         {
364             bool nadefound = false;
365             entity nade;
366             for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.realowner == actor)
367             {
368                 if(!nade.gl_detonate_later)
369                 {
370                     nade.gl_detonate_later = true;
371                     nadefound = true;
372                 }
373             }
374             if(nadefound)
375                 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
376         }
377         else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
378         {
379             W_Mortar_Attack2(thiswep);
380             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
381         }
382     }
383 }
384 METHOD(Mortar, wr_checkammo1, bool(entity thiswep))
385 {
386     SELFPARAM();
387     float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_PRI(mortar, ammo);
388     ammo_amount += self.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
389     return ammo_amount;
390 }
391 METHOD(Mortar, wr_checkammo2, bool(entity thiswep))
392 {
393     SELFPARAM();
394     float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_SEC(mortar, ammo);
395     ammo_amount += self.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
396     return ammo_amount;
397 }
398 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
399 {
400     SELFPARAM();
401     W_Reload(self, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
402 }
403 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
404 {
405     if(w_deathtype & HITTYPE_SECONDARY)
406         return WEAPON_MORTAR_SUICIDE_BOUNCE;
407     else
408         return WEAPON_MORTAR_SUICIDE_EXPLODE;
409 }
410 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
411 {
412     if(w_deathtype & HITTYPE_SECONDARY)
413         return WEAPON_MORTAR_MURDER_BOUNCE;
414     else
415         return WEAPON_MORTAR_MURDER_EXPLODE;
416 }
417
418 #endif
419 #ifdef CSQC
420
421 METHOD(Mortar, wr_impacteffect, void(entity thiswep))
422 {
423     SELFPARAM();
424     vector org2;
425     org2 = w_org + w_backoff * 12;
426     pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
427     if(!w_issilent)
428         sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);
429 }
430
431 #endif
432 #endif