
freeslot("MT_EGGOVERLORD","MT_LEFTOVERLORD","MT_RIGHTOVERLORD","MT_ENERGYOVERLORD","MT_TRACEOVERLORD",
"s_LEFTOVERLORD_ATK","MT_EETON","MT_ENERGYBUBBLE","MT_ENERGYEXLOAD","MT_EEWAVE","MT_NOOVERLORD","MT_JETFUMEO1","MT_SSPKO1")

function A_EetonFire(actor, var1, var2) // (actor, var1, var2)
local mo = actor
	// spawn objects 3
//face target
if actor.target and actor.target.valid then

actor.angle = R_PointToAngle2(actor.x, actor.y, actor.target.x, actor.target.y)
S_StartSound(actor, 96) //cannon sound

		mo.etonl = P_SpawnMobj(mo.x+FixedMul(2*FRACUNIT, cos(mo.angle-(ANGLE_22h))),  
	mo.y+FixedMul(2*FRACUNIT, sin(mo.angle-(ANGLE_22h))), mo.z+(2*FRACUNIT), MT_EETON)
		mo.etonr = P_SpawnMobj(mo.x+FixedMul(2*FRACUNIT, cos(mo.angle-(ANGLE_22h))),  
	mo.y+FixedMul(2*FRACUNIT, sin(mo.angle-(ANGLE_22h))), mo.z+(2*FRACUNIT), MT_EETON)
		
		mo.etonm = P_SpawnMobj(mo.x+FixedMul(2*FRACUNIT, cos(mo.angle-(0))),  
	mo.y+FixedMul(2*FRACUNIT, sin(mo.angle-(0))), mo.z+(1*FRACUNIT), MT_EETON)
	//set the angles 3

	mo.etonl.angle = mo.angle-ANGLE_22h
	mo.etonr.angle = mo.angle+ANGLE_22h
	mo.etonm.angle = mo.angle
	
	mo.etonl.creator = mo
	mo.etonr.creator = mo
	mo.etonm.creator = mo
	//set the middle object momz -5*FRACUNIT?
	P_Thrust(mo.etonl, mo.etonl.angle, FixedMul(25*FRACUNIT, mo.etonl.scale))
	P_Thrust(mo.etonr, mo.etonr.angle, FixedMul(25*FRACUNIT, mo.etonr.scale))
	P_Thrust(mo.etonm, mo.etonm.angle, FixedMul(20*FRACUNIT, mo.etonm.scale))
	mo.etonl.momz = -5*FRACUNIT
	mo.etonr.momz = -5*FRACUNIT
	mo.etonm.momz = -20*FRACUNIT
	//make sure they all have the same target
	mo.etonl.target = mo.target
	mo.etonr.target = mo.target
	mo.etonm.target = mo.target
	// set height limit
	mo.etonl.heightlimit = mo.z+(2*FRACUNIT)
	mo.etonr.heightlimit = mo.z+(2*FRACUNIT)
	mo.etonm.heightlimit = mo.z+(2*FRACUNIT)
end
	
end//-

addHook("MobjSpawn", function(mo)
    mo.jetfume1 = P_SpawnMobj(mo.x, mo.y, mo.z, MT_JETFUMEO1)
    mo.jetfume2 = P_SpawnMobj(mo.x, mo.y, mo.z, MT_JETFUMEO1)
    mo.jetfume3 = P_SpawnMobj(mo.x, mo.y, mo.z, MT_JETFUMEO1)
    mo.jetfume1.tracer = mo
    mo.jetfume2.tracer = mo
    mo.jetfume3.tracer = mo
end, MT_EGGOVERLORD)

