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