2014-11-01 18:16:23 +01:00
|
|
|
/*
|
|
|
|
Minetest
|
2017-05-25 19:53:47 +02:00
|
|
|
Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
Copyright (C) 2015-2017 paramat
|
2014-11-01 18:16:23 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2014-11-01 18:16:23 +01:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "mg_decoration.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
|
|
|
class Map;
|
2016-12-10 19:02:44 +01:00
|
|
|
class ServerMap;
|
2014-11-01 18:16:23 +01:00
|
|
|
class Mapgen;
|
2015-01-05 08:42:27 +01:00
|
|
|
class MMVManip;
|
2014-11-01 18:16:23 +01:00
|
|
|
class PseudoRandom;
|
|
|
|
class NodeResolver;
|
2017-01-09 20:39:22 +01:00
|
|
|
class Server;
|
2014-11-01 18:16:23 +01:00
|
|
|
|
2015-04-12 22:40:50 +02:00
|
|
|
/*
|
|
|
|
Minetest Schematic File Format
|
|
|
|
|
|
|
|
All values are stored in big-endian byte order.
|
|
|
|
[u32] signature: 'MTSM'
|
2015-05-09 07:38:20 +02:00
|
|
|
[u16] version: 4
|
2015-04-12 22:40:50 +02:00
|
|
|
[u16] size X
|
|
|
|
[u16] size Y
|
|
|
|
[u16] size Z
|
|
|
|
For each Y:
|
|
|
|
[u8] slice probability value
|
|
|
|
[Name-ID table] Name ID Mapping Table
|
|
|
|
[u16] name-id count
|
|
|
|
For each name-id mapping:
|
|
|
|
[u16] name length
|
|
|
|
[u8[]] name
|
|
|
|
ZLib deflated {
|
|
|
|
For each node in schematic: (for z, y, x)
|
|
|
|
[u16] content
|
|
|
|
For each node in schematic:
|
2015-05-09 07:38:20 +02:00
|
|
|
[u8] param1
|
|
|
|
bit 0-6: probability
|
|
|
|
bit 7: specific node force placement
|
2015-04-12 22:40:50 +02:00
|
|
|
For each node in schematic:
|
|
|
|
[u8] param2
|
|
|
|
}
|
|
|
|
|
|
|
|
Version changes:
|
|
|
|
1 - Initial version
|
|
|
|
2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
|
|
|
|
3 - Added y-slice probabilities; this allows for variable height structures
|
2015-05-09 07:38:20 +02:00
|
|
|
4 - Compressed range of node occurence prob., added per-node force placement bit
|
2015-04-12 22:40:50 +02:00
|
|
|
*/
|
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Schematic constants
|
2014-11-01 18:16:23 +01:00
|
|
|
#define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
|
2015-05-09 07:38:20 +02:00
|
|
|
#define MTSCHEM_FILE_VER_HIGHEST_READ 4
|
|
|
|
#define MTSCHEM_FILE_VER_HIGHEST_WRITE 4
|
|
|
|
|
|
|
|
#define MTSCHEM_PROB_MASK 0x7F
|
|
|
|
|
|
|
|
#define MTSCHEM_PROB_NEVER 0x00
|
|
|
|
#define MTSCHEM_PROB_ALWAYS 0x7F
|
|
|
|
#define MTSCHEM_PROB_ALWAYS_OLD 0xFF
|
2014-11-01 18:16:23 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
#define MTSCHEM_FORCE_PLACE 0x80
|
2014-11-01 18:16:23 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
enum SchematicType
|
|
|
|
{
|
|
|
|
SCHEMATIC_NORMAL,
|
|
|
|
};
|
|
|
|
|
2015-04-12 22:40:50 +02:00
|
|
|
enum SchematicFormatType {
|
|
|
|
SCHEM_FMT_HANDLE,
|
|
|
|
SCHEM_FMT_MTS,
|
|
|
|
SCHEM_FMT_LUA,
|
|
|
|
};
|
2014-11-01 18:16:23 +01:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
class Schematic : public ObjDef, public NodeResolver {
|
2014-11-01 18:16:23 +01:00
|
|
|
public:
|
2014-11-13 05:01:13 +01:00
|
|
|
Schematic();
|
2014-12-17 09:20:17 +01:00
|
|
|
virtual ~Schematic();
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
virtual void resolveNodeNames();
|
2014-11-01 18:16:23 +01:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
bool loadSchematicFromFile(const std::string &filename, INodeDefManager *ndef,
|
2015-05-08 06:05:08 +02:00
|
|
|
StringMap *replace_names=NULL);
|
|
|
|
bool saveSchematicToFile(const std::string &filename, INodeDefManager *ndef);
|
2014-11-01 18:16:23 +01:00
|
|
|
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
|
2014-11-13 05:01:13 +01:00
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
|
|
|
|
bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
|
|
|
|
bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
|
2015-05-07 08:54:30 +02:00
|
|
|
bool use_comments, u32 indent_spaces);
|
2015-04-12 22:40:50 +02:00
|
|
|
|
2015-11-04 09:33:12 +01:00
|
|
|
void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
|
|
|
|
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
|
2016-12-10 19:02:44 +01:00
|
|
|
void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);
|
2015-05-08 06:05:08 +02:00
|
|
|
|
2014-11-01 18:16:23 +01:00
|
|
|
void applyProbabilities(v3s16 p0,
|
|
|
|
std::vector<std::pair<v3s16, u8> > *plist,
|
|
|
|
std::vector<std::pair<s16, u8> > *splist);
|
2015-05-08 06:05:08 +02:00
|
|
|
|
|
|
|
std::vector<content_t> c_nodes;
|
2017-06-18 19:55:15 +02:00
|
|
|
u32 flags = 0;
|
2015-05-08 06:05:08 +02:00
|
|
|
v3s16 size;
|
2017-06-18 19:55:15 +02:00
|
|
|
MapNode *schemdata = nullptr;
|
|
|
|
u8 *slice_probs = nullptr;
|
2014-11-01 18:16:23 +01:00
|
|
|
};
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
class SchematicManager : public ObjDefManager {
|
2014-11-13 05:01:13 +01:00
|
|
|
public:
|
2017-01-09 20:39:22 +01:00
|
|
|
SchematicManager(Server *server);
|
2017-08-18 18:18:25 +02:00
|
|
|
virtual ~SchematicManager() = default;
|
2015-04-17 06:52:48 +02:00
|
|
|
|
|
|
|
virtual void clear();
|
2014-11-13 05:01:13 +01:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
const char *getObjectTitle() const
|
|
|
|
{
|
|
|
|
return "schematic";
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
static Schematic *create(SchematicType type)
|
2014-11-13 05:01:13 +01:00
|
|
|
{
|
|
|
|
return new Schematic;
|
|
|
|
}
|
2015-04-17 06:52:48 +02:00
|
|
|
|
|
|
|
private:
|
2017-01-09 20:39:22 +01:00
|
|
|
Server *m_server;
|
2014-11-13 05:01:13 +01:00
|
|
|
};
|
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount,
|
|
|
|
std::vector<std::string> *usednodes, INodeDefManager *ndef);
|