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