1 #include "mutator_nades.qh"
6 #include "gamemode_keyhunt.qh"
7 #include "gamemode_freezetag.qh"
8 #include "../../common/nades.qh"
9 #include "../../common/monsters/spawn.qh"
10 #include "../../common/monsters/sv_monsters.qh"
14 .entity nade_spawnloc;
16 void nade_timer_think()
18 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
19 self.nextthink = time;
20 if(!self.owner || wasfreed(self.owner))
24 void nade_burn_spawn(entity _nade)
26 CSQCProjectile(_nade, true, NADES[_nade.nade_type].m_projectile[true], true);
29 void nade_spawn(entity _nade)
31 entity timer = spawn();
32 setmodel(timer, "models/ok_nade_counter/ok_nade_counter.md3");
33 setattachment(timer, _nade, "");
34 timer.classname = "nade_timer";
35 timer.colormap = _nade.colormap;
36 timer.glowmod = _nade.glowmod;
37 timer.think = nade_timer_think;
38 timer.nextthink = time;
39 timer.wait = _nade.wait;
43 _nade.effects |= EF_LOWPRECISION;
45 CSQCProjectile(_nade, true, NADES[_nade.nade_type].m_projectile[false], true);
48 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
57 RandomSelection_Init();
58 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
59 if(e.takedamage == DAMAGE_AIM)
60 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
61 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
65 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
66 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
67 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
68 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
71 e.fireball_impactvec = p;
72 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
75 if(RandomSelection_chosen_ent)
77 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
78 d = damage + (edgedamage - damage) * (d / dist);
79 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
80 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
81 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
86 void napalm_ball_think()
88 if(round_handler_IsActive())
89 if(!round_handler_IsRoundStarted())
95 if(time > self.pushltime)
101 vector midpoint = ((self.absmin + self.absmax) * 0.5);
102 if(pointcontents(midpoint) == CONTENT_WATER)
104 self.velocity = self.velocity * 0.5;
106 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
107 { self.velocity_z = 200; }
110 self.angles = vectoangles(self.velocity);
112 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
113 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
115 self.nextthink = time + 0.1;
119 void nade_napalm_ball()
124 spamsound(self, CH_SHOTS, W_Sound("fireball_fire"), VOL_BASE, ATTEN_NORM);
127 proj.owner = self.owner;
128 proj.realowner = self.realowner;
129 proj.team = self.owner.team;
130 proj.classname = "grenade";
131 proj.bot_dodge = true;
132 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
133 proj.movetype = MOVETYPE_BOUNCE;
134 proj.projectiledeathtype = DEATH_NADE_NAPALM;
135 PROJECTILE_MAKETRIGGER(proj);
136 setmodel(proj, "null");
137 proj.scale = 1;//0.5;
138 setsize(proj, '-4 -4 -4', '4 4 4');
139 setorigin(proj, self.origin);
140 proj.think = napalm_ball_think;
141 proj.nextthink = time;
142 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
143 proj.effects = EF_LOWPRECISION | EF_FLAME;
145 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
146 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
147 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
148 proj.velocity = kick;
150 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
152 proj.angles = vectoangles(proj.velocity);
153 proj.flags = FL_PROJECTILE;
154 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
156 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
160 void napalm_fountain_think()
163 if(round_handler_IsActive())
164 if(!round_handler_IsRoundStarted())
170 if(time >= self.ltime)
176 vector midpoint = ((self.absmin + self.absmax) * 0.5);
177 if(pointcontents(midpoint) == CONTENT_WATER)
179 self.velocity = self.velocity * 0.5;
181 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
182 { self.velocity_z = 200; }
184 UpdateCSQCProjectile(self);
187 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
188 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
190 self.nextthink = time + 0.1;
191 if(time >= self.nade_special_time)
193 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
198 void nade_napalm_boom()
202 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
207 fountain.owner = self.owner;
208 fountain.realowner = self.realowner;
209 fountain.origin = self.origin;
210 setorigin(fountain, fountain.origin);
211 fountain.think = napalm_fountain_think;
212 fountain.nextthink = time;
213 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
214 fountain.pushltime = fountain.ltime;
215 fountain.team = self.team;
216 fountain.movetype = MOVETYPE_TOSS;
217 fountain.projectiledeathtype = DEATH_NADE_NAPALM;
218 fountain.bot_dodge = true;
219 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
220 fountain.nade_special_time = time;
221 setsize(fountain, '-16 -16 -16', '16 16 16');
222 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
225 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
227 frost_target.frozen_by = freezefield.realowner;
228 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
229 Freeze(frost_target, 1/freeze_time, 3, false);
230 if(frost_target.ballcarried)
231 if(g_keepaway) { ka_DropEvent(frost_target); }
232 else { DropBall(frost_target.ballcarried, frost_target.origin, frost_target.velocity);}
233 if(frost_target.flagcarried) { ctf_Handle_Throw(frost_target, world, DROP_THROW); }
234 if(frost_target.nade) { toss_nade(frost_target, '0 0 0', time + 0.05); }
236 kh_Key_DropAll(frost_target, false);
239 void nade_ice_think()
242 if(round_handler_IsActive())
243 if(!round_handler_IsRoundStarted())
249 if(time >= self.ltime)
251 if ( autocvar_g_nades_ice_explode )
254 switch(self.realowner.team)
256 case NUM_TEAM_1: expef = EFFECT_NADE_RED_EXPLODE; break;
257 case NUM_TEAM_2: expef = EFFECT_NADE_BLUE_EXPLODE; break;
258 case NUM_TEAM_3: expef = EFFECT_NADE_YELLOW_EXPLODE; break;
259 case NUM_TEAM_4: expef = EFFECT_NADE_PINK_EXPLODE; break;
260 default: expef = EFFECT_NADE_NEUTRAL_EXPLODE; break;
262 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
263 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
265 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
266 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
267 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
268 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
275 self.nextthink = time+0.1;
280 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
282 randomw = random()*M_PI*2;
284 randomp.x = randomr*cos(randomw);
285 randomp.y = randomr*sin(randomw);
287 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
289 if(time >= self.nade_special_time)
291 self.nade_special_time = time+0.7;
294 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
295 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
299 float current_freeze_time = self.ltime - time - 0.1;
302 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
304 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
305 if(e.takedamage && e.deadflag == DEAD_NO)
307 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
309 if(current_freeze_time > 0)
310 nade_ice_freeze(self, e, current_freeze_time);
317 fountain.owner = self.owner;
318 fountain.realowner = self.realowner;
319 fountain.origin = self.origin;
320 setorigin(fountain, fountain.origin);
321 fountain.think = nade_ice_think;
322 fountain.nextthink = time;
323 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
324 fountain.pushltime = fountain.wait = fountain.ltime;
325 fountain.team = self.team;
326 fountain.movetype = MOVETYPE_TOSS;
327 fountain.projectiledeathtype = DEATH_NADE_ICE;
328 fountain.bot_dodge = false;
329 setsize(fountain, '-16 -16 -16', '16 16 16');
330 fountain.nade_special_time = time+0.3;
331 fountain.angles = self.angles;
333 if ( autocvar_g_nades_ice_explode )
335 setmodel(fountain, "models/grenademodel.md3");
336 entity timer = spawn();
337 setmodel(timer, "models/ok_nade_counter/ok_nade_counter.md3");
338 setattachment(timer, fountain, "");
339 timer.classname = "nade_timer";
340 timer.colormap = self.colormap;
341 timer.glowmod = self.glowmod;
342 timer.think = nade_timer_think;
343 timer.nextthink = time;
344 timer.wait = fountain.ltime;
345 timer.owner = fountain;
349 setmodel(fountain, "null");
352 void nade_translocate_boom()
354 if(self.realowner.vehicle)
357 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
358 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
359 locout = trace_endpos;
361 makevectors(self.realowner.angles);
363 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
365 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
368 void nade_spawn_boom()
370 entity spawnloc = spawn();
371 setorigin(spawnloc, self.origin);
372 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
373 spawnloc.movetype = MOVETYPE_NONE;
374 spawnloc.solid = SOLID_NOT;
375 spawnloc.drawonlytoclient = self.realowner;
376 spawnloc.effects = EF_STARDUST;
377 spawnloc.cnt = autocvar_g_nades_spawn_count;
379 if(self.realowner.nade_spawnloc)
381 remove(self.realowner.nade_spawnloc);
382 self.realowner.nade_spawnloc = world;
385 self.realowner.nade_spawnloc = spawnloc;
388 void nade_heal_think()
390 if(time >= self.ltime)
396 self.nextthink = time;
398 if(time >= self.nade_special_time)
400 self.nade_special_time = time+0.25;
401 self.nade_show_particles = 1;
404 self.nade_show_particles = 0;
407 void nade_heal_touch()
411 if(IS_PLAYER(other) || IS_MONSTER(other))
412 if(other.deadflag == DEAD_NO)
415 health_factor = autocvar_g_nades_heal_rate*frametime/2;
416 if ( other != self.realowner )
418 if ( SAME_TEAM(other,self) )
419 health_factor *= autocvar_g_nades_heal_friend;
421 health_factor *= autocvar_g_nades_heal_foe;
423 if ( health_factor > 0 )
425 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
426 if ( other.health < maxhealth )
428 if ( self.nade_show_particles )
429 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
430 other.health = min(other.health+health_factor, maxhealth);
432 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
434 else if ( health_factor < 0 )
436 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL,other.origin,'0 0 0');
441 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
443 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
444 show_red.stat_healing_orb = time+0.1;
445 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
449 void nade_heal_boom()
453 healer.owner = self.owner;
454 healer.realowner = self.realowner;
455 setorigin(healer, self.origin);
456 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
457 healer.ltime = time + healer.healer_lifetime;
458 healer.team = self.realowner.team;
459 healer.bot_dodge = false;
460 healer.solid = SOLID_TRIGGER;
461 healer.touch = nade_heal_touch;
463 setmodel(healer, "models/ctf/shield.md3");
464 healer.healer_radius = autocvar_g_nades_nade_radius;
465 vector size = '1 1 1' * healer.healer_radius / 2;
466 setsize(healer,-size,size);
468 Net_LinkEntity(healer, true, 0, healer_send);
470 healer.think = nade_heal_think;
471 healer.nextthink = time;
472 healer.SendFlags |= 1;
475 void nade_monster_boom()
477 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
479 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
480 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
481 e.monster_skill = MONSTER_SKILL_INSANE;
487 bool nade_blast = true;
489 switch ( NADES[self.nade_type] )
491 case NADE_TYPE_NAPALM:
492 nade_blast = autocvar_g_nades_napalm_blast;
493 expef = EFFECT_EXPLOSION_MEDIUM;
497 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
499 case NADE_TYPE_TRANSLOCATE:
502 case NADE_TYPE_MONSTER:
503 case NADE_TYPE_SPAWN:
505 switch(self.realowner.team)
507 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
508 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
509 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
510 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
511 default: expef = EFFECT_SPAWN_NEUTRAL; break;
516 expef = EFFECT_SPAWN_RED;
520 case NADE_TYPE_NORMAL:
521 switch(self.realowner.team)
523 case NUM_TEAM_1: expef = EFFECT_NADE_RED_EXPLODE; break;
524 case NUM_TEAM_2: expef = EFFECT_NADE_BLUE_EXPLODE; break;
525 case NUM_TEAM_3: expef = EFFECT_NADE_YELLOW_EXPLODE; break;
526 case NUM_TEAM_4: expef = EFFECT_NADE_PINK_EXPLODE; break;
527 default: expef = EFFECT_NADE_NEUTRAL_EXPLODE; break;
532 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
534 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
535 sound(self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
537 self.event_damage = func_null; // prevent somehow calling damage in the next call
541 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
542 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
543 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);
547 switch ( NADES[self.nade_type] )
549 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
550 case NADE_TYPE_ICE: nade_ice_boom(); break;
551 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
552 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
553 case NADE_TYPE_HEAL: nade_heal_boom(); break;
554 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
562 /*float is_weapclip = 0;
563 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
564 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
565 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
567 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
575 //setsize(self, '-2 -2 -2', '2 2 2');
576 //UpdateCSQCProjectile(self);
577 if(self.health == self.max_health)
579 spamsound(self, CH_SHOTS, W_Sound(strcat("grenade_bounce", ftos(1 + rint(random() * 5)))), VOL_BASE, ATTEN_NORM);
589 sound(self, CH_SHOTS_SINGLE, "overkill/grenadebip.ogg", VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
590 self.think = nade_boom;
591 self.nextthink = max(self.wait, time);
594 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
596 if(ITEM_DAMAGE_NEEDKILL(deathtype))
598 self.takedamage = DAMAGE_NO;
603 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
606 if(DEATH_ISWEAPON(deathtype, WEP_BLASTER.m_id))
612 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id) && (deathtype & HITTYPE_SECONDARY))
614 force *= 0.5; // too much
618 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX.m_id) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id))
621 damage = self.max_health * 0.55;
624 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN.m_id) || DEATH_ISWEAPON(deathtype, WEP_HMG.m_id))
625 damage = self.max_health * 0.1;
627 if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE.m_id) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN.m_id)) // WEAPONTODO
628 if(deathtype & HITTYPE_SECONDARY)
630 damage = self.max_health * 0.1;
634 damage = self.max_health * 1.15;
636 self.velocity += force;
637 UpdateCSQCProjectile(self);
639 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
642 if(self.health == self.max_health)
644 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
645 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
646 self.think = nade_beep;
649 self.health -= damage;
651 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
652 self.realowner = attacker;
655 W_PrepareExplosionByDamage(attacker, nade_boom);
657 nade_burn_spawn(self);
660 void toss_nade(entity e, vector _velocity, float _time)
665 entity _nade = e.nade;
671 makevectors(e.v_angle);
673 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
675 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
677 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
678 + (v_right * autocvar_g_nades_throw_offset.y)
679 + (v_up * autocvar_g_nades_throw_offset.z);
680 if(autocvar_g_nades_throw_offset == '0 0 0')
683 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
684 //setmodel(_nade, W_Model("v_ok_grenade.md3"));
685 //setattachment(_nade, world, "");
686 PROJECTILE_MAKETRIGGER(_nade);
687 setsize(_nade, '-16 -16 -16', '16 16 16');
688 _nade.movetype = MOVETYPE_BOUNCE;
690 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
691 if (trace_startsolid)
692 setorigin(_nade, e.origin);
694 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
695 _nade.velocity = '0 0 100';
696 else if(autocvar_g_nades_nade_newton_style == 1)
697 _nade.velocity = e.velocity + _velocity;
698 else if(autocvar_g_nades_nade_newton_style == 2)
699 _nade.velocity = _velocity;
701 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
703 _nade.touch = nade_touch;
704 _nade.health = autocvar_g_nades_nade_health;
705 _nade.max_health = _nade.health;
706 _nade.takedamage = DAMAGE_AIM;
707 _nade.event_damage = nade_damage;
708 _nade.customizeentityforclient = func_null;
709 _nade.exteriormodeltoclient = world;
710 _nade.traileffectnum = 0;
711 _nade.teleportable = true;
712 _nade.pushable = true;
714 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
715 _nade.damagedbycontents = true;
716 _nade.angles = vectoangles(_nade.velocity);
717 _nade.flags = FL_PROJECTILE;
718 _nade.projectiledeathtype = DEATH_NADE;
719 _nade.toss_time = time;
720 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
722 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
723 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
725 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
731 _nade.think = nade_boom;
732 _nade.nextthink = _time;
735 e.nade_refire = time + autocvar_g_nades_nade_refire;
739 void nades_GiveBonus(entity player, float score)
741 if (autocvar_g_nades)
742 if (autocvar_g_nades_bonus)
743 if (IS_REAL_CLIENT(player))
744 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
745 if (player.frozen == 0)
746 if (player.deadflag == DEAD_NO)
748 if ( player.bonus_nade_score < 1 )
749 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
751 if ( player.bonus_nade_score >= 1 )
753 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
754 play2(player,"kh/alarm.wav");
755 player.bonus_nades++;
756 player.bonus_nade_score -= 1;
761 void nades_RemoveBonus(entity player)
763 player.bonus_nades = player.bonus_nade_score = 0;
766 float nade_customize()
768 //if(IS_SPEC(other)) { return false; }
769 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
771 // somewhat hide the model, but keep the glow
773 if(self.traileffectnum)
774 self.traileffectnum = 0;
779 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
780 if(!self.traileffectnum)
781 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(NADES[self.nade_type].m_projectile[false], self.team));
794 remove(self.fake_nade);
796 entity n = spawn(), fn = spawn();
798 n.classname = "nade";
799 fn.classname = "fake_nade";
801 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
802 n.nade_type = self.nade_type;
803 else if (self.bonus_nades >= 1)
805 n.nade_type = self.nade_type;
806 n.pokenade_type = self.pokenade_type;
807 self.bonus_nades -= 1;
811 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
812 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
815 n.nade_type = bound(1, n.nade_type, NADES_COUNT);
817 setmodel(n, W_Model("v_ok_grenade.md3"));
818 //setattachment(n, self, "bip01 l hand");
819 n.exteriormodeltoclient = self;
820 n.customizeentityforclient = nade_customize;
821 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(NADES[n.nade_type].m_projectile[false], self.team));
822 n.colormod = NADES[n.nade_type].m_color;
824 n.colormap = self.colormap;
825 n.glowmod = self.glowmod;
826 n.wait = time + autocvar_g_nades_nade_lifetime;
829 n.nextthink = max(n.wait - 3, time);
830 n.projectiledeathtype = DEATH_NADE;
832 setmodel(fn, W_Model("h_ok_grenade.iqm"));
833 setattachment(fn, self.weaponentity, "");
834 fn.realowner = fn.owner = self;
835 fn.colormod = NADES[n.nade_type].m_color;
836 fn.colormap = self.colormap;
837 fn.glowmod = self.glowmod;
838 fn.think = SUB_Remove;
839 fn.nextthink = n.wait;
853 if(self.deadflag != DEAD_NO)
856 if (!autocvar_g_nades)
857 return false; // allow turning them off mid match
859 if(forbidWeaponUse(self))
862 if (!IS_PLAYER(self))
868 void nades_CheckThrow()
875 if(self.nade_refire < time)
877 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
879 self.nade_refire = time + autocvar_g_nades_nade_refire;
884 if(time - self.nade.lifetime >= 1)
886 makevectors(self.v_angle);
887 float _force = time - self.nade.lifetime;
888 _force /= autocvar_g_nades_nade_lifetime;
889 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
890 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
895 void nades_Clear(entity player)
900 remove(player.fake_nade);
902 player.nade = player.fake_nade = world;
903 player.nade_timer = 0;
906 MUTATOR_HOOKFUNCTION(nades_CheckThrow)
908 if(MUTATOR_RETURNVALUE) { nades_CheckThrow(); }
912 MUTATOR_HOOKFUNCTION(nades_VehicleEnter)
915 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
920 MUTATOR_HOOKFUNCTION(nades_PlayerPreThink)
922 if(!IS_PLAYER(self)) { return false; }
924 float key_pressed = self.BUTTON_HOOK;
927 if(g_grappling_hook || client_hasweapon(self, WEP_HOOK.m_id, false, false) || (weaponsInMap & WEPSET_HOOK))
928 key_pressed = self.button16; // if hook is enabled, use an alternate key
932 self.nade_timer = bound(0, (time - self.nade.lifetime) / autocvar_g_nades_nade_lifetime, 1);
933 //print(sprintf("%d %d\n", self.nade_timer, time - self.nade.lifetime));
934 makevectors(self.angles);
935 self.nade.velocity = self.velocity;
937 setorigin(self.nade, self.origin + self.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
938 self.nade.angles_y = self.angles.y;
942 if(self.nade.wait - 0.1 <= time)
943 toss_nade(self, '0 0 0', time + 0.05);
946 if(self.nade_refire < time)
953 else if(time - self.nade.lifetime >= 1)
957 makevectors(self.v_angle);
958 float _force = time - self.nade.lifetime;
959 _force /= autocvar_g_nades_nade_lifetime;
960 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
961 toss_nade(self, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
968 if ( autocvar_g_nades_bonus && autocvar_g_nades )
972 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
974 if(self.flagcarried || self.ballcarried) // this player is important
975 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
977 time_score = autocvar_g_nades_bonus_score_time;
980 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
982 if(autocvar_g_nades_bonus_client_select)
984 self.nade_type = self.cvar_cl_nade_type;
985 self.pokenade_type = self.cvar_cl_pokenade_type;
989 self.nade_type = autocvar_g_nades_bonus_type;
990 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
993 self.nade_type = bound(1, self.nade_type, NADES_COUNT);
995 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
996 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1000 self.bonus_nades = self.bonus_nade_score = 0;
1006 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1010 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1012 FOR_EACH_PLAYER(other) if(self != other)
1014 if(other.deadflag == DEAD_NO)
1015 if(other.frozen == 0)
1016 if(SAME_TEAM(other, self))
1017 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1021 if(self.frozen == 1)
1022 other.reviving = true;
1028 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1030 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1031 self.health = max(1, self.revive_progress * start_health);
1033 if(self.revive_progress >= 1)
1037 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1038 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1041 FOR_EACH_PLAYER(other) if(other.reviving)
1043 other.revive_progress = self.revive_progress;
1044 other.reviving = false;
1051 MUTATOR_HOOKFUNCTION(nades_PlayerSpawn)
1053 if(autocvar_g_nades_spawn)
1054 self.nade_refire = time + autocvar_g_spawnshieldtime;
1056 self.nade_refire = time + autocvar_g_nades_nade_refire;
1058 if(autocvar_g_nades_bonus_client_select)
1059 self.nade_type = self.cvar_cl_nade_type;
1061 self.nade_timer = 0;
1063 if(self.nade_spawnloc)
1065 setorigin(self, self.nade_spawnloc.origin);
1066 self.nade_spawnloc.cnt -= 1;
1068 if(self.nade_spawnloc.cnt <= 0)
1070 remove(self.nade_spawnloc);
1071 self.nade_spawnloc = world;
1078 MUTATOR_HOOKFUNCTION(nades_PlayerDies)
1080 if(frag_target.nade)
1081 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1082 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1084 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);
1086 if(IS_PLAYER(frag_attacker))
1088 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1089 nades_RemoveBonus(frag_attacker);
1090 else if(frag_target.flagcarried)
1091 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1092 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1094 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1095 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1096 switch(frag_attacker.killcount)
1099 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1104 nades_GiveBonus(frag_attacker, killcount_bonus);
1107 nades_RemoveBonus(frag_target);
1112 MUTATOR_HOOKFUNCTION(nades_PlayerDamage)
1114 if(frag_target.frozen)
1115 if(autocvar_g_freezetag_revive_nade)
1116 if(frag_attacker == frag_target)
1117 if(frag_deathtype == DEATH_NADE)
1118 if(time - frag_inflictor.toss_time <= 0.1)
1120 Unfreeze(frag_target);
1121 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1122 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1124 frag_force = '0 0 0';
1125 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1126 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1132 MUTATOR_HOOKFUNCTION(nades_MonsterDies)
1134 if(IS_PLAYER(frag_attacker))
1135 if(DIFF_TEAM(frag_attacker, self))
1136 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1137 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1142 MUTATOR_HOOKFUNCTION(nades_RemovePlayer)
1145 nades_RemoveBonus(self);
1149 MUTATOR_HOOKFUNCTION(nades_SpectateCopy)
1151 self.nade_timer = other.nade_timer;
1152 self.nade_type = other.nade_type;
1153 self.pokenade_type = other.pokenade_type;
1154 self.bonus_nades = other.bonus_nades;
1155 self.bonus_nade_score = other.bonus_nade_score;
1156 self.stat_healing_orb = other.stat_healing_orb;
1157 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1161 MUTATOR_HOOKFUNCTION(nades_GetCvars)
1163 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1164 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1169 MUTATOR_HOOKFUNCTION(nades_BuildMutatorsString)
1171 ret_string = strcat(ret_string, ":Nades");
1175 MUTATOR_HOOKFUNCTION(nades_BuildMutatorsPrettyString)
1177 ret_string = strcat(ret_string, ", Nades");
1181 void nades_Initialize()
1183 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
1184 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
1185 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
1186 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
1187 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
1188 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
1190 precache_model("models/ok_nade_counter/ok_nade_counter.md3");
1191 precache_model(W_Model("h_ok_grenade.iqm"));
1192 precache_model(W_Model("v_ok_grenade.md3"));
1193 precache_model("models/ctf/shield.md3");
1195 precache_sound(W_Sound("rocket_impact"));
1196 precache_sound(W_Sound("grenade_bounce1"));
1197 precache_sound(W_Sound("grenade_bounce2"));
1198 precache_sound(W_Sound("grenade_bounce3"));
1199 precache_sound(W_Sound("grenade_bounce4"));
1200 precache_sound(W_Sound("grenade_bounce5"));
1201 precache_sound(W_Sound("grenade_bounce6"));
1202 precache_sound("overkill/grenadebip.ogg");
1205 MUTATOR_DEFINITION(mutator_nades)
1207 MUTATOR_HOOK(ForbidThrowCurrentWeapon, nades_CheckThrow, CBC_ORDER_LAST);
1208 MUTATOR_HOOK(VehicleEnter, nades_VehicleEnter, CBC_ORDER_ANY);
1209 MUTATOR_HOOK(PlayerPreThink, nades_PlayerPreThink, CBC_ORDER_ANY);
1210 MUTATOR_HOOK(PlayerSpawn, nades_PlayerSpawn, CBC_ORDER_ANY);
1211 MUTATOR_HOOK(PlayerDies, nades_PlayerDies, CBC_ORDER_LAST);
1212 MUTATOR_HOOK(PlayerDamage_Calculate, nades_PlayerDamage, CBC_ORDER_ANY);
1213 MUTATOR_HOOK(MonsterDies, nades_MonsterDies, CBC_ORDER_ANY);
1214 MUTATOR_HOOK(MakePlayerObserver, nades_RemovePlayer, CBC_ORDER_ANY);
1215 MUTATOR_HOOK(ClientDisconnect, nades_RemovePlayer, CBC_ORDER_ANY);
1216 MUTATOR_HOOK(SpectateCopy, nades_SpectateCopy, CBC_ORDER_ANY);
1217 MUTATOR_HOOK(GetCvars, nades_GetCvars, CBC_ORDER_ANY);
1218 MUTATOR_HOOK(reset_map_global, nades_RemovePlayer, CBC_ORDER_ANY);
1219 MUTATOR_HOOK(BuildMutatorsString, nades_BuildMutatorsString, CBC_ORDER_ANY);
1220 MUTATOR_HOOK(BuildMutatorsPrettyString, nades_BuildMutatorsPrettyString, CBC_ORDER_ANY);