]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/okvortex.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / okvortex.qc
1 #include "okvortex.qh"
2
3 #ifdef SVQC
4
5 .float okvortex_lasthit;
6 #endif
7
8 #if defined(GAMEQC)
9
10 METHOD(OverkillVortex, wr_glow, vector(OverkillVortex this, entity actor, entity wepent))
11 {
12         if (!WEP_CVAR(okvortex, charge)) return '0 0 0';
13         float charge = wepent.okvortex_charge;
14         float animlimit = WEP_CVAR(okvortex, charge_animlimit);
15         vector g;
16         g.x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, charge / animlimit);
17         g.y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, charge / animlimit);
18         g.z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, charge / animlimit);
19         if (charge > animlimit)
20         {
21                 g.x += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (charge - animlimit) / (1 - animlimit);
22                 g.y += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (charge - animlimit) / (1 - animlimit);
23                 g.z += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (charge - animlimit) / (1 - animlimit);
24         }
25         return g;
26 }
27 #endif
28
29 #ifdef SVQC
30 spawnfunc(weapon_okvortex) { weapon_defaultspawnfunc(this, WEP_OVERKILL_VORTEX); }
31
32 REGISTER_MUTATOR(okvortex_charge, true);
33
34 MUTATOR_HOOKFUNCTION(okvortex_charge, GetPressedKeys)
35 {
36         entity player = M_ARGV(0, entity);
37
38         // WEAPONTODO
39         if(!WEP_CVAR(okvortex, charge) || !WEP_CVAR(okvortex, charge_velocity_rate))
40                 return;
41
42         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
43         {
44                 .entity weaponentity = weaponentities[slot];
45
46                 if (player.(weaponentity).m_weapon == WEP_OVERKILL_VORTEX && WEP_CVAR(okvortex, charge) && WEP_CVAR(okvortex, charge_velocity_rate) && vdist(vec2(player.velocity), >, WEP_CVAR(okvortex, charge_minspeed)))
47                 {
48                         float xyspeed = vlen(vec2(player.velocity));
49                         // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
50                                 xyspeed = min(xyspeed, WEP_CVAR(okvortex, charge_maxspeed));
51                         float f = (xyspeed - WEP_CVAR(okvortex, charge_minspeed)) / (WEP_CVAR(okvortex, charge_maxspeed) - WEP_CVAR(okvortex, charge_minspeed));
52                         // add the extra charge
53                         player.(weaponentity).okvortex_charge = min(1, player.(weaponentity).okvortex_charge + WEP_CVAR(okvortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
54                 }
55         }
56 }
57
58 void W_OverkillVortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
59 {
60         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
61
62         mydmg = WEP_CVAR_BOTH(okvortex, !issecondary, damage);
63         myforce = WEP_CVAR_BOTH(okvortex, !issecondary, force);
64         mymindist = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_mindist);
65         mymaxdist = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_maxdist);
66         myhalflife = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_halflife);
67         myforcehalflife = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_forcehalflife);
68         myammo = WEP_CVAR_BOTH(okvortex, !issecondary, ammo);
69
70         float flying;
71         flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
72
73         if (WEP_CVAR(okvortex, charge))
74         {
75                 charge = WEP_CVAR(okvortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(okvortex, charge_mindmg) / mydmg) * actor.(weaponentity).okvortex_charge;
76                 actor.(weaponentity).okvortex_charge *= WEP_CVAR(okvortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
77                 // O RLY? -- divVerent
78                 // YA RLY -- FruitieX
79         }
80         else
81         {
82                 charge = 1;
83         }
84         mydmg *= charge;
85         myforce *= charge;
86
87         W_SetupShot(actor, weaponentity, true, 5, SND_NEXFIRE, CH_WEAPON_A, mydmg);
88         if(charge > WEP_CVAR(okvortex, charge_animlimit) && WEP_CVAR(okvortex, charge_animlimit)) // if the OverkillVortex is overcharged, we play an extra sound
89         {
90                 sound(actor, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(okvortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(okvortex, charge_animlimit)), ATTN_NORM);
91         }
92
93         yoda = 0;
94         damage_goodhits = 0;
95         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_OVERKILL_VORTEX.m_id);
96
97         if(yoda && flying)
98                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
99         if(damage_goodhits && actor.okvortex_lasthit)
100         {
101                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
102                 damage_goodhits = 0; // only every second time
103         }
104
105         actor.okvortex_lasthit = damage_goodhits;
106
107         //beam and muzzle flash done on client
108         SendCSQCVortexBeamParticle(charge);
109
110         W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
111 }
112
113 .float okvortex_chargepool_pauseregen_finished;
114
115 METHOD(OverkillVortex, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
116 {
117         if(bot_aim(actor, weaponentity, 1000000, 0, 1, false))
118                 PHYS_INPUT_BUTTON_ATCK(actor) = true;
119         else
120         {
121                 if(WEP_CVAR(okvortex, charge))
122                         PHYS_INPUT_BUTTON_ATCK2(actor) = true;
123         }
124 }
125
126 METHOD(OverkillVortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
127 {
128         if (WEP_CVAR(okvortex, charge) && actor.(weaponentity).okvortex_charge < WEP_CVAR(okvortex, charge_limit))
129         {
130                 actor.(weaponentity).okvortex_charge = min(1, actor.(weaponentity).okvortex_charge + WEP_CVAR(okvortex, charge_rate) * frametime / W_TICSPERFRAME);
131         }
132
133         if (weaponslot(weaponentity) == 0)
134         {
135                 actor.okvortex_charge = actor.(weaponentity).okvortex_charge;
136         }
137
138         if (WEP_CVAR_SEC(okvortex, chargepool))
139                 if (actor.(weaponentity).okvortex_chargepool_ammo < 1)
140                 {
141                         if (actor.okvortex_chargepool_pauseregen_finished < time)
142                                 actor.(weaponentity).okvortex_chargepool_ammo = min(1, actor.(weaponentity).okvortex_chargepool_ammo + WEP_CVAR_SEC(okvortex, chargepool_regen) * frametime / W_TICSPERFRAME);
143                         actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(okvortex, chargepool_pause_regen));
144                 }
145
146         if(weaponslot(weaponentity) == 0)
147                 actor.okvortex_chargepool_ammo = actor.(weaponentity).okvortex_chargepool_ammo;
148
149         if ((WEP_CVAR_SEC(okvortex, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
150         {
151                 // Secondary uses it's own refire timer if refire_type is 1.
152                 actor.jump_interval = time + WEP_CVAR_SEC(okvortex, refire) * W_WeaponRateFactor(actor);
153                 // Ugly hack to reuse the fire mode of the blaster.
154                 makevectors(actor.v_angle);
155                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
156                 actor.(weaponentity).m_weapon = WEP_BLASTER;
157                 W_Blaster_Attack(
158                         actor,
159                         weaponentity,
160                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
161                         WEP_CVAR_SEC(okvortex, shotangle),
162                         WEP_CVAR_SEC(okvortex, damage),
163                         WEP_CVAR_SEC(okvortex, edgedamage),
164                         WEP_CVAR_SEC(okvortex, radius),
165                         WEP_CVAR_SEC(okvortex, force),
166                         WEP_CVAR_SEC(okvortex, speed),
167                         WEP_CVAR_SEC(okvortex, spread),
168                         WEP_CVAR_SEC(okvortex, delay),
169                         WEP_CVAR_SEC(okvortex, lifetime)
170                 );
171                 actor.(weaponentity).m_weapon = oldwep;
172                 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
173                         (actor.(weaponentity).wframe == WFRAME_FIRE2))
174                 {
175                         // Set secondary fire animation.
176                         vector a = '0 0 0';
177                         actor.(weaponentity).wframe = WFRAME_FIRE2;
178                         a = actor.(weaponentity).anim_fire2;
179                         a.z *= g_weaponratefactor;
180                         FOREACH_CLIENT(true, LAMBDA(
181                                 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
182                                 {
183                                         wframe_send(it, actor.(weaponentity), a, true);
184                                 }
185                         ));
186                         animdecide_setaction(actor, ANIMACTION_SHOOT, true);
187                 }
188         }
189
190         if (autocvar_g_balance_okvortex_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR_PRI(okvortex, ammo))
191         {
192                 // Rorced reload
193                 thiswep.wr_reload(thiswep, actor, weaponentity);
194                 return;
195         }
196         if (fire & 1) // Primary attack
197         {
198                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(okvortex, refire)))
199                 {
200                         return;
201                 }
202                 W_OverkillVortex_Attack(thiswep, actor, weaponentity, 0);
203                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(okvortex, animtime), w_ready);
204                 return;
205         }
206         if ((fire & 2) && (WEP_CVAR(okvortex, secondary) == 2) && (WEP_CVAR_SEC(okvortex, refire_type) == 0))
207         {
208                 // Secondary attack
209                 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okshotgun, refire)))
210                 {
211                         return;
212                 }
213                 // ugly instagib hack to reuse the fire mode of the laser
214                 makevectors(actor.v_angle);
215                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
216                 actor.(weaponentity).m_weapon = WEP_BLASTER;
217                 W_Blaster_Attack(
218                         actor,
219                         weaponentity,
220                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
221                         WEP_CVAR_SEC(okvortex, shotangle),
222                         WEP_CVAR_SEC(okvortex, damage),
223                         WEP_CVAR_SEC(okvortex, edgedamage),
224                         WEP_CVAR_SEC(okvortex, radius),
225                         WEP_CVAR_SEC(okvortex, force),
226                         WEP_CVAR_SEC(okvortex, speed),
227                         WEP_CVAR_SEC(okvortex, spread),
228                         WEP_CVAR_SEC(okvortex, delay),
229                         WEP_CVAR_SEC(okvortex, lifetime)
230                 );
231                 actor.(weaponentity).m_weapon = oldwep;
232                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okvortex, animtime), w_ready);
233                 return;
234         }
235         //if ((WEP_CVAR(okvortex, charge) && (WEP_CVAR(okvortex, secondary) == 1)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
236         //{
237         //      if(WEP_CVAR(okvortex, charge))
238         //      {
239         //              actor.(weaponentity).okvortex_charge_rottime = time + WEP_CVAR(okvortex, charge_rot_pause);
240         //              float dt = frametime / W_TICSPERFRAME;
241         //
242         //              if(actor.(weaponentity).okvortex_charge < 1)
243         //              {
244         //                      if(WEP_CVAR_SEC(okvortex, chargepool))
245         //                      {
246         //                              if(WEP_CVAR_SEC(okvortex, ammo))
247         //                              {
248         //                                      // always deplete if secondary is held
249         //                                      actor.okvortex_chargepool_ammo = max(0, actor.okvortex_chargepool_ammo - WEP_CVAR_SEC(okvortex, ammo) * dt);
250
251         //                                      dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
252         //                                      actor.okvortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(okvortex, chargepool_pause_regen);
253         //                                      dt = min(dt, actor.okvortex_chargepool_ammo);
254         //                                      dt = max(0, dt);
255
256         //                                      actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
257         //                              }
258         //                      }
259
260         //                      else if(WEP_CVAR_SEC(okvortex, ammo))
261         //                      {
262         //                              if(fire & 2) // only eat ammo when the button is pressed
263         //                              {
264         //                                      dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
265         //                                      if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
266         //                                      {
267         //                                              // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
268         //                                              if(autocvar_g_balance_vortex_reload_ammo)
269         //                                              {
270         //                                                      dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(okvortex, ammo)) / WEP_CVAR_SEC(okvortex, ammo));
271         //                                                      dt = max(0, dt);
272         //                                                      if(dt > 0)
273         //                                                      {
274         //                                                              actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(okvortex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(okvortex, ammo) * dt);
275         //                                                      }
276         //                                                      actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) = actor.(weaponentity).clip_load;
277         //                                              }
278         //                                              else
279         //                                              {
280         //                                                      dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(okvortex, ammo)) / WEP_CVAR_SEC(okvortex, ammo));
281         //                                                      dt = max(0, dt);
282         //                                                      if(dt > 0)
283         //                                                      {
284         //                                                              actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(okvortex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(okvortex, ammo) * dt);
285         //                                                      }
286         //                                              }
287         //                                      }
288         //                                      actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
289         //                              }
290         //                      }
291
292         //                      else
293         //                      {
294         //                              dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
295         //                              actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
296         //                      }
297         //              }
298         //      }
299         //      else if(WEP_CVAR(okvortex, secondary))
300         //      {
301         //              if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okvortex, refire)))
302         //              {
303         //                      W_OverkillVortex_Attack(thiswep, actor, weaponentity, 1);
304         //                      weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(okvortex, animtime), w_ready);
305         //              }
306         //      }
307         //}
308 }
309
310 METHOD(OverkillVortex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
311 {
312         actor.okvortex_lasthit = 0;
313 }
314
315 METHOD(OverkillVortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
316 {
317         float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(okvortex, ammo);
318         ammo_amount += (autocvar_g_balance_okvortex_reload_ammo && actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) >= WEP_CVAR_PRI(okvortex, ammo));
319         return ammo_amount;
320 }
321
322 METHOD(OverkillVortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
323 {
324         if(WEP_CVAR(okvortex, secondary))
325         {
326                 // don't allow charging if we don't have enough ammo
327                 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(okvortex, ammo);
328                 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) >= WEP_CVAR_SEC(okvortex, ammo);
329                 return ammo_amount;
330         }
331         else
332         {
333                 return false; // zoom is not a fire mode
334         }
335 }
336
337 METHOD(OverkillVortex, wr_resetplayer, void(entity thiswep, entity actor))
338 {
339         if (WEP_CVAR(okvortex, charge)) {
340                 if (WEP_CVAR_SEC(okvortex, chargepool)) {
341                         actor.okvortex_chargepool_ammo = 1;
342                 }
343                 actor.okvortex_charge = WEP_CVAR(okvortex, charge_start);
344                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
345                 {
346                         .entity weaponentity = weaponentities[slot];
347                         actor.(weaponentity).okvortex_charge = WEP_CVAR(okvortex, charge_start);
348
349                         if (WEP_CVAR_SEC(okvortex, chargepool))
350                                 actor.(weaponentity).okvortex_chargepool_ammo = 1;
351                 }
352         }
353         actor.okvortex_lasthit = 0;
354 }
355
356 METHOD(OverkillVortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
357 {
358         W_Reload(actor, weaponentity, WEP_CVAR_PRI(okvortex, ammo), SND_RELOAD);
359 }
360
361 METHOD(OverkillVortex, wr_suicidemessage, Notification(entity thiswep))
362 {
363         return WEAPON_THINKING_WITH_PORTALS;
364 }
365
366 METHOD(OverkillVortex, wr_killmessage, Notification(entity thiswep))
367 {
368         return WEAPON_VORTEX_MURDER;
369 }
370
371 METHOD(OverkillVortex, wr_zoom, bool(entity thiswep, entity actor))
372 {
373         return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(okvortex, secondary);
374 }
375
376 #endif
377 #ifdef CSQC
378
379 METHOD(OverkillVortex, wr_impacteffect, void(entity thiswep, entity actor))
380 {
381         entity this = actor;
382         vector org2 = w_org + w_backoff * 6;
383         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
384         if(!w_issilent)
385                 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
386 }
387
388 METHOD(OverkillVortex, wr_init, void(entity thiswep))
389 {
390         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
391         {
392                 precache_pic("gfx/reticle_nex");
393         }
394 }
395
396 METHOD(OverkillVortex, wr_zoom, bool(entity thiswep, entity actor))
397 {
398         if(button_zoom || zoomscript_caught || (!WEP_CVAR(okvortex, secondary) && button_attack2))
399         {
400                 return true;
401         }
402         else
403         {
404                 // no weapon specific image for this weapon
405                 return false;
406         }
407 }
408
409 #endif