summaryrefslogtreecommitdiff
path: root/tree_cmd.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2005-05-09 22:33:00 +0000
committerDarkvater <Darkvater@openttd.org>2005-05-09 22:33:00 +0000
commit6d349b6284f2d7fe65517b03bb310eb508eb3d3a (patch)
treeadf0a3467d8519f1ef67e90a0a06731ea8c4dc1a /tree_cmd.c
parentf9fdddb0ad04bb3e1c441884696b08182b82e447 (diff)
downloadopenttd-6d349b6284f2d7fe65517b03bb310eb508eb3d3a.tar.xz
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
- CodeChange: changed the airport gui airport-type checking. Added function GetValidAirports() that returns bitmasked availibility, is also used for checking. - CodeChange: to check tree-planting, 2 const arrays have been moved to table/tree_land.h (type and count) - CodeChange: added IsTownIndex() in following of IsStationIndex(), etc. - Fix (regression): road tunnels did not work anymore, forgot that their type was 0x200 (documented now)
Diffstat (limited to 'tree_cmd.c')
-rw-r--r--tree_cmd.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/tree_cmd.c b/tree_cmd.c
index a29663d6f..921878ece 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "ttd.h"
#include "table/strings.h"
+#include "table/tree_land.h"
#include "map.h"
#include "tile.h"
#include "viewport.h"
@@ -142,11 +143,11 @@ void GenerateTrees(void)
} while (--i);
}
-/* Plant a tree
- * p1 = tree type, -1 means random.
- * p2 = end tile
+/** Plant a tree.
+ * @param x,y start tile of area-drag of tree plantation
+ * @param p1 tree type, -1 means random.
+ * @param p2 end tile of area-drag
*/
-
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
{
int32 cost;
@@ -155,7 +156,9 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
int x;
int y;
- if (p2 >= MapSize()) return CMD_ERROR;
+ if (p2 > MapSize()) return CMD_ERROR;
+ /* 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);
@@ -254,8 +257,7 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
}
}
- if (cost == 0) return CMD_ERROR;
- return cost;
+ return (cost == 0) ? CMD_ERROR : cost;
}
typedef struct TreeListEnt {
@@ -263,10 +265,6 @@ typedef struct TreeListEnt {
byte x,y;
} TreeListEnt;
-
-#include "table/tree_land.h"
-
-
static void DrawTile_Trees(TileInfo *ti)
{
uint16 m2;