]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/oknex.qc
OK weapons: removing old stuff.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / oknex.qc
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         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(oknex_charge, true);
31
32 MUTATOR_HOOKFUNCTION(oknex_charge, GetPressedKeys)
33 {
34         entity player = M_ARGV(0, entity);
35
36         // WEAPONTODO
37         if(!WEP_CVAR(oknex, charge) || !WEP_CVAR(oknex, 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_NEX && WEP_CVAR(oknex, charge) && WEP_CVAR(oknex, charge_velocity_rate) && vdist(vec2(player.velocity), >, WEP_CVAR(oknex, 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(oknex, charge_maxspeed));
49                         float f = (xyspeed - WEP_CVAR(oknex, charge_minspeed)) / (WEP_CVAR(oknex, charge_maxspeed) - WEP_CVAR(oknex, charge_minspeed));
50                         // add the extra charge
51                         player.(weaponentity).oknex_charge = min(1, player.(weaponentity).oknex_charge + WEP_CVAR(oknex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
52                 }
53         }
54 }
55
56 void W_OverkillNex_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(oknex, !issecondary, damage);
61         myforce = WEP_CVAR_BOTH(oknex, !issecondary, force);
62         mymindist = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_mindist);
63         mymaxdist = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_maxdist);
64         myhalflife = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_halflife);
65         myforcehalflife = WEP_CVAR_BOTH(oknex, !issecondary, damagefalloff_forcehalflife);
66         myammo = WEP_CVAR_BOTH(oknex, !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(oknex, charge))
72         {
73                 charge = WEP_CVAR(oknex, charge_mindmg) / mydmg + (1 - WEP_CVAR(oknex, charge_mindmg) / mydmg) * actor.(weaponentity).oknex_charge;
74                 actor.(weaponentity).oknex_charge *= WEP_CVAR(oknex, 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(oknex, charge_animlimit) && WEP_CVAR(oknex, charge_animlimit)) // if the OverkillNex is overcharged, we play an extra sound
87         {
88                 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);
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_NEX.m_id);
94
95         if(yoda && flying)
96                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
97         if(damage_goodhits && actor.oknex_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.oknex_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 oknex_chargepool_pauseregen_finished;
112
113 METHOD(OverkillNex, 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(oknex, charge))
120                         PHYS_INPUT_BUTTON_ATCK2(actor) = true;
121         }
122 }
123
124 METHOD(OverkillNex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
125 {
126         if (WEP_CVAR(oknex, charge) && actor.(weaponentity).oknex_charge < WEP_CVAR(oknex, charge_limit))
127         {
128                 actor.(weaponentity).oknex_charge = min(1, actor.(weaponentity).oknex_charge + WEP_CVAR(oknex, charge_rate) * frametime / W_TICSPERFRAME);
129         }
130
131         if (WEP_CVAR_SEC(oknex, chargepool))
132                 if (actor.(weaponentity).oknex_chargepool_ammo < 1)
133                 {
134                         if (actor.oknex_chargepool_pauseregen_finished < time)
135                                 actor.(weaponentity).oknex_chargepool_ammo = min(1, actor.(weaponentity).oknex_chargepool_ammo + WEP_CVAR_SEC(oknex, chargepool_regen) * frametime / W_TICSPERFRAME);
136                         actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(oknex, chargepool_pause_regen));
137                 }
138
139         if ((WEP_CVAR_SEC(oknex, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
140         {
141                 // Secondary uses it's own refire timer if refire_type is 1.
142                 actor.jump_interval = time + WEP_CVAR_SEC(oknex, refire) * W_WeaponRateFactor(actor);
143                 // Ugly hack to reuse the fire mode of the blaster.
144                 makevectors(actor.v_angle);
145                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
146                 actor.(weaponentity).m_weapon = WEP_BLASTER;
147                 W_Blaster_Attack(
148                         actor,
149                         weaponentity,
150                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
151                         WEP_CVAR_SEC(oknex, shotangle),
152                         WEP_CVAR_SEC(oknex, damage),
153                         WEP_CVAR_SEC(oknex, edgedamage),
154                         WEP_CVAR_SEC(oknex, radius),
155                         WEP_CVAR_SEC(oknex, force),
156                         WEP_CVAR_SEC(oknex, speed),
157                         WEP_CVAR_SEC(oknex, spread),
158                         WEP_CVAR_SEC(oknex, delay),
159                         WEP_CVAR_SEC(oknex, lifetime)
160                 );
161                 actor.(weaponentity).m_weapon = oldwep;
162                 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
163                         (actor.(weaponentity).wframe == WFRAME_FIRE2))
164                 {
165                         // Set secondary fire animation.
166                         vector a = '0 0 0';
167                         actor.(weaponentity).wframe = WFRAME_FIRE2;
168                         a = actor.(weaponentity).anim_fire2;
169                         a.z *= g_weaponratefactor;
170                         FOREACH_CLIENT(true, LAMBDA(
171                                 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
172                                 {
173                                         wframe_send(it, actor.(weaponentity), a, true);
174                                 }
175                         ));
176                         animdecide_setaction(actor, ANIMACTION_SHOOT, true);
177                 }
178         }
179
180         if (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR_PRI(oknex, ammo))
181         {
182                 // Rorced reload
183                 thiswep.wr_reload(thiswep, actor, weaponentity);
184                 return;
185         }
186         if (fire & 1) // Primary attack
187         {
188                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(oknex, refire)))
189                 {
190                         return;
191                 }
192                 W_OverkillNex_Attack(thiswep, actor, weaponentity, 0);
193                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(oknex, animtime), w_ready);
194                 return;
195         }
196         if ((fire & 2) && (WEP_CVAR(oknex, secondary) == 2) && (WEP_CVAR_SEC(oknex, refire_type) == 0))
197         {
198                 // Secondary attack
199                 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(oknex, refire)))
200                 {
201                         return;
202                 }
203                 // ugly instagib hack to reuse the fire mode of the laser
204                 makevectors(actor.v_angle);
205                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
206                 actor.(weaponentity).m_weapon = WEP_BLASTER;
207                 W_Blaster_Attack(
208                         actor,
209                         weaponentity,
210                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
211                         WEP_CVAR_SEC(oknex, shotangle),
212                         WEP_CVAR_SEC(oknex, damage),
213                         WEP_CVAR_SEC(oknex, edgedamage),
214                         WEP_CVAR_SEC(oknex, radius),
215                         WEP_CVAR_SEC(oknex, force),
216                         WEP_CVAR_SEC(oknex, speed),
217                         WEP_CVAR_SEC(oknex, spread),
218                         WEP_CVAR_SEC(oknex, delay),
219                         WEP_CVAR_SEC(oknex, lifetime)
220                 );
221                 actor.(weaponentity).m_weapon = oldwep;
222                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(oknex, animtime), w_ready);
223                 return;
224         }
225         //if ((WEP_CVAR(oknex, charge) && (WEP_CVAR(oknex, secondary) == 1)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
226         //{
227         //      if(WEP_CVAR(oknex, charge))
228         //      {
229         //              actor.(weaponentity).oknex_charge_rottime = time + WEP_CVAR(oknex, charge_rot_pause);
230         //              float dt = frametime / W_TICSPERFRAME;
231         //
232         //              if(actor.(weaponentity).oknex_charge < 1)
233         //              {
234         //                      if(WEP_CVAR_SEC(oknex, chargepool))
235         //                      {
236         //                              if(WEP_CVAR_SEC(oknex, ammo))
237         //                              {
238         //                                      // always deplete if secondary is held
239         //                                      actor.(weaponentity).oknex_chargepool_ammo = max(0, actor.(weaponentity).oknex_chargepool_ammo - WEP_CVAR_SEC(oknex, ammo) * dt);
240
241         //                                      dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
242         //                                      actor.oknex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(oknex, chargepool_pause_regen);
243         //                                      dt = min(dt, actor.(weaponentity).oknex_chargepool_ammo);
244         //                                      dt = max(0, dt);
245
246         //                                      actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
247         //                              }
248         //                      }
249
250         //                      else if(WEP_CVAR_SEC(oknex, ammo))
251         //                      {
252         //                              if(fire & 2) // only eat ammo when the button is pressed
253         //                              {
254         //                                      dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
255         //                                      if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
256         //                                      {
257         //                                              // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
258         //                                              if(autocvar_g_balance_vortex_reload_ammo)
259         //                                              {
260         //                                                      dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
261         //                                                      dt = max(0, dt);
262         //                                                      if(dt > 0)
263         //                                                      {
264         //                                                              actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(oknex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(oknex, ammo) * dt);
265         //                                                      }
266         //                                                      actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) = actor.(weaponentity).clip_load;
267         //                                              }
268         //                                              else
269         //                                              {
270         //                                                      dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
271         //                                                      dt = max(0, dt);
272         //                                                      if(dt > 0)
273         //                                                      {
274         //                                                              actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(oknex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(oknex, ammo) * dt);
275         //                                                      }
276         //                                              }
277         //                                      }
278         //                                      actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
279         //                              }
280         //                      }
281
282         //                      else
283         //                      {
284         //                              dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
285         //                              actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
286         //                      }
287         //              }
288         //      }
289         //      else if(WEP_CVAR(oknex, secondary))
290         //      {
291         //              if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(oknex, refire)))
292         //              {
293         //                      W_OverkillNex_Attack(thiswep, actor, weaponentity, 1);
294         //                      weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(oknex, animtime), w_ready);
295         //              }
296         //      }
297         //}
298 }
299
300 METHOD(OverkillNex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
301 {
302         actor.oknex_lasthit = 0;
303 }
304
305 METHOD(OverkillNex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
306 {
307         float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(oknex, ammo);
308         ammo_amount += (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) >= WEP_CVAR_PRI(oknex, ammo));
309         return ammo_amount;
310 }
311
312 METHOD(OverkillNex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
313 {
314         if (WEP_CVAR(oknex, secondary))
315         {
316                 // don't allow charging if we don't have enough ammo
317                 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(oknex, ammo);
318                 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) >= WEP_CVAR_SEC(oknex, ammo);
319                 return ammo_amount;
320         }
321         else
322         {
323                 return false; // zoom is not a fire mode
324         }
325 }
326
327 METHOD(OverkillNex, wr_resetplayer, void(entity thiswep, entity actor))
328 {
329         if (WEP_CVAR(oknex, charge)) {
330                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
331                 {
332                         .entity weaponentity = weaponentities[slot];
333                         actor.(weaponentity).oknex_charge = WEP_CVAR(oknex, charge_start);
334                 }
335         }
336         actor.oknex_lasthit = 0;
337 }
338
339 METHOD(OverkillNex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
340 {
341         W_Reload(actor, weaponentity, WEP_CVAR_PRI(oknex, ammo), SND_RELOAD);
342 }
343
344 METHOD(OverkillNex, wr_suicidemessage, Notification(entity thiswep))
345 {
346         return WEAPON_THINKING_WITH_PORTALS;
347 }
348
349 METHOD(OverkillNex, wr_killmessage, Notification(entity thiswep))
350 {
351         return WEAPON_OVERKILL_NEX_MURDER;
352 }
353
354 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
355 {
356         return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(oknex, secondary);
357 }
358
359 #endif
360 #ifdef CSQC
361
362 METHOD(OverkillNex, wr_impacteffect, void(entity thiswep, entity actor))
363 {
364         entity this = actor;
365         vector org2 = w_org + w_backoff * 6;
366         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
367         if(!w_issilent)
368                 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
369 }
370
371 METHOD(OverkillNex, wr_init, void(entity thiswep))
372 {
373         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
374         {
375                 precache_pic("gfx/reticle_nex");
376         }
377 }
378
379 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
380 {
381         if(button_zoom || zoomscript_caught || (!WEP_CVAR(oknex, secondary) && button_attack2))
382         {
383                 return true;
384         }
385         else
386         {
387                 // no weapon specific image for this weapon
388                 return false;
389         }
390 }
391
392 METHOD(OverkillNex, wr_zoomdir, bool(entity thiswep))
393 {
394     return button_attack2 && !WEP_CVAR(oknex, secondary);
395 }
396
397 #endif