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