Mercurial > hg > openttd
changeset 1980:e7a647ab6cb1 draft
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
author | tron <tron@openttd.org> |
---|---|
date | Sat, 25 Jun 2005 06:15:43 +0000 |
parents | 6be8120cf9b2 |
children | a5324b373a2d |
files | aircraft_cmd.c clear_cmd.c command.c disaster_cmd.c graph_gui.c industry_cmd.c landscape.c map.h misc_gui.c pathfind.c rail_cmd.c rail_gui.c road_cmd.c roadveh_cmd.c ship_cmd.c station_cmd.c town_cmd.c train_cmd.c unmovable_cmd.c vehicle.c viewport.c water_cmd.c waypoint.c window.c |
diffstat | 24 files changed, 65 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -169,7 +169,7 @@ int32 value; Vehicle *vl[3], *v, *u, *w; UnitID unit_num; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); const AircraftVehicleInfo *avi; Engine *e;
--- a/clear_cmd.c +++ b/clear_cmd.c @@ -236,7 +236,7 @@ ts.modheight = modheight_data; ts.tile_table = tile_table_data; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); /* Make an extra check for map-bounds cause we add tiles to the originating tile */ if (tile + TILE_XY(1,1) > MapSize()) return CMD_ERROR; @@ -394,7 +394,7 @@ SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!EnsureNoVehicle(tile)) return CMD_ERROR; @@ -450,7 +450,7 @@ SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!IsTileType(tile, MP_UNMOVABLE) || _map5[tile] != 3) return CMD_ERROR; if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
--- a/command.c +++ b/command.c @@ -325,7 +325,7 @@ CommandProc *proc; /* Do not even think about executing out-of-bounds tile-commands */ - if (TILE_FROM_XY(x,y) > MapSize()) { + if (TileVirtXY(x, y) > MapSize()) { _cmd_text = NULL; return CMD_ERROR; } @@ -336,7 +336,7 @@ _error_message = INVALID_STRING_ID; // update last build coord of player if ( (x|y) != 0 && _current_player < MAX_PLAYERS) { - GetPlayer(_current_player)->last_build_coordinate = TILE_FROM_XY(x,y); + GetPlayer(_current_player)->last_build_coordinate = TileVirtXY(x, y); } }
--- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -76,7 +76,7 @@ v->x_pos = x; v->y_pos = y; v->z_pos = z; - v->tile = TILE_FROM_XY(x,y); + v->tile = TileVirtXY(x, y); v->direction = direction; v->subtype = subtype; v->x_offs = -1; @@ -111,7 +111,7 @@ v->x_pos = x; v->y_pos = y; v->z_pos = z; - v->tile = TILE_FROM_XY(x,y); + v->tile = TileVirtXY(x, y); DisasterVehicleUpdateImage(v); VehiclePositionChanged(v); @@ -398,7 +398,7 @@ if ( (uint)x > MapMaxX() * 16-1) return; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!IsTileType(tile, MP_INDUSTRY)) return; @@ -469,7 +469,7 @@ if ( (uint)x > MapMaxX() * 16-1) return; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!IsTileType(tile, MP_INDUSTRY)) return;
--- a/graph_gui.c +++ b/graph_gui.c @@ -1206,7 +1206,7 @@ return; ss = GetSign(_sign_sort[id_v]); - ScrollMainWindowToTile(TILE_FROM_XY(ss->x, ss->y)); + ScrollMainWindowToTile(TileVirtXY(ss->x, ss->y)); } break; } } break;
--- a/industry_cmd.c +++ b/industry_cmd.c @@ -1555,7 +1555,7 @@ { Town *t; Industry *i; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); int num; const IndustryTileTable * const *itt; const IndustryTileTable *it;
--- a/landscape.c +++ b/landscape.c @@ -73,7 +73,7 @@ return; } - FindLandscapeHeightByTile(ti, TILE_FROM_XY(x,y)); + FindLandscapeHeightByTile(ti, TileVirtXY(x, y)); } uint GetPartialZ(int x, int y, int corners) @@ -284,7 +284,7 @@ */ int32 CmdLandscapeClear(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); @@ -318,7 +318,7 @@ for (x = sx; x <= ex; x += 16) { for (y = sy; y <= ey; y += 16) { - ret = DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags &~DC_EXEC, CMD_LANDSCAPE_CLEAR); + ret = DoCommandByTile(TileVirtXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); if (CmdFailed(ret)) continue; cost += ret; success = true; @@ -328,7 +328,7 @@ _additional_cash_required = ret; return cost - ret; } - DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR); + DoCommandByTile(TileVirtXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR); // draw explosion animation... if ((x == sx || x == ex) && (y == sy || y == ey)) {
--- a/map.h +++ b/map.h @@ -3,7 +3,6 @@ #include "stdafx.h" -#define TILE_FROM_XY(x,y) (TileIndex)((((y) >> 4) << MapLogX()) + ((x) >> 4)) #define TILE_XY(x,y) (((y) << MapLogX()) + (x)) #define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1)) @@ -37,6 +36,11 @@ typedef uint32 TileIndex; +static inline TileIndex TileVirtXY(uint x, uint y) +{ + return (y >> 4 << MapLogX()) + (x >> 4); +} + typedef enum { OWNER_TOWN = 0xf, // a town owns the tile OWNER_NONE = 0x10, // nobody owns the tile
--- a/misc_gui.c +++ b/misc_gui.c @@ -701,7 +701,7 @@ int y = _thd.pos.y; uint accepts[NUM_CARGO]; if (x != -1) { - GetAcceptanceAroundTiles(accepts, TILE_FROM_XY(x, y), _thd.size.x /16, _thd.size.y /16 , rad); + GetAcceptanceAroundTiles(accepts, TileVirtXY(x, y), _thd.size.x / 16, _thd.size.y / 16 , rad); DrawStationCoverageText(accepts, sx, sy, mask); } }
--- a/pathfind.c +++ b/pathfind.c @@ -230,7 +230,7 @@ x += _get_tunlen_inc[direction]; y += _get_tunlen_inc[direction+1]; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0 && // tunnel entrance/exit
--- a/rail_cmd.c +++ b/rail_cmd.c @@ -266,7 +266,7 @@ if (!ValParamRailtype(p1) || !ValParamTrackOrientation(track)) return CMD_ERROR; - tile = TILE_FROM_XY(x, y); + tile = TileVirtXY(x, y); tileh = GetTileSlope(tile, NULL); m5 = _map5[tile]; trackbit = TrackToTrackBits(track); @@ -410,7 +410,7 @@ SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); - tile = TILE_FROM_XY(x, y); + tile = TileVirtXY(x, y); tileh = GetTileSlope(tile, NULL); if (!IsTileType(tile, MP_TUNNELBRIDGE) && !IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_RAILWAY)) @@ -588,7 +588,7 @@ if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR; - if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TILE_FROM_XY(x,y)); + if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TileVirtXY(x, y)); for(;;) { ret = DoCommand(x, y, p2 & 0x3, TrackdirToTrack(trackdir), flags, (mode == 0) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL); @@ -638,7 +638,7 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) { Depot *d; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); int32 cost, ret; uint tileh; @@ -694,7 +694,7 @@ */ int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); bool semaphore; bool pre_signal; Track track = (Track)(p1 & 0x7); @@ -819,7 +819,7 @@ int ex, ey; int32 ret, total_cost, signal_ctr; byte signals; - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); bool error = true; int mode = p2 & 0x1; @@ -910,7 +910,7 @@ */ int32 CmdRemoveSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); Track track = (Track)(p1 & 0x7); if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile)) @@ -1003,7 +1003,7 @@ for (x = sx; x <= ex; x += TILE_SIZE) { for (y = sy; y <= ey; y += TILE_SIZE) { - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); DoConvertRailProc *proc; if (IsTileType(tile, MP_RAILWAY)) proc = DoConvertRail;
--- a/rail_gui.c +++ b/rail_gui.c @@ -314,7 +314,7 @@ static void DoRailroadTrack(int mode) { - DoCommandP(TILE_FROM_XY(_thd.selstart.x, _thd.selstart.y), TILE_FROM_XY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL, + DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL, _remove_button_clicked ? CMD_REMOVE_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) : CMD_BUILD_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) @@ -327,7 +327,7 @@ int trackstat = thd->drawstyle & 0xF; // 0..5 if (thd->drawstyle & HT_RAIL) { // one tile case - GenericPlaceRail(TILE_FROM_XY(thd->selend.x, thd->selend.y), trackstat); + GenericPlaceRail(TileVirtXY(thd->selend.x, thd->selend.y), trackstat); return; } @@ -340,13 +340,13 @@ byte trackstat = thd->drawstyle & 0xF; // 0..5 if (thd->drawstyle == HT_RECT) { // one tile case - GenericPlaceSignals(TILE_FROM_XY(thd->selend.x, thd->selend.y)); + GenericPlaceSignals(TileVirtXY(thd->selend.x, thd->selend.y)); return; } // _patches.drag_signals_density is given as a parameter such that each user in a network // game can specify his/her own signal density - DoCommandP(TILE_FROM_XY(thd->selstart.x, thd->selstart.y), TILE_FROM_XY(thd->selend.x, thd->selend.y), + DoCommandP(TileVirtXY(thd->selstart.x, thd->selstart.y), TileVirtXY(thd->selend.x, thd->selend.y), (_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) | (_patches.drag_signals_density << 24), CcPlaySound1E, (_remove_button_clicked ? CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) :
--- a/road_cmd.c +++ b/road_cmd.c @@ -518,7 +518,7 @@ if (p1 > MapSize()) return CMD_ERROR; start_tile = p1; - end_tile = TILE_FROM_XY(x, y); + end_tile = TileVirtXY(x, y); /* Only drag in X or Y direction dictated by the direction variable */ if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis @@ -572,7 +572,7 @@ if (p1 > MapSize()) return CMD_ERROR; start_tile = p1; - end_tile = TILE_FROM_XY(x, y); + end_tile = TileVirtXY(x, y); /* Only drag in X or Y direction dictated by the direction variable */ if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
--- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -120,7 +120,7 @@ int32 cost; Vehicle *v; UnitID unit_num; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); Engine *e; if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR; @@ -789,7 +789,7 @@ rvf.y = y; rvf.dir = dir; rvf.veh = v; - u = VehicleFromPos(TILE_FROM_XY(x,y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose); + u = VehicleFromPos(TileVirtXY(x, y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose); // This code protects a roadvehicle from being blocked for ever // If more than 1480 / 74 days a road vehicle is blocked, it will
--- a/ship_cmd.c +++ b/ship_cmd.c @@ -866,7 +866,7 @@ int32 value; Vehicle *v; UnitID unit_num; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); Engine *e; if (!IsEngineBuildable(p1, VEH_Ship)) return CMD_ERROR;
--- a/station_cmd.c +++ b/station_cmd.c @@ -942,7 +942,7 @@ SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); - tile_org = TILE_FROM_XY(x, y); + tile_org = TileVirtXY(x, y); /* Does the authority allow this? */ if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR; @@ -1125,7 +1125,7 @@ */ int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); Station *st; SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); @@ -1451,7 +1451,7 @@ SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR; @@ -1675,7 +1675,7 @@ /* Check if a valid, buildable airport was chosen for construction */ if (p1 > lengthof(_airport_map5_tiles) || !HASBIT(GetValidAirports(), p1)) return CMD_ERROR; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
--- a/town_cmd.c +++ b/town_cmd.c @@ -1023,7 +1023,7 @@ */ int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); TileInfo ti; Town *t; uint32 townnameparts;
--- a/train_cmd.c +++ b/train_cmd.c @@ -596,7 +596,7 @@ Vehicle *v, *u; UnitID unit_num; Engine *e; - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); /* Check if the engine-type is valid (for the player) */ if (!IsEngineBuildable(p1, VEH_Train)) return CMD_ERROR; @@ -2366,7 +2366,7 @@ CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); if (new_z != old_z) { - TileIndex tile = TILE_FROM_XY(v->x_pos, v->y_pos); + TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); // XXX workaround, whole UP/DOWN detection needs overhaul if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0x80) != 0) @@ -2582,13 +2582,13 @@ if (v->u.rail.track == 0x80) return; - assert(v->u.rail.track == 0x40 || TILE_FROM_XY(v->x_pos, v->y_pos) == v->tile); + assert(v->u.rail.track == 0x40 || TileVirtXY(v->x_pos, v->y_pos) == v->tile); tcc.v = v; tcc.v_skip = v->next; /* find colliding vehicle */ - realcoll = VehicleFromPos(TILE_FROM_XY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum); + realcoll = VehicleFromPos(TileVirtXY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum); if (realcoll == NULL) return;
--- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -61,7 +61,7 @@ extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, int *); int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); Player *p = GetPlayer(_current_player); int cost;
--- a/vehicle.c +++ b/vehicle.c @@ -592,7 +592,7 @@ BeginVehicleMove(v); - tile = TILE_FROM_XY(v->x_pos, v->y_pos); + tile = TileVirtXY(v->x_pos, v->y_pos); if (!IsTileType(tile, MP_INDUSTRY)) { EndVehicleMove(v); DeleteVehicle(v); @@ -1094,7 +1094,7 @@ et++; SndPlayVehicleFx(SND_31_EXTRACT, v); - tile = TILE_FROM_XY(v->x_pos, v->y_pos); + tile = TileVirtXY(v->x_pos, v->y_pos); if (IsTileType(tile, MP_INDUSTRY) && _map5[tile] == 0xA2) { AddAnimatedTile(tile); @@ -1703,7 +1703,7 @@ gp->x = x; gp->y = y; gp->old_tile = v->tile; - gp->new_tile = TILE_FROM_XY(x,y); + gp->new_tile = TileVirtXY(x, y); return gp->old_tile == gp->new_tile; }
--- a/viewport.c +++ b/viewport.c @@ -684,7 +684,7 @@ } else if (IsPartOfAutoLine(ti->x, ti->y)) { // autorail highlighting long line int dir = _thd.drawstyle & ~0xF0; - TileIndex start = TILE_FROM_XY(_thd.selstart.x, _thd.selstart.y); + TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y); int diffx, diffy; int side; @@ -1443,7 +1443,7 @@ Point pt; if (IS_INT_INSIDE(x, 0, MapSizeX() * 16) && IS_INT_INSIDE(y, 0, MapSizeY() * 16)) - z = GetTileZ(TILE_FROM_XY(x,y)); + z = GetTileZ(TileVirtXY(x, y)); pt = RemapCoords(x, y, z); MarkAllViewportsDirty( @@ -1699,7 +1699,7 @@ { Point pt = TranslateXYToTileCoord(vp,x,y); - if (pt.x != -1) ClickTile(TILE_FROM_XY(pt.x, pt.y)); + if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y)); } void HandleClickOnTrain(Vehicle *v); @@ -1783,7 +1783,7 @@ if ((w = GetCallbackWnd()) != NULL) { e.event = WE_PLACE_OBJ; e.place.pt = pt; - e.place.tile = TILE_FROM_XY(pt.x, pt.y); + e.place.tile = TileVirtXY(pt.x, pt.y); w->wndproc(w, &e); } } @@ -2027,7 +2027,7 @@ w = myabs(dx) + 16; h = myabs(dy) + 16; - if (TILE_FROM_XY(thd->selstart.x, thd->selstart.y) == TILE_FROM_XY(x,y)) { // check if we're only within one tile + if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile if(method == VPM_RAILDIRS) b = GetAutorailHT(x, y); else // rect for autosignals on one tile @@ -2187,8 +2187,8 @@ // and call the mouseup event. e.event = WE_PLACE_MOUSEUP; e.place.pt = _thd.selend; - e.place.tile = TILE_FROM_XY(e.place.pt.x, e.place.pt.y); - e.place.starttile = TILE_FROM_XY(_thd.selstart.x, _thd.selstart.y); + e.place.tile = TileVirtXY(e.place.pt.x, e.place.pt.y); + e.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y); w->wndproc(w, &e); return false;
--- a/water_cmd.c +++ b/water_cmd.c @@ -38,7 +38,7 @@ if (p1 > 3) return CMD_ERROR; - tile = TILE_FROM_XY(x,y); + tile = TileVirtXY(x, y); if (!EnsureNoVehicle(tile)) return CMD_ERROR; tile2 = tile + (p1 ? TILE_XY(0,1) : TILE_XY(1,0)); @@ -166,7 +166,7 @@ */ int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); uint tileh; SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
--- a/waypoint.c +++ b/waypoint.c @@ -155,7 +155,7 @@ */ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x, y); + TileIndex tile = TileVirtXY(x, y); Waypoint *wp; uint tileh; uint dir; @@ -285,7 +285,7 @@ */ int32 CmdRemoveTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - TileIndex tile = TILE_FROM_XY(x,y); + TileIndex tile = TileVirtXY(x, y); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); return RemoveTrainWaypoint(tile, flags, true); }