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