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_from(_nade.nade_type).m_projectile[true], true);
70 void nade_spawn(entity _nade)
72 entity timer = new(nade_timer);
73 setmodel(timer, MDL_NADE_TIMER);
74 setattachment(timer, _nade, "");
75 timer.colormap = _nade.colormap;
76 timer.glowmod = _nade.glowmod;
77 timer.think = nade_timer_think;
78 timer.nextthink = time;
79 timer.wait = _nade.wait;
83 _nade.effects |= EF_LOWPRECISION;
85 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
88 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
97 RandomSelection_Init();
98 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
99 if(e.takedamage == DAMAGE_AIM)
100 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
101 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
105 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
106 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
107 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
108 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
111 e.fireball_impactvec = p;
112 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
115 if(RandomSelection_chosen_ent)
117 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
118 d = damage + (edgedamage - damage) * (d / dist);
119 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
120 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
121 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
126 void napalm_ball_think()
128 if(round_handler_IsActive())
129 if(!round_handler_IsRoundStarted())
135 if(time > self.pushltime)
141 vector midpoint = ((self.absmin + self.absmax) * 0.5);
142 if(pointcontents(midpoint) == CONTENT_WATER)
144 self.velocity = self.velocity * 0.5;
146 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
147 { self.velocity_z = 200; }
150 self.angles = vectoangles(self.velocity);
152 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
153 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
155 self.nextthink = time + 0.1;
159 void nade_napalm_ball()
164 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
167 proj.owner = self.owner;
168 proj.realowner = self.realowner;
169 proj.team = self.owner.team;
170 proj.bot_dodge = true;
171 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
172 proj.movetype = MOVETYPE_BOUNCE;
173 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
174 PROJECTILE_MAKETRIGGER(proj);
175 setmodel(proj, MDL_Null);
176 proj.scale = 1;//0.5;
177 setsize(proj, '-4 -4 -4', '4 4 4');
178 setorigin(proj, self.origin);
179 proj.think = napalm_ball_think;
180 proj.nextthink = time;
181 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
182 proj.effects = EF_LOWPRECISION | EF_FLAME;
184 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
185 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
186 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
187 proj.velocity = kick;
189 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
191 proj.angles = vectoangles(proj.velocity);
192 proj.flags = FL_PROJECTILE;
193 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
195 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
199 void napalm_fountain_think()
202 if(round_handler_IsActive())
203 if(!round_handler_IsRoundStarted())
209 if(time >= self.ltime)
215 vector midpoint = ((self.absmin + self.absmax) * 0.5);
216 if(pointcontents(midpoint) == CONTENT_WATER)
218 self.velocity = self.velocity * 0.5;
220 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
221 { self.velocity_z = 200; }
223 UpdateCSQCProjectile(self);
226 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
227 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
229 self.nextthink = time + 0.1;
230 if(time >= self.nade_special_time)
232 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
237 void nade_napalm_boom()
241 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
246 fountain.owner = self.owner;
247 fountain.realowner = self.realowner;
248 fountain.origin = self.origin;
249 setorigin(fountain, fountain.origin);
250 fountain.think = napalm_fountain_think;
251 fountain.nextthink = time;
252 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
253 fountain.pushltime = fountain.ltime;
254 fountain.team = self.team;
255 fountain.movetype = MOVETYPE_TOSS;
256 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
257 fountain.bot_dodge = true;
258 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
259 fountain.nade_special_time = time;
260 setsize(fountain, '-16 -16 -16', '16 16 16');
261 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
264 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
266 frost_target.frozen_by = freezefield.realowner;
267 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
268 Freeze(frost_target, 1/freeze_time, 3, false);
270 Drop_Special_Items(frost_target);
273 void nade_ice_think()
276 if(round_handler_IsActive())
277 if(!round_handler_IsRoundStarted())
283 if(time >= self.ltime)
285 if ( autocvar_g_nades_ice_explode )
287 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
288 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
289 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
291 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
292 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
293 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
294 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
301 self.nextthink = time+0.1;
306 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
308 randomw = random()*M_PI*2;
310 randomp.x = randomr*cos(randomw);
311 randomp.y = randomr*sin(randomw);
313 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
315 if(time >= self.nade_special_time)
317 self.nade_special_time = time+0.7;
319 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
320 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
324 float current_freeze_time = self.ltime - time - 0.1;
327 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
329 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
330 if(e.takedamage && e.deadflag == DEAD_NO)
332 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
334 if(current_freeze_time > 0)
335 nade_ice_freeze(self, e, current_freeze_time);
342 fountain.owner = self.owner;
343 fountain.realowner = self.realowner;
344 fountain.origin = self.origin;
345 setorigin(fountain, fountain.origin);
346 fountain.think = nade_ice_think;
347 fountain.nextthink = time;
348 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
349 fountain.pushltime = fountain.wait = fountain.ltime;
350 fountain.team = self.team;
351 fountain.movetype = MOVETYPE_TOSS;
352 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
353 fountain.bot_dodge = false;
354 setsize(fountain, '-16 -16 -16', '16 16 16');
355 fountain.nade_special_time = time+0.3;
356 fountain.angles = self.angles;
358 if ( autocvar_g_nades_ice_explode )
360 setmodel(fountain, MDL_PROJECTILE_GRENADE);
361 entity timer = new(nade_timer);
362 setmodel(timer, MDL_NADE_TIMER);
363 setattachment(timer, fountain, "");
364 timer.colormap = self.colormap;
365 timer.glowmod = self.glowmod;
366 timer.think = nade_timer_think;
367 timer.nextthink = time;
368 timer.wait = fountain.ltime;
369 timer.owner = fountain;
373 setmodel(fountain, MDL_Null);
376 void nade_translocate_boom()
378 if(self.realowner.vehicle)
381 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
382 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
383 locout = trace_endpos;
385 makevectors(self.realowner.angles);
387 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
389 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
392 void nade_spawn_boom()
394 entity spawnloc = spawn();
395 setorigin(spawnloc, self.origin);
396 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
397 spawnloc.movetype = MOVETYPE_NONE;
398 spawnloc.solid = SOLID_NOT;
399 spawnloc.drawonlytoclient = self.realowner;
400 spawnloc.effects = EF_STARDUST;
401 spawnloc.cnt = autocvar_g_nades_spawn_count;
403 if(self.realowner.nade_spawnloc)
405 remove(self.realowner.nade_spawnloc);
406 self.realowner.nade_spawnloc = world;
409 self.realowner.nade_spawnloc = spawnloc;
412 void nade_heal_think()
414 if(time >= self.ltime)
420 self.nextthink = time;
422 if(time >= self.nade_special_time)
424 self.nade_special_time = time+0.25;
425 self.nade_show_particles = 1;
428 self.nade_show_particles = 0;
431 void nade_heal_touch()
435 if(IS_PLAYER(other) || IS_MONSTER(other))
436 if(other.deadflag == DEAD_NO)
439 health_factor = autocvar_g_nades_heal_rate*frametime/2;
440 if ( other != self.realowner )
442 if ( SAME_TEAM(other,self) )
443 health_factor *= autocvar_g_nades_heal_friend;
445 health_factor *= autocvar_g_nades_heal_foe;
447 if ( health_factor > 0 )
449 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
450 if ( other.health < maxhealth )
452 if ( self.nade_show_particles )
453 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
454 other.health = min(other.health+health_factor, maxhealth);
456 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
458 else if ( health_factor < 0 )
460 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
465 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
467 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
468 show_red.stat_healing_orb = time+0.1;
469 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
473 void nade_heal_boom()
477 healer.owner = self.owner;
478 healer.realowner = self.realowner;
479 setorigin(healer, self.origin);
480 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
481 healer.ltime = time + healer.healer_lifetime;
482 healer.team = self.realowner.team;
483 healer.bot_dodge = false;
484 healer.solid = SOLID_TRIGGER;
485 healer.touch = nade_heal_touch;
487 setmodel(healer, MDL_NADE_HEAL);
488 healer.healer_radius = autocvar_g_nades_nade_radius;
489 vector size = '1 1 1' * healer.healer_radius / 2;
490 setsize(healer,-size,size);
492 Net_LinkEntity(healer, true, 0, healer_send);
494 healer.think = nade_heal_think;
495 healer.nextthink = time;
496 healer.SendFlags |= 1;
499 void nade_monster_boom()
501 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
503 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
504 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
505 e.monster_skill = MONSTER_SKILL_INSANE;
511 bool nade_blast = true;
513 switch ( Nades_from(self.nade_type) )
515 case NADE_TYPE_NAPALM:
516 nade_blast = autocvar_g_nades_napalm_blast;
517 expef = EFFECT_EXPLOSION_MEDIUM;
521 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
523 case NADE_TYPE_TRANSLOCATE:
526 case NADE_TYPE_MONSTER:
527 case NADE_TYPE_SPAWN:
529 switch(self.realowner.team)
531 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
532 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
533 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
534 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
535 default: expef = EFFECT_SPAWN_NEUTRAL; break;
540 expef = EFFECT_SPAWN_RED;
544 case NADE_TYPE_NORMAL:
545 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
550 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
552 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
553 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
555 self.event_damage = func_null; // prevent somehow calling damage in the next call
559 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
560 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
561 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);
565 switch ( Nades_from(self.nade_type) )
567 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
568 case NADE_TYPE_ICE: nade_ice_boom(); break;
569 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
570 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
571 case NADE_TYPE_HEAL: nade_heal_boom(); break;
572 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
576 for(head = world; (head = find(head, classname, "grapplinghook")); )
577 if(head.aiment == self)
578 RemoveGrapplingHook(head.realowner);
585 /*float is_weapclip = 0;
586 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
587 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
588 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
590 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
593 for(head = world; (head = find(head, classname, "grapplinghook")); )
594 if(head.aiment == self)
595 RemoveGrapplingHook(head.realowner);
602 //setsize(self, '-2 -2 -2', '2 2 2');
603 //UpdateCSQCProjectile(self);
604 if(self.health == self.max_health)
606 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
616 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
617 self.think = nade_boom;
618 self.nextthink = max(self.wait, time);
621 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
623 if(ITEM_DAMAGE_NEEDKILL(deathtype))
625 self.takedamage = DAMAGE_NO;
630 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
633 if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
639 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
641 force *= 0.5; // too much
645 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
648 damage = self.max_health * 0.55;
651 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_HMG))
652 damage = self.max_health * 0.1;
654 if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
655 if(deathtype & HITTYPE_SECONDARY)
657 damage = self.max_health * 0.1;
661 damage = self.max_health * 1.15;
663 self.velocity += force;
664 UpdateCSQCProjectile(self);
666 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
669 if(self.health == self.max_health)
671 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
672 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
673 self.think = nade_beep;
676 self.health -= damage;
678 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
679 self.realowner = attacker;
682 W_PrepareExplosionByDamage(attacker, nade_boom);
684 nade_burn_spawn(self);
687 void toss_nade(entity e, vector _velocity, float _time)
692 entity _nade = e.nade;
698 makevectors(e.v_angle);
700 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
702 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
704 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
705 + (v_right * autocvar_g_nades_throw_offset.y)
706 + (v_up * autocvar_g_nades_throw_offset.z);
707 if(autocvar_g_nades_throw_offset == '0 0 0')
710 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
711 //setmodel(_nade, MDL_PROJECTILE_NADE);
712 //setattachment(_nade, world, "");
713 PROJECTILE_MAKETRIGGER(_nade);
714 setsize(_nade, '-16 -16 -16', '16 16 16');
715 _nade.movetype = MOVETYPE_BOUNCE;
717 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
718 if (trace_startsolid)
719 setorigin(_nade, e.origin);
721 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
722 _nade.velocity = '0 0 100';
723 else if(autocvar_g_nades_nade_newton_style == 1)
724 _nade.velocity = e.velocity + _velocity;
725 else if(autocvar_g_nades_nade_newton_style == 2)
726 _nade.velocity = _velocity;
728 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
730 _nade.touch = nade_touch;
731 _nade.health = autocvar_g_nades_nade_health;
732 _nade.max_health = _nade.health;
733 _nade.takedamage = DAMAGE_AIM;
734 _nade.event_damage = nade_damage;
735 _nade.customizeentityforclient = func_null;
736 _nade.exteriormodeltoclient = world;
737 _nade.traileffectnum = 0;
738 _nade.teleportable = true;
739 _nade.pushable = true;
741 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
742 _nade.damagedbycontents = true;
743 _nade.angles = vectoangles(_nade.velocity);
744 _nade.flags = FL_PROJECTILE;
745 _nade.projectiledeathtype = DEATH_NADE.m_id;
746 _nade.toss_time = time;
747 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
749 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
750 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
752 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
758 _nade.think = nade_boom;
759 _nade.nextthink = _time;
762 e.nade_refire = time + autocvar_g_nades_nade_refire;
766 void nades_GiveBonus(entity player, float score)
768 if (autocvar_g_nades)
769 if (autocvar_g_nades_bonus)
770 if (IS_REAL_CLIENT(player))
771 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
772 if (player.frozen == 0)
773 if (player.deadflag == DEAD_NO)
775 if ( player.bonus_nade_score < 1 )
776 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
778 if ( player.bonus_nade_score >= 1 )
780 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
781 play2(player, SND(KH_ALARM));
782 player.bonus_nades++;
783 player.bonus_nade_score -= 1;
788 void nades_RemoveBonus(entity player)
790 player.bonus_nades = player.bonus_nade_score = 0;
793 float nade_customize()
795 //if(IS_SPEC(other)) { return false; }
796 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
798 // somewhat hide the model, but keep the glow
800 if(self.traileffectnum)
801 self.traileffectnum = 0;
806 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
807 if(!self.traileffectnum)
808 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
817 if(autocvar_g_nades_bonus_only)
818 if(!self.bonus_nades)
819 return; // only allow bonus nades
825 remove(self.fake_nade);
827 entity n = new(nade), fn = new(fake_nade);
829 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
830 n.nade_type = self.nade_type;
831 else if (self.bonus_nades >= 1)
833 n.nade_type = self.nade_type;
834 n.pokenade_type = self.pokenade_type;
835 self.bonus_nades -= 1;
839 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
840 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
843 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
845 setmodel(n, MDL_PROJECTILE_NADE);
846 //setattachment(n, self, "bip01 l hand");
847 n.exteriormodeltoclient = self;
848 n.customizeentityforclient = nade_customize;
849 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
850 n.colormod = Nades_from(n.nade_type).m_color;
852 n.colormap = self.colormap;
853 n.glowmod = self.glowmod;
854 n.wait = time + autocvar_g_nades_nade_lifetime;
855 n.nade_time_primed = time;
857 n.nextthink = max(n.wait - 3, time);
858 n.projectiledeathtype = DEATH_NADE.m_id;
860 setmodel(fn, MDL_NADE_VIEW);
861 int slot = 0; // TODO: unhardcode
862 setattachment(fn, self.weaponentity[slot], "");
863 fn.realowner = fn.owner = self;
864 fn.colormod = Nades_from(n.nade_type).m_color;
865 fn.colormap = self.colormap;
866 fn.glowmod = self.glowmod;
867 fn.think = SUB_Remove;
868 fn.nextthink = n.wait;
882 if(self.deadflag != DEAD_NO)
885 if (!autocvar_g_nades)
886 return false; // allow turning them off mid match
888 if(forbidWeaponUse(self))
891 if (!IS_PLAYER(self))
897 .bool nade_altbutton;
899 void nades_CheckThrow()
904 entity held_nade = self.nade;
907 self.nade_altbutton = true;
908 if(time > self.nade_refire)
910 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
912 self.nade_refire = time + autocvar_g_nades_nade_refire;
917 self.nade_altbutton = false;
918 if (time >= held_nade.nade_time_primed + 1) {
919 makevectors(self.v_angle);
920 float _force = time - held_nade.nade_time_primed;
921 _force /= autocvar_g_nades_nade_lifetime;
922 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
923 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
928 void nades_Clear(entity player)
933 remove(player.fake_nade);
935 player.nade = player.fake_nade = world;
936 player.nade_timer = 0;
939 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
942 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
947 CLASS(NadeOffhand, OffhandWeapon)
948 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
950 entity held_nade = player.nade;
953 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
954 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
955 makevectors(player.angles);
956 held_nade.velocity = player.velocity;
957 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
958 held_nade.angles_y = player.angles.y;
960 if (time + 0.1 >= held_nade.wait)
961 toss_nade(player, '0 0 0', time + 0.05);
964 if (!CanThrowNade()) return;
965 if (!(time > player.nade_refire)) return;
969 held_nade = player.nade;
971 } else if (time >= held_nade.nade_time_primed + 1) {
973 makevectors(player.v_angle);
974 float _force = time - held_nade.nade_time_primed;
975 _force /= autocvar_g_nades_nade_lifetime;
976 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
977 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
981 ENDCLASS(NadeOffhand)
982 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
984 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
986 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
993 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
995 if (!IS_PLAYER(self)) { return false; }
997 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1001 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1004 float key_count = 0;
1005 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1008 if(self.flagcarried || self.ballcarried) // this player is important
1009 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1011 time_score = autocvar_g_nades_bonus_score_time;
1014 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1016 if(autocvar_g_nades_bonus_client_select)
1018 self.nade_type = self.cvar_cl_nade_type;
1019 self.pokenade_type = self.cvar_cl_pokenade_type;
1023 self.nade_type = autocvar_g_nades_bonus_type;
1024 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1027 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1029 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1030 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1034 self.bonus_nades = self.bonus_nade_score = 0;
1040 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1044 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1046 FOR_EACH_PLAYER(other) if(self != other)
1048 if(other.deadflag == DEAD_NO)
1049 if(other.frozen == 0)
1050 if(SAME_TEAM(other, self))
1051 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1055 if(self.frozen == 1)
1056 other.reviving = true;
1062 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1064 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1065 self.health = max(1, self.revive_progress * start_health);
1067 if(self.revive_progress >= 1)
1071 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1072 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1075 FOR_EACH_PLAYER(other) if(other.reviving)
1077 other.revive_progress = self.revive_progress;
1078 other.reviving = false;
1085 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1087 if(autocvar_g_nades_spawn)
1088 self.nade_refire = time + autocvar_g_spawnshieldtime;
1090 self.nade_refire = time + autocvar_g_nades_nade_refire;
1092 if(autocvar_g_nades_bonus_client_select)
1093 self.nade_type = self.cvar_cl_nade_type;
1095 self.nade_timer = 0;
1097 if (!self.offhand) self.offhand = OFFHAND_NADE;
1099 if(self.nade_spawnloc)
1101 setorigin(self, self.nade_spawnloc.origin);
1102 self.nade_spawnloc.cnt -= 1;
1104 if(self.nade_spawnloc.cnt <= 0)
1106 remove(self.nade_spawnloc);
1107 self.nade_spawnloc = world;
1114 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1116 if(frag_target.nade)
1117 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1118 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1120 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);
1122 if(IS_PLAYER(frag_attacker))
1124 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1125 nades_RemoveBonus(frag_attacker);
1126 else if(frag_target.flagcarried)
1127 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1128 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1130 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1131 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1132 switch(frag_attacker.killcount)
1135 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1140 nades_GiveBonus(frag_attacker, killcount_bonus);
1143 nades_RemoveBonus(frag_target);
1148 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1150 if(frag_target.frozen)
1151 if(autocvar_g_freezetag_revive_nade)
1152 if(frag_attacker == frag_target)
1153 if(frag_deathtype == DEATH_NADE.m_id)
1154 if(time - frag_inflictor.toss_time <= 0.1)
1156 Unfreeze(frag_target);
1157 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1158 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1160 frag_force = '0 0 0';
1161 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1162 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1168 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1170 if(IS_PLAYER(frag_attacker))
1171 if(DIFF_TEAM(frag_attacker, self))
1172 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1173 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1178 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1180 if(frag_target.nade)
1181 toss_nade(frag_target, '0 0 0', time + 0.05);
1186 bool nades_RemovePlayer()
1189 nades_RemoveBonus(self);
1193 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1194 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1195 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1197 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1199 self.nade_timer = other.nade_timer;
1200 self.nade_type = other.nade_type;
1201 self.pokenade_type = other.pokenade_type;
1202 self.bonus_nades = other.bonus_nades;
1203 self.bonus_nade_score = other.bonus_nade_score;
1204 self.stat_healing_orb = other.stat_healing_orb;
1205 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1209 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1211 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1212 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1217 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1219 ret_string = strcat(ret_string, ":Nades");
1223 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1225 ret_string = strcat(ret_string, ", Nades");