src/tree_cmd.cpp
branchNewGRF_ports
changeset 6720 35756db7e577
parent 6719 4cc327ad39d5
child 6743 cabfaa4a0295
equal deleted inserted replaced
6719:4cc327ad39d5 6720:35756db7e577
   211  * @param tile start tile of area-drag of tree plantation
   211  * @param tile start tile of area-drag of tree plantation
   212  * @param flags type of operation
   212  * @param flags type of operation
   213  * @param p1 tree type, -1 means random.
   213  * @param p1 tree type, -1 means random.
   214  * @param p2 end tile of area-drag
   214  * @param p2 end tile of area-drag
   215  */
   215  */
   216 int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   216 CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   217 {
   217 {
   218 	StringID msg = INVALID_STRING_ID;
   218 	StringID msg = INVALID_STRING_ID;
   219 	int32 cost;
   219 	CommandCost cost;
   220 	int ex;
   220 	int ex;
   221 	int ey;
   221 	int ey;
   222 	int sx, sy, x, y;
   222 	int sx, sy, x, y;
   223 
   223 
   224 	if (p2 >= MapSize()) return CMD_ERROR;
   224 	if (p2 >= MapSize()) return CMD_ERROR;
   233 	sx = TileX(p2);
   233 	sx = TileX(p2);
   234 	sy = TileY(p2);
   234 	sy = TileY(p2);
   235 	if (ex < sx) Swap(ex, sx);
   235 	if (ex < sx) Swap(ex, sx);
   236 	if (ey < sy) Swap(ey, sy);
   236 	if (ey < sy) Swap(ey, sy);
   237 
   237 
   238 	cost = 0; // total cost
       
   239 
       
   240 	for (x = sx; x <= ex; x++) {
   238 	for (x = sx; x <= ex; x++) {
   241 		for (y = sy; y <= ey; y++) {
   239 		for (y = sy; y <= ey; y++) {
   242 			TileIndex tile = TileXY(x, y);
   240 			TileIndex tile = TileXY(x, y);
   243 
   241 
   244 			switch (GetTileType(tile)) {
   242 			switch (GetTileType(tile)) {
   252 					if (flags & DC_EXEC) {
   250 					if (flags & DC_EXEC) {
   253 						AddTreeCount(tile, 1);
   251 						AddTreeCount(tile, 1);
   254 						MarkTileDirtyByTile(tile);
   252 						MarkTileDirtyByTile(tile);
   255 					}
   253 					}
   256 					/* 2x as expensive to add more trees to an existing tile */
   254 					/* 2x as expensive to add more trees to an existing tile */
   257 					cost += _price.build_trees * 2;
   255 					cost.AddCost(_price.build_trees * 2);
   258 					break;
   256 					break;
   259 
   257 
   260 				case MP_CLEAR:
   258 				case MP_CLEAR:
   261 					if (!IsTileOwner(tile, OWNER_NONE) ||
   259 					if (!IsTileOwner(tile, OWNER_NONE) ||
   262 							IsBridgeAbove(tile)) {
   260 							IsBridgeAbove(tile)) {
   263 						msg = STR_2804_SITE_UNSUITABLE;
   261 						msg = STR_2804_SITE_UNSUITABLE;
   264 						continue;
   262 						continue;
   265 					}
   263 					}
   266 
   264 
   267 					switch (GetClearGround(tile)) {
   265 					switch (GetClearGround(tile)) {
   268 						case CLEAR_FIELDS: cost += _price.clear_3; break;
   266 						case CLEAR_FIELDS: cost.AddCost(_price.clear_3); break;
   269 						case CLEAR_ROCKS:  cost += _price.clear_2; break;
   267 						case CLEAR_ROCKS:  cost.AddCost(_price.clear_2); break;
   270 						default: break;
   268 						default: break;
   271 					}
   269 					}
   272 
   270 
   273 					if (flags & DC_EXEC) {
   271 					if (flags & DC_EXEC) {
   274 						TreeType treetype;
   272 						TreeType treetype;
   295 						MarkTileDirtyByTile(tile);
   293 						MarkTileDirtyByTile(tile);
   296 
   294 
   297 						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS))
   295 						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS))
   298 							SetTropicZone(tile, TROPICZONE_RAINFOREST);
   296 							SetTropicZone(tile, TROPICZONE_RAINFOREST);
   299 					}
   297 					}
   300 					cost += _price.build_trees;
   298 					cost.AddCost(_price.build_trees);
   301 					break;
   299 					break;
   302 
   300 
   303 				default:
   301 				default:
   304 					msg = STR_2804_SITE_UNSUITABLE;
   302 					msg = STR_2804_SITE_UNSUITABLE;
   305 					break;
   303 					break;
   306 			}
   304 			}
   307 		}
   305 		}
   308 	}
   306 	}
   309 
   307 
   310 	if (cost == 0) {
   308 	if (cost.GetCost() == 0) {
   311 		return_cmd_error(msg);
   309 		return_cmd_error(msg);
   312 	} else {
   310 	} else {
   313 		return cost;
   311 		return cost;
   314 	}
   312 	}
   315 }
   313 }
   426 static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
   424 static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh)
   427 {
   425 {
   428 	return tileh;
   426 	return tileh;
   429 }
   427 }
   430 
   428 
   431 static int32 ClearTile_Trees(TileIndex tile, byte flags)
   429 static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
   432 {
   430 {
   433 	uint num;
   431 	uint num;
   434 
   432 
   435 	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
   433 	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
   436 		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   434 		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   441 	num = GetTreeCount(tile) + 1;
   439 	num = GetTreeCount(tile) + 1;
   442 	if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
   440 	if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
   443 
   441 
   444 	if (flags & DC_EXEC) DoClearSquare(tile);
   442 	if (flags & DC_EXEC) DoClearSquare(tile);
   445 
   443 
   446 	return num * _price.remove_trees;
   444 	return CommandCost(num * _price.remove_trees);
   447 }
   445 }
   448 
   446 
   449 static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
   447 static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
   450 {
   448 {
   451 	/* not used */
   449 	/* not used */