#include "~/Game Data/scripts/server/include/map_util.as"
#include "~/Maps/include/spiral_gas.as"

// Mathematical
const float Pi    = 3.14159265f;
const float twoPi = 6.28318531f;

// Universal
float au = 1000.f;

void makeMap(Galaxy@ Glx) {
	System@ sys;

	// Home system
	@sys = makeHomeSystem(Glx, vector(0, 0, 0));
	sys.addTag("homeSys");

	// Remnant system
	@sys = makeBasicSystem(Glx, vector(-2.f * au, 0, -3.f * au), 3);
	sys.addTag("remnSys");

	// Free system
	@sys = makeBasicSystem(Glx, vector(6.f * au, 0, -3.f * au), 5);
	sys.addTag("freeSys");

	// Neutral system
	@sys = makeBasicSystem(Glx, vector(-4.f * au, 0, 4.f * au), 3);
	sys.addTag("neutSys");

	// Enemy system
	@sys = makeBasicSystem(Glx, vector(6.f * au, 0, 6.f * au), 4);
	sys.addTag("enemSys");
}

System@ makeBasicSystem(Galaxy@ Glx, vector pos, uint planets) {
	// Create the system
	System@ sys = makeSystem(Glx, pos, au);

	// Create the star
	Star@ star = makeStar(sys, 1.f);
	Object@ starObj = star;

	// Create planets
	float orbit = orbitRadiusFactor * 1.f;
	uint outpost = 1;

	for (uint i = 0; i < planets; ++i) {
		orbit += orbitRadiusFactor * randomf(1.f, 2.f);
		makePlanet(sys, rand(15, 25), 0, orbit);
	}

	return sys;
}

System@ makeHomeSystem(Galaxy@ Glx, vector pos) {
	// Create the system
	System@ sys = makeSystem(Glx, pos, au);

	// Create the star
	Star@ star = makeStar(sys, 1.f);
	Object@ starObj = star;

	// Create planets
	float orbit = orbitRadiusFactor * 1.f;
	uint outpost = 1;

	for (uint i = 0; i < 3; ++i) {
		orbit += orbitRadiusFactor * randomf(1.f, 2.f);
		makePlanet(sys, 25, 0, orbit);
	}

	return sys;
}

Planet@ setupHomeworld(System@ sys, Empire@ owner) {
	return null;
}

float range(float low, float high, float pct) {
	return low + (clamp(0.f, 1.f, pct) * (high-low));
}
