]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
Use the player's color for Vortex charging instead of predefined colors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
1 #include "vortex.qh"
2
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))
5
6 #if defined(GAMEQC)
7 METHOD(Vortex, wr_glow, vector(Vortex this, int actor_colors, entity wepent))
8 {
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)
16         {
17                 f = (charge - animlimit) / (1 - animlimit);
18                 g += f * (mycolors * 0.7);
19         }
20         // transition color can't be '0 0 0' as it defaults to player model glow color
21         if (g == '0 0 0')
22                 g = '0 0 0.000001';
23         return g;
24 }
25 #endif
26
27 REGISTER_NET_TEMP(TE_CSQC_VORTEXBEAMPARTICLE)
28
29 #if defined(SVQC)
30 void SendCSQCVortexBeamParticle(float charge) {
31         vector v;
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));
37 }
38 #elif defined(CSQC)
39 NET_HANDLE(TE_CSQC_VORTEXBEAMPARTICLE, bool isNew)
40 {
41         float charge;
42         vector shotorg = ReadVector();
43         vector endpos = ReadVector();
44         charge = ReadByte() / 255.0;
45
46         //pointparticles(EFFECT_VORTEX_MUZZLEFLASH, shotorg, normalize(endpos - shotorg) * 1000, 1);
47
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;
51
52         if(!MUTATOR_CALLHOOK(Particles_VortexBeam, shotorg, endpos))
53         {
54                 if(autocvar_cl_particles_oldvortexbeam)
55                         WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
56                 else
57                         WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
58         }
59         return true;
60 }
61 #endif
62
63 #ifdef SVQC
64
65 REGISTER_MUTATOR(vortex_charge, true);
66
67 MUTATOR_HOOKFUNCTION(vortex_charge, GetPressedKeys)
68 {
69         entity player = M_ARGV(0, entity);
70
71         // WEAPONTODO
72         if(!WEP_CVAR(vortex, charge) || !WEP_CVAR(vortex, charge_velocity_rate))
73                 return;
74
75         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
76         {
77                 .entity weaponentity = weaponentities[slot];
78
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)))
80                 {
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);
87                 }
88         }
89 }
90
91 void W_Vortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
92 {
93         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
94
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);
102
103         float dtype = thiswep.m_id;
104         if(WEP_CVAR_BOTH(vortex, !issecondary, armorpierce))
105                 dtype |= HITTYPE_ARMORPIERCE;
106
107         float flying;
108         flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
109
110         if(WEP_CVAR(vortex, charge))
111         {
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
116         }
117         else
118                 charge = 1;
119         mydmg *= charge;
120         myforce *= charge;
121
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
124         {
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);
126         }
127
128         yoda = 0;
129         impressive_hits = 0;
130         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, mydmg, false, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, dtype);
131
132         if(yoda && flying)
133                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
134         if(impressive_hits && actor.vortex_lasthit)
135         {
136                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
137                 impressive_hits = 0; // only every second time
138         }
139
140         actor.vortex_lasthit = impressive_hits;
141
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);
146
147         W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
148 }
149
150 .float vortex_chargepool_pauseregen_finished;
151
152 void W_Vortex_Charge(entity actor, .entity weaponentity, float dt)
153 {
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);
156 }
157
158 METHOD(Vortex, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
159 {
160         if(bot_aim(actor, weaponentity, 1000000, 0, 1, false, true))
161                 PHYS_INPUT_BUTTON_ATCK(actor) = true;
162 }
163 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
164 {
165         if(!WEP_CVAR(vortex, charge_always))
166                 W_Vortex_Charge(actor, weaponentity, frametime / W_TICSPERFRAME);
167
168         if(WEP_CVAR_SEC(vortex, chargepool))
169                 if(actor.(weaponentity).vortex_chargepool_ammo < 1)
170                 {
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));
174                 }
175
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);
178         } else
179         {
180                 if(fire & 1)
181                 {
182                         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
183                         {
184                                 W_Vortex_Attack(thiswep, actor, weaponentity, 0);
185                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
186                         }
187                 }
188                 if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
189                 {
190                         if(WEP_CVAR(vortex, charge))
191                         {
192                                 actor.(weaponentity).vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
193                                 float dt = frametime / W_TICSPERFRAME;
194
195                                 if(actor.(weaponentity).vortex_charge < 1)
196                                 {
197                                         if(WEP_CVAR_SEC(vortex, chargepool))
198                                         {
199                                                 if(WEP_CVAR_SEC(vortex, ammo))
200                                                 {
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);
203
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);
207                                                         dt = max(0, dt);
208
209                                                         actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
210                                                 }
211                                         }
212
213                                         else if(WEP_CVAR_SEC(vortex, ammo))
214                                         {
215                                                 if(fire & 2) // only eat ammo when the button is pressed
216                                                 {
217                                                         dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
218                                                         if(!(actor.items & IT_UNLIMITED_AMMO))
219                                                         {
220                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
221                                                                 if(autocvar_g_balance_vortex_reload_ammo)
222                                                                 {
223                                                                         dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
224                                                                         dt = max(0, dt);
225                                                                         if(dt > 0)
226                                                                         {
227                                                                                 actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
228                                                                         }
229                                                                         actor.(weaponentity).(weapon_load[thiswep.m_id]) = actor.(weaponentity).clip_load;
230                                                                 }
231                                                                 else
232                                                                 {
233                                                                         dt = min(dt, (GetResource(actor, thiswep.ammo_type) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
234                                                                         dt = max(0, dt);
235                                                                         if(dt > 0)
236                                                                         {
237                                                                                 SetResource(actor, thiswep.ammo_type, max(WEP_CVAR_SEC(vortex, ammo), GetResource(actor, thiswep.ammo_type) - WEP_CVAR_SEC(vortex, ammo) * dt));
238                                                                         }
239                                                                 }
240                                                         }
241                                                         actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
242                                                 }
243                                         }
244
245                                         else
246                                         {
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);
249                                         }
250                                 }
251                         }
252                         else if(WEP_CVAR(vortex, secondary))
253                         {
254                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
255                                 {
256                                         W_Vortex_Attack(thiswep, actor, weaponentity, 1);
257                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
258                                 }
259                         }
260                 }
261         }
262 }
263 METHOD(Vortex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
264 {
265         actor.vortex_lasthit = 0;
266 }
267 METHOD(Vortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
268 {
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));
271         return ammo_amount;
272 }
273 METHOD(Vortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
274 {
275         if(WEP_CVAR(vortex, secondary))
276         {
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);
280                 return ammo_amount;
281         }
282         else
283         {
284                 return false; // zoom is not a fire mode
285         }
286 }
287 METHOD(Vortex, wr_resetplayer, void(entity thiswep, entity actor))
288 {
289         if (WEP_CVAR(vortex, charge)) {
290                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
291                 {
292                         .entity weaponentity = weaponentities[slot];
293                         actor.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start);
294
295                         if (WEP_CVAR_SEC(vortex, chargepool))
296                                 actor.(weaponentity).vortex_chargepool_ammo = 1;
297                 }
298         }
299         actor.vortex_lasthit = 0;
300 }
301 METHOD(Vortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
302 {
303         W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND_RELOAD);
304 }
305 METHOD(Vortex, wr_suicidemessage, Notification(entity thiswep))
306 {
307         return WEAPON_THINKING_WITH_PORTALS;
308 }
309 METHOD(Vortex, wr_killmessage, Notification(entity thiswep))
310 {
311         return WEAPON_VORTEX_MURDER;
312 }
313 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
314 {
315         return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(vortex, secondary);
316 }
317
318 #endif
319 #ifdef CSQC
320
321 METHOD(Vortex, wr_impacteffect, void(entity thiswep, entity actor))
322 {
323         entity this = actor;
324         vector org2 = w_org + w_backoff * 6;
325         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
326         if(!w_issilent)
327                 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
328 }
329 METHOD(Vortex, wr_init, void(entity thiswep))
330 {
331         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
332         {
333                 precache_pic("gfx/reticle_nex");
334         }
335 }
336 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
337 {
338         if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
339         {
340                 return true;
341         }
342         else
343         {
344                 // no weapon specific image for this weapon
345                 return false;
346         }
347 }
348 METHOD(Vortex, wr_zoomdir, bool(entity thiswep))
349 {
350         return button_attack2 && !WEP_CVAR(vortex, secondary);
351 }
352
353 #endif