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