#define SUBSYSTEM APPLICATION_EXEC "_star: "

#define STAR_NAME_LEN_MAX 128							/* Star maximum name length */

#define STAR_SOL 299792458.0							/* Speed of light in meters per second */

#define STAR_SUN_LUMINANCE_W 3.846e26						/* Sun luminance in watts */
#define STAR_SUN_MASS_KG 1.98855e30						/* Sun mass in kilograms */
#define STAR_SUN_RADIUS_KM 696342.0						/* Sun radius in kilometers */

#define STAR_COMP_CARBON_MIN 100						/* Star gas minimum and maximum slices */
#define STAR_COMP_CARBON_MAX 500000
#define STAR_COMP_HELIUM_MIN 500000
#define STAR_COMP_HELIUM_MAX 5000000
#define STAR_COMP_IRON_MIN 100
#define STAR_COMP_IRON_MAX 50000
#define STAR_COMP_MAGNESIUM_MIN 100
#define STAR_COMP_MAGNESIUM_MAX 50000
#define STAR_COMP_NEON_MIN 100
#define STAR_COMP_NEON_MAX 50000
#define STAR_COMP_NITROGEN_MIN 100
#define STAR_COMP_NITROGEN_MAX 50000
#define STAR_COMP_OXYGEN_MIN 100
#define STAR_COMP_OXYGEN_MAX 500000
#define STAR_COMP_SILICON_MIN 100
#define STAR_COMP_SILICON_MAX 50000
#define STAR_COMP_SULFUR_MIN 100
#define STAR_COMP_SULFUR_MAX 50000

#define STAR_CLASS_O 1								/* Star classes */
#define STAR_CLASS_B 2
#define STAR_CLASS_A 3
#define STAR_CLASS_F 4
#define STAR_CLASS_G 5
#define STAR_CLASS_K 6
#define STAR_CLASS_M 7
#define STAR_CLASS_L 8
#define STAR_CLASS_T 9
#define STAR_CLASS_Y 10
#define STAR_CLASS_NEUTRON_NEUTRON 11
#define STAR_CLASS_NEUTRON_PULSAR 12
#define STAR_CLASS_NEUTRON_MAGNETAR 13
#define STAR_CLASS_BLACKHOLE_MICRO 14
#define STAR_CLASS_BLACKHOLE_STELLAR 15
#define STAR_CLASS_BLACKHOLE_INTERMEDIATE 16
#define STAR_CLASS_BLACKHOLE_SUPERMASSIVE 17

#define STAR_SPECTRAL_O5 -0.33							/* Star spectral types */
#define STAR_SPECTRAL_O8 -0.32
#define STAR_SPECTRAL_O9 -0.31
#define STAR_SPECTRAL_B0 -0.30
#define STAR_SPECTRAL_B1 -0.265
#define STAR_SPECTRAL_B2 -0.24
#define STAR_SPECTRAL_B3 -0.205
#define STAR_SPECTRAL_B5 -0.17
#define STAR_SPECTRAL_B6 -0.15
#define STAR_SPECTRAL_B7 -0.135
#define STAR_SPECTRAL_B8 -0.11
#define STAR_SPECTRAL_B9 -0.075
#define STAR_SPECTRAL_A0 -0.02
#define STAR_SPECTRAL_A1 0.01
#define STAR_SPECTRAL_A2 0.05
#define STAR_SPECTRAL_A3 0.08
#define STAR_SPECTRAL_A5 0.15
#define STAR_SPECTRAL_A7 0.20
#define STAR_SPECTRAL_A8 0.25
#define STAR_SPECTRAL_F0 0.30
#define STAR_SPECTRAL_F2 0.35
#define STAR_SPECTRAL_F5 0.44
#define STAR_SPECTRAL_F8 0.52
#define STAR_SPECTRAL_G0 0.58
#define STAR_SPECTRAL_G2 0.63
#define STAR_SPECTRAL_G5 0.68
#define STAR_SPECTRAL_G8 0.74
#define STAR_SPECTRAL_K0 0.81
#define STAR_SPECTRAL_K1 0.86
#define STAR_SPECTRAL_K2 0.91
#define STAR_SPECTRAL_K3 0.96
#define STAR_SPECTRAL_K5 1.15
#define STAR_SPECTRAL_K7 1.33
#define STAR_SPECTRAL_M0 1.40
#define STAR_SPECTRAL_M1 1.46
#define STAR_SPECTRAL_M2 1.49
#define STAR_SPECTRAL_M3 1.51
#define STAR_SPECTRAL_M4 1.54
#define STAR_SPECTRAL_M5 1.64
#define STAR_SPECTRAL_M6 1.73
#define STAR_SPECTRAL_M7 1.80
#define STAR_SPECTRAL_M8 1.93

