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