]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_grenadelauncher.qc
Merge remote branch 'origin/terencehill/freezetag_fix'
[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_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         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
165                 self.ammo_rockets = self.ammo_rockets - autocvar_g_balance_grenadelauncher_primary_ammo;
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         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
212                 self.ammo_rockets = self.ammo_rockets - autocvar_g_balance_grenadelauncher_secondary_ammo;
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
264         if (req == WR_AIM)
265         {
266                 self.BUTTON_ATCK = FALSE;
267                 self.BUTTON_ATCK2 = FALSE;
268                 if (self.bot_secondary_grenademooth == 0)
269                 {
270                         if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
271                         {
272                                 self.BUTTON_ATCK = TRUE;
273                                 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
274                         }
275                 }
276                 else
277                 {
278                         if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
279                         {
280                                 self.BUTTON_ATCK2 = TRUE;
281                                 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
282                         }
283                 }
284         }
285         else if (req == WR_THINK)
286         {
287                 if (self.BUTTON_ATCK)
288                 if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
289                 {
290                         W_Grenade_Attack();
291                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
292                 }
293                 if (self.BUTTON_ATCK2)
294                 {
295                         if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
296                         {
297                                 nadefound = 0;
298                                 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
299                                 {
300                                         if(!nade.gl_detonate_later)
301                                         {
302                                                 nade.gl_detonate_later = TRUE;
303                                                 nadefound = 1;
304                                         }
305                                 }
306                                 if(nadefound)
307                                         sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
308                         }
309                         else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
310                         {
311                                 W_Grenade_Attack2();
312                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
313                         }
314                 }
315         }
316         else if (req == WR_PRECACHE)
317         {
318                 precache_model ("models/weapons/g_gl.md3");
319                 precache_model ("models/weapons/v_gl.md3");
320                 precache_model ("models/weapons/h_gl.iqm");
321                 precache_sound ("weapons/grenade_bounce1.wav");
322                 precache_sound ("weapons/grenade_bounce2.wav");
323                 precache_sound ("weapons/grenade_bounce3.wav");
324                 precache_sound ("weapons/grenade_bounce4.wav");
325                 precache_sound ("weapons/grenade_bounce5.wav");
326                 precache_sound ("weapons/grenade_bounce6.wav");
327                 precache_sound ("weapons/grenade_stick.wav");
328                 precache_sound ("weapons/grenade_fire.wav");
329         }
330         else if (req == WR_SETUP)
331                 weapon_setup(WEP_GRENADE_LAUNCHER);
332         else if (req == WR_CHECKAMMO1)
333                 return self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
334         else if (req == WR_CHECKAMMO2)
335                 return self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
336         return TRUE;
337 };
338 #endif
339 #ifdef CSQC
340 float w_glauncher(float req)
341 {
342         if(req == WR_IMPACTEFFECT)
343         {
344                 vector org2;
345                 org2 = w_org + w_backoff * 12;
346                 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
347                 if(!w_issilent)
348                         sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
349         }
350         else if(req == WR_PRECACHE)
351         {
352                 precache_sound("weapons/grenade_impact.wav");
353         }
354         else if (req == WR_SUICIDEMESSAGE)
355         {
356                 if(w_deathtype & HITTYPE_SECONDARY)
357                         w_deathtypestring = _("%s tried out his own grenade");
358                 else
359                         w_deathtypestring = _("%s detonated");
360         }
361         else if (req == WR_KILLMESSAGE)
362         {
363                 if(w_deathtype & HITTYPE_SPLASH)
364                         if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
365                                 w_deathtypestring = _("%s didn't see %s's grenade");
366                         else // unchecked: SECONDARY
367                                 w_deathtypestring = _("%s almost dodged %s's grenade");
368                 else // unchecked: SECONDARY, BOUNCE
369                         w_deathtypestring = _("%s ate %s's grenade");
370         }
371         return TRUE;
372 }
373 #endif
374 #endif