3 #include "../overkill/okmachinegun.qh"
4 #include "../overkill/okshotgun.qh"
7 bool autocvar_g_nades_nade_small;
8 float autocvar_g_nades_spread = 0.04;
11 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
15 REPLICATE(cvar_cl_nade_type, int, "cl_nade_type");
16 REPLICATE(cvar_cl_pokenade_type, string, "cl_pokenade_type");
18 entity Nade_TrailEffect(int proj, int nade_team)
22 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
23 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
26 FOREACH(Nades, true, {
27 for (int j = 0; j < 2; j++)
29 if (it.m_projectile[j] == proj)
31 string trail = it.m_trail[j].eent_eff_name;
32 if (trail) return it.m_trail[j];
43 #include <client/draw.qh>
44 #include <client/hud/hud.qh>
48 void HUD_DarkBlinking()
50 vector bottomright = vec2(vid_conwidth, vid_conheight);
51 drawfill('0 0 0', bottomright, NADE_TYPE_DARKNESS.m_color, 0.986, DRAWFLAG_NORMAL);
54 REGISTER_MUTATOR(cl_nades, true);
55 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
57 if (STAT(NADE_DARKNESS_TIME) > time)
60 sound(csqcplayer, CH_PAIN, SND_BLIND, VOL_BASE, ATTEN_NORM);
63 M_ARGV(1, float) = 0; // alpha_multipl 0, don't draw normal overlay
70 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
72 entity proj = M_ARGV(0, entity);
74 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
77 proj.traileffect = EFFECT_FIREBALL.m_id;
80 if (Nade_FromProjectile(proj.cnt) != NADE_TYPE_Null)
82 setmodel(proj, MDL_PROJECTILE_NADE);
83 entity trail = Nade_TrailEffect(proj.cnt, proj.team);
84 if (trail.eent_eff_name) proj.traileffect = trail.m_id;
88 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
90 entity proj = M_ARGV(0, entity);
92 if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
94 loopsound(proj, CH_SHOTS_SINGLE, SND_FIREBALL_FLY2, VOL_BASE, ATTEN_NORM);
95 proj.mins = '-16 -16 -16';
96 proj.maxs = '16 16 16';
99 entity nade_type = Nade_FromProjectile(proj.cnt);
100 if (nade_type == NADE_TYPE_Null) return;
101 if(STAT(NADES_SMALL))
103 proj.mins = '-8 -8 -8';
108 proj.mins = '-16 -16 -16';
109 proj.maxs = '16 16 16';
111 proj.colormod = nade_type.m_color;
112 set_movetype(proj, MOVETYPE_BOUNCE);
113 settouch(proj, func_null);
115 proj.avelocity = randomvec() * 720;
116 proj.alphamod = nade_type.m_alpha;
118 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
119 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
121 proj.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
124 MUTATOR_HOOKFUNCTION(cl_nades, BuildGameplayTipsString)
126 if (mut_is_active(MUT_NADES))
128 string key = getcommandkey(_("drop weapon / throw nade"), "dropweapon");
129 M_ARGV(0, string) = strcat(M_ARGV(0, string),
130 "\n", sprintf(_("^3nades^8 are enabled, press ^3%s^8 to use them"), key), "\n");
134 bool Projectile_isnade(int p)
136 return Nade_FromProjectile(p) != NADE_TYPE_Null;
138 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
140 float bonusNades = STAT(NADE_BONUS);
141 float bonusProgress = STAT(NADE_BONUS_SCORE);
142 float bonusType = STAT(NADE_BONUS_TYPE);
143 Nade def = REGISTRY_GET(Nades, bonusType);
144 vector nadeColor = def.m_color;
145 string nadeIcon = def.m_icon;
147 vector iconPos, textPos;
149 if(autocvar_hud_panel_ammo_iconalign)
151 iconPos = myPos + eX * 2 * mySize.y;
157 textPos = myPos + eX * mySize.y;
160 if(bonusNades > 0 || bonusProgress > 0)
162 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
164 if(autocvar_hud_panel_ammo_text)
165 drawstring_aspect(textPos, ftos(bonusNades), vec2((2/3) * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
168 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
170 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
177 #include <common/gamemodes/_mod.qh>
178 #include <common/monsters/sv_spawn.qh>
179 #include <common/monsters/sv_monsters.qh>
180 #include <server/command/common.qh>
182 .float nade_time_primed;
183 .float nade_lifetime;
185 .entity nade_spawnloc;
188 void nade_timer_think(entity this)
190 this.skin = 8 - (this.owner.wait - time) / (this.owner.nade_lifetime / 10);
191 this.nextthink = time;
192 if(!this.owner || wasfreed(this.owner))
196 void nade_burn_spawn(entity _nade)
198 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
201 void nade_spawn(entity _nade)
203 entity timer = new(nade_timer);
204 setmodel(timer, MDL_NADE_TIMER);
205 setattachment(timer, _nade, "");
206 timer.colormap = _nade.colormap;
207 timer.glowmod = _nade.glowmod;
208 setthink(timer, nade_timer_think);
209 timer.nextthink = time;
210 timer.wait = _nade.wait;
214 _nade.effects |= EF_LOWPRECISION;
216 CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
219 void normal_nade_boom(entity this)
221 RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
222 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
223 Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
224 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
227 void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime)
236 RandomSelection_Init();
237 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
238 if(e.takedamage == DAMAGE_AIM)
239 if(this.realowner != e || autocvar_g_nades_napalm_selfdamage)
240 if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
244 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
245 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
246 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
247 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
250 e.fireball_impactvec = p;
251 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
254 if(RandomSelection_chosen_ent)
256 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
257 d = damage + (edgedamage - damage) * (d / dist);
258 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype);
259 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
260 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
265 void napalm_ball_think(entity this)
267 if(round_handler_IsActive())
268 if(!round_handler_IsRoundStarted())
274 if(time > this.pushltime)
280 vector midpoint = ((this.absmin + this.absmax) * 0.5);
281 if(pointcontents(midpoint) == CONTENT_WATER)
283 this.velocity = this.velocity * 0.5;
285 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
286 { this.velocity_z = 200; }
289 this.angles = vectoangles(this.velocity);
291 napalm_damage(this, autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
292 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
294 this.nextthink = time + 0.1;
298 void nade_napalm_ball(entity this)
303 spamsound(this, CH_SHOTS, SND_FIREBALL_FIRE, VOL_BASE, ATTEN_NORM);
306 proj.owner = this.owner;
307 proj.realowner = this.realowner;
308 proj.team = this.owner.team;
309 proj.bot_dodge = true;
310 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
311 set_movetype(proj, MOVETYPE_BOUNCE);
312 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
313 PROJECTILE_MAKETRIGGER(proj);
314 setmodel(proj, MDL_Null);
315 proj.scale = 1;//0.5;
316 setsize(proj, '-4 -4 -4', '4 4 4');
317 setorigin(proj, this.origin);
318 setthink(proj, napalm_ball_think);
319 proj.nextthink = time;
320 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
321 proj.effects = EF_LOWPRECISION | EF_FLAME;
323 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
324 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
325 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
326 proj.velocity = kick;
328 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
330 proj.angles = vectoangles(proj.velocity);
331 proj.flags = FL_PROJECTILE;
332 IL_PUSH(g_projectiles, proj);
333 IL_PUSH(g_bot_dodge, proj);
334 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
336 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
340 void napalm_fountain_think(entity this)
343 if(round_handler_IsActive())
344 if(!round_handler_IsRoundStarted())
350 if(time >= this.ltime)
356 vector midpoint = ((this.absmin + this.absmax) * 0.5);
357 if(pointcontents(midpoint) == CONTENT_WATER)
359 this.velocity = this.velocity * 0.5;
361 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
362 { this.velocity_z = 200; }
364 UpdateCSQCProjectile(this);
367 napalm_damage(this, autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
368 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
370 this.nextthink = time + 0.1;
371 if(time >= this.nade_special_time)
373 this.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
374 nade_napalm_ball(this);
378 void nade_napalm_boom(entity this)
380 for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
381 nade_napalm_ball(this);
383 entity fountain = new(nade_napalm_fountain);
384 fountain.owner = this.owner;
385 fountain.realowner = this.realowner;
386 fountain.origin = this.origin;
387 fountain.flags = FL_PROJECTILE;
388 IL_PUSH(g_projectiles, fountain);
389 IL_PUSH(g_bot_dodge, fountain);
390 setorigin(fountain, fountain.origin);
391 setthink(fountain, napalm_fountain_think);
392 fountain.nextthink = time;
393 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
394 fountain.pushltime = fountain.ltime;
395 fountain.team = this.team;
396 set_movetype(fountain, MOVETYPE_TOSS);
397 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
398 fountain.bot_dodge = true;
399 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
400 fountain.nade_special_time = time;
401 setsize(fountain, '-16 -16 -16', '16 16 16');
402 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
405 void nade_ice_freeze(entity freezefield, entity frost_target, float freezetime)
407 frost_target.frozen_by = freezefield.realowner;
408 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
409 Freeze(frost_target, 1 / freezetime, FROZEN_TEMP_DYING, false);
411 Drop_Special_Items(frost_target);
414 void nade_ice_think(entity this)
416 if(round_handler_IsActive())
417 if(!round_handler_IsRoundStarted())
423 if(time >= this.ltime)
425 if ( autocvar_g_nades_ice_explode )
427 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
428 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
429 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
431 normal_nade_boom(this);
438 this.nextthink = time + 0.1;
443 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
445 randomw = random() * M_PI * 2;
447 randomp.x = randomr * cos(randomw);
448 randomp.y = randomr * sin(randomw);
450 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, this.origin + randomp, '0 0 0', 1);
452 if(time >= this.nade_special_time)
454 this.nade_special_time = time + 0.7;
456 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
457 Send_Effect(EFFECT_ICEFIELD, this.origin, '0 0 0', 1);
461 float current_freeze_time = this.ltime - time - 0.1;
463 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
464 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0
465 && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it),
467 switch (autocvar_g_nades_ice_teamcheck)
469 case 0: break; // affect everyone
471 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
472 // fall through (check case 1 condition too)
473 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
475 nade_ice_freeze(this, it, current_freeze_time);
479 void nade_ice_boom(entity this)
481 entity fountain = new(nade_ice_fountain);
482 fountain.owner = this.owner;
483 fountain.realowner = this.realowner;
484 fountain.origin = this.origin;
485 setorigin(fountain, fountain.origin);
486 setthink(fountain, nade_ice_think);
487 fountain.nextthink = time;
488 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
489 fountain.pushltime = fountain.wait = fountain.ltime;
490 fountain.team = this.team;
491 set_movetype(fountain, MOVETYPE_TOSS);
492 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
493 fountain.bot_dodge = false;
494 setsize(fountain, '-16 -16 -16', '16 16 16');
495 fountain.nade_special_time = time + 0.3;
496 fountain.angles = this.angles;
498 if ( autocvar_g_nades_ice_explode )
500 setmodel(fountain, MDL_PROJECTILE_GRENADE);
501 entity timer = new(nade_timer);
502 setmodel(timer, MDL_NADE_TIMER);
503 setattachment(timer, fountain, "");
504 timer.colormap = this.colormap;
505 timer.glowmod = this.glowmod;
506 setthink(timer, nade_timer_think);
507 timer.nextthink = time;
508 timer.wait = fountain.ltime;
509 timer.owner = fountain;
513 setmodel(fountain, MDL_Null);
516 void nade_translocate_boom(entity this)
518 if(this.realowner.vehicle)
521 setsize(this, PL_MIN_CONST-'16 16 16', PL_MAX_CONST+'16 16 16');
523 if(!move_out_of_solid(this))
525 sprint(this.realowner, "^1Couldn't move the translocator out of solid! origin: ", vtos(this.origin), "\n");
529 vector locout = this.origin + '0 0 1' * (1 - this.realowner.mins.z - 24);
530 tracebox(locout, this.realowner.mins, this.realowner.maxs, locout, MOVE_NOMONSTERS, this.realowner);
531 locout = trace_endpos;
533 makevectors(this.realowner.angles);
535 MUTATOR_CALLHOOK(PortalTeleport, this.realowner);
537 TeleportPlayer(this, this.realowner, locout, this.realowner.angles, v_forward * vlen(this.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
540 void nade_spawn_boom(entity this)
542 entity player = this.realowner;
543 entity spawnloc = new(nade_spawn_loc);
544 setorigin(spawnloc, this.origin);
545 setsize(spawnloc, player.mins, player.maxs);
546 set_movetype(spawnloc, MOVETYPE_NONE);
547 spawnloc.solid = SOLID_NOT;
548 spawnloc.drawonlytoclient = player;
549 spawnloc.effects = EF_STARDUST;
550 spawnloc.cnt = autocvar_g_nades_spawn_count;
552 if(player.nade_spawnloc)
553 delete(player.nade_spawnloc);
555 player.nade_spawnloc = spawnloc;
558 void nades_orb_think(entity this)
560 if(time >= this.ltime)
566 this.nextthink = time;
568 if(time >= this.nade_special_time)
570 this.nade_special_time = time+0.25;
571 this.nade_show_particles = 1;
574 this.nade_show_particles = 0;
577 entity nades_spawn_orb(entity own, entity realown, vector org, float orb_ltime, float orb_rad)
579 // NOTE: this function merely places an orb
580 // you must add a custom touch function to the returned entity if desired
581 // also set .colormod if you wish to have it colorized
582 entity orb = new(nades_spawn_orb);
584 orb.realowner = realown;
587 orb.orb_lifetime = orb_ltime; // required for timers
588 orb.ltime = time + orb.orb_lifetime;
589 orb.bot_dodge = false;
590 orb.team = realown.team;
591 orb.solid = SOLID_TRIGGER;
593 setmodel(orb, MDL_NADE_ORB);
595 orb.orb_radius = orb_rad; // required for fading
596 vector size = '1 1 1' * orb.orb_radius / 2;
597 setsize(orb, -size, size);
599 Net_LinkEntity(orb, true, 0, orb_send);
602 setthink(orb, nades_orb_think);
603 orb.nextthink = time;
608 void nade_entrap_touch(entity this, entity toucher)
610 if(DIFF_TEAM(toucher, this.realowner)) // TODO: what if realowner changes team or disconnects?
612 if (!isPushable(toucher))
615 float pushdeltatime = time - toucher.lastpushtime;
616 if (pushdeltatime > 0.15) pushdeltatime = 0;
617 toucher.lastpushtime = time;
618 if(!pushdeltatime) return;
620 // div0: ticrate independent, 1 = identity (not 20)
621 toucher.velocity = toucher.velocity * (autocvar_g_nades_entrap_strength ** pushdeltatime);
624 UpdateCSQCProjectile(toucher);
628 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
630 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
631 show_tint.nade_entrap_time = time + 0.1;
635 void nade_entrap_boom(entity this)
637 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_entrap_time, autocvar_g_nades_entrap_radius);
639 settouch(orb, nade_entrap_touch);
640 orb.colormod = NADE_TYPE_ENTRAP.m_color;
643 void nade_heal_touch(entity this, entity toucher)
648 if(IS_PLAYER(toucher) || IS_MONSTER(toucher) || IS_VEHICLE(toucher))
649 if(!IS_DEAD(toucher))
650 if(!STAT(FROZEN, toucher))
652 health_factor = autocvar_g_nades_heal_rate*frametime/2;
653 if ( toucher != this.realowner )
654 health_factor *= (SAME_TEAM(toucher,this)) ? autocvar_g_nades_heal_friend : autocvar_g_nades_heal_foe;
656 if ( health_factor > 0 )
658 maxhealth = (IS_MONSTER(toucher)) ? toucher.max_health : g_pickup_healthmega_max;
659 float hp = GetResource(toucher, RES_HEALTH);
662 if (this.nade_show_particles)
663 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
665 GiveResourceWithLimit(toucher, RES_HEALTH, health_factor, maxhealth);
668 else if ( health_factor < 0 )
669 Damage(toucher,this,this.realowner,-health_factor,DEATH_NADE_HEAL.m_id,DMG_NOWEP,toucher.origin,'0 0 0');
673 void nade_heal_boom(entity this)
675 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_heal_time, autocvar_g_nades_nade_radius);
677 settouch(orb, nade_heal_touch);
678 orb.colormod = '1 0 0';
681 void nade_monster_boom(entity this)
683 if(!autocvar_g_monsters)
686 e.noalign = true; // don't drop to floor
687 e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
689 return; // monster failed to be spawned
691 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
692 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
693 e.monster_skill = MONSTER_SKILL_INSANE;
696 void nade_veil_touch(entity this, entity toucher)
698 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
700 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
702 float tint_alpha = 0.75;
703 if(SAME_TEAM(toucher, this.realowner))
706 if(!show_tint.nade_veil_time)
708 toucher.nade_veil_prevalpha = toucher.alpha;
712 show_tint.nade_veil_time = time + 0.1;
716 void nade_veil_boom(entity this)
718 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_veil_time, autocvar_g_nades_veil_radius);
720 settouch(orb, nade_veil_touch);
721 orb.colormod = NADE_TYPE_VEIL.m_color;
724 void nade_ammo_touch(entity this, entity toucher)
728 float amshells = GetResource(toucher, RES_SHELLS);
729 float ambullets = GetResource(toucher, RES_BULLETS);
730 float amrockets = GetResource(toucher, RES_ROCKETS);
731 float amcells = GetResource(toucher, RES_CELLS);
732 float amplasma = GetResource(toucher, RES_PLASMA);
733 if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
734 if(!IS_DEAD(toucher))
735 if(!STAT(FROZEN, toucher))
737 ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
738 if ( toucher != this.realowner )
739 ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
741 #define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
742 if (amresource < maxammo) \
743 GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
745 #define DROP_AMMO_RESOURCE(amresource, res_resource) \
746 if (amresource > 0) \
747 SetResource(toucher, res_resource, amresource + ammo_factor);
749 if ( ammo_factor > 0 )
751 CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
752 CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
753 CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
754 CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
755 CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
757 if (this.nade_show_particles)
758 Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
760 else if ( ammo_factor < 0 )
762 //Foe drops ammo points
763 DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
764 DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
765 DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
766 DROP_AMMO_RESOURCE(amcells, RES_CELLS);
767 DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
772 #undef CHECK_AMMO_RESOURCE_LIMIT
773 #undef DROP_AMMO_RESOURCE
775 if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
777 entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
778 show_tint.nade_ammo_time = time + 0.1;
782 void nade_ammo_boom(entity this)
784 entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
786 settouch(orb, nade_ammo_touch);
787 orb.colormod = '0.66 0.33 0';
790 void nade_darkness_think(entity this)
792 if(round_handler_IsActive())
793 if(!round_handler_IsRoundStarted())
799 if(time >= this.ltime)
801 if ( autocvar_g_nades_darkness_explode )
803 entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
804 Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
805 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
807 normal_nade_boom(this);
810 Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
816 this.nextthink = time + 0.1;
821 randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
823 randomw = random() * M_PI * 2;
825 randomp.x = randomr * cos(randomw);
826 randomp.y = randomr * sin(randomw);
828 Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
830 if(time >= this.nade_special_time)
832 this.nade_special_time = time + 0.7;
833 Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
837 float current_dark_time = this.ltime - time - 0.1;
839 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
840 && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
842 switch (autocvar_g_nades_darkness_teamcheck)
844 case 0: break; // affect everyone
846 case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
847 // fall through (check case 1 condition too)
848 case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
850 STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
854 void nade_darkness_boom(entity this)
856 entity fountain = new(nade_darkness_fountain);
857 fountain.owner = this.owner;
858 fountain.realowner = this.realowner;
859 fountain.origin = this.origin;
860 setorigin(fountain, fountain.origin);
861 setthink(fountain, nade_darkness_think);
862 fountain.nextthink = time;
863 fountain.ltime = time + autocvar_g_nades_darkness_time;
864 fountain.pushltime = fountain.wait = fountain.ltime;
865 fountain.team = this.team;
866 set_movetype(fountain, MOVETYPE_TOSS);
867 fountain.projectiledeathtype = DEATH_NADE.m_id;
868 fountain.bot_dodge = false;
869 setsize(fountain, '-16 -16 -16', '16 16 16');
870 fountain.nade_special_time = time + 0.3;
871 fountain.angles = this.angles;
873 if ( autocvar_g_nades_darkness_explode )
875 setmodel(fountain, MDL_PROJECTILE_GRENADE);
876 entity timer = new(nade_timer);
877 setmodel(timer, MDL_NADE_TIMER);
878 setattachment(timer, fountain, "");
879 timer.colormap = this.colormap;
880 timer.glowmod = this.glowmod;
881 setthink(timer, nade_timer_think);
882 timer.nextthink = time;
883 timer.wait = fountain.ltime;
884 timer.owner = fountain;
888 setmodel(fountain, MDL_Null);
891 void nade_boom(entity this)
894 bool nade_blast = true;
896 #define GET_NADE_TYPE_SPAWN_EFFECT(team_owner) \
897 ((team_owner) == NUM_TEAM_1 ? EFFECT_SPAWN_RED : \
898 ((team_owner) == NUM_TEAM_2 ? EFFECT_SPAWN_BLUE : \
899 ((team_owner) == NUM_TEAM_3 ? EFFECT_SPAWN_YELLOW : \
900 ((team_owner) == NUM_TEAM_4 ? EFFECT_SPAWN_PINK : \
901 EFFECT_SPAWN_NEUTRAL))))
903 #define SET_NADE_EFFECT(nade_type, blast, exp_effect) \
905 nade_blast = blast; \
906 expef = exp_effect; \
909 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
911 SET_NADE_EFFECT(NADE_TYPE_NAPALM, autocvar_g_nades_napalm_blast, EFFECT_EXPLOSION_MEDIUM);
912 SET_NADE_EFFECT(NADE_TYPE_ICE, false, EFFECT_ELECTRO_COMBO /* hookbomb_explode electro_combo bigplasma_impact */);
913 SET_NADE_EFFECT(NADE_TYPE_TRANSLOCATE, false, NULL);
914 SET_NADE_EFFECT(NADE_TYPE_MONSTER, true, (!autocvar_g_monsters) ? EFFECT_NADE_EXPLODE(this.realowner.team) : NULL);
915 SET_NADE_EFFECT(NADE_TYPE_SPAWN, false, GET_NADE_TYPE_SPAWN_EFFECT(this.realowner.team));
916 SET_NADE_EFFECT(NADE_TYPE_HEAL, false, EFFECT_SPAWN_RED);
917 SET_NADE_EFFECT(NADE_TYPE_ENTRAP, false, EFFECT_SPAWN_YELLOW);
918 SET_NADE_EFFECT(NADE_TYPE_VEIL, false, EFFECT_SPAWN_NEUTRAL);
919 SET_NADE_EFFECT(NADE_TYPE_AMMO, false, EFFECT_SPAWN_BROWN);
920 SET_NADE_EFFECT(NADE_TYPE_DARKNESS, false, EFFECT_EXPLOSION_MEDIUM);
921 SET_NADE_EFFECT(NADE_TYPE_NORMAL, true, EFFECT_NADE_EXPLODE(this.realowner.team));
922 default: expef = EFFECT_NADE_EXPLODE(this.realowner.team); break;
924 #undef GET_NADE_TYPE_SPAWN_EFFECT
925 #undef SET_NADE_EFFECT
928 Send_Effect(expef, findbetterlocation(this.origin, 8), '0 0 0', 1);
930 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
931 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
933 this.event_damage = func_null; // prevent somehow calling damage in the next call
936 normal_nade_boom(this);
939 switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) )
941 case NADE_TYPE_NAPALM: nade_napalm_boom(this); break;
942 case NADE_TYPE_ICE: nade_ice_boom(this); break;
943 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(this); break;
944 case NADE_TYPE_SPAWN: nade_spawn_boom(this); break;
945 case NADE_TYPE_HEAL: nade_heal_boom(this); break;
946 case NADE_TYPE_MONSTER: nade_monster_boom(this); break;
947 case NADE_TYPE_ENTRAP: nade_entrap_boom(this); break;
948 case NADE_TYPE_VEIL: nade_veil_boom(this); break;
949 case NADE_TYPE_AMMO: nade_ammo_boom(this); break;
950 case NADE_TYPE_DARKNESS: nade_darkness_boom(this); break;
953 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
961 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
962 void nade_pickup(entity this, entity thenade)
964 spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, STAT(NADE_BONUS_TYPE, thenade), thenade.pokenade_type);
966 // set refire so player can't even
967 this.nade_refire = time + autocvar_g_nades_nade_refire;
968 STAT(NADE_TIMER, this) = 0;
971 this.nade.nade_time_primed = thenade.nade_time_primed;
974 bool CanThrowNade(entity this);
975 void nade_touch(entity this, entity toucher)
978 UpdateCSQCProjectile(this);
980 if(toucher == this.realowner)
981 return; // no this impacts
983 if(autocvar_g_nades_pickup)
984 if(time >= this.spawnshieldtime)
985 if(!toucher.nade && GetResource(this, RES_HEALTH) == this.max_health) // no boosted shot pickups, thank you very much
986 if(CanThrowNade(toucher)) // prevent some obvious things, like dead players
987 if(IS_REAL_CLIENT(toucher)) // above checks for IS_PLAYER, don't need to do it here
989 nade_pickup(toucher, this);
990 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
994 /*float is_weapclip = 0;
995 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
996 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
997 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
999 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
1001 IL_EACH(g_projectiles, it.classname == "grapplinghook" && it.aiment == this,
1009 PROJECTILE_TOUCH(this, toucher);
1011 //setsize(this, '-2 -2 -2', '2 2 2');
1012 //UpdateCSQCProjectile(this);
1013 if(GetResource(this, RES_HEALTH) == this.max_health)
1015 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTEN_NORM);
1019 this.enemy = toucher;
1023 void nade_beep(entity this)
1025 sound(this, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1026 setthink(this, nade_boom);
1027 this.nextthink = max(this.wait, time);
1030 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
1032 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1034 this.takedamage = DAMAGE_NO;
1039 if(STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1042 if (MUTATOR_CALLHOOK(Nade_Damage, this, DEATH_WEAPONOF(deathtype), force, damage)) {}
1043 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
1048 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
1050 force *= 0.5; // too much
1053 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_NEX))
1056 damage = this.max_health * 0.55;
1058 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_MACHINEGUN))
1059 damage = this.max_health * 0.1;
1060 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN) || DEATH_ISWEAPON(deathtype, WEP_OVERKILL_SHOTGUN)) // WEAPONTODO
1062 if(!(deathtype & HITTYPE_SECONDARY))
1063 damage = this.max_health * 1.15;
1067 entity death_weapon = DEATH_WEAPONOF(deathtype);
1068 if(((deathtype & HITTYPE_SECONDARY) ? (death_weapon.spawnflags & WEP_TYPE_MELEE_SEC) : (death_weapon.spawnflags & WEP_TYPE_MELEE_PRI)))
1070 damage = this.max_health * 0.1;
1074 this.velocity += force;
1075 UpdateCSQCProjectile(this);
1077 if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
1080 float hp = GetResource(this, RES_HEALTH);
1081 if(hp == this.max_health)
1083 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
1084 this.nextthink = max(time + this.nade_lifetime, time);
1085 setthink(this, nade_beep);
1089 SetResource(this, RES_HEALTH, hp);
1091 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_TRANSLOCATE.m_id && STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_SPAWN.m_id)
1092 if(STAT(NADE_BONUS_TYPE, this) != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker))
1093 this.realowner = attacker;
1097 if(autocvar_g_nades_spawn_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_SPAWN.m_id)
1098 Damage(this.realowner, attacker, attacker, autocvar_g_nades_spawn_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1100 if(autocvar_g_nades_translocate_destroy_damage > 0 && STAT(NADE_BONUS_TYPE, this) == NADE_TYPE_TRANSLOCATE.m_id)
1102 Damage(this.realowner, attacker, attacker, autocvar_g_nades_translocate_destroy_damage, DEATH_TOUCHEXPLODE.m_id, DMG_NOWEP, this.realowner.origin, '0 0 0');
1103 W_PrepareExplosionByDamage(this, this.realowner, nade_boom); // Don't change the owner
1108 W_PrepareExplosionByDamage(this, attacker, nade_boom);
1111 nade_burn_spawn(this);
1114 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
1119 entity _nade = e.nade;
1123 delete(e.fake_nade);
1126 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
1128 makevectors(e.v_angle);
1130 // NOTE: always throw from first weapon entity?
1131 W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0, DEATH_NADE.m_id);
1133 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
1134 + (v_right * autocvar_g_nades_throw_offset.y)
1135 + (v_up * autocvar_g_nades_throw_offset.z);
1137 setorigin(_nade, w_shotorg + offset);
1138 //setmodel(_nade, MDL_PROJECTILE_NADE);
1139 //setattachment(_nade, NULL, "");
1140 PROJECTILE_MAKETRIGGER(_nade);
1141 if(STAT(NADES_SMALL, e))
1142 setsize(_nade, '-8 -8 -8', '8 8 8');
1144 setsize(_nade, '-16 -16 -16', '16 16 16');
1145 set_movetype(_nade, MOVETYPE_BOUNCE);
1147 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, MOVE_NOMONSTERS, _nade);
1148 if (trace_startsolid)
1149 setorigin(_nade, e.origin);
1151 if(e.v_angle.x >= 70 && e.v_angle.x <= 110 && PHYS_INPUT_BUTTON_CROUCH(e))
1152 _nade.velocity = '0 0 100';
1153 else if(autocvar_g_nades_nade_newton_style == 1)
1154 _nade.velocity = e.velocity + _velocity;
1155 else if(autocvar_g_nades_nade_newton_style == 2)
1156 _nade.velocity = _velocity;
1158 _nade.velocity = W_CalculateProjectileVelocity(e, e.velocity, _velocity, true);
1161 _nade.realowner = e;
1163 settouch(_nade, nade_touch);
1164 _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
1165 SetResource(_nade, RES_HEALTH, autocvar_g_nades_nade_health);
1166 _nade.max_health = GetResource(_nade, RES_HEALTH);
1167 _nade.takedamage = DAMAGE_AIM;
1168 _nade.event_damage = nade_damage;
1169 setcefc(_nade, func_null);
1170 _nade.exteriormodeltoclient = NULL;
1171 _nade.traileffectnum = 0;
1172 _nade.teleportable = true;
1173 _nade.pushable = true;
1175 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
1176 _nade.damagedbycontents = true;
1177 IL_PUSH(g_damagedbycontents, _nade);
1178 _nade.angles = vectoangles(_nade.velocity);
1179 _nade.flags = FL_PROJECTILE;
1180 IL_PUSH(g_projectiles, _nade);
1181 IL_PUSH(g_bot_dodge, _nade);
1182 _nade.projectiledeathtype = DEATH_NADE.m_id;
1183 _nade.toss_time = time;
1184 _nade.solid = SOLID_CORPSE; //((STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
1186 if(STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_TRANSLOCATE.m_id || STAT(NADE_BONUS_TYPE, _nade) == NADE_TYPE_SPAWN.m_id)
1187 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1189 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
1195 setthink(_nade, nade_boom);
1196 _nade.nextthink = _time;
1199 e.nade_refire = time + autocvar_g_nades_nade_refire;
1200 STAT(NADE_TIMER, e) = 0;
1203 void nades_GiveBonus(entity player, float score)
1205 if (autocvar_g_nades)
1206 if (autocvar_g_nades_bonus)
1207 if (IS_REAL_CLIENT(player))
1208 if (IS_PLAYER(player) && STAT(NADE_BONUS, player) < autocvar_g_nades_bonus_max)
1209 if (!STAT(FROZEN, player))
1210 if (!IS_DEAD(player))
1212 if ( STAT(NADE_BONUS_SCORE, player) < 1 )
1213 STAT(NADE_BONUS_SCORE, player) += score/autocvar_g_nades_bonus_score_max;
1215 if ( STAT(NADE_BONUS_SCORE, player) >= 1 )
1217 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
1218 play2(player, SND(NADE_BONUS));
1219 STAT(NADE_BONUS, player)++;
1220 STAT(NADE_BONUS_SCORE, player) -= 1;
1225 /** Remove all bonus nades from a player */
1226 void nades_RemoveBonus(entity player)
1228 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1231 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
1233 entity player = M_ARGV(0, entity);
1235 nades_RemoveBonus(player);
1238 bool nade_customize(entity this, entity client)
1240 //if(IS_SPEC(client)) { return false; }
1241 if(client == this.exteriormodeltoclient || (IS_SPEC(client) && client.enemy == this.exteriormodeltoclient))
1243 // somewhat hide the model, but keep the glow
1245 if(this.traileffectnum)
1246 this.traileffectnum = 0;
1251 //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
1252 if(!this.traileffectnum)
1254 entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
1255 this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
1263 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
1265 entity n = new(nade), fn = new(fake_nade);
1267 STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
1268 n.pokenade_type = pntype;
1270 if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
1271 STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
1273 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1275 setmodel(n, MDL_PROJECTILE_NADE);
1276 //setattachment(n, player, "bip01 l hand");
1277 n.exteriormodeltoclient = player;
1278 setcefc(n, nade_customize);
1279 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
1280 n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1281 n.realowner = nowner;
1282 n.colormap = player.colormap;
1283 n.glowmod = player.glowmod;
1284 n.wait = time + max(0, ntime);
1285 n.nade_time_primed = time;
1286 setthink(n, nade_beep);
1287 n.nextthink = max(n.wait - 3, time);
1288 n.projectiledeathtype = DEATH_NADE.m_id;
1289 n.weaponentity_fld = weaponentity;
1290 n.nade_lifetime = ntime;
1291 n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1293 setmodel(fn, MDL_NADE_VIEW);
1294 //setattachment(fn, player.(weaponentity), "");
1295 fn.viewmodelforclient = player;
1296 fn.realowner = fn.owner = player;
1297 fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
1298 fn.colormap = player.colormap;
1299 fn.glowmod = player.glowmod;
1300 setthink(fn, SUB_Remove);
1301 fn.nextthink = n.wait;
1302 fn.weaponentity_fld = weaponentity;
1303 fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
1306 player.fake_nade = fn;
1309 void nade_prime(entity this)
1311 if(autocvar_g_nades_bonus_only && !STAT(NADE_BONUS, this))
1312 return; // only allow bonus nades
1314 // TODO: handle old nade if it exists?
1320 delete(this.fake_nade);
1321 this.fake_nade = NULL;
1324 string pntype = this.pokenade_type;
1326 if(StatusEffects_active(STATUSEFFECT_Strength, this) && autocvar_g_nades_bonus_onstrength)
1327 ntype = STAT(NADE_BONUS_TYPE, this);
1328 else if (STAT(NADE_BONUS, this) >= 1)
1330 ntype = STAT(NADE_BONUS_TYPE, this);
1331 pntype = this.pokenade_type;
1332 STAT(NADE_BONUS, this) -= 1;
1336 ntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_nade_type : autocvar_g_nades_nade_type);
1337 pntype = ((autocvar_g_nades_client_select) ? CS_CVAR(this).cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1340 spawn_held_nade(this, this, autocvar_g_nades_nade_lifetime, ntype, pntype);
1343 bool CanThrowNade(entity this)
1345 return !(this.vehicle || !autocvar_g_nades || IS_DEAD(this) || !IS_PLAYER(this) || weaponLocked(this));
1348 .bool nade_altbutton;
1350 void nades_CheckThrow(entity this)
1352 if(!CanThrowNade(this))
1355 entity held_nade = this.nade;
1358 this.nade_altbutton = true;
1359 if(time > this.nade_refire)
1362 this.nade_refire = time + autocvar_g_nades_nade_refire;
1367 this.nade_altbutton = false;
1368 if (time >= held_nade.nade_time_primed + 1) {
1369 makevectors(this.v_angle);
1370 float _force = time - held_nade.nade_time_primed;
1371 _force /= autocvar_g_nades_nade_lifetime;
1372 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1373 vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
1374 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1375 toss_nade(this, true, dir * _force, 0);
1380 void nades_Clear(entity player)
1383 delete(player.nade);
1384 if(player.fake_nade)
1385 delete(player.fake_nade);
1387 player.nade = player.fake_nade = NULL;
1388 STAT(NADE_TIMER, player) = 0;
1391 int nades_CheckTypes(entity player, int cl_ntype)
1393 // TODO check what happens without this patch
1394 #define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \
1395 case nade_ent.m_id: if (nade_cvar) return cl_ntype
1399 CL_NADE_TYPE_CHECK(NADE_TYPE_NAPALM, autocvar_g_nades_napalm);
1400 CL_NADE_TYPE_CHECK(NADE_TYPE_ICE, autocvar_g_nades_ice);
1401 CL_NADE_TYPE_CHECK(NADE_TYPE_TRANSLOCATE, autocvar_g_nades_translocate);
1402 CL_NADE_TYPE_CHECK(NADE_TYPE_SPAWN, autocvar_g_nades_spawn);
1403 CL_NADE_TYPE_CHECK(NADE_TYPE_HEAL, autocvar_g_nades_heal);
1404 CL_NADE_TYPE_CHECK(NADE_TYPE_MONSTER, autocvar_g_nades_pokenade);
1405 CL_NADE_TYPE_CHECK(NADE_TYPE_ENTRAP, autocvar_g_nades_entrap);
1406 CL_NADE_TYPE_CHECK(NADE_TYPE_VEIL, autocvar_g_nades_veil);
1407 CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo);
1408 CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness);
1410 return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types
1411 #undef CL_NADE_TYPE_CHECK
1414 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1416 entity player = M_ARGV(0, entity);
1419 toss_nade(player, true, '0 0 100', max(player.nade.wait, time + 0.05));
1422 CLASS(NadeOffhand, OffhandWeapon)
1423 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1425 entity held_nade = player.nade;
1427 if (!CanThrowNade(player)) return;
1428 if (!(time > player.nade_refire)) return;
1432 held_nade = player.nade;
1434 } else if (time >= held_nade.nade_time_primed + 1) {
1436 makevectors(player.v_angle);
1437 float _force = time - held_nade.nade_time_primed;
1438 _force /= autocvar_g_nades_nade_lifetime;
1439 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1440 vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
1441 dir = W_CalculateSpread(dir, autocvar_g_nades_spread, autocvar_g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
1442 toss_nade(player, false, dir * _force, 0);
1446 ENDCLASS(NadeOffhand)
1447 NadeOffhand OFFHAND_NADE;
1448 REGISTER_MUTATOR(nades, autocvar_g_nades)
1452 OFFHAND_NADE = NEW(NadeOffhand);
1457 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1459 entity player = M_ARGV(0, entity);
1461 if (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1462 nades_CheckThrow(player);
1467 #ifdef IN_REVIVING_RANGE
1468 #undef IN_REVIVING_RANGE
1471 // returns true if player is reviving it
1472 #define IN_REVIVING_RANGE(player, it, revive_extra_size) \
1473 (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
1474 && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
1476 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1478 entity player = M_ARGV(0, entity);
1480 if (!IS_PLAYER(player)) { return; }
1482 if (player.nade && (player.offhand != OFFHAND_NADE || (STAT(WEAPONS, player) & WEPSET(HOOK))))
1483 OFFHAND_NADE.offhand_think(OFFHAND_NADE, player, player.nade_altbutton);
1485 entity held_nade = player.nade;
1488 STAT(NADE_TIMER, player) = bound(0, (time - held_nade.nade_time_primed) / held_nade.nade_lifetime, 1);
1489 // LOG_TRACEF("%d %d", STAT(NADE_TIMER, player), time - held_nade.nade_time_primed);
1490 makevectors(player.angles);
1491 held_nade.velocity = player.velocity;
1492 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1493 held_nade.angles_y = player.angles.y;
1495 if (time + 0.1 >= held_nade.wait)
1497 toss_nade(player, false, '0 0 0', time + 0.05);
1498 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_THROW);
1502 if(IS_PLAYER(player))
1504 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1507 float key_count = 0;
1508 FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
1511 if(GameRules_scoring_is_vip(player))
1512 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1514 time_score = autocvar_g_nades_bonus_score_time;
1517 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1519 if(autocvar_g_nades_bonus_client_select)
1521 STAT(NADE_BONUS_TYPE, player) = nades_CheckTypes(player, CS_CVAR(player).cvar_cl_nade_type);
1522 player.pokenade_type = CS_CVAR(player).cvar_cl_pokenade_type;
1526 STAT(NADE_BONUS_TYPE, player) = autocvar_g_nades_bonus_type;
1527 player.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1530 STAT(NADE_BONUS_TYPE, player) = bound(1, STAT(NADE_BONUS_TYPE, player), Nades_COUNT);
1532 if(STAT(NADE_BONUS_SCORE, player) >= 0 && autocvar_g_nades_bonus_score_max)
1533 nades_GiveBonus(player, time_score / autocvar_g_nades_bonus_score_max);
1537 STAT(NADE_BONUS, player) = STAT(NADE_BONUS_SCORE, player) = 0;
1540 if(player.nade_veil_time && player.nade_veil_time <= time)
1542 player.nade_veil_time = 0;
1544 player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
1546 player.alpha = player.nade_veil_prevalpha;
1550 if (!(frametime && IS_PLAYER(player)))
1553 entity revivers_last = NULL;
1554 entity revivers_first = NULL;
1556 bool player_is_reviving = false;
1558 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1559 FOREACH_CLIENT(IS_PLAYER(it) && IN_REVIVING_RANGE(player, it, revive_extra_size), {
1560 // check if player is reviving anyone
1561 if (STAT(FROZEN, it) == FROZEN_TEMP_DYING)
1563 if ((STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1565 if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
1567 player_is_reviving = true;
1571 if (!(STAT(FROZEN, player) == FROZEN_TEMP_DYING))
1572 continue; // both player and it are NOT frozen
1574 revivers_last.chain = it;
1576 if (!revivers_first)
1577 revivers_first = it;
1581 revivers_last.chain = NULL;
1583 if (!n) // no teammate nearby
1585 // freezetag already resets revive progress
1586 if (!g_freezetag && !STAT(FROZEN, player) && !player_is_reviving)
1587 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
1589 else if (n > 0 && STAT(FROZEN, player) == FROZEN_TEMP_DYING) // OK, there is at least one teammate reviving us
1591 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1592 // undo what PlayerPreThink did
1593 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * player.revive_speed, 1);
1594 SetResource(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * start_health));
1596 if(STAT(REVIVE_PROGRESS, player) >= 1)
1598 Unfreeze(player, false);
1600 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
1601 Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
1604 for(entity it = revivers_first; it; it = it.chain)
1605 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
1609 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)
1611 entity player = M_ARGV(0, entity);
1612 // these automatically reset, no need to worry
1614 if(player.nade_entrap_time > time)
1615 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nades_entrap_speed;
1618 MUTATOR_HOOKFUNCTION(nades, MonsterMove)
1620 entity mon = M_ARGV(0, entity);
1622 if (mon.nade_entrap_time > time)
1624 M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
1625 M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
1628 if (mon.nade_veil_time && mon.nade_veil_time <= time)
1630 mon.alpha = mon.nade_veil_prevalpha;
1631 mon.nade_veil_time = 0;
1635 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1637 entity player = M_ARGV(0, entity);
1639 player.nade_refire = (autocvar_g_nades_onspawn)
1640 ? time + autocvar_g_nades_nade_refire
1641 : time + autocvar_g_spawnshieldtime;
1643 if(autocvar_g_nades_bonus_client_select)
1644 STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;
1646 STAT(NADE_TIMER, player) = 0;
1648 if (!player.offhand) player.offhand = OFFHAND_NADE;
1650 if(player.nade_spawnloc)
1652 setorigin(player, player.nade_spawnloc.origin);
1653 player.nade_spawnloc.cnt -= 1;
1655 if(player.nade_spawnloc.cnt <= 0)
1657 delete(player.nade_spawnloc);
1658 player.nade_spawnloc = NULL;
1661 if(autocvar_g_nades_spawn_health_respawn > 0)
1662 SetResource(player, RES_HEALTH, autocvar_g_nades_spawn_health_respawn);
1666 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1668 entity frag_attacker = M_ARGV(1, entity);
1669 entity frag_target = M_ARGV(2, entity);
1671 if(frag_target.nade)
1672 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1673 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1675 if(IS_PLAYER(frag_attacker))
1677 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)
1678 : autocvar_g_nades_bonus_score_minor);
1679 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1680 nades_RemoveBonus(frag_attacker);
1681 else if(GameRules_scoring_is_vip(frag_target))
1682 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1683 else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
1685 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1686 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1687 switch(CS(frag_attacker).killcount)
1690 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1695 nades_GiveBonus(frag_attacker, killcount_bonus);
1698 nades_RemoveBonus(frag_target);
1701 MUTATOR_HOOKFUNCTION(nades, Damage_Calculate)
1703 entity frag_inflictor = M_ARGV(0, entity);
1704 entity frag_attacker = M_ARGV(1, entity);
1705 entity frag_target = M_ARGV(2, entity);
1706 float frag_deathtype = M_ARGV(3, float);
1708 if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id)
1709 if(time - frag_inflictor.toss_time <= 0.1)
1711 Unfreeze(frag_target, false);
1712 SetResource(frag_target, RES_HEALTH, autocvar_g_freezetag_revive_nade_health);
1713 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1714 M_ARGV(4, float) = 0;
1715 M_ARGV(6, vector) = '0 0 0';
1716 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1717 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1721 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1723 entity frag_target = M_ARGV(0, entity);
1724 entity frag_attacker = M_ARGV(1, entity);
1726 if(IS_PLAYER(frag_attacker))
1727 if(DIFF_TEAM(frag_attacker, frag_target))
1728 if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1729 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1732 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1734 entity frag_target = M_ARGV(0, entity);
1736 if(frag_target.nade)
1737 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1740 void nades_RemovePlayer(entity this)
1743 nades_RemoveBonus(this);
1746 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1747 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { entity player = M_ARGV(0, entity); nades_RemovePlayer(player); }
1748 MUTATOR_HOOKFUNCTION(nades, reset_map_global)
1750 FOREACH_CLIENT(IS_PLAYER(it),
1752 nades_RemovePlayer(it);
1756 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1758 entity spectatee = M_ARGV(0, entity);
1759 entity client = M_ARGV(1, entity);
1761 STAT(NADE_TIMER, client) = STAT(NADE_TIMER, spectatee);
1762 STAT(NADE_BONUS_TYPE, client) = STAT(NADE_BONUS_TYPE, spectatee);
1763 client.pokenade_type = spectatee.pokenade_type;
1764 STAT(NADE_BONUS, client) = STAT(NADE_BONUS, spectatee);
1765 STAT(NADE_BONUS_SCORE, client) = STAT(NADE_BONUS_SCORE, spectatee);
1768 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1770 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Nades");
1773 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1775 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Nades");