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