summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai/default/default.c6
-rw-r--r--ai/trolly/trolly.c5
-rw-r--r--aircraft_cmd.c4
-rw-r--r--clear_cmd.c6
-rw-r--r--disaster_cmd.c2
-rw-r--r--gfx.c4
-rw-r--r--main_gui.c16
-rw-r--r--order_cmd.c4
-rw-r--r--players.c10
-rw-r--r--rail_gui.c12
-rw-r--r--road_gui.c7
-rw-r--r--ship_cmd.c4
-rw-r--r--smallmap_gui.c32
-rw-r--r--station.h4
-rw-r--r--strings.c6
-rw-r--r--town_cmd.c4
-rw-r--r--train_cmd.c4
-rw-r--r--tree_cmd.c8
-rw-r--r--tunnelbridge_cmd.c8
-rw-r--r--vehicle.c2
20 files changed, 72 insertions, 76 deletions
diff --git a/ai/default/default.c b/ai/default/default.c
index 7f0ae2aa8..1d763e483 100644
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -1086,9 +1086,9 @@ static void AiWantPassengerRoute(Player *p)
static void AiWantTrainRoute(Player *p)
{
- uint16 r;
+ uint16 r = GB(Random(), 0, 16);
+
p->ai.railtype_to_use = GetBestRailtype(p);
- r = (uint16)Random();
if (r > 0xD000) {
AiWantLongIndustryRoute(p);
@@ -1349,7 +1349,7 @@ static void AiWantPassengerRouteInsideTown(Player *p)
static void AiWantRoadRoute(Player *p)
{
- uint16 r = (uint16)Random();
+ uint16 r = GB(Random(), 0, 16);
if (r > 0x4000) {
AiWantLongRoadIndustryRoute(p);
diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c
index c40b0faef..f57644b10 100644
--- a/ai/trolly/trolly.c
+++ b/ai/trolly/trolly.c
@@ -781,7 +781,8 @@ static void AiNew_State_FindDepot(Player *p)
// To make the depot stand in the middle of the route, we start from the center..
// But first we walk through the route see if we can find a depot that is ours
// this keeps things nice ;)
- int g, i, j, r;
+ int g, i, r;
+ uint j;
TileIndex tile;
assert(p->ainew.state == AI_STATE_FIND_DEPOT);
@@ -796,7 +797,7 @@ static void AiNew_State_FindDepot(Player *p)
// We found a depot, is it ours? (TELL ME!!!)
if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
// Now, is it pointing to the right direction.........
- if ((_m[tile + TileOffsByDir(j)].m5 & 3) == (j ^ 2)) {
+ if (GB(_m[tile + TileOffsByDir(j)].m5, 0, 2) == (j ^ 2)) {
// Yeah!!!
p->ainew.depot_tile = tile + TileOffsByDir(j);
p->ainew.depot_direction = j ^ 2; // Reverse direction
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 13032b0a3..af45b88f9 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -475,14 +475,14 @@ int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32
* @param x,y unused
* @param p1 vehicle ID of the aircraft to refit
* @param p2 various bitstuffed elements
- * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
+ * - p2 = (bit 0-7) - the new cargo type to refit to
*/
int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
Vehicle *v;
int pass, mail;
int32 cost;
- CargoID new_cid = p2 & 0xFF; //gets the cargo number
+ CargoID new_cid = GB(p2, 0, 8);
const AircraftVehicleInfo *avi;
if (!IsVehicleIndex(p1)) return CMD_ERROR;
diff --git a/clear_cmd.c b/clear_cmd.c
index 90b70e568..e1a494b51 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -772,14 +772,14 @@ void GenerateClearTile(void)
TileIndex tile;
/* add hills */
- i = ScaleByMapSize((Random() & 0x3FF) + 0x400);
+ i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
do {
tile = RandomTile();
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1);
} while (--i);
/* add grey squares */
- i = ScaleByMapSize((Random() & 0x7F) + 0x80);
+ i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
do {
uint32 r = Random();
tile = RandomTileSeed(r);
@@ -791,7 +791,7 @@ void GenerateClearTile(void)
SB(_m[tile].m5, 2, 2, 2);
do {
if (--j == 0) goto get_out;
- tile_new = tile + TileOffsByDir(Random() & 3);
+ tile_new = tile + TileOffsByDir(GB(Random(), 0, 2));
} while (!IsTileType(tile_new, MP_CLEAR));
tile = tile_new;
}
diff --git a/disaster_cmd.c b/disaster_cmd.c
index a826bd6f0..f180a1836 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -920,7 +920,7 @@ static void Disaster7_Init(void)
{
TileIndex tile = i->xy;
- TileIndexDiff step = TileOffsByDir(Random() & 3);
+ TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2));
int count = 30;
do {
diff --git a/gfx.c b/gfx.c
index d3c6e7015..2e3079b62 100644
--- a/gfx.c
+++ b/gfx.c
@@ -441,7 +441,7 @@ void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
GetString(buffer, str);
tmp = FormatStringLinebreaks(buffer, maxw);
- num = (uint16)tmp;
+ num = GB(tmp, 0, 16);
switch (GB(tmp, 16, 16)) {
case 0: mt = 10; break;
@@ -487,7 +487,7 @@ void DrawStringMultiLine(int x, int y, StringID str, int maxw)
GetString(buffer, str);
tmp = FormatStringLinebreaks(buffer, maxw);
- num = (uint16)tmp;
+ num = GB(tmp, 0, 16);
switch (GB(tmp, 16, 16)) {
case 0: mt = 10; break;
diff --git a/main_gui.c b/main_gui.c
index 2b6a38e64..4ccc585b5 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -979,14 +979,14 @@ static void ToolbarOptionsClick(Window *w)
w = PopupMainToolbMenu(w, 43, 2, STR_02C3_GAME_OPTIONS, 13, 0);
x = (uint16)-1;
- if (_display_opt & DO_SHOW_TOWN_NAMES) x &= ~(1<<5);
- if (_display_opt & DO_SHOW_STATION_NAMES) x &= ~(1<<6);
- if (_display_opt & DO_SHOW_SIGNS) x &= ~(1<<7);
- if (_display_opt & DO_WAYPOINTS) x &= ~(1<<8);
- if (_display_opt & DO_FULL_ANIMATION) x &= ~(1<<9);
- if (_display_opt & DO_FULL_DETAIL) x &= ~(1<<10);
- if (_display_opt & DO_TRANS_BUILDINGS) x &= ~(1<<11);
- if (_display_opt & DO_TRANS_SIGNS) x &= ~(1<<12);
+ if (_display_opt & DO_SHOW_TOWN_NAMES) CLRBIT(x, 5);
+ if (_display_opt & DO_SHOW_STATION_NAMES) CLRBIT(x, 6);
+ if (_display_opt & DO_SHOW_SIGNS) CLRBIT(x, 7);
+ if (_display_opt & DO_WAYPOINTS) CLRBIT(x, 8);
+ if (_display_opt & DO_FULL_ANIMATION) CLRBIT(x, 9);
+ if (_display_opt & DO_FULL_DETAIL) CLRBIT(x, 10);
+ if (_display_opt & DO_TRANS_BUILDINGS) CLRBIT(x, 11);
+ if (_display_opt & DO_TRANS_SIGNS) CLRBIT(x, 12);
WP(w,menu_d).checked_items = x;
}
diff --git a/order_cmd.c b/order_cmd.c
index fc91034be..2820e88bd 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -830,8 +830,8 @@ void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak)
int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
Vehicle *v;
- OrderID cur_ord = p2 & 0xFFFF;
- uint16 serv_int = p2 >> 16;
+ OrderID cur_ord = GB(p2, 0, 16);
+ uint16 serv_int = GB(p2, 16, 16);
if (!IsVehicleIndex(p1)) return CMD_ERROR;
diff --git a/players.c b/players.c
index 2168eb264..15a53aba5 100644
--- a/players.c
+++ b/players.c
@@ -155,12 +155,12 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
uint val = GB(face, 20, 8);
if (!(flag&1)) {
- DrawSprite(0x36B + ((val&3)*3>>2), x, y);
- DrawSprite(0x36E + ((val>>2)&3), x, y);
- DrawSprite(0x372 + ((val>>4)*6>>4), x, y);
+ DrawSprite(0x36B + (GB(val, 0, 2) * 3 >> 2), x, y);
+ DrawSprite(0x36E + (GB(val, 2, 2) * 4 >> 2), x, y);
+ DrawSprite(0x372 + (GB(val, 4, 4) * 6 >> 4), x, y);
} else {
- DrawSprite(0x378 + ((val&3)*3>>2), x, y);
- DrawSprite(0x37B + ((val>>2)&3), x, y);
+ DrawSprite(0x378 + (GB(val, 0, 2) * 3 >> 2), x, y);
+ DrawSprite(0x37B + (GB(val, 2, 2) * 4 >> 2), x, y);
val >>= 4;
if (val < 3) {
diff --git a/rail_gui.c b/rail_gui.c
index 07f38ebc3..2d31d4fbb 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -285,18 +285,16 @@ static void BuildRailClick_Tunnel(Window *w)
static void BuildRailClick_Remove(Window *w)
{
- if (w->disabled_state & (1<<16))
- return;
+ if (HASBIT(w->disabled_state, 16)) return;
SetWindowDirty(w);
SndPlayFx(SND_15_BEEP);
- w->click_state ^= (1 << 16);
- _remove_button_clicked = (w->click_state & (1 << 16)) != 0;
- SetSelectionRed((w->click_state & (1 << 16)) != 0);
+ TOGGLEBIT(w->click_state, 16);
+ _remove_button_clicked = HASBIT(w->click_state, 16) != 0;
+ SetSelectionRed(HASBIT(w->click_state, 16) != 0);
// handle station builder
- if( w->click_state & (1 << 16) )
- {
+ if (HASBIT(w->click_state, 16)) {
if(_remove_button_clicked)
SetTileSelectSize(1, 1);
else
diff --git a/road_gui.c b/road_gui.c
index facebc49a..dbb0ea1af 100644
--- a/road_gui.c
+++ b/road_gui.c
@@ -159,12 +159,11 @@ static void BuildRoadClick_Tunnel(Window *w)
static void BuildRoadClick_Remove(Window *w)
{
- if (w->disabled_state & (1<<11))
- return;
+ if (HASBIT(w->disabled_state, 11)) return;
SetWindowDirty(w);
SndPlayFx(SND_15_BEEP);
- w->click_state ^= (1 << 11);
- SetSelectionRed((w->click_state & (1 << 11)) != 0);
+ TOGGLEBIT(w->click_state, 11);
+ SetSelectionRed(HASBIT(w->click_state, 11) != 0);
}
static void BuildRoadClick_Landscaping(Window *w)
diff --git a/ship_cmd.c b/ship_cmd.c
index 28d04c0bc..bd2bb2b6b 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -356,8 +356,8 @@ static void CheckShipLeaveDepot(Vehicle *v)
} else {
return;
}
- v->direction = (byte)m;
- v->u.ship.state = (byte)(m >> 8);
+ v->direction = GB(m, 0, 8);
+ v->u.ship.state = GB(m, 8, 8);
v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0;
diff --git a/smallmap_gui.c b/smallmap_gui.c
index 4d7107680..8fc731e1f 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -197,15 +197,15 @@ static const uint16 * const _legend_table[] = {
static inline void WRITE_PIXELS(Pixel* d, uint32 val)
{
# if defined(TTD_BIG_ENDIAN)
- d[0] = (byte)(val >> 24);
- d[1] = (byte)(val >> 16);
- d[2] = (byte)(val >> 8);
- d[3] = (byte)(val >> 0);
+ d[0] = GB(val, 24, 8);
+ d[1] = GB(val, 16, 8);
+ d[2] = GB(val, 8, 8);
+ d[3] = GB(val, 0, 8);
# elif defined(TTD_LITTLE_ENDIAN)
- d[0] = (byte)(val >> 0);
- d[1] = (byte)(val >> 8);
- d[2] = (byte)(val >> 16);
- d[3] = (byte)(val >> 24);
+ d[0] = GB(val, 0, 8);
+ d[1] = GB(val, 8, 8);
+ d[2] = GB(val, 16, 8);
+ d[3] = GB(val, 24, 8);
# endif
}
@@ -213,15 +213,15 @@ static const uint16 * const _legend_table[] = {
static inline void WRITE_PIXELS_OR(Pixel* d, uint32 val)
{
# if defined(TTD_BIG_ENDIAN)
- d[0] |= (byte)(val >> 24);
- d[1] |= (byte)(val >> 16);
- d[2] |= (byte)(val >> 8);
- d[3] |= (byte)(val >> 0);
+ d[0] |= GB(val, 24, 8);
+ d[1] |= GB(val, 16, 8);
+ d[2] |= GB(val, 8, 8);
+ d[3] |= GB(val, 0, 8);
# elif defined(TTD_LITTLE_ENDIAN)
- d[0] |= (byte)(val >> 0);
- d[1] |= (byte)(val >> 8);
- d[2] |= (byte)(val >> 16);
- d[3] |= (byte)(val >> 24);
+ d[0] |= GB(val, 0, 8);
+ d[1] |= GB(val, 8, 8);
+ d[2] |= GB(val, 16, 8);
+ d[3] |= GB(val, 24, 8);
# endif
}
#else
diff --git a/station.h b/station.h
index 6fa329292..9b35122b4 100644
--- a/station.h
+++ b/station.h
@@ -222,8 +222,8 @@ static inline bool IsCompatibleTrainStationTile(TileIndex tile, TileIndex ref)
assert(IsTrainStationTile(ref));
return
IsTrainStationTile(tile) &&
- (_m[tile].m3 & 0x0F) == (_m[ref].m3 & 0x0F) && // same rail type?
- (_m[tile].m5 & 0x01) == (_m[ref].m5 & 0x01); // same direction?
+ GB(_m[tile].m3, 0, 4) == GB(_m[ref].m3, 0, 4) && // same rail type?
+ GB(_m[tile].m5, 0, 1) == GB(_m[ref].m5, 0, 1); // same direction?
}
static inline bool IsRoadStationTile(TileIndex tile) {
diff --git a/strings.c b/strings.c
index 77c891efe..cde711a47 100644
--- a/strings.c
+++ b/strings.c
@@ -161,9 +161,7 @@ char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
uint index = GB(string, 0, 11);
uint tab = GB(string, 11, 5);
- if (!(string & 0xFFFF)) {
- error("!invalid string id 0 in GetString");
- }
+ if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString");
switch (tab) {
case 4:
@@ -196,7 +194,7 @@ char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
"Probably because an old version of the .lng file.\n", string
);
- return FormatString(buffr, GetStringPtr(string&0xFFFF), argv, string >> 24);
+ return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8));
}
char *GetString(char *buffr, StringID string)
diff --git a/town_cmd.c b/town_cmd.c
index e49cf4eb5..6de979765 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -97,7 +97,7 @@ static void DrawTile_Town(TileInfo *ti)
{
/* this "randomizes" on the (up to) 4 variants of a building */
byte gfx = _m[ti->tile].m4;
- byte stage = _m[ti->tile].m3 >> 6;
+ byte stage = GB(_m[ti->tile].m3, 6, 2);
uint variant;
variant = ti->x >> 4;
variant ^= ti->x >> 6;
@@ -635,7 +635,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
// Possibly extend the road in a direction.
// Randomize a direction and if it has a road, bail out.
- i = (int)Random() & 3;
+ i = GB(Random(), 0, 2);
if (HASBIT(mask, i))
return;
diff --git a/train_cmd.c b/train_cmd.c
index aed2c8ea8..3f2667ac2 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1623,10 +1623,10 @@ int32 CmdForceTrainProceed(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/
int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
+ CargoID new_cid = GB(p2, 0, 8);
Vehicle *v;
int32 cost;
uint num;
- CargoID new_cid = p2 & 0xFF; //gets the cargo number
if (!IsVehicleIndex(p1)) return CMD_ERROR;
@@ -3173,7 +3173,7 @@ static void ChangeTrainDirRandomly(Vehicle *v)
do {
//I need to buffer the train direction
if (!(v->u.rail.track & 0x40))
- v->direction = (v->direction + _random_dir_change[Random()&3]) & 7;
+ v->direction = (v->direction + _random_dir_change[GB(Random(), 0, 2)]) & 7;
if (!(v->vehstatus & VS_HIDDEN)) {
BeginVehicleMove(v);
UpdateTrainDeltaXY(v, v->direction);
diff --git a/tree_cmd.c b/tree_cmd.c
index 0505ef957..80ee3122e 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -214,7 +214,7 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
treetype = p1;
if (treetype == -1) {
- treetype = GetRandomTreeType(tile, Random() >> 24);
+ treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
if (treetype == -1) treetype = 27;
}
@@ -488,7 +488,7 @@ static void TileLoop_Trees(TileIndex tile)
if (_opt.landscape == LT_DESERT && _m[tile].m3 != 0x1B && GetMapExtraBits(tile) == 1) {
m5++; /* start destructing */
} else {
- switch(Random() & 0x7) {
+ switch (GB(Random(), 0, 3)) {
case 0: /* start destructing */
m5++;
break;
@@ -567,7 +567,7 @@ void OnTick_Trees(void)
(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
IsTileType(tile, MP_CLEAR) &&
(m = _m[tile].m5 & 0x1C, m <= 4) &&
- (tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
+ (tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
ModifyTile(tile,
MP_SETTYPE(MP_TREES) |
@@ -587,7 +587,7 @@ void OnTick_Trees(void)
tile = TILE_MASK(r);
if (IsTileType(tile, MP_CLEAR) &&
(m = _m[tile].m5 & 0x1C, m == 0 || m == 4 || m == 0x10) &&
- (tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
+ (tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
int m2;
if (m == 0) {
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index d5b1fea4d..6ad1f79f7 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -813,7 +813,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0};
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5&1)];
} else {
- if (!(m5 & 0x18)) goto clear_it;
+ if (GB(m5, 3, 2) == 0) goto clear_it;
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001;
}
@@ -1398,14 +1398,14 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode
if ((m5 & 0xF0) == 0) {
/* This is a tunnel */
- if (((m5 & 0xCU) >> 2) == mode) {
+ if (GB(m5, 2, 2) == mode) {
/* Tranport in the tunnel is compatible */
return m5&1 ? 0x202 : 0x101;
}
} else if (m5 & 0x80) {
/* This is a bridge */
result = 0;
- if (((m5 & 0x6U) >> 1) == mode) {
+ if (GB(m5, 1, 2) == mode) {
/* Transport over the bridge is compatible */
result = m5&1 ? 0x202 : 0x101;
}
@@ -1421,7 +1421,7 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode
return result;
} else {
/* Transport underneath */
- if ((m5 & 0x18U) >> 3 != mode)
+ if (GB(m5, 3, 2) != mode)
/* Incompatible transport underneath */
return result;
}
diff --git a/vehicle.c b/vehicle.c
index 542d2b99d..b179262a9 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1232,7 +1232,7 @@ static void BubbleTick(Vehicle *v)
return;
}
if (v->u.special.unk2 != 0) {
- v->spritenum = (InteractiveRandom() & 3) + 1;
+ v->spritenum = GB(InteractiveRandom(), 0, 2) + 1;
} else {
v->spritenum = 6;
}