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