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