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