(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff

This commit is contained in:
tron 2005-01-06 11:39:00 +00:00
parent 790b03c707
commit f8c95a1dbe
21 changed files with 469 additions and 463 deletions

32
ai.c
View File

@ -1534,7 +1534,7 @@ static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, b
int rad; int rad;
for(;p->mode != 4;p++) if (p->mode == 1) { for(;p->mode != 4;p++) if (p->mode == 1) {
tile2 = TILE_ADD(tile, p->tileoffs); tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
w = ((p->attr>>1) & 7); w = ((p->attr>>1) & 7);
h = ((p->attr>>4) & 7); h = ((p->attr>>4) & 7);
@ -1573,7 +1573,7 @@ static int32 AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData
for(;;) { for(;;) {
// This will seldomly overflow for valid reasons. Mask it to be on the safe side. // This will seldomly overflow for valid reasons. Mask it to be on the safe side.
uint c = TILE_MASK(tile + p->tileoffs); uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
_cleared_town = NULL; _cleared_town = NULL;
@ -1822,7 +1822,7 @@ static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd
while (p->mode != 3 || !((--cmd) & 0x80)) p++; while (p->mode != 3 || !((--cmd) & 0x80)) p++;
return tile + p->tileoffs - TileOffsByDir(*dir = p->attr); return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDir(*dir = p->attr);
} }
typedef struct AiRailPathFindData { typedef struct AiRailPathFindData {
@ -2357,7 +2357,7 @@ static int AiGetStationIdByDef(TileIndex tile, int id)
{ {
const AiDefaultBlockData *p = _default_rail_track_data[id]->data; const AiDefaultBlockData *p = _default_rail_track_data[id]->data;
while (p->mode != 1) p++; while (p->mode != 1) p++;
return _map2[TILE_ADD(tile,p->tileoffs)]; return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
} }
static void AiStateBuildRailVeh(Player *p) static void AiStateBuildRailVeh(Player *p)
@ -2373,7 +2373,7 @@ static void AiStateBuildRailVeh(Player *p)
ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data; ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data;
while (ptr->mode != 0) { ptr++; } while (ptr->mode != 0) { ptr++; }
tile = TILE_ADD(p->ai.src.use_tile, ptr->tileoffs); tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
cargo = p->ai.cargo_type; cargo = p->ai.cargo_type;
for(i=0;;) { for(i=0;;) {
@ -2469,7 +2469,7 @@ static void AiStateDeleteRailBlocks(Player *p)
if (aib->cur_building_rule != 255) { if (aib->cur_building_rule != 255) {
b = _default_rail_track_data[aib->cur_building_rule]->data; b = _default_rail_track_data[aib->cur_building_rule]->data;
while (b->mode != 4) { while (b->mode != 4) {
DoCommandByTile(TILE_ADD(aib->use_tile, b->tileoffs), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); DoCommandByTile(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
b++; b++;
} }
} }
@ -2493,7 +2493,7 @@ static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, by
if (p->mode == 4) { if (p->mode == 4) {
return true; return true;
} else if (p->mode == 1) { } else if (p->mode == 1) {
uint tile2 = TILE_ADD(tile, p->tileoffs); uint tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
if (cargo & 0x80) { if (cargo & 0x80) {
GetProductionAroundTiles(values, tile2, 1, 1, rad); GetProductionAroundTiles(values, tile2, 1, 1, rad);
return values[cargo & 0x7F] != 0; return values[cargo & 0x7F] != 0;
@ -2536,7 +2536,7 @@ static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData
int roadflag = 0; int roadflag = 0;
for(;p->mode != 4;p++) { for(;p->mode != 4;p++) {
uint c = TILE_MASK(tile+ p->tileoffs); uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
_cleared_town = NULL; _cleared_town = NULL;
@ -3085,7 +3085,7 @@ static TileIndex AiGetRoadBlockEdge(byte rule, TileIndex tile, int *dir)
const AiDefaultBlockData *p = _road_default_block_data[rule]->data; const AiDefaultBlockData *p = _road_default_block_data[rule]->data;
while (p->mode != 1) p++; while (p->mode != 1) p++;
*dir = p->attr; *dir = p->attr;
return TILE_ADD(tile, p->tileoffs); return TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
} }
@ -3158,7 +3158,7 @@ static int AiGetStationIdFromRoadBlock(TileIndex tile, int id)
{ {
const AiDefaultBlockData *p = _road_default_block_data[id]->data; const AiDefaultBlockData *p = _road_default_block_data[id]->data;
while (p->mode != 1) p++; while (p->mode != 1) p++;
return _map2[TILE_ADD(tile, p->tileoffs)]; return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
} }
static void AiStateBuildRoadVehicles(Player *p) static void AiStateBuildRoadVehicles(Player *p)
@ -3170,7 +3170,7 @@ static void AiStateBuildRoadVehicles(Player *p)
ptr = _road_default_block_data[p->ai.src.cur_building_rule]->data; ptr = _road_default_block_data[p->ai.src.cur_building_rule]->data;
for(;ptr->mode != 0;ptr++) {} for(;ptr->mode != 0;ptr++) {}
tile = TILE_ADD(p->ai.src.use_tile, ptr->tileoffs); tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
veh = AiChooseRoadVehToBuild(p->ai.cargo_type, p->player_money); veh = AiChooseRoadVehToBuild(p->ai.cargo_type, p->player_money);
if (veh == -1) { if (veh == -1) {
@ -3227,7 +3227,7 @@ static void AiStateDeleteRoadBlocks(Player *p)
b = _road_default_block_data[aib->cur_building_rule]->data; b = _road_default_block_data[aib->cur_building_rule]->data;
while (b->mode != 4) { while (b->mode != 4) {
if (b->mode <= 1) { if (b->mode <= 1) {
DoCommandByTile(TILE_ADD(aib->use_tile, b->tileoffs), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); DoCommandByTile(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
} }
b++; b++;
} }
@ -3339,7 +3339,7 @@ static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockDa
for(;p->mode == 0;p++) { for(;p->mode == 0;p++) {
if (!HASBIT(_avail_aircraft, p->attr)) if (!HASBIT(_avail_aircraft, p->attr))
return CMD_ERROR; return CMD_ERROR;
r = DoCommandByTile(TILE_MASK(tile + p->tileoffs), p->attr,0,flag | DC_AUTO | DC_NO_WATER,CMD_BUILD_AIRPORT); r = DoCommandByTile(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr,0,flag | DC_AUTO | DC_NO_WATER,CMD_BUILD_AIRPORT);
if (r == CMD_ERROR) if (r == CMD_ERROR)
return CMD_ERROR; return CMD_ERROR;
total_cost += r; total_cost += r;
@ -3362,7 +3362,7 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p,
} }
for(;p->mode==0;p++) { for(;p->mode==0;p++) {
tile2 = TILE_ADD(tile, p->tileoffs); tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
w = _airport_size_x[p->attr]; w = _airport_size_x[p->attr];
h = _airport_size_y[p->attr]; h = _airport_size_y[p->attr];
if (cargo & 0x80) { if (cargo & 0x80) {
@ -3479,7 +3479,7 @@ static int AiGetStationIdFromAircraftBlock(TileIndex tile, int id)
{ {
const AiDefaultBlockData *p = _airport_default_block_data[id]; const AiDefaultBlockData *p = _airport_default_block_data[id];
while (p->mode != 1) p++; while (p->mode != 1) p++;
return _map2[TILE_ADD(tile, p->tileoffs)]; return _map2[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))];
} }
static void AiStateBuildAircraftVehicles(Player *p) static void AiStateBuildAircraftVehicles(Player *p)
@ -3494,7 +3494,7 @@ static void AiStateBuildAircraftVehicles(Player *p)
ptr = _airport_default_block_data[p->ai.src.cur_building_rule]; ptr = _airport_default_block_data[p->ai.src.cur_building_rule];
for(;ptr->mode!=0;ptr++) {} for(;ptr->mode!=0;ptr++) {}
tile = TILE_ADD(p->ai.src.use_tile, ptr->tileoffs); tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
veh = AiChooseAircraftToBuild(p->player_money, p->ai.build_kind!=0 ? 1 : 0); veh = AiChooseAircraftToBuild(p->player_money, p->ai.build_kind!=0 ? 1 : 0);
if (veh == -1) { if (veh == -1) {

View File

@ -215,12 +215,12 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
Station *st; Station *st;
const AirportFTAClass *Airport; const AirportFTAClass *Airport;
const uint16 *cur_depot; const TileIndexDiffC *cur_depot;
byte i = 0; byte i = 0;
st = DEREF_STATION(_map2[tile]); st = DEREF_STATION(_map2[tile]);
Airport = GetAirport(st->airport_type); Airport = GetAirport(st->airport_type);
for (cur_depot = Airport->airport_depots; i != Airport->nof_depots; cur_depot++) { for (cur_depot = Airport->airport_depots; i != Airport->nof_depots; cur_depot++) {
if ((uint)(st->airport_tile + *cur_depot) == tile) { if ((uint)(st->airport_tile + ToTileIndexDiff(*cur_depot)) == tile) {
assert(Airport->layout[i].heading == HANGAR); assert(Airport->layout[i].heading == HANGAR);
v->u.air.pos = Airport->layout[i].position; v->u.air.pos = Airport->layout[i].position;
break; break;

View File

@ -14,7 +14,7 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
const byte nofhelipads, const byte nofhelipadgroups, const byte nofhelipads, const byte nofhelipadgroups,
const byte entry_point, const byte acc_planes, const byte entry_point, const byte acc_planes,
const AirportFTAbuildup *FA, const AirportFTAbuildup *FA,
const TileIndex *depots, const byte nof_depots); const TileIndexDiffC *depots, const byte nof_depots);
static void AirportFTAClass_Destructor(AirportFTAClass *Airport); static void AirportFTAClass_Destructor(AirportFTAClass *Airport);
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA); static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
@ -61,7 +61,7 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
const byte nofhelipads, const byte nofhelipadgroups, const byte nofhelipads, const byte nofhelipadgroups,
const byte entry_point, const byte acc_planes, const byte entry_point, const byte acc_planes,
const AirportFTAbuildup *FA, const AirportFTAbuildup *FA,
const TileIndex *depots, const byte nof_depots) const TileIndexDiffC *depots, const byte nof_depots)
{ {
// if there are more terminals than 6, internal variables have to be changed, so don't allow that // if there are more terminals than 6, internal variables have to be changed, so don't allow that
// same goes for helipads // same goes for helipads

View File

@ -32,7 +32,7 @@ typedef struct AirportFTAClass {
byte nofhelipadgroups; // helipads belong to so many groups (MAX is the nofhelipads) byte nofhelipadgroups; // helipads belong to so many groups (MAX is the nofhelipads)
byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point
byte acc_planes; // accept airplanes or helicopters or both byte acc_planes; // accept airplanes or helicopters or both
const TileIndex *airport_depots; // gives the position of the depots on the airports const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
byte nof_depots; // number of depots this airport has byte nof_depots; // number of depots this airport has
struct AirportFTA *layout; // state machine for airport struct AirportFTA *layout; // state machine for airport
} AirportFTAClass; } AirportFTAClass;

View File

@ -263,7 +263,7 @@ static const AirportMovingData _airport_moving_data_oilrig[9] = {
/////**********Movement Machine on Airports*********************/////// /////**********Movement Machine on Airports*********************///////
// first element of depots array tells us how many depots there are (to know size of array) // first element of depots array tells us how many depots there are (to know size of array)
// this may be changed later when airports are moved to external file // this may be changed later when airports are moved to external file
static const TileIndex _airport_depots_country[] = {TILE_XY(3,0)}; static const TileIndexDiffC _airport_depots_country[] = {{3, 0}};
static const AirportFTAbuildup _airport_fta_country[] = { static const AirportFTAbuildup _airport_fta_country[] = {
{ 0,HANGAR,NOTHING_block,1}, { 0,HANGAR,NOTHING_block,1},
{ 1,255,AIRPORT_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM1,TERM1_block,2}, {1,TERM2,0,4}, {1,HELITAKEOFF,0,19}, {1,0,0,6}, { 1,255,AIRPORT_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM1,TERM1_block,2}, {1,TERM2,0,4}, {1,HELITAKEOFF,0,19}, {1,0,0,6},
@ -293,7 +293,7 @@ static const AirportFTAbuildup _airport_fta_country[] = {
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE {MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
}; };
static const TileIndex _airport_depots_city[] = {TILE_XY(5,0)}; static const TileIndexDiffC _airport_depots_city[] = {{5, 0}};
static const AirportFTAbuildup _airport_fta_city[] = { static const AirportFTAbuildup _airport_fta_city[] = {
{ 0,HANGAR,NOTHING_block,1}, {0,TAKEOFF,OUT_WAY_block,1}, {0,0,0,1}, { 0,HANGAR,NOTHING_block,1}, {0,TAKEOFF,OUT_WAY_block,1}, {0,0,0,1},
{ 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7 { 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7
@ -327,7 +327,7 @@ static const AirportFTAbuildup _airport_fta_city[] = {
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE {MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
}; };
static const TileIndex _airport_depots_metropolitan[] = {TILE_XY(5,0)}; static const TileIndexDiffC _airport_depots_metropolitan[] = {{5, 0}};
static const AirportFTAbuildup _airport_fta_metropolitan[] = { static const AirportFTAbuildup _airport_fta_metropolitan[] = {
{ 0,HANGAR,NOTHING_block,1}, { 0,HANGAR,NOTHING_block,1},
{ 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7 { 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7
@ -363,7 +363,7 @@ static const AirportFTAbuildup _airport_fta_metropolitan[] = {
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE {MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
}; };
static const TileIndex _airport_depots_international[] = {TILE_XY(0,3), TILE_XY(6,1)}; static const TileIndexDiffC _airport_depots_international[] = {{0, 3}, {6, 1}};
static const AirportFTAbuildup _airport_fta_international[] = { static const AirportFTAbuildup _airport_fta_international[] = {
{ 0,HANGAR,NOTHING_block,2}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER1_block,1}, {0,HELITAKEOFF,HELIPAD1_block,2}, {0,0,0,2}, { 0,HANGAR,NOTHING_block,2}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER1_block,1}, {0,HELITAKEOFF,HELIPAD1_block,2}, {0,0,0,2},
{ 1,HANGAR,NOTHING_block,3}, {1,255,HANGAR2_AREA_block,1}, {1,HELITAKEOFF,HELIPAD2_block,3}, {1,0,0,3}, { 1,HANGAR,NOTHING_block,3}, {1,255,HANGAR2_AREA_block,1}, {1,HELITAKEOFF,HELIPAD2_block,3}, {1,0,0,3},

View File

@ -186,12 +186,17 @@ static bool TerraformTileHeight(TerraformerState *ts, uint tile, int height)
{ {
int direction = ts->direction, r; int direction = ts->direction, r;
const TileIndexDiff *ttm; const TileIndexDiffC *ttm;
static const TileIndexDiff _terraform_tilepos[5] = {TILE_XY(1,0), TILE_XY(-2,0), TILE_XY(1,1), TILE_XY(0,-2), 0 }; static const TileIndexDiffC _terraform_tilepos[] = {
{ 1, 0},
{-2, 0},
{ 1, 1},
{ 0, -2}
};
for(ttm = _terraform_tilepos; *ttm != 0; ttm++) { for(ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
tile += *ttm; tile += ToTileIndexDiff(*ttm);
r = TerraformGetHeightOfTile(ts, tile); r = TerraformGetHeightOfTile(ts, tile);
if (r != height && r-direction != height && r+direction != height) { if (r != height && r-direction != height && r+direction != height) {

View File

@ -909,7 +909,7 @@ static void Disaster7_Init()
{ {
uint tile = i->xy; uint tile = i->xy;
int step = TileOffsByDir(Random() & 3); TileIndexDiff step = TileOffsByDir(Random() & 3);
int count = 30; int count = 30;
do { do {
DisasterClearSquare(tile); DisasterClearSquare(tile);

View File

@ -49,7 +49,7 @@ typedef struct DrawIndustrySpec4Struct {
typedef struct IndustryTileTable { typedef struct IndustryTileTable {
TileIndexDiff ti; TileIndexDiffC ti;
byte map5; byte map5;
} IndustryTileTable; } IndustryTileTable;
@ -982,7 +982,12 @@ static void MaybePlantFarmField(Industry *i)
static void ChopLumberMillTrees(Industry *i) static void ChopLumberMillTrees(Industry *i)
{ {
static const TileIndexDiff _chop_dir[4] = { TILE_XY(0,1), TILE_XY(1,0), TILE_XY(0,-1), TILE_XY(-1,0) }; static const TileIndexDiffC _chop_dir[] = {
{ 0, 1},
{ 1, 0},
{ 0, -1},
{-1, 0}
};
uint tile = i->xy; uint tile = i->xy;
int dir, a, j; int dir, a, j;
@ -1013,7 +1018,7 @@ static void ChopLumberMillTrees(Industry *i)
_current_player = old_player; _current_player = old_player;
return; return;
} }
tile += _chop_dir[dir]; tile += ToTileIndexDiff(_chop_dir[dir]);
} while (--j); } while (--j);
} }
tile -= TILE_XY(1,1); tile -= TILE_XY(1,1);
@ -1280,7 +1285,7 @@ static bool CheckIfIndustryTilesAreFree(uint tile, const IndustryTileTable *it,
_error_message = STR_0239_SITE_UNSUITABLE; _error_message = STR_0239_SITE_UNSUITABLE;
do { do {
cur_tile = tile + it->ti; cur_tile = tile + ToTileIndexDiff(it->ti);
if (!IsValidTile(cur_tile)) { if (!IsValidTile(cur_tile)) {
if (it->map5 == 0xff) if (it->map5 == 0xff)
continue; continue;
@ -1353,7 +1358,7 @@ do_clear:
} }
} }
} }
} while ( (++it)->ti != -0x8000); } while ((++it)->ti.x != -0x80);
return true; return true;
} }
@ -1456,14 +1461,14 @@ static void DoCreateNewIndustry(Industry *i, uint tile, int type, const Industry
i->prod_level = 0x10; i->prod_level = 0x10;
do { do {
cur_tile = tile + it->ti; cur_tile = tile + ToTileIndexDiff(it->ti);
if (it->map5 != 0xFF) { if (it->map5 != 0xFF) {
byte size; byte size;
size = GET_TILE_X((TileIndex)it->ti); size = it->ti.x;
if (size > i->width) i->width = size; if (size > i->width) i->width = size;
size = GET_TILE_Y((TileIndex)it->ti); size = it->ti.y;
if (size > i->height)i->height = size; if (size > i->height)i->height = size;
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
@ -1473,7 +1478,7 @@ static void DoCreateNewIndustry(Industry *i, uint tile, int type, const Industry
_map2[cur_tile] = i - _industries; _map2[cur_tile] = i - _industries;
_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */ _map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */
} }
} while ( (++it)->ti != -0x8000); } while ((++it)->ti.x != -0x80);
i->width++; i->width++;
i->height++; i->height++;

View File

@ -631,35 +631,32 @@ static void GenerateTerrain(int type, int flag)
static void CreateDesertOrRainForest() static void CreateDesertOrRainForest()
{ {
uint tile; uint tile;
const TileIndexDiff *data; const TileIndexDiffC *data;
byte mt; byte mt;
int i; int i;
tile = 0; for (tile = 0; tile != MapSize(); ++tile) {
do { for (data = _make_desert_or_rainforest_data;
data = _make_desert_or_rainforest_data; data != endof(_make_desert_or_rainforest_data); ++data) {
do { mt = _map_type_and_height[TILE_MASK(tile + ToTileIndexDiff(*data))];
if ((i = *data++) == MDORD_LAST) { if ((mt & 0xf) >= 4 || (mt >> 4) == MP_WATER) break;
SetMapExtraBits(tile, 1); }
break; if (data == endof(_make_desert_or_rainforest_data))
} SetMapExtraBits(tile, 1);
mt = _map_type_and_height[TILE_MASK(tile + i)]; }
} while ((mt & 0xC) == 0 && (mt >> 4) != MP_WATER);
} while (++tile != MapSize());
for(i=0; i!=256; i++) for(i=0; i!=256; i++)
RunTileLoop(); RunTileLoop();
tile = 0; for (tile = 0; tile != MapSize(); ++tile) {
do { for (data = _make_desert_or_rainforest_data;
data = _make_desert_or_rainforest_data; data != endof(_make_desert_or_rainforest_data); ++data) {
do { TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
if ((i = *data++) == MDORD_LAST) { if (IS_TILETYPE(t, MP_CLEAR) && (_map5[t] & 0x1c) == 0x14) break;
SetMapExtraBits(tile, 2); }
break; if (data == endof(_make_desert_or_rainforest_data))
} SetMapExtraBits(tile, 2);
} while ( !IS_TILETYPE(TILE_MASK(tile+i), MP_CLEAR) || (_map5[TILE_MASK(tile + i)]&0x1C) != 0x14); }
} while (++tile != MapSize());
} }
void GenerateLandscape() void GenerateLandscape()

10
map.c
View File

@ -15,9 +15,9 @@ byte _map_owner [MAP_SIZE];
uint16 _map2 [MAP_SIZE]; uint16 _map2 [MAP_SIZE];
byte _map_extra_bits [MAP_SIZE / 4]; byte _map_extra_bits [MAP_SIZE / 4];
const TileIndexDiff _tileoffs_by_dir[4] = { const TileIndexDiffC _tileoffs_by_dir[] = {
TILE_XY(-1, 0), {-1, 0},
TILE_XY(0, 1), { 0, 1},
TILE_XY(1, 0), { 1, 0},
TILE_XY(0, -1), { 0, -1}
}; };

13
map.h
View File

@ -26,13 +26,22 @@ static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); }
typedef int16 TileIndexDiff; typedef int16 TileIndexDiff;
typedef struct TileIndexDiffC {
int16 x;
int16 y;
} TileIndexDiffC;
static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
{
return (tidc.y << MapLogX()) + tidc.x;
}
static inline TileIndexDiff TileOffsByDir(uint dir) static inline TileIndexDiff TileOffsByDir(uint dir)
{ {
extern const TileIndexDiff _tileoffs_by_dir[4]; extern const TileIndexDiffC _tileoffs_by_dir[4];
assert(dir < lengthof(_tileoffs_by_dir)); assert(dir < lengthof(_tileoffs_by_dir));
return _tileoffs_by_dir[dir]; return ToTileIndexDiff(_tileoffs_by_dir[dir]);
} }
#endif #endif

View File

@ -385,14 +385,14 @@ static int GetBestFit1x1(int x, int y)
// get the rail in each direction // get the rail in each direction
tile = TILE_FROM_XY(x,y); tile = TILE_FROM_XY(x,y);
for(i=0; i!=5; i++) { for(i=0; i!=5; i++) {
static TileIndexDiff _tile_inc[5] = { static const TileIndexDiffC _tile_inc[] = {
TILE_XY(-1, 0), {-1 , 0 },
TILE_XY(0, 1) - TILE_XY(-1, 0), { 0 - -1, 1 - 0},
TILE_XY(1, 0) - TILE_XY(0, 1), { 1 - 0, 0 - 1},
TILE_XY(0, -1) - TILE_XY(1, 0), { 0 - 1, -1 - 0},
TILE_XY(0, 0) - TILE_XY(0, -1), { 0 - 0, 0 - -1}
}; };
tile += _tile_inc[i]; tile += ToTileIndexDiff(_tile_inc[i]);
m[i] = 0; m[i] = 0;
if (IS_TILETYPE(tile, MP_RAILWAY) && _map5[tile] < 0x80) if (IS_TILETYPE(tile, MP_RAILWAY) && _map5[tile] < 0x80)
m[i] = _map5[tile]&0x3F; m[i] = _map5[tile]&0x3F;

View File

@ -190,15 +190,15 @@ static void PlayShipSound(Vehicle *v)
SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v); SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v);
} }
static const TileIndexDiff _dock_offs[] = { static const TileIndexDiffC _dock_offs[] = {
TILE_XY(2, 0), { 2, 0},
TILE_XY(-2, 0), {-2, 0},
TILE_XY(0, 2), { 0, 2},
TILE_XY(2, 0), { 2, 0},
TILE_XY(0, -2), { 0, -2},
TILE_XY(0,0), { 0, 0},
TILE_XY(0,0), { 0, 0},
TILE_XY(0,0), { 0, 0}
}; };
static void ProcessShipOrder(Vehicle *v) static void ProcessShipOrder(Vehicle *v)
@ -245,7 +245,7 @@ static void ProcessShipOrder(Vehicle *v)
st = DEREF_STATION(order.station); st = DEREF_STATION(order.station);
if (st->dock_tile != 0) { if (st->dock_tile != 0) {
v->dest_tile = TILE_ADD(st->dock_tile, _dock_offs[_map5[st->dock_tile]-0x4B]); v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(_dock_offs[_map5[st->dock_tile]-0x4B]));
} }
} else if (order.type == OT_GOTO_DEPOT) { } else if (order.type == OT_GOTO_DEPOT) {
v->dest_tile = _depots[order.station].xy; v->dest_tile = _depots[order.station].xy;
@ -319,9 +319,9 @@ static void RecalcShipStuff(Vehicle *v)
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
} }
static const TileIndexDiff _ship_leave_depot_offs[] = { static const TileIndexDiffC _ship_leave_depot_offs[] = {
TILE_XY(-1,0), {-1, 0},
TILE_XY(0,-1), { 0, -1}
}; };
static void CheckShipLeaveDepot(Vehicle *v) static void CheckShipLeaveDepot(Vehicle *v)
@ -337,10 +337,10 @@ static void CheckShipLeaveDepot(Vehicle *v)
d = (_map5[tile]&2) ? 1 : 0; d = (_map5[tile]&2) ? 1 : 0;
// Check first side // Check first side
if (_ship_sometracks[d] & GetTileShipTrackStatus(TILE_ADD(tile,_ship_leave_depot_offs[d]))) { if (_ship_sometracks[d] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[d])))) {
m = (d==0) ? 0x101 : 0x207; m = (d==0) ? 0x101 : 0x207;
// Check second side // Check second side
} else if (_ship_sometracks[d+2] & GetTileShipTrackStatus(TILE_ADD(tile, -2*_ship_leave_depot_offs[d]))) { } else if (_ship_sometracks[d+2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[d])))) {
m = (d==0) ? 0x105 : 0x203; m = (d==0) ? 0x105 : 0x203;
} else { } else {
return; return;

View File

@ -162,20 +162,20 @@ static Station *AllocateStation()
static int CountMapSquareAround(uint tile, byte type, byte min, byte max) { static int CountMapSquareAround(uint tile, byte type, byte min, byte max) {
static const TileIndexDiff _count_square_table[7*7+1] = { static const TileIndexDiffC _count_square_table[] = {
TILE_XY(-3,-3), 1, 1, 1, 1, 1, 1, {-3, -3}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}
}; };
const TileIndexDiff *p; const TileIndexDiffC *p;
int num = 0; int num = 0;
for (p = _count_square_table; p != endof(_count_square_table); ++p) { for (p = _count_square_table; p != endof(_count_square_table); ++p) {
tile = TILE_MASK(tile + *p); tile = TILE_MASK(tile + ToTileIndexDiff(*p));
if (IS_TILETYPE(tile, type) && _map5[tile] >= min && _map5[tile] <= max) if (IS_TILETYPE(tile, type) && _map5[tile] >= min && _map5[tile] <= max)
num++; num++;
@ -1612,7 +1612,7 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
st->owner = _current_player; st->owner = _current_player;
if (_current_player == _local_player && afc->nof_depots != 0) { if (_current_player == _local_player && afc->nof_depots != 0) {
_last_built_aircraft_depot_tile = tile + afc->airport_depots[0]; _last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]);
} }
st->airport_tile = tile; st->airport_tile = tile;
@ -1682,7 +1682,7 @@ END_TILE_LOOP(tile_cur, w,h,tile)
uint i; uint i;
for (i = 0; i < afc->nof_depots; ++i) for (i = 0; i < afc->nof_depots; ++i)
DeleteWindowById(WC_VEHICLE_DEPOT, tile + afc->airport_depots[i]); DeleteWindowById(WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]));
st->airport_tile = 0; st->airport_tile = 0;
st->facilities &= ~FACIL_AIRPORT; st->facilities &= ~FACIL_AIRPORT;
@ -1779,10 +1779,11 @@ static int32 RemoveBuoy(Station *st, uint32 flags)
return _price.remove_truck_station; return _price.remove_truck_station;
} }
static const TileIndexDiff _dock_tileoffs_chkaround[4] = { static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
TILE_XY(-1,0), {-1, 0},
0,0, { 0, 0},
TILE_XY(0,-1), { 0, 0},
{ 0, -1}
}; };
static const byte _dock_w_chk[4] = { 2,1,2,1 }; static const byte _dock_w_chk[4] = { 2,1,2,1 };
static const byte _dock_h_chk[4] = { 1,2,1,2 }; static const byte _dock_h_chk[4] = { 1,2,1,2 };
@ -1831,7 +1832,8 @@ int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(STR_304B_SITE_UNSUITABLE); return_cmd_error(STR_304B_SITE_UNSUITABLE);
/* middle */ /* middle */
st = GetStationAround(tile + _dock_tileoffs_chkaround[direction], st = GetStationAround(
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
_dock_w_chk[direction], _dock_h_chk[direction], -1); _dock_w_chk[direction], _dock_h_chk[direction], -1);
if (st == CHECK_STATIONS_ERR) if (st == CHECK_STATIONS_ERR)
return CMD_ERROR; return CMD_ERROR;

View File

@ -1,7 +1,7 @@
typedef struct { typedef struct {
byte mode; byte mode;
byte attr; byte attr;
TileIndexDiff tileoffs; TileIndexDiffC tileoffs;
} AiDefaultBlockData; } AiDefaultBlockData;
typedef struct { typedef struct {
@ -20,303 +20,303 @@ typedef struct {
#define MKHDR(a,b,c,d,e) a,b,c,d,e,{ #define MKHDR(a,b,c,d,e) a,b,c,d,e,{
#define MKDEPOT(a,b) {0,a,b} #define MKDEPOT(a, b, c) {0, a, {b, c}}
#define MKSTATION(a,b) {1,a,b} #define MKSTATION(a, b, c) {1, a, {b, c}}
#define MKRAIL(a,b) {2,a,b} #define MKRAIL(a, b, c) {2, a, {b, c}}
#define MKCLRRAIL(a,b) {3,a,b} #define MKCLRRAIL(a, b, c) {3, a, {b, c}}
#define MKEND {4, 0, 0}} #define MKEND {4, 0, {0, 0}}}
static const AiDefaultRailBlock _raildata_ai_0 = { static const AiDefaultRailBlock _raildata_ai_0 = {
MKHDR(1,2,1,0,1) MKHDR(1,2,1,0,1)
MKDEPOT(2,TILE_XY(-1,1)), MKDEPOT(2, -1,1),
MKSTATION(0x15,TILE_XY(0,-1)), MKSTATION(0x15, 0,-1),
MKRAIL(0x26,TILE_XY(0,1)), MKRAIL(0x26, 0,1),
MKCLRRAIL(1,TILE_XY(0,2)), MKCLRRAIL(1, 0,2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_1 = { static const AiDefaultRailBlock _raildata_ai_1 = {
MKHDR(1,2,1,0,3) MKHDR(1,2,1,0,3)
MKDEPOT(2,TILE_XY(-1,-1)), MKDEPOT(2, -1,-1),
MKRAIL(0x26,TILE_XY(0,-1)), MKRAIL(0x26, 0,-1),
MKSTATION(0x15,TILE_XY(0,0)), MKSTATION(0x15, 0,0),
MKCLRRAIL(3,TILE_XY(0,-2)), MKCLRRAIL(3, 0,-2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_2 = { static const AiDefaultRailBlock _raildata_ai_2 = {
MKHDR(1,2,1,0,0) MKHDR(1,2,1,0,0)
MKDEPOT(1,TILE_XY(-1,-1)), MKDEPOT(1, -1,-1),
MKRAIL(0x15,TILE_XY(-1,0)), MKRAIL(0x15, -1,0),
MKSTATION(0x14,TILE_XY(0,0)), MKSTATION(0x14, 0,0),
MKCLRRAIL(0,TILE_XY(-2,0)), MKCLRRAIL(0, -2,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_3 = { static const AiDefaultRailBlock _raildata_ai_3 = {
MKHDR(1,2,1,0,2) MKHDR(1,2,1,0,2)
MKDEPOT(1,TILE_XY(1,-1)), MKDEPOT(1, 1,-1),
MKRAIL(0x15,TILE_XY(1,0)), MKRAIL(0x15, 1,0),
MKSTATION(0x14,TILE_XY(-1,0)), MKSTATION(0x14, -1,0),
MKCLRRAIL(2,TILE_XY(2,0)), MKCLRRAIL(2, 2,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_4 = { static const AiDefaultRailBlock _raildata_ai_4 = {
MKHDR(1,2,2,0,255) MKHDR(1,2,2,0,255)
MKSTATION(0x15,TILE_XY(0,0)), MKSTATION(0x15, 0,0),
MKCLRRAIL(3,TILE_XY(0,-1)), MKCLRRAIL(3, 0,-1),
MKCLRRAIL(1,TILE_XY(0,2)), MKCLRRAIL(1, 0,2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_5 = { static const AiDefaultRailBlock _raildata_ai_5 = {
MKHDR(1,2,2,0,255) MKHDR(1,2,2,0,255)
MKSTATION(0x14,TILE_XY(0,0)), MKSTATION(0x14, 0,0),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(2,TILE_XY(2,0)), MKCLRRAIL(2, 2,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_6 = { static const AiDefaultRailBlock _raildata_ai_6 = {
MKHDR(2,3,1,0,1) MKHDR(2,3,1,0,1)
MKSTATION(0x27,TILE_XY(0,-2)), MKSTATION(0x27, 0,-2),
MKRAIL(0xC2,TILE_XY(0,1)), MKRAIL(0xC2, 0,1),
MKRAIL(0xC2,TILE_XY(1,1)), MKRAIL(0xC2, 1,1),
MKRAIL(0x1A,TILE_XY(0,2)), MKRAIL(0x1A, 0,2),
MKRAIL(0x26,TILE_XY(1,2)), MKRAIL(0x26, 1,2),
MKDEPOT(3,TILE_XY(1,3)), MKDEPOT(3, 1,3),
MKCLRRAIL(1,TILE_XY(0,3)), MKCLRRAIL(1, 0,3),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_7 = { static const AiDefaultRailBlock _raildata_ai_7 = {
MKHDR(2,3,1,0,3) MKHDR(2,3,1,0,3)
MKDEPOT(1,TILE_XY(0,-3)), MKDEPOT(1, 0,-3),
MKRAIL(0x1A,TILE_XY(0,-2)), MKRAIL(0x1A, 0,-2),
MKRAIL(0x26,TILE_XY(1,-2)), MKRAIL(0x26, 1,-2),
MKRAIL(0xC2,TILE_XY(0,-1)), MKRAIL(0xC2, 0,-1),
MKRAIL(0xC2,TILE_XY(1,-1)), MKRAIL(0xC2, 1,-1),
MKSTATION(0x27,TILE_XY(0,0)), MKSTATION(0x27, 0,0),
MKCLRRAIL(3,TILE_XY(1,-3)), MKCLRRAIL(3, 1,-3),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_8 = { static const AiDefaultRailBlock _raildata_ai_8 = {
MKHDR(2,3,1,0,2) MKHDR(2,3,1,0,2)
MKSTATION(0x26,TILE_XY(-2,0)), MKSTATION(0x26, -2,0),
MKRAIL(0xC1,TILE_XY(1,0)), MKRAIL(0xC1, 1,0),
MKRAIL(0xC1,TILE_XY(1,1)), MKRAIL(0xC1, 1,1),
MKRAIL(0x29,TILE_XY(2,0)), MKRAIL(0x29, 2,0),
MKRAIL(0x15,TILE_XY(2,1)), MKRAIL(0x15, 2,1),
MKDEPOT(0,TILE_XY(3,0)), MKDEPOT(0, 3,0),
MKCLRRAIL(2,TILE_XY(3,1)), MKCLRRAIL(2, 3,1),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_9 = { static const AiDefaultRailBlock _raildata_ai_9 = {
MKHDR(2,3,1,0,0) MKHDR(2,3,1,0,0)
MKDEPOT(2,TILE_XY(-3,-1)), MKDEPOT(2, -3,-1),
MKRAIL(0x29,TILE_XY(-2,-1)), MKRAIL(0x29, -2,-1),
MKRAIL(0x15,TILE_XY(-2,0)), MKRAIL(0x15, -2,0),
MKRAIL(0xC1,TILE_XY(-1,-1)), MKRAIL(0xC1, -1,-1),
MKRAIL(0xC1,TILE_XY(-1,0)), MKRAIL(0xC1, -1,0),
MKSTATION(0x26,TILE_XY(0,-1)), MKSTATION(0x26, 0,-1),
MKCLRRAIL(0,TILE_XY(-3,0)), MKCLRRAIL(0, -3,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_10 = { static const AiDefaultRailBlock _raildata_ai_10 = {
MKHDR(2,3,2,0,255) MKHDR(2,3,2,0,255)
MKRAIL(0x1A,TILE_XY(0,-3)), MKRAIL(0x1A, 0,-3),
MKRAIL(0x20,TILE_XY(1,-3)), MKRAIL(0x20, 1,-3),
MKRAIL(0xC2,TILE_XY(0,-2)), MKRAIL(0xC2, 0,-2),
MKRAIL(0xC2,TILE_XY(1,-2)), MKRAIL(0xC2, 1,-2),
MKSTATION(0x27,TILE_XY(0,-1)), MKSTATION(0x27, 0,-1),
MKRAIL(0xC2,TILE_XY(0,2)), MKRAIL(0xC2, 0,2),
MKRAIL(0xC2,TILE_XY(1,2)), MKRAIL(0xC2, 1,2),
MKRAIL(0x1A,TILE_XY(0,3)), MKRAIL(0x1A, 0,3),
MKRAIL(0x4,TILE_XY(1,3)), MKRAIL(0x4, 1,3),
MKCLRRAIL(3,TILE_XY(0,-4)), MKCLRRAIL(3, 0,-4),
MKCLRRAIL(1,TILE_XY(0,4)), MKCLRRAIL(1, 0,4),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_11 = { static const AiDefaultRailBlock _raildata_ai_11 = {
MKHDR(2,3,2,0,255) MKHDR(2,3,2,0,255)
MKRAIL(0x29,TILE_XY(-3,0)), MKRAIL(0x29, -3,0),
MKRAIL(0x10,TILE_XY(-3,1)), MKRAIL(0x10, -3,1),
MKRAIL(0xC1,TILE_XY(-2,0)), MKRAIL(0xC1, -2,0),
MKRAIL(0xC1,TILE_XY(-2,1)), MKRAIL(0xC1, -2,1),
MKSTATION(0x26,TILE_XY(-1,0)), MKSTATION(0x26, -1,0),
MKRAIL(0xC1,TILE_XY(2,0)), MKRAIL(0xC1, 2,0),
MKRAIL(0xC1,TILE_XY(2,1)), MKRAIL(0xC1, 2,1),
MKRAIL(0x29,TILE_XY(3,0)), MKRAIL(0x29, 3,0),
MKRAIL(0x4,TILE_XY(3,1)), MKRAIL(0x4, 3,1),
MKCLRRAIL(0,TILE_XY(-4,0)), MKCLRRAIL(0, -4,0),
MKCLRRAIL(2,TILE_XY(4,0)), MKCLRRAIL(2, 4,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_12 = { static const AiDefaultRailBlock _raildata_ai_12 = {
MKHDR(2,3,2,1,3) MKHDR(2,3,2,1,3)
MKRAIL(0x88,TILE_XY(-1,-3)), MKRAIL(0x88, -1,-3),
MKRAIL(0x6,TILE_XY(0,-3)), MKRAIL(0x6, 0,-3),
MKRAIL(0x2,TILE_XY(-1,-2)), MKRAIL(0x2, -1,-2),
MKRAIL(0x42,TILE_XY(0,-2)), MKRAIL(0x42, 0,-2),
MKRAIL(0x2,TILE_XY(-1,-1)), MKRAIL(0x2, -1,-1),
MKRAIL(0x2,TILE_XY(0,-1)), MKRAIL(0x2, 0,-1),
MKRAIL(0x2,TILE_XY(-1,0)), MKRAIL(0x2, -1,0),
MKRAIL(0x2,TILE_XY(0,0)), MKRAIL(0x2, 0,0),
MKRAIL(0x82,TILE_XY(-1,1)), MKRAIL(0x82, -1,1),
MKRAIL(0x2,TILE_XY(0,1)), MKRAIL(0x2, 0,1),
MKRAIL(0xA,TILE_XY(-1,2)), MKRAIL(0xA, -1,2),
MKRAIL(0x44,TILE_XY(0,2)), MKRAIL(0x44, 0,2),
MKCLRRAIL(3,TILE_XY(0,-4)), MKCLRRAIL(3, 0,-4),
MKCLRRAIL(1,TILE_XY(-1,3)), MKCLRRAIL(1, -1,3),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_13 = { static const AiDefaultRailBlock _raildata_ai_13 = {
MKHDR(2,3,2,1,0) MKHDR(2,3,2,1,0)
MKRAIL(0x21,TILE_XY(-3,0)), MKRAIL(0x21, -3,0),
MKRAIL(0x90,TILE_XY(-3,1)), MKRAIL(0x90, -3,1),
MKRAIL(0x81,TILE_XY(-2,0)), MKRAIL(0x81, -2,0),
MKRAIL(0x1,TILE_XY(-2,1)), MKRAIL(0x1, -2,1),
MKRAIL(0x1,TILE_XY(-1,0)), MKRAIL(0x1, -1,0),
MKRAIL(0x1,TILE_XY(-1,1)), MKRAIL(0x1, -1,1),
MKRAIL(0x1,TILE_XY(0,0)), MKRAIL(0x1, 0,0),
MKRAIL(0x1,TILE_XY(0,1)), MKRAIL(0x1, 0,1),
MKRAIL(0x1,TILE_XY(1,0)), MKRAIL(0x1, 1,0),
MKRAIL(0x41,TILE_XY(1,1)), MKRAIL(0x41, 1,1),
MKRAIL(0x60,TILE_XY(2,0)), MKRAIL(0x60, 2,0),
MKRAIL(0x11,TILE_XY(2,1)), MKRAIL(0x11, 2,1),
MKCLRRAIL(0,TILE_XY(-4,0)), MKCLRRAIL(0, -4,0),
MKCLRRAIL(2,TILE_XY(3,1)), MKCLRRAIL(2, 3,1),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_14 = { static const AiDefaultRailBlock _raildata_ai_14 = {
MKHDR(2,3,2,1,1) MKHDR(2,3,2,1,1)
MKRAIL(0x88,TILE_XY(-1,-3)), MKRAIL(0x88, -1,-3),
MKRAIL(0x6,TILE_XY(0,-3)), MKRAIL(0x6, 0,-3),
MKRAIL(0x2,TILE_XY(-1,-2)), MKRAIL(0x2, -1,-2),
MKRAIL(0x42,TILE_XY(0,-2)), MKRAIL(0x42, 0,-2),
MKRAIL(0x2,TILE_XY(-1,-1)), MKRAIL(0x2, -1,-1),
MKRAIL(0x2,TILE_XY(0,-1)), MKRAIL(0x2, 0,-1),
MKRAIL(0x2,TILE_XY(-1,0)), MKRAIL(0x2, -1,0),
MKRAIL(0x2,TILE_XY(0,0)), MKRAIL(0x2, 0,0),
MKRAIL(0x82,TILE_XY(-1,1)), MKRAIL(0x82, -1,1),
MKRAIL(0x2,TILE_XY(0,1)), MKRAIL(0x2, 0,1),
MKRAIL(0xA,TILE_XY(-1,2)), MKRAIL(0xA, -1,2),
MKRAIL(0x44,TILE_XY(0,2)), MKRAIL(0x44, 0,2),
MKCLRRAIL(1,TILE_XY(-1,3)), MKCLRRAIL(1, -1,3),
MKCLRRAIL(3,TILE_XY(0,-4)), MKCLRRAIL(3, 0,-4),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_15 = { static const AiDefaultRailBlock _raildata_ai_15 = {
MKHDR(2,3,2,1,2) MKHDR(2,3,2,1,2)
MKRAIL(0x21,TILE_XY(-3,0)), MKRAIL(0x21, -3,0),
MKRAIL(0x90,TILE_XY(-3,1)), MKRAIL(0x90, -3,1),
MKRAIL(0x81,TILE_XY(-2,0)), MKRAIL(0x81, -2,0),
MKRAIL(0x1,TILE_XY(-2,1)), MKRAIL(0x1, -2,1),
MKRAIL(0x1,TILE_XY(-1,0)), MKRAIL(0x1, -1,0),
MKRAIL(0x1,TILE_XY(-1,1)), MKRAIL(0x1, -1,1),
MKRAIL(0x1,TILE_XY(0,0)), MKRAIL(0x1, 0,0),
MKRAIL(0x1,TILE_XY(0,1)), MKRAIL(0x1, 0,1),
MKRAIL(0x1,TILE_XY(1,0)), MKRAIL(0x1, 1,0),
MKRAIL(0x41,TILE_XY(1,1)), MKRAIL(0x41, 1,1),
MKRAIL(0x60,TILE_XY(2,0)), MKRAIL(0x60, 2,0),
MKRAIL(0x11,TILE_XY(2,1)), MKRAIL(0x11, 2,1),
MKCLRRAIL(2,TILE_XY(3,1)), MKCLRRAIL(2, 3,1),
MKCLRRAIL(0,TILE_XY(-4,0)), MKCLRRAIL(0, -4,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_16 = { static const AiDefaultRailBlock _raildata_ai_16 = {
MKHDR(1,3,1,0,1) MKHDR(1,3,1,0,1)
MKSTATION(0x17,TILE_XY(0,-2)), MKSTATION(0x17, 0,-2),
MKRAIL(0x1A,TILE_XY(0,1)), MKRAIL(0x1A, 0,1),
MKCLRRAIL(1,TILE_XY(0,2)), MKCLRRAIL(1, 0,2),
MKDEPOT(0,TILE_XY(1,1)), MKDEPOT(0, 1,1),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_17 = { static const AiDefaultRailBlock _raildata_ai_17 = {
MKHDR(1,3,1,0,3) MKHDR(1,3,1,0,3)
MKCLRRAIL(3,TILE_XY(0,-2)), MKCLRRAIL(3, 0,-2),
MKRAIL(0x26,TILE_XY(0,-1)), MKRAIL(0x26, 0,-1),
MKDEPOT(2,TILE_XY(-1,-1)), MKDEPOT(2, -1,-1),
MKSTATION(0x17,TILE_XY(0,0)), MKSTATION(0x17, 0,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_18 = { static const AiDefaultRailBlock _raildata_ai_18 = {
MKHDR(1,3,1,0,0) MKHDR(1,3,1,0,0)
MKCLRRAIL(0,TILE_XY(-2,0)), MKCLRRAIL(0, -2,0),
MKRAIL(0x29,TILE_XY(-1,0)), MKRAIL(0x29, -1,0),
MKDEPOT(3,TILE_XY(-1,1)), MKDEPOT(3, -1,1),
MKSTATION(0x16,TILE_XY(0,0)), MKSTATION(0x16, 0,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_19 = { static const AiDefaultRailBlock _raildata_ai_19 = {
MKHDR(1,3,1,0,2) MKHDR(1,3,1,0,2)
MKSTATION(0x16,TILE_XY(-2,0)), MKSTATION(0x16, -2,0),
MKDEPOT(2,TILE_XY(0,-1)), MKDEPOT(2, 0,-1),
MKRAIL(0x20,TILE_XY(1,-1)), MKRAIL(0x20, 1,-1),
MKRAIL(0x15,TILE_XY(1,0)), MKRAIL(0x15, 1,0),
MKCLRRAIL(2,TILE_XY(2,0)), MKCLRRAIL(2, 2,0),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_20 = { static const AiDefaultRailBlock _raildata_ai_20 = {
MKHDR(2,3,1,0,1) MKHDR(2,3,1,0,1)
MKSTATION(0x26,TILE_XY(-2,0)), MKSTATION(0x26, -2,0),
MKRAIL(0xC1,TILE_XY(1,0)), MKRAIL(0xC1, 1,0),
MKRAIL(0xC1,TILE_XY(1,1)), MKRAIL(0xC1, 1,1),
MKRAIL(0x26,TILE_XY(2,0)), MKRAIL(0x26, 2,0),
MKRAIL(0x26,TILE_XY(2,1)), MKRAIL(0x26, 2,1),
MKDEPOT(1,TILE_XY(2,-1)), MKDEPOT(1, 2,-1),
MKCLRRAIL(1,TILE_XY(2,2)), MKCLRRAIL(1, 2,2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_21 = { static const AiDefaultRailBlock _raildata_ai_21 = {
MKHDR(2,3,1,0,3) MKHDR(2,3,1,0,3)
MKDEPOT(2,TILE_XY(-3,-1)), MKDEPOT(2, -3,-1),
MKRAIL(0x3F,TILE_XY(-2,-1)), MKRAIL(0x3F, -2,-1),
MKRAIL(0x10,TILE_XY(-2,0)), MKRAIL(0x10, -2,0),
MKRAIL(0xC1,TILE_XY(-1,-1)), MKRAIL(0xC1, -1,-1),
MKRAIL(0xC1,TILE_XY(-1,0)), MKRAIL(0xC1, -1,0),
MKSTATION(0x26,TILE_XY(0,-1)), MKSTATION(0x26, 0,-1),
MKCLRRAIL(3,TILE_XY(-2,-2)), MKCLRRAIL(3, -2,-2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_22 = { static const AiDefaultRailBlock _raildata_ai_22 = {
MKHDR(2,3,1,0,0) MKHDR(2,3,1,0,0)
MKSTATION(0x27,TILE_XY(0,-2)), MKSTATION(0x27, 0,-2),
MKRAIL(0xC2,TILE_XY(0,1)), MKRAIL(0xC2, 0,1),
MKRAIL(0xC2,TILE_XY(1,1)), MKRAIL(0xC2, 1,1),
MKRAIL(0x15,TILE_XY(0,2)), MKRAIL(0x15, 0,2),
MKRAIL(0x4,TILE_XY(1,2)), MKRAIL(0x4, 1,2),
MKRAIL(0x15,TILE_XY(-1,2)), MKRAIL(0x15, -1,2),
MKDEPOT(1,TILE_XY(-1,1)), MKDEPOT(1, -1,1),
MKCLRRAIL(0,TILE_XY(-2,2)), MKCLRRAIL(0, -2,2),
MKEND MKEND
}; };
static const AiDefaultRailBlock _raildata_ai_23 = { static const AiDefaultRailBlock _raildata_ai_23 = {
MKHDR(2,3,1,0,2) MKHDR(2,3,1,0,2)
MKDEPOT(1,TILE_XY(0,-3)), MKDEPOT(1, 0,-3),
MKRAIL(0x1A,TILE_XY(0,-2)), MKRAIL(0x1A, 0,-2),
MKRAIL(0x29,TILE_XY(1,-2)), MKRAIL(0x29, 1,-2),
MKRAIL(0xC2,TILE_XY(0,-1)), MKRAIL(0xC2, 0,-1),
MKRAIL(0xC2,TILE_XY(1,-1)), MKRAIL(0xC2, 1,-1),
MKSTATION(0x27,TILE_XY(0,0)), MKSTATION(0x27, 0,0),
MKCLRRAIL(2,TILE_XY(2,-2)), MKCLRRAIL(2, 2,-2),
MKEND MKEND
}; };
@ -356,93 +356,93 @@ static const AiDefaultRailBlock * const _default_rail_track_data[] = {
static const AiDefaultRoadBlock _roaddata_ai_0 = { static const AiDefaultRoadBlock _roaddata_ai_0 = {
MKHDR(0) MKHDR(0)
MKDEPOT(2,TILE_XY(-1,1)), MKDEPOT(2, -1,1),
MKSTATION(0x2,TILE_XY(-1,0)), MKSTATION(0x2, -1,0),
MKRAIL(0xC,TILE_XY(0,0)), MKRAIL(0xC, 0,0),
MKRAIL(0x9,TILE_XY(0,1)), MKRAIL(0x9, 0,1),
MKCLRRAIL(0,TILE_XY(0,-1)), MKCLRRAIL(0, 0,-1),
MKCLRRAIL(0,TILE_XY(1,0)), MKCLRRAIL(0, 1,0),
MKCLRRAIL(0,TILE_XY(1,1)), MKCLRRAIL(0, 1,1),
MKCLRRAIL(0,TILE_XY(0,2)), MKCLRRAIL(0, 0,2),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_1 = { static const AiDefaultRoadBlock _roaddata_ai_1 = {
MKHDR(0) MKHDR(0)
MKDEPOT(1,TILE_XY(0,-1)), MKDEPOT(1, 0,-1),
MKSTATION(0x1,TILE_XY(1,-1)), MKSTATION(0x1, 1,-1),
MKRAIL(0x3,TILE_XY(0,0)), MKRAIL(0x3, 0,0),
MKRAIL(0x9,TILE_XY(1,0)), MKRAIL(0x9, 1,0),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(0,TILE_XY(0,1)), MKCLRRAIL(0, 0,1),
MKCLRRAIL(0,TILE_XY(1,1)), MKCLRRAIL(0, 1,1),
MKCLRRAIL(0,TILE_XY(2,0)), MKCLRRAIL(0, 2,0),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_2 = { static const AiDefaultRoadBlock _roaddata_ai_2 = {
MKHDR(0) MKHDR(0)
MKDEPOT(3,TILE_XY(1,1)), MKDEPOT(3, 1,1),
MKSTATION(0x3,TILE_XY(0,1)), MKSTATION(0x3, 0,1),
MKRAIL(0x6,TILE_XY(0,0)), MKRAIL(0x6, 0,0),
MKRAIL(0xC,TILE_XY(1,0)), MKRAIL(0xC, 1,0),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(0,TILE_XY(0,-1)), MKCLRRAIL(0, 0,-1),
MKCLRRAIL(0,TILE_XY(1,-1)), MKCLRRAIL(0, 1,-1),
MKCLRRAIL(0,TILE_XY(2,0)), MKCLRRAIL(0, 2,0),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_3 = { static const AiDefaultRoadBlock _roaddata_ai_3 = {
MKHDR(0) MKHDR(0)
MKDEPOT(0,TILE_XY(1,0)), MKDEPOT(0, 1,0),
MKSTATION(0x0,TILE_XY(1,1)), MKSTATION(0x0, 1,1),
MKRAIL(0x6,TILE_XY(0,0)), MKRAIL(0x6, 0,0),
MKRAIL(0x3,TILE_XY(0,1)), MKRAIL(0x3, 0,1),
MKCLRRAIL(0,TILE_XY(0,-1)), MKCLRRAIL(0, 0,-1),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(0,TILE_XY(-1,1)), MKCLRRAIL(0, -1,1),
MKCLRRAIL(0,TILE_XY(0,2)), MKCLRRAIL(0, 0,2),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_4 = { static const AiDefaultRoadBlock _roaddata_ai_4 = {
MKHDR(1) MKHDR(1)
MKSTATION(0x2,TILE_XY(-1,0)), MKSTATION(0x2, -1,0),
MKRAIL(0x8,TILE_XY(0,0)), MKRAIL(0x8, 0,0),
MKCLRRAIL(0,TILE_XY(0,-1)), MKCLRRAIL(0, 0,-1),
MKCLRRAIL(0,TILE_XY(1,0)), MKCLRRAIL(0, 1,0),
MKCLRRAIL(0,TILE_XY(0,1)), MKCLRRAIL(0, 0,1),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_5 = { static const AiDefaultRoadBlock _roaddata_ai_5 = {
MKHDR(1) MKHDR(1)
MKSTATION(0x3,TILE_XY(0,1)), MKSTATION(0x3, 0,1),
MKRAIL(0x4,TILE_XY(0,0)), MKRAIL(0x4, 0,0),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(0,TILE_XY(0,-1)), MKCLRRAIL(0, 0,-1),
MKCLRRAIL(0,TILE_XY(1,0)), MKCLRRAIL(0, 1,0),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_6 = { static const AiDefaultRoadBlock _roaddata_ai_6 = {
MKHDR(1) MKHDR(1)
MKSTATION(0x0,TILE_XY(1,1)), MKSTATION(0x0, 1,1),
MKRAIL(0x2,TILE_XY(0,1)), MKRAIL(0x2, 0,1),
MKCLRRAIL(0,TILE_XY(0,0)), MKCLRRAIL(0, 0,0),
MKCLRRAIL(0,TILE_XY(-1,0)), MKCLRRAIL(0, -1,0),
MKCLRRAIL(0,TILE_XY(0,2)), MKCLRRAIL(0, 0,2),
MKEND MKEND
}; };
static const AiDefaultRoadBlock _roaddata_ai_7 = { static const AiDefaultRoadBlock _roaddata_ai_7 = {
MKHDR(1) MKHDR(1)
MKSTATION(0x1,TILE_XY(1,-1)), MKSTATION(0x1, 1,-1),
MKRAIL(0x1,TILE_XY(1,0)), MKRAIL(0x1, 1,0),
MKCLRRAIL(0,TILE_XY(0,0)), MKCLRRAIL(0, 0,0),
MKCLRRAIL(0,TILE_XY(1,1)), MKCLRRAIL(0, 1,1),
MKCLRRAIL(0,TILE_XY(2,0)), MKCLRRAIL(0, 2,0),
MKEND MKEND
}; };
@ -459,16 +459,16 @@ static const AiDefaultRoadBlock * const _road_default_block_data[] = {
NULL NULL
}; };
#define MKAIR(a,b) {0,a,b} #define MKAIR(a, b, c) {0, a, {b, c}}
static const AiDefaultBlockData _airportdata_ai_0[] = { static const AiDefaultBlockData _airportdata_ai_0[] = {
MKAIR(1, 0), MKAIR(1, 0, 0),
{1, 0, 0}, {1, 0, {0, 0}},
}; };
static const AiDefaultBlockData _airportdata_ai_1[] = { static const AiDefaultBlockData _airportdata_ai_1[] = {
MKAIR(0, 0), MKAIR(0, 0, 0),
{1, 0, 0} {1, 0, {0, 0}}
}; };
static const AiDefaultBlockData * const _airport_default_block_data[] = { static const AiDefaultBlockData * const _airport_default_block_data[] = {

View File

@ -1,6 +1,6 @@
#define MK(x,y, m) {TILE_XY(x,y), m} #define MK(x,y, m) {{x, y}, m}
#define MKEND {-0x8000, 0} #define MKEND {{-0x80, 0}, 0}
static const IndustryTileTable _tile_table_coal_mine_0[] = { static const IndustryTileTable _tile_table_coal_mine_0[] = {
MK(1,1, 0), MK(1,1, 0),

View File

@ -1,7 +1,6 @@
#define M(x,y) TILE_XY(x,y) #define M(x,y) {x, y}
#define MDORD_LAST 99 static const TileIndexDiffC _make_desert_or_rainforest_data[] = {
static const TileIndexDiff _make_desert_or_rainforest_data[150] = {
M(-5,-6), M(-5,-6),
M(-4,-6), M(-4,-6),
M(-3,-6), M(-3,-6),
@ -150,8 +149,7 @@ static const TileIndexDiff _make_desert_or_rainforest_data[150] = {
M(6,3), M(6,3),
M(-6,2), M(-6,2),
M(3,6), M(3,6),
M(3,-6), M(3,-6)
MDORD_LAST,
}; };

View File

@ -362,17 +362,17 @@ static void ChangeTileOwner_Town(uint tile, byte old_player, byte new_player)
} }
static const TileIndexDiff _roadblock_tileadd[4+3] = { static const TileIndexDiffC _roadblock_tileadd[] = {
TILE_XY(0,-1), { 0, -1},
TILE_XY(1,0), { 1, 0},
TILE_XY(0,1), { 0, 1},
TILE_XY(-1,0), {-1, 0},
// Store the first 3 elements again. // Store the first 3 elements again.
// Lets us rotate without using &3. // Lets us rotate without using &3.
TILE_XY(0,-1), { 0, -1},
TILE_XY(1,0), { 1, 0},
TILE_XY(0,1), { 0, 1}
}; };
static void TownTickHandler(Town *t) static void TownTickHandler(Town *t)
@ -448,10 +448,10 @@ static bool IsRoadAllowedHere(uint tile, int dir)
no_slope: no_slope:
// Tile has no slope // Tile has no slope
// Disallow the road if any neighboring tile has a road. // Disallow the road if any neighboring tile has a road.
if (HASBIT(GetTownRoadMask(TILE_ADD(tile, _roadblock_tileadd[dir+1])), dir^2) || if (HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]))), dir^2) ||
HASBIT(GetTownRoadMask(TILE_ADD(tile, _roadblock_tileadd[dir+3])), dir^2) || HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]))), dir^2) ||
HASBIT(GetTownRoadMask(TILE_ADD(tile, _roadblock_tileadd[dir+1] + _roadblock_tileadd[dir+2])), dir) || HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir) ||
HASBIT(GetTownRoadMask(TILE_ADD(tile, _roadblock_tileadd[dir+3] + _roadblock_tileadd[dir+2])), dir)) HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir))
return false; return false;
// Otherwise allow // Otherwise allow
@ -556,15 +556,15 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
a = (int)Random() & 3; a = (int)Random() & 3;
} while(a == b); } while(a == b);
if (!IsRoadAllowedHere(TILE_ADD(tile,_roadblock_tileadd[a]), a)) { if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) {
// A road is not allowed to continue the randomized road, // A road is not allowed to continue the randomized road,
// return if the road we're trying to build is curved. // return if the road we're trying to build is curved.
if ( a != (b^2)) if ( a != (b^2))
return; return;
// Return if neither side of the new road is a house // Return if neither side of the new road is a house
if (!IS_TILETYPE(TILE_ADD(tile,_roadblock_tileadd[a+1]), MP_HOUSE) && if (!IS_TILETYPE(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 1])), MP_HOUSE) &&
!IS_TILETYPE(TILE_ADD(tile,_roadblock_tileadd[a+3]), MP_HOUSE)) !IS_TILETYPE(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 3])), MP_HOUSE))
return; return;
// That means that the road is only allowed if there is a house // That means that the road is only allowed if there is a house
@ -597,7 +597,7 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
return; return;
// This is the tile we will reach if we extend to this direction. // This is the tile we will reach if we extend to this direction.
tmptile = TILE_ADD(tile,_roadblock_tileadd[i]); tmptile = TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[i]));
// Don't do it if it reaches to water. // Don't do it if it reaches to water.
if (IS_WATER_TILE(tmptile)) if (IS_WATER_TILE(tmptile))
@ -708,7 +708,7 @@ static int GrowTownAtRoad(Town *t, uint tile)
// Select a random bit from the blockmask, walk a step // Select a random bit from the blockmask, walk a step
// and continue the search from there. // and continue the search from there.
do block = Random() & 3; while (!HASBIT(mask,block)); do block = Random() & 3; while (!HASBIT(mask,block));
tile += _roadblock_tileadd[block]; tile += ToTileIndexDiff(_roadblock_tileadd[block]);
// Max number of times is checked. // Max number of times is checked.
} while (--_grow_town_result >= 0); } while (--_grow_town_result >= 0);
@ -732,25 +732,24 @@ static int GenRandomRoadBits()
bool GrowTown(Town *t) bool GrowTown(Town *t)
{ {
uint tile; uint tile;
const TileIndexDiff *ptr; const TileIndexDiffC *ptr;
int offs;
TileInfo ti; TileInfo ti;
byte old_player; byte old_player;
static const TileIndexDiff _town_coord_mod[] = { static const TileIndexDiffC _town_coord_mod[] = {
TILE_XY(-1,0), {-1, 0},
TILE_XY(1,1), { 1, 1},
TILE_XY(1,-1), { 1, -1},
TILE_XY(-1,-1), {-1, -1},
TILE_XY(-1,0), {-1, 0},
TILE_XY(0,2), { 0, 2},
TILE_XY(2,0), { 2, 0},
TILE_XY(0,-2), { 0, -2},
TILE_XY(-1,-1), {-1, -1},
TILE_XY(-2,2), {-2, 2},
TILE_XY(2,2), { 2, 2},
TILE_XY(2,-2), { 2, -2},
0, { 0, 0}
}; };
// Current player is a town // Current player is a town
@ -759,23 +758,19 @@ bool GrowTown(Town *t)
// Find a road that we can base the construction on. // Find a road that we can base the construction on.
tile = t->xy; tile = t->xy;
ptr = _town_coord_mod; for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
do {
if (GetRoadBitsByTile(tile) != 0) { if (GetRoadBitsByTile(tile) != 0) {
int r = GrowTownAtRoad(t, tile); int r = GrowTownAtRoad(t, tile);
_current_player = old_player; _current_player = old_player;
return r; return r;
} }
offs = *ptr++; tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
}
tile = TILE_ADD(tile, offs);
} while (offs);
// No road available, try to build a random road block by // No road available, try to build a random road block by
// clearing some land and then building a road there. // clearing some land and then building a road there.
tile = t->xy; tile = t->xy;
ptr = _town_coord_mod; for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
do {
FindLandscapeHeightByTile(&ti, tile); FindLandscapeHeightByTile(&ti, tile);
// Only work with plain land that not already has a house with map5=0 // Only work with plain land that not already has a house with map5=0
@ -786,9 +781,8 @@ bool GrowTown(Town *t)
return true; return true;
} }
} }
offs = *ptr++; tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
tile = TILE_ADD(tile, offs); }
} while (offs != 0);
_current_player = old_player; _current_player = old_player;
return false; return false;
@ -1085,15 +1079,15 @@ static bool CheckFree2x2Area(Town *t1, uint tile)
Town *t; Town *t;
int i; int i;
static const TileIndexDiff _tile_add[4] = { static const TileIndexDiffC _tile_add[] = {
TILE_XY(0,0), {0 , 0 },
TILE_XY(0,1) - TILE_XY(0,0), {0 - 0, 1 - 0},
TILE_XY(1,0) - TILE_XY(0,1), {1 - 0, 0 - 1},
TILE_XY(1,1) - TILE_XY(1,0), {1 - 1, 1 - 0}
}; };
for(i=0; i!=4; i++) { for(i=0; i!=4; i++) {
tile += _tile_add[i]; tile += ToTileIndexDiff(_tile_add[i]);
t = ClosestTownFromTile(tile, (uint)-1); t = ClosestTownFromTile(tile, (uint)-1);
if (t1 != t) if (t1 != t)
@ -1503,41 +1497,36 @@ static bool DoBuildStatueOfCompany(uint tile)
static void TownActionBuildStatue(Town *t, int action) static void TownActionBuildStatue(Town *t, int action)
{ {
// Layouted as an outward spiral // Layouted as an outward spiral
static const TileIndexDiff _statue_tiles[] = { static const TileIndexDiffC _statue_tiles[] = {
TILE_XY(-1,0), TILE_XY(0,1), TILE_XY(1,0), TILE_XY(1,0), {-1, 0},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(-1,0), TILE_XY(-1,0), { 0, 1},
TILE_XY(-1,0), TILE_XY(0,1), TILE_XY(0,1), TILE_XY(0,1), { 1, 0}, { 1, 0},
TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), { 0,-1}, { 0,-1},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), {-1, 0}, {-1, 0}, {-1, 0},
TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), { 0, 1}, { 0, 1}, { 0, 1},
TILE_XY(-1,0), TILE_XY(0,1), TILE_XY(0,1), TILE_XY(0,1), { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
TILE_XY(0,1), TILE_XY(0,1), TILE_XY(1,0), TILE_XY(1,0), { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(-1,0), TILE_XY(-1,0), { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
TILE_XY(-1,0), TILE_XY(0,1), TILE_XY(0,1), TILE_XY(0,1), {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
TILE_XY(0,1), TILE_XY(0,1), TILE_XY(0,1), TILE_XY(0,1), { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1},
TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,0), { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), TILE_XY(0,-1), { 0, 0}
TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), };
TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0), TILE_XY(-1,0),
0,
};
int offs;
uint tile = t->xy; uint tile = t->xy;
const TileIndexDiff *p = _statue_tiles; const TileIndexDiffC *p;
SETBIT(t->statues, _current_player); SETBIT(t->statues, _current_player);
do { for (p = _statue_tiles; p != endof(_statue_tiles); ++p) {
if (DoBuildStatueOfCompany(tile)) if (DoBuildStatueOfCompany(tile))
return; return;
offs = *p++; tile = TILE_ADD(tile, ToTileIndexDiff(*p));
tile = TILE_ADD(tile, offs); }
} while (offs);
} }
static void TownActionFundBuildings(Town *t, int action) static void TownActionFundBuildings(Town *t, int action)

View File

@ -466,15 +466,15 @@ static void TileLoop_Trees(uint tile)
byte m5; byte m5;
uint16 m2; uint16 m2;
static const TileIndexDiff _tileloop_trees_dir[] = { static const TileIndexDiffC _tileloop_trees_dir[] = {
TILE_XY(-1,-1), {-1, -1},
TILE_XY(0,-1), { 0, -1},
TILE_XY(1,-1), { 1, -1},
TILE_XY(-1,0), {-1, 0},
TILE_XY(1,0), { 1, 0},
TILE_XY(-1,1), {-1, 1},
TILE_XY(0,1), { 0, 1},
TILE_XY(1,1), { 1, 1}
}; };
if (_opt.landscape == LT_DESERT) { if (_opt.landscape == LT_DESERT) {
@ -514,7 +514,7 @@ static void TileLoop_Trees(uint tile)
case 2: { /* add a neighbouring tree */ case 2: { /* add a neighbouring tree */
byte m3 = _map3_lo[tile]; byte m3 = _map3_lo[tile];
tile += _tileloop_trees_dir[Random() & 7]; tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]);
if (!IS_TILETYPE(tile, MP_CLEAR)) if (!IS_TILETYPE(tile, MP_CLEAR))
return; return;

View File

@ -224,11 +224,11 @@ static void ClickTile_Unmovable(uint tile)
} }
} }
static const TileIndexDiff _tile_add[4] = { static const TileIndexDiffC _tile_add[] = {
TILE_XY(1,0), { 1, 0},
TILE_XY(0,1), { 0, 1},
TILE_XY(-1,0), {-1, 0},
TILE_XY(0,-1), { 0, -1}
}; };
/* checks, if a radio tower is within a 9x9 tile square around tile */ /* checks, if a radio tower is within a 9x9 tile square around tile */
@ -295,7 +295,7 @@ restart:
do { do {
if (--j == 0) if (--j == 0)
goto restart; goto restart;
tile = TILE_MASK(tile + _tile_add[dir]); tile = TILE_MASK(tile + ToTileIndexDiff(_tile_add[dir]));
} while (!(IS_TILETYPE(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16)); } while (!(IS_TILETYPE(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16));
assert(tile == TILE_MASK(tile)); assert(tile == TILE_MASK(tile));

View File

@ -143,7 +143,7 @@ static int32 DoBuildShiplift(uint tile, int dir, uint32 flags)
static int32 RemoveShiplift(uint tile, uint32 flags) static int32 RemoveShiplift(uint tile, uint32 flags)
{ {
int delta = TileOffsByDir(_map5[tile] & 3); TileIndexDiff delta = TileOffsByDir(_map5[tile] & 3);
// make sure no vehicle is on the tile. // make sure no vehicle is on the tile.
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
@ -290,17 +290,17 @@ static int32 ClearTile_Water(uint tile, byte flags) {
} else if ((m5 & 0x10) == 0x10) { } else if ((m5 & 0x10) == 0x10) {
// shiplift // shiplift
static const TileIndexDiff _shiplift_tomiddle_offs[12] = { static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
0,0,0,0, // middle { 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle
TILE_XY(-1, 0),TILE_XY(0, 1),TILE_XY(1, 0),TILE_XY(0, -1), // lower {-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower
TILE_XY(1, 0),TILE_XY(0, -1),TILE_XY(-1, 0),TILE_XY(0, 1), // upper { 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper
}; };
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
// don't allow water to delete it. // don't allow water to delete it.
if (_current_player == OWNER_WATER) return CMD_ERROR; if (_current_player == OWNER_WATER) return CMD_ERROR;
// move to the middle tile.. // move to the middle tile..
return RemoveShiplift(tile + _shiplift_tomiddle_offs[m5 & 0xF], flags); return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags);
} else { } else {
// ship depot // ship depot
if (flags & DC_AUTO) if (flags & DC_AUTO)
@ -480,23 +480,24 @@ static void AnimateTile_Water(uint tile)
/* not used */ /* not used */
} }
static void TileLoopWaterHelper(uint tile, const int16 *offs) static void TileLoopWaterHelper(uint tile, const TileIndexDiffC *offs)
{ {
byte *p; byte *p;
p = &_map_type_and_height[tile]; p = &_map_type_and_height[tile];
tile += offs[0]; tile += ToTileIndexDiff(offs[0]);
// type of this tile mustn't be water already. // type of this tile mustn't be water already.
if (p[offs[0]] >> 4 == MP_WATER) if (p[ToTileIndexDiff(offs[0])] >> 4 == MP_WATER)
return; return;
if ( (p[offs[1]] | p[offs[2]]) & 0xF ) if ((p[ToTileIndexDiff(offs[1])] | p[ToTileIndexDiff(offs[2])]) & 0xF)
return; return;
if ( (p[offs[3]] | p[offs[4]]) & 0xF ) { if ((p[ToTileIndexDiff(offs[3])] | p[ToTileIndexDiff(offs[4])]) & 0xF) {
// make coast.. // make coast..
if (p[offs[0]] >> 4 == MP_CLEAR || p[offs[0]] >> 4 == MP_TREES) { if (p[ToTileIndexDiff(offs[0])] >> 4 == MP_CLEAR ||
p[ToTileIndexDiff(offs[0])] >> 4 == MP_TREES) {
_current_player = OWNER_WATER; _current_player = OWNER_WATER;
if (DoCommandByTile(tile,0,0,DC_EXEC | DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) if (DoCommandByTile(tile,0,0,DC_EXEC | DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR)
ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,1); ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,1);
@ -573,12 +574,12 @@ static void FloodVehicle(Vehicle *v)
void TileLoop_Water(uint tile) void TileLoop_Water(uint tile)
{ {
int i; int i;
static const TileIndexDiff _tile_loop_offs_array[4][5] = { static const TileIndexDiffC _tile_loop_offs_array[][5] = {
// tile to mod shore? shore? // tile to mod shore? shore?
{TILE_XY(-1,0), TILE_XY(0,0), TILE_XY(0,1), TILE_XY(-1,0), TILE_XY(-1,1)}, {{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}},
{TILE_XY(0,1), TILE_XY(0,1), TILE_XY(1,1), TILE_XY(0,2), TILE_XY(1,2)}, {{ 0, 1}, {0, 1}, {1, 1}, { 0, 2}, { 1, 2}},
{TILE_XY(1,0), TILE_XY(1,0), TILE_XY(1,1), TILE_XY(2,0), TILE_XY(2,1)}, {{ 1, 0}, {1, 0}, {1, 1}, { 2, 0}, { 2, 1}},
{TILE_XY(0,-1), TILE_XY(0,0), TILE_XY(1,0), TILE_XY(0,-1), TILE_XY(1,-1)}, {{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
}; };
if (IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1) && if (IS_INT_INSIDE(GET_TILE_X(tile), 1, MapSizeX() - 3 + 1) &&