]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_nex.qc
No need for that extra prefix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_nex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ NEX,
4 /* function */ w_nex,
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 /* model    */ "nex",
10 /* netname  */ "nex",
11 /* fullname */ _("Vortex")
12 );
13
14 #define NEX_SETTINGS(w_cvar,w_prop) NEX_SETTINGS_LIST(w_cvar, w_prop, NEX, nex)
15 #define NEX_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
16         w_cvar(id, sn, BOTH, ammo) \
17         w_cvar(id, sn, BOTH, animtime) \
18         w_cvar(id, sn, BOTH, damage) \
19         w_cvar(id, sn, BOTH, force) \
20         w_cvar(id, sn, BOTH, damagefalloff_mindist) \
21         w_cvar(id, sn, BOTH, damagefalloff_maxdist) \
22         w_cvar(id, sn, BOTH, damagefalloff_halflife) \
23         w_cvar(id, sn, BOTH, damagefalloff_forcehalflife) \
24         w_cvar(id, sn, BOTH, refire) \
25         w_cvar(id, sn, NONE, charge) \
26         w_cvar(id, sn, NONE, charge_mindmg) \
27         w_cvar(id, sn, NONE, charge_shot_multiplier) \
28         w_cvar(id, sn, NONE, charge_animlimit) \
29         w_cvar(id, sn, NONE, charge_limit) \
30         w_cvar(id, sn, NONE, charge_rate) \
31         w_cvar(id, sn, NONE, charge_rot_rate) \
32         w_cvar(id, sn, NONE, charge_rot_pause) \
33         w_cvar(id, sn, NONE, charge_start) \
34         w_cvar(id, sn, NONE, charge_minspeed) \
35         w_cvar(id, sn, NONE, charge_maxspeed) \
36         w_cvar(id, sn, NONE, charge_velocity_rate) \
37         w_cvar(id, sn, NONE, secondary) \
38         w_cvar(id, sn, SEC,  chargepool) \
39         w_cvar(id, sn, SEC,  chargepool_regen) \
40         w_cvar(id, sn, SEC,  chargepool_pause_regen) \
41         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
42         w_prop(id, sn, float,  reloading_time, reload_time) \
43         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
44         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
45         w_prop(id, sn, string, weaponreplace, weaponreplace) \
46         w_prop(id, sn, float,  weaponstart, weaponstart) \
47         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
48
49 #ifdef SVQC
50 NEX_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
51 #endif
52 #else
53 #ifdef SVQC
54 void spawnfunc_weapon_nex (void) { weapon_defaultspawnfunc(WEP_NEX); }
55
56 void SendCSQCNexBeamParticle(float charge) {
57         vector v;
58         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
59         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
60         WriteByte(MSG_BROADCAST, TE_CSQC_NEXGUNBEAMPARTICLE);
61         WriteCoord(MSG_BROADCAST, w_shotorg_x);
62         WriteCoord(MSG_BROADCAST, w_shotorg_y);
63         WriteCoord(MSG_BROADCAST, w_shotorg_z);
64         WriteCoord(MSG_BROADCAST, v_x);
65         WriteCoord(MSG_BROADCAST, v_y);
66         WriteCoord(MSG_BROADCAST, v_z);
67         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
68 }
69
70 void W_Nex_Attack (float issecondary)
71 {
72         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
73         
74         mydmg = WEP_CVAR_BOTH(nex, !issecondary, damage);
75         myforce = WEP_CVAR_BOTH(nex, !issecondary, force);
76         mymindist = WEP_CVAR_BOTH(nex, !issecondary, damagefalloff_mindist);
77         mymaxdist = WEP_CVAR_BOTH(nex, !issecondary, damagefalloff_maxdist);
78         myhalflife = WEP_CVAR_BOTH(nex, !issecondary, damagefalloff_halflife);
79         myforcehalflife = WEP_CVAR_BOTH(nex, !issecondary, damagefalloff_forcehalflife);
80         myammo = WEP_CVAR_BOTH(nex, !issecondary, ammo);
81
82         float flying;
83         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
84
85         if(WEP_CVAR(nex, charge))
86         {
87                 charge = WEP_CVAR(nex, charge_mindmg) / mydmg + (1 - WEP_CVAR(nex, charge_mindmg) / mydmg) * self.nex_charge;
88                 self.nex_charge *= WEP_CVAR(nex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
89                 // O RLY? -- divVerent
90                 // YA RLY -- FruitieX
91         }
92         else
93                 charge = 1;
94         mydmg *= charge;
95         myforce *= charge;
96
97         W_SetupShot (self, TRUE, 5, "weapons/nexfire.wav", CH_WEAPON_A, mydmg);
98         if(charge > WEP_CVAR(nex, charge_animlimit) && WEP_CVAR(nex, charge_animlimit)) // if the Nex is overcharged, we play an extra sound
99         {
100                 sound (self, CH_WEAPON_B, "weapons/nexcharge.wav", VOL_BASE * (charge - 0.5 * WEP_CVAR(nex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(nex, charge_animlimit)), ATTN_NORM);
101         }
102
103         yoda = 0;
104         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_NEX);
105
106         if(yoda && flying)
107                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA); 
108
109         //beam and muzzle flash done on client
110         SendCSQCNexBeamParticle(charge);
111
112         W_DecreaseAmmo(myammo);
113 }
114
115 void spawnfunc_weapon_nex (void); // defined in t_items.qc
116
117 .float nex_chargepool_pauseregen_finished;
118 float w_nex(float req)
119 {
120         float dt;
121         float ammo_amount;
122         switch(req)
123         {
124                 case WR_AIM:
125                 {
126                         if(bot_aim(1000000, 0, 1, FALSE))
127                                 self.BUTTON_ATCK = TRUE;
128                         else
129                         {
130                                 if(WEP_CVAR(nex, charge))
131                                         self.BUTTON_ATCK2 = TRUE;
132                         }
133                         return TRUE;
134                 }
135                 case WR_THINK:
136                 {
137                         if(WEP_CVAR(nex, charge) && self.nex_charge < WEP_CVAR(nex, charge_limit))
138                                 self.nex_charge = min(1, self.nex_charge + WEP_CVAR(nex, charge_rate) * frametime / W_TICSPERFRAME);
139                                 
140                         if(WEP_CVAR_SEC(nex, chargepool))
141                                 if(self.nex_chargepool_ammo < 1)
142                                 {
143                                         if(self.nex_chargepool_pauseregen_finished < time)
144                                                 self.nex_chargepool_ammo = min(1, self.nex_chargepool_ammo + WEP_CVAR_SEC(nex, chargepool_regen) * frametime / W_TICSPERFRAME);
145                                         self.pauseregen_finished = max(self.pauseregen_finished, time + WEP_CVAR_SEC(nex, chargepool_pause_regen));
146                                 }
147
148                         if(autocvar_g_balance_nex_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(nex, ammo), WEP_CVAR_SEC(nex, ammo))) // forced reload
149                                 WEP_ACTION(self.weapon, WR_RELOAD);
150                         else
151                         {
152                                 if (self.BUTTON_ATCK)
153                                 {
154                                         if (weapon_prepareattack(0, WEP_CVAR_PRI(nex, refire)))
155                                         {
156                                                 W_Nex_Attack(0);
157                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(nex, animtime), w_ready);
158                                         }
159                                 }
160                                 if ((WEP_CVAR(nex, charge) && !WEP_CVAR(nex, secondary)) ? (self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) : self.BUTTON_ATCK2)
161                                 {
162                                         if(WEP_CVAR(nex, charge))
163                                         {
164                                                 self.nex_charge_rottime = time + WEP_CVAR(nex, charge_rot_pause);
165                                                 dt = frametime / W_TICSPERFRAME;
166
167                                                 if(self.nex_charge < 1)
168                                                 {
169                                                         if(WEP_CVAR_SEC(nex, chargepool))
170                                                         {
171                                                                 if(WEP_CVAR_SEC(nex, ammo))
172                                                                 {
173                                                                         // always deplete if secondary is held
174                                                                         self.nex_chargepool_ammo = max(0, self.nex_chargepool_ammo - WEP_CVAR_SEC(nex, ammo) * dt);
175
176                                                                         dt = min(dt, (1 - self.nex_charge) / WEP_CVAR(nex, charge_rate));
177                                                                         self.nex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(nex, chargepool_pause_regen);
178                                                                         dt = min(dt, self.nex_chargepool_ammo);
179                                                                         dt = max(0, dt);
180
181                                                                         self.nex_charge += dt * WEP_CVAR(nex, charge_rate);
182                                                                 }
183                                                         }
184
185                                                         else if(WEP_CVAR_SEC(nex, ammo))
186                                                         {
187                                                                 if(self.BUTTON_ATCK2) // only eat ammo when the button is pressed
188                                                                 {
189                                                                         dt = min(dt, (1 - self.nex_charge) / WEP_CVAR(nex, charge_rate));
190                                                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
191                                                                         {
192                                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
193                                                                                 if(autocvar_g_balance_nex_reload_ammo)
194                                                                                 {
195                                                                                         dt = min(dt, (self.clip_load - WEP_CVAR_PRI(nex, ammo)) / WEP_CVAR_SEC(nex, ammo));
196                                                                                         dt = max(0, dt);
197                                                                                         if(dt > 0)
198                                                                                         {
199                                                                                                 self.clip_load = max(WEP_CVAR_SEC(nex, ammo), self.clip_load - WEP_CVAR_SEC(nex, ammo) * dt);
200                                                                                         }
201                                                                                         self.(weapon_load[WEP_NEX]) = self.clip_load;
202                                                                                 }
203                                                                                 else
204                                                                                 {
205                                                                                         dt = min(dt, (self.ammo_cells - WEP_CVAR_PRI(nex, ammo)) / WEP_CVAR_SEC(nex, ammo));
206                                                                                         dt = max(0, dt);
207                                                                                         if(dt > 0)
208                                                                                         {
209                                                                                                 self.ammo_cells = max(WEP_CVAR_SEC(nex, ammo), self.ammo_cells - WEP_CVAR_SEC(nex, ammo) * dt);
210                                                                                         }
211                                                                                 }
212                                                                         }
213                                                                         self.nex_charge += dt * WEP_CVAR(nex, charge_rate);
214                                                                 }
215                                                         }
216
217                                                         else
218                                                         {
219                                                                 dt = min(dt, (1 - self.nex_charge) / WEP_CVAR(nex, charge_rate));
220                                                                 self.nex_charge += dt * WEP_CVAR(nex, charge_rate);
221                                                         }
222                                                 }
223                                         }
224                                         else if(WEP_CVAR(nex, secondary))
225                                         {
226                                                 if (weapon_prepareattack(0, WEP_CVAR_SEC(nex, refire)))
227                                                 {
228                                                         W_Nex_Attack(1);
229                                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_SEC(nex, animtime), w_ready);
230                                                 }
231                                         }
232                                 }
233                         }
234                         
235                         return TRUE;
236                 }
237                 case WR_INIT:
238                 {
239                         precache_model ("models/nexflash.md3");
240                         precache_model ("models/weapons/g_nex.md3");
241                         precache_model ("models/weapons/v_nex.md3");
242                         precache_model ("models/weapons/h_nex.iqm");
243                         precache_sound ("weapons/nexfire.wav");
244                         precache_sound ("weapons/nexcharge.wav");
245                         precache_sound ("weapons/nexwhoosh1.wav");
246                         precache_sound ("weapons/nexwhoosh2.wav");
247                         precache_sound ("weapons/nexwhoosh3.wav");
248                         NEX_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
249                         return TRUE;
250                 }
251                 case WR_SETUP:
252                 {
253                         self.current_ammo = ammo_cells;
254                         return TRUE;
255                 }
256                 case WR_CHECKAMMO1:
257                 {
258                         ammo_amount = self.ammo_cells >= WEP_CVAR_PRI(nex, ammo);
259                         ammo_amount += (autocvar_g_balance_nex_reload_ammo && self.(weapon_load[WEP_NEX]) >= WEP_CVAR_PRI(nex, ammo));
260                         return ammo_amount;
261                 }
262                 case WR_CHECKAMMO2:
263                 {
264                         if(WEP_CVAR(nex, secondary))
265                         {
266                                 // don't allow charging if we don't have enough ammo
267                                 ammo_amount = self.ammo_cells >= WEP_CVAR_SEC(nex, ammo);
268                                 ammo_amount += self.(weapon_load[WEP_NEX]) >= WEP_CVAR_SEC(nex, 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                         NEX_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(nex, ammo), WEP_CVAR_SEC(nex, 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_NEX_MURDER;
293                 }
294         }
295         return TRUE;
296 }
297 #endif
298 #ifdef CSQC
299 float w_nex(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                         return TRUE;
317                 }
318         }
319         return TRUE;
320 }
321 #endif
322 #endif