]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hagar.qc
Add some weapon firing functions that are prolly important.
[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;
119 void W_Hagar_Attack2_Load (void)
120 {
121         if not(weapon_action(self.weapon, WR_CHECKAMMO2))
122         {
123                 W_SwitchToOtherWeapon(self);
124                 return;
125         }
126
127         local entity missile, prevmissile, firstmissile;
128         local float counter, shots, loaded;
129         local float used_ammo, enough_ammo;
130         local vector s;
131         vector forward, right, up;
132
133         loaded = self.hagar_load >= autocvar_g_balance_hagar_secondary_load_max;
134
135         // check if we have enough ammo for another rocket
136         used_ammo = autocvar_g_balance_hagar_secondary_ammo;
137         if(autocvar_g_balance_hagar_reload_ammo)
138                 enough_ammo = self.weapon_load[WEP_HAGAR] >= used_ammo + (used_ammo * self.hagar_load);
139         else
140                 enough_ammo = self.ammo_rockets >= used_ammo + (used_ammo * self.hagar_load);
141
142         if(self.BUTTON_ATCK2 && !loaded && enough_ammo)
143         {
144                 // we can attempt to load another rocket
145                 if(self.hagarload_refire < time)
146                 {
147                         self.hagar_load += 1;
148                         sound(self, CHAN_WEAPON2, "weapons/hagar_load.wav", VOL_BASE, ATTN_NORM);
149
150                         self.hagarload_refire = time + autocvar_g_balance_hagar_secondary_refire;
151                 }
152         }
153         else if(self.hagar_load && (!self.BUTTON_ATCK2 || ((loaded || !enough_ammo) && !autocvar_g_balance_hagar_secondary_load_hold)))
154         if(weapon_prepareattack(0, autocvar_g_balance_hagar_secondary_refire))
155         {
156                 // time to release the rockets we've loaded
157
158                 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo * self.hagar_load, autocvar_g_balance_hagar_reload_ammo);
159
160                 W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
161                 pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
162
163                 forward = v_forward;
164                 right = v_right;
165                 up = v_up;
166
167                 shots = self.hagar_load;
168                 missile = world;
169                 while (counter < shots)
170                 {
171                         missile = spawn ();
172                         missile.owner = missile.realowner = self;
173                         missile.classname = "missile";
174                         missile.bot_dodge = TRUE;
175                         missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
176
177                         if(shots == 1) {
178                                 missile.queuenext = missile;
179                                 missile.queueprev = missile;
180                         }
181                         else if(counter == 0) { // first projectile, store in firstmissile for now
182                                 firstmissile = missile;
183                         }
184                         else if(counter == shots - 1) { // last projectile, link up with first projectile
185                                 prevmissile.queuenext = missile;
186                                 firstmissile.queueprev = missile;
187                                 missile.queuenext = firstmissile;
188                                 missile.queueprev = prevmissile;
189                         }
190                         else { // else link up with previous projectile
191                                 prevmissile.queuenext = missile;
192                                 missile.queueprev = prevmissile;
193                         }
194                         prevmissile = missile;
195
196                         missile.touch = W_Hagar_Touch; // not bouncy
197                         missile.use = W_Hagar_Explode2;
198                         missile.think = adaptor_think2use_hittype_splash;
199                         missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
200                         PROJECTILE_MAKETRIGGER(missile);
201                         missile.projectiledeathtype = WEP_HAGAR;
202                         setorigin (missile, w_shotorg);
203                         setsize(missile, '0 0 0', '0 0 0');
204                         missile.movetype = MOVETYPE_FLY;
205
206                         s = '0 0 0';
207                         if (counter == 0)
208                                 s = '0 0 0';
209                         else
210                         {
211                                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
212                                 s_y = v_forward_x;
213                                 s_z = v_forward_y;
214                         }
215                         s = s * cvar("g_balance_hagar_secondary_spread") * g_weaponspreadfactor;
216                         W_SetupProjectileVelocityEx(missile, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_hagar_secondary_speed"), 0, 0, 0, FALSE);
217
218                         missile.angles = vectoangles (missile.velocity);
219                         missile.flags = FL_PROJECTILE;
220
221                         CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
222
223                         other = missile; MUTATOR_CALLHOOK(EditProjectile);
224
225                         counter = counter + 1;
226                 }
227
228                 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_hagar_secondary_refire, w_ready);
229                 self.hagar_load = 0;
230         }
231 }
232
233 void spawnfunc_weapon_hagar (void)
234 {
235         weapon_defaultspawnfunc(WEP_HAGAR);
236 }
237
238 float w_hagar(float req)
239 {
240         float ammo_amount;
241         if (req == WR_AIM)
242                 if (random()>0.15)
243                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
244                 else
245                 {
246                         // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
247                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
248                 }
249         else if (req == WR_THINK)
250         {
251                 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
252                         weapon_action(self.weapon, WR_RELOAD);
253                 else if (self.BUTTON_ATCK && !self.hagar_load) // not while loading the secondary fire
254                 {
255                         if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
256                         {
257                                 W_Hagar_Attack();
258                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
259                         }
260                 }
261                 else if(autocvar_g_balance_hagar_secondary_load && autocvar_g_balance_hagar_secondary)
262                         W_Hagar_Attack2_Load(); // must run each frame
263                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
264                 {
265                         if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
266                         {
267                                 W_Hagar_Attack2();
268                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
269                         }
270                 }
271         }
272         else if (req == WR_PRECACHE)
273         {
274                 precache_model ("models/weapons/g_hagar.md3");
275                 precache_model ("models/weapons/v_hagar.md3");
276                 precache_model ("models/weapons/h_hagar.iqm");
277                 precache_sound ("weapons/hagar_fire.wav");
278                 precache_sound ("weapons/hagar_load.wav");
279                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
280         }
281         else if (req == WR_SETUP)
282         {
283                 weapon_setup(WEP_HAGAR);
284                 self.current_ammo = ammo_rockets;
285
286                 self.hagar_load = 0;
287         }
288         else if (req == WR_CHECKAMMO1)
289         {
290                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
291                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_primary_ammo;
292                 return ammo_amount;
293         }
294         else if (req == WR_CHECKAMMO2)
295         {
296                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
297                 ammo_amount += self.weapon_load[WEP_HAGAR] >= autocvar_g_balance_hagar_secondary_ammo;
298                 return ammo_amount;
299         }
300         else if (req == WR_RELOAD)
301         {
302                 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");
303         }
304         return TRUE;
305 };
306 #endif
307 #ifdef CSQC
308 float w_hagar(float req)
309 {
310         if(req == WR_IMPACTEFFECT)
311         {
312                 vector org2;
313                 org2 = w_org + w_backoff * 6;
314                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
315                 if(!w_issilent)
316                 {
317                         if (w_random<0.15)
318                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
319                         else if (w_random<0.7)
320                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
321                         else
322                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
323                 }
324         }
325         else if(req == WR_PRECACHE)
326         {
327                 precache_sound("weapons/hagexp1.wav");
328                 precache_sound("weapons/hagexp2.wav");
329                 precache_sound("weapons/hagexp3.wav");
330         }
331         else if (req == WR_SUICIDEMESSAGE)
332                 w_deathtypestring = _("%s played with tiny rockets");
333         else if (req == WR_KILLMESSAGE)
334         {
335                 if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
336                         w_deathtypestring = _("%s hoped %s's missiles wouldn't bounce");
337                 else // unchecked: SPLASH, SECONDARY
338                         w_deathtypestring = _("%s was pummeled by %s");
339         }
340         return TRUE;
341 }
342 #endif
343 #endif