1 #ifndef MUTATOR_NADES_H
2 #define MUTATOR_NADES_H
9 .float nade_special_time;
10 .float bonus_nade_score;
12 .string pokenade_type;
13 .entity nade_damage_target;
14 .float cvar_cl_nade_type;
15 .string cvar_cl_pokenade_type;
17 .float stat_healing_orb;
18 .float stat_healing_orb_alpha;
19 .float nade_show_particles;
21 // Remove nades that are being thrown
22 void(entity player) nades_Clear;
24 // Give a bonus grenade to a player
25 void(entity player, float score) nades_GiveBonus;
26 // Remove all bonus nades from a player
27 void(entity player) nades_RemoveBonus;
30 * called to adjust nade damage and force on hit
32 #define EV_Nade_Damage(i, o) \
33 /** weapon */ i(entity, MUTATOR_ARGV_0_entity) \
34 /** force */ i(vector, MUTATOR_ARGV_0_vector) \
35 /**/ o(vector, MUTATOR_ARGV_0_vector) \
36 /** damage */ i(float, MUTATOR_ARGV_0_float) \
37 /**/ o(float, MUTATOR_ARGV_0_float) \
39 MUTATOR_HOOKABLE(Nade_Damage, EV_Nade_Damage);
44 #include "../../../common/nades/all.qh"
45 #include "../../../common/gamemodes/all.qh"
46 #include "../../../common/monsters/spawn.qh"
47 #include "../../../common/monsters/sv_monsters.qh"
48 #include "../../g_subs.qh"
50 REGISTER_MUTATOR(nades, cvar("g_nades"))
54 addstat(STAT_NADE_TIMER, AS_FLOAT, nade_timer);
55 addstat(STAT_NADE_BONUS, AS_FLOAT, bonus_nades);
56 addstat(STAT_NADE_BONUS_TYPE, AS_INT, nade_type);
57 addstat(STAT_NADE_BONUS_SCORE, AS_FLOAT, bonus_nade_score);
58 addstat(STAT_HEALING_ORB, AS_FLOAT, stat_healing_orb);
59 addstat(STAT_HEALING_ORB_ALPHA, AS_FLOAT, stat_healing_orb_alpha);
65 .float nade_time_primed;
67 .entity nade_spawnloc;
69 void nade_timer_think()
71 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
72 self.nextthink = time;
73 if(!self.owner || wasfreed(self.owner))
77 void nade_burn_spawn(entity _nade)
79 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
82 void nade_spawn(entity _nade)
84 entity timer = new(nade_timer);
85 setmodel(timer, MDL_NADE_TIMER);
86 setattachment(timer, _nade, "");
87 timer.colormap = _nade.colormap;
88 timer.glowmod = _nade.glowmod;
89 timer.think = nade_timer_think;
90 timer.nextthink = time;
91 timer.wait = _nade.wait;
95 _nade.effects |= EF_LOWPRECISION;
97 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
100 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
109 RandomSelection_Init();
110 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
111 if(e.takedamage == DAMAGE_AIM)
112 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
113 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
117 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
118 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
119 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
120 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
123 e.fireball_impactvec = p;
124 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
127 if(RandomSelection_chosen_ent)
129 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
130 d = damage + (edgedamage - damage) * (d / dist);
131 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
132 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
133 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
138 void napalm_ball_think()
140 if(round_handler_IsActive())
141 if(!round_handler_IsRoundStarted())
147 if(time > self.pushltime)
153 vector midpoint = ((self.absmin + self.absmax) * 0.5);
154 if(pointcontents(midpoint) == CONTENT_WATER)
156 self.velocity = self.velocity * 0.5;
158 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
159 { self.velocity_z = 200; }
162 self.angles = vectoangles(self.velocity);
164 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
165 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
167 self.nextthink = time + 0.1;
171 void nade_napalm_ball()
176 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
179 proj.owner = self.owner;
180 proj.realowner = self.realowner;
181 proj.team = self.owner.team;
182 proj.bot_dodge = true;
183 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
184 proj.movetype = MOVETYPE_BOUNCE;
185 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
186 PROJECTILE_MAKETRIGGER(proj);
187 setmodel(proj, MDL_Null);
188 proj.scale = 1;//0.5;
189 setsize(proj, '-4 -4 -4', '4 4 4');
190 setorigin(proj, self.origin);
191 proj.think = napalm_ball_think;
192 proj.nextthink = time;
193 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
194 proj.effects = EF_LOWPRECISION | EF_FLAME;
196 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
197 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
198 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
199 proj.velocity = kick;
201 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
203 proj.angles = vectoangles(proj.velocity);
204 proj.flags = FL_PROJECTILE;
205 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
207 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
211 void napalm_fountain_think()
214 if(round_handler_IsActive())
215 if(!round_handler_IsRoundStarted())
221 if(time >= self.ltime)
227 vector midpoint = ((self.absmin + self.absmax) * 0.5);
228 if(pointcontents(midpoint) == CONTENT_WATER)
230 self.velocity = self.velocity * 0.5;
232 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
233 { self.velocity_z = 200; }
235 UpdateCSQCProjectile(self);
238 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
239 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
241 self.nextthink = time + 0.1;
242 if(time >= self.nade_special_time)
244 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
249 void nade_napalm_boom()
253 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
258 fountain.owner = self.owner;
259 fountain.realowner = self.realowner;
260 fountain.origin = self.origin;
261 setorigin(fountain, fountain.origin);
262 fountain.think = napalm_fountain_think;
263 fountain.nextthink = time;
264 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
265 fountain.pushltime = fountain.ltime;
266 fountain.team = self.team;
267 fountain.movetype = MOVETYPE_TOSS;
268 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
269 fountain.bot_dodge = true;
270 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
271 fountain.nade_special_time = time;
272 setsize(fountain, '-16 -16 -16', '16 16 16');
273 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
276 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
278 frost_target.frozen_by = freezefield.realowner;
279 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
280 Freeze(frost_target, 1/freeze_time, 3, false);
282 Drop_Special_Items(frost_target);
285 void nade_ice_think()
288 if(round_handler_IsActive())
289 if(!round_handler_IsRoundStarted())
295 if(time >= self.ltime)
297 if ( autocvar_g_nades_ice_explode )
299 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
300 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
301 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
303 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
304 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
305 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
306 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
313 self.nextthink = time+0.1;
318 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
320 randomw = random()*M_PI*2;
322 randomp.x = randomr*cos(randomw);
323 randomp.y = randomr*sin(randomw);
325 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
327 if(time >= self.nade_special_time)
329 self.nade_special_time = time+0.7;
331 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
332 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
336 float current_freeze_time = self.ltime - time - 0.1;
339 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
341 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
342 if(e.takedamage && e.deadflag == DEAD_NO)
344 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
346 if(current_freeze_time > 0)
347 nade_ice_freeze(self, e, current_freeze_time);
354 fountain.owner = self.owner;
355 fountain.realowner = self.realowner;
356 fountain.origin = self.origin;
357 setorigin(fountain, fountain.origin);
358 fountain.think = nade_ice_think;
359 fountain.nextthink = time;
360 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
361 fountain.pushltime = fountain.wait = fountain.ltime;
362 fountain.team = self.team;
363 fountain.movetype = MOVETYPE_TOSS;
364 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
365 fountain.bot_dodge = false;
366 setsize(fountain, '-16 -16 -16', '16 16 16');
367 fountain.nade_special_time = time+0.3;
368 fountain.angles = self.angles;
370 if ( autocvar_g_nades_ice_explode )
372 setmodel(fountain, MDL_PROJECTILE_GRENADE);
373 entity timer = new(nade_timer);
374 setmodel(timer, MDL_NADE_TIMER);
375 setattachment(timer, fountain, "");
376 timer.colormap = self.colormap;
377 timer.glowmod = self.glowmod;
378 timer.think = nade_timer_think;
379 timer.nextthink = time;
380 timer.wait = fountain.ltime;
381 timer.owner = fountain;
385 setmodel(fountain, MDL_Null);
388 void nade_translocate_boom()
390 if(self.realowner.vehicle)
393 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
394 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
395 locout = trace_endpos;
397 makevectors(self.realowner.angles);
399 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
401 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
404 void nade_spawn_boom()
406 entity spawnloc = spawn();
407 setorigin(spawnloc, self.origin);
408 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
409 spawnloc.movetype = MOVETYPE_NONE;
410 spawnloc.solid = SOLID_NOT;
411 spawnloc.drawonlytoclient = self.realowner;
412 spawnloc.effects = EF_STARDUST;
413 spawnloc.cnt = autocvar_g_nades_spawn_count;
415 if(self.realowner.nade_spawnloc)
417 remove(self.realowner.nade_spawnloc);
418 self.realowner.nade_spawnloc = world;
421 self.realowner.nade_spawnloc = spawnloc;
424 void nade_heal_think()
426 if(time >= self.ltime)
432 self.nextthink = time;
434 if(time >= self.nade_special_time)
436 self.nade_special_time = time+0.25;
437 self.nade_show_particles = 1;
440 self.nade_show_particles = 0;
443 void nade_heal_touch()
447 if(IS_PLAYER(other) || IS_MONSTER(other))
448 if(other.deadflag == DEAD_NO)
451 health_factor = autocvar_g_nades_heal_rate*frametime/2;
452 if ( other != self.realowner )
454 if ( SAME_TEAM(other,self) )
455 health_factor *= autocvar_g_nades_heal_friend;
457 health_factor *= autocvar_g_nades_heal_foe;
459 if ( health_factor > 0 )
461 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
462 if ( other.health < maxhealth )
464 if ( self.nade_show_particles )
465 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
466 other.health = min(other.health+health_factor, maxhealth);
468 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
470 else if ( health_factor < 0 )
472 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
477 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
479 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
480 show_red.stat_healing_orb = time+0.1;
481 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
485 void nade_heal_boom()
489 healer.owner = self.owner;
490 healer.realowner = self.realowner;
491 setorigin(healer, self.origin);
492 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
493 healer.ltime = time + healer.healer_lifetime;
494 healer.team = self.realowner.team;
495 healer.bot_dodge = false;
496 healer.solid = SOLID_TRIGGER;
497 healer.touch = nade_heal_touch;
499 setmodel(healer, MDL_NADE_HEAL);
500 healer.healer_radius = autocvar_g_nades_nade_radius;
501 vector size = '1 1 1' * healer.healer_radius / 2;
502 setsize(healer,-size,size);
504 Net_LinkEntity(healer, true, 0, healer_send);
506 healer.think = nade_heal_think;
507 healer.nextthink = time;
508 healer.SendFlags |= 1;
511 void nade_monster_boom()
513 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
515 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
516 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
517 e.monster_skill = MONSTER_SKILL_INSANE;
523 bool nade_blast = true;
525 switch ( Nades_from(self.nade_type) )
527 case NADE_TYPE_NAPALM:
528 nade_blast = autocvar_g_nades_napalm_blast;
529 expef = EFFECT_EXPLOSION_MEDIUM;
533 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
535 case NADE_TYPE_TRANSLOCATE:
538 case NADE_TYPE_MONSTER:
539 case NADE_TYPE_SPAWN:
541 switch(self.realowner.team)
543 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
544 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
545 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
546 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
547 default: expef = EFFECT_SPAWN_NEUTRAL; break;
552 expef = EFFECT_SPAWN_RED;
556 case NADE_TYPE_NORMAL:
557 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
562 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
564 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
565 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
567 self.event_damage = func_null; // prevent somehow calling damage in the next call
571 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
572 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
573 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);
577 switch ( Nades_from(self.nade_type) )
579 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
580 case NADE_TYPE_ICE: nade_ice_boom(); break;
581 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
582 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
583 case NADE_TYPE_HEAL: nade_heal_boom(); break;
584 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
588 for(head = world; (head = find(head, classname, "grapplinghook")); )
589 if(head.aiment == self)
590 RemoveGrapplingHook(head.realowner);
597 /*float is_weapclip = 0;
598 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
599 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
600 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
602 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
605 for(head = world; (head = find(head, classname, "grapplinghook")); )
606 if(head.aiment == self)
607 RemoveGrapplingHook(head.realowner);
614 //setsize(self, '-2 -2 -2', '2 2 2');
615 //UpdateCSQCProjectile(self);
616 if(self.health == self.max_health)
618 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
628 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
629 self.think = nade_boom;
630 self.nextthink = max(self.wait, time);
633 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
635 if(ITEM_DAMAGE_NEEDKILL(deathtype))
637 self.takedamage = DAMAGE_NO;
642 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
645 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
646 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
651 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
653 force *= 0.5; // too much
656 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
659 damage = self.max_health * 0.55;
661 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
662 damage = self.max_health * 0.1;
663 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
665 if(deathtype & HITTYPE_SECONDARY)
667 damage = self.max_health * 0.1;
671 damage = self.max_health * 1.15;
674 self.velocity += force;
675 UpdateCSQCProjectile(self);
677 if(damage <= 0 || ((self.flags & FL_ONGROUND) && IS_PLAYER(attacker)))
680 if(self.health == self.max_health)
682 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
683 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
684 self.think = nade_beep;
687 self.health -= damage;
689 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
690 self.realowner = attacker;
693 W_PrepareExplosionByDamage(attacker, nade_boom);
695 nade_burn_spawn(self);
698 void toss_nade(entity e, vector _velocity, float _time)
703 entity _nade = e.nade;
709 makevectors(e.v_angle);
711 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
713 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
715 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
716 + (v_right * autocvar_g_nades_throw_offset.y)
717 + (v_up * autocvar_g_nades_throw_offset.z);
718 if(autocvar_g_nades_throw_offset == '0 0 0')
721 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
722 //setmodel(_nade, MDL_PROJECTILE_NADE);
723 //setattachment(_nade, world, "");
724 PROJECTILE_MAKETRIGGER(_nade);
725 setsize(_nade, '-16 -16 -16', '16 16 16');
726 _nade.movetype = MOVETYPE_BOUNCE;
728 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
729 if (trace_startsolid)
730 setorigin(_nade, e.origin);
732 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
733 _nade.velocity = '0 0 100';
734 else if(autocvar_g_nades_nade_newton_style == 1)
735 _nade.velocity = e.velocity + _velocity;
736 else if(autocvar_g_nades_nade_newton_style == 2)
737 _nade.velocity = _velocity;
739 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
741 _nade.touch = nade_touch;
742 _nade.health = autocvar_g_nades_nade_health;
743 _nade.max_health = _nade.health;
744 _nade.takedamage = DAMAGE_AIM;
745 _nade.event_damage = nade_damage;
746 _nade.customizeentityforclient = func_null;
747 _nade.exteriormodeltoclient = world;
748 _nade.traileffectnum = 0;
749 _nade.teleportable = true;
750 _nade.pushable = true;
752 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
753 _nade.damagedbycontents = true;
754 _nade.angles = vectoangles(_nade.velocity);
755 _nade.flags = FL_PROJECTILE;
756 _nade.projectiledeathtype = DEATH_NADE.m_id;
757 _nade.toss_time = time;
758 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
760 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
761 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
763 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
769 _nade.think = nade_boom;
770 _nade.nextthink = _time;
773 e.nade_refire = time + autocvar_g_nades_nade_refire;
777 void nades_GiveBonus(entity player, float score)
779 if (autocvar_g_nades)
780 if (autocvar_g_nades_bonus)
781 if (IS_REAL_CLIENT(player))
782 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
783 if (player.frozen == 0)
784 if (player.deadflag == DEAD_NO)
786 if ( player.bonus_nade_score < 1 )
787 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
789 if ( player.bonus_nade_score >= 1 )
791 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
792 play2(player, SND(KH_ALARM));
793 player.bonus_nades++;
794 player.bonus_nade_score -= 1;
799 void nades_RemoveBonus(entity player)
801 player.bonus_nades = player.bonus_nade_score = 0;
804 float nade_customize()
806 //if(IS_SPEC(other)) { return false; }
807 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
809 // somewhat hide the model, but keep the glow
811 if(self.traileffectnum)
812 self.traileffectnum = 0;
817 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
818 if(!self.traileffectnum)
819 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
828 if(autocvar_g_nades_bonus_only)
829 if(!self.bonus_nades)
830 return; // only allow bonus nades
836 remove(self.fake_nade);
838 entity n = new(nade), fn = new(fake_nade);
840 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
841 n.nade_type = self.nade_type;
842 else if (self.bonus_nades >= 1)
844 n.nade_type = self.nade_type;
845 n.pokenade_type = self.pokenade_type;
846 self.bonus_nades -= 1;
850 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
851 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
854 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
856 setmodel(n, MDL_PROJECTILE_NADE);
857 //setattachment(n, self, "bip01 l hand");
858 n.exteriormodeltoclient = self;
859 n.customizeentityforclient = nade_customize;
860 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
861 n.colormod = Nades_from(n.nade_type).m_color;
863 n.colormap = self.colormap;
864 n.glowmod = self.glowmod;
865 n.wait = time + autocvar_g_nades_nade_lifetime;
866 n.nade_time_primed = time;
868 n.nextthink = max(n.wait - 3, time);
869 n.projectiledeathtype = DEATH_NADE.m_id;
871 setmodel(fn, MDL_NADE_VIEW);
872 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
873 setattachment(fn, self.(weaponentity), "");
874 fn.realowner = fn.owner = self;
875 fn.colormod = Nades_from(n.nade_type).m_color;
876 fn.colormap = self.colormap;
877 fn.glowmod = self.glowmod;
878 fn.think = SUB_Remove;
879 fn.nextthink = n.wait;
893 if(self.deadflag != DEAD_NO)
896 if (!autocvar_g_nades)
897 return false; // allow turning them off mid match
899 if(forbidWeaponUse(self))
902 if (!IS_PLAYER(self))
908 .bool nade_altbutton;
910 void nades_CheckThrow()
915 entity held_nade = self.nade;
918 self.nade_altbutton = true;
919 if(time > self.nade_refire)
921 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
923 self.nade_refire = time + autocvar_g_nades_nade_refire;
928 self.nade_altbutton = false;
929 if (time >= held_nade.nade_time_primed + 1) {
930 makevectors(self.v_angle);
931 float _force = time - held_nade.nade_time_primed;
932 _force /= autocvar_g_nades_nade_lifetime;
933 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
934 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
939 void nades_Clear(entity player)
944 remove(player.fake_nade);
946 player.nade = player.fake_nade = world;
947 player.nade_timer = 0;
950 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
953 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
958 CLASS(NadeOffhand, OffhandWeapon)
959 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
961 entity held_nade = player.nade;
964 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
965 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
966 makevectors(player.angles);
967 held_nade.velocity = player.velocity;
968 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
969 held_nade.angles_y = player.angles.y;
971 if (time + 0.1 >= held_nade.wait)
972 toss_nade(player, '0 0 0', time + 0.05);
975 if (!CanThrowNade()) return;
976 if (!(time > player.nade_refire)) return;
980 held_nade = player.nade;
982 } else if (time >= held_nade.nade_time_primed + 1) {
984 makevectors(player.v_angle);
985 float _force = time - held_nade.nade_time_primed;
986 _force /= autocvar_g_nades_nade_lifetime;
987 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
988 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
992 ENDCLASS(NadeOffhand)
993 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
995 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
997 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1004 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1006 if (!IS_PLAYER(self)) { return false; }
1008 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1012 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1015 float key_count = 0;
1016 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1019 if(self.flagcarried || self.ballcarried) // this player is important
1020 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1022 time_score = autocvar_g_nades_bonus_score_time;
1025 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1027 if(autocvar_g_nades_bonus_client_select)
1029 self.nade_type = self.cvar_cl_nade_type;
1030 self.pokenade_type = self.cvar_cl_pokenade_type;
1034 self.nade_type = autocvar_g_nades_bonus_type;
1035 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1038 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1040 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1041 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1045 self.bonus_nades = self.bonus_nade_score = 0;
1051 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1055 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1057 FOR_EACH_PLAYER(other) if(self != other)
1059 if(other.deadflag == DEAD_NO)
1060 if(other.frozen == 0)
1061 if(SAME_TEAM(other, self))
1062 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
1066 if(self.frozen == 1)
1067 other.reviving = true;
1073 if(n && self.frozen == 3) // OK, there is at least one teammate reviving us
1075 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1076 self.health = max(1, self.revive_progress * start_health);
1078 if(self.revive_progress >= 1)
1082 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1083 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1086 FOR_EACH_PLAYER(other) if(other.reviving)
1088 other.revive_progress = self.revive_progress;
1089 other.reviving = false;
1096 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1098 if(autocvar_g_nades_spawn)
1099 self.nade_refire = time + autocvar_g_spawnshieldtime;
1101 self.nade_refire = time + autocvar_g_nades_nade_refire;
1103 if(autocvar_g_nades_bonus_client_select)
1104 self.nade_type = self.cvar_cl_nade_type;
1106 self.nade_timer = 0;
1108 if (!self.offhand) self.offhand = OFFHAND_NADE;
1110 if(self.nade_spawnloc)
1112 setorigin(self, self.nade_spawnloc.origin);
1113 self.nade_spawnloc.cnt -= 1;
1115 if(self.nade_spawnloc.cnt <= 0)
1117 remove(self.nade_spawnloc);
1118 self.nade_spawnloc = world;
1125 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1127 if(frag_target.nade)
1128 if(!frag_target.frozen || !autocvar_g_freezetag_revive_nade)
1129 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1131 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);
1133 if(IS_PLAYER(frag_attacker))
1135 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1136 nades_RemoveBonus(frag_attacker);
1137 else if(frag_target.flagcarried)
1138 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1139 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1141 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1142 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1143 switch(frag_attacker.killcount)
1146 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1151 nades_GiveBonus(frag_attacker, killcount_bonus);
1154 nades_RemoveBonus(frag_target);
1159 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1161 if(frag_target.frozen)
1162 if(autocvar_g_freezetag_revive_nade)
1163 if(frag_attacker == frag_target)
1164 if(frag_deathtype == DEATH_NADE.m_id)
1165 if(time - frag_inflictor.toss_time <= 0.1)
1167 Unfreeze(frag_target);
1168 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1169 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1171 frag_force = '0 0 0';
1172 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1173 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1179 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1181 if(IS_PLAYER(frag_attacker))
1182 if(DIFF_TEAM(frag_attacker, self))
1183 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1184 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1189 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1191 if(frag_target.nade)
1192 toss_nade(frag_target, '0 0 0', time + 0.05);
1197 bool nades_RemovePlayer()
1200 nades_RemoveBonus(self);
1204 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1205 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1206 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1208 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1210 self.nade_timer = other.nade_timer;
1211 self.nade_type = other.nade_type;
1212 self.pokenade_type = other.pokenade_type;
1213 self.bonus_nades = other.bonus_nades;
1214 self.bonus_nade_score = other.bonus_nade_score;
1215 self.stat_healing_orb = other.stat_healing_orb;
1216 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1220 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1222 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1223 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1228 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1230 ret_string = strcat(ret_string, ":Nades");
1234 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1236 ret_string = strcat(ret_string, ", Nades");