minetest/src/mg_decoration.h

139 lines
3.1 KiB
C
Raw Normal View History

2014-11-01 18:16:23 +01:00
/*
Minetest
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.
*/
#pragma once
2014-11-01 18:16:23 +01:00
#include <unordered_set>
#include "objdef.h"
#include "noise.h"
#include "nodedef.h"
2014-11-01 18:16:23 +01:00
class Mapgen;
class MMVManip;
class PcgRandom;
class Schematic;
2014-11-01 18:16:23 +01:00
enum DecorationType {
DECO_SIMPLE,
DECO_SCHEMATIC,
DECO_LSYSTEM
};
#define DECO_PLACE_CENTER_X 0x01
#define DECO_PLACE_CENTER_Y 0x02
#define DECO_PLACE_CENTER_Z 0x04
#define DECO_USE_NOISE 0x08
#define DECO_FORCE_PLACEMENT 0x10
#define DECO_LIQUID_SURFACE 0x20
extern FlagDesc flagdesc_deco[];
class Decoration : public ObjDef, public NodeResolver {
2014-11-01 18:16:23 +01:00
public:
Decoration() = default;
virtual ~Decoration() = default;
virtual void resolveNodeNames();
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
size_t placeDeco(Mapgen *mg, u32 blockseed,
v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
virtual int getHeight() = 0;
2014-11-01 18:16:23 +01:00
u32 flags = 0;
int mapseed = 0;
2014-11-01 18:16:23 +01:00
std::vector<content_t> c_place_on;
s16 sidelen = 1;
s16 y_min;
s16 y_max;
float fill_ratio = 0.0f;
NoiseParams np;
std::vector<content_t> c_spawnby;
s16 nspawnby;
2014-11-01 18:16:23 +01:00
std::unordered_set<u8> biomes;
2014-11-01 18:16:23 +01:00
};
2014-11-01 18:16:23 +01:00
class DecoSimple : public Decoration {
public:
virtual void resolveNodeNames();
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
virtual int getHeight();
2014-11-01 18:16:23 +01:00
std::vector<content_t> c_decos;
s16 deco_height;
s16 deco_height_max;
u8 deco_param2;
2014-11-01 18:16:23 +01:00
};
class DecoSchematic : public Decoration {
public:
DecoSchematic() = default;
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
virtual int getHeight();
Rotation rotation;
s16 place_offset_y = 0;
Schematic *schematic = nullptr;
};
2014-11-01 18:16:23 +01:00
/*
class DecoLSystem : public Decoration {
public:
virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
};
*/
class DecorationManager : public ObjDefManager {
public:
DecorationManager(IGameDef *gamedef);
virtual ~DecorationManager() = default;
const char *getObjectTitle() const
{
return "decoration";
}
static Decoration *create(DecorationType type)
{
switch (type) {
case DECO_SIMPLE:
return new DecoSimple;
case DECO_SCHEMATIC:
return new DecoSchematic;
//case DECO_LSYSTEM:
// return new DecoLSystem;
default:
return NULL;
}
}
size_t placeAllDecos(Mapgen *mg, u32 blockseed,
v3s16 nmin, v3s16 nmax, s16 deco_zero_level = 0);
};