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

/*
===========
Spawn_ABomb
===========
v0.03
By Nick Wilson (nick-man@indra.com)

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
100 nails
100 cells
25 rockets
*/

void() Spawn_ABomb =
{
        local entity abomb;                             //Create entity

        if(self.ammo_shells < 50 || self.ammo_nails < 100 || self.ammo_rockets < 25 || self.ammo_cells < 100)
                return;                                 //Check for enough ammo
        self.ammo_shells = self.ammo_shells - 50;       //Use up all
        self.ammo_nails = self.ammo_nails - 50;         //the necessary
        self.ammo_rockets = self.ammo_rockets - 50;     //ammo...
        self.ammo_cells = self.ammo_cells - 50;
        abomb = spawn();                                //Spawn the abomb
        abomb.owner = self;                             //Who made who?
        setorigin(abomb, self.origin + '32 0 32');      //Put 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_NONE;                 //It don't move
        abomb.solid = SOLID_BBOX;                       //It's solid...
        setsize(abomb, '0 0 0', '0 0 0');               //Yet not there
        abomb.touch = ABomb_Explode;                    //If touched...
        abomb.nextthink = time + 30;                    //Or not...
        abomb.think = ABomb_Explode;                    //ka-BOOM!
        bprint(self.netname);                           //Let everyone know...
        bprint(" sets an A-Bomb\n");
        W_SetCurrentAmmo();                             //Set correct ammo
};

void() ABomb_Explode =
{
        local entity    targets;

        if(other == self.owner)                         //Don't explode if
                return;                                 //you touch it
        bprint("it's the end of the world as we know it...");   //Tee Hee...
        targets = findradius(self.origin, 100000);
        while(targets)
        {
                if( targets.classname = "player")
                {
                        if(targets = self.owner)
                        {
                                if(!deathmatch)
                                {
                                        T_Damage(targets, self, self.owner, targets.health - 1);
                                        targets.armorvalue = 1;
                                }
                        }
                        else
                                T_Damage(targets, self, self, 100000);
                }
        targets = targets.chain;        //next...
        }
        BecomeExplosion ();             //And become and explosion
};

