//====================================================================
//
// HOLOGRAPHIC SELF			by: Perecli Manole AKA Bort
//
//====================================================================
// Aside from this new file, the following are the modifications
// done to id's original source files:
//--------------------------------------------------------------------
// File: Progs.src
// Location: before the "weapons.qc" line
// Added: holo.qc
//--------------------------------------------------------------------
// File: Weapons.qc
// Procedure: ImpulseCommands
// Location: first line in the function
// Added: CheckHoloCommand ();
//--------------------------------------------------------------------


float   ACTIVATE_HOLO = 50;	// impulse constant
float	SEC = 10;		// number of seconds holo is on
float	COST = 10;		// number of power cells holo costs
float	IT_HOLO = 8388608;	// holo bit mask flageee
float   IT_HOLO_neg = 8388607;	// negative holo bit mask flag


//--------------------------------------------------------------------
// When time expires holograph gets deactivated
//--------------------------------------------------------------------
void() RemoveHolo =
{
	WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
	WriteByte (MSG_BROADCAST, TE_TELEPORT);
	WriteCoord (MSG_BROADCAST, self.origin_x);
	WriteCoord (MSG_BROADCAST, self.origin_y);
	WriteCoord (MSG_BROADCAST, self.origin_z);
	sound (self, CHAN_BODY, "misc/r_tele1.wav", 1, ATTN_NORM);
	SUB_Remove();
	self.owner.items = self.owner.items & IT_HOLO_neg;
	sprint(self.owner,"holograph expired\n");
};


//--------------------------------------------------------------------
// Frames for holograph self
//--------------------------------------------------------------------
void() holo_stand1 = [12, holo_stand2] {};  
void() holo_stand2 = [13, holo_stand3] {};
void() holo_stand3 = [14, holo_stand4] {};
void() holo_stand4 = [15, holo_stand5] {};
void() holo_stand5 = [16, holo_stand1] 
{
	self.health = self.health - 0.5;
	if (self.health <= 0)	
		RemoveHolo();	
};


//--------------------------------------------------------------------
// Spawns holograph self
//--------------------------------------------------------------------
void(entity myself) ActivateHolo =
{
	local entity	newholo;

	newholo = spawn();
	newholo.solid = SOLID_NOT;
	newholo.movetype = MOVETYPE_NOCLIP;
	newholo.origin = myself.origin;
	newholo.angles = myself.angles;
	newholo.colormap = myself.colormap;
	newholo.skin = myself.skin;
	setmodel (newholo, "progs/player.mdl");
	newholo.classname = "holo";
	newholo.owner=myself;
	newholo.health = SEC;
	myself.currentammo = myself.ammo_cells = myself.ammo_cells - COST;
	myself.items = myself.items | IT_HOLO;
	stuffcmd (newholo.owner, "bf\n");
	sprint(newholo.owner,"holograph activated\n");
	newholo.nextthink = time;	
	newholo.think = holo_stand1;    
};



//--------------------------------------------------------------------
// Checks if holograph should be activated
//--------------------------------------------------------------------
void() CheckHoloCommand = 
{
	if (self.impulse != ACTIVATE_HOLO )
		return;

	if ((self.items & IT_HOLO) == IT_HOLO)
	{
		sprint(self,"holograph active\n");
		return;
	}

	if (self.ammo_cells < 10)
	{
		sprint(self,"cells are low\n");
		return;
	}
	
	ActivateHolo (self);
}; 