Added DungeonCorridor.

This commit is contained in:
Relintai 2019-10-18 09:18:23 +02:00
parent a0fc4dfef2
commit a6b538f0d0
9 changed files with 161 additions and 11 deletions

1
SCsub
View File

@ -8,6 +8,7 @@ env.add_source_files(env.modules_sources,"main/biome.cpp")
env.add_source_files(env.modules_sources,"main/planet.cpp")
env.add_source_files(env.modules_sources,"data/dungeon_room_data.cpp")
env.add_source_files(env.modules_sources,"data/dungeon_corridor_data.cpp")
env.add_source_files(env.modules_sources,"data/dungeon_data.cpp")
env.add_source_files(env.modules_sources,"data/biome_data.cpp")
env.add_source_files(env.modules_sources,"data/planet_data.cpp")

View File

@ -0,0 +1,33 @@
#include "dungeon_corridor_data.h"
int DungeonCorridorData::get_max_connections() {
return _max_connections;
}
void DungeonCorridorData::set_max_connections(int value) {
_max_connections = value;
}
Ref<DungeonCorridor> DungeonCorridorData::setup_corridor(int seed) {
if (has_method("_setup_corridor")) {
return call("_setup_corridor", seed);
}
return Ref<DungeonCorridor>();
}
DungeonCorridorData::DungeonCorridorData() {
_max_connections = 2;
}
DungeonCorridorData::~DungeonCorridorData() {
}
void DungeonCorridorData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "corridor", PROPERTY_HINT_RESOURCE_TYPE, "DungeonCorridor"), "_setup_corridor", PropertyInfo(Variant::INT, "seed")));
ClassDB::bind_method(D_METHOD("setup_corridor", "seed"), &DungeonCorridorData::setup_corridor);
ClassDB::bind_method(D_METHOD("get_max_connections"), &DungeonCorridorData::get_max_connections);
ClassDB::bind_method(D_METHOD("set_max_connections", "value"), &DungeonCorridorData::set_max_connections);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_connections"), "set_max_connections", "get_max_connections");
}

View File

@ -0,0 +1,27 @@
#ifndef DUNGEON_CORRIDOR_DATA_H
#define DUNGEON_CORRIDOR_DATA_H
#include "dungeon_room_data.h"
#include "../main/dungeon_corridor.h"
class DungeonCorridorData : public DungeonRoomData {
GDCLASS(DungeonCorridorData, DungeonRoomData);
public:
int get_max_connections();
void set_max_connections(int value);
Ref<DungeonCorridor> setup_corridor(int seed);
DungeonCorridorData();
~DungeonCorridorData();
protected:
static void _bind_methods();
private:
int _max_connections;
};
#endif

View File

@ -83,7 +83,7 @@ Ref<DungeonRoom> DungeonRoomData::setup_room(int seed) {
return call("_setup_room", seed);
}
return Ref<DungeonRoom>(NULL);
return Ref<DungeonRoom>();
}
DungeonRoomData::DungeonRoomData() {

View File

@ -130,17 +130,17 @@ int Dungeon::get_dungeon_end_room_count() const {
}
//Corridors
Ref<DungeonRoom> Dungeon::get_dungeon_corridor(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_corridors.size(), Ref<DungeonRoom>());
Ref<DungeonCorridor> Dungeon::get_dungeon_corridor(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeon_corridors.size(), Ref<DungeonCorridor>());
return _dungeon_corridors.get(index);
}
void Dungeon::set_dungeon_corridor(const int index, const Ref<DungeonRoom> dungeon_corridor) {
void Dungeon::set_dungeon_corridor(const int index, const Ref<DungeonCorridor> dungeon_corridor) {
ERR_FAIL_INDEX(index, _dungeon_corridors.size());
_dungeon_corridors.set(index, dungeon_corridor);
}
void Dungeon::add_dungeon_corridor(const Ref<DungeonRoom> dungeon_corridor) {
void Dungeon::add_dungeon_corridor(const Ref<DungeonCorridor> dungeon_corridor) {
_dungeon_corridors.push_back(dungeon_corridor);
}
void Dungeon::remove_dungeon_corridor(const int index) {

View File

@ -4,6 +4,7 @@
#include "core/reference.h"
#include "dungeon_room.h"
#include "dungeon_corridor.h"
#include "../../voxelman/world/voxel_chunk.h"
#include "../../voxelman/world/voxel_structure.h"
@ -63,9 +64,9 @@ public:
int get_dungeon_end_room_count() const;
//Corridors
Ref<DungeonRoom> get_dungeon_corridor(const int index) const;
void set_dungeon_corridor(const int index, const Ref<DungeonRoom> dungeon_corridors);
void add_dungeon_corridor(const Ref<DungeonRoom> dungeon_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;
@ -97,7 +98,7 @@ private:
Vector<Ref<DungeonRoom> > _dungeon_rooms;
Vector<Ref<DungeonRoom> > _dungeon_start_rooms;
Vector<Ref<DungeonRoom> > _dungeon_end_rooms;
Vector<Ref<DungeonRoom> > _dungeon_corridors;
Vector<Ref<DungeonCorridor> > _dungeon_corridors;
};
#endif

53
main/dungeon_corridor.cpp Normal file
View File

@ -0,0 +1,53 @@
#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();
}
DungeonRoom::DungeonRoom() {
_max_connections = 2;
}
DungeonRoom::~DungeonRoom() {
_dungeon_rooms.clear();
}
void DungeonRoom::_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);
}

33
main/dungeon_corridor.h Normal file
View File

@ -0,0 +1,33 @@
#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;
DungeonCorridor();
~DungeonCorridor();
protected:
static void _bind_methods();
private:
int _max_connections;
Vector<Ref<DungeonRoom> > _rooms;
};
#endif

View File

@ -1,6 +1,7 @@
#include "register_types.h"
#include "data/dungeon_room_data.h"
#include "data/dungeon_corridor_data.h"
#include "data/dungeon_data.h"
#include "data/biome_data.h"
#include "data/planet_data.h"
@ -15,6 +16,7 @@
void register_world_generator_types() {
ClassDB::register_class<DungeonRoomData>();
ClassDB::register_class<DungeonCorridorData>();
ClassDB::register_class<DungeonData>();
ClassDB::register_class<BiomeData>();
ClassDB::register_class<PlanetData>();