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