#define STAR_TYPE_DWARF_BROWN 1							/* Star types */
#define STAR_TYPE_DWARF_RED 2
#define STAR_TYPE_DWARF_WHITE 3
#define STAR_TYPE_GIANT_SUB 4
#define STAR_TYPE_GIANT 5
#define STAR_TYPE_GIANT_SUPER 6
#define STAR_TYPE_GIANT_HYPER 7
#define STAR_TYPE_NEUTRON 8
#define STAR_TYPE_BLACKHOLE 9

#define STAR_DRAW_LIGHT_DEFAULT_RED 255						/* Star sphere light colors */
#define STAR_DRAW_LIGHT_DEFAULT_GREEN 155
#define STAR_DRAW_LIGHT_DEFAULT_BLUE 155

#define STAR_DRAW_LIGHT_NEUTRON_RED 155
#define STAR_DRAW_LIGHT_NEUTRON_GREEN 205
#define STAR_DRAW_LIGHT_NEUTRON_BLUE 255

#define STAR_DRAW_LIGHT_BLACKHOLE_RED 255
#define STAR_DRAW_LIGHT_BLACKHOLE_GREEN 255
#define STAR_DRAW_LIGHT_BLACKHOLE_BLUE 205

#define STAR_DRAW_LIGHT_X 0.0							/* Star sphere light position */
#define STAR_DRAW_LIGHT_Y 1.5
#define STAR_DRAW_LIGHT_Z -10.0

#define STAR_DRAW_NOISE_SEED 2147483647						/* Star sphere maximum noise seed */
#define STAR_DRAW_NOISE_TYPE 2							/* Star sphere noise type (for draw_sphere_*_cache()) */

#define STAR_DRAW_PREVIEW_WIDTH 256						/* Star sphere preview size in pixels */
#define STAR_DRAW_PREVIEW_HEIGHT 256

#define STAR_LIVE_ZOOM_STEPS 100.0						/* Star live zoom steps */

#define STAR_SOLAR_NAME_A 25							/* Star solar system name slice count */

struct star_cont {
	unsigned int a, b;							/* Star gas minimum and maximum slices */

	float *c;								/* Star gas percentage */
};

struct star_spect {
	double c;								/* Star spectral type B-V index */

	char *s;								/* Star spectral type name */
};

static char *star_name_p = "VS";						/* Star name prefix */

static char *star_class[] = {
	NULL,									/* Star class names (offset STAR_CLASS_*) */
	"O", "B", "A", "F", "G", "K", "M", "L", "T", "Y",
	"star", "pulsar", "magnetar",
	"micro", "stellar", "intermediate", "supermassive"
};

static char *star_type[] = {
	NULL,									/* Star type names (offset STAR_TYPE_*) */
	"Brown dwarf", "Red dwarf", "White dwarf",
	"Sub giant", "Giant", "Super giant", "Hyper giant",
	"Neutron",
	"Black hole"
};

static char *star_solar_name_a[STAR_SOLAR_NAME_A] = {
	"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",	/* Star solar system name slices */
	"n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"
};

