1 #ifndef MUTATOR_NADES_H
2 #define MUTATOR_NADES_H
5 #include "../../../../server/mutators/mutator/gamemode_freezetag.qc"
13 .float nade_special_time;
14 .float bonus_nade_score;
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;
22 .float 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"))
57 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
58 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
59 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
60 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
61 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
62 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
68 .float nade_time_primed;
70 .entity nade_spawnloc;
72 void nade_timer_think()
74 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
75 self.nextthink = time;
76 if(!self.owner || wasfreed(self.owner))
80 void nade_burn_spawn(entity _nade)
82 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
85 void nade_spawn(entity _nade)
87 entity timer = new(nade_timer);
88 setmodel(timer, MDL_NADE_TIMER);
89 setattachment(timer, _nade, "");
90 timer.colormap = _nade.colormap;
91 timer.glowmod = _nade.glowmod;
92 timer.think = nade_timer_think;
93 timer.nextthink = time;
94 timer.wait = _nade.wait;
98 _nade.effects |= EF_LOWPRECISION;
100 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
103 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
112 RandomSelection_Init();
113 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
114 if(e.takedamage == DAMAGE_AIM)
115 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
116 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
120 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
121 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
122 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
123 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
126 e.fireball_impactvec = p;
127 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
130 if(RandomSelection_chosen_ent)
132 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
133 d = damage + (edgedamage - damage) * (d / dist);
134 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
135 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
136 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
141 void napalm_ball_think()
143 if(round_handler_IsActive())
144 if(!round_handler_IsRoundStarted())
150 if(time > self.pushltime)
156 vector midpoint = ((self.absmin + self.absmax) * 0.5);
157 if(pointcontents(midpoint) == CONTENT_WATER)
159 self.velocity = self.velocity * 0.5;
161 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
162 { self.velocity_z = 200; }
165 self.angles = vectoangles(self.velocity);
167 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
168 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
170 self.nextthink = time + 0.1;
174 void nade_napalm_ball()
179 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
182 proj.owner = self.owner;
183 proj.realowner = self.realowner;
184 proj.team = self.owner.team;
185 proj.bot_dodge = true;
186 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
187 proj.movetype = MOVETYPE_BOUNCE;
188 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
189 PROJECTILE_MAKETRIGGER(proj);
190 setmodel(proj, MDL_Null);
191 proj.scale = 1;//0.5;
192 setsize(proj, '-4 -4 -4', '4 4 4');
193 setorigin(proj, self.origin);
194 proj.think = napalm_ball_think;
195 proj.nextthink = time;
196 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
197 proj.effects = EF_LOWPRECISION | EF_FLAME;
199 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
200 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
201 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
202 proj.velocity = kick;
204 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
206 proj.angles = vectoangles(proj.velocity);
207 proj.flags = FL_PROJECTILE;
208 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
210 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
214 void napalm_fountain_think()
217 if(round_handler_IsActive())
218 if(!round_handler_IsRoundStarted())
224 if(time >= self.ltime)
230 vector midpoint = ((self.absmin + self.absmax) * 0.5);
231 if(pointcontents(midpoint) == CONTENT_WATER)
233 self.velocity = self.velocity * 0.5;
235 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
236 { self.velocity_z = 200; }
238 UpdateCSQCProjectile(self);
241 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
242 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
244 self.nextthink = time + 0.1;
245 if(time >= self.nade_special_time)
247 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
252 void nade_napalm_boom()
256 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
261 fountain.owner = self.owner;
262 fountain.realowner = self.realowner;
263 fountain.origin = self.origin;
264 setorigin(fountain, fountain.origin);
265 fountain.think = napalm_fountain_think;
266 fountain.nextthink = time;
267 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
268 fountain.pushltime = fountain.ltime;
269 fountain.team = self.team;
270 fountain.movetype = MOVETYPE_TOSS;
271 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
272 fountain.bot_dodge = true;
273 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
274 fountain.nade_special_time = time;
275 setsize(fountain, '-16 -16 -16', '16 16 16');
276 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
279 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
281 frost_target.frozen_by = freezefield.realowner;
282 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
283 Freeze(frost_target, 1/freeze_time, 3, false);
285 Drop_Special_Items(frost_target);
288 void nade_ice_think()
291 if(round_handler_IsActive())
292 if(!round_handler_IsRoundStarted())
298 if(time >= self.ltime)
300 if ( autocvar_g_nades_ice_explode )
302 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
303 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
304 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
306 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
307 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
308 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
309 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
316 self.nextthink = time+0.1;
321 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
323 randomw = random()*M_PI*2;
325 randomp.x = randomr*cos(randomw);
326 randomp.y = randomr*sin(randomw);
328 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
330 if(time >= self.nade_special_time)
332 self.nade_special_time = time+0.7;
334 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
335 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
339 float current_freeze_time = self.ltime - time - 0.1;
342 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
344 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
345 if(e.takedamage && e.deadflag == DEAD_NO)
347 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
349 if(current_freeze_time > 0)
350 nade_ice_freeze(self, e, current_freeze_time);
357 fountain.owner = self.owner;
358 fountain.realowner = self.realowner;
359 fountain.origin = self.origin;
360 setorigin(fountain, fountain.origin);
361 fountain.think = nade_ice_think;
362 fountain.nextthink = time;
363 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
364 fountain.pushltime = fountain.wait = fountain.ltime;
365 fountain.team = self.team;
366 fountain.movetype = MOVETYPE_TOSS;
367 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
368 fountain.bot_dodge = false;
369 setsize(fountain, '-16 -16 -16', '16 16 16');
370 fountain.nade_special_time = time+0.3;
371 fountain.angles = self.angles;
373 if ( autocvar_g_nades_ice_explode )
375 setmodel(fountain, MDL_PROJECTILE_GRENADE);
376 entity timer = new(nade_timer);
377 setmodel(timer, MDL_NADE_TIMER);
378 setattachment(timer, fountain, "");
379 timer.colormap = self.colormap;
380 timer.glowmod = self.glowmod;
381 timer.think = nade_timer_think;
382 timer.nextthink = time;
383 timer.wait = fountain.ltime;
384 timer.owner = fountain;
388 setmodel(fountain, MDL_Null);
391 void nade_translocate_boom()
393 if(self.realowner.vehicle)
396 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
397 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
398 locout = trace_endpos;
400 makevectors(self.realowner.angles);
402 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
404 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
407 void nade_spawn_boom()
409 entity spawnloc = spawn();
410 setorigin(spawnloc, self.origin);
411 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
412 spawnloc.movetype = MOVETYPE_NONE;
413 spawnloc.solid = SOLID_NOT;
414 spawnloc.drawonlytoclient = self.realowner;
415 spawnloc.effects = EF_STARDUST;
416 spawnloc.cnt = autocvar_g_nades_spawn_count;
418 if(self.realowner.nade_spawnloc)
420 remove(self.realowner.nade_spawnloc);
421 self.realowner.nade_spawnloc = world;
424 self.realowner.nade_spawnloc = spawnloc;
427 void nade_heal_think()
429 if(time >= self.ltime)
435 self.nextthink = time;
437 if(time >= self.nade_special_time)
439 self.nade_special_time = time+0.25;
440 self.nade_show_particles = 1;
443 self.nade_show_particles = 0;
446 void nade_heal_touch()
450 if(IS_PLAYER(other) || IS_MONSTER(other))
451 if(other.deadflag == DEAD_NO)
454 health_factor = autocvar_g_nades_heal_rate*frametime/2;
455 if ( other != self.realowner )
457 if ( SAME_TEAM(other,self) )
458 health_factor *= autocvar_g_nades_heal_friend;
460 health_factor *= autocvar_g_nades_heal_foe;
462 if ( health_factor > 0 )
464 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
465 if ( other.health < maxhealth )
467 if ( self.nade_show_particles )
468 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
469 other.health = min(other.health+health_factor, maxhealth);
471 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
473 else if ( health_factor < 0 )
475 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
480 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
482 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
483 show_red.stat_healing_orb = time+0.1;
484 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
488 void nade_heal_boom()
492 healer.owner = self.owner;
493 healer.realowner = self.realowner;
494 setorigin(healer, self.origin);
495 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
496 healer.ltime = time + healer.healer_lifetime;
497 healer.team = self.realowner.team;
498 healer.bot_dodge = false;
499 healer.solid = SOLID_TRIGGER;
500 healer.touch = nade_heal_touch;
502 setmodel(healer, MDL_NADE_HEAL);
503 healer.healer_radius = autocvar_g_nades_nade_radius;
504 vector size = '1 1 1' * healer.healer_radius / 2;
505 setsize(healer,-size,size);
507 Net_LinkEntity(healer, true, 0, healer_send);
509 healer.think = nade_heal_think;
510 healer.nextthink = time;
511 healer.SendFlags |= 1;
514 void nade_monster_boom()
516 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
518 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
519 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
520 e.monster_skill = MONSTER_SKILL_INSANE;
526 bool nade_blast = true;
528 switch ( Nades_from(self.nade_type) )
530 case NADE_TYPE_NAPALM:
531 nade_blast = autocvar_g_nades_napalm_blast;
532 expef = EFFECT_EXPLOSION_MEDIUM;
536 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
538 case NADE_TYPE_TRANSLOCATE:
541 case NADE_TYPE_MONSTER:
542 case NADE_TYPE_SPAWN:
544 switch(self.realowner.team)
546 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
547 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
548 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
549 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
550 default: expef = EFFECT_SPAWN_NEUTRAL; break;
555 expef = EFFECT_SPAWN_RED;
559 case NADE_TYPE_NORMAL:
560 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
565 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
567 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
568 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
570 self.event_damage = func_null; // prevent somehow calling damage in the next call
574 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
575 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
576 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);
580 switch ( Nades_from(self.nade_type) )
582 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
583 case NADE_TYPE_ICE: nade_ice_boom(); break;
584 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
585 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
586 case NADE_TYPE_HEAL: nade_heal_boom(); break;
587 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
591 for(head = world; (head = find(head, classname, "grapplinghook")); )
592 if(head.aiment == self)
593 RemoveGrapplingHook(head.realowner);
600 /*float is_weapclip = 0;
601 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
602 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
603 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
605 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
608 for(head = world; (head = find(head, classname, "grapplinghook")); )
609 if(head.aiment == self)
610 RemoveGrapplingHook(head.realowner);
617 //setsize(self, '-2 -2 -2', '2 2 2');
618 //UpdateCSQCProjectile(self);
619 if(self.health == self.max_health)
621 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
631 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
632 self.think = nade_boom;
633 self.nextthink = max(self.wait, time);
636 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
638 if(ITEM_DAMAGE_NEEDKILL(deathtype))
640 self.takedamage = DAMAGE_NO;
645 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
648 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
649 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
654 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
656 force *= 0.5; // too much
659 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
662 damage = self.max_health * 0.55;
664 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
665 damage = self.max_health * 0.1;
666 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
668 if(deathtype & HITTYPE_SECONDARY)
670 damage = self.max_health * 0.1;
674 damage = self.max_health * 1.15;
677 self.velocity += force;
678 UpdateCSQCProjectile(self);
680 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
683 if(self.health == self.max_health)
685 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
686 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
687 self.think = nade_beep;
690 self.health -= damage;
692 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
693 self.realowner = attacker;
696 W_PrepareExplosionByDamage(attacker, nade_boom);
698 nade_burn_spawn(self);
701 void toss_nade(entity e, vector _velocity, float _time)
706 entity _nade = e.nade;
712 makevectors(e.v_angle);
714 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
716 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
718 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
719 + (v_right * autocvar_g_nades_throw_offset.y)
720 + (v_up * autocvar_g_nades_throw_offset.z);
721 if(autocvar_g_nades_throw_offset == '0 0 0')
724 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
725 //setmodel(_nade, MDL_PROJECTILE_NADE);
726 //setattachment(_nade, world, "");
727 PROJECTILE_MAKETRIGGER(_nade);
728 setsize(_nade, '-16 -16 -16', '16 16 16');
729 _nade.movetype = MOVETYPE_BOUNCE;
731 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
732 if (trace_startsolid)
733 setorigin(_nade, e.origin);
735 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
736 _nade.velocity = '0 0 100';
737 else if(autocvar_g_nades_nade_newton_style == 1)
738 _nade.velocity = e.velocity + _velocity;
739 else if(autocvar_g_nades_nade_newton_style == 2)
740 _nade.velocity = _velocity;
742 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
744 _nade.touch = nade_touch;
745 _nade.health = autocvar_g_nades_nade_health;
746 _nade.max_health = _nade.health;
747 _nade.takedamage = DAMAGE_AIM;
748 _nade.event_damage = nade_damage;
749 _nade.customizeentityforclient = func_null;
750 _nade.exteriormodeltoclient = world;
751 _nade.traileffectnum = 0;
752 _nade.teleportable = true;
753 _nade.pushable = true;
755 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
756 _nade.damagedbycontents = true;
757 _nade.angles = vectoangles(_nade.velocity);
758 _nade.flags = FL_PROJECTILE;
759 _nade.projectiledeathtype = DEATH_NADE.m_id;
760 _nade.toss_time = time;
761 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
763 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
764 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
766 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
772 _nade.think = nade_boom;
773 _nade.nextthink = _time;
776 e.nade_refire = time + autocvar_g_nades_nade_refire;
780 void nades_GiveBonus(entity player, float score)
782 if (autocvar_g_nades)
783 if (autocvar_g_nades_bonus)
784 if (IS_REAL_CLIENT(player))
785 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
786 if (player.frozen == 0)
787 if (player.deadflag == DEAD_NO)
789 if ( player.bonus_nade_score < 1 )
790 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
792 if ( player.bonus_nade_score >= 1 )
794 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
795 play2(player, SND(KH_ALARM));
796 player.bonus_nades++;
797 player.bonus_nade_score -= 1;
802 /** Remove all bonus nades from a player */
803 void nades_RemoveBonus(entity player)
805 player.bonus_nades = player.bonus_nade_score = 0;
808 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
810 nades_RemoveBonus(self);
813 float nade_customize()
815 //if(IS_SPEC(other)) { return false; }
816 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
818 // somewhat hide the model, but keep the glow
820 if(self.traileffectnum)
821 self.traileffectnum = 0;
826 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
827 if(!self.traileffectnum)
828 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
837 if(autocvar_g_nades_bonus_only)
838 if(!self.bonus_nades)
839 return; // only allow bonus nades
845 remove(self.fake_nade);
847 entity n = new(nade), fn = new(fake_nade);
849 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
850 n.nade_type = self.nade_type;
851 else if (self.bonus_nades >= 1)
853 n.nade_type = self.nade_type;
854 n.pokenade_type = self.pokenade_type;
855 self.bonus_nades -= 1;
859 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
860 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
863 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
865 setmodel(n, MDL_PROJECTILE_NADE);
866 //setattachment(n, self, "bip01 l hand");
867 n.exteriormodeltoclient = self;
868 n.customizeentityforclient = nade_customize;
869 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
870 n.colormod = Nades_from(n.nade_type).m_color;
872 n.colormap = self.colormap;
873 n.glowmod = self.glowmod;
874 n.wait = time + autocvar_g_nades_nade_lifetime;
875 n.nade_time_primed = time;
877 n.nextthink = max(n.wait - 3, time);
878 n.projectiledeathtype = DEATH_NADE.m_id;
880 setmodel(fn, MDL_NADE_VIEW);
881 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
882 setattachment(fn, self.(weaponentity), "");
883 fn.realowner = fn.owner = self;
884 fn.colormod = Nades_from(n.nade_type).m_color;
885 fn.colormap = self.colormap;
886 fn.glowmod = self.glowmod;
887 fn.think = SUB_Remove;
888 fn.nextthink = n.wait;
902 if(self.deadflag != DEAD_NO)
905 if (!autocvar_g_nades)
906 return false; // allow turning them off mid match
908 if(forbidWeaponUse(self))
911 if (!IS_PLAYER(self))
917 .bool nade_altbutton;
919 void nades_CheckThrow()
924 entity held_nade = self.nade;
927 self.nade_altbutton = true;
928 if(time > self.nade_refire)
930 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
932 self.nade_refire = time + autocvar_g_nades_nade_refire;
937 self.nade_altbutton = false;
938 if (time >= held_nade.nade_time_primed + 1) {
939 makevectors(self.v_angle);
940 float _force = time - held_nade.nade_time_primed;
941 _force /= autocvar_g_nades_nade_lifetime;
942 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
943 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
948 void nades_Clear(entity player)
953 remove(player.fake_nade);
955 player.nade = player.fake_nade = world;
956 player.nade_timer = 0;
959 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
962 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
967 CLASS(NadeOffhand, OffhandWeapon)
968 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
970 entity held_nade = player.nade;
973 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
974 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
975 makevectors(player.angles);
976 held_nade.velocity = player.velocity;
977 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
978 held_nade.angles_y = player.angles.y;
980 if (time + 0.1 >= held_nade.wait)
981 toss_nade(player, '0 0 0', time + 0.05);
984 if (!CanThrowNade()) return;
985 if (!(time > player.nade_refire)) return;
989 held_nade = player.nade;
991 } else if (time >= held_nade.nade_time_primed + 1) {
993 makevectors(player.v_angle);
994 float _force = time - held_nade.nade_time_primed;
995 _force /= autocvar_g_nades_nade_lifetime;
996 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
997 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
1001 ENDCLASS(NadeOffhand)
1002 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1004 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1006 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1013 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1015 if (!IS_PLAYER(self)) { return false; }
1017 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1021 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1024 float key_count = 0;
1025 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1028 if(self.flagcarried || self.ballcarried) // this player is important
1029 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1031 time_score = autocvar_g_nades_bonus_score_time;
1034 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1036 if(autocvar_g_nades_bonus_client_select)
1038 self.nade_type = self.cvar_cl_nade_type;
1039 self.pokenade_type = self.cvar_cl_pokenade_type;
1043 self.nade_type = autocvar_g_nades_bonus_type;
1044 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1047 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1049 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1050 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1054 self.bonus_nades = self.bonus_nade_score = 0;
1060 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1064 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1066 FOR_EACH_PLAYER(other) if(self != other)
1068 if(other.deadflag == DEAD_NO)
1069 if(other.frozen == 0)
1070 if(SAME_TEAM(other, self))
1071 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1075 if(self.frozen == 1)
1076 other.reviving = true;
1082 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1084 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1085 self.health = max(1, self.revive_progress * start_health);
1087 if(self.revive_progress >= 1)
1091 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1092 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1095 FOR_EACH_PLAYER(other) if(other.reviving)
1097 other.revive_progress = self.revive_progress;
1098 other.reviving = false;
1105 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1107 if(autocvar_g_nades_spawn)
1108 self.nade_refire = time + autocvar_g_spawnshieldtime;
1110 self.nade_refire = time + autocvar_g_nades_nade_refire;
1112 if(autocvar_g_nades_bonus_client_select)
1113 self.nade_type = self.cvar_cl_nade_type;
1115 self.nade_timer = 0;
1117 if (!self.offhand) self.offhand = OFFHAND_NADE;
1119 if(self.nade_spawnloc)
1121 setorigin(self, self.nade_spawnloc.origin);
1122 self.nade_spawnloc.cnt -= 1;
1124 if(self.nade_spawnloc.cnt <= 0)
1126 remove(self.nade_spawnloc);
1127 self.nade_spawnloc = world;
1134 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1136 if(frag_target.nade)
1137 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1138 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1140 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);
1142 if(IS_PLAYER(frag_attacker))
1144 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1145 nades_RemoveBonus(frag_attacker);
1146 else if(frag_target.flagcarried)
1147 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1148 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1150 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1151 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1152 switch(frag_attacker.killcount)
1155 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1160 nades_GiveBonus(frag_attacker, killcount_bonus);
1163 nades_RemoveBonus(frag_target);
1168 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1170 if(frag_target.frozen)
1171 if(autocvar_g_freezetag_revive_nade)
1172 if(frag_attacker == frag_target)
1173 if(frag_deathtype == DEATH_NADE.m_id)
1174 if(time - frag_inflictor.toss_time <= 0.1)
1176 Unfreeze(frag_target);
1177 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1178 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1180 frag_force = '0 0 0';
1181 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1182 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1188 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1190 if(IS_PLAYER(frag_attacker))
1191 if(DIFF_TEAM(frag_attacker, self))
1192 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1193 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1198 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1200 if(frag_target.nade)
1201 toss_nade(frag_target, '0 0 0', time + 0.05);
1206 bool nades_RemovePlayer()
1209 nades_RemoveBonus(self);
1213 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1214 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1215 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1217 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1219 self.nade_timer = other.nade_timer;
1220 self.nade_type = other.nade_type;
1221 self.pokenade_type = other.pokenade_type;
1222 self.bonus_nades = other.bonus_nades;
1223 self.bonus_nade_score = other.bonus_nade_score;
1224 self.stat_healing_orb = other.stat_healing_orb;
1225 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1229 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1231 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1232 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1237 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1239 ret_string = strcat(ret_string, ":Nades");
1243 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1245 ret_string = strcat(ret_string, ", Nades");