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