1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2 
3 /*
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef UQM_PLANETS_PLANETS_H_
20 #define UQM_PLANETS_PLANETS_H_
21 
22 #include "libs/mathlib.h"
23 
24 #define END_INTERPLANETARY START_INTERPLANETARY
25 
26 enum PlanetScanTypes
27 {
28 	MINERAL_SCAN = 0,
29 	ENERGY_SCAN,
30 	BIOLOGICAL_SCAN,
31 
32 	NUM_SCAN_TYPES,
33 };
34 
35 #define MAP_WIDTH SIS_SCREEN_WIDTH
36 #define MAP_HEIGHT (75 - SAFE_Y)
37 
38 enum
39 {
40 	BIOLOGICAL_DISASTER = 0,
41 	EARTHQUAKE_DISASTER,
42 	LIGHTNING_DISASTER,
43 	LAVASPOT_DISASTER,
44 
45 	/* additional lander sounds */
46 	LANDER_INJURED,
47 	LANDER_SHOOTS,
48 	LANDER_HITS,
49 	LIFEFORM_CANNED,
50 	LANDER_PICKUP,
51 	LANDER_FULL,
52 	LANDER_DEPARTS,
53 	LANDER_RETURNS,
54 	LANDER_DESTROYED
55 };
56 
57 #define MAX_SCROUNGED 50 /* max lander can hold */
58 
59 #define SCALE_RADIUS(r) ((r) << 6)
60 #define UNSCALE_RADIUS(r) ((r) >> 6)
61 #define MAX_ZOOM_RADIUS SCALE_RADIUS(128)
62 #define MIN_ZOOM_RADIUS (MAX_ZOOM_RADIUS>>3)
63 #define EARTH_RADIUS SCALE_RADIUS(8)
64 
65 #define MIN_PLANET_RADIUS SCALE_RADIUS (4)
66 #define MAX_PLANET_RADIUS SCALE_RADIUS (124)
67 
68 #define DISPLAY_FACTOR ((SIS_SCREEN_WIDTH >> 1) - 8)
69 
70 #define NUM_SCANDOT_TRANSITIONS 4
71 
72 #define MIN_MOON_RADIUS 35
73 #define MOON_DELTA 20
74 
75 #define MAX_SUNS 1
76 #define MAX_PLANETS 16
77 #define MAX_MOONS 4
78 
79 #define MAP_BORDER_HEIGHT  5
80 #define SCAN_SCREEN_HEIGHT (SIS_SCREEN_HEIGHT - MAP_HEIGHT - MAP_BORDER_HEIGHT)
81 
82 #define PLANET_ROTATION_TIME (ONE_SECOND * 12)
83 #define PLANET_ROTATION_RATE (PLANET_ROTATION_TIME / MAP_WIDTH)
84 // XXX: -9 to match the original, but why? I have no idea
85 #define PLANET_ORG_Y ((SCAN_SCREEN_HEIGHT - 9) / 2)
86 
87 #define NUM_RACE_RUINS  16
88 
89 typedef struct planet_desc PLANET_DESC;
90 typedef struct star_desc STAR_DESC;
91 typedef struct node_info NODE_INFO;
92 typedef struct planet_orbit PLANET_ORBIT;
93 typedef struct solarsys_state SOLARSYS_STATE;
94 
95 
96 #include "generate.h"
97 #include "../menustat.h"
98 #include "../units.h"
99 
100 #include "elemdata.h"
101 #include "lifeform.h"
102 #include "plandata.h"
103 #include "sundata.h"
104 
105 #if defined(__cplusplus)
106 extern "C" {
107 #endif
108 
109 struct planet_desc
110 {
111 	DWORD rand_seed;
112 
113 	BYTE data_index;
114 	BYTE NumPlanets;
115 	SIZE radius;
116 	POINT location;
117 
118 	Color temp_color;
119 	COUNT NextIndex;
120 	STAMP image;
121 
122 	PLANET_DESC *pPrevDesc;
123 			// The Sun or planet that this world is orbiting around.
124 };
125 
126 struct star_desc
127 {
128 	POINT star_pt;
129 	BYTE Type;
130 	BYTE Index;
131 	BYTE Prefix;
132 	BYTE Postfix;
133 };
134 
135 struct node_info
136 {
137 	// This structire is filled in when a generateMinerals, generateEnergy,
138 	// or generateLife call is made.
139 	POINT loc_pt;
140 			// Position of the mineral/bio/energy node on the planet.
141 	COUNT density;
142 			// For bio and energy: undefined
143 			// For minerals the low byte is the gross size of the
144 			// deposit (this determines the image), and the high
145 			// byte is the fine size (the actual quantity).
146 	COUNT type;
147 			// For minerals: the type of element
148 			// For bio: the type of the creature.
149 			//          0 through NUM_CREATURE_TYPES - 1 are normal creatures,
150 			//          NUM_CREATURE_TYPES     is an Evil One
151 			//          NUM_CREATURE_TYPES + 1 is a Brainbox Bulldozer
152 			//          NUM_CREATURE_TYPES + 2 is Zex' Beauty
153 			// For energy: undefined
154 };
155 
156 struct planet_orbit
157 {
158 	FRAME TopoZoomFrame;
159 			// 4x scaled topo image for planet-side
160 	SBYTE  *lpTopoData;
161 			// normal topo data; expressed in elevation levels
162 			// data is signed for planets other than gas giants
163 			// transformed to light variance map for 3d planet
164 	FRAME SphereFrame;
165 			// rotating 3d planet frames (current and next)
166 	FRAME ObjectFrame;
167 			// any extra planetary object (shield, atmo, rings)
168 			// automatically drawn if present
169 	FRAME TintFrame;
170 			// tinted topo images for current scan type (dynamic)
171 	Color TintColor;
172 			// the color of the last used tint
173 	Color *TopoColors;
174 			// RGBA version of topo image; for 3d planet
175 	Color *ScratchArray;
176 			// temp RGBA data for whatever transforms (nuked often)
177 	FRAME WorkFrame;
178 			// any extra frame workspace (for dynamic objects)
179 };
180 
181 // See doc/devel/generate for information on how this structure is
182 // filled.
183 struct solarsys_state
184 {
185 	// Standard field required by DoInput()
186 	BOOLEAN (*InputFunc) (struct solarsys_state *);
187 
188 	BOOLEAN InIpFlight;
189 			// Set to TRUE when player is flying around in interplanetary
190 			// Reset to FALSE when going into orbit or encounter
191 
192 	COUNT WaitIntersect;
193 			// Planet/moon number with which the flagship should not collide
194 			// For example, if the player just left the planet or inner system
195 			// If set to (COUNT)~0, all planet collisions are disabled until
196 			// the flagship stops intersecting with all planets.
197 	PLANET_DESC SunDesc[MAX_SUNS];
198 	PLANET_DESC PlanetDesc[MAX_PLANETS];
199 			// Description of the planets in the system.
200 			// Only defined after a call to (*genFuncs)->generatePlanets()
201 			// and overwritten by subsequent calls.
202 	PLANET_DESC MoonDesc[MAX_MOONS];
203 			// Description of the moons orbiting the planet pointed to
204 			// by pBaseDesc.
205 			// Only defined after a call to (*genFuncs)->generateMoons()
206 			// as its argument, and overwritten by subsequent calls.
207 	PLANET_DESC *pBaseDesc;
208 			// In outer system: points to PlanetDesc[]
209 			// In inner system: points to MoonDesc[]
210 	PLANET_DESC *pOrbitalDesc;
211 			// In orbit: points into PlanetDesc or MoonDesc to the planet
212 			// currently orbiting.
213 			// In inner system: points into PlanetDesc to the planet whose
214 			// inner system the ship is inside
215 	SIZE FirstPlanetIndex, LastPlanetIndex;
216 			// The planets get sorted on their image.origin.y value.
217 			// PlanetDesc[FirstPlanetIndex] is the planet with the lowest
218 			// image.origin.y, and PlanetDesc[LastPlanetIndex] has the
219 			// highest image.origin.y.
220 			// PlanetDesc[PlanetDesc[i].NextIndex] is the next planet
221 			// after PlanetDesc[i] in the ordering.
222 
223 	BYTE turn_counter;
224 	BYTE turn_wait;
225 	BYTE thrust_counter;
226 	BYTE max_ship_speed;
227 
228 	STRING XlatRef;
229 	const void *XlatPtr;
230 	COLORMAP OrbitalCMap;
231 
232 	SYSTEM_INFO SysInfo;
233 
234 	const GenerateFunctions *genFuncs;
235 			// Functions to call to fill in various parts of this structure.
236 			// See generate.h, doc/devel/generate
237 
238 	FRAME PlanetSideFrame[3 + MAX_LIFE_VARIATION];
239 			/* Frames for planet-side elements.
240 			 * [0] = bio cannister
241 			 * [1] = energy node (world-specific)
242 			 * [2] = unused (formerly static slave shield, presumed)
243 			 * [3] = bio 1 (world-specific)
244 			 * [4] = bio 2 (world-specific)
245 			 * [5] = bio 3 (world-specific)
246 			 */
247 	FRAME TopoFrame;
248 	PLANET_ORBIT Orbit;
249 	BOOLEAN InOrbit;
250 			// Set to TRUE when player hits a world in an inner system
251 			// Homeworld encounters count as 'in orbit'
252 };
253 
254 extern SOLARSYS_STATE *pSolarSysState;
255 extern MUSIC_REF SpaceMusic;
256 extern CONTEXT PlanetContext;
257 
258 // Random context used for all solar system, planets and surfaces generation
259 extern RandomContext *SysGenRNG;
260 
261 bool playerInSolarSystem (void);
262 bool playerInPlanetOrbit (void);
263 bool playerInInnerSystem (void);
264 bool worldIsPlanet (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
265 bool worldIsMoon (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
266 COUNT planetIndex (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
267 COUNT moonIndex (const SOLARSYS_STATE *solarSys, const PLANET_DESC *moon);
268 #define MATCH_PLANET ((BYTE) -1)
269 bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world,
270 		BYTE planetI, BYTE moonI);
271 
272 DWORD GetRandomSeedForStar (const STAR_DESC *star);
273 
274 POINT locationToDisplay (POINT pt, SIZE scaleRadius);
275 POINT displayToLocation (POINT pt, SIZE scaleRadius);
276 POINT planetOuterLocation (COUNT planetI);
277 
278 extern void LoadPlanet (FRAME SurfDefFrame);
279 extern void DrawPlanet (int dy, Color tintColor);
280 extern void FreePlanet (void);
281 extern void LoadStdLanderFont (PLANET_INFO *info);
282 extern void FreeLanderFont (PLANET_INFO *info);
283 
284 extern void ExploreSolarSys (void);
285 extern void DrawStarBackGround (void);
286 extern void XFormIPLoc (POINT *pIn, POINT *pOut, BOOLEAN ToDisplay);
287 extern void DrawOval (RECT *pRect, BYTE num_off_pixels);
288 extern void DrawFilledOval (RECT *pRect);
289 extern void FillOrbits (SOLARSYS_STATE *system, BYTE NumPlanets,
290 		PLANET_DESC *pBaseDesc, BOOLEAN TypesDefined);
291 extern void InitLander (BYTE LanderFlags);
292 
293 extern void InitSphereRotation (int direction, BOOLEAN shielded);
294 extern void UninitSphereRotation (void);
295 extern void PrepareNextRotationFrame (void);
296 extern void DrawPlanetSphere (int x, int y);
297 extern void DrawDefaultPlanetSphere (void);
298 extern void RenderPlanetSphere (FRAME Frame, int offset, BOOLEAN doThrob);
299 extern void SetShieldThrobEffect (FRAME FromFrame, int offset, FRAME ToFrame);
300 
301 extern void ZoomInPlanetSphere (void);
302 extern void RotatePlanetSphere (BOOLEAN keepRate);
303 
304 extern void DrawScannedObjects (BOOLEAN Reversed);
305 extern void GeneratePlanetSurface (PLANET_DESC *pPlanetDesc,
306 		FRAME SurfDefFrame);
307 extern void DeltaTopography (COUNT num_iterations, SBYTE *DepthArray,
308 		RECT *pRect, SIZE depth_delta);
309 
310 extern void DrawPlanetSurfaceBorder (void);
311 
312 extern UNICODE* GetNamedPlanetaryBody (void);
313 extern void GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize);
314 
315 extern void PlanetOrbitMenu (void);
316 extern void SaveSolarSysLocation (void);
317 
318 #if defined(__cplusplus)
319 }
320 #endif
321 
322 #endif /* UQM_PLANETS_PLANETS_H_ */
323