diff --git a/main/dungeon.cpp b/main/dungeon.cpp index 23e2c2b..fd2121c 100644 --- a/main/dungeon.cpp +++ b/main/dungeon.cpp @@ -577,10 +577,6 @@ Ref Dungeon::_instance(const int seed, Ref 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 r = _dungeon_rooms[i]; @@ -662,6 +658,8 @@ Ref Dungeon::_instance(const int seed, Ref inst) { #endif #ifdef VOXELMAN_PRESENT + inst->set_voxel_environment(_voxel_environment); + for (int i = 0; i < _voxel_environment_datas.size(); ++i) { Ref d = _voxel_environment_datas[i]; @@ -681,6 +679,28 @@ Ref Dungeon::_instance(const int seed, Ref inst) { } #endif +#ifdef TERRAMAN_PRESENT + inst->set_terra_environment(_terra_environment); + + for (int i = 0; i < _terra_environment_datas.size(); ++i) { + Ref 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 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 structure, bool spawn } #endif +#ifdef TERRAMAN_PRESENT +Ref Dungeon::get_terra_environment() { + return _terra_environment; +} +void Dungeon::set_terra_environment(Ref value) { + _terra_environment = value; +} + +//// Surfaces //// +Ref Dungeon::get_terra_surface(const int index) const { + ERR_FAIL_INDEX_V(index, _terra_surfaces.size(), Ref()); + + return _terra_surfaces.get(index); +} +void Dungeon::set_terra_surface(const int index, const Ref terra_surface) { + ERR_FAIL_INDEX(index, _terra_surfaces.size()); + + _terra_surfaces.set(index, terra_surface); +} +void Dungeon::add_terra_surface(const Ref 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 Dungeon::get_terra_surfaces() { + Vector 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 &terra_surfaces) { + _terra_surfaces.clear(); + for (int i = 0; i < terra_surfaces.size(); i++) { + Ref terra_surface = Ref(terra_surfaces[i]); + + _terra_surfaces.push_back(terra_surface); + } +} + +//Environments +Ref Dungeon::get_terra_environment_data(const int index) const { + ERR_FAIL_INDEX_V(index, _terra_environment_datas.size(), Ref()); + + return _terra_environment_datas.get(index); +} +void Dungeon::set_terra_environment_data(const int index, const Ref 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 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 Dungeon::get_terra_environment_datas() { + Vector 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 &environment_datas) { + _terra_environment_datas.clear(); + for (int i = 0; i < environment_datas.size(); i++) { + Ref environment_data = Ref(environment_datas[i]); + + _terra_environment_datas.push_back(environment_data); + } +} + +void Dungeon::setup_terra_library(Ref library) { + if (has_method("_setup_terra_library")) { + call("_setup_terra_library", library); + } +} + +void Dungeon::_setup_terra_library(Ref library) { + for (int i = 0; i < get_terra_surface_count(); ++i) { + Ref 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 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 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 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 d = get_dungeon_start_room(i); + + if (d.is_valid()) { + d->setup_terra_library(library); + } + } +} + +void Dungeon::generate_terra_chunk(Ref 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 structure, bool spawn_mobs) { + if (has_method("_generate_terra_structure")) { + call("_generate_terra_structure", structure, spawn_mobs); + } +} +#endif + Ref Dungeon::generate_map() { ERR_FAIL_COND_V(!has_method("_generate_map"), Ref()); @@ -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); diff --git a/main/dungeon.h b/main/dungeon.h index c1339cd..da348c7 100644 --- a/main/dungeon.h +++ b/main/dungeon.h @@ -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 structure, bool spawn_mobs); #endif +#ifdef TERRAMAN_PRESENT + //Environment + Ref get_terra_environment(); + void set_terra_environment(Ref value); + + //Environments + Ref get_terra_environment_data(const int index) const; + void set_terra_environment_data(const int index, const Ref environment_data); + void add_terra_environment_data(const Ref environment_data); + void remove_terra_environment_data(const int index); + int get_terra_environment_data_count() const; + + Vector get_terra_environment_datas(); + void set_terra_environment_datas(const Vector &environment_datas); + + //Surfaces + Ref get_terra_surface(const int index) const; + void set_terra_surface(const int index, const Ref terra_surface); + void add_terra_surface(const Ref terra_surface); + void remove_terra_surface(const int index); + int get_terra_surface_count() const; + + Vector get_terra_surfaces(); + void set_terra_surfaces(const Vector &terra_surfaces); + + void setup_terra_library(Ref library); + void _setup_terra_library(Ref library); + + void generate_terra_chunk(Ref chunk, bool spawn_mobs); + void generate_terra_structure(Ref structure, bool spawn_mobs); +#endif + Ref generate_map(); Dungeon(); @@ -294,6 +331,13 @@ private: Vector > _voxel_environment_datas; Vector > _voxel_surfaces; #endif + +#ifdef TERRAMAN_PRESENT + Ref _terra_environment; + + Vector > _terra_environment_datas; + Vector > _terra_surfaces; +#endif }; #endif