Mercurial > hg > openttd
changeset 15187:03033976eab9 draft
(svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 13 May 2010 11:19:30 +0000 |
parents | db17dc614727 |
children | d1bed581946f |
files | src/disaster_cmd.cpp src/smallmap_gui.cpp src/terraform_cmd.cpp src/tile_type.h src/tunnelbridge_cmd.cpp src/viewport.cpp |
diffstat | 6 files changed, 31 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -221,7 +221,7 @@ } } - if (v->y_pos >= ((int)MapSizeY() + 9) * TILE_SIZE - 1) { + if (v->y_pos >= (int)((MapSizeY() + 9) * TILE_SIZE - 1)) { delete v; return false; } @@ -291,7 +291,7 @@ /* Fly around randomly */ int x = TileX(v->dest_tile) * TILE_SIZE; int y = TileY(v->dest_tile) * TILE_SIZE; - if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= TILE_SIZE) { + if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) { v->direction = GetDirectionTowards(v, x, y); GetNewVehiclePosResult gp = GetNewVehiclePos(v); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); @@ -389,7 +389,7 @@ GetNewVehiclePosResult gp = GetNewVehiclePos(v); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); - if ((leave_at_top && gp.x < (-10 * TILE_SIZE)) || (!leave_at_top && gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1)) { + if ((leave_at_top && gp.x < (-10 * (int)TILE_SIZE)) || (!leave_at_top && gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1)) { delete v; return false; } @@ -505,7 +505,7 @@ Vehicle *target; FOR_ALL_VEHICLES(target) { if (target->type == VEH_TRAIN || target->type == VEH_ROAD) { - if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * TILE_SIZE) { + if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) { target->breakdown_ctr = 5; target->breakdown_delay = 0xF0; } @@ -536,7 +536,7 @@ } else if (v->current_order.GetDestination() == 0) { int x = TileX(v->dest_tile) * TILE_SIZE; int y = TileY(v->dest_tile) * TILE_SIZE; - if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= TILE_SIZE) { + if (Delta(x, v->x_pos) + Delta(y, v->y_pos) >= (int)TILE_SIZE) { v->direction = GetDirectionTowards(v, x, y); GetNewVehiclePosResult gp = GetNewVehiclePos(v); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); @@ -576,14 +576,14 @@ GetNewVehiclePosResult gp = GetNewVehiclePos(v); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); - if (gp.x > (int)MapSizeX() * TILE_SIZE + 9 * TILE_SIZE - 1) { + if (gp.x > (int)(MapSizeX() * TILE_SIZE + 9 * TILE_SIZE) - 1) { delete v; return false; } if (v->current_order.GetDestination() == 0) { Vehicle *u = Vehicle::Get(v->big_ufo_destroyer_target); - if (Delta(v->x_pos, u->x_pos) > TILE_SIZE) return true; + if (Delta(v->x_pos, u->x_pos) > (int)TILE_SIZE) return true; v->current_order.SetDestination(1); CreateEffectVehicleRel(u, 0, 7, 8, EV_EXPLOSION_LARGE);
--- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1304,7 +1304,7 @@ sx = -hv.x; sub = 0; } - if (sx > (int)MapMaxX() * TILE_SIZE - hv.x) { + if (sx > (int)(MapMaxX() * TILE_SIZE) - hv.x) { sx = MapMaxX() * TILE_SIZE - hv.x; sub = 0; } @@ -1312,7 +1312,7 @@ sy = -hv.y; sub = 0; } - if (sy > (int)MapMaxY() * TILE_SIZE - hv.y) { + if (sy > (int)(MapMaxY() * TILE_SIZE) - hv.y) { sy = MapMaxY() * TILE_SIZE - hv.y; sub = 0; }
--- a/src/terraform_cmd.cpp +++ b/src/terraform_cmd.cpp @@ -156,7 +156,7 @@ /* Check range of destination height */ if (height < 0) return_cmd_error(STR_ERROR_ALREADY_AT_SEA_LEVEL); - if (height > MAX_TILE_HEIGHT) return_cmd_error(STR_ERROR_TOO_HIGH); + if (height > (int)MAX_TILE_HEIGHT) return_cmd_error(STR_ERROR_TOO_HIGH); /* * Check if the terraforming has any effect.
--- a/src/tile_type.h +++ b/src/tile_type.h @@ -12,18 +12,16 @@ #ifndef TILE_TYPE_H #define TILE_TYPE_H +static const uint TILE_SIZE = 16; ///< Tiles are 16x16 "units" in size +static const uint TILE_UNIT_MASK = TILE_SIZE - 1; ///< for masking in/out the inner-tile units. +static const uint TILE_PIXELS = 32; ///< a tile is 32x32 pixels +static const uint TILE_HEIGHT = 8; ///< The standard height-difference between tiles on two levels is 8 (z-diff 8) -enum { - TILE_SIZE = 16, ///< Tiles are 16x16 "units" in size - TILE_UNIT_MASK = TILE_SIZE - 1, ///< for masking in/out the inner-tile units. - TILE_PIXELS = 32, ///< a tile is 32x32 pixels - TILE_HEIGHT = 8, ///< The standard height-difference between tiles on two levels is 8 (z-diff 8) +static const uint MAX_TILE_HEIGHT = 15; ///< Maximum allowed tile height - MAX_TILE_HEIGHT = 15, ///< Maximum allowed tile height - MIN_SNOWLINE_HEIGHT = 2, ///< Minimum snowline height - DEF_SNOWLINE_HEIGHT = 7, ///< Default snowline height - MAX_SNOWLINE_HEIGHT = (MAX_TILE_HEIGHT - 2), ///< Maximum allowed snowline height -}; +static const uint MIN_SNOWLINE_HEIGHT = 2; ///< Minimum snowline height +static const uint DEF_SNOWLINE_HEIGHT = 7; ///< Default snowline height +static const uint MAX_SNOWLINE_HEIGHT = (MAX_TILE_HEIGHT - 2); ///< Maximum allowed snowline height /**
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -861,7 +861,7 @@ } /* Draw back facing pillar, but not the highest part directly under the bridge-floor */ - if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) { + if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - (int)TILE_HEIGHT) { AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5); } }
--- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1017,8 +1017,8 @@ do { int width_cur = width; - int x_cur = x; - int y_cur = y; + uint x_cur = x; + uint y_cur = y; do { TileType tt = MP_VOID; @@ -1031,8 +1031,8 @@ ti.tileh = SLOPE_FLAT; ti.tile = INVALID_TILE; - if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE && - 0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) { + if (x_cur < MapMaxX() * TILE_SIZE && + y_cur < MapMaxY() * TILE_SIZE) { TileIndex tile = TileVirtXY(x_cur, y_cur); if (!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0)) { @@ -2318,7 +2318,7 @@ } else { /* We are not on a straight line. Determine the rail to build * based on whether we are above or below it. */ - b = dx + dy >= TILE_SIZE ? HT_LINE | HT_DIR_HU : HT_LINE | HT_DIR_HL; + b = dx + dy >= (int)TILE_SIZE ? HT_LINE | HT_DIR_HU : HT_LINE | HT_DIR_HL; /* Calculate where a horizontal line through the start point and * a vertical line from the selected end point intersect and @@ -2329,7 +2329,7 @@ /* 'Build' the last half rail tile if needed */ if ((offset & TILE_UNIT_MASK) > (TILE_SIZE / 2)) { - if (dx + dy >= TILE_SIZE) { + if (dx + dy >= (int)TILE_SIZE) { x += (dx + dy < 0) ? TILE_SIZE : -TILE_SIZE; } else { y += (dx + dy < 0) ? TILE_SIZE : -TILE_SIZE; @@ -2341,7 +2341,7 @@ CheckUnderflow(y, x, 1); CheckOverflow(x, y, (MapMaxX() - 1) * TILE_SIZE, 1); CheckOverflow(y, x, (MapMaxY() - 1) * TILE_SIZE, 1); - assert(x >= 0 && y >= 0 && x <= (int)MapMaxX() * TILE_SIZE && y <= (int)MapMaxY() * TILE_SIZE); + assert(x >= 0 && y >= 0 && x <= (int)(MapMaxX() * TILE_SIZE) && y <= (int)(MapMaxY() * TILE_SIZE)); } break; @@ -2376,7 +2376,7 @@ CheckUnderflow(y, x, -1); CheckOverflow(x, y, (MapMaxX() - 1) * TILE_SIZE, -1); CheckOverflow(y, x, (MapMaxY() - 1) * TILE_SIZE, -1); - assert(x >= 0 && y >= 0 && x <= (int)MapMaxX() * TILE_SIZE && y <= (int)MapMaxY() * TILE_SIZE); + assert(x >= 0 && y >= 0 && x <= (int)(MapMaxX() * TILE_SIZE) && y <= (int)(MapMaxY() * TILE_SIZE)); } break; @@ -2390,18 +2390,18 @@ b = HT_RECT; } } else if (h == TILE_SIZE) { // Is this in X direction? - if (dx == TILE_SIZE) { // 2x1 special handling + if (dx == (int)TILE_SIZE) { // 2x1 special handling b = (Check2x1AutoRail(3)) | HT_LINE; - } else if (dx == -TILE_SIZE) { + } else if (dx == -(int)TILE_SIZE) { b = (Check2x1AutoRail(2)) | HT_LINE; } else { b = HT_LINE | HT_DIR_X; } y = thd->selstart.y; } else if (w == TILE_SIZE) { // Or Y direction? - if (dy == TILE_SIZE) { // 2x1 special handling + if (dy == (int)TILE_SIZE) { // 2x1 special handling b = (Check2x1AutoRail(1)) | HT_LINE; - } else if (dy == -TILE_SIZE) { // 2x1 other direction + } else if (dy == -(int)TILE_SIZE) { // 2x1 other direction b = (Check2x1AutoRail(0)) | HT_LINE; } else { b = HT_LINE | HT_DIR_Y;