ObjDefManager, Mapgen SAPI: Huge refactoring
[oweals/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 MMVManip;
30 class PseudoRandom;
31 class NodeResolver;
32
33 /////////////////// Schematic flags
34 #define SCHEM_CIDS_UPDATED 0x08
35
36
37 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
38 #define MTSCHEM_FILE_VER_HIGHEST_READ  3
39 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
40
41 #define MTSCHEM_PROB_NEVER  0x00
42 #define MTSCHEM_PROB_ALWAYS 0xFF
43
44 enum SchematicType
45 {
46         SCHEMATIC_NORMAL,
47 };
48
49
50 class Schematic : public ObjDef, public NodeResolver {
51 public:
52         std::vector<content_t> c_nodes;
53
54         u32 flags;
55         v3s16 size;
56         MapNode *schemdata;
57         u8 *slice_probs;
58
59         Schematic();
60         virtual ~Schematic();
61
62         virtual void resolveNodeNames(NodeResolveInfo *nri);
63
64         void updateContentIds();
65
66         void blitToVManip(v3s16 p, MMVManip *vm,
67                 Rotation rot, bool force_placement, INodeDefManager *ndef);
68
69         bool loadSchematicFromFile(const char *filename, INodeDefManager *ndef,
70                 StringMap *replace_names);
71         void saveSchematicToFile(const char *filename, INodeDefManager *ndef);
72         bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
73
74         void placeStructure(Map *map, v3s16 p, u32 flags,
75                 Rotation rot, bool force_placement, INodeDefManager *nef);
76         void applyProbabilities(v3s16 p0,
77                 std::vector<std::pair<v3s16, u8> > *plist,
78                 std::vector<std::pair<s16, u8> > *splist);
79 };
80
81 class SchematicManager : public ObjDefManager {
82 public:
83         SchematicManager(IGameDef *gamedef);
84         ~SchematicManager() {}
85
86         const char *getObjectTitle() const
87         {
88                 return "schematic";
89         }
90
91         static Schematic *create(SchematicType type)
92         {
93                 return new Schematic;
94         }
95 };
96
97 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
98         std::vector<content_t> *usednodes);
99
100
101 #endif