src/town_cmd.cpp
changeset 7684 a79c09246c27
parent 7666 69cabc700c4d
child 7709 439dcda6d74b
equal deleted inserted replaced
7683:13e6fb7baa57 7684:a79c09246c27
    96 }
    96 }
    97 
    97 
    98 // Local
    98 // Local
    99 static int _grow_town_result;
    99 static int _grow_town_result;
   100 
   100 
       
   101 /* Describe the possible states */
       
   102 enum TownGrowthResult {
       
   103 	GROWTH_SUCCEED         = -1,
       
   104 	GROWTH_SEARCH_STOPPED  =  0
       
   105 //	GROWTH_SEARCH_RUNNING >=  1
       
   106 };
       
   107 
   101 static bool BuildTownHouse(Town *t, TileIndex tile);
   108 static bool BuildTownHouse(Town *t, TileIndex tile);
   102 static void DoBuildTownHouse(Town *t, TileIndex tile);
   109 static void DoBuildTownHouse(Town *t, TileIndex tile);
   103 
   110 
   104 static void TownDrawHouseLift(const TileInfo *ti)
   111 static void TownDrawHouseLift(const TileInfo *ti)
   105 {
   112 {
   859 		if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++;
   866 		if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++;
   860 
   867 
   861 		/* If there are enough neighbors stop here */
   868 		/* If there are enough neighbors stop here */
   862 		if (counter >= 3) {
   869 		if (counter >= 3) {
   863 			if (BuildTownHouse(t, tile)) {
   870 			if (BuildTownHouse(t, tile)) {
   864 				_grow_town_result = -1;
   871 				_grow_town_result = GROWTH_SUCCEED;
   865 				return true;
   872 				return true;
   866 			}
   873 			}
   867 			return false;
   874 			return false;
   868 		}
   875 		}
   869 	}
   876 	}
   879  * @return true if the RoadBits have been added else false
   886  * @return true if the RoadBits have been added else false
   880  */
   887  */
   881 static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
   888 static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
   882 {
   889 {
   883 	if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
   890 	if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
   884 		_grow_town_result = -1;
   891 		_grow_town_result = GROWTH_SUCCEED;
   885 		return true;
   892 		return true;
   886 	}
   893 	}
   887 	return false;
   894 	return false;
   888 }
   895 }
   889 
   896 
   934 		byte bridge_type = RandomRange(MAX_BRIDGES - 1);
   941 		byte bridge_type = RandomRange(MAX_BRIDGES - 1);
   935 
   942 
   936 		/* Can we actually build the bridge? */
   943 		/* Can we actually build the bridge? */
   937 		if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) {
   944 		if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) {
   938 			DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
   945 			DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
   939 			_grow_town_result--;
   946 			_grow_town_result = GROWTH_SUCCEED;
   940 			return true;
   947 			return true;
   941 		}
   948 		}
   942 	}
   949 	}
   943 	/* Quit if it selecting an appropiate bridge type fails a large number of times. */
   950 	/* Quit if it selecting an appropiate bridge type fails a large number of times. */
   944 	return false;
   951 	return false;
   970 	TILE_ASSERT(tile);
   977 	TILE_ASSERT(tile);
   971 
   978 
   972 	if (cur_rb == ROAD_NONE) {
   979 	if (cur_rb == ROAD_NONE) {
   973 		/* Tile has no road. First reset the status counter
   980 		/* Tile has no road. First reset the status counter
   974 		 * to say that this is the last iteration. */
   981 		 * to say that this is the last iteration. */
   975 		_grow_town_result = 0;
   982 		_grow_town_result = GROWTH_SEARCH_STOPPED;
   976 
   983 
   977 		/* Remove hills etc */
   984 		/* Remove hills etc */
   978 		LevelTownLand(tile);
   985 		LevelTownLand(tile);
   979 
   986 
   980 		/* Is a road allowed here? */
   987 		/* Is a road allowed here? */
  1022 
  1029 
  1023 	} else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) {
  1030 	} else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) {
  1024 		/* Continue building on a partial road.
  1031 		/* Continue building on a partial road.
  1025 		 * Should be allways OK, so we only generate
  1032 		 * Should be allways OK, so we only generate
  1026 		 * the fitting RoadBits */
  1033 		 * the fitting RoadBits */
  1027 		_grow_town_result = 0;
  1034 		_grow_town_result = GROWTH_SEARCH_STOPPED;
  1028 
  1035 
  1029 		switch (_patches.town_layout) {
  1036 		switch (_patches.town_layout) {
  1030 			default: NOT_REACHED();
  1037 			default: NOT_REACHED();
  1031 
  1038 
  1032 			case TL_NO_ROADS: /* Disallow Roads */
  1039 			case TL_NO_ROADS: /* Disallow Roads */
  1101 				LevelTownLand(house_tile);
  1108 				LevelTownLand(house_tile);
  1102 
  1109 
  1103 				/* And build a house.
  1110 				/* And build a house.
  1104 				 * Set result to -1 if we managed to build it. */
  1111 				 * Set result to -1 if we managed to build it. */
  1105 				if (BuildTownHouse(t1, house_tile)) {
  1112 				if (BuildTownHouse(t1, house_tile)) {
  1106 					_grow_town_result = -1;
  1113 					_grow_town_result = GROWTH_SUCCEED;
  1107 				}
  1114 				}
  1108 			}
  1115 			}
  1109 			return;
  1116 			return;
  1110 		}
  1117 		}
  1111 
  1118 
  1112 		_grow_town_result = 0;
  1119 		_grow_town_result = GROWTH_SEARCH_STOPPED;
  1113 	}
  1120 	}
  1114 
  1121 
  1115 	/* Return if a water tile */
  1122 	/* Return if a water tile */
  1116 	if (IsClearWaterTile(tile)) return;
  1123 	if (IsClearWaterTile(tile)) return;
  1117 
  1124 
  1174 		tile = TileAddByDiagDir(tile, target_dir);
  1181 		tile = TileAddByDiagDir(tile, target_dir);
  1175 
  1182 
  1176 		if (IsTileType(tile, MP_ROAD)) {
  1183 		if (IsTileType(tile, MP_ROAD)) {
  1177 			/* Don't allow building over roads of other cities */
  1184 			/* Don't allow building over roads of other cities */
  1178 			if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) {
  1185 			if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) {
  1179 				_grow_town_result = -1;
  1186 				_grow_town_result = GROWTH_SUCCEED;
  1180 			} else if (_game_mode == GM_EDITOR) {
  1187 			} else if (_game_mode == GM_EDITOR) {
  1181 				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
  1188 				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
  1182 				 * owner :) (happy happy happy road now) */
  1189 				 * owner :) (happy happy happy road now) */
  1183 				SetTileOwner(tile, OWNER_TOWN);
  1190 				SetTileOwner(tile, OWNER_TOWN);
  1184 				SetTownIndex(tile, t->index);
  1191 				SetTownIndex(tile, t->index);