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