38 #include "table/strings.h"
44 _tile_type_clear_procs,
45 _tile_type_rail_procs,
46 _tile_type_road_procs,
47 _tile_type_town_procs,
48 _tile_type_trees_procs,
49 _tile_type_station_procs,
50 _tile_type_water_procs,
51 _tile_type_void_procs,
52 _tile_type_industry_procs,
53 _tile_type_tunnelbridge_procs,
54 _tile_type_object_procs;
62 &_tile_type_clear_procs,
63 &_tile_type_rail_procs,
64 &_tile_type_road_procs,
65 &_tile_type_town_procs,
66 &_tile_type_trees_procs,
67 &_tile_type_station_procs,
68 &_tile_type_water_procs,
69 &_tile_type_void_procs,
70 &_tile_type_industry_procs,
71 &_tile_type_tunnelbridge_procs,
72 &_tile_type_object_procs,
77 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
78 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
124 *s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ?
SLOPE_SW :
SLOPE_NE);
128 *s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ?
SLOPE_SE :
SLOPE_NW);
139 default: NOT_REACHED();
172 default: NOT_REACHED();
258 z = 1 + ((x + y) >> 1);
262 z = 1 + ((x + (y ^ 0xF)) >> 1);
266 z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
270 z = 1 + (((x ^ 0xF) + y) >> 1);
279 int GetSlopePixelZ(
int x,
int y)
283 return _tile_type_procs[
GetTileType(tile)]->get_slope_z_proc(tile, x, y);
315 static const Slope corners[4][4] = {
325 if (halftile_test == corners[edge][0]) *z2 +=
TILE_HEIGHT;
326 if (halftile_test == corners[edge][1]) *z1 +=
TILE_HEIGHT;
328 if ((tileh & corners[edge][0]) != 0) *z1 +=
TILE_HEIGHT;
329 if ((tileh & corners[edge][1]) != 0) *z2 +=
TILE_HEIGHT;
347 if (z != NULL) *z += z_inc;
352 bool HasFoundationNW(
TileIndex tile,
Slope slope_here, uint z_here)
356 int z_W_here = z_here;
357 int z_N_here = z_here;
365 return (z_N_here > z_N) || (z_W_here > z_W);
369 bool HasFoundationNE(
TileIndex tile,
Slope slope_here, uint z_here)
373 int z_E_here = z_here;
374 int z_N_here = z_here;
382 return (z_N_here > z_N) || (z_E_here > z_E);
397 uint sprite_block = 0;
407 if (!HasFoundationNW(ti->
tile, slope, z)) sprite_block += 1;
408 if (!HasFoundationNE(ti->
tile, slope, z)) sprite_block += 2;
411 SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
412 SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
444 int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
445 int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
458 int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
459 int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
522 _tile_type_procs[
GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
537 return _snow_line != NULL;
547 _snow_line = CallocT<SnowLine>(1);
549 memcpy(_snow_line->
table, table,
sizeof(_snow_line->
table));
615 bool do_clear =
false;
647 if (do_clear) DoClearSquare(tile);
669 bool had_success =
false;
672 int limit = (c == NULL ? INT32_MAX :
GB(c->
clear_limit, 16, 16));
689 if (ret.
GetCost() > 0 && money < 0) {
690 _additional_cash_required = ret.
GetCost();
706 if (ret.
GetCost() != 0 && --limit <= 0)
break;
712 return had_success ? cost : last_error;
729 static const uint32 feedbacks[] = {
730 0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
744 _tile_type_procs[
GetTileType(0)]->tile_loop_proc(0);
749 _tile_type_procs[
GetTileType(tile)]->tile_loop_proc(tile);
752 tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback);
755 _cur_tileloop_tile = tile;
758 void InitializeLandscape()
775 for (uint x = 0; x < sizex; x++)
MakeVoid(sizex * y + x);
778 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
779 static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
781 static void GenerateTerrain(
int type, uint flag)
785 const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845,
ST_MAPGEN);
786 if (templ == NULL)
usererror(
"Map generator sprites could not be loaded");
791 if (x < 2 || y < 2)
return;
794 uint w = templ->
width;
799 const byte *p = templ->
data;
801 if ((flag & 4) != 0) {
807 default: NOT_REACHED();
809 if (xw + yw >
MapSize() - bias)
return;
813 if (yw < xw + bias)
return;
817 if (xw + yw <
MapSize() + bias)
return;
821 if (xw < yw + bias)
return;
826 if (x + w >=
MapMaxX() - 1)
return;
827 if (y + h >=
MapMaxY() - 1)
return;
832 default: NOT_REACHED();
837 for (uint w_cur = w; w_cur != 0; --w_cur) {
850 for (uint h_cur = h; h_cur != 0; --h_cur) {
864 for (uint w_cur = w; w_cur != 0; --w_cur) {
878 for (uint h_cur = h; h_cur != 0; --h_cur) {
892 static void CreateDesertOrRainForest()
903 for (data = _make_desert_or_rainforest_data;
904 data !=
endof(_make_desert_or_rainforest_data); ++data) {
908 if (data ==
endof(_make_desert_or_rainforest_data)) {
913 for (uint i = 0; i != 256; i++) {
924 for (data = _make_desert_or_rainforest_data;
925 data !=
endof(_make_desert_or_rainforest_data); ++data) {
929 if (data ==
endof(_make_desert_or_rainforest_data)) {
951 for (
int dx = -1; dx <= 1; dx++) {
952 for (
int dy = -1; dy <= 1; dy++) {
958 if (num < 4)
return false;
961 for (
int dx = -16; dx <= 16; dx++) {
962 for (
int dy = -16; dy <= 16; dy++) {
979 uint height = *(uint*)user_data;
1009 return heightEnd <= heightBegin &&
1013 ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd ==
SLOPE_FLAT || slopeBegin ==
SLOPE_FLAT);
1037 TileIndex tile = current->path.node.tile;
1039 aystar->num_neighbours = 0;
1043 aystar->neighbours[aystar->num_neighbours].tile = t2;
1045 aystar->num_neighbours++;
1053 for (
PathNode *path = ¤t->path; path != NULL; path = path->
parent) {
1085 finder.CalculateG = River_CalculateG;
1086 finder.CalculateH = River_CalculateH;
1087 finder.GetNeighbours = River_GetNeighbours;
1088 finder.EndNodeCheck = River_EndNodeCheck;
1089 finder.FoundEndNode = River_FoundEndNode;
1090 finder.user_target = &end;
1110 #define SET_MARK(x) marks.insert(x)
1111 #define IS_MARKED(x) (marks.find(x) != marks.end())
1116 std::set<TileIndex> marks;
1120 std::list<TileIndex> queue;
1121 queue.push_back(begin);
1127 end = queue.front();
1141 queue.push_back(t2);
1144 }
while (!queue.empty());
1149 }
else if (count > 32) {
1153 std::set<TileIndex>::const_iterator cit = marks.begin();
1163 lakeCenter != begin &&
1190 if (amount == 0)
return;
1195 for (; wells != 0; wells--) {
1197 for (
int tries = 0; tries < 128; tries++) {
1205 for (uint i = 0; i != 256; i++) {
1214 enum GenLandscapeSteps {
1216 GLS_TERRAGENESIS = 5,
1238 uint32 r = Random();
1241 GenerateTerrain(2, 0);
1244 uint flag =
GB(r, 7, 2) | 4;
1246 GenerateTerrain(4, flag);
1252 uint32 r = Random();
1255 GenerateTerrain(0, 0);
1258 uint flag =
GB(r, 7, 2) | 4;
1260 GenerateTerrain(0, flag);
1266 GenerateTerrain(3, flag);
1272 uint32 r = Random();
1276 for (; i != 0; --i) {
1289 ConvertGroundTilesIntoWaterTiles();
1298 void OnTick_Trees();
1299 void OnTick_Station();
1300 void OnTick_Industry();
1305 void CallLandscapeTick()