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 REGISTER_MUTATOR(cl_nades, true);
44 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
46 // TODO: make a common orb state!
47 if (STAT(HEALING_ORB) > time)
49 M_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
50 M_ARGV(1, float) = STAT(HEALING_ORB_ALPHA);
53 if (STAT(ENTRAP_ORB) > time)
55 M_ARGV(0, vector) = NADE_TYPE_ENTRAP.m_color;
56 M_ARGV(1, float) = STAT(ENTRAP_ORB_ALPHA);
59 if (STAT(VEIL_ORB) > time)
61 M_ARGV(0, vector) = NADE_TYPE_VEIL.m_color;
62 M_ARGV(1, float) = STAT(VEIL_ORB_ALPHA);
67 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
69 entity proj = M_ARGV(0, entity);
71 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
74 proj.traileffect = EFFECT_FIREBALL.m_id;
77 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
79 setmodel(proj, MDL_PROJECTILE_NADE);
80 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
81 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
85 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
87 entity proj = M_ARGV(0, entity);
89 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
91 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
92 proj.mins = '-16 -16 -16';
93 proj.maxs = '16 16 16';
96 entity nade_type = Nade_FromProjectile(proj.cnt);
97 if (nade_type == NADE_TYPE_Null) return;
100 proj.mins = '-8 -8 -8';
105 proj.mins = '-16 -16 -16';
106 proj.maxs = '16 16 16';
108 proj.colormod = nade_type.m_color;
109 set_movetype(proj, MOVETYPE_BOUNCE);
110 settouch(proj, func_null);
112 proj.avelocity = randomvec() * 720;
113 proj.alphamod = nade_type.m_alpha;
115 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
116 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
118 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
120 bool Projectile_isnade(int p)
122 return Nade_FromProjectile(p) != NADE_TYPE_Null;
124 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
126 float bonusNades = STAT(NADE_BONUS);
127 float bonusProgress = STAT(NADE_BONUS_SCORE);
128 float bonusType = STAT(NADE_BONUS_TYPE);
129 Nade def = REGISTRY_GET(Nades, bonusType);
130 vector nadeColor = def.m_color;
131 string nadeIcon = def.m_icon;
133 vector iconPos, textPos;
135 if(autocvar_hud_panel_ammo_iconalign)
137 iconPos = myPos + eX * 2 * mySize.y;
143 textPos = myPos + eX * mySize.y;
146 if(bonusNades > 0 || bonusProgress > 0)
148 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
150 if(autocvar_hud_panel_ammo_text)
151 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
154 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
156 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
163 #include <common/gamemodes/_mod.qh>
164 #include <common/monsters/sv_spawn.qh>
165 #include <common/monsters/sv_monsters.qh>
167 .float nade_time_primed;
168 .float nade_lifetime;
170 .entity nade_spawnloc;
173 void nade_timer_think(entity this)
175 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
176 this.nextthink = time;
177 if(!this.owner || wasfreed(this.owner))
181 void nade_burn_spawn(entity _nade)
183 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
186 void nade_spawn(entity _nade)
188 entity timer = new(nade_timer);
189 setmodel(timer, MDL_NADE_TIMER);
190 setattachment(timer, _nade, "");
191 timer.colormap = _nade.colormap;
192 timer.glowmod = _nade.glowmod;
193 setthink(timer, nade_timer_think);
194 timer.nextthink = time;
195 timer.wait = _nade.wait;
199 _nade.effects |= EF_LOWPRECISION;
201 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
204 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
213 RandomSelection_Init();
214 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
215 if(e.takedamage == DAMAGE_AIM)
216 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
217 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
221 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
222 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
223 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
224 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
227 e.fireball_impactvec = p;
228 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
231 if(RandomSelection_chosen_ent)
233 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
234 d = damage + (edgedamage - damage) * (d / dist);
235 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
236 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
237 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
242 void napalm_ball_think(entity this)
244 if(round_handler_IsActive())
245 if(!round_handler_IsRoundStarted())
251 if(time > this.pushltime)
257 vector midpoint = ((this.absmin + this.absmax) * 0.5);
258 if(pointcontents(midpoint) == CONTENT_WATER)
260 this.velocity = this.velocity * 0.5;
262 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
263 { this.velocity_z = 200; }
266 this.angles = vectoangles(this.velocity);
268 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
269 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
271 this.nextthink = time + 0.1;
275 void nade_napalm_ball(entity this)
280 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
283 proj.owner = this.owner;
284 proj.realowner = this.realowner;
285 proj.team = this.owner.team;
286 proj.bot_dodge = true;
287 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
288 set_movetype(proj, MOVETYPE_BOUNCE);
289 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
290 PROJECTILE_MAKETRIGGER(proj);
291 setmodel(proj, MDL_Null);
292 proj.scale = 1;//0.5;
293 setsize(proj, '-4 -4 -4', '4 4 4');
294 setorigin(proj, this.origin);
295 setthink(proj, napalm_ball_think);
296 proj.nextthink = time;
297 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
298 proj.effects = EF_LOWPRECISION | EF_FLAME;
300 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
301 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
302 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
303 proj.velocity = kick;
305 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
307 proj.angles = vectoangles(proj.velocity);
308 proj.flags = FL_PROJECTILE;
309 IL_PUSH(g_projectiles, proj);
310 IL_PUSH(g_bot_dodge, proj);
311 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
313 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
317 void napalm_fountain_think(entity this)
320 if(round_handler_IsActive())
321 if(!round_handler_IsRoundStarted())
327 if(time >= this.ltime)
333 vector midpoint = ((this.absmin + this.absmax) * 0.5);
334 if(pointcontents(midpoint) == CONTENT_WATER)
336 this.velocity = this.velocity * 0.5;
338 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
339 { this.velocity_z = 200; }
341 UpdateCSQCProjectile(this);
344 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
345 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
347 this.nextthink = time + 0.1;
348 if(time >= this.nade_special_time)
350 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
351 nade_napalm_ball(this);
355 void nade_napalm_boom(entity this)
357 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
358 nade_napalm_ball(this);
360 entity fountain = new(nade_napalm_fountain);
361 fountain.owner = this.owner;
362 fountain.realowner = this.realowner;
363 fountain.origin = this.origin;
364 fountain.flags = FL_PROJECTILE;
365 IL_PUSH(g_projectiles, fountain);
366 IL_PUSH(g_bot_dodge, fountain);
367 setorigin(fountain, fountain.origin);
368 setthink(fountain, napalm_fountain_think);
369 fountain.nextthink = time;
370 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
371 fountain.pushltime = fountain.ltime;
372 fountain.team = this.team;
373 set_movetype(fountain, MOVETYPE_TOSS);
374 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
375 fountain.bot_dodge = true;
376 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
377 fountain.nade_special_time = time;
378 setsize(fountain, '-16 -16 -16', '16 16 16');
379 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
382 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
384 frost_target.frozen_by = freezefield.realowner;
385 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
386 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
388 Drop_Special_Items(frost_target);
391 void nade_ice_think(entity this)
393 if(round_handler_IsActive())
394 if(!round_handler_IsRoundStarted())
400 if(time >= this.ltime)
402 if ( autocvar_g_nades_ice_explode )
404 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
405 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
406 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
408 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
409 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
410 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
411 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
418 this.nextthink = time+0.1;
423 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
425 randomw = random()*M_PI*2;
427 randomp.x = randomr*cos(randomw);
428 randomp.y = randomr*sin(randomw);
430 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
432 if(time >= this.nade_special_time)
434 this.nade_special_time = time+0.7;
436 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
437 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
441 float current_freeze_time = this.ltime - time - 0.1;
443 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0,
445 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(it, this.realowner) || it == this.realowner))
446 if(!it.revival_time || ((time - it.revival_time) >= 1.5))
447 if(!STAT(FROZEN, it))
448 nade_ice_freeze(this, it, current_freeze_time);
452 void nade_ice_boom(entity this)
454 entity fountain = new(nade_ice_fountain);
455 fountain.owner = this.owner;
456 fountain.realowner = this.realowner;
457 fountain.origin = this.origin;
458 setorigin(fountain, fountain.origin);
459 setthink(fountain, nade_ice_think);
460 fountain.nextthink = time;
461 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
462 fountain.pushltime = fountain.wait = fountain.ltime;
463 fountain.team = this.team;
464 set_movetype(fountain, MOVETYPE_TOSS);
465 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
466 fountain.bot_dodge = false;
467 setsize(fountain, '-16 -16 -16', '16 16 16');
468 fountain.nade_special_time = time+0.3;
469 fountain.angles = this.angles;
471 if ( autocvar_g_nades_ice_explode )
473 setmodel(fountain, MDL_PROJECTILE_GRENADE);
474 entity timer = new(nade_timer);
475 setmodel(timer, MDL_NADE_TIMER);
476 setattachment(timer, fountain, "");
477 timer.colormap = this.colormap;
478 timer.glowmod = this.glowmod;
479 setthink(timer, nade_timer_think);
480 timer.nextthink = time;
481 timer.wait = fountain.ltime;
482 timer.owner = fountain;
486 setmodel(fountain, MDL_Null);
489 void nade_translocate_boom(entity this)
491 if(this.realowner.vehicle)
494 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
495 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
496 locout = trace_endpos;
498 makevectors(this.realowner.angles);
500 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
502 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
505 void nade_spawn_boom(entity this)
507 entity player = this.realowner;
508 entity spawnloc = new(nade_spawn_loc);
509 setorigin(spawnloc, this.origin);
510 setsize(spawnloc, player.mins, player.maxs);
511 set_movetype(spawnloc, MOVETYPE_NONE);
512 spawnloc.solid = SOLID_NOT;
513 spawnloc.drawonlytoclient = player;
514 spawnloc.effects = EF_STARDUST;
515 spawnloc.cnt = autocvar_g_nades_spawn_count;
517 if(player.nade_spawnloc)
518 delete(player.nade_spawnloc);
520 player.nade_spawnloc = spawnloc;
523 void nades_orb_think(entity this)
525 if(time >= this.ltime)
531 this.nextthink = time;
533 if(time >= this.nade_special_time)
535 this.nade_special_time = time+0.25;
536 this.nade_show_particles = 1;
539 this.nade_show_particles = 0;
542 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
544 // NOTE: this function merely places an orb
545 // you must add a custom touch function to the returned entity if desired
546 // also set .colormod if you wish to have it colorized
547 entity orb = new(nades_spawn_orb);
549 orb.realowner = realown;
552 orb.orb_lifetime = orb_ltime; // required for timers
553 orb.ltime = time + orb.orb_lifetime;
554 orb.bot_dodge = false;
555 orb.team = realown.team;
556 orb.solid = SOLID_TRIGGER;
558 setmodel(orb, MDL_NADE_ORB);
560 orb.orb_radius = orb_rad; // required for fading
561 vector size = '1 1 1' * orb.orb_radius / 2;
562 setsize(orb, -size, size);
564 Net_LinkEntity(orb, true, 0, orb_send);
567 setthink(orb, nades_orb_think);
568 orb.nextthink = time;
573 void nade_entrap_touch(entity this, entity toucher)
575 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
577 if (!isPushable(toucher))
580 float pushdeltatime = time - toucher.lastpushtime;
581 if (pushdeltatime > 0.15) pushdeltatime = 0;
582 toucher.lastpushtime = time;
583 if(!pushdeltatime) return;
585 // div0: ticrate independent, 1 = identity (not 20)
586 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
589 UpdateCSQCProjectile(toucher);
593 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
595 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
596 STAT(ENTRAP_ORB, show_tint) = time + 0.1;
598 float tint_alpha = 0.75;
599 if(SAME_TEAM(toucher, this.realowner))
601 STAT(ENTRAP_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
605 void nade_entrap_boom(entity this)
607 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
609 settouch(orb, nade_entrap_touch);
610 orb.colormod = NADE_TYPE_ENTRAP.m_color;
613 void nade_heal_touch(entity this, entity toucher)
617 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
618 if(!IS_DEAD(toucher))
619 if(!STAT(FROZEN, toucher))
621 health_factor = autocvar_g_nades_heal_rate*frametime/2;
622 if ( toucher != this.realowner )
624 if ( SAME_TEAM(toucher,this) )
625 health_factor *= autocvar_g_nades_heal_friend;
627 health_factor *= autocvar_g_nades_heal_foe;
629 if ( health_factor > 0 )
631 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
632 float hp = GetResource(toucher, RES_HEALTH);
635 if (this.nade_show_particles)
637 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
639 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
642 else if ( health_factor < 0 )
644 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
649 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
651 entity show_red = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
652 STAT(HEALING_ORB, show_red) = time+0.1;
653 STAT(HEALING_ORB_ALPHA, show_red) = 0.75 * (this.ltime - time) / this.orb_lifetime;
657 void nade_heal_boom(entity this)
659 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
661 settouch(orb, nade_heal_touch);
662 orb.colormod = '1 0 0';
665 void nade_monster_boom(entity this)
668 e.noalign = true; // don't drop to floor
669 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
671 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
672 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
673 e.monster_skill = MONSTER_SKILL_INSANE;
676 void nade_veil_touch(entity this, entity toucher)
678 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
680 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
682 float tint_alpha = 0.75;
683 if(SAME_TEAM(toucher, this.realowner))
686 if(!STAT(VEIL_ORB, show_tint))
688 toucher.nade_veil_prevalpha = toucher.alpha;
692 STAT(VEIL_ORB, show_tint) = time + 0.1;
693 STAT(VEIL_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
697 void nade_veil_boom(entity this)
699 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
701 settouch(orb, nade_veil_touch);
702 orb.colormod = NADE_TYPE_VEIL.m_color;
705 void nade_boom(entity this)
708 bool nade_blast = true;
710 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
712 case NADE_TYPE_NAPALM:
713 nade_blast = autocvar_g_nades_napalm_blast;
714 expef = EFFECT_EXPLOSION_MEDIUM;
718 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
720 case NADE_TYPE_TRANSLOCATE:
723 case NADE_TYPE_MONSTER:
724 case NADE_TYPE_SPAWN:
726 switch(this.realowner.team)
728 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
729 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
730 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
731 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
732 default: expef = EFFECT_SPAWN_NEUTRAL; break;
737 expef = EFFECT_SPAWN_RED;
740 case NADE_TYPE_ENTRAP:
742 expef = EFFECT_SPAWN_YELLOW;
747 expef = EFFECT_SPAWN_NEUTRAL;
751 case NADE_TYPE_NORMAL:
752 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
757 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
759 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
760 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
762 this.event_damage = func_null; // prevent somehow calling damage in the next call
766 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
767 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
768 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
772 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
774 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
775 case NADE_TYPE_ICE: nade_ice_boom(this); break;
776 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
777 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
778 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
779 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
780 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
781 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
784 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
792 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
793 void nade_pickup(entity this, entity thenade)
795 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
797 // set refire so player can't even
798 this.nade_refire = time + autocvar_g_nades_nade_refire;
799 STAT(NADE_TIMER, this) = 0;
802 this.nade.nade_time_primed = thenade.nade_time_primed;
805 bool CanThrowNade(entity this);
806 void nade_touch(entity this, entity toucher)
809 UpdateCSQCProjectile(this);
811 if(toucher == this.realowner)
812 return; // no this impacts
814 if(autocvar_g_nades_pickup)
815 if(time >= this.spawnshieldtime)
816 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
817 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
818 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
820 nade_pickup(toucher, this);
821 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
825 /*float is_weapclip = 0;
826 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
827 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
828 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
830 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
832 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
840 PROJECTILE_TOUCH(this, toucher);
842 //setsize(this, '-2 -2 -2', '2 2 2');
843 //UpdateCSQCProjectile(this);
844 if(GetResource(this, RES_HEALTH) == this.max_health)
846 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
850 this.enemy = toucher;
854 void nade_beep(entity this)
856 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
857 setthink(this, nade_boom);
858 this.nextthink = max(this.wait, time);
861 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
863 if(ITEM_DAMAGE_NEEDKILL(deathtype))
865 this.takedamage = DAMAGE_NO;
870 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
873 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
874 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
879 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
881 force *= 0.5; // too much
884 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
887 damage = this.max_health * 0.55;
889 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
890 damage = this.max_health * 0.1;
891 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
893 if(!(deathtype & HITTYPE_SECONDARY))
894 damage = this.max_health * 1.15;
898 entity death_weapon = DEATH_WEAPONOF(deathtype);
899 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
901 damage = this.max_health * 0.1;
905 this.velocity += force;
906 UpdateCSQCProjectile(this);
908 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
911 float hp = GetResource(this, RES_HEALTH);
912 if(hp == this.max_health)
914 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
915 this.nextthink = max(time + this.nade_lifetime, time);
916 setthink(this, nade_beep);
920 SetResource(this, RES_HEALTH, hp);
923 if ( STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
924 this.realowner = attacker;
927 W_PrepareExplosionByDamage(this, attacker, nade_boom);
929 nade_burn_spawn(this);
932 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
937 entity _nade = e.nade;
944 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
946 makevectors(e.v_angle);
948 // NOTE: always throw from first weapon entity?
949 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
951 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
952 + (v_right * autocvar_g_nades_throw_offset.y)
953 + (v_up * autocvar_g_nades_throw_offset.z);
955 setorigin(_nade, w_shotorg + offset);
956 //setmodel(_nade, MDL_PROJECTILE_NADE);
957 //setattachment(_nade, NULL, "");
958 PROJECTILE_MAKETRIGGER(_nade);
959 if(STAT(NADES_SMALL, e))
960 setsize(_nade, '-8 -8 -8', '8 8 8');
962 setsize(_nade, '-16 -16 -16', '16 16 16');
963 set_movetype(_nade, MOVETYPE_BOUNCE);
965 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
966 if (trace_startsolid)
967 setorigin(_nade, e.origin);
969 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
970 _nade.velocity = '0 0 100';
971 else if(autocvar_g_nades_nade_newton_style == 1)
972 _nade.velocity = e.velocity + _velocity;
973 else if(autocvar_g_nades_nade_newton_style == 2)
974 _nade.velocity = _velocity;
976 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
981 settouch(_nade, nade_touch);
982 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
983 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
984 _nade.max_health = GetResource(_nade, RES_HEALTH);
985 _nade.takedamage = DAMAGE_AIM;
986 _nade.event_damage = nade_damage;
987 setcefc(_nade, func_null);
988 _nade.exteriormodeltoclient = NULL;
989 _nade.traileffectnum = 0;
990 _nade.teleportable = true;
991 _nade.pushable = true;
993 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
994 _nade.damagedbycontents = true;
995 IL_PUSH(g_damagedbycontents, _nade);
996 _nade.angles = vectoangles(_nade.velocity);
997 _nade.flags = FL_PROJECTILE;
998 IL_PUSH(g_projectiles, _nade);
999 IL_PUSH(g_bot_dodge, _nade);
1000 _nade.projectiledeathtype = DEATH_NADE.m_id;
1001 _nade.toss_time = time;
1002 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1004 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1005 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1007 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1013 setthink(_nade, nade_boom);
1014 _nade.nextthink = _time;
1017 e.nade_refire = time + autocvar_g_nades_nade_refire;
1018 STAT(NADE_TIMER, e) = 0;
1021 void nades_GiveBonus(entity player, float score)
1023 if (autocvar_g_nades)
1024 if (autocvar_g_nades_bonus)
1025 if (IS_REAL_CLIENT(player))
1026 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1027 if (!STAT(FROZEN, player))
1028 if (!IS_DEAD(player))
1030 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1031 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1033 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1035 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1036 play2(player, SND(NADE_BONUS));
1037 STAT(NADE_BONUS, player)++;
1038 STAT(NADE_BONUS_SCORE, player) -= 1;
1043 /** Remove all bonus nades from a player */
1044 void nades_RemoveBonus(entity player)
1046 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1049 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1051 entity player = M_ARGV(0, entity);
1053 nades_RemoveBonus(player);
1056 bool nade_customize(entity this, entity client)
1058 //if(IS_SPEC(client)) { return false; }
1059 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1061 // somewhat hide the model, but keep the glow
1063 if(this.traileffectnum)
1064 this.traileffectnum = 0;
1069 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1070 if(!this.traileffectnum)
1072 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1073 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1081 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1083 entity n = new(nade), fn = new(fake_nade);
1085 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1086 n.pokenade_type = pntype;
1088 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1089 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1091 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1093 setmodel(n, MDL_PROJECTILE_NADE);
1094 //setattachment(n, player, "bip01 l hand");
1095 n.exteriormodeltoclient = player;
1096 setcefc(n, nade_customize);
1097 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1098 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1099 n.realowner = nowner;
1100 n.colormap = player.colormap;
1101 n.glowmod = player.glowmod;
1102 n.wait = time + max(0, ntime);
1103 n.nade_time_primed = time;
1104 setthink(n, nade_beep);
1105 n.nextthink = max(n.wait - 3, time);
1106 n.projectiledeathtype = DEATH_NADE.m_id;
1107 n.weaponentity_fld = weaponentity;
1108 n.nade_lifetime = ntime;
1109 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1111 setmodel(fn, MDL_NADE_VIEW);
1112 //setattachment(fn, player.(weaponentity), "");
1113 fn.viewmodelforclient = player;
1114 fn.realowner = fn.owner = player;
1115 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1116 fn.colormap = player.colormap;
1117 fn.glowmod = player.glowmod;
1118 setthink(fn, SUB_Remove);
1119 fn.nextthink = n.wait;
1120 fn.weaponentity_fld = weaponentity;
1121 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1124 player.fake_nade = fn;
1127 void nade_prime(entity this)
1129 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1130 return; // only allow bonus nades
1132 // TODO: handle old nade if it exists?
1138 delete(this.fake_nade);
1139 this.fake_nade = NULL;
1142 string pntype = this.pokenade_type;
1144 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1145 ntype = STAT(NADE_BONUS_TYPE, this);
1146 else if (STAT(NADE_BONUS, this) >= 1)
1148 ntype = STAT(NADE_BONUS_TYPE, this);
1149 pntype = this.pokenade_type;
1150 STAT(NADE_BONUS, this) -= 1;
1154 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1155 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1158 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1161 bool CanThrowNade(entity this)
1163 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1166 .bool nade_altbutton;
1168 void nades_CheckThrow(entity this)
1170 if(!CanThrowNade(this))
1173 entity held_nade = this.nade;
1176 this.nade_altbutton = true;
1177 if(time > this.nade_refire)
1180 this.nade_refire = time + autocvar_g_nades_nade_refire;
1185 this.nade_altbutton = false;
1186 if (time >= held_nade.nade_time_primed + 1) {
1187 makevectors(this.v_angle);
1188 float _force = time - held_nade.nade_time_primed;
1189 _force /= autocvar_g_nades_nade_lifetime;
1190 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1191 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1192 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1193 toss_nade(this, true, dir * _force, 0);
1198 void nades_Clear(entity player)
1201 delete(player.nade);
1202 if(player.fake_nade)
1203 delete(player.fake_nade);
1205 player.nade = player.fake_nade = NULL;
1206 STAT(NADE_TIMER, player) = 0;
1209 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1211 entity player = M_ARGV(0, entity);
1214 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1217 CLASS(NadeOffhand, OffhandWeapon)
1218 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1220 entity held_nade = player.nade;
1222 if (!CanThrowNade(player)) return;
1223 if (!(time > player.nade_refire)) return;
1227 held_nade = player.nade;
1229 } else if (time >= held_nade.nade_time_primed + 1) {
1231 makevectors(player.v_angle);
1232 float _force = time - held_nade.nade_time_primed;
1233 _force /= autocvar_g_nades_nade_lifetime;
1234 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1235 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1236 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1237 toss_nade(player, false, dir * _force, 0);
1241 ENDCLASS(NadeOffhand)
1242 NadeOffhand OFFHAND_NADE;
1243 REGISTER_MUTATOR(nades, autocvar_g_nades)
1247 OFFHAND_NADE = NEW(NadeOffhand);
1252 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1254 entity player = M_ARGV(0, entity);
1256 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1257 nades_CheckThrow(player);
1262 #ifdef IN_REVIVING_RANGE
1263 #undef IN_REVIVING_RANGE
1266 // returns true if player is reviving it
1267 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1268 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1269 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1271 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1273 entity player = M_ARGV(0, entity);
1275 if (!IS_PLAYER(player)) { return; }
1277 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1278 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1280 entity held_nade = player.nade;
1283 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1284 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1285 makevectors(player.angles);
1286 held_nade.velocity = player.velocity;
1287 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1288 held_nade.angles_y = player.angles.y;
1290 if (time + 0.1 >= held_nade.wait)
1292 toss_nade(player, false, '0 0 0', time + 0.05);
1293 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1297 if(IS_PLAYER(player))
1299 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1302 float key_count = 0;
1303 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1306 if(GameRules_scoring_is_vip(player))
1307 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1309 time_score = autocvar_g_nades_bonus_score_time;
1312 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1314 if(autocvar_g_nades_bonus_client_select)
1316 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1317 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1321 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1322 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1325 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1327 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1328 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1332 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1335 if(STAT(VEIL_ORB, player) && STAT(VEIL_ORB, player) <= time)
1337 STAT(VEIL_ORB, player) = 0;
1339 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1341 player.alpha = player.nade_veil_prevalpha;
1345 if (!(frametime && IS_PLAYER(player)))
1348 entity revivers_last = NULL;
1349 entity revivers_first = NULL;
1351 bool player_is_reviving = false;
1353 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1354 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1355 // check if player is reviving anyone
1356 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1358 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1360 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1362 player_is_reviving = true;
1366 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1367 continue; // both player and it are NOT frozen
1369 revivers_last.chain = it;
1371 if (!revivers_first)
1372 revivers_first = it;
1376 revivers_last.chain = NULL;
1378 if (!n) // no teammate nearby
1380 // freezetag already resets revive progress
1381 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1382 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1384 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1386 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1387 // undo what PlayerPreThink did
1388 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1389 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1391 if(STAT(REVIVE_PROGRESS, player) >= 1)
1393 Unfreeze(player, false);
1395 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1396 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1399 for(entity it = revivers_first; it; it = it.chain)
1400 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1404 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1406 entity player = M_ARGV(0, entity);
1407 // these automatically reset, no need to worry
1409 if(STAT(ENTRAP_ORB, player) > time)
1410 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1413 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1415 entity mon = M_ARGV(0, entity);
1417 if (STAT(ENTRAP_ORB, mon) > time)
1419 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1420 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1423 if (STAT(VEIL_ORB, mon) && STAT(VEIL_ORB, mon) <= time)
1425 mon.alpha = mon.nade_veil_prevalpha;
1426 STAT(VEIL_ORB, mon) = 0;
1430 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1432 entity player = M_ARGV(0, entity);
1434 if(autocvar_g_nades_spawn)
1435 player.nade_refire = time + autocvar_g_spawnshieldtime;
1437 player.nade_refire = time + autocvar_g_nades_nade_refire;
1439 if(autocvar_g_nades_bonus_client_select)
1440 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1442 STAT(NADE_TIMER, player) = 0;
1444 if (!player.offhand) player.offhand = OFFHAND_NADE;
1446 if(player.nade_spawnloc)
1448 setorigin(player, player.nade_spawnloc.origin);
1449 player.nade_spawnloc.cnt -= 1;
1451 if(player.nade_spawnloc.cnt <= 0)
1453 delete(player.nade_spawnloc);
1454 player.nade_spawnloc = NULL;
1459 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1461 entity frag_attacker = M_ARGV(1, entity);
1462 entity frag_target = M_ARGV(2, entity);
1464 if(frag_target.nade)
1465 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1466 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1468 if(IS_PLAYER(frag_attacker))
1470 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)
1471 : autocvar_g_nades_bonus_score_minor);
1472 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1473 nades_RemoveBonus(frag_attacker);
1474 else if(GameRules_scoring_is_vip(frag_target))
1475 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1476 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1478 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1479 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1480 switch(CS(frag_attacker).killcount)
1483 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1488 nades_GiveBonus(frag_attacker, killcount_bonus);
1491 nades_RemoveBonus(frag_target);
1494 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1496 entity frag_inflictor = M_ARGV(0, entity);
1497 entity frag_attacker = M_ARGV(1, entity);
1498 entity frag_target = M_ARGV(2, entity);
1499 float frag_deathtype = M_ARGV(3, float);
1501 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1502 if(time - frag_inflictor.toss_time <= 0.1)
1504 Unfreeze(frag_target, false);
1505 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1506 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1507 M_ARGV(4, float) = 0;
1508 M_ARGV(6, vector) = '0 0 0';
1509 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1510 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1514 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1516 entity frag_target = M_ARGV(0, entity);
1517 entity frag_attacker = M_ARGV(1, entity);
1519 if(IS_PLAYER(frag_attacker))
1520 if(DIFF_TEAM(frag_attacker, frag_target))
1521 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1522 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1525 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1527 entity frag_target = M_ARGV(0, entity);
1529 if(frag_target.nade)
1530 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1533 void nades_RemovePlayer(entity this)
1536 nades_RemoveBonus(this);
1539 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1540 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1541 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1543 FOREACH_CLIENT(IS_PLAYER(it),
1545 nades_RemovePlayer(it);
1549 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1551 entity spectatee = M_ARGV(0, entity);
1552 entity client = M_ARGV(1, entity);
1554 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1555 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1556 client.pokenade_type = spectatee.pokenade_type;
1557 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1558 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1559 STAT(HEALING_ORB, client) = STAT(HEALING_ORB, spectatee);
1560 STAT(HEALING_ORB_ALPHA, client) = STAT(HEALING_ORB_ALPHA, spectatee);
1561 STAT(ENTRAP_ORB, client) = STAT(ENTRAP_ORB, spectatee);
1562 STAT(ENTRAP_ORB_ALPHA, client) = STAT(ENTRAP_ORB_ALPHA, spectatee);
1563 STAT(VEIL_ORB, client) = STAT(VEIL_ORB, spectatee);
1564 STAT(VEIL_ORB_ALPHA, client) = STAT(VEIL_ORB_ALPHA, spectatee);
1567 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1569 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");
1572 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1574 M_ARGV(0, string) = strcat(M_ARGV(0, string), "\n\n^3nades^8 are enabled, press 'g' (dropweapon) to use them\n");