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