Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
select.c
Go to the documentation of this file.
1/*
2 * Weapon selection.
3 *
4 * Retail object 0x461480-0x4618DF (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8/* Function start: 0x461480 */
9short find_next_gun(short obj, short currentGun)
10{
11 unsigned char *loadoutTable;
12 short earliest;
13 short foundCurrent;
14 short count;
15 ShipWeaponSlot *weaponSlot;
16 short i;
17
18 loadoutTable = g_aShipWeapons[obj];
19 foundCurrent = 0;
20 earliest = -1;
21 count = (signed char)loadoutTable[0];
22 weaponSlot = (ShipWeaponSlot *)&loadoutTable[1];
23 for (i = 0; i < count; i++, weaponSlot++) {
24 if (g_aObjectTypeData[weaponSlot->type].objectClass ==
26 if (weaponSlot->type != OBJECT_DATA_TURRET_GUN) {
27 if (earliest == -1)
28 earliest = weaponSlot->type;
29 if (foundCurrent == 0) {
30 if (weaponSlot->type == currentGun)
31 foundCurrent = 1;
32 } else if (weaponSlot->type != currentGun) {
33 return weaponSlot->type;
34 }
35 }
36 }
37 }
38 if (foundCurrent != 0 && earliest != currentGun)
39 return 0x80;
40 return earliest;
41}
42
43/* Function start: 0x4615A2 */
44int select_guns(short selectedGun)
45{
46 unsigned char *weapons;
47 short any;
48 short weaponCount;
49 short i;
50 ShipWeaponSlot *weaponSlot;
51
52 weapons = g_aShipWeapons[0];
53 any = 0;
54 weaponCount = (signed char)weapons[0];
55 i = 0;
56 weaponSlot = (ShipWeaponSlot *)&weapons[1];
57 for (; i < weaponCount; i++, weaponSlot++) {
58 if (g_aObjectTypeData[weaponSlot->type].objectClass ==
60 if (weaponSlot->type == selectedGun || selectedGun == 0x80) {
61 weaponSlot->disabled = 0;
62 any = 1;
63 } else {
64 weaponSlot->disabled = 1;
65 }
66 }
67 }
68 if (any != 0)
69 return selectedGun;
70 return -1;
71}
72
73/* Function start: 0x46166D */
81
82/* Function start: 0x4616B8 */
83void select_new_release_weapon(short preferredType)
84{
85 signed char weaponCount;
86 short firstFound;
87 signed char index;
88 short weaponType;
89
90 weaponCount = g_aShipWeapons[0][0];
91 index = (signed char)g_nSelectedReleaseWeaponIndex;
92 index++;
93 if (weaponCount <= index)
94 index = 0;
96 if (preferredType != -1) {
97 for (index = 0; weaponCount > index; index++) {
98 if (((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
99 index].type == preferredType) {
100 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
101 index].disabled = 0;
103 break;
104 }
105 }
106 }
108 for (index = 0; weaponCount > index; index++) {
109 weaponType =
110 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
111 index].weaponType;
112 if (g_aObjectTypeData[weaponType].objectClass !=
114 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
115 index].disabled = 0;
117 break;
118 }
119 }
120 }
121 } else {
122 firstFound = index;
123 while (index != g_nSelectedReleaseWeaponIndex) {
124 weaponType =
125 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
126 index].weaponType;
127 if (g_aObjectTypeData[weaponType].objectClass !=
129 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
130 index].type !=
131 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
133 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
134 g_nSelectedReleaseWeaponIndex].disabled = 1;
135 ((ShipWeaponSlot *)&g_aShipWeapons[0][1])[
136 index].disabled = 0;
138 break;
139 }
140 index++;
141 if (weaponCount <= index)
142 index = 0;
143 if (index == firstFound)
144 break;
145 }
146 }
147 if (get_mode(0) == 1)
149}
short get_mode(short i)
Definition cockpt.c:630
short find_next_gun(short obj, short currentGun)
Definition select.c:9
void InvalidateVduMode(short i)
Definition cockpt.c:714
void select_new_gun(void)
Definition select.c:74
void select_new_release_weapon(short preferredType)
Definition select.c:83
int select_guns(short selectedGun)
Definition select.c:44
Shared Win32 declarations, types and library interfaces.
@ OBJECT_CLASS_PROJECTILE
Definition game_data.h:45
#define OBJECT_DATA_TURRET_GUN
Definition game_data.h:1608
short g_nSelectedReleaseWeaponIndex
Definition viewrect.c:84
ObjectTypeData g_aObjectTypeData[OBJECT_DATA_COUNT]
Definition campglob.c:310
unsigned char g_aShipWeapons[10][0xA1]
Definition viewrect.c:150
short g_nSelectedGunType
Definition viewrect.c:83
short objectClass
Definition game_data.h:367
signed char disabled
Definition game_data.h:417