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