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)
678 if(!autocvar_g_monsters)
681 e.noalign = true; // don't drop to floor
682 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
684 return; // monster failed to be spawned
686 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
687 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
688 e.monster_skill = MONSTER_SKILL_INSANE;
691 void nade_veil_touch(entity this, entity toucher)
693 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
695 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
697 float tint_alpha = 0.75;
698 if(SAME_TEAM(toucher, this.realowner))
701 if(!STAT(VEIL_ORB, show_tint))
703 toucher.nade_veil_prevalpha = toucher.alpha;
707 STAT(VEIL_ORB, show_tint) = time + 0.1;
708 STAT(VEIL_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
712 void nade_veil_boom(entity this)
714 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
716 settouch(orb, nade_veil_touch);
717 orb.colormod = NADE_TYPE_VEIL.m_color;
720 void nade_boom(entity this)
723 bool nade_blast = true;
725 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
727 case NADE_TYPE_NAPALM:
728 nade_blast = autocvar_g_nades_napalm_blast;
729 expef = EFFECT_EXPLOSION_MEDIUM;
733 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
735 case NADE_TYPE_TRANSLOCATE:
738 case NADE_TYPE_MONSTER:
739 if(!autocvar_g_monsters)
741 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
742 break; // fall back to a standard nade explosion
744 case NADE_TYPE_SPAWN:
746 switch(this.realowner.team)
748 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
749 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
750 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
751 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
752 default: expef = EFFECT_SPAWN_NEUTRAL; break;
757 expef = EFFECT_SPAWN_RED;
760 case NADE_TYPE_ENTRAP:
762 expef = EFFECT_SPAWN_YELLOW;
767 expef = EFFECT_SPAWN_NEUTRAL;
771 case NADE_TYPE_NORMAL:
772 expef = EFFECT_NADE_EXPLODE(this.realowner.team);
777 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
779 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
780 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
782 this.event_damage = func_null; // prevent somehow calling damage in the next call
786 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
787 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
788 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);
792 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
794 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
795 case NADE_TYPE_ICE: nade_ice_boom(this); break;
796 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
797 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
798 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
799 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
800 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
801 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
804 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
812 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
813 void nade_pickup(entity this, entity thenade)
815 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
817 // set refire so player can't even
818 this.nade_refire = time + autocvar_g_nades_nade_refire;
819 STAT(NADE_TIMER, this) = 0;
822 this.nade.nade_time_primed = thenade.nade_time_primed;
825 bool CanThrowNade(entity this);
826 void nade_touch(entity this, entity toucher)
829 UpdateCSQCProjectile(this);
831 if(toucher == this.realowner)
832 return; // no this impacts
834 if(autocvar_g_nades_pickup)
835 if(time >= this.spawnshieldtime)
836 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
837 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
838 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
840 nade_pickup(toucher, this);
841 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
845 /*float is_weapclip = 0;
846 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
847 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
848 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
850 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
852 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
860 PROJECTILE_TOUCH(this, toucher);
862 //setsize(this, '-2 -2 -2', '2 2 2');
863 //UpdateCSQCProjectile(this);
864 if(GetResource(this, RES_HEALTH) == this.max_health)
866 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
870 this.enemy = toucher;
874 void nade_beep(entity this)
876 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
877 setthink(this, nade_boom);
878 this.nextthink = max(this.wait, time);
881 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
883 if(ITEM_DAMAGE_NEEDKILL(deathtype))
885 this.takedamage = DAMAGE_NO;
890 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
893 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
894 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
899 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
901 force *= 0.5; // too much
904 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
907 damage = this.max_health * 0.55;
909 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
910 damage = this.max_health * 0.1;
911 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
913 if(!(deathtype & HITTYPE_SECONDARY))
914 damage = this.max_health * 1.15;
918 entity death_weapon = DEATH_WEAPONOF(deathtype);
919 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
921 damage = this.max_health * 0.1;
925 this.velocity += force;
926 UpdateCSQCProjectile(this);
928 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
931 float hp = GetResource(this, RES_HEALTH);
932 if(hp == this.max_health)
934 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
935 this.nextthink = max(time + this.nade_lifetime, time);
936 setthink(this, nade_beep);
940 SetResource(this, RES_HEALTH, hp);
943 if ( STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
944 this.realowner = attacker;
947 W_PrepareExplosionByDamage(this, attacker, nade_boom);
949 nade_burn_spawn(this);
952 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
957 entity _nade = e.nade;
964 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
966 makevectors(e.v_angle);
968 // NOTE: always throw from first weapon entity?
969 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
971 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
972 + (v_right * autocvar_g_nades_throw_offset.y)
973 + (v_up * autocvar_g_nades_throw_offset.z);
975 setorigin(_nade, w_shotorg + offset);
976 //setmodel(_nade, MDL_PROJECTILE_NADE);
977 //setattachment(_nade, NULL, "");
978 PROJECTILE_MAKETRIGGER(_nade);
979 if(STAT(NADES_SMALL, e))
980 setsize(_nade, '-8 -8 -8', '8 8 8');
982 setsize(_nade, '-16 -16 -16', '16 16 16');
983 set_movetype(_nade, MOVETYPE_BOUNCE);
985 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
986 if (trace_startsolid)
987 setorigin(_nade, e.origin);
989 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
990 _nade.velocity = '0 0 100';
991 else if(autocvar_g_nades_nade_newton_style == 1)
992 _nade.velocity = e.velocity + _velocity;
993 else if(autocvar_g_nades_nade_newton_style == 2)
994 _nade.velocity = _velocity;
996 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1001 settouch(_nade, nade_touch);
1002 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1003 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1004 _nade.max_health = GetResource(_nade, RES_HEALTH);
1005 _nade.takedamage = DAMAGE_AIM;
1006 _nade.event_damage = nade_damage;
1007 setcefc(_nade, func_null);
1008 _nade.exteriormodeltoclient = NULL;
1009 _nade.traileffectnum = 0;
1010 _nade.teleportable = true;
1011 _nade.pushable = true;
1013 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1014 _nade.damagedbycontents = true;
1015 IL_PUSH(g_damagedbycontents, _nade);
1016 _nade.angles = vectoangles(_nade.velocity);
1017 _nade.flags = FL_PROJECTILE;
1018 IL_PUSH(g_projectiles, _nade);
1019 IL_PUSH(g_bot_dodge, _nade);
1020 _nade.projectiledeathtype = DEATH_NADE.m_id;
1021 _nade.toss_time = time;
1022 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1024 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1025 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1027 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1033 setthink(_nade, nade_boom);
1034 _nade.nextthink = _time;
1037 e.nade_refire = time + autocvar_g_nades_nade_refire;
1038 STAT(NADE_TIMER, e) = 0;
1041 void nades_GiveBonus(entity player, float score)
1043 if (autocvar_g_nades)
1044 if (autocvar_g_nades_bonus)
1045 if (IS_REAL_CLIENT(player))
1046 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1047 if (!STAT(FROZEN, player))
1048 if (!IS_DEAD(player))
1050 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1051 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1053 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1055 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1056 play2(player, SND(NADE_BONUS));
1057 STAT(NADE_BONUS, player)++;
1058 STAT(NADE_BONUS_SCORE, player) -= 1;
1063 /** Remove all bonus nades from a player */
1064 void nades_RemoveBonus(entity player)
1066 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1069 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1071 entity player = M_ARGV(0, entity);
1073 nades_RemoveBonus(player);
1076 bool nade_customize(entity this, entity client)
1078 //if(IS_SPEC(client)) { return false; }
1079 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1081 // somewhat hide the model, but keep the glow
1083 if(this.traileffectnum)
1084 this.traileffectnum = 0;
1089 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1090 if(!this.traileffectnum)
1092 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1093 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1101 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1103 entity n = new(nade), fn = new(fake_nade);
1105 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1106 n.pokenade_type = pntype;
1108 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1109 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1111 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1113 setmodel(n, MDL_PROJECTILE_NADE);
1114 //setattachment(n, player, "bip01 l hand");
1115 n.exteriormodeltoclient = player;
1116 setcefc(n, nade_customize);
1117 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1118 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1119 n.realowner = nowner;
1120 n.colormap = player.colormap;
1121 n.glowmod = player.glowmod;
1122 n.wait = time + max(0, ntime);
1123 n.nade_time_primed = time;
1124 setthink(n, nade_beep);
1125 n.nextthink = max(n.wait - 3, time);
1126 n.projectiledeathtype = DEATH_NADE.m_id;
1127 n.weaponentity_fld = weaponentity;
1128 n.nade_lifetime = ntime;
1129 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1131 setmodel(fn, MDL_NADE_VIEW);
1132 //setattachment(fn, player.(weaponentity), "");
1133 fn.viewmodelforclient = player;
1134 fn.realowner = fn.owner = player;
1135 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1136 fn.colormap = player.colormap;
1137 fn.glowmod = player.glowmod;
1138 setthink(fn, SUB_Remove);
1139 fn.nextthink = n.wait;
1140 fn.weaponentity_fld = weaponentity;
1141 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1144 player.fake_nade = fn;
1147 void nade_prime(entity this)
1149 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1150 return; // only allow bonus nades
1152 // TODO: handle old nade if it exists?
1158 delete(this.fake_nade);
1159 this.fake_nade = NULL;
1162 string pntype = this.pokenade_type;
1164 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1165 ntype = STAT(NADE_BONUS_TYPE, this);
1166 else if (STAT(NADE_BONUS, this) >= 1)
1168 ntype = STAT(NADE_BONUS_TYPE, this);
1169 pntype = this.pokenade_type;
1170 STAT(NADE_BONUS, this) -= 1;
1174 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1175 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1178 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1181 bool CanThrowNade(entity this)
1183 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1186 .bool nade_altbutton;
1188 void nades_CheckThrow(entity this)
1190 if(!CanThrowNade(this))
1193 entity held_nade = this.nade;
1196 this.nade_altbutton = true;
1197 if(time > this.nade_refire)
1200 this.nade_refire = time + autocvar_g_nades_nade_refire;
1205 this.nade_altbutton = false;
1206 if (time >= held_nade.nade_time_primed + 1) {
1207 makevectors(this.v_angle);
1208 float _force = time - held_nade.nade_time_primed;
1209 _force /= autocvar_g_nades_nade_lifetime;
1210 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1211 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1212 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1213 toss_nade(this, true, dir * _force, 0);
1218 void nades_Clear(entity player)
1221 delete(player.nade);
1222 if(player.fake_nade)
1223 delete(player.fake_nade);
1225 player.nade = player.fake_nade = NULL;
1226 STAT(NADE_TIMER, player) = 0;
1229 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1231 entity player = M_ARGV(0, entity);
1234 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1237 CLASS(NadeOffhand, OffhandWeapon)
1238 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1240 entity held_nade = player.nade;
1242 if (!CanThrowNade(player)) return;
1243 if (!(time > player.nade_refire)) return;
1247 held_nade = player.nade;
1249 } else if (time >= held_nade.nade_time_primed + 1) {
1251 makevectors(player.v_angle);
1252 float _force = time - held_nade.nade_time_primed;
1253 _force /= autocvar_g_nades_nade_lifetime;
1254 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1255 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1256 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1257 toss_nade(player, false, dir * _force, 0);
1261 ENDCLASS(NadeOffhand)
1262 NadeOffhand OFFHAND_NADE;
1263 REGISTER_MUTATOR(nades, autocvar_g_nades)
1267 OFFHAND_NADE = NEW(NadeOffhand);
1272 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1274 entity player = M_ARGV(0, entity);
1276 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1277 nades_CheckThrow(player);
1282 #ifdef IN_REVIVING_RANGE
1283 #undef IN_REVIVING_RANGE
1286 // returns true if player is reviving it
1287 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1288 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1289 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1291 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1293 entity player = M_ARGV(0, entity);
1295 if (!IS_PLAYER(player)) { return; }
1297 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1298 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1300 entity held_nade = player.nade;
1303 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1304 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1305 makevectors(player.angles);
1306 held_nade.velocity = player.velocity;
1307 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1308 held_nade.angles_y = player.angles.y;
1310 if (time + 0.1 >= held_nade.wait)
1312 toss_nade(player, false, '0 0 0', time + 0.05);
1313 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1317 if(IS_PLAYER(player))
1319 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1322 float key_count = 0;
1323 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1326 if(GameRules_scoring_is_vip(player))
1327 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1329 time_score = autocvar_g_nades_bonus_score_time;
1332 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1334 if(autocvar_g_nades_bonus_client_select)
1336 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1337 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1341 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1342 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1345 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1347 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1348 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1352 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1355 if(STAT(VEIL_ORB, player) && STAT(VEIL_ORB, player) <= time)
1357 STAT(VEIL_ORB, player) = 0;
1359 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1361 player.alpha = player.nade_veil_prevalpha;
1365 if (!(frametime && IS_PLAYER(player)))
1368 entity revivers_last = NULL;
1369 entity revivers_first = NULL;
1371 bool player_is_reviving = false;
1373 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1374 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1375 // check if player is reviving anyone
1376 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1378 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1380 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1382 player_is_reviving = true;
1386 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1387 continue; // both player and it are NOT frozen
1389 revivers_last.chain = it;
1391 if (!revivers_first)
1392 revivers_first = it;
1396 revivers_last.chain = NULL;
1398 if (!n) // no teammate nearby
1400 // freezetag already resets revive progress
1401 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1402 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1404 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1406 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1407 // undo what PlayerPreThink did
1408 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1409 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1411 if(STAT(REVIVE_PROGRESS, player) >= 1)
1413 Unfreeze(player, false);
1415 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1416 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1419 for(entity it = revivers_first; it; it = it.chain)
1420 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1424 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1426 entity player = M_ARGV(0, entity);
1427 // these automatically reset, no need to worry
1429 if(STAT(ENTRAP_ORB, player) > time)
1430 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1433 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1435 entity mon = M_ARGV(0, entity);
1437 if (STAT(ENTRAP_ORB, mon) > time)
1439 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1440 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1443 if (STAT(VEIL_ORB, mon) && STAT(VEIL_ORB, mon) <= time)
1445 mon.alpha = mon.nade_veil_prevalpha;
1446 STAT(VEIL_ORB, mon) = 0;
1450 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1452 entity player = M_ARGV(0, entity);
1454 if(autocvar_g_nades_spawn)
1455 player.nade_refire = time + autocvar_g_spawnshieldtime;
1457 player.nade_refire = time + autocvar_g_nades_nade_refire;
1459 if(autocvar_g_nades_bonus_client_select)
1460 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1462 STAT(NADE_TIMER, player) = 0;
1464 if (!player.offhand) player.offhand = OFFHAND_NADE;
1466 if(player.nade_spawnloc)
1468 setorigin(player, player.nade_spawnloc.origin);
1469 player.nade_spawnloc.cnt -= 1;
1471 if(player.nade_spawnloc.cnt <= 0)
1473 delete(player.nade_spawnloc);
1474 player.nade_spawnloc = NULL;
1479 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1481 entity frag_attacker = M_ARGV(1, entity);
1482 entity frag_target = M_ARGV(2, entity);
1484 if(frag_target.nade)
1485 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1486 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1488 if(IS_PLAYER(frag_attacker))
1490 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)
1491 : autocvar_g_nades_bonus_score_minor);
1492 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1493 nades_RemoveBonus(frag_attacker);
1494 else if(GameRules_scoring_is_vip(frag_target))
1495 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1496 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1498 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1499 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1500 switch(CS(frag_attacker).killcount)
1503 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1508 nades_GiveBonus(frag_attacker, killcount_bonus);
1511 nades_RemoveBonus(frag_target);
1514 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1516 entity frag_inflictor = M_ARGV(0, entity);
1517 entity frag_attacker = M_ARGV(1, entity);
1518 entity frag_target = M_ARGV(2, entity);
1519 float frag_deathtype = M_ARGV(3, float);
1521 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1522 if(time - frag_inflictor.toss_time <= 0.1)
1524 Unfreeze(frag_target, false);
1525 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1526 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1527 M_ARGV(4, float) = 0;
1528 M_ARGV(6, vector) = '0 0 0';
1529 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1530 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1534 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1536 entity frag_target = M_ARGV(0, entity);
1537 entity frag_attacker = M_ARGV(1, entity);
1539 if(IS_PLAYER(frag_attacker))
1540 if(DIFF_TEAM(frag_attacker, frag_target))
1541 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1542 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1545 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1547 entity frag_target = M_ARGV(0, entity);
1549 if(frag_target.nade)
1550 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1553 void nades_RemovePlayer(entity this)
1556 nades_RemoveBonus(this);
1559 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1560 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1561 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1563 FOREACH_CLIENT(IS_PLAYER(it),
1565 nades_RemovePlayer(it);
1569 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1571 entity spectatee = M_ARGV(0, entity);
1572 entity client = M_ARGV(1, entity);
1574 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1575 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1576 client.pokenade_type = spectatee.pokenade_type;
1577 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1578 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1579 STAT(HEALING_ORB, client) = STAT(HEALING_ORB, spectatee);
1580 STAT(HEALING_ORB_ALPHA, client) = STAT(HEALING_ORB_ALPHA, spectatee);
1581 STAT(ENTRAP_ORB, client) = STAT(ENTRAP_ORB, spectatee);
1582 STAT(ENTRAP_ORB_ALPHA, client) = STAT(ENTRAP_ORB_ALPHA, spectatee);
1583 STAT(VEIL_ORB, client) = STAT(VEIL_ORB, spectatee);
1584 STAT(VEIL_ORB_ALPHA, client) = STAT(VEIL_ORB_ALPHA, spectatee);
1587 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1589 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1592 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1594 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");