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