3 //REGISTER_STAT(WEP_CVAR_vortex_charge, bool, WEP_CVAR(vortex, charge))
4 //REGISTER_STAT(WEP_CVAR_vortex_charge_animlimit, float, WEP_CVAR(vortex, charge_animlimit))
7 METHOD(Vortex, wr_glow, vector(Vortex this, int actor_colors, entity wepent))
9 if (!WEP_CVAR(vortex, charge)) return '0 0 0';
10 float charge = max(0.25, wepent.vortex_charge);
11 float animlimit = WEP_CVAR(vortex, charge_animlimit);
12 float f = min(1, charge / animlimit);
13 vector mycolors = colormapPaletteColor(actor_colors & 0x0F, true);
14 vector g = f * (mycolors * 0.3);
15 if (charge > animlimit)
17 f = (charge - animlimit) / (1 - animlimit);
18 g += f * (mycolors * 0.7);
20 // transition color can't be '0 0 0' as it defaults to player model glow color
27 REGISTER_NET_TEMP(TE_CSQC_VORTEXBEAMPARTICLE)
30 void SendCSQCVortexBeamParticle(float charge) {
32 v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
33 WriteHeader(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
34 WriteVector(MSG_BROADCAST, w_shotorg);
35 WriteVector(MSG_BROADCAST, v);
36 WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
39 NET_HANDLE(TE_CSQC_VORTEXBEAMPARTICLE, bool isNew)
42 vector shotorg = ReadVector();
43 vector endpos = ReadVector();
44 charge = ReadByte() / 255.0;
46 //pointparticles(EFFECT_VORTEX_MUZZLEFLASH, shotorg, normalize(endpos - shotorg) * 1000, 1);
48 //draw either the old v2.3 beam or the new beam
49 charge = sqrt(charge); // divide evenly among trail spacing and alpha
50 particles_alphamin = particles_alphamax = particles_fade = charge;
52 if(!MUTATOR_CALLHOOK(Particles_VortexBeam, shotorg, endpos))
54 if(autocvar_cl_particles_oldvortexbeam)
55 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
57 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
65 REGISTER_MUTATOR(vortex_charge, true);
67 MUTATOR_HOOKFUNCTION(vortex_charge, GetPressedKeys)
69 entity player = M_ARGV(0, entity);
72 if(!WEP_CVAR(vortex, charge) || !WEP_CVAR(vortex, charge_velocity_rate))
75 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
77 .entity weaponentity = weaponentities[slot];
79 if (player.(weaponentity).m_weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && vdist(vec2(player.velocity), >, WEP_CVAR(vortex, charge_minspeed)))
81 float xyspeed = vlen(vec2(player.velocity));
82 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
83 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
84 float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
85 // add the extra charge
86 player.(weaponentity).vortex_charge = min(1, player.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
91 void W_Vortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
93 float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
95 mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
96 myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
97 mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
98 mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
99 myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
100 myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
101 myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
103 float dtype = thiswep.m_id;
104 if(WEP_CVAR_BOTH(vortex, !issecondary, armorpierce))
105 dtype |= HITTYPE_ARMORPIERCE;
108 flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
110 if(WEP_CVAR(vortex, charge))
112 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * actor.(weaponentity).vortex_charge;
113 actor.(weaponentity).vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
114 // O RLY? -- divVerent
115 // YA RLY -- FruitieX
122 W_SetupShot(actor, weaponentity, true, 5, SND_NEXFIRE, CH_WEAPON_A, mydmg, dtype);
123 if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
125 sound(actor, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(vortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(vortex, charge_animlimit)), ATTN_NORM);
130 FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, mydmg, false, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, dtype);
133 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
134 if(impressive_hits && actor.vortex_lasthit)
136 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
137 impressive_hits = 0; // only every second time
140 actor.vortex_lasthit = impressive_hits;
142 //beam done on client
143 vector v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
144 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, normalize(v - w_shotorg));
145 SendCSQCVortexBeamParticle(charge);
147 W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
150 .float vortex_chargepool_pauseregen_finished;
152 void W_Vortex_Charge(entity actor, .entity weaponentity, float dt)
154 if(WEP_CVAR(vortex, charge) && actor.(weaponentity).vortex_charge < WEP_CVAR(vortex, charge_limit))
155 actor.(weaponentity).vortex_charge = min(1, actor.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_rate) * dt);
158 METHOD(Vortex, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
160 if(bot_aim(actor, weaponentity, 1000000, 0, 1, false, true))
161 PHYS_INPUT_BUTTON_ATCK(actor) = true;
163 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
165 if(!WEP_CVAR(vortex, charge_always))
166 W_Vortex_Charge(actor, weaponentity, frametime / W_TICSPERFRAME);
168 if(WEP_CVAR_SEC(vortex, chargepool))
169 if(actor.(weaponentity).vortex_chargepool_ammo < 1)
171 if(actor.vortex_chargepool_pauseregen_finished < time)
172 actor.(weaponentity).vortex_chargepool_ammo = min(1, actor.(weaponentity).vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
173 actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
176 if(autocvar_g_balance_vortex_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
177 thiswep.wr_reload(thiswep, actor, weaponentity);
182 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
184 W_Vortex_Attack(thiswep, actor, weaponentity, 0);
185 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
188 if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
190 if(WEP_CVAR(vortex, charge))
192 actor.(weaponentity).vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
193 float dt = frametime / W_TICSPERFRAME;
195 if(actor.(weaponentity).vortex_charge < 1)
197 if(WEP_CVAR_SEC(vortex, chargepool))
199 if(WEP_CVAR_SEC(vortex, ammo))
201 // always deplete if secondary is held
202 actor.(weaponentity).vortex_chargepool_ammo = max(0, actor.(weaponentity).vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
204 dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
205 actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
206 dt = min(dt, actor.(weaponentity).vortex_chargepool_ammo);
209 actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
213 else if(WEP_CVAR_SEC(vortex, ammo))
215 if(fire & 2) // only eat ammo when the button is pressed
217 dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
218 if(!(actor.items & IT_UNLIMITED_AMMO))
220 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
221 if(autocvar_g_balance_vortex_reload_ammo)
223 dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
227 actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
229 actor.(weaponentity).(weapon_load[thiswep.m_id]) = actor.(weaponentity).clip_load;
233 dt = min(dt, (GetResource(actor, thiswep.ammo_type) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
237 SetResource(actor, thiswep.ammo_type, max(WEP_CVAR_SEC(vortex, ammo), GetResource(actor, thiswep.ammo_type) - WEP_CVAR_SEC(vortex, ammo) * dt));
241 actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
247 dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
248 actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
252 else if(WEP_CVAR(vortex, secondary))
254 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
256 W_Vortex_Attack(thiswep, actor, weaponentity, 1);
257 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
263 METHOD(Vortex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
265 actor.vortex_lasthit = 0;
267 METHOD(Vortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
269 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(vortex, ammo);
270 ammo_amount += (autocvar_g_balance_vortex_reload_ammo && actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
273 METHOD(Vortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
275 if(WEP_CVAR(vortex, secondary))
277 // don't allow charging if we don't have enough ammo
278 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(vortex, ammo);
279 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
284 return false; // zoom is not a fire mode
287 METHOD(Vortex, wr_resetplayer, void(entity thiswep, entity actor))
289 if (WEP_CVAR(vortex, charge)) {
290 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
292 .entity weaponentity = weaponentities[slot];
293 actor.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start);
295 if (WEP_CVAR_SEC(vortex, chargepool))
296 actor.(weaponentity).vortex_chargepool_ammo = 1;
299 actor.vortex_lasthit = 0;
301 METHOD(Vortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
303 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND_RELOAD);
305 METHOD(Vortex, wr_suicidemessage, Notification(entity thiswep))
307 return WEAPON_THINKING_WITH_PORTALS;
309 METHOD(Vortex, wr_killmessage, Notification(entity thiswep))
311 return WEAPON_VORTEX_MURDER;
313 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
315 return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(vortex, secondary);
321 METHOD(Vortex, wr_impacteffect, void(entity thiswep, entity actor))
324 vector org2 = w_org + w_backoff * 6;
325 pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
327 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
329 METHOD(Vortex, wr_init, void(entity thiswep))
331 if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
333 precache_pic("gfx/reticle_nex");
336 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
338 if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
344 // no weapon specific image for this weapon
348 METHOD(Vortex, wr_zoomdir, bool(entity thiswep))
350 return button_attack2 && !WEP_CVAR(vortex, secondary);