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