Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
damage.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup cockpit
4 * @brief The cockpit's component-damage display.
5 *
6 * Address range 42c800-42cdaf. Its initialized damage tables follow the
7 * preceding sound and configuration literals.
8 */
9#include "wc1.h"
10
11unsigned char *pDamageDisplayBackground = 0; /* 0x0046a748 */
12/* 0x0046a750 */
14 {36, 37}, {36, 28}, {36, 30}, {36, 23}, {36, 19},
15 {36, 15}, {36, 24}, {36, 16}, {36, 22}
16};
17/* 0x0046a778 */
18const char *apszComponentNames[9] = {
19 "Ion drive",
20 "Power plant",
21 "Shield gen'r",
22 "Computer sys",
23 "InterCom unit",
24 "Target track",
25 "Accel absorbers",
26 "Ejector system",
27 "Repair systems"
28};
29/* 0x0046a7a0 */
30static unsigned char abDamageDisplayFrames[9] = {
31 21, 22, 23, 24, 25, 26, 27, 28, 29
32};
33/* 0x0046a7b0 */
34static const char *apszDamageSeverityNames[5] = {
35 "Ok",
36 "Light",
37 "Moderate",
38 "Heavy",
39 "Destroyed"
40};
41
42static int nDisplayedComponentDamage; /* 0x00476554 */
43
44
45/* Linker commons defined here; LINK orders them by identifier hash. */
46short asInputButton2DoubleClick[2]; /* 0x0059e520 */
47void *apPacketHandlesList[0x1000]; /* 0x0059e530 */
48int aiPktHandleDeltas[0x1000]; /* 0x005a2530 */
49int nPacketHandleTotal; /* 0x005a6530 */
51Viewport *pFullScreenRecord; /* 0x005a6538 */
52unsigned short awScreenRowOffsets[202]; /* 0x005a6540 */
54
55/* Function start: 0x42C800 */
57{
58 signed char component;
59 char message[40];
60
61 nDmgDispState = 0;
63 for (component = 0; component < 9; component++) {
64 if (acPlayerComponentDamageList[component] >= 1)
66 }
67
68 set_new_vdu(0);
71 "DAMAGE REPORT", 2);
73 (short)(stLeftVdu.left + 2),
74 (short)(stLeftVdu.top + 6),
75 (short)(stLeftVdu.right - 2),
76 (short)(stLeftVdu.top + 6),
78 if (cDamagedComponentCount == 0) {
80 (short)(stLeftVdu.top + 20),
81 "NO INTERNAL\n\nDAMAGE", 2);
82 return;
83 }
84
85 component = cCurrentCockpitView;
87 (short)(aWeaponDisplayOrigins[component].x +
90 (short)(aWeaponDisplayOrigins[component].y +
92 /* The original reloads X from memory for the sprite argument. */
97 sprintf(message, "%d Unit%c Damaged",
99 (int)(signed char)(cDamagedComponentCount == 1 ? ' ' : 's'));
101}
102
103/* Function start: 0x42C970 */
105{
106 short previousComponentCount;
107 signed char componentCount;
108 signed char component;
109 signed char attempts;
110 signed char damage;
111 signed char componentIndex;
112
113 previousComponentCount = cDamagedComponentCount;
114 componentCount = 0;
115 for (componentIndex = 0; componentIndex < 9; componentIndex++) {
116 if (acPlayerComponentDamageList[componentIndex] >= 1)
117 componentCount++;
118 }
119
120 cDamagedComponentCount = componentCount;
121 if ((short)componentCount != previousComponentCount) {
123 return;
124 }
125 cDamagedComponentCount = componentCount;
126 if (componentCount == 0)
127 return;
128
129 if (bCockpitlessView == 0) {
131 if (nCurrentDmgDispTicks > 0)
132 return;
133 if (nDamageDisplayPhase == 1) {
135 attempts = 0;
137 do {
138 component++;
139 if (component >= 9)
140 component = 0;
141 damage = acPlayerComponentDamageList[component];
142 nDisplayedComponentDamage = (int)damage;
143 if (nDisplayedComponentDamage >= 1) {
145 break;
146 }
147 attempts++;
148 } while (attempts < 9);
149
150 sprintf(
152 "%s\nDamage: %s",
157 (short)(stLeftVdu.left + 1),
158 (short)(stLeftVdu.top + 7),
159 szDmgStateText, 2);
161 (signed char)abDamageDisplayFrames[
167 (short)(stDamageSpritePos.x +
170 (short)(stDamageSpritePos.y +
177 (short)cDamageDisplayFrame);
179 &stLeftVdu, (short)(stLeftVdu.left + 36),
180 (short)(stLeftVdu.top + 22),
183 0xa9);
188 (short)cDamageDisplayFrame);
189 } else {
195 (short)cDamageDisplayFrame);
198 (short)(stLeftVdu.left + 1),
199 (short)(stLeftVdu.top + 7),
200 szDmgStateText, 2);
203 &stLeftVdu, (short)(stLeftVdu.left + 36),
204 (short)(stLeftVdu.top + 22),
209 }
212 return;
213 }
214
216 if (nCurrentDmgDispTicks <= 0) {
218 attempts = 0;
220 for (;;) {
221 component++;
222 if (component >= 9)
223 component = 0;
225 (int)acPlayerComponentDamageList[component];
226 if (nDisplayedComponentDamage >= 1) {
228 return;
229 }
230 attempts++;
231 if (attempts >= 9)
232 return;
233 }
234 }
235
236 sprintf(
238 "%s\nDamage: %s",
243 (short)(stLeftVdu.top + 7),
244 szDmgStateText, 2);
246 (signed char)abDamageDisplayFrames[
252 (short)(stDamageSpritePos.x +
255 (short)(stDamageSpritePos.y +
262 (short)cDamageDisplayFrame);
264 (short)(stLeftVdu.left + 36),
265 (short)(stLeftVdu.top + 22),
267 stDamageSpritePos.y, 0xa9);
272 (short)cDamageDisplayFrame);
273}
274
275/* Function start: 0x42CDA0 */
276unsigned short GetJoystickPresentUnused(void)
277{
278 return 1;
279}
static const char * apszDamageSeverityNames[5]
Definition damage.c:34
static ShortPoint aDamageDisplayPositions[9]
Definition damage.c:13
static int nDisplayedComponentDamage
Definition damage.c:42
static unsigned char abDamageDisplayFrames[9]
Definition damage.c:30
ScreenAllocation stCurrentScreenAlloc
Definition damage.c:53
signed char cDamagedComponentCount
Definition targ.c:23
int nDamageDisplayPhase
Definition main.c:88
signed char acPlayerComponentDamageList[9]
Definition smart.c:19
unsigned char cBlackColour
Definition init.c:12
int nPacketHandleTotal
Definition damage.c:49
unsigned short awScreenRowOffsets[202]
Definition damage.c:52
short asInputButton2DoubleClick[2]
Definition damage.c:46
struct Shape * pCockpitWeaponShapePtr
Definition timer.c:16
Viewport * pFullScreenRecord
Definition damage.c:51
unsigned char * pDamageDisplayBackground
Definition damage.c:11
int bCockpitlessView
Definition main.c:39
ShortPoint aWeaponDisplayOrigins[5]
Definition objdata.c:593
ShortPoint stDamageSpritePos
Definition targ.c:20
void * apPacketHandlesList[0x1000]
Definition damage.c:47
int aiPktHandleDeltas[0x1000]
Definition damage.c:48
const char * apszComponentNames[9]
Definition damage.c:18
signed char cDamageDisplayFrame
Definition targ.c:22
Viewport stLeftVdu
Definition launch.c:48
signed char cDamageDisplayComponentValue
Definition targ.c:21
signed char cCurrentCockpitView
Definition screen.c:23
TextContext stLeftVduTextContext
Definition timer.c:12
unsigned char cPrimaryTextColour
Definition init.c:18
Viewport * pAllocatedScreenViewport
Definition damage.c:50
char szDmgStateText[0x48]
Definition targ.c:19
ShortPoint stWpnDispOrigin
Definition targ.c:18
int nDmgDispState
Definition main.c:87
short nCurrentDmgDispTicks
Definition targ.c:17
short y
Definition wcdata.h:416
short x
Definition wcdata.h:415
unsigned char colour
Definition wc1base.h:240
short right
Definition wc1base.h:78
short left
Definition wc1base.h:76
short top
Definition wc1base.h:77
Umbrella header for the game core.
void DrawViewportLine(Viewport *viewport, short x1, short y1, short x2, short y2, short colour)
Definition gr.c:995
void UpdateDamageDisplay(void)
Definition damage.c:104
void DrawSpriteDefault(Viewport *viewport, short x, short y, struct Shape *shape, short frame)
Definition gr.c:660
void InvalidateVduMode(short i)
Definition cockpt.c:764
void show_damage_disp(void)
Definition damage.c:56
void RestoreSpriteBackground(Viewport *viewport, unsigned char *background, short x, short y, struct Shape *shape, short frame)
Definition gr.c:799
void ShowComponentHitHudMessage(const char *text, unsigned short colour, short flashCount)
Definition cockpt.c:847
unsigned short GetJoystickPresentUnused(void)
Definition damage.c:276
void set_new_vdu(short vdu)
Definition cockpt.c:739
void CaptureSpriteBackground(Viewport *viewport, unsigned char *background, short x, short y, struct Shape *shape, short frame)
Definition gr.c:669
unsigned int DrawTextAt(TextContext *context, short x, short y, const char *text, unsigned char alignment)
Definition disk.c:239