]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hlac.qc
006c4d3ba260a120b4e96cd69e7a36166eed3105
[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 this weapon is reloadable, decrease its load. Else decrease the player's ammo
80         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
81         {
82                 if(autocvar_g_balance_hlac_reload_ammo)
83                 {
84                         self.clip_load -= autocvar_g_balance_hlac_primary_ammo;
85                         self.hlac_load = self.clip_load;
86                 }
87                 else
88                         self.ammo_cells -= autocvar_g_balance_hlac_primary_ammo;
89         }
90
91     spread = autocvar_g_balance_hlac_primary_spread_min + (autocvar_g_balance_hlac_primary_spread_add * self.misc_bulletcounter);
92     spread = min(spread,autocvar_g_balance_hlac_primary_spread_max);
93     if(self.crouch)
94         spread = spread * autocvar_g_balance_hlac_primary_spread_crouchmod;
95
96         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_primary_damage);
97         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
98         if (!g_norecoil)
99         {
100                 self.punchangle_x = random () - 0.5;
101                 self.punchangle_y = random () - 0.5;
102         }
103
104         missile = spawn ();
105         missile.owner = self;
106         missile.classname = "hlacbolt";
107         missile.bot_dodge = TRUE;
108
109     missile.bot_dodgerating = autocvar_g_balance_hlac_primary_damage;
110
111         missile.movetype = MOVETYPE_FLY;
112         PROJECTILE_MAKETRIGGER(missile);
113
114         setorigin (missile, w_shotorg);
115         setsize(missile, '0 0 0', '0 0 0');
116
117         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_primary_speed, spread);
118         //missile.angles = vectoangles (missile.velocity); // csqc
119
120         missile.touch = W_HLAC_Touch;
121         missile.think = SUB_Remove;
122
123     missile.nextthink = time + autocvar_g_balance_hlac_primary_lifetime;
124
125         missile.flags = FL_PROJECTILE;
126         missile.projectiledeathtype = WEP_HLAC;
127
128         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
129
130         other = missile; MUTATOR_CALLHOOK(EditProjectile);
131 }
132
133 void W_HLAC_Attack2f (void)
134 {
135         local entity missile;
136     float spread;
137
138     spread = autocvar_g_balance_hlac_secondary_spread;
139
140
141     if(self.crouch)
142         spread = spread * autocvar_g_balance_hlac_secondary_spread_crouchmod;
143
144         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_secondary_damage);
145         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
146
147         missile = spawn ();
148         missile.owner = self;
149         missile.classname = "hlacbolt";
150         missile.bot_dodge = TRUE;
151
152     missile.bot_dodgerating = autocvar_g_balance_hlac_secondary_damage;
153
154         missile.movetype = MOVETYPE_FLY;
155         PROJECTILE_MAKETRIGGER(missile);
156
157         setorigin (missile, w_shotorg);
158         setsize(missile, '0 0 0', '0 0 0');
159
160         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_secondary_speed, spread);
161         //missile.angles = vectoangles (missile.velocity); // csqc
162
163         missile.touch = W_HLAC_Touch;
164         missile.think = SUB_Remove;
165
166     missile.nextthink = time + autocvar_g_balance_hlac_secondary_lifetime;
167
168         missile.flags = FL_PROJECTILE;
169         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
170
171         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
172
173         other = missile; MUTATOR_CALLHOOK(EditProjectile);
174 }
175
176 void W_HLAC_Attack2 (void)
177 {
178     float i;
179
180         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
181         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
182         {
183                 if(autocvar_g_balance_hlac_reload_ammo)
184                 {
185                         self.clip_load -= autocvar_g_balance_hlac_secondary_ammo;
186                         self.hlac_load = self.clip_load;
187                 }
188                 else
189                         self.ammo_cells -= autocvar_g_balance_hlac_secondary_ammo;
190         }
191
192     for(i=autocvar_g_balance_hlac_secondary_shots;i>0;--i)
193         W_HLAC_Attack2f();
194
195         if (!g_norecoil)
196         {
197                 self.punchangle_x = random () - 0.5;
198                 self.punchangle_y = random () - 0.5;
199         }
200 }
201
202 // weapon frames
203 void HLAC_fire1_02()
204 {
205         if(self.weapon != self.switchweapon) // abort immediately if switching
206         {
207                 w_ready();
208                 return;
209         }
210
211         if (self.BUTTON_ATCK)
212         {
213                 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
214                 {
215                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
216                         w_ready();
217                         return;
218                 }
219
220                 ATTACK_FINISHED(self) = time + autocvar_g_balance_hlac_primary_refire * W_WeaponRateFactor();
221                 W_HLAC_Attack();
222                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
223         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
224         }
225         else
226         {
227                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_animtime, w_ready);
228         }
229 };
230
231 void spawnfunc_weapon_hlac (void)
232 {
233         weapon_defaultspawnfunc(WEP_HLAC);
234 }
235
236 float w_hlac(float req)
237 {
238         if (req == WR_AIM)
239         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hlac_primary_speed, 0, autocvar_g_balance_hlac_primary_lifetime, FALSE);
240         else if (req == WR_THINK)
241         {
242                 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
243                         W_HLAC_Reload();
244                 else if (self.BUTTON_ATCK)
245                 {
246                         if (weapon_prepareattack(0, autocvar_g_balance_hlac_primary_refire))
247                         {
248                                 self.misc_bulletcounter = 0;
249                                 W_HLAC_Attack();
250                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
251                         }
252                 }
253
254                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hlac_secondary)
255                 {
256                         if (weapon_prepareattack(1, autocvar_g_balance_hlac_secondary_refire))
257                         {
258                                 W_HLAC_Attack2();
259                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hlac_secondary_animtime, w_ready);
260                         }
261                 }
262         if(self.wish_reload)
263         {
264             if(self.switchweapon == self.weapon)
265             {
266                 if(self.weaponentity.state == WS_READY)
267                 {
268                     self.wish_reload = 0;
269                     W_HLAC_Reload();
270                 }
271             }
272         }
273         }
274         else if (req == WR_PRECACHE)
275         {
276         precache_model ("models/weapons/g_hlac.md3");
277                 precache_model ("models/weapons/v_hlac.md3");
278                 precache_model ("models/weapons/h_hlac.iqm");
279                 precache_sound ("weapons/lasergun_fire.wav");
280                 precache_sound ("weapons/reload.wav");
281
282         }
283         else if (req == WR_SETUP)
284         {
285                 weapon_setup(WEP_HLAC);
286                 W_HLAC_SetAmmoCounter();
287         }
288         else if (req == WR_CHECKAMMO1)
289         {
290                 if(autocvar_g_balance_hlac_reload_ammo)
291                         return self.hlac_load >= autocvar_g_balance_hlac_primary_ammo;
292                 else
293                         return self.ammo_cells >= autocvar_g_balance_hlac_primary_ammo;
294         }
295         else if (req == WR_CHECKAMMO2)
296         {
297                 if(autocvar_g_balance_hlac_reload_ammo)
298                         return self.hlac_load >= autocvar_g_balance_hlac_secondary_ammo;
299                 else
300                         return self.ammo_cells >= autocvar_g_balance_hlac_secondary_ammo;
301         }
302         else if (req == WR_RELOAD)
303         {
304                 W_HLAC_Reload();
305         }
306         return TRUE;
307 };
308 #endif
309 #ifdef CSQC
310 float w_hlac(float req)
311 {
312         if(req == WR_IMPACTEFFECT)
313         {
314                 vector org2;
315                 org2 = w_org + w_backoff * 6;
316                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
317                 if(!w_issilent)
318                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
319         }
320         else if(req == WR_PRECACHE)
321         {
322                 precache_sound("weapons/laserimpact.wav");
323         }
324         else if (req == WR_SUICIDEMESSAGE)
325                 w_deathtypestring = "%s should have used a smaller gun";
326         else if (req == WR_KILLMESSAGE)
327                 w_deathtypestring = "%s was cut down by %s";
328         return TRUE;
329 }
330 #endif
331 #endif