1 #include "vaporizer.qh"
3 REGISTER_NET_TEMP(TE_CSQC_VAPORBEAMPARTICLE)
6 void SendCSQCVaporizerBeamParticle(entity player, int hit) {
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);
21 bool autocvar_cl_vaporizerbeam_particle = false;
22 float autocvar_cl_vaporizerbeam_lifetime = 0.8;
23 float autocvar_cl_vaporizerbeam_colorboost = 0.7;
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)
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;
41 void VaporizerBeam_Draw(entity this)
43 //draw either the old v2.3 beam or the new beam
44 particles_alphamin = particles_alphamax = particles_fade = 1;
46 string tex = "particles/lgbeam";
48 tex = "particles/gauntletbeam";
50 //entity e = CSQCModel_server2csqc(this.sv_entnum - 1);
53 rgb = colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true);
58 rgb *= (1 + autocvar_cl_vaporizerbeam_colorboost);
60 float fail = (this.nextthink - time);
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;
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);
73 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), this.vorg1, this.vorg2, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);*/
76 NET_HANDLE(TE_CSQC_VAPORBEAMPARTICLE, bool isNew)
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;
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;
93 pointparticles(EFFECT_VORTEX_MUZZLEFLASH, this.vorg1, normalize(this.vorg2 - this.vorg1) * 1000, 1);
95 if(autocvar_cl_vaporizerbeam_particle)
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;
109 void W_RocketMinsta_Explosion(entity actor, .entity weaponentity, vector loc)
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);
120 void W_Vaporizer_Attack(Weapon thiswep, entity actor, .entity weaponentity)
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);
125 W_SetupShot(actor, weaponentity, true, 0, SND_Null, CH_WEAPON_A, vaporizer_damage);
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);
132 FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, vaporizer_damage, 800, 0, 0, 0, 0, WEP_VAPORIZER.m_id);
134 // do this now, as goodhits is disabled below
135 SendCSQCVaporizerBeamParticle(actor, damage_goodhits);
138 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
139 if(damage_goodhits && actor.vaporizer_lasthit)
141 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
142 damage_goodhits = 0; // only every second time
145 actor.vaporizer_lasthit = damage_goodhits;
148 if(!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
149 W_RocketMinsta_Explosion(actor, weaponentity, trace_endpos);
151 W_DecreaseAmmo(thiswep, actor, ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)), weaponentity);
154 void W_RocketMinsta_Laser_Explode (entity this, entity directhitentity)
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);
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);
169 void W_RocketMinsta_Laser_Explode_use(entity this, entity actor, entity trigger)
171 W_RocketMinsta_Laser_Explode(this, trigger); // we probably don't want trigger used here, but this matches closest to old behaviour
174 void W_RocketMinsta_Laser_Touch(entity this, entity toucher)
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);
182 void W_RocketMinsta_Attack2(entity actor, .entity weaponentity)
184 makevectors(actor.v_angle);
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;
192 Weapon w = actor.(weaponentity).m_weapon;
193 actor.(weaponentity).m_weapon = WEP_ELECTRO;
194 W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_CRYLINK_FIRE, CH_WEAPON_A, autocvar_g_rm_laser_damage);
195 actor.(weaponentity).m_weapon = w;
197 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
199 while(counter < total)
201 proj = new(plasma_prim);
202 proj.owner = proj.realowner = actor;
203 proj.bot_dodge = true;
204 proj.bot_dodgerating = autocvar_g_rm_laser_damage;
205 proj.use = W_RocketMinsta_Laser_Explode_use;
206 setthink(proj, adaptor_think2use_hittype_splash);
207 proj.nextthink = time + autocvar_g_rm_laser_lifetime;
208 PROJECTILE_MAKETRIGGER(proj);
209 proj.projectiledeathtype = WEP_ELECTRO.m_id;
210 proj.weaponentity_fld = weaponentity;
211 setorigin(proj, w_shotorg);
213 proj.rm_force = autocvar_g_rm_laser_force / total;
214 proj.rm_damage = autocvar_g_rm_laser_damage / total;
215 proj.rm_edmg = proj.rm_damage;
217 //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
219 set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
220 //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
221 proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * (spread * (rndspread ? random() : 1))) * cvar("g_rm_laser_speed");
222 proj.velocity_z = proj.velocity_z + cvar("g_rm_laser_zspread") * (random() - 0.5);
223 proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
224 proj.angles = vectoangles(proj.velocity);
225 settouch(proj, W_RocketMinsta_Laser_Touch);
226 setsize(proj, '0 0 -3', '0 0 -3');
227 proj.flags = FL_PROJECTILE;
228 IL_PUSH(g_projectiles, proj);
229 IL_PUSH(g_bot_dodge, proj);
230 proj.missile_flags = MIF_SPLASH;
232 CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
234 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
239 void W_RocketMinsta_Attack3 (entity actor, .entity weaponentity)
241 makevectors(actor.v_angle);
247 Weapon w = actor.(weaponentity).m_weapon;
248 actor.(weaponentity).m_weapon = WEP_ELECTRO;
249 W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_ELECTRO_FIRE2, CH_WEAPON_A, autocvar_g_rm_laser_damage);
250 actor.(weaponentity).m_weapon = w;
252 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
254 while(counter < total)
256 proj = new(plasma_prim);
257 proj.owner = proj.realowner = actor;
258 proj.bot_dodge = true;
259 proj.bot_dodgerating = autocvar_g_rm_laser_damage;
260 proj.use = W_RocketMinsta_Laser_Explode_use;
261 setthink(proj, adaptor_think2use_hittype_splash);
262 proj.nextthink = time + autocvar_g_rm_laser_lifetime;
263 PROJECTILE_MAKETRIGGER(proj);
264 proj.projectiledeathtype = WEP_ELECTRO.m_id;
265 proj.weaponentity_fld = weaponentity;
266 setorigin(proj, w_shotorg);
268 proj.rm_force = autocvar_g_rm_laser_force / total;
269 proj.rm_damage = autocvar_g_rm_laser_damage / total;
270 proj.rm_edmg = proj.rm_damage;
272 //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
274 set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
275 proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
276 proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
277 proj.angles = vectoangles(proj.velocity);
278 settouch(proj, W_RocketMinsta_Laser_Touch);
279 setsize(proj, '0 0 -3', '0 0 -3');
280 proj.flags = FL_PROJECTILE;
281 IL_PUSH(g_projectiles, proj);
282 IL_PUSH(g_bot_dodge, proj);
283 proj.missile_flags = MIF_SPLASH;
285 CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
287 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
292 METHOD(Vaporizer, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
294 if(GetResourceAmount(actor, thiswep.ammo_type) > 0)
295 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 1, false);
297 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
299 METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
301 float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
302 // if the laser uses load, we also consider its ammo for reloading
303 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
304 thiswep.wr_reload(thiswep, actor, weaponentity);
305 } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
306 thiswep.wr_reload(thiswep, actor, weaponentity);
308 if((fire & 1) && (actor.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(actor))
310 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire)))
312 W_Vaporizer_Attack(thiswep, actor, weaponentity);
313 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
316 if((fire & 2) || ((fire & 1) && !actor.ammo_cells && autocvar_g_rm))
318 if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
320 bool rapid = autocvar_g_rm_laser_rapid;
321 if(actor.(weaponentity).jump_interval <= time && !actor.(weaponentity).held_down)
324 actor.(weaponentity).held_down = true;
325 actor.(weaponentity).jump_interval = time + autocvar_g_rm_laser_refire;
326 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
328 W_RocketMinsta_Attack2(actor, weaponentity);
330 else if(rapid && actor.(weaponentity).jump_interval2 <= time && actor.(weaponentity).held_down)
332 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
334 W_RocketMinsta_Attack3(actor, weaponentity);
335 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
338 else if (actor.(weaponentity).jump_interval <= time)
340 // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
341 actor.(weaponentity).jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor(actor);
343 // decrease ammo for the laser?
344 if(WEP_CVAR_SEC(vaporizer, ammo))
345 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(vaporizer, ammo), weaponentity);
347 // ugly instagib hack to reuse the fire mode of the laser
348 makevectors(actor.v_angle);
349 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
350 actor.(weaponentity).m_weapon = WEP_BLASTER;
354 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
355 WEP_CVAR_SEC(vaporizer, shotangle),
356 WEP_CVAR_SEC(vaporizer, damage),
357 WEP_CVAR_SEC(vaporizer, edgedamage),
358 WEP_CVAR_SEC(vaporizer, radius),
359 WEP_CVAR_SEC(vaporizer, force),
360 WEP_CVAR_SEC(vaporizer, speed),
361 WEP_CVAR_SEC(vaporizer, spread),
362 WEP_CVAR_SEC(vaporizer, delay),
363 WEP_CVAR_SEC(vaporizer, lifetime)
365 actor.(weaponentity).m_weapon = oldwep;
367 // now do normal refire
368 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
372 actor.(weaponentity).held_down = false;
374 METHOD(Vaporizer, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
376 actor.vaporizer_lasthit = 0;
378 METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
380 float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
381 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= vaporizer_ammo;
382 ammo_amount += actor.(weaponentity).(weapon_load[WEP_VAPORIZER.m_id]) >= vaporizer_ammo;
385 METHOD(Vaporizer, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
387 if(!WEP_CVAR_SEC(vaporizer, ammo))
389 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(vaporizer, ammo);
390 ammo_amount += actor.(weaponentity).(weapon_load[WEP_VAPORIZER.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
393 METHOD(Vaporizer, wr_resetplayer, void(entity thiswep, entity actor))
395 actor.vaporizer_lasthit = 0;
397 METHOD(Vaporizer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
399 float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
401 if(WEP_CVAR_SEC(vaporizer, ammo))
402 used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
404 used_ammo = vaporizer_ammo;
406 W_Reload(actor, weaponentity, used_ammo, SND_RELOAD);
408 METHOD(Vaporizer, wr_suicidemessage, Notification(entity thiswep))
410 return WEAPON_THINKING_WITH_PORTALS;
412 METHOD(Vaporizer, wr_killmessage, Notification(entity thiswep))
414 return WEAPON_VAPORIZER_MURDER;
420 METHOD(Vaporizer, wr_impacteffect, void(entity thiswep, entity actor))
422 vector org2 = w_org + w_backoff * 6;
423 if(w_deathtype & HITTYPE_SECONDARY)
425 pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
426 if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
430 pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
431 if(!w_issilent) { sound(actor, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM); }
434 METHOD(Vaporizer, wr_init, void(entity thiswep))
436 if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
438 precache_pic("gfx/reticle_nex");
441 METHOD(Vaporizer, wr_zoom, bool(entity thiswep, entity actor))
443 if(button_zoom || zoomscript_caught)
449 // no weapon specific image for this weapon