diff options
author | tron <tron@openttd.org> | 2005-07-21 06:31:02 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-07-21 06:31:02 +0000 |
commit | d71788c40206fa35b792d34769fde7768b4456c1 (patch) | |
tree | dc5c9c74cec9bfa29f94932a20193cd902a80f15 | |
parent | 5c5840417e2f03514c51098f4786c6c1d6030b59 (diff) | |
download | openttd-d71788c40206fa35b792d34769fde7768b4456c1.tar.xz |
(svn r2660) Get rid of some more shifting/anding/casting
-rw-r--r-- | clear_cmd.c | 14 | ||||
-rw-r--r-- | economy.c | 2 | ||||
-rw-r--r-- | industry_cmd.c | 6 | ||||
-rw-r--r-- | landscape.c | 4 | ||||
-rw-r--r-- | main_gui.c | 4 | ||||
-rw-r--r-- | misc_cmd.c | 3 | ||||
-rw-r--r-- | news_gui.c | 2 | ||||
-rw-r--r-- | players.c | 5 | ||||
-rw-r--r-- | roadveh_cmd.c | 10 | ||||
-rw-r--r-- | saveload.c | 8 | ||||
-rw-r--r-- | ship_cmd.c | 10 | ||||
-rw-r--r-- | strings.c | 4 | ||||
-rw-r--r-- | town_cmd.c | 23 | ||||
-rw-r--r-- | train_cmd.c | 28 | ||||
-rw-r--r-- | tunnelbridge_cmd.c | 13 | ||||
-rw-r--r-- | unmovable_cmd.c | 13 |
16 files changed, 74 insertions, 75 deletions
diff --git a/clear_cmd.c b/clear_cmd.c index 38f1ccd68..7d0227f64 100644 --- a/clear_cmd.c +++ b/clear_cmd.c @@ -742,7 +742,7 @@ static void TileLoop_Clear(TileIndex tile) } /* did overflow, so continue */ } else { - m5 = ((byte)Random() > 21) ? (2) : (6); + m5 = (GB(Random(), 0, 8) > 21) ? 2 : 6; } m5++; } else if (_game_mode != GM_EDITOR) { @@ -767,29 +767,27 @@ static void TileLoop_Clear(TileIndex tile) void GenerateClearTile(void) { - int i,j; + uint i; TileIndex tile; - uint32 r; /* add hills */ i = ScaleByMapSize((Random() & 0x3FF) + 0x400); do { tile = RandomTile(); - if (IsTileType(tile, MP_CLEAR)) - _m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (1<<2)); + if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1); } while (--i); /* add grey squares */ i = ScaleByMapSize((Random() & 0x7F) + 0x80); do { - r = Random(); + uint32 r = Random(); tile = RandomTileSeed(r); if (IsTileType(tile, MP_CLEAR)) { - j = GB(r, 16, 4) + 5; + uint j = GB(r, 16, 4) + 5; for(;;) { TileIndex tile_new; - _m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (2<<2)); + SB(_m[tile].m5, 2, 2, 2); do { if (--j == 0) goto get_out; tile_new = tile + TileOffsByDir(Random() & 3); @@ -787,7 +787,7 @@ void StartupEconomy(void) _economy.infl_amount = _opt.diff.initial_interest; _economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1); _economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000; - _economy.fluct = (byte)(Random()) + 168; + _economy.fluct = GB(Random(), 0, 8) + 168; } Pair SetupSubsidyDecodeParam(Subsidy *s, bool mode) diff --git a/industry_cmd.c b/industry_cmd.c index b24922025..8c03d6341 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -960,8 +960,8 @@ static void PlantFarmField(TileIndex tile) /* determine field size */ r = (Random() & 0x303) + 0x404; if (_opt.landscape == LT_HILLY) r += 0x404; - size_x = (byte)r; - size_y = r >> 8; + size_x = GB(r, 0, 8); + size_y = GB(r, 8, 8); /* offset tile to match size */ tile -= TileDiffXY(size_x / 2, size_y / 2); @@ -977,7 +977,7 @@ static void PlantFarmField(TileIndex tile) /* determine type of field */ r = Random(); type = ((r & 0xE0) | 0xF); - type2 = ((byte)(r >> 8) * 9) >> 8; + type2 = GB(r, 8, 8) * 9 >> 8; /* make field */ BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) diff --git a/landscape.c b/landscape.c index 2d6b772e8..b1de88086 100644 --- a/landscape.c +++ b/landscape.c @@ -685,8 +685,8 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng) uint32 r = Random(); return TILE_MASK(TileXY( - TileX(a) + ((byte)r * rn * 2 >> 8) - rn, - TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn + TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn, + TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn )); } diff --git a/main_gui.c b/main_gui.c index 244cb2be0..3abb9cc65 100644 --- a/main_gui.c +++ b/main_gui.c @@ -502,7 +502,7 @@ static void MenuWndProc(Window *w, WindowEvent *e) do { if (sel== 0) GfxFillRect(x, y, x + eo, y+9, 0); - DrawString(x + 2, y, (StringID)(string + (chk&1)), (byte)(sel==0?(byte)0xC:(byte)0x10)); + DrawString(x + 2, y, string + (chk & 1), sel == 0 ? 0xC : 0x10); y += 10; string += inc; chk >>= 1; @@ -642,7 +642,7 @@ static void PlayerMenuWndProc(Window *w, WindowEvent *e) SetDParam(1, p->name_2); SetDParam(2, GetPlayerNameString(p->index, 3)); - color = (byte)((p->index==sel) ? 0xC : 0x10); + color = (p->index == sel) ? 0xC : 0x10; if (chk&1) color = 14; DrawString(x + 19, y, STR_7021, color); diff --git a/misc_cmd.c b/misc_cmd.c index 5e5926064..1b087b498 100644 --- a/misc_cmd.c +++ b/misc_cmd.c @@ -32,9 +32,10 @@ int32 CmdSetPlayerFace(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2) { Player *p, *pp; - byte colour = (byte)p2; + byte colour; if (p2 >= 16) return CMD_ERROR; // max 16 colours + colour = p2; p = GetPlayer(_current_player); diff --git a/news_gui.c b/news_gui.c index 08d284304..3886879cf 100644 --- a/news_gui.c +++ b/news_gui.c @@ -579,7 +579,7 @@ static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint /* Copy the just gotten string to another buffer to remove any formatting * from it such as big fonts, etc. */ for (ptr = buffer, dest = buffer2; *ptr != '\0'; ptr++) { - if ((byte)*ptr == '\r') { + if (*ptr == '\r') { dest[0] = dest[1] = dest[2] = dest[3] = ' '; dest += 4; } else if ((byte)*ptr >= ' ' && ((byte)*ptr < 0x88 || (byte)*ptr >= 0x99)) { @@ -180,10 +180,9 @@ void DrawPlayerFace(uint32 face, int color, int x, int y) void InvalidatePlayerWindows(Player *p) { - uint pid = p->index; - if ( (byte)pid == _local_player) - InvalidateWindow(WC_STATUS_BAR, 0); + PlayerID pid = p->index; + if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0); InvalidateWindow(WC_FINANCES, pid); } diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 2fad4cdb6..293d2004e 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -449,10 +449,10 @@ static void UpdateRoadVehDeltaXY(Vehicle *v) }; #undef MKIT uint32 x = _delta_xy_table[v->direction]; - v->x_offs = (byte)x; - v->y_offs = (byte)(x>>=8); - v->sprite_width = (byte)(x>>=8); - v->sprite_height = (byte)(x>>=8); + v->x_offs = GB(x, 0, 8); + v->y_offs = GB(x, 8, 8); + v->sprite_width = GB(x, 16, 8); + v->sprite_height = GB(x, 24, 8); } static void ClearCrashedStation(Vehicle *v) @@ -927,7 +927,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) return; - tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); + tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; if ((tt & 3) == 0) return; if ((tt & 0x3C) != 0) diff --git a/saveload.c b/saveload.c index 3c561f821..bef3ef6f9 100644 --- a/saveload.c +++ b/saveload.c @@ -123,14 +123,14 @@ static inline uint64 SlReadUint64(void) static inline void SlWriteUint16(uint16 v) { - SlWriteByte((byte)(v >> 8)); - SlWriteByte((byte)v); + SlWriteByte(GB(v, 8, 8)); + SlWriteByte(GB(v, 0, 8)); } static inline void SlWriteUint32(uint32 v) { - SlWriteUint16((uint16)(v >> 16)); - SlWriteUint16((uint16)v); + SlWriteUint16(GB(v, 16, 16)); + SlWriteUint16(GB(v, 0, 16)); } static inline void SlWriteUint64(uint64 x) diff --git a/ship_cmd.c b/ship_cmd.c index d7459d0bb..a0c3d7e10 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -312,10 +312,10 @@ static void UpdateShipDeltaXY(Vehicle *v, int dir) }; #undef MKIT uint32 x = _delta_xy_table[dir]; - v->x_offs = (byte)x; - v->y_offs = (byte)(x>>=8); - v->sprite_width = (byte)(x>>=8); - v->sprite_height = (byte)(x>>=8); + v->x_offs = GB(x, 0, 8); + v->y_offs = GB(x, 8, 8); + v->sprite_width = GB(x, 16, 8); + v->sprite_height = GB(x, 24, 8); } static void RecalcShipStuff(Vehicle *v) @@ -532,7 +532,7 @@ static uint FindShipTrack(Vehicle *v, TileIndex tile, int dir, uint bits, TileIn /* if we reach this position, there's two paths of equal value so far. * pick one randomly. */ - r = (byte)Random(); + r = GB(Random(), 0, 8); if (_pick_shiptrack_table[i] == ship_dir) r += 80; if (_pick_shiptrack_table[best_track] == ship_dir) r -= 80; if (r <= 127) goto bad; @@ -893,12 +893,12 @@ static char *GenPresidentName(char *buff, uint32 x) { uint i, base, num; - buff[0] = _initial_name_letters[(sizeof(_initial_name_letters) * (byte)x) >> 8]; + buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; buff[1] = '.'; buff[2] = ' '; // Insert a space after initial and period "I. Firstname" instead of "I.Firstname" buff += 3; - i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8; + i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; if (i < sizeof(_initial_name_letters)) { buff[0] = _initial_name_letters[i]; buff[1] = '.'; diff --git a/town_cmd.c b/town_cmd.c index 77a0a2403..4e92e886d 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -92,7 +92,7 @@ static void DrawTile_Town(TileInfo *ti) /* Retrieve pointer to the draw town tile struct */ { /* this "randomizes" on the (up to) 4 variants of a building */ - byte gfx = (byte)_m[ti->tile].m4; + byte gfx = _m[ti->tile].m4; byte stage = _m[ti->tile].m3 >> 6; uint variant; variant = ti->x >> 4; @@ -304,16 +304,20 @@ static void TileLoop_Town(TileIndex tile) r = Random(); - if ( (byte)r < _housetype_population[house] ) { - uint amt = ((byte)r >> 3) + 1, moved; + if (GB(r, 0, 8) < _housetype_population[house]) { + uint amt = GB(r, 0, 8) / 8 + 1; + uint moved; + if (_economy.fluct <= 0) amt = (amt + 1) >> 1; t->new_max_pass += amt; moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); t->new_act_pass += moved; } - if ( (byte)(r>>8) < _housetype_mailamount[house] ) { - uint amt = ((byte)(r>>8) >> 3) + 1, moved; + if (GB(r, 8, 8) < _housetype_mailamount[house] ) { + uint amt = GB(r, 8, 8) / 8 + 1; + uint moved; + if (_economy.fluct <= 0) amt = (amt + 1) >> 1; t->new_max_mail += amt; moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); @@ -321,17 +325,14 @@ static void TileLoop_Town(TileIndex tile) } if (_house_more_flags[house]&8 && (t->flags12&1) && --t->time_until_rebuild == 0) { - r>>=16; - t->time_until_rebuild = (r & 63) + 130; + t->time_until_rebuild = GB(r, 16, 6) + 130; _current_player = OWNER_TOWN; ClearTownHouse(t, tile); // rebuild with another house? - if ( (byte) (r >> 8) >= 12) { - DoBuildTownHouse(t, tile); - } + if (GB(r, 24, 8) >= 12) DoBuildTownHouse(t, tile); _current_player = OWNER_NONE; } @@ -1303,7 +1304,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile) // Value for map3lo m3lo = 0xC0; - if ((byte)r >= 220) m3lo &= (r>>8); + if (GB(r, 0, 8) >= 220) m3lo &= (r>>8); if (m3lo == 0xC0) ChangePopulation(t, _housetype_population[house]); diff --git a/train_cmd.c b/train_cmd.c index 35a3c8250..7b38ba072 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -398,7 +398,6 @@ static int32 CmdBuildRailWagon(uint engine, TileIndex tile, uint32 flags) int32 value; Vehicle *v; const RailVehicleInfo *rvi; - int dir; const Engine *e; int x,y; @@ -417,6 +416,7 @@ static int32 CmdBuildRailWagon(uint engine, TileIndex tile, uint32 flags) if (flags & DC_EXEC) { byte img = rvi->image_index; Vehicle *u, *w; + uint dir; v->spritenum = img; @@ -432,9 +432,9 @@ static int32 CmdBuildRailWagon(uint engine, TileIndex tile, uint32 flags) v->engine_type = engine; - dir = _m[tile].m5 & 3; + dir = GB(_m[tile].m5, 0, 2); - v->direction = (byte)(dir*2+1); + v->direction = dir * 2 + 1; v->tile = tile; x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir]; @@ -570,7 +570,7 @@ void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) { const RailVehicleInfo *rvi; - int value,dir; + int value; Vehicle *v, *u; UnitID unit_num; Engine *e; @@ -606,11 +606,13 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); if (flags & DC_EXEC) { + uint dir; + v->unitnumber = unit_num; - dir = _m[tile].m5 & 3; + dir = GB(_m[tile].m5, 0, 2); - v->direction = (byte)(dir*2+1); + v->direction = dir * 2 + 1; v->tile = tile; v->owner = _current_player; v->x_pos = (x |= _vehicle_initial_x_fract[dir]); @@ -1126,10 +1128,10 @@ static void UpdateTrainDeltaXY(Vehicle *v, int direction) uint32 x = _delta_xy_table[direction]; - v->x_offs = (byte)x; - v->y_offs = (byte)(x>>=8); - v->sprite_width = (byte)(x>>=8); - v->sprite_height = (byte)(x>>=8); + v->x_offs = GB(x, 0, 8); + v->y_offs = GB(x, 8, 8); + v->sprite_width = GB(x, 16, 8); + v->sprite_height = GB(x, 24, 8); } static void UpdateVarsAfterSwap(Vehicle *v) @@ -2116,7 +2118,7 @@ static bool CheckReverseTrain(Vehicle *v) /* if we reach this position, there's two paths of equal value so far. * pick one randomly. */ - r = (byte)Random(); + r = GB(Random(), 0, 8); if (_pick_track_table[i] == (v->direction & 3)) r += 80; if (_pick_track_table[best_track] == (v->direction & 3)) r -= 80; if (r <= 127) goto bad; @@ -3095,8 +3097,8 @@ static bool TrainCheckIfLineEnds(Vehicle *v) tile = v->tile; // tunnel entrance? - if (IsTunnelTile(tile) && (byte)((_m[tile].m5 & 3)*2+1) == v->direction) - return true; + if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) * 2 + 1 == v->direction) + return true; // depot? /* XXX -- When enabled, this makes it possible to crash trains of others diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 76e801f7f..e72de08d3 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -377,8 +377,7 @@ not_valid_below:; } _m[ti.tile].m2 = (bridge_type << 4) | m5; - _m[ti.tile].m3 &= 0xF; - _m[ti.tile].m3 |= (byte)(railtype << 4); + SB(_m[ti.tile].m3, 4, 4, railtype); MarkTileDirtyByTile(ti.tile); } @@ -549,8 +548,8 @@ int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; - _build_tunnel_railtype = (byte)(p1 & 0xFF); - _build_tunnel_bh = (byte)(p1 >> 8); + _build_tunnel_railtype = GB(p1, 0, 8); + _build_tunnel_bh = GB(p1, 8, 8); _build_tunnel_endtile = 0; excavated_tile = 0; @@ -602,7 +601,7 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length) } while ( !IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0xF0) != 0 || - (byte)(_m[tile].m5 ^ 2) != m5 || + (_m[tile].m5 ^ 2) != m5 || GetTileZ(tile) != z ); @@ -1015,9 +1014,9 @@ static void DrawTile_TunnelBridge(TileInfo *ti) bool ice = _m[ti->tile].m4 & 0x80; // draw tunnel? - if ( (byte)(ti->map5&0xF0) == 0) { + if ((ti->map5 & 0xF0) == 0) { /* railway type */ - image = (_m[ti->tile].m3 & 0xF) * 8; + image = GB(_m[ti->tile].m3, 0, 4) * 8; /* ice? */ if (ice) diff --git a/unmovable_cmd.c b/unmovable_cmd.c index 4a43e81b5..75701c1e5 100644 --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -267,7 +267,7 @@ static void AnimateTile_Unmovable(TileIndex tile) static void TileLoop_Unmovable(TileIndex tile) { byte m5 = _m[tile].m5; - byte level; // HQ level (depends on company performance) in the range 1..5. + uint level; // HQ level (depends on company performance) in the range 1..5. uint32 r; if (!(m5 & 0x80)) { @@ -278,23 +278,22 @@ static void TileLoop_Unmovable(TileIndex tile) /* HQ accepts passenger and mail; but we have to divide the values * between 4 tiles it occupies! */ - level = (m5 & ~0x80) / 4 + 1; + level = GB(m5, 0, 7) / 4 + 1; assert(level < 6); r = Random(); // Top town buildings generate 250, so the top HQ type makes 256. - if ((byte) r < (256 / 4 / (6 - level))) { - uint amt = ((byte) r >> 3) / 4 + 1; + if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { + uint amt = GB(r, 0, 8) / 8 / 4 + 1; if (_economy.fluct <= 0) amt = (amt + 1) >> 1; MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); } - r >>= 8; // Top town building generates 90, HQ can make up to 196. The // proportion passengers:mail is about the same as in the acceptance // equations. - if ((byte) r < (196 / 4 / (6 - level))) { - uint amt = ((byte) r >> 3) / 4 + 1; + if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { + uint amt = GB(r, 8, 8) / 8 / 4 + 1; if (_economy.fluct <= 0) amt = (amt + 1) >> 1; MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); } |