1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #if !defined(UQMDEBUG_H) && (defined(DEBUG) || defined(USE_DEBUG_KEY))
18 #define UQMDEBUG_H
19 
20 #include "clock.h"
21 #include "planets/planets.h"
22 #include "races.h"
23 #include "libs/compiler.h"
24 
25 #include <stdio.h>
26 
27 
28 // If set to true, interactive routines that are called (indirectly) in debug
29 // functions are a no-op.
30 extern BOOLEAN disableInteractivity;
31 
32 // If a function is assigned to this, it will be called from the
33 // Starcon2Main thread, in the main game loop.
34 extern void (* volatile debugHook) (void);
35 
36 // Called on the main() thread when the debug key (symbol 'Debug' in the
37 // keys.cfg) is pressed
38 void debugKeyPressed (void);
39 // Called on the Starcon2Main() thread when the debug key (symbol 'Debug'
40 // in the keys.cfg) is pressed.
41 void debugKeyPressedSynchronous (void);
42 
43 // Forward time to the next event. If skipHEE is set, the event named
44 // HYPERSPACE_ENCOUNTER_EVENT, which normally occurs every game day,
45 // is skipped. Must be called on the Starcon2Main thread.
46 void forwardToNextEvent (BOOLEAN skipHEE);
47 // Generate a list of all events in the event queue.
48 // Must be called on the Starcon2Main thread.
49 void dumpEvents (FILE *out);
50 // Describe one event.
51 void dumpEvent (FILE *out, const EVENT *eventPtr);
52 // Get the name of one event.
53 const char *eventName (BYTE func_index);
54 
55 // Give the flagship a decent equipment for debugging.
56 void equipShip (void);
57 // Give the player all devices.
58 void giveDevices (void);
59 
60 // Remove all escort ships.
61 void clearEscorts (void);
62 
63 // Show all active spheres of influence.
64 void showSpheres (void);
65 
66 // Make the ships of all races available for building at the shipyard.
67 void activateAllShips (void);
68 
69 // Move the Flagship to the destination of the autopilot.
70 // Should only be called from HS/QS.
71 // It can be called from debugHook directly after entering HS/QS though.
72 void doInstantMove (void);
73 
74 
75 // Call a function for all stars.
76 void forAllStars (void (*callback) (STAR_DESC *, void *), void *arg);
77 // Call a function for all planets in a star system.
78 void forAllPlanets (STAR_DESC *star, SOLARSYS_STATE *system,
79 		void (*callback) (STAR_DESC *, SOLARSYS_STATE *, PLANET_DESC *,
80 		void *), void *arg);
81 // Call a function for all moons of a planet.
82 void forAllMoons (STAR_DESC *star, SOLARSYS_STATE *system, PLANET_DESC *planet,
83 		void (*callback) (STAR_DESC *, SOLARSYS_STATE *, PLANET_DESC *,
84 		PLANET_DESC *, void *), void *arg);
85 
86 // Argument to UniverseRecurse()
87 typedef struct
88 {
89 	void (*systemFuncPre) (const STAR_DESC *star,
90 			const SOLARSYS_STATE *system, void *arg);
91 			// Called for each system prior to recursing to its planets.
92 	void (*systemFuncPost) (const STAR_DESC *star,
93 			const SOLARSYS_STATE *system, void *arg);
94 			// Called for each system after recursing to its planets.
95 	void (*planetFuncPre) (const PLANET_DESC *planet, void *arg);
96 			// Called for each planet prior to recursing to its moons.
97 	void (*planetFuncPost) (const PLANET_DESC *planet, void *arg);
98 			// Called for each planet after recursing to its moons.
99 	void (*moonFunc) (const PLANET_DESC *moon, void *arg);
100 			// Called for each moon.
101 	void *arg;
102 			// User data.
103 } UniverseRecurseArg;
104 // Recurse through all systems, planets, and moons in the universe.
105 // Must be called on the Starcon2Main thread.
106 void UniverseRecurse (UniverseRecurseArg *universeRecurseArg);
107 
108 // Describe the entire universe. Must be called on the Starcon2Main thread.
109 void dumpUniverse (FILE *out);
110 // Describe the entire universe, output to a file "./PlanetInfo".
111 // Must be called on the Starcon2Main thread.
112 void dumpUniverseToFile (void);
113 // Describe one star system.
114 void dumpSystem (FILE *out, const STAR_DESC *star,
115 		const SOLARSYS_STATE *system);
116 // Get a star color as a string.
117 const char *bodyColorString (BYTE col);
118 // Get a star type as a string.
119 const char *starTypeString (BYTE type);
120 // Get a string describing special presence in the star system.
121 const char *starPresenceString (BYTE index);
122 // Get a list describing all planets in a star.
123 void dumpPlanets (FILE *out, const STAR_DESC *star);
124 // Describe one planet.
125 void dumpPlanet(FILE *out, const PLANET_DESC *planet);
126 // Describe one moon.
127 void dumpMoon (FILE *out, const PLANET_DESC *moon);
128 // Calculate the total value of all minerals on a world.
129 COUNT calculateMineralValue (const SOLARSYS_STATE *system,
130 		const PLANET_DESC *world);
131 // Determine how much of each mineral type is present on a world
132 void generateMineralIndex(const SOLARSYS_STATE *system,
133 		const PLANET_DESC *world, COUNT minerals[]);
134 // Calculate the total value of all bio on a world.
135 COUNT calculateBioValue (const SOLARSYS_STATE *system,
136 		const PLANET_DESC *world);
137 // Determine how much of each mineral type is present on a world
138 void generateBioIndex(const SOLARSYS_STATE *system,
139 		const PLANET_DESC *world, COUNT bio[]);
140 
141 // Tally the resources for each star system.
142 // Must be called on the Starcon2Main thread.
143 void tallyResources (FILE *out);
144 // Tally the resources for each star system, output to a file
145 // "./ResourceTally". Must be called on the Starcon2Main thread.
146 void tallyResourcesToFile (void);
147 
148 
149 // Call a function for all planet types.
150 void forAllPlanetTypes (void (*callBack) (int, const PlanetFrame *,
151 		void *), void *arg);
152 // Describe one planet type.
153 void dumpPlanetType(FILE *out, int index, const PlanetFrame *planetFrame);
154 // Generate a list of all planet types.
155 void dumpPlanetTypes(FILE *out);
156 // Get a string describing a planet type.
157 const char *planetTypeString (int typeIndex);
158 // Get a string describing the size of a type of planet.
159 const char *worldSizeString (BYTE size);
160 // Get a string describing a planet type map generation algoritm.
161 const char *worldGenAlgoString (BYTE algo);
162 // Get a string describing the severity of a tectonics on a type of planet.
163 const char *tectonicsString (BYTE tectonics);
164 // Get a string describing the atmospheric pressure on a type of planet.
165 const char *atmosphereString (BYTE atmosphere);
166 // Get a string describing the density of a type of planet.
167 const char *densityString (BYTE density);
168 
169 // Get a string describing the quality of a deposit.
170 const char *depositQualityString (BYTE quality);
171 
172 
173 // Find a player ship. Setting playerNr to non-0 is only meaningful in battle.
174 STARSHIP* findPlayerShip (SIZE playerNr);
175 
176 // Resets the crew of the first player (the bottom one) to its maximum.
177 void resetCrewBattle(void);
178 
179 // Resets the energy of the first player (the bottom one) to its maximum.
180 void resetEnergyBattle(void);
181 
182 
183 // Move instantly across hyperspace/quasispace.
184 extern BOOLEAN instantMove;
185 
186 
187 // Dump all game strings.
188 void dumpStrings(FILE *out);
189 
190 
191 // Graphically and textually show all the contexts.
192 // Must be called on the Starcon2Main thread.
193 void debugContexts (void);
194 
195 
196 // To add some day:
197 // - a function to fast forward the game clock to a specifiable time.
198 
199 #endif  /* _DEBUG_H */
200 
201