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 "../planets.h"
21 #include "../../build.h"
22 #include "../../comm.h"
23 #include "../../globdata.h"
24 #include "../../ipdisp.h"
25 #include "../../nameref.h"
26 #include "../../state.h"
27 #include "libs/mathlib.h"
28 
29 
30 static bool GenerateIlwrath_generatePlanets (SOLARSYS_STATE *solarSys);
31 static bool GenerateIlwrath_generateOrbital (SOLARSYS_STATE *solarSys,
32 		PLANET_DESC *world);
33 static COUNT GenerateIlwrath_generateEnergy (const SOLARSYS_STATE *,
34 		const PLANET_DESC *world, COUNT whichNode, NODE_INFO *);
35 static bool GenerateIlwrath_pickupEnergy (SOLARSYS_STATE *solarSys,
36 		PLANET_DESC *world, COUNT whichNode);
37 
38 
39 const GenerateFunctions generateIlwrathFunctions = {
40 	/* .initNpcs         = */ GenerateDefault_initNpcs,
41 	/* .reinitNpcs       = */ GenerateDefault_reinitNpcs,
42 	/* .uninitNpcs       = */ GenerateDefault_uninitNpcs,
43 	/* .generatePlanets  = */ GenerateIlwrath_generatePlanets,
44 	/* .generateMoons    = */ GenerateDefault_generateMoons,
45 	/* .generateName     = */ GenerateDefault_generateName,
46 	/* .generateOrbital  = */ GenerateIlwrath_generateOrbital,
47 	/* .generateMinerals = */ GenerateDefault_generateMinerals,
48 	/* .generateEnergy   = */ GenerateIlwrath_generateEnergy,
49 	/* .generateLife     = */ GenerateDefault_generateLife,
50 	/* .pickupMinerals   = */ GenerateDefault_pickupMinerals,
51 	/* .pickupEnergy     = */ GenerateIlwrath_pickupEnergy,
52 	/* .pickupLife       = */ GenerateDefault_pickupLife,
53 };
54 
55 
56 static bool
GenerateIlwrath_generatePlanets(SOLARSYS_STATE * solarSys)57 GenerateIlwrath_generatePlanets (SOLARSYS_STATE *solarSys)
58 {
59 	COUNT angle;
60 
61 	GenerateDefault_generatePlanets (solarSys);
62 
63 	solarSys->PlanetDesc[0].data_index = PRIMORDIAL_WORLD;
64 	solarSys->PlanetDesc[0].radius = EARTH_RADIUS * 204L / 100;
65 	angle = ARCTAN (
66 			solarSys->PlanetDesc[0].location.x,
67 			solarSys->PlanetDesc[0].location.y);
68 	solarSys->PlanetDesc[0].location.x =
69 			COSINE (angle, solarSys->PlanetDesc[0].radius);
70 	solarSys->PlanetDesc[0].location.y =
71 			SINE (angle, solarSys->PlanetDesc[0].radius);
72 
73 	return true;
74 }
75 
76 static bool
GenerateIlwrath_generateOrbital(SOLARSYS_STATE * solarSys,PLANET_DESC * world)77 GenerateIlwrath_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
78 {
79 	if (matchWorld (solarSys, world, 0, MATCH_PLANET))
80 	{
81 		if (StartSphereTracking (ILWRATH_SHIP))
82 		{
83 			NotifyOthers (ILWRATH_SHIP, IPNL_ALL_CLEAR);
84 			PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP);
85 			ReinitQueue (&GLOBAL (ip_group_q));
86 			assert (CountLinks (&GLOBAL (npc_built_ship_q)) == 0);
87 
88 			CloneShipFragment (ILWRATH_SHIP,
89 					&GLOBAL (npc_built_ship_q), INFINITE_FLEET);
90 
91 			GLOBAL (CurrentActivity) |= START_INTERPLANETARY;
92 			SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7);
93 			InitCommunication (ILWRATH_CONVERSATION);
94 
95 			if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
96 			{
97 				GLOBAL (CurrentActivity) &= ~START_INTERPLANETARY;
98 				ReinitQueue (&GLOBAL (npc_built_ship_q));
99 				GetGroupInfo (GROUPS_RANDOM, GROUP_LOAD_IP);
100 			}
101 			return true;
102 		}
103 		else
104 		{
105 			LoadStdLanderFont (&solarSys->SysInfo.PlanetInfo);
106 			solarSys->PlanetSideFrame[1] =
107 					CaptureDrawable (
108 					LoadGraphic (RUINS_MASK_PMAP_ANIM));
109 			solarSys->SysInfo.PlanetInfo.DiscoveryString =
110 					CaptureStringTable (LoadStringTable (RUINS_STRTAB));
111 		}
112 	}
113 
114 	GenerateDefault_generateOrbital (solarSys, world);
115 
116 	if (matchWorld (solarSys, world, 0, MATCH_PLANET))
117 	{
118 		solarSys->SysInfo.PlanetInfo.Weather = 2;
119 		solarSys->SysInfo.PlanetInfo.Tectonics = 3;
120 	}
121 
122 	return true;
123 }
124 
125 static COUNT
GenerateIlwrath_generateEnergy(const SOLARSYS_STATE * solarSys,const PLANET_DESC * world,COUNT whichNode,NODE_INFO * info)126 GenerateIlwrath_generateEnergy (const SOLARSYS_STATE *solarSys,
127 		const PLANET_DESC *world, COUNT whichNode, NODE_INFO *info)
128 {
129 	if (matchWorld (solarSys, world, 0, MATCH_PLANET))
130 	{
131 		return GenerateDefault_generateRuins (solarSys, whichNode, info);
132 	}
133 
134 	return 0;
135 }
136 
137 static bool
GenerateIlwrath_pickupEnergy(SOLARSYS_STATE * solarSys,PLANET_DESC * world,COUNT whichNode)138 GenerateIlwrath_pickupEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
139 		COUNT whichNode)
140 {
141 	if (matchWorld (solarSys, world, 0, MATCH_PLANET))
142 	{
143 		// Standard ruins report
144 		GenerateDefault_landerReportCycle (solarSys);
145 		return false;
146 	}
147 
148 	(void) whichNode;
149 	return false;
150 }
151