122 PlaceTreesRandomly(); |
122 PlaceTreesRandomly(); |
123 } |
123 } |
124 } |
124 } |
125 |
125 |
126 /** Plant a tree. |
126 /** Plant a tree. |
127 * @param x,y start tile of area-drag of tree plantation |
127 * @param tile start tile of area-drag of tree plantation |
128 * @param p1 tree type, -1 means random. |
128 * @param p1 tree type, -1 means random. |
129 * @param p2 end tile of area-drag |
129 * @param p2 end tile of area-drag |
130 */ |
130 */ |
131 int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
131 int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
132 { |
132 { |
133 StringID msg = INVALID_STRING_ID; |
133 StringID msg = INVALID_STRING_ID; |
134 int32 cost; |
134 int32 cost; |
|
135 int ex; |
|
136 int ey; |
135 int sx, sy, x, y; |
137 int sx, sy, x, y; |
136 |
138 |
137 if (p2 >= MapSize()) return CMD_ERROR; |
139 if (p2 >= MapSize()) return CMD_ERROR; |
138 /* Check the tree type. It can be random or some valid value within the current climate */ |
140 /* Check the tree type. It can be random or some valid value within the current climate */ |
139 if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR; |
141 if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR; |
140 |
142 |
141 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
143 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
142 |
144 |
143 // make sure sx,sy are smaller than ex,ey |
145 // make sure sx,sy are smaller than ex,ey |
|
146 ex = TileX(tile); |
|
147 ey = TileY(tile); |
144 sx = TileX(p2); |
148 sx = TileX(p2); |
145 sy = TileY(p2); |
149 sy = TileY(p2); |
146 ex /= TILE_SIZE; |
|
147 ey /= TILE_SIZE; |
|
148 if (ex < sx) intswap(ex, sx); |
150 if (ex < sx) intswap(ex, sx); |
149 if (ey < sy) intswap(ey, sy); |
151 if (ey < sy) intswap(ey, sy); |
150 |
152 |
151 cost = 0; // total cost |
153 cost = 0; // total cost |
152 |
154 |