]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hlac.qc
Reload if we don't have ammo for a certain attack. Prevents situations in which you...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hlac.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HLAC, w_hlac, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hlac", "hlac", _("Heavy Laser Assault Cannon"))
3 #else
4 #ifdef SVQC
5
6 .float hlac_load;
7
8 void W_HLAC_SetAmmoCounter()
9 {
10         // set clip_load to the weapon we have switched to, if the gun uses reloading
11         if(!autocvar_g_balance_hlac_reload_ammo)
12                 self.clip_load = 0; // also keeps crosshair ammo from displaying
13         else
14         {
15                 self.clip_load = self.hlac_load;
16                 self.clip_size = autocvar_g_balance_hlac_reload_ammo; // for the crosshair ammo display
17         }
18 }
19
20 void W_HLAC_ReloadedAndReady()
21 {
22         float t;
23
24         // now do the ammo transfer
25         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
26         while(self.clip_load < autocvar_g_balance_hlac_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
27         {
28                 self.clip_load += 1;
29                 self.ammo_cells -= 1;
30         }
31         self.hlac_load = self.clip_load;
32
33         t = ATTACK_FINISHED(self) - autocvar_g_balance_hlac_reload_time - 1;
34         ATTACK_FINISHED(self) = t;
35         w_ready();
36 }
37
38 void W_HLAC_Reload()
39 {
40         // return if reloading is disabled for this weapon
41         if(!autocvar_g_balance_hlac_reload_ammo)
42                 return;
43
44         if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo)))
45                 return;
46
47         float t;
48
49         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
50
51         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_hlac_reload_time + 1;
52         ATTACK_FINISHED(self) = t;
53
54         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_hlac_reload_time, W_HLAC_ReloadedAndReady);
55
56         self.old_clip_load = self.clip_load;
57         self.clip_load = -1;
58 }
59
60 void W_HLAC_Touch (void)
61 {
62         PROJECTILE_TOUCH;
63
64         self.event_damage = SUB_Null;
65         
66         if(self.projectiledeathtype & HITTYPE_SECONDARY)
67                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_secondary_damage, autocvar_g_balance_hlac_secondary_edgedamage, autocvar_g_balance_hlac_secondary_radius, world, autocvar_g_balance_hlac_secondary_force, self.projectiledeathtype, other);
68         else
69                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_primary_damage, autocvar_g_balance_hlac_primary_edgedamage, autocvar_g_balance_hlac_primary_radius, world, autocvar_g_balance_hlac_primary_force, self.projectiledeathtype, other);
70
71         remove (self);
72 }
73
74 void W_HLAC_Attack (void)
75 {
76         local entity missile;
77     float spread;
78
79         // if there's not enough ammo for this attack (but we still have the weapon), reload
80         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < autocvar_g_balance_hlac_primary_ammo)
81         {
82                 W_HLAC_Reload();
83                 return;
84         }
85
86         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
87         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
88         {
89                 if(autocvar_g_balance_hlac_reload_ammo)
90                 {
91                         self.clip_load -= autocvar_g_balance_hlac_primary_ammo;
92                         self.hlac_load = self.clip_load;
93                 }
94                 else
95                         self.ammo_cells -= autocvar_g_balance_hlac_primary_ammo;
96         }
97
98     spread = autocvar_g_balance_hlac_primary_spread_min + (autocvar_g_balance_hlac_primary_spread_add * self.misc_bulletcounter);
99     spread = min(spread,autocvar_g_balance_hlac_primary_spread_max);
100     if(self.crouch)
101         spread = spread * autocvar_g_balance_hlac_primary_spread_crouchmod;
102
103         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_primary_damage);
104         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
105         if (!g_norecoil)
106         {
107                 self.punchangle_x = random () - 0.5;
108                 self.punchangle_y = random () - 0.5;
109         }
110
111         missile = spawn ();
112         missile.owner = self;
113         missile.classname = "hlacbolt";
114         missile.bot_dodge = TRUE;
115
116     missile.bot_dodgerating = autocvar_g_balance_hlac_primary_damage;
117
118         missile.movetype = MOVETYPE_FLY;
119         PROJECTILE_MAKETRIGGER(missile);
120
121         setorigin (missile, w_shotorg);
122         setsize(missile, '0 0 0', '0 0 0');
123
124         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_primary_speed, spread);
125         //missile.angles = vectoangles (missile.velocity); // csqc
126
127         missile.touch = W_HLAC_Touch;
128         missile.think = SUB_Remove;
129
130     missile.nextthink = time + autocvar_g_balance_hlac_primary_lifetime;
131
132         missile.flags = FL_PROJECTILE;
133         missile.projectiledeathtype = WEP_HLAC;
134
135         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
136
137         other = missile; MUTATOR_CALLHOOK(EditProjectile);
138 }
139
140 void W_HLAC_Attack2f (void)
141 {
142         local entity missile;
143     float spread;
144
145     spread = autocvar_g_balance_hlac_secondary_spread;
146
147
148     if(self.crouch)
149         spread = spread * autocvar_g_balance_hlac_secondary_spread_crouchmod;
150
151         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_secondary_damage);
152         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
153
154         missile = spawn ();
155         missile.owner = self;
156         missile.classname = "hlacbolt";
157         missile.bot_dodge = TRUE;
158
159     missile.bot_dodgerating = autocvar_g_balance_hlac_secondary_damage;
160
161         missile.movetype = MOVETYPE_FLY;
162         PROJECTILE_MAKETRIGGER(missile);
163
164         setorigin (missile, w_shotorg);
165         setsize(missile, '0 0 0', '0 0 0');
166
167         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_secondary_speed, spread);
168         //missile.angles = vectoangles (missile.velocity); // csqc
169
170         missile.touch = W_HLAC_Touch;
171         missile.think = SUB_Remove;
172
173     missile.nextthink = time + autocvar_g_balance_hlac_secondary_lifetime;
174
175         missile.flags = FL_PROJECTILE;
176         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
177
178         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
179
180         other = missile; MUTATOR_CALLHOOK(EditProjectile);
181 }
182
183 void W_HLAC_Attack2 (void)
184 {
185     float i;
186
187         // if there's not enough ammo for this attack (but we still have the weapon), reload
188         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < autocvar_g_balance_hlac_secondary_ammo)
189         {
190                 W_HLAC_Reload();
191                 return;
192         }
193
194         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
195         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
196         {
197                 if(autocvar_g_balance_hlac_reload_ammo)
198                 {
199                         self.clip_load -= autocvar_g_balance_hlac_secondary_ammo;
200                         self.hlac_load = self.clip_load;
201                 }
202                 else
203                         self.ammo_cells -= autocvar_g_balance_hlac_secondary_ammo;
204         }
205
206     for(i=autocvar_g_balance_hlac_secondary_shots;i>0;--i)
207         W_HLAC_Attack2f();
208
209         if (!g_norecoil)
210         {
211                 self.punchangle_x = random () - 0.5;
212                 self.punchangle_y = random () - 0.5;
213         }
214 }
215
216 // weapon frames
217 void HLAC_fire1_02()
218 {
219         if(self.weapon != self.switchweapon) // abort immediately if switching
220         {
221                 w_ready();
222                 return;
223         }
224
225         if (self.BUTTON_ATCK)
226         {
227                 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
228                 {
229                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
230                         w_ready();
231                         return;
232                 }
233
234                 ATTACK_FINISHED(self) = time + autocvar_g_balance_hlac_primary_refire * W_WeaponRateFactor();
235                 W_HLAC_Attack();
236                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
237         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
238         }
239         else
240         {
241                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_animtime, w_ready);
242         }
243 };
244
245 void spawnfunc_weapon_hlac (void)
246 {
247         weapon_defaultspawnfunc(WEP_HLAC);
248 }
249
250 float w_hlac(float req)
251 {
252         if (req == WR_AIM)
253         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hlac_primary_speed, 0, autocvar_g_balance_hlac_primary_lifetime, FALSE);
254         else if (req == WR_THINK)
255         {
256                 if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo)) // forced reload
257                         W_HLAC_Reload();
258                 else if (self.BUTTON_ATCK)
259                 {
260                         if (weapon_prepareattack(0, autocvar_g_balance_hlac_primary_refire))
261                         {
262                                 self.misc_bulletcounter = 0;
263                                 W_HLAC_Attack();
264                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
265                         }
266                 }
267
268                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hlac_secondary)
269                 {
270                         if (weapon_prepareattack(1, autocvar_g_balance_hlac_secondary_refire))
271                         {
272                                 W_HLAC_Attack2();
273                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hlac_secondary_animtime, w_ready);
274                         }
275                 }
276         if(self.wish_reload)
277         {
278             if(self.switchweapon == self.weapon)
279             {
280                 if(self.weaponentity.state == WS_READY)
281                 {
282                     self.wish_reload = 0;
283                     W_HLAC_Reload();
284                 }
285             }
286         }
287         }
288         else if (req == WR_PRECACHE)
289         {
290         precache_model ("models/weapons/g_hlac.md3");
291                 precache_model ("models/weapons/v_hlac.md3");
292                 precache_model ("models/weapons/h_hlac.iqm");
293                 precache_sound ("weapons/lasergun_fire.wav");
294
295         }
296         else if (req == WR_SETUP)
297         {
298                 weapon_setup(WEP_HLAC);
299                 W_HLAC_SetAmmoCounter();
300         }
301         else if (req == WR_CHECKAMMO1)
302         {
303                 if(autocvar_g_balance_hlac_reload_ammo)
304                         return self.hlac_load >= autocvar_g_balance_hlac_primary_ammo;
305                 else
306                         return self.ammo_cells >= autocvar_g_balance_hlac_primary_ammo;
307         }
308         else if (req == WR_CHECKAMMO2)
309         {
310                 if(autocvar_g_balance_hlac_reload_ammo)
311                         return self.hlac_load >= autocvar_g_balance_hlac_secondary_ammo;
312                 else
313                         return self.ammo_cells >= autocvar_g_balance_hlac_secondary_ammo;
314         }
315         else if (req == WR_RELOAD)
316         {
317                 W_HLAC_Reload();
318         }
319         return TRUE;
320 };
321 #endif
322 #ifdef CSQC
323 float w_hlac(float req)
324 {
325         if(req == WR_IMPACTEFFECT)
326         {
327                 vector org2;
328                 org2 = w_org + w_backoff * 6;
329                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
330                 if(!w_issilent)
331                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
332         }
333         else if(req == WR_PRECACHE)
334         {
335                 precache_sound("weapons/laserimpact.wav");
336         }
337         else if (req == WR_SUICIDEMESSAGE)
338                 w_deathtypestring = "%s should have used a smaller gun";
339         else if (req == WR_KILLMESSAGE)
340                 w_deathtypestring = "%s was cut down by %s";
341         return TRUE;
342 }
343 #endif
344 #endif