Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
comm.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup cockpit
4 * @brief Communication menus and video transmissions.
5 *
6 * Address range 430bc0-4318ef.
7 */
8#include "wc1.h"
9
10short nCommMenuChoiceCount = -1; /* 0x0046af60 */
11short nCommMenuReuseMode = 0; /* 0x0046af64 */
12unsigned char bMessageSpeed = 2; /* 0x0046af68 */
13static signed char cPendingCommMenuAction = 1; /* 0x0046af6c */
14unsigned char bRadioSilence = 0; /* 0x0046af70 */
15unsigned char bVideoImagesSuppressed = 0; /* 0x0046af74 */
16unsigned char bCommVideoEnabled = 1; /* 0x0046af78 */
17
18/* 0x0046af80 */
19const char *apszKilrathiAceNames[4] = {
20 "Bhurak",
21 "Dakhath",
22 "Khajja",
23 "Bakhtosh"
24};
25/* 0x0046af90 */
26static const char *apszCommMenuText[13] = {
27 "Never mind...",
28 "Attack my target!",
29 "Help me out here",
30 "Return to base.",
31 "Die furball!",
32 "Slag off!",
33 "Bite it cat face.",
34 "Break and attack.",
35 "Keep formation!",
36 "Form on my wing.",
37 "Keep radio silence",
38 "Broadcast freely",
39 "Request Landing"
40};
41signed char cCommMenuRecipient = -1; /* 0x0046afc4 */
42short nCommSpeakerObject = 0; /* 0x0046afc8 */
43short nCommSpeakerRating = 0; /* 0x0046afcc */
44short nCommPortraitIndex = -1; /* 0x0046afd0 */
45
46
47/* Linker commons defined here; LINK orders them by identifier hash. */
48struct Shape *apObjShapeArray[SPACE_OBJECT_COUNT]; /* 0x0059d2f0 */
49/* The pitch, yaw and roll control inputs (DOS g_inputPitch/Yaw/Roll). */
51short asShipWingLeaderArray[16]; /* 0x0059d400 */
52/* The Win32 object allocator reserves slots 0 through 9 for live ships. */
53short aasShipArmor[10][4]; /* 0x0059d420 */
54short asShipWpnEnergyList[10]; /* 0x0059d470 */
55signed char acFormationMemberLists[16]; /* 0x0059d490 */
56signed char acShipIonDriveDmg[16]; /* 0x0059d4a0 */
57short anShipMissionShips[16]; /* 0x0059d4b0 */
58FixedVector vToTgt; /* 0x0059d4d0 */
59short asCannedCommands[16]; /* 0x0059d4e0 */
60
61/* Function start: 0x430BC0 */
62short get_face(short rating, unsigned int side)
63{
64 if (rating == -1)
65 return 13 + (side < SIDE_KILRATHI ? -1 : 0);
66 if (side == SIDE_KILRATHI)
67 rating--;
68 return rating;
69}
70
71/* Function start: 0x430BF0 */
72void LoadCommPortraitShape(short face, signed char alternate)
73{
74 short section;
75
76 if (face >= 0 && face <= 7)
77 section = face + 1;
78 else if ((face > 7 && face < 12) || face == 13)
79 section = 10;
80 else
81 section = -1;
82 if (section != -1)
84 FetchDiskPacketRetrying(11, section,
85 (short)alternate);
86}
87
88/* Function start: 0x430C50 */
89void ResetCommMenuChoices(short reuse)
90{
91 short choice;
92
93 if (reuse == 0) {
94 memset(abCommMenuChoiceCommands, -1,
96 for (choice = 0; choice < 7; choice++) {
98 }
99 }
101 nCommMenuReuseMode = reuse;
102}
103
104/* Function start: 0x430CA0 */
105short IsCommMenuIdle(void)
106{
107 return nCommMenuChoiceCount == 0;
108}
109
110/* Function start: 0x430CB0 */
111void AppendCommMenuChoice(const char *text, short command)
112{
113 int index;
114
115 if (nCommMenuReuseMode == 1) {
119 }
120 index = nCommMenuChoiceCount++;
121 apszCommMenuChoiceTextTable[index] = text;
122 abCommMenuChoiceCommands[index] = (signed char)command;
123}
124
125/* Function start: 0x430D30 */
127{
129}
130
131/* Function start: 0x430D50 */
132void OpenCommMenuForTarget(const char *heading, const char *message)
133{
134 CockpitMessage(message, cYellowColour, -1);
135 pszCommMenuHeading = heading;
136}
137
138/* Function start: 0x430D80 */
140{
141 return get_mode(1) == 4;
142}
143
144/* Function start: 0x430DA0 */
146{
147 return (short)cPendingCommMenuAction;
148}
149
150/* Function start: 0x430DB0 */
151void SetPendingMenuAction(unsigned char v)
152{
153 cPendingCommMenuAction = (signed char)v;
154}
155
156/* Function start: 0x430DC0 */
158{
159 push_mode(1, 4);
161}
162
163/* Function start: 0x430DE0 */
165{
166 if (get_mode(1) == 4) {
167 pop_mode(1);
168 return;
169 }
171 exit_squadron("!stop");
172}
173
174/* Function start: 0x430E10 */
175short wingman_dead(void)
176{
177 return nYourWingman == -1;
178}
179
180/* Function start: 0x430E30 */
181short have_target(void)
182{
183 return unactive(acShipTargetTable[0]) == 0;
184}
185
186/* Function start: 0x430E50 */
187unsigned short CanOpenCommMenu(void)
188{
189 if (have_target() == 0) {
190 if (wingman_dead())
191 return 0;
192 }
193 return 1;
194}
195
196/* Function start: 0x430E70 */
197void SelectCommRecipient(short recipient)
198{
199 cCommMenuRecipient = recipient;
201}
202
203/* Function start: 0x430E90 */
205{
206 short target;
207
209 OpenCommMenuForTarget("VID-COM SYSTEM\n\nSend message to?\n\n",
210 "SELECT");
211 if (wingman_dead() != 0) {
213 return;
214 }
215 if (have_target() == 0 ||
218 return;
219 }
222 (signed char)acShipRating[
223 nYourWingman]]->callsign,
224 1);
225 target = acShipTargetTable[0];
226 if (target != -1) {
227 if (aeShipSide[target] == SIDE_KILRATHI &&
229 AppendCommMenuChoice("ENEMY TARGET", 2);
230 else if (aeShipSide[target] == SIDE_IMPERIAL &&
231 ((aeObjectClass[target] == OBJECT_CLASS_SHIP &&
232 any_enemy(0, 14000) != 0) ||
233 aeObjectTypeList[target] ==
237 aeObjectTypeList[acShipTargetTable[0]]].displayName,
238 3);
239 }
241}
242
243/* Function start: 0x430FC0 */
245{
246 signed char rating;
247 const char *name;
248
253 any_enemy(0, 14000) != 0) {
255 }
256 if (nAutoEngageTimer != -1)
261 if (bRadioSilence != 0)
263 else
265 }
267 aeShipSide[0]) {
270 bLandingAuthorized == 0) {
272 }
273 if (have_target() != 0 &&
277 }
278 if (evaluate_damage(0) < 50 && any_enemy(0, 14000) != 0)
280 }
288 }
289 if (IsCommMenuIdle() != 0)
291 else
293
294 if (IsCommChoiceMenuOpen() != 0) {
296 "VID-COM SYSTEM\n\nTo: ");
298 if (rating == -1) {
299 name = aObjectTypeData[
302 } else if (rating < 8) {
303 name = apWingmanPilotsList[rating]->callsign;
304 } else {
305 name = apszKilrathiAceNames[rating - 9];
306 }
307 strcat(szCommMenuHeadingBuf, name);
308 strcat(szCommMenuHeadingBuf, "\n");
310 "CHOOSE");
311 }
312}
313
314/* Function start: 0x431200 */
326
327/* Function start: 0x431240 */
339
340/* Function start: 0x431290 */
342{
343 signed char choice;
344
345 if (IsCommChoiceMenuOpen() == 0)
347 if (IsCommChoiceMenuOpen() != 0) {
348 set_new_vdu(1);
351 for (choice = 0; choice < nCommMenuChoiceCount; choice++) {
352 DrawFormattedText("\n%d %s", choice + 1,
354 }
356 (short)(stRightVduViewport.left + 36),
357 (short)(stRightVduViewport.top + 10),
360 }
361}
362
363/* Function start: 0x431350 */
364unsigned int Chosen_communicate_option(short choice)
365{
366 int action;
367
368 PlaySfxWaveFileByNumber(0x19, -1, 0);
369 action = GetPendingMenuAction();
370 switch (action) {
371 case 0:
373 return 0;
374 case 1:
375 if (abCommMenuChoiceCommands[choice] == 0) {
377 return 0;
378 }
379 if (abCommMenuChoiceCommands[choice] == 1) {
382 return 0;
383 }
386 return 0;
387 case 2:
389 request(0, (short)cCommMenuRecipient,
390 (short)abCommMenuChoiceCommands[choice]);
391 return 0;
392 }
393 return 0;
394}
395
396/* Function start: 0x431400 */
397void talk_equiv(void)
398{
400}
401
402/* Function start: 0x431410 */
414
415/* Function start: 0x431470 */
417{
418 if (
420 malf_noise(1, 1, 12, 23, 1);
422 if (get_mode(1) == 6)
423 pop_mode(1);
424}
425
426/* Function start: 0x4314C0 */
427void EndCommMenu(void)
428{
430 if (get_mode(1) == 6)
433}
434
435/* Function start: 0x4314F0 */
436void ShowCentredPrompt(char *text, unsigned short arg)
437{
440 cYellowColour, arg);
441}
442
443/* Function start: 0x431520 */
444short LoadCommDisplayResources(short rating, enum Side side)
445{
446 short loaded;
447
448 loaded = 1;
449 switch (side) {
450 case SIDE_IMPERIAL:
451 if (pConfedCommBackground == 0)
453 FetchDiskPacketRetrying(11, 0, 0);
454 loaded = pConfedCommBackground != 0;
455 break;
456 case SIDE_KILRATHI:
459 FetchDiskPacketRetrying(11, 9, 0);
460 loaded = pKilrathiCommBackground != 0;
461 break;
462 }
463 if (pCommStaticShape == 0)
465 FetchDiskPacketRetrying(11, 11, 0);
466 if (loaded != 0 && pCommStaticShape != 0)
467 return 1;
468 return 0;
469}
470
471/* Function start: 0x4315C0 */
472char *ExpandCommMessageTokens(const char *text)
473{
474 char *destination;
475 const char *marker;
476 short length;
477
478 szTxtWorkspaceBuffer[0] = '\0';
479 while ((marker = DosStrchr(text, '$')) != 0) {
480 destination = DosStrchr(szTxtWorkspaceBuffer, '\0');
481 while (marker != text)
482 *destination++ = *text++;
483 *destination = '\0';
484 marker++;
485 switch (*marker++) {
486 case 'C':
487 DosStrcat(
490 break;
491 case 'N':
492 case 'P':
495 break;
496 case 'R':
501 if (szTxtWorkspaceBuffer[length - 1] == '.' &&
502 *marker == '.') {
504 szTxtWorkspaceBuffer[length - 1] = '\0';
505 }
506 break;
507 }
508 text = marker;
509 }
512}
513
514/* Function start: 0x4316E0 */
515void real_vid_transmit(short obj, short message)
516{
517 char text[84];
518 char *expandedText;
519 char *speech;
520
521 nCommSpeakerObject = obj;
523 (short)acShipRating[obj];
526 aeShipSide[obj]);
527 if (nCommPortraitIndex == -1)
528 return;
529 if (bCommVideoEnabled != 0 && bVideoImagesSuppressed == 0) {
531 nCommPortraitIndex] == 0)
534 nCommPortraitIndex] != 0 &&
537 nCommSpeakerObject]) != 0) {
538 push_mode(1, 6);
539 malf_noise(1, 3, 12, 23, 1);
544 else
553 0);
554 }
555 }
556 speech = aapszPilotSpeeches[
557 nCommPortraitIndex][message];
558 if (nCommSpeakerRating >= 0 &&
559 nCommSpeakerRating <= 7) {
560 sprintf(text, "%s: %Fs",
562 nCommSpeakerRating]->callsign,
563 speech);
564 } else if (nCommSpeakerRating >= 9 &&
565 nCommSpeakerRating <= 12) {
566 sprintf(text, "%s: %Fs",
569 speech);
570 } else {
571 sprintf(text, "%s: %Fs",
572 aObjectTypeData[aeObjectTypeList[obj]].displayName,
573 speech);
574 }
575 expandedText = ExpandCommMessageTokens(text);
576 ShowCentredPrompt(expandedText, (unsigned short)MeasureMessageWidth(text));
577}
static const char * apszCommMenuText[13]
Definition comm.c:26
static signed char cPendingCommMenuAction
Definition comm.c:13
unsigned char cYellowColour
Definition init.c:15
signed char acShipRating[16]
Definition joycal.c:25
short anShipMissionShips[16]
Definition comm.c:57
TextContext stRightVduTxtContext
Definition targ.c:12
unsigned char bCommVideoEnabled
Definition comm.c:16
enum Side aeShipSide[12]
Definition ending.c:22
struct Shape * pConfedCommBackground
Definition cockpt.c:81
Viewport stRightVduViewport
Definition timer.c:14
short nCommSpeakerObject
Definition comm.c:42
short nCommPortraitIndex
Definition comm.c:44
struct Shape * pCommMenuPointerShape
Definition select.c:13
ObjectTypeData aObjectTypeData[OBJECT_TYPE_COUNT]
Definition objdata.c:86
char szHudMessageBuf[0x60]
Definition music.c:97
ShortVector stRotationInput
Definition comm.c:50
char szTxtWorkspaceBuffer[256]
Definition screens.c:164
signed char acShipIonDriveDmg[16]
Definition comm.c:56
short asShipWpnEnergyList[10]
Definition comm.c:54
FixedVector vToTgt
Definition comm.c:58
char * pszPendingHudMessage
Definition cockpt.c:14
unsigned char bVideoImagesSuppressed
Definition comm.c:15
short nCommSpeakerRating
Definition comm.c:43
enum ShipObjective aeShipObjectiveList[12]
Definition video.c:22
enum ObjectClass aeObjectClass[SPACE_OBJECT_COUNT]
Definition video.c:21
short nYourWingman
Definition game.c:61
short aasShipArmor[10][4]
Definition comm.c:53
signed char acFormationMemberLists[16]
Definition comm.c:55
signed char abCommMenuChoiceCommands[7]
Definition music.c:99
short asCannedCommands[16]
Definition comm.c:59
short nCommMenuReuseMode
Definition comm.c:11
char szCommMenuHeadingBuf[0x40]
Definition view.c:26
const char * apszKilrathiAceNames[4]
Definition comm.c:19
struct Shape * pCommStaticShape
Definition cockpt.c:82
PilotRecord * apWingmanPilotsList[8]
Definition gr.c:1533
short asShipWingLeaderArray[16]
Definition comm.c:51
CampaignState stCampaignState
Definition dib.c:107
unsigned char bLandingAuthorized
Definition spc.c:14
short nCommMenuChoiceCount
Definition comm.c:10
struct Shape * apObjShapeArray[SPACE_OBJECT_COUNT]
Definition comm.c:48
struct Shape * pKilrathiCommBackground
Definition cockpt.c:83
const char * pszCommMenuHeading
Definition view.c:25
enum ObjectType aeObjectTypeList[SPACE_OBJECT_COUNT]
Definition data.c:255
unsigned char bMessageSpeed
Definition comm.c:12
signed char cCommMenuRecipient
Definition comm.c:41
unsigned char bRadioSilence
Definition comm.c:14
const char * apszCommMenuChoiceTextTable[7]
Definition view.c:27
signed char acShipTargetTable[16]
Definition joycal.c:30
struct Shape * apCommunicationPortraitShapesTable[16]
Definition music.c:96
const char * apszPilotRankNames[5]
Definition killbrd.c:16
short nAutoEngageTimer
Definition game.c:104
char * aapszPilotSpeeches[14][11]
Definition music.c:98
PilotRecord * currentPilot
Definition wcdata.h:710
const char * displayName
Definition wcdata.h:369
char callsign[14]
Definition wcdata.h:598
char name[14]
Definition wcdata.h:597
short rank
Definition wcdata.h:600
short left
Definition wc1base.h:76
short top
Definition wc1base.h:77
Umbrella header for the game core.
void show_communications_disp(void)
Definition comm.c:341
short get_mode(short i)
Definition cockpt.c:690
char *__stdcall DosStrchr(const char *s, short c)
Definition strdos.c:43
short GetPendingMenuAction(void)
Definition comm.c:145
short have_target(void)
Definition comm.c:181
void SendCommMenuChoice(short i)
Definition comm.c:126
void malf_noise(short vdu, int effect, unsigned short colour, short sound, short refresh)
Definition cockpt.c:2231
void ResetCommMenuChoices(short reuse)
Definition comm.c:89
void * FetchDiskPacketRetrying(short logicalFile, short section, short flags)
Definition disk.c:126
void BuildCommunicationCommandMenu(void)
Definition comm.c:244
short evaluate_damage(short obj)
Definition logic.c:1366
short IsCommMenuIdle(void)
Definition comm.c:105
void EndCommMenu(void)
Definition comm.c:427
void DrawSpriteDefault(Viewport *viewport, short x, short y, struct Shape *shape, short frame)
Definition gr.c:660
short IsCommChoiceMenuOpen(void)
Definition comm.c:139
void InvalidateVduMode(short i)
Definition cockpt.c:764
void RefreshCommunicationMenu(void)
Definition comm.c:315
char *__stdcall DosStrcat(char *destination, const char *source)
Definition fade.c:92
void CockpitMessage(const char *text, unsigned short colour, int flashCount)
Definition cockpt.c:480
void real_vid_transmit(short obj, short message)
Definition comm.c:515
void OpenCommRecipientMenu(void)
Definition comm.c:157
void CloseCommChoiceMenu(void)
Definition comm.c:164
void EndCommSessionWithWingman(void)
Definition comm.c:416
void ShowCentredPrompt(char *text, unsigned short arg)
Definition comm.c:436
char * ExpandCommMessageTokens(const char *text)
Definition comm.c:472
void clear_message_time(void)
Definition cockpt.c:770
char *__stdcall DosStrcpy(char *dst, const char *src)
Definition strdos.c:49
void AppendCommMenuChoice(const char *text, short command)
Definition comm.c:111
void HandleCommunicationMenuRequest(void)
Definition comm.c:328
void LoadCommPortraitShape(short face, signed char alternate)
Definition comm.c:72
unsigned int Chosen_communicate_option(short choice)
Definition comm.c:364
void pop_mode(short i)
Definition cockpt.c:732
void OpenCommMenuForTarget(const char *heading, const char *message)
Definition comm.c:132
void SetPendingMenuAction(unsigned char v)
Definition comm.c:151
int any_enemy(short obj, short range)
Definition logic.c:887
short MeasureMessageWidth(const char *text)
Definition main.c:1218
void SelectCommRecipient(short recipient)
Definition comm.c:197
void exit_squadron(const char *msg)
Definition main.c:122
unsigned short CanOpenCommMenu(void)
Definition comm.c:187
short wingman_dead(void)
Definition comm.c:175
void SetHudMessageText(char *text, unsigned short colour, unsigned short duration)
Definition cockpt.c:2218
void push_mode(short i, int state)
Definition cockpt.c:723
void set_new_vdu(short vdu)
Definition cockpt.c:739
void PlaySfxWaveFileByNumber()
short get_face(short rating, unsigned int side)
Definition comm.c:62
unsigned int DrawTextAt(TextContext *context, short x, short y, const char *text, unsigned char alignment)
Definition disk.c:239
void request(short requester, short ship, short command)
Definition screen.c:204
void FreePacketAndClear(void *slot, unsigned short releaseFlags)
Definition mathutil.c:37
short __stdcall DosStrlen(const char *s)
Definition strdos.c:61
void FreeCommDisplayResources(void)
Definition comm.c:403
void DrawFormattedText(const char *format,...)
Definition cockpt.c:197
unsigned int unactive(short ship)
Definition logic.c:353
void BuildCommunicationRecipientMenu(void)
Definition comm.c:204
void ShutdownEventManager(void)
Definition strdos.c:101
short LoadCommDisplayResources(short rating, enum Side side)
Definition comm.c:444
void talk_equiv(void)
Definition comm.c:397
short message_showing(void)
Definition cockpt.c:776
@ OBJECT_TYPE_TIGERS_CLAW
Definition wcdata.h:63
Side
Definition wcdata.h:173
@ SIDE_IMPERIAL
Definition wcdata.h:174
@ SIDE_KILRATHI
Definition wcdata.h:175
@ OBJECTIVE_HOLD_FORMATION
Definition wcdata.h:146
#define SPACE_OBJECT_COUNT
Definition wcdata.h:1004
@ OBJECT_CLASS_SHIP
Definition wcdata.h:50