]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/mortar.qc
61fa98b4b5544df6233fd595973be9e35b957f9e
[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(entity this, entity directhitentity)
68 {
69         if(directhitentity.takedamage == DAMAGE_AIM)
70                 if(IS_PLAYER(directhitentity))
71                         if(DIFF_TEAM(this.realowner, directhitentity))
72                                 if(!IS_DEAD(directhitentity))
73                                         if(IsFlying(directhitentity))
74                                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
75
76         this.event_damage = func_null;
77         this.takedamage = DAMAGE_NO;
78
79         if(this.move_movetype == MOVETYPE_NONE)
80                 this.velocity = this.oldvelocity;
81
82         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);
83
84         delete(this);
85 }
86
87 void W_Mortar_Grenade_Explode_use(entity this, entity actor, entity trigger)
88 {
89         W_Mortar_Grenade_Explode(this, trigger);
90 }
91
92 void W_Mortar_Grenade_Explode2(entity this, entity directhitentity)
93 {
94         if(directhitentity.takedamage == DAMAGE_AIM)
95                 if(IS_PLAYER(directhitentity))
96                         if(DIFF_TEAM(this.realowner, directhitentity))
97                                 if(!IS_DEAD(directhitentity))
98                                         if(IsFlying(directhitentity))
99                                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
100
101         this.event_damage = func_null;
102         this.takedamage = DAMAGE_NO;
103
104         if(this.move_movetype == MOVETYPE_NONE)
105                 this.velocity = this.oldvelocity;
106
107         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);
108
109         delete(this);
110 }
111
112 void W_Mortar_Grenade_Explode2_use(entity this, entity actor, entity trigger)
113 {
114         W_Mortar_Grenade_Explode2(this, trigger);
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(entity this)
132 {
133         this.nextthink = time;
134         if(time > this.cnt)
135         {
136                 this.projectiledeathtype |= HITTYPE_BOUNCE;
137                 W_Mortar_Grenade_Explode(this, NULL);
138                 return;
139         }
140         if(this.gl_detonate_later && this.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
141                 W_Mortar_Grenade_Explode(this, NULL);
142 }
143
144 void W_Mortar_Grenade_Touch1(entity this, entity toucher)
145 {
146         PROJECTILE_TOUCH(this, toucher);
147         if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
148         {
149                 this.use(this, NULL, toucher);
150         }
151         else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
152         {
153                 spamsound(this, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
154                 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
155                 this.projectiledeathtype |= HITTYPE_BOUNCE;
156                 this.gl_bouncecnt += 1;
157         }
158         else if(WEP_CVAR_PRI(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
159         {
160                 spamsound(this, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
161
162                 // let it stick whereever it is
163                 this.oldvelocity = this.velocity;
164                 this.velocity = '0 0 0';
165                 set_movetype(this, MOVETYPE_NONE); // also disables gravity
166                 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
167                 UpdateCSQCProjectile(this);
168
169                 // do not respond to any more touches
170                 this.solid = SOLID_NOT;
171
172                 this.nextthink = min(this.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
173         }
174 }
175
176 void W_Mortar_Grenade_Touch2(entity this, entity toucher)
177 {
178         PROJECTILE_TOUCH(this, toucher);
179         if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
180         {
181                 this.use(this, NULL, toucher);
182         }
183         else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
184         {
185                 spamsound(this, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
186                 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
187                 this.projectiledeathtype |= HITTYPE_BOUNCE;
188                 this.gl_bouncecnt += 1;
189
190                 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && this.gl_bouncecnt == 1)
191                         this.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
192
193         }
194         else if(WEP_CVAR_SEC(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
195         {
196                 spamsound(this, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
197
198                 // let it stick whereever it is
199                 this.oldvelocity = this.velocity;
200                 this.velocity = '0 0 0';
201                 set_movetype(this, MOVETYPE_NONE); // also disables gravity
202                 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
203                 UpdateCSQCProjectile(this);
204
205                 // do not respond to any more touches
206                 this.solid = SOLID_NOT;
207
208                 this.nextthink = min(this.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
209         }
210 }
211
212 void W_Mortar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
213 {
214         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(mortar, ammo));
215
216         W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(mortar, damage));
217         w_shotdir = v_forward; // no TrueAim for grenades please
218
219         Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
220
221         entity gren = new(grenade);
222         gren.owner = gren.realowner = actor;
223         gren.bot_dodge = true;
224         gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
225         set_movetype(gren, MOVETYPE_BOUNCE);
226         gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
227         gren.bouncestop = WEP_CVAR(mortar, bouncestop);
228         PROJECTILE_MAKETRIGGER(gren);
229         gren.projectiledeathtype = WEP_MORTAR.m_id;
230         setorigin(gren, w_shotorg);
231         setsize(gren, '-3 -3 -3', '3 3 3');
232
233         gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
234         gren.nextthink = time;
235         setthink(gren, W_Mortar_Grenade_Think1);
236         gren.use = W_Mortar_Grenade_Explode_use;
237         settouch(gren, W_Mortar_Grenade_Touch1);
238
239         gren.takedamage = DAMAGE_YES;
240         gren.health = WEP_CVAR_PRI(mortar, health);
241         gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
242         gren.event_damage = W_Mortar_Grenade_Damage;
243         gren.damagedbycontents = true;
244         gren.missile_flags = MIF_SPLASH | MIF_ARC;
245         W_SetupProjVelocity_UP_PRI(gren, mortar);
246
247         gren.angles = vectoangles(gren.velocity);
248         gren.flags = FL_PROJECTILE;
249         IL_PUSH(g_projectiles, gren);
250
251         if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
252                 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
253         else
254                 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
255
256         MUTATOR_CALLHOOK(EditProjectile, actor, gren);
257 }
258
259 void W_Mortar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
260 {
261         entity gren;
262
263         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(mortar, ammo));
264
265         W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(mortar, damage));
266         w_shotdir = v_forward; // no TrueAim for grenades please
267
268         Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
269
270         gren = new(grenade);
271         gren.owner = gren.realowner = actor;
272         gren.bot_dodge = true;
273         gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
274         set_movetype(gren, MOVETYPE_BOUNCE);
275         gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
276         gren.bouncestop = WEP_CVAR(mortar, bouncestop);
277         PROJECTILE_MAKETRIGGER(gren);
278         gren.projectiledeathtype = WEP_MORTAR.m_id | HITTYPE_SECONDARY;
279         setorigin(gren, w_shotorg);
280         setsize(gren, '-3 -3 -3', '3 3 3');
281
282         gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
283         setthink(gren, adaptor_think2use_hittype_splash);
284         gren.use = W_Mortar_Grenade_Explode2_use;
285         settouch(gren, W_Mortar_Grenade_Touch2);
286
287         gren.takedamage = DAMAGE_YES;
288         gren.health = WEP_CVAR_SEC(mortar, health);
289         gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
290         gren.event_damage = W_Mortar_Grenade_Damage;
291         gren.damagedbycontents = true;
292         gren.missile_flags = MIF_SPLASH | MIF_ARC;
293         W_SetupProjVelocity_UP_SEC(gren, mortar);
294
295         gren.angles = vectoangles(gren.velocity);
296         gren.flags = FL_PROJECTILE;
297         IL_PUSH(g_projectiles, gren);
298
299         if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
300                 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
301         else
302                 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
303
304         MUTATOR_CALLHOOK(EditProjectile, actor, gren);
305 }
306
307 .float bot_secondary_grenademooth;
308
309 METHOD(Mortar, wr_aim, void(entity thiswep, entity actor))
310 {
311     PHYS_INPUT_BUTTON_ATCK(actor) = false;
312     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
313     if(actor.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
314     {
315         if(bot_aim(actor, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
316         {
317             PHYS_INPUT_BUTTON_ATCK(actor) = true;
318             if(random() < 0.01) actor.bot_secondary_grenademooth = 1;
319         }
320     }
321     else
322     {
323         if(bot_aim(actor, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
324         {
325             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
326             if(random() < 0.02) actor.bot_secondary_grenademooth = 0;
327         }
328     }
329 }
330 /*case WR_CALCINFO:
331 {
332     wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
333     wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
334     wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
335
336     // for the range calculation, closer to 1 is better
337     wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
338     wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
339
340     wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
341     wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
342
343     wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
344     wepinfo_ter_dps = 0;
345     */
346 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
347 {
348     if(autocvar_g_balance_mortar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
349         thiswep.wr_reload(thiswep, actor, weaponentity);
350     } else if(fire & 1)
351     {
352         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
353         {
354             W_Mortar_Attack(thiswep, actor, weaponentity);
355             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
356         }
357     }
358     else if(fire & 2)
359     {
360         if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
361         {
362             bool nadefound = false;
363             entity nade;
364             for(nade = NULL; (nade = find(nade, classname, "grenade")); ) if(nade.realowner == actor)
365             {
366                 if(!nade.gl_detonate_later)
367                 {
368                     nade.gl_detonate_later = true;
369                     nadefound = true;
370                 }
371             }
372             if(nadefound)
373                 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
374         }
375         else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
376         {
377             W_Mortar_Attack2(thiswep, actor, weaponentity);
378             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
379         }
380     }
381 }
382 METHOD(Mortar, wr_checkammo1, bool(entity thiswep, entity actor))
383 {
384     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(mortar, ammo);
385     ammo_amount += actor.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
386     return ammo_amount;
387 }
388 METHOD(Mortar, wr_checkammo2, bool(entity thiswep, entity actor))
389 {
390     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(mortar, ammo);
391     ammo_amount += actor.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
392     return ammo_amount;
393 }
394 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
395 {
396     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
397 }
398 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
399 {
400     if(w_deathtype & HITTYPE_SECONDARY)
401         return WEAPON_MORTAR_SUICIDE_BOUNCE;
402     else
403         return WEAPON_MORTAR_SUICIDE_EXPLODE;
404 }
405 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
406 {
407     if(w_deathtype & HITTYPE_SECONDARY)
408         return WEAPON_MORTAR_MURDER_BOUNCE;
409     else
410         return WEAPON_MORTAR_MURDER_EXPLODE;
411 }
412
413 #endif
414 #ifdef CSQC
415
416 METHOD(Mortar, wr_impacteffect, void(entity thiswep, entity actor))
417 {
418     vector org2;
419     org2 = w_org + w_backoff * 12;
420     pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
421     if(!w_issilent)
422         sound(actor, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);
423 }
424
425 #endif
426 #endif