]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_hagar.qc
Merge remote-tracking branch 'origin/master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_hagar.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ HAGAR,
4 /* function  */ w_hagar,
5 /* ammotype  */ IT_ROCKETS,
6 /* impulse   */ 8,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating    */ BOT_PICKUP_RATING_MID,
9 /* model     */ "hagar",
10 /* shortname */ "hagar",
11 /* fullname  */ _("Hagar")
12 );
13 #else
14 #ifdef SVQC
15 void spawnfunc_weapon_hagar() { weapon_defaultspawnfunc(WEP_HAGAR); }
16 // NO bounce protection, as bounces are limited!
17
18 void W_Hagar_Explode (void)
19 {
20         self.event_damage = func_null;
21         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_primary_damage, autocvar_g_balance_hagar_primary_edgedamage, autocvar_g_balance_hagar_primary_radius, world, world, autocvar_g_balance_hagar_primary_force, self.projectiledeathtype, other);
22
23         remove (self);
24 }
25
26 void W_Hagar_Explode2 (void)
27 {
28         self.event_damage = func_null;
29         RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_secondary_damage, autocvar_g_balance_hagar_secondary_edgedamage, autocvar_g_balance_hagar_secondary_radius, world, world, autocvar_g_balance_hagar_secondary_force, self.projectiledeathtype, other);
30
31         remove (self);
32 }
33
34 void W_Hagar_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
35 {
36         if (self.health <= 0)
37                 return;
38                 
39         float is_linkexplode = ( ((inflictor.owner != world) ? (inflictor.owner == self.owner) : TRUE)
40                 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY) 
41                 && (self.projectiledeathtype & HITTYPE_SECONDARY));
42         
43         if(is_linkexplode)
44                 is_linkexplode = (is_linkexplode && autocvar_g_balance_hagar_secondary_load_linkexplode);
45         else
46                 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
47
48         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, is_linkexplode))
49                 return; // g_projectiles_damage says to halt
50
51         self.health = self.health - damage;
52         self.angles = vectoangles(self.velocity);
53         
54         if (self.health <= 0)
55                 W_PrepareExplosionByDamage(attacker, self.think);
56 }
57
58 void W_Hagar_Touch (void)
59 {
60         PROJECTILE_TOUCH;
61         self.use ();
62 }
63
64 void W_Hagar_Touch2 (void)
65 {
66         PROJECTILE_TOUCH;
67
68         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
69                 self.use();
70         } else {
71                 self.cnt++;
72                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
73                 self.angles = vectoangles (self.velocity);
74                 self.owner = world;
75                 self.projectiledeathtype |= HITTYPE_BOUNCE;
76         }
77 }
78
79 void W_Hagar_Attack (void)
80 {
81         entity missile;
82
83         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_reload_ammo);
84
85         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CH_WEAPON_A, autocvar_g_balance_hagar_primary_damage);
86
87         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
88
89         missile = spawn ();
90         missile.owner = missile.realowner = self;
91         missile.classname = "missile";
92         missile.bot_dodge = TRUE;
93         missile.bot_dodgerating = autocvar_g_balance_hagar_primary_damage;
94         
95         missile.takedamage = DAMAGE_YES;
96         missile.health = autocvar_g_balance_hagar_primary_health;
97         missile.damageforcescale = autocvar_g_balance_hagar_primary_damageforcescale;
98         missile.event_damage = W_Hagar_Damage;
99         missile.damagedbycontents = TRUE;
100         
101         missile.touch = W_Hagar_Touch;
102         missile.use = W_Hagar_Explode;
103         missile.think = adaptor_think2use_hittype_splash;
104         missile.nextthink = time + autocvar_g_balance_hagar_primary_lifetime;
105         PROJECTILE_MAKETRIGGER(missile);
106         missile.projectiledeathtype = WEP_HAGAR;
107         setorigin (missile, w_shotorg);
108         setsize(missile, '0 0 0', '0 0 0');
109
110         missile.movetype = MOVETYPE_FLY;
111         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
112
113         missile.angles = vectoangles (missile.velocity);
114         missile.flags = FL_PROJECTILE;
115         missile.missile_flags = MIF_SPLASH; 
116
117         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
118
119         other = missile; MUTATOR_CALLHOOK(EditProjectile);
120 }
121
122 void W_Hagar_Attack2 (void)
123 {
124         entity missile;
125
126         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo, autocvar_g_balance_hagar_reload_ammo);
127
128         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CH_WEAPON_A, autocvar_g_balance_hagar_secondary_damage);
129
130         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
131
132         missile = spawn ();
133         missile.owner = missile.realowner = self;
134         missile.classname = "missile";
135         missile.bot_dodge = TRUE;
136         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
137         
138         missile.takedamage = DAMAGE_YES;
139         missile.health = autocvar_g_balance_hagar_secondary_health;
140         missile.damageforcescale = autocvar_g_balance_hagar_secondary_damageforcescale;
141         missile.event_damage = W_Hagar_Damage;
142         missile.damagedbycontents = TRUE;
143
144         missile.touch = W_Hagar_Touch2;
145         missile.cnt = 0;
146         missile.use = W_Hagar_Explode2;
147         missile.think = adaptor_think2use_hittype_splash;
148         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
149         PROJECTILE_MAKETRIGGER(missile);
150         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
151         setorigin (missile, w_shotorg);
152         setsize(missile, '0 0 0', '0 0 0');
153
154         missile.movetype = MOVETYPE_BOUNCEMISSILE;
155         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
156
157         missile.angles = vectoangles (missile.velocity);
158         missile.flags = FL_PROJECTILE;
159         missile.missile_flags = MIF_SPLASH; 
160
161         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
162
163         other = missile; MUTATOR_CALLHOOK(EditProjectile);
164 }
165
166 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
167 void W_Hagar_Attack2_Load_Release (void)
168 {
169         // time to release the rockets we've loaded
170
171         entity missile;
172         float counter, shots, spread_pershot;
173         vector s;
174         vector forward, right, up;
175
176         if(!self.hagar_load)
177                 return;
178
179         weapon_prepareattack_do(1, autocvar_g_balance_hagar_secondary_refire);
180
181         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CH_WEAPON_A, autocvar_g_balance_hagar_secondary_damage);
182         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
183
184         forward = v_forward;
185         right = v_right;
186         up = v_up;
187
188         shots = self.hagar_load;
189         missile = world;
190         for(counter = 0; counter < shots; ++counter)
191         {
192                 missile = spawn ();
193                 missile.owner = missile.realowner = self;
194                 missile.classname = "missile";
195                 missile.bot_dodge = TRUE;
196                 missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
197                 
198                 missile.takedamage = DAMAGE_YES;
199                 missile.health = autocvar_g_balance_hagar_secondary_health;
200                 missile.damageforcescale = autocvar_g_balance_hagar_secondary_damageforcescale;
201                 missile.event_damage = W_Hagar_Damage;
202                 missile.damagedbycontents = TRUE;
203
204                 missile.touch = W_Hagar_Touch; // not bouncy
205                 missile.use = W_Hagar_Explode2;
206                 missile.think = adaptor_think2use_hittype_splash;
207                 missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
208                 PROJECTILE_MAKETRIGGER(missile);
209                 missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
210                 setorigin (missile, w_shotorg);
211                 setsize(missile, '0 0 0', '0 0 0');
212                 missile.movetype = MOVETYPE_FLY;
213                 missile.missile_flags = MIF_SPLASH; 
214                 
215                 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
216                 spread_pershot = ((shots - 1) / (autocvar_g_balance_hagar_secondary_load_max - 1)); 
217                 spread_pershot = (1 - (spread_pershot * autocvar_g_balance_hagar_secondary_load_spread_bias));
218                 spread_pershot = (autocvar_g_balance_hagar_secondary_spread * spread_pershot * g_weaponspreadfactor);
219                 
220                 // pattern spread calculation
221                 s = '0 0 0';
222                 if (counter == 0)
223                         s = '0 0 0';
224                 else
225                 {
226                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
227                         s_y = v_forward_x;
228                         s_z = v_forward_y;
229                 }
230                 s = s * autocvar_g_balance_hagar_secondary_load_spread * g_weaponspreadfactor;
231                 
232                 W_SetupProjectileVelocityEx(missile, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_hagar_secondary_speed, 0, 0, spread_pershot, FALSE);
233
234                 missile.angles = vectoangles (missile.velocity);
235                 missile.flags = FL_PROJECTILE;
236
237                 CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
238
239                 other = missile; MUTATOR_CALLHOOK(EditProjectile);
240         }
241
242         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_load_animtime, w_ready);
243         self.hagar_loadstep = time + autocvar_g_balance_hagar_secondary_refire * W_WeaponRateFactor();
244         self.hagar_load = 0;
245 }
246
247 void W_Hagar_Attack2_Load (void)
248 {
249         // loadable hagar secondary attack, must always run each frame
250         
251         if(time < game_starttime)
252                 return;
253
254         float loaded, enough_ammo;
255         loaded = self.hagar_load >= autocvar_g_balance_hagar_secondary_load_max;
256
257         // this is different than WR_CHECKAMMO when it comes to reloading
258         if(autocvar_g_balance_hagar_reload_ammo)
259                 enough_ammo = self.(weapon_load[WEP_HAGAR]) >= autocvar_g_balance_hagar_secondary_ammo;
260         else
261                 enough_ammo = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
262
263         if(self.BUTTON_ATCK2)
264         {
265                 if(self.BUTTON_ATCK && autocvar_g_balance_hagar_secondary_load_abort)
266                 {
267                         if(self.hagar_load)
268                         {
269                                 // if we pressed primary fire while loading, unload all rockets and abort
270                                 self.weaponentity.state = WS_READY;
271                                 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo * self.hagar_load * -1, autocvar_g_balance_hagar_reload_ammo); // give back ammo
272                                 self.hagar_load = 0;
273                                 sound(self, CH_WEAPON_A, "weapons/hagar_beep.wav", VOL_BASE, ATTN_NORM);
274
275                                 // pause until we can load rockets again, once we re-press the alt fire button
276                                 self.hagar_loadstep = time + autocvar_g_balance_hagar_secondary_load_speed * W_WeaponRateFactor();
277
278                                 // require letting go of the alt fire button before we can load again
279                                 self.hagar_loadblock = TRUE;
280                         }
281                 }
282                 else
283                 {
284                         // check if we can attempt to load another rocket
285                         if(!loaded && enough_ammo)
286                         {
287                                 if(!self.hagar_loadblock && self.hagar_loadstep < time)
288                                 {
289                                         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo, autocvar_g_balance_hagar_reload_ammo);
290                                         self.weaponentity.state = WS_INUSE;
291                                         self.hagar_load += 1;
292                                         sound(self, CH_WEAPON_B, "weapons/hagar_load.wav", VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
293
294                                         if (self.hagar_load >= autocvar_g_balance_hagar_secondary_load_max)
295                                                 self.hagar_loadstep = time + autocvar_g_balance_hagar_secondary_load_hold * W_WeaponRateFactor();
296                                         else
297                                                 self.hagar_loadstep = time + autocvar_g_balance_hagar_secondary_load_speed * W_WeaponRateFactor();
298                                 }
299                         }
300                         else if(!self.hagar_loadbeep && self.hagar_load) // prevents the beep from playing each frame
301                         {
302                                 // if this is the last rocket we can load, play a beep sound to notify the player
303                                 sound(self, CH_WEAPON_A, "weapons/hagar_beep.wav", VOL_BASE, ATTN_NORM);
304                                 self.hagar_loadbeep = TRUE;
305                         }
306                 }
307         }
308         else if(self.hagar_loadblock)
309         {
310                 // the alt fire button has been released, so re-enable loading if blocked
311                 self.hagar_loadblock = FALSE;
312         }
313
314         if(self.hagar_load)
315         {
316                 // play warning sound if we're about to release
317                 if((loaded || !enough_ammo) && self.hagar_loadstep - 0.5 < time && autocvar_g_balance_hagar_secondary_load_hold >= 0)
318                 {
319                         if(!self.hagar_warning && self.hagar_load) // prevents the beep from playing each frame
320                         {
321                                 // we're about to automatically release after holding time, play a beep sound to notify the player
322                                 sound(self, CH_WEAPON_A, "weapons/hagar_beep.wav", VOL_BASE, ATTN_NORM);
323                                 self.hagar_warning = TRUE;
324                         }
325                 }
326                 
327                 // release if player let go of button or if they've held it in too long
328                 if(!self.BUTTON_ATCK2 || ((loaded || !enough_ammo) && self.hagar_loadstep < time && autocvar_g_balance_hagar_secondary_load_hold >= 0))
329                 {
330                         self.weaponentity.state = WS_READY;
331                         W_Hagar_Attack2_Load_Release();
332                 }
333         }
334         else
335         {
336                 self.hagar_loadbeep = FALSE;
337                 self.hagar_warning = FALSE;
338         }
339
340         // we aren't checking ammo during an attack, so we must do it here
341         if not(weapon_action(self.weapon, WR_CHECKAMMO1) + weapon_action(self.weapon, WR_CHECKAMMO2))
342         {
343                 // note: this doesn't force the switch
344                 W_SwitchToOtherWeapon(self);
345                 return;
346         }
347 }
348
349 float w_hagar(float req)
350 {
351         float ammo_amount;
352         switch(req)
353         {
354                 case WR_AIM:
355                 {
356                         if (random()>0.15)
357                                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
358                         else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
359                                 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
360                                 
361                         return TRUE;
362                 }
363                 case WR_THINK:
364                 {
365                         float loadable_secondary;
366                         loadable_secondary = (autocvar_g_balance_hagar_secondary_load && autocvar_g_balance_hagar_secondary);
367
368                         if (loadable_secondary)
369                                 W_Hagar_Attack2_Load(); // must always run each frame
370                         if(autocvar_g_balance_hagar_reload_ammo && self.clip_load < min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo)) // forced reload
371                                 weapon_action(self.weapon, WR_RELOAD);
372                         else if (self.BUTTON_ATCK && !self.hagar_load && !self.hagar_loadblock) // not while secondary is loaded or awaiting reset
373                         {
374                                 if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
375                                 {
376                                         W_Hagar_Attack();
377                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
378                                 }
379                         }
380                         else if (self.BUTTON_ATCK2 && !loadable_secondary && autocvar_g_balance_hagar_secondary)
381                         {
382                                 if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
383                                 {
384                                         W_Hagar_Attack2();
385                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
386                                 }
387                         }
388                         
389                         return TRUE;
390                 }
391                 case WR_GONETHINK:
392                 {
393                         // we lost the weapon and want to prepare switching away
394                         if(self.hagar_load)
395                         {
396                                 self.weaponentity.state = WS_READY;
397                                 W_Hagar_Attack2_Load_Release();
398                         }
399                         
400                         return TRUE;
401                 }
402                 case WR_PRECACHE:
403                 {
404                         precache_model ("models/weapons/g_hagar.md3");
405                         precache_model ("models/weapons/v_hagar.md3");
406                         precache_model ("models/weapons/h_hagar.iqm");
407                         precache_sound ("weapons/hagar_fire.wav");
408                         precache_sound ("weapons/hagar_load.wav");
409                         precache_sound ("weapons/hagar_beep.wav");
410                         return TRUE;
411                 }
412                 case WR_SETUP:
413                 {
414                         weapon_setup(WEP_HAGAR);
415                         self.current_ammo = ammo_rockets;
416                         self.hagar_loadblock = FALSE;
417
418                         if(self.hagar_load)
419                         {
420                                 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo * self.hagar_load * -1, autocvar_g_balance_hagar_reload_ammo); // give back ammo if necessary
421                                 self.hagar_load = 0;
422                         }
423                         
424                         return TRUE;
425                 }
426                 case WR_CHECKAMMO1:
427                 {
428                         ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
429                         ammo_amount += self.(weapon_load[WEP_HAGAR]) >= autocvar_g_balance_hagar_primary_ammo;
430                         return ammo_amount;
431                 }
432                 case WR_CHECKAMMO2:
433                 {
434                         ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
435                         ammo_amount += self.(weapon_load[WEP_HAGAR]) >= autocvar_g_balance_hagar_secondary_ammo;
436                         return ammo_amount;
437                 }
438                 case WR_RESETPLAYER:
439                 {
440                         self.hagar_load = 0;
441                         return TRUE;
442                 }
443                 case WR_PLAYERDEATH:
444                 {
445                         // if we have any rockets loaded when we die, release them
446                         if(self.hagar_load && autocvar_g_balance_hagar_secondary_load_releasedeath)
447                                 W_Hagar_Attack2_Load_Release();
448                                 
449                         return TRUE;
450                 }
451                 case WR_RELOAD:
452                 {
453                         if not(self.hagar_load) // require releasing loaded rockets first
454                                 W_Reload(min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo), autocvar_g_balance_hagar_reload_ammo, autocvar_g_balance_hagar_reload_time, "weapons/reload.wav");
455                                 
456                         return TRUE;
457                 }
458                 case WR_SUICIDEMESSAGE:
459                 {
460                         return WEAPON_HAGAR_SUICIDE;
461                 }
462                 case WR_KILLMESSAGE:
463                 {
464                         if(w_deathtype & HITTYPE_SECONDARY)
465                                 return WEAPON_HAGAR_MURDER_BURST;
466                         else
467                                 return WEAPON_HAGAR_MURDER_SPRAY;
468                 }
469         }
470         return TRUE;
471 }
472 #endif
473 #ifdef CSQC
474 float w_hagar(float req)
475 {
476         switch(req)
477         {
478                 case WR_IMPACTEFFECT:
479                 {
480                         vector org2;
481                         org2 = w_org + w_backoff * 6;
482                         pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
483                         if(!w_issilent)
484                         {
485                                 if (w_random<0.15)
486                                         sound(self, CH_SHOTS, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
487                                 else if (w_random<0.7)
488                                         sound(self, CH_SHOTS, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
489                                 else
490                                         sound(self, CH_SHOTS, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
491                         }
492                         
493                         return TRUE;
494                 }
495                 case WR_PRECACHE:
496                 {
497                         precache_sound("weapons/hagexp1.wav");
498                         precache_sound("weapons/hagexp2.wav");
499                         precache_sound("weapons/hagexp3.wav");
500                         return TRUE;
501                 }
502         }
503         return TRUE;
504 }
505 #endif
506 #endif