Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
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
8
short
g_asConstellationVelocity
[16] = {
9
8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1
10
};
/* 0x0049cae0 */
11
short
g_asConstellationFrame
[16] = {
12
0, 16, 16, 0, 4, 4, 20, 20, 24, 8, 8, 24, 28, 12, 12, 28
13
};
/* 0x0049cb00 */
14
short
g_nConstellationDirection
= -1;
/* 0x0049cb20 */
15
16
/* Function start: 0x45A2C0 */
17
void
InitializeFireworks
(
void
)
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 */
26
short
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
}
37
DrawSpriteDefault
(
38
viewport,
g_16_aFireworks
[index].x,
39
g_16_aFireworks
[index].y,
40
g_1_pTitleFireworkShape
,
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 */
55
void
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
-
66
g_pConstellationWindow
->
left
);
67
height = (short)(
g_pConstellationWindow
->
bottom
-
68
g_pConstellationWindow
->
top
);
69
g_14_nConstellationParticleTotal
=
70
(short)(density * 16 / 16);
71
for
(particle = 0; particle <
g_14_nConstellationParticleTotal
;
72
particle++) {
73
if
(
g_nConstellationDirection
!= 0) {
74
randomSlot =
RandomInRange
(0, 15);
75
g_aConstellationParticlesTable
[particle].
x
=
76
(short)(
g_pConstellationWindow
->
left
+
77
RandomInRange
(0, width));
78
g_aConstellationParticlesTable
[particle].
y
=
79
(short)(
g_pConstellationWindow
->
top
+
80
RandomInRange
(0, height));
81
g_aConstellationParticlesTable
[particle].
deltaX
=
82
(short)(
g_asConstellationVelocity
[randomSlot] *
83
g_nConstellationDirection
);
84
g_aConstellationParticlesTable
[particle].
frame
=
85
(short)(
g_asConstellationFrame
[randomSlot] +
86
RandomInRange
(0, 3));
87
}
else
{
88
g_aConstellationParticlesTable
[particle].
x
=
89
(short)(
g_pConstellationWindow
->
left
- 1);
90
g_aConstellationParticlesTable
[particle].
frame
= 0;
91
}
92
}
93
}
94
95
/* Function start: 0x45A5C7 */
96
signed
char
IsConstellationParticleOutsideViewport
(
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 */
108
void
DrawConstellationField
(
void
)
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
-
120
g_pConstellationWindow
->
top
);
121
for
(i = 0; i <
g_14_nConstellationParticleTotal
;
122
i++) {
123
DrawSpriteDefault
(
g_pConstellationWindow
,
124
g_aConstellationParticlesTable
[i].x,
125
g_aConstellationParticlesTable
[i].y,
126
g_pConstellationSprite
,
127
g_aConstellationParticlesTable
[i].frame);
128
g_aConstellationParticlesTable
[i].
x
= (short)(
129
g_aConstellationParticlesTable
[i].x +
130
g_aConstellationParticlesTable
[i].deltaX);
131
g_aConstellationParticlesTable
[i].
y
= (short)(
132
g_aConstellationParticlesTable
[i].y +
133
g_aConstellationParticlesTable
[i].deltaY);
134
phase = (short)(
135
(
g_aConstellationParticlesTable
[i].frame + 1) % 4);
136
g_aConstellationParticlesTable
[i].
frame
= (short)(
137
(
g_aConstellationParticlesTable
[i].frame & 0xfc) +
138
phase);
139
switch
(
g_nConstellationDirection
) {
140
case
-1:
141
if
(
IsConstellationParticleOutsideViewport
(
142
g_aConstellationParticlesTable
[i]) != 0) {
143
randomIndex =
RandomInRange
(0, 15);
144
speed =
g_asConstellationVelocity
[randomIndex];
145
g_aConstellationParticlesTable
[i].
x
= (short)(
146
g_pConstellationWindow
->
right
-
147
RandomInRange
(0, speed));
148
g_aConstellationParticlesTable
[i].
y
= (short)(
149
g_pConstellationWindow
->
top
+
150
RandomInRange
(0, height));
151
g_aConstellationParticlesTable
[i].
deltaX
=
152
(short)-speed;
153
g_aConstellationParticlesTable
[i].
deltaY
= 0;
154
g_aConstellationParticlesTable
[i].
frame
=
155
(short)(
g_asConstellationFrame
[randomIndex] +
156
RandomInRange
(0, 3));
157
}
158
break
;
159
case
0:
160
if
(
IsConstellationParticleOutsideViewport
(
161
g_aConstellationParticlesTable
[i]) != 0) {
162
randomIndex =
RandomInRange
(0, 15);
163
speed =
g_asConstellationVelocity
[randomIndex];
164
width = (short)(
g_pConstellationWindow
->
right
-
165
g_pConstellationWindow
->
left
);
166
height = (short)(
g_pConstellationWindow
->
bottom
-
167
g_pConstellationWindow
->
top
);
168
g_aConstellationParticlesTable
[i].
x
= (short)(
169
g_pConstellationWindow
->
left
+
170
RandomInRange
(0, width));
171
g_aConstellationParticlesTable
[i].
y
= (short)(
172
g_pConstellationWindow
->
top
+
173
RandomInRange
(0, height));
174
midX = (short)(
175
(
g_pConstellationWindow
->
right
-
176
g_pConstellationWindow
->
left
) / 2 +
177
g_pConstellationWindow
->
left
);
178
midY = (short)(
179
(
g_pConstellationWindow
->
bottom
-
180
g_pConstellationWindow
->
top
) / 2 +
181
g_pConstellationWindow
->
top
);
182
if
(
g_aConstellationParticlesTable
[i].x < midX &&
183
g_aConstellationParticlesTable
[i].y < midY) {
184
g_aConstellationParticlesTable
[i].
deltaX
=
185
(short)-speed;
186
g_aConstellationParticlesTable
[i].
deltaY
=
187
(short)-speed;
188
}
else
if
(
189
g_aConstellationParticlesTable
[i].x < midX &&
190
g_aConstellationParticlesTable
[i].y >= midY) {
191
g_aConstellationParticlesTable
[i].
deltaX
=
192
(short)-speed;
193
g_aConstellationParticlesTable
[i].
deltaY
= speed;
194
}
else
if
(
195
g_aConstellationParticlesTable
[i].x >= midX &&
196
g_aConstellationParticlesTable
[i].y < midY) {
197
g_aConstellationParticlesTable
[i].
deltaX
= speed;
198
g_aConstellationParticlesTable
[i].
deltaY
=
199
(short)-speed;
200
}
else
{
201
g_aConstellationParticlesTable
[i].
deltaX
= speed;
202
g_aConstellationParticlesTable
[i].
deltaY
= speed;
203
}
204
g_aConstellationParticlesTable
[i].
frame
=
205
(short)(
g_asConstellationFrame
[randomIndex] +
206
RandomInRange
(0, 3));
207
}
208
break
;
209
case
1:
210
if
(
IsConstellationParticleOutsideViewport
(
211
g_aConstellationParticlesTable
[i]) != 0) {
212
randomIndex =
RandomInRange
(0, 15);
213
speed =
g_asConstellationVelocity
[randomIndex];
214
g_aConstellationParticlesTable
[i].
deltaX
= speed;
215
g_aConstellationParticlesTable
[i].
deltaY
= 0;
216
g_aConstellationParticlesTable
[i].
x
= (short)(
217
g_pConstellationWindow
->
left
+
218
RandomInRange
(0, speed));
219
g_aConstellationParticlesTable
[i].
y
= (short)(
220
g_pConstellationWindow
->
top
+
221
RandomInRange
(0, height));
222
g_aConstellationParticlesTable
[i].
frame
=
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. */
233
FireworkState
g_16_aFireworks
[30];
/* 0x005c8df0 */
234
unsigned
char
*
g_1_pTitleFireworkShape
;
/* 0x005c8f58 */
235
Viewport
*
g_pConstellationWindow
;
/* 0x005c8f5c */
236
ConstellationParticle
g_aConstellationParticlesTable
[18];
/* 0x005c8f60 */
237
short
g_14_nConstellationParticleTotal
;
/* 0x005c9014 */
238
char
g_nUnusedStarfldWord
;
/* 0x005c9016 */
/* never referenced */
239
short
g_8_bSceneBackdropClicked
;
/* 0x005c9018 */
240
short
g_1_nCockpitArchiveVariantNumber
;
/* 0x005c901a */
void
void(__cdecl *g_pIxFree)(void *)
IsConstellationParticleOutsideViewport
signed char IsConstellationParticleOutsideViewport(ConstellationParticle particle)
Definition
starfld.c:96
DrawSpriteDefault
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition
gr.c:682
InitializeConstellationField
void InitializeConstellationField(Viewport *viewport, short direction, short density)
Definition
starfld.c:55
InitializeFireworks
void InitializeFireworks(void)
Definition
starfld.c:17
TheEndFireWorks
short TheEndFireWorks(Viewport *viewport, short count)
Definition
starfld.c:26
FlushSoundEffectsAndLog
void FlushSoundEffectsAndLog(void *effect, short flags)
Definition
music.c:439
DrawConstellationField
void DrawConstellationField(void)
Definition
starfld.c:108
PlaySfxWaveFileByNumber
void PlaySfxWaveFileByNumber(int soundNumber, int sourceObject, int looping)
Definition
music.c:490
RandomInRange
unsigned short RandomInRange(unsigned short lo, unsigned short hi)
Definition
eventmgr.c:31
game.h
Shared Win32 declarations, types and library interfaces.
g_pConstellationWindow
Viewport * g_pConstellationWindow
Definition
starfld.c:235
g_16_aFireworks
FireworkState g_16_aFireworks[30]
Definition
starfld.c:233
g_pConstellationSprite
unsigned char * g_pConstellationSprite
Definition
message.c:230
g_14_nConstellationParticleTotal
short g_14_nConstellationParticleTotal
Definition
starfld.c:237
g_nConstellationDirection
short g_nConstellationDirection
Definition
starfld.c:14
g_1_pTitleFireworkShape
unsigned char * g_1_pTitleFireworkShape
Definition
starfld.c:234
g_1_nCockpitArchiveVariantNumber
short g_1_nCockpitArchiveVariantNumber
Definition
starfld.c:240
g_asConstellationFrame
short g_asConstellationFrame[16]
Definition
starfld.c:11
g_aConstellationParticlesTable
ConstellationParticle g_aConstellationParticlesTable[18]
Definition
starfld.c:236
g_asConstellationVelocity
short g_asConstellationVelocity[16]
Definition
starfld.c:8
g_8_bSceneBackdropClicked
short g_8_bSceneBackdropClicked
Definition
starfld.c:239
g_nUnusedStarfldWord
char g_nUnusedStarfldWord
Definition
starfld.c:238
ConstellationParticle
Definition
game_data.h:1276
ConstellationParticle::deltaX
short deltaX
Definition
game_data.h:1279
ConstellationParticle::x
short x
Definition
game_data.h:1277
ConstellationParticle::y
short y
Definition
game_data.h:1278
ConstellationParticle::deltaY
short deltaY
Definition
game_data.h:1280
ConstellationParticle::frame
short frame
Definition
game_data.h:1281
FireworkState
Definition
game_data.h:334
FireworkState::frame
short frame
Definition
game_data.h:335
FireworkState::soundHandle
int soundHandle
Definition
game_data.h:339
Viewport
Definition
game.h:149
Viewport::right
short right
Definition
game.h:154
Viewport::bottom
short bottom
Definition
game.h:155
Viewport::left
short left
Definition
game.h:152
Viewport::top
short top
Definition
game.h:153
src
starfld.c
Generated by
1.18.0