; ==============================================================================
; Definitions

Const GAME_INIT		= 1		; game modes
Const GAME_INTRO	= 2
Const GAME_PLAY 	= 3
Const GAME_OVER 	= 4

Const CAM_FIRST 	= 1		; first person view
Const CAM_THIRD 	= 2		; third person view

Const AT_CORE		= 1		; player locales
Const AT_SURFACE	= 2
Const AT_ARROW		= 3
Const AT_JUMP		= 4
Const AT_ORBIT		= 5
Const AT_RINGS		= 6
Const AT_LINK		= 7
Const AT_SPACE		= 8

Const MENU_NONE		= 0
Const MENU_INTRO	= 1
Const MENU_MAIN		= 2
Const MENU_PLOT		= 3
Const MENU_HELP		= 4
Const MENU_CREDITS	= 5
Const MENU_QUIT		= 6

Const A_NONE		= 0
Const A_BREATH		= 1		; animation sequences
Const A_STARTWALK	= 2
Const A_WALK		= 3
Const A_STARTRUN	= 4
Const A_RUN			= 5
Const A_STOP		= 6
Const A_LOADBOW		= 7
Const A_TILTBOW		= 8
Const A_LOWERBOW	= 9
Const A_BREATHBOW	= 10

Const TYPE_PLANET	= 1		; collision types
Const TYPE_ARROW	= 2
Const TYPE_TARGET	= 3
Const TYPE_LINK		= 4
Const TYPE_PLAYER	= 5
Const TYPE_CAMERA	= 6

Const ARROW_INIT	= 0		; arrow modes
Const ARROW_ARC		= 1
Const ARROW_SPACE	= 2
Const ARROW_IMPACT	= 3

; ==============================================================================

Const ALPHAMAP_FLAG		= 1+2
Const MIPMAP_FLAG 		= 8

; ==============================================================================

Global GAMESTATE = GAME_INIT
Global MENUSTATE = MENU_NONE
Global PAUSED = False

Global g_orbspd# = 3600.0	; speed for planet orbits (seconds per earth year)
Global plrscl# = 0.1		; scale player to 1/10th of planetary radius
Global bowscl# = 0.5		; scale bow to 1/2 of player's scale

Global g_rfactor# = 1000.0	; make worlds' radius 1/5000th scale
Global sprdist# = 80.0		; how far away the planet 'icons' are from player
Global arcfact# = 0.4		; coefficient to steepen the arrow's parabolic arc

Global g_mini_id = 4

; ==============================================================================

;Collisions TYPE_PLAYER, TYPE_PLANET, 1, 2	; ellipsoid check, slide on impact
;Collisions TYPE_CAMERA, TYPE_PLANET, 1, 2	; ellipsoid check, slide on impact
;Collisions TYPE_CAMERA, TYPE_LINK,   1, 2	; ellipsoid check, slide on impact
Collisions TYPE_PLAYER, TYPE_LINK,   1, 2	; ellipsoid check, slide on impact
Collisions TYPE_LINK, TYPE_PLAYER,   1, 2	; ellipsoid check, slide on impact
;Collisions TYPE_ARROW,  TYPE_TARGET, 1, 1	; ellipsoid check, stop on impact
;Collisions TYPE_ARROW,  TYPE_PLANET, 1, 1	; ellipsoid check, stop on impact

; ==============================================================================

; aliases to be set by LoadGame()
Global sol.Planet
Global mercury.Planet
Global venus.Planet
Global earth.Planet
Global mars.Planet
Global jupiter.Planet
Global saturn.Planet
Global uranus.Planet
Global neptune.Planet
Global pluto.planet

; ==============================================================================

