Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
nav.c
Go to the documentation of this file.
1/*
2 * Navigation map.
3 *
4 * Retail object 0x44FA70-0x45244F (link order; see docs/ORDER.md).
5 */
6/* This unit owns storage declared in globals.h as statics. */
7#define NAV_C
8#include "game.h"
9
10short g_nNavMapCoordinateScaling = 0; /* 0x0049bb80 */
11short g_nNavMapScale = 1; /* 0x0049bb84 */
40unsigned char *g_pNavMapShape = 0; /* 0x0049bc48 */
41short g_nNavMapLabelCount = 0; /* 0x0049bc4c */
42short g_nNavMapReservedAreaCount = 0; /* 0x0049bc50 */
43unsigned char *g_pNavLocationText = 0; /* 0x0049bc54 */
45 "Patrol",
46 "Escort",
47 "Strike",
48 "Defend",
49 "Wingman",
50 "Flee",
51 "Goto Warp",
52 "Warp Arrive",
53 "Rendezvous",
54 "Come Home",
55 "Tanker",
56 "Tow",
57 "Break Off",
58 0
59}; /* 0x0049bc58 */
61 "Further objectives out-system."; /* 0x0049bc90 */
62short g_bBriefingMapActive = 0; /* 0x0049bcb0 */
63int g_bInflightComputerActive = 0; /* 0x0049bcb4 */
64
65/* NavMapLabelFits tries a placement before TryPlaceNavMapLabel is defined. */
66short TryPlaceNavMapLabel(short x, short y, short width, short force);
67
68/* Function start: 0x44FA70 */
69void DrawNavTextLine(unsigned char alignment, unsigned short colour,
70 const char *format, ...)
71{
72 va_list arguments;
73
76 va_start(arguments, format);
79 /* The original pushes the list itself; the port's FormatTextTokens takes
80 * its address, because va_arg has to advance the caller's copy on an ABI
81 * where a vararg is not always four bytes wide. */
82 FormatTextTokens((void (*)(int))AppendTextCharacter, format,
83 (unsigned long *)arguments);
84 va_end(arguments);
86}
87
88/* Function start: 0x44FADA */
89void SetNavMapCoordinateScaling(short enabled)
90{
92}
93
94/* Function start: 0x44FAEF */
95void ScaleNavMapMarkerSize(short *size)
96{
97 *size = (short)(*size / (g_nNavMapScale * 100));
98}
99
100/* Function start: 0x44FB19 */
101void ScaleNavMapCoordinates(short *x, short *y, short mapX, short mapY)
102{
103 *x = (short)((mapX - g_13_nNavmapMapCentreX) /
104 g_nNavMapScale + 75);
105 *y = (short)(67 - (mapY - g_nNavMapCentreY) /
107}
108
109/* Function start: 0x44FB68 */
110void nav_getxy(short *x, short *y, int worldX, int worldZ)
111{
112 *x = (short)((worldX / 100) >> 8);
113 *y = (short)((worldZ / 100) >> 8);
115 ScaleNavMapCoordinates(x, y, *x, *y);
116}
117
118/* Function start: 0x44FBC8 */
130
131/* Function start: 0x44FC37 */
132void IncludeNavMapWorldPoint(int worldX, int worldZ)
133{
134 short x;
135 short y;
136
137 nav_getxy(&x, &y, worldX, worldZ);
138 CheckPoint(x, y);
139}
140
141/* Function start: 0x44FC6D */
142void SetScale(void)
143{
144 short objectiveIndex;
145 short obj;
146 short mapHeight;
147 short mapWidth;
148
154 for (objectiveIndex = 0;
155 objectiveIndex < (short)g_cMissionObjectiveCount;
156 objectiveIndex++) {
157 if (mobile_objective(objectiveIndex) != 0) {
158 obj = find_ship_index((short)
159 g_aMissionObjectives[objectiveIndex].index);
160 if (obj != -1)
161 g_aMissionObjectives[objectiveIndex].position =
162 g_aShipPosition[obj];
163 }
164 nav_getxy(
165 &g_aMissionObjectives[objectiveIndex].mapX,
166 &g_aMissionObjectives[objectiveIndex].mapY,
167 g_aMissionObjectives[objectiveIndex].position.x,
168 g_aMissionObjectives[objectiveIndex].position.z);
169 CheckPoint(g_aMissionObjectives[objectiveIndex].mapX,
170 g_aMissionObjectives[objectiveIndex].mapY);
171 }
173 g_aShipPosition[0].z);
174 mapWidth = (short)(g_nNavPlotMaxX -
176 mapHeight = (short)(g_nNavmapMapMaximumY -
179 (short)(mapWidth / 2 + g_nNavmapMapMinimumX);
181 (short)(mapHeight / 2 + g_2_nNavMapMinimumYValue);
183 (short)((mapWidth / 2 + mapWidth) / 150),
184 (short)((mapHeight / 2 + mapHeight) / 135));
185 if (g_nNavMapScale == 0)
186 g_nNavMapScale = 100;
188}
189
190void set_sphere_point(const MissionShipRecord *record, FixedVector *position);
191
192/* Function start: 0x44FE9F */
194{
196 short type;
197 const char *text;
198 FixedVector location;
199 short flightPathCount;
200 short i;
201
205 flightPathCount = 0;
207 while ((type = record->type) != -1 &&
209 i = record->index;
212 switch (type) {
213 case 1:
214 case 2:
215 case 3:
216 case 4:
217 case 6:
218 text = (const char *)&g_aMissionShips[i];
219 set_sphere_point(&g_aMissionShips[i], &location);
220 g_abFlightPath[flightPathCount++] =
222 break;
223 case 0:
224 case 5:
225 text =
226 (const char *)&g_aMissionNavPoints[i];
227 location = g_aMissionNavPoints[i].position;
228 g_abFlightPath[flightPathCount++] =
230 break;
231 }
232
243 nav_getxy(
248 location.x, location.z);
252 record++;
253 }
254
255 g_abFlightPath[flightPathCount] = -1;
258 if (g_cMissionObjectiveCount != 0) {
259 while (set_new_objective(
260 (short)g_cCurrentNavPointIndex) == 0)
262 }
263}
264
265/* Function start: 0x450136 */
266short NavMapPointInsideReservedArea(short area, short x, short y)
267{
268 return g_aNavMapExclusionRects[area].left <= x &&
269 g_aNavMapExclusionRects[area].right >= x &&
270 g_aNavMapExclusionRects[area].top <= y &&
272}
273
274/* Function start: 0x4501B2 */
275short NavMapLabelFits(short x, short y, short width, short height)
276{
277 return x > 0 && y > 0 && x + width < 150 && y + height < 135;
278}
279
280short TryPlaceNavMapLabel(short x, short y, short width, short force);
281
282/* Function start: 0x450210 */
283short NavMapLabelPositionAvailable(short x, short y,
284 short width, short height)
285{
286 short clear;
287 short rect;
288 short checkX;
289 short checkY;
290
291 clear = 1;
292 clear = NavMapLabelFits(x, y, width, height);
293 if (clear == 1) {
294 for (rect = 0;
295 rect < g_nNavMapReservedAreaCount && clear != 0;
296 rect++) {
297 for (checkX = x; checkX < x + width && clear != 0;
298 checkX++) {
299 for (checkY = y; checkY < y + height && clear != 0;
300 checkY++) {
301 clear = (short)(NavMapPointInsideReservedArea(
302 rect, checkX, checkY) == 0);
303 }
304 }
305 }
306 }
307 return clear;
308}
309
310/* Function start: 0x450329 */
315
316/* Function start: 0x45033D */
317void ReserveNavMapArea(short x, short y, short width, short height)
318{
324 g_nNavMapReservedAreaCount].right = (short)(x + width);
326 g_nNavMapReservedAreaCount].bottom = (short)(y + height);
328}
329
330/* Function start: 0x4503A7 */
332{
334}
335
336/* Function start: 0x4503BB */
337short TryPlaceNavMapLabel(short x, short y, short width, short force)
338{
339 short placed;
340
341 placed = 0;
342 if (NavMapLabelPositionAvailable(x, y, width, 6) != 0 ||
343 (force != 0 && NavMapLabelFits(x, y, width, 6) != 0)) {
346 placed = 1;
347 }
348 return placed;
349}
350
351#pragma function(strlen)
352/* Function start: 0x450458 */
353void PlaceNavMapLabel(short x, short y, unsigned short colour,
354 const char *text)
355{
356 short textWidth;
357 short shift;
358
359 textWidth = (short)(strlen(text) * 4 + 2);
361 g_nNavMapLabelCount].colour = colour;
364 shift = -1;
365 do {
366 shift++;
367 } while (TryPlaceNavMapLabel((short)(shift + x + 4), y,
368 textWidth, 0) == 0 &&
369 TryPlaceNavMapLabel((short)(x - textWidth / 2),
370 (short)(shift + y + 5), textWidth,
371 (short)(shift == 12)) == 0 &&
372 TryPlaceNavMapLabel((short)(x - textWidth - 3 - shift), y,
373 textWidth, (short)(shift == 12)) == 0 &&
374 TryPlaceNavMapLabel(x, (short)(shift + y + 5), textWidth,
375 (short)(shift == 12)) == 0 &&
376 TryPlaceNavMapLabel((short)(x - textWidth / 2),
377 (short)(y - 9 - shift), textWidth,
378 (short)(shift == 12)) == 0 &&
379 shift != 12);
383 textWidth, 6);
385}
386
387/* Function start: 0x450623 */
388/* Two objectives share a nav label when both are jump-point kinds (type 0 or
389 * 5) or neither is. */
390short ObjectivesShareNavLabel(short objective, short other)
391{
392 switch (g_aMissionObjectives[objective].type) {
393 case 0:
394 case 5:
395 switch (g_aMissionObjectives[other].type) {
396 case 0:
397 case 5:
398 return 1;
399 default:
400 return 0;
401 }
402 default:
403 switch (g_aMissionObjectives[other].type) {
404 case 0:
405 case 5:
406 return 0;
407 default:
408 return 1;
409 }
410 }
411}
412
413/* Objective-state callees from the cockpit module. */
414short hidden_objective(short objective);
415short visited(short objective);
416short achieved(short objective);
417
418/* Function start: 0x4506F8 */
419void AddUniqueObjectiveNavLabel(short x, short y,
420 unsigned short colour, const char *text,
421 short objective, short missionShip)
422{
423 short previous;
424
425 if (missionShip == -1) {
426 PlaceNavMapLabel(x, y, colour, text);
427 return;
428 }
429 for (previous = 0; previous < objective; previous++) {
430 if (hidden_objective(previous) != 0)
431 continue;
432 else if (g_aMissionObjectives[previous].index ==
433 missionShip &&
434 ObjectivesShareNavLabel(objective, previous) != 0)
435 break;
436 }
437 if (previous >= objective)
438 PlaceNavMapLabel(x, y, colour, text);
439}
440
441/* Function start: 0x4507DA */
442short IsPointInNavMapLabel(short labelIndex, short x, short y)
443{
444 return g_1_aNavMapLabels[labelIndex].x <= x &&
445 (unsigned int)x <=
446 (unsigned int)(g_1_aNavMapLabels[labelIndex].x +
447 strlen(g_1_aNavMapLabels[labelIndex].text) * 4) &&
448 g_1_aNavMapLabels[labelIndex].y <= y &&
449 y <= g_1_aNavMapLabels[labelIndex].y + 6;
450}
451
452#pragma intrinsic(strlen)
453
454void DrawViewportLine(Viewport *viewport, short x1, short y1, short x2, short y2, short colour);
455void DrawViewportBorder(Viewport *viewport, short left, short top, short right, short bottom, short colour);
456
457/* Function start: 0x45087F */
459{
460 short label;
461
462 for (label = 0; label < (short)g_nNavMapLabelCount; label++) {
463 DrawFormattedText("%X%Y%F%s",
464 g_1_aNavMapLabels[label].x,
465 g_1_aNavMapLabels[label].y,
466 g_1_aNavMapLabels[label].colour,
467 g_1_aNavMapLabels[label].text);
468 }
469}
470
471/* Function start: 0x450900 */
472void DrawNavRectangleMarker(short x, short y, short size, short shadow,
473 unsigned short colour, short reserve)
474{
475 if (shadow == 0)
477 x, y, size, (short)((size * 7) / 8),
478 (short)colour);
479 else
482 x, y, size, (short)((size * 7) / 8), (short)colour);
483 if (reserve != 0 && size < 5)
484 ReserveNavMapArea((short)(x - size), (short)(y - size),
485 (short)(size * 2 + 1),
486 (short)(size * 2 + 1));
487}
488
489/* Hazard and text-context callees from other modules. */
490short find_ships_sphere(short missionShip);
491void SetTextContext(TextContext *context);
492
493/* Function start: 0x4509C9 */
494void DrawNavSquareOutline(Viewport *viewport, short x, short y,
495 short size, signed char colour)
496{
497 DrawViewportBorder(viewport, (short)(x - size), (short)(y - size),
498 (short)(x + size), (short)(y + size),
499 (short)colour);
500}
501
502/* Function start: 0x450A12 */
503void DrawNavSquareMarker(short x, short y, short size, short shadow,
504 short colour, short reserve)
505{
506 if (size == 0) {
508 x, y, colour);
510 (short)(x + 1), y, colour);
512 x, (short)(y + 1), colour);
514 (short)(x + 1),
515 (short)(y + 1), colour);
516 } else {
518 x, y, size,
519 (signed char)colour);
520 }
521 if (reserve != 0 && size < 5)
522 ReserveNavMapArea((short)(x - size), (short)(y - size),
523 (short)(size * 2 + 1),
524 (short)(size * 2 + 1));
525 (void)shadow;
526}
527
528void AddFixedVectors(const FixedVector *left, const FixedVector *right, FixedVector *sum);
529
530/* Function start: 0x450B03 */
531void DrawNavTriangleOutline(Viewport *viewport, short x, short y,
532 short size, signed char colour)
533{
534 DrawViewportLine(viewport, x, (short)(y - size),
535 (short)(x + size), (short)(y + size), colour);
536 DrawViewportLine(viewport, (short)(x + size), (short)(y + size),
537 (short)(x - size), (short)(y + size), colour);
538 DrawViewportLine(viewport, (short)(x - size), (short)(y + size),
539 x, (short)(y - size), colour);
540}
541
542/* Function start: 0x450BBA */
543void DrawNavTriangleMarker(short x, short y, short size, short shadow,
544 unsigned short colour, short reserve)
545{
547 x, y, size,
548 (signed char)colour);
549 if (reserve != 0 && size < 5)
550 ReserveNavMapArea((short)(x - size), (short)(y - size),
551 (short)(size * 2 + 1),
552 (short)(size * 2 + 1));
553 (void)shadow;
554}
555
556/* The player's own marker is drawn by the routine further down. */
557void DrawNavPlayerMarker(short colour, short reserve);
558
559/* Function start: 0x450C2A */
560void DrawNavCrossMarker(short x, short y, short size, short shadow,
561 unsigned short colour, short reserve)
562{
564 (short)(x - size), (short)(y - size),
565 (short)(x + size), (short)(y + size),
566 (short)colour);
568 (short)(x - size), (short)(y + size),
569 (short)(x + size), (short)(y - size),
570 (short)colour);
571 if (reserve != 0 && size < 5)
572 ReserveNavMapArea((short)(x - size), (short)(y - size),
573 (short)(size * 2 + 1),
574 (short)(size * 2 + 1));
575 (void)shadow;
576}
577
578/* Function start: 0x450CF8 */
579/* Whether this objective sits in the star system the nav map is showing. */
580short IsObjectiveInDisplayedSystem(short objective)
581{
582 short navPoint;
583
584 switch (g_aMissionObjectives[objective].type) {
585 case 0:
586 case 5:
588 g_aMissionObjectives[objective].index]
589 .systemIndex == g_1_stElapsedCampaignDate.year)
590 return 1;
591 else
592 return 0;
593 default:
594 navPoint = find_ships_sphere(
595 g_aMissionObjectives[objective].index);
596 if (navPoint == -1)
597 return 1;
598 else if (g_aMissionNavPoints[navPoint].systemIndex ==
600 return 1;
601 else
602 return 0;
603 }
604}
605
606/* Function start: 0x450DF6 */
607void SetScreenClipRect(unsigned short a, unsigned short b,
608 unsigned short c, unsigned short d)
609{
611}
612
613/* Function start: 0x450E1E */
615 short size, unsigned short markerColour,
616 unsigned short textColour, const char *text)
617{
618 short x;
619 short y;
620
621 AddFixedVectors(&navPosition, &offset, &navPosition);
623 nav_getxy(&x, &y, navPosition.x, navPosition.z);
624 DrawNavRectangleMarker(x, y, size, 0, markerColour, 1);
625 PlaceNavMapLabel(x, y, textColour, text);
626}
627
628/* Function start: 0x450E98 */
629void DrawNavPlayerMarker(short colour, short reserve)
630{
631 short x;
632 short y;
633
634 nav_getxy(&x, &y, g_aShipPosition[0].x,
635 g_aShipPosition[0].z);
639 x, y, colour);
640 DrawNavSquareMarker(x, y, 0, 0, colour, reserve);
641}
642
643/* Function start: 0x450F1E */
644/* Plot the briefing beacons on the nav map: a pixel, a square marker and a
645 * label for each active record. */
647{
648 const NavMapBeacon *beaconRecord;
649 short gridX;
650 short gridY;
651 short navX;
652 short navY;
653
654 beaconRecord = (const NavMapBeacon *)g_abMissionBriefingData;
655 while (beaconRecord->active != 0) {
656 nav_getxy(&navX, &navY, beaconRecord->position.x,
657 beaconRecord->position.z);
658 ScaleNavMapCoordinates(&gridX, &gridY, navX, navY);
661 DrawNavSquareMarker(gridX, gridY, 2, 0,
663 AddUniqueObjectiveNavLabel(gridX, gridY,
665 beaconRecord->name, 0, -1);
666 beaconRecord++;
667 }
668}
669
670/* Function start: 0x450FE2 */
671void BuildMap(short showPlayer)
672{
673 unsigned short nameColour;
674 MissionNavPoint *nav;
675 const NavMapObjectiveStyle *mark;
676 MissionShipRecord *ship;
677 short x;
678 short y;
679 short checkpoint;
680 short index;
681
682 SetScreenClipRect(1, 1, 153, 138);
684 g_pNavMapShape, 0);
685 SetScreenClipRect(2, 2, 152, 137);
690 2, g_ucPrimaryTextColour, -1);
696 SetScale();
698
699 for (checkpoint = 0; checkpoint < 10; checkpoint++) {
700 if (g_aMissionNavPoints[checkpoint].type != 0 &&
701 g_aMissionNavPoints[checkpoint].systemIndex ==
703 for (index = 0; index < 10; index++) {
704 if (nav->missionShips[index] != -1) {
705 ship = &g_aMissionShips[
706 nav->missionShips[index]];
707 /* WC2 hazard field types; the image names neither. */
708 switch (ship->objectType) {
709 case 5:
711 nav->position, ship->position,
712 ship->speed,
715 "Asteroids");
716 break;
717 case 6:
719 nav->position, ship->position,
720 ship->speed,
723 "Mines");
724 break;
725 }
726 }
727 }
728 }
729 nav++;
730 }
731
732 for (index = 0;
734 index++) {
735 if (mobile_objective(index) == 0 ||
737 (signed char)g_aMissionObjectives[
738 index].index].state == 0 &&
739 achieved(index) == 0)) {
741 &x, &y, g_aMissionObjectives[index].mapX,
742 g_aMissionObjectives[index].mapY);
743 if (hidden_objective(index) == 0 &&
744 IsObjectiveInDisplayedSystem(index) != 0) {
747 if (visited(index) == 0)
749 *mark->unvisitedColour);
750 switch (mark->markerType) {
751 case 0:
752 break;
753 case 1:
754 DrawNavSquareMarker(x, y, mark->markerSize, 0,
755 *mark->markerColour, 1);
756 break;
757 case 2:
758 DrawNavRectangleMarker(x, y, mark->markerSize, 0,
759 *mark->markerColour, 1);
760 break;
761 case 3:
762 DrawNavTriangleMarker(x, y, mark->markerSize, 0,
763 *mark->markerColour, 1);
764 break;
765 case 4:
766 DrawNavCrossMarker(x, y, mark->markerSize, 0,
767 *mark->markerColour, 1);
768 break;
769 }
770 if (g_cCurrentObjective == index)
771 nameColour = g_cYellowColour;
772 else
773 nameColour = *mark->labelColour;
777 x, y, nameColour, objective_name(index),
778 index,
779 (short)g_aMissionObjectives[index].index);
780 }
781 }
782 }
783
784 if (showPlayer != 0 &&
788 nav_getxy(&x, &y, g_aShipPosition[0].x,
789 g_aShipPosition[0].z);
793 }
795 SetScreenClipRect(0, 0, 259, 155);
796}
797
798void SetTextContext(TextContext *context);
799
800/* Function start: 0x45153A */
801void UpdateInflightNavText(short showColon)
802{
803 char time[12];
804 short savedX;
805
810 sprintf(time, "%02d",
811 (int)((signed char *)g_4_pElapsedCampaignDatePointer)[0]);
813 "%X%YStandard time %s",
816 time);
817 savedX = g_stNavMapTextCtx.cursorX;
818 if (showColon == 0) {
820 } else {
822 (short)(g_stNavMapTextCtx.cursorX + 4);
823 }
824 sprintf(time, "%02d ",
825 (int)((signed char *)g_4_pElapsedCampaignDatePointer)[1]);
826 DrawFormattedText(time);
827 g_stNavMapTextCtx.cursorX = savedX;
828 if (showColon != 0)
830}
831
832/* Function start: 0x451637 */
833void FormatNavCoordinates(unsigned char *out)
834{
835 unsigned char tmp[4];
836
837 if (out == 0)
838 out = (unsigned char *)&g_1_stElapsedCampaignDate;
840 out[1] = tmp[2];
841 out[0] = tmp[3];
842}
843
844/* Function start: 0x451673 */
845void DrawSelectedNavLegendEntry(const char *text, short navPoint)
846{
847 if ((short)g_cCurrentNavPointIndex == navPoint) {
848 DrawNavTextLine(0, (unsigned short)g_cYellowColour, text);
849 DrawNavTextLine(0, (unsigned short)g_cYellowColour,
850 "\n");
851 }
852}
853
854/* Function start: 0x4516C0 */
856{
857 short objective;
858
859 objective = 0;
860 while (objective < (short)g_cMissionObjectiveCount &&
861 (visited(objective) != 0 || hidden_objective(objective) != 0))
862 objective++;
863 SetTextCursor((unsigned short)g_stSecondaryViewBufferBlock.left, 120);
864 DrawSelectedNavLegendEntry("MISSION FLIGHT PATH",
865 objective);
867 "HOME BASE",
868 (short)((short)g_cMissionObjectiveCount - 1));
869}
870
871/* Function start: 0x451756 */
872char *nav_note(short objective)
873{
874 if (IsObjectiveInDisplayedSystem(objective) == 0)
876 if (*g_aMissionObjectives[objective].name == '?')
877 return g_aMissionObjectives[objective].name + 1;
878 else if (*g_aMissionObjectives[objective].name == '.')
879 return strchr(g_aMissionObjectives[objective].name, 0);
880 else
881 return g_aMissionObjectives[objective].name;
882}
883
884/* Function start: 0x45180F */
885void DrawNavLocationReadout(const char *title, short showFlightData)
886{
887 char fileName[11] = "sector.000";
888 short file;
889 short length;
890
892 SetScreenClipRect(155, 2, 259, 155);
902 "\n");
904 "%s\n\n", title);
905 if (g_pNavLocationText == 0) {
906 fileName[9] =
907 (char)(g_nSelectedCampaignSlot + '0');
908 file = OpenDataFileOrDie(fileName);
909 length = (short)filelength(file);
911 AllocateTaggedMemory(length + 1, 0x40);
912 ReadDataFileAtOffset((unsigned short)file, 0, length,
914 g_pNavLocationText[length] = 0;
915 }
917 "Sector: %s\n",
918 (char *)g_pNavLocationText);
920 "System: %s\n\n",
923 "* %s *\n",
926 "* %s *\n",
930 .playerMissionShip].missionType]);
932 "\nNotes\n");
934 "%s\n",
936 if (showFlightData != 0)
938 BuildMap(showFlightData);
939 if (showFlightData != 0) {
940 SetScreenClipRect(0, 0, 259, 155);
943 "%X%Y Location: %d.%d.%d",
944 8, 142,
945 g_aShipPosition[0].x >> 8,
946 g_aShipPosition[0].y >> 8,
947 g_aShipPosition[0].z >> 8);
948 }
950}
951
952/* Function start: 0x451AD3 */
954{
955 short objective;
956
958 FetchDiskPacketRetrying("cockpit.vga", 2, 0);
959 SetScreenClipRect(0, 0, 259, 155);
961 ReportOutOfMemoryAndExit("VSCREEN");
962 for (objective = 0; objective < (short)g_cMissionObjectiveCount;
963 objective++)
964 LocateMobileObjective(objective);
965}
966
967/* Function start: 0x451B70 */
969{
970 short font;
971 Viewport savedViewport;
972
973 savedViewport = g_stSecondaryViewBufferBlock;
977 DrawNavLocationReadout("Briefing Nav Map", 0);
981 for (font = 0; font < 4; font++) {
982 if (g_36_apTextGlyphs[font] != 0) {
984 g_36_apTextGlyphs[font] = 0;
985 }
986 }
987 g_stSecondaryViewBufferBlock = savedViewport;
989}
990
991#pragma function(abs)
992/* Function start: 0x451C5C */
993short SelectNavObjectiveAtPoint(short mouseX, short mouseY)
994{
995 short mapX;
996 short mapY;
997 short objectiveFound;
998 short step;
999 short distance;
1000 short previousNav;
1001
1002 objectiveFound = 0;
1003 previousNav = (short)g_cCurrentNavPointIndex;
1004 mouseX = (short)(mouseX - 30);
1005 mouseY = (short)(mouseY - 22);
1006 step = 0;
1007 while (g_abFlightPath[step] != -1 && step < 8) {
1008 if (hidden_objective(g_abFlightPath[step]) == 0 &&
1010 g_abFlightPath[step]) != 0) {
1012 &mapX, &mapY,
1014 g_abFlightPath[step]].mapX,
1016 g_abFlightPath[step]].mapY);
1017 distance = (short)(abs((int)mouseY - mapY) +
1018 abs((int)mouseX - mapX));
1019 if (distance < 6 ||
1021 (short)g_awNavObjectiveLabelIndex[step],
1022 mouseX, mouseY) != 0) {
1023 objectiveFound = 1;
1024 set_new_objective(step);
1025 if (previousNav == step)
1026 return objectiveFound;
1027 }
1028 }
1029 step++;
1030 }
1031 return objectiveFound;
1032}
1033
1034/* Function start: 0x451DDB */
1036{
1037 short x;
1038 short y;
1039
1041 &x, &y,
1048 x = (short)(x + 30);
1049 y = (short)(y + 22);
1051}
1052
1053/* Function start: 0x451E57 */
1054void ShowConfedNavScan(short refresh)
1055{
1056 SetRectBounds(&g_101_stScrViewInfo, 30, 22, 289, 177);
1057 if (refresh != 0)
1059 DrawNavLocationReadout("ConFed Nav Scan", 1);
1060 if (refresh != 0)
1062 SetRectBounds(&g_101_stScrViewInfo, 0, 0, 319, 199);
1063}
1064
1065/* Function start: 0x451EC9 */
1066/* Follow the selected objective's system, unless the map is still showing a
1067 * different system from the one the player is in. */
1069{
1070 short navPoint;
1071
1074 return;
1075 }
1076 switch (g_aMissionObjectives[
1077 g_cCurrentObjective].type) {
1078 case 0:
1079 case 5:
1084 return;
1085 default:
1086 navPoint = find_ships_sphere(
1088 g_cCurrentObjective].index);
1091 return;
1092 }
1093}
1094
1095/* Function start: 0x451FAA */
1097{
1098 MouseCursorState savedCursor;
1099 Viewport navViewport;
1100 InputEventState inputEvent;
1101 unsigned char *cockpitShape;
1102 int frame;
1103 int markerColor;
1104 short done;
1105 short selectedNav;
1106 short objectivesVisible;
1107 short savedNav;
1108 short objective;
1109
1110 done = 0;
1111 selectedNav = (short)g_cCurrentNavPointIndex;
1112 objectivesVisible = 0;
1113 savedNav = (short)g_cCurrentNavPointIndex;
1116
1117 if (message_showing() != 0)
1118 EndCommMenu();
1123 cockpitShape = FetchDiskPacketRetrying("cockpit.vga", 1, 0);
1126 DrawSpriteDefault(&g_101_stScrViewInfo, 0, 0, cockpitShape, 0);
1127 ReleasePacketHandle(cockpitShape);
1132
1133 for (objective = 0;
1134 objective < (short)g_cMissionObjectiveCount;
1135 objective++) {
1136 if (hidden_objective(objective) == 0 &&
1137 IsObjectiveInDisplayedSystem(objective) != 0) {
1138 objectivesVisible = 1;
1139 }
1140 }
1141 MarkDibDirty();
1142 DIBslamReal();
1143
1144 if (objectivesVisible == 0) {
1149 } else {
1150 navViewport = g_101_stScrViewInfo;
1151 SetRectBounds(&navViewport, 0x20, 0x18, 0xb6, 0x9f);
1152 SetInputViewport(&navViewport);
1157
1158 do {
1159 if ((short)g_cCurrentNavPointIndex !=
1160 selectedNav) {
1161 selectedNav =
1163 PlaySfxWaveFileByNumber(0x19, -1, 0);
1165 }
1167 0x121, 0xb1);
1172 (unsigned char *)g_4_pElapsedCampaignDatePointer);
1173 frame = g_196_nInputTimerTicks / 15;
1176 if (frame % 2 != 0)
1177 markerColor = g_bPrimaryViewBufferColour;
1178 else
1179 markerColor = g_ucHomeCarrierScannerColour;
1180 DrawNavPlayerMarker((short)markerColor, 0);
1183 UpdateInflightNavText((short)((frame / 4) % 2));
1184 SetRectBounds(&g_101_stScrViewInfo, 0, 0, 0x13f, 0xc7);
1189 /* The original passes a second argument the callee ignores. */
1190 switch (PollInputEvent(&inputEvent, 0xf)) {
1191 case 4:
1192 case 6:
1193 if (inputEvent.status != 0x1c &&
1194 inputEvent.status != 0x39) {
1195 if (inputEvent.status == 0x31) {
1198 (short)g_cCurrentObjective) == 0)
1201 }
1202 break;
1203 }
1204 case 1:
1205 done = 1;
1206 break;
1207 }
1211 MarkDibDirty();
1212 DIBslamReal();
1213 } while (done == 0 && g_bSceneEscapeRequested == 0);
1214
1215 if (g_bSceneEscapeRequested != 0) {
1218 (signed char)savedNav;
1220 }
1223 }
1224
1227 PlaySfxWaveFileByNumber(0x19, -1, 0);
1231 force_view(0, 0);
1234}
1235
1236/* Linker commons defined here. LINK lays a unit's commons out by the
1237 * identifiers' hash keys, so these spellings follow the original addresses. */
1238short g_nCurStellarSystem; /* 0x005d169c */
1239short g_nNavPlotMaxX; /* 0x005d169e */
1240short g_nNavmapMapMinimumX; /* 0x005d16a0 */
1241unsigned short g_awNavObjectiveLabelIndex[8]; /* 0x005d16b0 */
1242short g_nNavmapMapMaximumY; /* 0x005d16c0 */
1243short g_13_nNavmapMapCentreX; /* 0x005d16c2 */
1244short g_2_nNavMapMinimumYValue; /* 0x005d16c4 */
1246short g_nNavMapCentreY; /* 0x005d16ec */
1249void *g_4_pDigiData; /* 0x005d1710 */
1250unsigned short g_wDigiLeft; /* 0x005d1714 */
void(__cdecl *g_pIxFree)(void *)
void DrawNavSquareOutline(Viewport *viewport, short x, short y, short size, signed char colour)
Definition nav.c:494
short find_ships_sphere(short missionShip)
Definition logic.c:816
void Build_objective_list(void)
Definition nav.c:193
int ConfigureInputPump(int slot, void(*pump)(void))
Definition eventmgr.c:2112
void SetInputViewport(Viewport *viewport)
Definition eventmgr.c:2093
void DrawViewportLine(Viewport *viewport, short x1, short y1, short x2, short y2, short colour)
Definition gr.c:1060
void DrawViewportEllipseShadow(Viewport *viewport, short x, short y, short verticalRadius, short horizontalRadius, short colour)
Definition gr.c:1415
void SetRectBounds(Viewport *viewport, unsigned short left, unsigned short top, unsigned short right, unsigned short bottom)
Definition cockpt.c:2044
void PollJoystickButtonEvents(void)
Definition input.c:74
short MaxShort(short a, short b)
Definition disk.c:36
void CheckPoint(short x, short y)
Definition nav.c:119
void SplitGameClockTicksForNav(unsigned char *parts)
Definition eventmgr.c:2383
void InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition disk.c:254
short LocateMobileObjective(short objective)
Definition cockpt.c:1345
short ObjectivesShareNavLabel(short objective, short other)
Definition nav.c:390
void DrawNavHazardMarker(FixedVector navPosition, FixedVector offset, short size, unsigned short markerColour, unsigned short textColour, const char *text)
Definition nav.c:614
short AllocateViewport(Viewport *viewport, short clearColour, short flags)
Definition vpalloc.c:32
short NavMapPointInsideReservedArea(short area, short x, short y)
Definition nav.c:266
void DrawNavTextLine(unsigned char alignment, unsigned short colour, const char *format,...)
Definition nav.c:69
short NavMapLabelPositionAvailable(short x, short y, short width, short height)
Definition nav.c:283
void ShowConfedNavScan(short refresh)
Definition nav.c:1054
void AddFixedVectors(const FixedVector *left, const FixedVector *right, FixedVector *sum)
Definition geom.c:211
void InitializeSpaceFlightInput(void)
Definition message.c:16
void free_viewport(Viewport *viewport)
Definition vpfree.c:10
void EndCommMenu(void)
Definition comm.c:441
void DrawViewportPixel(Viewport *viewport, short x, short y, short colour)
Definition gr.c:1038
void DrawNavMapLegend(void)
Definition nav.c:855
void SetTextContext(TextContext *context)
Definition eventmgr.c:179
short IsPointInNavMapLabel(short label, short x, short y)
Definition nav.c:442
void get_player_input(void)
Definition main.c:389
void SetNavMapCoordinateScaling(short enabled)
Definition nav.c:89
int ReadDataFileAtOffset(unsigned short fd, int offset, unsigned int length, void *data)
Definition datafile.c:60
void DrawNavTriangleOutline(Viewport *viewport, short x, short y, short size, signed char colour)
Definition nav.c:531
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition gr.c:682
int PollInputEvent(InputEventState *event, short)
Definition eventmgr.c:922
short MinShort(short a, short b)
Definition disk.c:27
void FollowSelectedObjectiveSystem(void)
Definition nav.c:1068
void DIBslamReal(void)
Definition dib.cpp:562
const char * objective_name(short objective)
Definition cockpt.c:1181
void ReserveNavMapArea(short x, short y, short width, short height)
Definition nav.c:317
void BuildMap(short showPlayer)
Definition nav.c:671
void DrawNavMapLabels(void)
Definition nav.c:458
void DrawNavTriangleMarker(short x, short y, short size, short shadow, unsigned short colour, short reserve)
Definition nav.c:543
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition memapi.c:92
void DrawTextString(const char *text)
Definition eventmgr.c:262
short NavMapLabelFits(short x, short y, short width, short height)
Definition nav.c:275
short visited(short objective)
Definition cockpt.c:1140
short achieved(short objective)
Definition cockpt.c:1146
void * FetchDiskPacketRetrying(char *fileName, short section, short flags)
Definition disk.c:187
void ResetNavMapReservedAreas(void)
Definition nav.c:311
void ResetNavMapLabels(void)
Definition nav.c:331
void ReleasePacketSlot(void **slot)
Definition iffload.c:23
void force_view(int view, short obj)
Definition spc.c:423
char * nav_note(short objective)
Definition nav.c:872
void BriefingMap_LoadShapes(void)
Definition nav.c:953
short SelectNavObjectiveAtPoint(short mouseX, short mouseY)
Definition nav.c:993
void FormatTextTokens(void(*writer)(int), const char *format, va_list arguments)
Definition textfmt.c:18
short TryPlaceNavMapLabel(short x, short y, short width, short force)
Definition nav.c:337
void InflightComputer(void)
Definition nav.c:1096
void CentreMouseOnCurrentNavObjective(void)
Definition nav.c:1035
void DrawNavLocationReadout(const char *title, short showFlightData)
Definition nav.c:885
void DisableMouseCursorDrawing(void)
Definition eventmgr.c:1327
void SetScreenClipRect(unsigned short a, unsigned short b, unsigned short c, unsigned short d)
Definition nav.c:607
short OpenDataFileOrDie(const char *path)
Definition datafile.c:13
void ReportOutOfMemoryAndExit(const char *resource)
Definition message.c:101
void PlaceNavMapLabel(short x, short y, unsigned short colour, const char *text)
Definition nav.c:353
void DrawNavCrossMarker(short x, short y, short size, short shadow, unsigned short colour, short reserve)
Definition nav.c:560
void DrawNavSquareMarker(short x, short y, short size, short shadow, short colour, short reserve)
Definition nav.c:503
void DrawViewportEllipse(Viewport *viewport, short x, short y, short verticalRadius, short horizontalRadius, short colour)
Definition gr.c:1385
void DrawViewportBorder(Viewport *viewport, short left, short top, short right, short bottom, short colour)
Definition gr.c:1360
void DrawSelectedNavLegendEntry(const char *text, short navPoint)
Definition nav.c:845
void ClearViewport(Viewport *viewport, short colour)
Definition gr.c:1027
void AddUniqueObjectiveNavLabel(short x, short y, unsigned short colour, const char *text, short objective, short missionShip)
Definition nav.c:419
void EnableMouseCursorDrawing(void)
Definition eventmgr.c:1254
void AppendTextCharacter(char character)
Definition eventmgr.c:375
void SetScale(void)
Definition nav.c:142
void SetPersonnelMousePosition(short x, short y)
Definition mousepos.c:9
void PlaySfxWaveFileByNumber(int soundNumber, int sourceObject, int looping)
Definition music.c:490
short hidden_objective(short objective)
Definition cockpt.c:1206
void nav_getxy(short *x, short *y, int worldX, int worldZ)
Definition nav.c:110
void FormatNavCoordinates(unsigned char *out)
Definition nav.c:833
void SetMenuInputPump(void)
Definition eventmgr.c:2106
short IsObjectiveInDisplayedSystem(short objective)
Definition nav.c:580
void ReleasePacketHandle(void *handle)
Definition memapi.c:108
void ScaleNavMapCoordinates(short *x, short *y, short mapX, short mapY)
Definition nav.c:101
void BriefingMap_DisplayMap(void)
Definition nav.c:968
short mobile_objective(short objective)
Definition cockpt.c:1558
void RefreshObjectiveShipNavPoints(void)
Definition mission.c:251
void SetTextCursor(unsigned short a, unsigned short b)
Definition eventmgr.c:172
unsigned short WaitForAnyInputPress(void)
Definition disk.c:347
short set_new_objective(short pathIndex)
Definition cockpt.c:1272
void free_view_buffer(void)
Definition main.c:208
void ScaleNavMapMarkerSize(short *size)
Definition nav.c:95
short find_ship_index(short missionShip)
Definition logic.c:251
void set_sphere_point(const MissionShipRecord *record, FixedVector *position)
Definition mission.c:52
void DrawNavMapBriefingBeacons(void)
Definition nav.c:646
void IncludeNavMapWorldPoint(int worldX, int worldZ)
Definition nav.c:132
void SetFrameTimerAndWait(short period)
Definition eventmgr.c:1411
void DrawFormattedText(const char *format,...)
Definition textfmt.c:103
void MarkDibDirty(void)
Definition dib.cpp:532
void DrawNavRectangleMarker(short x, short y, short size, short shadow, unsigned short colour, short reserve)
Definition nav.c:472
void CopyViewportContents(Viewport *source, Viewport *destination)
Definition gr.c:995
void UpdateInflightNavText(short showColon)
Definition nav.c:801
short cycle_next_objective(void)
Definition cockpt.c:1299
void SetMouseCursorShape(unsigned char *shape, short frame)
Definition eventmgr.c:1357
short message_showing(void)
Definition cockpt.c:726
void DrawNavPlayerMarker(short colour, short reserve)
Definition nav.c:629
Shared Win32 declarations, types and library interfaces.
HostMouseMessage g_6_stHostMouseTextBlock
Definition winmain.c:1384
unsigned char * g_pNavMapShape
Definition nav.c:40
short g_nCurStellarSystem
Definition nav.c:1238
unsigned char * g_pNavLocationText
Definition nav.c:43
short g_bBriefingMapActive
Definition nav.c:62
signed char g_bSceneEscapeRequested
Definition eventmgr.c:2420
signed char g_abFlightPath[MISSION_OBJECTIVE_COUNT]
Definition viewrect.c:68
short g_nNavMapReservedAreaCount
Definition nav.c:42
NAV_STATIC NavMapLabel g_1_aNavMapLabels[20]
Definition globals.h:1614
unsigned char g_abMissionBriefingData[0xde]
Definition hotspot.c:256
signed char g_cCurrentObjective
Definition viewrect.c:57
unsigned short g_awNavObjectiveLabelIndex[8]
Definition nav.c:1241
unsigned char g_cYellowColour
Definition startup.c:547
InputManagerState * g_18_pEventManager
Definition eventmgr.c:2543
MissionNavPoint g_aMissionNavPoints[MISSION_NAV_POINT_COUNT]
Definition hotspot.c:237
char * g_apszShipMissionTypeNames[14]
Definition nav.c:44
short g_nNavMapScale
Definition nav.c:11
signed char g_cMissionObjectiveCount
Definition viewrect.c:66
MouseCursorState g_37_stPersonnelMousePointerState
Definition eventmgr.c:2544
TextContext * g_29_pCurrentTextContext
Definition eventmgr.c:2563
short g_nSelectedCampaignSlot
Definition campaign.c:354
char g_6_szDefaultTextBufferText[0xc8]
Definition message.c:228
TextContext g_stNavMapTextCtx
Definition nav.c:1245
unsigned char g_26_bMouseCursorEnabled
Definition eventmgr.c:2506
MissionObjectiveSource g_69_aMissionObjectiveSources[8]
Definition hotspot.c:252
unsigned char g_cSecondaryViewBufferColour
Definition startup.c:544
short g_2_nNavMapMinimumYValue
Definition nav.c:1244
short g_nNavMapCentreY
Definition nav.c:1246
unsigned char g_ucHomeCarrierScannerColour
Definition startup.c:553
short g_nNavmapMapMinimumX
Definition nav.c:1240
unsigned char g_88_nEventRepeatDelayState
Definition eventmgr.c:2500
short g_nNavMapCoordinateScaling
Definition nav.c:10
unsigned char g_cRedColour
Definition startup.c:548
unsigned char g_ucAsteroidNavMarkerColour
Definition startup.c:558
unsigned char g_ucPrimaryTextColour
Definition startup.c:550
CampaignDate * g_4_pElapsedCampaignDatePointer
Definition hotspot.c:255
unsigned char g_bPrimaryViewBufferColour
Definition startup.c:545
signed char g_cCurrentNavPointIndex
Definition viewrect.c:67
volatile int g_196_nInputTimerTicks
Definition eventmgr.c:2550
FixedVector g_aShipPosition[SPACE_OBJECT_COUNT]
Definition viewrect.c:108
unsigned char g_ucDefaultTextColour
Definition startup.c:556
NAV_STATIC ShortRect g_aNavMapExclusionRects[20]
Definition globals.h:1615
unsigned char g_ucNavObjectiveMarkerColour
Definition startup.c:555
Viewport g_101_stScrViewInfo
Definition cockpt.c:3831
void * g_4_pDigiData
Definition nav.c:1249
signed char g_1_cStoredViewDisplayModeValue
Definition eventmgr.c:2515
short g_nNavmapMapMaximumY
Definition nav.c:1242
short g_nNavPlotMaxX
Definition nav.c:1239
int g_bInflightComputerActive
Definition nav.c:63
MissionObjective g_aMissionObjectives[MISSION_OBJECTIVE_COUNT]
Definition viewrect.c:69
Viewport g_stSecondaryViewBufferBlock
Definition message.c:234
CampaignDate g_1_stElapsedCampaignDate
Definition nav.c:1248
MissionShipRecord g_aMissionShips[MISSION_SHIP_COUNT]
Definition hotspot.c:240
short g_nNavMapLabelCount
Definition nav.c:41
PilotProfile g_stCurrentPilotProfile
Definition viewrect.c:73
short g_18_nInterfaceEventMode
Definition eventmgr.c:2570
unsigned short g_wDigiLeft
Definition nav.c:1250
unsigned char g_abSeriesAuxData[0x28]
Definition hotspot.c:251
TextContext g_3_stDefaultStringContext
Definition message.c:239
unsigned char * g_36_apTextGlyphs[4]
Definition cockpt.c:3835
unsigned char g_5_abMissionAuxBlockBytes[0x28]
Definition hotspot.c:250
TextContext g_5_stNavLabelTextContextInfo
Definition nav.c:1247
short g_13_nNavmapMapCentreX
Definition nav.c:1243
MissionHeader g_13_stMissionHeaderBlock
Definition hotspot.c:253
NavMapObjectiveStyle g_aNavMapObjectiveStyles[12]
Definition nav.c:12
unsigned char g_ucPlayerNavLabelColour
Definition startup.c:554
char g_szNoFurtherObjectives[32]
Definition nav.c:60
short status
Definition game.h:213
signed char systemIndex
Definition game_data.h:1329
FixedVector position
Definition game_data.h:1327
short missionShips[10]
Definition game_data.h:1336
const char * displayName
Definition game_data.h:1420
unsigned char field_8
Definition game_data.h:1418
signed char flags
Definition game_data.h:1419
signed char index
Definition game_data.h:1417
FixedVector position
Definition game_data.h:1422
FixedVector position
Definition game_data.h:1372
volatile short y
Definition game.h:166
volatile short x
Definition game.h:165
FixedVector position
Definition game_data.h:1314
char name[20]
Definition game_data.h:1316
signed char active
Definition game_data.h:1317
short colour
Definition game_data.h:716
const char * text
Definition game_data.h:717
unsigned char * labelColour
Definition game_data.h:730
unsigned char * unvisitedColour
Definition game_data.h:728
unsigned char * markerColour
Definition game_data.h:729
char callsign[13]
Definition game_data.h:1115
short top
Definition game_data.h:480
short left
Definition game_data.h:479
short right
Definition game_data.h:481
short bottom
Definition game_data.h:482
unsigned char colour
Definition game.h:288
short cursorY
Definition game.h:286
char * text
Definition game.h:290
signed char alignment
Definition game.h:292
char * textCursor
Definition game.h:291
short cursorX
Definition game.h:285
Viewport * viewport
Definition game.h:284
short left
Definition game.h:152
short top
Definition game.h:153