/*
 code author status:
 total: 26 lines by Nick & lot of lines by NoNixLNX2 ...
 weapons.qc: 3 lines by Nick...
 abom*.qc: 22 lines by Nick & rest by NoNixLNX2 ...
 abomb.qc: 21 lines by Nick & rest by NoNixLNX2 ;)
 (not including the following Spawn_ABomb documentation block)
*/

void() W_SetCurrentAmmo;
void() ABomb_Explode;

/*
===========
Spawn_ABomb
===========
v0.03
By Nick Wilson (nick-man@indra.com)
v0.05b by NoNixLNX2 / tbittih@xgw.fi
v0.06b by NoNixLNX2 / tbittih@xgw.fi

Creates an A-Bomb that hovers in the air.  It explodes, and
kills everything.  It is set off after 30 seconds or if another player or
monster touches it.  What fun!
Uses:
50 shells  (« of max)
100 nails  (« of max)
50 cells   (« of max) (id's BUG in items.qc: bound_other_ammo vs ammo_touch, bound_other_ammo limits to 100 but ammo_touch to 200?)
25 rockets (¬ of max)
*/

void() check_rand_16x = // sorry but had to do this... don't trust qcc ;)
{
	local float rnx1;
	local float rnx2;
	local float rnx3;
	rnx3 = 4;
	while (rnx3 > 0) //can you see we don't trust qcc/float roundings?
	{
		rnx2 = 4;
		while (rnx2 > 0)
		{
			rnx1 = random();
			if (!rnx1) bprint("Holy fsck! ");
			bprint (ftos(rnx1)); bprint (" ");
			rnx2 = rnx2 - 1;
		}
		bprint ("\n");
		rnx3 = rnx3 - 1; // damn, where are the fsck-- and aargh++ ?
	}
/* results for 10 runs of this thingy: (does it round?)
 *	0.0's:	6	1.0's:	8
 *	added (16rand):	9.2 9.1 8.0 7.3 7.7 8.3 6.5 8.8 9.0 8.4
 *	82.3/160 = 0.514375
 *	can I trust that kind of random() function? maybe ;)
 *	... just don't use things like if (!random()) ...
 */
};
void() Spawn_ABomb =
{
//	check_rand_16x();	//this test proves that 0.0 != 0 ... damn I wasted two hours on this ;)
	local entity abomb;				//Create entity
/* test-block */
	if(self.ammo_shells < 50 || self.ammo_nails < 100 || self.ammo_rockets < 25 || self.ammo_cells < 50)
		return;					//Check for enough ammo
	self.ammo_shells = self.ammo_shells - 50;	//Use up all
	self.ammo_nails = self.ammo_nails - 100;	//the necessary
	self.ammo_rockets = self.ammo_rockets - 25;	//ammo...
	self.ammo_cells = self.ammo_cells - 50;
/* end-of-test-block */
	abomb = spawn();				//Spawn the abomb
	abomb.owner = self;				//Who made who?
	setorigin(abomb, self.origin + v_forward*16 + '0 0 24');	//above and in front
	abomb.velocity = '0 0 0';			//Not goin anywhere
	abomb.flags = FL_FLY;				//It flies
	setmodel(abomb, "progs/grenade.mdl");		//It's a grenade
	abomb.movetype = MOVETYPE_FLY;				//needed for spinning, MOVETYPE_NONE would be 'nuff if not spinning...
	abomb.solid = SOLID_BBOX;				//It's solid... (trigger)
	setsize(abomb, '0 0 0', '0 0 0');			//but you can walk through it...
	abomb.touch = ABomb_Touch;				//If touched...
	abomb.nextthink = time + 20;				//Or not...
	abomb.think = ABomb_Count10;				//ka-BOOM!
	abomb.effects=9; // EF_DIMLIGHT && BRIGHTFIELD
	abomb.avelocity='400 300 200';				//spin
	bprint(self.netname);				//Let everyone know...
	bprint(" sets an A-Bomb\n");
	lightstyle(0, "vutsrqponm");
	W_SetCurrentAmmo();				//Set correct ammo
};
