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) return false;
42 M_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
43 M_ARGV(1, float) = STAT(HEALING_ORB_ALPHA);
46 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
49 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
52 self.traileffect = EFFECT_FIREBALL.m_id;
55 if (Nade_FromProjectile(self.cnt) != NADE_TYPE_Null)
57 setmodel(self, MDL_PROJECTILE_NADE);
58 entity trail = Nade_TrailEffect(self.cnt, self.team);
59 if (trail.eent_eff_name) self.traileffect = trail.m_id;
63 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
66 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
68 loopsound(self, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
69 self.mins = '-16 -16 -16';
70 self.maxs = '16 16 16';
73 entity nade_type = Nade_FromProjectile(self.cnt);
74 if (nade_type == NADE_TYPE_Null) return;
75 if(STAT(NADES_SMALL, NULL))
77 self.mins = '-8 -8 -8';
82 self.mins = '-16 -16 -16';
83 self.maxs = '16 16 16';
85 self.colormod = nade_type.m_color;
86 self.move_movetype = MOVETYPE_BOUNCE;
87 settouch(self, func_null);
89 self.avelocity = randomvec() * 720;
91 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
92 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
94 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
96 bool Projectile_isnade(int p)
98 return Nade_FromProjectile(p) != NADE_TYPE_Null;
100 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
102 float bonusNades = STAT(NADE_BONUS);
103 float bonusProgress = STAT(NADE_BONUS_SCORE);
104 float bonusType = STAT(NADE_BONUS_TYPE);
105 Nade def = Nades_from(bonusType);
106 vector nadeColor = def.m_color;
107 string nadeIcon = def.m_icon;
109 vector iconPos, textPos;
111 if(autocvar_hud_panel_ammo_iconalign)
113 iconPos = myPos + eX * 2 * mySize.y;
119 textPos = myPos + eX * mySize.y;
122 if(bonusNades > 0 || bonusProgress > 0)
124 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
126 if(autocvar_hud_panel_ammo_text)
127 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
130 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
132 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
139 #include <common/gamemodes/all.qh>
140 #include <common/monsters/spawn.qh>
141 #include <common/monsters/sv_monsters.qh>
142 #include <server/g_subs.qh>
144 REGISTER_MUTATOR(nades, cvar("g_nades"));
146 .float nade_time_primed;
148 .entity nade_spawnloc;
150 void nade_timer_think(entity this)
152 this.skin = 8 - (this.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
153 this.nextthink = time;
154 if(!this.owner || wasfreed(this.owner))
158 void nade_burn_spawn(entity _nade)
160 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
163 void nade_spawn(entity _nade)
165 entity timer = new(nade_timer);
166 setmodel(timer, MDL_NADE_TIMER);
167 setattachment(timer, _nade, "");
168 timer.colormap = _nade.colormap;
169 timer.glowmod = _nade.glowmod;
170 setthink(timer, nade_timer_think);
171 timer.nextthink = time;
172 timer.wait = _nade.wait;
176 _nade.effects |= EF_LOWPRECISION;
178 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
181 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
190 RandomSelection_Init();
191 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
192 if(e.takedamage == DAMAGE_AIM)
193 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
194 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
198 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
199 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
200 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
201 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
204 e.fireball_impactvec = p;
205 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
208 if(RandomSelection_chosen_ent)
210 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
211 d = damage + (edgedamage - damage) * (d / dist);
212 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
213 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
214 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
219 void napalm_ball_think(entity this)
221 if(round_handler_IsActive())
222 if(!round_handler_IsRoundStarted())
228 if(time > this.pushltime)
234 vector midpoint = ((this.absmin + this.absmax) * 0.5);
235 if(pointcontents(midpoint) == CONTENT_WATER)
237 this.velocity = this.velocity * 0.5;
239 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
240 { this.velocity_z = 200; }
243 this.angles = vectoangles(this.velocity);
245 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
246 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
248 this.nextthink = time + 0.1;
252 void nade_napalm_ball(entity this)
257 spamsound(this, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
260 proj.owner = this.owner;
261 proj.realowner = this.realowner;
262 proj.team = this.owner.team;
263 proj.bot_dodge = true;
264 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
265 proj.movetype = MOVETYPE_BOUNCE;
266 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
267 PROJECTILE_MAKETRIGGER(proj);
268 setmodel(proj, MDL_Null);
269 proj.scale = 1;//0.5;
270 setsize(proj, '-4 -4 -4', '4 4 4');
271 setorigin(proj, this.origin);
272 setthink(proj, napalm_ball_think);
273 proj.nextthink = time;
274 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
275 proj.effects = EF_LOWPRECISION | EF_FLAME;
277 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
278 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
279 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
280 proj.velocity = kick;
282 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
284 proj.angles = vectoangles(proj.velocity);
285 proj.flags = FL_PROJECTILE;
286 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
288 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
292 void napalm_fountain_think(entity this)
295 if(round_handler_IsActive())
296 if(!round_handler_IsRoundStarted())
302 if(time >= this.ltime)
308 vector midpoint = ((this.absmin + this.absmax) * 0.5);
309 if(pointcontents(midpoint) == CONTENT_WATER)
311 this.velocity = this.velocity * 0.5;
313 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
314 { this.velocity_z = 200; }
316 UpdateCSQCProjectile(this);
319 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
320 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
322 this.nextthink = time + 0.1;
323 if(time >= this.nade_special_time)
325 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
326 nade_napalm_ball(this);
330 void nade_napalm_boom(entity this)
334 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
335 nade_napalm_ball(this);
339 fountain.owner = self.owner;
340 fountain.realowner = self.realowner;
341 fountain.origin = self.origin;
342 setorigin(fountain, fountain.origin);
343 setthink(fountain, napalm_fountain_think);
344 fountain.nextthink = time;
345 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
346 fountain.pushltime = fountain.ltime;
347 fountain.team = self.team;
348 fountain.movetype = MOVETYPE_TOSS;
349 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
350 fountain.bot_dodge = true;
351 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
352 fountain.nade_special_time = time;
353 setsize(fountain, '-16 -16 -16', '16 16 16');
354 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
357 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
359 frost_target.frozen_by = freezefield.realowner;
360 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
361 Freeze(frost_target, 1/freeze_time, 3, false);
363 Drop_Special_Items(frost_target);
366 void nade_ice_think(entity this)
369 if(round_handler_IsActive())
370 if(!round_handler_IsRoundStarted())
376 if(time >= self.ltime)
378 if ( autocvar_g_nades_ice_explode )
380 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
381 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
382 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
384 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
385 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
386 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
387 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
394 self.nextthink = time+0.1;
399 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
401 randomw = random()*M_PI*2;
403 randomp.x = randomr*cos(randomw);
404 randomp.y = randomr*sin(randomw);
406 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
408 if(time >= self.nade_special_time)
410 self.nade_special_time = time+0.7;
412 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
413 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
417 float current_freeze_time = self.ltime - time - 0.1;
420 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
422 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
423 if(e.takedamage && !IS_DEAD(e))
425 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
427 if(current_freeze_time > 0)
428 nade_ice_freeze(self, e, current_freeze_time);
431 void nade_ice_boom(entity this)
435 fountain.owner = this.owner;
436 fountain.realowner = this.realowner;
437 fountain.origin = this.origin;
438 setorigin(fountain, fountain.origin);
439 setthink(fountain, nade_ice_think);
440 fountain.nextthink = time;
441 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
442 fountain.pushltime = fountain.wait = fountain.ltime;
443 fountain.team = this.team;
444 fountain.movetype = MOVETYPE_TOSS;
445 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
446 fountain.bot_dodge = false;
447 setsize(fountain, '-16 -16 -16', '16 16 16');
448 fountain.nade_special_time = time+0.3;
449 fountain.angles = this.angles;
451 if ( autocvar_g_nades_ice_explode )
453 setmodel(fountain, MDL_PROJECTILE_GRENADE);
454 entity timer = new(nade_timer);
455 setmodel(timer, MDL_NADE_TIMER);
456 setattachment(timer, fountain, "");
457 timer.colormap = this.colormap;
458 timer.glowmod = this.glowmod;
459 setthink(timer, nade_timer_think);
460 timer.nextthink = time;
461 timer.wait = fountain.ltime;
462 timer.owner = fountain;
466 setmodel(fountain, MDL_Null);
469 void nade_translocate_boom(entity this)
471 if(this.realowner.vehicle)
474 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
475 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
476 locout = trace_endpos;
478 makevectors(this.realowner.angles);
480 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
482 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
485 void nade_spawn_boom(entity this)
487 entity spawnloc = spawn();
488 setorigin(spawnloc, this.origin);
489 setsize(spawnloc, this.realowner.mins, this.realowner.maxs);
490 spawnloc.movetype = MOVETYPE_NONE;
491 spawnloc.solid = SOLID_NOT;
492 spawnloc.drawonlytoclient = this.realowner;
493 spawnloc.effects = EF_STARDUST;
494 spawnloc.cnt = autocvar_g_nades_spawn_count;
496 if(this.realowner.nade_spawnloc)
498 remove(this.realowner.nade_spawnloc);
499 this.realowner.nade_spawnloc = world;
502 this.realowner.nade_spawnloc = spawnloc;
505 void nade_heal_think(entity this)
507 if(time >= self.ltime)
513 self.nextthink = time;
515 if(time >= self.nade_special_time)
517 self.nade_special_time = time+0.25;
518 self.nade_show_particles = 1;
521 self.nade_show_particles = 0;
524 void nade_heal_touch(entity this)
528 if(IS_PLAYER(other) || IS_MONSTER(other))
530 if(!STAT(FROZEN, other))
532 health_factor = autocvar_g_nades_heal_rate*frametime/2;
533 if ( other != self.realowner )
535 if ( SAME_TEAM(other,self) )
536 health_factor *= autocvar_g_nades_heal_friend;
538 health_factor *= autocvar_g_nades_heal_foe;
540 if ( health_factor > 0 )
542 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
543 if ( other.health < maxhealth )
545 if ( self.nade_show_particles )
546 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
547 other.health = min(other.health+health_factor, maxhealth);
549 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
551 else if ( health_factor < 0 )
553 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
558 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
560 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
561 show_red.stat_healing_orb = time+0.1;
562 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
566 void nade_heal_boom(entity this)
570 healer.owner = this.owner;
571 healer.realowner = this.realowner;
572 setorigin(healer, this.origin);
573 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
574 healer.ltime = time + healer.healer_lifetime;
575 healer.team = this.realowner.team;
576 healer.bot_dodge = false;
577 healer.solid = SOLID_TRIGGER;
578 settouch(healer, nade_heal_touch);
580 setmodel(healer, MDL_NADE_HEAL);
581 healer.healer_radius = autocvar_g_nades_nade_radius;
582 vector size = '1 1 1' * healer.healer_radius / 2;
583 setsize(healer,-size,size);
585 Net_LinkEntity(healer, true, 0, healer_send);
587 setthink(healer, nade_heal_think);
588 healer.nextthink = time;
589 healer.SendFlags |= 1;
592 void nade_monster_boom(entity this)
594 entity e = spawnmonster(this.pokenade_type, 0, this.realowner, this.realowner, this.origin, false, false, 1);
596 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
597 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
598 e.monster_skill = MONSTER_SKILL_INSANE;
601 void nade_boom(entity this)
604 bool nade_blast = true;
606 switch ( Nades_from(this.nade_type) )
608 case NADE_TYPE_NAPALM:
609 nade_blast = autocvar_g_nades_napalm_blast;
610 expef = EFFECT_EXPLOSION_MEDIUM;
614 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
616 case NADE_TYPE_TRANSLOCATE:
619 case NADE_TYPE_MONSTER:
620 case NADE_TYPE_SPAWN:
622 switch(this.realowner.team)
624 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
625 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
626 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
627 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
628 default: expef = EFFECT_SPAWN_NEUTRAL; break;
633 expef = EFFECT_SPAWN_RED;
637 case NADE_TYPE_NORMAL:
638 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
643 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
645 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
646 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
648 this.event_damage = func_null; // prevent somehow calling damage in the next call
652 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
653 autocvar_g_nades_nade_radius, this, world, autocvar_g_nades_nade_force, this.projectiledeathtype, this.enemy);
654 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
658 switch ( Nades_from(this.nade_type) )
660 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
661 case NADE_TYPE_ICE: nade_ice_boom(this); break;
662 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
663 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
664 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
665 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
668 FOREACH_ENTITY_ENT(aiment, this,
670 if(it.classname == "grapplinghook")
671 RemoveGrapplingHook(it.realowner);
677 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
678 void nade_pickup(entity this, entity thenade)
680 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, thenade.nade_type, thenade.pokenade_type);
682 // set refire so player can't even
683 this.nade_refire = time + autocvar_g_nades_nade_refire;
687 this.nade.nade_time_primed = thenade.nade_time_primed;
690 bool CanThrowNade(entity this);
691 void nade_touch(entity this)
694 UpdateCSQCProjectile(self);
696 if(other == self.realowner)
697 return; // no self impacts
699 if(autocvar_g_nades_pickup)
700 if(time >= self.spawnshieldtime)
701 if(!other.nade && self.health == self.max_health) // no boosted shot pickups, thank you very much
703 if(CanThrowNade(other)) // prevent some obvious things, like dead players
704 if(IS_REAL_CLIENT(other)) // above checks for IS_PLAYER, don't need to do it here
706 nade_pickup(other, self);
707 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
711 /*float is_weapclip = 0;
712 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
713 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
714 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
716 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
718 FOREACH_ENTITY_ENT(aiment, self,
720 if(it.classname == "grapplinghook")
721 RemoveGrapplingHook(it.realowner);
727 PROJECTILE_TOUCH(this);
729 //setsize(self, '-2 -2 -2', '2 2 2');
730 //UpdateCSQCProjectile(self);
731 if(self.health == self.max_health)
733 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
741 void nade_beep(entity this)
743 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
744 setthink(this, nade_boom);
745 this.nextthink = max(this.wait, time);
748 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
750 if(ITEM_DAMAGE_NEEDKILL(deathtype))
752 this.takedamage = DAMAGE_NO;
753 WITHSELF(this, nade_boom(this));
757 if(this.nade_type == NADE_TYPE_TRANSLOCATE.m_id || this.nade_type == NADE_TYPE_SPAWN.m_id)
760 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
761 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
766 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
768 force *= 0.5; // too much
771 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
774 damage = this.max_health * 0.55;
776 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
777 damage = this.max_health * 0.1;
778 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
780 if(deathtype & HITTYPE_SECONDARY)
782 damage = this.max_health * 0.1;
786 damage = this.max_health * 1.15;
789 this.velocity += force;
790 UpdateCSQCProjectile(this);
792 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
795 if(this.health == this.max_health)
797 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
798 this.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
799 setthink(this, nade_beep);
802 this.health -= damage;
804 if ( this.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
805 this.realowner = attacker;
808 W_PrepareExplosionByDamage(this, attacker, nade_boom);
810 nade_burn_spawn(this);
813 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
818 entity _nade = e.nade;
824 makevectors(e.v_angle);
826 W_SetupShot(e, false, false, SND_Null, CH_WEAPON_A, 0);
828 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
830 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
831 + (v_right * autocvar_g_nades_throw_offset.y)
832 + (v_up * autocvar_g_nades_throw_offset.z);
833 if(autocvar_g_nades_throw_offset == '0 0 0')
836 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
837 //setmodel(_nade, MDL_PROJECTILE_NADE);
838 //setattachment(_nade, world, "");
839 PROJECTILE_MAKETRIGGER(_nade);
840 if(STAT(NADES_SMALL, e))
841 setsize(_nade, '-8 -8 -8', '8 8 8');
843 setsize(_nade, '-16 -16 -16', '16 16 16');
844 _nade.movetype = MOVETYPE_BOUNCE;
846 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
847 if (trace_startsolid)
848 setorigin(_nade, e.origin);
850 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(self))
851 _nade.velocity = '0 0 100';
852 else if(autocvar_g_nades_nade_newton_style == 1)
853 _nade.velocity = e.velocity + _velocity;
854 else if(autocvar_g_nades_nade_newton_style == 2)
855 _nade.velocity = _velocity;
857 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
862 settouch(_nade, nade_touch);
863 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
864 _nade.health = autocvar_g_nades_nade_health;
865 _nade.max_health = _nade.health;
866 _nade.takedamage = DAMAGE_AIM;
867 _nade.event_damage = nade_damage;
868 setcefc(_nade, func_null);
869 _nade.exteriormodeltoclient = world;
870 _nade.traileffectnum = 0;
871 _nade.teleportable = true;
872 _nade.pushable = true;
874 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
875 _nade.damagedbycontents = true;
876 _nade.angles = vectoangles(_nade.velocity);
877 _nade.flags = FL_PROJECTILE;
878 _nade.projectiledeathtype = DEATH_NADE.m_id;
879 _nade.toss_time = time;
880 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
882 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
883 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
885 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
891 setthink(_nade, nade_boom);
892 _nade.nextthink = _time;
895 e.nade_refire = time + autocvar_g_nades_nade_refire;
899 void nades_GiveBonus(entity player, float score)
901 if (autocvar_g_nades)
902 if (autocvar_g_nades_bonus)
903 if (IS_REAL_CLIENT(player))
904 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
905 if (STAT(FROZEN, player) == 0)
906 if (!IS_DEAD(player))
908 if ( player.bonus_nade_score < 1 )
909 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
911 if ( player.bonus_nade_score >= 1 )
913 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
914 play2(player, SND(KH_ALARM));
915 player.bonus_nades++;
916 player.bonus_nade_score -= 1;
921 /** Remove all bonus nades from a player */
922 void nades_RemoveBonus(entity player)
924 player.bonus_nades = player.bonus_nade_score = 0;
927 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
930 nades_RemoveBonus(self);
933 float nade_customize(entity this)
935 //if(IS_SPEC(other)) { return false; }
936 if(other == self.exteriormodeltoclient || (IS_SPEC(other) && other.enemy == self.exteriormodeltoclient))
938 // somewhat hide the model, but keep the glow
940 if(self.traileffectnum)
941 self.traileffectnum = 0;
946 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
947 if(!self.traileffectnum)
948 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
955 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
957 entity n = new(nade), fn = new(fake_nade);
959 n.nade_type = bound(1, ntype, Nades_COUNT);
960 n.pokenade_type = pntype;
962 setmodel(n, MDL_PROJECTILE_NADE);
963 //setattachment(n, player, "bip01 l hand");
964 n.exteriormodeltoclient = player;
965 setcefc(n, nade_customize);
966 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
967 n.colormod = Nades_from(n.nade_type).m_color;
968 n.realowner = nowner;
969 n.colormap = player.colormap;
970 n.glowmod = player.glowmod;
971 n.wait = time + max(0, ntime);
972 n.nade_time_primed = time;
973 setthink(n, nade_beep);
974 n.nextthink = max(n.wait - 3, time);
975 n.projectiledeathtype = DEATH_NADE.m_id;
977 setmodel(fn, MDL_NADE_VIEW);
978 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
979 setattachment(fn, player.(weaponentity), "");
980 fn.realowner = fn.owner = player;
981 fn.colormod = Nades_from(n.nade_type).m_color;
982 fn.colormap = player.colormap;
983 fn.glowmod = player.glowmod;
984 setthink(fn, SUB_Remove);
985 fn.nextthink = n.wait;
988 player.fake_nade = fn;
993 if(autocvar_g_nades_bonus_only)
994 if(!self.bonus_nades)
995 return; // only allow bonus nades
1001 remove(self.fake_nade);
1004 string pntype = self.pokenade_type;
1006 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
1007 ntype = self.nade_type;
1008 else if (self.bonus_nades >= 1)
1010 ntype = self.nade_type;
1011 pntype = self.pokenade_type;
1012 self.bonus_nades -= 1;
1016 ntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
1017 pntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1020 spawn_held_nade(self, self, autocvar_g_nades_nade_lifetime, ntype, pntype);
1023 bool CanThrowNade(entity this)
1034 if (!autocvar_g_nades)
1035 return false; // allow turning them off mid match
1037 if(forbidWeaponUse(this))
1040 if (!IS_PLAYER(this))
1046 .bool nade_altbutton;
1048 void nades_CheckThrow()
1050 if(!CanThrowNade(self))
1053 entity held_nade = self.nade;
1056 self.nade_altbutton = true;
1057 if(time > self.nade_refire)
1059 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1061 self.nade_refire = time + autocvar_g_nades_nade_refire;
1066 self.nade_altbutton = false;
1067 if (time >= held_nade.nade_time_primed + 1) {
1068 makevectors(self.v_angle);
1069 float _force = time - held_nade.nade_time_primed;
1070 _force /= autocvar_g_nades_nade_lifetime;
1071 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1072 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1073 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1074 toss_nade(self, true, dir * _force, 0);
1079 void nades_Clear(entity player)
1082 remove(player.nade);
1083 if(player.fake_nade)
1084 remove(player.fake_nade);
1086 player.nade = player.fake_nade = world;
1087 player.nade_timer = 0;
1090 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1093 toss_nade(vh_player, true, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1098 CLASS(NadeOffhand, OffhandWeapon)
1099 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1101 entity held_nade = player.nade;
1104 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1105 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1106 makevectors(player.angles);
1107 held_nade.velocity = player.velocity;
1108 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1109 held_nade.angles_y = player.angles.y;
1111 if (time + 0.1 >= held_nade.wait)
1112 toss_nade(player, false, '0 0 0', time + 0.05);
1115 if (!CanThrowNade(player)) return;
1116 if (!(time > player.nade_refire)) return;
1120 held_nade = player.nade;
1122 } else if (time >= held_nade.nade_time_primed + 1) {
1124 makevectors(player.v_angle);
1125 float _force = time - held_nade.nade_time_primed;
1126 _force /= autocvar_g_nades_nade_lifetime;
1127 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1128 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1129 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1130 toss_nade(player, false, dir * _force, 0);
1134 ENDCLASS(NadeOffhand)
1135 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1137 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1140 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1147 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1149 if (!IS_PLAYER(self)) { return false; }
1151 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1155 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1158 float key_count = 0;
1159 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1162 if(self.flagcarried || self.ballcarried) // this player is important
1163 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1165 time_score = autocvar_g_nades_bonus_score_time;
1168 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1170 if(autocvar_g_nades_bonus_client_select)
1172 self.nade_type = self.cvar_cl_nade_type;
1173 self.pokenade_type = self.cvar_cl_pokenade_type;
1177 self.nade_type = autocvar_g_nades_bonus_type;
1178 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1181 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1183 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1184 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1188 self.bonus_nades = self.bonus_nade_score = 0;
1194 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1198 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1200 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
1202 if(STAT(FROZEN, it) == 0)
1203 if(SAME_TEAM(it, self))
1204 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
1208 if(STAT(FROZEN, self) == 1)
1215 if(n && STAT(FROZEN, self) == 3) // OK, there is at least one teammate reviving us
1217 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1218 self.health = max(1, self.revive_progress * start_health);
1220 if(self.revive_progress >= 1)
1224 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1225 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1228 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1229 other.revive_progress = self.revive_progress;
1230 other.reviving = false;
1237 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1239 if(autocvar_g_nades_spawn)
1240 self.nade_refire = time + autocvar_g_spawnshieldtime;
1242 self.nade_refire = time + autocvar_g_nades_nade_refire;
1244 if(autocvar_g_nades_bonus_client_select)
1245 self.nade_type = self.cvar_cl_nade_type;
1247 self.nade_timer = 0;
1249 if (!self.offhand) self.offhand = OFFHAND_NADE;
1251 if(self.nade_spawnloc)
1253 setorigin(self, self.nade_spawnloc.origin);
1254 self.nade_spawnloc.cnt -= 1;
1256 if(self.nade_spawnloc.cnt <= 0)
1258 remove(self.nade_spawnloc);
1259 self.nade_spawnloc = world;
1266 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1268 if(frag_target.nade)
1269 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1270 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1272 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);
1274 if(IS_PLAYER(frag_attacker))
1276 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1277 nades_RemoveBonus(frag_attacker);
1278 else if(frag_target.flagcarried)
1279 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1280 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1282 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1283 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1284 switch(frag_attacker.killcount)
1287 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1292 nades_GiveBonus(frag_attacker, killcount_bonus);
1295 nades_RemoveBonus(frag_target);
1300 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1302 if(STAT(FROZEN, frag_target))
1303 if(autocvar_g_freezetag_revive_nade)
1304 if(frag_attacker == frag_target)
1305 if(frag_deathtype == DEATH_NADE.m_id)
1306 if(time - frag_inflictor.toss_time <= 0.1)
1308 Unfreeze(frag_target);
1309 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1310 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1312 frag_force = '0 0 0';
1313 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1314 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1320 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1322 if(IS_PLAYER(frag_attacker))
1323 if(DIFF_TEAM(frag_attacker, frag_target))
1324 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1325 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1330 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1332 if(frag_target.nade)
1333 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1338 bool nades_RemovePlayer()
1341 nades_RemoveBonus(self);
1345 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1346 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1347 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1349 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1351 self.nade_timer = other.nade_timer;
1352 self.nade_type = other.nade_type;
1353 self.pokenade_type = other.pokenade_type;
1354 self.bonus_nades = other.bonus_nades;
1355 self.bonus_nade_score = other.bonus_nade_score;
1356 self.stat_healing_orb = other.stat_healing_orb;
1357 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1361 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
1362 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
1364 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1366 ret_string = strcat(ret_string, ":Nades");
1370 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1372 ret_string = strcat(ret_string, ", Nades");
1376 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1378 ret_string = strcat(ret_string, "\n\n^3nades^8 are enabled, press 'g' to use them\n");