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