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