]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vaporizer.qc
Nades code: don't use booleans as array indexes for m_projectile, optimize spawn_held...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vaporizer.qc
1 #include "vaporizer.qh"
2
3 #ifdef GAMEQC
4 REGISTER_NET_TEMP(TE_CSQC_VAPORBEAMPARTICLE)
5 #endif
6
7 #if defined(SVQC)
8 void SendCSQCVaporizerBeamParticle(entity player, int hit) {
9         vector v;
10         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
11         WriteHeader(MSG_BROADCAST, TE_CSQC_VAPORBEAMPARTICLE);
12         WriteVector(MSG_BROADCAST, w_shotorg);
13         WriteVector(MSG_BROADCAST, v);
14         WriteByte(MSG_BROADCAST, hit);
15         WriteByte(MSG_BROADCAST, etof(player));
16         WriteByte(MSG_BROADCAST, player.team);
17 }
18 #elif defined(CSQC)
19 bool autocvar_cl_vaporizerbeam_particle = false;
20 float autocvar_cl_vaporizerbeam_lifetime = 0.8;
21 float autocvar_cl_vaporizerbeam_colorboost = 0.7;
22
23 string Draw_VaporizerBeam_trace_callback_tex;
24 float Draw_VaporizerBeam_trace_callback_rnd;
25 vector Draw_VaporizerBeam_trace_callback_rgb;
26 float Draw_VaporizerBeam_trace_callback_a;
27 void Draw_VaporizerBeam_trace_callback(vector start, vector hit, vector end)
28 {
29         float i;
30         vector vorg;
31         vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
32         for(i = 0; i < Draw_VaporizerBeam_trace_callback_a; ++i)
33                 Draw_CylindricLine(hit, start, 8, Draw_VaporizerBeam_trace_callback_tex, 0.25, Draw_VaporizerBeam_trace_callback_rnd, Draw_VaporizerBeam_trace_callback_rgb, min(1, Draw_VaporizerBeam_trace_callback_a - i), DRAWFLAG_NORMAL, vorg);
34         Draw_VaporizerBeam_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
35 }
36
37 .vector vorg1, vorg2;
38 void VaporizerBeam_Draw(entity this)
39 {
40         //draw either the old v2.3 beam or the new beam
41         particles_alphamin = particles_alphamax = particles_fade = 1;
42
43         string tex = "particles/lgbeam";
44         if(this.cnt)
45                 tex = "particles/gauntletbeam";
46         vector rgb;
47         //entity e = CSQCModel_server2csqc(this.sv_entnum - 1);
48         //if (e == NULL)
49         //{
50                 rgb = colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true);
51                 //rgb = '1 1 1';
52         //}
53         //else
54         //      rgb = e.glowmod;
55         rgb *= (1 + autocvar_cl_vaporizerbeam_colorboost);
56
57         float fail = (this.nextthink - time);
58
59         Draw_VaporizerBeam_trace_callback_tex = tex;
60         Draw_VaporizerBeam_trace_callback_rnd = 0;
61         Draw_VaporizerBeam_trace_callback_rgb = rgb;
62         Draw_VaporizerBeam_trace_callback_a = bound(0, fail, 1);
63         WarpZone_TraceBox_ThroughZone(this.vorg1, '0 0 0', '0 0 0', this.vorg2, MOVE_NOTHING, NULL, NULL, Draw_VaporizerBeam_trace_callback);
64         Draw_VaporizerBeam_trace_callback_tex = string_null;
65
66         /*if(!MUTATOR_CALLHOOK(Particles_VaporizerBeam, this.vorg1, this.vorg2))
67         if(autocvar_cl_particles_oldvortexbeam)
68                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), this.vorg1, this.vorg2, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
69         else
70                 WarpZone_TrailParticles_WithMultiplier(NULL, particleeffectnum(EFFECT_VORTEX_BEAM), this.vorg1, this.vorg2, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);*/
71 }
72
73 NET_HANDLE(TE_CSQC_VAPORBEAMPARTICLE, bool isNew)
74 {
75         Net_Accept(vortex_beam);
76         setthink(this, SUB_Remove);
77         this.nextthink = time + bound(0, autocvar_cl_vaporizerbeam_lifetime, 10);
78         this.draw = VaporizerBeam_Draw;
79         if (isNew) IL_PUSH(g_drawables, this);
80         this.drawmask = MASK_NORMAL;
81
82         this.vorg1 = ReadVector();
83         this.vorg2 = ReadVector();
84         this.cnt = ReadByte();
85         int myowner = ReadByte();
86         this.owner = playerslots[myowner - 1];
87         this.sv_entnum = myowner;
88         this.team = ReadByte() - 1;
89
90         //pointparticles(EFFECT_VORTEX_MUZZLEFLASH, this.vorg1, normalize(this.vorg2 - this.vorg1) * 1000, 1);
91
92         if(autocvar_cl_vaporizerbeam_particle)
93         {
94                 WarpZone_TrailParticles(NULL, particleeffectnum(((this.cnt) ? EFFECT_VAPORIZER_HIT(this.team) : EFFECT_VAPORIZER(this.team))), this.vorg1, this.vorg2);
95                 this.draw = func_null;
96                 this.drawmask = MASK_NORMAL;
97                 delete(this);
98         }
99
100         return true;
101 }
102 #endif
103
104 #ifdef SVQC
105
106 void W_RocketMinsta_Explosion(entity actor, .entity weaponentity, vector loc)
107 {
108         if(accuracy_canbegooddamage(actor))
109                 accuracy_add(actor, WEP_DEVASTATOR, autocvar_g_rm_damage, 0);
110         entity dmgent = spawn();
111         dmgent.owner = dmgent.realowner = actor;
112         setorigin(dmgent, loc);
113         RadiusDamage (dmgent, actor, autocvar_g_rm_damage, autocvar_g_rm_edgedamage, autocvar_g_rm_radius, NULL, NULL, autocvar_g_rm_force, WEP_DEVASTATOR.m_id | HITTYPE_SPLASH, weaponentity, NULL);
114         delete(dmgent);
115 }
116
117 void W_Vaporizer_Attack(Weapon thiswep, entity actor, .entity weaponentity)
118 {
119         bool flying = IsFlying(actor); // do this BEFORE to make the trace values from FireRailgunBullet last
120         float vaporizer_damage = ((WEP_CVAR_PRI(vaporizer, damage) > 0) ? WEP_CVAR_PRI(vaporizer, damage) : 10000);
121
122         W_SetupShot(actor, weaponentity, true, 0, SND_Null, CH_WEAPON_A, vaporizer_damage, thiswep.m_id);
123         // handle sound separately so we can change the volume
124         // added bonus: no longer plays the strength sound (strength gives no bonus to instakill anyway)
125         sound (actor, CH_WEAPON_A, SND_MINSTANEXFIRE, VOL_BASE * 0.8, ATTEN_NORM);
126
127         yoda = 0;
128         impressive_hits = 0;
129         FireRailgunBullet(actor, weaponentity, w_shotorg, w_shotorg + w_shotdir * max_shot_distance, vaporizer_damage, true, WEP_CVAR_PRI(vaporizer, force), 0, 0, 0, 0, thiswep.m_id);
130
131         // do this now, as goodhits is disabled below
132         vector v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
133         W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, normalize(v - w_shotorg));
134         SendCSQCVaporizerBeamParticle(actor, impressive_hits);
135
136         if(yoda && flying)
137                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
138         if(impressive_hits && actor.vaporizer_lasthit)
139         {
140                 Send_Notification(NOTIF_ONE, actor, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
141                 impressive_hits = 0; // only every second time
142         }
143
144         actor.vaporizer_lasthit = impressive_hits;
145
146         if(autocvar_g_rm)
147         if(!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
148                 W_RocketMinsta_Explosion(actor, weaponentity, trace_endpos);
149
150         W_DecreaseAmmo(thiswep, actor, ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)), weaponentity);
151 }
152
153 void W_RocketMinsta_Laser_Damage(entity this, entity directhitentity)
154 {
155         int laser_count = max(1, this.rm_laser_count);
156         float laser_force = autocvar_g_rm_laser_force / laser_count;
157         float laser_damage = autocvar_g_rm_laser_damage / laser_count;
158         RadiusDamage(this, this.realowner, laser_damage, laser_damage, autocvar_g_rm_laser_radius, NULL, NULL, laser_force, this.projectiledeathtype, this.weaponentity_fld, directhitentity);
159 }
160
161 void W_RocketMinsta_Laser_Explode(entity this, entity directhitentity)
162 {
163         if(directhitentity.takedamage == DAMAGE_AIM)
164                 if(IS_PLAYER(directhitentity))
165                         if(DIFF_TEAM(this.realowner, directhitentity))
166                                 if(!IS_DEAD(directhitentity))
167                                         if(IsFlying(directhitentity))
168                                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
169
170         this.event_damage = func_null;
171         this.takedamage = DAMAGE_NO;
172         W_RocketMinsta_Laser_Damage(this, directhitentity);
173         delete(this);
174 }
175
176 void W_RocketMinsta_Laser_Explode_use(entity this, entity actor, entity trigger)
177 {
178         W_RocketMinsta_Laser_Explode(this, trigger); // we probably don't want trigger used here, but this matches closest to old behaviour
179 }
180
181 void W_RocketMinsta_Laser_Touch(entity this, entity toucher)
182 {
183         PROJECTILE_TOUCH(this, toucher);
184         //W_RocketMinsta_Laser_Explode ();
185         W_RocketMinsta_Laser_Damage(this, toucher);
186         delete(this);
187 }
188
189 // mode 0 fires many projectiles
190 // mode 1 fires 1 projectile
191 void W_RocketMinsta_Attack(entity actor, .entity weaponentity, int mode)
192 {
193         makevectors(actor.v_angle);
194
195         entity proj;
196         int laser_count = max(1, autocvar_g_rm_laser_count);
197         int total = (mode == 0) ? laser_count : 1;
198         Sound snd = (mode == 0) ? SND_CRYLINK_FIRE : SND_ELECTRO_FIRE2;
199         W_SetupShot_ProjectileSize(actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, snd, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
200
201         // uses electro effects
202         W_MuzzleFlash(WEP_ELECTRO, actor, weaponentity, w_shotorg, w_shotdir);
203
204         for (int counter = 0; counter < total; ++counter)
205         {
206                 proj = new(plasma_prim);
207                 proj.owner = proj.realowner = actor;
208                 proj.bot_dodge = true;
209                 proj.bot_dodgerating = autocvar_g_rm_laser_damage;
210                 proj.use = W_RocketMinsta_Laser_Explode_use;
211                 setthink(proj, adaptor_think2use_hittype_splash);
212                 proj.nextthink = time + autocvar_g_rm_laser_lifetime;
213                 PROJECTILE_MAKETRIGGER(proj);
214                 proj.projectiledeathtype = WEP_ELECTRO.m_id;
215                 proj.weaponentity_fld = weaponentity;
216                 setorigin(proj, w_shotorg);
217
218                 proj.rm_laser_count = total;
219
220                 //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
221
222                 set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
223                 if (mode == 0)
224                 {
225                         float spread = autocvar_g_rm_laser_spread * (autocvar_g_rm_laser_spread_random ? random() : 1);
226                         //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
227                         proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * spread) * cvar("g_rm_laser_speed");
228                         proj.velocity.z += cvar("g_rm_laser_zspread") * (random() - 0.5);
229                 }
230                 else
231                         proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
232                 proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
233                 proj.angles = vectoangles(proj.velocity);
234                 settouch(proj, W_RocketMinsta_Laser_Touch);
235                 setsize(proj, '0 0 -3', '0 0 -3');
236                 proj.flags = FL_PROJECTILE;
237                 IL_PUSH(g_projectiles, proj);
238                 IL_PUSH(g_bot_dodge, proj);
239                 proj.missile_flags = MIF_SPLASH;
240
241                 CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
242
243                 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
244         }
245 }
246
247 METHOD(Vaporizer, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
248 {
249     if((actor.items & IT_UNLIMITED_AMMO) || GetResource(actor, thiswep.ammo_type) > 0)
250         PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 1, false, true);
251     else
252         PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false, true); // WEAPONTODO: replace with proper vaporizer cvars
253 }
254 METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
255 {
256     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
257     // if the laser uses load, we also consider its ammo for reloading
258     if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && actor.(weaponentity).clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) { // forced reload
259         thiswep.wr_reload(thiswep, actor, weaponentity);
260         actor.(weaponentity).hagar_load = false; // rocket minsta exclusive var
261         return;
262     } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
263         thiswep.wr_reload(thiswep, actor, weaponentity);
264         actor.(weaponentity).hagar_load = false; // rocket minsta exclusive var
265         return;
266     }
267     if((fire & 1) && (GetResource(actor, RES_CELLS) || !autocvar_g_rm) && !weaponLocked(actor))
268     {
269         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire)))
270         {
271             W_Vaporizer_Attack(thiswep, actor, weaponentity);
272             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
273         }
274     }
275     if((fire & 2) || ((fire & 1) && !GetResource(actor, RES_CELLS) && autocvar_g_rm))
276     {
277         if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
278         {
279             bool rapid = autocvar_g_rm_laser_rapid;
280             //hagar_load was previously named held_down
281             if(actor.(weaponentity).jump_interval <= time && !actor.(weaponentity).hagar_load)
282             {
283                 if(rapid)
284                     actor.(weaponentity).hagar_load = true;
285                 actor.(weaponentity).jump_interval = time + autocvar_g_rm_laser_refire;
286                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
287                 impressive_hits = 0;
288                 W_RocketMinsta_Attack(actor, weaponentity, 0);
289             }
290             else if(rapid && actor.(weaponentity).jump_interval2 <= time && actor.(weaponentity).hagar_load)
291             {
292                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
293                 impressive_hits = 0;
294                 W_RocketMinsta_Attack(actor, weaponentity, 1);
295                 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
296             }
297         }
298         else if (actor.(weaponentity).jump_interval <= time)
299         {
300             // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
301             actor.(weaponentity).jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor(actor);
302
303             // decrease ammo for the laser?
304             if(WEP_CVAR_SEC(vaporizer, ammo))
305                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(vaporizer, ammo), weaponentity);
306
307             makevectors(actor.v_angle);
308             W_Blaster_Attack(actor, weaponentity, WEP_BLASTER.m_id | HITTYPE_SECONDARY);
309
310             // now do normal refire
311             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
312         }
313     }
314     else
315         actor.(weaponentity).hagar_load = false;
316 }
317 METHOD(Vaporizer, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
318 {
319     actor.vaporizer_lasthit = 0;
320 }
321 METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
322 {
323     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
324     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= vaporizer_ammo;
325     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= vaporizer_ammo;
326     return ammo_amount;
327 }
328 METHOD(Vaporizer, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
329 {
330     if(!WEP_CVAR_SEC(vaporizer, ammo))
331         return true;
332     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(vaporizer, ammo);
333     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
334     return ammo_amount;
335 }
336 METHOD(Vaporizer, wr_resetplayer, void(entity thiswep, entity actor))
337 {
338     actor.vaporizer_lasthit = 0;
339 }
340 METHOD(Vaporizer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
341 {
342     float vaporizer_ammo = ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
343     float used_ammo;
344     if(WEP_CVAR_SEC(vaporizer, ammo))
345         used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
346     else
347         used_ammo = vaporizer_ammo;
348
349     W_Reload(actor, weaponentity, used_ammo, SND_RELOAD);
350 }
351 METHOD(Vaporizer, wr_suicidemessage, Notification(entity thiswep))
352 {
353     return WEAPON_THINKING_WITH_PORTALS;
354 }
355 METHOD(Vaporizer, wr_killmessage, Notification(entity thiswep))
356 {
357     return WEAPON_VAPORIZER_MURDER;
358 }
359
360 #endif
361 #ifdef CSQC
362
363 METHOD(Vaporizer, wr_impacteffect, void(entity thiswep, entity actor))
364 {
365     vector org2 = w_org + w_backoff * 2;
366     if(w_deathtype & HITTYPE_SECONDARY)
367     {
368         pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
369         if(!w_issilent) { sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
370     }
371     else
372     {
373         pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
374         if(!w_issilent) { sound(actor, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM); }
375     }
376 }
377 METHOD(Vaporizer, wr_init, void(entity thiswep))
378 {
379     if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
380     {
381         precache_pic("gfx/reticle_nex");
382     }
383 }
384 METHOD(Vaporizer, wr_zoom, bool(entity thiswep, entity actor))
385 {
386     if(button_zoom || zoomscript_caught)
387     {
388         return true;
389     }
390     else
391     {
392         // no weapon specific image for this weapon
393         return false;
394     }
395 }
396
397 #endif