]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
Merge branch 'master' into TimePath/stats
[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 void W_Vortex_Attack(Weapon thiswep, float issecondary)
108 {SELFPARAM();
109         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
110
111         mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
112         myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
113         mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
114         mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
115         myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
116         myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
117         myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
118
119         float flying;
120         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
121
122         if(WEP_CVAR(vortex, charge))
123         {
124                 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * self.vortex_charge;
125                 self.vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
126                 // O RLY? -- divVerent
127                 // YA RLY -- FruitieX
128         }
129         else
130                 charge = 1;
131         mydmg *= charge;
132         myforce *= charge;
133
134         W_SetupShot(self, true, 5, SND(NEXFIRE), CH_WEAPON_A, mydmg);
135         if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
136         {
137                 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);
138         }
139
140         yoda = 0;
141         damage_goodhits = 0;
142         FireRailgunBullet(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_VORTEX.m_id);
143
144         if(yoda && flying)
145                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
146         if(damage_goodhits && self.vortex_lasthit)
147         {
148                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
149                 damage_goodhits = 0; // only every second time
150         }
151
152         self.vortex_lasthit = damage_goodhits;
153
154         //beam and muzzle flash done on client
155         SendCSQCVortexBeamParticle(charge);
156
157         W_DecreaseAmmo(thiswep, self, myammo);
158 }
159
160 .float vortex_chargepool_pauseregen_finished;
161
162                 METHOD(Vortex, wr_aim, void(entity thiswep))
163                 {
164                         if(bot_aim(1000000, 0, 1, false))
165                                 self.BUTTON_ATCK = true;
166                         else
167                         {
168                                 if(WEP_CVAR(vortex, charge))
169                                         self.BUTTON_ATCK2 = true;
170                         }
171                 }
172                 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
173                 {
174                         if(WEP_CVAR(vortex, charge) && actor.vortex_charge < WEP_CVAR(vortex, charge_limit))
175                                 actor.vortex_charge = min(1, actor.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
176
177                         if(WEP_CVAR_SEC(vortex, chargepool))
178                                 if(actor.vortex_chargepool_ammo < 1)
179                                 {
180                                         if(actor.vortex_chargepool_pauseregen_finished < time)
181                                                 actor.vortex_chargepool_ammo = min(1, actor.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
182                                         actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
183                                 }
184
185                         if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
186                                 Weapon w = get_weaponinfo(actor.weapon);
187                                 w.wr_reload(w);
188                         } else
189                         {
190                                 if(fire & 1)
191                                 {
192                                         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
193                                         {
194                                                 W_Vortex_Attack(thiswep, 0);
195                                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
196                                         }
197                                 }
198                                 if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (actor.BUTTON_ZOOM | actor.BUTTON_ZOOMSCRIPT) : (fire & 2))
199                                 {
200                                         if(WEP_CVAR(vortex, charge))
201                                         {
202                                                 actor.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
203                                                 float dt = frametime / W_TICSPERFRAME;
204
205                                                 if(actor.vortex_charge < 1)
206                                                 {
207                                                         if(WEP_CVAR_SEC(vortex, chargepool))
208                                                         {
209                                                                 if(WEP_CVAR_SEC(vortex, ammo))
210                                                                 {
211                                                                         // always deplete if secondary is held
212                                                                         actor.vortex_chargepool_ammo = max(0, actor.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
213
214                                                                         dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
215                                                                         actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
216                                                                         dt = min(dt, actor.vortex_chargepool_ammo);
217                                                                         dt = max(0, dt);
218
219                                                                         actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
220                                                                 }
221                                                         }
222
223                                                         else if(WEP_CVAR_SEC(vortex, ammo))
224                                                         {
225                                                                 if(fire & 2) // only eat ammo when the button is pressed
226                                                                 {
227                                                                         dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
228                                                                         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
229                                                                         {
230                                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
231                                                                                 if(autocvar_g_balance_vortex_reload_ammo)
232                                                                                 {
233                                                                                         dt = min(dt, (actor.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
234                                                                                         dt = max(0, dt);
235                                                                                         if(dt > 0)
236                                                                                         {
237                                                                                                 actor.clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
238                                                                                         }
239                                                                                         actor.(weapon_load[WEP_VORTEX.m_id]) = actor.clip_load;
240                                                                                 }
241                                                                                 else
242                                                                                 {
243                                                                                         dt = min(dt, (actor.WEP_AMMO(VORTEX) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
244                                                                                         dt = max(0, dt);
245                                                                                         if(dt > 0)
246                                                                                         {
247                                                                                                 actor.WEP_AMMO(VORTEX) = max(WEP_CVAR_SEC(vortex, ammo), actor.WEP_AMMO(VORTEX) - WEP_CVAR_SEC(vortex, ammo) * dt);
248                                                                                         }
249                                                                                 }
250                                                                         }
251                                                                         actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
252                                                                 }
253                                                         }
254
255                                                         else
256                                                         {
257                                                                 dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
258                                                                 actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
259                                                         }
260                                                 }
261                                         }
262                                         else if(WEP_CVAR(vortex, secondary))
263                                         {
264                                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
265                                                 {
266                                                         W_Vortex_Attack(thiswep, 1);
267                                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
268                                                 }
269                                         }
270                                 }
271                         }
272                 }
273                 METHOD(Vortex, wr_init, void(entity thiswep))
274                 {
275                         VORTEX_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
276                 }
277                 METHOD(Vortex, wr_setup, void(entity thiswep))
278                 {
279                         self.vortex_lasthit = 0;
280                 }
281                 METHOD(Vortex, wr_checkammo1, bool(entity thiswep))
282                 {
283                         float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_PRI(vortex, ammo);
284                         ammo_amount += (autocvar_g_balance_vortex_reload_ammo && self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
285                         return ammo_amount;
286                 }
287                 METHOD(Vortex, wr_checkammo2, bool(entity thiswep))
288                 {
289                         if(WEP_CVAR(vortex, secondary))
290                         {
291                                 // don't allow charging if we don't have enough ammo
292                                 float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_SEC(vortex, ammo);
293                                 ammo_amount += self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
294                                 return ammo_amount;
295                         }
296                         else
297                         {
298                                 return false; // zoom is not a fire mode
299                         }
300                 }
301                 METHOD(Vortex, wr_config, void(entity thiswep))
302                 {
303                         VORTEX_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
304                 }
305                 METHOD(Vortex, wr_resetplayer, void(entity thiswep))
306                 {
307                         if (WEP_CVAR(vortex, charge)) {
308                                 if (WEP_CVAR_SEC(vortex, chargepool)) {
309                                         self.vortex_chargepool_ammo = 1;
310                                 }
311                                 self.vortex_charge = WEP_CVAR(vortex, charge_start);
312                         }
313                         self.vortex_lasthit = 0;
314                 }
315                 METHOD(Vortex, wr_reload, void(entity thiswep))
316                 {
317                         W_Reload(self, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
318                 }
319                 METHOD(Vortex, wr_suicidemessage, int(entity thiswep))
320                 {
321                         return WEAPON_THINKING_WITH_PORTALS;
322                 }
323                 METHOD(Vortex, wr_killmessage, int(entity thiswep))
324                 {
325                         return WEAPON_VORTEX_MURDER;
326                 }
327
328 #endif
329 #ifdef CSQC
330 float autocvar_g_balance_vortex_secondary = 0; // WEAPONTODO
331
332                 METHOD(Vortex, wr_impacteffect, void(entity thiswep))
333                 {
334                         vector org2 = w_org + w_backoff * 6;
335                         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
336                         if(!w_issilent)
337                                 sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
338                 }
339                 METHOD(Vortex, wr_init, void(entity thiswep))
340                 {
341                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
342                         {
343                                 precache_pic("gfx/reticle_nex");
344                         }
345                 }
346                 METHOD(Vortex, wr_zoomreticle, bool(entity thiswep))
347                 {
348                         if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
349                         {
350                                 reticle_image = "gfx/reticle_nex";
351                                 return true;
352                         }
353                         else
354                         {
355                                 // no weapon specific image for this weapon
356                                 return false;
357                         }
358                 }
359
360 #endif
361 #endif