tree_cmd.c
changeset 3183 cf71bd234ebd
parent 3144 426b825578f9
child 3271 0e796a2b7c9e
equal deleted inserted replaced
3182:0f1161388ea1 3183:cf71bd234ebd
   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(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   132 {
   132 {
       
   133 	StringID msg = INVALID_STRING_ID;
   133 	int32 cost;
   134 	int32 cost;
   134 	int sx, sy, x, y;
   135 	int sx, sy, x, y;
   135 
   136 
   136 	if (p2 >= MapSize()) return CMD_ERROR;
   137 	if (p2 >= MapSize()) return CMD_ERROR;
   137 	/* 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 */
   156 
   157 
   157 			switch (GetTileType(tile)) {
   158 			switch (GetTileType(tile)) {
   158 				case MP_TREES:
   159 				case MP_TREES:
   159 					// no more space for trees?
   160 					// no more space for trees?
   160 					if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
   161 					if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
   161 						_error_message = STR_2803_TREE_ALREADY_HERE;
   162 						msg = STR_2803_TREE_ALREADY_HERE;
   162 						continue;
   163 						continue;
   163 					}
   164 					}
   164 
   165 
   165 					if (flags & DC_EXEC) {
   166 					if (flags & DC_EXEC) {
   166 						AddTreeCount(tile, 1);
   167 						AddTreeCount(tile, 1);
   170 					cost += _price.build_trees * 2;
   171 					cost += _price.build_trees * 2;
   171 					break;
   172 					break;
   172 
   173 
   173 				case MP_CLEAR:
   174 				case MP_CLEAR:
   174 					if (!IsTileOwner(tile, OWNER_NONE)) {
   175 					if (!IsTileOwner(tile, OWNER_NONE)) {
   175 						_error_message = STR_2804_SITE_UNSUITABLE;
   176 						msg = STR_2804_SITE_UNSUITABLE;
   176 						continue;
   177 						continue;
   177 					}
   178 					}
   178 
   179 
   179 					switch (GetClearGround(tile)) {
   180 					switch (GetClearGround(tile)) {
   180 						case CL_FIELDS: cost += _price.clear_3; break;
   181 						case CL_FIELDS: cost += _price.clear_3; break;
   211 					}
   212 					}
   212 					cost += _price.build_trees;
   213 					cost += _price.build_trees;
   213 					break;
   214 					break;
   214 
   215 
   215 				default:
   216 				default:
   216 					_error_message = STR_2804_SITE_UNSUITABLE;
   217 					msg = STR_2804_SITE_UNSUITABLE;
   217 					break;
   218 					break;
   218 			}
   219 			}
   219 		}
   220 		}
   220 	}
   221 	}
   221 
   222 
   222 	return (cost == 0) ? CMD_ERROR : cost;
   223 	if (cost == 0) {
       
   224 		return_cmd_error(msg);
       
   225 	} else {
       
   226 		return cost;
       
   227 	}
   223 }
   228 }
   224 
   229 
   225 typedef struct TreeListEnt {
   230 typedef struct TreeListEnt {
   226 	uint32 image;
   231 	uint32 image;
   227 	byte x,y;
   232 	byte x,y;