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