+void nade_ammo_touch(entity this, entity toucher)
+{
+ float maxammo = 999;
+ float ammo_factor;
+ float amshells = GetResource(toucher, RES_SHELLS);
+ float ambullets = GetResource(toucher, RES_BULLETS);
+ float amrockets = GetResource(toucher, RES_ROCKETS);
+ float amcells = GetResource(toucher, RES_CELLS);
+ float amplasma = GetResource(toucher, RES_PLASMA);
+ if(IS_PLAYER(toucher) || IS_MONSTER(toucher))
+ if(!IS_DEAD(toucher))
+ if(!STAT(FROZEN, toucher))
+ {
+ ammo_factor = autocvar_g_nades_ammo_rate*frametime/2;
+ if ( toucher != this.realowner )
+ ammo_factor *= (SAME_TEAM(toucher, this)) ? autocvar_g_nades_ammo_friend : autocvar_g_nades_ammo_foe;
+
+#define CHECK_AMMO_RESOURCE_LIMIT(amresource, res_resource) \
+ if (amresource < maxammo) \
+ GiveResourceWithLimit(toucher, res_resource, ammo_factor, maxammo);
+
+#define DROP_AMMO_RESOURCE(amresource, res_resource) \
+ if (amresource > 0) \
+ SetResource(toucher, res_resource, amresource + ammo_factor);
+
+ if ( ammo_factor > 0 )
+ {
+ CHECK_AMMO_RESOURCE_LIMIT(amshells, RES_SHELLS);
+ CHECK_AMMO_RESOURCE_LIMIT(ambullets, RES_BULLETS);
+ CHECK_AMMO_RESOURCE_LIMIT(amrockets, RES_ROCKETS);
+ CHECK_AMMO_RESOURCE_LIMIT(amcells, RES_CELLS);
+ CHECK_AMMO_RESOURCE_LIMIT(amplasma, RES_PLASMA);
+
+ if (this.nade_show_particles)
+ Send_Effect(EFFECT_HEALING, toucher.origin, '0 0 0', 1);
+ }
+ else if ( ammo_factor < 0 )
+ {
+ //Foe drops ammo points
+ DROP_AMMO_RESOURCE(amshells, RES_SHELLS);
+ DROP_AMMO_RESOURCE(ambullets, RES_BULLETS);
+ DROP_AMMO_RESOURCE(amrockets, RES_ROCKETS);
+ DROP_AMMO_RESOURCE(amcells, RES_CELLS);
+ DROP_AMMO_RESOURCE(amplasma, RES_PLASMA);
+
+ return;
+ }
+ }
+#undef CHECK_AMMO_RESOURCE_LIMIT
+#undef DROP_AMMO_RESOURCE
+
+ if ( IS_REAL_CLIENT(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
+ {
+ entity show_tint = (IS_VEHICLE(toucher) && toucher.owner) ? toucher.owner : toucher;
+ show_tint.nade_ammo_time = time + 0.1;
+ }
+}
+
+void nade_ammo_boom(entity this)
+{
+ entity orb = nades_spawn_orb(this.owner, this.realowner, this.origin, autocvar_g_nades_ammo_time, autocvar_g_nades_nade_radius);
+
+ settouch(orb, nade_ammo_touch);
+ orb.colormod = '0.66 0.33 0';
+}
+
+void nade_darkness_think(entity this)
+{
+ if(round_handler_IsActive())
+ if(!round_handler_IsRoundStarted())
+ {
+ delete(this);
+ return;
+ }
+
+ if(time >= this.ltime)
+ {
+ if ( autocvar_g_nades_darkness_explode )
+ {
+ entity expef = EFFECT_NADE_EXPLODE(this.realowner.team);
+ Send_Effect(expef, this.origin + '0 0 1', '0 0 0', 1);
+ sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+
+ normal_nade_boom(this);
+ }
+ else
+ Send_Effect(EFFECT_SPAWN_PURPLE, this.origin + '0 0 1', '0 0 0', 1);
+
+ delete(this);
+ return;
+ }
+
+ this.nextthink = time + 0.1;
+
+ // gaussian
+ float randomr;
+ randomr = random();
+ randomr = exp(-5 * randomr * randomr) * autocvar_g_nades_nade_radius;
+ float randomw;
+ randomw = random() * M_PI * 2;
+ vector randomp;
+ randomp.x = randomr * cos(randomw);
+ randomp.y = randomr * sin(randomw);
+ randomp.z = 1;
+ Send_Effect(EFFECT_DARKFIELD, this.origin + randomp, '0 0 0', 1);
+
+ if(time >= this.nade_special_time)
+ {
+ this.nade_special_time = time + 0.7;
+ Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1);
+ }
+
+
+ float current_dark_time = this.ltime - time - 0.1;
+
+ FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage
+ && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it),
+ {
+ switch (autocvar_g_nades_darkness_teamcheck)
+ {
+ case 0: break; // affect everyone
+ default:
+ case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates
+ // fall through (check case 1 condition too)
+ case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade
+ }
+ STAT(NADE_DARKNESS_TIME, it) = time + 0.1;
+ });
+}
+
+void nade_darkness_boom(entity this)
+{
+ entity fountain = new(nade_darkness_fountain);
+ fountain.owner = this.owner;
+ fountain.realowner = this.realowner;
+ fountain.origin = this.origin;
+ setorigin(fountain, fountain.origin);
+ setthink(fountain, nade_darkness_think);
+ fountain.nextthink = time;
+ fountain.ltime = time + autocvar_g_nades_darkness_time;
+ fountain.pushltime = fountain.wait = fountain.ltime;
+ fountain.team = this.team;
+ set_movetype(fountain, MOVETYPE_TOSS);
+ fountain.projectiledeathtype = DEATH_NADE.m_id;
+ fountain.bot_dodge = false;
+ setsize(fountain, '-16 -16 -16', '16 16 16');
+ fountain.nade_special_time = time + 0.3;
+ fountain.angles = this.angles;
+
+ if ( autocvar_g_nades_darkness_explode )
+ {
+ setmodel(fountain, MDL_PROJECTILE_GRENADE);
+ entity timer = new(nade_timer);
+ setmodel(timer, MDL_NADE_TIMER);
+ setattachment(timer, fountain, "");
+ timer.colormap = this.colormap;
+ timer.glowmod = this.glowmod;
+ setthink(timer, nade_timer_think);
+ timer.nextthink = time;
+ timer.wait = fountain.ltime;
+ timer.owner = fountain;
+ timer.skin = 10;
+ }
+ else
+ setmodel(fountain, MDL_Null);
+}
+