addHook("BossThinker", function(mo) //----------------//
local tar = mo.target

	if mo.state == S_EGGOVERLORD_FLEE1 or mo.state == S_EGGOVERLORD_FLEE2 then
		if mo.jetfume1 and mo.jetfume1.valid then
			P_TeleportMove(mo.jetfume1, mo.x - 54 * cos(mo.angle), mo.y - 54 * sin(mo.angle), mo.z + (38*FRACUNIT))
			mo.jetfume1.momx = mo.momx*2
			mo.jetfume1.momy = mo.momy*2
		end
		if mo.jetfume2 and mo.jetfume2.valid then
			P_TeleportMove(mo.jetfume2, mo.x - 54 * cos(mo.angle) - 22*cos(mo.angle-ANGLE_90), mo.y - 54 * sin(mo.angle) - 22*sin(mo.angle-ANGLE_90), mo.z + (10*FRACUNIT))
			mo.jetfume2.momx = mo.momx*2
			mo.jetfume2.momy = mo.momy*2
		end
		if mo.jetfume3 and mo.jetfume3.valid then
			P_TeleportMove(mo.jetfume3, mo.x - 54 * cos(mo.angle) - 22*cos(mo.angle+ANGLE_90), mo.y - 54 * sin(mo.angle) - 22*sin(mo.angle+ANGLE_90), mo.z + (10*FRACUNIT))
			mo.jetfume3.momx = mo.momx*2
			mo.jetfume3.momy = mo.momy*2
		end
	else
		if mo.jetfume1 and mo.jetfume1.valid then
			P_TeleportMove(mo.jetfume1, mo.x - 67 * cos(mo.angle), mo.y - 67 * sin(mo.angle), mo.z + (70*FRACUNIT))
			mo.jetfume1.momx = mo.momx*2
			mo.jetfume1.momy = mo.momy*2
		end
		if mo.jetfume2 and mo.jetfume2.valid then
			P_TeleportMove(mo.jetfume2, mo.x - 66 * cos(mo.angle) - 22*cos(mo.angle-ANGLE_90), mo.y - 66 * sin(mo.angle) - 24*sin(mo.angle-ANGLE_90), mo.z + (42*FRACUNIT))
			mo.jetfume2.momx = mo.momx*2
			mo.jetfume2.momy = mo.momy*2
		end
		if mo.jetfume3 and mo.jetfume3.valid then
			P_TeleportMove(mo.jetfume3, mo.x - 66 * cos(mo.angle) - 22*cos(mo.angle+ANGLE_90), mo.y - 66 * sin(mo.angle) - 24*sin(mo.angle+ANGLE_90), mo.z + (42*FRACUNIT))
			mo.jetfume3.momx = mo.momx*2
			mo.jetfume3.momy = mo.momy*2
		end
	end
	
	if mo.tracktracer == nill then
		mo.tracer = P_SpawnMobj(mo.x+FixedMul(10*FRACUNIT, cos(mo.angle)),  
			mo.y+FixedMul(10*FRACUNIT, sin(mo.angle)), mo.z+(188*FRACUNIT), MT_TRACEOVERLORD)
		mo.tracktracer = true
		mo.shieldtoggle = false
		mo.attack2countdown = 0
		mo.attack3countdown = -1 //-1
		mo.attack3altpattern = false
		mo.attack3phase = 0
		mo.startmoveing = 0
		mo.moveangle = mo.angle
		mo.dashspeed = 20*FRACUNIT
		mo.energyshot = 0
		mo.shotcooldown = 0
		mo.retreat = false // after 2nd attack is over return to the tracer
		mo.pathdist = 0
		mo.gathereffect = false
		mo.gatherz = 0
	end
	
	if tar and tar.valid then
	mo.attack2countdown = $+1
	end
	//-----------------------------the third attack-------------------//
	if mo.attack3countdown > 0 then
		mo.attack3countdown = $+1
		if mo.attack3countdown > 10*TICRATE and (mo.state == S_EGGOVERLORD_SEE or mo.state == S_EGGOVERLORD_ATK1)
			and mo.attack3phase == 0 then
			mo.state = S_EGGOVERLORD_LASER1
			if mo.attack3altpattern == false then
				P_LinedefExecute(904, mo, mo.subsector.sector)
			else
				P_LinedefExecute(903, mo, mo.subsector.sector)
			end
			S_StartSound(actor, 390) //laser charging up lasts about 5 seconds
			mo.attack3phase = 1
		end
		if mo.attack3countdown > 13*TICRATE and mo.attack3phase == 1 and mo.state != S_EGGOVERLORD_PAIN then
			if mo.attack3altpattern == false then
			P_LinedefExecute(905, mo, mo.subsector.sector)
			else
			P_LinedefExecute(906, mo, mo.subsector.sector)
			end
		S_StartSound(actor, 391) //391 laser fireing
		mo.attack3phase = 2
		mo.state = S_EGGOVERLORD_SEE
		end
		if mo.attack3countdown > 19*TICRATE and mo.attack3phase == 2 then // laser ending
			if mo.attack3altpattern == false then
			P_LinedefExecute(907, mo, mo.subsector.sector)
			mo.attack3altpattern = true
			else
			P_LinedefExecute(908, mo, mo.subsector.sector)
			mo.attack3altpattern = false
			end
		mo.attack3phase = 0
		mo.attack3countdown = -1
		end
	end

	if mo.shotcooldown > 0 then // fire energy blast at a rate //1*TICRATE
		mo.shotcooldown = $-1
	end

	if mo.tracer and mo.tracer.valid and mo.tracktracer == true then
		P_TeleportMove(mo, mo.tracer.x, mo.tracer.y, mo.tracer.z)
		mo.momx = 0 // fixed uneven generators bug?
		mo.momy = 0 
		mo.momz = 0 
	end

	if mo.leftbattery == nill then
		mo.energychargeing = false
		mo.destroypiece = false
		// spawn child object on the left side
		mo.leftbattery = P_SpawnMobj(mo.x+FixedMul(600*FRACUNIT, cos(mo.angle-(ANGLE_90))),  
	mo.y+FixedMul(600*FRACUNIT, sin(mo.angle-(ANGLE_90))), mo.z+(10*FRACUNIT), MT_LEFTOVERLORD)
		mo.leftbattery.angle = mo.angle
		mo.leftbattery.creator = mo
		mo.leftshield = true
		mo.leftbattery.gathertime = TICRATE // timer for spawining gater things for effects
		// spawn child object on the right side
		mo.rightbattery = P_SpawnMobj(mo.x+FixedMul(600*FRACUNIT, cos(mo.angle+(ANGLE_90))),  
	mo.y+FixedMul(600*FRACUNIT, sin(mo.angle+(ANGLE_90))), mo.z+(10*FRACUNIT), MT_RIGHTOVERLORD)
		mo.rightbattery.angle = mo.angle
		mo.rightbattery.creator = mo
		mo.rightshield = true
		mo.rightbattery.gathertime = TICRATE // timer for spawining gater things for effects
	end 
		
	// start and set effect postion //
	if mo.energychargeing == true and mo.energyeffect == nill and mo.attack2countdown < 48*TICRATE then
		mo.energyeffect = P_SpawnMobj(mo.x+FixedMul(1*FRACUNIT, cos(mo.angle+(ANGLE_90))),  
		mo.y+FixedMul(1*FRACUNIT, sin(mo.angle)), mo.z+(170*FRACUNIT), MT_ENERGYOVERLORD) // effect
		P_TeleportMove(mo.energyeffect, mo.x, mo.y, mo.z +170*FRACUNIT) //
	elseif (mo.energyeffect) and (mo.energyeffect.valid) then
	P_TeleportMove(mo.energyeffect, mo.x, mo.y, mo.z +170*FRACUNIT) //
	end

		//-------//the second attack //-----------//
	if mo.attack2countdown >= 41*TICRATE and mo.health > 0 then // start the 2nd attack /42
	//print(mo.attack2countdown)
	mo.tracktracer = false
	mo.momz = -20*FRACUNIT
		if mo.state != S_EGGOVERLORD_PAIN and mo.state != S_EGGOVERLORD_GATHER1 and mo.state != S_EGGOVERLORD_PAIN1 and
		mo.state != S_EGGOVERLORD_GATHER2 and mo.health > 0 then
			mo.state = S_EGGOVERLORD_GATHER1
			mo.flags2 = $&~(MF2_FRET) //stop flashing become hitabule
		end
		if P_IsObjectOnGround(mo) and mo.startmoveing == true then
			P_InstaThrust(mo, mo.moveangle, FixedMul(mo.dashspeed, mo.scale)) // move around
			//P_InstaThrust(mo.leftbattery, mo.moveangle, FixedMul(mo.dashspeed, mo.scale)) 
			//P_InstaThrust(mo.rightbattery, mo.moveangle, FixedMul(mo.dashspeed, mo.scale))
				if (mo.energyeffect) and mo.energyeffect.valid then
				P_InstaThrust(mo.energyeffect, mo.moveangle, FixedMul(mo.dashspeed, mo.scale))
				end
			if mo.energyshot == 0 and mo.attack2countdown >= 42*TICRATE  and mo.attack2countdown <= 47*TICRATE then
			S_StartSound(mo, 216) // powering up sound
			mo.gathereffect = true
			mo.energyshot = 9
			end
		end
		if mo.attack2countdown >= 44*TICRATE then
		mo.energychargeing = true
		end
		if mo.attack2countdown >= 46*TICRATE then
		mo.dashspeed = 40*FRACUNIT
		end
		if mo.attack2countdown >= 48*TICRATE then // fire the projectiles
			if mo.energyshot > 0 and mo.shotcooldown <= 0  then
				mo.gathereffect = false
				mo.shotcooldown = 1*((TICRATE*2)/3)
				mo.energyshot = $-1
				S_StartSound(mo, 239) // fireing sound
				mo.energyspawn = P_SpawnMobj(mo.x+FixedMul(1*FRACUNIT, cos(mo.angle+(ANGLE_90))),  
				mo.y+FixedMul(1*FRACUNIT, sin(mo.angle)), mo.z+(170*FRACUNIT), MT_ENERGYOVERLORD) 
				P_SetObjectMomZ(mo.energyspawn, 40*FRACUNIT, false)
				mo.energyspawn.flags = $&~(MF_NOGRAVITY) // fall down
				mo.energyspawn.fall = true
				mo.energyspawn.target = mo.target
				mo.energyspawn.scale = FRACUNIT*2 //larger
			end
			if (mo.energyeffect) and mo.energyeffect.valid and mo.energyshot <= 0 then // end effect
				P_RemoveMobj(mo.energyeffect)
				mo.energyeffect = nill
				mo.energychargeing = false
			end
			if mo.attack2countdown > 57*TICRATE then // attack is over
			mo.retreat = true // return to the path
			mo.energychargeing = false
				if mo.state != S_EGGOVERLORD_PAIN and mo.health > 0 then
				mo.state = S_EGGOVERLORD_RETRE
				end
				//--- if close enogh to the path return to basic funtion ---//
				if mo.pathdist <= 4*FRACUNIT and mo.tracktracer == false and mo.health > 0 then
					mo.state = S_EGGOVERLORD_SEE
					mo.tracktracer = true
					mo.attack2countdown = 0
					mo.attack3countdown = 1
					mo.leftbattery.momx = 0
					mo.leftbattery.momy = 0
					mo.rightbattery.momx = 0
					mo.rightbattery.momy = 0
				end
			end
		end
	else
	mo.startmoveing = true
	mo.moveangle = mo.angle
	mo.dashspeed = 20*FRACUNIT
	mo.energychargeing = false
	end 
	//----------//-----------------//-----------//
	mo.pathdist = P_AproxDistance(mo.tracer.x - mo.x, mo.tracer.y - mo.y)
	
		if mo.leftbattery.valid and mo.rightbattery.valid and mo.health > 0 then // do things with the generators
	// set postion of the child objects and momentome
	P_TeleportMove(mo.leftbattery, mo.x + 64 * cos(mo.angle-(ANGLE_90)), mo.y + 64 * sin(mo.angle-(ANGLE_90)), mo.z +25*FRACUNIT)
	mo.leftbattery.angle = mo.angle

	mo.leftbattery.z = mo.z +25*FRACUNIT
	P_TeleportMove(mo.rightbattery, mo.x + 64 * cos(mo.angle+(ANGLE_90)), mo.y + 64 * sin(mo.angle+(ANGLE_90)), mo.z +25*FRACUNIT)
	mo.rightbattery.angle = mo.angle
	
	mo.rightbattery.z = mo.z +25*FRACUNIT
		if mo.leftshield == false and mo.rightshield == false and (mo.energybubble) and mo.energybubble.valid then
			mo.energybubble.state = S_ENERGYBUBBLE_DIE // shield dies
			//mo.flags = $|(MF_SPECIAL|MF_SHOOTABLE) // become hitabule later
			S_StartSound(mo, 161)
			mo.energybubble = nill
			mo.shieldtoggle = false
		end
		if mo.leftshield == true and mo.rightshield == true and mo.shieldtoggle == false then
			mo.energybubble = P_SpawnMobj(mo.x+FixedMul(10*FRACUNIT, cos(mo.angle)),  
			mo.y+FixedMul(10*FRACUNIT, sin(mo.angle)), mo.z+(200*FRACUNIT), MT_ENERGYBUBBLE)
			mo.energybubble.tracer = mo
			mo.shieldtoggle = true
			mo.flags = $&~(MF_SPECIAL|MF_SHOOTABLE) // not hitabule shield should be up
			S_StartSound(mo, 420)
		end
	end
	
	//re appliy shield after taking so many hits
	if mo.state == S_EGGOVERLORD_PAIN1 and mo.shieldtoggle == false and
	(mo.health == 2 or mo.health == 5) then
	//mo.shieldtoggle = true
	mo.leftshield = true
	mo.rightshield = true
	end
	
	//-----z offset for the gaterpoint to reach----//
	mo.gatherz = mo.z+(170*FRACUNIT)
	
	//----------do stuff on death-------------------//
	if mo.health <= 0 and mo.leftbattery.valid and mo.rightbattery.valid then // stop moveing on the path
	mo.tracktracer = false
	mo.leftbattery.momz = 0
	mo.rightbattery.momz = 0
	mo.leftbattery.momx = 0
	mo.rightbattery.momx = 0
	mo.leftbattery.momy = 0
	mo.rightbattery.momy = 0
	mo.gathereffect = false
		if mo.destroypiece == false and mo.state == S_EGGOVERLORD_FLEE1 then
			mo.brokenpiece = P_SpawnMobj(mo.x+FixedMul(1*FRACUNIT, cos(mo.angle)),  
			mo.y+FixedMul(1*FRACUNIT, sin(mo.angle)), mo.z-(1*FRACUNIT), MT_NOOVERLORD)
			
			mo.brokenpiece.angle = mo.angle
			P_SetObjectMomZ(mo.brokenpiece, 6*FRACUNIT, true)
			mo.destroypiece = true
		end
		if (mo.energyeffect) and mo.energyeffect.valid then
			P_RemoveMobj(mo.energyeffect)
			mo.energyeffect = nill
		end
		if mo.attack3countdown > 0 then
				if mo.attack3altpattern == false then
				P_LinedefExecute(907, mo, mo.subsector.sector)
				mo.attack3altpattern = true
				else
				P_LinedefExecute(908, mo, mo.subsector.sector)
				mo.attack3altpattern = false
				end
			mo.attack3phase = 0
			mo.attack3countdown = -1
		end
	end
	
end, MT_EGGOVERLORD)//--------------------------------------------------///////------------------------------------------------//
//-----------------------------------------------------------------------------//
addHook("MobjThinker", function(mo) //-----set speed of the traver object------//
	mo.watertop = 2*FRACUNIT
end, MT_TRACEOVERLORD)//-------------------------------------------------------------------------------//

