]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hagar.qc
Code for using the new sound
[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 .entity queuenext;
8 .entity queueprev;
9
10 void W_Hagar_Explode (void)
11 {
12         self.event_damage = SUB_Null;
13         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);
14
15         remove (self);
16 }
17
18 void W_Hagar_Explode2 (void)
19 {
20         self.event_damage = SUB_Null;
21         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);
22
23         remove (self);
24 }
25
26 void W_Hagar_Touch (void)
27 {
28         PROJECTILE_TOUCH;
29         self.use ();
30 }
31
32 void W_Hagar_Touch2 (void)
33 {
34         PROJECTILE_TOUCH;
35
36         if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
37                 self.use();
38         } else {
39                 self.cnt++;
40                 pointparticles(particleeffectnum("hagar_bounce"), self.origin, self.velocity, 1);
41                 self.angles = vectoangles (self.velocity);
42                 self.owner = world;
43                 self.projectiledeathtype |= HITTYPE_BOUNCE;
44         }
45 }
46
47 void W_Hagar_Attack (void)
48 {
49         local entity missile;
50
51         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_reload_ammo);
52
53         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_primary_damage);
54
55         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
56
57         missile = spawn ();
58         missile.owner = missile.realowner = self;
59         missile.classname = "missile";
60         missile.bot_dodge = TRUE;
61         missile.bot_dodgerating = autocvar_g_balance_hagar_primary_damage;
62         missile.touch = W_Hagar_Touch;
63         missile.use = W_Hagar_Explode;
64         missile.think = adaptor_think2use_hittype_splash;
65         missile.nextthink = time + autocvar_g_balance_hagar_primary_lifetime;
66         PROJECTILE_MAKETRIGGER(missile);
67         missile.projectiledeathtype = WEP_HAGAR;
68         setorigin (missile, w_shotorg);
69         setsize(missile, '0 0 0', '0 0 0');
70
71         missile.movetype = MOVETYPE_FLY;
72         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_primary);
73
74         missile.angles = vectoangles (missile.velocity);
75         missile.flags = FL_PROJECTILE;
76
77         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
78
79         other = missile; MUTATOR_CALLHOOK(EditProjectile);
80 }
81
82 void W_Hagar_Attack2 (void)
83 {
84         local entity missile;
85
86         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo, autocvar_g_balance_hagar_reload_ammo);
87
88         W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
89
90         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
91
92         missile = spawn ();
93         missile.owner = missile.realowner = self;
94         missile.classname = "missile";
95         missile.bot_dodge = TRUE;
96         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
97         missile.touch = W_Hagar_Touch2;
98         missile.cnt = 0;
99         missile.use = W_Hagar_Explode2;
100         missile.think = adaptor_think2use_hittype_splash;
101         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
102         PROJECTILE_MAKETRIGGER(missile);
103         missile.projectiledeathtype = WEP_HAGAR | HITTYPE_SECONDARY;
104         setorigin (missile, w_shotorg);
105         setsize(missile, '0 0 0', '0 0 0');
106
107         missile.movetype = MOVETYPE_BOUNCEMISSILE;
108         W_SETUPPROJECTILEVELOCITY(missile, g_balance_hagar_secondary);
109
110         missile.angles = vectoangles (missile.velocity);
111         missile.flags = FL_PROJECTILE;
112
113         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
114
115         other = missile; MUTATOR_CALLHOOK(EditProjectile);
116 }
117
118 .float hagarload_refire, hagarload_loaded;
119
120 void W_Hagar_Attack2_Load (void)
121 {
122         if not(autocvar_g_balance_hagar_secondary)
123                 return;
124
125         local entity missile, prevmissile, firstmissile;
126         local float counter, shots;
127         local vector s;
128         vector forward, right, up;
129
130         if(self.BUTTON_ATCK2 && !self.hagarload_loaded)
131         {
132                 if(self.hagarload_refire < time)
133                 {
134                         self.hagar_load += 1;
135                         sound(self, CHAN_WEAPON, "weapons/hagar_load.wav", VOL_BASE, ATTN_NORM);
136
137                         if(self.hagar_load >= autocvar_g_balance_hagar_secondary_load_maxload)
138                                 self.hagarload_loaded = TRUE;
139
140                         self.hagarload_refire = time + autocvar_g_balance_hagar_secondary_refire;
141                 }
142         }
143         else if(self.hagar_load)
144         {
145                 W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
146                 pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
147
148                 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo * self.hagar_load, autocvar_g_balance_hagar_reload_ammo);
149
150                 forward = v_forward;
151                 right = v_right;
152                 up = v_up;
153
154                 shots = self.hagar_load;
155                 missile = world;
156                 while (counter < shots)
157                 {
158
159                         missile = spawn ();
160                         missile.owner = missile.realowner = self;
161                         missile.classname = "missile";
162                         missile.bot_dodge = TRUE;
163                         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
164                         if(shots == 1) {
165                                 missile.queuenext = missile;
166                                 missile.queueprev = missile;
167                         }
168                         else if(counter == 0) { // first projectile, store in firstmissile for now
169                                 firstmissile = missile;
170                         }
171                         else if(counter == shots - 1) { // last projectile, link up with first projectile
172                                 prevmissile.queuenext = missile;
173                                 firstmissile.queueprev = missile;
174                                 missile.queuenext = firstmissile;
175                                 missile.queueprev = prevmissile;
176                         }
177                         else { // else link up with previous projectile
178                                 prevmissile.queuenext = missile;
179                                 missile.queueprev = prevmissile;
180                         }
181
182                         prevmissile = missile;
183
184                         missile.touch = W_Hagar_Touch;
185                         missile.use = W_Hagar_Explode;
186                         missile.think = adaptor_think2use_hittype_splash;
187                         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
188                         PROJECTILE_MAKETRIGGER(missile);
189                         missile.projectiledeathtype = WEP_HAGAR;
190                         setorigin (missile, w_shotorg);
191                         setsize(missile, '0 0 0', '0 0 0');
192
193                         missile.movetype = MOVETYPE_FLY;
194
195                         s = '0 0 0';
196                         if (counter == 0)
197                                 s = '0 0 0';
198                         else
199                         {
200                                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
201                                 s_y = v_forward_x;
202                                 s_z = v_forward_y;
203                         }
204                         s = s * autocvar_g_balance_hagar_secondary_load_spread * g_weaponspreadfactor;
205                         W_SetupProjectileVelocityEx(missile, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_hagar_secondary_speed"), 0, 0, 0, FALSE);
206
207                         missile.angles = vectoangles (missile.velocity);
208                         missile.flags = FL_PROJECTILE;
209
210                         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
211
212                         other = missile; MUTATOR_CALLHOOK(EditProjectile);
213
214                         counter = counter + 1;
215                 }
216
217                 self.hagar_load = 0;
218                 self.hagarload_loaded = FALSE;
219         }
220 }
221
222 void spawnfunc_weapon_hagar (void)
223 {
224         weapon_defaultspawnfunc(WEP_HAGAR);
225 }
226
227 float w_hagar(float req)
228 {
229         float ammo_amount;
230         if (req == WR_AIM)
231                 if (random()>0.15)
232                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
233                 else
234                 {
235                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
236                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
237                 }
238         else if (req == WR_THINK)
239         {
240                 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
241                         weapon_action(self.weapon, WR_RELOAD);
242                 else if (self.BUTTON_ATCK && !self.hagar_load) // not while loading secondary fire
243                 {
244                         if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
245                         {
246                                 W_Hagar_Attack();
247                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
248                         }
249                 }
250                 else if(autocvar_g_balance_hagar_secondary_load)
251                         W_Hagar_Attack2_Load(); // must run each frame
252                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
253                 {
254                         if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
255                         {
256                                 W_Hagar_Attack2();
257                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
258                         }
259                 }
260         }
261         else if (req == WR_PRECACHE)
262         {
263                 precache_model ("models/weapons/g_hagar.md3");
264                 precache_model ("models/weapons/v_hagar.md3");
265                 precache_model ("models/weapons/h_hagar.iqm");
266                 precache_sound ("weapons/hagar_fire.wav");
267                 precache_sound ("weapons/hagar_load.wav");
268                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
269         }
270         else if (req == WR_SETUP)
271         {
272                 weapon_setup(WEP_HAGAR);
273                 self.current_ammo = ammo_rockets;
274
275                 self.hagar_load = 0;
276                 self.hagarload_loaded = FALSE;
277         }
278         else if (req == WR_CHECKAMMO1)
279         {
280                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
281                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_primary_ammo;
282                 return ammo_amount;
283         }
284         else if (req == WR_CHECKAMMO2)
285         {
286                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
287                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_secondary_ammo;
288                 return ammo_amount;
289         }
290         else if (req == WR_RELOAD)
291         {
292                 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");
293         }
294         return TRUE;
295 };
296 #endif
297 #ifdef CSQC
298 float w_hagar(float req)
299 {
300         if(req == WR_IMPACTEFFECT)
301         {
302                 vector org2;
303                 org2 = w_org + w_backoff * 6;
304                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
305                 if(!w_issilent)
306                 {
307                         if (w_random<0.15)
308                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
309                         else if (w_random<0.7)
310                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
311                         else
312                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
313                 }
314         }
315         else if(req == WR_PRECACHE)
316         {
317                 precache_sound("weapons/hagexp1.wav");
318                 precache_sound("weapons/hagexp2.wav");
319                 precache_sound("weapons/hagexp3.wav");
320         }
321         else if (req == WR_SUICIDEMESSAGE)
322                 w_deathtypestring = _("%s played with tiny rockets");
323         else if (req == WR_KILLMESSAGE)
324         {
325                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
326                         w_deathtypestring = _("%s hoped %s's missiles wouldn't bounce");
327                 else // unchecked: SPLASH, SECONDARY
328                         w_deathtypestring = _("%s was pummeled by %s");
329         }
330         return TRUE;
331 }
332 #endif
333 #endif