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