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 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
475 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0
476 && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it),
478 switch (autocvar_g_nades_ice_teamcheck)
480 case 0: break; // affect everyone
482 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
483 // fall through (check case 1 condition too)
484 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
486 nade_ice_freeze(this, it, current_freeze_time);
490 void nade_ice_boom(entity this)
492 entity fountain = new(nade_ice_fountain);
493 fountain.owner = this.owner;
494 fountain.realowner = this.realowner;
495 fountain.origin = this.origin;
496 setorigin(fountain, fountain.origin);
497 setthink(fountain, nade_ice_think);
498 fountain.nextthink = time;
499 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
500 fountain.pushltime = fountain.wait = fountain.ltime;
501 fountain.team = this.team;
502 set_movetype(fountain, MOVETYPE_TOSS);
503 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
504 fountain.bot_dodge = false;
505 setsize(fountain, '-16 -16 -16', '16 16 16');
506 fountain.nade_special_time = time + 0.3;
507 fountain.angles = this.angles;
509 if ( autocvar_g_nades_ice_explode )
511 setmodel(fountain, MDL_PROJECTILE_GRENADE);
512 entity timer = new(nade_timer);
513 setmodel(timer, MDL_NADE_TIMER);
514 setattachment(timer, fountain, "");
515 timer.colormap = this.colormap;
516 timer.glowmod = this.glowmod;
517 setthink(timer, nade_timer_think);
518 timer.nextthink = time;
519 timer.wait = fountain.ltime;
520 timer.owner = fountain;
524 setmodel(fountain, MDL_Null);
527 void nade_translocate_boom(entity this)
529 if(this.realowner.vehicle)
532 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
534 if(!move_out_of_solid(this))
536 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
540 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
541 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
542 locout = trace_endpos;
544 makevectors(this.realowner.angles);
546 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
548 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
551 void nade_spawn_boom(entity this)
553 entity player = this.realowner;
554 entity spawnloc = new(nade_spawn_loc);
555 setorigin(spawnloc, this.origin);
556 setsize(spawnloc, player.mins, player.maxs);
557 set_movetype(spawnloc, MOVETYPE_NONE);
558 spawnloc.solid = SOLID_NOT;
559 spawnloc.drawonlytoclient = player;
560 spawnloc.effects = EF_STARDUST;
561 spawnloc.cnt = autocvar_g_nades_spawn_count;
563 if(player.nade_spawnloc)
564 delete(player.nade_spawnloc);
566 player.nade_spawnloc = spawnloc;
569 void nades_orb_think(entity this)
571 if(time >= this.ltime)
577 this.nextthink = time;
579 if(time >= this.nade_special_time)
581 this.nade_special_time = time+0.25;
582 this.nade_show_particles = 1;
585 this.nade_show_particles = 0;
588 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
590 // NOTE: this function merely places an orb
591 // you must add a custom touch function to the returned entity if desired
592 // also set .colormod if you wish to have it colorized
593 entity orb = new(nades_spawn_orb);
595 orb.realowner = realown;
598 orb.orb_lifetime = orb_ltime; // required for timers
599 orb.ltime = time + orb.orb_lifetime;
600 orb.bot_dodge = false;
601 orb.team = realown.team;
602 orb.solid = SOLID_TRIGGER;
604 setmodel(orb, MDL_NADE_ORB);
606 orb.orb_radius = orb_rad; // required for fading
607 vector size = '1 1 1' * orb.orb_radius / 2;
608 setsize(orb, -size, size);
610 Net_LinkEntity(orb, true, 0, orb_send);
613 setthink(orb, nades_orb_think);
614 orb.nextthink = time;
619 void nade_entrap_touch(entity this, entity toucher)
621 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
623 if (!isPushable(toucher))
626 float pushdeltatime = time - toucher.lastpushtime;
627 if (pushdeltatime > 0.15) pushdeltatime = 0;
628 toucher.lastpushtime = time;
629 if(!pushdeltatime) return;
631 // div0: ticrate independent, 1 = identity (not 20)
632 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
635 UpdateCSQCProjectile(toucher);
639 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
641 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
642 show_tint.nade_entrap_time = time + 0.1;
646 void nade_entrap_boom(entity this)
648 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
650 settouch(orb, nade_entrap_touch);
651 orb.colormod = NADE_TYPE_ENTRAP.m_color;
654 void nade_heal_touch(entity this, entity toucher)
659 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
660 if(!IS_DEAD(toucher))
661 if(!STAT(FROZEN, toucher))
663 health_factor = autocvar_g_nades_heal_rate*frametime/2;
664 if ( toucher != this.realowner )
665 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
667 if ( health_factor > 0 )
669 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
670 float hp = GetResource(toucher, RES_HEALTH);
673 if (this.nade_show_particles)
674 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
676 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
679 else if ( health_factor < 0 )
680 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
684 void nade_heal_boom(entity this)
686 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
688 settouch(orb, nade_heal_touch);
689 orb.colormod = '1 0 0';
692 void nade_monster_boom(entity this)
694 if(!autocvar_g_monsters)
697 e.noalign = true; // don't drop to floor
698 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
700 return; // monster failed to be spawned
702 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
703 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
704 e.monster_skill = MONSTER_SKILL_INSANE;
707 void nade_veil_touch(entity this, entity toucher)
709 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
711 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
713 float tint_alpha = 0.75;
714 if(SAME_TEAM(toucher, this.realowner))
717 if(!show_tint.nade_veil_time)
719 toucher.nade_veil_prevalpha = toucher.alpha;
723 show_tint.nade_veil_time = time + 0.1;
727 void nade_veil_boom(entity this)
729 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
731 settouch(orb, nade_veil_touch);
732 orb.colormod = NADE_TYPE_VEIL.m_color;
735 void nade_ammo_touch(entity this, entity toucher)
739 float amshells = GetResource(toucher, RES_SHELLS);
740 float ambullets = GetResource(toucher, RES_BULLETS);
741 float amrockets = GetResource(toucher, RES_ROCKETS);
742 float amcells = GetResource(toucher, RES_CELLS);
743 float amplasma = GetResource(toucher, RES_PLASMA);
744 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
745 if(!IS_DEAD(toucher))
746 if(!STAT(FROZEN, toucher))
748 ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
749 if ( toucher != this.realowner )
750 ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
752 #define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
753 if (amresource < maxammo) \
754 GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
756 #define DROP_AMMO_RESOURCE(amresource, res_resource) \
757 if (amresource > 0) \
758 SetResource(toucher, res_resource, amresource + ammo_factor);
760 if ( ammo_factor > 0 )
762 CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
763 CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
764 CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
765 CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
766 CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
768 if (this.nade_show_particles)
769 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
771 else if ( ammo_factor < 0 )
773 //Foe drops ammo points
774 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
775 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
776 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
777 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
778 DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
783 #undef CHECK_AMMO_RESOURCE_LIMIT
784 #undef DROP_AMMO_RESOURCE
786 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
788 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
789 show_tint.nade_ammo_time = time + 0.1;
793 void nade_ammo_boom(entity this)
795 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
797 settouch(orb, nade_ammo_touch);
798 orb.colormod = '0.66 0.33 0';
801 void DarkBlinking(entity e)
803 if(e == NULL) return;
805 int accepted = VerifyClientEntity(e, true, false);
810 WriteHeader(MSG_ONE, TE_CSQC_DARKBLINKING);
814 void nade_darkness_think(entity this)
816 if(round_handler_IsActive())
817 if(!round_handler_IsRoundStarted())
823 if(time >= this.ltime)
825 if ( autocvar_g_nades_darkness_explode )
827 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
828 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
829 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
831 normal_nade_boom(this);
834 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
840 this.nextthink = time + 0.1;
845 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
847 randomw = random() * M_PI * 2;
849 randomp.x = randomr * cos(randomw);
850 randomp.y = randomr * sin(randomw);
852 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
854 if(time >= this.nade_special_time)
856 this.nade_special_time = time + 0.7;
857 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
861 float current_dark_time = this.ltime - time - 0.1;
863 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
864 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
866 switch (autocvar_g_nades_darkness_teamcheck)
868 case 0: break; // affect everyone
870 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
871 // fall through (check case 1 condition too)
872 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
874 STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
879 void nade_darkness_boom(entity this)
881 entity fountain = new(nade_darkness_fountain);
882 fountain.owner = this.owner;
883 fountain.realowner = this.realowner;
884 fountain.origin = this.origin;
885 setorigin(fountain, fountain.origin);
886 setthink(fountain, nade_darkness_think);
887 fountain.nextthink = time;
888 fountain.ltime = time + autocvar_g_nades_darkness_time;
889 fountain.pushltime = fountain.wait = fountain.ltime;
890 fountain.team = this.team;
891 set_movetype(fountain, MOVETYPE_TOSS);
892 fountain.projectiledeathtype = DEATH_NADE.m_id;
893 fountain.bot_dodge = false;
894 setsize(fountain, '-16 -16 -16', '16 16 16');
895 fountain.nade_special_time = time + 0.3;
896 fountain.angles = this.angles;
898 if ( autocvar_g_nades_darkness_explode )
900 setmodel(fountain, MDL_PROJECTILE_GRENADE);
901 entity timer = new(nade_timer);
902 setmodel(timer, MDL_NADE_TIMER);
903 setattachment(timer, fountain, "");
904 timer.colormap = this.colormap;
905 timer.glowmod = this.glowmod;
906 setthink(timer, nade_timer_think);
907 timer.nextthink = time;
908 timer.wait = fountain.ltime;
909 timer.owner = fountain;
913 setmodel(fountain, MDL_Null);
916 void nade_boom(entity this)
919 bool nade_blast = true;
921 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
922 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
923 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
924 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
925 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
926 EFFECT_SPAWN_NEUTRAL))))
928 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
930 nade_blast = blast; \
931 expef = exp_effect; \
934 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
936 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
937 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
938 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
939 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
940 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
941 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
942 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
943 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
944 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
945 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
946 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
947 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
949 #undef GET_NADE_TYPE_SPAWN_EFFECT
950 #undef SET_NADE_EFFECT
953 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
955 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
956 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
958 this.event_damage = func_null; // prevent somehow calling damage in the next call
961 normal_nade_boom(this);
964 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
966 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
967 case NADE_TYPE_ICE: nade_ice_boom(this); break;
968 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
969 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
970 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
971 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
972 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
973 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
974 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
975 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
978 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
986 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
987 void nade_pickup(entity this, entity thenade)
989 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
991 // set refire so player can't even
992 this.nade_refire = time + autocvar_g_nades_nade_refire;
993 STAT(NADE_TIMER, this) = 0;
996 this.nade.nade_time_primed = thenade.nade_time_primed;
999 bool CanThrowNade(entity this);
1000 void nade_touch(entity this, entity toucher)
1003 UpdateCSQCProjectile(this);
1005 if(toucher == this.realowner)
1006 return; // no this impacts
1008 if(autocvar_g_nades_pickup)
1009 if(time >= this.spawnshieldtime)
1010 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
1011 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
1012 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
1014 nade_pickup(toucher, this);
1015 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1019 /*float is_weapclip = 0;
1020 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
1021 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
1022 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
1024 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1026 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1034 PROJECTILE_TOUCH(this, toucher);
1036 //setsize(this, '-2 -2 -2', '2 2 2');
1037 //UpdateCSQCProjectile(this);
1038 if(GetResource(this, RES_HEALTH) == this.max_health)
1040 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1044 this.enemy = toucher;
1048 void nade_beep(entity this)
1050 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1051 setthink(this, nade_boom);
1052 this.nextthink = max(this.wait, time);
1055 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1057 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1059 this.takedamage = DAMAGE_NO;
1064 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1067 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1068 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1073 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
1075 force *= 0.5; // too much
1078 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1081 damage = this.max_health * 0.55;
1083 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1084 damage = this.max_health * 0.1;
1085 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1087 if(!(deathtype & HITTYPE_SECONDARY))
1088 damage = this.max_health * 1.15;
1092 entity death_weapon = DEATH_WEAPONOF(deathtype);
1093 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1095 damage = this.max_health * 0.1;
1099 this.velocity += force;
1100 UpdateCSQCProjectile(this);
1102 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1105 float hp = GetResource(this, RES_HEALTH);
1106 if(hp == this.max_health)
1108 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1109 this.nextthink = max(time + this.nade_lifetime, time);
1110 setthink(this, nade_beep);
1114 SetResource(this, RES_HEALTH, hp);
1116 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1117 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1118 this.realowner = attacker;
1122 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1123 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1125 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1127 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1128 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1133 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1136 nade_burn_spawn(this);
1139 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1144 entity _nade = e.nade;
1148 delete(e.fake_nade);
1151 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1153 makevectors(e.v_angle);
1155 // NOTE: always throw from first weapon entity?
1156 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1158 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1159 + (v_right * autocvar_g_nades_throw_offset.y)
1160 + (v_up * autocvar_g_nades_throw_offset.z);
1162 setorigin(_nade, w_shotorg + offset);
1163 //setmodel(_nade, MDL_PROJECTILE_NADE);
1164 //setattachment(_nade, NULL, "");
1165 PROJECTILE_MAKETRIGGER(_nade);
1166 if(STAT(NADES_SMALL, e))
1167 setsize(_nade, '-8 -8 -8', '8 8 8');
1169 setsize(_nade, '-16 -16 -16', '16 16 16');
1170 set_movetype(_nade, MOVETYPE_BOUNCE);
1172 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1173 if (trace_startsolid)
1174 setorigin(_nade, e.origin);
1176 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1177 _nade.velocity = '0 0 100';
1178 else if(autocvar_g_nades_nade_newton_style == 1)
1179 _nade.velocity = e.velocity + _velocity;
1180 else if(autocvar_g_nades_nade_newton_style == 2)
1181 _nade.velocity = _velocity;
1183 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1186 _nade.realowner = e;
1188 settouch(_nade, nade_touch);
1189 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1190 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1191 _nade.max_health = GetResource(_nade, RES_HEALTH);
1192 _nade.takedamage = DAMAGE_AIM;
1193 _nade.event_damage = nade_damage;
1194 setcefc(_nade, func_null);
1195 _nade.exteriormodeltoclient = NULL;
1196 _nade.traileffectnum = 0;
1197 _nade.teleportable = true;
1198 _nade.pushable = true;
1200 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1201 _nade.damagedbycontents = true;
1202 IL_PUSH(g_damagedbycontents, _nade);
1203 _nade.angles = vectoangles(_nade.velocity);
1204 _nade.flags = FL_PROJECTILE;
1205 IL_PUSH(g_projectiles, _nade);
1206 IL_PUSH(g_bot_dodge, _nade);
1207 _nade.projectiledeathtype = DEATH_NADE.m_id;
1208 _nade.toss_time = time;
1209 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1211 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1212 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1214 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1220 setthink(_nade, nade_boom);
1221 _nade.nextthink = _time;
1224 e.nade_refire = time + autocvar_g_nades_nade_refire;
1225 STAT(NADE_TIMER, e) = 0;
1228 void nades_GiveBonus(entity player, float score)
1230 if (autocvar_g_nades)
1231 if (autocvar_g_nades_bonus)
1232 if (IS_REAL_CLIENT(player))
1233 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1234 if (!STAT(FROZEN, player))
1235 if (!IS_DEAD(player))
1237 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1238 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1240 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1242 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1243 play2(player, SND(NADE_BONUS));
1244 STAT(NADE_BONUS, player)++;
1245 STAT(NADE_BONUS_SCORE, player) -= 1;
1250 /** Remove all bonus nades from a player */
1251 void nades_RemoveBonus(entity player)
1253 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1256 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1258 entity player = M_ARGV(0, entity);
1260 nades_RemoveBonus(player);
1263 bool nade_customize(entity this, entity client)
1265 //if(IS_SPEC(client)) { return false; }
1266 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1268 // somewhat hide the model, but keep the glow
1270 if(this.traileffectnum)
1271 this.traileffectnum = 0;
1276 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1277 if(!this.traileffectnum)
1279 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1280 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1288 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1290 entity n = new(nade), fn = new(fake_nade);
1292 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1293 n.pokenade_type = pntype;
1295 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1296 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1298 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1300 setmodel(n, MDL_PROJECTILE_NADE);
1301 //setattachment(n, player, "bip01 l hand");
1302 n.exteriormodeltoclient = player;
1303 setcefc(n, nade_customize);
1304 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1305 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1306 n.realowner = nowner;
1307 n.colormap = player.colormap;
1308 n.glowmod = player.glowmod;
1309 n.wait = time + max(0, ntime);
1310 n.nade_time_primed = time;
1311 setthink(n, nade_beep);
1312 n.nextthink = max(n.wait - 3, time);
1313 n.projectiledeathtype = DEATH_NADE.m_id;
1314 n.weaponentity_fld = weaponentity;
1315 n.nade_lifetime = ntime;
1316 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1318 setmodel(fn, MDL_NADE_VIEW);
1319 //setattachment(fn, player.(weaponentity), "");
1320 fn.viewmodelforclient = player;
1321 fn.realowner = fn.owner = player;
1322 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1323 fn.colormap = player.colormap;
1324 fn.glowmod = player.glowmod;
1325 setthink(fn, SUB_Remove);
1326 fn.nextthink = n.wait;
1327 fn.weaponentity_fld = weaponentity;
1328 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1331 player.fake_nade = fn;
1334 void nade_prime(entity this)
1336 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1337 return; // only allow bonus nades
1339 // TODO: handle old nade if it exists?
1345 delete(this.fake_nade);
1346 this.fake_nade = NULL;
1349 string pntype = this.pokenade_type;
1351 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1352 ntype = STAT(NADE_BONUS_TYPE, this);
1353 else if (STAT(NADE_BONUS, this) >= 1)
1355 ntype = STAT(NADE_BONUS_TYPE, this);
1356 pntype = this.pokenade_type;
1357 STAT(NADE_BONUS, this) -= 1;
1361 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1362 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1365 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1368 bool CanThrowNade(entity this)
1370 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1373 .bool nade_altbutton;
1375 void nades_CheckThrow(entity this)
1377 if(!CanThrowNade(this))
1380 entity held_nade = this.nade;
1383 this.nade_altbutton = true;
1384 if(time > this.nade_refire)
1387 this.nade_refire = time + autocvar_g_nades_nade_refire;
1392 this.nade_altbutton = false;
1393 if (time >= held_nade.nade_time_primed + 1) {
1394 makevectors(this.v_angle);
1395 float _force = time - held_nade.nade_time_primed;
1396 _force /= autocvar_g_nades_nade_lifetime;
1397 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1398 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1399 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1400 toss_nade(this, true, dir * _force, 0);
1405 void nades_Clear(entity player)
1408 delete(player.nade);
1409 if(player.fake_nade)
1410 delete(player.fake_nade);
1412 player.nade = player.fake_nade = NULL;
1413 STAT(NADE_TIMER, player) = 0;
1416 int nades_CheckTypes(entity player, int cl_ntype)
1418 // TODO check what happens without this patch
1419 #define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \
1420 case nade_ent.m_id: if (nade_cvar) return cl_ntype
1424 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1425 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1426 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1427 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1428 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1429 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1430 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1431 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1432 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1433 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1435 return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types
1436 #undef CL_NADE_TYPE_CHECK
1439 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1441 entity player = M_ARGV(0, entity);
1444 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1447 CLASS(NadeOffhand, OffhandWeapon)
1448 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1450 entity held_nade = player.nade;
1452 if (!CanThrowNade(player)) return;
1453 if (!(time > player.nade_refire)) return;
1457 held_nade = player.nade;
1459 } else if (time >= held_nade.nade_time_primed + 1) {
1461 makevectors(player.v_angle);
1462 float _force = time - held_nade.nade_time_primed;
1463 _force /= autocvar_g_nades_nade_lifetime;
1464 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1465 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1466 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1467 toss_nade(player, false, dir * _force, 0);
1471 ENDCLASS(NadeOffhand)
1472 NadeOffhand OFFHAND_NADE;
1473 REGISTER_MUTATOR(nades, autocvar_g_nades)
1477 OFFHAND_NADE = NEW(NadeOffhand);
1482 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1484 entity player = M_ARGV(0, entity);
1486 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1487 nades_CheckThrow(player);
1492 #ifdef IN_REVIVING_RANGE
1493 #undef IN_REVIVING_RANGE
1496 // returns true if player is reviving it
1497 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1498 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1499 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1501 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1503 entity player = M_ARGV(0, entity);
1505 if (!IS_PLAYER(player)) { return; }
1507 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1508 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1510 entity held_nade = player.nade;
1513 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1514 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1515 makevectors(player.angles);
1516 held_nade.velocity = player.velocity;
1517 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1518 held_nade.angles_y = player.angles.y;
1520 if (time + 0.1 >= held_nade.wait)
1522 toss_nade(player, false, '0 0 0', time + 0.05);
1523 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1527 if(IS_PLAYER(player))
1529 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1532 float key_count = 0;
1533 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1536 if(GameRules_scoring_is_vip(player))
1537 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1539 time_score = autocvar_g_nades_bonus_score_time;
1542 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1544 if(autocvar_g_nades_bonus_client_select)
1546 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1547 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1551 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1552 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1555 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1557 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1558 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1562 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1565 if(player.nade_veil_time && player.nade_veil_time <= time)
1567 player.nade_veil_time = 0;
1569 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1571 player.alpha = player.nade_veil_prevalpha;
1575 if (!(frametime && IS_PLAYER(player)))
1578 entity revivers_last = NULL;
1579 entity revivers_first = NULL;
1581 bool player_is_reviving = false;
1583 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1584 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1585 // check if player is reviving anyone
1586 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1588 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1590 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1592 player_is_reviving = true;
1596 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1597 continue; // both player and it are NOT frozen
1599 revivers_last.chain = it;
1601 if (!revivers_first)
1602 revivers_first = it;
1606 revivers_last.chain = NULL;
1608 if (!n) // no teammate nearby
1610 // freezetag already resets revive progress
1611 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1612 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1614 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1616 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1617 // undo what PlayerPreThink did
1618 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1619 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1621 if(STAT(REVIVE_PROGRESS, player) >= 1)
1623 Unfreeze(player, false);
1625 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1626 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1629 for(entity it = revivers_first; it; it = it.chain)
1630 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1634 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1636 entity player = M_ARGV(0, entity);
1637 // these automatically reset, no need to worry
1639 if(player.nade_entrap_time > time)
1640 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1643 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1645 entity mon = M_ARGV(0, entity);
1647 if (mon.nade_entrap_time > time)
1649 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1650 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1653 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1655 mon.alpha = mon.nade_veil_prevalpha;
1656 mon.nade_veil_time = 0;
1660 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1662 entity player = M_ARGV(0, entity);
1664 player.nade_refire = (autocvar_g_nades_onspawn)
1665 ? time + autocvar_g_nades_nade_refire
1666 : time + autocvar_g_spawnshieldtime;
1668 if(autocvar_g_nades_bonus_client_select)
1669 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1671 STAT(NADE_TIMER, player) = 0;
1673 if (!player.offhand) player.offhand = OFFHAND_NADE;
1675 if(player.nade_spawnloc)
1677 setorigin(player, player.nade_spawnloc.origin);
1678 player.nade_spawnloc.cnt -= 1;
1680 if(player.nade_spawnloc.cnt <= 0)
1682 delete(player.nade_spawnloc);
1683 player.nade_spawnloc = NULL;
1686 if(autocvar_g_nades_spawn_health_respawn > 0)
1687 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1691 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1693 entity frag_attacker = M_ARGV(1, entity);
1694 entity frag_target = M_ARGV(2, entity);
1696 if(frag_target.nade)
1697 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1698 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1700 if(IS_PLAYER(frag_attacker))
1702 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)
1703 : autocvar_g_nades_bonus_score_minor);
1704 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1705 nades_RemoveBonus(frag_attacker);
1706 else if(GameRules_scoring_is_vip(frag_target))
1707 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1708 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1710 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1711 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1712 switch(CS(frag_attacker).killcount)
1715 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1720 nades_GiveBonus(frag_attacker, killcount_bonus);
1723 nades_RemoveBonus(frag_target);
1726 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1728 entity frag_inflictor = M_ARGV(0, entity);
1729 entity frag_attacker = M_ARGV(1, entity);
1730 entity frag_target = M_ARGV(2, entity);
1731 float frag_deathtype = M_ARGV(3, float);
1733 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1734 if(time - frag_inflictor.toss_time <= 0.1)
1736 Unfreeze(frag_target, false);
1737 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1738 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1739 M_ARGV(4, float) = 0;
1740 M_ARGV(6, vector) = '0 0 0';
1741 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1742 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1746 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1748 entity frag_target = M_ARGV(0, entity);
1749 entity frag_attacker = M_ARGV(1, entity);
1751 if(IS_PLAYER(frag_attacker))
1752 if(DIFF_TEAM(frag_attacker, frag_target))
1753 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1754 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1757 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1759 entity frag_target = M_ARGV(0, entity);
1761 if(frag_target.nade)
1762 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1765 void nades_RemovePlayer(entity this)
1768 nades_RemoveBonus(this);
1771 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1772 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1773 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1775 FOREACH_CLIENT(IS_PLAYER(it),
1777 nades_RemovePlayer(it);
1781 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1783 entity spectatee = M_ARGV(0, entity);
1784 entity client = M_ARGV(1, entity);
1786 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1787 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1788 client.pokenade_type = spectatee.pokenade_type;
1789 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1790 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1793 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1795 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1798 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1800 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");