]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_laser.qc
Remove the switchable check and do all checks in the WR_CHECKAMMO checks. Only fixed...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_laser.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "laser", "laser", _("Laser"))
3 #else
4 #ifdef SVQC
5 void(float imp) W_SwitchWeapon;
6
7 void W_Laser_SetAmmoCounter()
8 {
9         // set clip_load to the weapon we have switched to, if the gun uses reloading
10         if(!autocvar_g_balance_laser_reload_ammo)
11                 self.clip_load = 0; // also keeps crosshair ammo from displaying
12         else
13         {
14                 self.clip_load = self.laser_load;
15                 self.clip_size = autocvar_g_balance_laser_reload_ammo; // for the crosshair ammo display
16         }
17 }
18
19 void W_Laser_ReloadedAndReady()
20 {
21         float t;
22
23         self.clip_load = autocvar_g_balance_laser_reload_ammo; // maximum load since this weapon uses no ammo
24         self.laser_load = self.clip_load;
25
26         t = ATTACK_FINISHED(self) - autocvar_g_balance_laser_reload_time - 1;
27         ATTACK_FINISHED(self) = t;
28         w_ready();
29 }
30
31 void W_Laser_Reload()
32 {
33         // return if reloading is disabled for this weapon
34         if(!autocvar_g_balance_laser_reload_ammo)
35                 return;
36
37         if(!W_ReloadCheck(1, 0))
38                 return;
39
40         float t;
41
42         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
43
44         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_laser_reload_time + 1;
45         ATTACK_FINISHED(self) = t;
46
47         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_laser_reload_time, W_Laser_ReloadedAndReady);
48
49         self.clip_load = -1;
50 }
51
52 void W_Laser_Touch (void)
53 {
54         PROJECTILE_TOUCH;
55
56         self.event_damage = SUB_Null;
57         if (self.dmg)
58                 RadiusDamage (self, self.owner, autocvar_g_balance_laser_secondary_damage, autocvar_g_balance_laser_secondary_edgedamage, autocvar_g_balance_laser_secondary_radius, world, autocvar_g_balance_laser_secondary_force, self.projectiledeathtype, other);
59         else
60                 RadiusDamage (self, self.owner, autocvar_g_balance_laser_primary_damage, autocvar_g_balance_laser_primary_edgedamage, autocvar_g_balance_laser_primary_radius, world, autocvar_g_balance_laser_primary_force, self.projectiledeathtype, other);
61
62         remove (self);
63 }
64
65 void W_Laser_Think()
66 {
67         self.movetype = MOVETYPE_FLY;
68         self.think = SUB_Remove;
69         if (self.dmg)
70                 self.nextthink = time + autocvar_g_balance_laser_secondary_lifetime;
71         else
72                 self.nextthink = time + autocvar_g_balance_laser_primary_lifetime;
73         CSQCProjectile(self, TRUE, PROJECTILE_LASER, TRUE);
74 }
75
76 void W_Laser_Attack (float issecondary)
77 {
78         local entity missile;
79         vector s_forward;
80         float a;
81         float nodamage;
82
83         if(issecondary == 2) // minstanex shot
84                 nodamage = g_minstagib;
85         else
86                 nodamage = FALSE;
87
88         a = autocvar_g_balance_laser_primary_shotangle;
89         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
90
91         if(nodamage)
92                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON2, 0);
93         else if(issecondary == 1)
94                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON2, autocvar_g_balance_laser_secondary_damage);
95         else
96                 W_SetupShot_Dir (self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON2, autocvar_g_balance_laser_primary_damage);
97         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
98
99         missile = spawn ();
100         missile.owner = self;
101         missile.classname = "laserbolt";
102         missile.dmg = 0;
103         if(!nodamage)
104         {
105                 missile.bot_dodge = TRUE;
106                 missile.bot_dodgerating = autocvar_g_balance_laser_primary_damage;
107         }
108
109         PROJECTILE_MAKETRIGGER(missile);
110         missile.projectiledeathtype = WEP_LASER;
111
112         setorigin (missile, w_shotorg);
113         setsize(missile, '0 0 0', '0 0 0');
114
115         W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_primary);
116         missile.angles = vectoangles (missile.velocity);
117         //missile.glow_color = 250; // 244, 250
118         //missile.glow_size = 120;
119         missile.touch = W_Laser_Touch;
120
121         missile.flags = FL_PROJECTILE;
122
123         missile.think = W_Laser_Think;
124         missile.nextthink = time + autocvar_g_balance_laser_primary_delay;
125
126         other = missile; MUTATOR_CALLHOOK(EditProjectile);
127
128         if(time >= missile.nextthink)
129         {
130                 entity oldself;
131                 oldself = self;
132                 self = missile;
133                 self.think();
134                 self = oldself;
135         }
136 }
137
138 .vector hook_start, hook_end;
139 float gauntletbeam_send(entity to, float sf)
140 {
141         WriteByte(MSG_ENTITY, ENT_CLIENT_GAUNTLET);
142         sf = sf & 0x7F;
143         if(sound_allowed(MSG_BROADCAST, self.owner))
144                 sf |= 0x80;
145         WriteByte(MSG_ENTITY, sf);
146         if(sf & 1)
147         {
148                 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
149         }
150         if(sf & 2)
151         {
152                 WriteCoord(MSG_ENTITY, self.hook_start_x);
153                 WriteCoord(MSG_ENTITY, self.hook_start_y);
154                 WriteCoord(MSG_ENTITY, self.hook_start_z);
155         }
156         if(sf & 4)
157         {
158                 WriteCoord(MSG_ENTITY, self.hook_end_x);
159                 WriteCoord(MSG_ENTITY, self.hook_end_y);
160                 WriteCoord(MSG_ENTITY, self.hook_end_z);
161         }
162         return TRUE;
163 }
164 .entity gauntletbeam;
165 .float prevgauntletfire;
166 void gauntletbeam_think()
167 {
168         float damage, myforce, myradius;
169         damage = autocvar_g_balance_laser_secondary_damage;
170         myforce = autocvar_g_balance_laser_secondary_force;
171         myradius = autocvar_g_balance_laser_secondary_radius;
172
173         self.owner.prevgauntletfire = time;
174         if (self.owner.weaponentity.state != WS_INUSE || self != self.owner.gauntletbeam || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK2)
175         {
176                 remove(self);
177                 return;
178         }
179
180         self.nextthink = time;
181
182         makevectors(self.owner.v_angle);
183
184         float dt;
185         dt = frametime;
186
187         W_SetupShot_Range(self.owner, TRUE, 0, "", 0, damage * dt, myradius);
188         WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
189
190         // apply the damage
191         if(trace_ent)
192         {
193                 vector force;
194                 force = w_shotdir * myforce;
195                 if(accuracy_isgooddamage(self.owner, trace_ent))
196                         accuracy_add(self.owner, WEP_LASER, 0, damage * dt);
197                 Damage (trace_ent, self.owner, self.owner, damage * dt, WEP_LASER | HITTYPE_SECONDARY, trace_endpos, force * dt);
198         }
199
200         // draw effect
201         if(w_shotorg != self.hook_start)
202         {
203                 self.SendFlags |= 2;
204                 self.hook_start = w_shotorg;
205         }
206         if(w_shotend != self.hook_end)
207         {
208                 self.SendFlags |= 4;
209                 self.hook_end = w_shotend;
210         }
211 }
212
213 // experimental gauntlet
214 void W_Laser_Attack2 ()
215 {
216         // only play fire sound if 0.5 sec has passed since player let go the fire button
217         if(time - self.prevgauntletfire > 0.5)
218         {
219                 sound (self, CHAN_WEAPON, "weapons/gauntlet_fire.wav", VOL_BASE, ATTN_NORM);
220         }
221
222         entity beam, oldself;
223
224         self.gauntletbeam = beam = spawn();
225         beam.solid = SOLID_NOT;
226         beam.think = gauntletbeam_think;
227         beam.owner = self;
228         beam.movetype = MOVETYPE_NONE;
229         beam.shot_spread = 0;
230         beam.bot_dodge = TRUE;
231         beam.bot_dodgerating = autocvar_g_balance_laser_primary_damage;
232         Net_LinkEntity(beam, FALSE, 0, gauntletbeam_send);
233
234         oldself = self;
235         self = beam;
236         self.think();
237         self = oldself;
238 }
239
240 void LaserInit()
241 {
242         weapon_action(WEP_LASER, WR_PRECACHE);
243         gauntlet_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LASER), FALSE, FALSE, 1);
244         gauntlet_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LASER), FALSE, FALSE, 2);
245         gauntlet_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LASER), FALSE, FALSE, 3);
246         gauntlet_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LASER), FALSE, FALSE, 4);
247 }
248
249 void spawnfunc_weapon_laser (void)
250 {
251         weapon_defaultspawnfunc(WEP_LASER);
252 }
253
254 float w_laser(float req)
255 {
256         local float r1;
257         local float r2;
258         if (req == WR_AIM)
259         {
260                 if(autocvar_g_balance_laser_secondary)
261                 {
262                         r1 = autocvar_g_balance_laser_primary_damage;
263                         r2 = autocvar_g_balance_laser_secondary_damage;
264                         if (random() * (r2 + r1) > r1)
265                                 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_laser_secondary_speed, 0, autocvar_g_balance_laser_secondary_lifetime, FALSE);
266                         else
267                                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE);
268                 }
269                 else
270                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE);
271         }
272         else if (req == WR_THINK)
273         {
274                 if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
275                         W_Laser_Reload();
276                 else if (self.BUTTON_ATCK)
277                 {
278                         if (weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
279                         {
280                                 // if this weapon is reloadable, decrease its load
281                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
282                                 {
283                                         if(autocvar_g_balance_laser_reload_ammo)
284                                         {
285                                                 self.clip_load -= 1;
286                                                 self.laser_load = self.clip_load;
287                                         }
288                                 }
289
290                                 W_Laser_Attack(0);
291                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
292                         }
293                 }
294                 else if (self.BUTTON_ATCK2)
295                 {
296                         if(autocvar_g_balance_laser_secondary)
297                         {
298                                 // if this weapon is reloadable, decrease its load
299                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
300                                 {
301                                         if(autocvar_g_balance_laser_reload_ammo)
302                                         {
303                                                 self.clip_load -= 1;
304                                                 self.laser_load = self.clip_load;
305                                         }
306                                 }
307
308                                 if (weapon_prepareattack(0, 0))
309                                 {
310                                         W_Laser_Attack2();
311                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_secondary_animtime, w_ready);
312                                 }
313                         }
314                         else
315                         {
316                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
317                                         W_SwitchWeapon (self.cnt);
318                         }
319                 }
320         if(self.wish_reload)
321         {
322             if(self.switchweapon == self.weapon)
323             {
324                 if(self.weaponentity.state == WS_READY)
325                 {
326                     self.wish_reload = 0;
327                     W_Laser_Reload();
328                 }
329             }
330         }
331         }
332         else if (req == WR_PRECACHE)
333         {
334                 precache_model ("models/weapons/g_laser.md3");
335                 precache_model ("models/weapons/v_laser.md3");
336                 precache_model ("models/weapons/h_laser.iqm");
337                 precache_sound ("weapons/lasergun_fire.wav");
338                 precache_sound ("weapons/gauntlet_fire.wav");
339                 precache_sound ("weapons/reload.wav");
340         }
341         else if (req == WR_SETUP)
342         {
343                 weapon_setup(WEP_LASER);
344                 W_Laser_SetAmmoCounter();
345         }
346         else if (req == WR_CHECKAMMO1)
347                 return TRUE;
348         else if (req == WR_CHECKAMMO2)
349                 return TRUE;
350         else if (req == WR_RELOAD)
351                 W_Laser_Reload();
352         return TRUE;
353 };
354 #endif
355 #ifdef CSQC
356 float w_laser(float req)
357 {
358         if(req == WR_IMPACTEFFECT)
359         {
360                 vector org2;
361                 org2 = w_org + w_backoff * 6;
362                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
363                 if(!w_issilent)
364                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
365         }
366         else if(req == WR_PRECACHE)
367         {
368                 precache_sound("weapons/laserimpact.wav");
369         }
370         else if (req == WR_SUICIDEMESSAGE)
371                 w_deathtypestring = "%s lasered themself to hell";
372         else if (req == WR_KILLMESSAGE)
373         {
374                 if(w_deathtype & HITTYPE_SECONDARY)
375                         w_deathtypestring = "%s was cut in half by %s's gauntlet"; // unchecked: SPLASH
376                 else
377                         w_deathtypestring = "%s was lasered to death by %s"; // unchecked: SPLASH
378         }
379         return TRUE;
380 }
381 #endif
382 #endif