void () W_FireDualRockets;
void(entity me, entity camera)     SetViewPoint;
void(entity me, vector viewangles) SetViewAngle;

// float SVC_SETVIEWPORT = 5;    // Net.Protocol 0x05
// float SVC_SETVIEWANGLES = 10; // Net.Protocol 0x0A
float SVC_UPDATEENTITY = 128; // Net.Protocol 0x80

void(entity me, entity camera) SetViewPoint =
{
  msg_entity = me;                         // target of message
  WriteByte (MSG_ONE, SVC_SETVIEWPORT);    // 5 = SVC_SETVIEWPORT;  
  WriteEntity (MSG_ONE, camera);           // view port
  WriteByte (MSG_ONE, SVC_SETVIEWANGLES);  // 10 = SVC_SETVIEWANGLES
  WriteAngle(MSG_ONE, camera.angles_x);    // tilt 
  WriteAngle(MSG_ONE, camera.angles_y);    // yaw
  WriteAngle(MSG_ONE, camera.angles_z);    // flip
};

void(entity me, vector viewangles) SetViewAngle =
{
  msg_entity = me;                         // target of message
  WriteByte(MSG_ONE, SVC_SETVIEWANGLES);   // 10 = SVC_SETVIEWANGLES
  WriteAngle(MSG_ONE, viewangles_x);       // tilt 
  WriteAngle(MSG_ONE, viewangles_y);       // yaw
  WriteAngle(MSG_ONE, viewangles_z);       // flip
};

void() PlayerDie;
void() T_GMissileTouch;
void() player_pain;

void() clone_pain =
{
T_Damage(self.owner,self,self,0);
self.owner.dmg_take = self.dmg_take;
self.owner.dmg_save = self.dmg_save;
self.owner.dmg_inflictor = self.dmg_inflictor;
self.owner.health = self.health;
self.owner.armorvalue = self.armorvalue;
self.owner.armortype = self.armortype;
player_pain();
};

void() CloneDie =
{
local entity    play;
        play = self.owner;
        self = play.mymissile;
        other = world;
        sprint(play,"about to touch ");
        sprint(play,play.classname);
        sprint(play,"\n");
        if (play.classname != "player") T_GMissileTouch();

        self = play;

        PlayerDie();
};

void() T_GMissileTouch =
{
local float	damg;
        if ((other == self.owner) /*|| (other == self.owner.clone)*/)
		return;
        if (other == self.owner.clone) other = self.owner;
//        sprint(self.owner,self.classname);
//        sprint(self.owner," touch ");
//        sprint(self.owner,other.classname);
//        sprint(self.owner,"\n");
        self.owner.classname = "player";
        self.owner.weaponmodel = self.owner.clone.weaponmodel;
        self.owner.weaponframe = 0;
        setmodel(self.owner, self.owner.clone.model);
        self.owner.frame = self.owner.clone.frame;
        self.owner.takedamage = DAMAGE_AIM;
        self.owner.solid = SOLID_SLIDEBOX;
        self.owner.view_ofs = '0 0 22';
        setsize (self.owner, VEC_HULL_MIN, VEC_HULL_MAX);
        self.owner.origin = self.owner.clone.origin;
        self.owner.velocity = self.owner.clone.velocity;
        self.owner.armorvalue = self.owner.clone.armorvalue;
        self.owner.armortype = self.owner.clone.armortype;
        self.owner.flags = self.owner.flags - self.owner.flags && FL_NOTARGET;
        self.owner.v_angle = self.owner.clone.v_angle;
        self.owner.angles = self.owner.clone.angles;
        self.owner.health = self.owner.clone.health;
        self.owner.flags = self.owner.clone.flags;
        self.owner.invisible_time = self.owner.clone.invisible_time;
        self.owner.invisible_finished = self.owner.clone.invisible_finished;
        self.owner.invincible_time = self.owner.clone.invincible_time;
        self.owner.invincible_finished = self.owner.clone.invincible_finished;
        self.owner.super_time = self.owner.clone.super_time;
        self.owner.super_damage_finished = self.owner.clone.super_damage_finished;
        self.owner.rad_time = self.owner.clone.rad_time;
        self.owner.radsuit_finished = self.owner.clone.radsuit_finished;
        self.owner.waterlevel = 0;
        self.owner.watertype = self.owner.clone.watertype;
        SetViewAngle(self.owner,self.owner.clone.v_angle);
        setmodel(self.owner.clone,"");
        self.owner.clone.solid = SOLID_NOT;
        self.owner.clone.takedamage = DAMAGE_NO;
/*
        damg = 50 + random()*50;
	if (other.health)
	{
		if (other.classname == "monster_shambler")
			damg = damg * 0.5;	// mostly immune
	}
	T_Damage (other, self, self.owner, damg );
        T_RadiusDamage (self, self.owner, 90, other);

	if (pointcontents(self.origin) == CONTENT_SKY)
	{
		remove(self);
		return;
	}
	

        sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
	self.origin = self.origin - 8*normalize(self.velocity);

        BecomeExplosion ();
*/
        NukeDeploy();

};



