1 #ifndef MUTATOR_NADES_H
2 #define MUTATOR_NADES_H
9 .float nade_special_time;
10 .float bonus_nade_score;
12 .string pokenade_type;
13 .entity nade_damage_target;
14 .float cvar_cl_nade_type;
15 .string cvar_cl_pokenade_type;
17 .float stat_healing_orb;
18 .float stat_healing_orb_alpha;
19 .float nade_show_particles;
21 // Remove nades that are being thrown
22 void(entity player) nades_Clear;
24 // Give a bonus grenade to a player
25 void(entity player, float score) nades_GiveBonus;
26 // Remove all bonus nades from a player
27 void(entity player) nades_RemoveBonus;
32 #include "../../../common/nades/all.qh"
33 #include "../../../common/gamemodes/all.qh"
34 #include "../../../common/monsters/spawn.qh"
35 #include "../../../common/monsters/sv_monsters.qh"
36 #include "../../g_subs.qh"
38 REGISTER_MUTATOR(nades, cvar("g_nades"))
42 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
43 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
44 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
45 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
46 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
47 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
53 .float nade_time_primed;
55 .entity nade_spawnloc;
57 void nade_timer_think()
59 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
60 self.nextthink = time;
61 if(!self.owner || wasfreed(self.owner))
65 void nade_burn_spawn(entity _nade)
67 CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[true], true);
70 void nade_spawn(entity _nade)
72 entity timer = spawn();
73 setmodel(timer, MDL_NADE_TIMER);
74 setattachment(timer, _nade, "");
75 timer.classname = "nade_timer";
76 timer.colormap = _nade.colormap;
77 timer.glowmod = _nade.glowmod;
78 timer.think = nade_timer_think;
79 timer.nextthink = time;
80 timer.wait = _nade.wait;
84 _nade.effects |= EF_LOWPRECISION;
86 CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[false], true);
89 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
98 RandomSelection_Init();
99 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
100 if(e.takedamage == DAMAGE_AIM)
101 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
102 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
106 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
107 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
108 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
109 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
112 e.fireball_impactvec = p;
113 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
116 if(RandomSelection_chosen_ent)
118 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
119 d = damage + (edgedamage - damage) * (d / dist);
120 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
121 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
122 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
127 void napalm_ball_think()
129 if(round_handler_IsActive())
130 if(!round_handler_IsRoundStarted())
136 if(time > self.pushltime)
142 vector midpoint = ((self.absmin + self.absmax) * 0.5);
143 if(pointcontents(midpoint) == CONTENT_WATER)
145 self.velocity = self.velocity * 0.5;
147 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
148 { self.velocity_z = 200; }
151 self.angles = vectoangles(self.velocity);
153 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
154 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
156 self.nextthink = time + 0.1;
160 void nade_napalm_ball()
165 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
168 proj.owner = self.owner;
169 proj.realowner = self.realowner;
170 proj.team = self.owner.team;
171 proj.classname = "grenade";
172 proj.bot_dodge = true;
173 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
174 proj.movetype = MOVETYPE_BOUNCE;
175 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
176 PROJECTILE_MAKETRIGGER(proj);
177 setmodel(proj, MDL_Null);
178 proj.scale = 1;//0.5;
179 setsize(proj, '-4 -4 -4', '4 4 4');
180 setorigin(proj, self.origin);
181 proj.think = napalm_ball_think;
182 proj.nextthink = time;
183 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
184 proj.effects = EF_LOWPRECISION | EF_FLAME;
186 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
187 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
188 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
189 proj.velocity = kick;
191 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
193 proj.angles = vectoangles(proj.velocity);
194 proj.flags = FL_PROJECTILE;
195 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
197 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
201 void napalm_fountain_think()
204 if(round_handler_IsActive())
205 if(!round_handler_IsRoundStarted())
211 if(time >= self.ltime)
217 vector midpoint = ((self.absmin + self.absmax) * 0.5);
218 if(pointcontents(midpoint) == CONTENT_WATER)
220 self.velocity = self.velocity * 0.5;
222 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
223 { self.velocity_z = 200; }
225 UpdateCSQCProjectile(self);
228 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
229 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
231 self.nextthink = time + 0.1;
232 if(time >= self.nade_special_time)
234 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
239 void nade_napalm_boom()
243 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
248 fountain.owner = self.owner;
249 fountain.realowner = self.realowner;
250 fountain.origin = self.origin;
251 setorigin(fountain, fountain.origin);
252 fountain.think = napalm_fountain_think;
253 fountain.nextthink = time;
254 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
255 fountain.pushltime = fountain.ltime;
256 fountain.team = self.team;
257 fountain.movetype = MOVETYPE_TOSS;
258 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
259 fountain.bot_dodge = true;
260 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
261 fountain.nade_special_time = time;
262 setsize(fountain, '-16 -16 -16', '16 16 16');
263 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
266 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
268 frost_target.frozen_by = freezefield.realowner;
269 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
270 Freeze(frost_target, 1/freeze_time, 3, false);
272 Drop_Special_Items(frost_target);
275 void nade_ice_think()
278 if(round_handler_IsActive())
279 if(!round_handler_IsRoundStarted())
285 if(time >= self.ltime)
287 if ( autocvar_g_nades_ice_explode )
289 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
290 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
291 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
293 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
294 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
295 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
296 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
303 self.nextthink = time+0.1;
308 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
310 randomw = random()*M_PI*2;
312 randomp.x = randomr*cos(randomw);
313 randomp.y = randomr*sin(randomw);
315 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
317 if(time >= self.nade_special_time)
319 self.nade_special_time = time+0.7;
321 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
322 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
326 float current_freeze_time = self.ltime - time - 0.1;
329 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
331 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
332 if(e.takedamage && e.deadflag == DEAD_NO)
334 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
336 if(current_freeze_time > 0)
337 nade_ice_freeze(self, e, current_freeze_time);
344 fountain.owner = self.owner;
345 fountain.realowner = self.realowner;
346 fountain.origin = self.origin;
347 setorigin(fountain, fountain.origin);
348 fountain.think = nade_ice_think;
349 fountain.nextthink = time;
350 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
351 fountain.pushltime = fountain.wait = fountain.ltime;
352 fountain.team = self.team;
353 fountain.movetype = MOVETYPE_TOSS;
354 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
355 fountain.bot_dodge = false;
356 setsize(fountain, '-16 -16 -16', '16 16 16');
357 fountain.nade_special_time = time+0.3;
358 fountain.angles = self.angles;
360 if ( autocvar_g_nades_ice_explode )
362 setmodel(fountain, MDL_PROJECTILE_GRENADE);
363 entity timer = spawn();
364 setmodel(timer, MDL_NADE_TIMER);
365 setattachment(timer, fountain, "");
366 timer.classname = "nade_timer";
367 timer.colormap = self.colormap;
368 timer.glowmod = self.glowmod;
369 timer.think = nade_timer_think;
370 timer.nextthink = time;
371 timer.wait = fountain.ltime;
372 timer.owner = fountain;
376 setmodel(fountain, MDL_Null);
379 void nade_translocate_boom()
381 if(self.realowner.vehicle)
384 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
385 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
386 locout = trace_endpos;
388 makevectors(self.realowner.angles);
390 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
392 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
395 void nade_spawn_boom()
397 entity spawnloc = spawn();
398 setorigin(spawnloc, self.origin);
399 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
400 spawnloc.movetype = MOVETYPE_NONE;
401 spawnloc.solid = SOLID_NOT;
402 spawnloc.drawonlytoclient = self.realowner;
403 spawnloc.effects = EF_STARDUST;
404 spawnloc.cnt = autocvar_g_nades_spawn_count;
406 if(self.realowner.nade_spawnloc)
408 remove(self.realowner.nade_spawnloc);
409 self.realowner.nade_spawnloc = world;
412 self.realowner.nade_spawnloc = spawnloc;
415 void nade_heal_think()
417 if(time >= self.ltime)
423 self.nextthink = time;
425 if(time >= self.nade_special_time)
427 self.nade_special_time = time+0.25;
428 self.nade_show_particles = 1;
431 self.nade_show_particles = 0;
434 void nade_heal_touch()
438 if(IS_PLAYER(other) || IS_MONSTER(other))
439 if(other.deadflag == DEAD_NO)
442 health_factor = autocvar_g_nades_heal_rate*frametime/2;
443 if ( other != self.realowner )
445 if ( SAME_TEAM(other,self) )
446 health_factor *= autocvar_g_nades_heal_friend;
448 health_factor *= autocvar_g_nades_heal_foe;
450 if ( health_factor > 0 )
452 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
453 if ( other.health < maxhealth )
455 if ( self.nade_show_particles )
456 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
457 other.health = min(other.health+health_factor, maxhealth);
459 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
461 else if ( health_factor < 0 )
463 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
468 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
470 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
471 show_red.stat_healing_orb = time+0.1;
472 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
476 void nade_heal_boom()
480 healer.owner = self.owner;
481 healer.realowner = self.realowner;
482 setorigin(healer, self.origin);
483 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
484 healer.ltime = time + healer.healer_lifetime;
485 healer.team = self.realowner.team;
486 healer.bot_dodge = false;
487 healer.solid = SOLID_TRIGGER;
488 healer.touch = nade_heal_touch;
490 setmodel(healer, MDL_NADE_HEAL);
491 healer.healer_radius = autocvar_g_nades_nade_radius;
492 vector size = '1 1 1' * healer.healer_radius / 2;
493 setsize(healer,-size,size);
495 Net_LinkEntity(healer, true, 0, healer_send);
497 healer.think = nade_heal_think;
498 healer.nextthink = time;
499 healer.SendFlags |= 1;
502 void nade_monster_boom()
504 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
506 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
507 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
508 e.monster_skill = MONSTER_SKILL_INSANE;
514 bool nade_blast = true;
516 switch ( Nades[self.nade_type] )
518 case NADE_TYPE_NAPALM:
519 nade_blast = autocvar_g_nades_napalm_blast;
520 expef = EFFECT_EXPLOSION_MEDIUM;
524 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
526 case NADE_TYPE_TRANSLOCATE:
529 case NADE_TYPE_MONSTER:
530 case NADE_TYPE_SPAWN:
532 switch(self.realowner.team)
534 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
535 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
536 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
537 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
538 default: expef = EFFECT_SPAWN_NEUTRAL; break;
543 expef = EFFECT_SPAWN_RED;
547 case NADE_TYPE_NORMAL:
548 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
553 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
555 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
556 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
558 self.event_damage = func_null; // prevent somehow calling damage in the next call
562 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
563 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
564 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
568 switch ( Nades[self.nade_type] )
570 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
571 case NADE_TYPE_ICE: nade_ice_boom(); break;
572 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
573 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
574 case NADE_TYPE_HEAL: nade_heal_boom(); break;
575 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
579 for(head = world; (head = find(head, classname, "grapplinghook")); )
580 if(head.aiment == self)
581 RemoveGrapplingHook(head.realowner);
588 /*float is_weapclip = 0;
589 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
590 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
591 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
593 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
596 for(head = world; (head = find(head, classname, "grapplinghook")); )
597 if(head.aiment == self)
598 RemoveGrapplingHook(head.realowner);
605 //setsize(self, '-2 -2 -2', '2 2 2');
606 //UpdateCSQCProjectile(self);
607 if(self.health == self.max_health)
609 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
619 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
620 self.think = nade_boom;
621 self.nextthink = max(self.wait, time);
624 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
626 if(ITEM_DAMAGE_NEEDKILL(deathtype))
628 self.takedamage = DAMAGE_NO;
633 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
636 if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
642 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
644 force *= 0.5; // too much
648 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
651 damage = self.max_health * 0.55;
654 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_HMG))
655 damage = self.max_health * 0.1;
657 if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
658 if(deathtype & HITTYPE_SECONDARY)
660 damage = self.max_health * 0.1;
664 damage = self.max_health * 1.15;
666 self.velocity += force;
667 UpdateCSQCProjectile(self);
669 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
672 if(self.health == self.max_health)
674 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
675 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
676 self.think = nade_beep;
679 self.health -= damage;
681 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
682 self.realowner = attacker;
685 W_PrepareExplosionByDamage(attacker, nade_boom);
687 nade_burn_spawn(self);
690 void toss_nade(entity e, vector _velocity, float _time)
695 entity _nade = e.nade;
701 makevectors(e.v_angle);
703 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
705 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
707 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
708 + (v_right * autocvar_g_nades_throw_offset.y)
709 + (v_up * autocvar_g_nades_throw_offset.z);
710 if(autocvar_g_nades_throw_offset == '0 0 0')
713 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
714 //setmodel(_nade, MDL_PROJECTILE_NADE);
715 //setattachment(_nade, world, "");
716 PROJECTILE_MAKETRIGGER(_nade);
717 setsize(_nade, '-16 -16 -16', '16 16 16');
718 _nade.movetype = MOVETYPE_BOUNCE;
720 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
721 if (trace_startsolid)
722 setorigin(_nade, e.origin);
724 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
725 _nade.velocity = '0 0 100';
726 else if(autocvar_g_nades_nade_newton_style == 1)
727 _nade.velocity = e.velocity + _velocity;
728 else if(autocvar_g_nades_nade_newton_style == 2)
729 _nade.velocity = _velocity;
731 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
733 _nade.touch = nade_touch;
734 _nade.health = autocvar_g_nades_nade_health;
735 _nade.max_health = _nade.health;
736 _nade.takedamage = DAMAGE_AIM;
737 _nade.event_damage = nade_damage;
738 _nade.customizeentityforclient = func_null;
739 _nade.exteriormodeltoclient = world;
740 _nade.traileffectnum = 0;
741 _nade.teleportable = true;
742 _nade.pushable = true;
744 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
745 _nade.damagedbycontents = true;
746 _nade.angles = vectoangles(_nade.velocity);
747 _nade.flags = FL_PROJECTILE;
748 _nade.projectiledeathtype = DEATH_NADE.m_id;
749 _nade.toss_time = time;
750 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
752 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
753 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
755 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
761 _nade.think = nade_boom;
762 _nade.nextthink = _time;
765 e.nade_refire = time + autocvar_g_nades_nade_refire;
769 void nades_GiveBonus(entity player, float score)
771 if (autocvar_g_nades)
772 if (autocvar_g_nades_bonus)
773 if (IS_REAL_CLIENT(player))
774 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
775 if (player.frozen == 0)
776 if (player.deadflag == DEAD_NO)
778 if ( player.bonus_nade_score < 1 )
779 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
781 if ( player.bonus_nade_score >= 1 )
783 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
784 play2(player, SND(KH_ALARM));
785 player.bonus_nades++;
786 player.bonus_nade_score -= 1;
791 void nades_RemoveBonus(entity player)
793 player.bonus_nades = player.bonus_nade_score = 0;
796 float nade_customize()
798 //if(IS_SPEC(other)) { return false; }
799 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
801 // somewhat hide the model, but keep the glow
803 if(self.traileffectnum)
804 self.traileffectnum = 0;
809 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
810 if(!self.traileffectnum)
811 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[self.nade_type].m_projectile[false], self.team).eent_eff_name);
820 if(autocvar_g_nades_bonus_only)
821 if(!self.bonus_nades)
822 return; // only allow bonus nades
828 remove(self.fake_nade);
830 entity n = spawn(), fn = spawn();
832 n.classname = "nade";
833 fn.classname = "fake_nade";
835 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
836 n.nade_type = self.nade_type;
837 else if (self.bonus_nades >= 1)
839 n.nade_type = self.nade_type;
840 n.pokenade_type = self.pokenade_type;
841 self.bonus_nades -= 1;
845 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
846 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
849 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
851 setmodel(n, MDL_PROJECTILE_NADE);
852 //setattachment(n, self, "bip01 l hand");
853 n.exteriormodeltoclient = self;
854 n.customizeentityforclient = nade_customize;
855 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[n.nade_type].m_projectile[false], self.team).eent_eff_name);
856 n.colormod = Nades[n.nade_type].m_color;
858 n.colormap = self.colormap;
859 n.glowmod = self.glowmod;
860 n.wait = time + autocvar_g_nades_nade_lifetime;
861 n.nade_time_primed = time;
863 n.nextthink = max(n.wait - 3, time);
864 n.projectiledeathtype = DEATH_NADE.m_id;
866 setmodel(fn, MDL_NADE_VIEW);
867 int slot = 0; // TODO: unhardcode
868 setattachment(fn, self.weaponentity[slot], "");
869 fn.realowner = fn.owner = self;
870 fn.colormod = Nades[n.nade_type].m_color;
871 fn.colormap = self.colormap;
872 fn.glowmod = self.glowmod;
873 fn.think = SUB_Remove;
874 fn.nextthink = n.wait;
888 if(self.deadflag != DEAD_NO)
891 if (!autocvar_g_nades)
892 return false; // allow turning them off mid match
894 if(forbidWeaponUse(self))
897 if (!IS_PLAYER(self))
903 .bool nade_altbutton;
905 void nades_CheckThrow()
910 entity held_nade = self.nade;
913 self.nade_altbutton = true;
914 if(time > self.nade_refire)
916 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
918 self.nade_refire = time + autocvar_g_nades_nade_refire;
923 self.nade_altbutton = false;
924 if (time >= held_nade.nade_time_primed + 1) {
925 makevectors(self.v_angle);
926 float _force = time - held_nade.nade_time_primed;
927 _force /= autocvar_g_nades_nade_lifetime;
928 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
929 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
934 void nades_Clear(entity player)
939 remove(player.fake_nade);
941 player.nade = player.fake_nade = world;
942 player.nade_timer = 0;
945 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
948 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
953 CLASS(NadeOffhand, OffhandWeapon)
954 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
956 entity held_nade = player.nade;
959 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
960 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
961 makevectors(player.angles);
962 held_nade.velocity = player.velocity;
963 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
964 held_nade.angles_y = player.angles.y;
966 if (time + 0.1 >= held_nade.wait)
967 toss_nade(player, '0 0 0', time + 0.05);
970 if (!CanThrowNade()) return;
971 if (!(time > player.nade_refire)) return;
975 held_nade = player.nade;
977 } else if (time >= held_nade.nade_time_primed + 1) {
979 makevectors(player.v_angle);
980 float _force = time - held_nade.nade_time_primed;
981 _force /= autocvar_g_nades_nade_lifetime;
982 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
983 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
987 ENDCLASS(NadeOffhand)
988 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
990 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
992 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
999 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1001 if (!IS_PLAYER(self)) { return false; }
1003 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1007 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1010 float key_count = 0;
1011 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1014 if(self.flagcarried || self.ballcarried) // this player is important
1015 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1017 time_score = autocvar_g_nades_bonus_score_time;
1020 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1022 if(autocvar_g_nades_bonus_client_select)
1024 self.nade_type = self.cvar_cl_nade_type;
1025 self.pokenade_type = self.cvar_cl_pokenade_type;
1029 self.nade_type = autocvar_g_nades_bonus_type;
1030 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1033 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1035 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1036 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1040 self.bonus_nades = self.bonus_nade_score = 0;
1046 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1050 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1052 FOR_EACH_PLAYER(other) if(self != other)
1054 if(other.deadflag == DEAD_NO)
1055 if(other.frozen == 0)
1056 if(SAME_TEAM(other, self))
1057 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1061 if(self.frozen == 1)
1062 other.reviving = true;
1068 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1070 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1071 self.health = max(1, self.revive_progress * start_health);
1073 if(self.revive_progress >= 1)
1077 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1078 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1081 FOR_EACH_PLAYER(other) if(other.reviving)
1083 other.revive_progress = self.revive_progress;
1084 other.reviving = false;
1091 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1093 if(autocvar_g_nades_spawn)
1094 self.nade_refire = time + autocvar_g_spawnshieldtime;
1096 self.nade_refire = time + autocvar_g_nades_nade_refire;
1098 if(autocvar_g_nades_bonus_client_select)
1099 self.nade_type = self.cvar_cl_nade_type;
1101 self.nade_timer = 0;
1103 if (!self.offhand) self.offhand = OFFHAND_NADE;
1105 if(self.nade_spawnloc)
1107 setorigin(self, self.nade_spawnloc.origin);
1108 self.nade_spawnloc.cnt -= 1;
1110 if(self.nade_spawnloc.cnt <= 0)
1112 remove(self.nade_spawnloc);
1113 self.nade_spawnloc = world;
1120 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1122 if(frag_target.nade)
1123 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1124 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1126 float killcount_bonus = ((frag_attacker.killcount >= 1) ? bound(0, autocvar_g_nades_bonus_score_minor * frag_attacker.killcount, autocvar_g_nades_bonus_score_medium) : autocvar_g_nades_bonus_score_minor);
1128 if(IS_PLAYER(frag_attacker))
1130 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1131 nades_RemoveBonus(frag_attacker);
1132 else if(frag_target.flagcarried)
1133 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1134 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1136 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1137 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1138 switch(frag_attacker.killcount)
1141 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1146 nades_GiveBonus(frag_attacker, killcount_bonus);
1149 nades_RemoveBonus(frag_target);
1154 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1156 if(frag_target.frozen)
1157 if(autocvar_g_freezetag_revive_nade)
1158 if(frag_attacker == frag_target)
1159 if(frag_deathtype == DEATH_NADE.m_id)
1160 if(time - frag_inflictor.toss_time <= 0.1)
1162 Unfreeze(frag_target);
1163 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1164 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1166 frag_force = '0 0 0';
1167 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1168 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1174 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1176 if(IS_PLAYER(frag_attacker))
1177 if(DIFF_TEAM(frag_attacker, self))
1178 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1179 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1184 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1186 if(frag_target.nade)
1187 toss_nade(frag_target, '0 0 0', time + 0.05);
1192 bool nades_RemovePlayer()
1195 nades_RemoveBonus(self);
1199 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1200 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1201 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1203 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1205 self.nade_timer = other.nade_timer;
1206 self.nade_type = other.nade_type;
1207 self.pokenade_type = other.pokenade_type;
1208 self.bonus_nades = other.bonus_nades;
1209 self.bonus_nade_score = other.bonus_nade_score;
1210 self.stat_healing_orb = other.stat_healing_orb;
1211 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1215 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1217 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1218 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1223 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1225 ret_string = strcat(ret_string, ":Nades");
1229 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1231 ret_string = strcat(ret_string, ", Nades");