Move files to subdirectories (#6599)
[oweals/minetest.git] / src / mapgen / 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 #pragma once
21
22 #include <matrix4.h>
23 #include "noise.h"
24
25 class MMVManip;
26 class INodeDefManager;
27 class ServerEnvironment;
28
29
30 namespace treegen {
31
32         enum error {
33                 SUCCESS,
34                 UNBALANCED_BRACKETS
35         };
36
37         struct TreeDef {
38                 std::string initial_axiom;
39                 std::string rules_a;
40                 std::string rules_b;
41                 std::string rules_c;
42                 std::string rules_d;
43
44                 MapNode trunknode;
45                 MapNode leavesnode;
46                 MapNode leaves2node;
47
48                 int leaves2_chance;
49                 int angle;
50                 int iterations;
51                 int iterations_random_level;
52                 std::string trunk_type;
53                 bool thin_branches;
54                 MapNode fruitnode;
55                 int fruit_chance;
56                 s32 seed;
57                 bool explicit_seed;
58         };
59
60         // Add default tree
61         void make_tree(MMVManip &vmanip, v3s16 p0,
62                 bool is_apple_tree, INodeDefManager *ndef, s32 seed);
63         // Add jungle tree
64         void make_jungletree(MMVManip &vmanip, v3s16 p0,
65                 INodeDefManager *ndef, s32 seed);
66         // Add pine tree
67         void make_pine_tree(MMVManip &vmanip, v3s16 p0,
68                 INodeDefManager *ndef, s32 seed);
69
70         // Add L-Systems tree (used by engine)
71         treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef,
72                 TreeDef tree_definition);
73         // Spawn L-systems tree from LUA
74         treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef,
75                 const TreeDef &tree_definition);
76
77         // L-System tree gen helper functions
78         void tree_node_placement(MMVManip &vmanip, v3f p0,
79                 MapNode node);
80         void tree_trunk_placement(MMVManip &vmanip, v3f p0,
81                 TreeDef &tree_definition);
82         void tree_leaves_placement(MMVManip &vmanip, v3f p0,
83                 PseudoRandom ps, TreeDef &tree_definition);
84         void tree_single_leaves_placement(MMVManip &vmanip, v3f p0,
85                 PseudoRandom ps, TreeDef &tree_definition);
86         void tree_fruit_placement(MMVManip &vmanip, v3f p0,
87                 TreeDef &tree_definition);
88         irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis);
89
90         v3f transposeMatrix(irr::core::matrix4 M ,v3f v);
91
92 }; // namespace treegen