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