using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SolarSystem {

	public static int MIN_SCALE_FACTOR_PLANET = 100;
	public static int MAX_SCALE_FACTOR_PLANET = 400;

	public static int MIN_SCALE_FACTOR_STAR = 800;
	public static int MAX_SCALE_FACTOR_STAR = 2000;

	public static int MAX_NUMBER_OF_PLANETS = 8;
	public static int MIN_NUMBER_OF_PLANETS = 4;

	public static int MIN_X_DISTANCE = -300;
	public static int MAX_X_DISTANCE = 300;

	public static int MIN_Z_DISTANCE = 3000;
	public static int MAX_Z_DISTANCE = 5000;

	public static float MAX_ROTATE_SPEED = 50f;
	public static float MIN_ROTATE_SPEED = 10f;

	public List<PlanetaryBody> system;
	public float endZ;

	public bool first;

	public SolarSystem() {
		generateSolarSystem();
		first = true;
	}

	public void generateSolarSystem() {
		system = new List<PlanetaryBody>();
		bool star = true;
		int planetCount = 0;
		float zOffset = 0;
		do {
			float random = Random.value;
			zOffset += Random.Range(MIN_Z_DISTANCE, MAX_Z_DISTANCE);
			//Debug.Log(zOffset);
			if (star && random < 0.1f && !first) {
				system.Add(new PlanetaryBody(Random.Range(MIN_ROTATE_SPEED, MAX_ROTATE_SPEED),
											Random.Range(MIN_SCALE_FACTOR_STAR, MAX_SCALE_FACTOR_STAR),
											Random.Range(MIN_X_DISTANCE, MAX_X_DISTANCE),
											zOffset,
											true));
				star = false;
			}
			else if (planetCount < MAX_NUMBER_OF_PLANETS) {
				first = false;
				planetCount++;
				system.Add(new PlanetaryBody(Random.Range(MIN_ROTATE_SPEED, MAX_ROTATE_SPEED),
											Random.Range(MIN_SCALE_FACTOR_PLANET, MAX_SCALE_FACTOR_PLANET),
											Random.Range(MIN_X_DISTANCE, MAX_X_DISTANCE),
											zOffset,
											false));

			}
		}
		while (star || planetCount < MIN_NUMBER_OF_PLANETS || (planetCount < MAX_NUMBER_OF_PLANETS && Random.value < 0.5f));
		endZ = zOffset;
	}
}
