6 entity Nade_TrailEffect(int proj, int nade_team)
10 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
11 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
14 FOREACH(Nades, true, LAMBDA(
15 for (int j = 0; j < 2; j++)
17 if (it.m_projectile[j] == proj)
19 string trail = it.m_trail[j].eent_eff_name;
20 if (trail) return it.m_trail[j];
31 REGISTER_MUTATOR(cl_nades, true);
32 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
34 if (getstatf(STAT_HEALING_ORB) <= time) return false;
35 MUTATOR_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
36 MUTATOR_ARGV(0, float) = getstatf(STAT_HEALING_ORB_ALPHA);
39 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
41 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
44 self.traileffect = EFFECT_FIREBALL.m_id;
47 if (Nade_FromProjectile(self.cnt) != NADE_TYPE_Null)
49 setmodel(self, MDL_PROJECTILE_NADE);
50 entity trail = Nade_TrailEffect(self.cnt, self.team);
51 if (trail.eent_eff_name) self.traileffect = trail.m_id;
55 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
57 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
59 loopsound(self, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
60 self.mins = '-16 -16 -16';
61 self.maxs = '16 16 16';
64 entity nade_type = Nade_FromProjectile(self.cnt);
65 if (nade_type == NADE_TYPE_Null) return;
66 self.mins = '-16 -16 -16';
67 self.maxs = '16 16 16';
68 self.colormod = nade_type.m_color;
69 self.move_movetype = MOVETYPE_BOUNCE;
70 self.move_touch = func_null;
72 self.avelocity = randomvec() * 720;
74 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
75 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
77 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
79 bool Projectile_isnade(int p)
81 return Nade_FromProjectile(p) != NADE_TYPE_Null;
83 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
85 float bonusNades = getstatf(STAT_NADE_BONUS);
86 float bonusProgress = getstatf(STAT_NADE_BONUS_SCORE);
87 float bonusType = getstati(STAT_NADE_BONUS_TYPE);
88 Nade def = Nades_from(bonusType);
89 vector nadeColor = def.m_color;
90 string nadeIcon = def.m_icon;
92 vector iconPos, textPos;
94 if(autocvar_hud_panel_ammo_iconalign)
96 iconPos = myPos + eX * 2 * mySize.y;
102 textPos = myPos + eX * mySize.y;
105 if(bonusNades > 0 || bonusProgress > 0)
107 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
109 if(autocvar_hud_panel_ammo_text)
110 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
113 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
115 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
122 #include "../../../gamemodes/all.qh"
123 #include "../../../monsters/spawn.qh"
124 #include "../../../monsters/sv_monsters.qh"
125 #include "../../../../server/g_subs.qh"
127 REGISTER_MUTATOR(nades, cvar("g_nades"))
131 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
132 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
133 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
134 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
135 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
136 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
142 .float nade_time_primed;
144 .entity nade_spawnloc;
146 void nade_timer_think()
148 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
149 self.nextthink = time;
150 if(!self.owner || wasfreed(self.owner))
154 void nade_burn_spawn(entity _nade)
156 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
159 void nade_spawn(entity _nade)
161 entity timer = new(nade_timer);
162 setmodel(timer, MDL_NADE_TIMER);
163 setattachment(timer, _nade, "");
164 timer.colormap = _nade.colormap;
165 timer.glowmod = _nade.glowmod;
166 timer.think = nade_timer_think;
167 timer.nextthink = time;
168 timer.wait = _nade.wait;
172 _nade.effects |= EF_LOWPRECISION;
174 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
177 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
186 RandomSelection_Init();
187 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
188 if(e.takedamage == DAMAGE_AIM)
189 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
190 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
194 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
195 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
196 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
197 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
200 e.fireball_impactvec = p;
201 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
204 if(RandomSelection_chosen_ent)
206 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
207 d = damage + (edgedamage - damage) * (d / dist);
208 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
209 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
210 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
215 void napalm_ball_think()
217 if(round_handler_IsActive())
218 if(!round_handler_IsRoundStarted())
224 if(time > self.pushltime)
230 vector midpoint = ((self.absmin + self.absmax) * 0.5);
231 if(pointcontents(midpoint) == CONTENT_WATER)
233 self.velocity = self.velocity * 0.5;
235 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
236 { self.velocity_z = 200; }
239 self.angles = vectoangles(self.velocity);
241 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
242 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
244 self.nextthink = time + 0.1;
248 void nade_napalm_ball()
253 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
256 proj.owner = self.owner;
257 proj.realowner = self.realowner;
258 proj.team = self.owner.team;
259 proj.bot_dodge = true;
260 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
261 proj.movetype = MOVETYPE_BOUNCE;
262 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
263 PROJECTILE_MAKETRIGGER(proj);
264 setmodel(proj, MDL_Null);
265 proj.scale = 1;//0.5;
266 setsize(proj, '-4 -4 -4', '4 4 4');
267 setorigin(proj, self.origin);
268 proj.think = napalm_ball_think;
269 proj.nextthink = time;
270 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
271 proj.effects = EF_LOWPRECISION | EF_FLAME;
273 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
274 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
275 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
276 proj.velocity = kick;
278 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
280 proj.angles = vectoangles(proj.velocity);
281 proj.flags = FL_PROJECTILE;
282 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
284 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
288 void napalm_fountain_think()
291 if(round_handler_IsActive())
292 if(!round_handler_IsRoundStarted())
298 if(time >= self.ltime)
304 vector midpoint = ((self.absmin + self.absmax) * 0.5);
305 if(pointcontents(midpoint) == CONTENT_WATER)
307 self.velocity = self.velocity * 0.5;
309 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
310 { self.velocity_z = 200; }
312 UpdateCSQCProjectile(self);
315 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
316 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
318 self.nextthink = time + 0.1;
319 if(time >= self.nade_special_time)
321 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
326 void nade_napalm_boom()
330 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
335 fountain.owner = self.owner;
336 fountain.realowner = self.realowner;
337 fountain.origin = self.origin;
338 setorigin(fountain, fountain.origin);
339 fountain.think = napalm_fountain_think;
340 fountain.nextthink = time;
341 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
342 fountain.pushltime = fountain.ltime;
343 fountain.team = self.team;
344 fountain.movetype = MOVETYPE_TOSS;
345 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
346 fountain.bot_dodge = true;
347 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
348 fountain.nade_special_time = time;
349 setsize(fountain, '-16 -16 -16', '16 16 16');
350 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
353 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
355 frost_target.frozen_by = freezefield.realowner;
356 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
357 Freeze(frost_target, 1/freeze_time, 3, false);
359 Drop_Special_Items(frost_target);
362 void nade_ice_think()
365 if(round_handler_IsActive())
366 if(!round_handler_IsRoundStarted())
372 if(time >= self.ltime)
374 if ( autocvar_g_nades_ice_explode )
376 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
377 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
378 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
380 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
381 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
382 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
383 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
390 self.nextthink = time+0.1;
395 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
397 randomw = random()*M_PI*2;
399 randomp.x = randomr*cos(randomw);
400 randomp.y = randomr*sin(randomw);
402 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
404 if(time >= self.nade_special_time)
406 self.nade_special_time = time+0.7;
408 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
409 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
413 float current_freeze_time = self.ltime - time - 0.1;
416 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
418 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
419 if(e.takedamage && e.deadflag == DEAD_NO)
421 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
423 if(current_freeze_time > 0)
424 nade_ice_freeze(self, e, current_freeze_time);
431 fountain.owner = self.owner;
432 fountain.realowner = self.realowner;
433 fountain.origin = self.origin;
434 setorigin(fountain, fountain.origin);
435 fountain.think = nade_ice_think;
436 fountain.nextthink = time;
437 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
438 fountain.pushltime = fountain.wait = fountain.ltime;
439 fountain.team = self.team;
440 fountain.movetype = MOVETYPE_TOSS;
441 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
442 fountain.bot_dodge = false;
443 setsize(fountain, '-16 -16 -16', '16 16 16');
444 fountain.nade_special_time = time+0.3;
445 fountain.angles = self.angles;
447 if ( autocvar_g_nades_ice_explode )
449 setmodel(fountain, MDL_PROJECTILE_GRENADE);
450 entity timer = new(nade_timer);
451 setmodel(timer, MDL_NADE_TIMER);
452 setattachment(timer, fountain, "");
453 timer.colormap = self.colormap;
454 timer.glowmod = self.glowmod;
455 timer.think = nade_timer_think;
456 timer.nextthink = time;
457 timer.wait = fountain.ltime;
458 timer.owner = fountain;
462 setmodel(fountain, MDL_Null);
465 void nade_translocate_boom()
467 if(self.realowner.vehicle)
470 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
471 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
472 locout = trace_endpos;
474 makevectors(self.realowner.angles);
476 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
478 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
481 void nade_spawn_boom()
483 entity spawnloc = spawn();
484 setorigin(spawnloc, self.origin);
485 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
486 spawnloc.movetype = MOVETYPE_NONE;
487 spawnloc.solid = SOLID_NOT;
488 spawnloc.drawonlytoclient = self.realowner;
489 spawnloc.effects = EF_STARDUST;
490 spawnloc.cnt = autocvar_g_nades_spawn_count;
492 if(self.realowner.nade_spawnloc)
494 remove(self.realowner.nade_spawnloc);
495 self.realowner.nade_spawnloc = world;
498 self.realowner.nade_spawnloc = spawnloc;
501 void nade_heal_think()
503 if(time >= self.ltime)
509 self.nextthink = time;
511 if(time >= self.nade_special_time)
513 self.nade_special_time = time+0.25;
514 self.nade_show_particles = 1;
517 self.nade_show_particles = 0;
520 void nade_heal_touch()
524 if(IS_PLAYER(other) || IS_MONSTER(other))
525 if(other.deadflag == DEAD_NO)
528 health_factor = autocvar_g_nades_heal_rate*frametime/2;
529 if ( other != self.realowner )
531 if ( SAME_TEAM(other,self) )
532 health_factor *= autocvar_g_nades_heal_friend;
534 health_factor *= autocvar_g_nades_heal_foe;
536 if ( health_factor > 0 )
538 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
539 if ( other.health < maxhealth )
541 if ( self.nade_show_particles )
542 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
543 other.health = min(other.health+health_factor, maxhealth);
545 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
547 else if ( health_factor < 0 )
549 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
554 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
556 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
557 show_red.stat_healing_orb = time+0.1;
558 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
562 void nade_heal_boom()
566 healer.owner = self.owner;
567 healer.realowner = self.realowner;
568 setorigin(healer, self.origin);
569 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
570 healer.ltime = time + healer.healer_lifetime;
571 healer.team = self.realowner.team;
572 healer.bot_dodge = false;
573 healer.solid = SOLID_TRIGGER;
574 healer.touch = nade_heal_touch;
576 setmodel(healer, MDL_NADE_HEAL);
577 healer.healer_radius = autocvar_g_nades_nade_radius;
578 vector size = '1 1 1' * healer.healer_radius / 2;
579 setsize(healer,-size,size);
581 Net_LinkEntity(healer, true, 0, healer_send);
583 healer.think = nade_heal_think;
584 healer.nextthink = time;
585 healer.SendFlags |= 1;
588 void nade_monster_boom()
590 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
592 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
593 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
594 e.monster_skill = MONSTER_SKILL_INSANE;
600 bool nade_blast = true;
602 switch ( Nades_from(self.nade_type) )
604 case NADE_TYPE_NAPALM:
605 nade_blast = autocvar_g_nades_napalm_blast;
606 expef = EFFECT_EXPLOSION_MEDIUM;
610 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
612 case NADE_TYPE_TRANSLOCATE:
615 case NADE_TYPE_MONSTER:
616 case NADE_TYPE_SPAWN:
618 switch(self.realowner.team)
620 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
621 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
622 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
623 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
624 default: expef = EFFECT_SPAWN_NEUTRAL; break;
629 expef = EFFECT_SPAWN_RED;
633 case NADE_TYPE_NORMAL:
634 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
639 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
641 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
642 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
644 self.event_damage = func_null; // prevent somehow calling damage in the next call
648 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
649 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
650 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);
654 switch ( Nades_from(self.nade_type) )
656 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
657 case NADE_TYPE_ICE: nade_ice_boom(); break;
658 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
659 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
660 case NADE_TYPE_HEAL: nade_heal_boom(); break;
661 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
665 for(head = world; (head = find(head, classname, "grapplinghook")); )
666 if(head.aiment == self)
667 RemoveGrapplingHook(head.realowner);
674 /*float is_weapclip = 0;
675 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
676 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
677 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
679 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
682 for(head = world; (head = find(head, classname, "grapplinghook")); )
683 if(head.aiment == self)
684 RemoveGrapplingHook(head.realowner);
691 //setsize(self, '-2 -2 -2', '2 2 2');
692 //UpdateCSQCProjectile(self);
693 if(self.health == self.max_health)
695 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
705 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
706 self.think = nade_boom;
707 self.nextthink = max(self.wait, time);
710 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
712 if(ITEM_DAMAGE_NEEDKILL(deathtype))
714 self.takedamage = DAMAGE_NO;
719 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
722 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
723 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
728 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
730 force *= 0.5; // too much
733 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
736 damage = self.max_health * 0.55;
738 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
739 damage = self.max_health * 0.1;
740 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
742 if(deathtype & HITTYPE_SECONDARY)
744 damage = self.max_health * 0.1;
748 damage = self.max_health * 1.15;
751 self.velocity += force;
752 UpdateCSQCProjectile(self);
754 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
757 if(self.health == self.max_health)
759 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
760 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
761 self.think = nade_beep;
764 self.health -= damage;
766 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
767 self.realowner = attacker;
770 W_PrepareExplosionByDamage(attacker, nade_boom);
772 nade_burn_spawn(self);
775 void toss_nade(entity e, vector _velocity, float _time)
780 entity _nade = e.nade;
786 makevectors(e.v_angle);
788 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
790 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
792 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
793 + (v_right * autocvar_g_nades_throw_offset.y)
794 + (v_up * autocvar_g_nades_throw_offset.z);
795 if(autocvar_g_nades_throw_offset == '0 0 0')
798 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
799 //setmodel(_nade, MDL_PROJECTILE_NADE);
800 //setattachment(_nade, world, "");
801 PROJECTILE_MAKETRIGGER(_nade);
802 setsize(_nade, '-16 -16 -16', '16 16 16');
803 _nade.movetype = MOVETYPE_BOUNCE;
805 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
806 if (trace_startsolid)
807 setorigin(_nade, e.origin);
809 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
810 _nade.velocity = '0 0 100';
811 else if(autocvar_g_nades_nade_newton_style == 1)
812 _nade.velocity = e.velocity + _velocity;
813 else if(autocvar_g_nades_nade_newton_style == 2)
814 _nade.velocity = _velocity;
816 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
818 _nade.touch = nade_touch;
819 _nade.health = autocvar_g_nades_nade_health;
820 _nade.max_health = _nade.health;
821 _nade.takedamage = DAMAGE_AIM;
822 _nade.event_damage = nade_damage;
823 _nade.customizeentityforclient = func_null;
824 _nade.exteriormodeltoclient = world;
825 _nade.traileffectnum = 0;
826 _nade.teleportable = true;
827 _nade.pushable = true;
829 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
830 _nade.damagedbycontents = true;
831 _nade.angles = vectoangles(_nade.velocity);
832 _nade.flags = FL_PROJECTILE;
833 _nade.projectiledeathtype = DEATH_NADE.m_id;
834 _nade.toss_time = time;
835 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
837 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
838 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
840 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
846 _nade.think = nade_boom;
847 _nade.nextthink = _time;
850 e.nade_refire = time + autocvar_g_nades_nade_refire;
854 void nades_GiveBonus(entity player, float score)
856 if (autocvar_g_nades)
857 if (autocvar_g_nades_bonus)
858 if (IS_REAL_CLIENT(player))
859 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
860 if (player.frozen == 0)
861 if (player.deadflag == DEAD_NO)
863 if ( player.bonus_nade_score < 1 )
864 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
866 if ( player.bonus_nade_score >= 1 )
868 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
869 play2(player, SND(KH_ALARM));
870 player.bonus_nades++;
871 player.bonus_nade_score -= 1;
876 /** Remove all bonus nades from a player */
877 void nades_RemoveBonus(entity player)
879 player.bonus_nades = player.bonus_nade_score = 0;
882 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
884 nades_RemoveBonus(self);
887 float nade_customize()
889 //if(IS_SPEC(other)) { return false; }
890 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
892 // somewhat hide the model, but keep the glow
894 if(self.traileffectnum)
895 self.traileffectnum = 0;
900 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
901 if(!self.traileffectnum)
902 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
911 if(autocvar_g_nades_bonus_only)
912 if(!self.bonus_nades)
913 return; // only allow bonus nades
919 remove(self.fake_nade);
921 entity n = new(nade), fn = new(fake_nade);
923 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
924 n.nade_type = self.nade_type;
925 else if (self.bonus_nades >= 1)
927 n.nade_type = self.nade_type;
928 n.pokenade_type = self.pokenade_type;
929 self.bonus_nades -= 1;
933 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
934 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
937 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
939 setmodel(n, MDL_PROJECTILE_NADE);
940 //setattachment(n, self, "bip01 l hand");
941 n.exteriormodeltoclient = self;
942 n.customizeentityforclient = nade_customize;
943 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
944 n.colormod = Nades_from(n.nade_type).m_color;
946 n.colormap = self.colormap;
947 n.glowmod = self.glowmod;
948 n.wait = time + autocvar_g_nades_nade_lifetime;
949 n.nade_time_primed = time;
951 n.nextthink = max(n.wait - 3, time);
952 n.projectiledeathtype = DEATH_NADE.m_id;
954 setmodel(fn, MDL_NADE_VIEW);
955 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
956 setattachment(fn, self.(weaponentity), "");
957 fn.realowner = fn.owner = self;
958 fn.colormod = Nades_from(n.nade_type).m_color;
959 fn.colormap = self.colormap;
960 fn.glowmod = self.glowmod;
961 fn.think = SUB_Remove_self;
962 fn.nextthink = n.wait;
976 if(self.deadflag != DEAD_NO)
979 if (!autocvar_g_nades)
980 return false; // allow turning them off mid match
982 if(forbidWeaponUse(self))
985 if (!IS_PLAYER(self))
991 .bool nade_altbutton;
993 void nades_CheckThrow()
998 entity held_nade = self.nade;
1001 self.nade_altbutton = true;
1002 if(time > self.nade_refire)
1004 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1006 self.nade_refire = time + autocvar_g_nades_nade_refire;
1011 self.nade_altbutton = false;
1012 if (time >= held_nade.nade_time_primed + 1) {
1013 makevectors(self.v_angle);
1014 float _force = time - held_nade.nade_time_primed;
1015 _force /= autocvar_g_nades_nade_lifetime;
1016 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1017 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
1022 void nades_Clear(entity player)
1025 remove(player.nade);
1026 if(player.fake_nade)
1027 remove(player.fake_nade);
1029 player.nade = player.fake_nade = world;
1030 player.nade_timer = 0;
1033 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1036 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1041 CLASS(NadeOffhand, OffhandWeapon)
1042 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1044 entity held_nade = player.nade;
1047 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1048 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1049 makevectors(player.angles);
1050 held_nade.velocity = player.velocity;
1051 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1052 held_nade.angles_y = player.angles.y;
1054 if (time + 0.1 >= held_nade.wait)
1055 toss_nade(player, '0 0 0', time + 0.05);
1058 if (!CanThrowNade()) return;
1059 if (!(time > player.nade_refire)) return;
1063 held_nade = player.nade;
1065 } else if (time >= held_nade.nade_time_primed + 1) {
1067 makevectors(player.v_angle);
1068 float _force = time - held_nade.nade_time_primed;
1069 _force /= autocvar_g_nades_nade_lifetime;
1070 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1071 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
1075 ENDCLASS(NadeOffhand)
1076 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1078 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1080 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1087 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1089 if (!IS_PLAYER(self)) { return false; }
1091 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1095 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1098 float key_count = 0;
1099 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1102 if(self.flagcarried || self.ballcarried) // this player is important
1103 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1105 time_score = autocvar_g_nades_bonus_score_time;
1108 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1110 if(autocvar_g_nades_bonus_client_select)
1112 self.nade_type = self.cvar_cl_nade_type;
1113 self.pokenade_type = self.cvar_cl_pokenade_type;
1117 self.nade_type = autocvar_g_nades_bonus_type;
1118 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1121 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1123 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1124 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1128 self.bonus_nades = self.bonus_nade_score = 0;
1134 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1138 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1140 FOR_EACH_PLAYER(other) if(self != other)
1142 if(other.deadflag == DEAD_NO)
1143 if(other.frozen == 0)
1144 if(SAME_TEAM(other, self))
1145 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1149 if(self.frozen == 1)
1150 other.reviving = true;
1156 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1158 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1159 self.health = max(1, self.revive_progress * start_health);
1161 if(self.revive_progress >= 1)
1165 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1166 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1169 FOR_EACH_PLAYER(other) if(other.reviving)
1171 other.revive_progress = self.revive_progress;
1172 other.reviving = false;
1179 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1181 if(autocvar_g_nades_spawn)
1182 self.nade_refire = time + autocvar_g_spawnshieldtime;
1184 self.nade_refire = time + autocvar_g_nades_nade_refire;
1186 if(autocvar_g_nades_bonus_client_select)
1187 self.nade_type = self.cvar_cl_nade_type;
1189 self.nade_timer = 0;
1191 if (!self.offhand) self.offhand = OFFHAND_NADE;
1193 if(self.nade_spawnloc)
1195 setorigin(self, self.nade_spawnloc.origin);
1196 self.nade_spawnloc.cnt -= 1;
1198 if(self.nade_spawnloc.cnt <= 0)
1200 remove(self.nade_spawnloc);
1201 self.nade_spawnloc = world;
1208 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1210 if(frag_target.nade)
1211 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1212 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1214 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);
1216 if(IS_PLAYER(frag_attacker))
1218 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1219 nades_RemoveBonus(frag_attacker);
1220 else if(frag_target.flagcarried)
1221 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1222 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1224 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1225 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1226 switch(frag_attacker.killcount)
1229 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1234 nades_GiveBonus(frag_attacker, killcount_bonus);
1237 nades_RemoveBonus(frag_target);
1242 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1244 if(frag_target.frozen)
1245 if(autocvar_g_freezetag_revive_nade)
1246 if(frag_attacker == frag_target)
1247 if(frag_deathtype == DEATH_NADE.m_id)
1248 if(time - frag_inflictor.toss_time <= 0.1)
1250 Unfreeze(frag_target);
1251 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1252 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1254 frag_force = '0 0 0';
1255 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1256 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1262 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1264 if(IS_PLAYER(frag_attacker))
1265 if(DIFF_TEAM(frag_attacker, self))
1266 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1267 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1272 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1274 if(frag_target.nade)
1275 toss_nade(frag_target, '0 0 0', time + 0.05);
1280 bool nades_RemovePlayer()
1283 nades_RemoveBonus(self);
1287 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1288 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1289 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1291 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1293 self.nade_timer = other.nade_timer;
1294 self.nade_type = other.nade_type;
1295 self.pokenade_type = other.pokenade_type;
1296 self.bonus_nades = other.bonus_nades;
1297 self.bonus_nade_score = other.bonus_nade_score;
1298 self.stat_healing_orb = other.stat_healing_orb;
1299 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1303 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1305 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1306 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1311 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1313 ret_string = strcat(ret_string, ":Nades");
1317 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1319 ret_string = strcat(ret_string, ", Nades");