]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
Merge branch 'master' into Mario/snake
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
1 #ifndef IMPLEMENTATION
2 REGISTER_WEAPON(
3 /* WEP_##id  */ VORTEX,
4 /* function  */ W_Vortex,
5 /* ammotype  */ ammo_cells,
6 /* impulse   */ 7,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating    */ BOT_PICKUP_RATING_HIGH,
9 /* color     */ '0.5 1 1',
10 /* modelname */ "nex",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairnex 0.65",
13 /* wepimg    */ "weaponnex",
14 /* refname   */ "vortex",
15 /* wepname   */ _("Vortex")
16 );
17
18 #define VORTEX_SETTINGS(w_cvar,w_prop) VORTEX_SETTINGS_LIST(w_cvar, w_prop, VORTEX, vortex)
19 #define VORTEX_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, BOTH, ammo) \
21         w_cvar(id, sn, BOTH, animtime) \
22         w_cvar(id, sn, BOTH, damage) \
23         w_cvar(id, sn, BOTH, force) \
24         w_cvar(id, sn, BOTH, damagefalloff_mindist) \
25         w_cvar(id, sn, BOTH, damagefalloff_maxdist) \
26         w_cvar(id, sn, BOTH, damagefalloff_halflife) \
27         w_cvar(id, sn, BOTH, damagefalloff_forcehalflife) \
28         w_cvar(id, sn, BOTH, refire) \
29         w_cvar(id, sn, NONE, charge) \
30         w_cvar(id, sn, NONE, charge_mindmg) \
31         w_cvar(id, sn, NONE, charge_shot_multiplier) \
32         w_cvar(id, sn, NONE, charge_animlimit) \
33         w_cvar(id, sn, NONE, charge_limit) \
34         w_cvar(id, sn, NONE, charge_rate) \
35         w_cvar(id, sn, NONE, charge_rot_rate) \
36         w_cvar(id, sn, NONE, charge_rot_pause) \
37         w_cvar(id, sn, NONE, charge_start) \
38         w_cvar(id, sn, NONE, charge_minspeed) \
39         w_cvar(id, sn, NONE, charge_maxspeed) \
40         w_cvar(id, sn, NONE, charge_velocity_rate) \
41         w_cvar(id, sn, NONE, secondary) \
42         w_cvar(id, sn, SEC,  chargepool) \
43         w_cvar(id, sn, SEC,  chargepool_regen) \
44         w_cvar(id, sn, SEC,  chargepool_pause_regen) \
45         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
46         w_prop(id, sn, float,  reloading_time, reload_time) \
47         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
48         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
49         w_prop(id, sn, string, weaponreplace, weaponreplace) \
50         w_prop(id, sn, float,  weaponstart, weaponstart) \
51         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
52         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
53
54 #ifdef SVQC
55 VORTEX_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
56
57 .float vortex_lasthit;
58 #endif
59 #endif
60 #ifdef IMPLEMENTATION
61 #ifdef SVQC
62 void spawnfunc_weapon_vortex(void) { weapon_defaultspawnfunc(WEP_VORTEX.m_id); }
63 void spawnfunc_weapon_nex(void) { spawnfunc_weapon_vortex(); }
64
65 void SendCSQCVortexBeamParticle(float charge) {
66         vector v;
67         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
68         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
69         WriteByte(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
70         WriteCoord(MSG_BROADCAST, w_shotorg.x);
71         WriteCoord(MSG_BROADCAST, w_shotorg.y);
72         WriteCoord(MSG_BROADCAST, w_shotorg.z);
73         WriteCoord(MSG_BROADCAST, v.x);
74         WriteCoord(MSG_BROADCAST, v.y);
75         WriteCoord(MSG_BROADCAST, v.z);
76         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
77 }
78
79 void W_Vortex_Attack(float issecondary)
80 {SELFPARAM();
81         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
82
83         mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
84         myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
85         mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
86         mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
87         myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
88         myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
89         myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
90
91         float flying;
92         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
93
94         if(WEP_CVAR(vortex, charge))
95         {
96                 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * self.vortex_charge;
97                 self.vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
98                 // O RLY? -- divVerent
99                 // YA RLY -- FruitieX
100         }
101         else
102                 charge = 1;
103         mydmg *= charge;
104         myforce *= charge;
105
106         W_SetupShot(self, true, 5, SND(NEXFIRE), CH_WEAPON_A, mydmg);
107         if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
108         {
109                 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);
110         }
111
112         yoda = 0;
113         damage_goodhits = 0;
114         FireRailgunBullet(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_VORTEX.m_id);
115
116         if(yoda && flying)
117                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
118         if(damage_goodhits && self.vortex_lasthit)
119         {
120                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
121                 damage_goodhits = 0; // only every second time
122         }
123
124         self.vortex_lasthit = damage_goodhits;
125
126         //beam and muzzle flash done on client
127         SendCSQCVortexBeamParticle(charge);
128
129         W_DecreaseAmmo(myammo);
130 }
131
132 void spawnfunc_weapon_vortex(void); // defined in t_items.qc
133
134 .float vortex_chargepool_pauseregen_finished;
135 bool W_Vortex(int req)
136 {SELFPARAM();
137         float dt;
138         float ammo_amount;
139         switch(req)
140         {
141                 case WR_AIM:
142                 {
143                         if(bot_aim(1000000, 0, 1, false))
144                                 self.BUTTON_ATCK = true;
145                         else
146                         {
147                                 if(WEP_CVAR(vortex, charge))
148                                         self.BUTTON_ATCK2 = true;
149                         }
150                         return true;
151                 }
152                 case WR_THINK:
153                 {
154                         if(WEP_CVAR(vortex, charge) && self.vortex_charge < WEP_CVAR(vortex, charge_limit))
155                                 self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
156
157                         if(WEP_CVAR_SEC(vortex, chargepool))
158                                 if(self.vortex_chargepool_ammo < 1)
159                                 {
160                                         if(self.vortex_chargepool_pauseregen_finished < time)
161                                                 self.vortex_chargepool_ammo = min(1, self.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
162                                         self.pauseregen_finished = max(self.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
163                                 }
164
165                         if(autocvar_g_balance_vortex_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) // forced reload
166                                 WEP_ACTION(self.weapon, WR_RELOAD);
167                         else
168                         {
169                                 if(self.BUTTON_ATCK)
170                                 {
171                                         if(weapon_prepareattack(0, WEP_CVAR_PRI(vortex, refire)))
172                                         {
173                                                 W_Vortex_Attack(0);
174                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
175                                         }
176                                 }
177                                 if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) : self.BUTTON_ATCK2)
178                                 {
179                                         if(WEP_CVAR(vortex, charge))
180                                         {
181                                                 self.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
182                                                 dt = frametime / W_TICSPERFRAME;
183
184                                                 if(self.vortex_charge < 1)
185                                                 {
186                                                         if(WEP_CVAR_SEC(vortex, chargepool))
187                                                         {
188                                                                 if(WEP_CVAR_SEC(vortex, ammo))
189                                                                 {
190                                                                         // always deplete if secondary is held
191                                                                         self.vortex_chargepool_ammo = max(0, self.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
192
193                                                                         dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
194                                                                         self.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
195                                                                         dt = min(dt, self.vortex_chargepool_ammo);
196                                                                         dt = max(0, dt);
197
198                                                                         self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
199                                                                 }
200                                                         }
201
202                                                         else if(WEP_CVAR_SEC(vortex, ammo))
203                                                         {
204                                                                 if(self.BUTTON_ATCK2) // only eat ammo when the button is pressed
205                                                                 {
206                                                                         dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
207                                                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
208                                                                         {
209                                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
210                                                                                 if(autocvar_g_balance_vortex_reload_ammo)
211                                                                                 {
212                                                                                         dt = min(dt, (self.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
213                                                                                         dt = max(0, dt);
214                                                                                         if(dt > 0)
215                                                                                         {
216                                                                                                 self.clip_load = max(WEP_CVAR_SEC(vortex, ammo), self.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
217                                                                                         }
218                                                                                         self.(weapon_load[WEP_VORTEX.m_id]) = self.clip_load;
219                                                                                 }
220                                                                                 else
221                                                                                 {
222                                                                                         dt = min(dt, (self.WEP_AMMO(VORTEX) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
223                                                                                         dt = max(0, dt);
224                                                                                         if(dt > 0)
225                                                                                         {
226                                                                                                 self.WEP_AMMO(VORTEX) = max(WEP_CVAR_SEC(vortex, ammo), self.WEP_AMMO(VORTEX) - WEP_CVAR_SEC(vortex, ammo) * dt);
227                                                                                         }
228                                                                                 }
229                                                                         }
230                                                                         self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
231                                                                 }
232                                                         }
233
234                                                         else
235                                                         {
236                                                                 dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
237                                                                 self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
238                                                         }
239                                                 }
240                                         }
241                                         else if(WEP_CVAR(vortex, secondary))
242                                         {
243                                                 if(weapon_prepareattack(0, WEP_CVAR_SEC(vortex, refire)))
244                                                 {
245                                                         W_Vortex_Attack(1);
246                                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
247                                                 }
248                                         }
249                                 }
250                         }
251
252                         return true;
253                 }
254                 case WR_INIT:
255                 {
256                         VORTEX_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
257                         return true;
258                 }
259                 case WR_SETUP:
260                 {
261                         self.vortex_lasthit = 0;
262                         return true;
263                 }
264                 case WR_CHECKAMMO1:
265                 {
266                         ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_PRI(vortex, ammo);
267                         ammo_amount += (autocvar_g_balance_vortex_reload_ammo && self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
268                         return ammo_amount;
269                 }
270                 case WR_CHECKAMMO2:
271                 {
272                         if(WEP_CVAR(vortex, secondary))
273                         {
274                                 // don't allow charging if we don't have enough ammo
275                                 ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_SEC(vortex, ammo);
276                                 ammo_amount += self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
277                                 return ammo_amount;
278                         }
279                         else
280                         {
281                                 return false; // zoom is not a fire mode
282                         }
283                 }
284                 case WR_CONFIG:
285                 {
286                         VORTEX_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
287                         return true;
288                 }
289                 case WR_RESETPLAYER:
290                 {
291                         self.vortex_lasthit = 0;
292                         return true;
293                 }
294                 case WR_RELOAD:
295                 {
296                         W_Reload(min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
297                         return true;
298                 }
299                 case WR_SUICIDEMESSAGE:
300                 {
301                         return WEAPON_THINKING_WITH_PORTALS;
302                 }
303                 case WR_KILLMESSAGE:
304                 {
305                         return WEAPON_VORTEX_MURDER;
306                 }
307         }
308         return false;
309 }
310 #endif
311 #ifdef CSQC
312 float autocvar_g_balance_vortex_secondary = 0; // WEAPONTODO
313 bool W_Vortex(int req)
314 {SELFPARAM();
315         switch(req)
316         {
317                 case WR_IMPACTEFFECT:
318                 {
319                         vector org2;
320                         org2 = w_org + w_backoff * 6;
321                         pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
322                         if(!w_issilent)
323                                 sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
324
325                         return true;
326                 }
327                 case WR_INIT:
328                 {
329                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
330                         {
331                                 precache_pic("gfx/reticle_nex");
332                         }
333                         return true;
334                 }
335                 case WR_ZOOMRETICLE:
336                 {
337                         if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
338                         {
339                                 reticle_image = "gfx/reticle_nex";
340                                 return true;
341                         }
342                         else
343                         {
344                                 // no weapon specific image for this weapon
345                                 return false;
346                         }
347                 }
348         }
349         return false;
350 }
351 #endif
352 #endif