Xonotic
oknex.qc
Go to the documentation of this file.
1 #include "oknex.qh"
2 
3 #ifdef SVQC
4 
5 .float oknex_lasthit;
6 #endif
7 
8 #if defined(GAMEQC)
9 
10 METHOD(OverkillNex, wr_glow, vector(OverkillNex this, entity actor, entity wepent))
11 {
12  if (!WEP_CVAR(oknex, charge)) return '0 0 0';
13  float charge = wepent.oknex_charge;
14  float animlimit = WEP_CVAR(oknex, charge_animlimit);
15  float f = autocvar_g_weapon_charge_colormod_hdrmultiplier * min(1, charge / animlimit);
16  vector g;
17  g.x = f * autocvar_g_weapon_charge_colormod_red_half;
18  g.y = f * autocvar_g_weapon_charge_colormod_green_half;
19  g.z = f * autocvar_g_weapon_charge_colormod_blue_half;
20  if (charge > animlimit)
21  {
22  f = autocvar_g_weapon_charge_colormod_hdrmultiplier * (charge - animlimit) / (1 - animlimit);
23  g.x += f * autocvar_g_weapon_charge_colormod_red_full;
24  g.y += f * autocvar_g_weapon_charge_colormod_green_full;
25  g.z += f * autocvar_g_weapon_charge_colormod_blue_full;
26  }
27  // transition color can't be '0 0 0' as it defaults to player model glow color
28  if (g == '0 0 0')
29  g = '0 0 0.000001';
30  return g;
31 }
32 #endif
33 
34 #ifdef SVQC
36 
38 {
39  entity player = M_ARGV(0, entity);
40 
41  // WEAPONTODO
42  if(!WEP_CVAR(oknex, charge) || !WEP_CVAR(oknex, charge_velocity_rate))
43  return;
44 
45  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
46  {
47  .entity weaponentity = weaponentities[slot];
48 
49  if (player.(weaponentity).m_weapon == WEP_OVERKILL_NEX && WEP_CVAR(oknex, charge) && WEP_CVAR(oknex, charge_velocity_rate) && vdist(vec2(player.velocity), >, WEP_CVAR(oknex, charge_minspeed)))
50  {
51  float xyspeed = vlen(vec2(player.velocity));
52  // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
53  xyspeed = min(xyspeed, WEP_CVAR(oknex, charge_maxspeed));
54  float f = (xyspeed - WEP_CVAR(oknex, charge_minspeed)) / (WEP_CVAR(oknex, charge_maxspeed) - WEP_CVAR(oknex, charge_minspeed));
55  // add the extra charge
56  player.(weaponentity).oknex_charge = min(1, player.(weaponentity).oknex_charge + WEP_CVAR(oknex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
57  }
58  }
59 }
60 
61 void W_OverkillNex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
62 {
63  float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
64 
65  mydmg = WEP_CVAR_BOTH(oknex, !issecondary, damage);
66  myforce = WEP_CVAR_BOTH(oknex, !issecondary, force);
67  mymindist = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_mindist);
68  mymaxdist = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_maxdist);
69  myhalflife = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_halflife);
70  myforcehalflife = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_forcehalflife);
71  myammo = WEP_CVAR_BOTH(oknex, !issecondary, ammo);
72 
73  float flying;
74  flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
75 
76  if (WEP_CVAR(oknex, charge))
77  {
78  charge = WEP_CVAR(oknex, charge_mindmg) / mydmg + (1 - WEP_CVAR(oknex, charge_mindmg) / mydmg) * actor.(weaponentity).oknex_charge;
79  actor.(weaponentity).oknex_charge *= WEP_CVAR(oknex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
80  // O RLY? -- divVerent
81  // YA RLY -- FruitieX
82  }
83  else
84  {
85  charge = 1;
86  }
87  mydmg *= charge;
88  myforce *= charge;
89 
90  W_SetupShot(actor, weaponentity, true, 5, SND_NEXFIRE, CH_WEAPON_A, mydmg, thiswep.m_id);
91  if(charge > WEP_CVAR(oknex, charge_animlimit) && WEP_CVAR(oknex, charge_animlimit)) // if the OverkillNex is overcharged, we play an extra sound
92  {
93  sound(actor, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(oknex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(oknex, charge_animlimit)), ATTN_NORM);
94  }
95 
96  yoda = 0;
97  impressive_hits = 0;
98  FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, mydmg, true, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, thiswep.m_id);
99 
100  if(yoda && flying)
101  Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
102  if(impressive_hits && actor.oknex_lasthit)
103  {
104  Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
105  impressive_hits = 0; // only every second time
106  }
107 
108  actor.oknex_lasthit = impressive_hits;
109 
110  //beam and muzzle flash done on client
111  SendCSQCVortexBeamParticle(charge);
112 
113  W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
114 }
115 
116 .float oknex_chargepool_pauseregen_finished;
117 
118 METHOD(OverkillNex, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
119 {
120  if(bot_aim(actor, weaponentity, 1000000, 0, 1, false))
121  PHYS_INPUT_BUTTON_ATCK(actor) = true;
122  else
123  {
124  if(WEP_CVAR(oknex, charge))
125  PHYS_INPUT_BUTTON_ATCK2(actor) = true;
126  }
127 }
128 
129 METHOD(OverkillNex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
130 {
131  if (WEP_CVAR(oknex, charge) && actor.(weaponentity).oknex_charge < WEP_CVAR(oknex, charge_limit))
132  {
133  actor.(weaponentity).oknex_charge = min(1, actor.(weaponentity).oknex_charge + WEP_CVAR(oknex, charge_rate) * frametime / W_TICSPERFRAME);
134  }
135 
136  if (WEP_CVAR_SEC(oknex, chargepool))
137  if (actor.(weaponentity).oknex_chargepool_ammo < 1)
138  {
139  if (actor.oknex_chargepool_pauseregen_finished < time)
140  actor.(weaponentity).oknex_chargepool_ammo = min(1, actor.(weaponentity).oknex_chargepool_ammo + WEP_CVAR_SEC(oknex, chargepool_regen) * frametime / W_TICSPERFRAME);
141  actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(oknex, chargepool_pause_regen));
142  }
143 
144  if ((WEP_CVAR_SEC(oknex, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
145  {
146  // Secondary uses it's own refire timer if refire_type is 1.
147  actor.jump_interval = time + WEP_CVAR_SEC(oknex, refire) * W_WeaponRateFactor(actor);
148  BLASTER_SECONDARY_ATTACK(oknex, actor, weaponentity);
149  if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
150  (actor.(weaponentity).wframe == WFRAME_FIRE2))
151  {
152  // Set secondary fire animation.
153  actor.(weaponentity).wframe = WFRAME_FIRE2;
154  FOREACH_CLIENT(true, LAMBDA(
155  if (it == actor || (IS_SPEC(it) && it.enemy == actor))
156  {
157  wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, autocvar_g_weaponratefactor, true);
158  }
159  ));
161  }
162  }
163 
164  if (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR_PRI(oknex, ammo))
165  {
166  // Rorced reload
167  thiswep.wr_reload(thiswep, actor, weaponentity);
168  return;
169  }
170  if (fire & 1) // Primary attack
171  {
172  if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(oknex, refire)))
173  {
174  return;
175  }
176  W_OverkillNex_Attack(thiswep, actor, weaponentity, 0);
177  weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(oknex, animtime), w_ready);
178  return;
179  }
180  if ((fire & 2) && (WEP_CVAR(oknex, secondary) == 2) && (WEP_CVAR_SEC(oknex, refire_type) == 0))
181  {
182  // Secondary attack
183  if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(oknex, refire)))
184  {
185  return;
186  }
187  BLASTER_SECONDARY_ATTACK(oknex, actor, weaponentity);
188  weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(oknex, animtime), w_ready);
189  return;
190  }
191  //if ((WEP_CVAR(oknex, charge) && (WEP_CVAR(oknex, secondary) == 1)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
192  //{
193  // if(WEP_CVAR(oknex, charge))
194  // {
195  // actor.(weaponentity).oknex_charge_rottime = time + WEP_CVAR(oknex, charge_rot_pause);
196  // float dt = frametime / W_TICSPERFRAME;
197  //
198  // if(actor.(weaponentity).oknex_charge < 1)
199  // {
200  // if(WEP_CVAR_SEC(oknex, chargepool))
201  // {
202  // if(WEP_CVAR_SEC(oknex, ammo))
203  // {
204  // // always deplete if secondary is held
205  // actor.(weaponentity).oknex_chargepool_ammo = max(0, actor.(weaponentity).oknex_chargepool_ammo - WEP_CVAR_SEC(oknex, ammo) * dt);
206 
207  // dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
208  // actor.oknex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(oknex, chargepool_pause_regen);
209  // dt = min(dt, actor.(weaponentity).oknex_chargepool_ammo);
210  // dt = max(0, dt);
211 
212  // actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
213  // }
214  // }
215 
216  // else if(WEP_CVAR_SEC(oknex, ammo))
217  // {
218  // if(fire & 2) // only eat ammo when the button is pressed
219  // {
220  // dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
221  // if(!(actor.items & IT_UNLIMITED_AMMO))
222  // {
223  // // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
224  // if(autocvar_g_balance_vortex_reload_ammo)
225  // {
226  // dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
227  // dt = max(0, dt);
228  // if(dt > 0)
229  // {
230  // actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(oknex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(oknex, ammo) * dt);
231  // }
232  // actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) = actor.(weaponentity).clip_load;
233  // }
234  // else
235  // {
236  // dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
237  // dt = max(0, dt);
238  // if(dt > 0)
239  // {
240  // actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(oknex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(oknex, ammo) * dt);
241  // }
242  // }
243  // }
244  // actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
245  // }
246  // }
247 
248  // else
249  // {
250  // dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
251  // actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
252  // }
253  // }
254  // }
255  // else if(WEP_CVAR(oknex, secondary))
256  // {
257  // if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(oknex, refire)))
258  // {
259  // W_OverkillNex_Attack(thiswep, actor, weaponentity, 1);
260  // weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(oknex, animtime), w_ready);
261  // }
262  // }
263  //}
264 }
265 
266 METHOD(OverkillNex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
267 {
268  actor.oknex_lasthit = 0;
269 }
270 
271 METHOD(OverkillNex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
272 {
273  float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(oknex, ammo);
274  ammo_amount += (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(oknex, ammo));
275  return ammo_amount;
276 }
277 
278 METHOD(OverkillNex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
279 {
280  if (WEP_CVAR(oknex, secondary))
281  {
282  // don't allow charging if we don't have enough ammo
283  float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(oknex, ammo);
284  ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(oknex, ammo);
285  return ammo_amount;
286  }
287  else
288  {
289  return false; // zoom is not a fire mode
290  }
291 }
292 
293 METHOD(OverkillNex, wr_resetplayer, void(entity thiswep, entity actor))
294 {
295  if (WEP_CVAR(oknex, charge)) {
296  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
297  {
298  .entity weaponentity = weaponentities[slot];
299  actor.(weaponentity).oknex_charge = WEP_CVAR(oknex, charge_start);
300  }
301  }
302  actor.oknex_lasthit = 0;
303 }
304 
305 METHOD(OverkillNex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
306 {
307  W_Reload(actor, weaponentity, WEP_CVAR_PRI(oknex, ammo), SND_RELOAD);
308 }
309 
310 METHOD(OverkillNex, wr_suicidemessage, Notification(entity thiswep))
311 {
312  return WEAPON_THINKING_WITH_PORTALS;
313 }
314 
315 METHOD(OverkillNex, wr_killmessage, Notification(entity thiswep))
316 {
317  return WEAPON_OVERKILL_NEX_MURDER;
318 }
319 
320 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
321 {
322  return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(oknex, secondary);
323 }
324 
325 #endif
326 #ifdef CSQC
327 
328 METHOD(OverkillNex, wr_impacteffect, void(entity thiswep, entity actor))
329 {
330  entity this = actor;
331  vector org2 = w_org + w_backoff * 6;
332  pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
333  if(!w_issilent)
334  sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
335 }
336 
337 METHOD(OverkillNex, wr_init, void(entity thiswep))
338 {
340  {
341  precache_pic("gfx/reticle_nex");
342  }
343 }
344 
345 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
346 {
347  if(button_zoom || zoomscript_caught || (!WEP_CVAR(oknex, secondary) && button_attack2))
348  {
349  return true;
350  }
351  else
352  {
353  // no weapon specific image for this weapon
354  return false;
355  }
356 }
357 
358 METHOD(OverkillNex, wr_zoomdir, bool(entity thiswep))
359 {
360  return button_attack2 && !WEP_CVAR(oknex, secondary);
361 }
362 
363 #endif
#define WEP_CVAR_PRI(wepname, name)
Definition: all.qh:300
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition: player.qh:148
bool bot_aim(entity this,.entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, float applygravity)
#define WEP_CVAR_SEC(wepname, name)
Definition: all.qh:301
float oknex_charge
Definition: wepent.qh:8
float weapon_load[REGISTRY_MAX(Weapons)]
Definition: weaponsystem.qh:29
vector w_shotorg
Definition: tracing.qh:18
#define REGISTER_MUTATOR(id, dependence)
Definition: base.qh:263
float zoomscript_caught
Definition: view.qh:117
entity() spawn
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
#define WEP_CVAR(wepname, name)
Definition: all.qh:299
#define LAMBDA(...)
Definition: misc.qh:37
vector w_shotdir
Definition: tracing.qh:19
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
float oknex_chargepool_ammo
Definition: wepent.qh:9
int impressive_hits
Definition: damage.qh:52
bool autocvar_cl_reticle
Definition: crosshair.qh:3
const float ATTN_NORM
Definition: csprogsdefs.qc:226
float ammo
Definition: sv_turrets.qh:44
#define IS_SPEC(v)
Definition: utils.qh:10
const int CH_WEAPON_A
Definition: sound.qh:7
bool button_attack2
Definition: main.qh:99
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
void GetPressedKeys(entity this)
Definition: client.qc:1681
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
void animdecide_setaction(entity e, float action, float restart)
Definition: animdecide.qc:338
#define WEP_CVAR_BOTH(wepname, isprimary, name)
Definition: all.qh:302
#define pointparticles
Definition: csprogsdefs.qh:13
float frametime
Definition: csprogsdefs.qc:17
const float VOL_BASE
Definition: sound.qh:36
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition: player.qh:146
const int ANIMACTION_SHOOT
Definition: animdecide.qh:145
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:33
#define M_ARGV(x, type)
Definition: events.qh:17
bool autocvar_cl_reticle_weapon
Definition: crosshair.qh:5
bool button_zoom
Definition: main.qh:97
const int CH_SHOTS
Definition: sound.qh:14
bool IsFlying(entity this)
Definition: player.qc:804
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
entity Notification
always last
Definition: all.qh:82
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
#define vec2(...)
Definition: vector.qh:90
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
#define MUTATOR_HOOKFUNCTION(...)
Definition: base.qh:310
void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use,.entity weaponentity)
#define sound(e, c, s, v, a)
Definition: sound.qh:52
void FireRailgunBullet(entity this,.entity weaponentity, vector start, vector end, float bdamage, bool headshot_notify, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, int deathtype)
Definition: tracing.qc:231
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
const int CH_WEAPON_B
Definition: sound.qh:8
int m_id
Definition: weapon.qh:42
float W_WeaponRateFactor(entity this)
Definition: weaponsystem.qc:33
float yoda
Definition: damage.qh:51
const int W_TICSPERFRAME
Definition: weaponsystem.qh:14
void W_Reload(entity actor,.entity weaponentity, float sent_ammo_min, Sound sent_sound)