]> git.lizzy.rs Git - minetest.git/blob - src/mg_schematic.h
8a495fef2e1fec2b011219c86b5935ccae3fe96d
[minetest.git] / src / mg_schematic.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
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 MG_SCHEMATIC_HEADER
21 #define MG_SCHEMATIC_HEADER
22
23 #include <map>
24 #include "mg_decoration.h"
25 #include "util/string.h"
26
27 class Map;
28 class Mapgen;
29 class ManualMapVoxelManipulator;
30 class PseudoRandom;
31 class NodeResolver;
32
33 /////////////////// Decoration flags
34 #define DECO_PLACE_CENTER_X     1
35 #define DECO_PLACE_CENTER_Y     2
36 #define DECO_PLACE_CENTER_Z     4
37 #define DECO_SCHEM_CIDS_UPDATED 8
38
39
40 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
41 #define MTSCHEM_FILE_VER_HIGHEST_READ  3
42 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
43
44 #define MTSCHEM_PROB_NEVER  0x00
45 #define MTSCHEM_PROB_ALWAYS 0xFF
46
47 extern FlagDesc flagdesc_deco_schematic[];
48
49 class DecoSchematic : public Decoration {
50 public:
51         std::string filename;
52
53         std::vector<content_t> c_nodes;
54
55         u32 flags;
56         Rotation rotation;
57         v3s16 size;
58         MapNode *schematic;
59         u8 *slice_probs;
60
61         DecoSchematic();
62         ~DecoSchematic();
63
64         void updateContentIds();
65         virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
66         virtual int getHeight();
67         virtual std::string getName();
68
69         void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
70                                         Rotation rot, bool force_placement);
71
72         bool loadSchematicFile(NodeResolver *resolver,
73                 std::map<std::string, std::string> &replace_names);
74         void saveSchematicFile(INodeDefManager *ndef);
75
76         bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
77         void placeStructure(Map *map, v3s16 p, bool force_placement);
78         void applyProbabilities(v3s16 p0,
79                 std::vector<std::pair<v3s16, u8> > *plist,
80                 std::vector<std::pair<s16, u8> > *splist);
81 };
82
83 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
84                                         std::vector<content_t> *usednodes);
85
86
87 #endif