// code author status: most of the code by id & rest by me ;)

void(entity targ, entity inflictor, entity attacker, float damage) T_Damage;

void(entity inflictor, entity attacker, float damage, entity ignore) T_ABombDamage =
{
	local	float 	points;
	local	entity	head;
	local	vector	org;
	local	float	mercy;
	local	float	mercy2;

	// remove powerups from attacker ...
	//	if (self.super_damage_finished > time)
	//		self.effects = self.effects | EF_DIMLIGHT;

	mercy2 = 1;

/* old code...
 *
 *	if (attacker.radsuit_finished > time)
 *	{
 *		attacker.items = attacker.items - IT_SUIT;
 *		attacker.radsuit_finished = 0;
 *		attacker.rad_time = 0;
 *		nomercy = nomercy * 0.8;
 *	}
 *
 *	if (attacker.invincible_finished > time)
 *	{
 *		attacker.items = attacker.items - IT_INVULNERABILITY;
 *		attacker.invincible_finished = 0;
 *		attacker.invincible_time = 0;
 *		nomercy = nomercy * 0.8;
 *	}
 *
 *	if (attacker.invisible_finished > time)
 *	{
 *		attacker.items = attacker.items - IT_INVISIBILITY;
 *		attacker.invisible_finished = 0;
 *		attacker.invisible_time = 0;
 *		nomercy = nomercy * 1.05;
 *	}
 *
 * end of old code...
 */
	if (attacker.super_damage_finished > time)
	{
		attacker.items = attacker.items - IT_QUAD;
		attacker.super_damage_finished = 0;
		attacker.super_time = 0;
		mercy2 = mercy2 * 0.85;
	}	

// nasty thing here... (nuclear glow... how to make it bright blue?)
	if (deathmatch || coop) attacker.effects = EF_BRIGHTLIGHT;

	head = findradius(inflictor.origin, damage+40);

	while (head)
	{
		if (head != ignore)
		{
			if (head.takedamage)
			{
/*				org = head.origin + (head.mins + head.maxs)*0.5;
 *				points = 0.5*vlen (inflictor.origin - org);
 *				if (points < 0)
 *					points = 0;
 *				points = damage - points;
 */
				points = damage;
				if (head == attacker)	// this means computer enemies can use it without dying ;)
					points = attacker.health - 1;
			//		points = points * 0.5;
				if (points > 0)
				{
			//		if (CanDamage (head, inflictor)) // fusion-neutron bombs don't care about the walls...
			//		{	// don't kill oldone (might crash)
						if (head.classname == "monster_oldone")
							T_Damage (head, inflictor, attacker, 1);
						else if (head.classname == "player")
						{
							if (head.armorvalue > 0) head.armorvalue = 1; // paranoid > 0
						
							mercy = mercy2;
							if (head == attacker) mercy = mercy * mercy; //quad damage
							if (head.radsuit_finished > time)
							{
								head.items = head.items - IT_SUIT;
								head.radsuit_finished = 0;
								head.rad_time = 0;
								mercy = mercy * 1.2;
							}
							if (head.invincible_finished > time)
							{
								head.items = head.items - IT_INVULNERABILITY;
								head.invincible_finished = 0;
								head.invincible_time = 0;
								mercy = mercy * 1.2;
							}
							if (head.invisible_finished > time)
							{
								head.items = head.items - IT_INVISIBILITY;
								head.invisible_finished = 0;
								head.invisible_time = 0;
								mercy = mercy * 0.85;
							}
							if (head.super_damage_finished > time)
							{
								head.items = head.items - IT_QUAD;
								head.super_damage_finished = 0;
								head.super_time = 0;
								mercy = mercy * 0.8;
							}
							
							// maximum mercy: 1.44 ... minimum: 0.578 ...
							
							if ((points < (head.health - head.armorvalue)) && (mercy < 1))
							{
								points = points + 25; //	means that attacker dies if ((IT_QUAD || IT_INVIS) && (!IT_ARMOR && !IT_RADSUIT && !IT_PENTAGRAM))
							}
							else
							{	// paranoid coding, isn't this? ... no >=s ... what are exact values?
								if ((points > (head.health + head.armorvalue)) && (mercy >1)) points = head.health + 75 - (50 * random()) - (50 * random());
							}
							
							T_Damage (head, inflictor, attacker, points);
/* experimental code... */
							stuffcmd (head, "gamma 0.01\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.03\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.05\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.1\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.2\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.3\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.4\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.5\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.6\n");
							stuffcmd (head, "wait\n");
							stuffcmd (head, "gamma 0.7\n");
/* end of experimental code */
						}
						else
							T_Damage (head, inflictor, attacker, points);
//					}
				}
			}
		}
		head = head.chain;
	}
};
