Skip to content

Commit fb2e52f

Browse files
committed
swars: Introduced WeaponType typedef
1 parent 1605c45 commit fb2e52f

File tree

16 files changed

+231
-221
lines changed

16 files changed

+231
-221
lines changed

src/enginzoom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ ushort get_unscaled_zoom(ushort szoom)
122122
return 240 * szoom / h;
123123
}
124124

125-
int get_weapon_zoom_min(ushort wtype)
125+
int get_weapon_zoom_min(WeaponType wtype)
126126
{
127127
struct WeaponDef *wdef;
128128
int zoom;

src/enginzoom.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "bftypes.h"
2323
#include "poly.h"
2424

25+
#include "game_bstype.h"
26+
2527
#ifdef __cplusplus
2628
extern "C" {
2729
#endif
@@ -58,7 +60,7 @@ void zoom_update(short zoom_min, short zoom_max);
5860

5961
ushort get_scaled_zoom(ushort zoom);
6062
ushort get_unscaled_zoom(ushort szoom);
61-
int get_weapon_zoom_min(ushort wtype);
63+
int get_weapon_zoom_min(WeaponType wtype);
6264

6365
short get_overall_scale_min(void);
6466
short get_overall_scale_max(void);

src/fedebrief.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void draw_mission_stats_vals_static(struct ScreenBox *box,
179179

180180
void snprint_concat_comma_separated_weapons_list(char *out, ushort outlen, ulong weapons)
181181
{
182-
ushort wtype;
182+
WeaponType wtype;
183183
ushort strid;
184184
ushort pos;
185185

@@ -189,7 +189,7 @@ void snprint_concat_comma_separated_weapons_list(char *out, ushort outlen, ulong
189189
struct Campaign *p_campgn;
190190

191191
wtype = weapons_prev_weapon(weapons, wtype);
192-
if (wtype == 0)
192+
if (wtype == WEP_NULL)
193193
break;
194194

195195
if (strlen(out) > outlen - 4u)

src/feequip.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,16 +1131,16 @@ void draw_fourpack_slots(short x, short y, ubyte fp)
11311131
draw_box_purple_list(x + 150, y + 30, 4u, 4u, 174);
11321132
}
11331133

1134-
void show_weapon_slot(short scr_x, short scr_y, short weptype)
1134+
void show_weapon_slot(short scr_x, short scr_y, WeaponType wtype)
11351135
{
11361136
ushort fp;
11371137

11381138
lbDisplay.DrawColour = 174;
11391139
lbDisplay.DrawFlags = 0x8000 | Lb_TEXT_ONE_COLOR;
1140-
draw_sprite_purple_list(scr_x, scr_y, &unk1_sprites[weptype - 1 + 1]);
1140+
draw_sprite_purple_list(scr_x, scr_y, &unk1_sprites[wtype - 1 + 1]);
11411141
lbDisplay.DrawFlags &= ~0x8000;
11421142

1143-
fp = weapon_fourpack_index(weptype);
1143+
fp = weapon_fourpack_index(wtype);
11441144
if (fp < WFRPK_COUNT) {
11451145
draw_fourpack_slots(scr_x, scr_y, fp);
11461146
}
@@ -1151,7 +1151,7 @@ void show_weapon_slot(short scr_x, short scr_y, short weptype)
11511151
if (mouse_down_over_box_coords(scr_x, scr_y, scr_x + 181, scr_y + 42))
11521152
{
11531153
lbDisplay.LeftButton = 0;
1154-
mo_weapon = weptype - 1;
1154+
mo_weapon = (int)wtype - 1;
11551155
mo_from_agent = selected_agent;
11561156
}
11571157
}
@@ -1160,11 +1160,11 @@ void show_weapon_slot(short scr_x, short scr_y, short weptype)
11601160
{
11611161
if (mouse_move_over_box_coords(scr_x, scr_y, scr_x + 181, scr_y + 42))
11621162
{
1163-
selected_weapon = weptype - 1;
1163+
selected_weapon = (int)wtype - 1;
11641164
switch_equip_offer_to_sell();
11651165
equip_update_for_selected_weapon();
11661166
}
1167-
if (weptype - 1 >= mo_weapon) {
1167+
if ((int)wtype - 1 >= mo_weapon) {
11681168
mo_weapon = -1;
11691169
}
11701170
}
@@ -1180,7 +1180,7 @@ ubyte show_weapon_slots(struct ScreenBox *p_box)
11801180
#endif
11811181
short scr_x, scr_y;
11821182
short slot;
1183-
short weptype;
1183+
WeaponType wtype;
11841184

11851185
scr_x = p_box->X + 5;
11861186
if ((p_box->Flags & GBxFlg_TextCopied) == 0)
@@ -1202,7 +1202,7 @@ ubyte show_weapon_slots(struct ScreenBox *p_box)
12021202

12031203
scr_y = p_box->Y + 5;
12041204
slot = 0;
1205-
for (weptype = 1; weptype < WEP_TYPES_COUNT; weptype++)
1205+
for (wtype = WEP_NULL + 1; wtype < WEP_TYPES_COUNT; wtype++)
12061206
{
12071207
TbBool has_weapon;
12081208

@@ -1211,19 +1211,19 @@ ubyte show_weapon_slots(struct ScreenBox *p_box)
12111211

12121212
if (selected_agent == 4)
12131213
{
1214-
has_weapon = player_agent_has_weapon(local_player_no, 0, weptype)
1215-
&& player_agent_has_weapon(local_player_no, 1, weptype)
1216-
&& player_agent_has_weapon(local_player_no, 2, weptype)
1217-
&& player_agent_has_weapon(local_player_no, 3, weptype);
1214+
has_weapon = player_agent_has_weapon(local_player_no, 0, wtype)
1215+
&& player_agent_has_weapon(local_player_no, 1, wtype)
1216+
&& player_agent_has_weapon(local_player_no, 2, wtype)
1217+
&& player_agent_has_weapon(local_player_no, 3, wtype);
12181218
}
12191219
else
12201220
{
1221-
has_weapon = player_agent_has_weapon(local_player_no, selected_agent, weptype);
1221+
has_weapon = player_agent_has_weapon(local_player_no, selected_agent, wtype);
12221222
}
12231223

12241224
if (has_weapon)
12251225
{
1226-
show_weapon_slot(scr_x, scr_y, weptype);
1226+
show_weapon_slot(scr_x, scr_y, wtype);
12271227
slot++;
12281228
scr_y += 44;
12291229
}

src/game.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ void teleport_current_agent(PlayerInfo *p_locplayer)
20952095

20962096
void person_give_all_weapons(struct Thing *p_person)
20972097
{
2098-
ushort wtype;
2098+
WeaponType wtype;
20992099

21002100
for (wtype = WEP_TYPES_COUNT-1; wtype > 0; wtype--)
21012101
{
@@ -2115,7 +2115,7 @@ void person_give_all_weapons(struct Thing *p_person)
21152115

21162116
void mark_all_weapons_researched(void)
21172117
{
2118-
ushort wtype;
2118+
WeaponType wtype;
21192119

21202120
for (wtype = WEP_TYPES_COUNT-1; wtype > 0; wtype--)
21212121
{
@@ -4880,7 +4880,7 @@ ubyte weapon_select_input(void)
48804880
#endif
48814881
PlayerInfo *p_locplayer;
48824882
ThingIdx dcthing;
4883-
ushort weptype;
4883+
WeaponType wtype;
48844884
int n;
48854885

48864886
#ifdef MORE_GAME_KEYS
@@ -4897,7 +4897,7 @@ ubyte weapon_select_input(void)
48974897

48984898
p_locplayer = &players[local_player_no];
48994899
dcthing = p_locplayer->DirectControl[0];
4900-
weptype = WEP_NULL;
4900+
wtype = WEP_NULL;
49014901

49024902

49034903
assert(sizeof(sel_weapon_keys)/sizeof(sel_weapon_keys[0]) <= WEAPONS_CARRIED_MAX_COUNT);
@@ -4915,27 +4915,27 @@ ubyte weapon_select_input(void)
49154915
{
49164916
clear_key_pressed(kkey);
49174917
#endif
4918-
weptype = find_nth_weapon_held(dcthing, n+1);
4919-
if (weptype != WEP_NULL)
4918+
wtype = find_nth_weapon_held(dcthing, n+1);
4919+
if (wtype != WEP_NULL)
49204920
break;
49214921
}
49224922
}
49234923

4924-
if (weptype == WEP_NULL)
4924+
if (wtype == WEP_NULL)
49254925
return 0;
49264926

49274927
// Double tapping - select for all agents
49284928
if (gameturn - last_sel_weapon_turn[n] < 7)
49294929
{
49304930
ubyte flag;
49314931

4932-
flag = (person_get_selected_weapon(dcthing) == weptype) ? WepSel_SELECT : WepSel_HIDE;
4933-
my_build_packet(&packets[local_player_no], PAct_SELECT_GRP_SPEC_WEAPON, dcthing, weptype, flag, 0);
4932+
flag = (person_get_selected_weapon(dcthing) == wtype) ? WepSel_SELECT : WepSel_HIDE;
4933+
my_build_packet(&packets[local_player_no], PAct_SELECT_GRP_SPEC_WEAPON, dcthing, wtype, flag, 0);
49344934
last_sel_weapon_turn[n] -= 7;
49354935
}
49364936
else
49374937
{
4938-
my_build_packet(&packets[local_player_no], PAct_SELECT_SPECIFIC_WEAPON, dcthing, weptype, WepSel_TOGGLE, 0);
4938+
my_build_packet(&packets[local_player_no], PAct_SELECT_SPECIFIC_WEAPON, dcthing, wtype, WepSel_TOGGLE, 0);
49394939
last_sel_weapon_turn[n] = gameturn;
49404940
}
49414941

src/game_bstype.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ typedef short ThingIdx;
4444
*/
4545
typedef ubyte PlayerIdx;
4646

47+
/** Type which stores type of a weapon.
48+
*/
49+
typedef ubyte WeaponType;
50+
4751
/** Coordinate on the screen surface.
4852
* The type shall allow safety store values beyond (below/above) real screen
4953
* coordinates, up to another screen size. This means it needs to allow to

0 commit comments

Comments
 (0)