tree_cmd.c
changeset 2118 aec8042f000b
parent 2088 d7a97ef74701
child 2148 542ea702738c
equal deleted inserted replaced
2117:252c514583de 2118:aec8042f000b
   130  * @param p2 end tile of area-drag
   130  * @param p2 end tile of area-drag
   131  */
   131  */
   132 int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   132 int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   133 {
   133 {
   134 	int32 cost;
   134 	int32 cost;
   135 	int sx;
   135 	int sx, sy, x, y;
   136 	int sy;
       
   137 	int x;
       
   138 	int y;
       
   139 
   136 
   140 	if (p2 > MapSize()) return CMD_ERROR;
   137 	if (p2 > MapSize()) return CMD_ERROR;
   141 	/* Check the tree type. It can be random or some valid value within the current climate */
   138 	/* Check the tree type. It can be random or some valid value within the current climate */
   142 	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
   139 	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
   143 
   140 
   144 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   141 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
   145 
   142 
   146 	// make sure sx,sy are smaller than ex,ey
   143 	// make sure sx,sy are smaller than ex,ey
   147 	sx = TileX(p2) * 16;
   144 	sx = TileX(p2);
   148 	sy = TileY(p2) * 16;
   145 	sy = TileY(p2);
       
   146 	ex /= 16; ey /= 16;
   149 	if (ex < sx) intswap(ex, sx);
   147 	if (ex < sx) intswap(ex, sx);
   150 	if (ey < sy) intswap(ey, sy);
   148 	if (ey < sy) intswap(ey, sy);
   151 
   149 
   152 	cost = 0; // total cost
   150 	cost = 0; // total cost
   153 
   151 
   154 	for (x = sx; x <= ex; x += 16) {
   152 	for (x = sx; x <= ex; x++) {
   155 		for (y = sy; y <= ey; y += 16) {
   153 		for (y = sy; y <= ey; y++) {
   156 			TileIndex tile = TileXY(x, y);
   154 			TileIndex tile = TileXY(x, y);
   157 
   155 
   158 			if (!EnsureNoVehicle(tile)) continue;
   156 			if (!EnsureNoVehicle(tile)) continue;
   159 
   157 
   160 			switch (GetTileType(tile)) {
   158 			switch (GetTileType(tile)) {