]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/oknex.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[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, WEP_OVERKILL_NEX.m_id);
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                 W_Blaster_Attack(
146                         actor,
147                         weaponentity,
148                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
149                         WEP_CVAR_SEC(oknex, shotangle),
150                         WEP_CVAR_SEC(oknex, damage),
151                         WEP_CVAR_SEC(oknex, edgedamage),
152                         WEP_CVAR_SEC(oknex, radius),
153                         WEP_CVAR_SEC(oknex, force),
154                         WEP_CVAR_SEC(oknex, speed),
155                         WEP_CVAR_SEC(oknex, spread),
156                         WEP_CVAR_SEC(oknex, delay),
157                         WEP_CVAR_SEC(oknex, lifetime)
158                 );
159                 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
160                         (actor.(weaponentity).wframe == WFRAME_FIRE2))
161                 {
162                         // Set secondary fire animation.
163                         vector a = '0 0 0';
164                         actor.(weaponentity).wframe = WFRAME_FIRE2;
165                         a = actor.(weaponentity).anim_fire2;
166                         a.z *= g_weaponratefactor;
167                         FOREACH_CLIENT(true, LAMBDA(
168                                 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
169                                 {
170                                         wframe_send(it, actor.(weaponentity), a, true);
171                                 }
172                         ));
173                         animdecide_setaction(actor, ANIMACTION_SHOOT, true);
174                 }
175         }
176
177         if (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR_PRI(oknex, ammo))
178         {
179                 // Rorced reload
180                 thiswep.wr_reload(thiswep, actor, weaponentity);
181                 return;
182         }
183         if (fire & 1) // Primary attack
184         {
185                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(oknex, refire)))
186                 {
187                         return;
188                 }
189                 W_OverkillNex_Attack(thiswep, actor, weaponentity, 0);
190                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(oknex, animtime), w_ready);
191                 return;
192         }
193         if ((fire & 2) && (WEP_CVAR(oknex, secondary) == 2) && (WEP_CVAR_SEC(oknex, refire_type) == 0))
194         {
195                 // Secondary attack
196                 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(oknex, refire)))
197                 {
198                         return;
199                 }
200                 // ugly instagib hack to reuse the fire mode of the laser
201                 makevectors(actor.v_angle);
202                 W_Blaster_Attack(
203                         actor,
204                         weaponentity,
205                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
206                         WEP_CVAR_SEC(oknex, shotangle),
207                         WEP_CVAR_SEC(oknex, damage),
208                         WEP_CVAR_SEC(oknex, edgedamage),
209                         WEP_CVAR_SEC(oknex, radius),
210                         WEP_CVAR_SEC(oknex, force),
211                         WEP_CVAR_SEC(oknex, speed),
212                         WEP_CVAR_SEC(oknex, spread),
213                         WEP_CVAR_SEC(oknex, delay),
214                         WEP_CVAR_SEC(oknex, lifetime)
215                 );
216                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(oknex, animtime), w_ready);
217                 return;
218         }
219         //if ((WEP_CVAR(oknex, charge) && (WEP_CVAR(oknex, secondary) == 1)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
220         //{
221         //      if(WEP_CVAR(oknex, charge))
222         //      {
223         //              actor.(weaponentity).oknex_charge_rottime = time + WEP_CVAR(oknex, charge_rot_pause);
224         //              float dt = frametime / W_TICSPERFRAME;
225         //
226         //              if(actor.(weaponentity).oknex_charge < 1)
227         //              {
228         //                      if(WEP_CVAR_SEC(oknex, chargepool))
229         //                      {
230         //                              if(WEP_CVAR_SEC(oknex, ammo))
231         //                              {
232         //                                      // always deplete if secondary is held
233         //                                      actor.(weaponentity).oknex_chargepool_ammo = max(0, actor.(weaponentity).oknex_chargepool_ammo - WEP_CVAR_SEC(oknex, ammo) * dt);
234
235         //                                      dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
236         //                                      actor.oknex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(oknex, chargepool_pause_regen);
237         //                                      dt = min(dt, actor.(weaponentity).oknex_chargepool_ammo);
238         //                                      dt = max(0, dt);
239
240         //                                      actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
241         //                              }
242         //                      }
243
244         //                      else if(WEP_CVAR_SEC(oknex, ammo))
245         //                      {
246         //                              if(fire & 2) // only eat ammo when the button is pressed
247         //                              {
248         //                                      dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
249         //                                      if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
250         //                                      {
251         //                                              // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
252         //                                              if(autocvar_g_balance_vortex_reload_ammo)
253         //                                              {
254         //                                                      dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
255         //                                                      dt = max(0, dt);
256         //                                                      if(dt > 0)
257         //                                                      {
258         //                                                              actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(oknex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(oknex, ammo) * dt);
259         //                                                      }
260         //                                                      actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) = actor.(weaponentity).clip_load;
261         //                                              }
262         //                                              else
263         //                                              {
264         //                                                      dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(oknex, ammo)) / WEP_CVAR_SEC(oknex, ammo));
265         //                                                      dt = max(0, dt);
266         //                                                      if(dt > 0)
267         //                                                      {
268         //                                                              actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(oknex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(oknex, ammo) * dt);
269         //                                                      }
270         //                                              }
271         //                                      }
272         //                                      actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
273         //                              }
274         //                      }
275
276         //                      else
277         //                      {
278         //                              dt = min(dt, (1 - actor.(weaponentity).oknex_charge) / WEP_CVAR(oknex, charge_rate));
279         //                              actor.(weaponentity).oknex_charge += dt * WEP_CVAR(oknex, charge_rate);
280         //                      }
281         //              }
282         //      }
283         //      else if(WEP_CVAR(oknex, secondary))
284         //      {
285         //              if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(oknex, refire)))
286         //              {
287         //                      W_OverkillNex_Attack(thiswep, actor, weaponentity, 1);
288         //                      weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(oknex, animtime), w_ready);
289         //              }
290         //      }
291         //}
292 }
293
294 METHOD(OverkillNex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
295 {
296         actor.oknex_lasthit = 0;
297 }
298
299 METHOD(OverkillNex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
300 {
301         float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(oknex, ammo);
302         ammo_amount += (autocvar_g_balance_oknex_reload_ammo && actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) >= WEP_CVAR_PRI(oknex, ammo));
303         return ammo_amount;
304 }
305
306 METHOD(OverkillNex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
307 {
308         if (WEP_CVAR(oknex, secondary))
309         {
310                 // don't allow charging if we don't have enough ammo
311                 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(oknex, ammo);
312                 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_NEX.m_id]) >= WEP_CVAR_SEC(oknex, ammo);
313                 return ammo_amount;
314         }
315         else
316         {
317                 return false; // zoom is not a fire mode
318         }
319 }
320
321 METHOD(OverkillNex, wr_resetplayer, void(entity thiswep, entity actor))
322 {
323         if (WEP_CVAR(oknex, charge)) {
324                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
325                 {
326                         .entity weaponentity = weaponentities[slot];
327                         actor.(weaponentity).oknex_charge = WEP_CVAR(oknex, charge_start);
328                 }
329         }
330         actor.oknex_lasthit = 0;
331 }
332
333 METHOD(OverkillNex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
334 {
335         W_Reload(actor, weaponentity, WEP_CVAR_PRI(oknex, ammo), SND_RELOAD);
336 }
337
338 METHOD(OverkillNex, wr_suicidemessage, Notification(entity thiswep))
339 {
340         return WEAPON_THINKING_WITH_PORTALS;
341 }
342
343 METHOD(OverkillNex, wr_killmessage, Notification(entity thiswep))
344 {
345         return WEAPON_OVERKILL_NEX_MURDER;
346 }
347
348 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
349 {
350         return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(oknex, secondary);
351 }
352
353 #endif
354 #ifdef CSQC
355
356 METHOD(OverkillNex, wr_impacteffect, void(entity thiswep, entity actor))
357 {
358         entity this = actor;
359         vector org2 = w_org + w_backoff * 6;
360         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
361         if(!w_issilent)
362                 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
363 }
364
365 METHOD(OverkillNex, wr_init, void(entity thiswep))
366 {
367         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
368         {
369                 precache_pic("gfx/reticle_nex");
370         }
371 }
372
373 METHOD(OverkillNex, wr_zoom, bool(entity thiswep, entity actor))
374 {
375         if(button_zoom || zoomscript_caught || (!WEP_CVAR(oknex, secondary) && button_attack2))
376         {
377                 return true;
378         }
379         else
380         {
381                 // no weapon specific image for this weapon
382                 return false;
383         }
384 }
385
386 METHOD(OverkillNex, wr_zoomdir, bool(entity thiswep))
387 {
388     return button_attack2 && !WEP_CVAR(oknex, secondary);
389 }
390
391 #endif