Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
auto.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup flight
4 * @brief Autopilot travel and interstitial flight sequences.
5 *
6 * Address range 403e50-40469f. The Mac auto unit preserves visit_the_cinema,
7 * player_wingman, set_speed, auto_position and auto_pilot_sequence in this
8 * order. The palette-file loader that follows belongs here too: its "rb"
9 * literal follows the initialized formation count in the original data.
10 */
11#include "wc1.h"
12#include <malloc.h>
13#include <float.h>
14#include <assert.h>
15
16/* Linker commons defined here; LINK orders them by identifier hash. */
17unsigned int nSystemKeyDown; /* 0x005a8964 */
18JOYINFO aJoystickInfos[2]; /* 0x005a8970 */
19int nHostMouseMessageX; /* 0x005a8990 */
20
21/* Function start: 0x403E50 */
22void visit_the_cinema(int view, int obj, short frames)
23{
24 int savedOriginUnlock;
25 int savedInputFlag;
26 int savedKeyboardFlag;
27
28 savedOriginUnlock = nOriginDevUnlock;
29 savedInputFlag = bPlayerVulnerable;
30 savedKeyboardFlag = bPlayerCollisionResponse;
34 /* The retail call converts both int parameters implicitly. Making the
35 * narrowing explicit changes the register setup and loses an exact match. */
36 force_view(view, obj);
37 while (frames-- > 0) {
40 DIBslam();
42 }
43 nOriginDevUnlock = savedOriginUnlock;
44 bPlayerVulnerable = savedInputFlag;
45 bPlayerCollisionResponse = savedKeyboardFlag;
46}
47
48/* Function start: 0x403EE0 */
49unsigned int player_wingman(short obj)
50{
51 if (obj != -1 && asShipWingLeaderArray[obj] == 0)
52 return 1;
53 return 0;
54}
55
56/* Function start: 0x403F10 */
57void set_speed(short obj, short speed)
58{
59 anShipSpeed[obj] = (int)speed << 8;
60 fix_velocity(obj);
61}
62
63static short nAutopilotFormationShipCount = 0; /* 0x00465544 */
64
65/* Function start: 0x403F40 */
66void auto_position(short obj, short *formationSlot)
67{
68 short lateral;
69 short vertical;
70 short forward;
71
72 if (player_wingman(obj) != 0) {
77 return;
78 }
79
80 (*formationSlot)++;
81 lateral = (*formationSlot & 1) ? 650 : -650;
82 if (nAutopilotFormationShipCount == *formationSlot)
83 lateral = 0;
84 vertical = 0;
85 forward = MaxShort(1, (short)(*formationSlot >> 1));
86 forward = (short)(forward * -1800);
87 if (nYourWingman != -1) {
88 int radii;
89 int separation;
90
91 radii = asObjectCollisionRadius[obj] +
93 separation = abs(
95 forward);
96 if (radii > separation)
97 vertical = 500;
98 }
100 lateral, vertical, forward);
101}
102
103/* Function start: 0x404050 */
105{
106 short savedCannedSceneMode;
107 short leaveCurrentNavPoint;
108 short formationSlot;
109 FixedVector destination;
110 signed char travelMode[10];
111 FixedVector travelStep;
112 short destinationRange;
113 short other;
114 short ship;
115 short initialDistance;
116 short cruiseSpeed;
117 short nearestShipRange;
118
119 savedCannedSceneMode = (short)nCannedSceneMode;
120 destination = aMissionObjectivesArray[
122 formationSlot = 0;
123 leaveCurrentNavPoint = 1;
124
125 if (auto_pilot_valid(1) != 0) {
128 cCurrentObjective].position,
130 nCurrentNavigationPoint].position) <
132 nCurrentNavigationPoint].proximityRadius + 25)
133 leaveCurrentNavPoint = 0;
134
138
139 for (ship = 0; ship < 10; ship++) {
140 travelMode[ship] = 0;
141 anShipSpeed[ship] = 0;
143 if (aeObjectClass[ship] >= OBJECT_CLASS_SHIP &&
144 aeSpecialManeuvers[ship] !=
146 aeShipSide[ship] == SIDE_IMPERIAL) {
147 if (is_team_member(
148 nShipMissionIndices[ship]) != 0) {
149 if (kilrathi_near(ship, 10000) == 0) {
150 travelMode[ship] = -1;
151 aeSpecialManeuvers[ship] =
153 anRollGoal[ship] = 0;
154 anObjectRollRotationList[ship] = 0;
155 anPitchGoal[ship] = 0;
156 anObjPitchRot[ship] = 0;
157 anYawTarget[ship] = 0;
158 anObjectYawRotation[ship] = 0;
159 if (ship != 0 &&
160 ship != nYourWingman)
162 }
163 } else if (leaveCurrentNavPoint != 0) {
164 remove_object(ship);
165 }
166 }
167 }
168
169 initialDistance = distance_from_point(0, &destination);
170 point_at(0, destination);
171 set_speed(0, 60);
172 travelMode[0] = 1;
173 formationSlot = 0;
174
175 for (ship = 0; ship < 10; ship++) {
176 if (travelMode[ship] == -1 && ship != 0) {
177 if (distance_from_object(ship, 0) > 20000) {
178 if (player_wingman(ship) != 0)
179 travelMode[ship] = 1;
180 else if (equ_vector(
182 &destination) != 0)
183 travelMode[ship] = 2;
184 else
185 travelMode[ship] = 3;
186 } else {
187 if (player_wingman(ship) != 0 ||
189 &destination) != 0)
190 travelMode[ship] = 1;
191 else
192 travelMode[ship] = 3;
193 }
194 if (travelMode[ship] == 1) {
195 auto_position(ship, &formationSlot);
197 0x3c00,
198 &aShipVelocity[ship]);
199 copy_frame(0, ship);
200 anShipSpeed[ship] =
201 anShipSpeed[0];
202 aShipVelocity[ship] =
203 aShipVelocity[0];
204 }
205 }
206 }
207
209 visit_the_cinema(12, 0, 120);
210 while (nCannedSceneMode == 4) {
212 &destination, &travelStep);
213 NormalizeFixedVector(&travelStep);
214 ScaleFixedVector(&travelStep, 0x19000, &travelStep);
215 AddFixedVectors(&aShipPositionsArray[0], &travelStep,
219
220 destinationRange = distance_from_point(0, &destination);
221 nearestShipRange = 0x7fff;
222 for (other = 0; other < 10; other++) {
223 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
224 travelMode[other] == 0)
225 nearestShipRange = MinShort(
226 nearestShipRange, distance_from_object(0, other));
227 }
228
229 if ((unsigned short)destinationRange < 1000 ||
230 pActiveHazardField != 0 ||
231 nearestShipRange < 4000 ||
232 report_kilrathi_rout(1) != 0)
233 nCannedSceneMode = savedCannedSceneMode;
234 }
235
238 cruiseSpeed = asShipMaximumSpeedArray[0];
239 for (ship = 0; ship < 10; ship++) {
240 if (travelMode[ship] != 0) {
241 short shipCruiseSpeed;
242
243 shipCruiseSpeed = aObjectTypeData[
245 if (shipCruiseSpeed < cruiseSpeed)
246 cruiseSpeed = shipCruiseSpeed;
247 }
248 }
249
250 formationSlot = 0;
251 for (ship = 0; ship < 10; ship++) {
252 if (travelMode[ship] != 0) {
253 set_speed(ship, cruiseSpeed);
254 if (ship != 0) {
255 switch (travelMode[ship]) {
256 case 1:
257 case 2:
258 auto_position(ship, &formationSlot);
259 break;
260 case 3:
262 ship,
263 &aShipDestinationsArray[ship]) <
264 initialDistance)
265 aShipPositionsArray[ship] =
267 break;
268 }
269 }
270 }
271 }
272
274 if (bCockpitlessView == 0) {
275 force_view(0, 0);
279 } else {
282 (unsigned short)(nScreenWidth - 1),
283 (unsigned short)(nScreenHeight - 1));
286 force_view(0, 0);
289 SetViewportRect(&stSpaceBufferViewport, 0, 0, 319, 199);
294 }
295 }
296}
297
298/* Function start: 0x404610 */
299unsigned short __stdcall LoadPaletteTripletsFile(const char *path)
300{
301 unsigned char *palette;
302 FILE *file;
303
304 palette = AllocateTaggedMemory(0x300, 0);
305 if (palette == 0)
306 return 0;
307 file = fopen(path, "rb");
308 if (file != 0) {
309 fseek(file, 0x30, SEEK_SET);
310 fread(palette, 0x300, 1, file);
312 fclose(file);
313 ReleasePacketHandle(palette);
314 return 1;
315 }
316 ReleasePacketHandle(palette);
317 return 0;
318}
static short nAutopilotFormationShipCount
Definition auto.c:63
enum Side aeShipSide[12]
Definition ending.c:22
short anRollGoal[16]
Definition ending.c:21
ObjectTypeData aObjectTypeData[OBJECT_TYPE_COUNT]
Definition objdata.c:86
short anPitchGoal[16]
Definition screen.c:13
short anObjectRollRotationList[SPACE_OBJECT_COUNT]
Definition screen.c:16
short anObjectYawRotation[SPACE_OBJECT_COUNT]
Definition joycal.c:33
short anObjPitchRot[SPACE_OBJECT_COUNT]
Definition data.c:247
ShortVector aShipFormationDeltaList[10]
Definition data.c:254
FixedVector aShipDestinationsArray[10]
Definition input.c:18
signed char abFlightPathList[MISSION_OBJECTIVE_COUNT]
Definition smart.c:20
JOYINFO aJoystickInfos[2]
Definition auto.c:18
short asShipMaximumSpeedArray[16]
Definition game.c:552
int bCockpitlessView
Definition main.c:39
HazardField * pActiveHazardField
Definition smart.c:18
MissionNavPoint aMissionNavPoints[MISSION_NAV_POINT_COUNT]
Definition game.c:199
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
Definition video.c:21
unsigned int nSystemKeyDown
Definition auto.c:17
short nYourWingman
Definition game.c:61
int nHostMouseMessageX
Definition auto.c:19
FixedVector aShipVelocity[SPACE_OBJECT_COUNT]
Definition smart.c:21
short asObjectCollisionRadius[64]
Definition ending.c:27
int anShipSpeed[64]
Definition data.c:248
short nScreenWidth
Definition data.c:34
Viewport stSpaceBufferViewport
Definition timer.c:13
short asShipWingLeaderArray[16]
Definition comm.c:51
int nCannedSceneMode
Definition main.c:21
signed char cCurrentObjective
Definition game.c:37
MissionObjective aMissionObjectivesArray[MISSION_OBJECTIVE_COUNT]
Definition screen.c:24
short nCurrentNavigationPoint
Definition music.c:90
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
Definition data.c:255
short nScreenHeight
Definition data.c:37
short nShipMissionIndices[10]
Definition game.c:559
FixedVector aShipPositionsArray[SPACE_OBJECT_COUNT]
Definition game.c:556
FixedVector aShipFwdVec[64]
Definition smart.c:17
short nCurrentViewCenterPosY
Definition eventmgr.c:26
short anYawTarget[16]
Definition smart.c:22
signed char cCurrentNavPtIdx
Definition dib.c:96
enum SpecialManeuver aeSpecialManeuvers[12]
Definition game.c:549
int bPlayerCollisionResponse
Definition main.c:37
int bPlayerVulnerable
Definition main.c:36
int nOriginDevUnlock
Definition main.c:34
FixedVector position
Definition wcdata.h:931
short cruiseVelocity
Definition wcdata.h:379
short right
Definition wc1base.h:78
short bottom
Definition wc1base.h:79
short left
Definition wc1base.h:76
short top
Definition wc1base.h:77
Umbrella header for the game core.
void * AllocateTaggedMemory(int size, unsigned short flags)
Definition ending.c:31
short kilrathi_near(short obj, short range)
Definition cockpt.c:501
unsigned int RenderSpaceViewFrame(void)
Definition main.c:1913
void SetMousePosition(int x, int y)
Definition winsys.c:56
void DIBslam(void)
Definition dib.c:513
short distance_between_points(const FixedVector *from, const FixedVector *to)
Definition geom.c:643
short distance_from_point(short obj, const FixedVector *point)
Definition geom.c:655
void __stdcall SetWholePaletteFromTriplets(unsigned char *palette)
Definition mathfp.c:172
void remove_object(short obj)
Definition geom.c:1002
unsigned int force_view(int view, short obj)
Definition spc.c:464
void auto_position(short obj, short *formationSlot)
Definition auto.c:66
void AddFixedVectors(const FixedVector *left, const FixedVector *right, FixedVector *sum)
Definition geom.c:296
unsigned int player_wingman(short obj)
Definition auto.c:49
void position_relative_ijk(FixedVector *position, short obj, short right, short up, short forward)
Definition geom.c:183
unsigned short __stdcall LoadPaletteTripletsFile(const char *path)
Definition auto.c:299
int equ_vector(const FixedVector *left, const FixedVector *right)
Definition geom.c:267
void auto_pilot_sequence(void)
Definition auto.c:104
short MinShort(short a, short b)
Definition mathutil.c:20
void DIBslamReal(void)
Definition dib.c:519
unsigned int GetScreenUpdateFlag(void)
Definition main.c:361
short distance_from_object(short obj, short other)
Definition geom.c:667
void copy_frame(short source, short destination)
Definition geom.c:585
unsigned int initialize_view_buffer(void)
Definition main.c:371
int report_kilrathi_rout(int mode)
Definition logic.c:391
void ResetSoundState(void)
Definition music.c:669
void visit_the_cinema(int view, int obj, short frames)
Definition auto.c:22
void ScaleFixedVector(const FixedVector *vector, int scale, FixedVector *result)
Definition geom.c:322
short auto_pilot_valid(short showReason)
Definition cockpt.c:517
void zero_vector(FixedVector *vector)
Definition geom.c:280
void SubtractFixedVectors(FixedVector *left, FixedVector *right, FixedVector *difference)
Definition geom.c:305
unsigned int fix_velocity(short obj)
Definition ship.c:438
void point_at(short obj, FixedVector point)
Definition geom.c:152
unsigned int Update_3Space(void)
Definition main.c:476
void ReleasePacketHandle(void *handle)
Definition ending.c:50
unsigned int is_team_member(short missionShip)
Definition mission.c:805
void ComputeVectorDelta(const FixedVector *from, const FixedVector *to, FixedVector *delta)
Definition geom.c:314
unsigned int ReleaseStaleNavTarget(void)
Definition main.c:1984
void set_speed(short obj, short speed)
Definition auto.c:57
void __stdcall SetViewportRect(Viewport *viewport, unsigned short left, unsigned short top, unsigned short right, unsigned short bottom)
Definition screens.c:1560
short MaxShort(short a, short b,...)
Definition mathutil.c:29
void clean_up_cockpit(void)
Definition targ.c:141
short NormalizeFixedVector(FixedVector *vector)
Definition geom.c:471
void check_hazards(void)
Definition winmain.c:478
@ SIDE_IMPERIAL
Definition wcdata.h:174
@ SPECIAL_MANEUVER_UNKNOWN_9
Definition wcdata.h:268
@ SPECIAL_MANEUVER_NONE
Definition wcdata.h:258
@ OBJECT_CLASS_SHIP
Definition wcdata.h:50