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