addHook("MobjThinker", function(mo) //----- gather object------//
	if mo.gatherpoint != nill then
		local xdiff = mo.gatherpoint.x-mo.x
		local ydiff = mo.gatherpoint.y-mo.y
		local zdiff = (mo.gatherpoint.z+(170*FRACUNIT))-mo.z
		mo.momx = xdiff/10+(mo.gatherpoint.momx)
		mo.momy = ydiff/10+(mo.gatherpoint.momy)
		mo.momz = zdiff/5
		mo.timer = $+1
		if mo.timer > (TICRATE) then
		P_RemoveMobj(mo)
		end
	end
end, MT_MSGATHER)

addHook("MobjThinker", function(mo) //-----when energyshot reaches the ground do something------//
	if mo.momz <= -7*FRACUNIT then //slow down the fall
		mo.momz = -7*FRACUNIT
	end
	if mo.fall == true and mo.z <= mo.floorz then
		mo.engexload = P_SpawnMobj(mo.x, mo.y, mo.z, MT_ENERGYEXLOAD)
		mo.engexload.target = mo.target
		S_StartSound(engexload, 401) //charge release sound
		P_RemoveMobj(mo)
	end

end, MT_ENERGYOVERLORD)//-------------------------------------------------------------------------------//

addHook("MobjThinker", function(mo) // broken piece
	P_SetObjectMomZ(mo, -4*FRACUNIT, true)
	if mo.z <= mo.floorz then
		P_RemoveMobj(mo)
	end

end, MT_NOOVERLORD)

addHook("MobjThinker", function(mo) //left generator

	if mo.creator and mo.creator.valid then // turn on-------//
		if mo.creator.leftshield == true and mo.state == S_LEFTOVERLORD_OFF then
				mo.state = S_LEFTOVERLORD_ON1
				mo.flags = $|(MF_SPECIAL|MF_SHOOTABLE)
				//mo.flags2 = $&~(MF2_FRET)
		end
		if mo.state == S_LEFTOVERLORD_OFF then
			mo.flags = $&~(MF_SPECIAL|MF_SHOOTABLE)
			//mo.flags2 = $|(MF2_FRET)
		end
		if mo.creator.leftshield == true then
		mo.flags = 4194821
		//mo.flags2 = $&~(MF2_FRET) //stop flashing become hitabule
		end
		// set postion twice
		P_TeleportMove(mo, mo.creator.x + 64 * cos(mo.angle-(ANGLE_90)), mo.creator.y + 64 * sin(mo.creator.angle-(ANGLE_90)), mo.creator.z +25*FRACUNIT)
		if mo.creator.gathereffect == true then //--//
			mo.gathertime = $+1
		// spawn gather objects
			if mo.gathertime > (TICRATE/3) then
			mo.gathertime = 0
			mo.gatherobj = P_SpawnMobj(mo.x+FixedMul(1*FRACUNIT, cos(mo.angle)),  
				mo.y+FixedMul(1*FRACUNIT, sin(mo.angle)), mo.z+(70*FRACUNIT), MT_MSGATHER)
			mo.gatherobj.gatherpoint = mo.creator
			mo.gatherobj.timer = 0 
			end
		end //--//
	end
	
	if mo.state == S_LEFTOVERLORD_DIE1 or mo.state == S_LEFTOVERLORD_DIE2 then
		P_SetObjectMomZ(mo, -9*FRACUNIT, true)
		if mo.z <= mo.floorz then
		P_RemoveMobj(mo)
		end
	//once creator reaches its later death state fall off it
	elseif mo.creator and mo.creator.valid and mo.creator.state == S_EGGOVERLORD_FLEE1 then
	mo.flags = MF_NOBLOCKMAP
	P_InstaThrust(mo,ANGLE_90,FixedMul((2*(FRACUNIT)), mo.scale))
	P_SetObjectMomZ(mo, 30*FRACUNIT, true)
	mo.state = S_LEFTOVERLORD_DIE1
	mo.creator = nil
	end

end, MT_LEFTOVERLORD)

