(svn r12756) -Cleanup: variable scope and coding style in station*

This commit is contained in:
smatz 2008-04-17 20:03:28 +00:00
parent a2884f0a3c
commit 5050ba84fb
2 changed files with 96 additions and 103 deletions

View File

@ -249,20 +249,19 @@ static bool GenerateStationName(Station *st, TileIndex tile, int flag)
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */
};
Town *t = st->town;
uint32 free_names = (uint32)-1;
int found;
unsigned long tmp;
const Town *t = st->town;
uint32 free_names = UINT32_MAX;
{
Station *s;
const Station *s;
FOR_ALL_STATIONS(s) {
if (s != st && s->town == t) {
uint str = M(s->string_id);
if (str <= 0x20) {
if (str == M(STR_SV_STNAME_FOREST))
if (str == M(STR_SV_STNAME_FOREST)) {
str = M(STR_SV_STNAME_WOODS);
}
ClrBit(free_names, str);
}
}
@ -270,7 +269,8 @@ static bool GenerateStationName(Station *st, TileIndex tile, int flag)
}
/* check default names */
tmp = free_names & _gen_station_name_bits[flag];
uint32 tmp = free_names & _gen_station_name_bits[flag];
int found;
if (tmp != 0) {
found = FindFirstBit(tmp);
goto done;
@ -564,18 +564,14 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
/* Put all the tiles that span an area in the table. */
if (st->train_tile != 0) {
MergePoint(&rect, st->train_tile);
MergePoint(&rect,
st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
);
MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1));
}
if (st->airport_tile != 0) {
const AirportFTAClass *afc = st->Airport();
MergePoint(&rect, st->airport_tile);
MergePoint(&rect,
st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)
);
MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
}
if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile);
@ -609,16 +605,16 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
/* Make sure the station can accept the goods type. */
bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) {
amt = 0;
}
SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8);
}
/* Only show a message in case the acceptance was actually changed. */
uint new_acc = GetAcceptanceMask(st);
if (old_acc == new_acc)
return;
if (old_acc == new_acc) return;
/* show a message to report that the acceptance was changed? */
if (show_msg && st->owner == _local_player && st->facilities) {
@ -899,9 +895,6 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, const St
*/
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
{
int w_org, h_org;
CommandCost ret;
/* Does the authority allow this? */
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
@ -910,6 +903,8 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
Axis axis = Extract<Axis, 0>(p1);
uint numtracks = GB(p1, 8, 8);
uint plat_len = GB(p1, 16, 8);
int w_org, h_org;
if (axis == AXIS_X) {
w_org = plat_len;
h_org = numtracks;
@ -931,7 +926,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
* for detail info, see:
* https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
if (CmdFailed(ret)) return ret;
CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
@ -1239,12 +1234,12 @@ CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
{
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
if (_current_player == OWNER_WATER && _patches.nonuniform_stations) {
return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
}
/* Current player owns the station? */
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
return CMD_ERROR;
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
/* determine width and height of platforms */
tile = st->train_tile;
@ -1348,8 +1343,6 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
CommandCost cost;
/* Not allowed to build over this road */
if (build_over_road) {
if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
@ -1374,7 +1367,8 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Do not remove roadtypes! */
rts |= cur_rts;
}
cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
if (CmdFailed(cost)) return cost;
Station *st = NULL;
@ -1670,18 +1664,18 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Check if a valid, buildable airport was chosen for construction */
if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) {
return CMD_ERROR;
}
Town *t = ClosestTownFromTile(tile, (uint)-1);
Town *t = ClosestTownFromTile(tile, UINT_MAX);
/* Check if local auth refuses a new airport */
{
uint num = 0;
const Station *st;
FOR_ALL_STATIONS(st) {
if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG)
num++;
if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
}
if (num >= 2) {
SetDParam(0, t->index);
@ -1716,13 +1710,15 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
AutoPtrT<Station> st_auto_delete;
if (st != NULL) {
if (st->owner != _current_player)
if (st->owner != _current_player) {
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
}
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR;
if (st->airport_tile != 0)
if (st->airport_tile != 0) {
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
}
} else {
airport_upgrade = false;
@ -1790,8 +1786,9 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
static CommandCost RemoveAirport(Station *st, uint32 flags)
{
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
return CMD_ERROR;
}
TileIndex tile = st->airport_tile;
@ -1801,7 +1798,7 @@ static CommandCost RemoveAirport(Station *st, uint32 flags)
CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
Vehicle *v;
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
@ -1958,8 +1955,6 @@ static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
*/
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
CommandCost cost;
DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
direction = ReverseDiagDir(direction);
@ -1971,8 +1966,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
if (CmdFailed(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
@ -1985,8 +1979,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Get the water class of the water tile before it is cleared.*/
WaterClass wc = GetWaterClass(tile_cur);
cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
if (CmdFailed(DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
@ -2011,8 +2004,9 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
AutoPtrT<Station> st_auto_delete;
if (st != NULL) {
if (st->owner != _current_player)
if (st->owner != _current_player) {
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
}
if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
@ -2052,6 +2046,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* success, so don't delete the new station */
st_auto_delete.Detach();
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
}
@ -2131,8 +2126,6 @@ static void DrawTile_Station(TileInfo *ti)
st = GetStationByTile(ti->tile);
statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
//debug("Cust-o-mized %p", statspec);
if (statspec != NULL) {
uint tile = GetStationGfx(ti->tile);
@ -2484,7 +2477,11 @@ static void StationHandleBigTick(Station *st)
}
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }
static inline void byte_inc_sat(byte *p)
{
byte b = *p + 1;
if (b != 0) *p = b;
}
static void UpdateStationRating(Station *st)
{
@ -2622,6 +2619,7 @@ void OnTick_Station()
void StationMonthlyLoop()
{
/* not used */
}
@ -2995,7 +2993,6 @@ void InitializeStations()
_RoadStop_pool.AddBlockToPool();
_station_tick_ctr = 0;
}
@ -3088,7 +3085,7 @@ static const SaveLoad _roadstop_desc[] = {
static const SaveLoad _station_desc[] = {
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDNULL(4, 0, 5), // bus/lorry tile
SLE_CONDNULL(4, 0, 5), ///< bus/lorry tile
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
@ -3099,8 +3096,7 @@ static const SaveLoad _station_desc[] = {
SLE_VAR(Station, trainst_w, SLE_UINT8),
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION),
/* alpha_order was stored here in savegame format 0 - 3 */
SLE_CONDNULL(1, 0, 3),
SLE_CONDNULL(1, 0, 3), ///< alpha_order
SLE_VAR(Station, string_id, SLE_STRINGID),
SLE_CONDSTR(Station, name, SLE_STR, 0, 84, SL_MAX_VERSION),
@ -3113,18 +3109,17 @@ static const SaveLoad _station_desc[] = {
SLE_VAR(Station, facilities, SLE_UINT8),
SLE_VAR(Station, airport_type, SLE_UINT8),
SLE_CONDNULL(2, 0, 5), // Truck/bus stop status
SLE_CONDNULL(1, 0, 4), // Blocked months
SLE_CONDNULL(2, 0, 5), ///< Truck/bus stop status
SLE_CONDNULL(1, 0, 4), ///< Blocked months
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U16, 0, 2),
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U32, 3, 45),
SLE_CONDVAR(Station, airport_flags, SLE_UINT64, 46, SL_MAX_VERSION),
SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
SLE_CONDNULL(2, 0, 25), ///< last-vehicle
SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION),
/* Was custom station class and id */
SLE_CONDNULL(2, 3, 25),
SLE_CONDNULL(2, 3, 25), ///< custom station class and id
SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30),
SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION),

View File

@ -102,7 +102,6 @@ static int CDECL StationNameSorter(const void *a, const void *b)
const Station *st1 = *(const Station**)a;
const Station *st2 = *(const Station**)b;
char buf1[64];
int r;
SetDParam(0, st1->index);
GetString(buf1, STR_STATION, lastof(buf1));
@ -113,7 +112,7 @@ static int CDECL StationNameSorter(const void *a, const void *b)
GetString(_bufcache, STR_STATION, lastof(_bufcache));
}
r = strcmp(buf1, _bufcache); // sort by name
int r = strcmp(buf1, _bufcache); // sort by name
return (_internal_sort_order & 1) ? -r : r;
}
@ -124,7 +123,7 @@ static int CDECL StationTypeSorter(const void *a, const void *b)
return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
}
static const uint32 _cargo_filter_max = ~0;
static const uint32 _cargo_filter_max = UINT32_MAX;
static uint32 _cargo_filter = _cargo_filter_max;
static int CDECL StationWaitingSorter(const void *a, const void *b)
@ -750,9 +749,6 @@ static void DrawStationViewWindow(Window *w)
{
StationID station_id = w->window_number;
const Station *st = GetStation(station_id);
int x, y; ///< coordinates used for printing waiting/accepted/rating of cargo
int pos; ///< = w->vscroll.pos
StringID str;
CargoDataList cargolist;
uint32 transfers = 0;
@ -808,13 +804,15 @@ static void DrawStationViewWindow(Window *w)
SetDParam(1, st->facilities);
DrawWindowWidgets(w);
x = 2;
y = 15;
pos = w->vscroll.pos;
int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
int y = 15;
int pos = w->vscroll.pos; ///< = w->vscroll.pos
uint width = w->widget[SVW_WAITING].right - w->widget[SVW_WAITING].left - 4;
int maxrows = w->vscroll.cap;
StringID str;
if (--pos < 0) {
str = STR_00D0_NOTHING;
for (CargoID i = 0; i < NUM_CARGO; i++) {