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;
121 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
123 if (mut_is_active(MUT_NADES))
125 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
126 M_ARGV(0, string) = strcat(M_ARGV(0, string),
127 "\n\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
131 bool Projectile_isnade(int p)
133 return Nade_FromProjectile(p) != NADE_TYPE_Null;
135 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
137 float bonusNades = STAT(NADE_BONUS);
138 float bonusProgress = STAT(NADE_BONUS_SCORE);
139 float bonusType = STAT(NADE_BONUS_TYPE);
140 Nade def = REGISTRY_GET(Nades, bonusType);
141 vector nadeColor = def.m_color;
142 string nadeIcon = def.m_icon;
144 vector iconPos, textPos;
146 if(autocvar_hud_panel_ammo_iconalign)
148 iconPos = myPos + eX * 2 * mySize.y;
154 textPos = myPos + eX * mySize.y;
157 if(bonusNades > 0 || bonusProgress > 0)
159 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
161 if(autocvar_hud_panel_ammo_text)
162 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
165 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
167 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
174 #include <common/gamemodes/_mod.qh>
175 #include <common/monsters/sv_spawn.qh>
176 #include <common/monsters/sv_monsters.qh>
178 .float nade_time_primed;
179 .float nade_lifetime;
181 .entity nade_spawnloc;
184 void nade_timer_think(entity this)
186 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
187 this.nextthink = time;
188 if(!this.owner || wasfreed(this.owner))
192 void nade_burn_spawn(entity _nade)
194 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
197 void nade_spawn(entity _nade)
199 entity timer = new(nade_timer);
200 setmodel(timer, MDL_NADE_TIMER);
201 setattachment(timer, _nade, "");
202 timer.colormap = _nade.colormap;
203 timer.glowmod = _nade.glowmod;
204 setthink(timer, nade_timer_think);
205 timer.nextthink = time;
206 timer.wait = _nade.wait;
210 _nade.effects |= EF_LOWPRECISION;
212 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
215 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
224 RandomSelection_Init();
225 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
226 if(e.takedamage == DAMAGE_AIM)
227 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
228 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
232 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
233 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
234 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
235 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
238 e.fireball_impactvec = p;
239 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
242 if(RandomSelection_chosen_ent)
244 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
245 d = damage + (edgedamage - damage) * (d / dist);
246 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
247 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
248 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
253 void napalm_ball_think(entity this)
255 if(round_handler_IsActive())
256 if(!round_handler_IsRoundStarted())
262 if(time > this.pushltime)
268 vector midpoint = ((this.absmin + this.absmax) * 0.5);
269 if(pointcontents(midpoint) == CONTENT_WATER)
271 this.velocity = this.velocity * 0.5;
273 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
274 { this.velocity_z = 200; }
277 this.angles = vectoangles(this.velocity);
279 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
280 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
282 this.nextthink = time + 0.1;
286 void nade_napalm_ball(entity this)
291 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
294 proj.owner = this.owner;
295 proj.realowner = this.realowner;
296 proj.team = this.owner.team;
297 proj.bot_dodge = true;
298 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
299 set_movetype(proj, MOVETYPE_BOUNCE);
300 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
301 PROJECTILE_MAKETRIGGER(proj);
302 setmodel(proj, MDL_Null);
303 proj.scale = 1;//0.5;
304 setsize(proj, '-4 -4 -4', '4 4 4');
305 setorigin(proj, this.origin);
306 setthink(proj, napalm_ball_think);
307 proj.nextthink = time;
308 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
309 proj.effects = EF_LOWPRECISION | EF_FLAME;
311 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
312 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
313 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
314 proj.velocity = kick;
316 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
318 proj.angles = vectoangles(proj.velocity);
319 proj.flags = FL_PROJECTILE;
320 IL_PUSH(g_projectiles, proj);
321 IL_PUSH(g_bot_dodge, proj);
322 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
324 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
328 void napalm_fountain_think(entity this)
331 if(round_handler_IsActive())
332 if(!round_handler_IsRoundStarted())
338 if(time >= this.ltime)
344 vector midpoint = ((this.absmin + this.absmax) * 0.5);
345 if(pointcontents(midpoint) == CONTENT_WATER)
347 this.velocity = this.velocity * 0.5;
349 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
350 { this.velocity_z = 200; }
352 UpdateCSQCProjectile(this);
355 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
356 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
358 this.nextthink = time + 0.1;
359 if(time >= this.nade_special_time)
361 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
362 nade_napalm_ball(this);
366 void nade_napalm_boom(entity this)
368 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
369 nade_napalm_ball(this);
371 entity fountain = new(nade_napalm_fountain);
372 fountain.owner = this.owner;
373 fountain.realowner = this.realowner;
374 fountain.origin = this.origin;
375 fountain.flags = FL_PROJECTILE;
376 IL_PUSH(g_projectiles, fountain);
377 IL_PUSH(g_bot_dodge, fountain);
378 setorigin(fountain, fountain.origin);
379 setthink(fountain, napalm_fountain_think);
380 fountain.nextthink = time;
381 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
382 fountain.pushltime = fountain.ltime;
383 fountain.team = this.team;
384 set_movetype(fountain, MOVETYPE_TOSS);
385 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
386 fountain.bot_dodge = true;
387 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
388 fountain.nade_special_time = time;
389 setsize(fountain, '-16 -16 -16', '16 16 16');
390 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
393 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
395 frost_target.frozen_by = freezefield.realowner;
396 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
397 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
399 Drop_Special_Items(frost_target);
402 void nade_ice_think(entity this)
404 if(round_handler_IsActive())
405 if(!round_handler_IsRoundStarted())
411 if(time >= this.ltime)
413 if ( autocvar_g_nades_ice_explode )
415 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
416 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
417 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
419 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
420 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
421 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
422 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
429 this.nextthink = time+0.1;
434 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
436 randomw = random()*M_PI*2;
438 randomp.x = randomr*cos(randomw);
439 randomp.y = randomr*sin(randomw);
441 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
443 if(time >= this.nade_special_time)
445 this.nade_special_time = time+0.7;
447 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
448 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
452 float current_freeze_time = this.ltime - time - 0.1;
454 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,
456 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(it, this.realowner) || it == this.realowner))
457 if(!it.revival_time || ((time - it.revival_time) >= 1.5))
458 if(!STAT(FROZEN, it))
459 nade_ice_freeze(this, it, current_freeze_time);
463 void nade_ice_boom(entity this)
465 entity fountain = new(nade_ice_fountain);
466 fountain.owner = this.owner;
467 fountain.realowner = this.realowner;
468 fountain.origin = this.origin;
469 setorigin(fountain, fountain.origin);
470 setthink(fountain, nade_ice_think);
471 fountain.nextthink = time;
472 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
473 fountain.pushltime = fountain.wait = fountain.ltime;
474 fountain.team = this.team;
475 set_movetype(fountain, MOVETYPE_TOSS);
476 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
477 fountain.bot_dodge = false;
478 setsize(fountain, '-16 -16 -16', '16 16 16');
479 fountain.nade_special_time = time+0.3;
480 fountain.angles = this.angles;
482 if ( autocvar_g_nades_ice_explode )
484 setmodel(fountain, MDL_PROJECTILE_GRENADE);
485 entity timer = new(nade_timer);
486 setmodel(timer, MDL_NADE_TIMER);
487 setattachment(timer, fountain, "");
488 timer.colormap = this.colormap;
489 timer.glowmod = this.glowmod;
490 setthink(timer, nade_timer_think);
491 timer.nextthink = time;
492 timer.wait = fountain.ltime;
493 timer.owner = fountain;
497 setmodel(fountain, MDL_Null);
500 void nade_translocate_boom(entity this)
502 if(this.realowner.vehicle)
505 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
506 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
507 locout = trace_endpos;
509 makevectors(this.realowner.angles);
511 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
513 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
516 void nade_spawn_boom(entity this)
518 entity player = this.realowner;
519 entity spawnloc = new(nade_spawn_loc);
520 setorigin(spawnloc, this.origin);
521 setsize(spawnloc, player.mins, player.maxs);
522 set_movetype(spawnloc, MOVETYPE_NONE);
523 spawnloc.solid = SOLID_NOT;
524 spawnloc.drawonlytoclient = player;
525 spawnloc.effects = EF_STARDUST;
526 spawnloc.cnt = autocvar_g_nades_spawn_count;
528 if(player.nade_spawnloc)
529 delete(player.nade_spawnloc);
531 player.nade_spawnloc = spawnloc;
534 void nades_orb_think(entity this)
536 if(time >= this.ltime)
542 this.nextthink = time;
544 if(time >= this.nade_special_time)
546 this.nade_special_time = time+0.25;
547 this.nade_show_particles = 1;
550 this.nade_show_particles = 0;
553 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
555 // NOTE: this function merely places an orb
556 // you must add a custom touch function to the returned entity if desired
557 // also set .colormod if you wish to have it colorized
558 entity orb = new(nades_spawn_orb);
560 orb.realowner = realown;
563 orb.orb_lifetime = orb_ltime; // required for timers
564 orb.ltime = time + orb.orb_lifetime;
565 orb.bot_dodge = false;
566 orb.team = realown.team;
567 orb.solid = SOLID_TRIGGER;
569 setmodel(orb, MDL_NADE_ORB);
571 orb.orb_radius = orb_rad; // required for fading
572 vector size = '1 1 1' * orb.orb_radius / 2;
573 setsize(orb, -size, size);
575 Net_LinkEntity(orb, true, 0, orb_send);
578 setthink(orb, nades_orb_think);
579 orb.nextthink = time;
584 void nade_entrap_touch(entity this, entity toucher)
586 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
588 if (!isPushable(toucher))
591 float pushdeltatime = time - toucher.lastpushtime;
592 if (pushdeltatime > 0.15) pushdeltatime = 0;
593 toucher.lastpushtime = time;
594 if(!pushdeltatime) return;
596 // div0: ticrate independent, 1 = identity (not 20)
597 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
600 UpdateCSQCProjectile(toucher);
604 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
606 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
607 STAT(ENTRAP_ORB, show_tint) = time + 0.1;
609 float tint_alpha = 0.75;
610 if(SAME_TEAM(toucher, this.realowner))
612 STAT(ENTRAP_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
616 void nade_entrap_boom(entity this)
618 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
620 settouch(orb, nade_entrap_touch);
621 orb.colormod = NADE_TYPE_ENTRAP.m_color;
624 void nade_heal_touch(entity this, entity toucher)
628 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
629 if(!IS_DEAD(toucher))
630 if(!STAT(FROZEN, toucher))
632 health_factor = autocvar_g_nades_heal_rate*frametime/2;
633 if ( toucher != this.realowner )
635 if ( SAME_TEAM(toucher,this) )
636 health_factor *= autocvar_g_nades_heal_friend;
638 health_factor *= autocvar_g_nades_heal_foe;
640 if ( health_factor > 0 )
642 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
643 float hp = GetResource(toucher, RES_HEALTH);
646 if (this.nade_show_particles)
648 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
650 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
653 else if ( health_factor < 0 )
655 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
660 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
662 entity show_red = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
663 STAT(HEALING_ORB, show_red) = time+0.1;
664 STAT(HEALING_ORB_ALPHA, show_red) = 0.75 * (this.ltime - time) / this.orb_lifetime;
668 void nade_heal_boom(entity this)
670 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
672 settouch(orb, nade_heal_touch);
673 orb.colormod = '1 0 0';
676 void nade_monster_boom(entity this)
679 e.noalign = true; // don't drop to floor
680 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
682 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
683 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
684 e.monster_skill = MONSTER_SKILL_INSANE;
687 void nade_veil_touch(entity this, entity toucher)
689 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
691 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
693 float tint_alpha = 0.75;
694 if(SAME_TEAM(toucher, this.realowner))
697 if(!STAT(VEIL_ORB, show_tint))
699 toucher.nade_veil_prevalpha = toucher.alpha;
703 STAT(VEIL_ORB, show_tint) = time + 0.1;
704 STAT(VEIL_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
708 void nade_veil_boom(entity this)
710 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
712 settouch(orb, nade_veil_touch);
713 orb.colormod = NADE_TYPE_VEIL.m_color;
716 void nade_boom(entity this)
719 bool nade_blast = true;
721 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
723 case NADE_TYPE_NAPALM:
724 nade_blast = autocvar_g_nades_napalm_blast;
725 expef = EFFECT_EXPLOSION_MEDIUM;
729 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
731 case NADE_TYPE_TRANSLOCATE:
734 case NADE_TYPE_MONSTER:
735 case NADE_TYPE_SPAWN:
737 switch(this.realowner.team)
739 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
740 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
741 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
742 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
743 default: expef = EFFECT_SPAWN_NEUTRAL; break;
748 expef = EFFECT_SPAWN_RED;
751 case NADE_TYPE_ENTRAP:
753 expef = EFFECT_SPAWN_YELLOW;
758 expef = EFFECT_SPAWN_NEUTRAL;
762 case NADE_TYPE_NORMAL:
763 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
768 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
770 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
771 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
773 this.event_damage = func_null; // prevent somehow calling damage in the next call
777 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
778 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
779 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);
783 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
785 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
786 case NADE_TYPE_ICE: nade_ice_boom(this); break;
787 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
788 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
789 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
790 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
791 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
792 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
795 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
803 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
804 void nade_pickup(entity this, entity thenade)
806 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
808 // set refire so player can't even
809 this.nade_refire = time + autocvar_g_nades_nade_refire;
810 STAT(NADE_TIMER, this) = 0;
813 this.nade.nade_time_primed = thenade.nade_time_primed;
816 bool CanThrowNade(entity this);
817 void nade_touch(entity this, entity toucher)
820 UpdateCSQCProjectile(this);
822 if(toucher == this.realowner)
823 return; // no this impacts
825 if(autocvar_g_nades_pickup)
826 if(time >= this.spawnshieldtime)
827 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
828 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
829 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
831 nade_pickup(toucher, this);
832 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
836 /*float is_weapclip = 0;
837 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
838 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
839 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
841 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
843 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
851 PROJECTILE_TOUCH(this, toucher);
853 //setsize(this, '-2 -2 -2', '2 2 2');
854 //UpdateCSQCProjectile(this);
855 if(GetResource(this, RES_HEALTH) == this.max_health)
857 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
861 this.enemy = toucher;
865 void nade_beep(entity this)
867 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
868 setthink(this, nade_boom);
869 this.nextthink = max(this.wait, time);
872 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
874 if(ITEM_DAMAGE_NEEDKILL(deathtype))
876 this.takedamage = DAMAGE_NO;
881 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
884 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
885 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
890 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
892 force *= 0.5; // too much
895 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
898 damage = this.max_health * 0.55;
900 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
901 damage = this.max_health * 0.1;
902 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
904 if(!(deathtype & HITTYPE_SECONDARY))
905 damage = this.max_health * 1.15;
909 entity death_weapon = DEATH_WEAPONOF(deathtype);
910 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
912 damage = this.max_health * 0.1;
916 this.velocity += force;
917 UpdateCSQCProjectile(this);
919 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
922 float hp = GetResource(this, RES_HEALTH);
923 if(hp == this.max_health)
925 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
926 this.nextthink = max(time + this.nade_lifetime, time);
927 setthink(this, nade_beep);
931 SetResource(this, RES_HEALTH, hp);
934 if ( STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
935 this.realowner = attacker;
938 W_PrepareExplosionByDamage(this, attacker, nade_boom);
940 nade_burn_spawn(this);
943 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
948 entity _nade = e.nade;
955 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
957 makevectors(e.v_angle);
959 // NOTE: always throw from first weapon entity?
960 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
962 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
963 + (v_right * autocvar_g_nades_throw_offset.y)
964 + (v_up * autocvar_g_nades_throw_offset.z);
966 setorigin(_nade, w_shotorg + offset);
967 //setmodel(_nade, MDL_PROJECTILE_NADE);
968 //setattachment(_nade, NULL, "");
969 PROJECTILE_MAKETRIGGER(_nade);
970 if(STAT(NADES_SMALL, e))
971 setsize(_nade, '-8 -8 -8', '8 8 8');
973 setsize(_nade, '-16 -16 -16', '16 16 16');
974 set_movetype(_nade, MOVETYPE_BOUNCE);
976 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
977 if (trace_startsolid)
978 setorigin(_nade, e.origin);
980 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
981 _nade.velocity = '0 0 100';
982 else if(autocvar_g_nades_nade_newton_style == 1)
983 _nade.velocity = e.velocity + _velocity;
984 else if(autocvar_g_nades_nade_newton_style == 2)
985 _nade.velocity = _velocity;
987 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
992 settouch(_nade, nade_touch);
993 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
994 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
995 _nade.max_health = GetResource(_nade, RES_HEALTH);
996 _nade.takedamage = DAMAGE_AIM;
997 _nade.event_damage = nade_damage;
998 setcefc(_nade, func_null);
999 _nade.exteriormodeltoclient = NULL;
1000 _nade.traileffectnum = 0;
1001 _nade.teleportable = true;
1002 _nade.pushable = true;
1004 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1005 _nade.damagedbycontents = true;
1006 IL_PUSH(g_damagedbycontents, _nade);
1007 _nade.angles = vectoangles(_nade.velocity);
1008 _nade.flags = FL_PROJECTILE;
1009 IL_PUSH(g_projectiles, _nade);
1010 IL_PUSH(g_bot_dodge, _nade);
1011 _nade.projectiledeathtype = DEATH_NADE.m_id;
1012 _nade.toss_time = time;
1013 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1015 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1016 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1018 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1024 setthink(_nade, nade_boom);
1025 _nade.nextthink = _time;
1028 e.nade_refire = time + autocvar_g_nades_nade_refire;
1029 STAT(NADE_TIMER, e) = 0;
1032 void nades_GiveBonus(entity player, float score)
1034 if (autocvar_g_nades)
1035 if (autocvar_g_nades_bonus)
1036 if (IS_REAL_CLIENT(player))
1037 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1038 if (!STAT(FROZEN, player))
1039 if (!IS_DEAD(player))
1041 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1042 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1044 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1046 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1047 play2(player, SND(NADE_BONUS));
1048 STAT(NADE_BONUS, player)++;
1049 STAT(NADE_BONUS_SCORE, player) -= 1;
1054 /** Remove all bonus nades from a player */
1055 void nades_RemoveBonus(entity player)
1057 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1060 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1062 entity player = M_ARGV(0, entity);
1064 nades_RemoveBonus(player);
1067 bool nade_customize(entity this, entity client)
1069 //if(IS_SPEC(client)) { return false; }
1070 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1072 // somewhat hide the model, but keep the glow
1074 if(this.traileffectnum)
1075 this.traileffectnum = 0;
1080 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1081 if(!this.traileffectnum)
1083 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1084 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1092 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1094 entity n = new(nade), fn = new(fake_nade);
1096 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1097 n.pokenade_type = pntype;
1099 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1100 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1102 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1104 setmodel(n, MDL_PROJECTILE_NADE);
1105 //setattachment(n, player, "bip01 l hand");
1106 n.exteriormodeltoclient = player;
1107 setcefc(n, nade_customize);
1108 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1109 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1110 n.realowner = nowner;
1111 n.colormap = player.colormap;
1112 n.glowmod = player.glowmod;
1113 n.wait = time + max(0, ntime);
1114 n.nade_time_primed = time;
1115 setthink(n, nade_beep);
1116 n.nextthink = max(n.wait - 3, time);
1117 n.projectiledeathtype = DEATH_NADE.m_id;
1118 n.weaponentity_fld = weaponentity;
1119 n.nade_lifetime = ntime;
1120 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1122 setmodel(fn, MDL_NADE_VIEW);
1123 //setattachment(fn, player.(weaponentity), "");
1124 fn.viewmodelforclient = player;
1125 fn.realowner = fn.owner = player;
1126 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1127 fn.colormap = player.colormap;
1128 fn.glowmod = player.glowmod;
1129 setthink(fn, SUB_Remove);
1130 fn.nextthink = n.wait;
1131 fn.weaponentity_fld = weaponentity;
1132 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1135 player.fake_nade = fn;
1138 void nade_prime(entity this)
1140 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1141 return; // only allow bonus nades
1143 // TODO: handle old nade if it exists?
1149 delete(this.fake_nade);
1150 this.fake_nade = NULL;
1153 string pntype = this.pokenade_type;
1155 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1156 ntype = STAT(NADE_BONUS_TYPE, this);
1157 else if (STAT(NADE_BONUS, this) >= 1)
1159 ntype = STAT(NADE_BONUS_TYPE, this);
1160 pntype = this.pokenade_type;
1161 STAT(NADE_BONUS, this) -= 1;
1165 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1166 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1169 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1172 bool CanThrowNade(entity this)
1174 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1177 .bool nade_altbutton;
1179 void nades_CheckThrow(entity this)
1181 if(!CanThrowNade(this))
1184 entity held_nade = this.nade;
1187 this.nade_altbutton = true;
1188 if(time > this.nade_refire)
1191 this.nade_refire = time + autocvar_g_nades_nade_refire;
1196 this.nade_altbutton = false;
1197 if (time >= held_nade.nade_time_primed + 1) {
1198 makevectors(this.v_angle);
1199 float _force = time - held_nade.nade_time_primed;
1200 _force /= autocvar_g_nades_nade_lifetime;
1201 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1202 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1203 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1204 toss_nade(this, true, dir * _force, 0);
1209 void nades_Clear(entity player)
1212 delete(player.nade);
1213 if(player.fake_nade)
1214 delete(player.fake_nade);
1216 player.nade = player.fake_nade = NULL;
1217 STAT(NADE_TIMER, player) = 0;
1220 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1222 entity player = M_ARGV(0, entity);
1225 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1228 CLASS(NadeOffhand, OffhandWeapon)
1229 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1231 entity held_nade = player.nade;
1233 if (!CanThrowNade(player)) return;
1234 if (!(time > player.nade_refire)) return;
1238 held_nade = player.nade;
1240 } else if (time >= held_nade.nade_time_primed + 1) {
1242 makevectors(player.v_angle);
1243 float _force = time - held_nade.nade_time_primed;
1244 _force /= autocvar_g_nades_nade_lifetime;
1245 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1246 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1247 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1248 toss_nade(player, false, dir * _force, 0);
1252 ENDCLASS(NadeOffhand)
1253 NadeOffhand OFFHAND_NADE;
1254 REGISTER_MUTATOR(nades, autocvar_g_nades)
1258 OFFHAND_NADE = NEW(NadeOffhand);
1263 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1265 entity player = M_ARGV(0, entity);
1267 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1268 nades_CheckThrow(player);
1273 #ifdef IN_REVIVING_RANGE
1274 #undef IN_REVIVING_RANGE
1277 // returns true if player is reviving it
1278 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1279 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1280 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1282 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1284 entity player = M_ARGV(0, entity);
1286 if (!IS_PLAYER(player)) { return; }
1288 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1289 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1291 entity held_nade = player.nade;
1294 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1295 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1296 makevectors(player.angles);
1297 held_nade.velocity = player.velocity;
1298 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1299 held_nade.angles_y = player.angles.y;
1301 if (time + 0.1 >= held_nade.wait)
1303 toss_nade(player, false, '0 0 0', time + 0.05);
1304 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1308 if(IS_PLAYER(player))
1310 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1313 float key_count = 0;
1314 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1317 if(GameRules_scoring_is_vip(player))
1318 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1320 time_score = autocvar_g_nades_bonus_score_time;
1323 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1325 if(autocvar_g_nades_bonus_client_select)
1327 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1328 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1332 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1333 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1336 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1338 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1339 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1343 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1346 if(STAT(VEIL_ORB, player) && STAT(VEIL_ORB, player) <= time)
1348 STAT(VEIL_ORB, player) = 0;
1350 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1352 player.alpha = player.nade_veil_prevalpha;
1356 if (!(frametime && IS_PLAYER(player)))
1359 entity revivers_last = NULL;
1360 entity revivers_first = NULL;
1362 bool player_is_reviving = false;
1364 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1365 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1366 // check if player is reviving anyone
1367 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1369 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1371 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1373 player_is_reviving = true;
1377 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1378 continue; // both player and it are NOT frozen
1380 revivers_last.chain = it;
1382 if (!revivers_first)
1383 revivers_first = it;
1387 revivers_last.chain = NULL;
1389 if (!n) // no teammate nearby
1391 // freezetag already resets revive progress
1392 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1393 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1395 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1397 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1398 // undo what PlayerPreThink did
1399 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1400 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1402 if(STAT(REVIVE_PROGRESS, player) >= 1)
1404 Unfreeze(player, false);
1406 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1407 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1410 for(entity it = revivers_first; it; it = it.chain)
1411 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1415 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1417 entity player = M_ARGV(0, entity);
1418 // these automatically reset, no need to worry
1420 if(STAT(ENTRAP_ORB, player) > time)
1421 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1424 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1426 entity mon = M_ARGV(0, entity);
1428 if (STAT(ENTRAP_ORB, mon) > time)
1430 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1431 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1434 if (STAT(VEIL_ORB, mon) && STAT(VEIL_ORB, mon) <= time)
1436 mon.alpha = mon.nade_veil_prevalpha;
1437 STAT(VEIL_ORB, mon) = 0;
1441 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1443 entity player = M_ARGV(0, entity);
1445 if(autocvar_g_nades_spawn)
1446 player.nade_refire = time + autocvar_g_spawnshieldtime;
1448 player.nade_refire = time + autocvar_g_nades_nade_refire;
1450 if(autocvar_g_nades_bonus_client_select)
1451 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1453 STAT(NADE_TIMER, player) = 0;
1455 if (!player.offhand) player.offhand = OFFHAND_NADE;
1457 if(player.nade_spawnloc)
1459 setorigin(player, player.nade_spawnloc.origin);
1460 player.nade_spawnloc.cnt -= 1;
1462 if(player.nade_spawnloc.cnt <= 0)
1464 delete(player.nade_spawnloc);
1465 player.nade_spawnloc = NULL;
1470 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1472 entity frag_attacker = M_ARGV(1, entity);
1473 entity frag_target = M_ARGV(2, entity);
1475 if(frag_target.nade)
1476 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1477 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1479 if(IS_PLAYER(frag_attacker))
1481 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)
1482 : autocvar_g_nades_bonus_score_minor);
1483 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1484 nades_RemoveBonus(frag_attacker);
1485 else if(GameRules_scoring_is_vip(frag_target))
1486 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1487 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1489 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1490 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1491 switch(CS(frag_attacker).killcount)
1494 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1499 nades_GiveBonus(frag_attacker, killcount_bonus);
1502 nades_RemoveBonus(frag_target);
1505 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1507 entity frag_inflictor = M_ARGV(0, entity);
1508 entity frag_attacker = M_ARGV(1, entity);
1509 entity frag_target = M_ARGV(2, entity);
1510 float frag_deathtype = M_ARGV(3, float);
1512 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1513 if(time - frag_inflictor.toss_time <= 0.1)
1515 Unfreeze(frag_target, false);
1516 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1517 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1518 M_ARGV(4, float) = 0;
1519 M_ARGV(6, vector) = '0 0 0';
1520 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1521 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1525 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1527 entity frag_target = M_ARGV(0, entity);
1528 entity frag_attacker = M_ARGV(1, entity);
1530 if(IS_PLAYER(frag_attacker))
1531 if(DIFF_TEAM(frag_attacker, frag_target))
1532 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1533 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1536 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1538 entity frag_target = M_ARGV(0, entity);
1540 if(frag_target.nade)
1541 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1544 void nades_RemovePlayer(entity this)
1547 nades_RemoveBonus(this);
1550 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1551 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1552 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1554 FOREACH_CLIENT(IS_PLAYER(it),
1556 nades_RemovePlayer(it);
1560 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1562 entity spectatee = M_ARGV(0, entity);
1563 entity client = M_ARGV(1, entity);
1565 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1566 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1567 client.pokenade_type = spectatee.pokenade_type;
1568 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1569 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1570 STAT(HEALING_ORB, client) = STAT(HEALING_ORB, spectatee);
1571 STAT(HEALING_ORB_ALPHA, client) = STAT(HEALING_ORB_ALPHA, spectatee);
1572 STAT(ENTRAP_ORB, client) = STAT(ENTRAP_ORB, spectatee);
1573 STAT(ENTRAP_ORB_ALPHA, client) = STAT(ENTRAP_ORB_ALPHA, spectatee);
1574 STAT(VEIL_ORB, client) = STAT(VEIL_ORB, spectatee);
1575 STAT(VEIL_ORB_ALPHA, client) = STAT(VEIL_ORB_ALPHA, spectatee);
1578 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1580 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1583 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1585 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");