]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/nades/nades.qc
Add some checks to prevent silly things, like corpses (not the undead ones) picking...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / nades / nades.qc
1 #include "nades.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6 bool autocvar_g_nades_nade_small;
7 #endif
8
9 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
10
11 #ifndef MENUQC
12 entity Nade_TrailEffect(int proj, int nade_team)
13 {
14     switch (proj)
15     {
16         case PROJECTILE_NADE:       return EFFECT_NADE_TRAIL(nade_team);
17         case PROJECTILE_NADE_BURN:  return EFFECT_NADE_TRAIL_BURN(nade_team);
18     }
19
20     FOREACH(Nades, true, LAMBDA(
21         for (int j = 0; j < 2; j++)
22         {
23             if (it.m_projectile[j] == proj)
24             {
25                 string trail = it.m_trail[j].eent_eff_name;
26                 if (trail) return it.m_trail[j];
27                 break;
28             }
29         }
30     ));
31
32     return EFFECT_Null;
33 }
34 #endif
35
36 #ifdef CSQC
37 REGISTER_MUTATOR(cl_nades, true);
38 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
39 {
40         if (STAT(HEALING_ORB) <= time) return false;
41         MUTATOR_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
42         MUTATOR_ARGV(0, float) = STAT(HEALING_ORB_ALPHA);
43         return true;
44 }
45 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
46 {
47         if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
48         {
49                 self.modelindex = 0;
50                 self.traileffect = EFFECT_FIREBALL.m_id;
51                 return true;
52         }
53         if (Nade_FromProjectile(self.cnt) != NADE_TYPE_Null)
54         {
55                 setmodel(self, MDL_PROJECTILE_NADE);
56                 entity trail = Nade_TrailEffect(self.cnt, self.team);
57                 if (trail.eent_eff_name) self.traileffect = trail.m_id;
58                 return true;
59         }
60 }
61 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
62 {
63         if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
64         {
65                 loopsound(self, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
66                 self.mins = '-16 -16 -16';
67                 self.maxs = '16 16 16';
68         }
69
70         entity nade_type = Nade_FromProjectile(self.cnt);
71         if (nade_type == NADE_TYPE_Null) return;
72         if(STAT(NADES_SMALL, NULL))
73         {
74                 self.mins = '-8 -8 -8';
75                 self.maxs = '8 8 8';
76         }
77         else
78         {
79                 self.mins = '-16 -16 -16';
80                 self.maxs = '16 16 16';
81         }
82         self.colormod = nade_type.m_color;
83         self.move_movetype = MOVETYPE_BOUNCE;
84         self.move_touch = func_null;
85         self.scale = 1.5;
86         self.avelocity = randomvec() * 720;
87
88         if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
89                 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
90         else
91                 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
92 }
93 bool Projectile_isnade(int p)
94 {
95         return Nade_FromProjectile(p) != NADE_TYPE_Null;
96 }
97 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
98 {
99         float bonusNades    = STAT(NADE_BONUS);
100         float bonusProgress = STAT(NADE_BONUS_SCORE);
101         float bonusType     = STAT(NADE_BONUS_TYPE);
102         Nade def = Nades_from(bonusType);
103         vector nadeColor    = def.m_color;
104         string nadeIcon     = def.m_icon;
105
106         vector iconPos, textPos;
107
108         if(autocvar_hud_panel_ammo_iconalign)
109         {
110                 iconPos = myPos + eX * 2 * mySize.y;
111                 textPos = myPos;
112         }
113         else
114         {
115                 iconPos = myPos;
116                 textPos = myPos + eX * mySize.y;
117         }
118
119         if(bonusNades > 0 || bonusProgress > 0)
120         {
121                 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
122
123                 if(autocvar_hud_panel_ammo_text)
124                         drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
125
126                 if(draw_expanding)
127                         drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
128
129                 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
130         }
131 }
132 #endif
133
134 #ifdef SVQC
135
136 #include <common/gamemodes/all.qh>
137 #include <common/monsters/spawn.qh>
138 #include <common/monsters/sv_monsters.qh>
139 #include <server/g_subs.qh>
140
141 REGISTER_MUTATOR(nades, cvar("g_nades"));
142
143 .float nade_time_primed;
144
145 .entity nade_spawnloc;
146
147 void nade_timer_think()
148 {SELFPARAM();
149         self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
150         self.nextthink = time;
151         if(!self.owner || wasfreed(self.owner))
152                 remove(self);
153 }
154
155 void nade_burn_spawn(entity _nade)
156 {
157         CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
158 }
159
160 void nade_spawn(entity _nade)
161 {
162         entity timer = new(nade_timer);
163         setmodel(timer, MDL_NADE_TIMER);
164         setattachment(timer, _nade, "");
165         timer.colormap = _nade.colormap;
166         timer.glowmod = _nade.glowmod;
167         timer.think = nade_timer_think;
168         timer.nextthink = time;
169         timer.wait = _nade.wait;
170         timer.owner = _nade;
171         timer.skin = 10;
172
173         _nade.effects |= EF_LOWPRECISION;
174
175         CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
176 }
177
178 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
179 {SELFPARAM();
180         entity e;
181         float d;
182         vector p;
183
184         if ( damage < 0 )
185                 return;
186
187         RandomSelection_Init();
188         for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
189                 if(e.takedamage == DAMAGE_AIM)
190                 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
191                 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
192                 if(!STAT(FROZEN, e))
193                 {
194                         p = e.origin;
195                         p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
196                         p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
197                         p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
198                         d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
199                         if(d < dist)
200                         {
201                                 e.fireball_impactvec = p;
202                                 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
203                         }
204                 }
205         if(RandomSelection_chosen_ent)
206         {
207                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
208                 d = damage + (edgedamage - damage) * (d / dist);
209                 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
210                 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
211                 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
212         }
213 }
214
215
216 void napalm_ball_think()
217 {SELFPARAM();
218         if(round_handler_IsActive())
219         if(!round_handler_IsRoundStarted())
220         {
221                 remove(self);
222                 return;
223         }
224
225         if(time > self.pushltime)
226         {
227                 remove(self);
228                 return;
229         }
230
231         vector midpoint = ((self.absmin + self.absmax) * 0.5);
232         if(pointcontents(midpoint) == CONTENT_WATER)
233         {
234                 self.velocity = self.velocity * 0.5;
235
236                 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
237                         { self.velocity_z = 200; }
238         }
239
240         self.angles = vectoangles(self.velocity);
241
242         napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
243                                   autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
244
245         self.nextthink = time + 0.1;
246 }
247
248
249 void nade_napalm_ball()
250 {SELFPARAM();
251         entity proj;
252         vector kick;
253
254         spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
255
256         proj = new(grenade);
257         proj.owner = self.owner;
258         proj.realowner = self.realowner;
259         proj.team = self.owner.team;
260         proj.bot_dodge = true;
261         proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
262         proj.movetype = MOVETYPE_BOUNCE;
263         proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
264         PROJECTILE_MAKETRIGGER(proj);
265         setmodel(proj, MDL_Null);
266         proj.scale = 1;//0.5;
267         setsize(proj, '-4 -4 -4', '4 4 4');
268         setorigin(proj, self.origin);
269         proj.think = napalm_ball_think;
270         proj.nextthink = time;
271         proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
272         proj.effects = EF_LOWPRECISION | EF_FLAME;
273
274         kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
275         kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
276         kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
277         proj.velocity = kick;
278
279         proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
280
281         proj.angles = vectoangles(proj.velocity);
282         proj.flags = FL_PROJECTILE;
283         proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
284
285         //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
286 }
287
288
289 void napalm_fountain_think()
290 {SELFPARAM();
291
292         if(round_handler_IsActive())
293         if(!round_handler_IsRoundStarted())
294         {
295                 remove(self);
296                 return;
297         }
298
299         if(time >= self.ltime)
300         {
301                 remove(self);
302                 return;
303         }
304
305         vector midpoint = ((self.absmin + self.absmax) * 0.5);
306         if(pointcontents(midpoint) == CONTENT_WATER)
307         {
308                 self.velocity = self.velocity * 0.5;
309
310                 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
311                         { self.velocity_z = 200; }
312
313                 UpdateCSQCProjectile(self);
314         }
315
316         napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
317                 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
318
319         self.nextthink = time + 0.1;
320         if(time >= self.nade_special_time)
321         {
322                 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
323                 nade_napalm_ball();
324         }
325 }
326
327 void nade_napalm_boom()
328 {SELFPARAM();
329         entity fountain;
330         int c;
331         for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
332                 nade_napalm_ball();
333
334
335         fountain = spawn();
336         fountain.owner = self.owner;
337         fountain.realowner = self.realowner;
338         fountain.origin = self.origin;
339         setorigin(fountain, fountain.origin);
340         fountain.think = napalm_fountain_think;
341         fountain.nextthink = time;
342         fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
343         fountain.pushltime = fountain.ltime;
344         fountain.team = self.team;
345         fountain.movetype = MOVETYPE_TOSS;
346         fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
347         fountain.bot_dodge = true;
348         fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
349         fountain.nade_special_time = time;
350         setsize(fountain, '-16 -16 -16', '16 16 16');
351         CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
352 }
353
354 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
355 {
356         frost_target.frozen_by = freezefield.realowner;
357         Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
358         Freeze(frost_target, 1/freeze_time, 3, false);
359
360         Drop_Special_Items(frost_target);
361 }
362
363 void nade_ice_think()
364 {SELFPARAM();
365
366         if(round_handler_IsActive())
367         if(!round_handler_IsRoundStarted())
368         {
369                 remove(self);
370                 return;
371         }
372
373         if(time >= self.ltime)
374         {
375                 if ( autocvar_g_nades_ice_explode )
376                 {
377                         entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
378                         Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
379                         sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
380
381                         RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
382                                 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
383                         Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
384                                 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
385                 }
386                 remove(self);
387                 return;
388         }
389
390
391         self.nextthink = time+0.1;
392
393         // gaussian
394         float randomr;
395         randomr = random();
396         randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
397         float randomw;
398         randomw = random()*M_PI*2;
399         vector randomp;
400         randomp.x = randomr*cos(randomw);
401         randomp.y = randomr*sin(randomw);
402         randomp.z = 1;
403         Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
404
405         if(time >= self.nade_special_time)
406         {
407                 self.nade_special_time = time+0.7;
408
409                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
410                 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
411         }
412
413
414         float current_freeze_time = self.ltime - time - 0.1;
415
416         entity e;
417         for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
418         if(e != self)
419         if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
420         if(e.takedamage && !IS_DEAD(e))
421         if(e.health > 0)
422         if(!e.revival_time || ((time - e.revival_time) >= 1.5))
423         if(!STAT(FROZEN, e))
424         if(current_freeze_time > 0)
425                 nade_ice_freeze(self, e, current_freeze_time);
426 }
427
428 void nade_ice_boom()
429 {SELFPARAM();
430         entity fountain;
431         fountain = spawn();
432         fountain.owner = self.owner;
433         fountain.realowner = self.realowner;
434         fountain.origin = self.origin;
435         setorigin(fountain, fountain.origin);
436         fountain.think = nade_ice_think;
437         fountain.nextthink = time;
438         fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
439         fountain.pushltime = fountain.wait = fountain.ltime;
440         fountain.team = self.team;
441         fountain.movetype = MOVETYPE_TOSS;
442         fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
443         fountain.bot_dodge = false;
444         setsize(fountain, '-16 -16 -16', '16 16 16');
445         fountain.nade_special_time = time+0.3;
446         fountain.angles = self.angles;
447
448         if ( autocvar_g_nades_ice_explode )
449         {
450                 setmodel(fountain, MDL_PROJECTILE_GRENADE);
451                 entity timer = new(nade_timer);
452                 setmodel(timer, MDL_NADE_TIMER);
453                 setattachment(timer, fountain, "");
454                 timer.colormap = self.colormap;
455                 timer.glowmod = self.glowmod;
456                 timer.think = nade_timer_think;
457                 timer.nextthink = time;
458                 timer.wait = fountain.ltime;
459                 timer.owner = fountain;
460                 timer.skin = 10;
461         }
462         else
463                 setmodel(fountain, MDL_Null);
464 }
465
466 void nade_translocate_boom()
467 {SELFPARAM();
468         if(self.realowner.vehicle)
469                 return;
470
471         vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
472         tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
473         locout = trace_endpos;
474
475         makevectors(self.realowner.angles);
476
477         MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
478
479         TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
480 }
481
482 void nade_spawn_boom()
483 {SELFPARAM();
484         entity spawnloc = spawn();
485         setorigin(spawnloc, self.origin);
486         setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
487         spawnloc.movetype = MOVETYPE_NONE;
488         spawnloc.solid = SOLID_NOT;
489         spawnloc.drawonlytoclient = self.realowner;
490         spawnloc.effects = EF_STARDUST;
491         spawnloc.cnt = autocvar_g_nades_spawn_count;
492
493         if(self.realowner.nade_spawnloc)
494         {
495                 remove(self.realowner.nade_spawnloc);
496                 self.realowner.nade_spawnloc = world;
497         }
498
499         self.realowner.nade_spawnloc = spawnloc;
500 }
501
502 void nade_heal_think()
503 {SELFPARAM();
504         if(time >= self.ltime)
505         {
506                 remove(self);
507                 return;
508         }
509
510         self.nextthink = time;
511
512         if(time >= self.nade_special_time)
513         {
514                 self.nade_special_time = time+0.25;
515                 self.nade_show_particles = 1;
516         }
517         else
518                 self.nade_show_particles = 0;
519 }
520
521 void nade_heal_touch()
522 {SELFPARAM();
523         float maxhealth;
524         float health_factor;
525         if(IS_PLAYER(other) || IS_MONSTER(other))
526         if(!IS_DEAD(other))
527         if(!STAT(FROZEN, other))
528         {
529                 health_factor = autocvar_g_nades_heal_rate*frametime/2;
530                 if ( other != self.realowner )
531                 {
532                         if ( SAME_TEAM(other,self) )
533                                 health_factor *= autocvar_g_nades_heal_friend;
534                         else
535                                 health_factor *= autocvar_g_nades_heal_foe;
536                 }
537                 if ( health_factor > 0 )
538                 {
539                         maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
540                         if ( other.health < maxhealth )
541                         {
542                                 if ( self.nade_show_particles )
543                                         Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
544                                 other.health = min(other.health+health_factor, maxhealth);
545                         }
546                         other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
547                 }
548                 else if ( health_factor < 0 )
549                 {
550                         Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
551                 }
552
553         }
554
555         if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
556         {
557                 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
558                 show_red.stat_healing_orb = time+0.1;
559                 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
560         }
561 }
562
563 void nade_heal_boom()
564 {SELFPARAM();
565         entity healer;
566         healer = spawn();
567         healer.owner = self.owner;
568         healer.realowner = self.realowner;
569         setorigin(healer, self.origin);
570         healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
571         healer.ltime = time + healer.healer_lifetime;
572         healer.team = self.realowner.team;
573         healer.bot_dodge = false;
574         healer.solid = SOLID_TRIGGER;
575         healer.touch = nade_heal_touch;
576
577         setmodel(healer, MDL_NADE_HEAL);
578         healer.healer_radius = autocvar_g_nades_nade_radius;
579         vector size = '1 1 1' * healer.healer_radius / 2;
580         setsize(healer,-size,size);
581
582         Net_LinkEntity(healer, true, 0, healer_send);
583
584         healer.think = nade_heal_think;
585         healer.nextthink = time;
586         healer.SendFlags |= 1;
587 }
588
589 void nade_monster_boom()
590 {SELFPARAM();
591         entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
592
593         if(autocvar_g_nades_pokenade_monster_lifetime > 0)
594                 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
595         e.monster_skill = MONSTER_SKILL_INSANE;
596 }
597
598 void nade_boom()
599 {SELFPARAM();
600         entity expef = NULL;
601         bool nade_blast = true;
602
603         switch ( Nades_from(self.nade_type) )
604         {
605                 case NADE_TYPE_NAPALM:
606                         nade_blast = autocvar_g_nades_napalm_blast;
607                         expef = EFFECT_EXPLOSION_MEDIUM;
608                         break;
609                 case NADE_TYPE_ICE:
610                         nade_blast = false;
611                         expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
612                         break;
613                 case NADE_TYPE_TRANSLOCATE:
614                         nade_blast = false;
615                         break;
616                 case NADE_TYPE_MONSTER:
617                 case NADE_TYPE_SPAWN:
618                         nade_blast = false;
619                         switch(self.realowner.team)
620                         {
621                                 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
622                                 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
623                                 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
624                                 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
625                                 default: expef = EFFECT_SPAWN_NEUTRAL; break;
626                         }
627                         break;
628                 case NADE_TYPE_HEAL:
629                         nade_blast = false;
630                         expef = EFFECT_SPAWN_RED;
631                         break;
632
633                 default:
634                 case NADE_TYPE_NORMAL:
635                         expef = EFFECT_NADE_EXPLODE(self.realowner.team);
636                         break;
637         }
638
639         if(expef)
640                 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
641
642         sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
643         sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
644
645         self.event_damage = func_null; // prevent somehow calling damage in the next call
646
647         if(nade_blast)
648         {
649                 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
650                                  autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
651                 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);
652         }
653
654         if(self.takedamage)
655         switch ( Nades_from(self.nade_type) )
656         {
657                 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
658                 case NADE_TYPE_ICE: nade_ice_boom(); break;
659                 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
660                 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
661                 case NADE_TYPE_HEAL: nade_heal_boom(); break;
662                 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
663         }
664
665         FOREACH_ENTITY_ENT(aiment, self,
666         {
667                 if(it.classname == "grapplinghook")
668                         RemoveGrapplingHook(it.realowner);
669         });
670
671         remove(self);
672 }
673
674 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype);
675 void nade_pickup(entity this, entity thenade)
676 {
677         spawn_held_nade(this, thenade.realowner, autocvar_g_nades_pickup_time, thenade.nade_type, thenade.pokenade_type);
678
679         // set refire so player can't even
680         this.nade_refire = time + autocvar_g_nades_nade_refire;
681         this.nade_timer = 0;
682
683         if(this.nade)
684                 this.nade.nade_time_primed = thenade.nade_time_primed;
685 }
686
687 bool CanThrowNade(entity this);
688 void nade_touch()
689 {SELFPARAM();
690         if(other)
691                 UpdateCSQCProjectile(self);
692
693         if(other == self.realowner)
694                 return; // no self impacts
695
696         if(autocvar_g_nades_pickup)
697         if(time >= self.spawnshieldtime)
698         if(!other.nade && self.health == self.max_health) // no boosted shot pickups, thank you very much
699         if(CanThrowNade(other)) // prevent some obvious things, like dead players
700         if(IS_REAL_CLIENT(other)) // above checks for IS_PLAYER, don't need to do it here
701         {
702                 nade_pickup(other, self);
703                 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
704                 remove(self);
705                 return;
706         }
707         /*float is_weapclip = 0;
708         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
709         if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
710         if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
711                 is_weapclip = 1;*/
712         if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
713         {
714                 FOREACH_ENTITY_ENT(aiment, self,
715                 {
716                         if(it.classname == "grapplinghook")
717                                 RemoveGrapplingHook(it.realowner);
718                 });
719                 remove(self);
720                 return;
721         }
722
723         PROJECTILE_TOUCH;
724
725         //setsize(self, '-2 -2 -2', '2 2 2');
726         //UpdateCSQCProjectile(self);
727         if(self.health == self.max_health)
728         {
729                 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
730                 return;
731         }
732
733         self.enemy = other;
734         nade_boom();
735 }
736
737 void nade_beep()
738 {SELFPARAM();
739         sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
740         self.think = nade_boom;
741         self.nextthink = max(self.wait, time);
742 }
743
744 void nade_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
745 {
746         if(ITEM_DAMAGE_NEEDKILL(deathtype))
747         {
748                 this.takedamage = DAMAGE_NO;
749                 WITH(entity, self, this, nade_boom());
750                 return;
751         }
752
753         if(this.nade_type == NADE_TYPE_TRANSLOCATE.m_id || this.nade_type == NADE_TYPE_SPAWN.m_id)
754                 return;
755
756         if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
757         else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
758         {
759                 force *= 1.5;
760                 damage = 0;
761         }
762         else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
763         {
764                 force *= 0.5; // too much
765                 damage = 0;
766         }
767         else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
768         {
769                 force *= 6;
770                 damage = this.max_health * 0.55;
771         }
772         else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
773                 damage = this.max_health * 0.1;
774         else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
775         {
776                 if(deathtype & HITTYPE_SECONDARY)
777                 {
778                         damage = this.max_health * 0.1;
779                         force *= 10;
780                 }
781                 else
782                         damage = this.max_health * 1.15;
783         }
784
785         this.velocity += force;
786         UpdateCSQCProjectile(this);
787
788         if(damage <= 0 || ((IS_ONGROUND(this)) && IS_PLAYER(attacker)))
789                 return;
790
791         if(this.health == this.max_health)
792         {
793                 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
794                 this.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
795                 this.think = nade_beep;
796         }
797
798         this.health -= damage;
799
800         if ( this.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
801                 this.realowner = attacker;
802
803         if(this.health <= 0)
804                 WITH(entity, self, this, W_PrepareExplosionByDamage(attacker, nade_boom));
805         else
806                 nade_burn_spawn(this);
807 }
808
809 void toss_nade(entity e, bool set_owner, vector _velocity, float _time)
810 {SELFPARAM();
811         if(e.nade == world)
812                 return;
813
814         entity _nade = e.nade;
815         e.nade = world;
816
817         remove(e.fake_nade);
818         e.fake_nade = world;
819
820         makevectors(e.v_angle);
821
822         W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
823
824         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
825
826         vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
827                                   + (v_right * autocvar_g_nades_throw_offset.y)
828                                   + (v_up * autocvar_g_nades_throw_offset.z);
829         if(autocvar_g_nades_throw_offset == '0 0 0')
830                 offset = '0 0 0';
831
832         setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
833         //setmodel(_nade, MDL_PROJECTILE_NADE);
834         //setattachment(_nade, world, "");
835         PROJECTILE_MAKETRIGGER(_nade);
836         if(STAT(NADES_SMALL, e))
837                 setsize(_nade, '-8 -8 -8', '8 8 8');
838         else
839                 setsize(_nade, '-16 -16 -16', '16 16 16');
840         _nade.movetype = MOVETYPE_BOUNCE;
841
842         tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
843         if (trace_startsolid)
844                 setorigin(_nade, e.origin);
845
846         if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
847                 _nade.velocity = '0 0 100';
848         else if(autocvar_g_nades_nade_newton_style == 1)
849                 _nade.velocity = e.velocity + _velocity;
850         else if(autocvar_g_nades_nade_newton_style == 2)
851                 _nade.velocity = _velocity;
852         else
853                 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
854
855         if(set_owner)
856                 _nade.realowner = e;
857
858         _nade.touch = nade_touch;
859         _nade.spawnshieldtime = time + 0.1; // prevent instantly picking up again
860         _nade.health = autocvar_g_nades_nade_health;
861         _nade.max_health = _nade.health;
862         _nade.takedamage = DAMAGE_AIM;
863         _nade.event_damage = nade_damage;
864         _nade.customizeentityforclient = func_null;
865         _nade.exteriormodeltoclient = world;
866         _nade.traileffectnum = 0;
867         _nade.teleportable = true;
868         _nade.pushable = true;
869         _nade.gravity = 1;
870         _nade.missile_flags = MIF_SPLASH | MIF_ARC;
871         _nade.damagedbycontents = true;
872         _nade.angles = vectoangles(_nade.velocity);
873         _nade.flags = FL_PROJECTILE;
874         _nade.projectiledeathtype = DEATH_NADE.m_id;
875         _nade.toss_time = time;
876         _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
877
878         if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
879                 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
880         else
881                 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
882
883         nade_spawn(_nade);
884
885         if(_time)
886         {
887                 _nade.think = nade_boom;
888                 _nade.nextthink = _time;
889         }
890
891         e.nade_refire = time + autocvar_g_nades_nade_refire;
892         e.nade_timer = 0;
893 }
894
895 void nades_GiveBonus(entity player, float score)
896 {
897         if (autocvar_g_nades)
898         if (autocvar_g_nades_bonus)
899         if (IS_REAL_CLIENT(player))
900         if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
901         if (STAT(FROZEN, player) == 0)
902         if (!IS_DEAD(player))
903         {
904                 if ( player.bonus_nade_score < 1 )
905                         player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
906
907                 if ( player.bonus_nade_score >= 1 )
908                 {
909                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
910                         play2(player, SND(KH_ALARM));
911                         player.bonus_nades++;
912                         player.bonus_nade_score -= 1;
913                 }
914         }
915 }
916
917 /** Remove all bonus nades from a player */
918 void nades_RemoveBonus(entity player)
919 {
920         player.bonus_nades = player.bonus_nade_score = 0;
921 }
922
923 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
924 {
925         nades_RemoveBonus(self);
926 }
927
928 float nade_customize()
929 {SELFPARAM();
930         //if(IS_SPEC(other)) { return false; }
931         if(other == self.exteriormodeltoclient || (IS_SPEC(other) && other.enemy == self.exteriormodeltoclient))
932         {
933                 // somewhat hide the model, but keep the glow
934                 //self.effects = 0;
935                 if(self.traileffectnum)
936                         self.traileffectnum = 0;
937                 self.alpha = -1;
938         }
939         else
940         {
941                 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
942                 if(!self.traileffectnum)
943                         self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
944                 self.alpha = 1;
945         }
946
947         return true;
948 }
949
950 void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, string pntype)
951 {
952         entity n = new(nade), fn = new(fake_nade);
953
954         n.nade_type = bound(1, ntype, Nades_COUNT);
955         n.pokenade_type = pntype;
956
957         setmodel(n, MDL_PROJECTILE_NADE);
958         //setattachment(n, player, "bip01 l hand");
959         n.exteriormodeltoclient = player;
960         n.customizeentityforclient = nade_customize;
961         n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], player.team).eent_eff_name);
962         n.colormod = Nades_from(n.nade_type).m_color;
963         n.realowner = nowner;
964         n.colormap = player.colormap;
965         n.glowmod = player.glowmod;
966         n.wait = time + max(0, ntime);
967         n.nade_time_primed = time;
968         n.think = nade_beep;
969         n.nextthink = max(n.wait - 3, time);
970         n.projectiledeathtype = DEATH_NADE.m_id;
971
972         setmodel(fn, MDL_NADE_VIEW);
973         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
974         setattachment(fn, player.(weaponentity), "");
975         fn.realowner = fn.owner = player;
976         fn.colormod = Nades_from(n.nade_type).m_color;
977         fn.colormap = player.colormap;
978         fn.glowmod = player.glowmod;
979         fn.think = SUB_Remove_self;
980         fn.nextthink = n.wait;
981
982         player.nade = n;
983         player.fake_nade = fn;
984 }
985
986 void nade_prime()
987 {SELFPARAM();
988         if(autocvar_g_nades_bonus_only)
989         if(!self.bonus_nades)
990                 return; // only allow bonus nades
991
992         if(self.nade)
993                 remove(self.nade);
994
995         if(self.fake_nade)
996                 remove(self.fake_nade);
997
998         int ntype;
999         string pntype = self.pokenade_type;
1000
1001         if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
1002                 ntype = self.nade_type;
1003         else if (self.bonus_nades >= 1)
1004         {
1005                 ntype = self.nade_type;
1006                 pntype = self.pokenade_type;
1007                 self.bonus_nades -= 1;
1008         }
1009         else
1010         {
1011                 ntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
1012                 pntype = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
1013         }
1014
1015         spawn_held_nade(self, self, autocvar_g_nades_nade_lifetime, ntype, pntype);
1016 }
1017
1018 bool CanThrowNade(entity this)
1019 {
1020         if(this.vehicle)
1021                 return false;
1022
1023         if(gameover)
1024                 return false;
1025
1026         if(IS_DEAD(this))
1027                 return false;
1028
1029         if (!autocvar_g_nades)
1030                 return false; // allow turning them off mid match
1031
1032         if(forbidWeaponUse(this))
1033                 return false;
1034
1035         if (!IS_PLAYER(this))
1036                 return false;
1037
1038         return true;
1039 }
1040
1041 .bool nade_altbutton;
1042
1043 void nades_CheckThrow()
1044 {SELFPARAM();
1045         if(!CanThrowNade(self))
1046                 return;
1047
1048         entity held_nade = self.nade;
1049         if (!held_nade)
1050         {
1051                 self.nade_altbutton = true;
1052                 if(time > self.nade_refire)
1053                 {
1054                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1055                         nade_prime();
1056                         self.nade_refire = time + autocvar_g_nades_nade_refire;
1057                 }
1058         }
1059         else
1060         {
1061                 self.nade_altbutton = false;
1062                 if (time >= held_nade.nade_time_primed + 1) {
1063                         makevectors(self.v_angle);
1064                         float _force = time - held_nade.nade_time_primed;
1065                         _force /= autocvar_g_nades_nade_lifetime;
1066                         _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1067                         toss_nade(self, true, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
1068                 }
1069         }
1070 }
1071
1072 void nades_Clear(entity player)
1073 {
1074         if(player.nade)
1075                 remove(player.nade);
1076         if(player.fake_nade)
1077                 remove(player.fake_nade);
1078
1079         player.nade = player.fake_nade = world;
1080         player.nade_timer = 0;
1081 }
1082
1083 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1084 {
1085         if(vh_player.nade)
1086                 toss_nade(vh_player, true, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1087
1088         return false;
1089 }
1090
1091 CLASS(NadeOffhand, OffhandWeapon)
1092     METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1093     {
1094         entity held_nade = player.nade;
1095                 if (held_nade)
1096                 {
1097                         player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1098                         // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1099                         makevectors(player.angles);
1100                         held_nade.velocity = player.velocity;
1101                         setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1102                         held_nade.angles_y = player.angles.y;
1103
1104                         if (time + 0.1 >= held_nade.wait)
1105                                 toss_nade(player, false, '0 0 0', time + 0.05);
1106                 }
1107
1108         if (!CanThrowNade(player)) return;
1109         if (!(time > player.nade_refire)) return;
1110                 if (key_pressed) {
1111                         if (!held_nade) {
1112                                 nade_prime();
1113                                 held_nade = player.nade;
1114                         }
1115                 } else if (time >= held_nade.nade_time_primed + 1) {
1116                         if (held_nade) {
1117                                 makevectors(player.v_angle);
1118                                 float _force = time - held_nade.nade_time_primed;
1119                                 _force /= autocvar_g_nades_nade_lifetime;
1120                                 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1121                                 toss_nade(player, false, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
1122                         }
1123                 }
1124     }
1125 ENDCLASS(NadeOffhand)
1126 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1127
1128 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1129 {
1130         if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1131                 nades_CheckThrow();
1132                 return true;
1133         }
1134         return false;
1135 }
1136
1137 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1138 {SELFPARAM();
1139         if (!IS_PLAYER(self)) { return false; }
1140
1141         if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1142
1143         if(IS_PLAYER(self))
1144         {
1145                 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1146                 {
1147                         entity key;
1148                         float key_count = 0;
1149                         FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1150
1151                         float time_score;
1152                         if(self.flagcarried || self.ballcarried) // this player is important
1153                                 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1154                         else
1155                                 time_score = autocvar_g_nades_bonus_score_time;
1156
1157                         if(key_count)
1158                                 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1159
1160                         if(autocvar_g_nades_bonus_client_select)
1161                         {
1162                                 self.nade_type = self.cvar_cl_nade_type;
1163                                 self.pokenade_type = self.cvar_cl_pokenade_type;
1164                         }
1165                         else
1166                         {
1167                                 self.nade_type = autocvar_g_nades_bonus_type;
1168                                 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1169                         }
1170
1171                         self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1172
1173                         if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1174                                 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1175                 }
1176                 else
1177                 {
1178                         self.bonus_nades = self.bonus_nade_score = 0;
1179                 }
1180         }
1181
1182         float n = 0;
1183         entity o = world;
1184         if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1185                 n = -1;
1186         else
1187         {
1188                 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1189                 n = 0;
1190                 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
1191                         if(!IS_DEAD(it))
1192                         if(STAT(FROZEN, it) == 0)
1193                         if(SAME_TEAM(it, self))
1194                         if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
1195                         {
1196                                 if(!o)
1197                                         o = it;
1198                                 if(STAT(FROZEN, self) == 1)
1199                                         it.reviving = true;
1200                                 ++n;
1201                         }
1202                 ));
1203         }
1204
1205         if(n && STAT(FROZEN, self) == 3) // OK, there is at least one teammate reviving us
1206         {
1207                 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1208                 self.health = max(1, self.revive_progress * start_health);
1209
1210                 if(self.revive_progress >= 1)
1211                 {
1212                         Unfreeze(self);
1213
1214                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1215                         Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1216                 }
1217
1218                 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1219                         other.revive_progress = self.revive_progress;
1220                         other.reviving = false;
1221                 ));
1222         }
1223
1224         return false;
1225 }
1226
1227 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1228 {SELFPARAM();
1229         if(autocvar_g_nades_spawn)
1230                 self.nade_refire = time + autocvar_g_spawnshieldtime;
1231         else
1232                 self.nade_refire  = time + autocvar_g_nades_nade_refire;
1233
1234         if(autocvar_g_nades_bonus_client_select)
1235                 self.nade_type = self.cvar_cl_nade_type;
1236
1237         self.nade_timer = 0;
1238
1239         if (!self.offhand) self.offhand = OFFHAND_NADE;
1240
1241         if(self.nade_spawnloc)
1242         {
1243                 setorigin(self, self.nade_spawnloc.origin);
1244                 self.nade_spawnloc.cnt -= 1;
1245
1246                 if(self.nade_spawnloc.cnt <= 0)
1247                 {
1248                         remove(self.nade_spawnloc);
1249                         self.nade_spawnloc = world;
1250                 }
1251         }
1252
1253         return false;
1254 }
1255
1256 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1257 {
1258         if(frag_target.nade)
1259         if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1260                 toss_nade(frag_target, true, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1261
1262         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);
1263
1264         if(IS_PLAYER(frag_attacker))
1265         {
1266                 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1267                         nades_RemoveBonus(frag_attacker);
1268                 else if(frag_target.flagcarried)
1269                         nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1270                 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1271                 {
1272                         #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1273                                 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1274                         switch(frag_attacker.killcount)
1275                         {
1276                                 KILL_SPREE_LIST
1277                                 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1278                         }
1279                         #undef SPREE_ITEM
1280                 }
1281                 else
1282                         nades_GiveBonus(frag_attacker, killcount_bonus);
1283         }
1284
1285         nades_RemoveBonus(frag_target);
1286
1287         return false;
1288 }
1289
1290 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1291 {
1292         if(STAT(FROZEN, frag_target))
1293         if(autocvar_g_freezetag_revive_nade)
1294         if(frag_attacker == frag_target)
1295         if(frag_deathtype == DEATH_NADE.m_id)
1296         if(time - frag_inflictor.toss_time <= 0.1)
1297         {
1298                 Unfreeze(frag_target);
1299                 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1300                 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1301                 frag_damage = 0;
1302                 frag_force = '0 0 0';
1303                 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1304                 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1305         }
1306
1307         return false;
1308 }
1309
1310 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1311 {
1312         if(IS_PLAYER(frag_attacker))
1313         if(DIFF_TEAM(frag_attacker, frag_target))
1314         if(!(frag_target.spawnflags & MONSTERFLAG_SPAWNED))
1315                 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1316
1317         return false;
1318 }
1319
1320 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1321 {
1322         if(frag_target.nade)
1323                 toss_nade(frag_target, true, '0 0 0', time + 0.05);
1324
1325         return false;
1326 }
1327
1328 bool nades_RemovePlayer()
1329 {SELFPARAM();
1330         nades_Clear(self);
1331         nades_RemoveBonus(self);
1332         return false;
1333 }
1334
1335 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1336 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1337 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1338
1339 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1340 {SELFPARAM();
1341         self.nade_timer = other.nade_timer;
1342         self.nade_type = other.nade_type;
1343         self.pokenade_type = other.pokenade_type;
1344         self.bonus_nades = other.bonus_nades;
1345         self.bonus_nade_score = other.bonus_nade_score;
1346         self.stat_healing_orb = other.stat_healing_orb;
1347         self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1348         return false;
1349 }
1350
1351 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1352 {
1353         GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1354         GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1355
1356         return false;
1357 }
1358
1359 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1360 {
1361         ret_string = strcat(ret_string, ":Nades");
1362         return false;
1363 }
1364
1365 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1366 {
1367         ret_string = strcat(ret_string, ", Nades");
1368         return false;
1369 }
1370
1371 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1372 {
1373         ret_string = strcat(ret_string, "\n\n^3nades^8 are enabled, press 'g' to use them\n");
1374         return false;
1375 }
1376
1377 #endif
1378 #endif