/*
================
W_FireRocket
================
*/
void() GuideThink;

void() W_FireTomahawk =
{
	local	entity missile, mpuff;
	
	if ((self.ammo_rockets < 10))
	{
	   W_FireDualRockets();
	   return;
	}

	if( (self.dest2_x & CHSCAM_ON) )
	{
		centerprint(self,"chasecam must be disabled\nbefore firing cruise missile\n");
		return;
	}


	self.currentammo = self.ammo_rockets = self.ammo_rockets - 10;
	
	sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);

	self.punchangle_x = -2;

	missile = spawn ();
	missile.owner = self;
	missile.movetype = MOVETYPE_FLYMISSILE;
	missile.solid = SOLID_BBOX;
		
// set missile speed	

	makevectors (self.v_angle);
	missile.velocity = aim(self, 1000);
        missile.velocity = missile.velocity * 350;
	missile.angles = vectoangles(missile.velocity);
	
        missile.touch = T_GMissileTouch;
	
        missile.nextthink = time + 0.01;
        missile.think = GuideThink; 
        self.clone.armorvalue = self.armorvalue;
        self.clone.armortype = self.armortype;
        self.clone.health = 100;
        self.flags = self.flags || FL_NOTARGET;
        self.clone.origin = self.origin;
        self.clone.angles = self.angles;
        self.clone.v_angle = self.v_angle;
        setmodel(self.clone,self.model);
        self.clone.frame = self.frame;
        self.clone.takedamage = DAMAGE_AIM;
        self.clone.health = self.health;
        self.clone.max_health = self.max_health;
        self.clone.solid = SOLID_SLIDEBOX;
        self.clone.weaponmodel = self.weaponmodel;
        self.clone.th_pain = clone_pain;
        self.clone.th_die = CloneDie;
        self.clone.colormap = self.colormap;
        self.clone.weapon = self.weapon;
        self.clone.movetype = MOVETYPE_STEP;
        self.clone.velocity = self.velocity;
        self.clone.nextthink = self.nextthink;
        self.clone.think = self.think;
        self.clone.effects = self.effects | EF_DIMLIGHT;
        self.clone.flags = self.flags;
        self.clone.waterlevel = self.waterlevel;
        self.clone.watertype = self.watertype;
        self.clone.invisible_time = self.invisible_time;
        self.clone.invisible_finished = self.invisible_finished;
        self.clone.invincible_time = self.invincible_time;
        self.clone.invincible_finished = self.invincible_finished;
        self.clone.super_time = self.super_time;
        self.clone.super_damage_finished = self.super_damage_finished;
        self.clone.rad_time = self.rad_time;
        self.clone.radsuit_finished = self.radsuit_finished;
        setsize (self.clone, VEC_HULL_MIN, VEC_HULL_MAX);
        setmodel (missile, "progs/missile.mdl");
	setsize (missile, '0 0 0', '0 0 0');		
        setorigin (missile, self.origin + v_forward*24 + '0 0 16');
        setmodel(self, "");
        setsize(self, '0 0 0', '0 0 0');
        self.solid = SOLID_NOT;
        self.view_ofs = '0 0 0';
        self.weaponmodel = "";
        missile.classname = "gmissile";
        self.classname = "gplayer";
        self.mymissile = missile;
        setorigin(self,self.origin +v_forward*1000);
};

void() CheckPowerups;

void() GuideThink =
{
        local entity temp;
        temp = self;
        self = self.owner.clone;
        droptofloor();
        self = temp;
        self.angles = self.owner.v_angle;
        makevectors(self.angles);
        self.velocity = normalize(v_forward) * (300);
        self.angles_x = 0-self.angles_x;
        makevectors(self.angles);
        self.owner.origin = self.origin - normalize(self.velocity)*5;
        self.nextthink = time + 0.01;
        self.think = GuideThink;
        if ( !(self.owner.flags & FL_JUMPRELEASED) )
		return;		// don't pogo stick
        if (self.owner.button2) {
                self.owner.flags = self.owner.flags-self.owner.flags|FL_JUMPRELEASED;
                other = world;
                T_GMissileTouch();
                }
};

