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