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