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