addHook("MobjThinker", function(mo) // right generator

	if mo.creator and mo.creator.valid then // turn on-------//
		if mo.creator.rightshield == true and mo.state == S_RIGHTOVERLORD_OFF then
				mo.state = S_RIGHTOVERLORD_ON1
				mo.flags = $|(MF_SPECIAL|MF_SHOOTABLE)	
				//mo.flags2 = $&~(MF2_FRET)
		end
		if mo.state == S_RIGHTOVERLORD_OFF then
			mo.flags = $&~(MF_SPECIAL|MF_SHOOTABLE)
			//mo.flags2 = $|(MF2_FRET) //stop flashing become hitabule
		end
		if mo.creator.rightshield == true then
		mo.flags = 4194821
		//mo.flags2 = $&~(MF2_FRET) //stop flashing become hitabule
		end
		// set postion twice
		P_TeleportMove(mo, mo.creator.x + 64 * cos(mo.angle+(ANGLE_90)), mo.creator.y + 64 * sin(mo.creator.angle+(ANGLE_90)), mo.creator.z +25*FRACUNIT)
		if mo.creator.gathereffect == true then //--//
			mo.gathertime = $+1
		// spawn gather objects
			if mo.gathertime > (TICRATE/3) then
			mo.gathertime = 0
			mo.gatherobj = P_SpawnMobj(mo.x+FixedMul(1*FRACUNIT, cos(mo.angle)),  
				mo.y+FixedMul(1*FRACUNIT, sin(mo.angle)), mo.z+(70*FRACUNIT), MT_MSGATHER)
			mo.gatherobj.gatherpoint = mo.creator
			mo.gatherobj.timer = 0 
			end
		end //--//
	end

	if mo.state == S_RIGHTOVERLORD_DIE1 or mo.state == S_RIGHTOVERLORD_DIE2 then
		P_SetObjectMomZ(mo, -9*FRACUNIT, true)
		if mo.z <= mo.floorz then
		P_RemoveMobj(mo)
		end
	//once creator reaches its later death state fall off it
	elseif mo.creator and mo.creator.valid and mo.creator.state == S_EGGOVERLORD_FLEE1 then
	mo.flags = MF_NOBLOCKMAP
	P_InstaThrust(mo,ANGLE_270,FixedMul((2*(FRACUNIT)), mo.scale))
	P_SetObjectMomZ(mo, 30*FRACUNIT, true)
	mo.state = S_RIGHTOVERLORD_DIE1
	mo.creator = nil
	end

end, MT_RIGHTOVERLORD)

