diff options
author | tron <tron@openttd.org> | 2005-10-03 21:20:01 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-10-03 21:20:01 +0000 |
commit | db3b1228bfad7fb42ce708dc93db21d840b07577 (patch) | |
tree | 4379525d1560a92903c1fdc87cdbad70a36ea271 | |
parent | b0a365ee676b8b612d88a3df1cac904db73e8bcf (diff) | |
download | openttd-db3b1228bfad7fb42ce708dc93db21d840b07577.tar.xz |
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
-rw-r--r-- | aircraft_cmd.c | 3 | ||||
-rw-r--r-- | disaster_cmd.c | 4 | ||||
-rw-r--r-- | industry_cmd.c | 10 | ||||
-rw-r--r-- | misc.c | 6 | ||||
-rw-r--r-- | namegen.c | 3 | ||||
-rw-r--r-- | players.c | 4 | ||||
-rw-r--r-- | roadveh_cmd.c | 6 | ||||
-rw-r--r-- | station_gui.c | 2 | ||||
-rw-r--r-- | town_cmd.c | 4 | ||||
-rw-r--r-- | train_cmd.c | 34 | ||||
-rw-r--r-- | train_gui.c | 14 | ||||
-rw-r--r-- | viewport.c | 2 |
12 files changed, 48 insertions, 44 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c index 948d27742..244dab455 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -1239,8 +1239,7 @@ static void MaybeCrashAirplane(Vehicle *v) prob = 0x10000 / 20; } - if ((uint16)Random() > prob) - return; + if (GB(Random(), 0, 16) > prob) return; // Crash the airplane. Remove all goods stored at the station. for(i=0; i!=NUM_CARGO; i++) { diff --git a/disaster_cmd.c b/disaster_cmd.c index ea9c9abbe..842f35df8 100644 --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -977,13 +977,13 @@ static void DoDisaster(void) if (j == 0) return; - _disaster_initprocs[buf[(uint16)Random() * j >> 16]](); + _disaster_initprocs[buf[GB(Random(), 0, 16) * j >> 16]](); } static void ResetDisasterDelay(void) { - _disaster_delay = (int)(Random() & 0x1FF) + 730; + _disaster_delay = GB(Random(), 0, 9) + 730; } void DisasterDailyLoop(void) diff --git a/industry_cmd.c b/industry_cmd.c index ff24f6711..3ba5adbc7 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -934,7 +934,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int directi if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { or = type; - if (or == 1 && (uint16)Random() <= 9362) or = 2; + if (or == 1 && GB(Random(), 0, 16) <= 9362) or = 2; or <<= 2; and = (byte)~0x1C; @@ -1486,9 +1486,9 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind i->town = t; i->owner = owner; - r = Random() & 0xFFF; - i->color_map = (byte)(r >> 8); - i->counter = (uint16)r; + r = Random(); + i->color_map = GB(r, 8, 8); + i->counter = GB(r, 0, 16); i->cargo_waiting[0] = 0; i->cargo_waiting[1] = 0; i->last_mo_production[0] = 0; @@ -1626,7 +1626,7 @@ Industry *CreateNewIndustry(TileIndex tile, int type) return NULL; /* pick a random layout */ - it = spec->table[(spec->num_table * (uint16)Random()) >> 16]; + it = spec->table[(spec->num_table * GB(Random(), 0, 16)) >> 16]; if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) return NULL; @@ -51,12 +51,12 @@ uint32 t; #if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER) uint DoRandomRange(uint max, int line, const char *file) { - return (uint16)DoRandom(line, file) * max >> 16; + return GB(DoRandom(line, file), 0, 16) * max >> 16; } #else uint RandomRange(uint max) { - return (uint16)Random() * max >> 16; + return GB(Random(), 0, 16) * max >> 16; } #endif @@ -71,7 +71,7 @@ uint32 InteractiveRandom(void) uint InteractiveRandomRange(uint max) { - return (uint16)InteractiveRandom() * max >> 16; + return GB(InteractiveRandom(), 0, 16) * max >> 16; } void SetDate(uint date) @@ -3,12 +3,13 @@ #include "stdafx.h" #include "openttd.h" #include "debug.h" +#include "macros.h" #include "namegen.h" #include "table/namegen.h" static inline uint32 SeedChance(int shift_by, int max, uint32 seed) { - return ((uint16)(seed >> shift_by) * max) >> 16; + return (GB(seed, shift_by, 16) * max) >> 16; } static inline uint32 SeedModChance(int shift_by, int max, uint32 seed) @@ -1004,7 +1004,7 @@ int8 SaveHighScoreValueNetwork(void) memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); /* Copy over Top5 companies */ - for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < (uint8)count; i++) { + for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) { char buf[sizeof(_highscore_table[0]->company)]; hs = &_highscore_table[LAST_HS_ITEM][i]; @@ -1019,7 +1019,7 @@ int8 SaveHighScoreValueNetwork(void) hs->title = EndGameGetPerformanceTitleFromValue(hs->score); // get the ranking of the local player - if ((*p_cur)->index == (int8)_local_player) + if ((*p_cur)->index == _local_player) player = i; p_cur++; diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 382f1d8da..ee882b25c 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -987,7 +987,7 @@ static int PickRandomBit(uint bits) num++; } while (b >>= 1); - num = ((uint16)Random() * num >> 16); + num = GB(Random(), 0, 16) * num >> 16; for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); return i; @@ -1029,8 +1029,8 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir) { uint32 r; r = GetTileTrackStatus(tile, TRANSPORT_ROAD); - signal = (uint16)(r >> 16); - bitmask = (uint16)r; + signal = GB(r, 16, 16); + bitmask = GB(r, 0, 16); } if (IsTileType(tile, MP_STREET)) { diff --git a/station_gui.c b/station_gui.c index 00376daae..98912fb08 100644 --- a/station_gui.c +++ b/station_gui.c @@ -318,7 +318,7 @@ static void DrawStationViewWindow(Window *w) StringID str; uint16 station_id; - station_id = (uint16)w->window_number; + station_id = w->window_number; st = GetStation(w->window_number); diff --git a/town_cmd.c b/town_cmd.c index 0c6615712..d2a14f59b 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -593,9 +593,9 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1) // Randomize new road block numbers a = block; b = block ^ 2; - r = (uint16)Random(); + r = GB(Random(), 0, 16); if (r <= 0x4000) do { - a = (int)Random() & 3; + a = GB(Random(), 0, 2); } while(a == b); if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) { diff --git a/train_cmd.c b/train_cmd.c index d418469a6..d1202eaa8 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -763,23 +763,25 @@ static Vehicle *FindGoodVehiclePos(const Vehicle *src) */ int32 CmdMoveRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) { + VehicleID s = GB(p1, 0, 16); + VehicleID d = GB(p1, 16, 16); Vehicle *src, *dst, *src_head, *dst_head; bool is_loco; - if (!IsVehicleIndex(p1 & 0xFFFF)) return CMD_ERROR; + if (!IsVehicleIndex(s)) return CMD_ERROR; - src = GetVehicle(p1 & 0xFFFF); + src = GetVehicle(s); if (src->type != VEH_Train) return CMD_ERROR; is_loco = !(RailVehInfo(src->engine_type)->flags & RVI_WAGON) && IS_FIRSTHEAD_SPRITE(src->spritenum); // if nothing is selected as destination, try and find a matching vehicle to drag to. - if (((int32)p1 >> 16) == -1) { + if (d == INVALID_VEHICLE) { dst = NULL; if (!is_loco) dst = FindGoodVehiclePos(src); } else { - dst = GetVehicle((int32)p1 >> 16); + dst = GetVehicle(d); } // don't move the same vehicle.. @@ -1759,14 +1761,14 @@ static void HandleLocomotiveSmokeCloud(Vehicle *v) case 1: // diesel smoke - if (u->cur_speed <= 40 && !IsTileDepotType(v->tile, TRANSPORT_RAIL) && !IsTunnelTile(v->tile) && (uint16)Random() <= 0x1E00) { + if (u->cur_speed <= 40 && !IsTileDepotType(v->tile, TRANSPORT_RAIL) && !IsTunnelTile(v->tile) && GB(Random(), 0, 16) <= 0x1E00) { CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE); } break; case 2: // blue spark - if ( (v->tick_counter&0x3) == 0 && !IsTileDepotType(v->tile, TRANSPORT_RAIL) && !IsTunnelTile(v->tile) && (uint16)Random() <= 0x5B0) { + if (GB(v->tick_counter, 0, 2) == 0 && !IsTileDepotType(v->tile, TRANSPORT_RAIL) && !IsTunnelTile(v->tile) && GB(Random(), 0, 16) <= 0x5B0) { CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK); } break; @@ -3016,7 +3018,7 @@ static void HandleCrashedTrain(Vehicle *v) CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); } - if (state <= 200 && (uint16)(r=Random()) <= 0x2492) { + if (state <= 200 && GB(r = Random(), 0, 16) <= 0x2492) { index = (r * 10 >> 16); u = v; @@ -3082,16 +3084,17 @@ static bool TrainCheckIfLineEnds(Vehicle *v) { TileIndex tile; uint x,y; + uint16 break_speed; int t; uint32 ts; byte trackdir; - if ((uint)(t=v->breakdown_ctr) > 1) { + t = v->breakdown_ctr; + if (t > 1) { v->vehstatus |= VS_TRAIN_SLOWING; - t = _breakdown_speeds[ ((~t) >> 4) & 0xF]; - if ((uint16)t <= v->cur_speed) - v->cur_speed = t; + break_speed = _breakdown_speeds[GB(~t, 4, 4)]; + if (break_speed < v->cur_speed) v->cur_speed = break_speed; } else { v->vehstatus &= ~VS_TRAIN_SLOWING; } @@ -3160,7 +3163,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v) break; } - if ( (uint16)ts != 0) { + if (GB(ts, 0, 16) != 0) { /* If we approach a rail-piece which we can't enter, don't enter it! */ if (x + 4 > 15 && !CheckCompatibleRail(v, tile)) { v->cur_speed = 0; @@ -3208,10 +3211,9 @@ static bool TrainCheckIfLineEnds(Vehicle *v) // slow down v->vehstatus |= VS_TRAIN_SLOWING; - t = _breakdown_speeds[x & 0xF]; - if (!(v->direction&1)) t>>=1; - if ((uint16)t < v->cur_speed) - v->cur_speed = t; + break_speed = _breakdown_speeds[x & 0xF]; + if (!(v->direction&1)) break_speed >>= 1; + if (break_speed < v->cur_speed) v->cur_speed = break_speed; return true; } diff --git a/train_gui.c b/train_gui.c index 4d8a69e57..2bed4cfb1 100644 --- a/train_gui.c +++ b/train_gui.c @@ -538,7 +538,7 @@ found_it: return 0; } -static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) +static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head) { Vehicle *v; @@ -559,13 +559,13 @@ static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) if (wagon == v) return; - DoCommandP(v->tile, v->index + ((wagon==NULL ? (uint32)-1 : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); + DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); } static void TrainDepotClickTrain(Window *w, int x, int y) { GetDepotVehiclePtData gdvp; - int mode, sel; + int mode; Vehicle *v; mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); @@ -576,9 +576,10 @@ static void TrainDepotClickTrain(Window *w, int x, int y) v = gdvp.wagon; switch(mode) { - case 0: // start dragging of vehicle - sel = (int16)WP(w,traindepot_d).sel; - if (sel != -1) { + case 0: { // start dragging of vehicle + VehicleID sel = WP(w, traindepot_d).sel; + + if (sel != INVALID_VEHICLE) { WP(w,traindepot_d).sel = INVALID_VEHICLE; TrainDepotMoveVehicle(v, sel, gdvp.head); } else if (v != NULL) { @@ -587,6 +588,7 @@ static void TrainDepotClickTrain(Window *w, int x, int y) SetWindowDirty(w); } break; + } case -1: // show info window ShowTrainViewWindow(v); diff --git a/viewport.c b/viewport.c index 66b93a852..c3cc10834 100644 --- a/viewport.c +++ b/viewport.c @@ -2229,7 +2229,7 @@ void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, Window VpStartPreSizing(); if ( (int)icon < 0) - SetAnimatedMouseCursor(_animcursors[~(int32)icon]); + SetAnimatedMouseCursor(_animcursors[~icon]); else SetMouseCursor(icon); } |