Removed Dungeon, DungeonCorridor, and DungeonRoom. Added Building (it's Dungeon but with a cleaned up api.)

This commit is contained in:
Relintai 2021-04-19 22:28:21 +02:00
parent d289ee942c
commit 260c430f11
14 changed files with 772 additions and 2857 deletions

4
SCsub
View File

@ -23,9 +23,7 @@ sources = [
"register_types.cpp",
"main/dungeon_room.cpp",
"main/dungeon_corridor.cpp",
"main/dungeon.cpp",
"main/building.cpp",
"main/biome.cpp",
"main/planet.cpp",

View File

@ -9,9 +9,7 @@ def get_doc_classes():
"WorldGeneratorPropData",
"Planet",
"Dungeon",
"DungeonRoom",
"DungeonCorridor",
"Building",
"Biome",
"WorldGenerator",

View File

@ -139,46 +139,46 @@ void Biome::set_entity_datas(const Vector<Variant> &entity_datas) {
}
#endif
//// Dungeons ////
Ref<Dungeon> Biome::get_dungeon(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeons.size(), Ref<Dungeon>());
//// Buildings ////
Ref<Building> Biome::get_building(const int index) const {
ERR_FAIL_INDEX_V(index, _buildings.size(), Ref<Building>());
return _dungeons.get(index);
return _buildings.get(index);
}
void Biome::set_dungeon(const int index, const Ref<Dungeon> dungeon) {
ERR_FAIL_INDEX(index, _dungeons.size());
void Biome::set_building(const int index, const Ref<Building> building) {
ERR_FAIL_INDEX(index, _buildings.size());
_dungeons.set(index, dungeon);
_buildings.set(index, building);
}
void Biome::add_dungeon(const Ref<Dungeon> dungeon) {
_dungeons.push_back(dungeon);
void Biome::add_building(const Ref<Building> building) {
_buildings.push_back(building);
}
void Biome::remove_dungeon(const int index) {
ERR_FAIL_INDEX(index, _dungeons.size());
void Biome::remove_building(const int index) {
ERR_FAIL_INDEX(index, _buildings.size());
_dungeons.remove(index);
_buildings.remove(index);
}
int Biome::get_dungeon_count() const {
return _dungeons.size();
int Biome::get_building_count() const {
return _buildings.size();
}
Vector<Variant> Biome::get_dungeons() {
Vector<Variant> Biome::get_buildings() {
Vector<Variant> r;
for (int i = 0; i < _dungeons.size(); i++) {
for (int i = 0; i < _buildings.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_dungeons[i].get_ref_ptr());
r.push_back(_buildings[i].get_ref_ptr());
#else
r.push_back(_dungeons[i]);
r.push_back(_buildings[i]);
#endif
}
return r;
}
void Biome::set_dungeons(const Vector<Variant> &dungeon_datas) {
_dungeons.clear();
for (int i = 0; i < dungeon_datas.size(); i++) {
Ref<Dungeon> dungeon_data = Ref<Dungeon>(dungeon_datas[i]);
void Biome::set_buildings(const Vector<Variant> &buildings) {
_buildings.clear();
for (int i = 0; i < buildings.size(); i++) {
Ref<Building> building = Ref<Building>(buildings[i]);
_dungeons.push_back(dungeon_data);
_buildings.push_back(building);
}
}
@ -207,13 +207,13 @@ Ref<Biome> Biome::_instance(const int seed, Ref<Biome> inst) {
inst->add_prop_data(p);
}
for (int i = 0; i < _dungeons.size(); ++i) {
Ref<Dungeon> d = _dungeons[i];
for (int i = 0; i < _buildings.size(); ++i) {
Ref<Building> d = _buildings[i];
if (!d.is_valid())
continue;
inst->add_dungeon(d->instance(seed));
inst->add_building(d->instance(seed));
}
#ifdef ESS_PRESENT
@ -403,8 +403,8 @@ void Biome::_setup_voxel_library(Ref<VoxelmanLibrary> library) {
}
}
for (int i = 0; i < get_dungeon_count(); ++i) {
Ref<Dungeon> d = get_dungeon(i);
for (int i = 0; i < get_building_count(); ++i) {
Ref<Building> d = get_building(i);
if (d.is_valid()) {
d->setup_voxel_library(library);
@ -552,14 +552,6 @@ void Biome::_setup_terra_library(Ref<TerramanLibrary> library) {
}
}
for (int i = 0; i < get_dungeon_count(); ++i) {
Ref<Dungeon> d = get_dungeon(i);
if (d.is_valid()) {
d->setup_terra_library(library);
}
}
#ifdef PROPS_PRESENT
for (int i = 0; i < get_prop_data_count(); ++i) {
Ref<WorldGeneratorPropData> s = get_prop_data(i);
@ -585,7 +577,7 @@ Biome::~Biome() {
_entity_datas.clear();
#endif
_dungeons.clear();
_buildings.clear();
_prop_datas.clear();
@ -661,16 +653,16 @@ void Biome::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
#endif
//Dungeons
ClassDB::bind_method(D_METHOD("get_dungeon", "index"), &Biome::get_dungeon);
ClassDB::bind_method(D_METHOD("set_dungeon", "index", "data"), &Biome::set_dungeon);
ClassDB::bind_method(D_METHOD("add_dungeon", "dungeon"), &Biome::add_dungeon);
ClassDB::bind_method(D_METHOD("remove_dungeon", "index"), &Biome::remove_dungeon);
ClassDB::bind_method(D_METHOD("get_dungeon_count"), &Biome::get_dungeon_count);
//Buildings
ClassDB::bind_method(D_METHOD("get_building", "index"), &Biome::get_building);
ClassDB::bind_method(D_METHOD("set_building", "index", "data"), &Biome::set_building);
ClassDB::bind_method(D_METHOD("add_building", "dungeon"), &Biome::add_building);
ClassDB::bind_method(D_METHOD("remove_building", "index"), &Biome::remove_building);
ClassDB::bind_method(D_METHOD("get_building_count"), &Biome::get_building_count);
ClassDB::bind_method(D_METHOD("get_dungeons"), &Biome::get_dungeons);
ClassDB::bind_method(D_METHOD("set_dungeons", "dungeon_datas"), &Biome::set_dungeons);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "dungeons", PROPERTY_HINT_NONE, "17/17:Dungeon", PROPERTY_USAGE_DEFAULT, "Dungeon"), "set_dungeons", "get_dungeons");
ClassDB::bind_method(D_METHOD("get_buildings"), &Biome::get_buildings);
ClassDB::bind_method(D_METHOD("set_buildings", "dungeon_datas"), &Biome::set_buildings);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buildings", PROPERTY_HINT_NONE, "17/17:Building", PROPERTY_USAGE_DEFAULT, "Building"), "set_buildings", "get_buildings");
#ifdef VOXELMAN_PRESENT
BIND_VMETHOD(MethodInfo("_setup_voxel_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary")));

View File

@ -33,7 +33,7 @@ SOFTWARE.
#include "core/resource.h"
#endif
#include "dungeon.h"
#include "building.h"
#include "../data/world_generator_prop_data.h"
#include "scene/resources/packed_scene.h"
@ -93,15 +93,15 @@ public:
void set_entity_datas(const Vector<Variant> &entity_datas);
#endif
//Dungeons
Ref<Dungeon> get_dungeon(const int index) const;
void set_dungeon(const int index, const Ref<Dungeon> dungeon);
void add_dungeon(const Ref<Dungeon> dungeon);
void remove_dungeon(const int index);
int get_dungeon_count() const;
//Buildings
Ref<Building> get_building(const int index) const;
void set_building(const int index, const Ref<Building> building);
void add_building(const Ref<Building> building);
void remove_building(const int index);
int get_building_count() const;
Vector<Variant> get_dungeons();
void set_dungeons(const Vector<Variant> &dungeon_datas);
Vector<Variant> get_buildings();
void set_buildings(const Vector<Variant> &buildings);
Ref<Biome> instance(const int seed);
virtual Ref<Biome> _instance(const int seed, Ref<Biome> inst);
@ -192,7 +192,7 @@ private:
Vector<Ref<EntityData> > _entity_datas;
#endif
Vector<Ref<Dungeon> > _dungeons;
Vector<Ref<Building> > _buildings;
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> _voxel_environment;

641
main/building.cpp Normal file
View File

@ -0,0 +1,641 @@
/*
Copyright (c) 2019-2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "building.h"
int Building::get_current_seed() {
return _current_seed;
}
void Building::set_current_seed(int value) {
_current_seed = value;
}
Vector2 Building::get_level_range() {
return _level_range;
}
void Building::set_level_range(Vector2 value) {
_level_range = value;
}
//Position
int Building::get_posx() {
return _posx;
}
void Building::set_posx(int value) {
_posx = value;
}
int Building::get_posy() {
return _posy;
}
void Building::set_posy(int value) {
_posy = value;
}
int Building::get_posz() {
return _posz;
}
void Building::set_posz(int value) {
_posz = value;
}
//Size
int Building::get_sizex() {
return _sizex;
}
void Building::set_sizex(int value) {
_sizex = value;
}
int Building::get_sizey() {
return _sizey;
}
void Building::set_sizey(int value) {
_sizey = value;
}
int Building::get_sizez() {
return _sizez;
}
void Building::set_sizez(int value) {
_sizez = value;
}
Ref<Building> Building::instance(const int seed) {
Ref<Building> inst;
inst = Ref<Building>(Object::cast_to<Building>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<Building> Building::_instance(const int seed, Ref<Building> inst) {
inst->set_current_seed(seed);
inst->set_level_range(_level_range);
inst->set_posx(_posx);
inst->set_posy(_posy);
inst->set_posz(_posz);
inst->set_sizex(_sizex);
inst->set_sizey(_sizey);
inst->set_sizez(_sizez);
#ifdef ESS_PRESENT
for (int i = 0; i < _entity_datas.size(); ++i) {
Ref<EntityData> d = _entity_datas[i];
inst->add_entity_data(d);
}
#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];
if (!d.is_valid())
continue;
inst->add_voxel_environment_data(d);
}
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
Ref<VoxelSurface> d = _voxel_surfaces[i];
if (!d.is_valid())
continue;
inst->add_voxel_surface(d);
}
#endif
#ifdef TERRAMAN_PRESENT
inst->set_terra_environment(_terra_environment);
for (int i = 0; i < _terra_environment_datas.size(); ++i) {
Ref<TerraEnvironmentData> 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<TerraSurface> d = _terra_surfaces[i];
if (!d.is_valid())
continue;
inst->add_terra_surface(d);
}
#endif
return inst;
}
void Building::setup() {
if (has_method("_setup")) {
call("_setup");
}
}
#ifdef ESS_PRESENT
//Entities
Ref<EntityData> Building::get_entity_data(const int index) const {
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>());
return _entity_datas.get(index);
}
void Building::set_entity_data(const int index, const Ref<EntityData> entity_data) {
ERR_FAIL_INDEX(index, _entity_datas.size());
_entity_datas.set(index, entity_data);
}
void Building::add_entity_data(const Ref<EntityData> entity_data) {
_entity_datas.push_back(entity_data);
}
void Building::remove_entity_data(const int index) {
ERR_FAIL_INDEX(index, _entity_datas.size());
_entity_datas.remove(index);
}
int Building::get_entity_data_count() const {
return _entity_datas.size();
}
Vector<Variant> Building::get_entity_datas() {
Vector<Variant> r;
for (int i = 0; i < _entity_datas.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_entity_datas[i].get_ref_ptr());
#else
r.push_back(_entity_datas[i]);
#endif
}
return r;
}
void Building::set_entity_datas(const Vector<Variant> &entity_datas) {
_entity_datas.clear();
for (int i = 0; i < entity_datas.size(); i++) {
Ref<EntityData> entity_data = Ref<EntityData>(entity_datas[i]);
_entity_datas.push_back(entity_data);
}
}
#endif
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> Building::get_voxel_environment() {
return _voxel_environment;
}
void Building::set_voxel_environment(Ref<EnvironmentData> value) {
_voxel_environment = value;
}
//// Surfaces ////
Ref<VoxelSurface> Building::get_voxel_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>());
return _voxel_surfaces.get(index);
}
void Building::set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.set(index, voxel_surface);
}
void Building::add_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
_voxel_surfaces.push_back(voxel_surface);
}
void Building::remove_voxel_surface(const int index) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.remove(index);
}
int Building::get_voxel_surface_count() const {
return _voxel_surfaces.size();
}
Vector<Variant> Building::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_surfaces[i].get_ref_ptr());
#else
r.push_back(_voxel_surfaces[i]);
#endif
}
return r;
}
void Building::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
_voxel_surfaces.clear();
for (int i = 0; i < voxel_surfaces.size(); i++) {
Ref<VoxelSurface> voxel_surface = Ref<VoxelSurface>(voxel_surfaces[i]);
_voxel_surfaces.push_back(voxel_surface);
}
}
//Environments
Ref<EnvironmentData> Building::get_voxel_environment_data(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_environment_datas.size(), Ref<EnvironmentData>());
return _voxel_environment_datas.get(index);
}
void Building::set_voxel_environment_data(const int index, const Ref<EnvironmentData> environment_data) {
ERR_FAIL_INDEX(index, _voxel_environment_datas.size());
_voxel_environment_datas.set(index, environment_data);
}
void Building::add_voxel_environment_data(const Ref<EnvironmentData> environment_data) {
_voxel_environment_datas.push_back(environment_data);
}
void Building::remove_voxel_environment_data(const int index) {
ERR_FAIL_INDEX(index, _voxel_environment_datas.size());
_voxel_environment_datas.remove(index);
}
int Building::get_voxel_environment_data_count() const {
return _voxel_environment_datas.size();
}
Vector<Variant> Building::get_voxel_environment_datas() {
Vector<Variant> r;
for (int i = 0; i < _voxel_environment_datas.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_environment_datas[i].get_ref_ptr());
#else
r.push_back(_voxel_environment_datas[i]);
#endif
}
return r;
}
void Building::set_voxel_environment_datas(const Vector<Variant> &environment_datas) {
_voxel_environment_datas.clear();
for (int i = 0; i < environment_datas.size(); i++) {
Ref<EnvironmentData> environment_data = Ref<EnvironmentData>(environment_datas[i]);
_voxel_environment_datas.push_back(environment_data);
}
}
void Building::setup_voxel_library(Ref<VoxelmanLibrary> library) {
if (has_method("_setup_voxel_library")) {
call("_setup_voxel_library", library);
}
}
void Building::_setup_voxel_library(Ref<VoxelmanLibrary> library) {
for (int i = 0; i < get_voxel_surface_count(); ++i) {
Ref<VoxelSurface> s = get_voxel_surface(i);
if (s.is_valid()) {
library->voxel_surface_add(s);
}
}
}
void Building::generate_voxel_chunk(Ref<VoxelChunk> chunk, bool spawn_mobs) {
ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_generate_voxel_chunk")) {
call("_generate_voxel_chunk", chunk, spawn_mobs);
}
}
void Building::generate_voxel_structure(Ref<VoxelStructure> structure, bool spawn_mobs) {
if (has_method("_generate_voxel_structure")) {
call("_generate_voxel_structure", structure, spawn_mobs);
}
}
#endif
#ifdef TERRAMAN_PRESENT
Ref<TerraEnvironmentData> Building::get_terra_environment() {
return _terra_environment;
}
void Building::set_terra_environment(Ref<TerraEnvironmentData> value) {
_terra_environment = value;
}
//// Surfaces ////
Ref<TerraSurface> Building::get_terra_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _terra_surfaces.size(), Ref<TerraSurface>());
return _terra_surfaces.get(index);
}
void Building::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 Building::add_terra_surface(const Ref<TerraSurface> terra_surface) {
_terra_surfaces.push_back(terra_surface);
}
void Building::remove_terra_surface(const int index) {
ERR_FAIL_INDEX(index, _terra_surfaces.size());
_terra_surfaces.remove(index);
}
int Building::get_terra_surface_count() const {
return _terra_surfaces.size();
}
Vector<Variant> Building::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 Building::set_terra_surfaces(const Vector<Variant> &terra_surfaces) {
_terra_surfaces.clear();
for (int i = 0; i < terra_surfaces.size(); i++) {
Ref<TerraSurface> terra_surface = Ref<TerraSurface>(terra_surfaces[i]);
_terra_surfaces.push_back(terra_surface);
}
}
//Environments
Ref<TerraEnvironmentData> Building::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 Building::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 Building::add_terra_environment_data(const Ref<TerraEnvironmentData> environment_data) {
_terra_environment_datas.push_back(environment_data);
}
void Building::remove_terra_environment_data(const int index) {
ERR_FAIL_INDEX(index, _terra_environment_datas.size());
_terra_environment_datas.remove(index);
}
int Building::get_terra_environment_data_count() const {
return _terra_environment_datas.size();
}
Vector<Variant> Building::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 Building::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 Building::setup_terra_library(Ref<TerramanLibrary> library) {
if (has_method("_setup_terra_library")) {
call("_setup_terra_library", library);
}
}
void Building::_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);
}
}
}
void Building::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 Building::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> Building::generate_map() {
ERR_FAIL_COND_V(!has_method("_generate_map"), Ref<Image>());
return call("_generate_map");
}
Building::Building() {
_current_seed = 0;
_posx = 0;
_posy = 0;
_posz = 0;
_sizex = 0;
_sizey = 0;
_sizez = 0;
}
Building::~Building() {
#ifdef ESS_PRESENT
_entity_datas.clear();
#endif
#ifdef VOXELMAN_PRESENT
_voxel_environment.unref();
_voxel_environment_datas.clear();
_voxel_surfaces.clear();
#endif
#ifdef TERRAMAN_PRESENT
_terra_environment.unref();
_terra_environment_datas.clear();
_terra_surfaces.clear();
#endif
}
void Building::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "Building"),
"_instance",
PropertyInfo(Variant::INT, "p_seed"),
PropertyInfo(Variant::OBJECT, "p_instance", PROPERTY_HINT_RESOURCE_TYPE, "Building")));
BIND_VMETHOD(MethodInfo("_setup"));
ClassDB::bind_method(D_METHOD("instance", "seed"), &Building::instance);
ClassDB::bind_method(D_METHOD("_instance", "p_seed", "p_instance"), &Building::_instance);
ClassDB::bind_method(D_METHOD("setup"), &Building::setup);
ClassDB::bind_method(D_METHOD("get_current_seed"), &Building::get_current_seed);
ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &Building::set_current_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed");
ClassDB::bind_method(D_METHOD("get_level_range"), &Building::get_level_range);
ClassDB::bind_method(D_METHOD("set_level_range", "value"), &Building::set_level_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range");
//Position
ClassDB::bind_method(D_METHOD("get_posx"), &Building::get_posx);
ClassDB::bind_method(D_METHOD("set_posx", "value"), &Building::set_posx);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posx"), "set_posx", "get_posx");
ClassDB::bind_method(D_METHOD("get_posy"), &Building::get_posy);
ClassDB::bind_method(D_METHOD("set_posy", "value"), &Building::set_posy);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posy"), "set_posy", "get_posy");
ClassDB::bind_method(D_METHOD("get_posz"), &Building::get_posz);
ClassDB::bind_method(D_METHOD("set_posz", "value"), &Building::set_posz);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posz"), "set_posz", "get_posz");
//Size
ClassDB::bind_method(D_METHOD("get_sizex"), &Building::get_sizex);
ClassDB::bind_method(D_METHOD("set_sizex", "value"), &Building::set_sizex);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizex"), "set_sizex", "get_sizex");
ClassDB::bind_method(D_METHOD("get_sizey"), &Building::get_sizey);
ClassDB::bind_method(D_METHOD("set_sizey", "value"), &Building::set_sizey);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizey"), "set_sizey", "get_sizey");
ClassDB::bind_method(D_METHOD("get_sizez"), &Building::get_sizez);
ClassDB::bind_method(D_METHOD("set_sizez", "value"), &Building::set_sizez);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizez"), "set_sizez", "get_sizez");
#ifdef ESS_PRESENT
//Entities
ClassDB::bind_method(D_METHOD("get_entity_data", "index"), &Building::get_entity_data);
ClassDB::bind_method(D_METHOD("set_entity_data", "index", "data"), &Building::set_entity_data);
ClassDB::bind_method(D_METHOD("add_entity_data", "entity_data"), &Building::add_entity_data);
ClassDB::bind_method(D_METHOD("remove_entity_data", "index"), &Building::remove_entity_data);
ClassDB::bind_method(D_METHOD("get_entity_data_count"), &Building::get_entity_data_count);
ClassDB::bind_method(D_METHOD("get_entity_datas"), &Building::get_entity_datas);
ClassDB::bind_method(D_METHOD("set_entity_datas", "entity_datas"), &Building::set_entity_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
#endif
#ifdef VOXELMAN_PRESENT
BIND_VMETHOD(MethodInfo("_setup_voxel_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary")));
BIND_VMETHOD(MethodInfo("_generate_voxel_structure", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
BIND_VMETHOD(MethodInfo("_generate_voxel_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
ClassDB::bind_method(D_METHOD("setup_voxel_library", "library"), &Building::setup_voxel_library);
ClassDB::bind_method(D_METHOD("_setup_voxel_library", "library"), &Building::_setup_voxel_library);
ClassDB::bind_method(D_METHOD("generate_voxel_chunk", "chunk", "spawn_mobs"), &Building::generate_voxel_chunk);
ClassDB::bind_method(D_METHOD("generate_voxel_structure", "structure", "spawn_mobs"), &Building::generate_voxel_structure);
//Environment
ClassDB::bind_method(D_METHOD("get_voxel_environment"), &Building::get_voxel_environment);
ClassDB::bind_method(D_METHOD("set_voxel_environment", "value"), &Building::set_voxel_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "voxel_environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_voxel_environment", "get_voxel_environment");
//Environments
ClassDB::bind_method(D_METHOD("get_voxel_environment_data", "index"), &Building::get_voxel_environment_data);
ClassDB::bind_method(D_METHOD("set_voxel_environment_data", "index", "data"), &Building::set_voxel_environment_data);
ClassDB::bind_method(D_METHOD("add_voxel_environment_data", "environment_data"), &Building::add_voxel_environment_data);
ClassDB::bind_method(D_METHOD("remove_voxel_environment_data", "index"), &Building::remove_voxel_environment_data);
ClassDB::bind_method(D_METHOD("get_voxel_environment_data_count"), &Building::get_voxel_environment_data_count);
ClassDB::bind_method(D_METHOD("get_voxel_environment_datas"), &Building::get_voxel_environment_datas);
ClassDB::bind_method(D_METHOD("set_voxel_environment_datas", "environment_datas"), &Building::set_voxel_environment_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_environment_datas", PROPERTY_HINT_NONE, "17/17:EnvironmentData", PROPERTY_USAGE_DEFAULT, "EnvironmentData"), "set_voxel_environment_datas", "get_voxel_environment_datas");
//Surfaces
ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &Building::get_voxel_surface);
ClassDB::bind_method(D_METHOD("set_voxel_surface", "index", "data"), &Building::set_voxel_surface);
ClassDB::bind_method(D_METHOD("add_voxel_surface", "voxel_surface"), &Building::add_voxel_surface);
ClassDB::bind_method(D_METHOD("remove_voxel_surface", "index"), &Building::remove_voxel_surface);
ClassDB::bind_method(D_METHOD("get_voxel_surface_count"), &Building::get_voxel_surface_count);
ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &Building::get_voxel_surfaces);
ClassDB::bind_method(D_METHOD("set_voxel_surfaces", "voxel_surfaces"), &Building::set_voxel_surfaces);
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"), &Building::setup_terra_library);
ClassDB::bind_method(D_METHOD("_setup_terra_library", "library"), &Building::_setup_terra_library);
ClassDB::bind_method(D_METHOD("generate_terra_chunk", "chunk", "spawn_mobs"), &Building::generate_terra_chunk);
ClassDB::bind_method(D_METHOD("generate_terra_structure", "structure", "spawn_mobs"), &Building::generate_terra_structure);
//Environment
ClassDB::bind_method(D_METHOD("get_terra_environment"), &Building::get_terra_environment);
ClassDB::bind_method(D_METHOD("set_terra_environment", "value"), &Building::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"), &Building::get_terra_environment_data);
ClassDB::bind_method(D_METHOD("set_terra_environment_data", "index", "data"), &Building::set_terra_environment_data);
ClassDB::bind_method(D_METHOD("add_terra_environment_data", "environment_data"), &Building::add_terra_environment_data);
ClassDB::bind_method(D_METHOD("remove_terra_environment_data", "index"), &Building::remove_terra_environment_data);
ClassDB::bind_method(D_METHOD("get_terra_environment_data_count"), &Building::get_terra_environment_data_count);
ClassDB::bind_method(D_METHOD("get_terra_environment_datas"), &Building::get_terra_environment_datas);
ClassDB::bind_method(D_METHOD("set_terra_environment_datas", "environment_datas"), &Building::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"), &Building::get_terra_surface);
ClassDB::bind_method(D_METHOD("set_terra_surface", "index", "data"), &Building::set_terra_surface);
ClassDB::bind_method(D_METHOD("add_terra_surface", "terra_surface"), &Building::add_terra_surface);
ClassDB::bind_method(D_METHOD("remove_terra_surface", "index"), &Building::remove_terra_surface);
ClassDB::bind_method(D_METHOD("get_terra_surface_count"), &Building::get_terra_surface_count);
ClassDB::bind_method(D_METHOD("get_terra_surfaces"), &Building::get_terra_surfaces);
ClassDB::bind_method(D_METHOD("set_terra_surfaces", "terra_surfaces"), &Building::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"), &Building::generate_map);
}

View File

@ -20,25 +20,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef DUNGEON_ROOM_H
#define DUNGEON_ROOM_H
#ifndef BUILDING_H
#define BUILDING_H
#include "core/version.h"
#if VERSION_MAJOR > 3
#include "core/io/image.h"
#include "core/io/resource.h"
#include "core/object/reference.h"
#include "core/templates/vector.h"
#else
#include "core/image.h"
#include "core/reference.h"
#include "core/resource.h"
#include "core/vector.h"
#endif
#include "../data/world_generator_prop_data.h"
#include "scene/resources/packed_scene.h"
#ifdef VOXELMAN_PRESENT
#include "../../voxelman/library/voxelman_library.h"
#include "../../voxelman/world/environment_data.h"
@ -48,8 +44,8 @@ SOFTWARE.
#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_environment_data.h"
#include "../../terraman/world/terra_structure.h"
#endif
@ -57,8 +53,8 @@ SOFTWARE.
#include "../../entity_spell_system/entities/data/entity_data.h"
#endif
class DungeonRoom : public Resource {
GDCLASS(DungeonRoom, Resource);
class Building : public Resource {
GDCLASS(Building, Resource);
public:
int get_current_seed();
@ -67,26 +63,6 @@ public:
Vector2 get_level_range();
void set_level_range(Vector2 value);
//Min Size
int get_min_sizex();
void set_min_sizex(int value);
int get_min_sizey();
void set_min_sizey(int value);
int get_min_sizez();
void set_min_sizez(int value);
//Max Size
int get_max_sizex();
void set_max_sizex(int value);
int get_max_sizey();
void set_max_sizey(int value);
int get_max_sizez();
void set_max_sizez(int value);
//Pos
int get_posx();
void set_posx(int value);
@ -107,22 +83,16 @@ public:
int get_sizez();
void set_sizez(int value);
//Props
Ref<WorldGeneratorPropData> get_prop_data(const int index) const;
void set_prop_data(const int index, const Ref<WorldGeneratorPropData> prop_data);
void add_prop_data(const Ref<WorldGeneratorPropData> prop_data);
void remove_prop_data(const int index);
int get_prop_data_count() const;
Vector<Variant> get_prop_datas();
void set_prop_datas(const Vector<Variant> &prop_datas);
Ref<Building> instance(const int seed);
virtual Ref<Building> _instance(const int seed, Ref<Building> inst);
void setup();
#ifdef ESS_PRESENT
//Entities
Ref<EntityData> get_entity_data(const int index) const;
void set_entity_data(const int index, const Ref<EntityData> entity_data);
void add_entity_data(const Ref<EntityData> entity_data);
void set_entity_data(const int index, const Ref<EntityData> entity_datas);
void add_entity_data(const Ref<EntityData> entity_datas);
void remove_entity_data(const int index);
int get_entity_data_count() const;
@ -130,20 +100,11 @@ public:
void set_entity_datas(const Vector<Variant> &entity_datas);
#endif
Ref<DungeonRoom> instance(const int seed);
virtual Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> inst);
void setup();
#ifdef VOXELMAN_PRESENT
//Environment
Ref<EnvironmentData> get_voxel_environment();
void set_voxel_environment(Ref<EnvironmentData> value);
//Structure
Ref<VoxelStructure> get_voxel_structure();
void set_voxel_structure(Ref<VoxelStructure> structure);
//Environments
Ref<EnvironmentData> get_voxel_environment_data(const int index) const;
void set_voxel_environment_data(const int index, const Ref<EnvironmentData> environment_data);
@ -168,7 +129,7 @@ public:
void _setup_voxel_library(Ref<VoxelmanLibrary> library);
void generate_voxel_chunk(Ref<VoxelChunk> chunk, bool spawn_mobs);
void generate_voxel_room(Ref<VoxelStructure> structure, bool spawn_mobs);
void generate_voxel_structure(Ref<VoxelStructure> structure, bool spawn_mobs);
#endif
#ifdef TERRAMAN_PRESENT
@ -176,10 +137,6 @@ public:
Ref<TerraEnvironmentData> get_terra_environment();
void set_terra_environment(Ref<TerraEnvironmentData> value);
//Structure
Ref<TerraStructure> get_terra_structure();
void set_terra_structure(Ref<TerraStructure> structure);
//Environments
Ref<TerraEnvironmentData> get_terra_environment_data(const int index) const;
void set_terra_environment_data(const int index, const Ref<TerraEnvironmentData> environment_data);
@ -204,11 +161,13 @@ public:
void _setup_terra_library(Ref<TerramanLibrary> library);
void generate_terra_chunk(Ref<TerraChunk> chunk, bool spawn_mobs);
void generate_terra_room(Ref<TerraStructure> structure, bool spawn_mobs);
void generate_terra_structure(Ref<TerraStructure> structure, bool spawn_mobs);
#endif
DungeonRoom();
~DungeonRoom();
Ref<Image> generate_map();
Building();
~Building();
protected:
static void _bind_methods();
@ -218,14 +177,6 @@ private:
Vector2 _level_range;
int _min_sizex;
int _min_sizey;
int _min_sizez;
int _max_sizex;
int _max_sizey;
int _max_sizez;
int _posx;
int _posy;
int _posz;
@ -234,15 +185,12 @@ private:
int _sizey;
int _sizez;
Vector<Ref<WorldGeneratorPropData> > _prop_datas;
#ifdef ESS_PRESENT
Vector<Ref<EntityData> > _entity_datas;
#endif
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> _voxel_environment;
Ref<VoxelStructure> _voxel_structure;
Vector<Ref<EnvironmentData> > _voxel_environment_datas;
Vector<Ref<VoxelSurface> > _voxel_surfaces;
@ -250,7 +198,6 @@ private:
#ifdef TERRAMAN_PRESENT
Ref<TerraEnvironmentData> _terra_environment;
Ref<TerraStructure> _terra_structure;
Vector<Ref<TerraEnvironmentData> > _terra_environment_datas;
Vector<Ref<TerraSurface> > _terra_surfaces;

File diff suppressed because it is too large Load Diff

View File

@ -1,343 +0,0 @@
/*
Copyright (c) 2019-2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef DUNGEON_H
#define DUNGEON_H
#include "core/version.h"
#if VERSION_MAJOR > 3
#include "core/io/resource.h"
#include "core/object/reference.h"
#else
#include "core/reference.h"
#include "core/resource.h"
#endif
#include "dungeon_corridor.h"
#include "dungeon_room.h"
#ifdef VOXELMAN_PRESENT
#include "../../voxelman/library/voxelman_library.h"
#include "../../voxelman/world/environment_data.h"
#include "../../voxelman/world/voxel_chunk.h"
#include "../../voxelman/world/voxel_structure.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
#include "../../entity_spell_system/entities/data/entity_data.h"
#endif
class Dungeon : public Resource {
GDCLASS(Dungeon, Resource);
public:
int get_current_seed();
void set_current_seed(int value);
Vector2 get_level_range();
void set_level_range(Vector2 value);
//Min Size
int get_min_sizex();
void set_min_sizex(int value);
int get_min_sizey();
void set_min_sizey(int value);
int get_min_sizez();
void set_min_sizez(int value);
//Max Size
int get_max_sizex();
void set_max_sizex(int value);
int get_max_sizey();
void set_max_sizey(int value);
int get_max_sizez();
void set_max_sizez(int value);
//Room Count
int get_min_room_count();
void set_min_room_count(int value);
int get_max_room_count();
void set_max_room_count(int value);
//Pos
int get_posx();
void set_posx(int value);
int get_posy();
void set_posy(int value);
int get_posz();
void set_posz(int value);
//Size
int get_sizex();
void set_sizex(int value);
int get_sizey();
void set_sizey(int value);
int get_sizez();
void set_sizez(int value);
//Room Count
int get_room_count();
void set_room_count(int value);
//Rooms
Ref<DungeonRoom> get_dungeon_room(const int index) const;
void set_dungeon_room(const int index, const Ref<DungeonRoom> dungeon_room);
void add_dungeon_room(const Ref<DungeonRoom> dungeon_room);
void remove_dungeon_room(const int index);
int get_dungeon_room_count() const;
Vector<Variant> get_dungeon_rooms();
void set_dungeon_rooms(const Vector<Variant> &dungeon_rooms);
//Start Rooms
Ref<DungeonRoom> get_dungeon_start_room(const int index) const;
void set_dungeon_start_room(const int index, const Ref<DungeonRoom> dungeon_start_room);
void add_dungeon_start_room(const Ref<DungeonRoom> dungeon_start_room);
void remove_dungeon_start_room(const int index);
int get_dungeon_start_room_count() const;
Vector<Variant> get_dungeon_start_rooms();
void set_dungeon_start_rooms(const Vector<Variant> &dungeon_start_rooms);
//End Rooms
Ref<DungeonRoom> get_dungeon_end_room(const int index) const;
void set_dungeon_end_room(const int index, const Ref<DungeonRoom> dungeon_end_room);
void add_dungeon_end_room(const Ref<DungeonRoom> dungeon_end_room);
void remove_dungeon_end_room(const int index);
int get_dungeon_end_room_count() const;
Vector<Variant> get_dungeon_end_rooms();
void set_dungeon_end_rooms(const Vector<Variant> &dungeon_end_rooms);
//Corridors
Ref<DungeonCorridor> get_dungeon_corridor(const int index) const;
void set_dungeon_corridor(const int index, const Ref<DungeonCorridor> dungeon_corridors);
void add_dungeon_corridor(const Ref<DungeonCorridor> dungeon_corridors);
void remove_dungeon_corridor(const int index);
int get_dungeon_corridor_count() const;
Vector<Variant> get_dungeon_corridors();
void set_dungeon_corridors(const Vector<Variant> &dungeon_corridors);
//Room Datas
Ref<DungeonRoom> get_dungeon_room_data(const int index) const;
void set_dungeon_room_data(const int index, const Ref<DungeonRoom> dungeon_room);
void add_dungeon_room_data(const Ref<DungeonRoom> dungeon_room);
void remove_dungeon_room_data(const int index);
int get_dungeon_room_data_count() const;
Vector<Variant> get_dungeon_room_datas();
void set_dungeon_room_datas(const Vector<Variant> &dungeon_rooms);
//Start Room Datas
Ref<DungeonRoom> get_dungeon_start_room_data(const int index) const;
void set_dungeon_start_room_data(const int index, const Ref<DungeonRoom> dungeon_start_room);
void add_dungeon_start_room_data(const Ref<DungeonRoom> dungeon_start_room);
void remove_dungeon_start_room_data(const int index);
int get_dungeon_start_room_data_count() const;
Vector<Variant> get_dungeon_start_room_datas();
void set_dungeon_start_room_datas(const Vector<Variant> &dungeon_start_rooms);
//End Room Datas
Ref<DungeonRoom> get_dungeon_end_room_data(const int index) const;
void set_dungeon_end_room_data(const int index, const Ref<DungeonRoom> dungeon_end_room);
void add_dungeon_end_room_data(const Ref<DungeonRoom> dungeon_end_room);
void remove_dungeon_end_room_data(const int index);
int get_dungeon_end_room_data_count() const;
Vector<Variant> get_dungeon_end_room_datas();
void set_dungeon_end_room_datas(const Vector<Variant> &dungeon_end_rooms);
//Corridor Datas
Ref<DungeonCorridor> get_dungeon_corridor_data(const int index) const;
void set_dungeon_corridor_data(const int index, const Ref<DungeonCorridor> dungeon_corridors);
void add_dungeon_corridor_data(const Ref<DungeonCorridor> dungeon_corridors);
void remove_dungeon_corridor_data(const int index);
int get_dungeon_corridor_data_count() const;
Vector<Variant> get_dungeon_corridor_datas();
void set_dungeon_corridor_datas(const Vector<Variant> &dungeon_corridors);
#ifdef ESS_PRESENT
//Entities
Ref<EntityData> get_entity_data(const int index) const;
void set_entity_data(const int index, const Ref<EntityData> entity_datas);
void add_entity_data(const Ref<EntityData> entity_datas);
void remove_entity_data(const int index);
int get_entity_data_count() const;
Vector<Variant> get_entity_datas();
void set_entity_datas(const Vector<Variant> &entity_datas);
#endif
Ref<Dungeon> instance(const int seed);
virtual Ref<Dungeon> _instance(const int seed, Ref<Dungeon> inst);
void setup();
#ifdef VOXELMAN_PRESENT
//Environment
Ref<EnvironmentData> get_voxel_environment();
void set_voxel_environment(Ref<EnvironmentData> value);
//Environments
Ref<EnvironmentData> get_voxel_environment_data(const int index) const;
void set_voxel_environment_data(const int index, const Ref<EnvironmentData> environment_data);
void add_voxel_environment_data(const Ref<EnvironmentData> environment_data);
void remove_voxel_environment_data(const int index);
int get_voxel_environment_data_count() const;
Vector<Variant> get_voxel_environment_datas();
void set_voxel_environment_datas(const Vector<Variant> &environment_datas);
//Surfaces
Ref<VoxelSurface> get_voxel_surface(const int index) const;
void set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void remove_voxel_surface(const int index);
int get_voxel_surface_count() const;
Vector<Variant> get_voxel_surfaces();
void set_voxel_surfaces(const Vector<Variant> &voxel_surfaces);
void setup_voxel_library(Ref<VoxelmanLibrary> library);
void _setup_voxel_library(Ref<VoxelmanLibrary> library);
void generate_voxel_chunk(Ref<VoxelChunk> chunk, bool spawn_mobs);
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();
~Dungeon();
protected:
static void _bind_methods();
private:
int _current_seed;
Vector2 _level_range;
int _posx;
int _posy;
int _posz;
int _sizex;
int _sizey;
int _sizez;
int _room_count;
int _min_sizex;
int _min_sizey;
int _min_sizez;
int _max_sizex;
int _max_sizey;
int _max_sizez;
int _min_room_count;
int _max_room_count;
Vector<Ref<DungeonRoom> > _dungeon_rooms;
Vector<Ref<DungeonRoom> > _dungeon_start_rooms;
Vector<Ref<DungeonRoom> > _dungeon_end_rooms;
Vector<Ref<DungeonCorridor> > _dungeon_corridors;
Vector<Ref<DungeonRoom> > _dungeon_room_datas;
Vector<Ref<DungeonRoom> > _dungeon_start_room_datas;
Vector<Ref<DungeonRoom> > _dungeon_end_room_datas;
Vector<Ref<DungeonCorridor> > _dungeon_corridor_datas;
#ifdef ESS_PRESENT
Vector<Ref<EntityData> > _entity_datas;
#endif
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> _voxel_environment;
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

View File

@ -1,84 +0,0 @@
/*
Copyright (c) 2019-2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "dungeon_corridor.h"
int DungeonCorridor::get_max_connections() {
return _max_connections;
}
void DungeonCorridor::set_max_connections(int value) {
_max_connections = value;
}
//Rooms
Ref<DungeonRoom> DungeonCorridor::get_dungeon_room(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_rooms.size(), Ref<DungeonRoom>());
return _dungeon_rooms.get(index);
}
void DungeonCorridor::set_dungeon_room(const int index, const Ref<DungeonRoom> dungeon_room) {
ERR_FAIL_INDEX(index, _dungeon_rooms.size());
_dungeon_rooms.set(index, dungeon_room);
}
void DungeonCorridor::add_dungeon_room(const Ref<DungeonRoom> dungeon_room) {
_dungeon_rooms.push_back(dungeon_room);
}
void DungeonCorridor::remove_dungeon_room(const int index) {
ERR_FAIL_INDEX(index, _dungeon_rooms.size());
_dungeon_rooms.remove(index);
}
int DungeonCorridor::get_dungeon_room_count() const {
return _dungeon_rooms.size();
}
Ref<DungeonRoom> DungeonCorridor::_instance(const int seed, Ref<DungeonRoom> inst) {
DungeonRoom::_instance(seed, inst);
Ref<DungeonCorridor> cinst = inst;
cinst->set_max_connections(_max_connections);
return cinst;
}
DungeonCorridor::DungeonCorridor() {
_max_connections = 2;
}
DungeonCorridor::~DungeonCorridor() {
_dungeon_rooms.clear();
}
void DungeonCorridor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_max_connections"), &DungeonCorridor::get_max_connections);
ClassDB::bind_method(D_METHOD("set_max_connections", "value"), &DungeonCorridor::set_max_connections);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_connections"), "set_max_connections", "get_max_connections");
//Rooms
ClassDB::bind_method(D_METHOD("get_dungeon_room", "index"), &DungeonCorridor::get_dungeon_room);
ClassDB::bind_method(D_METHOD("set_dungeon_room", "index", "data"), &DungeonCorridor::set_dungeon_room);
ClassDB::bind_method(D_METHOD("add_dungeon_room", "dungeon_room"), &DungeonCorridor::add_dungeon_room);
ClassDB::bind_method(D_METHOD("remove_dungeon_room", "index"), &DungeonCorridor::remove_dungeon_room);
ClassDB::bind_method(D_METHOD("get_dungeon_room_count"), &DungeonCorridor::get_dungeon_room_count);
}

View File

@ -1,56 +0,0 @@
/*
Copyright (c) 2019-2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef DUNGEON_CORRIDOR_H
#define DUNGEON_CORRIDOR_H
#include "dungeon_room.h"
class DungeonCorridor : public DungeonRoom {
GDCLASS(DungeonCorridor, DungeonRoom);
public:
int get_max_connections();
void set_max_connections(int value);
//Rooms
Ref<DungeonRoom> get_dungeon_room(const int index) const;
void set_dungeon_room(const int index, const Ref<DungeonRoom> dungeon_room);
void add_dungeon_room(const Ref<DungeonRoom> dungeon_room);
void remove_dungeon_room(const int index);
int get_dungeon_room_count() const;
Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> inst);
DungeonCorridor();
~DungeonCorridor();
protected:
static void _bind_methods();
private:
int _max_connections;
Vector<Ref<DungeonRoom> > _dungeon_rooms;
};
#endif

View File

@ -1,836 +0,0 @@
/*
Copyright (c) 2019-2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "dungeon_room.h"
int DungeonRoom::get_current_seed() {
return _current_seed;
}
void DungeonRoom::set_current_seed(int value) {
_current_seed = value;
}
Vector2 DungeonRoom::get_level_range() {
return _level_range;
}
void DungeonRoom::set_level_range(Vector2 value) {
_level_range = value;
}
//Min Size
int DungeonRoom::get_min_sizex() {
return _min_sizex;
}
void DungeonRoom::set_min_sizex(int value) {
_min_sizex = value;
}
int DungeonRoom::get_min_sizey() {
return _min_sizey;
}
void DungeonRoom::set_min_sizey(int value) {
_min_sizey = value;
}
int DungeonRoom::get_min_sizez() {
return _min_sizez;
}
void DungeonRoom::set_min_sizez(int value) {
_min_sizez = value;
}
//Max Size
int DungeonRoom::get_max_sizex() {
return _max_sizex;
}
void DungeonRoom::set_max_sizex(int value) {
_max_sizex = value;
}
int DungeonRoom::get_max_sizey() {
return _max_sizey;
}
void DungeonRoom::set_max_sizey(int value) {
_max_sizey = value;
}
int DungeonRoom::get_max_sizez() {
return _max_sizez;
}
void DungeonRoom::set_max_sizez(int value) {
_max_sizez = value;
}
//Position
int DungeonRoom::get_posx() {
return _posx;
}
void DungeonRoom::set_posx(int value) {
_posx = value;
}
int DungeonRoom::get_posy() {
return _posy;
}
void DungeonRoom::set_posy(int value) {
_posy = value;
}
int DungeonRoom::get_posz() {
return _posz;
}
void DungeonRoom::set_posz(int value) {
_posz = value;
}
//Size
int DungeonRoom::get_sizex() {
return _sizex;
}
void DungeonRoom::set_sizex(int value) {
_sizex = value;
}
int DungeonRoom::get_sizey() {
return _sizey;
}
void DungeonRoom::set_sizey(int value) {
_sizey = value;
}
int DungeonRoom::get_sizez() {
return _sizez;
}
void DungeonRoom::set_sizez(int value) {
_sizez = value;
}
//Props
Ref<WorldGeneratorPropData> DungeonRoom::get_prop_data(const int index) const {
ERR_FAIL_INDEX_V(index, _prop_datas.size(), Ref<WorldGeneratorPropData>());
return _prop_datas.get(index);
}
void DungeonRoom::set_prop_data(const int index, const Ref<WorldGeneratorPropData> prop_data) {
ERR_FAIL_INDEX(index, _prop_datas.size());
_prop_datas.set(index, prop_data);
}
void DungeonRoom::add_prop_data(const Ref<WorldGeneratorPropData> prop_data) {
_prop_datas.push_back(prop_data);
}
void DungeonRoom::remove_prop_data(const int index) {
ERR_FAIL_INDEX(index, _prop_datas.size());
_prop_datas.remove(index);
}
int DungeonRoom::get_prop_data_count() const {
return _prop_datas.size();
}
Vector<Variant> DungeonRoom::get_prop_datas() {
Vector<Variant> r;
for (int i = 0; i < _prop_datas.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_prop_datas[i].get_ref_ptr());
#else
r.push_back(_prop_datas[i]);
#endif
}
return r;
}
void DungeonRoom::set_prop_datas(const Vector<Variant> &prop_datas) {
_prop_datas.clear();
for (int i = 0; i < prop_datas.size(); i++) {
Ref<WorldGeneratorPropData> prop_data = Ref<WorldGeneratorPropData>(prop_datas[i]);
_prop_datas.push_back(prop_data);
}
}
#ifdef ESS_PRESENT
//Entities
Ref<EntityData> DungeonRoom::get_entity_data(const int index) const {
ERR_FAIL_INDEX_V(index, _entity_datas.size(), Ref<EntityData>());
return _entity_datas.get(index);
}
void DungeonRoom::set_entity_data(const int index, const Ref<EntityData> entity_data) {
ERR_FAIL_INDEX(index, _entity_datas.size());
_entity_datas.set(index, entity_data);
}
void DungeonRoom::add_entity_data(const Ref<EntityData> entity_data) {
_entity_datas.push_back(entity_data);
}
void DungeonRoom::remove_entity_data(const int index) {
ERR_FAIL_INDEX(index, _entity_datas.size());
_entity_datas.remove(index);
}
int DungeonRoom::get_entity_data_count() const {
return _entity_datas.size();
}
Vector<Variant> DungeonRoom::get_entity_datas() {
Vector<Variant> r;
for (int i = 0; i < _entity_datas.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_entity_datas[i].get_ref_ptr());
#else
r.push_back(_entity_datas[i]);
#endif
}
return r;
}
void DungeonRoom::set_entity_datas(const Vector<Variant> &entity_datas) {
_entity_datas.clear();
for (int i = 0; i < entity_datas.size(); i++) {
Ref<EntityData> entity_data = Ref<EntityData>(entity_datas[i]);
_entity_datas.push_back(entity_data);
}
}
#endif
Ref<DungeonRoom> DungeonRoom::instance(const int seed) {
Ref<DungeonRoom> inst;
inst = Ref<DungeonRoom>(Object::cast_to<DungeonRoom>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<DungeonRoom> DungeonRoom::_instance(const int seed, Ref<DungeonRoom> inst) {
inst->set_current_seed(seed);
inst->set_level_range(_level_range);
inst->set_posx(_posx);
inst->set_posy(_posy);
inst->set_posz(_posz);
inst->set_sizex(_sizex);
inst->set_sizey(_sizey);
inst->set_sizez(_sizez);
inst->set_min_sizex(_min_sizex);
inst->set_min_sizey(_min_sizey);
inst->set_min_sizez(_min_sizez);
inst->set_max_sizex(_max_sizex);
inst->set_max_sizey(_max_sizey);
inst->set_max_sizez(_max_sizez);
for (int i = 0; i < _prop_datas.size(); ++i) {
Ref<WorldGeneratorPropData> p = _prop_datas[i];
inst->add_prop_data(p);
}
#ifdef ESS_PRESENT
for (int i = 0; i < _entity_datas.size(); ++i) {
Ref<EntityData> d = _entity_datas[i];
inst->add_entity_data(d);
}
#endif
#ifdef VOXELMAN_PRESENT
inst->set_voxel_environment(_voxel_environment);
//don't
//inst->set_structure(_structure);
for (int i = 0; i < _voxel_environment_datas.size(); ++i) {
Ref<EnvironmentData> d = _voxel_environment_datas[i];
if (!d.is_valid())
continue;
inst->add_voxel_environment_data(d);
}
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
Ref<VoxelSurface> d = _voxel_surfaces[i];
if (!d.is_valid())
continue;
inst->add_voxel_surface(d);
}
#endif
#ifdef TERRAMAN_PRESENT
inst->set_terra_environment(_terra_environment);
//don't
//inst->set_structure(_structure);
for (int i = 0; i < _terra_environment_datas.size(); ++i) {
Ref<TerraEnvironmentData> 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<TerraSurface> d = _terra_surfaces[i];
if (!d.is_valid())
continue;
inst->add_terra_surface(d);
}
#endif
return inst;
}
void DungeonRoom::setup() {
if (has_method("_setup")) {
call("_setup");
}
}
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> DungeonRoom::get_voxel_environment() {
return _voxel_environment;
}
void DungeonRoom::set_voxel_environment(Ref<EnvironmentData> value) {
_voxel_environment = value;
}
Ref<VoxelStructure> DungeonRoom::get_voxel_structure() {
return _voxel_structure;
}
void DungeonRoom::set_voxel_structure(Ref<VoxelStructure> structure) {
_voxel_structure = structure;
}
//Environments
Ref<EnvironmentData> DungeonRoom::get_voxel_environment_data(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_environment_datas.size(), Ref<EnvironmentData>());
return _voxel_environment_datas.get(index);
}
void DungeonRoom::set_voxel_environment_data(const int index, const Ref<EnvironmentData> environment_data) {
ERR_FAIL_INDEX(index, _voxel_environment_datas.size());
_voxel_environment_datas.set(index, environment_data);
}
void DungeonRoom::add_voxel_environment_data(const Ref<EnvironmentData> environment_data) {
_voxel_environment_datas.push_back(environment_data);
}
void DungeonRoom::remove_voxel_environment_data(const int index) {
ERR_FAIL_INDEX(index, _voxel_environment_datas.size());
_voxel_environment_datas.remove(index);
}
int DungeonRoom::get_voxel_environment_data_count() const {
return _voxel_environment_datas.size();
}
Vector<Variant> DungeonRoom::get_voxel_environment_datas() {
Vector<Variant> r;
for (int i = 0; i < _voxel_environment_datas.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_environment_datas[i].get_ref_ptr());
#else
r.push_back(_voxel_environment_datas[i]);
#endif
}
return r;
}
void DungeonRoom::set_voxel_environment_datas(const Vector<Variant> &environment_datas) {
_voxel_environment_datas.clear();
for (int i = 0; i < environment_datas.size(); i++) {
Ref<EnvironmentData> environment_data = Ref<EnvironmentData>(environment_datas[i]);
_voxel_environment_datas.push_back(environment_data);
}
}
//// Surfaces ////
Ref<VoxelSurface> DungeonRoom::get_voxel_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>());
return _voxel_surfaces.get(index);
}
void DungeonRoom::set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.set(index, voxel_surface);
}
void DungeonRoom::add_voxel_surface(const Ref<VoxelSurface> voxel_surface) {
_voxel_surfaces.push_back(voxel_surface);
}
void DungeonRoom::remove_voxel_surface(const int index) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.remove(index);
}
int DungeonRoom::get_voxel_surface_count() const {
return _voxel_surfaces.size();
}
Vector<Variant> DungeonRoom::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_surfaces[i].get_ref_ptr());
#else
r.push_back(_voxel_surfaces[i]);
#endif
}
return r;
}
void DungeonRoom::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
_voxel_surfaces.clear();
for (int i = 0; i < voxel_surfaces.size(); i++) {
Ref<VoxelSurface> voxel_surface = Ref<VoxelSurface>(voxel_surfaces[i]);
_voxel_surfaces.push_back(voxel_surface);
}
}
void DungeonRoom::setup_voxel_library(Ref<VoxelmanLibrary> library) {
if (has_method("_setup_voxel_library")) {
call("_setup_voxel_library", library);
}
}
void DungeonRoom::_setup_voxel_library(Ref<VoxelmanLibrary> library) {
for (int i = 0; i < get_voxel_surface_count(); ++i) {
Ref<VoxelSurface> s = get_voxel_surface(i);
if (s.is_valid()) {
library->voxel_surface_add(s);
}
}
#ifdef PROPS_PRESENT
for (int i = 0; i < get_prop_data_count(); ++i) {
Ref<WorldGeneratorPropData> s = get_prop_data(i);
if (s.is_valid()) {
Ref<PackedScene> pd = s->get_prop();
if (pd.is_valid())
library->prop_add(pd);
}
}
#endif
}
void DungeonRoom::generate_voxel_chunk(Ref<VoxelChunk> chunk, bool spawn_mobs) {
ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_generate_voxel_chunk")) {
call("_generate_voxel_chunk", chunk, spawn_mobs);
}
}
void DungeonRoom::generate_voxel_room(Ref<VoxelStructure> structure, bool spawn_mobs) {
if (has_method("_generate_voxel_room")) {
call("_generate_voxel_room", structure, spawn_mobs);
}
}
#endif
#ifdef TERRAMAN_PRESENT
Ref<TerraEnvironmentData> DungeonRoom::get_terra_environment() {
return _terra_environment;
}
void DungeonRoom::set_terra_environment(Ref<TerraEnvironmentData> value) {
_terra_environment = value;
}
Ref<TerraStructure> DungeonRoom::get_terra_structure() {
return _terra_structure;
}
void DungeonRoom::set_terra_structure(Ref<TerraStructure> structure) {
_terra_structure = structure;
}
//Environments
Ref<TerraEnvironmentData> DungeonRoom::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 DungeonRoom::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 DungeonRoom::add_terra_environment_data(const Ref<TerraEnvironmentData> environment_data) {
_terra_environment_datas.push_back(environment_data);
}
void DungeonRoom::remove_terra_environment_data(const int index) {
ERR_FAIL_INDEX(index, _terra_environment_datas.size());
_terra_environment_datas.remove(index);
}
int DungeonRoom::get_terra_environment_data_count() const {
return _terra_environment_datas.size();
}
Vector<Variant> DungeonRoom::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 DungeonRoom::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);
}
}
//// Surfaces ////
Ref<TerraSurface> DungeonRoom::get_terra_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _terra_surfaces.size(), Ref<TerraSurface>());
return _terra_surfaces.get(index);
}
void DungeonRoom::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 DungeonRoom::add_terra_surface(const Ref<TerraSurface> terra_surface) {
_terra_surfaces.push_back(terra_surface);
}
void DungeonRoom::remove_terra_surface(const int index) {
ERR_FAIL_INDEX(index, _terra_surfaces.size());
_terra_surfaces.remove(index);
}
int DungeonRoom::get_terra_surface_count() const {
return _terra_surfaces.size();
}
Vector<Variant> DungeonRoom::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 DungeonRoom::set_terra_surfaces(const Vector<Variant> &terra_surfaces) {
_terra_surfaces.clear();
for (int i = 0; i < terra_surfaces.size(); i++) {
Ref<TerraSurface> terra_surface = Ref<TerraSurface>(terra_surfaces[i]);
_terra_surfaces.push_back(terra_surface);
}
}
void DungeonRoom::setup_terra_library(Ref<TerramanLibrary> library) {
if (has_method("_setup_terra_library")) {
call("_setup_terra_library", library);
}
}
void DungeonRoom::_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);
}
}
#ifdef PROPS_PRESENT
for (int i = 0; i < get_prop_data_count(); ++i) {
Ref<WorldGeneratorPropData> s = get_prop_data(i);
if (s.is_valid()) {
Ref<PackedScene> pd = s->get_prop();
if (pd.is_valid())
library->prop_add(pd);
}
}
#endif
}
void DungeonRoom::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 DungeonRoom::generate_terra_room(Ref<TerraStructure> structure, bool spawn_mobs) {
if (has_method("_generate_terra_room")) {
call("_generate_terra_room", structure, spawn_mobs);
}
}
#endif
DungeonRoom::DungeonRoom() {
_current_seed = 0;
_min_sizex = 0;
_min_sizey = 0;
_min_sizez = 0;
_max_sizex = 0;
_max_sizey = 0;
_max_sizez = 0;
_posx = 0;
_posy = 0;
_posz = 0;
_sizex = 0;
_sizey = 0;
_sizez = 0;
}
DungeonRoom::~DungeonRoom() {
_prop_datas.clear();
#ifdef ESS_PRESENT
_entity_datas.clear();
#endif
#ifdef VOXELMAN_PRESENT
_voxel_environment.unref();
_voxel_structure.unref();
_voxel_environment_datas.clear();
_voxel_surfaces.clear();
#endif
#ifdef TERRAMAN_PRESENT
_terra_environment.unref();
_terra_structure.unref();
_terra_environment_datas.clear();
_terra_surfaces.clear();
#endif
}
void DungeonRoom::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "DungeonRoom"),
"_instance",
PropertyInfo(Variant::INT, "p_seed"),
PropertyInfo(Variant::OBJECT, "p_instance", PROPERTY_HINT_RESOURCE_TYPE, "DungeonRoom")));
BIND_VMETHOD(MethodInfo("_setup"));
ClassDB::bind_method(D_METHOD("instance", "seed"), &DungeonRoom::instance);
ClassDB::bind_method(D_METHOD("_instance", "p_seed", "p_instance"), &DungeonRoom::_instance);
ClassDB::bind_method(D_METHOD("setup"), &DungeonRoom::setup);
ClassDB::bind_method(D_METHOD("get_current_seed"), &DungeonRoom::get_current_seed);
ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &DungeonRoom::set_current_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed");
ClassDB::bind_method(D_METHOD("get_level_range"), &DungeonRoom::get_level_range);
ClassDB::bind_method(D_METHOD("set_level_range", "value"), &DungeonRoom::set_level_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range");
//Min Size
ClassDB::bind_method(D_METHOD("get_min_sizex"), &DungeonRoom::get_min_sizex);
ClassDB::bind_method(D_METHOD("set_min_sizex", "value"), &DungeonRoom::set_min_sizex);
ADD_PROPERTY(PropertyInfo(Variant::INT, "min_sizex"), "set_min_sizex", "get_min_sizex");
ClassDB::bind_method(D_METHOD("get_min_sizey"), &DungeonRoom::get_min_sizey);
ClassDB::bind_method(D_METHOD("set_min_sizey", "value"), &DungeonRoom::set_min_sizey);
ADD_PROPERTY(PropertyInfo(Variant::INT, "min_sizey"), "set_min_sizey", "get_min_sizey");
ClassDB::bind_method(D_METHOD("get_min_sizez"), &DungeonRoom::get_min_sizez);
ClassDB::bind_method(D_METHOD("set_min_sizez", "value"), &DungeonRoom::set_min_sizez);
ADD_PROPERTY(PropertyInfo(Variant::INT, "min_sizez"), "set_min_sizez", "get_min_sizez");
//Max Size
ClassDB::bind_method(D_METHOD("get_max_sizex"), &DungeonRoom::get_max_sizex);
ClassDB::bind_method(D_METHOD("set_max_sizex", "value"), &DungeonRoom::set_max_sizex);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_sizex"), "set_max_sizex", "get_max_sizex");
ClassDB::bind_method(D_METHOD("get_max_sizey"), &DungeonRoom::get_max_sizey);
ClassDB::bind_method(D_METHOD("set_max_sizey", "value"), &DungeonRoom::set_max_sizey);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_sizey"), "set_max_sizey", "get_max_sizey");
ClassDB::bind_method(D_METHOD("get_max_sizez"), &DungeonRoom::get_max_sizez);
ClassDB::bind_method(D_METHOD("set_max_sizez", "value"), &DungeonRoom::set_max_sizez);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_sizez"), "set_max_sizez", "get_max_sizez");
//Position
ClassDB::bind_method(D_METHOD("get_posx"), &DungeonRoom::get_posx);
ClassDB::bind_method(D_METHOD("set_posx", "value"), &DungeonRoom::set_posx);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posx"), "set_posx", "get_posx");
ClassDB::bind_method(D_METHOD("get_posy"), &DungeonRoom::get_posy);
ClassDB::bind_method(D_METHOD("set_posy", "value"), &DungeonRoom::set_posy);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posy"), "set_posy", "get_posy");
ClassDB::bind_method(D_METHOD("get_posz"), &DungeonRoom::get_posz);
ClassDB::bind_method(D_METHOD("set_posz", "value"), &DungeonRoom::set_posz);
ADD_PROPERTY(PropertyInfo(Variant::INT, "posz"), "set_posz", "get_posz");
//Size
ClassDB::bind_method(D_METHOD("get_sizex"), &DungeonRoom::get_sizex);
ClassDB::bind_method(D_METHOD("set_sizex", "value"), &DungeonRoom::set_sizex);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizex"), "set_sizex", "get_sizex");
ClassDB::bind_method(D_METHOD("get_sizey"), &DungeonRoom::get_sizey);
ClassDB::bind_method(D_METHOD("set_sizey", "value"), &DungeonRoom::set_sizey);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizey"), "set_sizey", "get_sizey");
ClassDB::bind_method(D_METHOD("get_sizez"), &DungeonRoom::get_sizez);
ClassDB::bind_method(D_METHOD("set_sizez", "value"), &DungeonRoom::set_sizez);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sizez"), "set_sizez", "get_sizez");
//Props
ClassDB::bind_method(D_METHOD("get_prop_data", "index"), &DungeonRoom::get_prop_data);
ClassDB::bind_method(D_METHOD("set_prop_data", "index", "data"), &DungeonRoom::set_prop_data);
ClassDB::bind_method(D_METHOD("add_prop_data", "prop_data"), &DungeonRoom::add_prop_data);
ClassDB::bind_method(D_METHOD("remove_prop_data", "index"), &DungeonRoom::remove_prop_data);
ClassDB::bind_method(D_METHOD("get_prop_data_count"), &DungeonRoom::get_prop_data_count);
ClassDB::bind_method(D_METHOD("get_prop_datas"), &DungeonRoom::get_prop_datas);
ClassDB::bind_method(D_METHOD("set_prop_datas", "prop_datas"), &DungeonRoom::set_prop_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "prop_datas", PROPERTY_HINT_NONE, "17/17:WorldGeneratorPropData", PROPERTY_USAGE_DEFAULT, "WorldGeneratorPropData"), "set_prop_datas", "get_prop_datas");
#ifdef ESS_PRESENT
//Entities
ClassDB::bind_method(D_METHOD("get_entity_data", "index"), &DungeonRoom::get_entity_data);
ClassDB::bind_method(D_METHOD("set_entity_data", "index", "data"), &DungeonRoom::set_entity_data);
ClassDB::bind_method(D_METHOD("add_entity_data", "entity_data"), &DungeonRoom::add_entity_data);
ClassDB::bind_method(D_METHOD("remove_entity_data", "index"), &DungeonRoom::remove_entity_data);
ClassDB::bind_method(D_METHOD("get_entity_data_count"), &DungeonRoom::get_entity_data_count);
ClassDB::bind_method(D_METHOD("get_entity_datas"), &DungeonRoom::get_entity_datas);
ClassDB::bind_method(D_METHOD("set_entity_datas", "entity_datas"), &DungeonRoom::set_entity_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_datas", PROPERTY_HINT_NONE, "17/17:EntityData", PROPERTY_USAGE_DEFAULT, "EntityData"), "set_entity_datas", "get_entity_datas");
#endif
#ifdef VOXELMAN_PRESENT
ClassDB::bind_method(D_METHOD("get_voxel_environment"), &DungeonRoom::get_voxel_environment);
ClassDB::bind_method(D_METHOD("set_voxel_environment", "value"), &DungeonRoom::set_voxel_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "voxel_environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_voxel_environment", "get_voxel_environment");
ClassDB::bind_method(D_METHOD("get_voxel_structure"), &DungeonRoom::get_voxel_structure);
ClassDB::bind_method(D_METHOD("set_voxel_structure", "value"), &DungeonRoom::set_voxel_structure);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "voxel_structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), "set_voxel_structure", "get_voxel_structure");
//Environments
ClassDB::bind_method(D_METHOD("get_voxel_environment_data", "index"), &DungeonRoom::get_voxel_environment_data);
ClassDB::bind_method(D_METHOD("set_voxel_environment_data", "index", "data"), &DungeonRoom::set_voxel_environment_data);
ClassDB::bind_method(D_METHOD("add_voxel_environment_data", "environment_data"), &DungeonRoom::add_voxel_environment_data);
ClassDB::bind_method(D_METHOD("remove_voxel_environment_data", "index"), &DungeonRoom::remove_voxel_environment_data);
ClassDB::bind_method(D_METHOD("get_voxel_environment_data_count"), &DungeonRoom::get_voxel_environment_data_count);
ClassDB::bind_method(D_METHOD("get_voxel_environment_datas"), &DungeonRoom::get_voxel_environment_datas);
ClassDB::bind_method(D_METHOD("set_voxel_environment_datas", "voxel_environment_datas"), &DungeonRoom::set_voxel_environment_datas);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_environment_datas", PROPERTY_HINT_NONE, "17/17:EnvironmentData", PROPERTY_USAGE_DEFAULT, "EnvironmentData"), "set_voxel_environment_datas", "get_voxel_environment_datas");
//Surfaces
ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &DungeonRoom::get_voxel_surface);
ClassDB::bind_method(D_METHOD("set_voxel_surface", "index", "data"), &DungeonRoom::set_voxel_surface);
ClassDB::bind_method(D_METHOD("add_voxel_surface", "voxel_surface"), &DungeonRoom::add_voxel_surface);
ClassDB::bind_method(D_METHOD("remove_voxel_surface", "index"), &DungeonRoom::remove_voxel_surface);
ClassDB::bind_method(D_METHOD("get_voxel_surface_count"), &DungeonRoom::get_voxel_surface_count);
ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &DungeonRoom::get_voxel_surfaces);
ClassDB::bind_method(D_METHOD("set_voxel_surfaces", "voxel_surfaces"), &DungeonRoom::set_voxel_surfaces);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurface", PROPERTY_USAGE_DEFAULT, "VoxelSurface"), "set_voxel_surfaces", "get_voxel_surfaces");
BIND_VMETHOD(MethodInfo("_setup_voxel_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary")));
BIND_VMETHOD(MethodInfo("_generate_voxel_room", PropertyInfo(Variant::OBJECT, "structure", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStructure"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
BIND_VMETHOD(MethodInfo("_generate_voxel_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
ClassDB::bind_method(D_METHOD("setup_voxel_library", "library"), &DungeonRoom::setup_voxel_library);
ClassDB::bind_method(D_METHOD("_setup_voxel_library", "library"), &DungeonRoom::_setup_voxel_library);
ClassDB::bind_method(D_METHOD("generate_voxel_chunk", "chunk", "spawn_mobs"), &DungeonRoom::generate_voxel_chunk);
ClassDB::bind_method(D_METHOD("generate_voxel_room", "structure", "spawn_mobs"), &DungeonRoom::generate_voxel_room);
#endif
#ifdef TERRAMAN_PRESENT
ClassDB::bind_method(D_METHOD("get_terra_environment"), &DungeonRoom::get_terra_environment);
ClassDB::bind_method(D_METHOD("set_terra_environment", "value"), &DungeonRoom::set_terra_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "terra_environment", PROPERTY_HINT_RESOURCE_TYPE, "TerraEnvironmentData"), "set_terra_environment", "get_terra_environment");
ClassDB::bind_method(D_METHOD("get_terra_structure"), &DungeonRoom::get_terra_structure);
ClassDB::bind_method(D_METHOD("set_terra_structure", "value"), &DungeonRoom::set_terra_structure);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "terra_structure", PROPERTY_HINT_RESOURCE_TYPE, "TerraStructure"), "set_terra_structure", "get_terra_structure");
//Environments
ClassDB::bind_method(D_METHOD("get_terra_environment_data", "index"), &DungeonRoom::get_terra_environment_data);
ClassDB::bind_method(D_METHOD("set_terra_environment_data", "index", "data"), &DungeonRoom::set_terra_environment_data);
ClassDB::bind_method(D_METHOD("add_terra_environment_data", "environment_data"), &DungeonRoom::add_terra_environment_data);
ClassDB::bind_method(D_METHOD("remove_terra_environment_data", "index"), &DungeonRoom::remove_terra_environment_data);
ClassDB::bind_method(D_METHOD("get_terra_environment_data_count"), &DungeonRoom::get_terra_environment_data_count);
ClassDB::bind_method(D_METHOD("get_terra_environment_datas"), &DungeonRoom::get_terra_environment_datas);
ClassDB::bind_method(D_METHOD("set_terra_environment_datas", "terra_environment_datas"), &DungeonRoom::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"), &DungeonRoom::get_terra_surface);
ClassDB::bind_method(D_METHOD("set_terra_surface", "index", "data"), &DungeonRoom::set_terra_surface);
ClassDB::bind_method(D_METHOD("add_terra_surface", "terra_surface"), &DungeonRoom::add_terra_surface);
ClassDB::bind_method(D_METHOD("remove_terra_surface", "index"), &DungeonRoom::remove_terra_surface);
ClassDB::bind_method(D_METHOD("get_terra_surface_count"), &DungeonRoom::get_terra_surface_count);
ClassDB::bind_method(D_METHOD("get_terra_surfaces"), &DungeonRoom::get_terra_surfaces);
ClassDB::bind_method(D_METHOD("set_terra_surfaces", "terra_surfaces"), &DungeonRoom::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");
BIND_VMETHOD(MethodInfo("_setup_terra_library", PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "TerramanLibrary")));
BIND_VMETHOD(MethodInfo("_generate_terra_room", 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"), &DungeonRoom::setup_terra_library);
ClassDB::bind_method(D_METHOD("_setup_terra_library", "library"), &DungeonRoom::_setup_terra_library);
ClassDB::bind_method(D_METHOD("generate_terra_chunk", "chunk", "spawn_mobs"), &DungeonRoom::generate_terra_chunk);
ClassDB::bind_method(D_METHOD("generate_terra_room", "structure", "spawn_mobs"), &DungeonRoom::generate_terra_room);
#endif
}

View File

@ -104,27 +104,47 @@ void Planet::set_biomes(const Vector<Variant> &biomes) {
}
}
//// Dungeons ////
Ref<Dungeon> Planet::get_dungeon(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeons.size(), Ref<Dungeon>());
//// Buildings ////
Ref<Building> Planet::get_building(const int index) const {
ERR_FAIL_INDEX_V(index, _buildings.size(), Ref<Building>());
return _dungeons.get(index);
return _buildings.get(index);
}
void Planet::set_dungeon(const int index, const Ref<Dungeon> dungeon) {
ERR_FAIL_INDEX(index, _dungeons.size());
void Planet::set_building(const int index, const Ref<Building> building) {
ERR_FAIL_INDEX(index, _buildings.size());
_dungeons.set(index, dungeon);
_buildings.set(index, building);
}
void Planet::add_dungeon(const Ref<Dungeon> dungeon) {
_dungeons.push_back(dungeon);
void Planet::add_building(const Ref<Building> building) {
_buildings.push_back(building);
}
void Planet::remove_dungeon(const int index) {
ERR_FAIL_INDEX(index, _dungeons.size());
void Planet::remove_building(const int index) {
ERR_FAIL_INDEX(index, _buildings.size());
_dungeons.remove(index);
_buildings.remove(index);
}
int Planet::get_dungeon_count() const {
return _dungeons.size();
int Planet::get_building_count() const {
return _buildings.size();
}
Vector<Variant> Planet::get_buildings() {
Vector<Variant> r;
for (int i = 0; i < _buildings.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_buildings[i].get_ref_ptr());
#else
r.push_back(_buildings[i]);
#endif
}
return r;
}
void Planet::set_buildings(const Vector<Variant> &buildings) {
_buildings.clear();
for (int i = 0; i < buildings.size(); i++) {
Ref<Building> building = Ref<Building>(buildings[i]);
_buildings.push_back(building);
}
}
Ref<Planet> Planet::instance(const int seed) {
@ -153,13 +173,13 @@ Ref<Planet> Planet::_instance(const int seed, Ref<Planet> inst) {
inst->add_biome(b->instance(seed));
}
for (int i = 0; i < _dungeons.size(); ++i) {
Ref<Dungeon> d = _dungeons[i];
for (int i = 0; i < _buildings.size(); ++i) {
Ref<Building> d = _buildings[i];
if (!d.is_valid())
continue;
inst->add_dungeon(d->instance(seed));
inst->add_building(d->instance(seed));
}
#ifdef FASTNOISE_PRESENT
@ -349,8 +369,8 @@ void Planet::_setup_voxel_library(Ref<VoxelmanLibrary> library) {
}
}
for (int i = 0; i < get_dungeon_count(); ++i) {
Ref<Dungeon> d = get_dungeon(i);
for (int i = 0; i < get_building_count(); ++i) {
Ref<Building> d = get_building(i);
if (d.is_valid()) {
d->setup_voxel_library(library);
@ -486,14 +506,6 @@ void Planet::_setup_terra_library(Ref<TerramanLibrary> library) {
s->setup_terra_library(library);
}
}
for (int i = 0; i < get_dungeon_count(); ++i) {
Ref<Dungeon> d = get_dungeon(i);
if (d.is_valid()) {
d->setup_terra_library(library);
}
}
}
void Planet::generate_terra_chunk(Ref<TerraChunk> chunk, bool spawn_mobs) {
@ -512,7 +524,7 @@ Planet::Planet() {
}
Planet::~Planet() {
_biomes.clear();
_dungeons.clear();
_buildings.clear();
#ifdef FASTNOISE_PRESENT
_humidity_noise_params.unref();
@ -580,12 +592,16 @@ void Planet::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_biomes", "biomes"), &Planet::set_biomes);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "biomes", PROPERTY_HINT_NONE, "17/17:Biome", PROPERTY_USAGE_DEFAULT, "Biome"), "set_biomes", "get_biomes");
//Dungeons
ClassDB::bind_method(D_METHOD("get_dungeon", "index"), &Planet::get_dungeon);
ClassDB::bind_method(D_METHOD("set_dungeon", "index", "data"), &Planet::set_dungeon);
ClassDB::bind_method(D_METHOD("add_dungeon", "dungeon"), &Planet::add_dungeon);
ClassDB::bind_method(D_METHOD("remove_dungeon", "index"), &Planet::remove_dungeon);
ClassDB::bind_method(D_METHOD("get_dungeon_count"), &Planet::get_dungeon_count);
//Buildings
ClassDB::bind_method(D_METHOD("get_building", "index"), &Planet::get_building);
ClassDB::bind_method(D_METHOD("set_building", "index", "data"), &Planet::set_building);
ClassDB::bind_method(D_METHOD("add_building", "dungeon"), &Planet::add_building);
ClassDB::bind_method(D_METHOD("remove_building", "index"), &Planet::remove_building);
ClassDB::bind_method(D_METHOD("get_building_count"), &Planet::get_building_count);
ClassDB::bind_method(D_METHOD("get_buildings"), &Planet::get_buildings);
ClassDB::bind_method(D_METHOD("set_buildings", "buildings"), &Planet::set_buildings);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buildings", PROPERTY_HINT_NONE, "17/17:Building", PROPERTY_USAGE_DEFAULT, "Building"), "set_buildings", "get_buildings");
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "_generate_map"));

View File

@ -36,7 +36,7 @@ SOFTWARE.
#endif
#include "biome.h"
#include "dungeon.h"
#include "building.h"
#ifdef FASTNOISE_PRESENT
#include "../../fastnoise/fastnoise_noise_params.h"
@ -87,12 +87,15 @@ public:
Vector<Variant> get_biomes();
void set_biomes(const Vector<Variant> &biome_datas);
//Dungeons
Ref<Dungeon> get_dungeon(const int index) const;
void set_dungeon(const int index, const Ref<Dungeon> dungeon);
void add_dungeon(const Ref<Dungeon> dungeon);
void remove_dungeon(const int index);
int get_dungeon_count() const;
//Building
Ref<Building> get_building(const int index) const;
void set_building(const int index, const Ref<Building> building);
void add_building(const Ref<Building> building);
void remove_building(const int index);
int get_building_count() const;
Vector<Variant> get_buildings();
void set_buildings(const Vector<Variant> &buildings);
Ref<Planet> instance(const int seed);
virtual Ref<Planet> _instance(const int seed, Ref<Planet> inst);
@ -176,7 +179,7 @@ private:
Vector2 _level_range;
Vector<Ref<Biome> > _biomes;
Vector<Ref<Dungeon> > _dungeons;
Vector<Ref<Building> > _buildings;
#ifdef FASTNOISE_PRESENT
Ref<FastnoiseNoiseParams> _humidity_noise_params;

View File

@ -24,10 +24,8 @@ SOFTWARE.
#include "data/world_generator_prop_data.h"
#include "main/building.h"
#include "main/biome.h"
#include "main/dungeon.h"
#include "main/dungeon_corridor.h"
#include "main/dungeon_room.h"
#include "main/planet.h"
#include "world_generator.h"
@ -35,9 +33,7 @@ SOFTWARE.
void register_world_generator_types() {
ClassDB::register_class<WorldGeneratorPropData>();
ClassDB::register_class<DungeonRoom>();
ClassDB::register_class<DungeonCorridor>();
ClassDB::register_class<Dungeon>();
ClassDB::register_class<Building>();
ClassDB::register_class<Biome>();
ClassDB::register_class<Planet>();