Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
mission.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup flight
4 * @brief Mission setup, ship resources, formation placement and pilot speech.
5 *
6 * Address range 40b670-40d08f. The joystick and navigation-map helpers at its
7 * end stay here provisionally: where their original object began is
8 * unresolved.
9 */
10#include <process.h>
11#include <crtdbg.h>
12#include "wc1.h"
13
14short nDebriefingPersonality = 0; /* 0x00465c80 */
15static
16int bInitialFormationSetup = 0; /* 0x00465c84 */
17void *aapPacketReferences[4][0x25] = {0}; /* 0x00465c88 */
18static
19/* 0x00465ed8 */
21 {
22 { 0, 0, 0 }, { -750, 0, 0 }, { 750, 0, 0 }, { 0, 0, -750 },
23 { 0, 0, 750 }, { -750, 0, -750 }, { 750, 0, -750 },
24 { 0, 0, -1500 }
25 },
26 {
27 { 0, 0, 0 }, { 750, 0, 0 }, { -750, -100, -250 },
28 { 1500, -100, -250 }, { -1500, -200, -500 },
29 { -2250, -300, -750 }, { 2250, -200, -500 },
30 { 3000, -300, -750 }
31 },
32 {
33 { 0, 0, 0 }, { 750, 0, -500 }, { -750, 0, -500 },
34 { 0, 0, -1000 }, { -1500, 0, -1000 }, { -750, 0, -1500 },
35 { 1500, 0, -1000 }, { 750, 0, -1500 }
36 },
37 {
38 { 0, 0, 0 }, { 750, 0, -250 }, { 0, 325, -500 },
39 { 750, -325, -750 }, { 0, 325, -500 }, { 750, -325, -750 },
40 { 0, 0, -1000 }, { 750, 0, -1250 }
41 },
42 {
43 { 0, 0, 0 }, { 0, 0, -750 }, { -750, 0, -500 },
44 { -750, 0, -1250 }, { 750, 0, -500 }, { 750, 0, -1250 },
45 { 0, 500, -500 }, { 0, 500, -1250 }
46 }
47};
48static
49/* 0x00465fc8 */
51 5, 5, 4, 4, 3, 3, 3, 2, 2, 1, 3, 3, 3, 3, 2, 2, 2, 1
52};
53
54/* Linker commons defined here; LINK orders them by identifier hash. */
55unsigned char abSeriesAuxData[0x28]; /* 0x005a8240 */
60signed char cCurrentObjResourceLogicalFile; /* 0x005a86b0 */
61Viewport *pScrambleView; /* 0x005a86b4 */
62short nSceneScrambleCanopyFrameValue; /* 0x005a86b8 */
63
64/* Function start: 0x40B670 */
66 FixedVector *position)
67{
70 &record->position, position);
71}
72
73/* Function start: 0x40B6A0 */
74unsigned int is_alive(int pilot)
75{
76 if (pilot <= 4)
77 return 1;
78 if (pilot == 13)
79 return nArcadeState != 4;
80 if (pilot >= 5 && pilot <= 12)
82 pilot - 5] == 0;
83 if (pilot >= 14 && pilot <= 17)
84 return (unsigned int)ace_status((short)(pilot - 14), 1);
85 return 0;
86}
87
88/* Function start: 0x40B700 */
89unsigned int check_futurion(short i)
90{
94 }
95 return 0;
96}
97
98/* Function start: 0x40B730 */
114
115/* Function start: 0x40B7A0 */
117{
118 short playerShip;
119 short initial;
120 short missionShip;
121 short pilot;
122
127
132 if (nTrainSimActive == 0 && nStartNavPointOverride != -1)
134 Set_up_ship_info(0, playerShip, -1);
135
139 nYourWingman = -1;
140 for (initial = 0; initial < 8; initial++) {
141 missionShip = stCurrentMissionHeader.initialMissionShips[initial];
142 if (missionShip != -1) {
143 pilot = aMissionShips[missionShip].behaviour.pilot;
144 if (is_alive(pilot) != 0 &&
145 find_ships_sphere(missionShip) == -1) {
147 if (nYourWingman == -1 &&
148 pilot > 4 && pilot < 14)
150 }
151 }
152 }
154
156 missionShip = 0;
157 nCarrierMissionShipIndexValue = missionShip;
158 while (aMissionShips[missionShip].type !=
160 (nCarrierMissionShipIndexValue = missionShip) <
162 missionShip++;
163 nCarrierMissionShipIndexValue = missionShip;
164 }
165 nTargetLockMode = 0;
167}
168
169/* Function start: 0x40B940 */
171{
172 short obj;
173
174 for (obj = 0; obj < 10; obj++) {
175 if (aeObjectClass[obj] ==
179 }
180 }
181 return 0;
182}
183
184/* Function start: 0x40B990 */
186{
187 short obj;
188
189 if (aObjectTypeData[type].objectClass ==
191 for (obj = 1; obj < 10; obj++) {
192 if (aeObjectTypeList[obj] == type) {
195 }
196 }
197 }
198 return 0;
199}
200
201/* Function start: 0x40B9F0 */
202int load_ship(enum ObjectType type, short slot)
203{
204 short obj;
205 short section;
206
207 if (type != -1) {
208 if (aObjectResourceSlotsArray[slot].shapeSet == 0) {
209 aObjectResourceSlotsArray[slot].type = type;
211 (signed char)(type + 22);
212 if (type == OBJECT_TYPE_ASTEROID_FIELD) {
215 FetchDiskPacketRetrying(3, 13, 0);
218 FetchDiskPacketRetrying(3, 16, 0);
230 if (nMemoryConfig == 2) {
234 3, 17, 0);
243 }
244 obj = 10;
245 do {
246 if (aeObjectClass[obj] ==
248 apObjShapeArray[obj] =
251 }
252 obj++;
253 } while (obj <= SPACE_LAST_MOVING_OBJECT);
254 return 0;
255 }
256 if (type != OBJECT_TYPE_MINE_FIELD) {
257 if (aObjectTypeData[type].objectClass !=
259 aObjectTypeData[type].objectClass !=
262 section = 0;
263 do {
265 [section] =
267 (short)
269 section, 4);
270 if (aapPacketReferences[slot]
271 [section] == 0)
272 break;
273 section++;
274 } while (section < 0x25);
275 }
279 0x25, 0);
280 aObjectTypeData[type].shape =
282 obj = 1;
283 do {
284 if (aeObjectTypeList[obj] == type) {
286 &apObjShapeArray[obj], 0);
288 }
289 obj++;
290 } while (obj < 10);
291 return 0;
292 }
293
297 0, 0);
303 2, 0);
309 1, 0);
310 aObjectTypeData[type].shape =
312 obj = 0;
313 do {
314 if (aeObjectClass[obj] >=
316 aeObjectTypeList[obj] == type) {
317 apObjShapeArray[obj] =
319 .shapeSet;
320 }
321 obj++;
322 } while (obj < 10);
323 }
324 }
325 }
326 return 0;
327}
328
329/* Function start: 0x40BC70 */
330int free_ship(short slot)
331{
332 enum ObjectType type;
333 short obj;
334 short section;
335
336 type = (enum ObjectType)aObjectResourceSlotsArray[slot].type;
337
338 if (aObjectTypeData[type].objectClass == OBJECT_CLASS_CAPITAL_SHIP) {
341 for (section = 0; section < 0x25; section++) {
343 &aapPacketReferences[slot][section],
344 4);
345 }
346 }
348 aObjectTypeData[type].shape = 0;
349 }
350 if (aObjectResourceSlotsArray[slot].shapeSet == 0)
351 return 0;
352
354 if (type == OBJECT_TYPE_ASTEROID_FIELD) {
357 0);
360 0);
366 obj = 10;
367 do {
369 remove_object(obj);
370 else if (aeObjectClass[obj] ==
372 apObjShapeArray[obj] = 0;
373 obj++;
374 } while (obj <= SPACE_LAST_MOVING_OBJECT);
375 return 0;
376 }
377
378 if (type != OBJECT_TYPE_MINE_FIELD) {
379 aObjectTypeData[type].shapeSet = 0;
381 aObjectTypeData[type].animation = 0;
383 aObjectTypeData[type].shape = 0;
384 obj = 0;
385 do {
386 if (aeObjectClass[obj] >=
388 aeObjectTypeList[obj] == type)
389 apObjShapeArray[obj] = 0;
390 obj++;
391 } while (obj < 10);
392 }
393 return 0;
394}
395
396/* Function start: 0x40BE20 */
398{
399 short slot = 0;
400
403 do {
404 if (aObjectResourceSlotsArray[slot].type != -1)
405 free_ship(slot);
406 slot++;
407 } while (slot < 3);
409 return 0;
410}
411
412/* Function start: 0x40BE60 */
414{
415 enum ObjectType type;
416 short slot;
417
419 slot = 0;
421 do {
422 type = (enum ObjectType)
423 aObjectResourceSlotsArray[slot].type;
424 if (type != -1)
425 load_ship(type, slot);
426 slot++;
427 } while (slot < 3);
428 return 0;
429}
430
431/* Function start: 0x40BEA0 */
433{
434 short i = 0;
435
436 do {
437 remove_object(i);
438 i = i + 1;
439 } while (i < 10);
440}
441
442/* Function start: 0x40BEC0 */
443short get_shape_slot(void)
444{
445 short slot = 0;
446
447 do {
448 if (aObjectResourceSlotsArray[slot].type == -1)
449 return slot;
450 slot++;
451 } while (slot < 4);
452 return -1;
453}
454
455/* Function start: 0x40BEF0 */
457{
458 short slot = 0;
459
460 do {
461 if ((enum ObjectType)
462 aObjectResourceSlotsArray[slot].type == type)
463 return 1;
464 slot++;
465 } while (slot < 4);
466 return 0;
467}
468
469/* Function start: 0x40BF20 */
470int shape_needed(const MissionNavPoint *navPoint, enum ObjectType type)
471{
472 short preload;
473
474 if (type != (enum ObjectType)-1) {
475 for (preload = 0; preload < 2; preload++) {
476 if (navPoint->preloadObjectTypes[preload] == type)
477 return 1;
478 }
479 }
480 return 0;
481}
482
483/* Function start: 0x40BF50 */
485{
486 ObjectResourceSlot *resource;
487 short slot;
488 short preload;
489 enum ObjectType type;
490
492 slot = 1;
494 do {
495 resource = &aObjectResourceSlotsArray[slot];
496 if (resource->type != -1 &&
497 !shape_needed(navPoint, (enum ObjectType)resource->type)) {
498 free_ship(slot);
499 resource->type = -1;
500 }
501 slot++;
502 } while (slot < 3);
503
504 for (preload = 0; preload < 2; preload++) {
505 type = navPoint->preloadObjectTypes[preload];
506 if (type != (enum ObjectType)-1) {
507 if (!shape_loaded(type)) {
508 slot = get_shape_slot();
509 if (slot != -1)
510 load_ship(type, slot);
511 }
512 }
513 }
515 return 0;
516}
517
518/* Function start: 0x40BFF0 */
519int set_up_action_sphere(short navPoint)
520{
521 MissionNavPoint *nav;
522 int objectIndex;
523 short obj;
524 short trigger;
525 short objective;
526 signed char triggerType;
527
528 nCurrentNavigationPoint = navPoint;
529 nav = &aMissionNavPoints[navPoint];
531 aMissionNavPoints[navPoint + 1].type == 2 ? 2 : -1;
532 nEnemySighting = 0x7fff;
533
534 for (obj = 1; obj < 10; obj++) {
535 objectIndex = obj;
536 if (aeObjectClass[objectIndex] != OBJECT_CLASS_NULL &&
537 acShipSpawnNavPt[objectIndex] != -1) {
538 if (aeObjectClass[objectIndex] >= OBJECT_CLASS_SHIP &&
539 aeShipMissionType[objectIndex] == MISSION_TYPE_ROUT) {
541 nShipMissionIndices[objectIndex]].state = 3;
542 }
543 if (aeObjectClass[objectIndex] ==
545 FreePacketAndClear(&apObjShapeArray[objectIndex], 0);
546 }
547 if (asObjectScreenXList[objectIndex] != -0x7fff)
548 explode(-1, obj);
549 else
550 remove_object(obj);
551 }
552 }
556
557 for (obj = 0; obj < 10; obj++) {
558 if (nav->missionShips[obj] != -1)
559 init_ship(nav->missionShips[obj], navPoint);
560 }
561
562 trigger = 0;
563 do {
564 triggerType = ((signed char *)nav->triggers)[trigger];
565 if (triggerType != -1) {
567 ((signed char *)nav->triggers)[trigger + 1]].type =
568 triggerType;
569 }
570 trigger += 2;
571 } while (trigger < 8);
572
573 for (objective = 0; objective < cMissionObjectiveCountValue; objective++) {
574 LocateMobileObjective(objective);
575 }
578 return 0;
579}
580
581/* Function start: 0x40C150 */
582void free_pilot_talk(short personality)
583{
584 short line;
585
586 for (line = 0; line < 11; line++) {
587 if (aapszPilotSpeeches[personality][line] != 0) {
589 &aapszPilotSpeeches[personality][line], 0);
590 }
591 if (apCommunicationPortraitShapesTable[personality] != 0) {
593 &apCommunicationPortraitShapesTable[personality], 8);
594 }
595 }
596}
597
598/* Function start: 0x40C1A0 */
599/* Nothing in the shipped executable calls this. */
601{
602 short personality;
603
604 for (personality = 0; personality < 14; personality++) {
605 free_pilot_talk(personality);
606 }
607}
608
609/* Function start: 0x40C1C0 */
610void get_pilot_talk(short personality)
611{
612 char speech[84];
613 short file;
614 short line;
615 short loaded;
616
617 free_pilot_talk(personality);
619 loaded = 1;
620 file = OpenDataFileOrDie(pDiskFileRecords[13].name);
621 loaded &= (file >= 0);
622 for (line = 0; line < 11; line++) {
623 loaded &= (ReadDataFileAtOffset(file,
624 (personality * 11 + line) * 80,
625 80, speech) != 0);
626 if (loaded != 0) {
627 aapszPilotSpeeches[personality][line] =
628 AllocateTaggedMemory(strlen(speech) + 1, 0);
629 DosStrcpy(aapszPilotSpeeches[personality][line], speech);
630 }
631 }
632
633 CloseDataFile(file);
634 if (loaded == 0)
635 ShowModalMessage("Error loading pilot speech");
636 LoadCommPortraitShape(personality, 4);
637}
638
639/* Function start: 0x40C2B0 */
640unsigned int init_personalities(void)
641{
642 short missionShip;
643 short personality;
644 short face;
645
646 missionShip = 0;
647 do {
648 personality = (short)
649 aMissionShips[missionShip].behaviour.pilot - 5;
650 if (personality >= 0 && personality < 8) {
651 face = get_face(personality, SIDE_IMPERIAL);
652 get_pilot_talk(face);
653 }
654 if (personality > 8) {
655 face = get_face(personality, SIDE_KILRATHI);
656 get_pilot_talk(face);
657 prepare_ace((short)(personality - 9));
658 }
659 missionShip++;
660 } while (missionShip < ACTIVE_MISSION_SHIP_COUNT);
661
662 face = get_face(-1, SIDE_KILRATHI);
663 get_pilot_talk(face);
664 face = get_face(-1, SIDE_IMPERIAL);
665 get_pilot_talk(face);
666 return 0;
667}
668
669/* Function start: 0x40C350 */
670unsigned int room_for_me(short obj, short minimum)
671{
672 return 1;
673}
674
675/* Function start: 0x40C360 */
676void approve_xyz(short obj, short minimum, short maximum)
677{
678 if (obj == -1 || room_for_me(obj, minimum) != 0)
679 return;
680 do {
682 &aShipPositionsArray[obj]);
683 } while (room_for_me(obj, minimum) == 0);
684}
685
686/* Function start: 0x40C3C0 */
688{
689 MissionNavPoint *waveNav;
690 short entry;
691
692 if (nTrainSimActive != 0) {
693 spacetrack(21, 2, 0);
695 if (nCurrentWave != -1)
699 }
700
701 if (nCurrentWave == -1 || nCannedSceneMode != 0)
702 return;
703
704 /* The original indexes through a base biased one MissionNavPoint before
705 * aMissionNavPoints. Preserve that -1 when expressing it as a typed
706 * array index: arcade wave 2 is stored in nav record 1. */
708 if (waveNav->type == nCurrentWave++) {
709 new_sphere_shapes(waveNav);
710 waveNav->type = -1;
711 for (entry = 0; entry < 10; entry++) {
712 approve_xyz(init_ship(waveNav->missionShips[entry],
714 5000, 10000);
715 }
716 } else {
717 nCurrentWave = -1;
718 }
719}
720
721/* Function start: 0x40C4A0 */
722unsigned int sub_int_vector(const ShortVector *left,
723 const ShortVector *right,
724 ShortVector *difference)
725{
726 difference->x = left->x - right->x;
727 difference->y = left->y - right->y;
728 difference->z = left->z - right->z;
729 return 0;
730}
731
732/* Function start: 0x40C4E0 */
733unsigned int set_formation_position(short obj,
734 const MissionShipRecord *record)
735{
736 const MissionShipRecord *leaderRecord;
737 short source;
738
739 if (record->formationIndex != -1) {
740 source = obj;
741 for (leaderRecord = record;
742 leaderRecord->leaderMissionIndex != -1;
743 leaderRecord = &aMissionShips[
744 leaderRecord->leaderMissionIndex])
745 source = find_ship_index(leaderRecord->leaderMissionIndex);
746
749 [record->formationSpot],
751 [leaderRecord->formationSpot],
753 if (source == 0 && bInitialFormationSetup == 0)
754 return 0;
755 copy_frame(source, obj);
756 set_sphere_point(leaderRecord, &aShipPositionsArray[obj]);
758 &aShipPositionsArray[obj]);
759 anShipSpeed[obj] = leaderRecord->speed << 8;
760 }
761 return 0;
762}
763
764/* Function start: 0x40C5E0 */
765unsigned int Set_up_ship_info(short obj, short missionShip,
766 signed char navPoint)
767{
768 MissionShipRecord *record;
769
772 acPreviousAttackers[obj] = -1;
773 asActionCounts[obj] = 0;
774 abShipExhaustHeatList[obj] = 0;
775 asShipAccumulatedDmg[obj] = 0;
776 acShipDmg[obj] = 0;
777 asCannedCommands[obj] = 0;
778 acShipIonDriveDmg[obj] = 0;
781 apCannedSequenceList[obj] = 0;
782 acShipSpawnNavPt[obj] = navPoint;
783 nShipMissionIndices[obj] = missionShip;
784 acShipPointingModeList[obj] = 1;
785
786 record = &aMissionShips[missionShip];
788 alter_yaw((short)-record->pitch, obj);
789 alter_pitch((short)-record->yaw, obj);
790 alter_roll(record->roll, obj);
791 aeShipSide[obj] = record->side;
792 anShipSpeed[obj] = record->speed << 8;
793 aiPilotLevel[obj] = record->behaviour.pilot;
794 reset_mission_type(obj, record->missionType);
798 set_formation_position(obj, record);
801 return 0;
802}
803
804/* Function start: 0x40C740 */
805unsigned int is_team_member(short missionShip)
806{
807 short index;
808
809 if (missionShip == stCurrentMissionHeader.playerMissionShip)
810 return 1;
811 for (index = 0; index < 8; index++) {
812 if (missionShip == stCurrentMissionHeader.initialMissionShips[index])
813 return 1;
814 }
815 return 0;
816}
817
818/* init_ship's callees from other modules. */
819void AddFixedVectors(const FixedVector *left, const FixedVector *right,
820 FixedVector *sum);
821short initialize_ship(enum ObjectType type, short owner);
822
823/* Function start: 0x40C780 */
824unsigned int find_next_ship_turn_slot(short obj)
825{
826 short other;
827 signed char interval;
828
829 acTurnRegulatorsArray[obj] = 1;
830 interval = (signed char)anPilotTurnInterval[aiPilotLevel[obj]];
831 acTurnIntervalArray[obj] = interval;
832 other = 1;
833 do {
834 if (aeObjectClass[other] == OBJECT_CLASS_SHIP &&
835 other != obj &&
837 acTurnIntervalArray[other] == interval) {
839 other = 1;
840 if (interval < acTurnRegulatorsArray[obj])
841 break;
842 }
843 other++;
844 } while (other <= 9);
845 return 0;
846}
847
848/* Function start: 0x40C800 */
849short init_ship(short missionShip, short navPoint)
850{
851 MissionShipRecord *record;
852 enum ObjectType type;
853 FixedVector center;
854 short obj;
855
856 if (missionShip == -1)
857 return -1;
858 record = &aMissionShips[missionShip];
859 type = record->type;
860 if (type == OBJECT_TYPE_ASTEROID_FIELD ||
861 type == OBJECT_TYPE_MINE_FIELD) {
862 AddFixedVectors(&aMissionNavPoints[navPoint].position,
863 &record->position, &center);
864 add_hazard_field(type, center,
865 (short)(record->speed + 3000),
866 (short)record->behaviour.pilot);
867 } else {
868 obj = find_ship_index(missionShip);
869 if (obj != -1 || record->state != 0)
870 return -1;
872 is_alive(record->behaviour.pilot) == 0) {
873 if (record->behaviour.pilot <= 8)
874 return -1;
875 record->behaviour.pilot = 3;
876 }
877 record->navPoint = navPoint;
878 if (is_team_member(missionShip) != 0)
879 navPoint = -1;
880 obj = initialize_ship(type, -1);
881 if (obj != -1) {
882 Set_up_ship_info(obj, missionShip, (signed char)navPoint);
884 check_futurion(obj);
885 return obj;
886 }
887 }
888 /* The original hazard path returns the still-uninitialized object slot. */
889 return obj;
890}
891
892/* Function start: 0x40C950 */
893unsigned int init_intelligence_data(short obj)
894{
895 short missionTarget;
896
897 abShipTurnList[obj] = 0;
898 clear_alert(obj);
900 missionTarget = anShipMissionShips[obj];
903
904 switch (aeShipMissionType[obj]) {
909 anShipMissionShips[obj] = missionTarget;
910 break;
913 aMissionNavPoints[missionTarget].position;
914 break;
918 if (aeShipSide[obj] == SIDE_KILRATHI)
919 break;
920 /* fall through */
923 break;
925 apCannedSequenceList[obj] = (const short *)aiPilotLevel[obj];
926 aiPilotLevel[obj] = 2;
928 break;
929 default:
930 break;
931 }
932
933 if (aiPilotLevel[obj] > 4)
934 acShipRating[obj] =
935 (signed char)(aiPilotLevel[obj] -
937 else
938 acShipRating[obj] =
939 (signed char)~RATING_PROVINCIAL;
940 acShipStressList[obj] = 0;
941 return 0;
942}
943
944/* Function start: 0x40CAA0 */
945short __stdcall SampleBothJoysticks(InputDeviceSample *samples,
946 short fallback)
947{
948 GetJoystickPosition(&samples[0].x,
949 &samples[0].y,
950 &samples[0].buttons, 0, fallback);
951 GetJoystickPosition(&samples[1].x,
952 &samples[1].y,
953 &samples[1].buttons, 1, fallback);
954 return 1;
955}
956
957/* Function start: 0x40CAE0 */
959 short joystick,
960 unsigned short fallback)
961{
962 InputDeviceSample *sample;
963 int result;
964 short sampleIndex;
965
966 if (joystick != 0)
967 sampleIndex = 1;
968 else
969 sampleIndex = 0;
970 sample = &samples[sampleIndex];
971 result = GetJoystickPosition(&sample->x,
972 &sample->y,
973 &sample->buttons, joystick, fallback);
974 if (result != 0)
976 return result;
977}
978
979/* Function start: 0x40CB20 */
980/* No inbound reference is known in the shipped executable; this routine is
981 * believed unreachable. */
983{
984 return GetJoystickButtons();
985}
986
987/* Function start: 0x40CB30 */
988/* No inbound reference is known in the shipped executable; this routine is
989 * believed unreachable. */
991{
992 short device;
993
995 if (device != -1)
997 device, 0);
998}
999
1000/* Function start: 0x40CB60 */
1001void DrawNavTextLine(unsigned char alignment, unsigned short colour,
1002 const char *format, ...)
1003{
1004 va_list arguments;
1005
1006 va_start(arguments, format);
1007 pCurTextContext->colour = colour;
1008 pCurTextContext->alignment = alignment;
1011 FormatTextTokens((void (__stdcall *)(int))AppendTextCharacter,
1012 format, arguments);
1013 va_end(arguments);
1015}
1016
1017/* Function start: 0x40CBB0 */
1019{
1020 nNavMapCoordinateScaling = enabled;
1021}
1022
1023/* Function start: 0x40CBC0 */
1024void ScaleNavMapMarkerSize(short *size)
1025{
1026 *size = (short)(*size / (nNavMapScale * 100));
1027}
1028
1029/* Function start: 0x40CBE0 */
1030void ScaleNavMapCoordinates(short *x, short *y, short mapX, short mapY)
1031{
1032 *x = (short)((mapX - nNavMapCentreX) /
1033 nNavMapScale + 75);
1034 *y = (short)((nNavMapCenterPositionY - mapY) /
1035 nNavMapScale + 67);
1036}
1037
1038/* Function start: 0x40CC30 */
1039void nav_getxy(short *x, short *y, int worldX, int worldZ)
1040{
1041 short mapY;
1042
1043 *x = (short)((worldX / 100) >> 8);
1044 mapY = (short)((worldZ / 100) >> 8);
1045 *y = mapY;
1046 if (nNavMapCoordinateScaling != 0)
1047 ScaleNavMapCoordinates(x, y, *x, mapY);
1048}
1049
1050/* Map-extent and objective helpers from other modules. */
1051short MinShort(short a, short b);
1052short MaxShort(short a, short b, ...);
1053short find_ship_index(short missionShip);
1054short mobile_objective(short objective);
1055int set_new_objective(short pathIndex);
1056
1057/* Function start: 0x40CC80 */
1069
1070/* Function start: 0x40CCF0 */
1071void IncludeNavMapWorldPoint(int worldX, int worldZ)
1072{
1073 short x;
1074 short y;
1075
1076 nav_getxy(&x, &y, worldX, worldZ);
1077 CheckPoint(x, y);
1078}
1079
1080/* Function start: 0x40CD30 */
1081void SetScale(void)
1082{
1083 short objectiveIndex;
1084 short ship;
1085 short halfHeight;
1086 short halfWidth;
1087 short height;
1088 short width;
1089
1095 for (objectiveIndex = 0; objectiveIndex < (short)cMissionObjectiveCountValue; objectiveIndex++) {
1096 if (mobile_objective(objectiveIndex) != 0) {
1097 ship = find_ship_index((short)
1098 aMissionObjectivesArray[objectiveIndex].index);
1099 if (ship != -1)
1100 aMissionObjectivesArray[objectiveIndex].position =
1101 aShipPositionsArray[ship];
1102 }
1103 nav_getxy(
1104 &aMissionObjectivesArray[objectiveIndex].mapX,
1105 &aMissionObjectivesArray[objectiveIndex].mapY,
1106 aMissionObjectivesArray[objectiveIndex].position.x,
1107 aMissionObjectivesArray[objectiveIndex].position.z);
1108 CheckPoint(aMissionObjectivesArray[objectiveIndex].mapX,
1109 aMissionObjectivesArray[objectiveIndex].mapY);
1110 }
1112 aShipPositionsArray[0].z);
1113 width = (short)(nNavMapMaximumPositionX -
1115 height = (short)(nNavMapMaximumPosY -
1117 halfWidth = (short)(width / 2);
1119 (short)(nNavigationMapMinimumCoordX + halfWidth);
1120 halfHeight = (short)(height / 2);
1122 (short)(nNavigationMapMinimumPositionY + halfHeight);
1124 (short)((width + halfWidth) / 150),
1125 (short)((halfHeight + height) / 135));
1126 if (nNavMapScale == 0)
1127 nNavMapScale = 100;
1129}
1130
1131/* Function start: 0x40CED0 */
1133{
1134 MissionObjectiveSource *source;
1135 MissionShipRecord *ship;
1136 FixedVector position;
1137 int type;
1138 const char *displayName;
1139 short flightPathCount;
1140 short sourceIndex;
1141
1142 flightPathCount = 0;
1145 source = aMissionObjectiveSources;
1146 type = source->type;
1147 for (; type != -1; source++, type = source->type) {
1148 sourceIndex = source->index;
1151 switch (type) {
1152 case 0:
1153 position = aMissionNavPoints[
1154 sourceIndex].position;
1155 displayName = aMissionNavPoints[
1156 sourceIndex].name;
1157 abFlightPathList[flightPathCount++] =
1159 break;
1160 case 1:
1161 case 2:
1162 case 3:
1163 case 4:
1164 ship = &aMissionShips[sourceIndex];
1165 displayName =
1167 set_sphere_point(ship, &position);
1168 abFlightPathList[flightPathCount++] =
1170 break;
1171 }
1172
1181 nav_getxy(
1186 position.x, position.z);
1190 }
1191
1192 abFlightPathList[flightPathCount] = -1;
1195 cCurrentNavPtIdx = 0;
1197 if (cMissionObjectiveCountValue != 0) {
1198 while (set_new_objective(
1199 (short)cCurrentNavPtIdx) == 0)
1201 }
1202}
InputDeviceSample aInputDevSamples[2]
Definition nav.c:78
signed char acShipRating[16]
Definition joycal.c:25
signed char acShipDestroyedWeaponCountArray[16]
Definition screen.c:31
enum ShipTactic aeShipTacticArray[12]
Definition input.c:20
MissionHeaderDisk stCurrentMissionHeader
Definition mission.c:57
short anShipMissionShips[16]
Definition comm.c:57
signed char abShipExhaustHeatList[10]
Definition input.c:21
signed char acShipSpawnNavPt[16]
Definition music.c:88
short nCurrentWave
Definition game.c:34
short nMissionMedalScoreValue
Definition gameflow.c:29
enum Side aeShipSide[12]
Definition ending.c:22
short nEnemySighting
Definition brains.c:20
signed char acShipStressList[16]
Definition ending.c:20
int nMemoryConfig
Definition ship.c:58
signed char acPlayerComponentDamageList[9]
Definition smart.c:19
short nNavMapCoordinateScaling
Definition nav.c:12
enum ShipManeuver aeShipManeuversTable[12]
Definition screen.c:25
ObjectTypeData aObjectTypeData[OBJECT_TYPE_COUNT]
Definition objdata.c:86
int aiPilotLevel[12]
Definition video.c:16
CampaignDate * pElapsedCampaignDatePtr
Definition mission.c:59
ShortVector aShipFormationDeltaList[10]
Definition data.c:254
signed char cMissionObjectiveCountValue
Definition game.c:554
short asShipAccumulatedDmg[SPACE_OBJECT_COUNT]
Definition music.c:89
Viewport * pScrambleView
Definition mission.c:61
short nDebriefingPersonality
Definition mission.c:14
signed char acWingmanMessageStatesArray[16]
Definition video.c:25
signed char acShipIonDriveDmg[16]
Definition comm.c:56
TextContext * pCurTextContext
Definition data.c:244
unsigned char abSeriesAuxData[0x28]
Definition mission.c:55
short nArcadeBonusCountdown
Definition main.c:42
signed char abFlightPathList[MISSION_OBJECTIVE_COUNT]
Definition smart.c:20
signed char acShipDmg[10]
Definition game.c:553
signed char abShipTurnList[16]
Definition screen.c:17
PacketResourceDescriptor aMissionResourceDescriptors[5]
Definition logic.c:40
int nAvailableGameMemory
Definition ship.c:61
enum ShipMissionType aeShipMissionType[12]
Definition game.c:550
MissionObjectiveSource aMissionObjectiveSources[16]
Definition mission.c:56
MissionNavPoint aMissionNavPoints[MISSION_NAV_POINT_COUNT]
Definition game.c:199
short nSceneScrambleCanopyFrameValue
Definition mission.c:62
int bCurrentPlayerDestroyed
Definition logic.c:111
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
Definition video.c:21
short nNavMapMaximumPosY
Definition nearheap.c:19
short bCurrentExpandedMemoryAvail
Definition eventmgr.c:27
short nYourWingman
Definition game.c:61
signed char acShipPointingModeList[16]
Definition ending.c:28
const short * apCannedSequenceList[12]
Definition screen.c:26
short asCannedCommands[16]
Definition comm.c:59
FixedVector aShipVelocity[SPACE_OBJECT_COUNT]
Definition smart.c:21
short nStartNavPointOverride
Definition main.c:41
short asCapitalShipViewFramesTable[16]
Definition screen.c:28
int nArcadeState
Definition main.c:22
short nCarrierMissionShipIndexValue
Definition cockpt.c:101
FixedVector aShipMissionSpotArray[10]
Definition screen.c:27
int anShipSpeed[64]
Definition data.c:248
short nWingmanKillCount
Definition init.c:57
int nSceneResourceBudgetValue
Definition ship.c:62
void * aapPacketReferences[4][0x25]
Definition mission.c:17
short asShipWingLeaderArray[16]
Definition comm.c:51
short asObjectCounterArray[SPACE_OBJECT_COUNT]
Definition game.c:547
int nCannedSceneMode
Definition main.c:21
signed char cCurrentObjective
Definition game.c:37
CampaignState stCampaignState
Definition dib.c:107
short asObjectScreenXList[SPACE_OBJECT_COUNT]
Definition screen.c:21
unsigned char bLandingAuthorized
Definition spc.c:14
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
short nCurrentActiveInputDevice
Definition nav.c:60
short nFreeShipSlot
Definition game.c:25
short nCurrentNavigationPoint
Definition music.c:90
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
Definition data.c:255
ObjectResourceSlot aObjectResourceSlotsArray[4]
Definition screen.c:30
signed char acTurnIntervalArray[16]
Definition screen.c:15
short nNavMapMaximumPositionX
Definition nearheap.c:16
short nPlayerKillTotal
Definition logic.c:112
short nNavMapCenterPositionY
Definition nav.c:58
MissionShipRecord aMissionShips[MISSION_SHIP_STORAGE_COUNT]
Definition game.c:230
signed char acPreviousAttackers[16]
Definition dib.c:101
short nCurrentHazardFieldTotal
Definition dib.c:100
short nShipMissionIndices[10]
Definition game.c:559
FixedVector aShipPositionsArray[SPACE_OBJECT_COUNT]
Definition game.c:556
DiskFileRecord * pDiskFileRecords
Definition disk.c:36
signed char cCurrentObjResourceLogicalFile
Definition mission.c:60
short nNavigationMapMinimumCoordX
Definition nearheap.c:17
signed char acShipCommunicatorArray[16]
Definition game.c:560
short nNavMapScale
Definition nav.c:13
signed char cCurrentNavPtIdx
Definition dib.c:96
struct Shape * apCommunicationPortraitShapesTable[16]
Definition music.c:96
char * aapszPilotSpeeches[14][11]
Definition music.c:98
int nCurrentWingmanKilledThisMission
Definition init.c:56
short nTargetLockMode
Definition game.c:95
enum SpecialManeuver aeSpecialManeuvers[12]
Definition game.c:549
short nNavMapCentreX
Definition nearheap.c:20
short asActionCounts[10]
Definition dib.c:103
signed char acTurnRegulatorsArray[16]
Definition joycal.c:35
CampaignDate * pCurrentCampaignDate
Definition mission.c:58
short nNavigationMapMinimumPositionY
Definition nearheap.c:21
static int bInitialFormationSetup
Definition mission.c:16
static int anPilotTurnInterval[18]
Definition mission.c:50
static ShortVector aaFormationPositions[5][8]
Definition mission.c:20
void FreeAllPilotTalk(void)
Definition mission.c:600
short missionScore
Definition wcdata.h:723
enum ObjectType playerShipType
Definition wcdata.h:711
int personalityDeathMission[8]
Definition wcdata.h:718
unsigned int buttons
Definition wc1base.h:152
short homeMissionShip
Definition wcdata.h:564
short playerMissionShip
Definition wcdata.h:565
short entryNavPoint
Definition wcdata.h:563
short initialMissionShips[8]
Definition wcdata.h:566
FixedVector position
Definition wcdata.h:859
enum ObjectType preloadObjectTypes[2]
Definition wcdata.h:862
short missionShips[10]
Definition wcdata.h:863
char name[0x1e]
Definition wcdata.h:857
signed char type
Definition wcdata.h:858
signed char triggers[4][2]
Definition wcdata.h:861
const char * displayName
Definition wcdata.h:929
unsigned char flags
Definition wcdata.h:928
signed char index
Definition wcdata.h:927
FixedVector position
Definition wcdata.h:931
enum ShipMissionType missionType
Definition wcdata.h:884
enum Side side
Definition wcdata.h:881
signed char targetMissionIndex
Definition wcdata.h:899
enum ObjectType type
Definition wcdata.h:880
signed char navPoint
Definition wcdata.h:885
MissionShipBehaviour behaviour
Definition wcdata.h:893
signed char leaderMissionIndex
Definition wcdata.h:897
FixedVector position
Definition wcdata.h:886
signed char formationIndex
Definition wcdata.h:898
signed char formationSpot
Definition wcdata.h:890
signed char state
Definition wcdata.h:896
unsigned char * animation
Definition wcdata.h:913
signed char type
Definition wcdata.h:911
struct Shape * shapeSet
Definition wcdata.h:912
struct Shape * shape
Definition wcdata.h:914
unsigned char * animation
Definition wcdata.h:380
struct Shape * shapeSet
Definition wcdata.h:393
struct Shape * shape
Definition wcdata.h:394
const char * displayName
Definition wcdata.h:369
short z
Definition wcdata.h:435
short x
Definition wcdata.h:433
short y
Definition wcdata.h:434
unsigned char colour
Definition wc1base.h:240
char * text
Definition wc1base.h:242
char * textCursor
Definition wc1base.h:243
unsigned char alignment
Definition wc1base.h:244
Umbrella header for the game core.
void clear_alert(short obj)
Definition logic.c:189
int shape_loaded(enum ObjectType type)
Definition mission.c:456
int __stdcall GetJoystickPosition(int *x, int *y, unsigned int *buttons, short joystick, unsigned short fallback)
Definition winmain.c:969
short find_ships_sphere(short missionShip)
Definition logic.c:1165
void Build_objective_list(void)
Definition mission.c:1132
void * AllocateTaggedMemory(int size, unsigned short flags)
Definition ending.c:31
void get_pilot_talk(short personality)
Definition mission.c:610
int new_sphere_shapes(MissionNavPoint *navPoint)
Definition mission.c:484
int locate_ship(short missionShip, FixedVector *point)
Definition logic.c:1200
void approve_xyz(short obj, short minimum, short maximum)
Definition mission.c:676
void CheckPoint(short x, short y)
Definition mission.c:1058
unsigned int init_intelligence_data(short obj)
Definition mission.c:893
short LocateMobileObjective(short objective)
Definition cockpt.c:1204
int set_up_action_sphere(short navPoint)
Definition mission.c:519
int advance_canned_sequence(short obj)
Definition mono.c:246
unsigned int Set_up_ship_info(short obj, short missionShip, signed char navPoint)
Definition mission.c:765
void remove_object(short obj)
Definition geom.c:1002
void alter_pitch(short angle, short obj)
Definition geom.c:619
void DrawNavTextLine(unsigned char alignment, unsigned short colour, const char *format,...)
Definition mission.c:1001
short get_shape_slot(void)
Definition mission.c:443
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 FigureArcadeTime(void)
Definition main.c:1862
void set_objects_data(short obj, enum ObjectType type, short owner)
Definition ship.c:173
void set_up_next_wave(void)
Definition mission.c:687
void __stdcall PromptInsertNumberedDisk(short logicalFile)
Definition disk.c:322
void alter_roll(short angle, short obj)
Definition geom.c:635
unsigned int spacetrack(int track, int mode, short enabled)
Definition music.c:411
void SetNavMapCoordinateScaling(short enabled)
Definition mission.c:1018
short __stdcall SampleBothJoysticks(InputDeviceSample *samples, short fallback)
Definition mission.c:945
int __stdcall ReadDataFileAtOffset(unsigned short fd, int offset, unsigned int length, void *data)
Definition mono.c:61
int LoadPacketResourceList(PacketResourceDescriptor *resources, short flags, int availableBytes)
Definition logic.c:1429
short MinShort(short a, short b)
Definition mathutil.c:20
unsigned int find_next_ship_turn_slot(short obj)
Definition mission.c:824
void ShowModalMessage(const char *format,...)
Definition main.c:1258
unsigned int GetScreenUpdateFlag(void)
Definition main.c:361
unsigned int offset_location(short obj, const ShortVector *offset, FixedVector *location)
Definition smart.c:192
void __stdcall CloseDataFile(unsigned short fd)
Definition mono.c:23
int free_all_slots(void)
Definition mission.c:397
int explode(short attacker, short victim)
Definition ship.c:1340
void GetArcadeBonus(void)
Definition main.c:1852
unsigned int init_3Space_objects()
void copy_frame(short source, short destination)
Definition geom.c:585
char *__stdcall DosStrcpy(char *dst, const char *src)
Definition strdos.c:49
unsigned int initialize_view_buffer(void)
Definition main.c:371
void free_pilot_talk(short personality)
Definition mission.c:582
int set_new_objective(short pathIndex)
Definition cockpt.c:1131
void prepare_ace(short ace)
Definition logic.c:153
void alter_yaw(short angle, short obj)
Definition geom.c:627
void remove_nav_point_objects(void)
Definition mission.c:432
int release_all_capital_ship_shapes(void)
Definition mission.c:170
short initialize_ship(enum ObjectType type, short owner)
Definition ship.c:102
short __stdcall OpenDataFileOrDie(const char *path)
Definition winsys.c:297
void LoadCommPortraitShape(short face, signed char alternate)
Definition comm.c:72
unsigned int is_alive(int pilot)
Definition mission.c:74
unsigned int room_for_me(short obj, short minimum)
Definition mission.c:670
void __stdcall DrawTextString(const char *text)
Definition mathfp.c:232
void zero_vector(FixedVector *vector)
Definition geom.c:280
short GetJoystickButtons(void)
Definition winmain.c:1005
unsigned int LoadMissionData(short series, short mission)
Definition cmpgn.c:586
short init_ship(short missionShip, short navPoint)
Definition mission.c:849
void prepare_mission(void)
Definition mission.c:116
int release_capital_ship_shapes(enum ObjectType type)
Definition mission.c:185
void FormatTextTokens(void(__stdcall *writer)(int), const char *format, va_list arguments)
Definition cockpt.c:116
void SetScale(void)
Definition mission.c:1081
unsigned int InitializeCockpitResources(signed char mode)
Definition logic.c:1741
void SampleActiveJoystickDevice(void)
Definition mission.c:990
void nav_getxy(short *x, short *y, int worldX, int worldZ)
Definition mission.c:1039
short get_face(short rating, unsigned int side)
Definition comm.c:62
unsigned int reset_mission_type(short obj, enum ShipMissionType missionType)
Definition logic.c:653
void ScaleNavMapCoordinates(short *x, short *y, short mapX, short mapY)
Definition mission.c:1030
unsigned int init_mission(short series, short mission)
Definition mission.c:99
unsigned int is_team_member(short missionShip)
Definition mission.c:805
short mobile_objective(short objective)
Definition cockpt.c:1433
short ReadJoystickButtons(void)
Definition mission.c:982
unsigned int init_personalities(void)
Definition mission.c:640
void random_radial(const FixedVector *center, short radius, FixedVector *position)
Definition geom.c:363
short MaxShort(short a, short b,...)
Definition mathutil.c:29
void clean_up_cockpit(void)
Definition targ.c:141
int shape_needed(const MissionNavPoint *navPoint, enum ObjectType type)
Definition mission.c:470
void ScaleNavMapMarkerSize(short *size)
Definition mission.c:1024
unsigned int set_formation_position(short obj, const MissionShipRecord *record)
Definition mission.c:733
void FreePacketAndClear(void *slot, unsigned short releaseFlags)
Definition mathutil.c:37
int load_ship(enum ObjectType type, short slot)
Definition mission.c:202
void __stdcall AppendTextCharacter(char character)
Definition mathfp.c:341
short find_ship_index(short missionShip)
Definition logic.c:439
unsigned int check_futurion(short i)
Definition mission.c:89
void set_sphere_point(const MissionShipRecord *record, FixedVector *position)
Definition mission.c:65
void add_hazard_field(enum ObjectType type, FixedVector center, short radius, short density)
Definition winmain.c:461
void IncludeNavMapWorldPoint(int worldX, int worldZ)
Definition mission.c:1071
int free_ship(short slot)
Definition mission.c:330
void remove_all_hazards(void)
Definition winmain.c:141
int load_all_slots(void)
Definition mission.c:413
short ace_status(short ace, unsigned char bits)
Definition logic.c:115
unsigned int sub_int_vector(const ShortVector *left, const ShortVector *right, ShortVector *difference)
Definition mission.c:722
int __stdcall SampleJoystickDevice(InputDeviceSample *samples, short joystick, unsigned short fallback)
Definition mission.c:958
@ RATING_ACE_SPIRIT
Definition wcdata.h:188
@ RATING_PROVINCIAL
Definition wcdata.h:183
#define SPACE_LAST_MOVING_OBJECT
Definition wcdata.h:1005
@ MISSION_TYPE_ESCORT
Definition wcdata.h:123
@ MISSION_TYPE_WARP_ARRIVE
Definition wcdata.h:129
@ MISSION_TYPE_CANNED_SEQUENCE
Definition wcdata.h:130
@ MISSION_TYPE_GOTO_WARP
Definition wcdata.h:128
@ MISSION_TYPE_WINGMAN
Definition wcdata.h:126
@ MISSION_TYPE_ROUT
Definition wcdata.h:127
@ MISSION_TYPE_DEFEND
Definition wcdata.h:125
@ MISSION_TYPE_COME_HOME
Definition wcdata.h:132
@ MISSION_TYPE_STRIKE
Definition wcdata.h:124
#define ACTIVE_MISSION_SHIP_COUNT
Definition wcdata.h:1011
ObjectType
Definition wcdata.h:54
@ OBJECT_TYPE_TIGERS_CLAW
Definition wcdata.h:63
@ OBJECT_TYPE_DEBRIS_METAL_SHEET
Definition wcdata.h:98
@ OBJECT_TYPE_DEBRIS_WING
Definition wcdata.h:99
@ OBJECT_TYPE_ROCK_CHUNK
Definition wcdata.h:95
@ OBJECT_TYPE_MINE_FIELD
Definition wcdata.h:78
@ OBJECT_TYPE_ASTEROID5
Definition wcdata.h:93
@ OBJECT_TYPE_ASTEROID3
Definition wcdata.h:91
@ OBJECT_TYPE_ASTEROID4
Definition wcdata.h:92
@ OBJECT_TYPE_ASTEROID_FIELD
Definition wcdata.h:77
@ OBJECT_TYPE_ASTEROID6
Definition wcdata.h:94
@ OBJECT_TYPE_ASTEROID1
Definition wcdata.h:89
@ OBJECT_TYPE_ASTEROID2
Definition wcdata.h:90
@ SIDE_IMPERIAL
Definition wcdata.h:174
@ SIDE_KILRATHI
Definition wcdata.h:175
@ SPECIAL_MANEUVER_NONE
Definition wcdata.h:258
@ MANEUVER_WARPING_IN
Definition wcdata.h:208
@ 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
@ OBJECT_CLASS_NULL
Definition wcdata.h:38
@ TACTIC_WARP_IN
Definition wcdata.h:159
#define MISSION_SHIP_SCAN_LIMIT
Definition wcdata.h:1010