mirror of
https://github.com/Relintai/world_generator.git
synced 2025-04-13 21:30:51 +02:00
Same change for Dungeon.
This commit is contained in:
parent
679cce8d60
commit
3f92d0b11b
231
main/dungeon.cpp
231
main/dungeon.cpp
@ -577,10 +577,6 @@ Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> inst) {
|
||||
inst->set_min_room_count(_min_room_count);
|
||||
inst->set_max_room_count(_max_room_count);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_voxel_environment(_voxel_environment);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _dungeon_rooms.size(); ++i) {
|
||||
Ref<DungeonRoom> r = _dungeon_rooms[i];
|
||||
|
||||
@ -662,6 +658,8 @@ Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> inst) {
|
||||
#endif
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_voxel_environment(_voxel_environment);
|
||||
|
||||
for (int i = 0; i < _voxel_environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _voxel_environment_datas[i];
|
||||
|
||||
@ -681,6 +679,28 @@ Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> inst) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
inst->set_terra_environment(_terra_environment);
|
||||
|
||||
for (int i = 0; i < _terra_environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _terra_environment_datas[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_terra_environment_data(d);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _terra_surfaces.size(); ++i) {
|
||||
Ref<VoxelSurface> d = _terra_surfaces[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_terra_surface(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
@ -848,6 +868,163 @@ void Dungeon::generate_voxel_structure(Ref<VoxelStructure> structure, bool spawn
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
Ref<TerraEnvironmentData> Dungeon::get_terra_environment() {
|
||||
return _terra_environment;
|
||||
}
|
||||
void Dungeon::set_terra_environment(Ref<TerraEnvironmentData> value) {
|
||||
_terra_environment = value;
|
||||
}
|
||||
|
||||
//// Surfaces ////
|
||||
Ref<TerraSurface> Dungeon::get_terra_surface(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, _terra_surfaces.size(), Ref<TerraSurface>());
|
||||
|
||||
return _terra_surfaces.get(index);
|
||||
}
|
||||
void Dungeon::set_terra_surface(const int index, const Ref<TerraSurface> terra_surface) {
|
||||
ERR_FAIL_INDEX(index, _terra_surfaces.size());
|
||||
|
||||
_terra_surfaces.set(index, terra_surface);
|
||||
}
|
||||
void Dungeon::add_terra_surface(const Ref<TerraSurface> terra_surface) {
|
||||
_terra_surfaces.push_back(terra_surface);
|
||||
}
|
||||
void Dungeon::remove_terra_surface(const int index) {
|
||||
ERR_FAIL_INDEX(index, _terra_surfaces.size());
|
||||
|
||||
_terra_surfaces.remove(index);
|
||||
}
|
||||
int Dungeon::get_terra_surface_count() const {
|
||||
return _terra_surfaces.size();
|
||||
}
|
||||
|
||||
Vector<Variant> Dungeon::get_terra_surfaces() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _terra_surfaces.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_terra_surfaces[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_terra_surfaces[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void Dungeon::set_terra_surfaces(const Vector<Variant> &terra_surfaces) {
|
||||
_terra_surfaces.clear();
|
||||
for (int i = 0; i < terra_surfaces.size(); i++) {
|
||||
Ref<EnvironmentData> terra_surface = Ref<EnvironmentData>(terra_surfaces[i]);
|
||||
|
||||
_terra_surfaces.push_back(terra_surface);
|
||||
}
|
||||
}
|
||||
|
||||
//Environments
|
||||
Ref<TerraEnvironmentData> Dungeon::get_terra_environment_data(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, _terra_environment_datas.size(), Ref<TerraEnvironmentData>());
|
||||
|
||||
return _terra_environment_datas.get(index);
|
||||
}
|
||||
void Dungeon::set_terra_environment_data(const int index, const Ref<TerraEnvironmentData> environment_data) {
|
||||
ERR_FAIL_INDEX(index, _terra_environment_datas.size());
|
||||
|
||||
_terra_environment_datas.set(index, environment_data);
|
||||
}
|
||||
void Dungeon::add_terra_environment_data(const Ref<TerraEnvironmentData> environment_data) {
|
||||
_terra_environment_datas.push_back(environment_data);
|
||||
}
|
||||
void Dungeon::remove_terra_environment_data(const int index) {
|
||||
ERR_FAIL_INDEX(index, _terra_environment_datas.size());
|
||||
|
||||
_terra_environment_datas.remove(index);
|
||||
}
|
||||
int Dungeon::get_terra_environment_data_count() const {
|
||||
return _terra_environment_datas.size();
|
||||
}
|
||||
|
||||
Vector<Variant> Dungeon::get_terra_environment_datas() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _terra_environment_datas.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_terra_environment_datas[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_terra_environment_datas[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void Dungeon::set_terra_environment_datas(const Vector<Variant> &environment_datas) {
|
||||
_terra_environment_datas.clear();
|
||||
for (int i = 0; i < environment_datas.size(); i++) {
|
||||
Ref<TerraEnvironmentData> environment_data = Ref<TerraEnvironmentData>(environment_datas[i]);
|
||||
|
||||
_terra_environment_datas.push_back(environment_data);
|
||||
}
|
||||
}
|
||||
|
||||
void Dungeon::setup_terra_library(Ref<TerramanLibrary> library) {
|
||||
if (has_method("_setup_terra_library")) {
|
||||
call("_setup_terra_library", library);
|
||||
}
|
||||
}
|
||||
|
||||
void Dungeon::_setup_terra_library(Ref<TerramanLibrary> library) {
|
||||
for (int i = 0; i < get_terra_surface_count(); ++i) {
|
||||
Ref<TerraSurface> s = get_terra_surface(i);
|
||||
|
||||
if (s.is_valid()) {
|
||||
library->voxel_surface_add(s);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_dungeon_corridor_count(); ++i) {
|
||||
Ref<DungeonCorridor> d = get_dungeon_corridor(i);
|
||||
|
||||
if (d.is_valid()) {
|
||||
d->setup_terra_library(library);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_dungeon_end_room_count(); ++i) {
|
||||
Ref<DungeonRoom> d = get_dungeon_end_room(i);
|
||||
|
||||
if (d.is_valid()) {
|
||||
d->setup_terra_library(library);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_dungeon_room_count(); ++i) {
|
||||
Ref<DungeonRoom> d = get_dungeon_room(i);
|
||||
|
||||
if (d.is_valid()) {
|
||||
d->setup_terra_library(library);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_dungeon_start_room_count(); ++i) {
|
||||
Ref<DungeonRoom> d = get_dungeon_start_room(i);
|
||||
|
||||
if (d.is_valid()) {
|
||||
d->setup_terra_library(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Dungeon::generate_terra_chunk(Ref<TerraChunk> chunk, bool spawn_mobs) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
if (has_method("_generate_terra_chunk")) {
|
||||
call("_generate_terra_chunk", chunk, spawn_mobs);
|
||||
}
|
||||
}
|
||||
|
||||
void Dungeon::generate_terra_structure(Ref<TerraStructure> structure, bool spawn_mobs) {
|
||||
if (has_method("_generate_terra_structure")) {
|
||||
call("_generate_terra_structure", structure, spawn_mobs);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Ref<Image> Dungeon::generate_map() {
|
||||
ERR_FAIL_COND_V(!has_method("_generate_map"), Ref<Image>());
|
||||
|
||||
@ -894,6 +1071,13 @@ Dungeon::~Dungeon() {
|
||||
_voxel_environment_datas.clear();
|
||||
_voxel_surfaces.clear();
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
_terra_environment.unref();
|
||||
|
||||
_terra_environment_datas.clear();
|
||||
_terra_surfaces.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dungeon::_bind_methods() {
|
||||
@ -1128,6 +1312,45 @@ void Dungeon::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurface", PROPERTY_USAGE_DEFAULT, "VoxelSurface"), "set_voxel_surfaces", "get_voxel_surfaces");
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
BIND_VMETHOD(MethodInfo("_setup_terra_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "TerramanLibrary")));
|
||||
BIND_VMETHOD(MethodInfo("_generate_terra_structure", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "TerraStructure"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
BIND_VMETHOD(MethodInfo("_generate_terra_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup_terra_library", "library"), &Dungeon::setup_terra_library);
|
||||
ClassDB::bind_method(D_METHOD("_setup_terra_library", "library"), &Dungeon::_setup_terra_library);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate_terra_chunk", "chunk", "spawn_mobs"), &Dungeon::generate_terra_chunk);
|
||||
ClassDB::bind_method(D_METHOD("generate_terra_structure", "structure", "spawn_mobs"), &Dungeon::generate_terra_structure);
|
||||
|
||||
//Environment
|
||||
ClassDB::bind_method(D_METHOD("get_terra_environment"), &Dungeon::get_terra_environment);
|
||||
ClassDB::bind_method(D_METHOD("set_terra_environment", "value"), &Dungeon::set_terra_environment);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "terra_environment", PROPERTY_HINT_RESOURCE_TYPE, "TerraEnvironmentData"), "set_terra_environment", "get_terra_environment");
|
||||
|
||||
//Environments
|
||||
ClassDB::bind_method(D_METHOD("get_terra_environment_data", "index"), &Dungeon::get_terra_environment_data);
|
||||
ClassDB::bind_method(D_METHOD("set_terra_environment_data", "index", "data"), &Dungeon::set_terra_environment_data);
|
||||
ClassDB::bind_method(D_METHOD("add_terra_environment_data", "environment_data"), &Dungeon::add_terra_environment_data);
|
||||
ClassDB::bind_method(D_METHOD("remove_terra_environment_data", "index"), &Dungeon::remove_terra_environment_data);
|
||||
ClassDB::bind_method(D_METHOD("get_terra_environment_data_count"), &Dungeon::get_terra_environment_data_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_terra_environment_datas"), &Dungeon::get_terra_environment_datas);
|
||||
ClassDB::bind_method(D_METHOD("set_terra_environment_datas", "environment_datas"), &Dungeon::set_terra_environment_datas);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "terra_environment_datas", PROPERTY_HINT_NONE, "17/17:TerraEnvironmentData", PROPERTY_USAGE_DEFAULT, "TerraEnvironmentData"), "set_terra_environment_datas", "get_terra_environment_datas");
|
||||
|
||||
//Surfaces
|
||||
ClassDB::bind_method(D_METHOD("get_terra_surface", "index"), &Dungeon::get_terra_surface);
|
||||
ClassDB::bind_method(D_METHOD("set_terra_surface", "index", "data"), &Dungeon::set_terra_surface);
|
||||
ClassDB::bind_method(D_METHOD("add_terra_surface", "terra_surface"), &Dungeon::add_terra_surface);
|
||||
ClassDB::bind_method(D_METHOD("remove_terra_surface", "index"), &Dungeon::remove_terra_surface);
|
||||
ClassDB::bind_method(D_METHOD("get_terra_surface_count"), &Dungeon::get_terra_surface_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_terra_surfaces"), &Dungeon::get_terra_surfaces);
|
||||
ClassDB::bind_method(D_METHOD("set_terra_surfaces", "terra_surfaces"), &Dungeon::set_terra_surfaces);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "terra_surfaces", PROPERTY_HINT_NONE, "17/17:TerraSurface", PROPERTY_USAGE_DEFAULT, "TerraSurface"), "set_terra_surfaces", "get_terra_surfaces");
|
||||
#endif
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "_generate_map"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate_map"), &Dungeon::generate_map);
|
||||
|
@ -41,8 +41,13 @@ SOFTWARE.
|
||||
#include "../../voxelman/world/environment_data.h"
|
||||
#include "../../voxelman/world/voxel_chunk.h"
|
||||
#include "../../voxelman/world/voxel_structure.h"
|
||||
#else
|
||||
#include "scene/main/node.h"
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
#include "../../terraman/library/terraman_library.h"
|
||||
#include "../../terraman/world/terra_environment_data.h"
|
||||
#include "../../terraman/world/terra_chunk.h"
|
||||
#include "../../terraman/world/terra_structure.h"
|
||||
#endif
|
||||
|
||||
#ifdef ESS_PRESENT
|
||||
@ -239,6 +244,38 @@ public:
|
||||
void generate_voxel_structure(Ref<VoxelStructure> structure, bool spawn_mobs);
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
//Environment
|
||||
Ref<TerraEnvironmentData> get_terra_environment();
|
||||
void set_terra_environment(Ref<TerraEnvironmentData> value);
|
||||
|
||||
//Environments
|
||||
Ref<TerraEnvironmentData> get_terra_environment_data(const int index) const;
|
||||
void set_terra_environment_data(const int index, const Ref<TerraEnvironmentData> environment_data);
|
||||
void add_terra_environment_data(const Ref<TerraEnvironmentData> environment_data);
|
||||
void remove_terra_environment_data(const int index);
|
||||
int get_terra_environment_data_count() const;
|
||||
|
||||
Vector<Variant> get_terra_environment_datas();
|
||||
void set_terra_environment_datas(const Vector<Variant> &environment_datas);
|
||||
|
||||
//Surfaces
|
||||
Ref<TerraSurface> get_terra_surface(const int index) const;
|
||||
void set_terra_surface(const int index, const Ref<TerraSurface> terra_surface);
|
||||
void add_terra_surface(const Ref<TerraSurface> terra_surface);
|
||||
void remove_terra_surface(const int index);
|
||||
int get_terra_surface_count() const;
|
||||
|
||||
Vector<Variant> get_terra_surfaces();
|
||||
void set_terra_surfaces(const Vector<Variant> &terra_surfaces);
|
||||
|
||||
void setup_terra_library(Ref<TerramanLibrary> library);
|
||||
void _setup_terra_library(Ref<TerramanLibrary> library);
|
||||
|
||||
void generate_terra_chunk(Ref<TerraChunk> chunk, bool spawn_mobs);
|
||||
void generate_terra_structure(Ref<TerraStructure> structure, bool spawn_mobs);
|
||||
#endif
|
||||
|
||||
Ref<Image> generate_map();
|
||||
|
||||
Dungeon();
|
||||
@ -294,6 +331,13 @@ private:
|
||||
Vector<Ref<EnvironmentData> > _voxel_environment_datas;
|
||||
Vector<Ref<VoxelSurface> > _voxel_surfaces;
|
||||
#endif
|
||||
|
||||
#ifdef TERRAMAN_PRESENT
|
||||
Ref<TerraEnvironmentData> _terra_environment;
|
||||
|
||||
Vector<Ref<TerraEnvironmentData> > _terra_environment_datas;
|
||||
Vector<Ref<TerraSurface> > _terra_surfaces;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user