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