Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
logic.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup flight
4 * @brief Ship mission logic, resource ownership and scene animation.
5 *
6 * Address range 422010-42572f; its interior boundaries are provisional. The
7 * preceding startup unit has a separate pool of initialized data and string
8 * literals.
9 */
10/* LOGIC was built against an older arrangement of the shared headers than
11 * every other module: nYourWingman is declared earlier, the armor and
12 * tactic arrays in the opposite order, the packet-handle, screen-row and
13 * input-button declarations are absent, and LOGIC's own routines are
14 * prototyped without parameter names. WC1_LOGIC_SOURCE selects that view
15 * in globals.h and wc1funcs.h. It is the one remaining source marker:
16 * giving LOGIC the common view needs symbol-key planning across LOGIC,
17 * SHIP, BRAINS and MUSIC, and splitting the headers for it would need about
18 * thirty compensating declaration moves. */
19#define WC1_LOGIC_SOURCE
20#include <sys/types.h>
21#include "wc1.h"
22#include <crtdbg.h>
23
50 { &pTgtLockShapePtr, 8, 0 },
52 { &pConfedCommBackground, 11, 0 },
53 { &pCommStaticShape, 11, 11 },
54 { &pKilrathiCommBackground, 11, 9 },
55 { &pCockpitExplosionShape, 8, 5 },
56 { &pCockpitIndicatorShape, 8, 4 },
68 { 0, 0, 0 }
69}; /* 0x00469c48 */
71 { &pCockpitDamageShape, -1, 7 },
72 { &pCockpitWeaponShapePtr, -1, 9 },
73 { &pCockpitIndicatorShape, 8, 4 },
74 { &pTgtLockShapePtr, 8, 0 },
75 { 0, 0, 0 }
76}; /* 0x00469ce0 */
78 { &pCockpitPilotShape, -1, 4 },
79 { &pCockpitDamageShape, -1, 7 },
80 { &pCockpitWeaponShapePtr, -1, 9 },
81 { &apCockpitShapesList[0], -1, 0 },
82 { &apCockpitShapesList[1], -1, 1 },
83 { &apCockpitShapesList[2], -1, 2 },
84 { &apCockpitShapesList[3], -1, 3 },
85 { 0, 0, 0 }
86}; /* 0x00469d08 */
87unsigned int bIntroSceneResourcesActive = 1; /* 0x00469d48 */
89 -1, -1, -1, -1
90}; /* 0x00469d50 */
91int bCockpitResourcesActive = 0; /* 0x00469d58 */
92int b3SpaceObjectsActive = 0; /* 0x00469d5c */
94 63, 64, 65, 66, 67, 68, 69, 70
95}; /* 0x00469d60 */
96short bSceneAnimationWaitCommand = 0; /* 0x00469d70 */
97
98/* Linker commons defined here; LINK orders them by identifier hash. */
99unsigned char *pSceneAnimationSceneDataPtr; /* 0x005a7c54 */
101unsigned char *pSceneAnimationTextData; /* 0x005a7c5c */
102unsigned char *pSceneAnimationPacketPtr; /* 0x005a7c60 */
104short nSceneAnimationDelayFrames; /* 0x005a7c68 */
105unsigned char *pSceneAnimationDefinitionsPtr; /* 0x005a7c6c */
106struct Shape *pSceneAnimationSecondaryShape; /* 0x005a7c70 */
107signed char cCockpitLogicalFile; /* 0x005a7c74 */
108struct Shape *apCockpitShapesList[4]; /* 0x005a7c80 */
109struct Shape *pCinematicViewBackdropPtr; /* 0x005a7c90 */
110struct Shape *pLogicRearViewBackdropPtr; /* 0x005a7c94 */
111int bCurrentPlayerDestroyed; /* 0x005a7c98 */
112short nPlayerKillTotal; /* 0x005a7c9c */
113
114/* Function start: 0x422010 */
115short ace_status(short ace, unsigned char bits)
116{
117 return (stCampaignState.aceFlags[ace] & bits) == bits;
118}
119
120/* Function start: 0x422030 */
121void unflag_ace(short ace, unsigned char bits)
122{
123 stCampaignState.aceFlags[ace] &= ~bits;
124}
125
126/* Function start: 0x422050 */
127void flag_ace(short ace, unsigned char bits)
128{
129 stCampaignState.aceFlags[ace] |= bits;
130}
131
132/* Function start: 0x422060 */
133void kill_ace(short ace)
134{
135 if (ace_status(ace, 1) != 0) {
136 unflag_ace(ace, 1);
137 flag_ace(ace, 2);
138 }
139}
140
141/* Function start: 0x422090 */
142void ace_greeting(short obj)
143{
144 short ace = (short)aiPilotLevel[obj] - 14;
145 int message;
146
147 message = ace_status(ace, 4) != 0;
148 send_message(obj, message);
149 flag_ace(ace, 8);
150}
151
152/* Function start: 0x4220D0 */
153void prepare_ace(short ace)
154{
155 unflag_ace(ace, 0x1a);
156 flag_ace(ace, 0x20);
157}
158
159/* Function start: 0x4220F0 */
160short signed_random(short range)
161{
162 return RandomBelowOrEqual((short)(range * 2)) - range;
163}
164
165/* Function start: 0x422110 */
166int alert_flag(short ship, unsigned int bits)
167{
168 return (anShipAlertFlags[ship] & bits) != 0;
169}
170
171/* Function start: 0x422130 */
172/* NOT a constant return: `mov eax,0x59b430 / cmp eax,1 / sbb eax,eax / inc eax`
173 * is the classic `>= 1` boolean idiom applied to the *address* 0x0059B430,
174 * which is always non-zero -- hence Ghidra folding it to `return 1`. Written
175 * the way the original was, so the idiom survives. */
176unsigned int HasSpeechBuffer(void)
177{
178 return (unsigned int)&anShipAlertFlags >= 1;
179}
180
181/* Function start: 0x422140 */
182unsigned short set_alert(short i, unsigned int bits)
183{
184 anShipAlertFlags[i] |= bits;
185 return 0;
186}
187
188/* Function start: 0x422160 */
189void clear_alert(short i)
190{
192 anShipAlertFlags[i] = 0;
193 abCollisionAlertTargets[i] = 0xff;
194}
195
196/* Function start: 0x422180 */
197void start_collision_alert(short obj, short other)
198{
199 if ((short)(signed char)abCollisionAlertTargets[obj] != other) {
200 abCollisionAlertTargets[obj] = (unsigned char)other;
201 steady_object(obj);
202 }
203 asCollisionDelayList[obj] = 3;
204 set_alert(obj, 1);
205 asShipAfterburnerTimer[obj] = 0;
207}
208
209/* Function start: 0x4221E0 */
211{
213 if (asCollisionDelayList[obj] <= 0)
214 clear_alert(obj);
215 else
216 set_alert(obj, 2);
217}
218
219/* Function start: 0x422220 */
220short normal_speed(short obj)
221{
222 if (aeSpecialManeuvers[obj] !=
225 return 1;
226 return 0;
227}
228
229/* Function start: 0x422260 */
230short real_crash_time(short obj, short other)
231{
232 short range;
233 short collisionRadius;
234 short time;
235 short elapsed;
236 short step;
237 int collisionFound;
238 long distance;
239 long relativeSpeed;
240 FixedVector relativePosition;
241 FixedVector relativeVelocity;
242 FixedVector travel;
243 FixedVector separation;
244
245 collisionRadius = *(volatile short *)&asObjectCollisionRadius[obj];
246 collisionRadius += asObjectCollisionRadius[other];
247 collisionRadius += 30;
248 collisionFound = 0;
250 &aShipPositionsArray[other],
251 &relativePosition);
252 distance = Vector_magnitude(&relativePosition);
253 if (((long)collisionRadius + 1500) * 0x100 < distance)
254 return 0x7fff;
255
257 &aShipVelocity[other],
258 &relativeVelocity);
259 relativeSpeed = Vector_magnitude(&relativeVelocity);
260 if (relativeSpeed == 0)
261 return 0x7fbc;
262
264 DivideFixed((int)distance, (int)relativeSpeed));
265 if (time >= 30)
266 return time;
267
268 ScaleFixedVector(&relativeVelocity, (int)time << 8, &travel);
269 AddFixedVectors(&relativePosition, &travel, &separation);
271 Vector_magnitude(&separation));
272 if (range > collisionRadius) {
273 if ((collisionRadius * 2 >> 4) > range)
274 return 25;
275 return 32000;
276 }
277
278 elapsed = 0;
279 do {
280 if (elapsed >= time)
281 break;
282 step = MaxShort(1, (short)((time - elapsed) >> 1));
283 elapsed += step;
284 ScaleFixedVector(&relativeVelocity, (int)elapsed << 8, &travel);
285 AddFixedVectors(&relativePosition, &travel, &separation);
287 Vector_magnitude(&separation));
288 if (collisionRadius >= range)
289 collisionFound = 1;
290 } while (collisionFound == 0);
291 return elapsed;
292}
293
294/* Function start: 0x422440 */
296{
297 short i = 0;
298
299 do {
301 i = i + 1;
302 } while (i < 10);
303}
304
305/* Function start: 0x422460 */
306short crash_time(short obj, short other)
307{
308 if (asCollisionPartnerTable[obj] == other)
309 return asCollisionTimes[obj];
310 if (other < 10 && asCollisionPartnerTable[other] == obj)
311 return asCollisionTimes[other];
312 if (aeObjectClass[other] == OBJECT_CLASS_ASTEROID &&
313 (asObjectScreenXList[other] == -0x7fff ||
314 asObjectScreenXList[obj] == -0x7fff))
315 return 0x7fff;
316 return real_crash_time(obj, other);
317}
318
319/* CL 4.20 uses declaration indices to break register-allocation ties.
320 * These and the later callee declarations preserve the measured context;
321 * each declaration precedes the callee's first use in this unit. */
322unsigned int unactive(short ship);
323
324/* Function start: 0x4224F0 */
325short detect_collisions(short obj)
326{
327 short candidate;
328 short other;
329 short time;
330 short closestTime;
331
332 candidate = -1;
333 closestTime = 30;
334 for (other = 0; other <= 60; other++) {
335 if (other != obj &&
338 time = crash_time(obj, other);
339 if (closestTime > time) {
340 closestTime = time;
341 candidate = other;
342 }
343 }
344 }
345 if (candidate != -1) {
346 asCollisionPartnerTable[obj] = candidate;
347 asCollisionTimes[obj] = closestTime;
348 }
349 return candidate;
350}
351
352/* Function start: 0x422560 */
353unsigned int unactive(short ship)
354{
355 if (ship != -1 &&
358 return 0;
359 return 1;
360}
361
362/* Function start: 0x422590 */
363int are_alive(short obj)
364{
365 if (unactive(obj) == 0 &&
367 return 1;
368 return 0;
369}
370
371/* Function start: 0x4225C0 */
372int trim_goals(short obj, short amount)
373{
374 int objectIndex = obj;
375
376 obj = anYawTarget[objectIndex];
377
378 if (amount < obj)
379 anYawTarget[objectIndex] = amount;
380 else if (obj < -amount)
381 anYawTarget[objectIndex] = -amount;
382 obj = anPitchGoal[objectIndex];
383 if (amount < obj)
384 anPitchGoal[objectIndex] = amount;
385 else if (obj < -amount)
386 anPitchGoal[objectIndex] = -amount;
387 return 0;
388}
389
390/* Function start: 0x422640 */
392{
393 short obj;
394 unsigned int queryMode;
395
396 queryMode = mode;
397 for (obj = 0; obj < 10; obj++) {
398 if (aeObjectClass[obj] >= OBJECT_CLASS_SHIP &&
399 aeSpecialManeuvers[obj] !=
401 switch (queryMode) {
402 case 0:
403 if (aeShipSide[obj] == SIDE_KILRATHI)
404 return 1;
405 break;
406 case 1:
407 if (aeShipSide[obj] == SIDE_KILRATHI &&
409 distance_from_object(0, obj) < 16000)
410 return 1;
411 break;
412 case 2:
413 if (aeShipSide[obj] == SIDE_KILRATHI &&
414 (aeShipObjectiveList[obj] ==
416 aeShipObjectiveList[obj] ==
418 return 1;
419 break;
420 }
421 }
422 }
423 if (queryMode == 1 && nCurrentWave != -1)
425 return 0;
426}
427
428/* Mission and formation callees. */
429void maneuver_complete(short ship);
430int being_tailed(short obj, short other);
431unsigned int build_squad_list(short leader);
432unsigned int find_squad_center(FixedVector *center);
433unsigned int reset_objective(short ship, enum ShipObjective objective);
434int report_kilrathi_rout(int mode);
435unsigned int reset_tactic(short ship, enum ShipTactic tactic);
436void zero_vector(FixedVector *vector);
437
438/* Function start: 0x422710 */
439short find_ship_index(short missionShip)
440{
441 short obj;
442
444 if (missionShip != -1) {
445 for (obj = 0; obj < 10; obj++) {
446 if (((aeObjectClass[obj] >= OBJECT_CLASS_SHIP &&
447 aeSpecialManeuvers[obj] !=
450 nShipMissionIndices[obj] == missionShip) {
452 return obj;
453 }
454 }
455 }
456 return -1;
457}
458
459/* Routed-ship mission selection. */
460unsigned int reset_mission_type(short obj,
461 enum ShipMissionType missionType);
462
463/* Function start: 0x422780 */
464short try2rout(short obj)
465{
466 short canContinue;
467 short other;
468
469 canContinue = 0;
470 if (nTrainSimActive != 0) {
471 canContinue = 1;
472 } else {
473 for (other = 0; other < 10; other++) {
474 if (aeObjectClass[other] ==
476 aeSpecialManeuvers[other] !=
478 aeShipSide[obj] ==
479 aeShipSide[other])
480 canContinue = 1;
481 }
482 }
483 if (canContinue != 0) {
484 acShipStressList[obj] = 0;
486 } else {
488 if (obj == nYourWingman)
489 send_message(obj, 9);
490 }
491 return canContinue == 0;
492}
493
494/* Function start: 0x422830 */
495signed char no_goal(short ship)
496{
497 return (anYawTarget[ship] |
498 anPitchGoal[ship] |
499 anRollGoal[ship]) == 0;
500}
501
502/* Function start: 0x422860 */
503int being_tailed(short obj, short other)
504{
505 ship_vs_ship(obj, other);
506 return nFacingToTargetValue < -60 &&
507 nTargetFacingValue > 85 &&
508 nTgtRange < 7000;
509}
510
511/* Function start: 0x4228A0 */
512int any_enemy_tail(short obj)
513{
514 short other;
515
516 for (other = 0; other < 10; other++) {
517 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
518 aeSpecialManeuvers[other] !=
520 aeShipSide[obj] != aeShipSide[other] &&
521 acShipTargetTable[other] == obj &&
522 being_tailed(obj, other) != 0) {
523 nTargetShip = other;
524 return 1;
525 }
526 }
527 nTargetShip = -1;
528 return 0;
529}
530
531/* Tactic selection. */
532unsigned int alter_tactic(short ship, enum ShipTactic tactic);
533
534/* Function start: 0x422930 */
535short detect_enemy_tail(short obj)
536{
537 short other;
538
539 for (other = 0; other < 10; other++) {
540 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
541 aeSpecialManeuvers[other] !=
543 aeShipSide[obj] != aeShipSide[other] &&
544 acShipTargetTable[other] == obj &&
545 being_tailed(obj, other) != 0)
546 return other;
547 }
548 return -1;
549}
550
551/* Function start: 0x4229B0 */
553{
554 short target = acShipTargetTable[0];
555
556 if (unactive(target) == 0 && being_tailed(target, obj) != 0)
557 return 1;
558 return 0;
559}
560
561/* Function start: 0x4229F0 */
562int missile_on_tail(short obj)
563{
564 short other;
565
566 for (other = 0; other < 10; other++) {
567 if (aeObjectClass[other] == OBJECT_CLASS_MISSILE &&
568 acShipTargetTable[other] == obj)
569 return 1;
570 }
571 return 0;
572}
573
574/* Function start: 0x422A30 */
575short select_weighted_value(short *choices)
576{
577 short roll;
578
579 roll = RandomBelowOrEqual(100) + 1;
580 roll -= choices[0];
581 while (roll > 0) {
582 if (choices[0] == -1)
583 break;
584 choices += 2;
585 roll -= choices[0];
586 }
587 if (choices[0] == -1)
588 return -1;
589 return choices[1];
590}
591
592/* Function start: 0x422A70 */
593unsigned int build_squad_list(short leader)
594{
595 short obj;
596 short index = 1;
597
598 acFormationMemberLists[0] = (signed char)leader;
600 for (obj = 0; obj < 10; obj++) {
601 if (asShipWingLeaderArray[obj] == leader) {
602 acFormationMemberLists[index++] = (signed char)obj;
603 acFormationMemberLists[index] = -1;
604 }
605 }
606 return 0;
607}
608
609/* Function start: 0x422AC0 */
610unsigned int find_squad_center(FixedVector *center)
611{
612 short count = 0;
613
614 zero_vector(center);
615 while (acFormationMemberLists[count] != -1) {
617 (short)acFormationMemberLists[count]],
618 center);
619 count++;
620 }
621 if (count != 0)
622 divide_vector(center, (int)count << 8, center);
623 return 0;
624}
625
626/* Function start: 0x422B30 */
627unsigned int init_formation_burst(short obj)
628{
629 FixedVector center;
630 FixedVector *destination;
631 short member;
632 short index;
633
634 build_squad_list(obj);
635 find_squad_center(&center);
636 index = 0;
637 member = acFormationMemberLists[0];
638 while (member != -1) {
639 destination = &aShipDestinationsArray[member];
640 ComputeVectorDelta(&center, &aShipPositionsArray[member],
641 destination);
642 ScaleFixedVector(destination, 0xa00, destination);
643 AddFixedVectors(destination, &aShipPositionsArray[member],
644 destination);
645 steady_object(member);
647 member = acFormationMemberLists[++index];
648 }
649 return 0;
650}
651
652/* Function start: 0x422BE0 */
653unsigned int reset_mission_type(short obj,
654 enum ShipMissionType missionType)
655{
656 if (missionType == MISSION_TYPE_ROUT &&
660 aeShipMissionType[obj] = missionType;
661 return 0;
662}
663
664/* Function start: 0x422C30 */
665unsigned int change_mission_type(short obj,
666 enum ShipMissionType missionType)
667{
669 aeShipMissionType[obj] = missionType;
670 else
671 reset_mission_type(obj, missionType);
672 return 0;
673}
674
675/* Function start: 0x422C70 */
676unsigned int reset_objective(short ship, enum ShipObjective objective)
677{
678 steady_object(ship);
680 aeShipObjectiveList[ship] = objective;
681 return 0;
682}
683
684/* Function start: 0x422CA0 */
685unsigned int alter_objective(short ship, enum ShipObjective objective)
686{
687 steady_object(ship);
689 aeShipObjectiveList[ship] = objective;
690 return 0;
691}
692
693/* Function start: 0x422CD0 */
694unsigned int reset_tactic(short ship, enum ShipTactic tactic)
695{
697 /* Keep the tactic read distinct from the promoted ship index. */
698 aeShipTacticArray[ship] = *(enum ShipTactic volatile *)&tactic;
699 acShipTargetTable[ship] = -1;
700 return 0;
701}
702
703/* Function start: 0x422D00 */
704unsigned int alter_tactic(short ship, enum ShipTactic tactic)
705{
707 aeShipTacticArray[ship] = tactic;
708 return 0;
709}
710
711/* Function start: 0x422D30 */
712void reset_maneuver(short ship, short maneuver)
713{
714 aeShipManeuversTable[ship] = (enum ShipManeuver)maneuver;
715 asShipTotal[ship] = 0;
716 acShipSequence[ship] = 0;
717}
718
719/* Function start: 0x422D60 */
720void try2reset_maneuver(short obj, short maneuver)
721{
722 if (aeShipManeuversTable[obj] != maneuver) {
723 reset_maneuver(obj, maneuver);
724 steady_object(obj);
725 }
726}
727
728/* Function start: 0x422D90 */
729unsigned int set_special(short ship, enum SpecialManeuver special)
730{
731 enum SpecialManeuver *currentState;
732 enum SpecialManeuver current;
733
734 currentState = &aeSpecialManeuvers[ship];
735 current = *currentState;
736 if (current < SPECIAL_MANEUVER_LOST_CONTROL || special > current)
737 *currentState = special;
738
739 if (*currentState == SPECIAL_MANEUVER_BLOWING_UP &&
740 (short)alert_flag(ship, 1))
741 *currentState = SPECIAL_MANEUVER_NONE;
742 return 0;
743}
744
745/* Function start: 0x422DD0 */
746unsigned int approach_zero_speed(short ship)
747{
748 approach_speed(ship, 0);
749 return 0;
750}
751
752/* Function start: 0x422DF0 */
753unsigned int approach_min_speed(short obj)
754{
755 approach_speed(obj, 0x500);
756 return 0;
757}
758
759/* Function start: 0x422E10 */
760unsigned int approach_half_speed(short obj)
761{
762 short speed = aObjectTypeData[
764
765 approach_speed(obj, (int)(short)(speed & 0xfffe) << 7);
766 return 0;
767}
768
769/* Function start: 0x422E50 */
770unsigned int approach_cruise_speed(short ship)
771{
772 approach_speed(ship,
773 (int)aObjectTypeData[
774 aeObjectTypeList[ship]].cruiseVelocity << 8);
775 return 0;
776}
777
778/* Function start: 0x422E80 */
779unsigned int approach_full_speed(short ship)
780{
781 approach_speed(ship,
782 (int)asShipMaximumSpeedArray[ship] << 8);
783 return 0;
784}
785
786/* Function start: 0x422EA0 */
787unsigned int approach_ship_speed(short obj, short other)
788{
789 approach_speed(obj, anShipSpeed[other]);
790 return 0;
791}
792
793/* Function start: 0x422EC0 */
794unsigned int get_front_spot(short obj, unsigned short distance,
795 FixedVector *point)
796{
798 (int)distance << 8, point);
799 AddFixedVectors(&aShipPositionsArray[obj], point, point);
800 return 0;
801}
802
803/* Function start: 0x422F10 */
804unsigned int get_rear_spot(short obj, unsigned short distance,
805 FixedVector *point)
806{
808 -((int)distance << 8), point);
809 AddFixedVectors(&aShipPositionsArray[obj], point, point);
810 return 0;
811}
812
813/* Function start: 0x422F60 */
814unsigned int close_behind(volatile short range)
815{
816 if (range > nTgtRange &&
817 nTargetFacingValue < -0x32)
818 return 1;
819 return 0;
820}
821
822/* Range, objective, resource, and display callees. */
823short distance_from_point(short obj, const FixedVector *point);
824void get_facing_range_from_object(short obj, short other);
825short MinShort(short a, short b);
826void fire(short obj, short target);
827unsigned int IsVectorWithinRange(FixedVector *vector, short range);
828unsigned int ships_within_range(short obj, short other, short range);
829short build_target_list(short obj, short range);
830int in_danger(short obj);
831void inherit_leader_mission(short obj);
832short skill_rating(short obj);
833short find_ship_index(short missionShip);
834unsigned int dead_ship(short missionShip);
835short find_ships_sphere(short missionShip);
836unsigned int get_follow_point(short obj, FixedVector *point);
837short FindNearestNavPoint(short ship);
838int hostile_sphere(short obj, short navPoint);
839int explode(short attacker, short victim);
840void ace_greeting(short obj);
841short visited(short objective);
842short find_weapon(short obj, enum ObjectType weaponType);
843void *FetchDiskPacketRetrying(short logicalFile, short section,
844 short flags);
845void FreePacketAndClear(void *slot, unsigned short releaseFlags);
846void __stdcall PromptInsertNumberedDisk(short logicalFile);
847unsigned int __stdcall GetPacketSize(const char *filename,
848 short section);
849void __stdcall SetPaletteEntry(short index, short *rgb);
850void ClearViewport(Viewport *viewport, short colour);
851void DrawSpriteDefault(Viewport *viewport, short x, short y,
852 struct Shape *shape, short frame);
853void ReleasePacketHandle(void *handle);
854
855/* Function start: 0x422F80 */
856short scan_for_enemy(short obj, unsigned short range)
857{
858 short distance;
859 short other;
860
861 nTargetShip = -1;
862 nTgtRange = 0;
863 for (other = 0; other < 10; other++) {
864 if (aeObjectClass[other] < OBJECT_CLASS_SHIP ||
865 aeSpecialManeuvers[other] ==
867 continue;
868 if (aeShipSide[obj] == aeShipSide[other])
869 continue;
870 distance = distance_from_point(other, &aShipPositionsArray[obj]);
871 if (distance < range &&
872 (nTargetShip == -1 ||
873 nTgtRange > distance)) {
874 nTargetShip = other;
875 nTgtRange = distance;
876 }
877 }
878 if (nTargetShip != -1) {
880 nTgtRange =
882 }
883 return nTargetShip;
884}
885
886/* Function start: 0x423070 */
887int any_enemy(short obj, short range)
888{
889 short other;
890
891 nTargetShip = -1;
892 for (other = 0; other < 10; other++) {
893 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
894 aeSpecialManeuvers[other] !=
896 aeShipSide[obj] != aeShipSide[other]) {
897 nTgtRange = distance_from_object(obj, other);
898 if (nTgtRange < range) {
899 nTargetShip = other;
900 return 1;
901 }
902 }
903 }
904 return 0;
905}
906
907/* Function start: 0x4230F0 */
908short nearest_enemy_range(short obj)
909{
910 short other;
911 short range;
912
913 nTargetShip = -1;
914 range = 0x7fff;
915 for (other = 0; other < 10; other++) {
916 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
917 aeSpecialManeuvers[other] !=
919 aeShipSide[obj] != aeShipSide[other])
920 range = MinShort(range, distance_from_object(obj, other));
921 }
922 return range;
923}
924
925/* Function start: 0x423160 */
926/* Nothing in the shipped executable calls this function. */
927int FindEnemyAimingWithinRange(short obj, short range)
928{
929 short other;
930
931 for (other = 0; other < 10; other++) {
932 if (aeObjectClass[other] < OBJECT_CLASS_SHIP ||
933 aeSpecialManeuvers[other] ==
935 aeShipSide[obj] == aeShipSide[other])
936 continue;
938 if (range > nTgtRange && nTargetFacingValue > 80) {
939 nTargetShip = other;
940 return 1;
941 }
942 }
943 return 0;
944}
945
946/* Function start: 0x4231E0 */
947/* Nothing in the shipped executable calls this function. */
948unsigned int FireOnAlternateTurns(short obj)
949{
950 if ((abShipTurnList[obj] & 1) == 0)
951 fire(obj, acShipTargetTable[obj]);
952 return 0;
953}
954
955/* Function start: 0x423210 */
956void fire_when_ready(short obj, short aimed)
957{
958 (void)aimed;
959 if (nYourWingman == obj &&
960 aiPilotLevel[obj] != 11) {
961 ship_vs_ship(obj, 0);
962 if (nFacingToTargetValue > 80)
963 return;
964 }
965 fire(obj, acShipTargetTable[obj]);
966}
967
968/* Function start: 0x423260 */
969unsigned int ships_within_range(short obj, short other, short range)
970{
971 FixedVector delta;
972
974 &aShipPositionsArray[other], &delta);
975 return IsVectorWithinRange(&delta, range);
976}
977
978/* Function start: 0x4232B0 */
979int attacker_in_range(short obj, unsigned short range)
980{
981 short attacker;
982 short defendedObject = obj;
983
984 for (obj = 0; obj < 10; obj++) {
985 if (aeObjectClass[obj] >= OBJECT_CLASS_SHIP &&
986 aeSpecialManeuvers[obj] !=
988 aeShipSide[defendedObject] != aeShipSide[obj] &&
989 acShipTargetTable[obj] == defendedObject) {
990 attacker = obj;
991
992 obj = distance_from_object(obj, defendedObject);
993 nTgtRange = obj;
994 if (range > obj) {
995 nTargetShip = attacker;
996 return 1;
997 }
998 obj = attacker;
999 }
1000 }
1001 nTargetShip = -1;
1002 return 0;
1003}
1004
1005/* Function start: 0x423350 */
1006int in_danger(short obj)
1007{
1008 short target;
1009 short other;
1010 unsigned short range;
1011
1012 target = -1;
1013 for (other = 0; other < 10; other++) {
1014 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
1015 aeSpecialManeuvers[other] !=
1017 aeShipSide[obj] != aeShipSide[other]) {
1018 nTargetShip = target;
1019 if (acShipTargetTable[other] != obj)
1020 continue;
1021 range = (unsigned short)distance_from_object(other, obj);
1022 target = nTargetShip;
1023 if (target == -1 || range < nTgtRange) {
1024 target = other;
1025 nTgtRange = (short)range;
1026 }
1027 }
1028 }
1029 nTargetShip = target;
1030 return target != -1;
1031}
1032
1033/* Function start: 0x423400 */
1034unsigned int target_within_range(short obj)
1035{
1036 short target = acShipTargetTable[obj];
1037
1038 if (unactive(target) != 0)
1039 return 0;
1040 return ships_within_range(obj, target, 7000);
1041}
1042
1043/* Function start: 0x423440 */
1044short build_target_list(short obj, short range)
1045{
1046 short count;
1047 short other;
1048 short distance;
1049
1050 count = 0;
1051 for (other = 0; other < 10; other++) {
1052 if (aeObjectClass[other] >= OBJECT_CLASS_SHIP &&
1053 aeSpecialManeuvers[other] !=
1055 aeShipSide[obj] != aeShipSide[other]) {
1056 distance = distance_from_object(obj, other);
1057 if (distance < range) {
1058 acFormationMemberLists[count] =
1059 (signed char)other;
1060 asTargetListRangesArray[count] = distance;
1061 count++;
1062 }
1063 }
1064 }
1065 acFormationMemberLists[count] = -1;
1066 return count;
1067}
1068
1069/* Function start: 0x4234C0 */
1071{
1072 short target;
1073 short index;
1074
1075 build_target_list(obj, 7000);
1076 index = -1;
1077 do {
1078 index++;
1079 target = (short)acFormationMemberLists[index];
1080 if (target == -1)
1081 break;
1082 } while (in_danger(target) != 0);
1083 if (target == -1 && index > 0) {
1084 index--;
1085 target = (short)acFormationMemberLists[
1086 RandomBelowOrEqual(index)];
1087 }
1088 nTargetShip = target;
1089 return target != -1;
1090}
1091
1092/* Function start: 0x423530 */
1094{
1095 short leader = asShipWingLeaderArray[obj];
1096
1097 if (leader != -1 &&
1099 aeShipMissionType[obj] =
1100 aeShipMissionType[leader];
1101 anShipMissionShips[obj] =
1102 anShipMissionShips[leader];
1104 aShipMissionSpotArray[leader];
1105 asShipWingLeaderArray[obj] = -1;
1106 }
1107}
1108
1109/* Function start: 0x4235B0 */
1110void inherit_leader(short obj)
1111{
1112 short leader = asShipWingLeaderArray[obj];
1113 short other;
1114
1115 if (leader == -1 || aeObjectClass[obj] < OBJECT_CLASS_SHIP)
1116 return;
1119 for (other = 0; other < 10; other++) {
1120 if (asShipWingLeaderArray[other] == leader)
1121 asShipWingLeaderArray[other] = obj;
1122 }
1123}
1124
1125/* Function start: 0x423610 */
1126unsigned int dead_ship(short i)
1127{
1128 if (i != -1 && aMissionShips[i].state != 3)
1129 return 0;
1130 return 1;
1131}
1132
1133/* Function start: 0x423640 */
1134int gone_ship(short missionShip)
1135{
1136 if (missionShip != -1 &&
1137 aMissionShips[missionShip].state != 3 &&
1138 aMissionShips[missionShip].state != 2)
1139 return 0;
1140 return 1;
1141}
1142
1143/* Function start: 0x423670 */
1144short skill_rating(short obj)
1145{
1146 int rating = aiPilotLevel[obj];
1147
1148 if (rating <= 4)
1149 return MaxShort(2, (short)rating);
1150 if (rating == 13)
1151 return 5;
1152 if (rating < 14)
1153 return (short)((rating - 5 >> 1) + 4);
1154 return (short)rating - 10;
1155}
1156
1157/* Function start: 0x4236B0 */
1158int skill_check(short obj, short difficulty)
1159{
1161 skill_rating(obj);
1162}
1163
1164/* Function start: 0x4236F0 */
1165short find_ships_sphere(short missionShip)
1166{
1167 MissionNavPoint *navPoint;
1168 short fallback;
1169 short targetShip;
1170 short navIndex;
1171
1172 navIndex = 0;
1173 targetShip = missionShip;
1174 navPoint = aMissionNavPoints;
1175 fallback = -1;
1176 for (; navIndex < ACTIVE_MISSION_NAV_POINT_COUNT;
1177 navIndex++, navPoint++) {
1178 for (missionShip = 0; missionShip < 10; missionShip++) {
1179 if (navPoint->missionShips[missionShip] == targetShip) {
1180 if (navPoint->type == 1)
1181 return navIndex;
1182 if (fallback == -1)
1183 fallback = navIndex;
1184 }
1185 }
1186 }
1187 if (fallback != -1) {
1188 navIndex = fallback;
1189 if (aMissionNavPoints[navIndex].type > 1)
1190 do {
1191 navIndex--;
1192 } while (aMissionNavPoints[navIndex].type > 1);
1193 } else {
1194 navIndex = -1;
1195 }
1196 return navIndex;
1197}
1198
1199/* Function start: 0x423780 */
1200int locate_ship(short missionShip, FixedVector *point)
1201{
1202 short navPoint;
1203 short obj;
1204
1205 obj = find_ship_index(missionShip);
1206 if (obj != -1) {
1207 *point = aShipPositionsArray[obj];
1208 return 1;
1209 }
1210 if (dead_ship(missionShip) != 0)
1211 return 0;
1212 navPoint = find_ships_sphere(missionShip);
1213 if (navPoint != -1) {
1214 AddFixedVectors(&aMissionNavPoints[navPoint].position,
1215 &aMissionShips[missionShip].position,
1216 point);
1217 return 1;
1218 }
1219 zero_vector(point);
1220 return 0;
1221}
1222
1223/* Function start: 0x423820 */
1224unsigned int get_follow_point(short obj, FixedVector *point)
1225{
1226 short pathIndex;
1227 short objective;
1228 short missionShip;
1229 int type;
1230
1231 if (aeShipSide[obj] == SIDE_KILRATHI) {
1232 *point = aMissionNavPoints[
1234 return 0;
1235 }
1236 pathIndex = (short)abShipNavPtIdx[obj];
1237 while (++pathIndex < 16) {
1238 objective = (short)abFlightPathList[pathIndex];
1239 type = aMissionObjectivesArray[objective].type;
1240 switch (type) {
1241 case 0:
1242 *point = aMissionObjectivesArray[objective].position;
1243 abShipNavPtIdx[obj] = (signed char)pathIndex;
1244 return 0;
1245 case 1:
1246 missionShip = (short)aMissionObjectivesArray[objective].index;
1247 objective = find_ship_index(missionShip);
1248 if (objective == -1)
1249 *point = aMissionNavPoints[missionShip].position;
1250 else
1251 *point = aShipPositionsArray[objective];
1252 abShipNavPtIdx[obj] = (signed char)pathIndex;
1253 return 0;
1254 }
1255 }
1256 return 0;
1257}
1258
1259/* Function start: 0x423930 */
1260unsigned int get_first_follow_point(short obj, FixedVector *point)
1261{
1262 if (aeShipSide[obj] == SIDE_IMPERIAL)
1263 abShipNavPtIdx[obj] =
1264 cCurrentNavPtIdx - 1;
1265 get_follow_point(obj, point);
1266 return 0;
1267}
1268
1269/* Function start: 0x423970 */
1270int hostile_sphere(short obj, short navPoint)
1271{
1272 short index;
1273
1274 for (index = 0; index < 10; index++) {
1275 short checkedObject = obj;
1276 obj = aMissionNavPoints[navPoint].missionShips[index];
1277 if (obj != -1 &&
1278 aeShipSide[checkedObject] != aMissionShips[obj].side)
1279 return 1;
1280 obj = checkedObject;
1281 }
1282 return 0;
1283}
1284
1285/* Function start: 0x4239D0 */
1286int abandoned(short obj, short other)
1287{
1288 short navPoint;
1289
1290 if ((abShipTurnList[obj] & 7) == 0 &&
1291 aeShipSide[obj] != SIDE_KILRATHI &&
1292 RandomBelowOrEqual(8) == 0) {
1293 navPoint = FindNearestNavPoint(obj);
1294 if (nCurrentNavigationPoint != navPoint &&
1295 hostile_sphere(obj, navPoint) != 0 &&
1296 distance_from_object(obj, other) > 10000) {
1297 explode(-1, obj);
1298 return 1;
1299 }
1300 return 0;
1301 }
1302 return 0;
1303}
1304
1305/* Function start: 0x423A50 */
1306void engage(short obj, short target, enum ShipObjective objective)
1307{
1308 if (aeShipObjectiveList[obj] != objective) {
1309 reset_objective(obj, objective);
1310 if (acShipRating[obj] > 8 &&
1311 ace_status(
1312 (short)((short)aiPilotLevel[obj] - 14), 8) == 0)
1313 ace_greeting(obj);
1314 }
1315 acShipTargetTable[obj] = target;
1316}
1317
1318/* Function start: 0x423AC0 */
1319int target_valid(short obj)
1320{
1321 return unactive(acShipTargetTable[obj]) == 0 &&
1322 aeShipSide[
1323 acShipTargetTable[obj]] !=
1324 aeShipSide[obj];
1325}
1326
1327/* Function start: 0x423B00 */
1328unsigned int triumph(short obj)
1329{
1330 unsigned int result = 0;
1331 short objective;
1332
1333 switch (aeShipMissionType[obj]) {
1335 objective = 0;
1336 while (abFlightPathList[objective] != -1 &&
1337 visited(
1338 (short)abFlightPathList[objective]) != 0)
1339 objective++;
1340 return 1;
1344 return dead_ship(anShipMissionShips[obj]) == 0;
1346 result = dead_ship(anShipMissionShips[obj]);
1347 }
1348 return result;
1349}
1350
1351/* Function start: 0x423BA0 */
1352short find_ratio(short inputMinimum, short inputMaximum,
1353 short input, short outputMinimum,
1354 short outputMaximum)
1355{
1356 if (input < inputMinimum)
1357 return outputMinimum;
1358 if (input > inputMaximum)
1359 return outputMaximum;
1360 return (short)(((int)(outputMaximum - outputMinimum) *
1361 (int)(input - inputMinimum)) /
1362 (int)(inputMaximum - inputMinimum)) + outputMinimum;
1363}
1364
1365/* Function start: 0x423C00 */
1366short evaluate_damage(short obj)
1367{
1368 enum ObjectType objectType = aeObjectTypeList[obj];
1369 enum ObjectClass objectClass;
1370 ObjectTypeData *typeData = &aObjectTypeData[objectType];
1371
1372 objectClass = aeObjectClass[obj];
1373
1374 if (objectClass < OBJECT_CLASS_SHIP)
1375 return 100;
1376 return (short)((acShipDmg[obj] * -26) /
1377 typeData->damageCapacity +
1378 (aasShipArmor[obj][1] * 27) /
1379 typeData->armorRear +
1380 (aasShipArmor[obj][0] * 23) /
1381 typeData->armorFront +
1382 (aasShipArmor[obj][2] * 12) /
1383 typeData->armorLeft +
1384 (aasShipArmor[obj][3] * 12) /
1385 typeData->armorRight + 26);
1386}
1387
1388/* Function start: 0x423CD0 */
1389short mine_available(short obj)
1390{
1392}
1393
1394/* Function start: 0x423CE0 */
1396 unsigned short flags, short defaultLogicalFile)
1397{
1398 while (resources->resource != 0) {
1399 if (*(PackedResourcePointer *)resources->resource == 0) {
1400 if (resources->logicalFile == -1)
1401 *(PackedResourcePointer *)resources->resource =
1403 defaultLogicalFile, resources->section, flags);
1404 else
1405 *(PackedResourcePointer *)resources->resource =
1407 resources->logicalFile, resources->section, flags);
1408 if (*(PackedResourcePointer *)resources->resource == 0)
1409 return 0;
1410 }
1411 resources++;
1412 }
1413 return 1;
1414}
1415
1416/* Function start: 0x423D50 */
1418 unsigned short releaseFlags)
1419{
1420 while (resources->resource != 0) {
1421 if (*(PackedResourcePointer *)resources->resource != 0)
1422 FreePacketAndClear(resources->resource, releaseFlags);
1423 resources++;
1424 }
1425 return 0;
1426}
1427
1428/* Function start: 0x423D80 */
1430 short flags, int availableBytes)
1431{
1432 int packetSize;
1433
1434 while (resources->resource != 0) {
1435 if (*(PackedResourcePointer *)resources->resource == 0) {
1437 packetSize = (int)GetPacketSize(
1439 resources->logicalFile].name,
1440 resources->section);
1441 if (packetSize < availableBytes) {
1442 *(PackedResourcePointer *)resources->resource =
1444 resources->logicalFile, resources->section,
1445 (unsigned short)flags);
1446 if (*(PackedResourcePointer *)resources->resource == 0)
1447 return availableBytes;
1448 availableBytes -= packetSize;
1449 }
1450 }
1451 resources++;
1452 }
1453 return availableBytes;
1454}
1455
1456/* Function start: 0x423E10 */
1458{
1459 short black[3];
1460 short index;
1461
1462 black[0] = 0;
1463 black[1] = 0;
1464 black[2] = 0;
1465 index = 0;
1466 do {
1467 memcpy(aPaletteFadeEntries[index], black,
1468 sizeof(black));
1469 SetPaletteEntry((short)(index + 185),
1470 aPaletteFadeEntries[index]);
1471 index++;
1472 } while (index < 6);
1473 memcpy(asDamageFlashColour, black, sizeof(black));
1474 asDamageFlashColour[2] = 32;
1477 return 0;
1478}
1479
1480/* Function start: 0x423E90 */
1481unsigned int initialize_cockpit(int requestedMode)
1482{
1483 Viewport savedScreen;
1484 struct Shape *backdrop;
1485 signed char mode;
1486 unsigned int result;
1487
1488 if (message_showing())
1489 EndCommMenu();
1490
1491 mode = (signed char)requestedMode;
1492
1493 if (bCockpitlessView == 0 && mode == cScreenViewMode) {
1496 else
1498 return 0;
1499 }
1500
1502 savedScreen = stScreenView;
1503 stScreenView.top = 0;
1504 stScreenView.left = 0;
1505 stScreenView.right = 319;
1506 stScreenView.bottom = 199;
1508
1510 (unsigned char)(cCurrentCockpitView + 17);
1511 cScreenViewMode = mode;
1512 switch (mode) {
1513 case 0:
1514 if (apCockpitShapesList[0] != 0) {
1515 if (bCockpitlessView == 0)
1517 apCockpitShapesList[0], 0);
1518 } else {
1519 backdrop = FetchDiskPacketRetrying(
1520 (short)cCockpitLogicalFile, 0, 0);
1521 if (bCockpitlessView == 0)
1522 DrawSpriteDefault(&stScreenView, 0, 0, backdrop, 0);
1523 ReleasePacketHandle(backdrop);
1524 }
1526 if (bCockpitlessView == 0)
1528 reset_cockpit();
1531 update_VDUs();
1533 if (bCockpitlessView == 0)
1536 break;
1537 case 1:
1538 if (apCockpitShapesList[1] != 0) {
1539 if (bCockpitlessView == 0)
1541 apCockpitShapesList[1], 0);
1542 } else {
1543 backdrop = FetchDiskPacketRetrying(
1544 (short)cCockpitLogicalFile, 1, 0);
1545 if (bCockpitlessView == 0)
1546 DrawSpriteDefault(&stScreenView, 0, 0, backdrop, 0);
1547 ReleasePacketHandle(backdrop);
1548 }
1550 break;
1551 case 2:
1552 if (apCockpitShapesList[2] != 0) {
1553 if (bCockpitlessView == 0)
1555 apCockpitShapesList[2], 0);
1556 } else {
1557 backdrop = FetchDiskPacketRetrying(
1558 (short)cCockpitLogicalFile, 2, 0);
1559 if (bCockpitlessView == 0)
1560 DrawSpriteDefault(&stScreenView, 0, 0, backdrop, 0);
1561 ReleasePacketHandle(backdrop);
1562 }
1564 break;
1565 case 3:
1566 if (apCockpitShapesList[3] != 0) {
1567 if (bCockpitlessView == 0)
1569 apCockpitShapesList[3], 0);
1570 } else {
1571 backdrop = FetchDiskPacketRetrying(
1572 (short)cCockpitLogicalFile, 3, 0);
1573 if (bCockpitlessView == 0)
1574 DrawSpriteDefault(&stScreenView, 0, 0, backdrop, 0);
1575 ReleasePacketHandle(backdrop);
1576 }
1578 break;
1579 case 4:
1580 if (bIntroSceneResourcesActive == 1) {
1581 if (pCinematicViewBackdropPtr != 0) {
1584 if (bCockpitlessView < 1) {
1585 DIBslam();
1586 DIBslamReal();
1587 }
1588 } else {
1589 struct Shape *cinematicBackdrop;
1590
1591 cinematicBackdrop = FetchDiskPacketRetrying(8, 6, 0);
1592 DrawSpriteDefault(&stScreenView, 0, 0, cinematicBackdrop, 0);
1593 if (bCockpitlessView < 1) {
1594 DIBslam();
1595 DIBslamReal();
1596 }
1597 ReleasePacketHandle(cinematicBackdrop);
1598 }
1599 }
1601 break;
1602 case 5:
1604 break;
1605 case 6:
1607 break;
1608 case 7:
1609 if (pLogicRearViewBackdropPtr != 0) {
1610 if (bCockpitlessView == 0)
1613 } else {
1614 backdrop = FetchDiskPacketRetrying(8, 7, 0);
1615 if (bCockpitlessView == 0)
1616 DrawSpriteDefault(&stScreenView, 0, 0, backdrop, 0);
1617 ReleasePacketHandle(backdrop);
1618 }
1620 break;
1621 }
1622
1625 (unsigned short)(nScreenWidth - 1),
1626 (unsigned short)(nScreenHeight - 1));
1627 result = initialize_view_buffer();
1628 stScreenView = savedScreen;
1629 return result;
1630}
1631
1632/* Function start: 0x4242D0 */
1634 const ConstellationObjectDefinition *definition, short object)
1635{
1636 FixedVector position;
1637
1639 init_ijk(63);
1640 alter_yaw((short)-definition->yaw, 63);
1641 alter_pitch((short)-definition->pitch, 63);
1642 alter_roll(definition->roll, 63);
1644 0x753000, &position);
1645 aShipPositionsArray[object] = position;
1646 asObjScreenScalesArray[object] = 0xff;
1647 asObjScreenAngles[object] = 0;
1648 asObjectViewFrames[object] = 0;
1650 apObjShapeArray[object] =
1652 12, (short)(definition->shapePacket + 1), 0);
1653 return 0;
1654}
1655
1656/* Function start: 0x4243B0 */
1657unsigned int FreeConstellationObject(short object)
1658{
1660 remove_object(object);
1661 return 0;
1662}
1663
1664/* Function start: 0x4243E0 */
1665unsigned int init_constellation(short scene)
1666{
1667 short slot;
1668 short object;
1669
1671 return 0;
1672
1673 scene--;
1675 FetchDiskPacketRetrying(12, 0, 0);
1676 if (nTrainSimActive != 0 || scene < 0)
1677 return;
1678
1679 for (slot = 0; slot < 4; slot++) {
1680 if (pConstellationDefinitionsPtr[scene * 4 + slot].shapePacket !=
1681 -1) {
1682 object = find_vacant_3d_object();
1683 if (object != -1) {
1685 &pConstellationDefinitionsPtr[scene * 4 + slot],
1686 object);
1687 }
1688 asConstellationObjectIndices[slot] = object;
1689 } else {
1691 }
1692 }
1693 /* The successful path returns the last expression left in EAX. */
1694}
1695
1696/* Function start: 0x424490 */
1697unsigned int free_constellation(void)
1698{
1699 short object;
1700 short slot;
1701
1702 slot = 0;
1704 do {
1705 object = asConstellationObjectIndices[slot];
1706 if (object != -1) {
1709 }
1710 slot++;
1711 } while (slot < 4);
1712 return 0;
1713}
1714
1715/* Function start: 0x4244E0 */
1739
1740/* Function start: 0x4245B0 */
1741unsigned int InitializeCockpitResources(signed char mode)
1742{
1743 int backgroundSize;
1744 unsigned int result;
1745 short maximumSize;
1746 short frame;
1747 short weapon;
1748
1749 if (bCockpitResourcesActive == 1) {
1750 if (mode == cCurrentCockpitView)
1751 return 0;
1752 free_cockpit();
1753 }
1754
1756 cCurrentCockpitView = mode;
1757 cCockpitLogicalFile = (unsigned char)(mode + 17);
1760 reset_cockpit();
1762
1764 (short)cCockpitLogicalFile);
1767 (short)cCockpitLogicalFile, 6);
1769 init_vdus();
1770
1774 (signed char)cBlackColour);
1777
1794
1795 *(ShortRect *)&stLeftVdu.left =
1799
1800 if (pCurrentPilotHandShapePtr != 0) {
1805 (unsigned short)(
1808 (unsigned short)(
1814 }
1815
1817 (short)cCockpitLogicalFile);
1820
1822 maximumSize = 0;
1823 for (weapon = 0;
1824 weapon < aShipWeaponsTable[0][0];
1825 weapon++) {
1826 if (aObjectTypeData[((ShipWeaponSlot *)&aShipWeaponsTable[0][1])[weapon].type].objectClass ==
1828 backgroundSize = MeasureShapeFrameStorage(
1830 (short)(((ShipWeaponSlot *)&aShipWeaponsTable[0][1])[weapon].type * 2 - 0x2f));
1831 maximumSize = MaxShort(maximumSize, (short)backgroundSize);
1832 }
1833 }
1834 if (maximumSize != 0)
1836 AllocateTaggedMemory(maximumSize, 0);
1837
1839 if (pCockpitExplosionShape != 0) {
1840 maximumSize = 0;
1841 for (frame = 0; frame < 8; frame++) {
1842 backgroundSize = MeasureShapeFrameStorage(
1843 pCockpitExplosionShape, frame);
1844 maximumSize = MaxShort(maximumSize, (short)backgroundSize);
1845 }
1846 if (maximumSize != 0)
1848 AllocateTaggedMemory(maximumSize, 0);
1849 }
1850
1852 maximumSize = 0;
1853 for (frame = 0; frame < 9; frame++) {
1854 /* The original passes an unused third zero to MaxShort. */
1855 maximumSize = MaxShort(maximumSize,
1857 }
1858 if (maximumSize != 0)
1860 AllocateTaggedMemory(maximumSize, 0);
1861
1863 result = init_personalities();
1865 bRadioSilence = 0;
1866 if (nMemoryConfig == 2)
1868 else if (nSceneResourceBudgetValue > 0x59d8)
1870 else
1872 return result;
1873}
1874
1875/* Function start: 0x4249A0 */
1902
1903/* Function start: 0x424A80 */
1904unsigned int init_3Space_objects(short scene)
1905{
1906 short slot;
1907
1908 if (b3SpaceObjectsActive == 1)
1909 return 0;
1911 cScreenViewMode = -1;
1913 nExternalViewShip = -1;
1915 bScriptedView = 0;
1920 slot = 0;
1921 do {
1923 slot++;
1924 } while (slot <= 3);
1925 init_constellation(scene);
1927}
1928
1929/* Function start: 0x424B00 */
1931{
1945
1959 return 0;
1960}
1961
1962/* Function start: 0x424B80 */
1963unsigned int remove_all_3d_objects(void)
1964{
1965 short i = 0;
1966
1967 do {
1968 remove_object(i);
1969 i = i + 1;
1970 } while (i < 0x40);
1971 return 0;
1972}
1973
1974/* Function start: 0x424BA0 */
1975unsigned int free_3Space(void)
1976{
1977 if (b3SpaceObjectsActive == 0)
1978 return 0;
1986 return 0;
1987}
1988
1989/* Function start: 0x424BE0 */
2013
2014/* Function start: 0x424C60 */
2015unsigned int init_inflight_music(void)
2016{
2020 return 0;
2021}
2022
2023/* Function start: 0x424C80 */
2024unsigned int free_inflight_music(void)
2025{
2026 int *record;
2027
2030 if (nInFlightMusicSlotA != -1) {
2031 record = (int *)(abAudioPlaybackSlots + nInFlightMusicSlotA * 6);
2033 *record = 0;
2034 }
2035 if (nInFlightMusicSlotB != -1) {
2036 record = (int *)(abAudioPlaybackSlots + nInFlightMusicSlotB * 6);
2038 *record = 0;
2039 }
2040 return 0;
2041}
2042
2043/* Function start: 0x424CE0 */
2044unsigned int PreloadMusicTrackHook(short track)
2045{
2046 (void)track;
2047 return 0;
2048}
2049
2050/* Function start: 0x424CF0 */
2051unsigned int ReleaseMusicTrackHook(short track)
2052{
2053 (void)track;
2054 return 0;
2055}
2056
2057/* Function start: 0x424D00 */
2058unsigned short LoadSceneAnimationResources(short scene, short variant)
2059{
2060 unsigned char *packet;
2061 short logicalFile;
2062
2063 logicalFile = asSceneAnimationLogicalFiles[scene];
2065 FetchDiskPacketRetrying(logicalFile, 0, 0);
2068 logicalFile, (short)(variant + 1), 0);
2071 logicalFile, (short)(variant + 3), 0);
2072 packet = FetchDiskPacketRetrying(
2073 logicalFile, (short)(variant + 5), 0);
2074 pSceneAnimationPacketPtr = packet;
2076 packet + *(unsigned int *)(packet + 0);
2078 packet + *(unsigned int *)(packet + 4);
2081 return 0;
2082}
2083
2084/* Function start: 0x424DA0 */
2092
2093/* Function start: 0x424DE0 */
2094signed char *__stdcall FindSceneAnimationCommand(
2095 signed char *script, signed char command)
2096{
2097 signed char opcode;
2098
2099 while (*script != 0) {
2100 opcode = *script++;
2101 if (opcode == command) {
2102 script--;
2103 break;
2104 }
2105 switch (opcode) {
2106 case 'A':
2107 case 'L':
2108 case 'Q':
2109 script++;
2110 case 'B':
2111 case 'G':
2112 case 'J':
2113 case 'R':
2114 case 'W':
2115 script += 2;
2116 break;
2117 case 'D':
2118 while (*script++ != -1) {
2119 }
2120 break;
2121 case 'E':
2122 case 'P':
2123 case 'S':
2124 script++;
2125 break;
2126 case 'X':
2127 script += 10;
2128 break;
2129 }
2130 }
2131 return *script != 0 ? script : 0;
2132}
2133
2134/* Function start: 0x424EA0 */
2135short __stdcall SceneAnimationGoalReached(short delta, short current,
2136 short goal)
2137{
2138 if (delta < 0) {
2139 if (current <= goal)
2140 return 1;
2141 } else if (delta > 0) {
2142 if (current >= goal)
2143 return 1;
2144 } else if (current == goal) {
2145 return 1;
2146 }
2147 return 0;
2148}
2149
2150/* Function start: 0x424EF0 */
2151unsigned short __stdcall UpdateSceneAnimationObject(
2152 SceneAnimationObject *object, Viewport *viewport)
2153{
2154 SceneAnimationObject *source;
2155 signed char *commandStart;
2156 signed char *cursor;
2157 signed char *label;
2158 short labelNumber;
2159 signed char frame;
2160 unsigned short complete;
2161 unsigned short goalFlags;
2162 signed char property;
2163 short value;
2164 short xOffset;
2165 short layer;
2166 short delay;
2167 short objectIndex;
2168 short objectSet;
2169 short objectCount;
2170 signed char stop;
2171
2172 complete = 0;
2173 delay = object->delay;
2174 stop = 0;
2175 if (delay != 0)
2176 cursor = object->repeatCursor;
2177 else
2178 cursor = object->scriptCursor;
2179
2180 while (*cursor != 0 && stop == 0) {
2181 switch (*cursor++) {
2182 case 'A':
2183 property = *cursor++;
2184 value = *(short *)cursor;
2185 cursor += 2;
2186 switch (property) {
2187 case 'F':
2188 object->frame = (short)(object->frame + value);
2189 object->deltaFrame = value;
2190 break;
2191 case 'R':
2192 object->rotation = (short)(object->rotation + value);
2193 object->deltaRotation = value;
2194 if (object->rotation < 0)
2195 object->rotation = (short)(
2196 ((unsigned short)(0x167 - object->rotation) /
2197 0x168) * 0x168 + object->rotation);
2198 if (object->rotation >= 0x168)
2199 object->rotation = (short)(
2200 object->rotation -
2201 ((unsigned short)object->rotation / 0x168) *
2202 0x168);
2203 break;
2204 case 'S':
2205 object->scale = (short)(object->scale + value);
2206 object->deltaScale = value;
2207 if (object->scale < 0x40)
2208 object->scale = 0x40;
2209 else if (object->scale > 0x1fff)
2210 object->scale = 0x1fff;
2211 break;
2212 case 'T':
2213 delay = (short)(delay + value);
2214 break;
2215 case 'X':
2216 object->x = (short)(object->x + value);
2217 object->deltaX = value;
2218 break;
2219 case 'Y':
2220 object->y = (short)(object->y + value);
2221 object->deltaY = value;
2222 break;
2223 }
2224 break;
2225
2226 case 'B':
2227 cursor += 2;
2228 break;
2229
2230 case 'D':
2231 commandStart = cursor - 1;
2232 object->repeatCursor = commandStart;
2233 xOffset = 0;
2234 layer = object->layer;
2235 frame = *cursor++;
2236 while (frame != -1) {
2237 if (layer != 2 && nFrameSkipCounter <= 0)
2239 viewport, (short)(object->x + xOffset), object->y,
2240 object->shape, frame, object->rotation,
2241 object->scale, object->frame);
2242 if (layer == 0)
2243 xOffset = (short)(xOffset + 320);
2244 frame = *cursor++;
2245 }
2246 stop++;
2247 break;
2248
2249 case 'E':
2250 commandStart = cursor - 1;
2251 xOffset = 0;
2252 layer = object->layer;
2253 complete = 1;
2254 frame = *cursor++;
2255 while (frame != -1) {
2256 if (layer != 2 && nFrameSkipCounter <= 0)
2258 viewport, (short)(object->x + xOffset), object->y,
2259 object->shape, frame, object->rotation,
2260 object->scale, object->frame);
2261 xOffset = (short)(xOffset + 320);
2262 frame = *cursor++;
2263 }
2264 cursor = commandStart;
2265 stop++;
2266 break;
2267
2268 case 'J':
2269 stop++;
2270 /* Fall through to the label search. */
2271 case 'G':
2272 labelNumber = *(short *)cursor;
2273 label = object->scriptStart;
2274 do {
2275 label = FindSceneAnimationCommand(label, 'B');
2276 label++;
2277 value = *(short *)label;
2278 label += 2;
2279 } while (value != labelNumber);
2280 cursor = label;
2281 break;
2282
2283 case 'L':
2284 property = *cursor++;
2285 value = *(short *)cursor;
2286 cursor += 2;
2287 switch (property) {
2288 case 'F':
2289 object->frame = value;
2290 break;
2291 case 'R':
2292 object->rotation = value;
2293 if (object->rotation < 0)
2294 object->rotation = (short)(
2295 ((unsigned short)(0x167 - object->rotation) /
2296 0x168) * 0x168 + object->rotation);
2297 if (object->rotation >= 0x168)
2298 object->rotation = (short)(
2299 object->rotation -
2300 ((unsigned short)object->rotation / 0x168) *
2301 0x168);
2302 break;
2303 case 'S':
2304 object->scale = value;
2305 if (object->scale < 0x40)
2306 object->scale = 0x40;
2307 else if (object->scale > 0x1fff)
2308 object->scale = 0x1fff;
2309 break;
2310 case 'T':
2311 delay = value;
2312 break;
2313 case 'X':
2314 object->x = value;
2315 break;
2316 case 'Y':
2317 object->y = value;
2318 break;
2319 }
2320 break;
2321
2322 case 'P':
2323 stop++;
2324 break;
2325
2326 case 'Q':
2327 property = *cursor++;
2328 value = *(short *)cursor;
2329 cursor += 2;
2330 switch (property) {
2331 case 'F':
2332 object->goalFlags |= 0x10;
2333 object->goalFrame = value;
2334 break;
2335 case 'R':
2336 object->goalFlags |= 1;
2337 object->goalRotation = value;
2338 break;
2339 case 'S':
2340 object->goalFlags |= 2;
2341 object->goalScale = value;
2342 break;
2343 case 'X':
2344 object->goalFlags |= 4;
2345 object->goalX = value;
2346 break;
2347 case 'Y':
2348 object->goalFlags |= 8;
2349 object->goalY = value;
2350 break;
2351 }
2352 break;
2353
2354 case 'R':
2355 objectCount = *(short *)pSceneAnimationDefinitionsPtr;
2356 objectSet = (short)*cursor++;
2357 objectIndex = (short)*cursor++;
2358 source = &pSceneAnimationObjects[
2359 (short)(objectCount * objectSet) + objectIndex];
2360 object->x = source->x;
2361 object->y = source->y;
2362 object->rotation = source->rotation;
2363 object->scale = source->scale;
2364 object->frame = source->frame;
2365 break;
2366
2367 case 'W':
2368 nSceneAnimationDelayFrames = *(short *)cursor;
2369 cursor += 2;
2371 break;
2372
2373 case 'X':
2374 object->x = *(short *)cursor;
2375 cursor += 2;
2376 object->y = *(short *)cursor;
2377 cursor += 2;
2378 object->rotation = *(short *)cursor;
2379 cursor += 2;
2380 object->scale = *(short *)cursor;
2381 cursor += 2;
2382 object->frame = *(short *)cursor;
2383 cursor += 2;
2384 break;
2385 }
2386 }
2387
2388 if (object->delay != 0) {
2389 object->delay--;
2390 return 0;
2391 }
2392
2393 object->scriptCursor = cursor;
2394 goalFlags = object->goalFlags;
2395 object->delay = delay;
2396 if (complete == 0 && goalFlags != 0) {
2397 if ((goalFlags & 0x10) != 0)
2398 complete |= SceneAnimationGoalReached(
2399 object->deltaFrame, object->frame, object->goalFrame);
2400 if ((goalFlags & 4) != 0)
2401 complete |= SceneAnimationGoalReached(
2402 object->deltaX, object->x, object->goalX);
2403 if ((goalFlags & 8) != 0)
2404 complete |= SceneAnimationGoalReached(
2405 object->deltaY, object->y, object->goalY);
2406 if ((goalFlags & 2) != 0)
2407 complete |= SceneAnimationGoalReached(
2408 object->deltaScale, object->scale, object->goalScale);
2409 if ((goalFlags & 1) != 0)
2410 complete |= SceneAnimationGoalReached(
2411 object->deltaRotation, object->rotation,
2412 object->goalRotation);
2413 }
2414 return complete;
2415}
2416
2417/* Function start: 0x425500 */
2418void PlaySceneAnimation(char *text, short animation, short duration)
2419{
2420 unsigned short complete;
2421 short objectCount;
2422 SceneAnimationObject *objects;
2423 short remaining;
2424 SceneAnimationObject *object;
2425 short skipRemaining;
2426
2428 complete = 0;
2430 AddPCName(text);
2432 cBlackColour);
2433 FormatTextBufferFromStart("%X%Y%F%s%P",
2434 0, 160,
2437
2438 objectCount = *(short *)pSceneAnimationDefinitionsPtr;
2439 objects = pSceneAnimationObjects +
2440 (short)(objectCount * animation);
2441 object = objects;
2442 if (objectCount > 0) {
2443 remaining = objectCount;
2444 do {
2445 if (object->layer == 0)
2446 object->shape = pCurrentSceneAnimationPrimaryShape;
2447 else
2448 object->shape = pSceneAnimationSecondaryShape;
2449 object->scriptStart = (signed char *)pSceneAnimationDefinitionsPtr;
2450 object->scriptStart += object->scriptOffset;
2451 object->scriptCursor = object->scriptStart;
2452 object++;
2453 } while (--remaining != 0);
2454 }
2455
2459 DIBslam();
2460 DIBslamReal();
2461 for (;;) {
2462 do {
2464 object = objects;
2465 if (objectCount > 0) {
2466 remaining = objectCount;
2467 do {
2468 complete |= UpdateSceneAnimationObject(
2469 object, &stSceneBuffer);
2470 object++;
2471 } while (--remaining != 0);
2472 }
2473 if (nSceneAnimationDelayFrames != -1) {
2476 else
2477 complete++;
2478 }
2479 if (complete == 0) {
2481 DIBslam();
2482 DIBslamReal();
2483 }
2484 if (nFrameSkipCounter == 0) {
2486 if (bSlowSceneAnimation != 0)
2488 }
2489 if ((complete == 0 && CheckEscaped() != 0) ||
2490 bEscapePressedFlag != 0) {
2491 if (nSceneAnimationDelayFrames == -1) {
2492 while (complete == 0 &&
2494 object = objects;
2495 if (objectCount > 0) {
2496 skipRemaining = objectCount;
2497 do {
2499 complete |= UpdateSceneAnimationObject(
2500 object, &stSceneBuffer);
2501 object++;
2502 } while (--skipRemaining != 0);
2503 }
2504 }
2505 }
2507 }
2508 } while (complete == 0);
2509
2510 if (nSceneAnimationDelayFrames == -1) {
2511 SetFrameTimerPeriodDirect((short)(duration / 2));
2512 do {
2513 if ((short)IsFrameTickElapsed() != 0 || CheckEscaped() != 0)
2514 break;
2515 } while (bEscapePressedFlag == 0);
2516 }
2517 if (complete != 0)
2518 return;
2519 }
2520}
void(__cdecl *pIxFree)(void *)
unsigned char bEscapePressedFlag
Definition mathfp.c:24
short asCollisionTimes[10]
Definition init.c:55
struct Shape * pCockpitExplosionShape
Definition cockpt.c:27
Viewport stPilotHandBackdropView
Definition timer.c:15
signed char acShipRating[16]
Definition joycal.c:25
short nLogicLastFoundShipValue
Definition init.c:58
short bSlowSceneAnimation
Definition init.c:11
int nInFlightMusicSlotB
Definition music.c:27
enum ShipTactic aeShipTacticArray[12]
Definition input.c:20
PacketResourceDescriptor aCockpitResourceDescriptors[19]
Definition logic.c:49
short asObjScreenScalesArray[SPACE_OBJECT_COUNT]
Definition dib.c:105
unsigned int anShipAlertFlags[12]
Definition data.c:250
short anShipMissionShips[16]
Definition comm.c:57
TextContext stRightVduTxtContext
Definition targ.c:12
unsigned char bCommVideoEnabled
Definition comm.c:16
short nCurrentWave
Definition game.c:34
enum Side aeShipSide[12]
Definition ending.c:22
short anRollGoal[16]
Definition ending.c:21
Viewport stPilotHandComposite
Definition select.c:16
struct Shape * pConfedCommBackground
Definition cockpt.c:81
struct Shape * pCockpitDamageShape
Definition select.c:19
Viewport stRightVduViewport
Definition timer.c:14
short nRenderedSpaceFrame
Definition input.c:22
signed char acShipStressList[16]
Definition ending.c:20
signed char aShipWeaponsTable[10][0x47]
Definition dib.c:108
Viewport stPilotHandView
Definition launch.c:47
int nMemoryConfig
Definition ship.c:58
short asObjScreenAngles[SPACE_OBJECT_COUNT]
Definition joycal.c:26
unsigned char * pRadarMarkerBackground
Definition cockpt.c:91
enum ShipManeuver aeShipManeuversTable[12]
Definition screen.c:25
ObjectTypeData aObjectTypeData[OBJECT_TYPE_COUNT]
Definition objdata.c:86
short nCockpitExplosionFrame
Definition cockpt.c:28
signed char abShipNavPtIdx[16]
Definition screen.c:14
int aiPilotLevel[12]
Definition video.c:16
short asShipTotal[16]
Definition game.c:551
unsigned char cBlackColour
Definition init.c:12
short anPitchGoal[16]
Definition screen.c:13
unsigned int anVduModeCache[2]
Definition joycal.c:28
char szTxtWorkspaceBuffer[256]
Definition screens.c:164
short nConvTextColorValue
Definition screens.c:170
struct Shape * pCinematicViewBackdropPtr
Definition logic.c:109
short asCollisionPartnerTable[10]
Definition init.c:59
FixedVector aShipDestinationsArray[10]
Definition input.c:18
short nTgtRange
Definition joycal.c:27
ConstellationObjectDefinition * pConstellationDefinitionsPtr
Definition gr.c:1532
signed char abFlightPathList[MISSION_OBJECTIVE_COUNT]
Definition smart.c:20
struct Shape * pCockpitWeaponShapePtr
Definition timer.c:16
short asCollisionDelayList[16]
Definition video.c:26
short asShipMaximumSpeedArray[16]
Definition game.c:552
signed char acShipDmg[10]
Definition game.c:553
unsigned char * pSceneAnimationDefinitionsPtr
Definition logic.c:105
unsigned char * pDamageDisplayBackground
Definition damage.c:11
signed char abShipTurnList[16]
Definition screen.c:17
int bCockpitlessView
Definition main.c:39
unsigned char * pReleaseWeaponDisplayBackground
Definition cockpt.c:29
short nFrameSkipCounter
Definition main.c:23
short nSceneAnimationDelayFrames
Definition logic.c:104
short nFacingToTargetValue
Definition screen.c:19
int nCombatMusicActive
Definition music.c:31
PacketResourceDescriptor aMissionResourceDescriptors[5]
Definition logic.c:40
enum ShipMissionType aeShipMissionType[12]
Definition game.c:550
TextContext stCurrentCockpitReadoutTextCtx
Definition targ.c:13
enum ShipObjective aeShipObjectiveList[12]
Definition video.c:22
short asTargetListRangesArray[16]
Definition video.c:17
MissionNavPoint aMissionNavPoints[MISSION_NAV_POINT_COUNT]
Definition game.c:199
int bCurrentPlayerDestroyed
Definition logic.c:111
short nFrameSkip
Definition main.c:24
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
Definition video.c:21
struct Shape * pCurrentConstellationShape
Definition timer.c:20
short nYourWingman
Definition game.c:61
short aasShipArmor[10][4]
Definition comm.c:53
signed char acFormationMemberLists[16]
Definition comm.c:55
struct Shape * pCurrentSceneAnimationPrimaryShape
Definition logic.c:100
Viewport stCurrentConvTextViewport
Definition timer.c:17
short nPlayerCollisionObject
Definition game.c:64
Viewport stSceneBuffer
Definition select.c:17
short aPaletteFadeEntries[6][3]
Definition select.c:18
struct Shape * pTgtLockShapePtr
Definition pload.c:12
short nClosestVisibleObject
Definition game.c:58
int nInFlightMusicActive
Definition music.c:32
FixedVector aShipVelocity[SPACE_OBJECT_COUNT]
Definition smart.c:21
int bScriptedView
Definition view.c:14
unsigned int bIntroSceneResourcesActive
Definition logic.c:87
Viewport stLeftVdu
Definition launch.c:48
short asObjectCollisionRadius[64]
Definition ending.c:27
short nExternalViewShip
Definition game.c:52
short asShipAfterburnerTimer[16]
Definition game.c:558
signed char cCurrentCockpitView
Definition screen.c:23
unsigned char cPrimaryViewBufferColour
Definition init.c:27
signed char cCockpitLogicalFile
Definition logic.c:107
char szDefaultTxtBuf[0xc8]
Definition timer.c:18
FixedVector aShipMissionSpotArray[10]
Definition screen.c:27
int anShipSpeed[64]
Definition data.c:248
unsigned char * pSceneAnimationTextData
Definition logic.c:101
short asDamageFlashColour[3]
Definition targ.c:16
short nScreenWidth
Definition data.c:34
int nSceneResourceBudgetValue
Definition ship.c:62
Viewport stScreenView
Definition launch.c:50
struct Shape * pCommStaticShape
Definition cockpt.c:82
struct Shape * pSceneAnimationSecondaryShape
Definition logic.c:106
Viewport stSpaceBufferViewport
Definition timer.c:13
int bViewBufferEnabled
Definition main.c:38
short asShipWingLeaderArray[16]
Definition comm.c:51
TextContext stLeftVduTextContext
Definition timer.c:12
short nTargetFacingValue
Definition input.c:17
unsigned char cPrimaryTextColour
Definition init.c:18
unsigned char * pSceneAnimationSceneDataPtr
Definition logic.c:99
CampaignState stCampaignState
Definition dib.c:107
struct Shape * apCockpitShapesList[4]
Definition logic.c:108
struct Shape * pCurrentPilotHandShapePtr
Definition select.c:15
short asObjectScreenXList[SPACE_OBJECT_COUNT]
Definition screen.c:21
short nCurrentSpaceFrameValue
Definition data.c:249
int bMissileCameraEnabled
Definition game.c:98
MissionObjective aMissionObjectivesArray[MISSION_OBJECTIVE_COUNT]
Definition screen.c:24
int nTrainSimActive
Definition trainsim.c:31
struct Shape * apObjShapeArray[SPACE_OBJECT_COUNT]
Definition comm.c:48
struct Shape * pKilrathiCommBackground
Definition cockpt.c:83
PacketResourceDescriptor aCommon3SpaceResources[12]
Definition logic.c:24
signed char cScreenViewMode
Definition strdos.c:13
unsigned char abCollisionAlertTargets[0x10]
Definition joycal.c:36
short nCurrentNavigationPoint
Definition music.c:90
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
Definition data.c:255
short asObjectViewFrames[SPACE_OBJECT_COUNT]
Definition video.c:23
Viewport stModalSrcViewport
Definition select.c:14
CockpitLayout stCockpitLayout
Definition data.c:193
ObjectResourceSlot aObjectResourceSlotsArray[4]
Definition screen.c:30
struct Shape * pCockpitPilotShape
Definition cockpt.c:25
short nPlayerKillTotal
Definition logic.c:112
ScreenViewportPacket * pCurrentScreenViewportPkt
Definition launch.c:49
MissionShipRecord aMissionShips[MISSION_SHIP_STORAGE_COUNT]
Definition game.c:230
Viewport stCockpitBar
Definition launch.c:52
short nScreenHeight
Definition data.c:37
char acShipSequence[10]
Definition input.c:16
struct Shape * pCockpitIndicatorShape
Definition timer.c:19
unsigned char bRadioSilence
Definition comm.c:14
short nShipMissionIndices[10]
Definition game.c:559
FixedVector aShipPositionsArray[SPACE_OBJECT_COUNT]
Definition game.c:556
DiskFileRecord * pDiskFileRecords
Definition disk.c:36
short nTargetShip
Definition game.c:548
int nInFlightMusicSlotA
Definition music.c:25
FixedVector aShipFwdVec[64]
Definition smart.c:17
signed char acShipTargetTable[16]
Definition joycal.c:30
short anYawTarget[16]
Definition smart.c:22
SceneAnimationObject * pSceneAnimationObjects
Definition logic.c:103
signed char cCurrentNavPtIdx
Definition dib.c:96
unsigned char * pSceneAnimationPacketPtr
Definition logic.c:102
struct Shape * apCommunicationPortraitShapesTable[16]
Definition music.c:96
unsigned char * pCockpitExplosionBackground
Definition cockpt.c:26
int nInitialFlightMusicPending
Definition music.c:30
enum SpecialManeuver aeSpecialManeuvers[12]
Definition game.c:549
struct Shape * pLogicRearViewBackdropPtr
Definition logic.c:110
unsigned char abAudioPlaybackSlots[0xf8]
Definition install.c:14
int b3SpaceObjectsActive
Definition logic.c:92
PacketResourceDescriptor aCockpitSecondaryResources[5]
Definition logic.c:70
short asSceneAnimationLogicalFiles[8]
Definition logic.c:93
int bCockpitResourcesActive
Definition logic.c:91
int FindEnemyAimingWithinRange(short obj, short range)
Definition logic.c:927
PacketResourceDescriptor aCockpitPrimaryResources[8]
Definition logic.c:77
short asConstellationObjectIndices[4]
Definition logic.c:88
unsigned int FireOnAlternateTurns(short obj)
Definition logic.c:948
short bSceneAnimationWaitCommand
Definition logic.c:96
unsigned char aceFlags[4]
Definition wcdata.h:719
ShortRect pilotHandBounds[5]
Definition wcdata.h:465
ShortRect rightVduBounds[5]
Definition wcdata.h:462
ShortRect leftVduBounds[5]
Definition wcdata.h:461
ShortPoint readoutOrigins[4][6]
Definition wcdata.h:460
char name[13]
Definition wcdata.h:490
FixedVector position
Definition wcdata.h:859
short missionShips[10]
Definition wcdata.h:863
signed char type
Definition wcdata.h:858
FixedVector position
Definition wcdata.h:931
signed char type
Definition wcdata.h:911
short armorRight
Definition wcdata.h:392
unsigned char * animation
Definition wcdata.h:380
short armorRear
Definition wcdata.h:390
struct Shape * shapeSet
Definition wcdata.h:393
short damageCapacity
Definition wcdata.h:376
short cruiseVelocity
Definition wcdata.h:379
short armorLeft
Definition wcdata.h:391
short armorFront
Definition wcdata.h:389
struct Shape * shape
Definition wcdata.h:651
short y
Definition wcdata.h:416
short x
Definition wcdata.h:415
short top
Definition wcdata.h:441
short left
Definition wcdata.h:440
short right
Definition wcdata.h:442
short bottom
Definition wcdata.h:443
char * text
Definition wc1base.h:242
Viewport * viewport
Definition wc1base.h:236
unsigned char * pixels
Definition wc1base.h:74
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 * PackedResourcePointer
Definition wc1base.h:45
void clear_alert(short obj)
Definition logic.c:189
void set_up_screen_viewport(signed char mode)
Definition eventmgr.c:1016
unsigned int approach_full_speed(short ship)
Definition logic.c:779
int any_enemy_tail(short obj)
Definition logic.c:512
unsigned int RefreshMemoryStatusOverlay(void)
Definition main.c:467
unsigned short __stdcall UpdateSceneAnimationObject(SceneAnimationObject *object, Viewport *viewport)
Definition logic.c:2151
short real_crash_time(short obj, short other)
Definition logic.c:230
short find_ships_sphere(short missionShip)
Definition logic.c:1165
unsigned int approach_zero_speed(short ship)
Definition logic.c:746
void * AllocateTaggedMemory(int size, unsigned short flags)
Definition ending.c:31
unsigned int free_cockpit(void)
Definition logic.c:1876
unsigned int get_rear_spot(short obj, unsigned short distance, FixedVector *point)
Definition logic.c:804
void ace_greeting(short obj)
Definition logic.c:142
void FormatTextBufferFromStart(const char *format,...)
Definition cockpt.c:211
unsigned int initialize_cockpit(int requestedMode)
Definition logic.c:1481
unsigned int close_behind()
void * reset_cockpit(void)
Definition cockpt.c:540
void DIBslam(void)
Definition dib.c:513
int select_safe_target(short obj)
Definition logic.c:1070
int locate_ship(short missionShip, FixedVector *point)
Definition logic.c:1200
short skill_rating(short obj)
Definition logic.c:1144
unsigned int free_3Space_objects(void)
Definition logic.c:1990
void * LoadPacketAllocated(short logicalFile, short section)
Definition disk.c:94
short detect_collisions(short obj)
Definition logic.c:325
unsigned int InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition disk.c:192
unsigned int reset_objective(short ship, enum ShipObjective objective)
Definition logic.c:676
unsigned short LoadSceneAnimationResources(short scene, short variant)
Definition logic.c:2058
unsigned short set_alert(short obj, unsigned int bits)
Definition logic.c:182
unsigned int get_first_follow_point(short obj, FixedVector *point)
Definition logic.c:1260
short select_weighted_value(short *choices)
Definition logic.c:575
short distance_from_point(short obj, const FixedVector *point)
Definition geom.c:655
void ship_vs_ship(short obj, short other)
Definition geom.c:710
unsigned int find_squad_center(FixedVector *center)
Definition logic.c:610
void kill_ace(short ace)
Definition logic.c:133
unsigned int steady_object(short ship)
Definition ship.c:422
void engage(short obj, short target, enum ShipObjective objective)
Definition logic.c:1306
unsigned int free_3Space(void)
Definition logic.c:1975
unsigned short __stdcall AllocateViewport(Viewport *viewport, short clearColour, short flags)
Definition view.c:758
unsigned int __stdcall GetPacketSize(const char *filename, short section)
Definition screen.c:368
void remove_object(short obj)
Definition geom.c:1002
unsigned int get_front_spot(short obj, unsigned short distance, FixedVector *point)
Definition logic.c:794
unsigned int HasSpeechBuffer(void)
Definition logic.c:176
void alter_pitch(short angle, short obj)
Definition geom.c:619
int missile_on_tail(short obj)
Definition logic.c:562
unsigned int free_inflight_music(void)
Definition logic.c:2024
long Vector_magnitude(const FixedVector *vector)
Definition mathfp.c:132
void * FetchDiskPacketRetrying(short logicalFile, short section, short flags)
Definition disk.c:126
void AddFixedVectors(const FixedVector *left, const FixedVector *right, FixedVector *sum)
Definition geom.c:296
void __stdcall SetTextCursor(unsigned short a, unsigned short b)
Definition mathfp.c:145
int hostile_sphere(short obj, short navPoint)
Definition logic.c:1270
void check_next_wave(void)
Definition ship.c:995
short evaluate_damage(short obj)
Definition logic.c:1366
void init_vdus(void)
Definition logic.c:1716
unsigned int dead_ship(short missionShip)
Definition logic.c:1126
void __stdcall PromptInsertNumberedDisk(short logicalFile)
Definition disk.c:322
int abandoned(short obj, short other)
Definition logic.c:1286
unsigned int ships_within_range(short obj, short other, short range)
Definition logic.c:969
void EndCommMenu(void)
Definition comm.c:427
void clear_cockpit_damage(void)
Definition cockpt.c:2556
void ResetPilotHandAnimation(void)
Definition cockpt.c:2479
void DrawSpriteScaled(Viewport *viewport, short x, short y, struct Shape *shape, short frame, short angle, short scale, short flip)
Definition gr.c:1176
void alter_roll(short angle, short obj)
Definition geom.c:635
int being_tailed(short obj, short other)
Definition logic.c:503
unsigned int load_common_3Space_objects(void)
Definition logic.c:1930
void fire_when_ready(short obj, short aimed)
Definition logic.c:956
void DrawSpriteDefault(Viewport *viewport, short x, short y, struct Shape *shape, short frame)
Definition gr.c:660
void init_ijk(short obj)
Definition geom.c:568
int IsFrameTickElapsed(void)
Definition eventmgr.c:629
short nearest_enemy_range(short obj)
Definition logic.c:908
short FixedToShortSaturating(int value)
Definition geom.c:193
void StopMusicUnlessSuppressed(void)
Definition music.c:419
void __stdcall SetPaletteEntry(short index, short *rgb)
Definition gr.c:654
int LoadPacketResourceList(PacketResourceDescriptor *resources, short flags, int availableBytes)
Definition logic.c:1429
unsigned int triumph(short obj)
Definition logic.c:1328
void clear_head_up_display(void)
Definition cockpt.c:1455
short MinShort(short a, short b)
Definition mathutil.c:20
short crash_time(short obj, short other)
Definition logic.c:306
void DIBslamReal(void)
Definition dib.c:519
unsigned int target_within_range(short obj)
Definition logic.c:1034
short find_ratio(short inputMinimum, short inputMaximum, short input, short outputMinimum, short outputMaximum)
Definition logic.c:1352
short scan_for_enemy(short obj, unsigned short range)
Definition logic.c:856
unsigned int PreloadMusicTrackHook(short track)
Definition logic.c:2044
unsigned int GetScreenUpdateFlag(void)
Definition main.c:361
void InvalidateVduMode(short i)
Definition cockpt.c:764
void ClearHudGunReadouts(void)
Definition cockpt.c:433
unsigned int init_constellation(short scene)
Definition logic.c:1665
unsigned int approach_ship_speed(short obj, short other)
Definition logic.c:787
unsigned int approach_half_speed(short obj)
Definition logic.c:760
void __stdcall SetTextContext(TextContext *context)
Definition mathfp.c:152
void clear_crash_cache(void)
Definition logic.c:295
short distance_from_object(short obj, short other)
Definition geom.c:667
int explode(short attacker, short victim)
Definition ship.c:1340
void ClearInputKeyState(void)
Definition eventmgr.c:800
unsigned int approach_speed(short ship, int targetSpeed)
Definition ship.c:405
void try2end_collision_alert(short obj)
Definition logic.c:210
unsigned int init_3Space_objects()
short mine_available(short obj)
Definition logic.c:1389
void inherit_leader_mission(short obj)
Definition logic.c:1093
unsigned int initialize_view_buffer(void)
Definition main.c:371
unsigned int init_formation_burst(short obj)
Definition logic.c:627
short signed_random(short range)
Definition logic.c:160
short visited(short objective)
Definition cockpt.c:1036
void prepare_ace(short ace)
Definition logic.c:153
void alter_yaw(short angle, short obj)
Definition geom.c:627
void ReleaseSceneAnimationResources(void)
Definition logic.c:2085
void __stdcall SetFrameTimerPeriodDirect(short p)
Definition eventmgr.c:617
int report_kilrathi_rout(int mode)
Definition logic.c:391
unsigned int ResetCockpitPaletteEntries(void)
Definition logic.c:1457
unsigned int set_special(short ship, enum SpecialManeuver special)
Definition logic.c:729
unsigned int change_mission_type(short obj, enum ShipMissionType missionType)
Definition logic.c:665
unsigned int init_inflight_music(void)
Definition logic.c:2015
void ScaleFixedVector(const FixedVector *vector, int scale, FixedVector *result)
Definition geom.c:322
signed char no_goal(short ship)
Definition logic.c:495
short build_target_list(short obj, short range)
Definition logic.c:1044
void send_message(short obj, short message)
Definition cockpt.c:2489
int attacker_in_range(short obj, unsigned short range)
Definition logic.c:979
unsigned int alter_objective(short ship, enum ShipObjective objective)
Definition logic.c:685
long DivideFixed(int numerator, int denominator)
Definition mathfp.c:76
void explosion_draw(void)
Definition cockpt.c:2563
void zero_vector(FixedVector *vector)
Definition geom.c:280
int gone_ship(short missionShip)
Definition logic.c:1134
unsigned int ReleaseMusicTrackHook(short track)
Definition logic.c:2051
short real_velocity(short obj)
Definition ship.c:431
unsigned int alter_tactic(short ship, enum ShipTactic tactic)
Definition logic.c:704
unsigned int FreeConstellationObject(short object)
Definition logic.c:1657
signed char *__stdcall FindSceneAnimationCommand(signed char *script, signed char command)
Definition logic.c:2094
int in_danger(short obj)
Definition logic.c:1006
unsigned int free_constellation(void)
Definition logic.c:1697
int any_enemy(short obj, short range)
Definition logic.c:887
short FindNearestNavPoint(short ship)
Definition main.c:1967
unsigned int approach_min_speed(short obj)
Definition logic.c:753
short __stdcall SceneAnimationGoalReached(short delta, short current, short goal)
Definition logic.c:2135
void ClearViewport(Viewport *viewport, short colour)
Definition gr.c:963
unsigned int remove_all_3d_objects(void)
Definition logic.c:1963
short try2rout(short obj)
Definition logic.c:464
void flag_ace(short ace, unsigned char bits)
Definition logic.c:127
short detect_enemy_tail(short obj)
Definition logic.c:535
short find_vacant_3d_object(void)
Definition geom.c:987
void get_facing_range_from_object(short obj, short other)
Definition geom.c:691
unsigned int InitializeConstellationObject(const ConstellationObjectDefinition *definition, short object)
Definition logic.c:1633
void start_collision_alert(short obj, short other)
Definition logic.c:197
void try2reset_maneuver(short obj, short maneuver)
Definition logic.c:720
unsigned int IsVectorWithinRange(FixedVector *vector, short range)
Definition eventmgr.c:1212
unsigned int InitializeCockpitResources(signed char mode)
Definition logic.c:1741
void ResetScannerContacts(void)
Definition cockpt.c:1443
unsigned int get_follow_point(short obj, FixedVector *point)
Definition logic.c:1224
void unflag_ace(short ace, unsigned char bits)
Definition logic.c:121
unsigned int InitializeCockpitReadout(signed char slot, TextContext *context)
Definition cockpt.c:341
unsigned int approach_cruise_speed(short ship)
Definition logic.c:770
void set_mode(short i, int state)
Definition cockpt.c:697
void PlaySceneAnimation(char *text, short animation, short duration)
Definition logic.c:2418
void fire(short obj, short target)
Definition ship.c:1445
short difficulty(void)
Definition winmain.c:154
unsigned int reset_tactic(short ship, enum ShipTactic tactic)
Definition logic.c:694
void inherit_leader(short obj)
Definition logic.c:1110
void __stdcall free_viewport(Viewport *viewport)
Definition gameflow.c:420
void ReleasePacketHandle(void *handle)
Definition ending.c:50
unsigned int reset_mission_type(short obj, enum ShipMissionType missionType)
Definition logic.c:653
void divide_vector(FixedVector *vector, int divisor, FixedVector *result)
Definition geom.c:330
void ComputeVectorDelta(const FixedVector *from, const FixedVector *to, FixedVector *delta)
Definition geom.c:314
unsigned int init_personalities(void)
Definition mission.c:640
int skill_check(short obj, short difficulty)
Definition logic.c:1158
void __stdcall SetViewportRect(Viewport *viewport, unsigned short left, unsigned short top, unsigned short right, unsigned short bottom)
Definition screens.c:1560
unsigned int build_squad_list(short leader)
Definition logic.c:593
short MaxShort(short a, short b,...)
Definition mathutil.c:29
int target_valid(short obj)
Definition logic.c:1319
int FreeShapeSet(PacketResourceDescriptor *resources, unsigned short releaseFlags)
Definition logic.c:1417
short CheckEscaped(void)
Definition disk.c:442
void maneuver_complete(short ship)
Definition fl.c:90
void FreePacketAndClear(void *slot, unsigned short releaseFlags)
Definition mathutil.c:37
int load_ship(enum ObjectType type, short slot)
Definition mission.c:202
short normal_speed(short obj)
Definition logic.c:220
unsigned int ReleaseTextFont(short fontIndex)
Definition disk.c:222
short find_ship_index(short missionShip)
Definition logic.c:439
void update_VDUs(void)
Definition cockpt.c:2767
int __stdcall MeasureShapeFrameStorage(struct Shape *shape, short frame)
Definition mathfp.c:349
int trim_goals(short obj, short amount)
Definition logic.c:372
int is_ship_tailing_player_target(short obj)
Definition logic.c:552
int LoadShapeSet(PacketResourceDescriptor *resources, unsigned short flags, short defaultLogicalFile)
Definition logic.c:1395
void FreeCommDisplayResources(void)
Definition comm.c:403
int alert_flag(short ship, unsigned int bits)
Definition logic.c:166
int free_ship(short slot)
Definition mission.c:330
int are_alive(short obj)
Definition logic.c:363
void remove_all_hazards(void)
Definition winmain.c:141
void reset_maneuver(short ship, short maneuver)
Definition logic.c:712
short ace_status(short ace, unsigned char bits)
Definition logic.c:115
short RandomBelowOrEqual(short n)
Definition mathfp.c:59
unsigned int unactive(short ship)
Definition logic.c:353
char * AddPCName(const char *text)
Definition cmpgn.c:102
short find_weapon(short obj, enum ObjectType weaponType)
Definition ship.c:1888
short message_showing(void)
Definition cockpt.c:776
ShipMissionType
Definition wcdata.h:120
@ MISSION_TYPE_PATROL
Definition wcdata.h:122
@ MISSION_TYPE_ESCORT
Definition wcdata.h:123
@ MISSION_TYPE_WINGMAN
Definition wcdata.h:126
@ MISSION_TYPE_ROUT
Definition wcdata.h:127
@ MISSION_TYPE_DEFEND
Definition wcdata.h:125
@ MISSION_TYPE_STRIKE
Definition wcdata.h:124
ObjectType
Definition wcdata.h:54
@ OBJECT_TYPE_EXPLOSION0
Definition wcdata.h:103
@ OBJECT_TYPE_HYPERSPACE_JUMP_FLASH
Definition wcdata.h:112
@ OBJECT_TYPE_NEUTRON_PARTICLE_GUN
Definition wcdata.h:80
@ OBJECT_TYPE_HEAT_SEEKING_MISSILE
Definition wcdata.h:84
@ OBJECT_TYPE_DEBRIS_METAL_SHEET
Definition wcdata.h:98
@ OBJECT_TYPE_FF_MISSILE
Definition wcdata.h:85
@ OBJECT_TYPE_MASS_DRIVER_CANNON
Definition wcdata.h:81
@ OBJECT_TYPE_DEBRIS_WING
Definition wcdata.h:99
@ OBJECT_TYPE_DEBRIS_GLASS
Definition wcdata.h:100
@ OBJECT_TYPE_EXPLOSION2
Definition wcdata.h:105
@ OBJECT_TYPE_IMAGE_RECOGNITION_MISSILE
Definition wcdata.h:86
@ OBJECT_TYPE_DEBRIS_O_RING
Definition wcdata.h:101
@ OBJECT_TYPE_BLUE_SPARK
Definition wcdata.h:108
@ OBJECT_TYPE_EXPLOSION1
Definition wcdata.h:104
@ OBJECT_TYPE_RED_SPARK
Definition wcdata.h:107
@ OBJECT_TYPE_LASER_CANNON
Definition wcdata.h:79
@ OBJECT_TYPE_LASER_SPARK
Definition wcdata.h:106
@ OBJECT_TYPE_DEBRIS_PIPE
Definition wcdata.h:102
@ OBJECT_TYPE_THRUSTERS
Definition wcdata.h:110
@ OBJECT_TYPE_DUMB_FIRE_MISSILE
Definition wcdata.h:83
@ OBJECT_TYPE_HORNET
Definition wcdata.h:55
@ OBJECT_TYPE_DEBRIS_SHIP_GIRDER_CHUNK
Definition wcdata.h:96
@ OBJECT_TYPE_TURRET
Definition wcdata.h:82
@ OBJECT_TYPE_SPARK_TRAIL
Definition wcdata.h:109
@ OBJECT_TYPE_DEBRIS_SHIP_TUBING
Definition wcdata.h:97
@ OBJECT_TYPE_SPACE_MINE
Definition wcdata.h:88
@ SIDE_IMPERIAL
Definition wcdata.h:174
@ SIDE_KILRATHI
Definition wcdata.h:175
ShipObjective
Definition wcdata.h:136
@ OBJECTIVE_ENGAGE_ENEMY
Definition wcdata.h:144
@ OBJECTIVE_DESTROY_SHIP
Definition wcdata.h:142
@ OBJECTIVE_BREAK_FORMATION
Definition wcdata.h:147
@ OBJECTIVE_WANDER
Definition wcdata.h:143
@ OBJECTIVE_NONE
Definition wcdata.h:137
SpecialManeuver
Definition wcdata.h:257
@ SPECIAL_MANEUVER_BLOWING_UP
Definition wcdata.h:267
@ SPECIAL_MANEUVER_UNKNOWN_9
Definition wcdata.h:268
@ SPECIAL_MANEUVER_AFTERBURNER
Definition wcdata.h:260
@ SPECIAL_MANEUVER_NONE
Definition wcdata.h:258
ShipManeuver
Definition wcdata.h:206
@ MANEUVER_HARD_BRAKE
Definition wcdata.h:217
@ MANEUVER_NONE
Definition wcdata.h:207
#define ACTIVE_MISSION_NAV_POINT_COUNT
Definition wcdata.h:1013
ObjectClass
Definition wcdata.h:37
@ OBJECT_CLASS_PLANET
Definition wcdata.h:41
@ OBJECT_CLASS_MISSILE
Definition wcdata.h:49
@ OBJECT_CLASS_SHIP
Definition wcdata.h:50
@ OBJECT_CLASS_CAPITAL_SHIP
Definition wcdata.h:51
@ OBJECT_CLASS_FUTURION
Definition wcdata.h:39
@ OBJECT_CLASS_ASTEROID
Definition wcdata.h:47
ShipTactic
Definition wcdata.h:150
@ TACTIC_NONE
Definition wcdata.h:151