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];
42 REGISTER_NET_TEMP(TE_CSQC_DARKBLINKING);
44 #include <client/draw.qh>
45 #include <client/hud/hud.qh>
47 float dark_appeartime;
51 void HUD_DarkBlinking()
53 vector bottomright = vec2(vid_conwidth, vid_conheight);
54 drawfill('0 0 0', bottomright, NADE_TYPE_DARKNESS.m_color, 0.986, DRAWFLAG_NORMAL);
57 REGISTER_MUTATOR(cl_nades, true);
58 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
60 if (STAT(NADE_DARKNESS_TIME) > time)
62 M_ARGV(0, vector) = NADE_TYPE_DARKNESS.m_color;
69 NET_HANDLE(TE_CSQC_DARKBLINKING, bool isNew)
75 localcmd("play2 sound/misc/blind\n");
77 dark_appeartime = time;
78 dark_fadetime = STAT(NADE_DARKNESS_TIME);
81 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
83 entity proj = M_ARGV(0, entity);
85 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
88 proj.traileffect = EFFECT_FIREBALL.m_id;
91 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
93 setmodel(proj, MDL_PROJECTILE_NADE);
94 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
95 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
99 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
101 entity proj = M_ARGV(0, entity);
103 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
105 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
106 proj.mins = '-16 -16 -16';
107 proj.maxs = '16 16 16';
110 entity nade_type = Nade_FromProjectile(proj.cnt);
111 if (nade_type == NADE_TYPE_Null) return;
112 if(STAT(NADES_SMALL))
114 proj.mins = '-8 -8 -8';
119 proj.mins = '-16 -16 -16';
120 proj.maxs = '16 16 16';
122 proj.colormod = nade_type.m_color;
123 set_movetype(proj, MOVETYPE_BOUNCE);
124 settouch(proj, func_null);
126 proj.avelocity = randomvec() * 720;
127 proj.alphamod = nade_type.m_alpha;
129 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
130 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
132 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
135 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
137 if (mut_is_active(MUT_NADES))
139 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
140 M_ARGV(0, string) = strcat(M_ARGV(0, string),
141 "\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
145 bool Projectile_isnade(int p)
147 return Nade_FromProjectile(p) != NADE_TYPE_Null;
149 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
151 float bonusNades = STAT(NADE_BONUS);
152 float bonusProgress = STAT(NADE_BONUS_SCORE);
153 float bonusType = STAT(NADE_BONUS_TYPE);
154 Nade def = REGISTRY_GET(Nades, bonusType);
155 vector nadeColor = def.m_color;
156 string nadeIcon = def.m_icon;
158 vector iconPos, textPos;
160 if(autocvar_hud_panel_ammo_iconalign)
162 iconPos = myPos + eX * 2 * mySize.y;
168 textPos = myPos + eX * mySize.y;
171 if(bonusNades > 0 || bonusProgress > 0)
173 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
175 if(autocvar_hud_panel_ammo_text)
176 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
179 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
181 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
188 #include <common/gamemodes/_mod.qh>
189 #include <common/monsters/sv_spawn.qh>
190 #include <common/monsters/sv_monsters.qh>
191 #include <server/command/common.qh>
193 .float nade_time_primed;
194 .float nade_lifetime;
196 .entity nade_spawnloc;
199 void nade_timer_think(entity this)
201 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
202 this.nextthink = time;
203 if(!this.owner || wasfreed(this.owner))
207 void nade_burn_spawn(entity _nade)
209 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
212 void nade_spawn(entity _nade)
214 entity timer = new(nade_timer);
215 setmodel(timer, MDL_NADE_TIMER);
216 setattachment(timer, _nade, "");
217 timer.colormap = _nade.colormap;
218 timer.glowmod = _nade.glowmod;
219 setthink(timer, nade_timer_think);
220 timer.nextthink = time;
221 timer.wait = _nade.wait;
225 _nade.effects |= EF_LOWPRECISION;
227 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
230 void normal_nade_boom(entity this)
232 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
233 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
234 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
235 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
238 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
247 RandomSelection_Init();
248 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
249 if(e.takedamage == DAMAGE_AIM)
250 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
251 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
255 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
256 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
257 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
258 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
261 e.fireball_impactvec = p;
262 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
265 if(RandomSelection_chosen_ent)
267 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
268 d = damage + (edgedamage - damage) * (d / dist);
269 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
270 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
271 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
276 void napalm_ball_think(entity this)
278 if(round_handler_IsActive())
279 if(!round_handler_IsRoundStarted())
285 if(time > this.pushltime)
291 vector midpoint = ((this.absmin + this.absmax) * 0.5);
292 if(pointcontents(midpoint) == CONTENT_WATER)
294 this.velocity = this.velocity * 0.5;
296 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
297 { this.velocity_z = 200; }
300 this.angles = vectoangles(this.velocity);
302 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
303 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
305 this.nextthink = time + 0.1;
309 void nade_napalm_ball(entity this)
314 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
317 proj.owner = this.owner;
318 proj.realowner = this.realowner;
319 proj.team = this.owner.team;
320 proj.bot_dodge = true;
321 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
322 set_movetype(proj, MOVETYPE_BOUNCE);
323 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
324 PROJECTILE_MAKETRIGGER(proj);
325 setmodel(proj, MDL_Null);
326 proj.scale = 1;//0.5;
327 setsize(proj, '-4 -4 -4', '4 4 4');
328 setorigin(proj, this.origin);
329 setthink(proj, napalm_ball_think);
330 proj.nextthink = time;
331 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
332 proj.effects = EF_LOWPRECISION | EF_FLAME;
334 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
335 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
336 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
337 proj.velocity = kick;
339 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
341 proj.angles = vectoangles(proj.velocity);
342 proj.flags = FL_PROJECTILE;
343 IL_PUSH(g_projectiles, proj);
344 IL_PUSH(g_bot_dodge, proj);
345 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
347 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
351 void napalm_fountain_think(entity this)
354 if(round_handler_IsActive())
355 if(!round_handler_IsRoundStarted())
361 if(time >= this.ltime)
367 vector midpoint = ((this.absmin + this.absmax) * 0.5);
368 if(pointcontents(midpoint) == CONTENT_WATER)
370 this.velocity = this.velocity * 0.5;
372 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
373 { this.velocity_z = 200; }
375 UpdateCSQCProjectile(this);
378 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
379 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
381 this.nextthink = time + 0.1;
382 if(time >= this.nade_special_time)
384 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
385 nade_napalm_ball(this);
389 void nade_napalm_boom(entity this)
391 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
392 nade_napalm_ball(this);
394 entity fountain = new(nade_napalm_fountain);
395 fountain.owner = this.owner;
396 fountain.realowner = this.realowner;
397 fountain.origin = this.origin;
398 fountain.flags = FL_PROJECTILE;
399 IL_PUSH(g_projectiles, fountain);
400 IL_PUSH(g_bot_dodge, fountain);
401 setorigin(fountain, fountain.origin);
402 setthink(fountain, napalm_fountain_think);
403 fountain.nextthink = time;
404 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
405 fountain.pushltime = fountain.ltime;
406 fountain.team = this.team;
407 set_movetype(fountain, MOVETYPE_TOSS);
408 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
409 fountain.bot_dodge = true;
410 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
411 fountain.nade_special_time = time;
412 setsize(fountain, '-16 -16 -16', '16 16 16');
413 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
416 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
418 frost_target.frozen_by = freezefield.realowner;
419 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
420 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
422 Drop_Special_Items(frost_target);
425 void nade_ice_think(entity this)
427 if(round_handler_IsActive())
428 if(!round_handler_IsRoundStarted())
434 if(time >= this.ltime)
436 if ( autocvar_g_nades_ice_explode )
438 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
439 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
440 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
442 normal_nade_boom(this);
449 this.nextthink = time + 0.1;
454 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
456 randomw = random() * M_PI * 2;
458 randomp.x = randomr * cos(randomw);
459 randomp.y = randomr * sin(randomw);
461 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
463 if(time >= this.nade_special_time)
465 this.nade_special_time = time + 0.7;
467 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
468 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
472 float current_freeze_time = this.ltime - time - 0.1;
474 #define ICE_NADE_RADIUS_TEAMCHECK(checked) \
476 if (!it.revival_time || ((time - it.revival_time) >= 1.5)) \
477 if (!STAT(FROZEN, it)) \
478 nade_ice_freeze(this, it, current_freeze_time); \
481 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,
483 switch (autocvar_g_nades_ice_teamcheck)
485 // 1: nade owner isn't affected; 2: no teammate is affected; any other number than 1 and 2: friendly fire
486 case 1: ICE_NADE_RADIUS_TEAMCHECK(it != this.realowner);
487 case 2: ICE_NADE_RADIUS_TEAMCHECK(DIFF_TEAM(it, this.realowner) && it != this.realowner);
488 default: ICE_NADE_RADIUS_TEAMCHECK(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(it, this.realowner) || it == this.realowner));
491 #undef ICE_NADE_RADIUS_TEAMCHECK
494 void nade_ice_boom(entity this)
496 entity fountain = new(nade_ice_fountain);
497 fountain.owner = this.owner;
498 fountain.realowner = this.realowner;
499 fountain.origin = this.origin;
500 setorigin(fountain, fountain.origin);
501 setthink(fountain, nade_ice_think);
502 fountain.nextthink = time;
503 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
504 fountain.pushltime = fountain.wait = fountain.ltime;
505 fountain.team = this.team;
506 set_movetype(fountain, MOVETYPE_TOSS);
507 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
508 fountain.bot_dodge = false;
509 setsize(fountain, '-16 -16 -16', '16 16 16');
510 fountain.nade_special_time = time + 0.3;
511 fountain.angles = this.angles;
513 if ( autocvar_g_nades_ice_explode )
515 setmodel(fountain, MDL_PROJECTILE_GRENADE);
516 entity timer = new(nade_timer);
517 setmodel(timer, MDL_NADE_TIMER);
518 setattachment(timer, fountain, "");
519 timer.colormap = this.colormap;
520 timer.glowmod = this.glowmod;
521 setthink(timer, nade_timer_think);
522 timer.nextthink = time;
523 timer.wait = fountain.ltime;
524 timer.owner = fountain;
528 setmodel(fountain, MDL_Null);
531 void nade_translocate_boom(entity this)
533 if(this.realowner.vehicle)
536 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
538 if(!move_out_of_solid(this))
540 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
544 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
545 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
546 locout = trace_endpos;
548 makevectors(this.realowner.angles);
550 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
552 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
555 void nade_spawn_boom(entity this)
557 entity player = this.realowner;
558 entity spawnloc = new(nade_spawn_loc);
559 setorigin(spawnloc, this.origin);
560 setsize(spawnloc, player.mins, player.maxs);
561 set_movetype(spawnloc, MOVETYPE_NONE);
562 spawnloc.solid = SOLID_NOT;
563 spawnloc.drawonlytoclient = player;
564 spawnloc.effects = EF_STARDUST;
565 spawnloc.cnt = autocvar_g_nades_spawn_count;
567 if(player.nade_spawnloc)
568 delete(player.nade_spawnloc);
570 player.nade_spawnloc = spawnloc;
573 void nades_orb_think(entity this)
575 if(time >= this.ltime)
581 this.nextthink = time;
583 if(time >= this.nade_special_time)
585 this.nade_special_time = time+0.25;
586 this.nade_show_particles = 1;
589 this.nade_show_particles = 0;
592 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
594 // NOTE: this function merely places an orb
595 // you must add a custom touch function to the returned entity if desired
596 // also set .colormod if you wish to have it colorized
597 entity orb = new(nades_spawn_orb);
599 orb.realowner = realown;
602 orb.orb_lifetime = orb_ltime; // required for timers
603 orb.ltime = time + orb.orb_lifetime;
604 orb.bot_dodge = false;
605 orb.team = realown.team;
606 orb.solid = SOLID_TRIGGER;
608 setmodel(orb, MDL_NADE_ORB);
610 orb.orb_radius = orb_rad; // required for fading
611 vector size = '1 1 1' * orb.orb_radius / 2;
612 setsize(orb, -size, size);
614 Net_LinkEntity(orb, true, 0, orb_send);
617 setthink(orb, nades_orb_think);
618 orb.nextthink = time;
623 void nade_entrap_touch(entity this, entity toucher)
625 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
627 if (!isPushable(toucher))
630 float pushdeltatime = time - toucher.lastpushtime;
631 if (pushdeltatime > 0.15) pushdeltatime = 0;
632 toucher.lastpushtime = time;
633 if(!pushdeltatime) return;
635 // div0: ticrate independent, 1 = identity (not 20)
636 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
639 UpdateCSQCProjectile(toucher);
643 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
645 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
646 show_tint.nade_entrap_time = time + 0.1;
650 void nade_entrap_boom(entity this)
652 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
654 settouch(orb, nade_entrap_touch);
655 orb.colormod = NADE_TYPE_ENTRAP.m_color;
658 void nade_heal_touch(entity this, entity toucher)
663 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
664 if(!IS_DEAD(toucher))
665 if(!STAT(FROZEN, toucher))
667 health_factor = autocvar_g_nades_heal_rate*frametime/2;
668 if ( toucher != this.realowner )
669 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
671 if ( health_factor > 0 )
673 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
674 float hp = GetResource(toucher, RES_HEALTH);
677 if (this.nade_show_particles)
678 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
680 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
683 else if ( health_factor < 0 )
684 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
688 void nade_heal_boom(entity this)
690 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
692 settouch(orb, nade_heal_touch);
693 orb.colormod = '1 0 0';
696 void nade_monster_boom(entity this)
698 if(!autocvar_g_monsters)
701 e.noalign = true; // don't drop to floor
702 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
704 return; // monster failed to be spawned
706 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
707 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
708 e.monster_skill = MONSTER_SKILL_INSANE;
711 void nade_veil_touch(entity this, entity toucher)
713 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
715 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
717 float tint_alpha = 0.75;
718 if(SAME_TEAM(toucher, this.realowner))
721 if(!show_tint.nade_veil_time)
723 toucher.nade_veil_prevalpha = toucher.alpha;
727 show_tint.nade_veil_time = time + 0.1;
731 void nade_veil_boom(entity this)
733 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
735 settouch(orb, nade_veil_touch);
736 orb.colormod = NADE_TYPE_VEIL.m_color;
739 void nade_ammo_touch(entity this, entity toucher)
743 float amshells = GetResource(toucher, RES_SHELLS);
744 float ambullets = GetResource(toucher, RES_BULLETS);
745 float amrockets = GetResource(toucher, RES_ROCKETS);
746 float amcells = GetResource(toucher, RES_CELLS);
747 float amplasma = GetResource(toucher, RES_PLASMA);
748 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
749 if(!IS_DEAD(toucher))
750 if(!STAT(FROZEN, toucher))
752 ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
753 if ( toucher != this.realowner )
754 ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
756 #define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
757 if (amresource < maxammo) \
758 GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
760 #define DROP_AMMO_RESOURCE(amresource, res_resource) \
761 if (amresource > 0) \
762 SetResource(toucher, res_resource, amresource + ammo_factor);
764 if ( ammo_factor > 0 )
766 CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
767 CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
768 CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
769 CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
770 CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
772 if (this.nade_show_particles)
773 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
775 else if ( ammo_factor < 0 )
777 //Foe drops ammo points
778 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
779 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
780 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
781 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
782 DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
787 #undef CHECK_AMMO_RESOURCE_LIMIT
788 #undef DROP_AMMO_RESOURCE
790 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
792 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
793 show_tint.nade_ammo_time = time + 0.1;
797 void nade_ammo_boom(entity this)
799 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
801 settouch(orb, nade_ammo_touch);
802 orb.colormod = '0.66 0.33 0';
805 void DarkBlinking(entity e)
807 if(e == NULL) return;
809 int accepted = VerifyClientEntity(e, true, false);
814 WriteHeader(MSG_ONE, TE_CSQC_DARKBLINKING);
818 void nade_darkness_think(entity this)
820 if(round_handler_IsActive())
821 if(!round_handler_IsRoundStarted())
827 if(time >= this.ltime)
829 if ( autocvar_g_nades_darkness_explode )
831 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
832 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
833 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
835 normal_nade_boom(this);
838 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
844 this.nextthink = time + 0.1;
849 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
851 randomw = random() * M_PI * 2;
853 randomp.x = randomr * cos(randomw);
854 randomp.y = randomr * sin(randomw);
856 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
858 if(time >= this.nade_special_time)
860 this.nade_special_time = time + 0.7;
861 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
864 float current_dark_time = this.ltime - time - 0.1;
866 #define DARK_NADE_RADIUS_TEAMCHECK(checked) \
868 if ( IS_REAL_CLIENT(it) ) \
870 STAT(NADE_DARKNESS_TIME, it) = time + 0.1; \
875 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0,
877 switch (autocvar_g_nades_darkness_teamcheck)
879 // 1: nade owner isn't affected; 2: no teammate is affected; any other number than 1 and 2: friendly fire
880 case 1: DARK_NADE_RADIUS_TEAMCHECK(it != this.realowner);
881 case 2: DARK_NADE_RADIUS_TEAMCHECK(DIFF_TEAM(it, this.realowner) && it != this.realowner);
882 default: DARK_NADE_RADIUS_TEAMCHECK(!autocvar_g_nades_darkness_teamcheck || (DIFF_TEAM(it, this.realowner) && it != this.realowner));
885 #undef DARK_NADE_RADIUS_TEAMCHECK
888 void nade_darkness_boom(entity this)
890 entity fountain = new(nade_darkness_fountain);
891 fountain.owner = this.owner;
892 fountain.realowner = this.realowner;
893 fountain.origin = this.origin;
894 setorigin(fountain, fountain.origin);
895 setthink(fountain, nade_darkness_think);
896 fountain.nextthink = time;
897 fountain.ltime = time + autocvar_g_nades_darkness_time;
898 fountain.pushltime = fountain.wait = fountain.ltime;
899 fountain.team = this.team;
900 set_movetype(fountain, MOVETYPE_TOSS);
901 fountain.projectiledeathtype = DEATH_NADE.m_id;
902 fountain.bot_dodge = false;
903 setsize(fountain, '-16 -16 -16', '16 16 16');
904 fountain.nade_special_time = time + 0.3;
905 fountain.angles = this.angles;
907 if ( autocvar_g_nades_darkness_explode )
909 setmodel(fountain, MDL_PROJECTILE_GRENADE);
910 entity timer = new(nade_timer);
911 setmodel(timer, MDL_NADE_TIMER);
912 setattachment(timer, fountain, "");
913 timer.colormap = this.colormap;
914 timer.glowmod = this.glowmod;
915 setthink(timer, nade_timer_think);
916 timer.nextthink = time;
917 timer.wait = fountain.ltime;
918 timer.owner = fountain;
922 setmodel(fountain, MDL_Null);
925 void nade_boom(entity this)
928 bool nade_blast = true;
930 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
931 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
932 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
933 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
934 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
935 EFFECT_SPAWN_NEUTRAL))))
937 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
939 nade_blast = blast; \
940 expef = exp_effect; \
943 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
945 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
946 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
947 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
948 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
949 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
950 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
951 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
952 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
953 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
954 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
955 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
956 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
958 #undef GET_NADE_TYPE_SPAWN_EFFECT
959 #undef SET_NADE_EFFECT
962 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
964 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
965 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
967 this.event_damage = func_null; // prevent somehow calling damage in the next call
970 normal_nade_boom(this);
973 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
975 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
976 case NADE_TYPE_ICE: nade_ice_boom(this); break;
977 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
978 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
979 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
980 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
981 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
982 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
983 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
984 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
987 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
995 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
996 void nade_pickup(entity this, entity thenade)
998 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
1000 // set refire so player can't even
1001 this.nade_refire = time + autocvar_g_nades_nade_refire;
1002 STAT(NADE_TIMER, this) = 0;
1005 this.nade.nade_time_primed = thenade.nade_time_primed;
1008 bool CanThrowNade(entity this);
1009 void nade_touch(entity this, entity toucher)
1012 UpdateCSQCProjectile(this);
1014 if(toucher == this.realowner)
1015 return; // no this impacts
1017 if(autocvar_g_nades_pickup)
1018 if(time >= this.spawnshieldtime)
1019 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
1020 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
1021 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
1023 nade_pickup(toucher, this);
1024 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1028 /*float is_weapclip = 0;
1029 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
1030 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
1031 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
1033 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1035 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1043 PROJECTILE_TOUCH(this, toucher);
1045 //setsize(this, '-2 -2 -2', '2 2 2');
1046 //UpdateCSQCProjectile(this);
1047 if(GetResource(this, RES_HEALTH) == this.max_health)
1049 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1053 this.enemy = toucher;
1057 void nade_beep(entity this)
1059 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1060 setthink(this, nade_boom);
1061 this.nextthink = max(this.wait, time);
1064 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1066 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1068 this.takedamage = DAMAGE_NO;
1073 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1076 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1077 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1082 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
1084 force *= 0.5; // too much
1087 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1090 damage = this.max_health * 0.55;
1092 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1093 damage = this.max_health * 0.1;
1094 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1096 if(!(deathtype & HITTYPE_SECONDARY))
1097 damage = this.max_health * 1.15;
1101 entity death_weapon = DEATH_WEAPONOF(deathtype);
1102 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1104 damage = this.max_health * 0.1;
1108 this.velocity += force;
1109 UpdateCSQCProjectile(this);
1111 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1114 float hp = GetResource(this, RES_HEALTH);
1115 if(hp == this.max_health)
1117 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1118 this.nextthink = max(time + this.nade_lifetime, time);
1119 setthink(this, nade_beep);
1123 SetResource(this, RES_HEALTH, hp);
1125 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1126 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1127 this.realowner = attacker;
1131 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1132 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1134 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1136 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1137 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1142 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1145 nade_burn_spawn(this);
1148 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1153 entity _nade = e.nade;
1157 delete(e.fake_nade);
1160 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1162 makevectors(e.v_angle);
1164 // NOTE: always throw from first weapon entity?
1165 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1167 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1168 + (v_right * autocvar_g_nades_throw_offset.y)
1169 + (v_up * autocvar_g_nades_throw_offset.z);
1171 setorigin(_nade, w_shotorg + offset);
1172 //setmodel(_nade, MDL_PROJECTILE_NADE);
1173 //setattachment(_nade, NULL, "");
1174 PROJECTILE_MAKETRIGGER(_nade);
1175 if(STAT(NADES_SMALL, e))
1176 setsize(_nade, '-8 -8 -8', '8 8 8');
1178 setsize(_nade, '-16 -16 -16', '16 16 16');
1179 set_movetype(_nade, MOVETYPE_BOUNCE);
1181 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1182 if (trace_startsolid)
1183 setorigin(_nade, e.origin);
1185 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1186 _nade.velocity = '0 0 100';
1187 else if(autocvar_g_nades_nade_newton_style == 1)
1188 _nade.velocity = e.velocity + _velocity;
1189 else if(autocvar_g_nades_nade_newton_style == 2)
1190 _nade.velocity = _velocity;
1192 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1195 _nade.realowner = e;
1197 settouch(_nade, nade_touch);
1198 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1199 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1200 _nade.max_health = GetResource(_nade, RES_HEALTH);
1201 _nade.takedamage = DAMAGE_AIM;
1202 _nade.event_damage = nade_damage;
1203 setcefc(_nade, func_null);
1204 _nade.exteriormodeltoclient = NULL;
1205 _nade.traileffectnum = 0;
1206 _nade.teleportable = true;
1207 _nade.pushable = true;
1209 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1210 _nade.damagedbycontents = true;
1211 IL_PUSH(g_damagedbycontents, _nade);
1212 _nade.angles = vectoangles(_nade.velocity);
1213 _nade.flags = FL_PROJECTILE;
1214 IL_PUSH(g_projectiles, _nade);
1215 IL_PUSH(g_bot_dodge, _nade);
1216 _nade.projectiledeathtype = DEATH_NADE.m_id;
1217 _nade.toss_time = time;
1218 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1220 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1221 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1223 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1229 setthink(_nade, nade_boom);
1230 _nade.nextthink = _time;
1233 e.nade_refire = time + autocvar_g_nades_nade_refire;
1234 STAT(NADE_TIMER, e) = 0;
1237 void nades_GiveBonus(entity player, float score)
1239 if (autocvar_g_nades)
1240 if (autocvar_g_nades_bonus)
1241 if (IS_REAL_CLIENT(player))
1242 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1243 if (!STAT(FROZEN, player))
1244 if (!IS_DEAD(player))
1246 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1247 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1249 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1251 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1252 play2(player, SND(NADE_BONUS));
1253 STAT(NADE_BONUS, player)++;
1254 STAT(NADE_BONUS_SCORE, player) -= 1;
1259 /** Remove all bonus nades from a player */
1260 void nades_RemoveBonus(entity player)
1262 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1265 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1267 entity player = M_ARGV(0, entity);
1269 nades_RemoveBonus(player);
1272 bool nade_customize(entity this, entity client)
1274 //if(IS_SPEC(client)) { return false; }
1275 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1277 // somewhat hide the model, but keep the glow
1279 if(this.traileffectnum)
1280 this.traileffectnum = 0;
1285 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1286 if(!this.traileffectnum)
1288 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1289 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1297 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1299 entity n = new(nade), fn = new(fake_nade);
1301 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1302 n.pokenade_type = pntype;
1304 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1305 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1307 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1309 setmodel(n, MDL_PROJECTILE_NADE);
1310 //setattachment(n, player, "bip01 l hand");
1311 n.exteriormodeltoclient = player;
1312 setcefc(n, nade_customize);
1313 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1314 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1315 n.realowner = nowner;
1316 n.colormap = player.colormap;
1317 n.glowmod = player.glowmod;
1318 n.wait = time + max(0, ntime);
1319 n.nade_time_primed = time;
1320 setthink(n, nade_beep);
1321 n.nextthink = max(n.wait - 3, time);
1322 n.projectiledeathtype = DEATH_NADE.m_id;
1323 n.weaponentity_fld = weaponentity;
1324 n.nade_lifetime = ntime;
1325 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1327 setmodel(fn, MDL_NADE_VIEW);
1328 //setattachment(fn, player.(weaponentity), "");
1329 fn.viewmodelforclient = player;
1330 fn.realowner = fn.owner = player;
1331 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1332 fn.colormap = player.colormap;
1333 fn.glowmod = player.glowmod;
1334 setthink(fn, SUB_Remove);
1335 fn.nextthink = n.wait;
1336 fn.weaponentity_fld = weaponentity;
1337 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1340 player.fake_nade = fn;
1343 void nade_prime(entity this)
1345 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1346 return; // only allow bonus nades
1348 // TODO: handle old nade if it exists?
1354 delete(this.fake_nade);
1355 this.fake_nade = NULL;
1358 string pntype = this.pokenade_type;
1360 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1361 ntype = STAT(NADE_BONUS_TYPE, this);
1362 else if (STAT(NADE_BONUS, this) >= 1)
1364 ntype = STAT(NADE_BONUS_TYPE, this);
1365 pntype = this.pokenade_type;
1366 STAT(NADE_BONUS, this) -= 1;
1370 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1371 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1374 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1377 bool CanThrowNade(entity this)
1379 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1382 .bool nade_altbutton;
1384 void nades_CheckThrow(entity this)
1386 if(!CanThrowNade(this))
1389 entity held_nade = this.nade;
1392 this.nade_altbutton = true;
1393 if(time > this.nade_refire)
1396 this.nade_refire = time + autocvar_g_nades_nade_refire;
1401 this.nade_altbutton = false;
1402 if (time >= held_nade.nade_time_primed + 1) {
1403 makevectors(this.v_angle);
1404 float _force = time - held_nade.nade_time_primed;
1405 _force /= autocvar_g_nades_nade_lifetime;
1406 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1407 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1408 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1409 toss_nade(this, true, dir * _force, 0);
1414 void nades_Clear(entity player)
1417 delete(player.nade);
1418 if(player.fake_nade)
1419 delete(player.fake_nade);
1421 player.nade = player.fake_nade = NULL;
1422 STAT(NADE_TIMER, player) = 0;
1425 int nades_CheckTypes(entity player, int cl_ntype)
1427 #define CL_NADE_TYPE_CHECK(cl_ntype, cvar) \
1428 case cl_ntype.m_id: \
1429 if (!cvar) return NADE_TYPE_NORMAL.m_id; \
1434 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1435 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1436 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1437 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1438 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1439 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1440 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1441 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1442 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1443 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1446 #undef CL_NADE_TYPE_CHECK
1449 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1451 entity player = M_ARGV(0, entity);
1454 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1457 CLASS(NadeOffhand, OffhandWeapon)
1458 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1460 entity held_nade = player.nade;
1462 if (!CanThrowNade(player)) return;
1463 if (!(time > player.nade_refire)) return;
1467 held_nade = player.nade;
1469 } else if (time >= held_nade.nade_time_primed + 1) {
1471 makevectors(player.v_angle);
1472 float _force = time - held_nade.nade_time_primed;
1473 _force /= autocvar_g_nades_nade_lifetime;
1474 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1475 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1476 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1477 toss_nade(player, false, dir * _force, 0);
1481 ENDCLASS(NadeOffhand)
1482 NadeOffhand OFFHAND_NADE;
1483 REGISTER_MUTATOR(nades, autocvar_g_nades)
1487 OFFHAND_NADE = NEW(NadeOffhand);
1492 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1494 entity player = M_ARGV(0, entity);
1496 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1497 nades_CheckThrow(player);
1502 #ifdef IN_REVIVING_RANGE
1503 #undef IN_REVIVING_RANGE
1506 // returns true if player is reviving it
1507 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1508 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1509 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1511 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1513 entity player = M_ARGV(0, entity);
1515 if (!IS_PLAYER(player)) { return; }
1517 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1518 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1520 entity held_nade = player.nade;
1523 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1524 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1525 makevectors(player.angles);
1526 held_nade.velocity = player.velocity;
1527 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1528 held_nade.angles_y = player.angles.y;
1530 if (time + 0.1 >= held_nade.wait)
1532 toss_nade(player, false, '0 0 0', time + 0.05);
1533 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1537 if(IS_PLAYER(player))
1539 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1542 float key_count = 0;
1543 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1546 if(GameRules_scoring_is_vip(player))
1547 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1549 time_score = autocvar_g_nades_bonus_score_time;
1552 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1554 if(autocvar_g_nades_bonus_client_select)
1556 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1557 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1561 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1562 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1565 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1567 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1568 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1572 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1575 if(player.nade_veil_time && player.nade_veil_time <= time)
1577 player.nade_veil_time = 0;
1579 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1581 player.alpha = player.nade_veil_prevalpha;
1585 if (!(frametime && IS_PLAYER(player)))
1588 entity revivers_last = NULL;
1589 entity revivers_first = NULL;
1591 bool player_is_reviving = false;
1593 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1594 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1595 // check if player is reviving anyone
1596 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1598 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1600 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1602 player_is_reviving = true;
1606 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1607 continue; // both player and it are NOT frozen
1609 revivers_last.chain = it;
1611 if (!revivers_first)
1612 revivers_first = it;
1616 revivers_last.chain = NULL;
1618 if (!n) // no teammate nearby
1620 // freezetag already resets revive progress
1621 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1622 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1624 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1626 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1627 // undo what PlayerPreThink did
1628 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1629 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1631 if(STAT(REVIVE_PROGRESS, player) >= 1)
1633 Unfreeze(player, false);
1635 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1636 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1639 for(entity it = revivers_first; it; it = it.chain)
1640 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1644 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1646 entity player = M_ARGV(0, entity);
1647 // these automatically reset, no need to worry
1649 if(player.nade_entrap_time > time)
1650 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1653 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1655 entity mon = M_ARGV(0, entity);
1657 if (mon.nade_entrap_time > time)
1659 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1660 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1663 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1665 mon.alpha = mon.nade_veil_prevalpha;
1666 mon.nade_veil_time = 0;
1670 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1672 entity player = M_ARGV(0, entity);
1674 if (autocvar_g_nades_onspawn)
1676 if (StatusEffects_active(STATUSEFFECT_SpawnShield, player))
1677 player.nade_refire = time + autocvar_g_spawnshieldtime;
1680 player.nade_refire = time + autocvar_g_nades_nade_refire;
1682 if(autocvar_g_nades_bonus_client_select)
1683 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1685 STAT(NADE_TIMER, player) = 0;
1687 if (!player.offhand) player.offhand = OFFHAND_NADE;
1689 if(player.nade_spawnloc)
1691 setorigin(player, player.nade_spawnloc.origin);
1692 player.nade_spawnloc.cnt -= 1;
1694 if(player.nade_spawnloc.cnt <= 0)
1696 delete(player.nade_spawnloc);
1697 player.nade_spawnloc = NULL;
1700 if(autocvar_g_nades_spawn_health_respawn > 0)
1701 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1705 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1707 entity frag_attacker = M_ARGV(1, entity);
1708 entity frag_target = M_ARGV(2, entity);
1710 if(frag_target.nade)
1711 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1712 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1714 if(IS_PLAYER(frag_attacker))
1716 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)
1717 : autocvar_g_nades_bonus_score_minor);
1718 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1719 nades_RemoveBonus(frag_attacker);
1720 else if(GameRules_scoring_is_vip(frag_target))
1721 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1722 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1724 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1725 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1726 switch(CS(frag_attacker).killcount)
1729 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1734 nades_GiveBonus(frag_attacker, killcount_bonus);
1737 nades_RemoveBonus(frag_target);
1740 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1742 entity frag_inflictor = M_ARGV(0, entity);
1743 entity frag_attacker = M_ARGV(1, entity);
1744 entity frag_target = M_ARGV(2, entity);
1745 float frag_deathtype = M_ARGV(3, float);
1747 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1748 if(time - frag_inflictor.toss_time <= 0.1)
1750 Unfreeze(frag_target, false);
1751 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1752 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1753 M_ARGV(4, float) = 0;
1754 M_ARGV(6, vector) = '0 0 0';
1755 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1756 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1760 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1762 entity frag_target = M_ARGV(0, entity);
1763 entity frag_attacker = M_ARGV(1, entity);
1765 if(IS_PLAYER(frag_attacker))
1766 if(DIFF_TEAM(frag_attacker, frag_target))
1767 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1768 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1771 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1773 entity frag_target = M_ARGV(0, entity);
1775 if(frag_target.nade)
1776 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1779 void nades_RemovePlayer(entity this)
1782 nades_RemoveBonus(this);
1785 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1786 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1787 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1789 FOREACH_CLIENT(IS_PLAYER(it),
1791 nades_RemovePlayer(it);
1795 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1797 entity spectatee = M_ARGV(0, entity);
1798 entity client = M_ARGV(1, entity);
1800 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1801 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1802 client.pokenade_type = spectatee.pokenade_type;
1803 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1804 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1807 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1809 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1812 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1814 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");