2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
// Copyright (C) 2015-2018 paramat
|
2014-11-01 13:16:23 -04:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2014-11-01 13:16:23 -04:00
|
|
|
|
2017-06-04 21:00:04 +02:00
|
|
|
#include <unordered_set>
|
2015-05-18 22:30:25 -04:00
|
|
|
#include "objdef.h"
|
|
|
|
#include "noise.h"
|
|
|
|
#include "nodedef.h"
|
2014-11-01 13:16:23 -04:00
|
|
|
|
2020-05-20 22:16:14 +01:00
|
|
|
typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
|
|
|
|
|
2014-11-01 13:16:23 -04:00
|
|
|
class Mapgen;
|
2015-01-05 02:42:27 -05:00
|
|
|
class MMVManip;
|
2015-11-08 23:40:18 -05:00
|
|
|
class PcgRandom;
|
2014-11-12 23:01:13 -05:00
|
|
|
class Schematic;
|
2024-03-12 20:10:28 +01:00
|
|
|
namespace treegen { struct TreeDef; }
|
2014-11-01 13:16:23 -04:00
|
|
|
|
|
|
|
enum DecorationType {
|
|
|
|
DECO_SIMPLE,
|
|
|
|
DECO_SCHEMATIC,
|
|
|
|
DECO_LSYSTEM
|
|
|
|
};
|
|
|
|
|
2015-03-05 01:53:11 +00:00
|
|
|
#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
|
2015-10-21 08:51:59 +01:00
|
|
|
#define DECO_LIQUID_SURFACE 0x20
|
2017-10-11 01:06:40 +01:00
|
|
|
#define DECO_ALL_FLOORS 0x40
|
|
|
|
#define DECO_ALL_CEILINGS 0x80
|
2014-11-12 23:01:13 -05:00
|
|
|
|
2014-12-10 00:56:44 -05:00
|
|
|
extern FlagDesc flagdesc_deco[];
|
2014-11-12 23:01:13 -05:00
|
|
|
|
|
|
|
|
2015-03-30 23:40:35 -04:00
|
|
|
class Decoration : public ObjDef, public NodeResolver {
|
2014-11-01 13:16:23 -04:00
|
|
|
public:
|
2017-08-18 18:18:25 +02:00
|
|
|
Decoration() = default;
|
|
|
|
virtual ~Decoration() = default;
|
2015-04-17 00:52:48 -04:00
|
|
|
|
|
|
|
virtual void resolveNodeNames();
|
|
|
|
|
2016-09-11 23:34:43 +01:00
|
|
|
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
|
2017-09-17 00:26:20 +01:00
|
|
|
size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
2015-04-17 00:52:48 -04:00
|
|
|
|
2017-10-11 01:06:40 +01:00
|
|
|
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
|
2014-11-01 13:16:23 -04:00
|
|
|
|
2017-06-18 19:55:15 +02:00
|
|
|
u32 flags = 0;
|
|
|
|
int mapseed = 0;
|
2014-11-01 13:16:23 -04:00
|
|
|
std::vector<content_t> c_place_on;
|
2017-06-18 19:55:15 +02:00
|
|
|
s16 sidelen = 1;
|
2014-12-30 01:48:20 -05:00
|
|
|
s16 y_min;
|
|
|
|
s16 y_max;
|
2017-06-18 19:55:15 +02:00
|
|
|
float fill_ratio = 0.0f;
|
2014-12-10 00:56:44 -05:00
|
|
|
NoiseParams np;
|
2016-09-11 23:34:43 +01:00
|
|
|
std::vector<content_t> c_spawnby;
|
|
|
|
s16 nspawnby;
|
2017-10-09 20:13:10 +01:00
|
|
|
s16 place_offset_y = 0;
|
2023-01-17 17:19:35 +01:00
|
|
|
s16 check_offset = -1;
|
2014-11-01 13:16:23 -04:00
|
|
|
|
2020-05-20 22:16:14 +01:00
|
|
|
std::unordered_set<biome_t> biomes;
|
2020-04-09 23:40:12 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void cloneTo(Decoration *def) const;
|
2014-11-01 13:16:23 -04:00
|
|
|
};
|
|
|
|
|
2017-09-06 22:20:09 +01:00
|
|
|
|
2014-11-01 13:16:23 -04:00
|
|
|
class DecoSimple : public Decoration {
|
|
|
|
public:
|
2020-04-09 23:40:12 +02:00
|
|
|
ObjDef *clone() const;
|
|
|
|
|
2016-09-11 23:34:43 +01:00
|
|
|
virtual void resolveNodeNames();
|
2017-10-11 01:06:40 +01:00
|
|
|
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
|
2015-04-17 00:52:48 -04:00
|
|
|
|
2014-11-01 13:16:23 -04:00
|
|
|
std::vector<content_t> c_decos;
|
|
|
|
s16 deco_height;
|
|
|
|
s16 deco_height_max;
|
2016-12-06 16:39:33 -08:00
|
|
|
u8 deco_param2;
|
2017-10-08 21:08:52 +01:00
|
|
|
u8 deco_param2_max;
|
2014-11-01 13:16:23 -04:00
|
|
|
};
|
|
|
|
|
2017-09-06 22:20:09 +01:00
|
|
|
|
2014-11-12 23:01:13 -05:00
|
|
|
class DecoSchematic : public Decoration {
|
|
|
|
public:
|
2020-04-09 23:40:12 +02:00
|
|
|
ObjDef *clone() const;
|
|
|
|
|
2017-08-18 18:18:25 +02:00
|
|
|
DecoSchematic() = default;
|
2020-04-10 02:05:20 +02:00
|
|
|
virtual ~DecoSchematic();
|
2014-11-12 23:01:13 -05:00
|
|
|
|
2017-10-11 01:06:40 +01:00
|
|
|
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
|
2015-04-17 00:52:48 -04:00
|
|
|
|
|
|
|
Rotation rotation;
|
2017-06-18 19:55:15 +02:00
|
|
|
Schematic *schematic = nullptr;
|
2020-04-10 02:05:20 +02:00
|
|
|
bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
|
2014-11-12 23:01:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-11-01 13:16:23 -04:00
|
|
|
class DecoLSystem : public Decoration {
|
|
|
|
public:
|
2024-03-12 20:10:28 +01:00
|
|
|
ObjDef *clone() const;
|
|
|
|
|
|
|
|
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
|
|
|
|
|
|
|
|
// In case it gets cloned it uses the same tree def.
|
|
|
|
std::shared_ptr<treegen::TreeDef> tree_def;
|
2014-11-01 13:16:23 -04:00
|
|
|
};
|
|
|
|
|
2017-09-06 22:20:09 +01:00
|
|
|
|
2015-03-30 23:40:35 -04:00
|
|
|
class DecorationManager : public ObjDefManager {
|
2014-11-12 23:01:13 -05:00
|
|
|
public:
|
2014-12-12 14:07:49 -05:00
|
|
|
DecorationManager(IGameDef *gamedef);
|
2017-08-18 18:18:25 +02:00
|
|
|
virtual ~DecorationManager() = default;
|
2014-11-12 23:01:13 -05:00
|
|
|
|
2020-04-09 23:40:12 +02:00
|
|
|
DecorationManager *clone() const;
|
|
|
|
|
2015-03-30 23:40:35 -04:00
|
|
|
const char *getObjectTitle() const
|
|
|
|
{
|
|
|
|
return "decoration";
|
|
|
|
}
|
|
|
|
|
2015-03-31 23:27:19 -04:00
|
|
|
static Decoration *create(DecorationType type)
|
2014-11-12 23:01:13 -05:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case DECO_SIMPLE:
|
|
|
|
return new DecoSimple;
|
|
|
|
case DECO_SCHEMATIC:
|
|
|
|
return new DecoSchematic;
|
2024-03-12 20:10:28 +01:00
|
|
|
case DECO_LSYSTEM:
|
|
|
|
return new DecoLSystem;
|
2014-11-12 23:01:13 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 00:26:20 +01:00
|
|
|
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
2020-04-09 23:40:12 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
DecorationManager() {};
|
2014-11-12 23:01:13 -05:00
|
|
|
};
|