Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
select.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup flight
4 * @brief Gun and missile selection.
5 *
6 * Address range 42ad00-42af9f, corroborated by the Mac select symbols.
7 */
8#include <assert.h>
9#include "wc1.h"
10#include <process.h>
11
12/* Linker commons defined here; LINK orders them by identifier hash. */
13struct Shape *pCommMenuPointerShape; /* 0x005a7660 */
15struct Shape *pCurrentPilotHandShapePtr; /* 0x005a7684 */
17Viewport stSceneBuffer; /* 0x005a76b0 */
18short aPaletteFadeEntries[6][3]; /* 0x005a76d0 */
19struct Shape *pCockpitDamageShape; /* 0x005a76f4 */
20
21/* Function start: 0x42AD00 */
22short find_next_gun(short obj, enum ObjectType currentGun)
23{
24 short firstGun;
25 signed char *loadout;
26 short weapon;
27 short weaponCount;
28 ShipWeaponSlot *weaponSlot;
29 int foundCurrent;
30
31 loadout = aShipWeaponsTable[obj];
32 foundCurrent = 0;
33 firstGun = -1;
34 weaponCount = loadout[0];
35 weaponSlot = (ShipWeaponSlot *)&loadout[1];
36 for (weapon = 0; weapon < weaponCount; weapon++, weaponSlot++) {
37 if (aObjectTypeData[weaponSlot->type].objectClass ==
39 if (firstGun == -1)
40 firstGun = (short)weaponSlot->type;
41 if (foundCurrent == 0) {
42 if (weaponSlot->type == currentGun)
43 foundCurrent = 1;
44 } else if (weaponSlot->type != currentGun) {
45 return (short)weaponSlot->type;
46 }
47 }
48 }
49 if (foundCurrent != 0 && firstGun != currentGun)
50 firstGun = 0x80;
51 return firstGun;
52}
53
54/* Function start: 0x42ADA0 */
55int select_guns(short obj, short selectedGun)
56{
57 ShipWeaponSlot *weaponSlot;
58 int found;
59 short count;
60 short weapon;
61
62 found = 0;
63 count = aShipWeaponsTable[0][0];
64 for (weapon = 0, weaponSlot = (ShipWeaponSlot *)&aShipWeaponsTable[0][1];
65 weapon < count; weapon++, weaponSlot++) {
66 if (aObjectTypeData[weaponSlot->type].objectClass ==
68 if (selectedGun == weaponSlot->type || selectedGun == 0x80) {
69 weaponSlot->disabled = 0;
70 found = 1;
71 } else {
72 weaponSlot->disabled = 1;
73 }
74 }
75 }
76 if (found != 0)
77 return selectedGun;
78 else
79 return -1;
80}
81
82/* Function start: 0x42AE10 */
83unsigned int select_new_gun(void)
84{
87 if (get_mode(0) == 1)
89 return 0;
90}
91
92/* Function start: 0x42AE50 */
93unsigned int select_new_release_weapon(enum ObjectType preferredType)
94{
95 signed char weaponCount;
96 unsigned int currentWeapon;
97 short firstWeapon;
98 signed char weapon;
99 ShipWeaponSlot *weaponSlots;
100
101 weaponCount = aShipWeaponsTable[0][0];
102 currentWeapon = nSelectedReleaseWeaponIndex;
103 weapon = (signed char)(currentWeapon + 1);
104 weaponSlots = (ShipWeaponSlot *)&aShipWeaponsTable[0][1];
105
106 if (weaponCount <= weapon)
107 weapon = 0;
108 if (currentWeapon == -1) {
109 if (preferredType != -1) {
110 weapon = 0;
111 if (aShipWeaponsTable[0][0] > weapon) {
112 for (; weapon <
113 aShipWeaponsTable[0][0];
114 weapon++) {
115 if (weaponSlots[weapon].type == preferredType) {
116 currentWeapon = weapon;
117 weaponSlots[currentWeapon].disabled = 0;
118 break;
119 }
120 }
121 }
122 }
123 nSelectedReleaseWeaponIndex = currentWeapon;
124 if (currentWeapon == -1) {
125 weapon = 0;
126 if (weaponCount > 0) {
127 for (; weapon < weaponCount; weapon++) {
128 if (aObjectTypeData[
129 weaponSlots[weapon].type].objectClass !=
131 currentWeapon = weapon;
132 nSelectedReleaseWeaponIndex = currentWeapon;
133 weaponSlots[currentWeapon].disabled = 0;
134 break;
135 }
136 }
137 }
138 }
139 } else {
140 firstWeapon = weapon;
141 do {
142 enum ObjectType type;
143
144 if (currentWeapon == weapon)
145 break;
146 type = weaponSlots[weapon].type;
147 if (aObjectTypeData[type].objectClass !=
149 weaponSlots[currentWeapon].type != type) {
150 weaponSlots[currentWeapon].disabled = 1;
151 currentWeapon = weapon;
152 nSelectedReleaseWeaponIndex = currentWeapon;
153 weaponSlots[currentWeapon].disabled = 0;
154 break;
155 }
156 weapon++;
157 if (weaponCount <= weapon)
158 weapon = 0;
159 } while (weapon != firstWeapon);
160 }
161 if (get_mode(0) == 1)
163 return 0;
164}
Viewport stPilotHandComposite
Definition select.c:16
struct Shape * pCockpitDamageShape
Definition select.c:19
signed char aShipWeaponsTable[10][0x47]
Definition dib.c:108
struct Shape * pCommMenuPointerShape
Definition select.c:13
ObjectTypeData aObjectTypeData[OBJECT_TYPE_COUNT]
Definition objdata.c:86
Viewport stSceneBuffer
Definition select.c:17
short aPaletteFadeEntries[6][3]
Definition select.c:18
enum ObjectType eSelectedGunType
Definition game.c:67
struct Shape * pCurrentPilotHandShapePtr
Definition select.c:15
int nSelectedReleaseWeaponIndex
Definition game.c:70
Viewport stModalSrcViewport
Definition select.c:14
enum ObjectClass objectClass
Definition wcdata.h:370
enum ObjectType type
Definition wcdata.h:408
signed char disabled
Definition wcdata.h:410
Umbrella header for the game core.
short get_mode(short i)
Definition cockpt.c:690
short find_next_gun(short obj, enum ObjectType currentGun)
Definition select.c:22
int select_guns(short obj, short selectedGun)
Definition select.c:55
void InvalidateVduMode(short i)
Definition cockpt.c:764
unsigned int select_new_release_weapon(enum ObjectType preferredType)
Definition select.c:93
unsigned int select_new_gun(void)
Definition select.c:83
ObjectType
Definition wcdata.h:54
@ OBJECT_CLASS_PROJECTILE
Definition wcdata.h:46