//-----------eeton play sound 3 times-----------------//
addHook("MobjThinker", function(mo)
	if mo.playsound == nill then
	mo.playsound = true
	elseif mo.state == S_EETON4 or mo.state == S_EETON6 or mo.state == S_EETON9 then
		if mo.playsound == true then
		S_StartSound(actor, 99) //deton sound
		mo.playsound = false
		end
	else
		mo.playsound = true
	end
	
	if mo.heightlimit != nill and mo.z > mo.heightlimit then
	mo.z = mo.heightlimit
	mo.momz = 0
	end
	
end, MT_EETON)
//-------------------------------------------------------------------------------//

addHook("ShouldDamage", function(mo, moinflictor, mosource, damage, damagetype) // no contact damage from touching generators
	if moinflictor != nil and moinflictor.valid and (moinflictor.type == MT_LEFTOVERLORD or moinflictor.type == MT_RIGHTOVERLORD) then
		return false
	end
end,  	MT_PLAYER )

//------tell your creator you have been hit and should be turned off-------//
addHook("MobjDamage", function(mo, moinflictor, mosource, damage, damagetype)

	if mo.creator and mo.creator.valid then
		mo.state = S_LEFTOVERLORD_HIT1
		//mo.flags2 = $&~(MF2_FRET)
		mo.creator.leftshield = false
	end

	
end, MT_LEFTOVERLORD)

