]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/okvortex.qc
Fixed OK Vortex reload.
[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 spawnfunc(weapon_okvortex) { weapon_defaultspawnfunc(this, WEP_OVERKILL_VORTEX); }
31
32 REGISTER_MUTATOR(okvortex_charge, true);
33
34 MUTATOR_HOOKFUNCTION(okvortex_charge, GetPressedKeys)
35 {
36         entity player = M_ARGV(0, entity);
37
38         // WEAPONTODO
39         if(!WEP_CVAR(okvortex, charge) || !WEP_CVAR(okvortex, charge_velocity_rate))
40                 return;
41
42         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
43         {
44                 .entity weaponentity = weaponentities[slot];
45
46                 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)))
47                 {
48                         float xyspeed = vlen(vec2(player.velocity));
49                         // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
50                                 xyspeed = min(xyspeed, WEP_CVAR(okvortex, charge_maxspeed));
51                         float f = (xyspeed - WEP_CVAR(okvortex, charge_minspeed)) / (WEP_CVAR(okvortex, charge_maxspeed) - WEP_CVAR(okvortex, charge_minspeed));
52                         // add the extra charge
53                         player.(weaponentity).okvortex_charge = min(1, player.(weaponentity).okvortex_charge + WEP_CVAR(okvortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
54                 }
55         }
56 }
57
58 void W_OverkillVortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
59 {
60         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
61
62         mydmg = WEP_CVAR_BOTH(okvortex, !issecondary, damage);
63         myforce = WEP_CVAR_BOTH(okvortex, !issecondary, force);
64         mymindist = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_mindist);
65         mymaxdist = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_maxdist);
66         myhalflife = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_halflife);
67         myforcehalflife = WEP_CVAR_BOTH(okvortex, !issecondary, damagefalloff_forcehalflife);
68         myammo = WEP_CVAR_BOTH(okvortex, !issecondary, ammo);
69
70         float flying;
71         flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
72
73         if(WEP_CVAR(okvortex, charge))
74         {
75                 charge = WEP_CVAR(okvortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(okvortex, charge_mindmg) / mydmg) * actor.(weaponentity).okvortex_charge;
76                 actor.(weaponentity).okvortex_charge *= WEP_CVAR(okvortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
77                 // O RLY? -- divVerent
78                 // YA RLY -- FruitieX
79         }
80         else
81                 charge = 1;
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                 actor.(weaponentity).okvortex_charge = min(1, actor.(weaponentity).okvortex_charge + WEP_CVAR(okvortex, charge_rate) * frametime / W_TICSPERFRAME);
128
129         if(weaponslot(weaponentity) == 0)
130                 actor.okvortex_charge = actor.(weaponentity).okvortex_charge;
131
132         if(WEP_CVAR_SEC(okvortex, chargepool))
133                 if(actor.(weaponentity).okvortex_chargepool_ammo < 1)
134                 {
135                         if(actor.okvortex_chargepool_pauseregen_finished < time)
136                                 actor.(weaponentity).okvortex_chargepool_ammo = min(1, actor.(weaponentity).okvortex_chargepool_ammo + WEP_CVAR_SEC(okvortex, chargepool_regen) * frametime / W_TICSPERFRAME);
137                         actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(okvortex, chargepool_pause_regen));
138                 }
139
140         if(weaponslot(weaponentity) == 0)
141                 actor.okvortex_chargepool_ammo = actor.(weaponentity).okvortex_chargepool_ammo;
142
143         if(autocvar_g_balance_okvortex_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(okvortex, ammo), WEP_CVAR_SEC(okvortex, ammo))) { // forced reload
144                 thiswep.wr_reload(thiswep, actor, weaponentity);
145         } else
146         {
147                 if (fire & 1)
148                 {
149                         if (weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(okvortex, refire)))
150                         {
151                                 W_OverkillVortex_Attack(thiswep, actor, weaponentity, 0);
152                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(okvortex, animtime), w_ready);
153                         }
154                 }
155                 else if ((fire & 2) && (WEP_CVAR(okvortex, secondary) == 2))
156                 {
157                         if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okshotgun, refire)))
158                         {
159                                 return;
160                         }
161                         // ugly instagib hack to reuse the fire mode of the laser
162                         makevectors(actor.v_angle);
163                         Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
164                         actor.(weaponentity).m_weapon = WEP_BLASTER;
165                         W_Blaster_Attack(
166                                 actor,
167                                 weaponentity,
168                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
169                                 WEP_CVAR_SEC(okshotgun, shotangle),
170                                 WEP_CVAR_SEC(okshotgun, damage),
171                                 WEP_CVAR_SEC(okshotgun, edgedamage),
172                                 WEP_CVAR_SEC(okshotgun, radius),
173                                 WEP_CVAR_SEC(okshotgun, force),
174                                 WEP_CVAR_SEC(okshotgun, speed),
175                                 WEP_CVAR_SEC(okshotgun, spread),
176                                 WEP_CVAR_SEC(okshotgun, delay),
177                                 WEP_CVAR_SEC(okshotgun, lifetime)
178                         );
179                         actor.(weaponentity).m_weapon = oldwep;
180                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okshotgun, animtime), w_ready);
181                         return;
182                 }
183                 if((WEP_CVAR(okvortex, charge) && !WEP_CVAR(okvortex, secondary)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
184                 {
185                         if(WEP_CVAR(okvortex, charge))
186                         {
187                                 actor.(weaponentity).okvortex_charge_rottime = time + WEP_CVAR(okvortex, charge_rot_pause);
188                                 float dt = frametime / W_TICSPERFRAME;
189
190                                 if(actor.(weaponentity).okvortex_charge < 1)
191                                 {
192                                         if(WEP_CVAR_SEC(okvortex, chargepool))
193                                         {
194                                                 if(WEP_CVAR_SEC(okvortex, ammo))
195                                                 {
196                                                         // always deplete if secondary is held
197                                                         actor.okvortex_chargepool_ammo = max(0, actor.okvortex_chargepool_ammo - WEP_CVAR_SEC(okvortex, ammo) * dt);
198
199                                                         dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
200                                                         actor.okvortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(okvortex, chargepool_pause_regen);
201                                                         dt = min(dt, actor.okvortex_chargepool_ammo);
202                                                         dt = max(0, dt);
203
204                                                         actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
205                                                 }
206                                         }
207
208                                         else if(WEP_CVAR_SEC(okvortex, ammo))
209                                         {
210                                                 if(fire & 2) // only eat ammo when the button is pressed
211                                                 {
212                                                         dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
213                                                         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
214                                                         {
215                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
216                                                                 if(autocvar_g_balance_vortex_reload_ammo)
217                                                                 {
218                                                                         dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(okvortex, ammo)) / WEP_CVAR_SEC(okvortex, ammo));
219                                                                         dt = max(0, dt);
220                                                                         if(dt > 0)
221                                                                         {
222                                                                                 actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(okvortex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(okvortex, ammo) * dt);
223                                                                         }
224                                                                         actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) = actor.(weaponentity).clip_load;
225                                                                 }
226                                                                 else
227                                                                 {
228                                                                         dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(okvortex, ammo)) / WEP_CVAR_SEC(okvortex, ammo));
229                                                                         dt = max(0, dt);
230                                                                         if(dt > 0)
231                                                                         {
232                                                                                 actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(okvortex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(okvortex, ammo) * dt);
233                                                                         }
234                                                                 }
235                                                         }
236                                                         actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
237                                                 }
238                                         }
239
240                                         else
241                                         {
242                                                 dt = min(dt, (1 - actor.(weaponentity).okvortex_charge) / WEP_CVAR(okvortex, charge_rate));
243                                                 actor.(weaponentity).okvortex_charge += dt * WEP_CVAR(okvortex, charge_rate);
244                                         }
245                                 }
246                         }
247                         else if(WEP_CVAR(okvortex, secondary))
248                         {
249                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okvortex, refire)))
250                                 {
251                                         W_OverkillVortex_Attack(thiswep, actor, weaponentity, 1);
252                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(okvortex, animtime), w_ready);
253                                 }
254                         }
255                 }
256         }
257 }
258 METHOD(OverkillVortex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
259 {
260         actor.okvortex_lasthit = 0;
261 }
262 METHOD(OverkillVortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
263 {
264         float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(okvortex, ammo);
265         ammo_amount += (autocvar_g_balance_okvortex_reload_ammo && actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) >= WEP_CVAR_PRI(okvortex, ammo));
266         return ammo_amount;
267 }
268 METHOD(OverkillVortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
269 {
270         if(WEP_CVAR(okvortex, secondary))
271         {
272                 // don't allow charging if we don't have enough ammo
273                 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(okvortex, ammo);
274                 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_VORTEX.m_id]) >= WEP_CVAR_SEC(okvortex, ammo);
275                 return ammo_amount;
276         }
277         else
278         {
279                 return false; // zoom is not a fire mode
280         }
281 }
282 METHOD(OverkillVortex, wr_resetplayer, void(entity thiswep, entity actor))
283 {
284         if (WEP_CVAR(okvortex, charge)) {
285                 if (WEP_CVAR_SEC(okvortex, chargepool)) {
286                         actor.okvortex_chargepool_ammo = 1;
287                 }
288                 actor.okvortex_charge = WEP_CVAR(okvortex, charge_start);
289                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
290                 {
291                         .entity weaponentity = weaponentities[slot];
292                         actor.(weaponentity).okvortex_charge = WEP_CVAR(okvortex, charge_start);
293
294                         if (WEP_CVAR_SEC(okvortex, chargepool))
295                                 actor.(weaponentity).okvortex_chargepool_ammo = 1;
296                 }
297         }
298         actor.okvortex_lasthit = 0;
299 }
300 METHOD(OverkillVortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
301 {
302         W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(okvortex, ammo), WEP_CVAR_SEC(okvortex, ammo)), SND_RELOAD);
303 }
304 METHOD(OverkillVortex, wr_suicidemessage, Notification(entity thiswep))
305 {
306         return WEAPON_THINKING_WITH_PORTALS;
307 }
308 METHOD(OverkillVortex, wr_killmessage, Notification(entity thiswep))
309 {
310         return WEAPON_VORTEX_MURDER;
311 }
312 METHOD(OverkillVortex, wr_zoom, bool(entity thiswep, entity actor))
313 {
314         return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(okvortex, secondary);
315 }
316
317 #endif
318 #ifdef CSQC
319
320 METHOD(OverkillVortex, wr_impacteffect, void(entity thiswep, entity actor))
321 {
322         entity this = actor;
323         vector org2 = w_org + w_backoff * 6;
324         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
325         if(!w_issilent)
326                 sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
327 }
328 METHOD(OverkillVortex, wr_init, void(entity thiswep))
329 {
330         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
331         {
332                 precache_pic("gfx/reticle_nex");
333         }
334 }
335 METHOD(OverkillVortex, wr_zoom, bool(entity thiswep, entity actor))
336 {
337         if(button_zoom || zoomscript_caught || (!WEP_CVAR(okvortex, secondary) && button_attack2))
338         {
339                 return true;
340         }
341         else
342         {
343                 // no weapon specific image for this weapon
344                 return false;
345         }
346 }
347
348 #endif