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