]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
Unhardcode a few more weapon entity checks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
1 #include "vortex.qh"
2 #ifndef IMPLEMENTATION
3 CLASS(Vortex, Weapon)
4 /* ammotype  */ ATTRIB(Vortex, ammo_field, .int, ammo_cells);
5 /* impulse   */ ATTRIB(Vortex, impulse, int, 7);
6 /* flags     */ ATTRIB(Vortex, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
7 /* rating    */ ATTRIB(Vortex, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
8 /* color     */ ATTRIB(Vortex, wpcolor, vector, '0.5 1 1');
9 /* modelname */ ATTRIB(Vortex, mdl, string, "nex");
10 #ifdef GAMEQC
11 /* model     */ ATTRIB(Vortex, m_model, Model, MDL_VORTEX_ITEM);
12 #endif
13 /* crosshair */ ATTRIB(Vortex, w_crosshair, string, "gfx/crosshairnex");
14 /* crosshair */ ATTRIB(Vortex, w_crosshair_size, float, 0.65);
15 /* wepimg    */ ATTRIB(Vortex, model2, string, "weaponnex");
16 /* refname   */ ATTRIB(Vortex, netname, string, "vortex");
17 /* wepname   */ ATTRIB(Vortex, m_name, string, _("Vortex"));
18
19 #define X(BEGIN, P, END, class, prefix) \
20         BEGIN(class) \
21                 P(class, prefix, ammo, float, BOTH) \
22                 P(class, prefix, animtime, float, BOTH) \
23                 P(class, prefix, chargepool, float, SEC) \
24                 P(class, prefix, chargepool_pause_regen, float, SEC) \
25                 P(class, prefix, chargepool_regen, float, SEC) \
26                 P(class, prefix, charge, float, NONE) \
27                 P(class, prefix, charge_animlimit, float, NONE) \
28                 P(class, prefix, charge_limit, float, NONE) \
29                 P(class, prefix, charge_maxspeed, float, NONE) \
30                 P(class, prefix, charge_mindmg, float, NONE) \
31                 P(class, prefix, charge_minspeed, float, NONE) \
32                 P(class, prefix, charge_rate, float, NONE) \
33                 P(class, prefix, charge_rot_pause, float, NONE) \
34                 P(class, prefix, charge_rot_rate, float, NONE) \
35                 P(class, prefix, charge_shot_multiplier, float, NONE) \
36                 P(class, prefix, charge_start, float, NONE) \
37                 P(class, prefix, charge_velocity_rate, float, NONE) \
38                 P(class, prefix, damagefalloff_forcehalflife, float, BOTH) \
39                 P(class, prefix, damagefalloff_halflife, float, BOTH) \
40                 P(class, prefix, damagefalloff_maxdist, float, BOTH) \
41                 P(class, prefix, damagefalloff_mindist, float, BOTH) \
42                 P(class, prefix, damage, float, BOTH) \
43                 P(class, prefix, force, float, BOTH) \
44                 P(class, prefix, refire, float, BOTH) \
45                 P(class, prefix, secondary, float, NONE) \
46                 P(class, prefix, reload_ammo, float, NONE) \
47         P(class, prefix, reload_time, float, NONE) \
48         P(class, prefix, switchdelay_raise, float, NONE) \
49         P(class, prefix, switchdelay_drop, float, NONE) \
50         P(class, prefix, weaponreplace, string, NONE) \
51         P(class, prefix, weaponstart, float, NONE) \
52         P(class, prefix, weaponstartoverride, float, NONE) \
53         P(class, prefix, weaponthrowable, float, NONE) \
54         END()
55     W_PROPS(X, Vortex, vortex)
56 #undef X
57
58 ENDCLASS(Vortex)
59 REGISTER_WEAPON(VORTEX, vortex, NEW(Vortex));
60
61
62 #ifdef SVQC
63
64 .float vortex_lasthit;
65 #endif
66 #endif
67 #ifdef IMPLEMENTATION
68
69 REGISTER_STAT(WEP_CVAR_vortex_charge, bool, WEP_CVAR(vortex, charge))
70 REGISTER_STAT(WEP_CVAR_vortex_charge_animlimit, float, WEP_CVAR(vortex, charge_animlimit))
71
72 #if defined(GAMEQC)
73 float autocvar_g_weapon_charge_colormod_red_full;
74 float autocvar_g_weapon_charge_colormod_red_half;
75 float autocvar_g_weapon_charge_colormod_green_full;
76 float autocvar_g_weapon_charge_colormod_blue_full;
77 float autocvar_g_weapon_charge_colormod_blue_half;
78 float autocvar_g_weapon_charge_colormod_green_half;
79 float autocvar_g_weapon_charge_colormod_hdrmultiplier;
80
81 METHOD(Vortex, wr_glow, vector(Vortex this, entity actor, entity wepent))
82 {
83         if (!STAT(WEP_CVAR_vortex_charge, actor)) return '0 0 0';
84         float charge = wepent.vortex_charge;
85         float animlimit = STAT(WEP_CVAR_vortex_charge_animlimit, actor);
86         vector g;
87         g.x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, charge / animlimit);
88         g.y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, charge / animlimit);
89         g.z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, charge / animlimit);
90         if (charge > animlimit)
91         {
92                 g.x += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (charge - animlimit) / (1 - animlimit);
93                 g.y += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (charge - animlimit) / (1 - animlimit);
94                 g.z += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (charge - animlimit) / (1 - animlimit);
95         }
96         return g;
97 }
98 #endif
99
100 REGISTER_NET_TEMP(TE_CSQC_VORTEXBEAMPARTICLE)
101
102 #if defined(SVQC)
103 void SendCSQCVortexBeamParticle(float charge) {
104         vector v;
105         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
106         WriteHeader(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
107         WriteCoord(MSG_BROADCAST, w_shotorg.x);
108         WriteCoord(MSG_BROADCAST, w_shotorg.y);
109         WriteCoord(MSG_BROADCAST, w_shotorg.z);
110         WriteCoord(MSG_BROADCAST, v.x);
111         WriteCoord(MSG_BROADCAST, v.y);
112         WriteCoord(MSG_BROADCAST, v.z);
113         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
114 }
115 #elif defined(CSQC)
116 NET_HANDLE(TE_CSQC_VORTEXBEAMPARTICLE, bool isNew)
117 {
118         vector shotorg, endpos;
119         float charge;
120         shotorg.x = ReadCoord(); shotorg.y = ReadCoord(); shotorg.z = ReadCoord();
121         endpos.x = ReadCoord(); endpos.y = ReadCoord(); endpos.z = ReadCoord();
122         charge = ReadByte() / 255.0;
123
124         pointparticles(EFFECT_VORTEX_MUZZLEFLASH, shotorg, normalize(endpos - shotorg) * 1000, 1);
125
126         //draw either the old v2.3 beam or the new beam
127         charge = sqrt(charge); // divide evenly among trail spacing and alpha
128         particles_alphamin = particles_alphamax = particles_fade = charge;
129
130         if(!MUTATOR_CALLHOOK(Particles_VortexBeam, shotorg, endpos))
131         if(autocvar_cl_particles_oldvortexbeam && (STAT(ALLOW_OLDVORTEXBEAM) || isdemo()))
132                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
133         else
134                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
135         return true;
136 }
137 #endif
138
139 #ifdef SVQC
140 spawnfunc(weapon_vortex) { weapon_defaultspawnfunc(this, WEP_VORTEX); }
141 spawnfunc(weapon_nex) { spawnfunc_weapon_vortex(this); }
142
143 REGISTER_MUTATOR(vortex_charge, true);
144
145 MUTATOR_HOOKFUNCTION(vortex_charge, GetPressedKeys)
146 {
147     entity player = M_ARGV(0, entity);
148
149         // WEAPONTODO
150         float xyspeed = vlen(vec2(player.velocity));
151     .entity weaponentity = weaponentities[0]; // TODO: unhardcode
152         if (player.(weaponentity).m_weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
153         {
154                 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
155                 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
156                 float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
157                 // add the extra charge
158                 player.(weaponentity).vortex_charge = min(1, player.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
159         }
160 }
161
162 void W_Vortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
163 {
164         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
165
166         mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
167         myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
168         mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
169         mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
170         myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
171         myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
172         myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
173
174         float flying;
175         flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
176
177         if(WEP_CVAR(vortex, charge))
178         {
179                 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * actor.(weaponentity).vortex_charge;
180                 actor.(weaponentity).vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
181                 // O RLY? -- divVerent
182                 // YA RLY -- FruitieX
183         }
184         else
185                 charge = 1;
186         mydmg *= charge;
187         myforce *= charge;
188
189         W_SetupShot(actor, weaponentity, true, 5, SND_NEXFIRE, CH_WEAPON_A, mydmg);
190         if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
191         {
192                 sound(actor, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(vortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(vortex, charge_animlimit)), ATTN_NORM);
193         }
194
195         yoda = 0;
196         damage_goodhits = 0;
197         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_VORTEX.m_id);
198
199         if(yoda && flying)
200                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
201         if(damage_goodhits && actor.vortex_lasthit)
202         {
203                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
204                 damage_goodhits = 0; // only every second time
205         }
206
207         actor.vortex_lasthit = damage_goodhits;
208
209         //beam and muzzle flash done on client
210         SendCSQCVortexBeamParticle(charge);
211
212         W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
213 }
214
215 .float vortex_chargepool_pauseregen_finished;
216
217 METHOD(Vortex, wr_aim, void(entity thiswep, entity actor))
218 {
219     if(bot_aim(actor, 1000000, 0, 1, false))
220         PHYS_INPUT_BUTTON_ATCK(actor) = true;
221     else
222     {
223         if(WEP_CVAR(vortex, charge))
224             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
225     }
226 }
227 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
228 {
229     if(WEP_CVAR(vortex, charge) && actor.(weaponentity).vortex_charge < WEP_CVAR(vortex, charge_limit))
230         actor.(weaponentity).vortex_charge = min(1, actor.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
231
232     if(weaponslot(weaponentity) == 0)
233         actor.vortex_charge = actor.(weaponentity).vortex_charge;
234
235     if(WEP_CVAR_SEC(vortex, chargepool))
236         if(actor.(weaponentity).vortex_chargepool_ammo < 1)
237         {
238             if(actor.vortex_chargepool_pauseregen_finished < time)
239                 actor.(weaponentity).vortex_chargepool_ammo = min(1, actor.(weaponentity).vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
240             actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
241         }
242
243     if(weaponslot(weaponentity) == 0)
244         actor.vortex_chargepool_ammo = actor.(weaponentity).vortex_chargepool_ammo;
245
246     if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
247         thiswep.wr_reload(thiswep, actor, weaponentity);
248     } else
249     {
250         if(fire & 1)
251         {
252             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
253             {
254                 W_Vortex_Attack(thiswep, actor, weaponentity, 0);
255                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
256             }
257         }
258         if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
259         {
260             if(WEP_CVAR(vortex, charge))
261             {
262                 actor.(weaponentity).vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
263                 float dt = frametime / W_TICSPERFRAME;
264
265                 if(actor.(weaponentity).vortex_charge < 1)
266                 {
267                     if(WEP_CVAR_SEC(vortex, chargepool))
268                     {
269                         if(WEP_CVAR_SEC(vortex, ammo))
270                         {
271                             // always deplete if secondary is held
272                             actor.vortex_chargepool_ammo = max(0, actor.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
273
274                             dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
275                             actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
276                             dt = min(dt, actor.vortex_chargepool_ammo);
277                             dt = max(0, dt);
278
279                             actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
280                         }
281                     }
282
283                     else if(WEP_CVAR_SEC(vortex, ammo))
284                     {
285                         if(fire & 2) // only eat ammo when the button is pressed
286                         {
287                             dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
288                             if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
289                             {
290                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
291                                 if(autocvar_g_balance_vortex_reload_ammo)
292                                 {
293                                     dt = min(dt, (actor.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
294                                     dt = max(0, dt);
295                                     if(dt > 0)
296                                     {
297                                         actor.clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
298                                     }
299                                     actor.(weapon_load[WEP_VORTEX.m_id]) = actor.clip_load;
300                                 }
301                                 else
302                                 {
303                                     dt = min(dt, (actor.(thiswep.ammo_field) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
304                                     dt = max(0, dt);
305                                     if(dt > 0)
306                                     {
307                                         actor.(thiswep.ammo_field) = max(WEP_CVAR_SEC(vortex, ammo), actor.(thiswep.ammo_field) - WEP_CVAR_SEC(vortex, ammo) * dt);
308                                     }
309                                 }
310                             }
311                             actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
312                         }
313                     }
314
315                     else
316                     {
317                         dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
318                         actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
319                     }
320                 }
321             }
322             else if(WEP_CVAR(vortex, secondary))
323             {
324                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
325                 {
326                     W_Vortex_Attack(thiswep, actor, weaponentity, 1);
327                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
328                 }
329             }
330         }
331     }
332 }
333 METHOD(Vortex, wr_setup, void(entity thiswep, entity actor))
334 {
335     actor.vortex_lasthit = 0;
336 }
337 METHOD(Vortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
338 {
339     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(vortex, ammo);
340     ammo_amount += (autocvar_g_balance_vortex_reload_ammo && actor.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
341     return ammo_amount;
342 }
343 METHOD(Vortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
344 {
345     if(WEP_CVAR(vortex, secondary))
346     {
347         // don't allow charging if we don't have enough ammo
348         float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(vortex, ammo);
349         ammo_amount += actor.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
350         return ammo_amount;
351     }
352     else
353     {
354         return false; // zoom is not a fire mode
355     }
356 }
357 METHOD(Vortex, wr_resetplayer, void(entity thiswep, entity actor))
358 {
359     if (WEP_CVAR(vortex, charge)) {
360         if (WEP_CVAR_SEC(vortex, chargepool)) {
361             actor.vortex_chargepool_ammo = 1;
362         }
363         actor.vortex_charge = WEP_CVAR(vortex, charge_start);
364         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
365         {
366             .entity weaponentity = weaponentities[slot];
367             actor.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start);
368
369             if (WEP_CVAR_SEC(vortex, chargepool))
370                 actor.(weaponentity).vortex_chargepool_ammo = 1;
371         }
372     }
373     actor.vortex_lasthit = 0;
374 }
375 METHOD(Vortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
376 {
377     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND_RELOAD);
378 }
379 METHOD(Vortex, wr_suicidemessage, Notification(entity thiswep))
380 {
381     return WEAPON_THINKING_WITH_PORTALS;
382 }
383 METHOD(Vortex, wr_killmessage, Notification(entity thiswep))
384 {
385     return WEAPON_VORTEX_MURDER;
386 }
387 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
388 {
389     return PHYS_INPUT_BUTTON_ATCK2(actor);
390 }
391
392 #endif
393 #ifdef CSQC
394
395 METHOD(Vortex, wr_impacteffect, void(entity thiswep, entity actor))
396 {
397     entity this = actor;
398     vector org2 = w_org + w_backoff * 6;
399     pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
400     if(!w_issilent)
401         sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
402 }
403 METHOD(Vortex, wr_init, void(entity thiswep))
404 {
405     if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
406     {
407         precache_pic("gfx/reticle_nex");
408     }
409 }
410 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
411 {
412     if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
413     {
414         reticle_image = "gfx/reticle_nex";
415         return true;
416     }
417     else
418     {
419         // no weapon specific image for this weapon
420         return false;
421     }
422 }
423
424 #endif
425 #endif