--called by the host at the start of a game, makes the objects in question
function initHost()
	--terrain.callUpdate = 0--skip calling the update function
	--terrain.callWithin = 0
	
	--foreground fogs
	stage.createEmitter("nebulaefog", terrain.centerx, terrain.centery)
	emitter.upload(stage.newClient)
	
	--background fogs (just modify the forground ones)
	stage.createEmitter("nebulaefog", terrain.centerx, terrain.centery)
	emitter.layer = 3
	emitter.dist = 1.2
	emitter.posVar = 200
	--emitter.alpha = .15
	--emitter.alphaVar = .05
	emitter.upload(stage.newClient)

	return 0
end

--called (by the host) every loop
function updateHost()
	--for all tracked ships
	for i = 1, terrain.countTrackedShips() do
		terrain.getTrackedShip(i-1)
		--terrain.GFP("got tracked ship")
	
		--if we're exiting this section of nebula
		if stage.terrain_at(ship) ~= terrain then
			--stop tracking the ship
			terrain.loseShip(ship)
			--terrain.GFP("stopped tracking ship")
		
			--if we're exiting ALL nebula 
			if stage.terrain_at(ship) == nil then-- or stage.terrain_at(ship).name ~= "nebulafog" then
				terrain.GFP("exit all neb")
				--make a final puff of fog (ending the old continuous one)
				stage.createEmitter("nebulaefog_puff", 0, 0)
				emitter.num = 8
				emitter.interval = 0
				emitter.alpha = emitter.alpha/2
				emitter.movrot = ship.movrot
				emitter.movrotVar = 20
				emitter.speed = ship.speed
				emitter.upload(0, ship.getIDNUM(), 1)
			end
		end
	end
	
	
	return 0
end

--called (by the host) when a ship is inside this terrain tile
function shipWithin()
	--if terrain.playerNear > 0 then
		--if ship.behavior ~= "inert" and ship.behavior ~= "warp" then
		if ship.behavior == "player" then
			--if it wasn't inside us and now it is
			if terrain.isTrackingShip(ship) == 0 then
				--start tracking this ship
				terrain.trackShip(ship)

				--make a puff of fog
				stage.createEmitter("nebulaefog_puff", 0, 0)
				emitter.num = 16--omit once we fix things
				emitter.interval = 100
				emitter.upload(0, ship.getIDNUM(), 1)
			end
		end
	--end
	
	--make them invisible to the minimap
	
	return 0
end


--sets the editor/minimap display icon and color
function setIcon()
	icon.frame = 21	--from map_icons.png, which frame to use.
	icon.color = 0	--grey
	return 0
end