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