addHook("MobjDamage", function(mo, moinflictor, mosource, damage, damagetype)

	if mo.creator and mo.creator.valid then
		mo.state = S_RIGHTOVERLORD_HIT1
		//mo.flags2 = $&~(MF2_FRET)
		mo.creator.rightshield = false
	end

	
end, MT_RIGHTOVERLORD)

addHook("MobjMoveBlocked", function(mo)

	if mo.attack2countdown >= 2*TICRATE then
		mo.moveangle = $+ANGLE_135
			if mo.leftbattery.valid and mo.rightbattery.valid then // do things with the generators
				// set postion of the child objects and momentome
				P_TeleportMove(mo.leftbattery, mo.x + 64 * cos(mo.angle-(ANGLE_90)), mo.y + 64 * sin(mo.angle-(ANGLE_90)), mo.z +25*FRACUNIT)
				mo.leftbattery.angle = mo.angle
				//mo.leftbattery.flags = $|(MF_NOBLOCKMAP|MF_ENEMY|MF_SPECIAL|MF_SHOOTABLE)
				P_TeleportMove(mo.rightbattery, mo.x + 64 * cos(mo.angle+(ANGLE_90)), mo.y + 64 * sin(mo.angle+(ANGLE_90)), mo.z +25*FRACUNIT)
				mo.rightbattery.angle = mo.angle
				//mo.rightbattery.flags = $|(MF_NOBLOCKMAP|MF_ENEMY|MF_SPECIAL|MF_SHOOTABLE)
			end
	end

end, MT_EGGOVERLORD)

