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];
44 #include <client/draw.qh>
45 #include <client/hud/hud.qh>
47 bool darkness_fadealpha;
49 void HUD_DarkBlinking()
51 vector bottomright = vec2(vid_conwidth, vid_conheight);
52 drawfill('0 0 0', bottomright, NADE_TYPE_DARKNESS.m_color, darkness_fadealpha, DRAWFLAG_NORMAL);
55 REGISTER_MUTATOR(cl_nades, true);
56 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
58 if (STAT(NADE_DARKNESS_TIME) > time)
60 if (!darkness_fadealpha)
61 sound(csqcplayer, CH_PAIN, SND_BLIND, VOL_BASE, ATTEN_NORM);
62 darkness_fadealpha = min(0.986, darkness_fadealpha + frametime * 7);
64 else if (darkness_fadealpha > 0)
65 darkness_fadealpha = max(0, darkness_fadealpha - frametime * 7);
67 if (darkness_fadealpha > 0)
70 M_ARGV(1, float) = 0; // alpha_multipl 0, don't draw normal overlay
76 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
78 entity proj = M_ARGV(0, entity);
80 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
83 proj.traileffect = EFFECT_FIREBALL.m_id;
86 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
88 setmodel(proj, MDL_PROJECTILE_NADE);
89 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
90 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
94 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
96 if (!mut_is_active(MUT_NADES)) return;
98 entity proj = M_ARGV(0, entity);
100 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
102 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
103 proj.mins = '-16 -16 -16';
104 proj.maxs = '16 16 16';
107 entity nade_type = Nade_FromProjectile(proj.cnt);
108 if (nade_type == NADE_TYPE_Null) return;
110 if(STAT(NADES_SMALL))
112 proj.mins = '-8 -8 -8';
117 proj.mins = '-16 -16 -16';
118 proj.maxs = '16 16 16';
120 proj.colormod = nade_type.m_color;
121 set_movetype(proj, MOVETYPE_BOUNCE);
122 settouch(proj, func_null);
124 proj.avelocity = randomvec() * 720;
125 proj.alphamod = nade_type.m_alpha;
127 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
128 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
130 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
133 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
135 if (mut_is_active(MUT_NADES))
137 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
138 M_ARGV(0, string) = strcat(M_ARGV(0, string),
139 "\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
143 bool Projectile_isnade(int p)
145 return Nade_FromProjectile(p) != NADE_TYPE_Null;
147 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
149 float bonusNades = STAT(NADE_BONUS);
150 float bonusProgress = STAT(NADE_BONUS_SCORE);
151 float bonusType = STAT(NADE_BONUS_TYPE);
152 Nade def = REGISTRY_GET(Nades, bonusType);
153 vector nadeColor = def.m_color;
154 string nadeIcon = def.m_icon;
156 vector iconPos, textPos;
158 if(autocvar_hud_panel_ammo_iconalign)
160 iconPos = myPos + eX * 2 * mySize.y;
166 textPos = myPos + eX * mySize.y;
169 if(bonusNades > 0 || bonusProgress > 0)
171 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
173 if(autocvar_hud_panel_ammo_text)
174 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
177 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
179 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
186 #include <common/gamemodes/_mod.qh>
187 #include <common/monsters/sv_spawn.qh>
188 #include <common/monsters/sv_monsters.qh>
189 #include <server/command/common.qh>
191 .float nade_time_primed;
192 .float nade_lifetime;
194 .entity nade_spawnloc;
197 void nade_timer_think(entity this)
199 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
200 this.nextthink = time;
201 if(!this.owner || wasfreed(this.owner))
205 void nade_burn_spawn(entity _nade)
207 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[1], true);
210 void nade_spawn(entity _nade)
212 entity timer = new(nade_timer);
213 setmodel(timer, MDL_NADE_TIMER);
214 setattachment(timer, _nade, "");
215 timer.colormap = _nade.colormap;
216 timer.glowmod = _nade.glowmod;
217 setthink(timer, nade_timer_think);
218 timer.nextthink = time;
219 timer.wait = _nade.wait;
223 _nade.effects |= EF_LOWPRECISION;
225 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[0], true);
228 void normal_nade_boom(entity this)
230 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
231 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
232 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
233 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
236 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
245 RandomSelection_Init();
246 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
247 if(e.takedamage == DAMAGE_AIM)
248 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
249 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
253 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
254 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
255 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
256 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
259 e.fireball_impactvec = p;
260 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
263 if(RandomSelection_chosen_ent)
265 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
266 d = damage + (edgedamage - damage) * (d / dist);
267 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
268 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
269 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
274 void napalm_ball_think(entity this)
276 if(round_handler_IsActive())
277 if(!round_handler_IsRoundStarted())
283 if(time > this.pushltime)
289 vector midpoint = ((this.absmin + this.absmax) * 0.5);
290 if(pointcontents(midpoint) == CONTENT_WATER)
292 this.velocity = this.velocity * 0.5;
294 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
295 { this.velocity_z = 200; }
298 this.angles = vectoangles(this.velocity);
300 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
301 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
303 this.nextthink = time + 0.1;
307 void nade_napalm_ball(entity this)
312 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
315 proj.owner = this.owner;
316 proj.realowner = this.realowner;
317 proj.team = this.owner.team;
318 proj.bot_dodge = true;
319 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
320 set_movetype(proj, MOVETYPE_BOUNCE);
321 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
322 PROJECTILE_MAKETRIGGER(proj);
323 setmodel(proj, MDL_Null);
324 proj.scale = 1;//0.5;
325 setsize(proj, '-4 -4 -4', '4 4 4');
326 setorigin(proj, this.origin);
327 setthink(proj, napalm_ball_think);
328 proj.nextthink = time;
329 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
330 proj.effects = EF_LOWPRECISION | EF_FLAME;
332 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
333 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
334 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
335 proj.velocity = kick;
337 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
339 proj.angles = vectoangles(proj.velocity);
340 proj.flags = FL_PROJECTILE;
341 IL_PUSH(g_projectiles, proj);
342 IL_PUSH(g_bot_dodge, proj);
343 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
345 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
349 void napalm_fountain_think(entity this)
352 if(round_handler_IsActive())
353 if(!round_handler_IsRoundStarted())
359 if(time >= this.ltime)
365 vector midpoint = ((this.absmin + this.absmax) * 0.5);
366 if(pointcontents(midpoint) == CONTENT_WATER)
368 this.velocity = this.velocity * 0.5;
370 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
371 { this.velocity_z = 200; }
373 UpdateCSQCProjectile(this);
376 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
377 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
379 this.nextthink = time + 0.1;
380 if(time >= this.nade_special_time)
382 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
383 nade_napalm_ball(this);
387 void nade_napalm_boom(entity this)
389 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; ++c)
390 nade_napalm_ball(this);
392 entity fountain = new(nade_napalm_fountain);
393 fountain.owner = this.owner;
394 fountain.realowner = this.realowner;
395 fountain.origin = this.origin;
396 fountain.flags = FL_PROJECTILE;
397 IL_PUSH(g_projectiles, fountain);
398 IL_PUSH(g_bot_dodge, fountain);
399 setorigin(fountain, fountain.origin);
400 setthink(fountain, napalm_fountain_think);
401 fountain.nextthink = time;
402 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
403 fountain.pushltime = fountain.ltime;
404 fountain.team = this.team;
405 set_movetype(fountain, MOVETYPE_TOSS);
406 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
407 fountain.bot_dodge = true;
408 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
409 fountain.nade_special_time = time;
410 setsize(fountain, '-16 -16 -16', '16 16 16');
411 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
414 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
416 frost_target.frozen_by = freezefield.realowner;
417 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
418 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
420 Drop_Special_Items(frost_target);
423 void nade_ice_think(entity this)
425 if(round_handler_IsActive())
426 if(!round_handler_IsRoundStarted())
432 if(time >= this.ltime)
434 if ( autocvar_g_nades_ice_explode )
436 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
437 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
438 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
440 normal_nade_boom(this);
447 this.nextthink = time + 0.1;
452 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
454 randomw = random() * (2 * M_PI);
456 randomp.x = randomr * cos(randomw);
457 randomp.y = randomr * sin(randomw);
459 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
461 if(time >= this.nade_special_time)
463 this.nade_special_time = time + 0.7;
465 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
466 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
470 float current_freeze_time = this.ltime - time - 0.1;
472 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
473 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0
474 && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it),
476 switch (autocvar_g_nades_ice_teamcheck)
478 case 0: break; // affect everyone
480 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
481 // fall through (check case 1 condition too)
482 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
484 nade_ice_freeze(this, it, current_freeze_time);
488 void nade_ice_boom(entity this)
490 entity fountain = new(nade_ice_fountain);
491 fountain.owner = this.owner;
492 fountain.realowner = this.realowner;
493 fountain.origin = this.origin;
494 setorigin(fountain, fountain.origin);
495 setthink(fountain, nade_ice_think);
496 fountain.nextthink = time;
497 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
498 fountain.pushltime = fountain.wait = fountain.ltime;
499 fountain.team = this.team;
500 set_movetype(fountain, MOVETYPE_TOSS);
501 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
502 fountain.bot_dodge = false;
503 setsize(fountain, '-16 -16 -16', '16 16 16');
504 fountain.nade_special_time = time + 0.3;
505 fountain.angles = this.angles;
507 if ( autocvar_g_nades_ice_explode )
509 setmodel(fountain, MDL_PROJECTILE_GRENADE);
510 entity timer = new(nade_timer);
511 setmodel(timer, MDL_NADE_TIMER);
512 setattachment(timer, fountain, "");
513 timer.colormap = this.colormap;
514 timer.glowmod = this.glowmod;
515 setthink(timer, nade_timer_think);
516 timer.nextthink = time;
517 timer.wait = fountain.ltime;
518 timer.owner = fountain;
522 setmodel(fountain, MDL_Null);
525 void nade_translocate_boom(entity this)
527 if(this.realowner.vehicle)
530 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
532 if(!move_out_of_solid(this))
534 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
538 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
539 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
540 locout = trace_endpos;
542 makevectors(this.realowner.angles);
544 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
546 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
549 void nade_spawn_boom(entity this)
551 entity player = this.realowner;
552 entity spawnloc = new(nade_spawn_loc);
553 setorigin(spawnloc, this.origin);
554 setsize(spawnloc, player.mins, player.maxs);
555 set_movetype(spawnloc, MOVETYPE_NONE);
556 spawnloc.solid = SOLID_NOT;
557 spawnloc.drawonlytoclient = player;
558 spawnloc.effects = EF_STARDUST;
559 spawnloc.cnt = autocvar_g_nades_spawn_count;
561 if(player.nade_spawnloc)
562 delete(player.nade_spawnloc);
564 player.nade_spawnloc = spawnloc;
567 void nades_orb_think(entity this)
569 if(time >= this.ltime)
575 this.nextthink = time;
577 if(time >= this.nade_special_time)
579 this.nade_special_time = time+0.25;
580 this.nade_show_particles = 1;
583 this.nade_show_particles = 0;
586 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
588 // NOTE: this function merely places an orb
589 // you must add a custom touch function to the returned entity if desired
590 // also set .colormod if you wish to have it colorized
591 entity orb = new(nades_spawn_orb);
593 orb.realowner = realown;
596 orb.orb_lifetime = orb_ltime; // required for timers
597 orb.ltime = time + orb.orb_lifetime;
598 orb.bot_dodge = false;
599 orb.team = realown.team;
600 orb.solid = SOLID_TRIGGER;
602 setmodel(orb, MDL_NADE_ORB);
604 orb.orb_radius = orb_rad; // required for fading
605 vector size = '1 1 1' * orb.orb_radius / 2;
606 setsize(orb, -size, size);
608 Net_LinkEntity(orb, true, 0, orb_send);
611 setthink(orb, nades_orb_think);
612 orb.nextthink = time;
617 void nade_entrap_touch(entity this, entity toucher)
619 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
621 if (!isPushable(toucher))
624 float pushdeltatime = time - toucher.lastpushtime;
625 if (pushdeltatime > 0.15) pushdeltatime = 0;
626 toucher.lastpushtime = time;
627 if(!pushdeltatime) return;
629 // div0: ticrate independent, 1 = identity (not 20)
630 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
633 UpdateCSQCProjectile(toucher);
637 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
639 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
640 show_tint.nade_entrap_time = time + 0.1;
644 void nade_entrap_boom(entity this)
646 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
648 settouch(orb, nade_entrap_touch);
649 orb.colormod = NADE_TYPE_ENTRAP.m_color;
652 void nade_heal_touch(entity this, entity toucher)
657 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
658 if(!IS_DEAD(toucher))
659 if(!STAT(FROZEN, toucher))
661 health_factor = autocvar_g_nades_heal_rate*frametime/2;
662 if ( toucher != this.realowner )
663 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
665 if ( health_factor > 0 )
667 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
668 float hp = GetResource(toucher, RES_HEALTH);
671 if (this.nade_show_particles)
672 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
674 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
677 else if ( health_factor < 0 )
678 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
682 void nade_heal_boom(entity this)
684 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
686 settouch(orb, nade_heal_touch);
687 orb.colormod = '1 0 0';
690 void nade_monster_boom(entity this)
692 if(!autocvar_g_monsters)
695 e.noalign = true; // don't drop to floor
696 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
698 return; // monster failed to be spawned
700 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
701 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
702 e.monster_skill = MONSTER_SKILL_INSANE;
705 void nade_veil_touch(entity this, entity toucher)
707 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
709 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
711 float tint_alpha = 0.75;
712 if(SAME_TEAM(toucher, this.realowner))
715 if(!show_tint.nade_veil_time)
717 toucher.nade_veil_prevalpha = toucher.alpha;
721 show_tint.nade_veil_time = time + 0.1;
725 void nade_veil_boom(entity this)
727 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
729 settouch(orb, nade_veil_touch);
730 orb.colormod = NADE_TYPE_VEIL.m_color;
733 void nade_ammo_touch(entity this, entity toucher)
737 float amshells = GetResource(toucher, RES_SHELLS);
738 float ambullets = GetResource(toucher, RES_BULLETS);
739 float amrockets = GetResource(toucher, RES_ROCKETS);
740 float amcells = GetResource(toucher, RES_CELLS);
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);
764 if (this.nade_show_particles)
765 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
767 else if ( ammo_factor < 0 )
769 //Foe drops ammo points
770 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
771 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
772 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
773 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
778 #undef CHECK_AMMO_RESOURCE_LIMIT
779 #undef DROP_AMMO_RESOURCE
781 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
783 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
784 show_tint.nade_ammo_time = time + 0.1;
788 void nade_ammo_boom(entity this)
790 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
792 settouch(orb, nade_ammo_touch);
793 orb.colormod = '0.66 0.33 0';
796 void nade_darkness_think(entity this)
798 if(round_handler_IsActive())
799 if(!round_handler_IsRoundStarted())
805 if(time >= this.ltime)
807 if ( autocvar_g_nades_darkness_explode )
809 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
810 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
811 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
813 normal_nade_boom(this);
816 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
822 this.nextthink = time + 0.1;
827 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
829 randomw = random() * (2 * M_PI);
831 randomp.x = randomr * cos(randomw);
832 randomp.y = randomr * sin(randomw);
834 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
836 if(time >= this.nade_special_time)
838 this.nade_special_time = time + 0.7;
839 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
843 float current_dark_time = this.ltime - time - 0.1;
845 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
846 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
848 switch (autocvar_g_nades_darkness_teamcheck)
850 case 0: break; // affect everyone
852 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
853 // fall through (check case 1 condition too)
854 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
856 STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
860 void nade_darkness_boom(entity this)
862 entity fountain = new(nade_darkness_fountain);
863 fountain.owner = this.owner;
864 fountain.realowner = this.realowner;
865 fountain.origin = this.origin;
866 setorigin(fountain, fountain.origin);
867 setthink(fountain, nade_darkness_think);
868 fountain.nextthink = time;
869 fountain.ltime = time + autocvar_g_nades_darkness_time;
870 fountain.pushltime = fountain.wait = fountain.ltime;
871 fountain.team = this.team;
872 set_movetype(fountain, MOVETYPE_TOSS);
873 fountain.projectiledeathtype = DEATH_NADE.m_id;
874 fountain.bot_dodge = false;
875 setsize(fountain, '-16 -16 -16', '16 16 16');
876 fountain.nade_special_time = time + 0.3;
877 fountain.angles = this.angles;
879 if ( autocvar_g_nades_darkness_explode )
881 setmodel(fountain, MDL_PROJECTILE_GRENADE);
882 entity timer = new(nade_timer);
883 setmodel(timer, MDL_NADE_TIMER);
884 setattachment(timer, fountain, "");
885 timer.colormap = this.colormap;
886 timer.glowmod = this.glowmod;
887 setthink(timer, nade_timer_think);
888 timer.nextthink = time;
889 timer.wait = fountain.ltime;
890 timer.owner = fountain;
894 setmodel(fountain, MDL_Null);
897 void nade_boom(entity this)
900 bool nade_blast = true;
902 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
903 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
904 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
905 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
906 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
907 EFFECT_SPAWN_NEUTRAL))))
909 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
911 nade_blast = blast; \
912 expef = exp_effect; \
915 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
917 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
918 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
919 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
920 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
921 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
922 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
923 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
924 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
925 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
926 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
927 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
928 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
930 #undef GET_NADE_TYPE_SPAWN_EFFECT
931 #undef SET_NADE_EFFECT
934 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
936 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
937 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
939 this.event_damage = func_null; // prevent somehow calling damage in the next call
942 normal_nade_boom(this);
945 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
947 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
948 case NADE_TYPE_ICE: nade_ice_boom(this); break;
949 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
950 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
951 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
952 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
953 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
954 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
955 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
956 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
959 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
967 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
968 void nade_pickup(entity this, entity thenade)
970 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
972 // set refire so player can't even
973 this.nade_refire = time + autocvar_g_nades_nade_refire;
974 STAT(NADE_TIMER, this) = 0;
977 this.nade.nade_time_primed = thenade.nade_time_primed;
980 bool CanThrowNade(entity this);
981 void nade_touch(entity this, entity toucher)
984 UpdateCSQCProjectile(this);
986 if(toucher == this.realowner)
987 return; // no this impacts
989 if(autocvar_g_nades_pickup)
990 if(time >= this.spawnshieldtime)
991 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
992 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
993 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
995 nade_pickup(toucher, this);
996 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1000 /*float is_weapclip = 0;
1001 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
1002 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
1003 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
1005 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1007 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1015 PROJECTILE_TOUCH(this, toucher);
1017 //setsize(this, '-2 -2 -2', '2 2 2');
1018 //UpdateCSQCProjectile(this);
1019 if(GetResource(this, RES_HEALTH) == this.max_health)
1021 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1025 this.enemy = toucher;
1029 void nade_beep(entity this)
1031 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1032 setthink(this, nade_boom);
1033 this.nextthink = max(this.wait, time);
1036 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1038 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1040 this.takedamage = DAMAGE_NO;
1045 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1048 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1049 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1054 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1057 damage = this.max_health * 0.55;
1059 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1060 damage = this.max_health * 0.1;
1061 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1063 if(!(deathtype & HITTYPE_SECONDARY))
1064 damage = this.max_health * 1.15;
1068 entity death_weapon = DEATH_WEAPONOF(deathtype);
1069 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1071 damage = this.max_health * 0.1;
1075 this.velocity += force;
1076 UpdateCSQCProjectile(this);
1078 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1081 float hp = GetResource(this, RES_HEALTH);
1082 if(hp == this.max_health)
1084 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1085 this.nextthink = max(time + this.nade_lifetime, time);
1086 setthink(this, nade_beep);
1090 SetResource(this, RES_HEALTH, hp);
1092 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1093 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1094 this.realowner = attacker;
1098 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1099 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1101 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1103 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1104 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1109 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1112 nade_burn_spawn(this);
1115 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1120 entity _nade = e.nade;
1124 delete(e.fake_nade);
1127 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1129 makevectors(e.v_angle);
1131 // NOTE: always throw from first weapon entity?
1132 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1134 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1135 + (v_right * autocvar_g_nades_throw_offset.y)
1136 + (v_up * autocvar_g_nades_throw_offset.z);
1138 setorigin(_nade, w_shotorg + offset);
1139 //setmodel(_nade, MDL_PROJECTILE_NADE);
1140 //setattachment(_nade, NULL, "");
1141 PROJECTILE_MAKETRIGGER(_nade);
1142 if(STAT(NADES_SMALL, e))
1143 setsize(_nade, '-8 -8 -8', '8 8 8');
1145 setsize(_nade, '-16 -16 -16', '16 16 16');
1146 set_movetype(_nade, MOVETYPE_BOUNCE);
1148 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1149 if (trace_startsolid)
1150 setorigin(_nade, e.origin);
1152 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1153 _nade.velocity = '0 0 100';
1154 else if(autocvar_g_nades_nade_newton_style == 1)
1155 _nade.velocity = e.velocity + _velocity;
1156 else if(autocvar_g_nades_nade_newton_style == 2)
1157 _nade.velocity = _velocity;
1159 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1162 _nade.realowner = e;
1164 settouch(_nade, nade_touch);
1165 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1166 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1167 _nade.max_health = GetResource(_nade, RES_HEALTH);
1168 _nade.takedamage = DAMAGE_AIM;
1169 _nade.event_damage = nade_damage;
1170 setcefc(_nade, func_null);
1171 _nade.exteriormodeltoclient = NULL;
1172 _nade.traileffectnum = 0;
1173 _nade.teleportable = true;
1174 _nade.pushable = true;
1176 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1177 _nade.damagedbycontents = true;
1178 IL_PUSH(g_damagedbycontents, _nade);
1179 _nade.angles = vectoangles(_nade.velocity);
1180 _nade.flags = FL_PROJECTILE;
1181 IL_PUSH(g_projectiles, _nade);
1182 IL_PUSH(g_bot_dodge, _nade);
1183 _nade.projectiledeathtype = DEATH_NADE.m_id;
1184 _nade.toss_time = time;
1185 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1187 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1188 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1190 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1196 setthink(_nade, nade_boom);
1197 _nade.nextthink = _time;
1200 e.nade_refire = time + autocvar_g_nades_nade_refire;
1201 STAT(NADE_TIMER, e) = 0;
1204 void nades_GiveBonus(entity player, float score)
1206 if (autocvar_g_nades)
1207 if (autocvar_g_nades_bonus)
1208 if (IS_REAL_CLIENT(player))
1209 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1210 if (!STAT(FROZEN, player))
1211 if (!IS_DEAD(player))
1213 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1214 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1216 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1218 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1219 play2(player, SND(NADE_BONUS));
1220 STAT(NADE_BONUS, player)++;
1221 STAT(NADE_BONUS_SCORE, player) -= 1;
1226 /** Remove all bonus nades from a player */
1227 void nades_RemoveBonus(entity player)
1229 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1232 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1234 entity player = M_ARGV(0, entity);
1236 nades_RemoveBonus(player);
1239 bool nade_customize(entity this, entity client)
1241 //if(IS_SPEC(client)) { return false; }
1242 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1244 // somewhat hide the model, but keep the glow
1246 if(this.traileffectnum)
1247 this.traileffectnum = 0;
1252 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1253 if(!this.traileffectnum)
1255 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1256 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[0], this.team).eent_eff_name);
1264 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1266 entity n = new(nade), fn = new(fake_nade);
1268 n.pokenade_type = pntype;
1270 Nade def = REGISTRY_GET(Nades, max(1, ntype));
1271 if(def == NADE_TYPE_Null)
1272 def = NADE_TYPE_NORMAL;
1274 STAT(NADE_BONUS_TYPE, n) = def.m_id;
1276 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1278 setmodel(n, MDL_PROJECTILE_NADE);
1279 //setattachment(n, player, "bip01 l hand");
1280 n.exteriormodeltoclient = player;
1281 setcefc(n, nade_customize);
1282 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(def.m_projectile[0], player.team).eent_eff_name);
1283 n.colormod = def.m_color;
1284 n.realowner = nowner;
1285 n.colormap = player.colormap;
1286 n.glowmod = player.glowmod;
1287 n.wait = time + max(0, ntime);
1288 n.nade_time_primed = time;
1289 setthink(n, nade_beep);
1290 n.nextthink = max(n.wait - 3, time);
1291 n.projectiledeathtype = DEATH_NADE.m_id;
1292 n.weaponentity_fld = weaponentity;
1293 n.nade_lifetime = ntime;
1294 n.alpha = def.m_alpha;
1296 setmodel(fn, MDL_NADE_VIEW);
1297 //setattachment(fn, player.(weaponentity), "");
1298 fn.viewmodelforclient = player;
1299 fn.realowner = fn.owner = player;
1300 fn.colormod = def.m_color;
1301 fn.colormap = player.colormap;
1302 fn.glowmod = player.glowmod;
1303 setthink(fn, SUB_Remove);
1304 fn.nextthink = n.wait;
1305 fn.weaponentity_fld = weaponentity;
1306 fn.alpha = def.m_alpha;
1309 player.fake_nade = fn;
1312 void nade_prime(entity this)
1314 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1315 return; // only allow bonus nades
1317 // TODO: handle old nade if it exists?
1323 delete(this.fake_nade);
1324 this.fake_nade = NULL;
1327 string pntype = this.pokenade_type;
1329 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1330 ntype = STAT(NADE_BONUS_TYPE, this);
1331 else if (STAT(NADE_BONUS, this) >= 1)
1333 ntype = STAT(NADE_BONUS_TYPE, this);
1334 pntype = this.pokenade_type;
1335 STAT(NADE_BONUS, this) -= 1;
1339 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1340 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1343 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1346 bool CanThrowNade(entity this)
1348 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1351 .bool nade_altbutton;
1353 void nades_CheckThrow(entity this)
1355 if(!CanThrowNade(this))
1358 entity held_nade = this.nade;
1361 this.nade_altbutton = true;
1362 if(time > this.nade_refire)
1365 this.nade_refire = time + autocvar_g_nades_nade_refire;
1370 this.nade_altbutton = false;
1371 if (time >= held_nade.nade_time_primed + 1) {
1372 makevectors(this.v_angle);
1373 float _force = time - held_nade.nade_time_primed;
1374 _force /= autocvar_g_nades_nade_lifetime;
1375 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1376 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1377 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1378 toss_nade(this, true, dir * _force, 0);
1383 void nades_Clear(entity player)
1386 delete(player.nade);
1387 if(player.fake_nade)
1388 delete(player.fake_nade);
1390 player.nade = player.fake_nade = NULL;
1391 STAT(NADE_TIMER, player) = 0;
1394 int nades_CheckTypes(entity player, int cl_ntype)
1396 // TODO check what happens without this patch
1397 #define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \
1398 case nade_ent.m_id: if (nade_cvar) return cl_ntype
1402 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1403 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1404 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1405 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1406 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1407 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1408 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1409 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1410 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1411 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1413 return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types
1414 #undef CL_NADE_TYPE_CHECK
1417 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1419 entity player = M_ARGV(0, entity);
1422 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1425 CLASS(NadeOffhand, OffhandWeapon)
1426 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1428 entity held_nade = player.nade;
1430 if (!CanThrowNade(player)) return;
1431 if (!(time > player.nade_refire)) return;
1435 held_nade = player.nade;
1437 } else if (time >= held_nade.nade_time_primed + 1) {
1439 makevectors(player.v_angle);
1440 float _force = time - held_nade.nade_time_primed;
1441 _force /= autocvar_g_nades_nade_lifetime;
1442 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1443 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1444 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1445 toss_nade(player, false, dir * _force, 0);
1449 ENDCLASS(NadeOffhand)
1450 NadeOffhand OFFHAND_NADE;
1451 REGISTER_MUTATOR(nades, autocvar_g_nades)
1455 OFFHAND_NADE = NEW(NadeOffhand);
1460 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1462 entity player = M_ARGV(0, entity);
1464 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1465 nades_CheckThrow(player);
1470 #ifdef IN_REVIVING_RANGE
1471 #undef IN_REVIVING_RANGE
1474 // returns true if player is reviving it
1475 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1476 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1477 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1479 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1481 entity player = M_ARGV(0, entity);
1483 if (!IS_PLAYER(player)) { return; }
1485 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1486 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1488 entity held_nade = player.nade;
1491 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1492 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1493 makevectors(player.angles);
1494 held_nade.velocity = player.velocity;
1495 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1496 held_nade.angles_y = player.angles.y;
1498 if (time + 0.1 >= held_nade.wait)
1500 toss_nade(player, false, '0 0 0', time + 0.05);
1501 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1505 if(IS_PLAYER(player))
1507 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1510 float key_count = 0;
1511 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1514 if(GameRules_scoring_is_vip(player))
1515 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1517 time_score = autocvar_g_nades_bonus_score_time;
1520 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1522 if(autocvar_g_nades_bonus_client_select)
1524 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1525 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1529 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1530 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1533 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1535 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1536 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1540 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1543 if(player.nade_veil_time && player.nade_veil_time <= time)
1545 player.nade_veil_time = 0;
1547 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1549 player.alpha = player.nade_veil_prevalpha;
1553 if (!(frametime && IS_PLAYER(player)))
1556 entity revivers_last = NULL;
1557 entity revivers_first = NULL;
1559 bool player_is_reviving = false;
1561 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1562 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1563 // check if player is reviving anyone
1564 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1566 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1568 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1570 player_is_reviving = true;
1574 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1575 continue; // both player and it are NOT frozen
1577 revivers_last.chain = it;
1579 if (!revivers_first)
1580 revivers_first = it;
1584 revivers_last.chain = NULL;
1586 if (!n) // no teammate nearby
1588 // freezetag already resets revive progress
1589 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1590 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1592 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1594 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1595 // undo what PlayerPreThink did
1596 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1597 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1599 if(STAT(REVIVE_PROGRESS, player) >= 1)
1601 Unfreeze(player, false);
1603 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1604 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1607 for(entity it = revivers_first; it; it = it.chain)
1608 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1612 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1614 entity player = M_ARGV(0, entity);
1615 // these automatically reset, no need to worry
1617 if(player.nade_entrap_time > time)
1618 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1621 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1623 entity mon = M_ARGV(0, entity);
1625 if (mon.nade_entrap_time > time)
1627 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1628 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1631 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1633 mon.alpha = mon.nade_veil_prevalpha;
1634 mon.nade_veil_time = 0;
1638 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1640 entity player = M_ARGV(0, entity);
1642 if (StatusEffects_active(STATUSEFFECT_SpawnShield, player))
1643 player.nade_refire = StatusEffects_gettime(STATUSEFFECT_SpawnShield, player);
1645 player.nade_refire = time;
1647 if (!autocvar_g_nades_onspawn)
1648 player.nade_refire += autocvar_g_nades_nade_refire;
1650 if(autocvar_g_nades_bonus_client_select)
1651 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1653 STAT(NADE_TIMER, player) = 0;
1655 if (!player.offhand) player.offhand = OFFHAND_NADE;
1657 if(player.nade_spawnloc)
1659 setorigin(player, player.nade_spawnloc.origin);
1660 player.nade_spawnloc.cnt -= 1;
1662 if(player.nade_spawnloc.cnt <= 0)
1664 delete(player.nade_spawnloc);
1665 player.nade_spawnloc = NULL;
1668 if(autocvar_g_nades_spawn_health_respawn > 0)
1669 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1673 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1675 entity frag_attacker = M_ARGV(1, entity);
1676 entity frag_target = M_ARGV(2, entity);
1678 if(frag_target.nade)
1679 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1680 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1682 if(IS_PLAYER(frag_attacker))
1684 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)
1685 : autocvar_g_nades_bonus_score_minor);
1686 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1687 nades_RemoveBonus(frag_attacker);
1688 else if(GameRules_scoring_is_vip(frag_target))
1689 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1690 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1692 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1693 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1694 switch(CS(frag_attacker).killcount)
1697 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1702 nades_GiveBonus(frag_attacker, killcount_bonus);
1705 nades_RemoveBonus(frag_target);
1708 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1710 entity frag_inflictor = M_ARGV(0, entity);
1711 entity frag_attacker = M_ARGV(1, entity);
1712 entity frag_target = M_ARGV(2, entity);
1713 float frag_deathtype = M_ARGV(3, float);
1715 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1716 if(time - frag_inflictor.toss_time <= 0.1)
1718 Unfreeze(frag_target, false);
1719 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1720 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1721 M_ARGV(4, float) = 0;
1722 M_ARGV(6, vector) = '0 0 0';
1723 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1724 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1728 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1730 entity frag_target = M_ARGV(0, entity);
1731 entity frag_attacker = M_ARGV(1, entity);
1733 if(IS_PLAYER(frag_attacker))
1734 if(DIFF_TEAM(frag_attacker, frag_target))
1735 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1736 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1739 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1741 entity frag_target = M_ARGV(0, entity);
1743 if(frag_target.nade)
1744 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1747 void nades_RemovePlayer(entity this)
1750 nades_RemoveBonus(this);
1753 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1754 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1755 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1757 FOREACH_CLIENT(IS_PLAYER(it),
1759 nades_RemovePlayer(it);
1763 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1765 entity spectatee = M_ARGV(0, entity);
1766 entity client = M_ARGV(1, entity);
1768 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1769 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1770 client.pokenade_type = spectatee.pokenade_type;
1771 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1772 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1775 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1777 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1780 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1782 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");