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