37 #include "table/strings.h"
43 _tile_type_clear_procs,
44 _tile_type_rail_procs,
45 _tile_type_road_procs,
46 _tile_type_town_procs,
47 _tile_type_trees_procs,
48 _tile_type_station_procs,
49 _tile_type_water_procs,
50 _tile_type_void_procs,
51 _tile_type_industry_procs,
52 _tile_type_tunnelbridge_procs,
53 _tile_type_object_procs;
61 &_tile_type_clear_procs,
62 &_tile_type_rail_procs,
63 &_tile_type_road_procs,
64 &_tile_type_town_procs,
65 &_tile_type_trees_procs,
66 &_tile_type_station_procs,
67 &_tile_type_water_procs,
68 &_tile_type_void_procs,
69 &_tile_type_industry_procs,
70 &_tile_type_tunnelbridge_procs,
71 &_tile_type_object_procs,
76 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
77 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
123 *s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ?
SLOPE_SW :
SLOPE_NE);
127 *s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ?
SLOPE_SE :
SLOPE_NW);
138 default: NOT_REACHED();
171 default: NOT_REACHED();
257 z = 1 + ((x + y) >> 1);
261 z = 1 + ((x + (y ^ 0xF)) >> 1);
265 z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
269 z = 1 + (((x ^ 0xF) + y) >> 1);
278 int GetSlopePixelZ(
int x,
int y)
282 return _tile_type_procs[
GetTileType(tile)]->get_slope_z_proc(tile, x, y);
314 static const Slope corners[4][4] = {
324 if (halftile_test == corners[edge][0]) *z2 +=
TILE_HEIGHT;
325 if (halftile_test == corners[edge][1]) *z1 +=
TILE_HEIGHT;
327 if ((tileh & corners[edge][0]) != 0) *z1 +=
TILE_HEIGHT;
328 if ((tileh & corners[edge][1]) != 0) *z2 +=
TILE_HEIGHT;
346 if (z != NULL) *z += z_inc;
351 bool HasFoundationNW(
TileIndex tile,
Slope slope_here, uint z_here)
355 int z_W_here = z_here;
356 int z_N_here = z_here;
364 return (z_N_here > z_N) || (z_W_here > z_W);
368 bool HasFoundationNE(
TileIndex tile,
Slope slope_here, uint z_here)
372 int z_E_here = z_here;
373 int z_N_here = z_here;
381 return (z_N_here > z_N) || (z_E_here > z_E);
396 uint sprite_block = 0;
406 if (!HasFoundationNW(ti->
tile, slope, z)) sprite_block += 1;
407 if (!HasFoundationNE(ti->
tile, slope, z)) sprite_block += 2;
410 SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
411 SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
443 int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
444 int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
457 int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
458 int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
521 _tile_type_procs[
GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
536 return _snow_line != NULL;
546 _snow_line = CallocT<SnowLine>(1);
548 memcpy(_snow_line->
table, table,
sizeof(_snow_line->
table));
614 bool do_clear =
false;
646 if (do_clear) DoClearSquare(tile);
668 bool had_success =
false;
671 int limit = (c == NULL ? INT32_MAX :
GB(c->
clear_limit, 16, 16));
688 if (ret.
GetCost() > 0 && money < 0) {
689 _additional_cash_required = ret.
GetCost();
705 if (ret.
GetCost() != 0 && --limit <= 0)
break;
711 return had_success ? cost : last_error;
728 static const uint32 feedbacks[] = {
729 0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
743 _tile_type_procs[
GetTileType(0)]->tile_loop_proc(0);
748 _tile_type_procs[
GetTileType(tile)]->tile_loop_proc(tile);
751 tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback);
754 _cur_tileloop_tile = tile;
757 void InitializeLandscape()
774 for (uint x = 0; x < sizex; x++)
MakeVoid(sizex * y + x);
777 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
778 static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
780 static void GenerateTerrain(
int type, uint flag)
784 const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845,
ST_MAPGEN);
785 if (templ == NULL)
usererror(
"Map generator sprites could not be loaded");
790 if (x < 2 || y < 2)
return;
793 uint w = templ->
width;
798 const byte *p = templ->
data;
800 if ((flag & 4) != 0) {
806 default: NOT_REACHED();
808 if (xw + yw >
MapSize() - bias)
return;
812 if (yw < xw + bias)
return;
816 if (xw + yw <
MapSize() + bias)
return;
820 if (xw < yw + bias)
return;
825 if (x + w >=
MapMaxX() - 1)
return;
826 if (y + h >=
MapMaxY() - 1)
return;
831 default: NOT_REACHED();
836 for (uint w_cur = w; w_cur != 0; --w_cur) {
849 for (uint h_cur = h; h_cur != 0; --h_cur) {
863 for (uint w_cur = w; w_cur != 0; --w_cur) {
877 for (uint h_cur = h; h_cur != 0; --h_cur) {
891 static void CreateDesertOrRainForest()
902 for (data = _make_desert_or_rainforest_data;
903 data !=
endof(_make_desert_or_rainforest_data); ++data) {
907 if (data ==
endof(_make_desert_or_rainforest_data)) {
912 for (uint i = 0; i != 256; i++) {
923 for (data = _make_desert_or_rainforest_data;
924 data !=
endof(_make_desert_or_rainforest_data); ++data) {
928 if (data ==
endof(_make_desert_or_rainforest_data)) {
950 for (
int dx = -1; dx <= 1; dx++) {
951 for (
int dy = -1; dy <= 1; dy++) {
957 if (num < 4)
return false;
960 for (
int dx = -16; dx <= 16; dx++) {
961 for (
int dy = -16; dy <= 16; dy++) {
978 uint height = *(uint*)user_data;
1008 return heightEnd <= heightBegin &&
1012 ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd ==
SLOPE_FLAT || slopeBegin ==
SLOPE_FLAT);
1036 TileIndex tile = current->path.node.tile;
1038 aystar->num_neighbours = 0;
1042 aystar->neighbours[aystar->num_neighbours].tile = t2;
1044 aystar->num_neighbours++;
1052 for (
PathNode *path = ¤t->path; path != NULL; path = path->
parent) {
1084 finder.CalculateG = River_CalculateG;
1085 finder.CalculateH = River_CalculateH;
1086 finder.GetNeighbours = River_GetNeighbours;
1087 finder.EndNodeCheck = River_EndNodeCheck;
1088 finder.FoundEndNode = River_FoundEndNode;
1089 finder.user_target = &end;
1109 #define SET_MARK(x) marks.insert(x)
1110 #define IS_MARKED(x) (marks.find(x) != marks.end())
1115 std::set<TileIndex> marks;
1119 std::list<TileIndex> queue;
1120 queue.push_back(begin);
1126 end = queue.front();
1140 queue.push_back(t2);
1143 }
while (!queue.empty());
1148 }
else if (count > 32) {
1152 std::set<TileIndex>::const_iterator cit = marks.begin();
1162 lakeCenter != begin &&
1189 if (amount == 0)
return;
1194 for (; wells != 0; wells--) {
1196 for (
int tries = 0; tries < 128; tries++) {
1204 for (uint i = 0; i != 256; i++) {
1213 enum GenLandscapeSteps {
1215 GLS_TERRAGENESIS = 5,
1237 uint32 r = Random();
1240 GenerateTerrain(2, 0);
1243 uint flag =
GB(r, 7, 2) | 4;
1245 GenerateTerrain(4, flag);
1251 uint32 r = Random();
1254 GenerateTerrain(0, 0);
1257 uint flag =
GB(r, 7, 2) | 4;
1259 GenerateTerrain(0, flag);
1265 GenerateTerrain(3, flag);
1271 uint32 r = Random();
1275 for (; i != 0; --i) {
1288 ConvertGroundTilesIntoWaterTiles();
1297 void OnTick_Trees();
1298 void OnTick_Station();
1299 void OnTick_Industry();
1304 void CallLandscapeTick()