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