]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vaporizer.qc
8b1e1bfce8f4038497685731e8e54bbe3f2667e3
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vaporizer.qc
1 #include "vaporizer.qh"
2
3 REGISTER_NET_TEMP(TE_CSQC_VAPORBEAMPARTICLE)
4
5 #if defined(SVQC)
6 void SendCSQCVaporizerBeamParticle(entity player, int hit) {
7         vector v;
8         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
9         WriteHeader(MSG_BROADCAST, TE_CSQC_VAPORBEAMPARTICLE);
10         WriteVector(MSG_BROADCAST, w_shotorg);
11         WriteVector(MSG_BROADCAST, v);
12         WriteByte(MSG_BROADCAST, hit);
13         WriteByte(MSG_BROADCAST, etof(player));
14         WriteByte(MSG_BROADCAST, player.team);
15 }
16 #elif defined(CSQC)
17 bool autocvar_cl_vaporizerbeam_particle = false;
18 float autocvar_cl_vaporizerbeam_lifetime = 0.8;
19 float autocvar_cl_vaporizerbeam_colorboost = 0.7;
20
21 string Draw_VaporizerBeam_trace_callback_tex;
22 float Draw_VaporizerBeam_trace_callback_rnd;
23 vector Draw_VaporizerBeam_trace_callback_rgb;
24 float Draw_VaporizerBeam_trace_callback_a;
25 void Draw_VaporizerBeam_trace_callback(vector start, vector hit, vector end)
26 {
27         float i;
28         vector vorg;
29         vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
30         for(i = 0; i < Draw_VaporizerBeam_trace_callback_a; ++i)
31                 Draw_CylindricLine(hit, start, 8, Draw_VaporizerBeam_trace_callback_tex, 0.25, Draw_VaporizerBeam_trace_callback_rnd, Draw_VaporizerBeam_trace_callback_rgb, min(1, Draw_VaporizerBeam_trace_callback_a - i), DRAWFLAG_NORMAL, vorg);
32         Draw_VaporizerBeam_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
33 }
34
35 .vector vorg1, vorg2;
36 void VaporizerBeam_Draw(entity this)
37 {
38         //draw either the old v2.3 beam or the new beam
39         particles_alphamin = particles_alphamax = particles_fade = 1;
40
41         string tex = "particles/lgbeam";
42         if(this.cnt)
43                 tex = "particles/gauntletbeam";
44         vector rgb;
45         //entity e = CSQCModel_server2csqc(this.sv_entnum - 1);
46         //if (e == NULL)
47         //{
48                 rgb = colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true);
49                 //rgb = '1 1 1';
50         //}
51         //else
52         //      rgb = e.glowmod;
53         rgb *= (1 + autocvar_cl_vaporizerbeam_colorboost);
54
55         float fail = (this.nextthink - time);
56
57         Draw_VaporizerBeam_trace_callback_tex = tex;
58         Draw_VaporizerBeam_trace_callback_rnd = 0;
59         Draw_VaporizerBeam_trace_callback_rgb = rgb;
60         Draw_VaporizerBeam_trace_callback_a = bound(0, fail, 1);
61         WarpZone_TraceBox_ThroughZone(this.vorg1, '0 0 0', '0 0 0', this.vorg2, MOVE_NOTHING, NULL, NULL, Draw_VaporizerBeam_trace_callback);
62         Draw_VaporizerBeam_trace_callback_tex = string_null;
63
64         /*if(!MUTATOR_CALLHOOK(Particles_VaporizerBeam, this.vorg1, this.vorg2))
65         if(autocvar_cl_particles_oldvortexbeam && (STAT(ALLOW_OLDVORTEXBEAM) || isdemo()))
66                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), this.vorg1, this.vorg2, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
67         else
68                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), this.vorg1, this.vorg2, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);*/
69 }
70
71 NET_HANDLE(TE_CSQC_VAPORBEAMPARTICLE, bool isNew)
72 {
73         Net_Accept(vortex_beam);
74         setthink(this, SUB_Remove);
75         this.nextthink = time + bound(0, autocvar_cl_vaporizerbeam_lifetime, 10);
76         this.draw = VaporizerBeam_Draw;
77         if (isNew) IL_PUSH(g_drawables, this);
78         this.drawmask = MASK_NORMAL;
79
80         this.vorg1 = ReadVector();
81         this.vorg2 = ReadVector();
82         this.cnt = ReadByte();
83         int myowner = ReadByte();
84         this.owner = playerslots[myowner - 1];
85         this.sv_entnum = myowner;
86         this.team = ReadByte() - 1;
87
88         //pointparticles(EFFECT_VORTEX_MUZZLEFLASH, this.vorg1, normalize(this.vorg2 - this.vorg1) * 1000, 1);
89
90         if(autocvar_cl_vaporizerbeam_particle)
91         {
92                 WarpZone_TrailParticles(NULL, particleeffectnum(((this.cnt) ? EFFECT_VAPORIZER_HIT(this.team) : EFFECT_VAPORIZER(this.team))), this.vorg1, this.vorg2);
93                 this.draw = func_null;
94                 this.drawmask = MASK_NORMAL;
95                 delete(this);
96         }
97
98         return true;
99 }
100 #endif
101
102 #ifdef SVQC
103
104 void W_RocketMinsta_Explosion(entity actor, .entity weaponentity, vector loc)
105 {
106         if(accuracy_canbegooddamage(actor))
107                 accuracy_add(actor, WEP_DEVASTATOR, autocvar_g_rm_damage, 0);
108         entity dmgent = spawn();
109         dmgent.owner = dmgent.realowner = actor;
110         setorigin(dmgent, loc);
111         RadiusDamage (dmgent, actor, autocvar_g_rm_damage, autocvar_g_rm_edgedamage, autocvar_g_rm_radius, NULL, NULL, autocvar_g_rm_force, WEP_DEVASTATOR.m_id | HITTYPE_SPLASH, weaponentity, NULL);
112         delete(dmgent);
113 }
114
115 void W_Vaporizer_Attack(Weapon thiswep, entity actor, .entity weaponentity)
116 {
117         bool flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
118         float vaporizer_damage = ((WEP_CVAR_PRI(vaporizer, damage) > 0) ? WEP_CVAR_PRI(vaporizer, damage) : 10000);
119
120         W_SetupShot(actor, weaponentity, true, 0, SND_Null, CH_WEAPON_A, vaporizer_damage, thiswep.m_id);
121         // handle sound separately so we can change the volume
122         // added bonus: no longer plays the strength sound (strength gives no bonus to instakill anyway)
123         sound (actor, CH_WEAPON_A, SND_MINSTANEXFIRE, VOL_BASE * 0.8, ATTEN_NORM);
124
125         yoda = 0;
126         damage_goodhits = 0;
127         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, vaporizer_damage, WEP_CVAR_PRI(vaporizer, force), 0, 0, 0, 0, thiswep.m_id);
128
129         // do this now, as goodhits is disabled below
130         W_MuzzleFlash(actor, weaponentity, EFFECT_VORTEX_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
131         SendCSQCVaporizerBeamParticle(actor, damage_goodhits);
132
133         if(yoda && flying)
134                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
135         if(damage_goodhits && actor.vaporizer_lasthit)
136         {
137                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
138                 damage_goodhits = 0; // only every second time
139         }
140
141         actor.vaporizer_lasthit = damage_goodhits;
142
143         if(autocvar_g_rm)
144         if(!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
145                 W_RocketMinsta_Explosion(actor, weaponentity, trace_endpos);
146
147         W_DecreaseAmmo(thiswep, actor, ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)), weaponentity);
148 }
149
150 void W_RocketMinsta_Laser_Explode (entity this, entity directhitentity)
151 {
152         if(directhitentity.takedamage == DAMAGE_AIM)
153                 if(IS_PLAYER(directhitentity))
154                         if(DIFF_TEAM(this.realowner, directhitentity))
155                                 if(!IS_DEAD(directhitentity))
156                                         if(IsFlying(directhitentity))
157                                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
158
159         this.event_damage = func_null;
160         this.takedamage = DAMAGE_NO;
161         RadiusDamage (this, this.realowner, this.rm_damage, this.rm_edmg, autocvar_g_rm_laser_radius, NULL, NULL, this.rm_force, this.projectiledeathtype, this.weaponentity_fld, directhitentity);
162         delete(this);
163 }
164
165 void W_RocketMinsta_Laser_Explode_use(entity this, entity actor, entity trigger)
166 {
167         W_RocketMinsta_Laser_Explode(this, trigger); // we probably don't want trigger used here, but this matches closest to old behaviour
168 }
169
170 void W_RocketMinsta_Laser_Touch(entity this, entity toucher)
171 {
172         PROJECTILE_TOUCH(this, toucher);
173         //W_RocketMinsta_Laser_Explode ();
174         RadiusDamage(this, this.realowner, this.rm_damage, this.rm_edmg, autocvar_g_rm_laser_radius, NULL, NULL, this.rm_force, this.projectiledeathtype, this.weaponentity_fld, toucher);
175         delete(this);
176 }
177
178 void W_RocketMinsta_Attack2(entity actor, .entity weaponentity)
179 {
180         makevectors(actor.v_angle);
181
182         entity proj;
183         float counter = 0;
184         float total = autocvar_g_rm_laser_count;
185         float spread = autocvar_g_rm_laser_spread;
186         float rndspread = autocvar_g_rm_laser_spread_random;
187
188         W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_CRYLINK_FIRE, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
189
190         W_MuzzleFlash(actor, weaponentity, EFFECT_ELECTRO_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
191
192     while(counter < total)
193         {
194         proj = new(plasma_prim);
195         proj.owner = proj.realowner = actor;
196         proj.bot_dodge = true;
197         proj.bot_dodgerating = autocvar_g_rm_laser_damage;
198         proj.use = W_RocketMinsta_Laser_Explode_use;
199         setthink(proj, adaptor_think2use_hittype_splash);
200         proj.nextthink = time + autocvar_g_rm_laser_lifetime;
201         PROJECTILE_MAKETRIGGER(proj);
202         proj.projectiledeathtype = WEP_ELECTRO.m_id;
203         proj.weaponentity_fld = weaponentity;
204         setorigin(proj, w_shotorg);
205
206                 proj.rm_force = autocvar_g_rm_laser_force / total;
207                 proj.rm_damage = autocvar_g_rm_laser_damage / total;
208                 proj.rm_edmg = proj.rm_damage;
209
210         //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
211
212         set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
213         //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
214                 proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * (spread * (rndspread ? random() : 1))) * cvar("g_rm_laser_speed");
215                 proj.velocity_z = proj.velocity_z + cvar("g_rm_laser_zspread") * (random() - 0.5);
216                 proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
217         proj.angles = vectoangles(proj.velocity);
218         settouch(proj, W_RocketMinsta_Laser_Touch);
219         setsize(proj, '0 0 -3', '0 0 -3');
220         proj.flags = FL_PROJECTILE;
221         IL_PUSH(g_projectiles, proj);
222         IL_PUSH(g_bot_dodge, proj);
223         proj.missile_flags = MIF_SPLASH;
224
225         CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
226
227         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
228         counter++;
229     }
230 }
231
232 void W_RocketMinsta_Attack3 (entity actor, .entity weaponentity)
233 {
234         makevectors(actor.v_angle);
235
236         entity proj;
237         float counter = 0;
238         float total = 1;
239
240         W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_ELECTRO_FIRE2, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
241
242         W_MuzzleFlash(actor, weaponentity, EFFECT_ELECTRO_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
243
244     while(counter < total)
245         {
246         proj = new(plasma_prim);
247         proj.owner = proj.realowner = actor;
248         proj.bot_dodge = true;
249         proj.bot_dodgerating = autocvar_g_rm_laser_damage;
250         proj.use = W_RocketMinsta_Laser_Explode_use;
251         setthink(proj, adaptor_think2use_hittype_splash);
252         proj.nextthink = time + autocvar_g_rm_laser_lifetime;
253         PROJECTILE_MAKETRIGGER(proj);
254         proj.projectiledeathtype = WEP_ELECTRO.m_id;
255         proj.weaponentity_fld = weaponentity;
256         setorigin(proj, w_shotorg);
257
258                 proj.rm_force = autocvar_g_rm_laser_force / total;
259                 proj.rm_damage = autocvar_g_rm_laser_damage / total;
260                 proj.rm_edmg = proj.rm_damage;
261
262         //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
263
264         set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
265                 proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
266                 proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
267         proj.angles = vectoangles(proj.velocity);
268         settouch(proj, W_RocketMinsta_Laser_Touch);
269         setsize(proj, '0 0 -3', '0 0 -3');
270         proj.flags = FL_PROJECTILE;
271         IL_PUSH(g_projectiles, proj);
272         IL_PUSH(g_bot_dodge, proj);
273         proj.missile_flags = MIF_SPLASH;
274
275         CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
276
277         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
278         counter++;
279     }
280 }
281
282 METHOD(Vaporizer, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
283 {
284     if((actor.items & IT_UNLIMITED_AMMO) || GetResource(actor, thiswep.ammo_type) > 0)
285         PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 1, false);
286     else
287         PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false); // WEAPONTODO: replace with proper vaporizer cvars
288 }
289 METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
290 {
291     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
292     // if the laser uses load, we also consider its ammo for reloading
293     if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && actor.(weaponentity).clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) { // forced reload
294         thiswep.wr_reload(thiswep, actor, weaponentity);
295     } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
296         thiswep.wr_reload(thiswep, actor, weaponentity);
297     }
298     if((fire & 1) && (GetResource(actor, RES_CELLS) || !autocvar_g_rm) && !weaponLocked(actor))
299     {
300         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire)))
301         {
302             W_Vaporizer_Attack(thiswep, actor, weaponentity);
303             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
304         }
305     }
306     if((fire & 2) || ((fire & 1) && !GetResource(actor, RES_CELLS) && autocvar_g_rm))
307     {
308         if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
309         {
310             bool rapid = autocvar_g_rm_laser_rapid;
311             if(actor.(weaponentity).jump_interval <= time && !actor.(weaponentity).held_down)
312             {
313                 if(rapid)
314                     actor.(weaponentity).held_down = true;
315                 actor.(weaponentity).jump_interval = time + autocvar_g_rm_laser_refire;
316                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
317                 damage_goodhits = 0;
318                 W_RocketMinsta_Attack2(actor, weaponentity);
319             }
320             else if(rapid && actor.(weaponentity).jump_interval2 <= time && actor.(weaponentity).held_down)
321             {
322                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
323                 damage_goodhits = 0;
324                 W_RocketMinsta_Attack3(actor, weaponentity);
325                 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
326             }
327         }
328         else if (actor.(weaponentity).jump_interval <= time)
329         {
330             // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
331             actor.(weaponentity).jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor(actor);
332
333             // decrease ammo for the laser?
334             if(WEP_CVAR_SEC(vaporizer, ammo))
335                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(vaporizer, ammo), weaponentity);
336
337             BLASTER_SECONDARY_ATTACK(vaporizer, actor, weaponentity);
338
339             // now do normal refire
340             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
341         }
342     }
343     else
344         actor.(weaponentity).held_down = false;
345 }
346 METHOD(Vaporizer, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
347 {
348     actor.vaporizer_lasthit = 0;
349 }
350 METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
351 {
352     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
353     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= vaporizer_ammo;
354     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= vaporizer_ammo;
355     return ammo_amount;
356 }
357 METHOD(Vaporizer, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
358 {
359     if(!WEP_CVAR_SEC(vaporizer, ammo))
360         return true;
361     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(vaporizer, ammo);
362     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
363     return ammo_amount;
364 }
365 METHOD(Vaporizer, wr_resetplayer, void(entity thiswep, entity actor))
366 {
367     actor.vaporizer_lasthit = 0;
368 }
369 METHOD(Vaporizer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
370 {
371     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
372     float used_ammo;
373     if(WEP_CVAR_SEC(vaporizer, ammo))
374         used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
375     else
376         used_ammo = vaporizer_ammo;
377
378     W_Reload(actor, weaponentity, used_ammo, SND_RELOAD);
379 }
380 METHOD(Vaporizer, wr_suicidemessage, Notification(entity thiswep))
381 {
382     return WEAPON_THINKING_WITH_PORTALS;
383 }
384 METHOD(Vaporizer, wr_killmessage, Notification(entity thiswep))
385 {
386     return WEAPON_VAPORIZER_MURDER;
387 }
388
389 #endif
390 #ifdef CSQC
391
392 METHOD(Vaporizer, wr_impacteffect, void(entity thiswep, entity actor))
393 {
394     vector org2 = w_org + w_backoff * 6;
395     if(w_deathtype & HITTYPE_SECONDARY)
396     {
397         pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
398         if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
399     }
400     else
401     {
402         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
403         if(!w_issilent) { sound(actor, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM); }
404     }
405 }
406 METHOD(Vaporizer, wr_init, void(entity thiswep))
407 {
408     if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
409     {
410         precache_pic("gfx/reticle_nex");
411     }
412 }
413 METHOD(Vaporizer, wr_zoom, bool(entity thiswep, entity actor))
414 {
415     if(button_zoom || zoomscript_caught)
416     {
417         return true;
418     }
419     else
420     {
421         // no weapon specific image for this weapon
422         return false;
423     }
424 }
425
426 #endif