]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_grenadelauncher.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_grenadelauncher.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "gl", "grenadelauncher", _("Mortar"))
3 #else
4 #ifdef SVQC
5 .float gl_detonate_later;
6 .float gl_bouncecnt;
7
8 void W_Grenade_Explode (void)
9 {
10         if(other.takedamage == DAMAGE_AIM)
11                 if(other.classname == "player")
12                         if(IsDifferentTeam(self.owner, other))
13                                 if(other.deadflag == DEAD_NO)
14                                         if(IsFlying(other))
15                                                 AnnounceTo(self.owner, "airshot");
16
17         self.event_damage = SUB_Null;
18         self.takedamage = DAMAGE_NO;
19
20         if(self.movetype == MOVETYPE_NONE)
21                 self.velocity = self.oldvelocity;
22
23         RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_primary_damage, autocvar_g_balance_grenadelauncher_primary_edgedamage, autocvar_g_balance_grenadelauncher_primary_radius, world, autocvar_g_balance_grenadelauncher_primary_force, self.projectiledeathtype, other);
24
25         remove (self);
26 }
27
28 void W_Grenade_Explode2 (void)
29 {
30         if(other.takedamage == DAMAGE_AIM)
31                 if(other.classname == "player")
32                         if(IsDifferentTeam(self.owner, other))
33                                 if(IsFlying(other))
34                                         AnnounceTo(self.owner, "airshot");
35
36         self.event_damage = SUB_Null;
37         self.takedamage = DAMAGE_NO;
38
39         if(self.movetype == MOVETYPE_NONE)
40                 self.velocity = self.oldvelocity;
41
42         RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_secondary_damage, autocvar_g_balance_grenadelauncher_secondary_edgedamage, autocvar_g_balance_grenadelauncher_secondary_radius, world, autocvar_g_balance_grenadelauncher_secondary_force, self.projectiledeathtype, other);
43
44         remove (self);
45 }
46
47 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
48 {
49         if (self.health <= 0)
50                 return;
51         self.health = self.health - damage;
52         if (self.health <= 0)
53         {
54                 W_PrepareExplosionByDamage(attacker, self.think);
55         }
56 }
57
58 void W_Grenade_Think1 (void)
59 {
60         self.nextthink = time;
61         if (time > self.cnt)
62         {
63                 other = world;
64                 self.projectiledeathtype |= HITTYPE_BOUNCE;
65                 W_Grenade_Explode ();
66                 return;
67         }
68         if(self.gl_detonate_later && self.gl_bouncecnt >= autocvar_g_balance_grenadelauncher_primary_remote_minbouncecnt)
69                 W_Grenade_Explode();
70 }
71
72 void W_Grenade_Touch1 (void)
73 {
74         PROJECTILE_TOUCH;
75         if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_primary_type == 0) // always explode when hitting a player, or if normal mortar projectile
76         {
77                 self.use ();
78         }
79         else if (autocvar_g_balance_grenadelauncher_primary_type == 1) // bounce
80         {
81                 float r;
82                 r = random() * 6;
83                 if(r < 1)
84                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
85                 else if(r < 2)
86                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
87                 else if(r < 3)
88                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
89                 else if(r < 4)
90                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
91                 else if(r < 5)
92                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
93                 else
94                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
95                 self.projectiledeathtype |= HITTYPE_BOUNCE;
96                 self.gl_bouncecnt += 1;
97         }
98         else if(autocvar_g_balance_grenadelauncher_primary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
99         {
100                 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
101
102                 // let it stick whereever it is
103                 self.oldvelocity = self.velocity;
104                 self.velocity = '0 0 0';
105                 self.movetype = MOVETYPE_NONE; // also disables gravity
106                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
107                 UpdateCSQCProjectile(self);
108
109                 // do not respond to any more touches
110                 self.solid = SOLID_NOT;
111
112                 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_primary_lifetime2);
113         }
114 }
115
116 void W_Grenade_Touch2 (void)
117 {
118         PROJECTILE_TOUCH;
119         if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_secondary_type == 0) // always explode when hitting a player, or if normal mortar projectile
120         {
121                 self.use ();
122         }
123         else if (autocvar_g_balance_grenadelauncher_secondary_type == 1) // bounce
124         {
125                 float r;
126                 r = random() * 6;
127                 if(r < 1)
128                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
129                 else if(r < 2)
130                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
131                 else if(r < 3)
132                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
133                 else if(r < 4)
134                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
135                 else if(r < 5)
136                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
137                 else
138                         spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
139                 self.projectiledeathtype |= HITTYPE_BOUNCE;
140                 self.gl_bouncecnt += 1;
141         }
142         else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
143         {
144                 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
145
146                 // let it stick whereever it is
147                 self.oldvelocity = self.velocity;
148                 self.velocity = '0 0 0';
149                 self.movetype = MOVETYPE_NONE; // also disables gravity
150                 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
151                 UpdateCSQCProjectile(self);
152
153                 // do not respond to any more touches
154                 self.solid = SOLID_NOT;
155
156                 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime2);
157         }
158 }
159
160 void W_Grenade_Attack (void)
161 {
162         local entity gren;
163
164         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
165
166         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_primary_damage);
167         w_shotdir = v_forward; // no TrueAim for grenades please
168
169         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
170
171         gren = spawn ();
172         gren.owner = self;
173         gren.classname = "grenade";
174         gren.bot_dodge = TRUE;
175         gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
176         gren.movetype = MOVETYPE_BOUNCE;
177         gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
178         gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
179         PROJECTILE_MAKETRIGGER(gren);
180         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
181         setorigin(gren, w_shotorg);
182         setsize(gren, '-3 -3 -3', '3 3 3');
183
184         gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
185         gren.nextthink = time;
186         gren.think = W_Grenade_Think1;
187         gren.use = W_Grenade_Explode;
188         gren.touch = W_Grenade_Touch1;
189
190         gren.takedamage = DAMAGE_YES;
191         gren.health = autocvar_g_balance_grenadelauncher_primary_health;
192         gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
193         gren.event_damage = W_Grenade_Damage;
194         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
195
196         gren.angles = vectoangles (gren.velocity);
197         gren.flags = FL_PROJECTILE;
198
199         if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
200                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
201         else
202                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
203
204         other = gren; MUTATOR_CALLHOOK(EditProjectile);
205 }
206
207 void W_Grenade_Attack2 (void)
208 {
209         local entity gren;
210
211         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_secondary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
212
213         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_secondary_damage);
214         w_shotdir = v_forward; // no TrueAim for grenades please
215
216         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
217
218         gren = spawn ();
219         gren.owner = self;
220         gren.classname = "grenade";
221         gren.bot_dodge = TRUE;
222         gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
223         gren.movetype = MOVETYPE_BOUNCE;
224         gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
225         gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
226         PROJECTILE_MAKETRIGGER(gren);
227         gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
228         setorigin(gren, w_shotorg);
229         setsize(gren, '-3 -3 -3', '3 3 3');
230
231         gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
232         gren.think = adaptor_think2use_hittype_splash;
233         gren.use = W_Grenade_Explode2;
234         gren.touch = W_Grenade_Touch2;
235
236         gren.takedamage = DAMAGE_YES;
237         gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
238         gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
239         gren.event_damage = W_Grenade_Damage;
240         W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
241
242         gren.angles = vectoangles (gren.velocity);
243         gren.flags = FL_PROJECTILE;
244
245         if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
246                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
247         else
248                 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
249
250         other = gren; MUTATOR_CALLHOOK(EditProjectile);
251 }
252
253 void spawnfunc_weapon_grenadelauncher (void)
254 {
255         weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
256 }
257
258 .float bot_secondary_grenademooth;
259 float w_glauncher(float req)
260 {
261         entity nade;
262         float nadefound;
263         float ammo_amount;
264
265         if (req == WR_AIM)
266         {
267                 self.BUTTON_ATCK = FALSE;
268                 self.BUTTON_ATCK2 = FALSE;
269                 if (self.bot_secondary_grenademooth == 0)
270                 {
271                         if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
272                         {
273                                 self.BUTTON_ATCK = TRUE;
274                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
275                         }
276                 }
277                 else
278                 {
279                         if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
280                         {
281                                 self.BUTTON_ATCK2 = TRUE;
282                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
283                         }
284                 }
285         }
286         else if (req == WR_THINK)
287         {
288                 if(autocvar_g_balance_grenadelauncher_reload_ammo && self.clip_load < min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo)) // forced reload
289                         weapon_action(self.weapon, WR_RELOAD);
290                 else if (self.BUTTON_ATCK)
291                 {
292                         if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
293                         {
294                                 W_Grenade_Attack();
295                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
296                         }
297                 }
298                 else if (self.BUTTON_ATCK2)
299                 {
300                         if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
301                         {
302                                 nadefound = 0;
303                                 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
304                                 {
305                                         if(!nade.gl_detonate_later)
306                                         {
307                                                 nade.gl_detonate_later = TRUE;
308                                                 nadefound = 1;
309                                         }
310                                 }
311                                 if(nadefound)
312                                         sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
313                         }
314                         else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
315                         {
316                                 W_Grenade_Attack2();
317                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
318                         }
319                 }
320         }
321         else if (req == WR_PRECACHE)
322         {
323                 precache_model ("models/weapons/g_gl.md3");
324                 precache_model ("models/weapons/v_gl.md3");
325                 precache_model ("models/weapons/h_gl.iqm");
326                 precache_sound ("weapons/grenade_bounce1.wav");
327                 precache_sound ("weapons/grenade_bounce2.wav");
328                 precache_sound ("weapons/grenade_bounce3.wav");
329                 precache_sound ("weapons/grenade_bounce4.wav");
330                 precache_sound ("weapons/grenade_bounce5.wav");
331                 precache_sound ("weapons/grenade_bounce6.wav");
332                 precache_sound ("weapons/grenade_stick.wav");
333                 precache_sound ("weapons/grenade_fire.wav");
334                 precache_sound ("weapons/reload.wav");
335         }
336         else if (req == WR_SETUP)
337         {
338                 weapon_setup(WEP_GRENADE_LAUNCHER);
339                 self.current_ammo = ammo_rockets;
340         }
341         else if (req == WR_CHECKAMMO1)
342         {
343                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
344                 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_primary_ammo;
345                 return ammo_amount;
346         }
347         else if (req == WR_CHECKAMMO2)
348         {
349                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
350                 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_secondary_ammo;
351                 return ammo_amount;
352         }
353         else if (req == WR_RELOAD)
354         {
355                 W_Reload(min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo), autocvar_g_balance_grenadelauncher_reload_ammo, autocvar_g_balance_grenadelauncher_reload_time, "weapons/reload.wav");
356         }
357         return TRUE;
358 };
359 #endif
360 #ifdef CSQC
361 float w_glauncher(float req)
362 {
363         if(req == WR_IMPACTEFFECT)
364         {
365                 vector org2;
366                 org2 = w_org + w_backoff * 12;
367                 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
368                 if(!w_issilent)
369                         sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
370         }
371         else if(req == WR_PRECACHE)
372         {
373                 precache_sound("weapons/grenade_impact.wav");
374         }
375         else if (req == WR_SUICIDEMESSAGE)
376         {
377                 if(w_deathtype & HITTYPE_SECONDARY)
378                         w_deathtypestring = _("%s tried out his own grenade");
379                 else
380                         w_deathtypestring = _("%s detonated");
381         }
382         else if (req == WR_KILLMESSAGE)
383         {
384                 if(w_deathtype & HITTYPE_SPLASH)
385                         if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
386                                 w_deathtypestring = _("%s didn't see %s's grenade");
387                         else // unchecked: SECONDARY
388                                 w_deathtypestring = _("%s almost dodged %s's grenade");
389                 else // unchecked: SECONDARY, BOUNCE
390                         w_deathtypestring = _("%s ate %s's grenade");
391         }
392         return TRUE;
393 }
394 #endif
395 #endif