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 #include "genall.h"
20 #include "../lander.h"
21 #include "../planets.h"
22 #include "../../build.h"
23 #include "../../comm.h"
24 #include "../../gendef.h"
25 #include "../../starmap.h"
26 #include "../../globdata.h"
27 #include "../../ipdisp.h"
28 #include "../../nameref.h"
29 #include "../../setup.h"
30 #include "../../state.h"
31 #include "libs/mathlib.h"
32 
33 
34 static bool GenerateThraddash_generatePlanets (SOLARSYS_STATE *solarSys);
35 static bool GenerateThraddash_generateOrbital (SOLARSYS_STATE *solarSys,
36 		PLANET_DESC *world);
37 static COUNT GenerateThraddash_generateEnergy (const SOLARSYS_STATE *,
38 		const PLANET_DESC *world, COUNT whichNode, NODE_INFO *);
39 static bool GenerateThraddash_pickupEnergy (SOLARSYS_STATE *solarSys,
40 		PLANET_DESC *world, COUNT whichNode);
41 
42 
43 const GenerateFunctions generateThraddashFunctions = {
44 	/* .initNpcs         = */ GenerateDefault_initNpcs,
45 	/* .reinitNpcs       = */ GenerateDefault_reinitNpcs,
46 	/* .uninitNpcs       = */ GenerateDefault_uninitNpcs,
47 	/* .generatePlanets  = */ GenerateThraddash_generatePlanets,
48 	/* .generateMoons    = */ GenerateDefault_generateMoons,
49 	/* .generateName     = */ GenerateDefault_generateName,
50 	/* .generateOrbital  = */ GenerateThraddash_generateOrbital,
51 	/* .generateMinerals = */ GenerateDefault_generateMinerals,
52 	/* .generateEnergy   = */ GenerateThraddash_generateEnergy,
53 	/* .generateLife     = */ GenerateDefault_generateLife,
54 	/* .pickupMinerals   = */ GenerateDefault_pickupMinerals,
55 	/* .pickupEnergy     = */ GenerateThraddash_pickupEnergy,
56 	/* .pickupLife       = */ GenerateDefault_pickupLife,
57 };
58 
59 
60 static bool
GenerateThraddash_generatePlanets(SOLARSYS_STATE * solarSys)61 GenerateThraddash_generatePlanets (SOLARSYS_STATE *solarSys)
62 {
63 	COUNT angle;
64 
65 	GenerateDefault_generatePlanets (solarSys);
66 
67 	if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED)
68 	{
69 		solarSys->PlanetDesc[0].data_index = PRIMORDIAL_WORLD;
70 		solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 65L / 100;
71 		angle = ARCTAN (solarSys->PlanetDesc[0].location.x,
72 				solarSys->PlanetDesc[0].location.y);
73 		solarSys->PlanetDesc[0].location.x =
74 				COSINE (angle, solarSys->PlanetDesc[0].radius);
75 		solarSys->PlanetDesc[0].location.y =
76 				SINE (angle, solarSys->PlanetDesc[0].radius);
77 	}
78 	else  /* CurStarDescPtr->Index == THRADD_DEFINED */
79 	{
80 		solarSys->PlanetDesc[0].data_index = WATER_WORLD;
81 		solarSys->PlanetDesc[0].NumPlanets = 0;
82 		solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 98L / 100;
83 		angle = ARCTAN (solarSys->PlanetDesc[0].location.x,
84 				solarSys->PlanetDesc[0].location.y);
85 		solarSys->PlanetDesc[0].location.x =
86 				COSINE (angle, solarSys->PlanetDesc[0].radius);
87 		solarSys->PlanetDesc[0].location.y =
88 				SINE (angle, solarSys->PlanetDesc[0].radius);
89 	}
90 	return true;
91 }
92 
93 static bool
GenerateThraddash_generateOrbital(SOLARSYS_STATE * solarSys,PLANET_DESC * world)94 GenerateThraddash_generateOrbital (SOLARSYS_STATE *solarSys,
95 		PLANET_DESC *world)
96 {
97 	if (matchWorld (solarSys, world, 0, MATCH_PLANET))
98 	{
99 		if (StartSphereTracking (THRADDASH_SHIP)
100 				&& (CurStarDescPtr->Index == THRADD_DEFINED
101 				|| (!GET_GAME_STATE (HELIX_UNPROTECTED)
102 				&& (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3)))
103 		{
104 			NotifyOthers (THRADDASH_SHIP, IPNL_ALL_CLEAR);
105 			PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP);
106 			ReinitQueue (&GLOBAL (ip_group_q));
107 			assert (CountLinks (&GLOBAL (npc_built_ship_q)) == 0);
108 
109 			CloneShipFragment (THRADDASH_SHIP, &GLOBAL (npc_built_ship_q),
110 					INFINITE_FLEET);
111 
112 			GLOBAL (CurrentActivity) |= START_INTERPLANETARY;
113 			if (CurStarDescPtr->Index == THRADD_DEFINED)
114 			{
115 				SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7);
116 			}
117 			else
118 			{
119 				SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 6);
120 			}
121 			InitCommunication (THRADD_CONVERSATION);
122 
123 			if (GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
124 				return true;
125 
126 			GLOBAL (CurrentActivity) &= ~START_INTERPLANETARY;
127 			ReinitQueue (&GLOBAL (npc_built_ship_q));
128 			GetGroupInfo (GROUPS_RANDOM, GROUP_LOAD_IP);
129 
130 			if (CurStarDescPtr->Index == THRADD_DEFINED
131 					|| (!GET_GAME_STATE (HELIX_UNPROTECTED)
132 					&& (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3))
133 				return true;
134 
135 			RepairSISBorder ();
136 		}
137 
138 		if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED
139 				&& !GET_GAME_STATE (AQUA_HELIX))
140 		{
141 			LoadStdLanderFont (&solarSys->SysInfo.PlanetInfo);
142 			solarSys->PlanetSideFrame[1] =
143 					CaptureDrawable (LoadGraphic (AQUA_MASK_PMAP_ANIM));
144 			solarSys->SysInfo.PlanetInfo.DiscoveryString =
145 					CaptureStringTable (LoadStringTable (AQUA_STRTAB));
146 		}
147 		else if (CurStarDescPtr->Index == THRADD_DEFINED)
148 		{
149 			LoadStdLanderFont (&solarSys->SysInfo.PlanetInfo);
150 			solarSys->PlanetSideFrame[1] =
151 					CaptureDrawable (LoadGraphic (RUINS_MASK_PMAP_ANIM));
152 			solarSys->SysInfo.PlanetInfo.DiscoveryString =
153 					CaptureStringTable (LoadStringTable (RUINS_STRTAB));
154 		}
155 	}
156 
157 	GenerateDefault_generateOrbital (solarSys, world);
158 	return true;
159 }
160 
161 static COUNT
GenerateThraddash_generateEnergy(const SOLARSYS_STATE * solarSys,const PLANET_DESC * world,COUNT whichNode,NODE_INFO * info)162 GenerateThraddash_generateEnergy (const SOLARSYS_STATE *solarSys,
163 		const PLANET_DESC *world, COUNT whichNode, NODE_INFO *info)
164 {
165 	if (CurStarDescPtr->Index == THRADD_DEFINED
166 			&& matchWorld (solarSys, world, 0, MATCH_PLANET))
167 	{
168 		return GenerateDefault_generateRuins (solarSys, whichNode, info);
169 	}
170 
171 	if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED
172 			&& matchWorld (solarSys, world, 0, MATCH_PLANET))
173 	{
174 		// This check is redundant since the retrieval bit will keep the
175 		// node from showing up again
176 		if (GET_GAME_STATE (AQUA_HELIX))
177 		{	// already picked up
178 			return 0;
179 		}
180 
181 		return GenerateDefault_generateArtifact (solarSys, whichNode, info);
182 	}
183 
184 	return 0;
185 }
186 
187 static bool
GenerateThraddash_pickupEnergy(SOLARSYS_STATE * solarSys,PLANET_DESC * world,COUNT whichNode)188 GenerateThraddash_pickupEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
189 		COUNT whichNode)
190 {
191 	if (CurStarDescPtr->Index == THRADD_DEFINED
192 			&& matchWorld (solarSys, world, 0, MATCH_PLANET))
193 	{
194 		// Standard ruins report
195 		GenerateDefault_landerReportCycle (solarSys);
196 		return false;
197 	}
198 
199 	if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED
200 			&& matchWorld (solarSys, world, 0, MATCH_PLANET))
201 	{
202 		assert (!GET_GAME_STATE (AQUA_HELIX) && whichNode == 0);
203 
204 		GenerateDefault_landerReport (solarSys);
205 		SetLanderTakeoff ();
206 
207 		SET_GAME_STATE (HELIX_VISITS, 0);
208 		SET_GAME_STATE (AQUA_HELIX, 1);
209 		SET_GAME_STATE (AQUA_HELIX_ON_SHIP, 1);
210 		SET_GAME_STATE (HELIX_UNPROTECTED, 1);
211 
212 		return true; // picked up
213 	}
214 
215 	(void) whichNode;
216 	return false;
217 }
218