6 bool autocvar_g_nades_nade_small;
7 float autocvar_g_nades_spread = 0.04;
10 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
13 entity Nade_TrailEffect(int proj, int nade_team)
17 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
18 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
21 FOREACH(Nades, true, LAMBDA(
22 for (int j = 0; j < 2; j++)
24 if (it.m_projectile[j] == proj)
26 string trail = it.m_trail[j].eent_eff_name;
27 if (trail) return it.m_trail[j];
38 REGISTER_MUTATOR(cl_nades, true);
39 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
41 if (STAT(HEALING_ORB) > time)
43 MUTATOR_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
44 MUTATOR_ARGV(0, float) = STAT(HEALING_ORB_ALPHA);
47 if (STAT(ENTRAP_ORB) > time)
49 MUTATOR_ARGV(0, vector) = NADE_TYPE_ENTRAP.m_color;
50 MUTATOR_ARGV(0, float) = STAT(ENTRAP_ORB_ALPHA);
55 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
58 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
61 self.traileffect = EFFECT_FIREBALL.m_id;
64 if (Nade_FromProjectile(self.cnt) != NADE_TYPE_Null)
66 setmodel(self, MDL_PROJECTILE_NADE);
67 entity trail = Nade_TrailEffect(self.cnt, self.team);
68 if (trail.eent_eff_name) self.traileffect = trail.m_id;
72 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
75 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
77 loopsound(self, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
78 self.mins = '-16 -16 -16';
79 self.maxs = '16 16 16';
82 entity nade_type = Nade_FromProjectile(self.cnt);
83 if (nade_type == NADE_TYPE_Null) return;
84 if(STAT(NADES_SMALL, NULL))
86 self.mins = '-8 -8 -8';
91 self.mins = '-16 -16 -16';
92 self.maxs = '16 16 16';
94 self.colormod = nade_type.m_color;
95 self.move_movetype = MOVETYPE_BOUNCE;
96 self.move_touch = func_null;
98 self.avelocity = randomvec() * 720;
100 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
101 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
103 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
105 bool Projectile_isnade(int p)
107 return Nade_FromProjectile(p) != NADE_TYPE_Null;
109 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
111 float bonusNades = STAT(NADE_BONUS);
112 float bonusProgress = STAT(NADE_BONUS_SCORE);
113 float bonusType = STAT(NADE_BONUS_TYPE);
114 Nade def = Nades_from(bonusType);
115 vector nadeColor = def.m_color;
116 string nadeIcon = def.m_icon;
118 vector iconPos, textPos;
120 if(autocvar_hud_panel_ammo_iconalign)
122 iconPos = myPos + eX * 2 * mySize.y;
128 textPos = myPos + eX * mySize.y;
131 if(bonusNades > 0 || bonusProgress > 0)
133 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
135 if(autocvar_hud_panel_ammo_text)
136 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
139 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
141 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
148 #include <common/gamemodes/all.qh>
149 #include <common/monsters/spawn.qh>
150 #include <common/monsters/sv_monsters.qh>
151 #include <server/g_subs.qh>
153 REGISTER_MUTATOR(nades, cvar("g_nades"));
155 .float nade_time_primed;
157 .entity nade_spawnloc;
159 void nade_timer_think()
161 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
162 self.nextthink = time;
163 if(!self.owner || wasfreed(self.owner))
167 void nade_burn_spawn(entity _nade)
169 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
172 void nade_spawn(entity _nade)
174 entity timer = new(nade_timer);
175 setmodel(timer, MDL_NADE_TIMER);
176 setattachment(timer, _nade, "");
177 timer.colormap = _nade.colormap;
178 timer.glowmod = _nade.glowmod;
179 timer.think = nade_timer_think;
180 timer.nextthink = time;
181 timer.wait = _nade.wait;
185 _nade.effects |= EF_LOWPRECISION;
187 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
190 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
199 RandomSelection_Init();
200 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
201 if(e.takedamage == DAMAGE_AIM)
202 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
203 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
207 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
208 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
209 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
210 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
213 e.fireball_impactvec = p;
214 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
217 if(RandomSelection_chosen_ent)
219 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
220 d = damage + (edgedamage - damage) * (d / dist);
221 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
222 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
223 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
228 void napalm_ball_think()
230 if(round_handler_IsActive())
231 if(!round_handler_IsRoundStarted())
237 if(time > self.pushltime)
243 vector midpoint = ((self.absmin + self.absmax) * 0.5);
244 if(pointcontents(midpoint) == CONTENT_WATER)
246 self.velocity = self.velocity * 0.5;
248 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
249 { self.velocity_z = 200; }
252 self.angles = vectoangles(self.velocity);
254 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
255 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
257 self.nextthink = time + 0.1;
261 void nade_napalm_ball()
266 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
269 proj.owner = self.owner;
270 proj.realowner = self.realowner;
271 proj.team = self.owner.team;
272 proj.bot_dodge = true;
273 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
274 proj.movetype = MOVETYPE_BOUNCE;
275 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
276 PROJECTILE_MAKETRIGGER(proj);
277 setmodel(proj, MDL_Null);
278 proj.scale = 1;//0.5;
279 setsize(proj, '-4 -4 -4', '4 4 4');
280 setorigin(proj, self.origin);
281 proj.think = napalm_ball_think;
282 proj.nextthink = time;
283 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
284 proj.effects = EF_LOWPRECISION | EF_FLAME;
286 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
287 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
288 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
289 proj.velocity = kick;
291 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
293 proj.angles = vectoangles(proj.velocity);
294 proj.flags = FL_PROJECTILE;
295 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
297 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
301 void napalm_fountain_think()
304 if(round_handler_IsActive())
305 if(!round_handler_IsRoundStarted())
311 if(time >= self.ltime)
317 vector midpoint = ((self.absmin + self.absmax) * 0.5);
318 if(pointcontents(midpoint) == CONTENT_WATER)
320 self.velocity = self.velocity * 0.5;
322 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
323 { self.velocity_z = 200; }
325 UpdateCSQCProjectile(self);
328 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
329 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
331 self.nextthink = time + 0.1;
332 if(time >= self.nade_special_time)
334 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
339 void nade_napalm_boom()
343 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
348 fountain.owner = self.owner;
349 fountain.realowner = self.realowner;
350 fountain.origin = self.origin;
351 setorigin(fountain, fountain.origin);
352 fountain.think = napalm_fountain_think;
353 fountain.nextthink = time;
354 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
355 fountain.pushltime = fountain.ltime;
356 fountain.team = self.team;
357 fountain.movetype = MOVETYPE_TOSS;
358 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
359 fountain.bot_dodge = true;
360 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
361 fountain.nade_special_time = time;
362 setsize(fountain, '-16 -16 -16', '16 16 16');
363 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
366 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
368 frost_target.frozen_by = freezefield.realowner;
369 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
370 Freeze(frost_target, 1/freeze_time, 3, false);
372 Drop_Special_Items(frost_target);
375 void nade_ice_think()
378 if(round_handler_IsActive())
379 if(!round_handler_IsRoundStarted())
385 if(time >= self.ltime)
387 if ( autocvar_g_nades_ice_explode )
389 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
390 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
391 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
393 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
394 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
395 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
396 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
403 self.nextthink = time+0.1;
408 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
410 randomw = random()*M_PI*2;
412 randomp.x = randomr*cos(randomw);
413 randomp.y = randomr*sin(randomw);
415 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
417 if(time >= self.nade_special_time)
419 self.nade_special_time = time+0.7;
421 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
422 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
426 float current_freeze_time = self.ltime - time - 0.1;
429 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
431 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
432 if(e.takedamage && !IS_DEAD(e))
434 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
436 if(current_freeze_time > 0)
437 nade_ice_freeze(self, e, current_freeze_time);
444 fountain.owner = self.owner;
445 fountain.realowner = self.realowner;
446 fountain.origin = self.origin;
447 setorigin(fountain, fountain.origin);
448 fountain.think = nade_ice_think;
449 fountain.nextthink = time;
450 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
451 fountain.pushltime = fountain.wait = fountain.ltime;
452 fountain.team = self.team;
453 fountain.movetype = MOVETYPE_TOSS;
454 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
455 fountain.bot_dodge = false;
456 setsize(fountain, '-16 -16 -16', '16 16 16');
457 fountain.nade_special_time = time+0.3;
458 fountain.angles = self.angles;
460 if ( autocvar_g_nades_ice_explode )
462 setmodel(fountain, MDL_PROJECTILE_GRENADE);
463 entity timer = new(nade_timer);
464 setmodel(timer, MDL_NADE_TIMER);
465 setattachment(timer, fountain, "");
466 timer.colormap = self.colormap;
467 timer.glowmod = self.glowmod;
468 timer.think = nade_timer_think;
469 timer.nextthink = time;
470 timer.wait = fountain.ltime;
471 timer.owner = fountain;
475 setmodel(fountain, MDL_Null);
478 void nade_translocate_boom()
480 if(self.realowner.vehicle)
483 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
484 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
485 locout = trace_endpos;
487 makevectors(self.realowner.angles);
489 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
491 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
494 void nade_spawn_boom()
496 entity spawnloc = spawn();
497 setorigin(spawnloc, self.origin);
498 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
499 spawnloc.movetype = MOVETYPE_NONE;
500 spawnloc.solid = SOLID_NOT;
501 spawnloc.drawonlytoclient = self.realowner;
502 spawnloc.effects = EF_STARDUST;
503 spawnloc.cnt = autocvar_g_nades_spawn_count;
505 if(self.realowner.nade_spawnloc)
507 remove(self.realowner.nade_spawnloc);
508 self.realowner.nade_spawnloc = world;
511 self.realowner.nade_spawnloc = spawnloc;
514 void nades_orb_think()
516 if(time >= this.ltime)
522 this.nextthink = time;
524 if(time >= this.nade_special_time)
526 this.nade_special_time = time+0.25;
527 this.nade_show_particles = 1;
530 this.nade_show_particles = 0;
533 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
535 // NOTE: this function merely places an orb
536 // you must add a custom touch function to the returned entity if desired
537 // also set .colormod if you wish to have it colorized
538 entity orb = spawn(); // Net_LinkEntity sets the classname (TODO)
540 orb.realowner = realown;
543 orb.orb_lifetime = orb_ltime; // required for timers
544 orb.ltime = time + orb.orb_lifetime;
545 orb.bot_dodge = false;
546 orb.team = realown.team;
547 orb.solid = SOLID_TRIGGER;
549 setmodel(orb, MDL_NADE_ORB);
550 orb.orb_radius = orb_rad; // required for fading
551 vector size = '1 1 1' * orb.orb_radius / 2;
552 setsize(orb, -size, size);
554 Net_LinkEntity(orb, true, 0, orb_send);
557 orb.think = nades_orb_think;
558 orb.nextthink = time;
563 void nade_entrap_touch()
565 if(DIFF_TEAM(other, self.realowner)) // TODO: what if realowner changes team or disconnects?
567 if (!isPushable(other))
570 float pushdeltatime = time - other.lastpushtime;
571 if (pushdeltatime > 0.15) pushdeltatime = 0;
572 other.lastpushtime = time;
573 if(!pushdeltatime) return;
575 // div0: ticrate independent, 1 = identity (not 20)
577 other.velocity = other.velocity * pow(autocvar_g_nades_entrap_strength, pushdeltatime);
579 UpdateCSQCProjectile(other);
581 other.move_velocity = other.move_velocity * pow(autocvar_g_nades_entrap_strength, pushdeltatime);
584 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
586 entity show_tint = (IS_VEHICLE(other)) ? other.owner : other;
587 STAT(ENTRAP_ORB, show_tint) = time + 0.1;
588 STAT(ENTRAP_ORB_ALPHA, show_tint) = 0.75 * (self.ltime - time) / self.orb_lifetime;
593 void nade_entrap_boom(entity this)
595 entity healer = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
597 healer.touch = nade_entrap_touch;
598 healer.colormod = NADE_TYPE_ENTRAP.m_color;
601 void nade_heal_touch()
605 if(IS_PLAYER(other) || IS_MONSTER(other))
607 if(!STAT(FROZEN, other))
609 health_factor = autocvar_g_nades_heal_rate*frametime/2;
610 if ( other != self.realowner )
612 if ( SAME_TEAM(other,self) )
613 health_factor *= autocvar_g_nades_heal_friend;
615 health_factor *= autocvar_g_nades_heal_foe;
617 if ( health_factor > 0 )
619 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
620 if ( other.health < maxhealth )
622 if ( self.nade_show_particles )
623 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
624 other.health = min(other.health+health_factor, maxhealth);
626 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
628 else if ( health_factor < 0 )
630 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
635 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
637 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
638 show_red.stat_healing_orb = time+0.1;
639 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.orb_lifetime;
643 void nade_heal_boom(entity this)
645 entity healer = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
647 healer.touch = nade_heal_touch;
648 healer.colormod = '1 0 0';
651 void nade_monster_boom()
653 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
655 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
656 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
657 e.monster_skill = MONSTER_SKILL_INSANE;
663 bool nade_blast = true;
665 switch ( Nades_from(self.nade_type) )
667 case NADE_TYPE_NAPALM:
668 nade_blast = autocvar_g_nades_napalm_blast;
669 expef = EFFECT_EXPLOSION_MEDIUM;
673 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
675 case NADE_TYPE_TRANSLOCATE:
678 case NADE_TYPE_MONSTER:
679 case NADE_TYPE_SPAWN:
681 switch(self.realowner.team)
683 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
684 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
685 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
686 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
687 default: expef = EFFECT_SPAWN_NEUTRAL; break;
692 expef = EFFECT_SPAWN_RED;
695 case NADE_TYPE_ENTRAP:
697 expef = EFFECT_SPAWN_YELLOW;
701 case NADE_TYPE_NORMAL:
702 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
707 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
709 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
710 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
712 self.event_damage = func_null; // prevent somehow calling damage in the next call
716 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
717 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
718 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);
722 switch ( Nades_from(self.nade_type) )
724 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
725 case NADE_TYPE_ICE: nade_ice_boom(); break;
726 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
727 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
728 case NADE_TYPE_HEAL: nade_heal_boom(self); break;
729 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
730 case NADE_TYPE_ENTRAP: nade_entrap_boom(self); break;
733 FOREACH_ENTITY_ENT(aiment, self,
735 if(it.classname == "grapplinghook")
736 RemoveGrapplingHook(it.realowner);
742 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
743 void nade_pickup(entity this, entity thenade)
745 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, thenade.nade_type, thenade.pokenade_type);
747 // set refire so player can't even
748 this.nade_refire = time + autocvar_g_nades_nade_refire;
752 this.nade.nade_time_primed = thenade.nade_time_primed;
755 bool CanThrowNade(entity this);
759 UpdateCSQCProjectile(self);
761 if(other == self.realowner)
762 return; // no self impacts
764 if(autocvar_g_nades_pickup)
765 if(time >= self.spawnshieldtime)
766 if(!other.nade && self.health == self.max_health) // no boosted shot pickups, thank you very much
768 if(CanThrowNade(other)) // prevent some obvious things, like dead players
769 if(IS_REAL_CLIENT(other)) // above checks for IS_PLAYER, don't need to do it here
771 nade_pickup(other, self);
772 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
776 /*float is_weapclip = 0;
777 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
778 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
779 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
781 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
783 FOREACH_ENTITY_ENT(aiment, self,
785 if(it.classname == "grapplinghook")
786 RemoveGrapplingHook(it.realowner);
794 //setsize(self, '-2 -2 -2', '2 2 2');
795 //UpdateCSQCProjectile(self);
796 if(self.health == self.max_health)
798 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
808 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
809 self.think = nade_boom;
810 self.nextthink = max(self.wait, time);
813 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
815 if(ITEM_DAMAGE_NEEDKILL(deathtype))
817 this.takedamage = DAMAGE_NO;
818 WITHSELF(this, nade_boom());
822 if(this.nade_type == NADE_TYPE_TRANSLOCATE.m_id || this.nade_type == NADE_TYPE_SPAWN.m_id)
825 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
826 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
831 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
833 force *= 0.5; // too much
836 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
839 damage = this.max_health * 0.55;
841 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
842 damage = this.max_health * 0.1;
843 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
845 if(deathtype & HITTYPE_SECONDARY)
847 damage = this.max_health * 0.1;
851 damage = this.max_health * 1.15;
854 this.velocity += force;
855 UpdateCSQCProjectile(this);
857 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
860 if(this.health == this.max_health)
862 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
863 this.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
864 this.think = nade_beep;
867 this.health -= damage;
869 if ( this.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
870 this.realowner = attacker;
873 W_PrepareExplosionByDamage(this, attacker, nade_boom);
875 nade_burn_spawn(this);
878 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
883 entity _nade = e.nade;
889 makevectors(e.v_angle);
891 W_SetupShot(e, false, false, SND_Null, CH_WEAPON_A, 0);
893 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
895 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
896 + (v_right * autocvar_g_nades_throw_offset.y)
897 + (v_up * autocvar_g_nades_throw_offset.z);
898 if(autocvar_g_nades_throw_offset == '0 0 0')
901 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
902 //setmodel(_nade, MDL_PROJECTILE_NADE);
903 //setattachment(_nade, world, "");
904 PROJECTILE_MAKETRIGGER(_nade);
905 if(STAT(NADES_SMALL, e))
906 setsize(_nade, '-8 -8 -8', '8 8 8');
908 setsize(_nade, '-16 -16 -16', '16 16 16');
909 _nade.movetype = MOVETYPE_BOUNCE;
911 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
912 if (trace_startsolid)
913 setorigin(_nade, e.origin);
915 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(self))
916 _nade.velocity = '0 0 100';
917 else if(autocvar_g_nades_nade_newton_style == 1)
918 _nade.velocity = e.velocity + _velocity;
919 else if(autocvar_g_nades_nade_newton_style == 2)
920 _nade.velocity = _velocity;
922 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
927 _nade.touch = nade_touch;
928 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
929 _nade.health = autocvar_g_nades_nade_health;
930 _nade.max_health = _nade.health;
931 _nade.takedamage = DAMAGE_AIM;
932 _nade.event_damage = nade_damage;
933 _nade.customizeentityforclient = func_null;
934 _nade.exteriormodeltoclient = world;
935 _nade.traileffectnum = 0;
936 _nade.teleportable = true;
937 _nade.pushable = true;
939 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
940 _nade.damagedbycontents = true;
941 _nade.angles = vectoangles(_nade.velocity);
942 _nade.flags = FL_PROJECTILE;
943 _nade.projectiledeathtype = DEATH_NADE.m_id;
944 _nade.toss_time = time;
945 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
947 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
948 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
950 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
956 _nade.think = nade_boom;
957 _nade.nextthink = _time;
960 e.nade_refire = time + autocvar_g_nades_nade_refire;
964 void nades_GiveBonus(entity player, float score)
966 if (autocvar_g_nades)
967 if (autocvar_g_nades_bonus)
968 if (IS_REAL_CLIENT(player))
969 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
970 if (STAT(FROZEN, player) == 0)
971 if (!IS_DEAD(player))
973 if ( player.bonus_nade_score < 1 )
974 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
976 if ( player.bonus_nade_score >= 1 )
978 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
979 play2(player, SND(KH_ALARM));
980 player.bonus_nades++;
981 player.bonus_nade_score -= 1;
986 /** Remove all bonus nades from a player */
987 void nades_RemoveBonus(entity player)
989 player.bonus_nades = player.bonus_nade_score = 0;
992 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
995 nades_RemoveBonus(self);
998 float nade_customize()
1000 //if(IS_SPEC(other)) { return false; }
1001 if(other == self.exteriormodeltoclient || (IS_SPEC(other) && other.enemy == self.exteriormodeltoclient))
1003 // somewhat hide the model, but keep the glow
1005 if(self.traileffectnum)
1006 self.traileffectnum = 0;
1011 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1012 if(!self.traileffectnum)
1013 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
1020 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1022 entity n = new(nade), fn = new(fake_nade);
1024 n.nade_type = bound(1, ntype, Nades_COUNT);
1025 n.pokenade_type = pntype;
1027 setmodel(n, MDL_PROJECTILE_NADE);
1028 //setattachment(n, player, "bip01 l hand");
1029 n.exteriormodeltoclient = player;
1030 n.customizeentityforclient = nade_customize;
1031 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
1032 n.colormod = Nades_from(n.nade_type).m_color;
1033 n.realowner = nowner;
1034 n.colormap = player.colormap;
1035 n.glowmod = player.glowmod;
1036 n.wait = time + max(0, ntime);
1037 n.nade_time_primed = time;
1038 n.think = nade_beep;
1039 n.nextthink = max(n.wait - 3, time);
1040 n.projectiledeathtype = DEATH_NADE.m_id;
1042 setmodel(fn, MDL_NADE_VIEW);
1043 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1044 setattachment(fn, player.(weaponentity), "");
1045 fn.realowner = fn.owner = player;
1046 fn.colormod = Nades_from(n.nade_type).m_color;
1047 fn.colormap = player.colormap;
1048 fn.glowmod = player.glowmod;
1049 fn.think = SUB_Remove_self;
1050 fn.nextthink = n.wait;
1053 player.fake_nade = fn;
1058 if(autocvar_g_nades_bonus_only)
1059 if(!self.bonus_nades)
1060 return; // only allow bonus nades
1066 remove(self.fake_nade);
1069 string pntype = self.pokenade_type;
1071 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
1072 ntype = self.nade_type;
1073 else if (self.bonus_nades >= 1)
1075 ntype = self.nade_type;
1076 pntype = self.pokenade_type;
1077 self.bonus_nades -= 1;
1081 ntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
1082 pntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1085 spawn_held_nade(self, self, autocvar_g_nades_nade_lifetime, ntype, pntype);
1088 bool CanThrowNade(entity this)
1099 if (!autocvar_g_nades)
1100 return false; // allow turning them off mid match
1102 if(forbidWeaponUse(this))
1105 if (!IS_PLAYER(this))
1111 .bool nade_altbutton;
1113 void nades_CheckThrow()
1115 if(!CanThrowNade(self))
1118 entity held_nade = self.nade;
1121 self.nade_altbutton = true;
1122 if(time > self.nade_refire)
1124 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1126 self.nade_refire = time + autocvar_g_nades_nade_refire;
1131 self.nade_altbutton = false;
1132 if (time >= held_nade.nade_time_primed + 1) {
1133 makevectors(self.v_angle);
1134 float _force = time - held_nade.nade_time_primed;
1135 _force /= autocvar_g_nades_nade_lifetime;
1136 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1137 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1138 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1139 toss_nade(self, true, dir * _force, 0);
1144 void nades_Clear(entity player)
1147 remove(player.nade);
1148 if(player.fake_nade)
1149 remove(player.fake_nade);
1151 player.nade = player.fake_nade = world;
1152 player.nade_timer = 0;
1155 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1158 toss_nade(vh_player, true, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1163 CLASS(NadeOffhand, OffhandWeapon)
1164 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1166 entity held_nade = player.nade;
1169 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1170 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1171 makevectors(player.angles);
1172 held_nade.velocity = player.velocity;
1173 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1174 held_nade.angles_y = player.angles.y;
1176 if (time + 0.1 >= held_nade.wait)
1177 toss_nade(player, false, '0 0 0', time + 0.05);
1180 if (!CanThrowNade(player)) return;
1181 if (!(time > player.nade_refire)) return;
1185 held_nade = player.nade;
1187 } else if (time >= held_nade.nade_time_primed + 1) {
1189 makevectors(player.v_angle);
1190 float _force = time - held_nade.nade_time_primed;
1191 _force /= autocvar_g_nades_nade_lifetime;
1192 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1193 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1194 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1195 toss_nade(player, false, dir * _force, 0);
1199 ENDCLASS(NadeOffhand)
1200 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1202 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1205 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1212 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1214 if (!IS_PLAYER(self)) { return false; }
1216 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1220 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1223 float key_count = 0;
1224 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1227 if(self.flagcarried || self.ballcarried) // this player is important
1228 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1230 time_score = autocvar_g_nades_bonus_score_time;
1233 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1235 if(autocvar_g_nades_bonus_client_select)
1237 self.nade_type = self.cvar_cl_nade_type;
1238 self.pokenade_type = self.cvar_cl_pokenade_type;
1242 self.nade_type = autocvar_g_nades_bonus_type;
1243 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1246 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1248 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1249 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1253 self.bonus_nades = self.bonus_nade_score = 0;
1259 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1263 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1265 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
1267 if(STAT(FROZEN, it) == 0)
1268 if(SAME_TEAM(it, self))
1269 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
1273 if(STAT(FROZEN, self) == 1)
1280 if(n && STAT(FROZEN, self) == 3) // OK, there is at least one teammate reviving us
1282 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1283 self.health = max(1, self.revive_progress * start_health);
1285 if(self.revive_progress >= 1)
1289 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1290 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1293 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1294 other.revive_progress = self.revive_progress;
1295 other.reviving = false;
1302 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics)
1304 if (STAT(ENTRAP_ORB, this) > time)
1306 this.stat_sv_maxspeed *= autocvar_g_nades_entrap_speed;
1307 this.stat_sv_airspeedlimit_nonqw *= autocvar_g_nades_entrap_speed;
1312 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1314 if(autocvar_g_nades_spawn)
1315 self.nade_refire = time + autocvar_g_spawnshieldtime;
1317 self.nade_refire = time + autocvar_g_nades_nade_refire;
1319 if(autocvar_g_nades_bonus_client_select)
1320 self.nade_type = self.cvar_cl_nade_type;
1322 self.nade_timer = 0;
1324 if (!self.offhand) self.offhand = OFFHAND_NADE;
1326 if(self.nade_spawnloc)
1328 setorigin(self, self.nade_spawnloc.origin);
1329 self.nade_spawnloc.cnt -= 1;
1331 if(self.nade_spawnloc.cnt <= 0)
1333 remove(self.nade_spawnloc);
1334 self.nade_spawnloc = world;
1341 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1343 if(frag_target.nade)
1344 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1345 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1347 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);
1349 if(IS_PLAYER(frag_attacker))
1351 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1352 nades_RemoveBonus(frag_attacker);
1353 else if(frag_target.flagcarried)
1354 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1355 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1357 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1358 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1359 switch(frag_attacker.killcount)
1362 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1367 nades_GiveBonus(frag_attacker, killcount_bonus);
1370 nades_RemoveBonus(frag_target);
1375 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1377 if(STAT(FROZEN, frag_target))
1378 if(autocvar_g_freezetag_revive_nade)
1379 if(frag_attacker == frag_target)
1380 if(frag_deathtype == DEATH_NADE.m_id)
1381 if(time - frag_inflictor.toss_time <= 0.1)
1383 Unfreeze(frag_target);
1384 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1385 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1387 frag_force = '0 0 0';
1388 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1389 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1395 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1397 if(IS_PLAYER(frag_attacker))
1398 if(DIFF_TEAM(frag_attacker, frag_target))
1399 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1400 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1405 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1407 if(frag_target.nade)
1408 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1413 bool nades_RemovePlayer()
1416 nades_RemoveBonus(self);
1420 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1421 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1422 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1424 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1426 self.nade_timer = other.nade_timer;
1427 self.nade_type = other.nade_type;
1428 self.pokenade_type = other.pokenade_type;
1429 self.bonus_nades = other.bonus_nades;
1430 self.bonus_nade_score = other.bonus_nade_score;
1431 self.stat_healing_orb = other.stat_healing_orb;
1432 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1433 STAT(ENTRAP_ORB, this) = STAT(ENTRAP_ORB, other);
1434 STAT(ENTRAP_ORB_ALPHA, this) = STAT(ENTRAP_ORB_ALPHA, other);
1438 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
1439 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
1441 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1443 ret_string = strcat(ret_string, ":Nades");
1447 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1449 ret_string = strcat(ret_string, ", Nades");
1453 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1455 ret_string = strcat(ret_string, "\n\n^3nades^8 are enabled, press 'g' to use them\n");