---------------------- Initialization ----------------------

--Initial Number of Autonomous Agents
number_of_agents = 30

--Initial Agent Positions
--  Choices are:
--	  Random_XZ (random on the XZ plane)
--	  Random	(random inside the simulation)
-- 	  Origin    (all Agents start at 0,0,0)
initial_position = "Random"

--Simulation Size
--  This sets the size of the simulation
--  The simulation is always centered on the origin
size_x = 100
size_y = 100
size_z = 100

--Minimum Volume Radius
--  This value is a threshold: when a volume's radius
--  drops below this number, that volume is deleted.
--  Higher values increase performance in some simulations
--  Lower values maybe neccessary for particular simulations
min_vol_radius = 0.25

-------------------- Helper Functions ----------------------
function PrintTable(t)
	for n = 1, #t do
		print( t[n] )
	end
end

----------------------- Agent Script -----------------------
-- This function is called once per agent in the scene
function UpdateAgent(Agent, NumVolumes)
	
	NeighborDistance = 10.0
	CollisionRadius = 0.5
	
	-- Flocking Priority:
	-- #1 (lowest): move randomly
	TurnUpRand(-30, 30)
	TurnLeftRand(-30, 30)
	
	-- #2: Try to steer the same direction as everyone else
	SteerWithNeighbors(NeighborDistance)
	
	-- #3: Don't get too far away
	SteerAtNeighbors(NeighborDistance)
	
	-- #4: Don't hit anyone
	AvoidCollisions(CollisionRadius)
	
	TurnTowardOrigin(0.25)

	StepAgent()
	DropVolume(10.0)
	 
	return 0
end

-- This function is called on each Volume in the scene after the agents have stepped
function UpdateEnvironment(Volume)
	Evaporate(0.75)
end