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 = self.owner;
342 fountain.realowner = self.realowner;
343 fountain.origin = self.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 = self.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)
371 if(round_handler_IsActive())
372 if(!round_handler_IsRoundStarted())
378 if(time >= self.ltime)
380 if ( autocvar_g_nades_ice_explode )
382 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
383 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
384 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
386 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
387 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
388 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
389 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
396 self.nextthink = time+0.1;
401 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
403 randomw = random()*M_PI*2;
405 randomp.x = randomr*cos(randomw);
406 randomp.y = randomr*sin(randomw);
408 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
410 if(time >= self.nade_special_time)
412 self.nade_special_time = time+0.7;
414 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
415 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
419 float current_freeze_time = self.ltime - time - 0.1;
422 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
424 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
425 if(e.takedamage && !IS_DEAD(e))
427 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
429 if(current_freeze_time > 0)
430 nade_ice_freeze(self, e, current_freeze_time);
433 void nade_ice_boom(entity this)
437 fountain.owner = this.owner;
438 fountain.realowner = this.realowner;
439 fountain.origin = this.origin;
440 setorigin(fountain, fountain.origin);
441 setthink(fountain, nade_ice_think);
442 fountain.nextthink = time;
443 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
444 fountain.pushltime = fountain.wait = fountain.ltime;
445 fountain.team = this.team;
446 fountain.movetype = MOVETYPE_TOSS;
447 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
448 fountain.bot_dodge = false;
449 setsize(fountain, '-16 -16 -16', '16 16 16');
450 fountain.nade_special_time = time+0.3;
451 fountain.angles = this.angles;
453 if ( autocvar_g_nades_ice_explode )
455 setmodel(fountain, MDL_PROJECTILE_GRENADE);
456 entity timer = new(nade_timer);
457 setmodel(timer, MDL_NADE_TIMER);
458 setattachment(timer, fountain, "");
459 timer.colormap = this.colormap;
460 timer.glowmod = this.glowmod;
461 setthink(timer, nade_timer_think);
462 timer.nextthink = time;
463 timer.wait = fountain.ltime;
464 timer.owner = fountain;
468 setmodel(fountain, MDL_Null);
471 void nade_translocate_boom(entity this)
473 if(this.realowner.vehicle)
476 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
477 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
478 locout = trace_endpos;
480 makevectors(this.realowner.angles);
482 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
484 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
487 void nade_spawn_boom(entity this)
489 entity spawnloc = spawn();
490 setorigin(spawnloc, this.origin);
491 setsize(spawnloc, this.realowner.mins, this.realowner.maxs);
492 spawnloc.movetype = MOVETYPE_NONE;
493 spawnloc.solid = SOLID_NOT;
494 spawnloc.drawonlytoclient = this.realowner;
495 spawnloc.effects = EF_STARDUST;
496 spawnloc.cnt = autocvar_g_nades_spawn_count;
498 if(this.realowner.nade_spawnloc)
500 remove(this.realowner.nade_spawnloc);
501 this.realowner.nade_spawnloc = world;
504 this.realowner.nade_spawnloc = spawnloc;
507 void nade_heal_think(entity this)
509 if(time >= self.ltime)
515 self.nextthink = time;
517 if(time >= self.nade_special_time)
519 self.nade_special_time = time+0.25;
520 self.nade_show_particles = 1;
523 self.nade_show_particles = 0;
526 void nade_heal_touch(entity this)
530 if(IS_PLAYER(other) || IS_MONSTER(other))
532 if(!STAT(FROZEN, other))
534 health_factor = autocvar_g_nades_heal_rate*frametime/2;
535 if ( other != self.realowner )
537 if ( SAME_TEAM(other,self) )
538 health_factor *= autocvar_g_nades_heal_friend;
540 health_factor *= autocvar_g_nades_heal_foe;
542 if ( health_factor > 0 )
544 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
545 if ( other.health < maxhealth )
547 if ( self.nade_show_particles )
548 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
549 other.health = min(other.health+health_factor, maxhealth);
551 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
553 else if ( health_factor < 0 )
555 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
560 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
562 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
563 show_red.stat_healing_orb = time+0.1;
564 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
568 void nade_heal_boom(entity this)
572 healer.owner = this.owner;
573 healer.realowner = this.realowner;
574 setorigin(healer, this.origin);
575 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
576 healer.ltime = time + healer.healer_lifetime;
577 healer.team = this.realowner.team;
578 healer.bot_dodge = false;
579 healer.solid = SOLID_TRIGGER;
580 settouch(healer, nade_heal_touch);
582 setmodel(healer, MDL_NADE_HEAL);
583 healer.healer_radius = autocvar_g_nades_nade_radius;
584 vector size = '1 1 1' * healer.healer_radius / 2;
585 setsize(healer,-size,size);
587 Net_LinkEntity(healer, true, 0, healer_send);
589 setthink(healer, nade_heal_think);
590 healer.nextthink = time;
591 healer.SendFlags |= 1;
594 void nade_monster_boom(entity this)
596 entity e = spawnmonster(this.pokenade_type, 0, this.realowner, this.realowner, this.origin, false, false, 1);
598 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
599 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
600 e.monster_skill = MONSTER_SKILL_INSANE;
603 void nade_boom(entity this)
606 bool nade_blast = true;
608 switch ( Nades_from(this.nade_type) )
610 case NADE_TYPE_NAPALM:
611 nade_blast = autocvar_g_nades_napalm_blast;
612 expef = EFFECT_EXPLOSION_MEDIUM;
616 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
618 case NADE_TYPE_TRANSLOCATE:
621 case NADE_TYPE_MONSTER:
622 case NADE_TYPE_SPAWN:
624 switch(this.realowner.team)
626 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
627 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
628 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
629 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
630 default: expef = EFFECT_SPAWN_NEUTRAL; break;
635 expef = EFFECT_SPAWN_RED;
639 case NADE_TYPE_NORMAL:
640 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
645 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
647 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
648 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
650 this.event_damage = func_null; // prevent somehow calling damage in the next call
654 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
655 autocvar_g_nades_nade_radius, this, world, autocvar_g_nades_nade_force, this.projectiledeathtype, this.enemy);
656 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);
660 switch ( Nades_from(this.nade_type) )
662 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
663 case NADE_TYPE_ICE: nade_ice_boom(this); break;
664 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
665 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
666 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
667 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
670 FOREACH_ENTITY_ENT(aiment, this,
672 if(it.classname == "grapplinghook")
673 RemoveGrapplingHook(it.realowner);
679 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
680 void nade_pickup(entity this, entity thenade)
682 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, thenade.nade_type, thenade.pokenade_type);
684 // set refire so player can't even
685 this.nade_refire = time + autocvar_g_nades_nade_refire;
689 this.nade.nade_time_primed = thenade.nade_time_primed;
692 bool CanThrowNade(entity this);
693 void nade_touch(entity this)
696 UpdateCSQCProjectile(self);
698 if(other == self.realowner)
699 return; // no self impacts
701 if(autocvar_g_nades_pickup)
702 if(time >= self.spawnshieldtime)
703 if(!other.nade && self.health == self.max_health) // no boosted shot pickups, thank you very much
705 if(CanThrowNade(other)) // prevent some obvious things, like dead players
706 if(IS_REAL_CLIENT(other)) // above checks for IS_PLAYER, don't need to do it here
708 nade_pickup(other, self);
709 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
713 /*float is_weapclip = 0;
714 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
715 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
716 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
718 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
720 FOREACH_ENTITY_ENT(aiment, self,
722 if(it.classname == "grapplinghook")
723 RemoveGrapplingHook(it.realowner);
729 PROJECTILE_TOUCH(this);
731 //setsize(self, '-2 -2 -2', '2 2 2');
732 //UpdateCSQCProjectile(self);
733 if(self.health == self.max_health)
735 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
743 void nade_beep(entity this)
745 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
746 setthink(this, nade_boom);
747 this.nextthink = max(this.wait, time);
750 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
752 if(ITEM_DAMAGE_NEEDKILL(deathtype))
754 this.takedamage = DAMAGE_NO;
755 WITHSELF(this, nade_boom(this));
759 if(this.nade_type == NADE_TYPE_TRANSLOCATE.m_id || this.nade_type == NADE_TYPE_SPAWN.m_id)
762 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
763 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
768 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
770 force *= 0.5; // too much
773 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
776 damage = this.max_health * 0.55;
778 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
779 damage = this.max_health * 0.1;
780 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
782 if(deathtype & HITTYPE_SECONDARY)
784 damage = this.max_health * 0.1;
788 damage = this.max_health * 1.15;
791 this.velocity += force;
792 UpdateCSQCProjectile(this);
794 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
797 if(this.health == this.max_health)
799 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
800 this.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
801 setthink(this, nade_beep);
804 this.health -= damage;
806 if ( this.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
807 this.realowner = attacker;
810 W_PrepareExplosionByDamage(this, attacker, nade_boom);
812 nade_burn_spawn(this);
815 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
820 entity _nade = e.nade;
826 makevectors(e.v_angle);
828 W_SetupShot(e, false, false, SND_Null, CH_WEAPON_A, 0);
830 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
832 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
833 + (v_right * autocvar_g_nades_throw_offset.y)
834 + (v_up * autocvar_g_nades_throw_offset.z);
835 if(autocvar_g_nades_throw_offset == '0 0 0')
838 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
839 //setmodel(_nade, MDL_PROJECTILE_NADE);
840 //setattachment(_nade, world, "");
841 PROJECTILE_MAKETRIGGER(_nade);
842 if(STAT(NADES_SMALL, e))
843 setsize(_nade, '-8 -8 -8', '8 8 8');
845 setsize(_nade, '-16 -16 -16', '16 16 16');
846 _nade.movetype = MOVETYPE_BOUNCE;
848 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
849 if (trace_startsolid)
850 setorigin(_nade, e.origin);
852 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
853 _nade.velocity = '0 0 100';
854 else if(autocvar_g_nades_nade_newton_style == 1)
855 _nade.velocity = e.velocity + _velocity;
856 else if(autocvar_g_nades_nade_newton_style == 2)
857 _nade.velocity = _velocity;
859 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
864 settouch(_nade, nade_touch);
865 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
866 _nade.health = autocvar_g_nades_nade_health;
867 _nade.max_health = _nade.health;
868 _nade.takedamage = DAMAGE_AIM;
869 _nade.event_damage = nade_damage;
870 setcefc(_nade, func_null);
871 _nade.exteriormodeltoclient = world;
872 _nade.traileffectnum = 0;
873 _nade.teleportable = true;
874 _nade.pushable = true;
876 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
877 _nade.damagedbycontents = true;
878 _nade.angles = vectoangles(_nade.velocity);
879 _nade.flags = FL_PROJECTILE;
880 _nade.projectiledeathtype = DEATH_NADE.m_id;
881 _nade.toss_time = time;
882 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
884 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
885 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
887 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
893 setthink(_nade, nade_boom);
894 _nade.nextthink = _time;
897 e.nade_refire = time + autocvar_g_nades_nade_refire;
901 void nades_GiveBonus(entity player, float score)
903 if (autocvar_g_nades)
904 if (autocvar_g_nades_bonus)
905 if (IS_REAL_CLIENT(player))
906 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
907 if (STAT(FROZEN, player) == 0)
908 if (!IS_DEAD(player))
910 if ( player.bonus_nade_score < 1 )
911 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
913 if ( player.bonus_nade_score >= 1 )
915 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
916 play2(player, SND(KH_ALARM));
917 player.bonus_nades++;
918 player.bonus_nade_score -= 1;
923 /** Remove all bonus nades from a player */
924 void nades_RemoveBonus(entity player)
926 player.bonus_nades = player.bonus_nade_score = 0;
929 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
931 entity player = M_ARGV(0, entity);
933 nades_RemoveBonus(player);
936 float nade_customize(entity this)
938 //if(IS_SPEC(other)) { return false; }
939 if(other == self.exteriormodeltoclient || (IS_SPEC(other) && other.enemy == self.exteriormodeltoclient))
941 // somewhat hide the model, but keep the glow
943 if(self.traileffectnum)
944 self.traileffectnum = 0;
949 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
950 if(!self.traileffectnum)
951 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
958 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
960 entity n = new(nade), fn = new(fake_nade);
962 n.nade_type = bound(1, ntype, Nades_COUNT);
963 n.pokenade_type = pntype;
965 setmodel(n, MDL_PROJECTILE_NADE);
966 //setattachment(n, player, "bip01 l hand");
967 n.exteriormodeltoclient = player;
968 setcefc(n, nade_customize);
969 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
970 n.colormod = Nades_from(n.nade_type).m_color;
971 n.realowner = nowner;
972 n.colormap = player.colormap;
973 n.glowmod = player.glowmod;
974 n.wait = time + max(0, ntime);
975 n.nade_time_primed = time;
976 setthink(n, nade_beep);
977 n.nextthink = max(n.wait - 3, time);
978 n.projectiledeathtype = DEATH_NADE.m_id;
980 setmodel(fn, MDL_NADE_VIEW);
981 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
982 setattachment(fn, player.(weaponentity), "");
983 fn.realowner = fn.owner = player;
984 fn.colormod = Nades_from(n.nade_type).m_color;
985 fn.colormap = player.colormap;
986 fn.glowmod = player.glowmod;
987 setthink(fn, SUB_Remove);
988 fn.nextthink = n.wait;
991 player.fake_nade = fn;
996 if(autocvar_g_nades_bonus_only)
997 if(!self.bonus_nades)
998 return; // only allow bonus nades
1004 remove(self.fake_nade);
1007 string pntype = self.pokenade_type;
1009 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
1010 ntype = self.nade_type;
1011 else if (self.bonus_nades >= 1)
1013 ntype = self.nade_type;
1014 pntype = self.pokenade_type;
1015 self.bonus_nades -= 1;
1019 ntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
1020 pntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1023 spawn_held_nade(self, self, autocvar_g_nades_nade_lifetime, ntype, pntype);
1026 bool CanThrowNade(entity this)
1037 if (!autocvar_g_nades)
1038 return false; // allow turning them off mid match
1040 if(forbidWeaponUse(this))
1043 if (!IS_PLAYER(this))
1049 .bool nade_altbutton;
1051 void nades_CheckThrow()
1053 if(!CanThrowNade(self))
1056 entity held_nade = self.nade;
1059 self.nade_altbutton = true;
1060 if(time > self.nade_refire)
1062 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1064 self.nade_refire = time + autocvar_g_nades_nade_refire;
1069 self.nade_altbutton = false;
1070 if (time >= held_nade.nade_time_primed + 1) {
1071 makevectors(self.v_angle);
1072 float _force = time - held_nade.nade_time_primed;
1073 _force /= autocvar_g_nades_nade_lifetime;
1074 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1075 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1076 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1077 toss_nade(self, true, dir * _force, 0);
1082 void nades_Clear(entity player)
1085 remove(player.nade);
1086 if(player.fake_nade)
1087 remove(player.fake_nade);
1089 player.nade = player.fake_nade = world;
1090 player.nade_timer = 0;
1093 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1096 toss_nade(vh_player, true, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1101 CLASS(NadeOffhand, OffhandWeapon)
1102 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1104 entity held_nade = player.nade;
1107 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1108 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1109 makevectors(player.angles);
1110 held_nade.velocity = player.velocity;
1111 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1112 held_nade.angles_y = player.angles.y;
1114 if (time + 0.1 >= held_nade.wait)
1115 toss_nade(player, false, '0 0 0', time + 0.05);
1118 if (!CanThrowNade(player)) return;
1119 if (!(time > player.nade_refire)) return;
1123 held_nade = player.nade;
1125 } else if (time >= held_nade.nade_time_primed + 1) {
1127 makevectors(player.v_angle);
1128 float _force = time - held_nade.nade_time_primed;
1129 _force /= autocvar_g_nades_nade_lifetime;
1130 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1131 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1132 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1133 toss_nade(player, false, dir * _force, 0);
1137 ENDCLASS(NadeOffhand)
1138 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1140 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1143 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1150 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1152 if (!IS_PLAYER(self)) { return false; }
1154 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1158 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1161 float key_count = 0;
1162 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1165 if(self.flagcarried || self.ballcarried) // this player is important
1166 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1168 time_score = autocvar_g_nades_bonus_score_time;
1171 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1173 if(autocvar_g_nades_bonus_client_select)
1175 self.nade_type = self.cvar_cl_nade_type;
1176 self.pokenade_type = self.cvar_cl_pokenade_type;
1180 self.nade_type = autocvar_g_nades_bonus_type;
1181 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1184 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1186 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1187 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1191 self.bonus_nades = self.bonus_nade_score = 0;
1197 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1201 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1203 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
1205 if(STAT(FROZEN, it) == 0)
1206 if(SAME_TEAM(it, self))
1207 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
1211 if(STAT(FROZEN, self) == 1)
1218 if(n && STAT(FROZEN, self) == 3) // OK, there is at least one teammate reviving us
1220 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1221 self.health = max(1, self.revive_progress * start_health);
1223 if(self.revive_progress >= 1)
1227 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1228 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1231 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1232 other.revive_progress = self.revive_progress;
1233 other.reviving = false;
1240 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1242 entity player = M_ARGV(0, entity);
1244 if(autocvar_g_nades_spawn)
1245 player.nade_refire = time + autocvar_g_spawnshieldtime;
1247 player.nade_refire = time + autocvar_g_nades_nade_refire;
1249 if(autocvar_g_nades_bonus_client_select)
1250 player.nade_type = player.cvar_cl_nade_type;
1252 player.nade_timer = 0;
1254 if (!player.offhand) player.offhand = OFFHAND_NADE;
1256 if(player.nade_spawnloc)
1258 setorigin(player, player.nade_spawnloc.origin);
1259 player.nade_spawnloc.cnt -= 1;
1261 if(player.nade_spawnloc.cnt <= 0)
1263 remove(player.nade_spawnloc);
1264 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);
1331 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1333 entity frag_target = M_ARGV(0, entity);
1334 entity frag_attacker = M_ARGV(1, entity);
1336 if(IS_PLAYER(frag_attacker))
1337 if(DIFF_TEAM(frag_attacker, frag_target))
1338 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1339 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1344 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1346 entity frag_target = M_ARGV(0, entity);
1348 if(frag_target.nade)
1349 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1354 void nades_RemovePlayer(entity this)
1357 nades_RemoveBonus(this);
1360 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1361 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1362 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1364 FOREACH_CLIENT(IS_PLAYER(it),
1366 nades_RemovePlayer(it);
1370 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1372 entity spectatee = M_ARGV(0, entity);
1373 entity client = M_ARGV(1, entity);
1375 client.nade_timer = spectatee.nade_timer;
1376 client.nade_type = spectatee.nade_type;
1377 client.pokenade_type = spectatee.pokenade_type;
1378 client.bonus_nades = spectatee.bonus_nades;
1379 client.bonus_nade_score = spectatee.bonus_nade_score;
1380 client.stat_healing_orb = spectatee.stat_healing_orb;
1381 client.stat_healing_orb_alpha = spectatee.stat_healing_orb_alpha;
1384 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
1385 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
1387 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1389 ret_string = strcat(ret_string, ":Nades");
1393 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1395 ret_string = strcat(ret_string, ", Nades");
1399 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1401 ret_string = strcat(ret_string, "\n\n^3nades^8 are enabled, press 'g' to use them\n");