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