Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
starfld.c
Go to the documentation of this file.
1/*
2 * Fireworks and constellation fields.
3 *
4 * Retail object 0x45A2C0-0x45AC4F (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
9 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1
10}; /* 0x0049cae0 */
12 0, 16, 16, 0, 4, 4, 20, 20, 24, 8, 8, 24, 28, 12, 12, 28
13}; /* 0x0049cb00 */
14short g_nConstellationDirection = -1; /* 0x0049cb20 */
15
16/* Function start: 0x45A2C0 */
18{
19 short i;
20
21 for (i = 0; i < 0x1e; i++)
22 g_16_aFireworks[i].frame = -1;
23}
24
25/* Function start: 0x45A300 */
26short TheEndFireWorks(Viewport *viewport, short count)
27{
28 short inactiveCount = 0;
29 short index;
30
31 inactiveCount = 0;
32 for (index = (short)(count - 1); index >= 0; index--) {
33 if (g_16_aFireworks[index].frame == -1) {
34 inactiveCount++;
35 continue;
36 }
38 viewport, g_16_aFireworks[index].x,
39 g_16_aFireworks[index].y,
41 (short)(g_16_aFireworks[index].frame +
42 g_16_aFireworks[index].variant * 8));
43 if (g_16_aFireworks[index].frame++ == 7) {
44 g_16_aFireworks[index].frame = -1;
45 ((void (__cdecl *)(int, short))FlushSoundEffectsAndLog)(
46 g_16_aFireworks[index].soundHandle, index);
47 } else if (g_16_aFireworks[index].frame == 1) {
48 PlaySfxWaveFileByNumber(0x25, -1, 0);
49 }
50 }
51 return inactiveCount;
52}
53
54/* Function start: 0x45A441 */
55void InitializeConstellationField(Viewport *viewport, short direction,
56 short density)
57{
58 short width;
59 short particle;
60 short randomSlot;
61 short height;
62
63 g_pConstellationWindow = viewport;
64 g_nConstellationDirection = direction;
65 width = (short)(g_pConstellationWindow->right -
67 height = (short)(g_pConstellationWindow->bottom -
70 (short)(density * 16 / 16);
71 for (particle = 0; particle < g_14_nConstellationParticleTotal;
72 particle++) {
74 randomSlot = RandomInRange(0, 15);
77 RandomInRange(0, width));
80 RandomInRange(0, height));
82 (short)(g_asConstellationVelocity[randomSlot] *
85 (short)(g_asConstellationFrame[randomSlot] +
86 RandomInRange(0, 3));
87 } else {
89 (short)(g_pConstellationWindow->left - 1);
91 }
92 }
93}
94
95/* Function start: 0x45A5C7 */
97 ConstellationParticle particle)
98{
99 if (g_pConstellationWindow->left > particle.x ||
100 g_pConstellationWindow->right < particle.x ||
101 g_pConstellationWindow->top > particle.y ||
102 g_pConstellationWindow->bottom < particle.y)
103 return 1;
104 return 0;
105}
106
107/* Function start: 0x45A634 */
109{
110 short midX;
111 short speed;
112 short midY;
113 short width;
114 short i;
115 short randomIndex;
116 short height;
117 short phase;
118
119 height = (short)(g_pConstellationWindow->bottom -
121 for (i = 0; i < g_14_nConstellationParticleTotal;
122 i++) {
134 phase = (short)(
135 (g_aConstellationParticlesTable[i].frame + 1) % 4);
137 (g_aConstellationParticlesTable[i].frame & 0xfc) +
138 phase);
140 case -1:
143 randomIndex = RandomInRange(0, 15);
144 speed = g_asConstellationVelocity[randomIndex];
147 RandomInRange(0, speed));
150 RandomInRange(0, height));
152 (short)-speed;
155 (short)(g_asConstellationFrame[randomIndex] +
156 RandomInRange(0, 3));
157 }
158 break;
159 case 0:
162 randomIndex = RandomInRange(0, 15);
163 speed = g_asConstellationVelocity[randomIndex];
164 width = (short)(g_pConstellationWindow->right -
166 height = (short)(g_pConstellationWindow->bottom -
170 RandomInRange(0, width));
173 RandomInRange(0, height));
174 midX = (short)(
178 midY = (short)(
182 if (g_aConstellationParticlesTable[i].x < midX &&
183 g_aConstellationParticlesTable[i].y < midY) {
185 (short)-speed;
187 (short)-speed;
188 } else if (
189 g_aConstellationParticlesTable[i].x < midX &&
190 g_aConstellationParticlesTable[i].y >= midY) {
192 (short)-speed;
194 } else if (
195 g_aConstellationParticlesTable[i].x >= midX &&
196 g_aConstellationParticlesTable[i].y < midY) {
199 (short)-speed;
200 } else {
203 }
205 (short)(g_asConstellationFrame[randomIndex] +
206 RandomInRange(0, 3));
207 }
208 break;
209 case 1:
212 randomIndex = RandomInRange(0, 15);
213 speed = g_asConstellationVelocity[randomIndex];
218 RandomInRange(0, speed));
221 RandomInRange(0, height));
223 (short)(g_asConstellationFrame[randomIndex] +
224 RandomInRange(0, 3));
225 }
226 break;
227 }
228 }
229}
230
231/* Linker commons defined here. LINK lays a unit's commons out by the
232 * identifiers' hash keys, so these spellings follow the original addresses. */
233FireworkState g_16_aFireworks[30]; /* 0x005c8df0 */
234unsigned char *g_1_pTitleFireworkShape; /* 0x005c8f58 */
237short g_14_nConstellationParticleTotal; /* 0x005c9014 */
238char g_nUnusedStarfldWord; /* 0x005c9016 */ /* never referenced */
239short g_8_bSceneBackdropClicked; /* 0x005c9018 */
240short g_1_nCockpitArchiveVariantNumber; /* 0x005c901a */
void(__cdecl *g_pIxFree)(void *)
signed char IsConstellationParticleOutsideViewport(ConstellationParticle particle)
Definition starfld.c:96
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition gr.c:682
void InitializeConstellationField(Viewport *viewport, short direction, short density)
Definition starfld.c:55
void InitializeFireworks(void)
Definition starfld.c:17
short TheEndFireWorks(Viewport *viewport, short count)
Definition starfld.c:26
void FlushSoundEffectsAndLog(void *effect, short flags)
Definition music.c:439
void DrawConstellationField(void)
Definition starfld.c:108
void PlaySfxWaveFileByNumber(int soundNumber, int sourceObject, int looping)
Definition music.c:490
unsigned short RandomInRange(unsigned short lo, unsigned short hi)
Definition eventmgr.c:31
Shared Win32 declarations, types and library interfaces.
Viewport * g_pConstellationWindow
Definition starfld.c:235
FireworkState g_16_aFireworks[30]
Definition starfld.c:233
unsigned char * g_pConstellationSprite
Definition message.c:230
short g_14_nConstellationParticleTotal
Definition starfld.c:237
short g_nConstellationDirection
Definition starfld.c:14
unsigned char * g_1_pTitleFireworkShape
Definition starfld.c:234
short g_1_nCockpitArchiveVariantNumber
Definition starfld.c:240
short g_asConstellationFrame[16]
Definition starfld.c:11
ConstellationParticle g_aConstellationParticlesTable[18]
Definition starfld.c:236
short g_asConstellationVelocity[16]
Definition starfld.c:8
short g_8_bSceneBackdropClicked
Definition starfld.c:239
char g_nUnusedStarfldWord
Definition starfld.c:238
short right
Definition game.h:154
short bottom
Definition game.h:155
short left
Definition game.h:152
short top
Definition game.h:153