static unsigned int star_flat[] = {
	0,									/* Star rotation speed in kilometers per second (offset to STAR_CLASS_*) */
	190, 200, 210, 190, 160, 95, 25, 12, 1, 0,
	2000, 20000000,
	0, 0, 0, 0
};

static struct star_spect star_spectral[] = {
	{ STAR_SPECTRAL_O5, "O5" },
	{ STAR_SPECTRAL_O8, "O8" },
	{ STAR_SPECTRAL_O9, "O9" },
	{ STAR_SPECTRAL_B0, "B0" },
	{ STAR_SPECTRAL_B1, "B1" },
	{ STAR_SPECTRAL_B2, "B2" },
	{ STAR_SPECTRAL_B3, "B3" },
	{ STAR_SPECTRAL_B5, "B5" },
	{ STAR_SPECTRAL_B6, "B6" },
	{ STAR_SPECTRAL_B7, "B7" },
	{ STAR_SPECTRAL_B8, "B8" },
	{ STAR_SPECTRAL_B9, "B9" },
	{ STAR_SPECTRAL_A0, "A0" },
	{ STAR_SPECTRAL_A1, "A1" },
	{ STAR_SPECTRAL_A2, "A2" },
	{ STAR_SPECTRAL_A3, "A3" },
	{ STAR_SPECTRAL_A5, "A5" },
	{ STAR_SPECTRAL_A7, "A7" },
	{ STAR_SPECTRAL_A8, "A8" },
	{ STAR_SPECTRAL_F0, "F0" },
	{ STAR_SPECTRAL_F2, "F2" },
	{ STAR_SPECTRAL_F5, "F5" },
	{ STAR_SPECTRAL_F8, "F8" },
	{ STAR_SPECTRAL_G0, "G0" },
	{ STAR_SPECTRAL_G2, "G2" },
	{ STAR_SPECTRAL_G5, "G5" },
	{ STAR_SPECTRAL_G8, "G8" },
	{ STAR_SPECTRAL_K0, "K0" },
	{ STAR_SPECTRAL_K1, "K1" },
	{ STAR_SPECTRAL_K2, "K2" },
	{ STAR_SPECTRAL_K3, "K3" },
	{ STAR_SPECTRAL_K5, "K5" },
	{ STAR_SPECTRAL_K7, "K7" },
	{ STAR_SPECTRAL_M0, "M0" },
	{ STAR_SPECTRAL_M1, "M1" },
	{ STAR_SPECTRAL_M2, "M2" },
	{ STAR_SPECTRAL_M3, "M3" },
	{ STAR_SPECTRAL_M4, "M4" },
	{ STAR_SPECTRAL_M5, "M5" },
	{ STAR_SPECTRAL_M6, "M6" },
	{ STAR_SPECTRAL_M7, "M7" },
	{ STAR_SPECTRAL_M8, "M8" },

	{ 0.0, NULL }
};

static void star_create_comp(struct star *);
static void star_create_comp_neutron(struct star *);
static void star_create_comp_blackhole(struct star *);
static float star_create_comp_op(struct star_cont *);
static void star_create_spec(struct star *);
static void star_create_spec_spectral(struct star *, double);
static void star_create_spec_type(struct star *, double, double);
static void star_create_spec_flat(struct star *);
static void star_create_spec_neutron(struct star *);
static void star_create_spec_neutron_type(struct star *);
static void star_create_spec_blackhole(struct star *);
static void star_create_spec_blackhole_type(struct star *, double);
static void star_create_draw(struct star *);
static int star_create_name(struct star *);
static int star_create_nick(struct star *);
static int star_preview_create(struct star *, int, int, double);
static int star_preview_create_op(struct star *, int, int);
static void star_run_burn(struct star *);
static int star_live_op(struct star *);
static void star_live_title(struct star *, unsigned int);

static void star_print_human_op(struct star *, char *, int, float, float, float) __UNUSED__;
