3 #include "../overkill/okmachinegun.qh"
4 #include "../overkill/okshotgun.qh"
7 bool autocvar_g_nades_nade_small;
8 float autocvar_g_nades_spread = 0.04;
11 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
15 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
16 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
18 entity Nade_TrailEffect(int proj, int nade_team)
22 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
23 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
26 FOREACH(Nades, true, {
27 for (int j = 0; j < 2; j++)
29 if (it.m_projectile[j] == proj)
31 string trail = it.m_trail[j].eent_eff_name;
32 if (trail) return it.m_trail[j];
43 #include <client/draw.qh>
44 #include <client/hud/hud.qh>
46 bool darkness_fadealpha;
48 void HUD_DarkBlinking()
50 vector bottomright = vec2(vid_conwidth, vid_conheight);
51 drawfill('0 0 0', bottomright, NADE_TYPE_DARKNESS.m_color, darkness_fadealpha, DRAWFLAG_NORMAL);
54 REGISTER_MUTATOR(cl_nades, true);
55 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
57 if (STAT(NADE_DARKNESS_TIME) > time)
59 if (!darkness_fadealpha)
60 sound(csqcplayer, CH_PAIN, SND_BLIND, VOL_BASE, ATTEN_NORM);
61 darkness_fadealpha = min(0.986, darkness_fadealpha + frametime * 7);
63 else if (darkness_fadealpha > 0)
64 darkness_fadealpha = max(0, darkness_fadealpha - frametime * 7);
66 if (darkness_fadealpha > 0)
69 M_ARGV(1, float) = 0; // alpha_multipl 0, don't draw normal overlay
75 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
77 entity proj = M_ARGV(0, entity);
79 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
82 proj.traileffect = EFFECT_FIREBALL.m_id;
85 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
87 setmodel(proj, MDL_PROJECTILE_NADE);
88 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
89 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
93 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
95 entity proj = M_ARGV(0, entity);
97 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
99 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
100 proj.mins = '-16 -16 -16';
101 proj.maxs = '16 16 16';
104 entity nade_type = Nade_FromProjectile(proj.cnt);
105 if (nade_type == NADE_TYPE_Null) return;
106 if(STAT(NADES_SMALL))
108 proj.mins = '-8 -8 -8';
113 proj.mins = '-16 -16 -16';
114 proj.maxs = '16 16 16';
116 proj.colormod = nade_type.m_color;
117 set_movetype(proj, MOVETYPE_BOUNCE);
118 settouch(proj, func_null);
120 proj.avelocity = randomvec() * 720;
121 proj.alphamod = nade_type.m_alpha;
123 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
124 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
126 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
129 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
131 if (mut_is_active(MUT_NADES))
133 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
134 M_ARGV(0, string) = strcat(M_ARGV(0, string),
135 "\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
139 bool Projectile_isnade(int p)
141 return Nade_FromProjectile(p) != NADE_TYPE_Null;
143 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
145 float bonusNades = STAT(NADE_BONUS);
146 float bonusProgress = STAT(NADE_BONUS_SCORE);
147 float bonusType = STAT(NADE_BONUS_TYPE);
148 Nade def = REGISTRY_GET(Nades, bonusType);
149 vector nadeColor = def.m_color;
150 string nadeIcon = def.m_icon;
152 vector iconPos, textPos;
154 if(autocvar_hud_panel_ammo_iconalign)
156 iconPos = myPos + eX * 2 * mySize.y;
162 textPos = myPos + eX * mySize.y;
165 if(bonusNades > 0 || bonusProgress > 0)
167 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
169 if(autocvar_hud_panel_ammo_text)
170 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
173 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
175 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
182 #include <common/gamemodes/_mod.qh>
183 #include <common/monsters/sv_spawn.qh>
184 #include <common/monsters/sv_monsters.qh>
185 #include <server/command/common.qh>
187 .float nade_time_primed;
188 .float nade_lifetime;
190 .entity nade_spawnloc;
193 void nade_timer_think(entity this)
195 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
196 this.nextthink = time;
197 if(!this.owner || wasfreed(this.owner))
201 void nade_burn_spawn(entity _nade)
203 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
206 void nade_spawn(entity _nade)
208 entity timer = new(nade_timer);
209 setmodel(timer, MDL_NADE_TIMER);
210 setattachment(timer, _nade, "");
211 timer.colormap = _nade.colormap;
212 timer.glowmod = _nade.glowmod;
213 setthink(timer, nade_timer_think);
214 timer.nextthink = time;
215 timer.wait = _nade.wait;
219 _nade.effects |= EF_LOWPRECISION;
221 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
224 void normal_nade_boom(entity this)
226 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
227 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
228 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
229 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
232 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
241 RandomSelection_Init();
242 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
243 if(e.takedamage == DAMAGE_AIM)
244 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
245 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
249 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
250 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
251 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
252 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
255 e.fireball_impactvec = p;
256 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
259 if(RandomSelection_chosen_ent)
261 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
262 d = damage + (edgedamage - damage) * (d / dist);
263 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
264 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
265 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
270 void napalm_ball_think(entity this)
272 if(round_handler_IsActive())
273 if(!round_handler_IsRoundStarted())
279 if(time > this.pushltime)
285 vector midpoint = ((this.absmin + this.absmax) * 0.5);
286 if(pointcontents(midpoint) == CONTENT_WATER)
288 this.velocity = this.velocity * 0.5;
290 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
291 { this.velocity_z = 200; }
294 this.angles = vectoangles(this.velocity);
296 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
297 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
299 this.nextthink = time + 0.1;
303 void nade_napalm_ball(entity this)
308 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
311 proj.owner = this.owner;
312 proj.realowner = this.realowner;
313 proj.team = this.owner.team;
314 proj.bot_dodge = true;
315 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
316 set_movetype(proj, MOVETYPE_BOUNCE);
317 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
318 PROJECTILE_MAKETRIGGER(proj);
319 setmodel(proj, MDL_Null);
320 proj.scale = 1;//0.5;
321 setsize(proj, '-4 -4 -4', '4 4 4');
322 setorigin(proj, this.origin);
323 setthink(proj, napalm_ball_think);
324 proj.nextthink = time;
325 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
326 proj.effects = EF_LOWPRECISION | EF_FLAME;
328 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
329 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
330 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
331 proj.velocity = kick;
333 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
335 proj.angles = vectoangles(proj.velocity);
336 proj.flags = FL_PROJECTILE;
337 IL_PUSH(g_projectiles, proj);
338 IL_PUSH(g_bot_dodge, proj);
339 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
341 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
345 void napalm_fountain_think(entity this)
348 if(round_handler_IsActive())
349 if(!round_handler_IsRoundStarted())
355 if(time >= this.ltime)
361 vector midpoint = ((this.absmin + this.absmax) * 0.5);
362 if(pointcontents(midpoint) == CONTENT_WATER)
364 this.velocity = this.velocity * 0.5;
366 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
367 { this.velocity_z = 200; }
369 UpdateCSQCProjectile(this);
372 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
373 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
375 this.nextthink = time + 0.1;
376 if(time >= this.nade_special_time)
378 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
379 nade_napalm_ball(this);
383 void nade_napalm_boom(entity this)
385 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
386 nade_napalm_ball(this);
388 entity fountain = new(nade_napalm_fountain);
389 fountain.owner = this.owner;
390 fountain.realowner = this.realowner;
391 fountain.origin = this.origin;
392 fountain.flags = FL_PROJECTILE;
393 IL_PUSH(g_projectiles, fountain);
394 IL_PUSH(g_bot_dodge, fountain);
395 setorigin(fountain, fountain.origin);
396 setthink(fountain, napalm_fountain_think);
397 fountain.nextthink = time;
398 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
399 fountain.pushltime = fountain.ltime;
400 fountain.team = this.team;
401 set_movetype(fountain, MOVETYPE_TOSS);
402 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
403 fountain.bot_dodge = true;
404 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
405 fountain.nade_special_time = time;
406 setsize(fountain, '-16 -16 -16', '16 16 16');
407 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
410 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
412 frost_target.frozen_by = freezefield.realowner;
413 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
414 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
416 Drop_Special_Items(frost_target);
419 void nade_ice_think(entity this)
421 if(round_handler_IsActive())
422 if(!round_handler_IsRoundStarted())
428 if(time >= this.ltime)
430 if ( autocvar_g_nades_ice_explode )
432 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
433 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
434 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
436 normal_nade_boom(this);
443 this.nextthink = time + 0.1;
448 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
450 randomw = random() * M_PI * 2;
452 randomp.x = randomr * cos(randomw);
453 randomp.y = randomr * sin(randomw);
455 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
457 if(time >= this.nade_special_time)
459 this.nade_special_time = time + 0.7;
461 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
462 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
466 float current_freeze_time = this.ltime - time - 0.1;
468 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
469 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0
470 && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it),
472 switch (autocvar_g_nades_ice_teamcheck)
474 case 0: break; // affect everyone
476 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
477 // fall through (check case 1 condition too)
478 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
480 nade_ice_freeze(this, it, current_freeze_time);
484 void nade_ice_boom(entity this)
486 entity fountain = new(nade_ice_fountain);
487 fountain.owner = this.owner;
488 fountain.realowner = this.realowner;
489 fountain.origin = this.origin;
490 setorigin(fountain, fountain.origin);
491 setthink(fountain, nade_ice_think);
492 fountain.nextthink = time;
493 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
494 fountain.pushltime = fountain.wait = fountain.ltime;
495 fountain.team = this.team;
496 set_movetype(fountain, MOVETYPE_TOSS);
497 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
498 fountain.bot_dodge = false;
499 setsize(fountain, '-16 -16 -16', '16 16 16');
500 fountain.nade_special_time = time + 0.3;
501 fountain.angles = this.angles;
503 if ( autocvar_g_nades_ice_explode )
505 setmodel(fountain, MDL_PROJECTILE_GRENADE);
506 entity timer = new(nade_timer);
507 setmodel(timer, MDL_NADE_TIMER);
508 setattachment(timer, fountain, "");
509 timer.colormap = this.colormap;
510 timer.glowmod = this.glowmod;
511 setthink(timer, nade_timer_think);
512 timer.nextthink = time;
513 timer.wait = fountain.ltime;
514 timer.owner = fountain;
518 setmodel(fountain, MDL_Null);
521 void nade_translocate_boom(entity this)
523 if(this.realowner.vehicle)
526 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
528 if(!move_out_of_solid(this))
530 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
534 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
535 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
536 locout = trace_endpos;
538 makevectors(this.realowner.angles);
540 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
542 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
545 void nade_spawn_boom(entity this)
547 entity player = this.realowner;
548 entity spawnloc = new(nade_spawn_loc);
549 setorigin(spawnloc, this.origin);
550 setsize(spawnloc, player.mins, player.maxs);
551 set_movetype(spawnloc, MOVETYPE_NONE);
552 spawnloc.solid = SOLID_NOT;
553 spawnloc.drawonlytoclient = player;
554 spawnloc.effects = EF_STARDUST;
555 spawnloc.cnt = autocvar_g_nades_spawn_count;
557 if(player.nade_spawnloc)
558 delete(player.nade_spawnloc);
560 player.nade_spawnloc = spawnloc;
563 void nades_orb_think(entity this)
565 if(time >= this.ltime)
571 this.nextthink = time;
573 if(time >= this.nade_special_time)
575 this.nade_special_time = time+0.25;
576 this.nade_show_particles = 1;
579 this.nade_show_particles = 0;
582 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
584 // NOTE: this function merely places an orb
585 // you must add a custom touch function to the returned entity if desired
586 // also set .colormod if you wish to have it colorized
587 entity orb = new(nades_spawn_orb);
589 orb.realowner = realown;
592 orb.orb_lifetime = orb_ltime; // required for timers
593 orb.ltime = time + orb.orb_lifetime;
594 orb.bot_dodge = false;
595 orb.team = realown.team;
596 orb.solid = SOLID_TRIGGER;
598 setmodel(orb, MDL_NADE_ORB);
600 orb.orb_radius = orb_rad; // required for fading
601 vector size = '1 1 1' * orb.orb_radius / 2;
602 setsize(orb, -size, size);
604 Net_LinkEntity(orb, true, 0, orb_send);
607 setthink(orb, nades_orb_think);
608 orb.nextthink = time;
613 void nade_entrap_touch(entity this, entity toucher)
615 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
617 if (!isPushable(toucher))
620 float pushdeltatime = time - toucher.lastpushtime;
621 if (pushdeltatime > 0.15) pushdeltatime = 0;
622 toucher.lastpushtime = time;
623 if(!pushdeltatime) return;
625 // div0: ticrate independent, 1 = identity (not 20)
626 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
629 UpdateCSQCProjectile(toucher);
633 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
635 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
636 show_tint.nade_entrap_time = time + 0.1;
640 void nade_entrap_boom(entity this)
642 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
644 settouch(orb, nade_entrap_touch);
645 orb.colormod = NADE_TYPE_ENTRAP.m_color;
648 void nade_heal_touch(entity this, entity toucher)
653 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
654 if(!IS_DEAD(toucher))
655 if(!STAT(FROZEN, toucher))
657 health_factor = autocvar_g_nades_heal_rate*frametime/2;
658 if ( toucher != this.realowner )
659 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
661 if ( health_factor > 0 )
663 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
664 float hp = GetResource(toucher, RES_HEALTH);
667 if (this.nade_show_particles)
668 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
670 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
673 else if ( health_factor < 0 )
674 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
678 void nade_heal_boom(entity this)
680 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
682 settouch(orb, nade_heal_touch);
683 orb.colormod = '1 0 0';
686 void nade_monster_boom(entity this)
688 if(!autocvar_g_monsters)
691 e.noalign = true; // don't drop to floor
692 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
694 return; // monster failed to be spawned
696 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
697 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
698 e.monster_skill = MONSTER_SKILL_INSANE;
701 void nade_veil_touch(entity this, entity toucher)
703 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
705 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
707 float tint_alpha = 0.75;
708 if(SAME_TEAM(toucher, this.realowner))
711 if(!show_tint.nade_veil_time)
713 toucher.nade_veil_prevalpha = toucher.alpha;
717 show_tint.nade_veil_time = time + 0.1;
721 void nade_veil_boom(entity this)
723 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
725 settouch(orb, nade_veil_touch);
726 orb.colormod = NADE_TYPE_VEIL.m_color;
729 void nade_ammo_touch(entity this, entity toucher)
733 float amshells = GetResource(toucher, RES_SHELLS);
734 float ambullets = GetResource(toucher, RES_BULLETS);
735 float amrockets = GetResource(toucher, RES_ROCKETS);
736 float amcells = GetResource(toucher, RES_CELLS);
737 float amplasma = GetResource(toucher, RES_PLASMA);
738 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
739 if(!IS_DEAD(toucher))
740 if(!STAT(FROZEN, toucher))
742 ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
743 if ( toucher != this.realowner )
744 ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
746 #define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
747 if (amresource < maxammo) \
748 GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
750 #define DROP_AMMO_RESOURCE(amresource, res_resource) \
751 if (amresource > 0) \
752 SetResource(toucher, res_resource, amresource + ammo_factor);
754 if ( ammo_factor > 0 )
756 CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
757 CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
758 CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
759 CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
760 CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
762 if (this.nade_show_particles)
763 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
765 else if ( ammo_factor < 0 )
767 //Foe drops ammo points
768 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
769 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
770 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
771 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
772 DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
777 #undef CHECK_AMMO_RESOURCE_LIMIT
778 #undef DROP_AMMO_RESOURCE
780 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
782 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
783 show_tint.nade_ammo_time = time + 0.1;
787 void nade_ammo_boom(entity this)
789 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
791 settouch(orb, nade_ammo_touch);
792 orb.colormod = '0.66 0.33 0';
795 void nade_darkness_think(entity this)
797 if(round_handler_IsActive())
798 if(!round_handler_IsRoundStarted())
804 if(time >= this.ltime)
806 if ( autocvar_g_nades_darkness_explode )
808 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
809 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
810 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
812 normal_nade_boom(this);
815 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
821 this.nextthink = time + 0.1;
826 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
828 randomw = random() * M_PI * 2;
830 randomp.x = randomr * cos(randomw);
831 randomp.y = randomr * sin(randomw);
833 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
835 if(time >= this.nade_special_time)
837 this.nade_special_time = time + 0.7;
838 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
842 float current_dark_time = this.ltime - time - 0.1;
844 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
845 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
847 switch (autocvar_g_nades_darkness_teamcheck)
849 case 0: break; // affect everyone
851 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
852 // fall through (check case 1 condition too)
853 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
855 STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
859 void nade_darkness_boom(entity this)
861 entity fountain = new(nade_darkness_fountain);
862 fountain.owner = this.owner;
863 fountain.realowner = this.realowner;
864 fountain.origin = this.origin;
865 setorigin(fountain, fountain.origin);
866 setthink(fountain, nade_darkness_think);
867 fountain.nextthink = time;
868 fountain.ltime = time + autocvar_g_nades_darkness_time;
869 fountain.pushltime = fountain.wait = fountain.ltime;
870 fountain.team = this.team;
871 set_movetype(fountain, MOVETYPE_TOSS);
872 fountain.projectiledeathtype = DEATH_NADE.m_id;
873 fountain.bot_dodge = false;
874 setsize(fountain, '-16 -16 -16', '16 16 16');
875 fountain.nade_special_time = time + 0.3;
876 fountain.angles = this.angles;
878 if ( autocvar_g_nades_darkness_explode )
880 setmodel(fountain, MDL_PROJECTILE_GRENADE);
881 entity timer = new(nade_timer);
882 setmodel(timer, MDL_NADE_TIMER);
883 setattachment(timer, fountain, "");
884 timer.colormap = this.colormap;
885 timer.glowmod = this.glowmod;
886 setthink(timer, nade_timer_think);
887 timer.nextthink = time;
888 timer.wait = fountain.ltime;
889 timer.owner = fountain;
893 setmodel(fountain, MDL_Null);
896 void nade_boom(entity this)
899 bool nade_blast = true;
901 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
902 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
903 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
904 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
905 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
906 EFFECT_SPAWN_NEUTRAL))))
908 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
910 nade_blast = blast; \
911 expef = exp_effect; \
914 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
916 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
917 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
918 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
919 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
920 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
921 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
922 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
923 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
924 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
925 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
926 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
927 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
929 #undef GET_NADE_TYPE_SPAWN_EFFECT
930 #undef SET_NADE_EFFECT
933 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
935 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
936 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
938 this.event_damage = func_null; // prevent somehow calling damage in the next call
941 normal_nade_boom(this);
944 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
946 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
947 case NADE_TYPE_ICE: nade_ice_boom(this); break;
948 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
949 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
950 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
951 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
952 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
953 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
954 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
955 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
958 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
966 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
967 void nade_pickup(entity this, entity thenade)
969 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
971 // set refire so player can't even
972 this.nade_refire = time + autocvar_g_nades_nade_refire;
973 STAT(NADE_TIMER, this) = 0;
976 this.nade.nade_time_primed = thenade.nade_time_primed;
979 bool CanThrowNade(entity this);
980 void nade_touch(entity this, entity toucher)
983 UpdateCSQCProjectile(this);
985 if(toucher == this.realowner)
986 return; // no this impacts
988 if(autocvar_g_nades_pickup)
989 if(time >= this.spawnshieldtime)
990 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
991 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
992 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
994 nade_pickup(toucher, this);
995 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
999 /*float is_weapclip = 0;
1000 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
1001 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
1002 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
1004 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1006 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1014 PROJECTILE_TOUCH(this, toucher);
1016 //setsize(this, '-2 -2 -2', '2 2 2');
1017 //UpdateCSQCProjectile(this);
1018 if(GetResource(this, RES_HEALTH) == this.max_health)
1020 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1024 this.enemy = toucher;
1028 void nade_beep(entity this)
1030 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1031 setthink(this, nade_boom);
1032 this.nextthink = max(this.wait, time);
1035 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1037 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1039 this.takedamage = DAMAGE_NO;
1044 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1047 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1048 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1053 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
1055 force *= 0.5; // too much
1058 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1061 damage = this.max_health * 0.55;
1063 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1064 damage = this.max_health * 0.1;
1065 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1067 if(!(deathtype & HITTYPE_SECONDARY))
1068 damage = this.max_health * 1.15;
1072 entity death_weapon = DEATH_WEAPONOF(deathtype);
1073 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1075 damage = this.max_health * 0.1;
1079 this.velocity += force;
1080 UpdateCSQCProjectile(this);
1082 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1085 float hp = GetResource(this, RES_HEALTH);
1086 if(hp == this.max_health)
1088 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1089 this.nextthink = max(time + this.nade_lifetime, time);
1090 setthink(this, nade_beep);
1094 SetResource(this, RES_HEALTH, hp);
1096 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1097 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1098 this.realowner = attacker;
1102 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1103 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1105 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1107 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1108 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1113 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1116 nade_burn_spawn(this);
1119 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1124 entity _nade = e.nade;
1128 delete(e.fake_nade);
1131 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1133 makevectors(e.v_angle);
1135 // NOTE: always throw from first weapon entity?
1136 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1138 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1139 + (v_right * autocvar_g_nades_throw_offset.y)
1140 + (v_up * autocvar_g_nades_throw_offset.z);
1142 setorigin(_nade, w_shotorg + offset);
1143 //setmodel(_nade, MDL_PROJECTILE_NADE);
1144 //setattachment(_nade, NULL, "");
1145 PROJECTILE_MAKETRIGGER(_nade);
1146 if(STAT(NADES_SMALL, e))
1147 setsize(_nade, '-8 -8 -8', '8 8 8');
1149 setsize(_nade, '-16 -16 -16', '16 16 16');
1150 set_movetype(_nade, MOVETYPE_BOUNCE);
1152 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1153 if (trace_startsolid)
1154 setorigin(_nade, e.origin);
1156 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1157 _nade.velocity = '0 0 100';
1158 else if(autocvar_g_nades_nade_newton_style == 1)
1159 _nade.velocity = e.velocity + _velocity;
1160 else if(autocvar_g_nades_nade_newton_style == 2)
1161 _nade.velocity = _velocity;
1163 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1166 _nade.realowner = e;
1168 settouch(_nade, nade_touch);
1169 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1170 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1171 _nade.max_health = GetResource(_nade, RES_HEALTH);
1172 _nade.takedamage = DAMAGE_AIM;
1173 _nade.event_damage = nade_damage;
1174 setcefc(_nade, func_null);
1175 _nade.exteriormodeltoclient = NULL;
1176 _nade.traileffectnum = 0;
1177 _nade.teleportable = true;
1178 _nade.pushable = true;
1180 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1181 _nade.damagedbycontents = true;
1182 IL_PUSH(g_damagedbycontents, _nade);
1183 _nade.angles = vectoangles(_nade.velocity);
1184 _nade.flags = FL_PROJECTILE;
1185 IL_PUSH(g_projectiles, _nade);
1186 IL_PUSH(g_bot_dodge, _nade);
1187 _nade.projectiledeathtype = DEATH_NADE.m_id;
1188 _nade.toss_time = time;
1189 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1191 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1192 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1194 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1200 setthink(_nade, nade_boom);
1201 _nade.nextthink = _time;
1204 e.nade_refire = time + autocvar_g_nades_nade_refire;
1205 STAT(NADE_TIMER, e) = 0;
1208 void nades_GiveBonus(entity player, float score)
1210 if (autocvar_g_nades)
1211 if (autocvar_g_nades_bonus)
1212 if (IS_REAL_CLIENT(player))
1213 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1214 if (!STAT(FROZEN, player))
1215 if (!IS_DEAD(player))
1217 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1218 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1220 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1222 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1223 play2(player, SND(NADE_BONUS));
1224 STAT(NADE_BONUS, player)++;
1225 STAT(NADE_BONUS_SCORE, player) -= 1;
1230 /** Remove all bonus nades from a player */
1231 void nades_RemoveBonus(entity player)
1233 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1236 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1238 entity player = M_ARGV(0, entity);
1240 nades_RemoveBonus(player);
1243 bool nade_customize(entity this, entity client)
1245 //if(IS_SPEC(client)) { return false; }
1246 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1248 // somewhat hide the model, but keep the glow
1250 if(this.traileffectnum)
1251 this.traileffectnum = 0;
1256 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1257 if(!this.traileffectnum)
1259 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1260 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1268 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1270 entity n = new(nade), fn = new(fake_nade);
1272 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1273 n.pokenade_type = pntype;
1275 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1276 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1278 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1280 setmodel(n, MDL_PROJECTILE_NADE);
1281 //setattachment(n, player, "bip01 l hand");
1282 n.exteriormodeltoclient = player;
1283 setcefc(n, nade_customize);
1284 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1285 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1286 n.realowner = nowner;
1287 n.colormap = player.colormap;
1288 n.glowmod = player.glowmod;
1289 n.wait = time + max(0, ntime);
1290 n.nade_time_primed = time;
1291 setthink(n, nade_beep);
1292 n.nextthink = max(n.wait - 3, time);
1293 n.projectiledeathtype = DEATH_NADE.m_id;
1294 n.weaponentity_fld = weaponentity;
1295 n.nade_lifetime = ntime;
1296 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1298 setmodel(fn, MDL_NADE_VIEW);
1299 //setattachment(fn, player.(weaponentity), "");
1300 fn.viewmodelforclient = player;
1301 fn.realowner = fn.owner = player;
1302 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1303 fn.colormap = player.colormap;
1304 fn.glowmod = player.glowmod;
1305 setthink(fn, SUB_Remove);
1306 fn.nextthink = n.wait;
1307 fn.weaponentity_fld = weaponentity;
1308 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1311 player.fake_nade = fn;
1314 void nade_prime(entity this)
1316 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1317 return; // only allow bonus nades
1319 // TODO: handle old nade if it exists?
1325 delete(this.fake_nade);
1326 this.fake_nade = NULL;
1329 string pntype = this.pokenade_type;
1331 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1332 ntype = STAT(NADE_BONUS_TYPE, this);
1333 else if (STAT(NADE_BONUS, this) >= 1)
1335 ntype = STAT(NADE_BONUS_TYPE, this);
1336 pntype = this.pokenade_type;
1337 STAT(NADE_BONUS, this) -= 1;
1341 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1342 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1345 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1348 bool CanThrowNade(entity this)
1350 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1353 .bool nade_altbutton;
1355 void nades_CheckThrow(entity this)
1357 if(!CanThrowNade(this))
1360 entity held_nade = this.nade;
1363 this.nade_altbutton = true;
1364 if(time > this.nade_refire)
1367 this.nade_refire = time + autocvar_g_nades_nade_refire;
1372 this.nade_altbutton = false;
1373 if (time >= held_nade.nade_time_primed + 1) {
1374 makevectors(this.v_angle);
1375 float _force = time - held_nade.nade_time_primed;
1376 _force /= autocvar_g_nades_nade_lifetime;
1377 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1378 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1379 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1380 toss_nade(this, true, dir * _force, 0);
1385 void nades_Clear(entity player)
1388 delete(player.nade);
1389 if(player.fake_nade)
1390 delete(player.fake_nade);
1392 player.nade = player.fake_nade = NULL;
1393 STAT(NADE_TIMER, player) = 0;
1396 int nades_CheckTypes(entity player, int cl_ntype)
1398 // TODO check what happens without this patch
1399 #define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \
1400 case nade_ent.m_id: if (nade_cvar) return cl_ntype
1404 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1405 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1406 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1407 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1408 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1409 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1410 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1411 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1412 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1413 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1415 return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types
1416 #undef CL_NADE_TYPE_CHECK
1419 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1421 entity player = M_ARGV(0, entity);
1424 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1427 CLASS(NadeOffhand, OffhandWeapon)
1428 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1430 entity held_nade = player.nade;
1432 if (!CanThrowNade(player)) return;
1433 if (!(time > player.nade_refire)) return;
1437 held_nade = player.nade;
1439 } else if (time >= held_nade.nade_time_primed + 1) {
1441 makevectors(player.v_angle);
1442 float _force = time - held_nade.nade_time_primed;
1443 _force /= autocvar_g_nades_nade_lifetime;
1444 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1445 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1446 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1447 toss_nade(player, false, dir * _force, 0);
1451 ENDCLASS(NadeOffhand)
1452 NadeOffhand OFFHAND_NADE;
1453 REGISTER_MUTATOR(nades, autocvar_g_nades)
1457 OFFHAND_NADE = NEW(NadeOffhand);
1462 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1464 entity player = M_ARGV(0, entity);
1466 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1467 nades_CheckThrow(player);
1472 #ifdef IN_REVIVING_RANGE
1473 #undef IN_REVIVING_RANGE
1476 // returns true if player is reviving it
1477 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1478 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1479 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1481 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1483 entity player = M_ARGV(0, entity);
1485 if (!IS_PLAYER(player)) { return; }
1487 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1488 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1490 entity held_nade = player.nade;
1493 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1494 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1495 makevectors(player.angles);
1496 held_nade.velocity = player.velocity;
1497 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1498 held_nade.angles_y = player.angles.y;
1500 if (time + 0.1 >= held_nade.wait)
1502 toss_nade(player, false, '0 0 0', time + 0.05);
1503 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1507 if(IS_PLAYER(player))
1509 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1512 float key_count = 0;
1513 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1516 if(GameRules_scoring_is_vip(player))
1517 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1519 time_score = autocvar_g_nades_bonus_score_time;
1522 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1524 if(autocvar_g_nades_bonus_client_select)
1526 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1527 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1531 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1532 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1535 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1537 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1538 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1542 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1545 if(player.nade_veil_time && player.nade_veil_time <= time)
1547 player.nade_veil_time = 0;
1549 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1551 player.alpha = player.nade_veil_prevalpha;
1555 if (!(frametime && IS_PLAYER(player)))
1558 entity revivers_last = NULL;
1559 entity revivers_first = NULL;
1561 bool player_is_reviving = false;
1563 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1564 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1565 // check if player is reviving anyone
1566 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1568 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1570 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1572 player_is_reviving = true;
1576 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1577 continue; // both player and it are NOT frozen
1579 revivers_last.chain = it;
1581 if (!revivers_first)
1582 revivers_first = it;
1586 revivers_last.chain = NULL;
1588 if (!n) // no teammate nearby
1590 // freezetag already resets revive progress
1591 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1592 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1594 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1596 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1597 // undo what PlayerPreThink did
1598 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1599 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1601 if(STAT(REVIVE_PROGRESS, player) >= 1)
1603 Unfreeze(player, false);
1605 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1606 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1609 for(entity it = revivers_first; it; it = it.chain)
1610 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1614 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1616 entity player = M_ARGV(0, entity);
1617 // these automatically reset, no need to worry
1619 if(player.nade_entrap_time > time)
1620 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1623 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1625 entity mon = M_ARGV(0, entity);
1627 if (mon.nade_entrap_time > time)
1629 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1630 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1633 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1635 mon.alpha = mon.nade_veil_prevalpha;
1636 mon.nade_veil_time = 0;
1640 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1642 entity player = M_ARGV(0, entity);
1644 player.nade_refire = (autocvar_g_nades_onspawn)
1645 ? time + autocvar_g_nades_nade_refire
1646 : time + autocvar_g_spawnshieldtime;
1648 if(autocvar_g_nades_bonus_client_select)
1649 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1651 STAT(NADE_TIMER, player) = 0;
1653 if (!player.offhand) player.offhand = OFFHAND_NADE;
1655 if(player.nade_spawnloc)
1657 setorigin(player, player.nade_spawnloc.origin);
1658 player.nade_spawnloc.cnt -= 1;
1660 if(player.nade_spawnloc.cnt <= 0)
1662 delete(player.nade_spawnloc);
1663 player.nade_spawnloc = NULL;
1666 if(autocvar_g_nades_spawn_health_respawn > 0)
1667 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1671 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1673 entity frag_attacker = M_ARGV(1, entity);
1674 entity frag_target = M_ARGV(2, entity);
1676 if(frag_target.nade)
1677 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1678 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1680 if(IS_PLAYER(frag_attacker))
1682 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)
1683 : autocvar_g_nades_bonus_score_minor);
1684 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1685 nades_RemoveBonus(frag_attacker);
1686 else if(GameRules_scoring_is_vip(frag_target))
1687 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1688 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1690 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1691 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1692 switch(CS(frag_attacker).killcount)
1695 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1700 nades_GiveBonus(frag_attacker, killcount_bonus);
1703 nades_RemoveBonus(frag_target);
1706 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1708 entity frag_inflictor = M_ARGV(0, entity);
1709 entity frag_attacker = M_ARGV(1, entity);
1710 entity frag_target = M_ARGV(2, entity);
1711 float frag_deathtype = M_ARGV(3, float);
1713 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1714 if(time - frag_inflictor.toss_time <= 0.1)
1716 Unfreeze(frag_target, false);
1717 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1718 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1719 M_ARGV(4, float) = 0;
1720 M_ARGV(6, vector) = '0 0 0';
1721 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1722 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1726 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1728 entity frag_target = M_ARGV(0, entity);
1729 entity frag_attacker = M_ARGV(1, entity);
1731 if(IS_PLAYER(frag_attacker))
1732 if(DIFF_TEAM(frag_attacker, frag_target))
1733 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1734 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1737 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1739 entity frag_target = M_ARGV(0, entity);
1741 if(frag_target.nade)
1742 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1745 void nades_RemovePlayer(entity this)
1748 nades_RemoveBonus(this);
1751 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1752 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1753 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1755 FOREACH_CLIENT(IS_PLAYER(it),
1757 nades_RemovePlayer(it);
1761 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1763 entity spectatee = M_ARGV(0, entity);
1764 entity client = M_ARGV(1, entity);
1766 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1767 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1768 client.pokenade_type = spectatee.pokenade_type;
1769 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1770 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1773 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1775 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1778 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1780 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");