Type Planet
	Field name$, id%, parent.Planet
	Field visited
	
	Field model		; handle to planet's surface entity
	Field sky		; handle to planet's sky entity

	Field surfacetex; surface texture
	Field skytex	; sky texture
	
	Field ringtex$	; ring texture file path
	
	Field ambmusic	; ambient music
	
	Field orbpivot	; pivot at planet's orbital center
	Field moonpivot	; static pivot in planet's core (for tethering moons and such)
	Field ringpivot	; pivot in planet's core (for planetary rings)
	Field campivot	; pivot in planet's core (for camera tethering)
	
	Field radius#	; in km
	Field distance#	; distance from sun (AU)
	Field period#	; orbital period (days)
	Field incline#	; orbital inclination (degrees)
	Field tilt#		; axial tilt (degrees)
	Field ringtilt#
	
	Field flipped	; whether mesh has been flipped
	Field sprite	; icon to represent planet
	
	Field ticks%
	Field theta#
	Field camdist#
	Field oldx#, oldy#, oldz#
	Field dx#, dy#, dz#
End Type

Type Player
	Field state,newstate; CORE, SURFACE, JUMP, ORBIT, RINGS, LINK, SPACE
	Field model 		; 3d entity representing player
	Field bow			; 3d entity representing bow
	Field arrow			; 3d entity representing arrow
	Field arrowflare	; sprite for arrow's flare effect
	Field animode		; animation sequence number or zero if not animating
	Field bowticks		; how many updates arrow has been drawn back
	Field timer#		; countdown from 120 to 0, reset when link created
	Field loc.Planet	; nearby planet data structure
	Field cam.ChaseCam	; ptr to camera data structure
	Field atime#
End Type

Type ChaseCam
	Field state,camera
	Field pitch#		 ; degrees of tilt up/down
End Type

Type Link
	Field p1.Planet, p2.Planet, shape
End Type

Type Particle
	Field entity, name$
	Field r#,g#,b#		; pixel color
	Field x#, y#, z#	; position
	Field Vx#, Vy#, Vz#	; velocity vector
	Field Fx#, Fy#, Fz# ; component force accumulators
	Field ticks			; number of updates since creation
	Field maxticks		; number of updates until deletion
End Type

Type Arrow
	Field state			; ARROW_INIT, ARROW_PLANET, ARROW_SPACE, ARROW_IMPACT
	Field ticks#		; number of updates since creation
	Field maxticks#		; number of updates until deletion
	Field model			; the actual arrow entity
	Field flare			; sprite that follows the arrow
	Field startpivot	; pivot positioned where the arrow was fired
	Field targetpivot	; pivot positioned where the arrow is headed
	Field hit.Planet	; the planet that the arrow hit (used for ARROW_IMPACT state)
	
	Field compression#	; measures how far the arrow was pulled back (1 = not at all, 0 = fully)
	Field speed#		; how far towards the target to move PER SECOND
	Field Xx#,Xy#,Xz#
	Field Yx#,Yy#,Yz#
	Field Zx#,Zy#,Zz#
	Field dz#
	Field normz#
End Type

Type SndEffect
	Field queued#, volume#
	Field name$
	Field sound, channel
	Field pitch
End Type

Type AnimFrames
	Field file_prefix$, file_suffix$
	Field seq_start%, seq_end%
	Field pivot
	Field frames[100]
	Field anim_speed#		; fps
	Field current_frame#
End Type

; ==============================================================================
; Solar System Constants

.planetData
;					    km	 mil km
; moon?, name$,    radius#,   dist#, period#, incl#, tilt#, modelortexture$,  skytex$,  ringtex$
Data -2,"sol",        6960*2,     0,       0,     0,     0, "sol.jpg",            "",               ""
Data 0, "mercury",    2439,    57.9,    88.0,   7.0,  0.01, "mercury.jpg",          "",               ""
Data 0, "venus",      6052,   108.2,   224.7,   3.4, 177.4, "venus.x",              "", "";"venusAlpha.tga", ""
Data 0, "earth",      6378,   149.6,   365.2,   0.0,  23.5, "earthText.tga",        "earthCloud.tga", ""
 Data 1,"the moon",   1738,   0.383,    28.0,   0.0,   0.0, "themoon.jpg",          "",               ""
