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