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