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