]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_laser.qc
Remove whitespace
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_laser.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ LASER,
4 /* function  */ W_Laser,
5 /* ammotype  */ 0,
6 /* impulse   */ 1,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating    */ 0,
9 /* model     */ "laser",
10 /* shortname */ "laser",
11 /* fullname  */ _("Blaster")
12 );
13 #else
14 #ifdef SVQC
15 void(float imp) W_SwitchWeapon;
16 void() W_LastWeapon;
17 .float swing_prev;
18 .entity swing_alreadyhit;
19
20 void SendCSQCShockwaveParticle(vector endpos) 
21 {
22         //endpos = WarpZone_UnTransformOrigin(transform, endpos);
23         
24         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
25         WriteByte(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
26         WriteCoord(MSG_BROADCAST, w_shotorg_x);
27         WriteCoord(MSG_BROADCAST, w_shotorg_y);
28         WriteCoord(MSG_BROADCAST, w_shotorg_z);
29         WriteCoord(MSG_BROADCAST, endpos_x);
30         WriteCoord(MSG_BROADCAST, endpos_y);
31         WriteCoord(MSG_BROADCAST, endpos_z);
32         WriteByte(MSG_BROADCAST, bound(0, autocvar_g_balance_laser_shockwave_spread_max, 255));
33         WriteByte(MSG_BROADCAST, bound(0, autocvar_g_balance_laser_shockwave_spread_min, 255));
34         WriteByte(MSG_BROADCAST, num_for_edict(self));
35 }
36
37 void W_Laser_Touch()
38 {
39         PROJECTILE_TOUCH;
40
41         self.event_damage = func_null;
42         
43         if(self.dmg)
44                 RadiusDamage(self, self.realowner, autocvar_g_balance_laser_secondary_damage, autocvar_g_balance_laser_secondary_edgedamage, autocvar_g_balance_laser_secondary_radius, world, world, autocvar_g_balance_laser_secondary_force, self.projectiledeathtype, other);
45         else
46                 RadiusDamage(self, self.realowner, autocvar_g_balance_laser_primary_damage, autocvar_g_balance_laser_primary_edgedamage, autocvar_g_balance_laser_primary_radius, world, world, autocvar_g_balance_laser_primary_force, self.projectiledeathtype, other);
47
48         remove(self);
49 }
50
51 void W_Laser_Think()
52 {
53         self.movetype = MOVETYPE_FLY;
54         self.think = SUB_Remove;
55         
56         if(self.dmg)
57                 self.nextthink = time + autocvar_g_balance_laser_secondary_lifetime;
58         else
59                 self.nextthink = time + autocvar_g_balance_laser_primary_lifetime;
60                 
61         CSQCProjectile(self, TRUE, PROJECTILE_LASER, TRUE);
62 }
63
64
65 float W_Laser_Shockwave_CheckSpread(vector targetorg, vector nearest_on_line, vector sw_shotorg, vector attack_endpos)
66 {
67         float spreadlimit;
68         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
69         float distance_from_line = vlen(targetorg - nearest_on_line);
70         
71         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
72         spreadlimit = (autocvar_g_balance_laser_shockwave_spread_min * (1 - spreadlimit) + autocvar_g_balance_laser_shockwave_spread_max * spreadlimit);
73         
74         if(spreadlimit && (distance_from_line <= spreadlimit) && ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90))
75                 return bound(0, (distance_from_line / spreadlimit), 1);
76         else
77                 return FALSE;
78 }
79
80 float W_Laser_Shockwave_IsVisible(entity head, vector nearest_on_line, vector sw_shotorg, vector attack_endpos)
81 {
82         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
83         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
84         vector corner;
85         float i;
86
87         // STEP ONE: Check if the nearest point is clear
88         if(W_Laser_Shockwave_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
89         {
90                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
91                 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
92         }
93
94         // STEP TWO: Check if shotorg to center point is clear
95         if(W_Laser_Shockwave_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
96         {
97                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
98                 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
99         }
100
101         // STEP THREE: Check each corner to see if they are clear
102         for(i=1; i<=8; ++i)
103         {
104                 corner = get_corner_position(head, i);
105                 if(W_Laser_Shockwave_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
106                 {
107                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
108                         if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
109                 }
110         }
111
112         return FALSE;
113 }
114
115 #define PLAYER_CENTER(ent) (ent.origin + ((ent.classname == "player") ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
116
117 entity shockwave_hit[32];
118 float shockwave_hit_damage[32];
119 vector shockwave_hit_force[32];
120
121 float W_Laser_Shockwave_CheckHit(float queue, entity head, vector final_force, float final_damage)
122 {
123         if not(head) { return FALSE; }
124         float i;
125
126         ++queue;
127         
128         for(i = 1; i <= queue; ++i)
129         {
130                 if(shockwave_hit[i] == head)
131                 {
132                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
133                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
134                         return FALSE;
135                 }
136         }
137
138         shockwave_hit[queue] = head;
139         shockwave_hit_force[queue] = final_force;
140         shockwave_hit_damage[queue] = final_damage;
141         return TRUE;
142 }
143
144 void W_Laser_Shockwave()
145 {
146         // declarations
147         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
148         float final_damage; //, final_spread;
149         vector final_force, center, vel;
150         entity head, next;
151
152         float i, queue = 0;
153         
154         // set up the shot direction
155         W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_shockwave_damage);
156         vector attack_endpos = (w_shotorg + (w_shotdir * autocvar_g_balance_laser_shockwave_distance));
157         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
158         vector attack_hitpos = trace_endpos;
159         float distance_to_end = vlen(w_shotorg - attack_endpos);
160         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
161         //entity transform = WarpZone_trace_transform;
162
163         // do the firing effect now
164         SendCSQCShockwaveParticle(attack_endpos);
165         Damage_DamageInfo(attack_hitpos, autocvar_g_balance_laser_shockwave_splash_damage, autocvar_g_balance_laser_shockwave_splash_edgedamage, autocvar_g_balance_laser_shockwave_splash_radius, w_shotdir * autocvar_g_balance_laser_shockwave_splash_force, WEP_LASER, 0, self);
166
167         // splash damage/jumping trace
168         head = WarpZone_FindRadius(attack_hitpos, max(autocvar_g_balance_laser_shockwave_splash_radius, autocvar_g_balance_laser_shockwave_jump_radius), FALSE);
169         while(head)
170         {
171                 next = head.chain;
172
173                 if(head.takedamage)
174                 {
175                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
176                         center = PLAYER_CENTER(head);
177
178                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
179                         
180                         if((head == self) && (distance_to_head <= autocvar_g_balance_laser_shockwave_jump_radius))
181                         {
182                                 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_jump_radius)) : 0));
183                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
184                                 multiplier = max(autocvar_g_balance_laser_shockwave_jump_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_jump_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_jump_multiplier_distance)));
185
186                                 final_force = ((normalize(center - attack_hitpos) * autocvar_g_balance_laser_shockwave_jump_force) * multiplier);
187                                 vel = head.velocity; vel_z = 0;
188                                 vel = normalize(vel) * bound(0, vlen(vel) / autocvar_sv_maxspeed, 1) * autocvar_g_balance_laser_shockwave_jump_force_velocitybias;
189                                 final_force = (vlen(final_force) * normalize(normalize(final_force) + vel));
190                                 final_force_z *= autocvar_g_balance_laser_shockwave_jump_force_zscale;
191                                 final_damage = (autocvar_g_balance_laser_shockwave_jump_damage * multiplier + autocvar_g_balance_laser_shockwave_jump_edgedamage * (1 - multiplier));
192
193                                 Damage(head, self, self, final_damage, WEP_LASER, head.origin, final_force);
194                                 //print("SELF HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
195                         }
196                         else if (distance_to_head <= autocvar_g_balance_laser_shockwave_splash_radius)
197                         {       
198                                 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_splash_radius)) : 0));
199                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
200                                 multiplier = max(autocvar_g_balance_laser_shockwave_splash_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_splash_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_splash_multiplier_distance)));
201
202                                 final_force = normalize(center - (attack_hitpos - (w_shotdir * autocvar_g_balance_laser_shockwave_splash_force_forwardbias)));
203                                 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
204                                 final_force = ((final_force * autocvar_g_balance_laser_shockwave_splash_force) * multiplier);
205                                 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
206                                 final_damage = (autocvar_g_balance_laser_shockwave_splash_damage * multiplier + autocvar_g_balance_laser_shockwave_splash_edgedamage * (1 - multiplier));
207
208                                 if(W_Laser_Shockwave_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
209                                 //print("SPLASH HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
210                         }
211                 }
212                 head = next;
213         }
214
215         // cone damage trace
216         head = WarpZone_FindRadius(w_shotorg, autocvar_g_balance_laser_shockwave_distance, FALSE);
217         while(head)
218         {
219                 next = head.chain;
220                 
221                 if((head != self) && head.takedamage)
222                 {
223                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc) 
224                         center = PLAYER_CENTER(head);
225
226                         // find the closest point on the enemy to the center of the attack
227                         float ang; // angle between shotdir and h
228                         float h; // hypotenuse, which is the distance between attacker to head
229                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
230                         
231                         h = vlen(center - self.origin);
232                         ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
233                         a = h * cos(ang);
234
235                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
236                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
237                         float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // todo: use the findradius function for this
238
239                         if((distance_to_target <= autocvar_g_balance_laser_shockwave_distance) 
240                                 && (W_Laser_Shockwave_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
241                         {
242                                 multiplier_from_accuracy = (1 - W_Laser_Shockwave_CheckSpread(nearest_to_attacker, nearest_on_line, w_shotorg, attack_endpos));
243                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_target / distance_to_end)) : 0));
244                                 multiplier = max(autocvar_g_balance_laser_shockwave_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_multiplier_distance)));
245
246                                 final_force = normalize(center - (nearest_on_line - (w_shotdir * autocvar_g_balance_laser_shockwave_force_forwardbias)));
247                                 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
248                                 final_force = ((final_force * autocvar_g_balance_laser_shockwave_force) * multiplier);
249                                 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
250                                 final_damage = (autocvar_g_balance_laser_shockwave_damage * multiplier + autocvar_g_balance_laser_shockwave_edgedamage * (1 - multiplier));
251
252                                 if(W_Laser_Shockwave_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
253                                 //print("CONE HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
254                         }
255                 }
256                 head = next;
257         }
258
259         for(i = 1; i <= queue; ++i)
260         {
261                 head = shockwave_hit[i];
262                 final_force = shockwave_hit_force[i];
263                 final_damage = shockwave_hit_damage[i];
264                 
265                 Damage(head, self, self, final_damage, WEP_LASER, head.origin, final_force);
266                 print("SHOCKWAVE by ", self.netname, ": damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force)), ".\n");
267                 
268                 shockwave_hit[i] = world;
269                 shockwave_hit_force[i] = '0 0 0';
270                 shockwave_hit_damage[i] = 0;
271         }
272         //print("queue was ", ftos(queue), ".\n\n");
273 }
274
275 void W_Laser_Melee_Think()
276 {
277         // declarations
278         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
279         entity target_victim;
280         vector targpos;
281
282         if(!self.cnt) // set start time of melee
283         {
284                 self.cnt = time; 
285                 W_PlayStrengthSound(self.realowner);
286         }
287
288         makevectors(self.realowner.v_angle); // update values for v_* vectors
289         
290         // calculate swing percentage based on time
291         meleetime = autocvar_g_balance_laser_melee_time * W_WeaponRateFactor();
292         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
293         f = ((1 - swing) * autocvar_g_balance_laser_melee_traces);
294         
295         // check to see if we can still continue, otherwise give up now
296         if((self.realowner.deadflag != DEAD_NO) && autocvar_g_balance_laser_melee_no_doubleslap)
297         {
298                 remove(self);
299                 return;
300         }
301         
302         // if okay, perform the traces needed for this frame 
303         for(i=self.swing_prev; i < f; ++i)
304         {
305                 swing_factor = ((1 - (i / autocvar_g_balance_laser_melee_traces)) * 2 - 1);
306                 
307                 targpos = (self.realowner.origin + self.realowner.view_ofs 
308                         + (v_forward * autocvar_g_balance_laser_melee_range)
309                         + (v_up * swing_factor * autocvar_g_balance_laser_melee_swing_up)
310                         + (v_right * swing_factor * autocvar_g_balance_laser_melee_swing_side));
311
312                 WarpZone_traceline_antilag(self.realowner, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self.realowner, ANTILAG_LATENCY(self.realowner));
313                 
314                 // draw lightning beams for debugging
315                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
316                 te_customflash(targpos, 40,  2, '1 1 1');
317                 
318                 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
319
320                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
321                         && (trace_ent.takedamage == DAMAGE_AIM)  
322                         && (trace_ent != self.swing_alreadyhit)
323                         && (is_player || autocvar_g_balance_laser_melee_nonplayerdamage))
324                 {
325                         target_victim = trace_ent; // so it persists through other calls
326                         
327                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
328                                 swing_damage = (autocvar_g_balance_laser_melee_damage * min(1, swing_factor + 1));
329                         else
330                                 swing_damage = (autocvar_g_balance_laser_melee_nonplayerdamage * min(1, swing_factor + 1));
331                         
332                         //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
333                         
334                         Damage(target_victim, self.realowner, self.realowner, 
335                                 swing_damage, WEP_LASER | HITTYPE_SECONDARY, 
336                                 self.realowner.origin + self.realowner.view_ofs, 
337                                 v_forward * autocvar_g_balance_laser_melee_force);
338                                 
339                         if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_LASER, 0, swing_damage); }
340                         
341                         if(autocvar_g_balance_laser_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
342                         {
343                                 self.swing_alreadyhit = target_victim;
344                                 continue; // move along to next trace
345                         }
346                         else
347                         {
348                                 remove(self);
349                                 return;
350                         }
351                 }
352         }
353         
354         if(time >= self.cnt + meleetime)
355         {
356                 // melee is finished
357                 remove(self);
358                 return;
359         }
360         else
361         {
362                 // set up next frame 
363                 self.swing_prev = i;
364                 self.nextthink = time;
365         }
366 }
367
368 void W_Laser_Melee()
369 {
370         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
371         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_melee_animtime, w_ready);
372
373         entity meleetemp;
374         meleetemp = spawn();
375         meleetemp.owner = meleetemp.realowner = self;
376         meleetemp.think = W_Laser_Melee_Think;
377         meleetemp.nextthink = time + autocvar_g_balance_laser_melee_delay * W_WeaponRateFactor();
378         W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_laser_melee_damage, autocvar_g_balance_laser_melee_range);
379 }
380
381 void W_Laser_Attack(float issecondary)
382 {
383         entity missile;
384         vector s_forward;
385         float a;
386
387         a = autocvar_g_balance_laser_primary_shotangle;
388         s_forward = v_forward * cos(a * DEG2RAD) + v_up * sin(a * DEG2RAD);
389
390         //if(nodamage)
391         //      W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, 0);
392         /*else*/if(issecondary == 1)
393                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_secondary_damage);
394         else
395                 W_SetupShot_Dir(self, s_forward, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_primary_damage);
396         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
397
398         missile = spawn();
399         missile.owner = missile.realowner = self;
400         missile.classname = "laserbolt";
401         missile.dmg = 0;
402         missile.bot_dodge = TRUE;
403         missile.bot_dodgerating = autocvar_g_balance_laser_primary_damage;
404
405         PROJECTILE_MAKETRIGGER(missile);
406         missile.projectiledeathtype = WEP_LASER;
407
408         setorigin(missile, w_shotorg);
409         setsize(missile, '0 0 0', '0 0 0');
410
411         W_SETUPPROJECTILEVELOCITY(missile, g_balance_laser_primary);
412         missile.angles = vectoangles(missile.velocity);
413         //missile.glow_color = 250; // 244, 250
414         //missile.glow_size = 120;
415         missile.touch = W_Laser_Touch;
416
417         missile.flags = FL_PROJECTILE;
418         missile.missile_flags = MIF_SPLASH; 
419
420         missile.think = W_Laser_Think;
421         missile.nextthink = time + autocvar_g_balance_laser_primary_delay;
422
423         other = missile; MUTATOR_CALLHOOK(EditProjectile);
424
425         if(time >= missile.nextthink)
426         {
427                 entity oldself;
428                 oldself = self;
429                 self = missile;
430                 self.think();
431                 self = oldself;
432         }
433 }
434
435 void spawnfunc_weapon_laser(void)
436 {
437         weapon_defaultspawnfunc(WEP_LASER);
438 }
439
440 float W_Laser(float request)
441 {
442         switch(request)
443         {
444                 case WR_AIM:
445                 {
446                         if((autocvar_g_balance_laser_secondary == 2) && (vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_laser_melee_range))
447                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
448                         else
449                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
450                         return TRUE;
451                 }
452                 
453                 case WR_THINK:
454                 {
455                         if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
456                                 weapon_action(self.weapon, WR_RELOAD);
457                         else if(self.BUTTON_ATCK)
458                         {
459                                 if(weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
460                                 {
461                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
462
463                                         if not(autocvar_g_balance_laser_primary)
464                                                 W_Laser_Shockwave();
465                                         else
466                                                 W_Laser_Attack(FALSE);
467
468                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
469                                 }
470                         }
471                         else if(self.BUTTON_ATCK2)
472                         {
473                                 switch(autocvar_g_balance_laser_secondary)
474                                 {
475                                         case 0: // switch to last used weapon
476                                         {
477                                                 if(self.switchweapon == WEP_LASER) // don't do this if already switching
478                                                         W_LastWeapon();
479
480                                                 break;
481                                         }
482
483                                         case 1: // normal projectile secondary
484                                         {
485                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_secondary_refire))
486                                                 {
487                                                         W_DecreaseAmmo(ammo_none, 1, TRUE);
488                                                         W_Laser_Attack(TRUE);
489                                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_secondary_animtime, w_ready);
490                                                 }
491
492                                                 break;
493                                         }
494
495                                         case 2: // melee attack secondary
496                                         {
497                                                 if(!self.crouch) // we are not currently crouching; this fixes an exploit where your melee anim is not visible, and besides wouldn't make much sense
498                                                 if(weapon_prepareattack(1, autocvar_g_balance_laser_melee_refire))
499                                                 {
500                                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
501                                                         W_Laser_Melee();
502                                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_melee_animtime, w_ready);
503                                                 }
504                                         }
505                                 }
506                         }
507                         return TRUE;
508                 }
509                 
510                 case WR_PRECACHE: 
511                 {
512                         precache_model("models/weapons/g_laser.md3");
513                         precache_model("models/weapons/v_laser.md3");
514                         precache_model("models/weapons/h_laser.iqm");
515                         precache_sound("weapons/lasergun_fire.wav");
516                         return TRUE;
517                 }
518                 
519                 case WR_SETUP:
520                 {
521                         weapon_setup(WEP_LASER);
522                         self.current_ammo = ammo_none;
523                         return TRUE;
524                 }
525                 
526                 case WR_CHECKAMMO1:
527                 case WR_CHECKAMMO2:
528                 {
529                         return TRUE; // laser has infinite ammo
530                 }
531                 
532                 case WR_RELOAD:
533                 {
534                         W_Reload(0, autocvar_g_balance_laser_reload_ammo, autocvar_g_balance_laser_reload_time, "weapons/reload.wav");
535                         return TRUE;
536                 }
537                 
538                 case WR_SUICIDEMESSAGE:
539                 {
540                         return WEAPON_LASER_SUICIDE;
541                 }
542                 
543                 case WR_KILLMESSAGE:
544                 {
545                         return WEAPON_LASER_MURDER;
546                 }
547         }
548         
549         return TRUE;
550 }
551 #endif
552 #ifdef CSQC
553 float W_Laser(float request)
554 {
555         switch(request)
556         {
557                 case WR_IMPACTEFFECT:
558                 {
559                         vector org2;
560                         org2 = w_org + w_backoff * 6;
561                         pointparticles(particleeffectnum("new_laser_impact"), org2, w_backoff * 1000, 1);
562                         if(!w_issilent) { sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM); }
563                         return TRUE;
564                 }
565                 
566                 case WR_PRECACHE:
567                 {
568                         precache_sound("weapons/laserimpact.wav");
569                         return TRUE;
570                 }
571         }
572         
573         return TRUE;
574 }
575 #endif
576 #endif