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