1 #include "mutator_nades.qh"
5 #include "gamemode_keyhunt.qh"
6 #include "gamemode_freezetag.qh"
7 #include "../../common/nades/all.qh"
8 #include "../../common/gamemodes/all.qh"
9 #include "../../common/monsters/spawn.qh"
10 #include "../../common/monsters/sv_monsters.qh"
11 #include "../g_subs.qh"
13 REGISTER_MUTATOR(nades, cvar("g_nades"))
17 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
18 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
19 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
20 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
21 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
22 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
28 .float nade_time_primed;
30 .entity nade_spawnloc;
32 void nade_timer_think()
34 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
35 self.nextthink = time;
36 if(!self.owner || wasfreed(self.owner))
40 void nade_burn_spawn(entity _nade)
42 CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[true], true);
45 void nade_spawn(entity _nade)
47 entity timer = spawn();
48 setmodel(timer, MDL_NADE_TIMER);
49 setattachment(timer, _nade, "");
50 timer.classname = "nade_timer";
51 timer.colormap = _nade.colormap;
52 timer.glowmod = _nade.glowmod;
53 timer.think = nade_timer_think;
54 timer.nextthink = time;
55 timer.wait = _nade.wait;
59 _nade.effects |= EF_LOWPRECISION;
61 CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[false], true);
64 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
73 RandomSelection_Init();
74 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
75 if(e.takedamage == DAMAGE_AIM)
76 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
77 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
81 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
82 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
83 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
84 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
87 e.fireball_impactvec = p;
88 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
91 if(RandomSelection_chosen_ent)
93 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
94 d = damage + (edgedamage - damage) * (d / dist);
95 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
96 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
97 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
102 void napalm_ball_think()
104 if(round_handler_IsActive())
105 if(!round_handler_IsRoundStarted())
111 if(time > self.pushltime)
117 vector midpoint = ((self.absmin + self.absmax) * 0.5);
118 if(pointcontents(midpoint) == CONTENT_WATER)
120 self.velocity = self.velocity * 0.5;
122 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
123 { self.velocity_z = 200; }
126 self.angles = vectoangles(self.velocity);
128 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
129 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
131 self.nextthink = time + 0.1;
135 void nade_napalm_ball()
140 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
143 proj.owner = self.owner;
144 proj.realowner = self.realowner;
145 proj.team = self.owner.team;
146 proj.classname = "grenade";
147 proj.bot_dodge = true;
148 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
149 proj.movetype = MOVETYPE_BOUNCE;
150 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
151 PROJECTILE_MAKETRIGGER(proj);
152 setmodel(proj, MDL_Null);
153 proj.scale = 1;//0.5;
154 setsize(proj, '-4 -4 -4', '4 4 4');
155 setorigin(proj, self.origin);
156 proj.think = napalm_ball_think;
157 proj.nextthink = time;
158 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
159 proj.effects = EF_LOWPRECISION | EF_FLAME;
161 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
162 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
163 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
164 proj.velocity = kick;
166 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
168 proj.angles = vectoangles(proj.velocity);
169 proj.flags = FL_PROJECTILE;
170 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
172 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
176 void napalm_fountain_think()
179 if(round_handler_IsActive())
180 if(!round_handler_IsRoundStarted())
186 if(time >= self.ltime)
192 vector midpoint = ((self.absmin + self.absmax) * 0.5);
193 if(pointcontents(midpoint) == CONTENT_WATER)
195 self.velocity = self.velocity * 0.5;
197 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
198 { self.velocity_z = 200; }
200 UpdateCSQCProjectile(self);
203 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
204 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
206 self.nextthink = time + 0.1;
207 if(time >= self.nade_special_time)
209 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
214 void nade_napalm_boom()
218 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
223 fountain.owner = self.owner;
224 fountain.realowner = self.realowner;
225 fountain.origin = self.origin;
226 setorigin(fountain, fountain.origin);
227 fountain.think = napalm_fountain_think;
228 fountain.nextthink = time;
229 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
230 fountain.pushltime = fountain.ltime;
231 fountain.team = self.team;
232 fountain.movetype = MOVETYPE_TOSS;
233 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
234 fountain.bot_dodge = true;
235 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
236 fountain.nade_special_time = time;
237 setsize(fountain, '-16 -16 -16', '16 16 16');
238 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
241 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
243 frost_target.frozen_by = freezefield.realowner;
244 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
245 Freeze(frost_target, 1/freeze_time, 3, false);
246 if(frost_target.ballcarried)
247 if(g_keepaway) { ka_DropEvent(frost_target); }
248 else { DropBall(frost_target.ballcarried, frost_target.origin, frost_target.velocity);}
249 if(frost_target.flagcarried) { ctf_Handle_Throw(frost_target, world, DROP_THROW); }
250 if(frost_target.nade) { toss_nade(frost_target, '0 0 0', time + 0.05); }
252 kh_Key_DropAll(frost_target, false);
255 void nade_ice_think()
258 if(round_handler_IsActive())
259 if(!round_handler_IsRoundStarted())
265 if(time >= self.ltime)
267 if ( autocvar_g_nades_ice_explode )
269 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
270 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
271 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
273 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
274 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
275 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
276 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
283 self.nextthink = time+0.1;
288 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
290 randomw = random()*M_PI*2;
292 randomp.x = randomr*cos(randomw);
293 randomp.y = randomr*sin(randomw);
295 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
297 if(time >= self.nade_special_time)
299 self.nade_special_time = time+0.7;
301 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
302 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
306 float current_freeze_time = self.ltime - time - 0.1;
309 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
311 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
312 if(e.takedamage && e.deadflag == DEAD_NO)
314 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
316 if(current_freeze_time > 0)
317 nade_ice_freeze(self, e, current_freeze_time);
324 fountain.owner = self.owner;
325 fountain.realowner = self.realowner;
326 fountain.origin = self.origin;
327 setorigin(fountain, fountain.origin);
328 fountain.think = nade_ice_think;
329 fountain.nextthink = time;
330 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
331 fountain.pushltime = fountain.wait = fountain.ltime;
332 fountain.team = self.team;
333 fountain.movetype = MOVETYPE_TOSS;
334 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
335 fountain.bot_dodge = false;
336 setsize(fountain, '-16 -16 -16', '16 16 16');
337 fountain.nade_special_time = time+0.3;
338 fountain.angles = self.angles;
340 if ( autocvar_g_nades_ice_explode )
342 setmodel(fountain, MDL_PROJECTILE_GRENADE);
343 entity timer = spawn();
344 setmodel(timer, MDL_NADE_TIMER);
345 setattachment(timer, fountain, "");
346 timer.classname = "nade_timer";
347 timer.colormap = self.colormap;
348 timer.glowmod = self.glowmod;
349 timer.think = nade_timer_think;
350 timer.nextthink = time;
351 timer.wait = fountain.ltime;
352 timer.owner = fountain;
356 setmodel(fountain, MDL_Null);
359 void nade_translocate_boom()
361 if(self.realowner.vehicle)
364 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
365 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
366 locout = trace_endpos;
368 makevectors(self.realowner.angles);
370 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
372 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
375 void nade_spawn_boom()
377 entity spawnloc = spawn();
378 setorigin(spawnloc, self.origin);
379 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
380 spawnloc.movetype = MOVETYPE_NONE;
381 spawnloc.solid = SOLID_NOT;
382 spawnloc.drawonlytoclient = self.realowner;
383 spawnloc.effects = EF_STARDUST;
384 spawnloc.cnt = autocvar_g_nades_spawn_count;
386 if(self.realowner.nade_spawnloc)
388 remove(self.realowner.nade_spawnloc);
389 self.realowner.nade_spawnloc = world;
392 self.realowner.nade_spawnloc = spawnloc;
395 void nade_heal_think()
397 if(time >= self.ltime)
403 self.nextthink = time;
405 if(time >= self.nade_special_time)
407 self.nade_special_time = time+0.25;
408 self.nade_show_particles = 1;
411 self.nade_show_particles = 0;
414 void nade_heal_touch()
418 if(IS_PLAYER(other) || IS_MONSTER(other))
419 if(other.deadflag == DEAD_NO)
422 health_factor = autocvar_g_nades_heal_rate*frametime/2;
423 if ( other != self.realowner )
425 if ( SAME_TEAM(other,self) )
426 health_factor *= autocvar_g_nades_heal_friend;
428 health_factor *= autocvar_g_nades_heal_foe;
430 if ( health_factor > 0 )
432 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
433 if ( other.health < maxhealth )
435 if ( self.nade_show_particles )
436 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
437 other.health = min(other.health+health_factor, maxhealth);
439 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
441 else if ( health_factor < 0 )
443 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
448 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
450 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
451 show_red.stat_healing_orb = time+0.1;
452 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
456 void nade_heal_boom()
460 healer.owner = self.owner;
461 healer.realowner = self.realowner;
462 setorigin(healer, self.origin);
463 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
464 healer.ltime = time + healer.healer_lifetime;
465 healer.team = self.realowner.team;
466 healer.bot_dodge = false;
467 healer.solid = SOLID_TRIGGER;
468 healer.touch = nade_heal_touch;
470 setmodel(healer, MDL_NADE_HEAL);
471 healer.healer_radius = autocvar_g_nades_nade_radius;
472 vector size = '1 1 1' * healer.healer_radius / 2;
473 setsize(healer,-size,size);
475 Net_LinkEntity(healer, true, 0, healer_send);
477 healer.think = nade_heal_think;
478 healer.nextthink = time;
479 healer.SendFlags |= 1;
482 void nade_monster_boom()
484 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
486 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
487 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
488 e.monster_skill = MONSTER_SKILL_INSANE;
494 bool nade_blast = true;
496 switch ( Nades[self.nade_type] )
498 case NADE_TYPE_NAPALM:
499 nade_blast = autocvar_g_nades_napalm_blast;
500 expef = EFFECT_EXPLOSION_MEDIUM;
504 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
506 case NADE_TYPE_TRANSLOCATE:
509 case NADE_TYPE_MONSTER:
510 case NADE_TYPE_SPAWN:
512 switch(self.realowner.team)
514 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
515 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
516 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
517 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
518 default: expef = EFFECT_SPAWN_NEUTRAL; break;
523 expef = EFFECT_SPAWN_RED;
527 case NADE_TYPE_NORMAL:
528 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
533 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
535 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
536 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
538 self.event_damage = func_null; // prevent somehow calling damage in the next call
542 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
543 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
544 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
548 switch ( Nades[self.nade_type] )
550 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
551 case NADE_TYPE_ICE: nade_ice_boom(); break;
552 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
553 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
554 case NADE_TYPE_HEAL: nade_heal_boom(); break;
555 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
559 for(head = world; (head = find(head, classname, "grapplinghook")); )
560 if(head.aiment == self)
561 RemoveGrapplingHook(head.realowner);
568 /*float is_weapclip = 0;
569 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
570 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
571 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
573 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
576 for(head = world; (head = find(head, classname, "grapplinghook")); )
577 if(head.aiment == self)
578 RemoveGrapplingHook(head.realowner);
585 //setsize(self, '-2 -2 -2', '2 2 2');
586 //UpdateCSQCProjectile(self);
587 if(self.health == self.max_health)
589 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
599 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
600 self.think = nade_boom;
601 self.nextthink = max(self.wait, time);
604 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
606 if(ITEM_DAMAGE_NEEDKILL(deathtype))
608 self.takedamage = DAMAGE_NO;
613 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
616 if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
622 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
624 force *= 0.5; // too much
628 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
631 damage = self.max_health * 0.55;
634 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN) || DEATH_ISWEAPON(deathtype, WEP_HMG))
635 damage = self.max_health * 0.1;
637 if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
638 if(deathtype & HITTYPE_SECONDARY)
640 damage = self.max_health * 0.1;
644 damage = self.max_health * 1.15;
646 self.velocity += force;
647 UpdateCSQCProjectile(self);
649 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
652 if(self.health == self.max_health)
654 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
655 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
656 self.think = nade_beep;
659 self.health -= damage;
661 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
662 self.realowner = attacker;
665 W_PrepareExplosionByDamage(attacker, nade_boom);
667 nade_burn_spawn(self);
670 void toss_nade(entity e, vector _velocity, float _time)
675 entity _nade = e.nade;
681 makevectors(e.v_angle);
683 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
685 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
687 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
688 + (v_right * autocvar_g_nades_throw_offset.y)
689 + (v_up * autocvar_g_nades_throw_offset.z);
690 if(autocvar_g_nades_throw_offset == '0 0 0')
693 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
694 //setmodel(_nade, MDL_PROJECTILE_NADE);
695 //setattachment(_nade, world, "");
696 PROJECTILE_MAKETRIGGER(_nade);
697 setsize(_nade, '-16 -16 -16', '16 16 16');
698 _nade.movetype = MOVETYPE_BOUNCE;
700 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
701 if (trace_startsolid)
702 setorigin(_nade, e.origin);
704 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
705 _nade.velocity = '0 0 100';
706 else if(autocvar_g_nades_nade_newton_style == 1)
707 _nade.velocity = e.velocity + _velocity;
708 else if(autocvar_g_nades_nade_newton_style == 2)
709 _nade.velocity = _velocity;
711 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
713 _nade.touch = nade_touch;
714 _nade.health = autocvar_g_nades_nade_health;
715 _nade.max_health = _nade.health;
716 _nade.takedamage = DAMAGE_AIM;
717 _nade.event_damage = nade_damage;
718 _nade.customizeentityforclient = func_null;
719 _nade.exteriormodeltoclient = world;
720 _nade.traileffectnum = 0;
721 _nade.teleportable = true;
722 _nade.pushable = true;
724 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
725 _nade.damagedbycontents = true;
726 _nade.angles = vectoangles(_nade.velocity);
727 _nade.flags = FL_PROJECTILE;
728 _nade.projectiledeathtype = DEATH_NADE.m_id;
729 _nade.toss_time = time;
730 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
732 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
733 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
735 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
741 _nade.think = nade_boom;
742 _nade.nextthink = _time;
745 e.nade_refire = time + autocvar_g_nades_nade_refire;
749 void nades_GiveBonus(entity player, float score)
751 if (autocvar_g_nades)
752 if (autocvar_g_nades_bonus)
753 if (IS_REAL_CLIENT(player))
754 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
755 if (player.frozen == 0)
756 if (player.deadflag == DEAD_NO)
758 if ( player.bonus_nade_score < 1 )
759 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
761 if ( player.bonus_nade_score >= 1 )
763 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
764 play2(player, SND(KH_ALARM));
765 player.bonus_nades++;
766 player.bonus_nade_score -= 1;
771 void nades_RemoveBonus(entity player)
773 player.bonus_nades = player.bonus_nade_score = 0;
776 float nade_customize()
778 //if(IS_SPEC(other)) { return false; }
779 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
781 // somewhat hide the model, but keep the glow
783 if(self.traileffectnum)
784 self.traileffectnum = 0;
789 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
790 if(!self.traileffectnum)
791 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[self.nade_type].m_projectile[false], self.team).eent_eff_name);
800 if(autocvar_g_nades_bonus_only)
801 if(!self.bonus_nades)
802 return; // only allow bonus nades
808 remove(self.fake_nade);
810 entity n = spawn(), fn = spawn();
812 n.classname = "nade";
813 fn.classname = "fake_nade";
815 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
816 n.nade_type = self.nade_type;
817 else if (self.bonus_nades >= 1)
819 n.nade_type = self.nade_type;
820 n.pokenade_type = self.pokenade_type;
821 self.bonus_nades -= 1;
825 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
826 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
829 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
831 setmodel(n, MDL_PROJECTILE_NADE);
832 //setattachment(n, self, "bip01 l hand");
833 n.exteriormodeltoclient = self;
834 n.customizeentityforclient = nade_customize;
835 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[n.nade_type].m_projectile[false], self.team).eent_eff_name);
836 n.colormod = Nades[n.nade_type].m_color;
838 n.colormap = self.colormap;
839 n.glowmod = self.glowmod;
840 n.wait = time + autocvar_g_nades_nade_lifetime;
841 n.nade_time_primed = time;
843 n.nextthink = max(n.wait - 3, time);
844 n.projectiledeathtype = DEATH_NADE.m_id;
846 setmodel(fn, MDL_NADE_VIEW);
847 setattachment(fn, self.weaponentity, "");
848 fn.realowner = fn.owner = self;
849 fn.colormod = Nades[n.nade_type].m_color;
850 fn.colormap = self.colormap;
851 fn.glowmod = self.glowmod;
852 fn.think = SUB_Remove;
853 fn.nextthink = n.wait;
867 if(self.deadflag != DEAD_NO)
870 if (!autocvar_g_nades)
871 return false; // allow turning them off mid match
873 if(forbidWeaponUse(self))
876 if (!IS_PLAYER(self))
882 .bool nade_altbutton;
884 void nades_CheckThrow()
889 entity held_nade = self.nade;
892 self.nade_altbutton = true;
893 if(time > self.nade_refire)
895 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
897 self.nade_refire = time + autocvar_g_nades_nade_refire;
902 self.nade_altbutton = false;
903 if (time >= held_nade.nade_time_primed + 1) {
904 makevectors(self.v_angle);
905 float _force = time - held_nade.nade_time_primed;
906 _force /= autocvar_g_nades_nade_lifetime;
907 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
908 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
913 void nades_Clear(entity player)
918 remove(player.fake_nade);
920 player.nade = player.fake_nade = world;
921 player.nade_timer = 0;
924 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
927 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
932 CLASS(NadeOffhand, OffhandWeapon)
933 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
935 entity held_nade = player.nade;
938 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
939 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
940 makevectors(player.angles);
941 held_nade.velocity = player.velocity;
942 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
943 held_nade.angles_y = player.angles.y;
945 if (time + 0.1 >= held_nade.wait)
946 toss_nade(player, '0 0 0', time + 0.05);
949 if (!CanThrowNade()) return;
950 if (!(time > player.nade_refire)) return;
954 held_nade = player.nade;
956 } else if (time >= held_nade.nade_time_primed + 1) {
958 makevectors(player.v_angle);
959 float _force = time - held_nade.nade_time_primed;
960 _force /= autocvar_g_nades_nade_lifetime;
961 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
962 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
966 ENDCLASS(NadeOffhand)
967 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
969 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
971 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
978 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
980 if (!IS_PLAYER(self)) { return false; }
982 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
986 if ( autocvar_g_nades_bonus && autocvar_g_nades )
990 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
993 if(self.flagcarried || self.ballcarried) // this player is important
994 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
996 time_score = autocvar_g_nades_bonus_score_time;
999 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1001 if(autocvar_g_nades_bonus_client_select)
1003 self.nade_type = self.cvar_cl_nade_type;
1004 self.pokenade_type = self.cvar_cl_pokenade_type;
1008 self.nade_type = autocvar_g_nades_bonus_type;
1009 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1012 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1014 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1015 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1019 self.bonus_nades = self.bonus_nade_score = 0;
1025 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1029 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1031 FOR_EACH_PLAYER(other) if(self != other)
1033 if(other.deadflag == DEAD_NO)
1034 if(other.frozen == 0)
1035 if(SAME_TEAM(other, self))
1036 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1040 if(self.frozen == 1)
1041 other.reviving = true;
1047 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1049 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1050 self.health = max(1, self.revive_progress * start_health);
1052 if(self.revive_progress >= 1)
1056 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1057 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1060 FOR_EACH_PLAYER(other) if(other.reviving)
1062 other.revive_progress = self.revive_progress;
1063 other.reviving = false;
1070 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1072 if(autocvar_g_nades_spawn)
1073 self.nade_refire = time + autocvar_g_spawnshieldtime;
1075 self.nade_refire = time + autocvar_g_nades_nade_refire;
1077 if(autocvar_g_nades_bonus_client_select)
1078 self.nade_type = self.cvar_cl_nade_type;
1080 self.nade_timer = 0;
1082 if (!self.offhand) self.offhand = OFFHAND_NADE;
1084 if(self.nade_spawnloc)
1086 setorigin(self, self.nade_spawnloc.origin);
1087 self.nade_spawnloc.cnt -= 1;
1089 if(self.nade_spawnloc.cnt <= 0)
1091 remove(self.nade_spawnloc);
1092 self.nade_spawnloc = world;
1099 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1101 if(frag_target.nade)
1102 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1103 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1105 float killcount_bonus = ((frag_attacker.killcount >= 1) ? bound(0, autocvar_g_nades_bonus_score_minor * frag_attacker.killcount, autocvar_g_nades_bonus_score_medium) : autocvar_g_nades_bonus_score_minor);
1107 if(IS_PLAYER(frag_attacker))
1109 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1110 nades_RemoveBonus(frag_attacker);
1111 else if(frag_target.flagcarried)
1112 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1113 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1115 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1116 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1117 switch(frag_attacker.killcount)
1120 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1125 nades_GiveBonus(frag_attacker, killcount_bonus);
1128 nades_RemoveBonus(frag_target);
1133 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1135 if(frag_target.frozen)
1136 if(autocvar_g_freezetag_revive_nade)
1137 if(frag_attacker == frag_target)
1138 if(frag_deathtype == DEATH_NADE.m_id)
1139 if(time - frag_inflictor.toss_time <= 0.1)
1141 Unfreeze(frag_target);
1142 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1143 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1145 frag_force = '0 0 0';
1146 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1147 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1153 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1155 if(IS_PLAYER(frag_attacker))
1156 if(DIFF_TEAM(frag_attacker, self))
1157 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1158 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1163 bool nades_RemovePlayer()
1166 nades_RemoveBonus(self);
1170 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1171 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1172 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1174 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1176 self.nade_timer = other.nade_timer;
1177 self.nade_type = other.nade_type;
1178 self.pokenade_type = other.pokenade_type;
1179 self.bonus_nades = other.bonus_nades;
1180 self.bonus_nade_score = other.bonus_nade_score;
1181 self.stat_healing_orb = other.stat_healing_orb;
1182 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1186 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1188 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1189 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1194 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1196 ret_string = strcat(ret_string, ":Nades");
1200 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1202 ret_string = strcat(ret_string, ", Nades");