function SetSpecialSVs()
	StartSimpleHiResJob("WeatherMachineSpinning")
	Logic.SetEntityScriptingValue(Logic.GetEntityIDByName("KerberosWeatherMachine"),18,Float2Int(5.8))
	
	--blocking erzeugende entities
	local tempinvisobjects = 61
	for i = 1, tempinvisobjects,1 do
		assert(IsValid("InvisObject"..i))
		SetVisibility(Logic.GetEntityIDByName("InvisObject"..i),true)
	end
	
	
	local testtowerID = Logic.GetEntityIDByName("testtower")
	SetVisibility(testtowerID,true)
	Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	for i = 1,2,1 do 
		testtowerID = Logic.GetEntityIDByName("BossDoorTower"..i)
		SetVisibility(testtowerID,true)
		Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	end
	Destroied_Trigger = Trigger.RequestTrigger(Events.LOGIC_EVENT_ENTITY_DESTROYED,nil,"testtowerdown",nil,nil)
	testtowerID = Logic.GetEntityIDByName("Bosscannontower")
	Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	testtowerID = Logic.GetEntityIDByName("BossTower1")
	Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	
	testtowerID = Logic.GetEntityIDByName("FinalBase")
	Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	testtowerID = Logic.GetEntityIDByName("KerberosWeatherMachine")
	Logic.SetEntityInvulnerabilityFlag(testtowerID, 1)
	
end

function testtowerdown()
	if Logic.Event.GetEntityID() == Logic.GetEntityIDByName("TowerBanditTower") then
		DestroyEntity("testtower")
		return true
	end
	return false
end

function ReloadfuncForSave()
	local editedbuildings = {"Bosscannontower",
			"testtower",
			"BossTower1",
			"BossDoorTower1",
			"BossDoorTower2"
			}
		for _,towerIDs in ipairs(editedbuildings) do
			if IsAlive(towerIDs) then
				local towerEntityID = Logic.GetEntityIDByName(towerIDs)
				local sentryID = Logic.GetFoundationTop(towerEntityID)
				local towersize
				if HistoryFlag == 1 then
					towersize = Logic.GetEntityScriptingValue(towerEntityID,-29)
				else
					towersize = Logic.GetEntityScriptingValue(towerEntityID,-33)
				end
				if HistoryFlag == 1 then
					Logic.SetEntityScriptingValue(sentryID,-29,towersize)
				else
					Logic.SetEntityScriptingValue(sentryID,-33,towersize)
				end
			end
		end
		Tower1TurretID = Logic.GetFoundationTop(Logic.GetEntityIDByName("BossTower1"))
		
		if waffenstillstand ~= nil then
			MapLocal_StartCountDown(waffenstillstand)
		end
	--GUIzeug
	if LastFightPart  ~= nil then
--[[	if LastFightPart >= 1 then
			Display.GfxSetSetFogParams(1, 0.0, 1.0, 1, 152,172,182, 5000,29000)
			Display.GfxSetSetFogParams(2, 0.0, 1.0, 1, 102,132,142, 3000,29000)
			Display.GfxSetSetFogParams(3, 0.0, 1.0, 1, 152,172,182, 3000,29000)
			Display.GfxSetSetRainEffectStatus(1, 0.0, 1.0, 1)
			Display.GfxSetSetRainEffectStatus(2, 0.0, 1.0, 1)
			Display.GfxSetSetRainEffectStatus(3, 0.0, 1.0, 1)
			Display.GfxSetSetLightParams(1,  0.0, 1.0, 40, -15, -50,  255,70,70, 128,104,72)
			Display.GfxSetSetLightParams(2,  0.0, 1.0, 40, -15, -50,  255,70,70, 128,104,72)
			Display.GfxSetSetLightParams(3,  0.0, 1.0, 40, -15, -50,  255,70,70, 255,234,202)
		end
		]]
		if LastFightPart >= 3 then
			function GUIUpdate_VCTechRaceProgress() end
			function GUIUpdate_GetTeamPoints() end
			function GUIUpdate_VCTechRaceColor(_Player) end
			XGUIEng.ShowWidget("VCMP_Window", 1)
			XGUIEng.ShowWidget("VCMP_Team2", 0)
			XGUIEng.ShowWidget("VCMP_Team3", 0)
			XGUIEng.ShowWidget("VCMP_Team4", 0)
			XGUIEng.ShowWidget("VCMP_Team5", 0)
			XGUIEng.ShowWidget("VCMP_Team6", 0)
			XGUIEng.ShowWidget("VCMP_Team7", 0)
			XGUIEng.ShowWidget("VCMP_Team8", 0)
			XGUIEng.ShowWidget("VCMP_Team2_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team3_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team4_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team5_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team6_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team7_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team8_Shade", 0)
			XGUIEng.ShowWidget("VCMP_Team1Name",0)
			XGUIEng.ShowWidget("VCMP_Team1Player1", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player2", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player3", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player4", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player5", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player6", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player7", 0)
			XGUIEng.ShowWidget("VCMP_Team1Player8", 0)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Window"), 256, 80, 522, 300)
			XGUIEng.ShowWidget("VCMP_Team1TechRace",1)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Team1"),0,0,522,30)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Team1TechRace"),0,0,522,48)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Team1Progress"),12,19,498,10)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Team1ProgressBG"),12,19,498,10)
			XGUIEng.SetWidgetPositionAndSize(XGUIEng.GetWidgetID("VCMP_Team1_Shade"),0,0,522,48)
			XGUIEng.SetMaterialColor(XGUIEng.GetWidgetID("VCMP_Team1Progress"), 0, 120, 0, 0, 255)
			for i = 0,5,1 do XGUIEng.SetMaterialColor(XGUIEng.GetWidgetID("VCMP_Team1_Shade"), i, 255, 255, 255, 255) end
			for i = 0,5,1 do XGUIEng.SetMaterialColor(XGUIEng.GetWidgetID("VCMP_Team1ProgressBG"), i, 50, 50, 50, 255) end
			for i = 0,5,1 do XGUIEng.SetMaterialTexture(XGUIEng.GetWidgetID("VCMP_Team1_Shade"), i, Folders.Map.."testobjekt10.png") end
			BossbalkenCalc(LastFightPart)
		end
	end
