1 #ifndef MUTATOR_NADES_H
2 #define MUTATOR_NADES_H
5 #include "../../../../server/mutators/mutator/gamemode_freezetag.qc"
10 .float nade_timer = _STAT(NADE_TIMER);
12 .float bonus_nades = _STAT(NADE_BONUS);
13 .float nade_special_time;
14 .float bonus_nade_score = _STAT(NADE_BONUS_SCORE);
15 .int nade_type = _STAT(NADE_BONUS_TYPE);
16 .string pokenade_type;
17 .entity nade_damage_target;
18 .float cvar_cl_nade_type;
19 .string cvar_cl_pokenade_type;
21 .float stat_healing_orb = _STAT(HEALING_ORB);
22 .float stat_healing_orb_alpha = _STAT(HEALING_ORB_ALPHA);
23 .float nade_show_particles;
25 // Remove nades that are being thrown
26 void nades_Clear(entity player);
28 // Give a bonus grenade to a player
29 void(entity player, float score) nades_GiveBonus;
32 * called to adjust nade damage and force on hit
34 #define EV_Nade_Damage(i, o) \
35 /** weapon */ i(entity, MUTATOR_ARGV_0_entity) \
36 /** force */ i(vector, MUTATOR_ARGV_0_vector) \
37 /**/ o(vector, MUTATOR_ARGV_0_vector) \
38 /** damage */ i(float, MUTATOR_ARGV_0_float) \
39 /**/ o(float, MUTATOR_ARGV_0_float) \
41 MUTATOR_HOOKABLE(Nade_Damage, EV_Nade_Damage);
47 #include "../../../nades/all.qh"
48 #include "../../../gamemodes/all.qh"
49 #include "../../../monsters/spawn.qh"
50 #include "../../../monsters/sv_monsters.qh"
51 #include "../../../../server/g_subs.qh"
53 REGISTER_MUTATOR(nades, cvar("g_nades"));
55 .float nade_time_primed;
57 .entity nade_spawnloc;
59 void nade_timer_think()
61 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
62 self.nextthink = time;
63 if(!self.owner || wasfreed(self.owner))
67 void nade_burn_spawn(entity _nade)
69 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
72 void nade_spawn(entity _nade)
74 entity timer = new(nade_timer);
75 setmodel(timer, MDL_NADE_TIMER);
76 setattachment(timer, _nade, "");
77 timer.colormap = _nade.colormap;
78 timer.glowmod = _nade.glowmod;
79 timer.think = nade_timer_think;
80 timer.nextthink = time;
81 timer.wait = _nade.wait;
85 _nade.effects |= EF_LOWPRECISION;
87 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
90 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
99 RandomSelection_Init();
100 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
101 if(e.takedamage == DAMAGE_AIM)
102 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
103 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
107 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
108 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
109 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
110 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
113 e.fireball_impactvec = p;
114 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
117 if(RandomSelection_chosen_ent)
119 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
120 d = damage + (edgedamage - damage) * (d / dist);
121 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
122 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
123 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
128 void napalm_ball_think()
130 if(round_handler_IsActive())
131 if(!round_handler_IsRoundStarted())
137 if(time > self.pushltime)
143 vector midpoint = ((self.absmin + self.absmax) * 0.5);
144 if(pointcontents(midpoint) == CONTENT_WATER)
146 self.velocity = self.velocity * 0.5;
148 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
149 { self.velocity_z = 200; }
152 self.angles = vectoangles(self.velocity);
154 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
155 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
157 self.nextthink = time + 0.1;
161 void nade_napalm_ball()
166 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
169 proj.owner = self.owner;
170 proj.realowner = self.realowner;
171 proj.team = self.owner.team;
172 proj.bot_dodge = true;
173 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
174 proj.movetype = MOVETYPE_BOUNCE;
175 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
176 PROJECTILE_MAKETRIGGER(proj);
177 setmodel(proj, MDL_Null);
178 proj.scale = 1;//0.5;
179 setsize(proj, '-4 -4 -4', '4 4 4');
180 setorigin(proj, self.origin);
181 proj.think = napalm_ball_think;
182 proj.nextthink = time;
183 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
184 proj.effects = EF_LOWPRECISION | EF_FLAME;
186 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
187 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
188 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
189 proj.velocity = kick;
191 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
193 proj.angles = vectoangles(proj.velocity);
194 proj.flags = FL_PROJECTILE;
195 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
197 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
201 void napalm_fountain_think()
204 if(round_handler_IsActive())
205 if(!round_handler_IsRoundStarted())
211 if(time >= self.ltime)
217 vector midpoint = ((self.absmin + self.absmax) * 0.5);
218 if(pointcontents(midpoint) == CONTENT_WATER)
220 self.velocity = self.velocity * 0.5;
222 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
223 { self.velocity_z = 200; }
225 UpdateCSQCProjectile(self);
228 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
229 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
231 self.nextthink = time + 0.1;
232 if(time >= self.nade_special_time)
234 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
239 void nade_napalm_boom()
243 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
248 fountain.owner = self.owner;
249 fountain.realowner = self.realowner;
250 fountain.origin = self.origin;
251 setorigin(fountain, fountain.origin);
252 fountain.think = napalm_fountain_think;
253 fountain.nextthink = time;
254 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
255 fountain.pushltime = fountain.ltime;
256 fountain.team = self.team;
257 fountain.movetype = MOVETYPE_TOSS;
258 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
259 fountain.bot_dodge = true;
260 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
261 fountain.nade_special_time = time;
262 setsize(fountain, '-16 -16 -16', '16 16 16');
263 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
266 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
268 frost_target.frozen_by = freezefield.realowner;
269 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
270 Freeze(frost_target, 1/freeze_time, 3, false);
272 Drop_Special_Items(frost_target);
275 void nade_ice_think()
278 if(round_handler_IsActive())
279 if(!round_handler_IsRoundStarted())
285 if(time >= self.ltime)
287 if ( autocvar_g_nades_ice_explode )
289 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
290 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
291 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
293 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
294 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
295 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
296 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
303 self.nextthink = time+0.1;
308 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
310 randomw = random()*M_PI*2;
312 randomp.x = randomr*cos(randomw);
313 randomp.y = randomr*sin(randomw);
315 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
317 if(time >= self.nade_special_time)
319 self.nade_special_time = time+0.7;
321 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
322 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
326 float current_freeze_time = self.ltime - time - 0.1;
329 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
331 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
332 if(e.takedamage && e.deadflag == DEAD_NO)
334 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
336 if(current_freeze_time > 0)
337 nade_ice_freeze(self, e, current_freeze_time);
344 fountain.owner = self.owner;
345 fountain.realowner = self.realowner;
346 fountain.origin = self.origin;
347 setorigin(fountain, fountain.origin);
348 fountain.think = nade_ice_think;
349 fountain.nextthink = time;
350 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
351 fountain.pushltime = fountain.wait = fountain.ltime;
352 fountain.team = self.team;
353 fountain.movetype = MOVETYPE_TOSS;
354 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
355 fountain.bot_dodge = false;
356 setsize(fountain, '-16 -16 -16', '16 16 16');
357 fountain.nade_special_time = time+0.3;
358 fountain.angles = self.angles;
360 if ( autocvar_g_nades_ice_explode )
362 setmodel(fountain, MDL_PROJECTILE_GRENADE);
363 entity timer = new(nade_timer);
364 setmodel(timer, MDL_NADE_TIMER);
365 setattachment(timer, fountain, "");
366 timer.colormap = self.colormap;
367 timer.glowmod = self.glowmod;
368 timer.think = nade_timer_think;
369 timer.nextthink = time;
370 timer.wait = fountain.ltime;
371 timer.owner = fountain;
375 setmodel(fountain, MDL_Null);
378 void nade_translocate_boom()
380 if(self.realowner.vehicle)
383 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
384 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
385 locout = trace_endpos;
387 makevectors(self.realowner.angles);
389 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
391 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
394 void nade_spawn_boom()
396 entity spawnloc = spawn();
397 setorigin(spawnloc, self.origin);
398 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
399 spawnloc.movetype = MOVETYPE_NONE;
400 spawnloc.solid = SOLID_NOT;
401 spawnloc.drawonlytoclient = self.realowner;
402 spawnloc.effects = EF_STARDUST;
403 spawnloc.cnt = autocvar_g_nades_spawn_count;
405 if(self.realowner.nade_spawnloc)
407 remove(self.realowner.nade_spawnloc);
408 self.realowner.nade_spawnloc = world;
411 self.realowner.nade_spawnloc = spawnloc;
414 void nade_heal_think()
416 if(time >= self.ltime)
422 self.nextthink = time;
424 if(time >= self.nade_special_time)
426 self.nade_special_time = time+0.25;
427 self.nade_show_particles = 1;
430 self.nade_show_particles = 0;
433 void nade_heal_touch()
437 if(IS_PLAYER(other) || IS_MONSTER(other))
438 if(other.deadflag == DEAD_NO)
441 health_factor = autocvar_g_nades_heal_rate*frametime/2;
442 if ( other != self.realowner )
444 if ( SAME_TEAM(other,self) )
445 health_factor *= autocvar_g_nades_heal_friend;
447 health_factor *= autocvar_g_nades_heal_foe;
449 if ( health_factor > 0 )
451 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
452 if ( other.health < maxhealth )
454 if ( self.nade_show_particles )
455 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
456 other.health = min(other.health+health_factor, maxhealth);
458 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
460 else if ( health_factor < 0 )
462 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
467 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
469 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
470 show_red.stat_healing_orb = time+0.1;
471 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
475 void nade_heal_boom()
479 healer.owner = self.owner;
480 healer.realowner = self.realowner;
481 setorigin(healer, self.origin);
482 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
483 healer.ltime = time + healer.healer_lifetime;
484 healer.team = self.realowner.team;
485 healer.bot_dodge = false;
486 healer.solid = SOLID_TRIGGER;
487 healer.touch = nade_heal_touch;
489 setmodel(healer, MDL_NADE_HEAL);
490 healer.healer_radius = autocvar_g_nades_nade_radius;
491 vector size = '1 1 1' * healer.healer_radius / 2;
492 setsize(healer,-size,size);
494 Net_LinkEntity(healer, true, 0, healer_send);
496 healer.think = nade_heal_think;
497 healer.nextthink = time;
498 healer.SendFlags |= 1;
501 void nade_monster_boom()
503 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
505 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
506 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
507 e.monster_skill = MONSTER_SKILL_INSANE;
513 bool nade_blast = true;
515 switch ( Nades_from(self.nade_type) )
517 case NADE_TYPE_NAPALM:
518 nade_blast = autocvar_g_nades_napalm_blast;
519 expef = EFFECT_EXPLOSION_MEDIUM;
523 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
525 case NADE_TYPE_TRANSLOCATE:
528 case NADE_TYPE_MONSTER:
529 case NADE_TYPE_SPAWN:
531 switch(self.realowner.team)
533 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
534 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
535 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
536 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
537 default: expef = EFFECT_SPAWN_NEUTRAL; break;
542 expef = EFFECT_SPAWN_RED;
546 case NADE_TYPE_NORMAL:
547 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
552 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
554 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
555 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
557 self.event_damage = func_null; // prevent somehow calling damage in the next call
561 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
562 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
563 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);
567 switch ( Nades_from(self.nade_type) )
569 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
570 case NADE_TYPE_ICE: nade_ice_boom(); break;
571 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
572 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
573 case NADE_TYPE_HEAL: nade_heal_boom(); break;
574 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
578 for(head = world; (head = find(head, classname, "grapplinghook")); )
579 if(head.aiment == self)
580 RemoveGrapplingHook(head.realowner);
587 /*float is_weapclip = 0;
588 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
589 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
590 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
592 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
595 for(head = world; (head = find(head, classname, "grapplinghook")); )
596 if(head.aiment == self)
597 RemoveGrapplingHook(head.realowner);
604 //setsize(self, '-2 -2 -2', '2 2 2');
605 //UpdateCSQCProjectile(self);
606 if(self.health == self.max_health)
608 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
618 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
619 self.think = nade_boom;
620 self.nextthink = max(self.wait, time);
623 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
625 if(ITEM_DAMAGE_NEEDKILL(deathtype))
627 self.takedamage = DAMAGE_NO;
632 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
635 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
636 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
641 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
643 force *= 0.5; // too much
646 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
649 damage = self.max_health * 0.55;
651 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
652 damage = self.max_health * 0.1;
653 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
655 if(deathtype & HITTYPE_SECONDARY)
657 damage = self.max_health * 0.1;
661 damage = self.max_health * 1.15;
664 self.velocity += force;
665 UpdateCSQCProjectile(self);
667 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
670 if(self.health == self.max_health)
672 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
673 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
674 self.think = nade_beep;
677 self.health -= damage;
679 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
680 self.realowner = attacker;
683 W_PrepareExplosionByDamage(attacker, nade_boom);
685 nade_burn_spawn(self);
688 void toss_nade(entity e, vector _velocity, float _time)
693 entity _nade = e.nade;
699 makevectors(e.v_angle);
701 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
703 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
705 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
706 + (v_right * autocvar_g_nades_throw_offset.y)
707 + (v_up * autocvar_g_nades_throw_offset.z);
708 if(autocvar_g_nades_throw_offset == '0 0 0')
711 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
712 //setmodel(_nade, MDL_PROJECTILE_NADE);
713 //setattachment(_nade, world, "");
714 PROJECTILE_MAKETRIGGER(_nade);
715 setsize(_nade, '-16 -16 -16', '16 16 16');
716 _nade.movetype = MOVETYPE_BOUNCE;
718 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
719 if (trace_startsolid)
720 setorigin(_nade, e.origin);
722 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
723 _nade.velocity = '0 0 100';
724 else if(autocvar_g_nades_nade_newton_style == 1)
725 _nade.velocity = e.velocity + _velocity;
726 else if(autocvar_g_nades_nade_newton_style == 2)
727 _nade.velocity = _velocity;
729 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
731 _nade.touch = nade_touch;
732 _nade.health = autocvar_g_nades_nade_health;
733 _nade.max_health = _nade.health;
734 _nade.takedamage = DAMAGE_AIM;
735 _nade.event_damage = nade_damage;
736 _nade.customizeentityforclient = func_null;
737 _nade.exteriormodeltoclient = world;
738 _nade.traileffectnum = 0;
739 _nade.teleportable = true;
740 _nade.pushable = true;
742 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
743 _nade.damagedbycontents = true;
744 _nade.angles = vectoangles(_nade.velocity);
745 _nade.flags = FL_PROJECTILE;
746 _nade.projectiledeathtype = DEATH_NADE.m_id;
747 _nade.toss_time = time;
748 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
750 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
751 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
753 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
759 _nade.think = nade_boom;
760 _nade.nextthink = _time;
763 e.nade_refire = time + autocvar_g_nades_nade_refire;
767 void nades_GiveBonus(entity player, float score)
769 if (autocvar_g_nades)
770 if (autocvar_g_nades_bonus)
771 if (IS_REAL_CLIENT(player))
772 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
773 if (player.frozen == 0)
774 if (player.deadflag == DEAD_NO)
776 if ( player.bonus_nade_score < 1 )
777 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
779 if ( player.bonus_nade_score >= 1 )
781 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
782 play2(player, SND(KH_ALARM));
783 player.bonus_nades++;
784 player.bonus_nade_score -= 1;
789 /** Remove all bonus nades from a player */
790 void nades_RemoveBonus(entity player)
792 player.bonus_nades = player.bonus_nade_score = 0;
795 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
797 nades_RemoveBonus(self);
800 float nade_customize()
802 //if(IS_SPEC(other)) { return false; }
803 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
805 // somewhat hide the model, but keep the glow
807 if(self.traileffectnum)
808 self.traileffectnum = 0;
813 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
814 if(!self.traileffectnum)
815 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
824 if(autocvar_g_nades_bonus_only)
825 if(!self.bonus_nades)
826 return; // only allow bonus nades
832 remove(self.fake_nade);
834 entity n = new(nade), fn = new(fake_nade);
836 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
837 n.nade_type = self.nade_type;
838 else if (self.bonus_nades >= 1)
840 n.nade_type = self.nade_type;
841 n.pokenade_type = self.pokenade_type;
842 self.bonus_nades -= 1;
846 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
847 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
850 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
852 setmodel(n, MDL_PROJECTILE_NADE);
853 //setattachment(n, self, "bip01 l hand");
854 n.exteriormodeltoclient = self;
855 n.customizeentityforclient = nade_customize;
856 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
857 n.colormod = Nades_from(n.nade_type).m_color;
859 n.colormap = self.colormap;
860 n.glowmod = self.glowmod;
861 n.wait = time + autocvar_g_nades_nade_lifetime;
862 n.nade_time_primed = time;
864 n.nextthink = max(n.wait - 3, time);
865 n.projectiledeathtype = DEATH_NADE.m_id;
867 setmodel(fn, MDL_NADE_VIEW);
868 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
869 setattachment(fn, self.(weaponentity), "");
870 fn.realowner = fn.owner = self;
871 fn.colormod = Nades_from(n.nade_type).m_color;
872 fn.colormap = self.colormap;
873 fn.glowmod = self.glowmod;
874 fn.think = SUB_Remove;
875 fn.nextthink = n.wait;
889 if(self.deadflag != DEAD_NO)
892 if (!autocvar_g_nades)
893 return false; // allow turning them off mid match
895 if(forbidWeaponUse(self))
898 if (!IS_PLAYER(self))
904 .bool nade_altbutton;
906 void nades_CheckThrow()
911 entity held_nade = self.nade;
914 self.nade_altbutton = true;
915 if(time > self.nade_refire)
917 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
919 self.nade_refire = time + autocvar_g_nades_nade_refire;
924 self.nade_altbutton = false;
925 if (time >= held_nade.nade_time_primed + 1) {
926 makevectors(self.v_angle);
927 float _force = time - held_nade.nade_time_primed;
928 _force /= autocvar_g_nades_nade_lifetime;
929 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
930 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
935 void nades_Clear(entity player)
940 remove(player.fake_nade);
942 player.nade = player.fake_nade = world;
943 player.nade_timer = 0;
946 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
949 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
954 CLASS(NadeOffhand, OffhandWeapon)
955 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
957 entity held_nade = player.nade;
960 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
961 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
962 makevectors(player.angles);
963 held_nade.velocity = player.velocity;
964 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
965 held_nade.angles_y = player.angles.y;
967 if (time + 0.1 >= held_nade.wait)
968 toss_nade(player, '0 0 0', time + 0.05);
971 if (!CanThrowNade()) return;
972 if (!(time > player.nade_refire)) return;
976 held_nade = player.nade;
978 } else if (time >= held_nade.nade_time_primed + 1) {
980 makevectors(player.v_angle);
981 float _force = time - held_nade.nade_time_primed;
982 _force /= autocvar_g_nades_nade_lifetime;
983 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
984 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
988 ENDCLASS(NadeOffhand)
989 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
991 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
993 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1000 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1002 if (!IS_PLAYER(self)) { return false; }
1004 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1008 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1011 float key_count = 0;
1012 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1015 if(self.flagcarried || self.ballcarried) // this player is important
1016 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1018 time_score = autocvar_g_nades_bonus_score_time;
1021 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1023 if(autocvar_g_nades_bonus_client_select)
1025 self.nade_type = self.cvar_cl_nade_type;
1026 self.pokenade_type = self.cvar_cl_pokenade_type;
1030 self.nade_type = autocvar_g_nades_bonus_type;
1031 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1034 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1036 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1037 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1041 self.bonus_nades = self.bonus_nade_score = 0;
1047 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1051 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1053 FOR_EACH_PLAYER(other) if(self != other)
1055 if(other.deadflag == DEAD_NO)
1056 if(other.frozen == 0)
1057 if(SAME_TEAM(other, self))
1058 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1062 if(self.frozen == 1)
1063 other.reviving = true;
1069 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1071 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1072 self.health = max(1, self.revive_progress * start_health);
1074 if(self.revive_progress >= 1)
1078 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1079 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1082 FOR_EACH_PLAYER(other) if(other.reviving)
1084 other.revive_progress = self.revive_progress;
1085 other.reviving = false;
1092 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1094 if(autocvar_g_nades_spawn)
1095 self.nade_refire = time + autocvar_g_spawnshieldtime;
1097 self.nade_refire = time + autocvar_g_nades_nade_refire;
1099 if(autocvar_g_nades_bonus_client_select)
1100 self.nade_type = self.cvar_cl_nade_type;
1102 self.nade_timer = 0;
1104 if (!self.offhand) self.offhand = OFFHAND_NADE;
1106 if(self.nade_spawnloc)
1108 setorigin(self, self.nade_spawnloc.origin);
1109 self.nade_spawnloc.cnt -= 1;
1111 if(self.nade_spawnloc.cnt <= 0)
1113 remove(self.nade_spawnloc);
1114 self.nade_spawnloc = world;
1121 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1123 if(frag_target.nade)
1124 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1125 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1127 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);
1129 if(IS_PLAYER(frag_attacker))
1131 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1132 nades_RemoveBonus(frag_attacker);
1133 else if(frag_target.flagcarried)
1134 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1135 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1137 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1138 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1139 switch(frag_attacker.killcount)
1142 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1147 nades_GiveBonus(frag_attacker, killcount_bonus);
1150 nades_RemoveBonus(frag_target);
1155 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1157 if(frag_target.frozen)
1158 if(autocvar_g_freezetag_revive_nade)
1159 if(frag_attacker == frag_target)
1160 if(frag_deathtype == DEATH_NADE.m_id)
1161 if(time - frag_inflictor.toss_time <= 0.1)
1163 Unfreeze(frag_target);
1164 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1165 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1167 frag_force = '0 0 0';
1168 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1169 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1175 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1177 if(IS_PLAYER(frag_attacker))
1178 if(DIFF_TEAM(frag_attacker, self))
1179 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1180 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1185 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1187 if(frag_target.nade)
1188 toss_nade(frag_target, '0 0 0', time + 0.05);
1193 bool nades_RemovePlayer()
1196 nades_RemoveBonus(self);
1200 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1201 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1202 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1204 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1206 self.nade_timer = other.nade_timer;
1207 self.nade_type = other.nade_type;
1208 self.pokenade_type = other.pokenade_type;
1209 self.bonus_nades = other.bonus_nades;
1210 self.bonus_nade_score = other.bonus_nade_score;
1211 self.stat_healing_orb = other.stat_healing_orb;
1212 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1216 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1218 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1219 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1224 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1226 ret_string = strcat(ret_string, ":Nades");
1230 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1232 ret_string = strcat(ret_string, ", Nades");