src/tree_cmd.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
--- a/src/tree_cmd.cpp	Fri Nov 23 16:59:30 2007 +0000
+++ b/src/tree_cmd.cpp	Wed Jan 09 18:11:12 2008 +0000
@@ -9,18 +9,19 @@
 #include "table/strings.h"
 #include "table/sprites.h"
 #include "table/tree_land.h"
-#include "functions.h"
-#include "map.h"
+#include "tile_cmd.h"
 #include "landscape.h"
-#include "tile.h"
 #include "tree_map.h"
-#include "viewport.h"
-#include "command.h"
+#include "viewport_func.h"
+#include "command_func.h"
+#include "economy_func.h"
 #include "town.h"
-#include "sound.h"
 #include "variables.h"
 #include "genworld.h"
 #include "transparency.h"
+#include "functions.h"
+#include "player.h"
+#include "sound_func.h"
 
 /**
  * List of tree placer algorithm.
@@ -164,7 +165,7 @@
 			continue;
 
 		/* Not too much height difference */
-		if (delta(GetTileZ(cur_tile), height) > 2) continue;
+		if (Delta(GetTileZ(cur_tile), height) > 2) continue;
 
 		/* Place one tree and quit */
 		PlaceTree(cur_tile, r);
@@ -272,7 +273,7 @@
 CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	StringID msg = INVALID_STRING_ID;
-	CommandCost cost;
+	CommandCost cost(EXPENSES_OTHER);
 	int ex;
 	int ey;
 	int sx, sy, x, y;
@@ -281,8 +282,6 @@
 	/* Check the tree type. It can be random or some valid value within the current climate */
 	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
 
-	SET_EXPENSES_TYPE(EXPENSES_OTHER);
-
 	// make sure sx,sy are smaller than ex,ey
 	ex = TileX(tile);
 	ey = TileY(tile);
@@ -324,21 +323,20 @@
 					}
 
 					switch (GetClearGround(tile)) {
-						case CLEAR_FIELDS: cost.AddCost(_price.clear_3); break;
-						case CLEAR_ROCKS:  cost.AddCost(_price.clear_2); break;
+						case CLEAR_FIELDS: cost.AddCost(_price.clear_fields); break;
+						case CLEAR_ROCKS:  cost.AddCost(_price.clear_rocks); break;
 						default: break;
 					}
 
+					if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
+						Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
+						if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
+					}
+
 					if (flags & DC_EXEC) {
 						TreeType treetype;
 						uint growth;
 
-						if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
-							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
-							if (t != NULL)
-								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
-						}
-
 						treetype = (TreeType)p1;
 						if (treetype == TREE_INVALID) {
 							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
@@ -354,7 +352,7 @@
 						}
 						MarkTileDirtyByTile(tile);
 
-						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS))
+						if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS))
 							SetTropicZone(tile, TROPICZONE_RAINFOREST);
 					}
 					cost.AddCost(_price.build_trees);
@@ -418,7 +416,7 @@
 		/* different tree styles above one of the grounds */
 		if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT &&
 				GetTreeDensity(ti->tile) >= 2 &&
-				IS_INT_INSIDE(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
+				IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
 			index += 164 - (TREE_SUB_ARCTIC << 2);
 		}
 
@@ -487,18 +485,17 @@
 {
 	uint num;
 
-	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
+	if (IsValidPlayer(_current_player)) {
 		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
-		if (t != NULL)
-			ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
+		if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
 	}
 
 	num = GetTreeCount(tile) + 1;
-	if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
+	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
 
 	if (flags & DC_EXEC) DoClearSquare(tile);
 
-	return CommandCost(num * _price.remove_trees);
+	return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees);
 }
 
 static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
@@ -510,7 +507,7 @@
 {
 	TreeType tt = GetTreeType(tile);
 
-	if (IS_INT_INSIDE(tt, TREE_RAINFOREST, TREE_CACTUS)) {
+	if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
 		td->str = STR_280F_RAINFOREST;
 	} else {
 		td->str = tt == TREE_CACTUS ? STR_2810_CACTUS_PLANTS : STR_280E_TREES;
@@ -543,7 +540,7 @@
 			};
 			uint32 r = Random();
 
-			if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
+			if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
 			break;
 		}
 
@@ -567,7 +564,7 @@
 		} else {
 			if (GetTreeDensity(tile) == 3) {
 				uint32 r = Random();
-				if (CHANCE16I(1, 200, r)) {
+				if (Chance16I(1, 200, r)) {
 					SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
 				}
 			}