end

function WeatherMachineSpinning()
	if Counter.Tick2("weathermachineticker",32) then
		if IsValid("KerberosWeatherMachine") then
			Logic.SetBuildingSubAnim(Logic.GetEntityIDByName("KerberosWeatherMachine"),0, "PB_Weathermachine_Activated_600")
		else 
			return true
		end
	end
	return false
end

function qmod(a, b)
	return a - math.floor(a/b)*b
end

function Int2Float(num)
	if(num == 0) then
		return 0
	end

	local sign = 1

	if(num < 0) then
		num = 2147483648 + num
		sign = -1
	end

	local frac = qmod(num, 8388608)
	local headPart = (num-frac)/8388608
	local expNoSign = qmod(headPart, 256)
	local exp = expNoSign-127
	local fraction = 1
	local fp = 0.5
	local check = 4194304
	for i = 23, 0, -1 do
		if(frac - check) > 0 then
			fraction = fraction + fp
			frac = frac - check
		end
		check = check / 2
		fp = fp / 2
	end
	return fraction * math.pow(2, exp) * sign
end

function bitsInt(num)
	local t={}
	while num>0 do
		rest=qmod(num, 2)
		table.insert(t,1,rest)
		num=(num-rest)/2
	end
	table.remove(t, 1)
	return t
end

function bitsFrac(num, t)
	for i = 1, 48 do
		num = num * 2
		if(num >= 1) then
			table.insert(t, 1)
			num = num - 1
		else
			table.insert(t, 0)
		end
		if(num == 0) then
			return t
		end
	end
	return t
end

function Float2Int(fval)
	if(fval == 0) then
		return 0
	end

	local signed = false
	if(fval < 0) then
		signed = true
		fval = fval * -1
	end
	local outval = 0;
	local bits
	local exp = 0
	if fval >= 1 then
		local intPart = math.floor(fval)
		local fracPart = fval - intPart
		bits = bitsInt(intPart)
		exp = table.getn(bits)
		bitsFrac(fracPart, bits)
	else
		bits = {}
		bitsFrac(fval, bits)
		while(bits[1] == 0) do
			exp = exp - 1
			table.remove(bits, 1)
		end
		exp = exp - 1
		table.remove(bits, 1)
	end

	local bitVal = 4194304
	local start = 1

	for bpos = start, 23 do
		local bit = bits[bpos]
		if(not bit) then
			break;
		end

		if(bit == 1) then
			outval = outval + bitVal
		end
		bitVal = bitVal / 2
	end

	outval = outval + (exp+127)*8388608

	if(signed) then
		outval = outval - 2147483648
	end

	return outval;
end

function CallFuncWithRandomLinePosition(a, b, func)
    local ax = a.X
	local ay = a.Y
	local bx = b.X
	local by = b.Y
	
	-- vector a->b
	local dx = bx - ax
	local dy = by - ay

	
	-- "normalize"
	dx = dx*math.random()
	dy = dy*math.random()
	
		func{X=ax+dx, Y=ay+dy}
end

function round( _n )
	return math.floor( _n + 0.5 );
end

function CallFuncWithCirclePositions(_pos, _range, _spacing, _func)
	-- Validate input
	if type(_pos) == "string" or type(_pos) == "number" then
		_pos = GetPosition(_pos);
	end
	assert( IsValidPosition(_pos), "Benoetigt Position!" );
	assert( type(_range) == "number", "Benoetigt Reichweitenangabe!" );
	_spacing = _spacing or 100;
	assert( type(_spacing) == "number", "Benoetigt Abstandsangabe!" );
	assert( type(_func) == "function", "Benoetigt Funktion!" );
	
	-- Determine angle step size
	local perimeter = 2 * _range * math.pi;
	local n = math.floor(perimeter / _spacing);
	local angleStep = 360/n;
	
	-- Go!
	local nSin;
	local nCos;
	local angle;
	local x,y,eID;
	for i = 0,(n-1),1 do
		angle = i*angleStep;
		nSin = math.sin((math.rad(angle)));
		nCos = math.cos((math.rad(angle)));
		x = _pos.X - nCos*_range;
		y = _pos.Y - nSin*_range;
		_func({X=x,Y=y,r=angle});
	end
end

function RandomFuncInArea(_pos,_range,_func)
	if type(_pos) == "string" or type(_pos) == "number" then
		_pos = GetPosition(_pos);
	end
	assert( IsValidPosition(_pos), "Benoetigt Position!" );
	assert( type(_range) == "number", "Benoetigt Reichweitenangabe!" );
	local direction = math.random(1,360)
	local nSin = math.sin((math.rad(direction)))
	local nCos = math.cos((math.rad(direction)))
	local x = _pos.X - nCos*math.random(1,_range)
	local y = _pos.Y - nSin*math.random(1,_range)
	
	_func({X=x,Y=y})
end