Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
hotspot.c
Go to the documentation of this file.
1/*
2 * Scene hotspot selection.
3 *
4 * Retail object 0x409120-0x40984F (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8/* Function start: 0x409120 */
9short WaitForSceneAdvance(void *scenePacket)
10{
11 unsigned char *cursor;
12 unsigned char *nextChunk;
13 short hotspotCount;
14 unsigned int formId;
15
16 if (g_pActiveScenePacket != scenePacket) {
18 nextChunk = (unsigned char *)scenePacket +
19 ((ScenePacketHeader *)scenePacket)->formOffset;
20 for (;;) {
21 cursor = nextChunk;
22 formId = ReadNextSceneForm(&cursor, &nextChunk);
23 if (formId == 0x52544f48) {
25 &cursor, &g_stSceneZoneTable);
26 if (g_stSceneZoneTable.type != 0)
29 } else if (formId == 0x54585448) {
31 &cursor, &g_stSceneTextList);
32 if (g_stSceneTextList.type == 2)
33 break;
35 } else if (formId == 0)
36 break;
37 }
38 g_pActiveScenePacket = scenePacket;
39 }
40 hotspotCount = g_stSceneZoneTable.count;
44 if (hotspotCount <= 2)
45 return 0;
46 return 1;
47}
48
49/* Hit-test callee from the event manager. */
50short IsPointInRect(short x, short y, const short *rect);
51
52/* Function start: 0x40926E */
54 short selection)
55{
56 unsigned char *cursor;
57 unsigned char *nextForm;
58 SceneHotspot *hotspot;
59 short index;
60 unsigned int magic;
61
62 if (g_pActiveScenePacket != scenePacket) {
64 nextForm = (unsigned char *)scenePacket +
65 ((ScenePacketHeader *)scenePacket)->formOffset;
66 for (;;) {
67 cursor = nextForm;
68 magic = ReadNextSceneForm(&cursor, &nextForm);
69 if (magic == 0x52544f48) {
71 &cursor, &g_stSceneZoneTable);
72 if (g_stSceneZoneTable.type != 0)
75 } else if (magic == 0x54585448) {
77 &cursor, &g_stSceneTextList);
78 if (g_stSceneTextList.type == 2)
79 break;
81 } else if (magic == 0)
82 break;
83 }
84 g_pActiveScenePacket = scenePacket;
85 }
86
87 for (index = 0; index < g_stSceneZoneTable.count;
88 index++) {
89 hotspot = ((SceneHotspot **)
91 if (hotspot->selection == selection) {
96 break;
97 }
98 }
102}
103
104/* Function start: 0x409417 */
105short FindSceneHotspotAtPosition(void *scenePacket, short offsetX,
106 short offsetY, short x, short y)
107{
108 ShortRect hitRect;
109 short selection;
110 unsigned char *cursor;
111 SceneHotspot *hotspot;
112 short index;
113 unsigned char *nextForm;
114 unsigned int magic;
115
116 selection = 0;
118 if (g_pActiveScenePacket != scenePacket) {
120 nextForm = (unsigned char *)scenePacket +
121 ((ScenePacketHeader *)scenePacket)->formOffset;
122 for (;;) {
123 cursor = nextForm;
124 magic = ReadNextSceneForm(&cursor, &nextForm);
125 if (magic == 0x52544f48) {
127 &cursor, &g_stSceneZoneTable);
128 if (g_stSceneZoneTable.type != 0)
131 } else if (magic == 0x54585448) {
133 &cursor, &g_stSceneTextList);
134 if (g_stSceneTextList.type == 2)
135 break;
137 } else if (magic == 0)
138 break;
139 }
140 g_pActiveScenePacket = scenePacket;
141 }
142
143 for (index = 0; index < g_stSceneZoneTable.count; index++) {
144 hotspot =
146 OffsetSceneHotspotBounds(&hitRect, hotspot, offsetX, offsetY);
147 if (IsPointInRect(x, y, &hitRect.left) != 0) {
148 selection = hotspot->selection;
149 if (g_stSceneTextList.data != 0) {
151 ((char **)g_stSceneTextList.data)[0];
152 if (index != g_stSceneZoneTable.count - 1) {
153 index = (short)(selection - 1);
154 while (index-- != 0) {
157 }
158 if (*g_pszPersonnelFooter == 0)
160 } else
162 }
163 break;
164 }
165 }
166 return selection;
167}
168
169/* Function start: 0x40963B */
170short PollSceneHotspotInput(void *scenePacket, short offsetX,
171 short offsetY, short dismissOnBackground,
172 short maximumSelection)
173{
174 InputEventState polled;
175 short selection;
176 InputEventState *inputEvent;
177 short controlPressed;
178 short jPressed;
179
180 selection = 0;
182 inputEvent = FindQueuedInputEvent(4);
183 /* The original test ends in a stray semicolon, so the block below runs
184 * whether or not a key event is queued. */
185 if (inputEvent != 0)
186 ;
187 {
188 controlPressed = (short)GetControlKeyState();
189 jPressed = (short)GetJKeyState();
190 if ((controlPressed != 0 && jPressed != 0) ||
192 controlPressed = 0;
193 jPressed = 0;
197 }
198 }
199 inputEvent = FindQueuedInputEvent(1);
200 if (inputEvent == 0)
201 inputEvent = &polled;
202 GetNextInputEvent(&polled);
203 selection = FindSceneHotspotAtPosition(
204 scenePacket, offsetX, offsetY, inputEvent->x, inputEvent->y);
205 if (maximumSelection != 0 && selection > maximumSelection)
206 selection = 0;
207 if (g_bDisableChalkboardReplay != 0 && selection == 2) {
208 selection = 0;
210 }
211 if (selection != 0) {
213 } else if (g_bPersonnelMenuDrawing != 0) {
215 }
217 if (inputEvent->type != 1) {
218 selection = 0;
219 } else if (selection == 0 && dismissOnBackground != 0) {
221 }
222 if (selection != 0 ||
223 (dismissOnBackground != 0 &&
228 }
229 return selection;
230}
231
232/* This unit's initialized data, after its functions so that the two unused
233 * words do not move the functions' symbol keys. Nothing between intro.c's
234 * literals and campaign.c's data marks the boundary between the two units,
235 * so placing the mission arrays here is evidence of position, not of
236 * ownership. Nothing in the original references the two unused words. */
238 { 0 }
239}; /* 0x00491e98 */
241int g_nUnusedSceneWord = 0; /* 0x00492650 */
242void *g_pActiveScenePacket = 0; /* 0x00492654 */
243char *g_pszPersonnelFooter = 0; /* 0x00492658 */
244int g_nUnusedSceneFlag = 1; /* 0x0049265c */
245
246/* Linker commons defined here. LINK lays a unit's commons out by the
247 * identifiers' hash keys, so these spellings follow the original addresses. */
250unsigned char g_5_abMissionAuxBlockBytes[0x28]; /* 0x005d3c10 */
251unsigned char g_abSeriesAuxData[0x28]; /* 0x005d3c40 */
254char g_10_nUnusedHotspotWord; /* 0x005d3e88 */ /* never referenced */
256unsigned char g_abMissionBriefingData[0xde]; /* 0x005d3e90 */
short WaitForSceneAdvance(void *scenePacket)
Definition hotspot.c:9
int GetJKeyState(void)
Definition winmain.c:1142
short ServiceInputDevices(short deviceMask)
Definition eventmgr.c:2071
void CalibrateJoystickInteractive()
Definition titlemnu.c:10
InputEventState * FindQueuedInputEvent(int type)
Definition eventmgr.c:969
void ReleasePacketSlot(void **slot)
Definition iffload.c:23
short PollSceneHotspotInput(void *scenePacket, short offsetX, short offsetY, short dismissOnBackground, short maximumSelection)
Definition hotspot.c:170
unsigned int ReadNextSceneForm(unsigned char **cursor, unsigned char **nextForm)
Definition iffload.c:66
int GetControlKeyState(void)
Definition winmain.c:1136
short OffsetSceneHotspotBounds(ShortRect *bounds, const SceneHotspot *hotspot, short offsetX, short offsetY)
Definition eventmgr.c:2180
char * DosStrchr(const char *s, short c)
Definition eventmgr.c:459
int GetNextInputEvent(InputEventState *event)
Definition eventmgr.c:800
signed char DecodeSceneResourceChunk(unsigned char **cursor, SceneResourceTable *resource)
Definition iffload.c:335
short FindSceneHotspotAtPosition(void *scenePacket, short offsetX, short offsetY, short x, short y)
Definition hotspot.c:105
void LoadSceneHotspotBoundsForSelection(void *scenePacket, short selection)
Definition hotspot.c:53
short IsPointInRect(short x, short y, const short *rect)
Definition eventmgr.c:246
void SetMouseCursorShape(unsigned char *shape, short frame)
Definition eventmgr.c:1357
void ReleaseInputEventQueue(void)
Definition eventmgr.c:734
Shared Win32 declarations, types and library interfaces.
#define MISSION_SHIP_COUNT
Definition game_data.h:1639
#define MISSION_NAV_POINT_COUNT
Definition game_data.h:1641
short g_8_nSceneRegionRightWord
Definition cockpt.c:3824
short g_27_nSceneHotspotTopValue
Definition cockpt.c:3823
int g_bJoystickCalibrationHotkey
Definition winmain.c:1397
unsigned char g_abMissionBriefingData[0xde]
Definition hotspot.c:256
InputManagerState * g_18_pEventManager
Definition eventmgr.c:2543
MissionNavPoint g_aMissionNavPoints[MISSION_NAV_POINT_COUNT]
Definition hotspot.c:237
char * g_pszPersonnelFooter
Definition hotspot.c:243
MissionObjectiveSource g_69_aMissionObjectiveSources[8]
Definition hotspot.c:252
void * g_pActiveScenePacket
Definition hotspot.c:242
short g_bPersonnelMenuDrawing
Definition personnel.c:39
CampaignDate * g_4_pElapsedCampaignDatePointer
Definition hotspot.c:255
short g_bDisableChalkboardReplay
Definition optmenu.c:14
short g_128_nShotHotspotLeft
Definition cockpt.c:3822
short g_15_nSceneAreaLowestWord
Definition cockpt.c:3825
MissionShipRecord g_aMissionShips[MISSION_SHIP_COUNT]
Definition hotspot.c:240
unsigned char g_abSeriesAuxData[0x28]
Definition hotspot.c:251
unsigned char g_5_abMissionAuxBlockBytes[0x28]
Definition hotspot.c:250
SceneResourceTable g_stSceneTextList
Definition hotspot.c:249
SceneResourceTable g_stSceneZoneTable
Definition hotspot.c:248
MissionHeader g_13_stMissionHeaderBlock
Definition hotspot.c:253
short g_8_bSceneBackdropClicked
Definition starfld.c:239
int g_nUnusedSceneWord
Definition hotspot.c:241
char g_10_nUnusedHotspotWord
Definition hotspot.c:254
int g_nUnusedSceneFlag
Definition hotspot.c:244
unsigned char selection
Definition game_data.h:770
short left
Definition game_data.h:479