(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read

This commit is contained in:
tron 2005-07-20 15:29:28 +00:00
parent f432314fa9
commit ac66e3e28f
23 changed files with 130 additions and 128 deletions

View File

@ -1534,15 +1534,16 @@ static void AiStateWantNewRoute(Player *p)
static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
{ {
uint values[NUM_CARGO]; uint values[NUM_CARGO];
int w,h;
int rad; int rad;
for(;p->mode != 4;p++) if (p->mode == 1) { for(;p->mode != 4;p++) if (p->mode == 1) {
TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
uint w;
uint h;
w = ((p->attr>>1) & 7); w = GB(p->attr, 1, 3);
h = ((p->attr>>4) & 7); h = GB(p->attr, 4, 3);
if (p->attr&1) intswap(w, h); if (p->attr & 1) uintswap(w, h);
if (_patches.modified_catchment) { if (_patches.modified_catchment) {

View File

@ -1045,13 +1045,13 @@ static void HandleCrashedAircraft(Vehicle *v)
if (v->u.air.crashed_counter < 650) { if (v->u.air.crashed_counter < 650) {
if (CHANCE16R(1,32,r)) { if (CHANCE16R(1,32,r)) {
v->direction = (v->direction+_crashed_aircraft_moddir[(r >> 16)&3]) & 7; v->direction = (v->direction + _crashed_aircraft_moddir[GB(r, 16, 2)]) & 7;
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
r = Random(); r = Random();
CreateEffectVehicleRel(v, CreateEffectVehicleRel(v,
4 + (r&0xF), GB(r, 0, 4) + 4,
4 + ((r>>4)&0xF), GB(r, 4, 4) + 4,
((r>>8)&0xF), GB(r, 8, 4),
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
} }
} else if (v->u.air.crashed_counter >= 10000) { } else if (v->u.air.crashed_counter >= 10000) {

View File

@ -470,7 +470,7 @@ void DrawHillyLandTile(TileInfo *ti)
if (ti->tileh != 0) { if (ti->tileh != 0) {
DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]); DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]);
} else { } else {
DrawGroundSprite(_landscape_clear_sprites[((ti->x^ti->y) >> 4) & 0x7]); DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]);
} }
} }
@ -485,11 +485,11 @@ void DrawClearLandFence(TileInfo *ti, byte img)
} }
if (img & 0x38) { if (img & 0x38) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[((img >> 3) & 7) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z); DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 3, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
} }
if (img & 0x7) { if (img & 0x7) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[(img & 7) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z); DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(img, 0, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
} }
} }
@ -785,7 +785,7 @@ void GenerateClearTile(void)
r = Random(); r = Random();
tile = RandomTileSeed(r); tile = RandomTileSeed(r);
if (IsTileType(tile, MP_CLEAR)) { if (IsTileType(tile, MP_CLEAR)) {
j = ((r >> 16) & 0xF) + 5; j = GB(r, 16, 4) + 5;
for(;;) { for(;;) {
TileIndex tile_new; TileIndex tile_new;

View File

@ -226,9 +226,9 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
uint32 r = Random(); uint32 r = Random();
CreateEffectVehicleRel(v, CreateEffectVehicleRel(v,
-7 + (r&0xF), GB(r, 0, 4) - 7,
-7 + (r>>4&0xF), GB(r, 4, 4) - 7,
5 + (r>>8&0x7), GB(r, 8, 3) + 5,
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
} }
} else if (v->age == 350) { } else if (v->age == 350) {
@ -364,9 +364,9 @@ static void DisasterTick_2(Vehicle *v)
uint32 r = Random(); uint32 r = Random();
CreateEffectVehicleAbove( CreateEffectVehicleAbove(
x + (r & 0x3F), GB(r, 0, 6) + x,
y + (r >> 6 & 0x3F), GB(r, 6, 6) + y,
(r >> 12 & 0xF), GB(r, 12, 4),
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
if (++v->age >= 55) if (++v->age >= 55)
@ -435,9 +435,9 @@ static void DisasterTick_3(Vehicle *v)
uint32 r = Random(); uint32 r = Random();
CreateEffectVehicleAbove( CreateEffectVehicleAbove(
x + (r & 0x3F), GB(r, 0, 6) + x,
y + (r >> 6 & 0x3F), GB(r, 6, 6) + y,
(r >> 12 & 0xF), GB(r, 12, 4),
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
if (++v->age >= 55) if (++v->age >= 55)
@ -620,8 +620,8 @@ static void DisasterTick_4b(Vehicle *v)
for(i=0; i!=80; i++) { for(i=0; i!=80; i++) {
uint32 r = Random(); uint32 r = Random();
CreateEffectVehicleAbove( CreateEffectVehicleAbove(
v->x_pos-32+(r&0x3F), GB(r, 0, 6) + v->x_pos - 32,
v->y_pos-32+(r>>5&0x3F), GB(r, 5, 6) + v->y_pos - 32,
0, 0,
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
} }

View File

@ -196,22 +196,22 @@ void StartupEngines(void)
e->player_avail = 0; e->player_avail = 0;
r = Random(); r = Random();
e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro); e->intro_date = GB(r, 0, 9) + ei->base_intro;
if (e->intro_date <= _date) { if (e->intro_date <= _date) {
e->age = (_date - e->intro_date) >> 5; e->age = (_date - e->intro_date) >> 5;
e->player_avail = (byte)-1; e->player_avail = (byte)-1;
e->flags |= ENGINE_AVAILABLE; e->flags |= ENGINE_AVAILABLE;
} }
e->reliability_start = (uint16)(((r >> 16) & 0x3fff) + 0x7AE0); e->reliability_start = GB(r, 16, 14) + 0x7AE0;
r = Random(); r = Random();
e->reliability_max = (uint16)((r & 0x3fff) + 0xbfff); e->reliability_max = GB(r, 0, 14) + 0xBFFF;
e->reliability_final = (uint16)(((r>>16) & 0x3fff) + 0x3fff); e->reliability_final = GB(r, 16, 14) + 0x3FFF;
r = Random(); r = Random();
e->duration_phase_1 = (uint16)((r & 0x1F) + 7); e->duration_phase_1 = GB(r, 0, 5) + 7;
e->duration_phase_2 = (uint16)(((r >> 5) & 0xF) + ei->base_life * 12 - 96); e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
e->duration_phase_3 = (uint16)(((r >> 9) & 0x7F) + 120); e->duration_phase_3 = GB(r, 9, 7) + 120;
e->reliability_spd_dec = (ei->unk2&0x7F) << 2; e->reliability_spd_dec = (ei->unk2&0x7F) << 2;

View File

@ -315,7 +315,7 @@ static void DrawCoalPlantSparkles(TileInfo *ti)
{ {
int image = _m[ti->tile].owner; int image = _m[ti->tile].owner;
if (image & 0x80) { if (image & 0x80) {
image = (image >> 2) & 0x1F; image = GB(image, 2, 5);
if (image != 0 && image < 7) { if (image != 0 && image < 7) {
AddChildSpriteScreen(image + 0x806, AddChildSpriteScreen(image + 0x806,
_coal_plant_sparkles_x[image-1], _coal_plant_sparkles_x[image-1],
@ -1802,7 +1802,7 @@ static void MaybeNewIndustry(uint32 r)
int j; int j;
Industry *i; Industry *i;
type = _new_industry_rand[_opt.landscape][(r >> 16) & 0x1F]; type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)];
if (type == IT_OIL_WELL && _date > 10958) if (type == IT_OIL_WELL && _date > 10958)
return; return;

View File

@ -352,7 +352,7 @@ void CDECL ModifyTile(TileIndex tile, uint flags, ...)
va_start(va, flags); va_start(va, flags);
if ((i = (flags >> 8) & 0xF) != 0) { if ((i = GB(flags, 8, 4)) != 0) {
SetTileType(tile, i - 1); SetTileType(tile, i - 1);
} }
@ -485,7 +485,7 @@ static void GenerateTerrain(int type, int flag)
if (x < 2 || y < 2) if (x < 2 || y < 2)
return; return;
direction = (r >> 22) & 3; direction = GB(r, 22, 2);
if (direction & 1) { if (direction & 1) {
w = template->height; w = template->height;
h = template->width; h = template->width;
@ -632,16 +632,16 @@ void GenerateLandscape(void)
GenerateTerrain(2, 0); GenerateTerrain(2, 0);
r = Random(); r = Random();
flag = (r & 3) | 4; flag = GB(r, 0, 2) | 4;
for (i = ScaleByMapSize(((r >> 16) & 0x7F) + 450); i != 0; --i) for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i)
GenerateTerrain(4, flag); GenerateTerrain(4, flag);
} else if (_opt.landscape == LT_DESERT) { } else if (_opt.landscape == LT_DESERT) {
for (i = ScaleByMapSize((Random()&0x7F) + 170); i != 0; --i) for (i = ScaleByMapSize((Random()&0x7F) + 170); i != 0; --i)
GenerateTerrain(0, 0); GenerateTerrain(0, 0);
r = Random(); r = Random();
flag = (r & 3) | 4; flag = GB(r, 0, 2) | 4;
for (i = ScaleByMapSize(((r >> 16) & 0xFF) + 1700); i != 0; --i) for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i)
GenerateTerrain(0, flag); GenerateTerrain(0, flag);
flag ^= 2; flag ^= 2;

View File

@ -132,8 +132,8 @@ static void SelectSongToPlay(void)
i = 500; i = 500;
do { do {
uint32 r = InteractiveRandom(); uint32 r = InteractiveRandom();
byte *a = &_cur_playlist[r & 0x1F]; byte *a = &_cur_playlist[GB(r, 0, 5)];
byte *b = &_cur_playlist[(r >> 8)&0x1F]; byte *b = &_cur_playlist[GB(r, 8, 5)];
if (*a != 0 && *b != 0) { if (*a != 0 && *b != 0) {
byte t = *a; byte t = *a;

View File

@ -44,30 +44,30 @@ void NetworkSend_uint8(Packet *packet, uint8 data)
void NetworkSend_uint16(Packet *packet, uint16 data) void NetworkSend_uint16(Packet *packet, uint16 data)
{ {
assert(packet->size < sizeof(packet->buffer) - sizeof(data)); assert(packet->size < sizeof(packet->buffer) - sizeof(data));
packet->buffer[packet->size++] = data & 0xFF; packet->buffer[packet->size++] = GB(data, 0, 8);
packet->buffer[packet->size++] = (data >> 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 8, 8);
} }
void NetworkSend_uint32(Packet *packet, uint32 data) void NetworkSend_uint32(Packet *packet, uint32 data)
{ {
assert(packet->size < sizeof(packet->buffer) - sizeof(data)); assert(packet->size < sizeof(packet->buffer) - sizeof(data));
packet->buffer[packet->size++] = data & 0xFF; packet->buffer[packet->size++] = GB(data, 0, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 8, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 16, 8);
packet->buffer[packet->size++] = (data >> 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 24, 8);
} }
void NetworkSend_uint64(Packet *packet, uint64 data) void NetworkSend_uint64(Packet *packet, uint64 data)
{ {
assert(packet->size < sizeof(packet->buffer) - sizeof(data)); assert(packet->size < sizeof(packet->buffer) - sizeof(data));
packet->buffer[packet->size++] = data & 0xFF; packet->buffer[packet->size++] = GB(data, 0, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 8, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 16, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 24, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 32, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 40, 8);
packet->buffer[packet->size++] = (data >>= 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 48, 8);
packet->buffer[packet->size++] = (data >> 8) & 0xFF; packet->buffer[packet->size++] = GB(data, 56, 8);
} }
// Sends a string over the network. It sends out // Sends a string over the network. It sends out

View File

@ -722,8 +722,8 @@ static bool LoadOldStation(LoadgameState *ls, int num)
if (st->xy != 0) { if (st->xy != 0) {
if (st->train_tile) { if (st->train_tile) {
/* Calculate the trainst_w and trainst_h */ /* Calculate the trainst_w and trainst_h */
int w = (_old_platforms >> 3) & 0x7; uint w = GB(_old_platforms, 3, 3);
int h = (_old_platforms & 0x7); uint h = GB(_old_platforms, 0, 3);
st->trainst_w = w; st->trainst_w = w;
st->trainst_h = h; st->trainst_h = h;
} }

View File

@ -135,9 +135,9 @@ static inline uint32 PackOrder(const Order *order)
static inline Order UnpackOrder(uint32 packed) static inline Order UnpackOrder(uint32 packed)
{ {
Order order; Order order;
order.type = (packed & 0x000000FF); order.type = GB(packed, 0, 8);
order.flags = (packed & 0x0000FF00) >> 8; order.flags = GB(packed, 8, 8);
order.station = (packed & 0xFFFF0000) >> 16; order.station = GB(packed, 16, 16);
order.next = NULL; order.next = NULL;
order.index = 0; // avoid compiler warning order.index = 0; // avoid compiler warning
return order; return order;

View File

@ -40,9 +40,9 @@ MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZ
Order UnpackOldOrder(uint16 packed) Order UnpackOldOrder(uint16 packed)
{ {
Order order; Order order;
order.type = (packed & 0x000F); order.type = GB(packed, 0, 4);
order.flags = (packed & 0x00F0) >> 4; order.flags = GB(packed, 4, 4);
order.station = (packed & 0xFF00) >> 8; order.station = GB(packed, 8, 8);
order.next = NULL; order.next = NULL;
// Sanity check // Sanity check
@ -63,9 +63,9 @@ Order UnpackOldOrder(uint16 packed)
Order UnpackVersion4Order(uint16 packed) Order UnpackVersion4Order(uint16 packed)
{ {
Order order; Order order;
order.type = (packed & 0x000F); order.type = GB(packed, 0, 4);
order.flags = (packed & 0x00F0) >> 4; order.flags = GB(packed, 4, 4);
order.station = (packed & 0xFF00) >> 8; order.station = GB(packed, 8, 8);
order.next = NULL; order.next = NULL;
order.index = 0; // avoid compiler warning order.index = 0; // avoid compiler warning
return order; return order;
@ -144,17 +144,17 @@ void AssignOrder(Order *order, Order data)
/** Add an order to the orderlist of a vehicle. /** Add an order to the orderlist of a vehicle.
* @param x,y unused * @param x,y unused
* @param p1 various bitstuffed elements * @param p1 various bitstuffed elements
* - p1 = (bit 0 - 15) - ID of the vehicle (p1 & 0xFFFF) * - p1 = (bit 0 - 15) - ID of the vehicle
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
* the order will be inserted before that one (p1 & 0xFFFF0000)>>16 * the order will be inserted before that one
* only the first 8 bytes used currently (bit 16 - 23) (max 255) * only the first 8 bits used currently (bit 16 - 23) (max 255)
* @param p2 packed order to insert * @param p2 packed order to insert
*/ */
int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
VehicleID veh = p1 & 0xFFFF; VehicleID veh = GB(p1, 0, 16);
OrderID sel_ord = p1 >> 16; OrderID sel_ord = GB(p1, 16, 16);
Order new_order = UnpackOrder(p2); Order new_order = UnpackOrder(p2);
if (!IsVehicleIndex(veh)) return CMD_ERROR; if (!IsVehicleIndex(veh)) return CMD_ERROR;
@ -509,18 +509,18 @@ int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/** Modify an order in the orderlist of a vehicle. /** Modify an order in the orderlist of a vehicle.
* @param x,y unused * @param x,y unused
* @param p1 various bitstuffed elements * @param p1 various bitstuffed elements
* - p1 = (bit 0 - 15) - ID of the vehicle (p1 & 0xFFFF) * - p1 = (bit 0 - 15) - ID of the vehicle
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
* the order will be inserted before that one (p1 & 0xFFFF0000)>>16 * the order will be inserted before that one
* only the first 8 bytes used currently (bit 16 - 23) (max 255) * only the first 8 bits used currently (bit 16 - 23) (max 255)
* @param p2 mode to change the order to (always set) * @param p2 mode to change the order to (always set)
*/ */
int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *v; Vehicle *v;
Order *order; Order *order;
OrderID sel_ord = p1 >> 16; // XXX - automatically truncated to 8 bits. OrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
VehicleID veh = p1 & 0xFFFF; VehicleID veh = GB(p1, 0, 16);
if (!IsVehicleIndex(veh)) return CMD_ERROR; if (!IsVehicleIndex(veh)) return CMD_ERROR;
if (p2 != OFB_FULL_LOAD && p2 != OFB_UNLOAD && p2 != OFB_NON_STOP && p2 != OFB_TRANSFER) return CMD_ERROR; if (p2 != OFB_FULL_LOAD && p2 != OFB_UNLOAD && p2 != OFB_NON_STOP && p2 != OFB_TRANSFER) return CMD_ERROR;
@ -583,8 +583,8 @@ int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Vehicle *dst; Vehicle *dst;
VehicleID veh_src = (p1 >> 16) & 0xFFFF; VehicleID veh_src = GB(p1, 16, 16);
VehicleID veh_dst = p1 & 0xFFFF; VehicleID veh_dst = GB(p1, 0, 16);
if (!IsVehicleIndex(veh_dst)) return CMD_ERROR; if (!IsVehicleIndex(veh_dst)) return CMD_ERROR;

View File

@ -45,7 +45,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
/* draw the chin */ /* draw the chin */
/* FIXME: real code uses -2 in zoomlevel 1 */ /* FIXME: real code uses -2 in zoomlevel 1 */
{ {
uint val = (face >> 4) & 3; uint val = GB(face, 4, 2);
if (!(flag & 2)) { if (!(flag & 2)) {
DrawSprite(0x327 + (flag&1?0:val), x, y); DrawSprite(0x327 + (flag&1?0:val), x, y);
} else { } else {
@ -54,8 +54,8 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
} }
/* draw the eyes */ /* draw the eyes */
{ {
uint val1 = (face >> 6)&15; uint val1 = GB(face, 6, 4);
uint val2 = (face >> 20)&7; uint val2 = GB(face, 20, 3);
uint32 high = 0x314<<16; uint32 high = 0x314<<16;
if (val2 >= 6) { if (val2 >= 6) {
@ -81,7 +81,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
/* draw the mouth */ /* draw the mouth */
{ {
uint val = (face >> 10) & 63; uint val = GB(face, 10, 6);
uint val2; uint val2;
if (!(flag&1)) { if (!(flag&1)) {
@ -127,7 +127,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
/* draw the hair */ /* draw the hair */
{ {
uint val = (face >> 16) & 15; uint val = GB(face, 16, 4);
if (!(flag&2)) { if (!(flag&2)) {
if (!(flag&1)) { if (!(flag&1)) {
DrawSprite(0x382 + (val*9>>4), x, y); DrawSprite(0x382 + (val*9>>4), x, y);
@ -145,7 +145,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
/* draw the tie */ /* draw the tie */
{ {
uint val = (face >> 20) & 0xFF; uint val = GB(face, 20, 8);
if (!(flag&1)) { if (!(flag&1)) {
DrawSprite(0x36B + ((val&3)*3>>2), x, y); DrawSprite(0x36B + ((val&3)*3>>2), x, y);
@ -164,7 +164,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
/* draw the glasses */ /* draw the glasses */
{ {
uint val = (face >> 28) & 7; uint val = GB(face, 28, 3);
if (!(flag&2)) { if (!(flag&2)) {
if (val<=1) { if (val<=1) {
@ -371,7 +371,7 @@ static byte GeneratePlayerColor(void)
n = 100; n = 100;
do { do {
r = Random(); r = Random();
COLOR_SWAP(r & 0xF, (r >> 4) & 0xF); COLOR_SWAP(GB(r, 0, 4), GB(r, 4, 4));
} while (--n); } while (--n);
// Bubble sort it according to the values in table 1 // Bubble sort it according to the values in table 1
@ -754,8 +754,8 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} break; } break;
case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */ case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */
PlayerID pid_old = p2 & 0xFFFF; PlayerID pid_old = GB(p2, 0, 16);
PlayerID pid_new = (p2 >> 16) & 0xFFFF; PlayerID pid_new = GB(p2, 16, 16);
if (pid_old >= MAX_PLAYERS || pid_new >= MAX_PLAYERS) return CMD_ERROR; if (pid_old >= MAX_PLAYERS || pid_new >= MAX_PLAYERS) return CMD_ERROR;

View File

@ -577,7 +577,7 @@ static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2
{ {
int ex, ey; int ex, ey;
int32 ret, total_cost = 0; int32 ret, total_cost = 0;
Track track = (Track)((p2 >> 4) & 7); Track track = (Track)GB(p2, 4, 3);
Trackdir trackdir; Trackdir trackdir;
byte mode = HASBIT(p2, 7); byte mode = HASBIT(p2, 7);
@ -845,7 +845,7 @@ static int32 CmdSignalTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32
bool error = true; bool error = true;
int mode = p2 & 0x1; int mode = p2 & 0x1;
Track track = (p2 >> 4) & 7; Track track = GB(p2, 4, 3);
Trackdir trackdir = TrackToTrackdir(track); Trackdir trackdir = TrackToTrackdir(track);
byte semaphores = (HASBIT(p2, 3)) ? 8 : 0; byte semaphores = (HASBIT(p2, 3)) ? 8 : 0;
byte signal_density = (p2 >> 24); byte signal_density = (p2 >> 24);

View File

@ -789,7 +789,7 @@ static void DrawTile_Road(TileInfo *ti)
image = _road_tile_sprites_1[ti->map5 & 0xF]; image = _road_tile_sprites_1[ti->map5 & 0xF];
} }
m2 = (_m[ti->tile].m4 & 0x70) >> 4; m2 = GB(_m[ti->tile].m4, 4, 3);
if (m2 == 0) image |= 0x3178000; if (m2 == 0) image |= 0x3178000;
@ -835,7 +835,7 @@ static void DrawTile_Road(TileInfo *ti)
if ( _m[ti->tile].m4 & 0x80) { if ( _m[ti->tile].m4 & 0x80) {
image += 8; image += 8;
} else { } else {
m2 = (_m[ti->tile].m4 & 0x70) >> 4; m2 = GB(_m[ti->tile].m4, 4, 3);
if (m2 == 0) image |= 0x3178000; if (m2 == 0) image |= 0x3178000;
if (m2 > 1) image += 4; if (m2 > 1) image += 4;
} }
@ -1006,7 +1006,7 @@ static void TileLoop_Road(TileIndex tile)
if (_m[tile].m5 & 0xE0) if (_m[tile].m5 & 0xE0)
return; return;
if (((_m[tile].m4 & 0x70) >> 4) < 6) { if (GB(_m[tile].m4, 4, 3) < 6) {
t = ClosestTownFromTile(tile, (uint)-1); t = ClosestTownFromTile(tile, (uint)-1);
grp = 0; grp = 0;
@ -1018,7 +1018,7 @@ static void TileLoop_Road(TileIndex tile)
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) && !(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) &&
(_m[tile].m5==5 || _m[tile].m5==10)) { (_m[tile].m5==5 || _m[tile].m5==10)) {
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) { if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) {
_m[tile].m4 |= ((((_m[tile].m4 & 0x70) >> 4 ) <= 2) ? 7 : 6) << 4; _m[tile].m4 |= (GB(_m[tile].m4, 4, 3) <= 2 ? 7 : 6) << 4;
SndPlayTileFx(SND_21_JACKHAMMER, tile); SndPlayTileFx(SND_21_JACKHAMMER, tile);
CreateEffectVehicleAbove( CreateEffectVehicleAbove(
@ -1034,7 +1034,7 @@ static void TileLoop_Road(TileIndex tile)
{ {
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
byte b = (_m[tile].m4 & 0x70) >> 4; byte b = GB(_m[tile].m4, 4, 3);
if (b == p[0]) if (b == p[0])
return; return;
@ -1062,7 +1062,7 @@ static void TileLoop_Road(TileIndex tile)
return; return;
} }
//roadworks finished //roadworks finished
_m[tile].m4 = ((((b& 0x70) >> 4)== 6) ? 1 : 2) << 4; _m[tile].m4 = (GB(b, 4, 3) == 6 ? 1 : 2) << 4;
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} }
@ -1090,7 +1090,7 @@ static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode)
byte b = _m[tile].m5; byte b = _m[tile].m5;
if ((b & 0xF0) == 0) { if ((b & 0xF0) == 0) {
/* Ordinary road */ /* Ordinary road */
if (!_road_special_gettrackstatus && ((_m[tile].m4&0x70) >> 4) >= 6) if (!_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6)
return 0; return 0;
return _road_trackbits[b&0xF] * 0x101; return _road_trackbits[b&0xF] * 0x101;
} else if (IsLevelCrossing(tile)) { } else if (IsLevelCrossing(tile)) {
@ -1125,7 +1125,7 @@ static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
{ {
int i = (_m[tile].m5 >> 4); int i = (_m[tile].m5 >> 4);
if (i == 0) if (i == 0)
i = ((_m[tile].m4 & 0x70) >> 4) + 3; i = GB(_m[tile].m4, 4, 3) + 3;
td->str = _road_tile_strings[i - 1]; td->str = _road_tile_strings[i - 1];
td->owner = GetTileOwner(tile); td->owner = GetTileOwner(tile);
} }

View File

@ -1019,16 +1019,16 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
/** Network-safe changing of patch-settings. /** Network-safe changing of patch-settings.
* @param p1 various bitstuffed elements * @param p1 various bitstuffed elements
* - p1 = (bit 0- 7) - the patches type (page) that is being changed (construction, network, ai) (p1 & 0xFF) * - p1 = (bit 0- 7) - the patches type (page) that is being changed (construction, network, ai)
* - p2 = (bit 8-15) - the actual patch (entry) being set inside the category ((p1>>8) & 0xFF) * - p2 = (bit 8-15) - the actual patch (entry) being set inside the category
* @param p2 the new value for the patch * @param p2 the new value for the patch
* @todo check that the new value is a valid one. Awful lot of work, but since only * @todo check that the new value is a valid one. Awful lot of work, but since only
* the server is allowed to do this, we trust it on this one :) * the server is allowed to do this, we trust it on this one :)
*/ */
int32 CmdChangePatchSetting(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangePatchSetting(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
byte pcat = p1 & 0xFF; byte pcat = GB(p1, 0, 8);
byte pel = (p1 >> 8) & 0xFF; byte pel = GB(p1, 8, 8);
if (pcat >= lengthof(_patches_page)) return CMD_ERROR; if (pcat >= lengthof(_patches_page)) return CMD_ERROR;
if (pel >= _patches_page[pcat].num) return CMD_ERROR; if (pel >= _patches_page[pcat].num) return CMD_ERROR;

View File

@ -933,8 +933,8 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, StationS
* @param x,y starting position of station dragging/placement * @param x,y starting position of station dragging/placement
* @param p1 various bitstuffed elements * @param p1 various bitstuffed elements
* - p1 = (bit 0) - orientation (p1 & 1) * - p1 = (bit 0) - orientation (p1 & 1)
* - p1 = (bit 8-15) - number of tracks (p1 >> 8) & 0xFF) * - p1 = (bit 8-15) - number of tracks
* - p1 = (bit 16-23) - platform length (p1 >> 16) & 0xFF) * - p1 = (bit 16-23) - platform length
* @param p2 various bitstuffed elements * @param p2 various bitstuffed elements
* - p2 = (bit 0- 3) - railtype (p2 & 0xF) * - p2 = (bit 0- 3) - railtype (p2 & 0xF)
* - p2 = (bit 4) - set for custom station (p2 & 0x10) * - p2 = (bit 4) - set for custom station (p2 & 0x10)
@ -961,8 +961,8 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* unpack parameters */ /* unpack parameters */
direction = p1 & 1; direction = p1 & 1;
numtracks = (p1 >> 8) & 0xFF; numtracks = GB(p1, 8, 8);
plat_len = (p1 >> 16) & 0xFF; plat_len = GB(p1, 16, 8);
/* w = length, h = num_tracks */ /* w = length, h = num_tracks */
if (direction) { if (direction) {
h_org = plat_len; h_org = plat_len;

View File

@ -179,8 +179,8 @@ static const char *GetStringPtr(StringID string)
// should set those bits. // should set those bits.
char *GetStringWithArgs(char *buffr, uint string, const int32 *argv) char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
{ {
uint index = string & 0x7FF; uint index = GB(string, 0, 11);
uint tab = (string >> 11) & 0x1F; uint tab = GB(string, 11, 5);
if (!(string & 0xFFFF)) { if (!(string & 0xFFFF)) {
error("!invalid string id 0 in GetString"); error("!invalid string id 0 in GetString");

View File

@ -769,9 +769,10 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
static int GenRandomRoadBits(void) static int GenRandomRoadBits(void)
{ {
uint32 r = Random(); uint32 r = Random();
int a = r&3, b = (r >> 8) & 3; uint a = GB(r, 0, 2);
uint b = GB(r, 8, 2);
if (a == b) b ^= 2; if (a == b) b ^= 2;
return (1<<a)+(1<<b); return (1 << a) + (1 << b);
} }
// Grow the town // Grow the town
@ -1307,7 +1308,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
ChangePopulation(t, _housetype_population[house]); ChangePopulation(t, _housetype_population[house]);
// Initial value for map5. // Initial value for map5.
m5 = (r >> 16) & 0x3F; m5 = GB(r, 16, 6);
} }
assert(IsTileType(tile, MP_CLEAR)); assert(IsTileType(tile, MP_CLEAR));

View File

@ -3013,9 +3013,9 @@ static void HandleCrashedTrain(Vehicle *v)
r = Random(); r = Random();
CreateEffectVehicleRel(u, CreateEffectVehicleRel(u,
2 + ((r>>8)&7), GB(r, 8, 3) + 2,
2 + ((r>>16)&7), GB(r, 16, 3) + 2,
5 + (r&7), GB(r, 0, 3) + 5,
EV_EXPLOSION_SMALL); EV_EXPLOSION_SMALL);
break; break;
} }

View File

@ -184,8 +184,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
/* unpack parameters */ /* unpack parameters */
bridge_type = p2 & 0xFF; bridge_type = GB(p2, 0, 8);
railtype = (byte)(p2 >> 8); railtype = GB(p2, 8, 8);
if (p1 > MapSize()) return CMD_ERROR; if (p1 > MapSize()) return CMD_ERROR;
@ -1023,8 +1023,8 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (ice) if (ice)
image += 32; image += 32;
image += _draw_tunnel_table_1[(ti->map5 >> 2) & 0x3]; image += _draw_tunnel_table_1[GB(ti->map5, 2, 2)];
image += (ti->map5 & 3) << 1; image += GB(ti->map5, 0, 2) * 2;
DrawGroundSprite(image); DrawGroundSprite(image);
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z);
@ -1055,7 +1055,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
} }
// bridge ending. // bridge ending.
b = _bridge_sprite_table[(_m[ti->tile].m2 >> 4) & 0xF][6]; b = _bridge_sprite_table[GB(_m[ti->tile].m2, 4, 4)][6];
b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */ b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */
b += (tmp&1); // direction b += (tmp&1); // direction
if (ti->tileh == 0) b += 4; // sloped "entrance" ? if (ti->tileh == 0) b += 4; // sloped "entrance" ?
@ -1077,7 +1077,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
uint z; uint z;
int x,y; int x,y;
image = (ti->map5 >> 3) & 3; // type of stuff under bridge (only defined for 0,1) image = GB(ti->map5, 3, 2); // type of stuff under bridge (only defined for 0,1)
assert(image <= 1); assert(image <= 1);
if (!(ti->map5 & 0x20)) { if (!(ti->map5 & 0x20)) {
@ -1115,7 +1115,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
DrawGroundSprite(image); DrawGroundSprite(image);
} }
// get bridge sprites // get bridge sprites
b = _bridge_sprite_table[(_m[ti->tile].m2 >> 4) & 0xF][_m[ti->tile].m2&0xF] + tmp * 4; b = _bridge_sprite_table[GB(_m[ti->tile].m2, 4, 4)][GB(_m[ti->tile].m2, 0, 4)] + tmp * 4;
z = GetBridgeHeight(ti) + 5; z = GetBridgeHeight(ti) + 5;
@ -1285,9 +1285,9 @@ static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] =
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
{ {
if ((_m[tile].m5 & 0x80) == 0) { if ((_m[tile].m5 & 0x80) == 0) {
td->str = STR_5017_RAILROAD_TUNNEL + ((_m[tile].m5 >> 2) & 3); td->str = STR_5017_RAILROAD_TUNNEL + GB(_m[tile].m5, 2, 2);
} else { } else {
td->str = _bridge_tile_str[ (_m[tile].m2 >> 4) + (((_m[tile].m5>>1)&3)<<4) ]; td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)];
/* scan to the end of the bridge, that's where the owner is stored */ /* scan to the end of the bridge, that's where the owner is stored */
if (_m[tile].m5 & 0x40) { if (_m[tile].m5 & 0x40) {

View File

@ -612,8 +612,8 @@ void ViewportAddVehicles(DrawPixelInfo *dpi)
static void ChimneySmokeInit(Vehicle *v) static void ChimneySmokeInit(Vehicle *v)
{ {
uint32 r = Random(); uint32 r = Random();
v->cur_image = SPR_CHIMNEY_SMOKE_0 + (r & 7); v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3);
v->progress = (r >> 16) & 7; v->progress = GB(r, 16, 3);
} }
static void ChimneySmokeTick(Vehicle *v) static void ChimneySmokeTick(Vehicle *v)
@ -1299,8 +1299,8 @@ void CheckVehicleBreakdown(Vehicle *v)
/* check if to break down */ /* check if to break down */
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) {
v->breakdown_ctr = (byte)(((r >> 16) & 0x3F) + 0x3F); v->breakdown_ctr = GB(r, 16, 6) + 0x3F;
v->breakdown_delay = (byte)(((r >> 24) & 0x7F) | 0x80); v->breakdown_delay = GB(r, 24, 7) + 0x80;
v->breakdown_chance = 0; v->breakdown_chance = 0;
} }
} }

View File

@ -2142,8 +2142,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
#if defined(_MSC_VER) #if defined(_MSC_VER)
{ {
uint64 seed = rdtsc(); uint64 seed = rdtsc();
_random_seeds[0][0] = seed & 0xffffffff; _random_seeds[0][0] = GB(seed, 0, 32);
_random_seeds[0][1] = seed >> 32; _random_seeds[0][1] = GB(seed, 32, 32);
} }
#else #else
_random_seeds[0][0] = GetTickCount(); _random_seeds[0][0] = GetTickCount();