Data 0, "mars",       3397,   227.9,   687.0,   1.9,  25.2, "mars.x",               "",               ""
Data 0, "jupiter",   71492,   778.6,  4331.0,   1.3,   3.1, "jupiter.jpg",          "", ""
 Data 1,"io",         1815,  0.4216,   1.769,  0.04,   0.0, "MOONS\io.jpg",         "", ""
 Data 1,"ganymede",   2634,    1.07,   7.154, 0.183,   0.0, "MOONS\ganymede.jpg",   "", ""
 Data 1,"europa",     1619,  0.6709,   3.551,  0.47,   0.0, "MOONS\europa.jpg",     "", ""
 Data 1,"callisto",   2403,   1.883,  16.689, 0.281,   0.0, "MOONS\callisto.jpg",   "", ""
;Data 1,"amalthea",
Data 0, "saturn",    60268,  1433.5,   10747,   2.5,  26.7, "saturn.png",           "saturn-clouds.png", "saturnRings.tga"
;Data 1,"titan",      2575, 1.22185,   15.94,  0.33,   0.0, "MOONS\titan.jpg",      "", ""
 Data 1,"tethys",      530, 0.29466,   1.887,  1.09,   0.0, "MOONS\tethys.jpg",     "", ""
 Data 1,"dione",       560, 0.29466,   2.736,  0.02,   0.0, "MOONS\dione.jpg",      "", ""
 Data 1,"mimas",       196, 0.18552,   0.942,  1.53,   0.0, "MOONS\mimas.jpg",      "", ""
 Data 1,"rhea",        765, 0.52704,   4.517,  0.35,   0.0, "MOONS\rhea.jpg",       "", ""
 Data 1,"iapetus",     730,  3.5613,   79.33, 14.72,   0.0, "MOONS\iapetus.jpg",    "", ""
;Data 1,"hyperion",
Data 0, "uranus",    25559, 2870.99,   30680, 0.774, 97.86, "uranus.jpg",           "", "uranusRings.tga"
 Data 1,"oberon",    761.4,  0.5826,  13.463,   0.1,   0.0, "MOONS\oberon.jpg",     "", ""
 Data 1,"titania",   788.9, 0.43584,     8.7,  0.14,   0.0, "MOONS\titania.jpg",    "", ""
 Data 1,"ariel",     578.9, 0.19124,    2.52,  0.31,   0.0, "MOONS\ariel.jpg",      "", ""
 Data 1,"miranda",   235.8, 0.01297,   1.413,  4.22,   0.0, "MOONS\miranda.jpg",    "", ""
 Data 1,"umbriel",   584.7, 0.26597,   4.144,  0.36,   0.0, "MOONS\umbriel.jpg",    "", ""
Data 0, "neptune",   24746,  4504.3,   59800, 1.774, 29.56, "neptune.jpg",          "", ""
 Data 1,"triton",     1350,  0.3548,-5.87685,157.35,   0.0, "MOONS\triton.jpg",     "", ""
Data 0, "pluto",      1195,    5870,   90588,  17.2, 122.5, "Pluto2K.png",          "", ""
 Data 1,"charon",      586, 0.01964,   6.387,  98.8,   0.0, "MOONS\charon-lok.jpg", "", ""
Data -1

; sources:
; http://www.solarviews.com/eng/planetormoonname.html
; http://maps.jpl.nasa.gov


;EntityFX sol,2 ; enable vertex colors 
;LightMesh sol,255,255,0,50,-20,20,-20 ; apply fake lighting 
;sprGlow = CreateSprite(p) 	;trying to create a glow around the sun
;sol\sprGlow = LoadSprite("sunGlow.tga", ALPHAMAP_FLAG)
;SpriteViewMode sol\sprGlow,1