]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vaporizer.qc
2f6d94dd7d18852fb428ef92f84a24f68bd31763
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vaporizer.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Vaporizer, Weapon)
3 /* ammotype  */ ATTRIB(Vaporizer, ammo_field, .int, ammo_cells)
4 /* impulse   */ ATTRIB(Vaporizer, impulse, int, 7)
5 /* flags     */ ATTRIB(Vaporizer, spawnflags, int, WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_FLAG_SUPERWEAPON | WEP_TYPE_HITSCAN);
6 /* rating    */ ATTRIB(Vaporizer, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color     */ ATTRIB(Vaporizer, wpcolor, vector, '0.5 1 1');
8 /* modelname */ ATTRIB(Vaporizer, mdl, string, "minstanex");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(Vaporizer, m_model, Model, MDL_VAPORIZER_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(Vaporizer, w_crosshair, string, "gfx/crosshairminstanex");
13 /* crosshair */ ATTRIB(Vaporizer, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(Vaporizer, model2, string, "weaponminstanex");
15 /* refname   */ ATTRIB(Vaporizer, netname, string, "vaporizer");
16 /* wepname   */ ATTRIB(Vaporizer, message, string, _("Vaporizer"));
17 ENDCLASS(Vaporizer)
18 REGISTER_WEAPON(VAPORIZER, NEW(Vaporizer));
19
20 #define VAPORIZER_SETTINGS(w_cvar,w_prop) VAPORIZER_SETTINGS_LIST(w_cvar, w_prop, VAPORIZER, vaporizer)
21 #define VAPORIZER_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, PRI, ammo) \
23         w_cvar(id, sn, PRI, animtime) \
24         w_cvar(id, sn, PRI, damage) \
25         w_cvar(id, sn, PRI, refire) \
26         w_cvar(id, sn, SEC, ammo) \
27         w_cvar(id, sn, SEC, animtime) \
28         w_cvar(id, sn, SEC, damage) \
29         w_cvar(id, sn, SEC, delay) \
30         w_cvar(id, sn, SEC, edgedamage) \
31         w_cvar(id, sn, SEC, force) \
32         w_cvar(id, sn, SEC, lifetime) \
33         w_cvar(id, sn, SEC, radius) \
34         w_cvar(id, sn, SEC, refire) \
35         w_cvar(id, sn, SEC, shotangle) \
36         w_cvar(id, sn, SEC, speed) \
37         w_cvar(id, sn, SEC, spread) \
38         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
39         w_prop(id, sn, float,  reloading_time, reload_time) \
40         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
41         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
42         w_prop(id, sn, string, weaponreplace, weaponreplace) \
43         w_prop(id, sn, float,  weaponstart, weaponstart) \
44         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
45         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
46
47 #ifdef SVQC
48 VAPORIZER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
49 .float vaporizer_lasthit;
50 .float jump_interval;
51 .float jump_interval2;
52 .bool held_down;
53 .float rm_force;
54 .float rm_damage;
55 .float rm_edmg;
56 #endif
57 #endif
58 #ifdef IMPLEMENTATION
59 #ifdef SVQC
60 void spawnfunc_weapon_vaporizer(void) { weapon_defaultspawnfunc(WEP_VAPORIZER.m_id); }
61 void spawnfunc_weapon_minstanex(void) { spawnfunc_weapon_vaporizer(); }
62
63 void W_RocketMinsta_Explosion(vector loc)
64 {SELFPARAM();
65         if(accuracy_canbegooddamage(self))
66                 accuracy_add(self, WEP_DEVASTATOR.m_id, autocvar_g_rm_damage, 0);
67         entity dmgent = spawn();
68         dmgent.owner = dmgent.realowner = self;
69         setorigin(dmgent, loc);
70         RadiusDamage (dmgent, self, autocvar_g_rm_damage, autocvar_g_rm_edgedamage, autocvar_g_rm_radius, world, world, autocvar_g_rm_force, WEP_DEVASTATOR.m_id | HITTYPE_SPLASH, other);
71         remove(dmgent);
72 }
73
74 void W_Vaporizer_Attack(void)
75 {SELFPARAM();
76         bool flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
77         float vaporizer_damage = ((WEP_CVAR_PRI(vaporizer, damage) > 0) ? WEP_CVAR_PRI(vaporizer, damage) : 10000);
78
79         W_SetupShot(self, true, 0, "", CH_WEAPON_A, vaporizer_damage);
80         // handle sound separately so we can change the volume
81         // added bonus: no longer plays the strength sound (strength gives no bonus to instakill anyway)
82         sound (self, CH_WEAPON_A, SND_MINSTANEXFIRE, VOL_BASE * 0.8, ATTEN_NORM);
83
84         yoda = 0;
85         damage_goodhits = 0;
86         FireRailgunBullet(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, vaporizer_damage, 800, 0, 0, 0, 0, WEP_VAPORIZER.m_id);
87
88         if(yoda && flying)
89                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
90         if(damage_goodhits && self.vaporizer_lasthit)
91         {
92                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
93                 damage_goodhits = 0; // only every second time
94         }
95
96         self.vaporizer_lasthit = damage_goodhits;
97
98         Send_Effect(EFFECT_VORTEX_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
99
100         // teamcolor / hit beam effect
101         vector v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
102         Send_Effect((damage_goodhits ? EFFECT_VAPORIZER_HIT(self.team) : EFFECT_VAPORIZER(self.team)), w_shotorg, v, 1);
103
104         if(autocvar_g_rm)
105         if(!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
106                 W_RocketMinsta_Explosion(trace_endpos);
107
108         W_DecreaseAmmo(((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)));
109 }
110
111 void W_RocketMinsta_Laser_Explode (void)
112 {SELFPARAM();
113         if(other.takedamage == DAMAGE_AIM)
114                 if(IS_PLAYER(other))
115                         if(DIFF_TEAM(self.realowner, other))
116                                 if(other.deadflag == DEAD_NO)
117                                         if(IsFlying(other))
118                                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
119
120         self.event_damage = func_null;
121         self.takedamage = DAMAGE_NO;
122         RadiusDamage (self, self.realowner, self.rm_damage, self.rm_edmg, autocvar_g_rm_laser_radius, world, world, self.rm_force, self.projectiledeathtype, other);
123         remove(self);
124 }
125
126 void W_RocketMinsta_Laser_Touch (void)
127 {SELFPARAM();
128         PROJECTILE_TOUCH;
129         //W_RocketMinsta_Laser_Explode ();
130         RadiusDamage (self, self.realowner, self.rm_damage, self.rm_edmg, autocvar_g_rm_laser_radius, world, world, self.rm_force, self.projectiledeathtype, other);
131         remove(self);
132 }
133
134 void W_RocketMinsta_Attack2(void)
135 {SELFPARAM();
136         makevectors(self.v_angle);
137
138         entity proj;
139         float counter = 0;
140         float total = autocvar_g_rm_laser_count;
141         float spread = autocvar_g_rm_laser_spread;
142         float rndspread = autocvar_g_rm_laser_spread_random;
143
144         float w = self.weapon;
145         self.weapon = WEP_ELECTRO.m_id;
146         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', false, 2, SND(CRYLINK_FIRE), CH_WEAPON_A, autocvar_g_rm_laser_damage);
147         self.weapon = w;
148
149         Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
150
151     while(counter < total)
152         {
153         proj = spawn ();
154         proj.classname = "plasma_prim";
155         proj.owner = proj.realowner = self;
156         proj.bot_dodge = true;
157         proj.bot_dodgerating = autocvar_g_rm_laser_damage;
158         proj.use = W_RocketMinsta_Laser_Explode;
159         proj.think = adaptor_think2use_hittype_splash;
160         proj.nextthink = time + autocvar_g_rm_laser_lifetime;
161         PROJECTILE_MAKETRIGGER(proj);
162         proj.projectiledeathtype = WEP_ELECTRO.m_id;
163         setorigin(proj, w_shotorg);
164
165                 proj.rm_force = autocvar_g_rm_laser_force / total;
166                 proj.rm_damage = autocvar_g_rm_laser_damage / total;
167                 proj.rm_edmg = proj.rm_damage;
168
169         //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
170
171         proj.movetype = MOVETYPE_BOUNCEMISSILE;
172         //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
173                 proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * (spread * (rndspread ? random() : 1))) * cvar("g_rm_laser_speed");
174                 proj.velocity_z = proj.velocity_z + cvar("g_rm_laser_zspread") * (random() - 0.5);
175                 proj.velocity = W_CalculateProjectileVelocity(proj.realowner.velocity, proj.velocity, true);
176         proj.angles = vectoangles(proj.velocity);
177         proj.touch = W_RocketMinsta_Laser_Touch;
178         setsize(proj, '0 0 -3', '0 0 -3');
179         proj.flags = FL_PROJECTILE;
180         proj.missile_flags = MIF_SPLASH;
181
182         CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
183
184         MUTATOR_CALLHOOK(EditProjectile, self, proj);
185         counter++;
186     }
187 }
188
189 void W_RocketMinsta_Attack3 (void)
190 {SELFPARAM();
191         makevectors(self.v_angle);
192
193         entity proj;
194         float counter = 0;
195         float total = 1;
196
197         int w = self.weapon;
198         self.weapon = WEP_ELECTRO.m_id;
199         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', false, 2, SND(ELECTRO_FIRE2), CH_WEAPON_A, autocvar_g_rm_laser_damage);
200         self.weapon = w;
201
202         Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
203
204     while(counter < total)
205         {
206         proj = spawn ();
207         proj.classname = "plasma_prim";
208         proj.owner = proj.realowner = self;
209         proj.bot_dodge = true;
210         proj.bot_dodgerating = autocvar_g_rm_laser_damage;
211         proj.use = W_RocketMinsta_Laser_Explode;
212         proj.think = adaptor_think2use_hittype_splash;
213         proj.nextthink = time + autocvar_g_rm_laser_lifetime;
214         PROJECTILE_MAKETRIGGER(proj);
215         proj.projectiledeathtype = WEP_ELECTRO.m_id;
216         setorigin(proj, w_shotorg);
217
218                 proj.rm_force = autocvar_g_rm_laser_force / total;
219                 proj.rm_damage = autocvar_g_rm_laser_damage / total;
220                 proj.rm_edmg = proj.rm_damage;
221
222         //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
223
224         proj.movetype = MOVETYPE_BOUNCEMISSILE;
225                 proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
226                 proj.velocity = W_CalculateProjectileVelocity(proj.realowner.velocity, proj.velocity, true);
227         proj.angles = vectoangles(proj.velocity);
228         proj.touch = W_RocketMinsta_Laser_Touch;
229         setsize(proj, '0 0 -3', '0 0 -3');
230         proj.flags = FL_PROJECTILE;
231         proj.missile_flags = MIF_SPLASH;
232
233         CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
234
235         MUTATOR_CALLHOOK(EditProjectile, self, proj);
236         counter++;
237     }
238 }
239
240                 METHOD(Vaporizer, wr_aim, bool(entity thiswep))
241                 {
242                         if(self.WEP_AMMO(VAPORIZER) > 0)
243                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, false);
244                         else
245                                 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false); // WEAPONTODO: replace with proper vaporizer cvars
246
247                         return true;
248                 }
249                 METHOD(Vaporizer, wr_think, bool(entity thiswep))
250                 {
251                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
252                         // if the laser uses load, we also consider its ammo for reloading
253                         if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && self.clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) // forced reload
254                                 _WEP_ACTION(self.weapon, WR_RELOAD);
255                         else if(WEP_CVAR(vaporizer, reload_ammo) && self.clip_load < vaporizer_ammo) // forced reload
256                                 _WEP_ACTION(self.weapon, WR_RELOAD);
257                         if(self.BUTTON_ATCK && (self.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(self))
258                         {
259                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(vaporizer, refire)))
260                                 {
261                                         W_Vaporizer_Attack();
262                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
263                                 }
264                         }
265                         if(self.BUTTON_ATCK2 || (self.BUTTON_ATCK && !self.ammo_cells && autocvar_g_rm))
266                         {
267                                 if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
268                                 {
269                                         bool rapid = autocvar_g_rm_laser_rapid;
270                                         if(self.jump_interval <= time && !self.held_down)
271                                         {
272                                                 if(rapid)
273                                                         self.held_down = true;
274                                                 self.jump_interval = time + autocvar_g_rm_laser_refire;
275                                                 self.jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
276                                                 damage_goodhits = 0;
277                                                 W_RocketMinsta_Attack2();
278                                         }
279                                         else if(rapid && self.jump_interval2 <= time && self.held_down)
280                                         {
281                                                 self.jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
282                                                 damage_goodhits = 0;
283                                                 W_RocketMinsta_Attack3();
284                                                 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
285                                         }
286                                 }
287                                 else if (self.jump_interval <= time)
288                                 {
289                                         // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
290                                         self.jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor();
291
292                                         // decrease ammo for the laser?
293                                         if(WEP_CVAR_SEC(vaporizer, ammo))
294                                                 W_DecreaseAmmo(WEP_CVAR_SEC(vaporizer, ammo));
295
296                                         // ugly instagib hack to reuse the fire mode of the laser
297                                         makevectors(self.v_angle);
298                                         int oldwep = self.weapon; // we can't avoid this hack
299                                         self.weapon = WEP_BLASTER.m_id;
300                                         W_Blaster_Attack(
301                                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
302                                                 WEP_CVAR_SEC(vaporizer, shotangle),
303                                                 WEP_CVAR_SEC(vaporizer, damage),
304                                                 WEP_CVAR_SEC(vaporizer, edgedamage),
305                                                 WEP_CVAR_SEC(vaporizer, radius),
306                                                 WEP_CVAR_SEC(vaporizer, force),
307                                                 WEP_CVAR_SEC(vaporizer, speed),
308                                                 WEP_CVAR_SEC(vaporizer, spread),
309                                                 WEP_CVAR_SEC(vaporizer, delay),
310                                                 WEP_CVAR_SEC(vaporizer, lifetime)
311                                         );
312                                         self.weapon = oldwep;
313
314                                         // now do normal refire
315                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
316                                 }
317                         }
318                         else
319                                 self.held_down = false;
320
321                         return true;
322                 }
323                 METHOD(Vaporizer, wr_init, bool(entity thiswep))
324                 {
325                         //W_Blaster(WR_INIT); // Samual: Is this really the proper thing to do? Didn't we already run this previously?
326                         VAPORIZER_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
327                         return true;
328                 }
329                 METHOD(Vaporizer, wr_setup, bool(entity thiswep))
330                 {
331                         self.ammo_field = WEP_AMMO(VAPORIZER);
332                         self.vaporizer_lasthit = 0;
333                         return true;
334                 }
335                 METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep))
336                 {
337                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
338                         float ammo_amount = self.WEP_AMMO(VAPORIZER) >= vaporizer_ammo;
339                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= vaporizer_ammo;
340                         return ammo_amount;
341                 }
342                 METHOD(Vaporizer, wr_checkammo2, bool(entity thiswep))
343                 {
344                         if(!WEP_CVAR_SEC(vaporizer, ammo))
345                                 return true;
346                         float ammo_amount = self.WEP_AMMO(VAPORIZER) >= WEP_CVAR_SEC(vaporizer, ammo);
347                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
348                         return ammo_amount;
349                 }
350                 METHOD(Vaporizer, wr_config, bool(entity thiswep))
351                 {
352                         VAPORIZER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
353                         return true;
354                 }
355                 METHOD(Vaporizer, wr_resetplayer, bool(entity thiswep))
356                 {
357                         self.vaporizer_lasthit = 0;
358                         return true;
359                 }
360                 METHOD(Vaporizer, wr_reload, bool(entity thiswep))
361                 {
362                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
363                         float used_ammo;
364                         if(WEP_CVAR_SEC(vaporizer, ammo))
365                                 used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
366                         else
367                                 used_ammo = vaporizer_ammo;
368
369                         W_Reload(used_ammo, SND(RELOAD));
370                         return true;
371                 }
372                 METHOD(Vaporizer, wr_suicidemessage, bool(entity thiswep))
373                 {
374                         return WEAPON_THINKING_WITH_PORTALS;
375                 }
376                 METHOD(Vaporizer, wr_killmessage, bool(entity thiswep))
377                 {
378                         return WEAPON_VAPORIZER_MURDER;
379                 }
380
381 #endif
382 #ifdef CSQC
383
384                 METHOD(Vaporizer, wr_impacteffect, bool(entity thiswep))
385                 {
386                         vector org2 = w_org + w_backoff * 6;
387                         if(w_deathtype & HITTYPE_SECONDARY)
388                         {
389                                 pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), org2, w_backoff * 1000, 1);
390                                 if(!w_issilent) { sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
391                         }
392                         else
393                         {
394                                 pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
395                                 if(!w_issilent) { sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM); }
396                         }
397                         return true;
398                 }
399                 METHOD(Vaporizer, wr_init, bool(entity thiswep))
400                 {
401                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
402                         {
403                                 precache_pic("gfx/reticle_nex");
404                         }
405                         return true;
406                 }
407                 METHOD(Vaporizer, wr_zoomreticle, bool(entity thiswep))
408                 {
409                         if(button_zoom || zoomscript_caught)
410                         {
411                                 reticle_image = "gfx/reticle_nex";
412                                 return true;
413                         }
414                         else
415                         {
416                                 // no weapon specific image for this weapon
417                                 return false;
418                         }
419                 }
420
421 #endif
422 #endif