3 Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2018 paramat
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "mg_decoration.h"
25 #include "util/string.h"
36 Minetest Schematic File Format
38 All values are stored in big-endian byte order.
39 [u32] signature: 'MTSM'
45 [u8] slice probability value
46 [Name-ID table] Name ID Mapping Table
48 For each name-id mapping:
52 For each node in schematic: (for z, y, x)
54 For each node in schematic:
57 bit 7: specific node force placement
58 For each node in schematic:
64 2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
65 3 - Added y-slice probabilities; this allows for variable height structures
66 4 - Compressed range of node occurence prob., added per-node force placement bit
69 //// Schematic constants
70 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
71 #define MTSCHEM_FILE_VER_HIGHEST_READ 4
72 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 4
74 #define MTSCHEM_PROB_MASK 0x7F
76 #define MTSCHEM_PROB_NEVER 0x00
77 #define MTSCHEM_PROB_ALWAYS 0x7F
78 #define MTSCHEM_PROB_ALWAYS_OLD 0xFF
80 #define MTSCHEM_FORCE_PLACE 0x80
87 enum SchematicFormatType {
93 class Schematic : public ObjDef, public NodeResolver {
98 ObjDef *clone() const;
100 virtual void resolveNodeNames();
102 bool loadSchematicFromFile(const std::string &filename,
103 const NodeDefManager *ndef, StringMap *replace_names = NULL);
104 bool saveSchematicToFile(const std::string &filename,
105 const NodeDefManager *ndef);
106 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
108 bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
109 bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
110 bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
111 bool use_comments, u32 indent_spaces);
113 void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
114 bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
115 void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);
117 void applyProbabilities(v3s16 p0,
118 std::vector<std::pair<v3s16, u8> > *plist,
119 std::vector<std::pair<s16, u8> > *splist);
121 std::vector<content_t> c_nodes;
124 MapNode *schemdata = nullptr;
125 u8 *slice_probs = nullptr;
128 class SchematicManager : public ObjDefManager {
130 SchematicManager(Server *server);
131 virtual ~SchematicManager() = default;
133 SchematicManager *clone() const;
135 virtual void clear();
137 const char *getObjectTitle() const
142 static Schematic *create(SchematicType type)
144 return new Schematic;
148 SchematicManager() {};
153 void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount,
154 std::vector<std::string> *usednodes, const NodeDefManager *ndef);