3 #include "../overkill/okmachinegun.qh"
4 #include "../overkill/okshotgun.qh"
7 bool autocvar_g_nades_nade_small;
8 float autocvar_g_nades_spread = 0.04;
11 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
15 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
16 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
18 entity Nade_TrailEffect(int proj, int nade_team)
22 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
23 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
26 FOREACH(Nades, true, {
27 for (int j = 0; j < 2; j++)
29 if (it.m_projectile[j] == proj)
31 string trail = it.m_trail[j].eent_eff_name;
32 if (trail) return it.m_trail[j];
43 #include <client/draw.qh>
44 #include <client/hud/hud.qh>
46 bool darkness_fadealpha;
48 void HUD_DarkBlinking()
50 vector bottomright = vec2(vid_conwidth, vid_conheight);
51 drawfill('0 0 0', bottomright, NADE_TYPE_DARKNESS.m_color, darkness_fadealpha, DRAWFLAG_NORMAL);
54 REGISTER_MUTATOR(cl_nades, true);
55 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
57 if (STAT(NADE_DARKNESS_TIME) > time)
59 if (!darkness_fadealpha)
60 sound(csqcplayer, CH_PAIN, SND_BLIND, VOL_BASE, ATTEN_NORM);
61 darkness_fadealpha = min(0.986, darkness_fadealpha + frametime * 7);
63 else if (darkness_fadealpha > 0)
64 darkness_fadealpha = max(0, darkness_fadealpha - frametime * 7);
66 if (darkness_fadealpha > 0)
69 M_ARGV(1, float) = 0; // alpha_multipl 0, don't draw normal overlay
75 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
77 entity proj = M_ARGV(0, entity);
79 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
82 proj.traileffect = EFFECT_FIREBALL.m_id;
85 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
87 setmodel(proj, MDL_PROJECTILE_NADE);
88 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
89 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
93 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
95 if (!mut_is_active(MUT_NADES)) return;
97 entity proj = M_ARGV(0, entity);
99 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
101 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
102 proj.mins = '-16 -16 -16';
103 proj.maxs = '16 16 16';
106 entity nade_type = Nade_FromProjectile(proj.cnt);
107 if (nade_type == NADE_TYPE_Null) return;
109 if(STAT(NADES_SMALL))
111 proj.mins = '-8 -8 -8';
116 proj.mins = '-16 -16 -16';
117 proj.maxs = '16 16 16';
119 proj.colormod = nade_type.m_color;
120 set_movetype(proj, MOVETYPE_BOUNCE);
121 settouch(proj, func_null);
123 proj.avelocity = randomvec() * 720;
124 proj.alphamod = nade_type.m_alpha;
126 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
127 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
129 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
132 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
134 if (mut_is_active(MUT_NADES))
136 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
137 M_ARGV(0, string) = strcat(M_ARGV(0, string),
138 "\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
142 bool Projectile_isnade(int p)
144 return Nade_FromProjectile(p) != NADE_TYPE_Null;
146 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
148 float bonusNades = STAT(NADE_BONUS);
149 float bonusProgress = STAT(NADE_BONUS_SCORE);
150 float bonusType = STAT(NADE_BONUS_TYPE);
151 Nade def = REGISTRY_GET(Nades, bonusType);
152 vector nadeColor = def.m_color;
153 string nadeIcon = def.m_icon;
155 vector iconPos, textPos;
157 if(autocvar_hud_panel_ammo_iconalign)
159 iconPos = myPos + eX * 2 * mySize.y;
165 textPos = myPos + eX * mySize.y;
168 if(bonusNades > 0 || bonusProgress > 0)
170 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
172 if(autocvar_hud_panel_ammo_text)
173 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
176 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
178 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
185 #include <common/gamemodes/_mod.qh>
186 #include <common/monsters/sv_spawn.qh>
187 #include <common/monsters/sv_monsters.qh>
188 #include <server/command/common.qh>
190 .float nade_time_primed;
191 .float nade_lifetime;
193 .entity nade_spawnloc;
196 void nade_timer_think(entity this)
198 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
199 this.nextthink = time;
200 if(!this.owner || wasfreed(this.owner))
204 void nade_burn_spawn(entity _nade)
206 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
209 void nade_spawn(entity _nade)
211 entity timer = new(nade_timer);
212 setmodel(timer, MDL_NADE_TIMER);
213 setattachment(timer, _nade, "");
214 timer.colormap = _nade.colormap;
215 timer.glowmod = _nade.glowmod;
216 setthink(timer, nade_timer_think);
217 timer.nextthink = time;
218 timer.wait = _nade.wait;
222 _nade.effects |= EF_LOWPRECISION;
224 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
227 void normal_nade_boom(entity this)
229 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
230 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
231 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
232 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
235 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
244 RandomSelection_Init();
245 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
246 if(e.takedamage == DAMAGE_AIM)
247 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
248 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
252 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
253 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
254 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
255 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
258 e.fireball_impactvec = p;
259 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
262 if(RandomSelection_chosen_ent)
264 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
265 d = damage + (edgedamage - damage) * (d / dist);
266 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
267 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
268 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
273 void napalm_ball_think(entity this)
275 if(round_handler_IsActive())
276 if(!round_handler_IsRoundStarted())
282 if(time > this.pushltime)
288 vector midpoint = ((this.absmin + this.absmax) * 0.5);
289 if(pointcontents(midpoint) == CONTENT_WATER)
291 this.velocity = this.velocity * 0.5;
293 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
294 { this.velocity_z = 200; }
297 this.angles = vectoangles(this.velocity);
299 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
300 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
302 this.nextthink = time + 0.1;
306 void nade_napalm_ball(entity this)
311 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
314 proj.owner = this.owner;
315 proj.realowner = this.realowner;
316 proj.team = this.owner.team;
317 proj.bot_dodge = true;
318 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
319 set_movetype(proj, MOVETYPE_BOUNCE);
320 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
321 PROJECTILE_MAKETRIGGER(proj);
322 setmodel(proj, MDL_Null);
323 proj.scale = 1;//0.5;
324 setsize(proj, '-4 -4 -4', '4 4 4');
325 setorigin(proj, this.origin);
326 setthink(proj, napalm_ball_think);
327 proj.nextthink = time;
328 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
329 proj.effects = EF_LOWPRECISION | EF_FLAME;
331 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
332 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
333 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
334 proj.velocity = kick;
336 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
338 proj.angles = vectoangles(proj.velocity);
339 proj.flags = FL_PROJECTILE;
340 IL_PUSH(g_projectiles, proj);
341 IL_PUSH(g_bot_dodge, proj);
342 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
344 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
348 void napalm_fountain_think(entity this)
351 if(round_handler_IsActive())
352 if(!round_handler_IsRoundStarted())
358 if(time >= this.ltime)
364 vector midpoint = ((this.absmin + this.absmax) * 0.5);
365 if(pointcontents(midpoint) == CONTENT_WATER)
367 this.velocity = this.velocity * 0.5;
369 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
370 { this.velocity_z = 200; }
372 UpdateCSQCProjectile(this);
375 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
376 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
378 this.nextthink = time + 0.1;
379 if(time >= this.nade_special_time)
381 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
382 nade_napalm_ball(this);
386 void nade_napalm_boom(entity this)
388 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
389 nade_napalm_ball(this);
391 entity fountain = new(nade_napalm_fountain);
392 fountain.owner = this.owner;
393 fountain.realowner = this.realowner;
394 fountain.origin = this.origin;
395 fountain.flags = FL_PROJECTILE;
396 IL_PUSH(g_projectiles, fountain);
397 IL_PUSH(g_bot_dodge, fountain);
398 setorigin(fountain, fountain.origin);
399 setthink(fountain, napalm_fountain_think);
400 fountain.nextthink = time;
401 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
402 fountain.pushltime = fountain.ltime;
403 fountain.team = this.team;
404 set_movetype(fountain, MOVETYPE_TOSS);
405 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
406 fountain.bot_dodge = true;
407 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
408 fountain.nade_special_time = time;
409 setsize(fountain, '-16 -16 -16', '16 16 16');
410 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
413 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
415 frost_target.frozen_by = freezefield.realowner;
416 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
417 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
419 Drop_Special_Items(frost_target);
422 void nade_ice_think(entity this)
424 if(round_handler_IsActive())
425 if(!round_handler_IsRoundStarted())
431 if(time >= this.ltime)
433 if ( autocvar_g_nades_ice_explode )
435 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
436 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
437 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
439 normal_nade_boom(this);
446 this.nextthink = time + 0.1;
451 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
453 randomw = random() * M_PI * 2;
455 randomp.x = randomr * cos(randomw);
456 randomp.y = randomr * sin(randomw);
458 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
460 if(time >= this.nade_special_time)
462 this.nade_special_time = time + 0.7;
464 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
465 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
469 float current_freeze_time = this.ltime - time - 0.1;
471 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
472 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0
473 && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it),
475 switch (autocvar_g_nades_ice_teamcheck)
477 case 0: break; // affect everyone
479 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
480 // fall through (check case 1 condition too)
481 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
483 nade_ice_freeze(this, it, current_freeze_time);
487 void nade_ice_boom(entity this)
489 entity fountain = new(nade_ice_fountain);
490 fountain.owner = this.owner;
491 fountain.realowner = this.realowner;
492 fountain.origin = this.origin;
493 setorigin(fountain, fountain.origin);
494 setthink(fountain, nade_ice_think);
495 fountain.nextthink = time;
496 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
497 fountain.pushltime = fountain.wait = fountain.ltime;
498 fountain.team = this.team;
499 set_movetype(fountain, MOVETYPE_TOSS);
500 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
501 fountain.bot_dodge = false;
502 setsize(fountain, '-16 -16 -16', '16 16 16');
503 fountain.nade_special_time = time + 0.3;
504 fountain.angles = this.angles;
506 if ( autocvar_g_nades_ice_explode )
508 setmodel(fountain, MDL_PROJECTILE_GRENADE);
509 entity timer = new(nade_timer);
510 setmodel(timer, MDL_NADE_TIMER);
511 setattachment(timer, fountain, "");
512 timer.colormap = this.colormap;
513 timer.glowmod = this.glowmod;
514 setthink(timer, nade_timer_think);
515 timer.nextthink = time;
516 timer.wait = fountain.ltime;
517 timer.owner = fountain;
521 setmodel(fountain, MDL_Null);
524 void nade_translocate_boom(entity this)
526 if(this.realowner.vehicle)
529 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
531 if(!move_out_of_solid(this))
533 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
537 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
538 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
539 locout = trace_endpos;
541 makevectors(this.realowner.angles);
543 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
545 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
548 void nade_spawn_boom(entity this)
550 entity player = this.realowner;
551 entity spawnloc = new(nade_spawn_loc);
552 setorigin(spawnloc, this.origin);
553 setsize(spawnloc, player.mins, player.maxs);
554 set_movetype(spawnloc, MOVETYPE_NONE);
555 spawnloc.solid = SOLID_NOT;
556 spawnloc.drawonlytoclient = player;
557 spawnloc.effects = EF_STARDUST;
558 spawnloc.cnt = autocvar_g_nades_spawn_count;
560 if(player.nade_spawnloc)
561 delete(player.nade_spawnloc);
563 player.nade_spawnloc = spawnloc;
566 void nades_orb_think(entity this)
568 if(time >= this.ltime)
574 this.nextthink = time;
576 if(time >= this.nade_special_time)
578 this.nade_special_time = time+0.25;
579 this.nade_show_particles = 1;
582 this.nade_show_particles = 0;
585 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
587 // NOTE: this function merely places an orb
588 // you must add a custom touch function to the returned entity if desired
589 // also set .colormod if you wish to have it colorized
590 entity orb = new(nades_spawn_orb);
592 orb.realowner = realown;
595 orb.orb_lifetime = orb_ltime; // required for timers
596 orb.ltime = time + orb.orb_lifetime;
597 orb.bot_dodge = false;
598 orb.team = realown.team;
599 orb.solid = SOLID_TRIGGER;
601 setmodel(orb, MDL_NADE_ORB);
603 orb.orb_radius = orb_rad; // required for fading
604 vector size = '1 1 1' * orb.orb_radius / 2;
605 setsize(orb, -size, size);
607 Net_LinkEntity(orb, true, 0, orb_send);
610 setthink(orb, nades_orb_think);
611 orb.nextthink = time;
616 void nade_entrap_touch(entity this, entity toucher)
618 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
620 if (!isPushable(toucher))
623 float pushdeltatime = time - toucher.lastpushtime;
624 if (pushdeltatime > 0.15) pushdeltatime = 0;
625 toucher.lastpushtime = time;
626 if(!pushdeltatime) return;
628 // div0: ticrate independent, 1 = identity (not 20)
629 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
632 UpdateCSQCProjectile(toucher);
636 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
638 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
639 show_tint.nade_entrap_time = time + 0.1;
643 void nade_entrap_boom(entity this)
645 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
647 settouch(orb, nade_entrap_touch);
648 orb.colormod = NADE_TYPE_ENTRAP.m_color;
651 void nade_heal_touch(entity this, entity toucher)
656 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
657 if(!IS_DEAD(toucher))
658 if(!STAT(FROZEN, toucher))
660 health_factor = autocvar_g_nades_heal_rate*frametime/2;
661 if ( toucher != this.realowner )
662 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
664 if ( health_factor > 0 )
666 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
667 float hp = GetResource(toucher, RES_HEALTH);
670 if (this.nade_show_particles)
671 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
673 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
676 else if ( health_factor < 0 )
677 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
681 void nade_heal_boom(entity this)
683 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
685 settouch(orb, nade_heal_touch);
686 orb.colormod = '1 0 0';
689 void nade_monster_boom(entity this)
691 if(!autocvar_g_monsters)
694 e.noalign = true; // don't drop to floor
695 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
697 return; // monster failed to be spawned
699 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
700 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
701 e.monster_skill = MONSTER_SKILL_INSANE;
704 void nade_veil_touch(entity this, entity toucher)
706 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
708 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
710 float tint_alpha = 0.75;
711 if(SAME_TEAM(toucher, this.realowner))
714 if(!show_tint.nade_veil_time)
716 toucher.nade_veil_prevalpha = toucher.alpha;
720 show_tint.nade_veil_time = time + 0.1;
724 void nade_veil_boom(entity this)
726 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
728 settouch(orb, nade_veil_touch);
729 orb.colormod = NADE_TYPE_VEIL.m_color;
732 void nade_ammo_touch(entity this, entity toucher)
736 float amshells = GetResource(toucher, RES_SHELLS);
737 float ambullets = GetResource(toucher, RES_BULLETS);
738 float amrockets = GetResource(toucher, RES_ROCKETS);
739 float amcells = GetResource(toucher, RES_CELLS);
740 float amplasma = GetResource(toucher, RES_PLASMA);
741 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
742 if(!IS_DEAD(toucher))
743 if(!STAT(FROZEN, toucher))
745 ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
746 if ( toucher != this.realowner )
747 ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
749 #define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
750 if (amresource < maxammo) \
751 GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
753 #define DROP_AMMO_RESOURCE(amresource, res_resource) \
754 if (amresource > 0) \
755 SetResource(toucher, res_resource, amresource + ammo_factor);
757 if ( ammo_factor > 0 )
759 CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
760 CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
761 CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
762 CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
763 CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
765 if (this.nade_show_particles)
766 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
768 else if ( ammo_factor < 0 )
770 //Foe drops ammo points
771 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
772 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
773 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
774 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
775 DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
780 #undef CHECK_AMMO_RESOURCE_LIMIT
781 #undef DROP_AMMO_RESOURCE
783 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
785 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
786 show_tint.nade_ammo_time = time + 0.1;
790 void nade_ammo_boom(entity this)
792 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
794 settouch(orb, nade_ammo_touch);
795 orb.colormod = '0.66 0.33 0';
798 void nade_darkness_think(entity this)
800 if(round_handler_IsActive())
801 if(!round_handler_IsRoundStarted())
807 if(time >= this.ltime)
809 if ( autocvar_g_nades_darkness_explode )
811 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
812 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
813 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
815 normal_nade_boom(this);
818 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
824 this.nextthink = time + 0.1;
829 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
831 randomw = random() * M_PI * 2;
833 randomp.x = randomr * cos(randomw);
834 randomp.y = randomr * sin(randomw);
836 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
838 if(time >= this.nade_special_time)
840 this.nade_special_time = time + 0.7;
841 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
845 float current_dark_time = this.ltime - time - 0.1;
847 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
848 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
850 switch (autocvar_g_nades_darkness_teamcheck)
852 case 0: break; // affect everyone
854 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
855 // fall through (check case 1 condition too)
856 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
858 STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
862 void nade_darkness_boom(entity this)
864 entity fountain = new(nade_darkness_fountain);
865 fountain.owner = this.owner;
866 fountain.realowner = this.realowner;
867 fountain.origin = this.origin;
868 setorigin(fountain, fountain.origin);
869 setthink(fountain, nade_darkness_think);
870 fountain.nextthink = time;
871 fountain.ltime = time + autocvar_g_nades_darkness_time;
872 fountain.pushltime = fountain.wait = fountain.ltime;
873 fountain.team = this.team;
874 set_movetype(fountain, MOVETYPE_TOSS);
875 fountain.projectiledeathtype = DEATH_NADE.m_id;
876 fountain.bot_dodge = false;
877 setsize(fountain, '-16 -16 -16', '16 16 16');
878 fountain.nade_special_time = time + 0.3;
879 fountain.angles = this.angles;
881 if ( autocvar_g_nades_darkness_explode )
883 setmodel(fountain, MDL_PROJECTILE_GRENADE);
884 entity timer = new(nade_timer);
885 setmodel(timer, MDL_NADE_TIMER);
886 setattachment(timer, fountain, "");
887 timer.colormap = this.colormap;
888 timer.glowmod = this.glowmod;
889 setthink(timer, nade_timer_think);
890 timer.nextthink = time;
891 timer.wait = fountain.ltime;
892 timer.owner = fountain;
896 setmodel(fountain, MDL_Null);
899 void nade_boom(entity this)
902 bool nade_blast = true;
904 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
905 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
906 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
907 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
908 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
909 EFFECT_SPAWN_NEUTRAL))))
911 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
913 nade_blast = blast; \
914 expef = exp_effect; \
917 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
919 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
920 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
921 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
922 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
923 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
924 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
925 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
926 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
927 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
928 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
929 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
930 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
932 #undef GET_NADE_TYPE_SPAWN_EFFECT
933 #undef SET_NADE_EFFECT
936 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
938 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
939 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
941 this.event_damage = func_null; // prevent somehow calling damage in the next call
944 normal_nade_boom(this);
947 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
949 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
950 case NADE_TYPE_ICE: nade_ice_boom(this); break;
951 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
952 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
953 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
954 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
955 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
956 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
957 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
958 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
961 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
969 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
970 void nade_pickup(entity this, entity thenade)
972 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
974 // set refire so player can't even
975 this.nade_refire = time + autocvar_g_nades_nade_refire;
976 STAT(NADE_TIMER, this) = 0;
979 this.nade.nade_time_primed = thenade.nade_time_primed;
982 bool CanThrowNade(entity this);
983 void nade_touch(entity this, entity toucher)
986 UpdateCSQCProjectile(this);
988 if(toucher == this.realowner)
989 return; // no this impacts
991 if(autocvar_g_nades_pickup)
992 if(time >= this.spawnshieldtime)
993 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
994 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
995 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
997 nade_pickup(toucher, this);
998 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1002 /*float is_weapclip = 0;
1003 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
1004 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
1005 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
1007 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1009 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1017 PROJECTILE_TOUCH(this, toucher);
1019 //setsize(this, '-2 -2 -2', '2 2 2');
1020 //UpdateCSQCProjectile(this);
1021 if(GetResource(this, RES_HEALTH) == this.max_health)
1023 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1027 this.enemy = toucher;
1031 void nade_beep(entity this)
1033 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1034 setthink(this, nade_boom);
1035 this.nextthink = max(this.wait, time);
1038 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1040 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1042 this.takedamage = DAMAGE_NO;
1047 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1050 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1051 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1056 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
1058 force *= 0.5; // too much
1061 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1064 damage = this.max_health * 0.55;
1066 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1067 damage = this.max_health * 0.1;
1068 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1070 if(!(deathtype & HITTYPE_SECONDARY))
1071 damage = this.max_health * 1.15;
1075 entity death_weapon = DEATH_WEAPONOF(deathtype);
1076 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1078 damage = this.max_health * 0.1;
1082 this.velocity += force;
1083 UpdateCSQCProjectile(this);
1085 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1088 float hp = GetResource(this, RES_HEALTH);
1089 if(hp == this.max_health)
1091 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1092 this.nextthink = max(time + this.nade_lifetime, time);
1093 setthink(this, nade_beep);
1097 SetResource(this, RES_HEALTH, hp);
1099 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1100 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1101 this.realowner = attacker;
1105 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1106 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1108 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1110 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1111 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1116 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1119 nade_burn_spawn(this);
1122 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1127 entity _nade = e.nade;
1131 delete(e.fake_nade);
1134 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1136 makevectors(e.v_angle);
1138 // NOTE: always throw from first weapon entity?
1139 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1141 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1142 + (v_right * autocvar_g_nades_throw_offset.y)
1143 + (v_up * autocvar_g_nades_throw_offset.z);
1145 setorigin(_nade, w_shotorg + offset);
1146 //setmodel(_nade, MDL_PROJECTILE_NADE);
1147 //setattachment(_nade, NULL, "");
1148 PROJECTILE_MAKETRIGGER(_nade);
1149 if(STAT(NADES_SMALL, e))
1150 setsize(_nade, '-8 -8 -8', '8 8 8');
1152 setsize(_nade, '-16 -16 -16', '16 16 16');
1153 set_movetype(_nade, MOVETYPE_BOUNCE);
1155 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1156 if (trace_startsolid)
1157 setorigin(_nade, e.origin);
1159 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1160 _nade.velocity = '0 0 100';
1161 else if(autocvar_g_nades_nade_newton_style == 1)
1162 _nade.velocity = e.velocity + _velocity;
1163 else if(autocvar_g_nades_nade_newton_style == 2)
1164 _nade.velocity = _velocity;
1166 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1169 _nade.realowner = e;
1171 settouch(_nade, nade_touch);
1172 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1173 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1174 _nade.max_health = GetResource(_nade, RES_HEALTH);
1175 _nade.takedamage = DAMAGE_AIM;
1176 _nade.event_damage = nade_damage;
1177 setcefc(_nade, func_null);
1178 _nade.exteriormodeltoclient = NULL;
1179 _nade.traileffectnum = 0;
1180 _nade.teleportable = true;
1181 _nade.pushable = true;
1183 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1184 _nade.damagedbycontents = true;
1185 IL_PUSH(g_damagedbycontents, _nade);
1186 _nade.angles = vectoangles(_nade.velocity);
1187 _nade.flags = FL_PROJECTILE;
1188 IL_PUSH(g_projectiles, _nade);
1189 IL_PUSH(g_bot_dodge, _nade);
1190 _nade.projectiledeathtype = DEATH_NADE.m_id;
1191 _nade.toss_time = time;
1192 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1194 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1195 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1197 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1203 setthink(_nade, nade_boom);
1204 _nade.nextthink = _time;
1207 e.nade_refire = time + autocvar_g_nades_nade_refire;
1208 STAT(NADE_TIMER, e) = 0;
1211 void nades_GiveBonus(entity player, float score)
1213 if (autocvar_g_nades)
1214 if (autocvar_g_nades_bonus)
1215 if (IS_REAL_CLIENT(player))
1216 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1217 if (!STAT(FROZEN, player))
1218 if (!IS_DEAD(player))
1220 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1221 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1223 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1225 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1226 play2(player, SND(NADE_BONUS));
1227 STAT(NADE_BONUS, player)++;
1228 STAT(NADE_BONUS_SCORE, player) -= 1;
1233 /** Remove all bonus nades from a player */
1234 void nades_RemoveBonus(entity player)
1236 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1239 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1241 entity player = M_ARGV(0, entity);
1243 nades_RemoveBonus(player);
1246 bool nade_customize(entity this, entity client)
1248 //if(IS_SPEC(client)) { return false; }
1249 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1251 // somewhat hide the model, but keep the glow
1253 if(this.traileffectnum)
1254 this.traileffectnum = 0;
1259 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1260 if(!this.traileffectnum)
1262 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1263 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1271 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1273 entity n = new(nade), fn = new(fake_nade);
1275 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1276 n.pokenade_type = pntype;
1278 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1279 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1281 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1283 setmodel(n, MDL_PROJECTILE_NADE);
1284 //setattachment(n, player, "bip01 l hand");
1285 n.exteriormodeltoclient = player;
1286 setcefc(n, nade_customize);
1287 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1288 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1289 n.realowner = nowner;
1290 n.colormap = player.colormap;
1291 n.glowmod = player.glowmod;
1292 n.wait = time + max(0, ntime);
1293 n.nade_time_primed = time;
1294 setthink(n, nade_beep);
1295 n.nextthink = max(n.wait - 3, time);
1296 n.projectiledeathtype = DEATH_NADE.m_id;
1297 n.weaponentity_fld = weaponentity;
1298 n.nade_lifetime = ntime;
1299 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1301 setmodel(fn, MDL_NADE_VIEW);
1302 //setattachment(fn, player.(weaponentity), "");
1303 fn.viewmodelforclient = player;
1304 fn.realowner = fn.owner = player;
1305 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1306 fn.colormap = player.colormap;
1307 fn.glowmod = player.glowmod;
1308 setthink(fn, SUB_Remove);
1309 fn.nextthink = n.wait;
1310 fn.weaponentity_fld = weaponentity;
1311 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1314 player.fake_nade = fn;
1317 void nade_prime(entity this)
1319 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1320 return; // only allow bonus nades
1322 // TODO: handle old nade if it exists?
1328 delete(this.fake_nade);
1329 this.fake_nade = NULL;
1332 string pntype = this.pokenade_type;
1334 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1335 ntype = STAT(NADE_BONUS_TYPE, this);
1336 else if (STAT(NADE_BONUS, this) >= 1)
1338 ntype = STAT(NADE_BONUS_TYPE, this);
1339 pntype = this.pokenade_type;
1340 STAT(NADE_BONUS, this) -= 1;
1344 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1345 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1348 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1351 bool CanThrowNade(entity this)
1353 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1356 .bool nade_altbutton;
1358 void nades_CheckThrow(entity this)
1360 if(!CanThrowNade(this))
1363 entity held_nade = this.nade;
1366 this.nade_altbutton = true;
1367 if(time > this.nade_refire)
1370 this.nade_refire = time + autocvar_g_nades_nade_refire;
1375 this.nade_altbutton = false;
1376 if (time >= held_nade.nade_time_primed + 1) {
1377 makevectors(this.v_angle);
1378 float _force = time - held_nade.nade_time_primed;
1379 _force /= autocvar_g_nades_nade_lifetime;
1380 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1381 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1382 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1383 toss_nade(this, true, dir * _force, 0);
1388 void nades_Clear(entity player)
1391 delete(player.nade);
1392 if(player.fake_nade)
1393 delete(player.fake_nade);
1395 player.nade = player.fake_nade = NULL;
1396 STAT(NADE_TIMER, player) = 0;
1399 int nades_CheckTypes(entity player, int cl_ntype)
1401 // TODO check what happens without this patch
1402 #define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \
1403 case nade_ent.m_id: if (nade_cvar) return cl_ntype
1407 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1408 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1409 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1410 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1411 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1412 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1413 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1414 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1415 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1416 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1418 return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types
1419 #undef CL_NADE_TYPE_CHECK
1422 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1424 entity player = M_ARGV(0, entity);
1427 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1430 CLASS(NadeOffhand, OffhandWeapon)
1431 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1433 entity held_nade = player.nade;
1435 if (!CanThrowNade(player)) return;
1436 if (!(time > player.nade_refire)) return;
1440 held_nade = player.nade;
1442 } else if (time >= held_nade.nade_time_primed + 1) {
1444 makevectors(player.v_angle);
1445 float _force = time - held_nade.nade_time_primed;
1446 _force /= autocvar_g_nades_nade_lifetime;
1447 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1448 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1449 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1450 toss_nade(player, false, dir * _force, 0);
1454 ENDCLASS(NadeOffhand)
1455 NadeOffhand OFFHAND_NADE;
1456 REGISTER_MUTATOR(nades, autocvar_g_nades)
1460 OFFHAND_NADE = NEW(NadeOffhand);
1465 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1467 entity player = M_ARGV(0, entity);
1469 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1470 nades_CheckThrow(player);
1475 #ifdef IN_REVIVING_RANGE
1476 #undef IN_REVIVING_RANGE
1479 // returns true if player is reviving it
1480 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1481 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1482 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1484 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1486 entity player = M_ARGV(0, entity);
1488 if (!IS_PLAYER(player)) { return; }
1490 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1491 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1493 entity held_nade = player.nade;
1496 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1497 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1498 makevectors(player.angles);
1499 held_nade.velocity = player.velocity;
1500 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1501 held_nade.angles_y = player.angles.y;
1503 if (time + 0.1 >= held_nade.wait)
1505 toss_nade(player, false, '0 0 0', time + 0.05);
1506 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1510 if(IS_PLAYER(player))
1512 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1515 float key_count = 0;
1516 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1519 if(GameRules_scoring_is_vip(player))
1520 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1522 time_score = autocvar_g_nades_bonus_score_time;
1525 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1527 if(autocvar_g_nades_bonus_client_select)
1529 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1530 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1534 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1535 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1538 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1540 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1541 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1545 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1548 if(player.nade_veil_time && player.nade_veil_time <= time)
1550 player.nade_veil_time = 0;
1552 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1554 player.alpha = player.nade_veil_prevalpha;
1558 if (!(frametime && IS_PLAYER(player)))
1561 entity revivers_last = NULL;
1562 entity revivers_first = NULL;
1564 bool player_is_reviving = false;
1566 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1567 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1568 // check if player is reviving anyone
1569 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1571 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1573 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1575 player_is_reviving = true;
1579 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1580 continue; // both player and it are NOT frozen
1582 revivers_last.chain = it;
1584 if (!revivers_first)
1585 revivers_first = it;
1589 revivers_last.chain = NULL;
1591 if (!n) // no teammate nearby
1593 // freezetag already resets revive progress
1594 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1595 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1597 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1599 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1600 // undo what PlayerPreThink did
1601 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1602 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1604 if(STAT(REVIVE_PROGRESS, player) >= 1)
1606 Unfreeze(player, false);
1608 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1609 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1612 for(entity it = revivers_first; it; it = it.chain)
1613 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1617 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1619 entity player = M_ARGV(0, entity);
1620 // these automatically reset, no need to worry
1622 if(player.nade_entrap_time > time)
1623 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1626 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1628 entity mon = M_ARGV(0, entity);
1630 if (mon.nade_entrap_time > time)
1632 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1633 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1636 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1638 mon.alpha = mon.nade_veil_prevalpha;
1639 mon.nade_veil_time = 0;
1643 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1645 entity player = M_ARGV(0, entity);
1647 player.nade_refire = (autocvar_g_nades_onspawn)
1648 ? time + autocvar_g_nades_nade_refire
1649 : time + autocvar_g_spawnshieldtime;
1651 if(autocvar_g_nades_bonus_client_select)
1652 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1654 STAT(NADE_TIMER, player) = 0;
1656 if (!player.offhand) player.offhand = OFFHAND_NADE;
1658 if(player.nade_spawnloc)
1660 setorigin(player, player.nade_spawnloc.origin);
1661 player.nade_spawnloc.cnt -= 1;
1663 if(player.nade_spawnloc.cnt <= 0)
1665 delete(player.nade_spawnloc);
1666 player.nade_spawnloc = NULL;
1669 if(autocvar_g_nades_spawn_health_respawn > 0)
1670 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1674 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1676 entity frag_attacker = M_ARGV(1, entity);
1677 entity frag_target = M_ARGV(2, entity);
1679 if(frag_target.nade)
1680 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1681 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1683 if(IS_PLAYER(frag_attacker))
1685 float killcount_bonus = ((CS(frag_attacker).killcount >= 1) ? bound(0, autocvar_g_nades_bonus_score_minor * CS(frag_attacker).killcount, autocvar_g_nades_bonus_score_medium)
1686 : autocvar_g_nades_bonus_score_minor);
1687 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1688 nades_RemoveBonus(frag_attacker);
1689 else if(GameRules_scoring_is_vip(frag_target))
1690 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1691 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1693 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1694 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1695 switch(CS(frag_attacker).killcount)
1698 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1703 nades_GiveBonus(frag_attacker, killcount_bonus);
1706 nades_RemoveBonus(frag_target);
1709 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1711 entity frag_inflictor = M_ARGV(0, entity);
1712 entity frag_attacker = M_ARGV(1, entity);
1713 entity frag_target = M_ARGV(2, entity);
1714 float frag_deathtype = M_ARGV(3, float);
1716 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1717 if(time - frag_inflictor.toss_time <= 0.1)
1719 Unfreeze(frag_target, false);
1720 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1721 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1722 M_ARGV(4, float) = 0;
1723 M_ARGV(6, vector) = '0 0 0';
1724 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1725 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1729 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1731 entity frag_target = M_ARGV(0, entity);
1732 entity frag_attacker = M_ARGV(1, entity);
1734 if(IS_PLAYER(frag_attacker))
1735 if(DIFF_TEAM(frag_attacker, frag_target))
1736 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1737 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1740 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1742 entity frag_target = M_ARGV(0, entity);
1744 if(frag_target.nade)
1745 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1748 void nades_RemovePlayer(entity this)
1751 nades_RemoveBonus(this);
1754 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1755 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1756 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1758 FOREACH_CLIENT(IS_PLAYER(it),
1760 nades_RemovePlayer(it);
1764 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1766 entity spectatee = M_ARGV(0, entity);
1767 entity client = M_ARGV(1, entity);
1769 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1770 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1771 client.pokenade_type = spectatee.pokenade_type;
1772 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1773 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1776 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1778 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1781 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1783 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");