3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
20 #ifndef MG_SCHEMATIC_HEADER
21 #define MG_SCHEMATIC_HEADER
24 #include "mg_decoration.h"
25 #include "util/string.h"
35 Minetest Schematic File Format
37 All values are stored in big-endian byte order.
38 [u32] signature: 'MTSM'
44 [u8] slice probability value
45 [Name-ID table] Name ID Mapping Table
47 For each name-id mapping:
51 For each node in schematic: (for z, y, x)
53 For each node in schematic:
54 [u8] probability of occurance (param1)
55 For each node in schematic:
61 2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
62 3 - Added y-slice probabilities; this allows for variable height structures
65 /////////////////// Schematic flags
66 #define SCHEM_CIDS_UPDATED 0x08
68 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
69 #define MTSCHEM_FILE_VER_HIGHEST_READ 3
70 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
72 #define MTSCHEM_PROB_NEVER 0x00
73 #define MTSCHEM_PROB_ALWAYS 0xFF
80 enum SchematicFormatType {
86 class Schematic : public ObjDef, public NodeResolver {
88 std::vector<content_t> c_nodes;
98 virtual void resolveNodeNames();
100 void updateContentIds();
102 void blitToVManip(v3s16 p, MMVManip *vm,
103 Rotation rot, bool force_placement);
105 bool loadSchematicFromFile(const std::string &filename, INodeDefManager *ndef,
106 StringMap *replace_names);
107 bool saveSchematicToFile(const std::string &filename);
108 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
110 bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
111 bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
112 bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
115 void placeStructure(Map *map, v3s16 p, u32 flags,
116 Rotation rot, bool force_placement);
117 void applyProbabilities(v3s16 p0,
118 std::vector<std::pair<v3s16, u8> > *plist,
119 std::vector<std::pair<s16, u8> > *splist);
122 class SchematicManager : public ObjDefManager {
124 SchematicManager(IGameDef *gamedef);
125 virtual ~SchematicManager() {}
127 virtual void clear();
129 const char *getObjectTitle() const
134 static Schematic *create(SchematicType type)
136 return new Schematic;
143 void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount,
144 std::vector<std::string> *usednodes, INodeDefManager *ndef);