addHook("MobjThinker", function(mo)
	if mo.momx == 0 and mo.momy == 0 then
		P_RemoveMobj(mo)
	end
end, MT_SSPKO1)

//----- when shield collides with player push them back---//
addHook("TouchSpecial", function(touchshield, mo) 

touchshield.pushangle = R_PointToAngle2(touchshield.x, touchshield.y, mo.x, mo.y)
	if touchshield.pushangle then
	S_StartSound(mo, 399) // shield hit
	P_InstaThrust(mo, touchshield.pushangle, FixedMul(40*FRACUNIT, mo.scale))
	P_SetObjectMomZ(mo, 10*FRACUNIT, false)
	end
	
	return true

end, MT_ENERGYBUBBLE)

//----------------shield on death tell boss to be hitabule -----------------------//
addHook("MobjRemoved", function(mo)
	if mo.tracer and mo.tracer.valid then
		mo.tracer.flags = $|(MF_SPECIAL|MF_SHOOTABLE)
		
	end
end, MT_ENERGYBUBBLE)

//-------------------------prevent antangabule shield generators-------------------------//
addHook("MobjDeath", function(mo, inflictor, damagetype)
	//print(damagetype)
	mo.health = 1000
	//I have no idea what flags death changes so we just set the flags the dumb way
	mo.flags = 4194837
	return true
end, MT_LEFTOVERLORD)

addHook("MobjDeath", function(mo, inflictor, damagetype)
	//print(damagetype)
	mo.health = 1000
	//I have no idea what flags death changes so we just set the flags the dumb way
	mo.flags = 4194837
	return true
end, MT_RIGHTOVERLORD)

//------------- remove remade eletric waves if it hits a wall or stops moveing------------//
addHook("MobjThinker", function(wave)
	if wave.once == nill then
	wave.once = false
	wave.friction = 5*FRACUNIT
	end
	if wave.momx == 0 and wave.momy == 0 and wave.once == false then
	wave.state = S_SPRK1
	wave.once = true
	end
end, MT_EEWAVE)

addHook("MobjMoveBlocked", function(wave)
	wave.state = S_SPRK1
end, MT_EEWAVE)

//------------------------prevent the no moveing bug----------------------//
addHook("MobjCollide", function(mo, moveingobj)

	if moveingobj.type == MT_EGGOVERLORD then
		return false
	end
end, MT_RIGHTOVERLORD)

addHook("MobjCollide", function(mo, moveingobj)

	if moveingobj.type == MT_EGGOVERLORD then
		return false
	end
end, MT_LEFTOVERLORD)
