Log in

Slord #8 [335.3]

780 rounds, 583 wins, 196 losses, 1 draws

Ships

AI-RR-C

{"name": "AI-RR-C", "parts": [{"name": "core","type": "brain","pos": [0,0],"rot": 0,"welds": [1,2,3,4]},{"type": "hull","pos": [-1,0],"rot": 0,"welds": [9,22]},{"type": "hull","pos": [1,0],"rot": 0,"welds": [5,10]},{"name": "rangerMid","type": "ranger","pos": [0,1],"rot": 0},{"name": "gyro","type": "gyroscope","pos": [0,-1],"rot": 0,"welds": [24]},{"type": "hull","pos": [2,0],"rot": 0,"welds": [7,18]},{"type": "hull","pos": [-3,0],"rot": 0,"welds": [22,13,15]},{"type": "hull","pos": [3,0],"rot": 0,"welds": [8,16]},{"type": "hull","pos": [4,0],"rot": 0,"welds": [12,20]},{"name": "rocketL","type": "rocket_launcher","pos": [-1,1],"rot": 0},{"name": "rocketR","type": "rocket_launcher","pos": [1,1],"rot": 0},{"name": "bigThrustL","type": "big_thruster","pos": [-4,-1],"rot": 0},{"name": "bigThrustR","type": "big_thruster","pos": [4,-1],"rot": 0},{"type": "hull","pos": [-4,0],"rot": 0,"welds": [11,19]},{"type": "hull","pos": [0,-3],"rot": 0,"welds": [23,24]},{"name": "rangerL","type": "ranger","pos": [-3,1],"rot": 0},{"name": "rangerR","type": "ranger","pos": [3,1],"rot": 0},{"name": "turretL","type": "rocket_launcher","pos": [-2,1],"rot": 0,"welds": [22]},{"name": "turretR","type": "rocket_launcher","pos": [2,1],"rot": 0},{"name": "turretL2","type": "rocket_launcher","pos": [-4,1],"rot": 0},{"name": "turretR2","type": "rocket_launcher","pos": [4,1],"rot": 0},{"type": "hull","pos": [-1,-3],"rot": 0,"welds": [14,25]},{"type": "hull","pos": [-2,0],"rot": 0},{"type": "hull","pos": [1,-3],"rot": 0,"welds": [26]},{"type": "hull","pos": [0,-2],"rot": 0},{"name": "thrustL","type": "thruster","pos": [-2,-3],"rot": 3},{"name": "thrustR","type": "thruster","pos": [2,-3],"rot": 1}]}
function Start()
	rotate = true
	lastSeen = 0
	FireGuns()
end

function Update()

	angVel = gyro:AngVel()
	local targetAngVel = 80
	thrustVal = 1 
	UpdateLastSeen()
	
	if(lastSeen < 0 or lastSeen > 0) then
		targetAngVel = targetAngVel * lastSeen
	end
	
	if(rangerMid.alive == true) then
		if(rangerMid:Range() > -1) then --check rangerMid hit something
			if(not rangerMid:IsAlly()) then --if can see enemy
				if(not rangerL:IsAlly()) then -- and not going to hit ally to left...
					if(not rangerR:IsAlly()) then -- or right
						FireGuns() --shoot!
						ReversePower() --come to dead stop, rotationally
						rotate = false
					end
				end
			else
				rotate = true
			end
		else
			rotate = true
		end

		if(rotate == true) then
			FixedRotate(targetAngVel)
		end
	else
		if(not rangerL:IsAlly() and not rangerR:IsAlly()) then --don't shoot friendlies
			FireGuns()
			FixedRotate(200 * lastSeen) --counteract rotation from rockets
		end
	end
	
	UpdateCore()
end

function UpdateLastSeen()

	if(rangerL:Range() > -1) then
		if(not rangerL:IsAlly()) then
			lastSeen = 1
		end
	end
	if(rangerR:Range() > -1) then
		if(not rangerR:IsAlly()) then 
			lastSeen = -1
		end
	end
end

function FixedRotate(targetAngVelocity)
	StopPower()
	if(angVel < targetAngVelocity) then
		LeftPower(1)
	elseif(angVel > targetAngVelocity) then
		RightPower(1)
	end
end

function LeftPower(multiplier)

	thrustL:SetThrust(thrustVal * multiplier)
	bigThrustR:SetThrust(0.1)
	bigThrustL:SetThrust(0)
end

function RightPower(multiplier)

	thrustR:SetThrust(thrustVal * multiplier)
	bigThrustR:SetThrust(0)
	bigThrustL:SetThrust(0.1)
	
end

function StopPower()

	thrustL:SetThrust(0)
	thrustR:SetThrust(0)
	bigThrustR:SetThrust(0)
	bigThrustL:SetThrust(0)

end

function ReversePower()

	StopPower()
	if(angVel > 0) then
		bigThrustL:SetThrust(angVel)
	else
		bigThrustR:SetThrust(angVel)
	end	

end

function UpdateCore()
	if(rangerL.alive and rangerL:Range() > 0) then
		if(rangerL:IsAlly()) then
			--green l
			core:SetColor(0,0,Color(0,255,0))
			core:SetColor(0,1,Color(0,255,0))
			core:SetColor(0,2,Color(0,255,0))
		else
			--red l
			core:SetColor(0,0,Color(255,0,0))
			core:SetColor(0,1,Color(255,0,0))
			core:SetColor(0,2,Color(255,0,0))
		end
	else
		--blue l
		core:SetColor(0,0,Color(0,0,255))
		core:SetColor(0,1,Color(0,0,255))
		core:SetColor(0,2,Color(0,0,255))
	end
	if(rangerMid.alive and rangerMid:Range() > 0) then
		if(rangerMid:IsAlly()) then
			--green m
			core:SetColor(1,0,Color(0,255,0))
			core:SetColor(1,1,Color(0,255,0))
			core:SetColor(1,2,Color(0,255,0))
		else
			--red m
			core:SetColor(1,0,Color(255,0,0))
			core:SetColor(1,1,Color(255,0,0))
			core:SetColor(1,2,Color(255,0,0))
		end
	else
		--blue m
		core:SetColor(1,0,Color(0,0,255))
		core:SetColor(1,1,Color(0,0,255))
		core:SetColor(1,2,Color(0,0,255))
	end
	if(rangerR.alive and rangerR:Range() > 0) then
		if(rangerR:IsAlly()) then
			--green r
			core:SetColor(2,0,Color(0,255,0))
			core:SetColor(2,1,Color(0,255,0))
			core:SetColor(2,2,Color(0,255,0))
		else
			--red r
			core:SetColor(2,0,Color(255,0,0))
			core:SetColor(2,1,Color(255,0,0))
			core:SetColor(2,2,Color(255,0,0))
		end
	
	else
		--blue r
		core:SetColor(2,0,Color(0,0,255))
		core:SetColor(2,1,Color(0,0,255))
		core:SetColor(2,2,Color(0,0,255))
	end
end

function FireGuns()
	StopPower()
	bigThrustL:SetThrust(1) --counteract push-back
	bigThrustR:SetThrust(1)	--
	
	turretL:Fire()
	turretL2:Fire()
	rocketL:Fire()
	
	turretR:Fire()
	turretR2:Fire()
	rocketR:Fire()
	
end