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