3 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2017 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.
21 #ifndef MG_SCHEMATIC_HEADER
22 #define MG_SCHEMATIC_HEADER
25 #include "mg_decoration.h"
26 #include "util/string.h"
37 Minetest Schematic File Format
39 All values are stored in big-endian byte order.
40 [u32] signature: 'MTSM'
46 [u8] slice probability value
47 [Name-ID table] Name ID Mapping Table
49 For each name-id mapping:
53 For each node in schematic: (for z, y, x)
55 For each node in schematic:
58 bit 7: specific node force placement
59 For each node in schematic:
65 2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
66 3 - Added y-slice probabilities; this allows for variable height structures
67 4 - Compressed range of node occurence prob., added per-node force placement bit
70 //// Schematic constants
71 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
72 #define MTSCHEM_FILE_VER_HIGHEST_READ 4
73 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 4
75 #define MTSCHEM_PROB_MASK 0x7F
77 #define MTSCHEM_PROB_NEVER 0x00
78 #define MTSCHEM_PROB_ALWAYS 0x7F
79 #define MTSCHEM_PROB_ALWAYS_OLD 0xFF
81 #define MTSCHEM_FORCE_PLACE 0x80
88 enum SchematicFormatType {
94 class Schematic : public ObjDef, public NodeResolver {
99 virtual void resolveNodeNames();
101 bool loadSchematicFromFile(const std::string &filename, INodeDefManager *ndef,
102 StringMap *replace_names=NULL);
103 bool saveSchematicToFile(const std::string &filename, INodeDefManager *ndef);
104 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
106 bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
107 bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
108 bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
109 bool use_comments, u32 indent_spaces);
111 void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
112 bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
113 void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);
115 void applyProbabilities(v3s16 p0,
116 std::vector<std::pair<v3s16, u8> > *plist,
117 std::vector<std::pair<s16, u8> > *splist);
119 std::vector<content_t> c_nodes;
122 MapNode *schemdata = nullptr;
123 u8 *slice_probs = nullptr;
126 class SchematicManager : public ObjDefManager {
128 SchematicManager(Server *server);
129 virtual ~SchematicManager() {}
131 virtual void clear();
133 const char *getObjectTitle() const
138 static Schematic *create(SchematicType type)
140 return new Schematic;
147 void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount,
148 std::vector<std::string> *usednodes, INodeDefManager *ndef);