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