Change internal type for seeds to s32
[oweals/minetest.git] / src / treegen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>,
4                           2012-2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef TREEGEN_HEADER
21 #define TREEGEN_HEADER
22
23 #include <matrix4.h>
24 #include "noise.h"
25
26 class MMVManip;
27 class INodeDefManager;
28 class ServerEnvironment;
29
30
31 namespace treegen {
32
33         enum error {
34                 SUCCESS,
35                 UNBALANCED_BRACKETS
36         };
37
38         struct TreeDef {
39                 std::string initial_axiom;
40                 std::string rules_a;
41                 std::string rules_b;
42                 std::string rules_c;
43                 std::string rules_d;
44
45                 MapNode trunknode;
46                 MapNode leavesnode;
47                 MapNode leaves2node;
48
49                 int leaves2_chance;
50                 int angle;
51                 int iterations;
52                 int iterations_random_level;
53                 std::string trunk_type;
54                 bool thin_branches;
55                 MapNode fruitnode;
56                 int fruit_chance;
57                 s32 seed;
58                 bool explicit_seed;
59         };
60
61         // Add default tree
62         void make_tree(MMVManip &vmanip, v3s16 p0,
63                 bool is_apple_tree, INodeDefManager *ndef, s32 seed);
64         // Add jungle tree
65         void make_jungletree(MMVManip &vmanip, v3s16 p0,
66                 INodeDefManager *ndef, s32 seed);
67         // Add pine tree
68         void make_pine_tree(MMVManip &vmanip, v3s16 p0,
69                 INodeDefManager *ndef, s32 seed);
70
71         // Add L-Systems tree (used by engine)
72         treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef,
73                 TreeDef tree_definition);
74         // Spawn L-systems tree from LUA
75         treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef,
76                 TreeDef tree_definition);
77
78         // L-System tree gen helper functions
79         void tree_node_placement(MMVManip &vmanip, v3f p0,
80                 MapNode node);
81         void tree_trunk_placement(MMVManip &vmanip, v3f p0,
82                 TreeDef &tree_definition);
83         void tree_leaves_placement(MMVManip &vmanip, v3f p0,
84                 PseudoRandom ps, TreeDef &tree_definition);
85         void tree_single_leaves_placement(MMVManip &vmanip, v3f p0,
86                 PseudoRandom ps, TreeDef &tree_definition);
87         void tree_fruit_placement(MMVManip &vmanip, v3f p0,
88                 TreeDef &tree_definition);
89         irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis);
90
91         v3f transposeMatrix(irr::core::matrix4 M ,v3f v);
92
93 }; // namespace treegen
94 #endif