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