Mercurial > hg > openttd
changeset 3098:f746e2c344d7 draft
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
author | tron <tron@openttd.org> |
---|---|
date | Tue, 28 Feb 2006 13:18:14 +0000 |
parents | da8c4f235fe9 |
children | 5f58ebf999f0 |
files | road_cmd.c |
diffstat | 1 files changed, 40 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/road_cmd.c +++ b/road_cmd.c @@ -224,7 +224,7 @@ ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); _m[tile].m5 ^= c; - if (GB(_m[tile].m5, 0, 4) == 0) { + if (GetRoadBits(tile) == 0) { DoClearSquare(tile); } else { MarkTileDirtyByTile(tile); @@ -270,33 +270,33 @@ } -static const byte _valid_tileh_slopes_road[3][15] = { +static const RoadBits _valid_tileh_slopes_road[3][15] = { // set of normal ones { ROAD_ALL, 0, 0, - ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5 - ROAD_NW | ROAD_SE, 0, 0, - ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11 - ROAD_SW | ROAD_NE, 0, 0 + ROAD_X, 0, 0, // 3, 4, 5 + ROAD_Y, 0, 0, + ROAD_Y, 0, 0, // 9, 10, 11 + ROAD_X, 0, 0 }, // allowed road for an evenly raised platform { 0, ROAD_SW | ROAD_NW, ROAD_SW | ROAD_SE, - ROAD_NW | ROAD_SE | ROAD_SW, + ROAD_Y | ROAD_SW, ROAD_SE | ROAD_NE, // 4 ROAD_ALL, - ROAD_SW | ROAD_NE | ROAD_SE, + ROAD_X | ROAD_SE, ROAD_ALL, ROAD_NW | ROAD_NE, // 8 - ROAD_SW | ROAD_NE | ROAD_NW, + ROAD_X | ROAD_NW, ROAD_ALL, ROAD_ALL, - ROAD_NW | ROAD_SE | ROAD_NE, // 12 + ROAD_Y | ROAD_NE, // 12 ROAD_ALL, ROAD_ALL }, @@ -549,7 +549,8 @@ tile = start_tile; // Start tile is the small number. for (;;) { - uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; + RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X; + if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; @@ -604,12 +605,13 @@ tile = start_tile; // Start tile is the small number. for (;;) { - uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; + RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X; + if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; // try to remove the halves. - if (bits) { + if (bits != 0) { ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD); if (!CmdFailed(ret)) cost += ret; } @@ -669,7 +671,7 @@ ModifyTile(tile, MP_SETTYPE(MP_STREET) | MP_MAPOWNER_CURRENT | MP_MAP5, - (p1 | 0x20) /* map5 */ + (ROAD_DEPOT << 4) | p1 /* map5 */ ); } @@ -745,7 +747,7 @@ #include "table/road_land.h" -uint GetRoadFoundation(uint tileh, uint bits) +uint GetRoadFoundation(uint tileh, RoadBits bits) { int i; // normal level sloped building @@ -758,8 +760,8 @@ (i += 2, tileh == 4) || (i += 2, tileh == 8) ) && ( - ( bits == (ROAD_SW | ROAD_NE)) || - (i++, bits == (ROAD_NW | ROAD_SE)) + ( bits == ROAD_X) || + (i++, bits == ROAD_Y) )) { return i + 15; } @@ -782,7 +784,7 @@ * @param snow Draw snow * @param flat Draw foundation */ -static void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool flat) +static void DrawRoadBits(TileInfo* ti, RoadBits road, byte ground_type, bool snow, bool flat) { const DrawRoadTileStruct *drts; PalSpriteID image = 0; @@ -820,7 +822,7 @@ if (ground_type >= 6) { // Road works - DrawGroundSprite(HASBIT(road, 3) ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y); + DrawGroundSprite(road & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y); return; } @@ -839,12 +841,12 @@ PalSpriteID image; uint16 m2; - switch (GB(ti->map5, 4, 4)) { - case 0: // normal road - DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false); + switch (GetRoadType(ti->tile)) { + case ROAD_NORMAL: + DrawRoadBits(ti, GetRoadBits(ti->tile), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false); break; - case 1: { // level crossing + case ROAD_CROSSING: { if (ti->tileh != 0) DrawFoundation(ti, ti->tileh); image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing; @@ -865,7 +867,8 @@ break; } - default: { // depot + default: + case ROAD_DEPOT: { uint32 ormod; PlayerID player; const DrawRoadSeqStruct* drss; @@ -926,9 +929,10 @@ // check if it's a foundation if (ti->tileh != 0) { - switch (GB(ti->map5, 4, 4)) { - case 0: { // normal road - uint f = GetRoadFoundation(ti->tileh, GB(ti->map5, 0, 4)); + switch (GetRoadType(ti->tile)) { + case ROAD_NORMAL: { + uint f = GetRoadFoundation(ti->tileh, GetRoadBits(ti->tile)); + if (f != 0) { if (f < 15) { // leveled foundation @@ -941,8 +945,8 @@ } // if these are on a slope then there's a level foundation - case 1: // level crossing - case 2: // depot + case ROAD_DEPOT: + case ROAD_CROSSING: return z + 8; default: break; @@ -956,9 +960,10 @@ { // check if it's a foundation if (ti->tileh != 0) { - switch (GB(ti->map5, 4, 4)) { - case 0: { // normal road - uint f = GetRoadFoundation(ti->tileh, GB(ti->map5, 0, 4)); + switch (GetRoadType(ti->tile)) { + case ROAD_NORMAL: { + uint f = GetRoadFoundation(ti->tileh, GetRoadBits(ti->tile)); + if (f != 0) { if (f < 15) { // leveled foundation @@ -971,8 +976,8 @@ } // if these are on a slope then there's a level foundation - case 1: // level crossing - case 2: // depot + case ROAD_CROSSING: + case ROAD_DEPOT: return 0; default: break; @@ -1213,7 +1218,7 @@ SetTileOwner(tile, _m[tile].m3); _m[tile].m3 = 0; _m[tile].m4 &= 0x80; - _m[tile].m5 = GetCrossingRoadBits(tile); + _m[tile].m5 = (ROAD_NORMAL << 4) | GetCrossingRoadBits(tile); break; default: