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