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