]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vaporizer.qc
f7aceee20f3f531f0519610d3a1de5e511ad2b17
[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 spawnfunc(weapon_vaporizer) { weapon_defaultspawnfunc(WEP_VAPORIZER.m_id); }
61 spawnfunc(weapon_minstanex) { spawnfunc_weapon_vaporizer(this); }
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(Weapon thiswep)
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(thiswep, self, ((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, void(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                 METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
248                 {
249                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
250                         // if the laser uses load, we also consider its ammo for reloading
251                         if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && actor.clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) { // forced reload
252                                 Weapon w = get_weaponinfo(actor.weapon);
253                                 w.wr_reload(w);
254                         } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.clip_load < vaporizer_ammo) { // forced reload
255                                 Weapon w = get_weaponinfo(actor.weapon);
256                                 w.wr_reload(w);
257                         }
258                         if(fire1 && (actor.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(actor))
259                         {
260                                 if(weapon_prepareattack(thiswep, actor, false, WEP_CVAR_PRI(vaporizer, refire)))
261                                 {
262                                         W_Vaporizer_Attack(thiswep);
263                                         weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
264                                 }
265                         }
266                         if(fire2 || (fire1 && !actor.ammo_cells && autocvar_g_rm))
267                         {
268                                 if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
269                                 {
270                                         bool rapid = autocvar_g_rm_laser_rapid;
271                                         if(actor.jump_interval <= time && !actor.held_down)
272                                         {
273                                                 if(rapid)
274                                                         actor.held_down = true;
275                                                 actor.jump_interval = time + autocvar_g_rm_laser_refire;
276                                                 actor.jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
277                                                 damage_goodhits = 0;
278                                                 W_RocketMinsta_Attack2();
279                                         }
280                                         else if(rapid && actor.jump_interval2 <= time && actor.held_down)
281                                         {
282                                                 actor.jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
283                                                 damage_goodhits = 0;
284                                                 W_RocketMinsta_Attack3();
285                                                 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
286                                         }
287                                 }
288                                 else if (actor.jump_interval <= time)
289                                 {
290                                         // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
291                                         actor.jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor();
292
293                                         // decrease ammo for the laser?
294                                         if(WEP_CVAR_SEC(vaporizer, ammo))
295                                                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(vaporizer, ammo));
296
297                                         // ugly instagib hack to reuse the fire mode of the laser
298                                         makevectors(actor.v_angle);
299                                         int oldwep = actor.weapon; // we can't avoid this hack
300                                         actor.weapon = WEP_BLASTER.m_id;
301                                         W_Blaster_Attack(
302                                                 actor,
303                                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
304                                                 WEP_CVAR_SEC(vaporizer, shotangle),
305                                                 WEP_CVAR_SEC(vaporizer, damage),
306                                                 WEP_CVAR_SEC(vaporizer, edgedamage),
307                                                 WEP_CVAR_SEC(vaporizer, radius),
308                                                 WEP_CVAR_SEC(vaporizer, force),
309                                                 WEP_CVAR_SEC(vaporizer, speed),
310                                                 WEP_CVAR_SEC(vaporizer, spread),
311                                                 WEP_CVAR_SEC(vaporizer, delay),
312                                                 WEP_CVAR_SEC(vaporizer, lifetime)
313                                         );
314                                         actor.weapon = oldwep;
315
316                                         // now do normal refire
317                                         weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
318                                 }
319                         }
320                         else
321                                 actor.held_down = false;
322                 }
323                 METHOD(Vaporizer, wr_init, void(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                 }
328                 METHOD(Vaporizer, wr_setup, void(entity thiswep))
329                 {
330                         self.ammo_field = WEP_AMMO(VAPORIZER);
331                         self.vaporizer_lasthit = 0;
332                 }
333                 METHOD(Vaporizer, wr_checkammo1, bool(entity thiswep))
334                 {
335                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
336                         float ammo_amount = self.WEP_AMMO(VAPORIZER) >= vaporizer_ammo;
337                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= vaporizer_ammo;
338                         return ammo_amount;
339                 }
340                 METHOD(Vaporizer, wr_checkammo2, bool(entity thiswep))
341                 {
342                         if(!WEP_CVAR_SEC(vaporizer, ammo))
343                                 return true;
344                         float ammo_amount = self.WEP_AMMO(VAPORIZER) >= WEP_CVAR_SEC(vaporizer, ammo);
345                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
346                         return ammo_amount;
347                 }
348                 METHOD(Vaporizer, wr_config, void(entity thiswep))
349                 {
350                         VAPORIZER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
351                 }
352                 METHOD(Vaporizer, wr_resetplayer, void(entity thiswep))
353                 {
354                         self.vaporizer_lasthit = 0;
355                 }
356                 METHOD(Vaporizer, wr_reload, void(entity thiswep))
357                 {
358                         float vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
359                         float used_ammo;
360                         if(WEP_CVAR_SEC(vaporizer, ammo))
361                                 used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
362                         else
363                                 used_ammo = vaporizer_ammo;
364
365                         W_Reload(self, used_ammo, SND(RELOAD));
366                 }
367                 METHOD(Vaporizer, wr_suicidemessage, int(entity thiswep))
368                 {
369                         return WEAPON_THINKING_WITH_PORTALS;
370                 }
371                 METHOD(Vaporizer, wr_killmessage, int(entity thiswep))
372                 {
373                         return WEAPON_VAPORIZER_MURDER;
374                 }
375
376 #endif
377 #ifdef CSQC
378
379                 METHOD(Vaporizer, wr_impacteffect, void(entity thiswep))
380                 {
381                         vector org2 = w_org + w_backoff * 6;
382                         if(w_deathtype & HITTYPE_SECONDARY)
383                         {
384                                 pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), org2, w_backoff * 1000, 1);
385                                 if(!w_issilent) { sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
386                         }
387                         else
388                         {
389                                 pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
390                                 if(!w_issilent) { sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM); }
391                         }
392                 }
393                 METHOD(Vaporizer, wr_init, void(entity thiswep))
394                 {
395                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
396                         {
397                                 precache_pic("gfx/reticle_nex");
398                         }
399                 }
400                 METHOD(Vaporizer, wr_zoomreticle, bool(entity thiswep))
401                 {
402                         if(button_zoom || zoomscript_caught)
403                         {
404                                 reticle_image = "gfx/reticle_nex";
405                                 return true;
406                         }
407                         else
408                         {
409                                 // no weapon specific image for this weapon
410                                 return false;
411                         }
412                 }
413
414 #endif
415 #endif