Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
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 */
9
short
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
==
25
OBJECT_CLASS_PROJECTILE
) {
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 */
44
int
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
==
59
OBJECT_CLASS_PROJECTILE
) {
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 */
74
void
select_new_gun
(
void
)
75
{
76
g_nSelectedGunType
=
77
select_guns
(
find_next_gun
(0,
g_nSelectedGunType
));
78
if
(
get_mode
(0) == 1)
79
InvalidateVduMode
(0);
80
}
81
82
/* Function start: 0x4616B8 */
83
void
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;
95
if
(
g_nSelectedReleaseWeaponIndex
== -1) {
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;
102
g_nSelectedReleaseWeaponIndex
= index;
103
break
;
104
}
105
}
106
}
107
if
(
g_nSelectedReleaseWeaponIndex
== -1) {
108
for
(index = 0; weaponCount > index; index++) {
109
weaponType =
110
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
111
index].weaponType;
112
if
(
g_aObjectTypeData
[weaponType].objectClass !=
113
OBJECT_CLASS_PROJECTILE
) {
114
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
115
index].disabled = 0;
116
g_nSelectedReleaseWeaponIndex
= index;
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 !=
128
OBJECT_CLASS_PROJECTILE
&&
129
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
130
index].type !=
131
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
132
g_nSelectedReleaseWeaponIndex
].type) {
133
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
134
g_nSelectedReleaseWeaponIndex
].disabled = 1;
135
((
ShipWeaponSlot
*)&
g_aShipWeapons
[0][1])[
136
index].disabled = 0;
137
g_nSelectedReleaseWeaponIndex
= index;
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)
148
InvalidateVduMode
(0);
149
}
get_mode
short get_mode(short i)
Definition
cockpt.c:630
find_next_gun
short find_next_gun(short obj, short currentGun)
Definition
select.c:9
InvalidateVduMode
void InvalidateVduMode(short i)
Definition
cockpt.c:714
select_new_gun
void select_new_gun(void)
Definition
select.c:74
select_new_release_weapon
void select_new_release_weapon(short preferredType)
Definition
select.c:83
select_guns
int select_guns(short selectedGun)
Definition
select.c:44
game.h
Shared Win32 declarations, types and library interfaces.
OBJECT_CLASS_PROJECTILE
@ OBJECT_CLASS_PROJECTILE
Definition
game_data.h:45
OBJECT_DATA_TURRET_GUN
#define OBJECT_DATA_TURRET_GUN
Definition
game_data.h:1608
g_nSelectedReleaseWeaponIndex
short g_nSelectedReleaseWeaponIndex
Definition
viewrect.c:84
g_aObjectTypeData
ObjectTypeData g_aObjectTypeData[OBJECT_DATA_COUNT]
Definition
campglob.c:310
g_aShipWeapons
unsigned char g_aShipWeapons[10][0xA1]
Definition
viewrect.c:150
g_nSelectedGunType
short g_nSelectedGunType
Definition
viewrect.c:83
ObjectTypeData::objectClass
short objectClass
Definition
game_data.h:367
ShipWeaponSlot
Definition
game_data.h:414
ShipWeaponSlot::type
short type
Definition
game_data.h:415
ShipWeaponSlot::disabled
signed char disabled
Definition
game_data.h:417
src
select.c
Generated by
1.18.0