]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
GetResourceAmount --> GetResource, SetResourceAmount --> SetResource
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
1 #include "vortex.qh"
2
3 //REGISTER_STAT(WEP_CVAR_vortex_charge, bool, WEP_CVAR(vortex, charge))
4 //REGISTER_STAT(WEP_CVAR_vortex_charge_animlimit, float, WEP_CVAR(vortex, charge_animlimit))
5
6 #if defined(GAMEQC)
7 float autocvar_g_weapon_charge_colormod_red_full;
8 float autocvar_g_weapon_charge_colormod_red_half;
9 float autocvar_g_weapon_charge_colormod_green_full;
10 float autocvar_g_weapon_charge_colormod_blue_full;
11 float autocvar_g_weapon_charge_colormod_blue_half;
12 float autocvar_g_weapon_charge_colormod_green_half;
13 float autocvar_g_weapon_charge_colormod_hdrmultiplier;
14
15 METHOD(Vortex, wr_glow, vector(Vortex this, entity actor, entity wepent))
16 {
17         if (!WEP_CVAR(vortex, charge)) return '0 0 0';
18         float charge = wepent.vortex_charge;
19         float animlimit = WEP_CVAR(vortex, charge_animlimit);
20         vector g;
21         g.x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, charge / animlimit);
22         g.y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, charge / animlimit);
23         g.z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, charge / animlimit);
24         if (charge > animlimit)
25         {
26                 g.x += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (charge - animlimit) / (1 - animlimit);
27                 g.y += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (charge - animlimit) / (1 - animlimit);
28                 g.z += autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (charge - animlimit) / (1 - animlimit);
29         }
30         return g;
31 }
32 #endif
33
34 REGISTER_NET_TEMP(TE_CSQC_VORTEXBEAMPARTICLE)
35
36 #if defined(SVQC)
37 void SendCSQCVortexBeamParticle(float charge) {
38         vector v;
39         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
40         WriteHeader(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
41         WriteVector(MSG_BROADCAST, w_shotorg);
42         WriteVector(MSG_BROADCAST, v);
43         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
44 }
45 #elif defined(CSQC)
46 NET_HANDLE(TE_CSQC_VORTEXBEAMPARTICLE, bool isNew)
47 {
48         float charge;
49     vector shotorg = ReadVector();
50     vector endpos = ReadVector();
51         charge = ReadByte() / 255.0;
52
53         pointparticles(EFFECT_VORTEX_MUZZLEFLASH, shotorg, normalize(endpos - shotorg) * 1000, 1);
54
55         //draw either the old v2.3 beam or the new beam
56         charge = sqrt(charge); // divide evenly among trail spacing and alpha
57         particles_alphamin = particles_alphamax = particles_fade = charge;
58
59         if(!MUTATOR_CALLHOOK(Particles_VortexBeam, shotorg, endpos))
60         {
61                 if(autocvar_cl_particles_oldvortexbeam && (STAT(ALLOW_OLDVORTEXBEAM) || isdemo()))
62                         WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
63                 else
64                         WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
65         }
66         return true;
67 }
68 #endif
69
70 #ifdef SVQC
71
72 REGISTER_MUTATOR(vortex_charge, true);
73
74 MUTATOR_HOOKFUNCTION(vortex_charge, GetPressedKeys)
75 {
76     entity player = M_ARGV(0, entity);
77
78         // WEAPONTODO
79     if(!WEP_CVAR(vortex, charge) || !WEP_CVAR(vortex, charge_velocity_rate))
80         return;
81
82     for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
83     {
84         .entity weaponentity = weaponentities[slot];
85
86         if (player.(weaponentity).m_weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && vdist(vec2(player.velocity), >, WEP_CVAR(vortex, charge_minspeed)))
87         {
88             float xyspeed = vlen(vec2(player.velocity));
89                 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
90                 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
91                 float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
92                 // add the extra charge
93                 player.(weaponentity).vortex_charge = min(1, player.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
94         }
95     }
96 }
97
98 void W_Vortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float issecondary)
99 {
100         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
101
102         mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
103         myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
104         mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
105         mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
106         myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
107         myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
108         myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
109
110     float dtype = thiswep.m_id;
111     if(WEP_CVAR_BOTH(vortex, !issecondary, armorpierce))
112         dtype |= HITTYPE_ARMORPIERCE;
113
114         float flying;
115         flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
116
117         if(WEP_CVAR(vortex, charge))
118         {
119                 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * actor.(weaponentity).vortex_charge;
120                 actor.(weaponentity).vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
121                 // O RLY? -- divVerent
122                 // YA RLY -- FruitieX
123         }
124         else
125                 charge = 1;
126         mydmg *= charge;
127         myforce *= charge;
128
129         W_SetupShot(actor, weaponentity, true, 5, SND_NEXFIRE, CH_WEAPON_A, mydmg, dtype);
130         if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
131         {
132                 sound(actor, 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);
133         }
134
135         yoda = 0;
136         damage_goodhits = 0;
137         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, dtype);
138
139         if(yoda && flying)
140                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
141         if(damage_goodhits && actor.vortex_lasthit)
142         {
143                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
144                 damage_goodhits = 0; // only every second time
145         }
146
147         actor.vortex_lasthit = damage_goodhits;
148
149         //beam and muzzle flash done on client
150         SendCSQCVortexBeamParticle(charge);
151
152         W_DecreaseAmmo(thiswep, actor, myammo, weaponentity);
153 }
154
155 .float vortex_chargepool_pauseregen_finished;
156
157 METHOD(Vortex, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
158 {
159     if(bot_aim(actor, weaponentity, 1000000, 0, 1, false))
160         PHYS_INPUT_BUTTON_ATCK(actor) = true;
161     else
162     {
163         if(WEP_CVAR(vortex, charge))
164             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
165     }
166 }
167 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
168 {
169     if(WEP_CVAR(vortex, charge) && actor.(weaponentity).vortex_charge < WEP_CVAR(vortex, charge_limit))
170         actor.(weaponentity).vortex_charge = min(1, actor.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
171
172     if(WEP_CVAR_SEC(vortex, chargepool))
173         if(actor.(weaponentity).vortex_chargepool_ammo < 1)
174         {
175             if(actor.vortex_chargepool_pauseregen_finished < time)
176                 actor.(weaponentity).vortex_chargepool_ammo = min(1, actor.(weaponentity).vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
177             actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
178         }
179
180     if(autocvar_g_balance_vortex_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
181         thiswep.wr_reload(thiswep, actor, weaponentity);
182     } else
183     {
184         if(fire & 1)
185         {
186             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
187             {
188                 W_Vortex_Attack(thiswep, actor, weaponentity, 0);
189                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
190             }
191         }
192         if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (PHYS_INPUT_BUTTON_ZOOM(actor) | PHYS_INPUT_BUTTON_ZOOMSCRIPT(actor)) : (fire & 2))
193         {
194             if(WEP_CVAR(vortex, charge))
195             {
196                 actor.(weaponentity).vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
197                 float dt = frametime / W_TICSPERFRAME;
198
199                 if(actor.(weaponentity).vortex_charge < 1)
200                 {
201                     if(WEP_CVAR_SEC(vortex, chargepool))
202                     {
203                         if(WEP_CVAR_SEC(vortex, ammo))
204                         {
205                             // always deplete if secondary is held
206                             actor.(weaponentity).vortex_chargepool_ammo = max(0, actor.(weaponentity).vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
207
208                             dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
209                             actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
210                             dt = min(dt, actor.(weaponentity).vortex_chargepool_ammo);
211                             dt = max(0, dt);
212
213                             actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
214                         }
215                     }
216
217                     else if(WEP_CVAR_SEC(vortex, ammo))
218                     {
219                         if(fire & 2) // only eat ammo when the button is pressed
220                         {
221                             dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
222                             if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
223                             {
224                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
225                                 if(autocvar_g_balance_vortex_reload_ammo)
226                                 {
227                                     dt = min(dt, (actor.(weaponentity).clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
228                                     dt = max(0, dt);
229                                     if(dt > 0)
230                                     {
231                                         actor.(weaponentity).clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.(weaponentity).clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
232                                     }
233                                     actor.(weaponentity).(weapon_load[thiswep.m_id]) = actor.(weaponentity).clip_load;
234                                 }
235                                 else
236                                 {
237                                     dt = min(dt, (GetResource(actor, thiswep.ammo_type) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
238                                     dt = max(0, dt);
239                                     if(dt > 0)
240                                     {
241                                         SetResource(actor, thiswep.ammo_type, max(WEP_CVAR_SEC(vortex, ammo), GetResource(actor, thiswep.ammo_type) - WEP_CVAR_SEC(vortex, ammo) * dt));
242                                     }
243                                 }
244                             }
245                             actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
246                         }
247                     }
248
249                     else
250                     {
251                         dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate));
252                         actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
253                     }
254                 }
255             }
256             else if(WEP_CVAR(vortex, secondary))
257             {
258                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
259                 {
260                     W_Vortex_Attack(thiswep, actor, weaponentity, 1);
261                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
262                 }
263             }
264         }
265     }
266 }
267 METHOD(Vortex, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
268 {
269     actor.vortex_lasthit = 0;
270 }
271 METHOD(Vortex, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
272 {
273     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(vortex, ammo);
274     ammo_amount += (autocvar_g_balance_vortex_reload_ammo && actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
275     return ammo_amount;
276 }
277 METHOD(Vortex, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
278 {
279     if(WEP_CVAR(vortex, secondary))
280     {
281         // don't allow charging if we don't have enough ammo
282         float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(vortex, ammo);
283         ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
284         return ammo_amount;
285     }
286     else
287     {
288         return false; // zoom is not a fire mode
289     }
290 }
291 METHOD(Vortex, wr_resetplayer, void(entity thiswep, entity actor))
292 {
293     if (WEP_CVAR(vortex, charge)) {
294         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
295         {
296             .entity weaponentity = weaponentities[slot];
297             actor.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start);
298
299             if (WEP_CVAR_SEC(vortex, chargepool))
300                 actor.(weaponentity).vortex_chargepool_ammo = 1;
301         }
302     }
303     actor.vortex_lasthit = 0;
304 }
305 METHOD(Vortex, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
306 {
307     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND_RELOAD);
308 }
309 METHOD(Vortex, wr_suicidemessage, Notification(entity thiswep))
310 {
311     return WEAPON_THINKING_WITH_PORTALS;
312 }
313 METHOD(Vortex, wr_killmessage, Notification(entity thiswep))
314 {
315     return WEAPON_VORTEX_MURDER;
316 }
317 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
318 {
319     return PHYS_INPUT_BUTTON_ATCK2(actor) && !WEP_CVAR(vortex, secondary);
320 }
321
322 #endif
323 #ifdef CSQC
324
325 METHOD(Vortex, wr_impacteffect, void(entity thiswep, entity actor))
326 {
327     entity this = actor;
328     vector org2 = w_org + w_backoff * 6;
329     pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
330     if(!w_issilent)
331         sound(this, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
332 }
333 METHOD(Vortex, wr_init, void(entity thiswep))
334 {
335     if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
336     {
337         precache_pic("gfx/reticle_nex");
338     }
339 }
340 METHOD(Vortex, wr_zoom, bool(entity thiswep, entity actor))
341 {
342     if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
343     {
344         return true;
345     }
346     else
347     {
348         // no weapon specific image for this weapon
349         return false;
350     }
351 }
352 METHOD(Vortex, wr_zoomdir, bool(entity thiswep))
353 {
354     return button_attack2 && !WEP_CVAR(vortex, secondary);
355 }
356
357 #endif