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)
48 entity proj = M_ARGV(0, entity);
50 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
53 proj.traileffect = EFFECT_FIREBALL.m_id;
56 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
58 setmodel(proj, MDL_PROJECTILE_NADE);
59 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
60 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
64 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
66 entity proj = M_ARGV(0, entity);
68 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
70 loopsound(proj, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
71 proj.mins = '-16 -16 -16';
72 proj.maxs = '16 16 16';
75 entity nade_type = Nade_FromProjectile(proj.cnt);
76 if (nade_type == NADE_TYPE_Null) return;
77 if(STAT(NADES_SMALL, NULL))
79 proj.mins = '-8 -8 -8';
84 proj.mins = '-16 -16 -16';
85 proj.maxs = '16 16 16';
87 proj.colormod = nade_type.m_color;
88 proj.move_movetype = MOVETYPE_BOUNCE;
89 settouch(proj, func_null);
91 proj.avelocity = randomvec() * 720;
93 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
94 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
96 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
98 bool Projectile_isnade(int p)
100 return Nade_FromProjectile(p) != NADE_TYPE_Null;
102 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
104 float bonusNades = STAT(NADE_BONUS);
105 float bonusProgress = STAT(NADE_BONUS_SCORE);
106 float bonusType = STAT(NADE_BONUS_TYPE);
107 Nade def = Nades_from(bonusType);
108 vector nadeColor = def.m_color;
109 string nadeIcon = def.m_icon;
111 vector iconPos, textPos;
113 if(autocvar_hud_panel_ammo_iconalign)
115 iconPos = myPos + eX * 2 * mySize.y;
121 textPos = myPos + eX * mySize.y;
124 if(bonusNades > 0 || bonusProgress > 0)
126 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
128 if(autocvar_hud_panel_ammo_text)
129 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
132 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
134 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
141 #include <common/gamemodes/all.qh>
142 #include <common/monsters/spawn.qh>
143 #include <common/monsters/sv_monsters.qh>
144 #include <server/g_subs.qh>
146 REGISTER_MUTATOR(nades, cvar("g_nades"));
148 .float nade_time_primed;
150 .entity nade_spawnloc;
152 void nade_timer_think(entity this)
154 this.skin = 8 - (this.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
155 this.nextthink = time;
156 if(!this.owner || wasfreed(this.owner))
160 void nade_burn_spawn(entity _nade)
162 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
165 void nade_spawn(entity _nade)
167 entity timer = new(nade_timer);
168 setmodel(timer, MDL_NADE_TIMER);
169 setattachment(timer, _nade, "");
170 timer.colormap = _nade.colormap;
171 timer.glowmod = _nade.glowmod;
172 setthink(timer, nade_timer_think);
173 timer.nextthink = time;
174 timer.wait = _nade.wait;
178 _nade.effects |= EF_LOWPRECISION;
180 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
183 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
192 RandomSelection_Init();
193 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
194 if(e.takedamage == DAMAGE_AIM)
195 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
196 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
200 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
201 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
202 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
203 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
206 e.fireball_impactvec = p;
207 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
210 if(RandomSelection_chosen_ent)
212 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
213 d = damage + (edgedamage - damage) * (d / dist);
214 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
215 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
216 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
221 void napalm_ball_think(entity this)
223 if(round_handler_IsActive())
224 if(!round_handler_IsRoundStarted())
230 if(time > this.pushltime)
236 vector midpoint = ((this.absmin + this.absmax) * 0.5);
237 if(pointcontents(midpoint) == CONTENT_WATER)
239 this.velocity = this.velocity * 0.5;
241 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
242 { this.velocity_z = 200; }
245 this.angles = vectoangles(this.velocity);
247 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
248 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
250 this.nextthink = time + 0.1;
254 void nade_napalm_ball(entity this)
259 spamsound(this, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
262 proj.owner = this.owner;
263 proj.realowner = this.realowner;
264 proj.team = this.owner.team;
265 proj.bot_dodge = true;
266 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
267 proj.movetype = MOVETYPE_BOUNCE;
268 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
269 PROJECTILE_MAKETRIGGER(proj);
270 setmodel(proj, MDL_Null);
271 proj.scale = 1;//0.5;
272 setsize(proj, '-4 -4 -4', '4 4 4');
273 setorigin(proj, this.origin);
274 setthink(proj, napalm_ball_think);
275 proj.nextthink = time;
276 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
277 proj.effects = EF_LOWPRECISION | EF_FLAME;
279 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
280 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
281 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
282 proj.velocity = kick;
284 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
286 proj.angles = vectoangles(proj.velocity);
287 proj.flags = FL_PROJECTILE;
288 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
290 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
294 void napalm_fountain_think(entity this)
297 if(round_handler_IsActive())
298 if(!round_handler_IsRoundStarted())
304 if(time >= this.ltime)
310 vector midpoint = ((this.absmin + this.absmax) * 0.5);
311 if(pointcontents(midpoint) == CONTENT_WATER)
313 this.velocity = this.velocity * 0.5;
315 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
316 { this.velocity_z = 200; }
318 UpdateCSQCProjectile(this);
321 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
322 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
324 this.nextthink = time + 0.1;
325 if(time >= this.nade_special_time)
327 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
328 nade_napalm_ball(this);
332 void nade_napalm_boom(entity this)
336 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
337 nade_napalm_ball(this);
341 fountain.owner = this.owner;
342 fountain.realowner = this.realowner;
343 fountain.origin = this.origin;
344 setorigin(fountain, fountain.origin);
345 setthink(fountain, napalm_fountain_think);
346 fountain.nextthink = time;
347 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
348 fountain.pushltime = fountain.ltime;
349 fountain.team = this.team;
350 fountain.movetype = MOVETYPE_TOSS;
351 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
352 fountain.bot_dodge = true;
353 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
354 fountain.nade_special_time = time;
355 setsize(fountain, '-16 -16 -16', '16 16 16');
356 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
359 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
361 frost_target.frozen_by = freezefield.realowner;
362 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
363 Freeze(frost_target, 1/freeze_time, 3, false);
365 Drop_Special_Items(frost_target);
368 void nade_ice_think(entity this)
370 if(round_handler_IsActive())
371 if(!round_handler_IsRoundStarted())
377 if(time >= this.ltime)
379 if ( autocvar_g_nades_ice_explode )
381 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
382 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
383 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
385 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
386 autocvar_g_nades_nade_radius, this, world, autocvar_g_nades_nade_force, this.projectiledeathtype, this.enemy);
387 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
388 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
395 this.nextthink = time+0.1;
400 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
402 randomw = random()*M_PI*2;
404 randomp.x = randomr*cos(randomw);
405 randomp.y = randomr*sin(randomw);
407 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
409 if(time >= this.nade_special_time)
411 this.nade_special_time = time+0.7;
413 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
414 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
418 float current_freeze_time = this.ltime - time - 0.1;
421 for(e = findradius(this.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
423 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, this.realowner) || e == this.realowner))
424 if(e.takedamage && !IS_DEAD(e))
426 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
428 if(current_freeze_time > 0)
429 nade_ice_freeze(this, e, current_freeze_time);
432 void nade_ice_boom(entity this)
436 fountain.owner = this.owner;
437 fountain.realowner = this.realowner;
438 fountain.origin = this.origin;
439 setorigin(fountain, fountain.origin);
440 setthink(fountain, nade_ice_think);
441 fountain.nextthink = time;
442 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
443 fountain.pushltime = fountain.wait = fountain.ltime;
444 fountain.team = this.team;
445 fountain.movetype = MOVETYPE_TOSS;
446 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
447 fountain.bot_dodge = false;
448 setsize(fountain, '-16 -16 -16', '16 16 16');
449 fountain.nade_special_time = time+0.3;
450 fountain.angles = this.angles;
452 if ( autocvar_g_nades_ice_explode )
454 setmodel(fountain, MDL_PROJECTILE_GRENADE);
455 entity timer = new(nade_timer);
456 setmodel(timer, MDL_NADE_TIMER);
457 setattachment(timer, fountain, "");
458 timer.colormap = this.colormap;
459 timer.glowmod = this.glowmod;
460 setthink(timer, nade_timer_think);
461 timer.nextthink = time;
462 timer.wait = fountain.ltime;
463 timer.owner = fountain;
467 setmodel(fountain, MDL_Null);
470 void nade_translocate_boom(entity this)
472 if(this.realowner.vehicle)
475 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
476 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
477 locout = trace_endpos;
479 makevectors(this.realowner.angles);
481 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
483 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
486 void nade_spawn_boom(entity this)
488 entity spawnloc = spawn();
489 setorigin(spawnloc, this.origin);
490 setsize(spawnloc, this.realowner.mins, this.realowner.maxs);
491 spawnloc.movetype = MOVETYPE_NONE;
492 spawnloc.solid = SOLID_NOT;
493 spawnloc.drawonlytoclient = this.realowner;
494 spawnloc.effects = EF_STARDUST;
495 spawnloc.cnt = autocvar_g_nades_spawn_count;
497 if(this.realowner.nade_spawnloc)
499 remove(this.realowner.nade_spawnloc);
500 this.realowner.nade_spawnloc = world;
503 this.realowner.nade_spawnloc = spawnloc;
506 void nade_heal_think(entity this)
508 if(time >= this.ltime)
514 this.nextthink = time;
516 if(time >= this.nade_special_time)
518 this.nade_special_time = time+0.25;
519 this.nade_show_particles = 1;
522 this.nade_show_particles = 0;
525 void nade_heal_touch(entity this)
529 if(IS_PLAYER(other) || IS_MONSTER(other))
531 if(!STAT(FROZEN, other))
533 health_factor = autocvar_g_nades_heal_rate*frametime/2;
534 if ( other != this.realowner )
536 if ( SAME_TEAM(other,this) )
537 health_factor *= autocvar_g_nades_heal_friend;
539 health_factor *= autocvar_g_nades_heal_foe;
541 if ( health_factor > 0 )
543 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
544 if ( other.health < maxhealth )
546 if ( this.nade_show_particles )
547 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
548 other.health = min(other.health+health_factor, maxhealth);
550 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
552 else if ( health_factor < 0 )
554 Damage(other,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
559 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
561 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
562 show_red.stat_healing_orb = time+0.1;
563 show_red.stat_healing_orb_alpha = 0.75 * (this.ltime - time) / this.healer_lifetime;
567 void nade_heal_boom(entity this)
571 healer.owner = this.owner;
572 healer.realowner = this.realowner;
573 setorigin(healer, this.origin);
574 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
575 healer.ltime = time + healer.healer_lifetime;
576 healer.team = this.realowner.team;
577 healer.bot_dodge = false;
578 healer.solid = SOLID_TRIGGER;
579 settouch(healer, nade_heal_touch);
581 setmodel(healer, MDL_NADE_HEAL);
582 healer.healer_radius = autocvar_g_nades_nade_radius;
583 vector size = '1 1 1' * healer.healer_radius / 2;
584 setsize(healer,-size,size);
586 Net_LinkEntity(healer, true, 0, healer_send);
588 setthink(healer, nade_heal_think);
589 healer.nextthink = time;
590 healer.SendFlags |= 1;
593 void nade_monster_boom(entity this)
595 entity e = spawnmonster(this.pokenade_type, 0, this.realowner, this.realowner, this.origin, false, false, 1);
597 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
598 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
599 e.monster_skill = MONSTER_SKILL_INSANE;
602 void nade_boom(entity this)
605 bool nade_blast = true;
607 switch ( Nades_from(this.nade_type) )
609 case NADE_TYPE_NAPALM:
610 nade_blast = autocvar_g_nades_napalm_blast;
611 expef = EFFECT_EXPLOSION_MEDIUM;
615 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
617 case NADE_TYPE_TRANSLOCATE:
620 case NADE_TYPE_MONSTER:
621 case NADE_TYPE_SPAWN:
623 switch(this.realowner.team)
625 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
626 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
627 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
628 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
629 default: expef = EFFECT_SPAWN_NEUTRAL; break;
634 expef = EFFECT_SPAWN_RED;
638 case NADE_TYPE_NORMAL:
639 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
644 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
646 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
647 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
649 this.event_damage = func_null; // prevent somehow calling damage in the next call
653 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
654 autocvar_g_nades_nade_radius, this, world, autocvar_g_nades_nade_force, this.projectiledeathtype, this.enemy);
655 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);
659 switch ( Nades_from(this.nade_type) )
661 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
662 case NADE_TYPE_ICE: nade_ice_boom(this); break;
663 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
664 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
665 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
666 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
669 FOREACH_ENTITY_ENT(aiment, this,
671 if(it.classname == "grapplinghook")
672 RemoveGrapplingHook(it.realowner);
678 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
679 void nade_pickup(entity this, entity thenade)
681 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, thenade.nade_type, thenade.pokenade_type);
683 // set refire so player can't even
684 this.nade_refire = time + autocvar_g_nades_nade_refire;
688 this.nade.nade_time_primed = thenade.nade_time_primed;
691 bool CanThrowNade(entity this);
692 void nade_touch(entity this)
695 UpdateCSQCProjectile(this);
697 if(other == this.realowner)
698 return; // no this impacts
700 if(autocvar_g_nades_pickup)
701 if(time >= this.spawnshieldtime)
702 if(!other.nade && this.health == this.max_health) // no boosted shot pickups, thank you very much
704 if(CanThrowNade(other)) // prevent some obvious things, like dead players
705 if(IS_REAL_CLIENT(other)) // above checks for IS_PLAYER, don't need to do it here
707 nade_pickup(other, this);
708 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
712 /*float is_weapclip = 0;
713 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
714 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
715 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
717 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
719 FOREACH_ENTITY_ENT(aiment, this,
721 if(it.classname == "grapplinghook")
722 RemoveGrapplingHook(it.realowner);
728 PROJECTILE_TOUCH(this);
730 //setsize(this, '-2 -2 -2', '2 2 2');
731 //UpdateCSQCProjectile(this);
732 if(this.health == this.max_health)
734 spamsound(this, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
742 void nade_beep(entity this)
744 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
745 setthink(this, nade_boom);
746 this.nextthink = max(this.wait, time);
749 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
751 if(ITEM_DAMAGE_NEEDKILL(deathtype))
753 this.takedamage = DAMAGE_NO;
758 if(this.nade_type == NADE_TYPE_TRANSLOCATE.m_id || this.nade_type == NADE_TYPE_SPAWN.m_id)
761 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
762 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
767 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
769 force *= 0.5; // too much
772 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
775 damage = this.max_health * 0.55;
777 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
778 damage = this.max_health * 0.1;
779 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
781 if(deathtype & HITTYPE_SECONDARY)
783 damage = this.max_health * 0.1;
787 damage = this.max_health * 1.15;
790 this.velocity += force;
791 UpdateCSQCProjectile(this);
793 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
796 if(this.health == this.max_health)
798 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
799 this.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
800 setthink(this, nade_beep);
803 this.health -= damage;
805 if ( this.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
806 this.realowner = attacker;
809 W_PrepareExplosionByDamage(this, attacker, nade_boom);
811 nade_burn_spawn(this);
814 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
819 entity _nade = e.nade;
825 makevectors(e.v_angle);
827 W_SetupShot(e, false, false, SND_Null, CH_WEAPON_A, 0);
829 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
831 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
832 + (v_right * autocvar_g_nades_throw_offset.y)
833 + (v_up * autocvar_g_nades_throw_offset.z);
834 if(autocvar_g_nades_throw_offset == '0 0 0')
837 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
838 //setmodel(_nade, MDL_PROJECTILE_NADE);
839 //setattachment(_nade, world, "");
840 PROJECTILE_MAKETRIGGER(_nade);
841 if(STAT(NADES_SMALL, e))
842 setsize(_nade, '-8 -8 -8', '8 8 8');
844 setsize(_nade, '-16 -16 -16', '16 16 16');
845 _nade.movetype = MOVETYPE_BOUNCE;
847 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
848 if (trace_startsolid)
849 setorigin(_nade, e.origin);
851 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
852 _nade.velocity = '0 0 100';
853 else if(autocvar_g_nades_nade_newton_style == 1)
854 _nade.velocity = e.velocity + _velocity;
855 else if(autocvar_g_nades_nade_newton_style == 2)
856 _nade.velocity = _velocity;
858 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
863 settouch(_nade, nade_touch);
864 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
865 _nade.health = autocvar_g_nades_nade_health;
866 _nade.max_health = _nade.health;
867 _nade.takedamage = DAMAGE_AIM;
868 _nade.event_damage = nade_damage;
869 setcefc(_nade, func_null);
870 _nade.exteriormodeltoclient = world;
871 _nade.traileffectnum = 0;
872 _nade.teleportable = true;
873 _nade.pushable = true;
875 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
876 _nade.damagedbycontents = true;
877 _nade.angles = vectoangles(_nade.velocity);
878 _nade.flags = FL_PROJECTILE;
879 _nade.projectiledeathtype = DEATH_NADE.m_id;
880 _nade.toss_time = time;
881 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
883 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
884 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
886 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
892 setthink(_nade, nade_boom);
893 _nade.nextthink = _time;
896 e.nade_refire = time + autocvar_g_nades_nade_refire;
900 void nades_GiveBonus(entity player, float score)
902 if (autocvar_g_nades)
903 if (autocvar_g_nades_bonus)
904 if (IS_REAL_CLIENT(player))
905 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
906 if (STAT(FROZEN, player) == 0)
907 if (!IS_DEAD(player))
909 if ( player.bonus_nade_score < 1 )
910 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
912 if ( player.bonus_nade_score >= 1 )
914 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
915 play2(player, SND(KH_ALARM));
916 player.bonus_nades++;
917 player.bonus_nade_score -= 1;
922 /** Remove all bonus nades from a player */
923 void nades_RemoveBonus(entity player)
925 player.bonus_nades = player.bonus_nade_score = 0;
928 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
930 entity player = M_ARGV(0, entity);
932 nades_RemoveBonus(player);
935 float nade_customize(entity this)
937 //if(IS_SPEC(other)) { return false; }
938 if(other == this.exteriormodeltoclient || (IS_SPEC(other) && other.enemy == this.exteriormodeltoclient))
940 // somewhat hide the model, but keep the glow
942 if(this.traileffectnum)
943 this.traileffectnum = 0;
948 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
949 if(!this.traileffectnum)
950 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(this.nade_type).m_projectile[false], this.team).eent_eff_name);
957 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
959 entity n = new(nade), fn = new(fake_nade);
961 n.nade_type = max(1, ntype);
962 n.pokenade_type = pntype;
964 if(Nades_from(n.nade_type) == NADE_TYPE_Null)
965 n.nade_type = NADE_TYPE_NORMAL.m_id;
967 setmodel(n, MDL_PROJECTILE_NADE);
968 //setattachment(n, player, "bip01 l hand");
969 n.exteriormodeltoclient = player;
970 setcefc(n, nade_customize);
971 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
972 n.colormod = Nades_from(n.nade_type).m_color;
973 n.realowner = nowner;
974 n.colormap = player.colormap;
975 n.glowmod = player.glowmod;
976 n.wait = time + max(0, ntime);
977 n.nade_time_primed = time;
978 setthink(n, nade_beep);
979 n.nextthink = max(n.wait - 3, time);
980 n.projectiledeathtype = DEATH_NADE.m_id;
982 setmodel(fn, MDL_NADE_VIEW);
983 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
984 setattachment(fn, player.(weaponentity), "");
985 fn.realowner = fn.owner = player;
986 fn.colormod = Nades_from(n.nade_type).m_color;
987 fn.colormap = player.colormap;
988 fn.glowmod = player.glowmod;
989 setthink(fn, SUB_Remove);
990 fn.nextthink = n.wait;
993 player.fake_nade = fn;
996 void nade_prime(entity this)
998 if(autocvar_g_nades_bonus_only)
999 if(!this.bonus_nades)
1000 return; // only allow bonus nades
1006 remove(this.fake_nade);
1009 string pntype = this.pokenade_type;
1011 if(this.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
1012 ntype = this.nade_type;
1013 else if (this.bonus_nades >= 1)
1015 ntype = this.nade_type;
1016 pntype = this.pokenade_type;
1017 this.bonus_nades -= 1;
1021 ntype = ((autocvar_g_nades_client_select) ? this.cvar_cl_nade_type : autocvar_g_nades_nade_type);
1022 pntype = ((autocvar_g_nades_client_select) ? this.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1025 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1028 bool CanThrowNade(entity this)
1039 if (!autocvar_g_nades)
1040 return false; // allow turning them off mid match
1042 if(forbidWeaponUse(this))
1045 if (!IS_PLAYER(this))
1051 .bool nade_altbutton;
1053 void nades_CheckThrow(entity this)
1055 if(!CanThrowNade(this))
1058 entity held_nade = this.nade;
1061 this.nade_altbutton = true;
1062 if(time > this.nade_refire)
1064 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_NADE_THROW);
1066 this.nade_refire = time + autocvar_g_nades_nade_refire;
1071 this.nade_altbutton = false;
1072 if (time >= held_nade.nade_time_primed + 1) {
1073 makevectors(this.v_angle);
1074 float _force = time - held_nade.nade_time_primed;
1075 _force /= autocvar_g_nades_nade_lifetime;
1076 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1077 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1078 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1079 toss_nade(this, true, dir * _force, 0);
1084 void nades_Clear(entity player)
1087 remove(player.nade);
1088 if(player.fake_nade)
1089 remove(player.fake_nade);
1091 player.nade = player.fake_nade = world;
1092 player.nade_timer = 0;
1095 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1097 entity player = M_ARGV(0, entity);
1100 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1103 CLASS(NadeOffhand, OffhandWeapon)
1104 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1106 entity held_nade = player.nade;
1109 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1110 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1111 makevectors(player.angles);
1112 held_nade.velocity = player.velocity;
1113 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1114 held_nade.angles_y = player.angles.y;
1116 if (time + 0.1 >= held_nade.wait)
1117 toss_nade(player, false, '0 0 0', time + 0.05);
1120 if (!CanThrowNade(player)) return;
1121 if (!(time > player.nade_refire)) return;
1125 held_nade = player.nade;
1127 } else if (time >= held_nade.nade_time_primed + 1) {
1129 makevectors(player.v_angle);
1130 float _force = time - held_nade.nade_time_primed;
1131 _force /= autocvar_g_nades_nade_lifetime;
1132 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1133 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1134 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1135 toss_nade(player, false, dir * _force, 0);
1139 ENDCLASS(NadeOffhand)
1140 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1142 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1144 entity player = M_ARGV(0, entity);
1146 if (player.offhand != OFFHAND_NADE || (player.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1147 nades_CheckThrow(player);
1152 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1154 entity player = M_ARGV(0, entity);
1156 if (!IS_PLAYER(player)) { return; }
1158 if (player.nade && (player.offhand != OFFHAND_NADE || (player.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1160 if(IS_PLAYER(player))
1162 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1165 float key_count = 0;
1166 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1169 if(player.flagcarried || player.ballcarried) // this player is important
1170 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1172 time_score = autocvar_g_nades_bonus_score_time;
1175 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1177 if(autocvar_g_nades_bonus_client_select)
1179 player.nade_type = player.cvar_cl_nade_type;
1180 player.pokenade_type = player.cvar_cl_pokenade_type;
1184 player.nade_type = autocvar_g_nades_bonus_type;
1185 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1188 player.nade_type = bound(1, player.nade_type, Nades_COUNT);
1190 if(player.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1191 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1195 player.bonus_nades = player.bonus_nade_score = 0;
1201 if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
1205 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1207 FOREACH_CLIENT(IS_PLAYER(it) && it != player, LAMBDA(
1209 if(STAT(FROZEN, it) == 0)
1210 if(SAME_TEAM(it, player))
1211 if(boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1215 if(STAT(FROZEN, player) == 1)
1222 if(n && STAT(FROZEN, player) == 3) // OK, there is at least one teammate reviving us
1224 player.revive_progress = bound(0, player.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1225 player.health = max(1, player.revive_progress * start_health);
1227 if(player.revive_progress >= 1)
1231 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1232 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1235 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1236 it.revive_progress = player.revive_progress;
1237 it.reviving = false;
1242 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1244 entity player = M_ARGV(0, entity);
1246 if(autocvar_g_nades_spawn)
1247 player.nade_refire = time + autocvar_g_spawnshieldtime;
1249 player.nade_refire = time + autocvar_g_nades_nade_refire;
1251 if(autocvar_g_nades_bonus_client_select)
1252 player.nade_type = player.cvar_cl_nade_type;
1254 player.nade_timer = 0;
1256 if (!player.offhand) player.offhand = OFFHAND_NADE;
1258 if(player.nade_spawnloc)
1260 setorigin(player, player.nade_spawnloc.origin);
1261 player.nade_spawnloc.cnt -= 1;
1263 if(player.nade_spawnloc.cnt <= 0)
1265 remove(player.nade_spawnloc);
1266 player.nade_spawnloc = world;
1271 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1273 entity frag_attacker = M_ARGV(1, entity);
1274 entity frag_target = M_ARGV(2, entity);
1276 if(frag_target.nade)
1277 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1278 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1280 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);
1282 if(IS_PLAYER(frag_attacker))
1284 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1285 nades_RemoveBonus(frag_attacker);
1286 else if(frag_target.flagcarried)
1287 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1288 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1290 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1291 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1292 switch(frag_attacker.killcount)
1295 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1300 nades_GiveBonus(frag_attacker, killcount_bonus);
1303 nades_RemoveBonus(frag_target);
1306 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1308 entity frag_inflictor = M_ARGV(0, entity);
1309 entity frag_attacker = M_ARGV(1, entity);
1310 entity frag_target = M_ARGV(2, entity);
1311 float frag_deathtype = M_ARGV(3, float);
1313 if(STAT(FROZEN, frag_target))
1314 if(autocvar_g_freezetag_revive_nade)
1315 if(frag_attacker == frag_target)
1316 if(frag_deathtype == DEATH_NADE.m_id)
1317 if(time - frag_inflictor.toss_time <= 0.1)
1319 Unfreeze(frag_target);
1320 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1321 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1322 M_ARGV(4, float) = 0;
1323 M_ARGV(6, vector) = '0 0 0';
1324 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1325 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1329 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1331 entity frag_target = M_ARGV(0, entity);
1332 entity frag_attacker = M_ARGV(1, entity);
1334 if(IS_PLAYER(frag_attacker))
1335 if(DIFF_TEAM(frag_attacker, frag_target))
1336 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1337 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1340 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1342 entity frag_target = M_ARGV(0, entity);
1344 if(frag_target.nade)
1345 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1348 void nades_RemovePlayer(entity this)
1351 nades_RemoveBonus(this);
1354 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1355 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1356 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1358 FOREACH_CLIENT(IS_PLAYER(it),
1360 nades_RemovePlayer(it);
1364 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1366 entity spectatee = M_ARGV(0, entity);
1367 entity client = M_ARGV(1, entity);
1369 client.nade_timer = spectatee.nade_timer;
1370 client.nade_type = spectatee.nade_type;
1371 client.pokenade_type = spectatee.pokenade_type;
1372 client.bonus_nades = spectatee.bonus_nades;
1373 client.bonus_nade_score = spectatee.bonus_nade_score;
1374 client.stat_healing_orb = spectatee.stat_healing_orb;
1375 client.stat_healing_orb_alpha = spectatee.stat_healing_orb_alpha;
1378 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
1379 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
1381 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1383 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");
1386 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1388 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1391 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1393 M_ARGV(0, string) = strcat(M_ARGV(0, string), "\n\n^3nades^8 are enabled, press 'g' to use them\n");