mirror of
https://github.com/Relintai/world_generator.git
synced 2024-11-20 10:47:18 +01:00
Initial commit.
This commit is contained in:
commit
7b711b79b5
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.import
|
||||
*.d
|
||||
*.o
|
||||
*.meta
|
||||
|
125
DungeonCorridor.cpp
Normal file
125
DungeonCorridor.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include "DungeonCorridor.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
DungeonRoom* DungeonCorridor::getStartRoom(){
|
||||
return this->startRoom;
|
||||
}
|
||||
void DungeonCorridor::setStartRoom(DungeonRoom* value)
|
||||
{
|
||||
this->startRoom = value;
|
||||
}
|
||||
DungeonRoom* DungeonCorridor::getEndRoom()
|
||||
{
|
||||
return this->endRoom;
|
||||
}
|
||||
void DungeonCorridor::setEndRoom(DungeonRoom* value)
|
||||
{
|
||||
this->endRoom = value;
|
||||
}
|
||||
DungeonCorridor::DungeonCorridor(int size, DungeonRoom* startRoom, DungeonRoom* endRoom)
|
||||
{
|
||||
size = 4;
|
||||
this->size = size;
|
||||
this->setStartRoom(startRoom);
|
||||
this->setEndRoom(endRoom);
|
||||
}
|
||||
void DungeonCorridor::GenerateCorridor(ArrayND<char, 2>* dungeon)
|
||||
{
|
||||
int num = this->getStartRoom()->X + Mathf::RoundToInt((float)(this->getStartRoom()->Width) / (float)2);
|
||||
int num2 = this->getStartRoom()->Y + Mathf::RoundToInt((float)(this->getStartRoom()->Height) / (float)2);
|
||||
int num3 = this->getEndRoom()->X + Mathf::RoundToInt((float)(this->getEndRoom()->Width) / (float)2);
|
||||
int num4 = this->getEndRoom()->Y + Mathf::RoundToInt((float)(this->getEndRoom()->Height) / (float)2);
|
||||
if ((num <= num3) && (num2 <= num4)) {
|
||||
this->widthir = new IntRect(num, num2, num3 - num, this->size);
|
||||
this->heightir = new IntRect((this->widthir->X + this->widthir->Width) - this->size, num2, this->size, num4 - num2);
|
||||
}
|
||||
else {
|
||||
if ((num > num3) && (num2 <= num4)) {
|
||||
this->widthir = new IntRect(num3, num2, num - num3, this->size);
|
||||
this->heightir = new IntRect(this->widthir->X, num2, this->size, num4 - num2);
|
||||
}
|
||||
else {
|
||||
if ((num <= num3) && (num2 > num4)) {
|
||||
this->widthir = new IntRect(num, num4, num3 - num, this->size);
|
||||
this->heightir = new IntRect(num, num4, this->size, num2 - num4);
|
||||
}
|
||||
else {
|
||||
if ((num > num3) && (num2 > num4)) {
|
||||
this->widthir = new IntRect(num3 - this->size, num2 - this->size, num - num3, this->size);
|
||||
this->heightir = new IntRect(this->widthir->X, num4, this->size, num2 - num4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this->Write(dungeon, this->widthir);
|
||||
this->Write(dungeon, this->heightir);
|
||||
}
|
||||
void DungeonCorridor::Write(ArrayND<char, 2>* dungeon, IntRect* rect)
|
||||
{
|
||||
for (int i = rect->getY(); i < (rect->getY() + rect->getHeight()); i += 1) {
|
||||
for (int j = rect->getX(); j < (rect->getX() + rect->getWidth()); j += 1) {
|
||||
if (((*(dungeon->GetData(j, i)) != 1) && (*(dungeon->GetData(j, i)) != 2)) && (*(dungeon->GetData(j, i)) != 20)) {
|
||||
if ((j == rect->getX()) && (i == rect->getY())) {
|
||||
dungeon->SetData(j, i, 13);
|
||||
}
|
||||
else {
|
||||
if ((j == rect->getX()) && (i == ((rect->getY() + rect->getHeight()) - 1))) {
|
||||
dungeon->SetData(j, i, 13);
|
||||
}
|
||||
else {
|
||||
if ((j == ((rect->getX() + rect->getWidth()) - 1)) && (i == rect->getY())) {
|
||||
dungeon->SetData(j, i, 13);
|
||||
}
|
||||
else {
|
||||
if ((j == ((rect->getX() + rect->getWidth()) - 1)) && (i == ((rect->getY() + rect->getHeight()) - 1))) {
|
||||
dungeon->SetData(j, i, 13);
|
||||
}
|
||||
else {
|
||||
if (j == rect->getX()) {
|
||||
dungeon->SetData(j, i, 14);
|
||||
}
|
||||
else {
|
||||
if (j == ((rect->getX() + rect->getWidth()) - 1)) {
|
||||
dungeon->SetData(j, i, 12);
|
||||
}
|
||||
else {
|
||||
if (i == rect->getY()) {
|
||||
dungeon->SetData(j, i, 13);
|
||||
}
|
||||
else {
|
||||
if (i == ((rect->getY() + rect->getHeight()) - 1)) {
|
||||
dungeon->SetData(j, i, 11);
|
||||
}
|
||||
else {
|
||||
dungeon->SetData(j, i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DungeonCorridor::GenerateAIPlayers(int level)
|
||||
{
|
||||
this->GenerateAIPlayers(level, this->widthir);
|
||||
this->GenerateAIPlayers(level, this->heightir);
|
||||
}
|
||||
void DungeonCorridor::GenerateAIPlayers(int level, IntRect* rect)
|
||||
{
|
||||
int num = UnityEngine::Random::Range(0, 3);
|
||||
for (int i = 0; i < num; i += 1) {
|
||||
int num2 = rect->getX() + UnityEngine::Random::Range(1, rect->getWidth() - 2);
|
||||
int num3 = rect->getY() + UnityEngine::Random::Range(1, rect->getHeight() - 2);
|
||||
new Vector3(((float)(num2) * Voxelizzer::world->voxelScale) * (float)2, Voxelizzer::world->voxelScale, ((float)(num3) * Voxelizzer::world->voxelScale) * (float)2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
49
DungeonCorridor.h
Normal file
49
DungeonCorridor.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
#include "DungeonRoom.h"
|
||||
#include "IntRect.h"
|
||||
#include "Mathf.h"
|
||||
#include "UnityEngine.h"
|
||||
#include "Vector3.h"
|
||||
#include "Voxelizzer.h"
|
||||
|
||||
using namespace UnityEngine;
|
||||
using namespace VoxelToolbox;
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class DungeonCorridor : public virtual Object
|
||||
{
|
||||
private:
|
||||
DungeonRoom* startRoom;
|
||||
private:
|
||||
DungeonRoom* endRoom;
|
||||
public:
|
||||
int size;
|
||||
private:
|
||||
IntRect* widthir;
|
||||
private:
|
||||
IntRect* heightir;
|
||||
public:
|
||||
DungeonRoom* getStartRoom();
|
||||
public:
|
||||
void setStartRoom(DungeonRoom* value);
|
||||
public:
|
||||
DungeonRoom* getEndRoom();
|
||||
public:
|
||||
void setEndRoom(DungeonRoom* value);
|
||||
public:
|
||||
DungeonCorridor(int size, DungeonRoom* startRoom, DungeonRoom* endRoom);
|
||||
public:
|
||||
void GenerateCorridor(ArrayND<char, 2>* dungeon);
|
||||
private:
|
||||
void Write(ArrayND<char, 2>* dungeon, IntRect* rect);
|
||||
public:
|
||||
virtual void GenerateAIPlayers(int level);
|
||||
private:
|
||||
void GenerateAIPlayers(int level, IntRect* rect);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
37
DungeonEndRoom.cpp
Normal file
37
DungeonEndRoom.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "DungeonEndRoom.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
DungeonEndRoom::DungeonEndRoom(int x, int y, int width, int height) : DungeonRoom(x, y, width, height){
|
||||
}
|
||||
void DungeonEndRoom::WriteRoom(ArrayND<char, 2>* dungeon)
|
||||
{
|
||||
for (int i = DungeonRoom::getY(); i < (DungeonRoom::getY() + DungeonRoom::getHeight()); i += 1) {
|
||||
for (int j = DungeonRoom::getX(); j < (DungeonRoom::getX() + DungeonRoom::getWidth()); j += 1) {
|
||||
dungeon->SetData(j, i, 1);
|
||||
}
|
||||
}
|
||||
for (int k = DungeonRoom::getX() + 1; k < ((DungeonRoom::getX() + DungeonRoom::getWidth()) - 1); k += 1) {
|
||||
dungeon->SetData(k, (DungeonRoom::getY() + DungeonRoom::getHeight()) - 1, 11);
|
||||
}
|
||||
for (int l = DungeonRoom::getX() + 1; l < ((DungeonRoom::getX() + DungeonRoom::getWidth()) - 1); l += 1) {
|
||||
dungeon->SetData(l, DungeonRoom::getY(), 13);
|
||||
}
|
||||
for (int m = DungeonRoom::getY() + 1; m < ((DungeonRoom::getY() + DungeonRoom::getHeight()) - 1); m += 1) {
|
||||
dungeon->SetData(DungeonRoom::getX(), m, 14);
|
||||
}
|
||||
for (int n = DungeonRoom::getY() + 1; n < ((DungeonRoom::getY() + DungeonRoom::getHeight()) - 1); n += 1) {
|
||||
dungeon->SetData((DungeonRoom::getX() + DungeonRoom::getWidth()) - 1, n, 12);
|
||||
}
|
||||
dungeon->SetData(DungeonRoom::getX(), DungeonRoom::getY(), 13);
|
||||
dungeon->SetData((DungeonRoom::getX() + DungeonRoom::getWidth()) - 1, DungeonRoom::getY(), 13);
|
||||
dungeon->SetData(DungeonRoom::getX(), (DungeonRoom::getY() + DungeonRoom::getHeight()) - 1, 13);
|
||||
dungeon->SetData((DungeonRoom::getX() + DungeonRoom::getWidth()) - 1, (DungeonRoom::getY() + DungeonRoom::getHeight()) - 1, 13);
|
||||
int num = UnityEngine::Random::Range(DungeonRoom::getX() + 1, (DungeonRoom::getX() + DungeonRoom::getWidth()) - 1);
|
||||
int num2 = UnityEngine::Random::Range(DungeonRoom::getY() + 1, (DungeonRoom::getY() + DungeonRoom::getHeight()) - 1);
|
||||
dungeon->SetData(num, num2, 20);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
19
DungeonEndRoom.h
Normal file
19
DungeonEndRoom.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
#include "DungeonRoom.h"
|
||||
#include "UnityEngine.h"
|
||||
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class DungeonEndRoom : public virtual DungeonRoom, public virtual Object
|
||||
{
|
||||
public:
|
||||
DungeonEndRoom(int x, int y, int width, int height);
|
||||
public:
|
||||
virtual void WriteRoom(ArrayND<char, 2>* dungeon);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
205
DungeonGenerator.cpp
Normal file
205
DungeonGenerator.cpp
Normal file
@ -0,0 +1,205 @@
|
||||
#include "DungeonGenerator.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
ArrayND<char, 2>* DungeonGenerator::getDungeon(){
|
||||
return this->dungeon;
|
||||
}
|
||||
void DungeonGenerator::Awake()
|
||||
{
|
||||
this->rooms = new List_T<DungeonRoom>();
|
||||
this->corridors = new List_T<DungeonCorridor>();
|
||||
this->dungeon = new ArrayND<char>(this->DUNGEON_Size_X, this->DUNGEON_Size_Y);
|
||||
}
|
||||
void DungeonGenerator::Generate(int level)
|
||||
{
|
||||
UnityEngine::Random::InitState(BrokenSeals::Game->Seed);
|
||||
if (!CxNet::IsServer) {
|
||||
this->SpawnMobs = false;
|
||||
}
|
||||
this->GenerateDungeon();
|
||||
this->GenerateCorridors();
|
||||
this->PreprocessDungeonSimple();
|
||||
this->GeneratePlayers(level);
|
||||
}
|
||||
void DungeonGenerator::GenerateDungeon()
|
||||
{
|
||||
for (int i = 0; i < this->ROOM_PLACEMENT_TRIES; i += 1) {
|
||||
int x = UnityEngine::Random::Range(0, this->DUNGEON_Size_X - this->ROOM_MAX_SIZE);
|
||||
int y = UnityEngine::Random::Range(0, this->DUNGEON_Size_Y - this->ROOM_MAX_SIZE);
|
||||
int width = UnityEngine::Random::Range(this->ROOM_MIN_SIZE, this->ROOM_MAX_SIZE);
|
||||
int height = UnityEngine::Random::Range(this->ROOM_MIN_SIZE, this->ROOM_MAX_SIZE);
|
||||
if (this->CanPlaceRoom(x, y, width, height)) {
|
||||
if (this->rooms->Count > 0) {
|
||||
DungeonRoom* dungeonRoom = new DungeonRoom(x, y, width, height);
|
||||
dungeonRoom->WriteRoom(this->dungeon);
|
||||
this->corridors->Add(new DungeonCorridor(this->CORRIDOR_SIZE, this->rooms->GetData(this->rooms->Count - 1), dungeonRoom));
|
||||
this->rooms->Add(dungeonRoom);
|
||||
}
|
||||
else {
|
||||
DungeonStartRoom* dungeonStartRoom = new DungeonStartRoom(x, y, width, height);
|
||||
dungeonStartRoom->WriteRoom(this->dungeon);
|
||||
dungeonStartRoom->GenerateSpawnPoint(this->startPositionPrefab);
|
||||
this->rooms->Add(dungeonStartRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
DungeonRoom* dungeonRoom2 = this->rooms->GetData(this->rooms->Count - 1);
|
||||
this->rooms->Remove(dungeonRoom2);
|
||||
this->corridors->RemoveAt(this->corridors->Count - 1);
|
||||
DungeonEndRoom* dungeonEndRoom = new DungeonEndRoom(dungeonRoom2->getX(), dungeonRoom2->getY(), dungeonRoom2->getWidth(), dungeonRoom2->getHeight());
|
||||
this->corridors->Add(new DungeonCorridor(this->CORRIDOR_SIZE, this->rooms->GetData(this->rooms->Count - 1), dungeonEndRoom));
|
||||
this->rooms->Add(dungeonEndRoom);
|
||||
dungeonEndRoom->WriteRoom(this->dungeon);
|
||||
}
|
||||
void DungeonGenerator::GenerateCorridors()
|
||||
{
|
||||
for (int i = 0; i < this->corridors->Count; i += 1) {
|
||||
this->corridors->GetData(i)->GenerateCorridor(this->dungeon);
|
||||
}
|
||||
}
|
||||
void DungeonGenerator::GeneratePlayers(int level)
|
||||
{
|
||||
if (!this->SpawnMobs) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < this->rooms->Count; i += 1) {
|
||||
this->rooms->GetData(i)->GenerateAIPlayers(level);
|
||||
}
|
||||
for (int j = 0; j < this->corridors->Count; j += 1) {
|
||||
this->corridors->GetData(j)->GenerateAIPlayers(level);
|
||||
}
|
||||
}
|
||||
void DungeonGenerator::PreprocessDungeonSimple()
|
||||
{
|
||||
for (int i = 1; i < this->DUNGEON_Size_X; i += 1) {
|
||||
for (int j = 1; j < this->DUNGEON_Size_Y; j += 1) {
|
||||
this->dungeon->GetData(i, j);
|
||||
if (TileConsts::isWall(this->dungeon->GetData(i, j))) {
|
||||
bool arg_68_0 = *(this->dungeon->GetData(i, j - 1)) == 0;
|
||||
bool flag = *(this->dungeon->GetData(i - 1, j)) == 0;
|
||||
bool flag2 = *(this->dungeon->GetData(i - 1, j - 1)) == 0;
|
||||
if ((arg_68_0 | flag) | flag2) {
|
||||
this->dungeon->SetData(i, j, 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DungeonGenerator::PreprocessDungeon()
|
||||
{
|
||||
for (int i = 1; i < this->DUNGEON_Size_X; i += 1) {
|
||||
for (int j = 1; j < this->DUNGEON_Size_Y; j += 1) {
|
||||
char b = this->dungeon->GetData(i, j);
|
||||
if (((b != 0) && (b != 1)) && (b != 20)) {
|
||||
bool flag = TileConsts::isWall(this->dungeon->GetData(i, j + 1));
|
||||
bool flag2 = TileConsts::isWall(this->dungeon->GetData(i, j - 1));
|
||||
bool flag3 = TileConsts::isWall(this->dungeon->GetData(i - 1, j));
|
||||
bool flag4 = TileConsts::isWall(this->dungeon->GetData(i + 1, j));
|
||||
bool flag5 = TileConsts::isWall(this->dungeon->GetData(i + 1, j + 1));
|
||||
bool flag6 = TileConsts::isWall(this->dungeon->GetData(i - 1, j + 1));
|
||||
bool flag7 = TileConsts::isWall(this->dungeon->GetData(i + 1, j - 1));
|
||||
bool flag8 = TileConsts::isWall(this->dungeon->GetData(i - 1, j - 1));
|
||||
if (!flag & flag2) {
|
||||
if (((!flag4 & flag) & flag3) && !flag2) {
|
||||
this->dungeon->SetData(i, j, 17);
|
||||
}
|
||||
else {
|
||||
if (((!flag4 && !flag) & flag3) & flag2) {
|
||||
this->dungeon->SetData(i, j, 18);
|
||||
}
|
||||
else {
|
||||
if (((!flag3 && !flag) & flag4) & flag2) {
|
||||
this->dungeon->SetData(i, j, 17);
|
||||
}
|
||||
else {
|
||||
if (((((((flag3 && !flag8) && !flag2) && !flag7) && !flag4) && !flag5) & flag) && !flag6) {
|
||||
this->dungeon->SetData(i, j, 23);
|
||||
}
|
||||
else {
|
||||
if ((!flag3 & flag) & flag4) {
|
||||
}
|
||||
if (((((((flag3 && !flag8) & flag2) && !flag7) && !flag4) && !flag5) && !flag) && !flag6) {
|
||||
this->dungeon->SetData(i, j, 22);
|
||||
}
|
||||
else {
|
||||
if (((((((!flag3 && !flag8) && !flag2) && !flag7) & flag4) && !flag5) & flag) && !flag6) {
|
||||
this->dungeon->SetData(i, j, 21);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String* DungeonGenerator::StringifyDungeon()
|
||||
{
|
||||
this->sb = new StringBuilder();
|
||||
for (int i = 0; i < this->DUNGEON_Size_Y; i += 1) {
|
||||
for (int j = 0; j < this->DUNGEON_Size_X; j += 1) {
|
||||
if (*(this->dungeon->GetData(j, i)) != 0) {
|
||||
this->sb->Append(j);
|
||||
this->sb->Append(new String(";"));
|
||||
this->sb->Append(i);
|
||||
this->sb->Append(new String(";"));
|
||||
this->sb->Append(this->dungeon->GetData(j, i));
|
||||
this->sb->Append(new String("|"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this->sb->ToString();
|
||||
}
|
||||
void DungeonGenerator::GenerateDebugDungeon()
|
||||
{
|
||||
this->dungeon = new ArrayND<char>(this->DUNGEON_Size_X, this->DUNGEON_Size_Y);
|
||||
for (int i = 0; i < this->DUNGEON_Size_Y; i += 1) {
|
||||
for (int j = 0; j < this->DUNGEON_Size_X; j += 1) {
|
||||
this->dungeon->SetData(j, i, 1);
|
||||
}
|
||||
}
|
||||
for (int k = 0; k < 300; k += 1) {
|
||||
this->dungeon->SetData(UnityEngine::Random::Range(0, this->DUNGEON_Size_X), UnityEngine::Random::Range(0, this->DUNGEON_Size_Y), 2);
|
||||
}
|
||||
}
|
||||
bool DungeonGenerator::CanPlaceRoom(int x, int y, int width, int height)
|
||||
{
|
||||
for (int i = y; i < (y + height); i += 1) {
|
||||
for (int j = x; j < (x + width); j += 1) {
|
||||
if (*(this->dungeon->GetData(j, i)) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void DungeonGenerator::Reset()
|
||||
{
|
||||
if (this->rooms == null) {
|
||||
return;
|
||||
}
|
||||
this->rooms->Clear();
|
||||
this->corridors->Clear();
|
||||
for (int i = 0; i < this->DUNGEON_Size_Y; i += 1) {
|
||||
for (int j = 0; j < this->DUNGEON_Size_X; j += 1) {
|
||||
this->dungeon->SetData(j, i, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
DungeonGenerator::DungeonGenerator()
|
||||
{
|
||||
SpawnMobs = true;
|
||||
DUNGEON_Size_X = 200;
|
||||
DUNGEON_Size_Y = 200;
|
||||
ROOM_MIN_SIZE = 20;
|
||||
ROOM_MAX_SIZE = 26;
|
||||
ROOM_PLACEMENT_TRIES = 100;
|
||||
CORRIDOR_SIZE = 4;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
83
DungeonGenerator.h
Normal file
83
DungeonGenerator.h
Normal file
@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
#include "MonoBehaviour.h"
|
||||
#include "GameObject.h"
|
||||
#include "DungeonRoom.h"
|
||||
#include <System/Collections/Generic/List.h>
|
||||
#include "DungeonCorridor.h"
|
||||
#include <System/Text/StringBuilder.h>
|
||||
#include "UnityEngine.h"
|
||||
#include "BrokenSeals.h"
|
||||
#include "CxNet.h"
|
||||
#include "DungeonStartRoom.h"
|
||||
#include "DungeonEndRoom.h"
|
||||
#include "TileConsts.h"
|
||||
|
||||
using namespace UnityEngine;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace System::Text;
|
||||
using namespace CxNetworking;
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class DungeonGenerator : public virtual MonoBehaviour, public virtual Object
|
||||
{
|
||||
public:
|
||||
int Seed;
|
||||
public:
|
||||
bool SpawnMobs;
|
||||
public:
|
||||
int DUNGEON_Size_X;
|
||||
public:
|
||||
int DUNGEON_Size_Y;
|
||||
public:
|
||||
int ROOM_MIN_SIZE;
|
||||
public:
|
||||
int ROOM_MAX_SIZE;
|
||||
public:
|
||||
int ROOM_PLACEMENT_TRIES;
|
||||
public:
|
||||
int CORRIDOR_SIZE;
|
||||
//Attribute: SerializeField*
|
||||
private:
|
||||
GameObject* startPositionPrefab;
|
||||
private:
|
||||
ArrayND<char, 2>* dungeon;
|
||||
private:
|
||||
List_T<DungeonRoom>* rooms;
|
||||
private:
|
||||
List_T<DungeonCorridor>* corridors;
|
||||
private:
|
||||
StringBuilder* sb;
|
||||
public:
|
||||
ArrayND<char, 2>* getDungeon();
|
||||
//Ignored empty method declaration
|
||||
private:
|
||||
void Awake();
|
||||
public:
|
||||
void Generate(int level);
|
||||
public:
|
||||
void GenerateDungeon();
|
||||
public:
|
||||
void GenerateCorridors();
|
||||
public:
|
||||
void GeneratePlayers(int level);
|
||||
public:
|
||||
void PreprocessDungeonSimple();
|
||||
public:
|
||||
void PreprocessDungeon();
|
||||
public:
|
||||
String* StringifyDungeon();
|
||||
private:
|
||||
void GenerateDebugDungeon();
|
||||
private:
|
||||
bool CanPlaceRoom(int x, int y, int width, int height);
|
||||
public:
|
||||
void Reset();
|
||||
public:
|
||||
DungeonGenerator();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
161
DungeonRoom.cpp
Normal file
161
DungeonRoom.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
#include "DungeonRoom.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
Array<String>* DungeonRoom::biga;
|
||||
Array<String>* DungeonRoom::bigb;
|
||||
Array<String>* DungeonRoom::smalla;
|
||||
Array<String>* DungeonRoom::smallb;
|
||||
int DungeonRoom::getX(){
|
||||
return this->x;
|
||||
}
|
||||
void DungeonRoom::setX(int value)
|
||||
{
|
||||
this->x = value;
|
||||
}
|
||||
int DungeonRoom::getY()
|
||||
{
|
||||
return this->y;
|
||||
}
|
||||
void DungeonRoom::setY(int value)
|
||||
{
|
||||
this->y = value;
|
||||
}
|
||||
int DungeonRoom::getWidth()
|
||||
{
|
||||
return this->width;
|
||||
}
|
||||
void DungeonRoom::setWidth(int value)
|
||||
{
|
||||
this->width = value;
|
||||
}
|
||||
int DungeonRoom::getHeight()
|
||||
{
|
||||
return this->height;
|
||||
}
|
||||
void DungeonRoom::setHeight(int value)
|
||||
{
|
||||
this->height = value;
|
||||
}
|
||||
DungeonRoom::DungeonRoom(int x, int y, int width, int height)
|
||||
{
|
||||
this->setX(x);
|
||||
this->setY(y);
|
||||
this->setWidth(width);
|
||||
this->setHeight(height);
|
||||
}
|
||||
void DungeonRoom::WriteRoom(ArrayND<char, 2>* dungeon)
|
||||
{
|
||||
for (int i = this->getY(); i < (this->getY() + this->getHeight()); i += 1) {
|
||||
for (int j = this->getX(); j < (this->getX() + this->getWidth()); j += 1) {
|
||||
dungeon->SetData(j, i, 1);
|
||||
}
|
||||
}
|
||||
for (int k = this->getX() + 1; k < ((this->getX() + this->getWidth()) - 1); k += 1) {
|
||||
dungeon->SetData(k, (this->getY() + this->getHeight()) - 1, 11);
|
||||
}
|
||||
for (int l = this->getX() + 1; l < ((this->getX() + this->getWidth()) - 1); l += 1) {
|
||||
dungeon->SetData(l, this->getY(), 13);
|
||||
}
|
||||
for (int m = this->getY() + 1; m < ((this->getY() + this->getHeight()) - 1); m += 1) {
|
||||
dungeon->SetData(this->getX(), m, 14);
|
||||
}
|
||||
for (int n = this->getY() + 1; n < ((this->getY() + this->getHeight()) - 1); n += 1) {
|
||||
dungeon->SetData((this->getX() + this->getWidth()) - 1, n, 12);
|
||||
}
|
||||
dungeon->SetData(this->getX(), this->getY(), 13);
|
||||
dungeon->SetData((this->getX() + this->getWidth()) - 1, this->getY(), 13);
|
||||
dungeon->SetData(this->getX(), (this->getY() + this->getHeight()) - 1, 13);
|
||||
dungeon->SetData((this->getX() + this->getWidth()) - 1, (this->getY() + this->getHeight()) - 1, 13);
|
||||
}
|
||||
void DungeonRoom::GenerateAIPlayers(int level)
|
||||
{
|
||||
int num = UnityEngine::Random::Range(3, 5);
|
||||
for (int i = 0; i < num; i += 1) {
|
||||
int num2 = this->getX() + UnityEngine::Random::Range(1, this->getWidth() - 2);
|
||||
int num3 = this->getY() + UnityEngine::Random::Range(1, this->getHeight() - 2);
|
||||
Vector3* position = new Vector3((float)(num2) * Voxelizzer::world->voxelScale, Voxelizzer::world->voxelScale, (float)(num3) * Voxelizzer::world->voxelScale);
|
||||
Entity::SSpawn(EntityType::Mob, UnityEngine::Random::Range(10000, 10005), level, this->GenerateName(), 0u, null, false, position, );
|
||||
}
|
||||
}
|
||||
String* DungeonRoom::GenerateName()
|
||||
{
|
||||
UnityEngine::Random::State* state = UnityEngine::Random::state;
|
||||
String* text = DungeonRoom::biga->GetData(UnityEngine::Random::Range(0, DungeonRoom::biga->Length));
|
||||
bool flag = false;
|
||||
int num = UnityEngine::Random::Range(3, 7);
|
||||
for (int i = 0; i < num; i += 1) {
|
||||
if (flag) {
|
||||
*text += DungeonRoom::smallb->GetData(UnityEngine::Random::Range(0, DungeonRoom::smallb->Length));
|
||||
}
|
||||
else {
|
||||
*text += DungeonRoom::smalla->GetData(UnityEngine::Random::Range(0, DungeonRoom::smalla->Length));
|
||||
}
|
||||
flag = !flag;
|
||||
}
|
||||
UnityEngine::Random::state = state;
|
||||
return text;
|
||||
}
|
||||
DungeonRoom::DungeonRoom()
|
||||
{
|
||||
Array<String>* expr_06 = new Array<String>(5);
|
||||
expr_06->SetData(0, new String("A"));
|
||||
expr_06->SetData(1, new String("E"));
|
||||
expr_06->SetData(2, new String("I"));
|
||||
expr_06->SetData(3, new String("O"));
|
||||
expr_06->SetData(4, new String("U"));
|
||||
DungeonRoom::biga = expr_06;
|
||||
Array<String>* expr_3A = new Array<String>(19);
|
||||
expr_3A->SetData(0, new String("B"));
|
||||
expr_3A->SetData(1, new String("C"));
|
||||
expr_3A->SetData(2, new String("D"));
|
||||
expr_3A->SetData(3, new String("E"));
|
||||
expr_3A->SetData(4, new String("F"));
|
||||
expr_3A->SetData(5, new String("G"));
|
||||
expr_3A->SetData(6, new String("H"));
|
||||
expr_3A->SetData(7, new String("J"));
|
||||
expr_3A->SetData(8, new String("K"));
|
||||
expr_3A->SetData(9, new String("L"));
|
||||
expr_3A->SetData(10, new String("M"));
|
||||
expr_3A->SetData(11, new String("N"));
|
||||
expr_3A->SetData(12, new String("P"));
|
||||
expr_3A->SetData(13, new String("Q"));
|
||||
expr_3A->SetData(14, new String("R"));
|
||||
expr_3A->SetData(15, new String("V"));
|
||||
expr_3A->SetData(16, new String("X"));
|
||||
expr_3A->SetData(17, new String("Y"));
|
||||
expr_3A->SetData(18, new String("Z"));
|
||||
DungeonRoom::bigb = expr_3A;
|
||||
Array<String>* expr_E7 = new Array<String>(5);
|
||||
expr_E7->SetData(0, new String("a"));
|
||||
expr_E7->SetData(1, new String("e"));
|
||||
expr_E7->SetData(2, new String("i"));
|
||||
expr_E7->SetData(3, new String("o"));
|
||||
expr_E7->SetData(4, new String("u"));
|
||||
DungeonRoom::smalla = expr_E7;
|
||||
Array<String>* expr_11B = new Array<String>(19);
|
||||
expr_11B->SetData(0, new String("b"));
|
||||
expr_11B->SetData(1, new String("c"));
|
||||
expr_11B->SetData(2, new String("d"));
|
||||
expr_11B->SetData(3, new String("e"));
|
||||
expr_11B->SetData(4, new String("f"));
|
||||
expr_11B->SetData(5, new String("g"));
|
||||
expr_11B->SetData(6, new String("h"));
|
||||
expr_11B->SetData(7, new String("j"));
|
||||
expr_11B->SetData(8, new String("k"));
|
||||
expr_11B->SetData(9, new String("l"));
|
||||
expr_11B->SetData(10, new String("m"));
|
||||
expr_11B->SetData(11, new String("n"));
|
||||
expr_11B->SetData(12, new String("p"));
|
||||
expr_11B->SetData(13, new String("q"));
|
||||
expr_11B->SetData(14, new String("r"));
|
||||
expr_11B->SetData(15, new String("v"));
|
||||
expr_11B->SetData(16, new String("x"));
|
||||
expr_11B->SetData(17, new String("y"));
|
||||
expr_11B->SetData(18, new String("z"));
|
||||
DungeonRoom::smallb = expr_11B;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
64
DungeonRoom.h
Normal file
64
DungeonRoom.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
#include "UnityEngine.h"
|
||||
#include "Vector3.h"
|
||||
#include "Voxelizzer.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityType.h"
|
||||
#include "Quaternion.h"
|
||||
|
||||
using namespace UnityEngine;
|
||||
using namespace VoxelToolbox;
|
||||
using namespace BS::Player;
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class DungeonRoom : public virtual Object
|
||||
{
|
||||
private:
|
||||
static Array<String>* biga;
|
||||
private:
|
||||
static Array<String>* bigb;
|
||||
private:
|
||||
static Array<String>* smalla;
|
||||
private:
|
||||
static Array<String>* smallb;
|
||||
private:
|
||||
int x;
|
||||
private:
|
||||
int y;
|
||||
private:
|
||||
int width;
|
||||
private:
|
||||
int height;
|
||||
public:
|
||||
int getX();
|
||||
public:
|
||||
void setX(int value);
|
||||
public:
|
||||
int getY();
|
||||
public:
|
||||
void setY(int value);
|
||||
public:
|
||||
int getWidth();
|
||||
public:
|
||||
void setWidth(int value);
|
||||
public:
|
||||
int getHeight();
|
||||
public:
|
||||
void setHeight(int value);
|
||||
public:
|
||||
DungeonRoom(int x, int y, int width, int height);
|
||||
public:
|
||||
virtual void WriteRoom(ArrayND<char, 2>* dungeon);
|
||||
public:
|
||||
virtual void GenerateAIPlayers(int level);
|
||||
public:
|
||||
String* GenerateName();
|
||||
static:
|
||||
DungeonRoom();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
23
DungeonStartRoom.cpp
Normal file
23
DungeonStartRoom.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "DungeonStartRoom.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
DungeonStartRoom::DungeonStartRoom(int x, int y, int width, int height) : DungeonRoom(x, y, 8, 8){
|
||||
}
|
||||
void DungeonStartRoom::GenerateSpawnPoint(GameObject* startPositionPrefab)
|
||||
{
|
||||
bool flag = false;
|
||||
while (!flag) {
|
||||
int num = DungeonRoom::getX() + UnityEngine::Random::Range(1, DungeonRoom::getWidth() - 2);
|
||||
int num2 = DungeonRoom::getY() + UnityEngine::Random::Range(1, DungeonRoom::getHeight() - 2);
|
||||
flag = true;
|
||||
UnityEngine::Object::Instantiate<GameObject>(startPositionPrefab, Vector3::zero, Quaternion::identity)->transform->position = new Vector3((float)(num) * Voxelizzer::world->voxelScale, Voxelizzer::world->voxelScale, (float)(num2) * Voxelizzer::world->voxelScale);
|
||||
}
|
||||
}
|
||||
void DungeonStartRoom::GenerateAIPlayers(int level)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
27
DungeonStartRoom.h
Normal file
27
DungeonStartRoom.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
#include "DungeonRoom.h"
|
||||
#include "GameObject.h"
|
||||
#include "UnityEngine.h"
|
||||
#include "Vector3.h"
|
||||
#include "Voxelizzer.h"
|
||||
#include "Quaternion.h"
|
||||
|
||||
using namespace UnityEngine;
|
||||
using namespace VoxelToolbox;
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class DungeonStartRoom : public virtual DungeonRoom, public virtual Object
|
||||
{
|
||||
public:
|
||||
DungeonStartRoom(int x, int y, int width, int height);
|
||||
public:
|
||||
void GenerateSpawnPoint(GameObject* startPositionPrefab);
|
||||
public:
|
||||
virtual void GenerateAIPlayers(int level);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
46
IntRect.cpp
Normal file
46
IntRect.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "IntRect.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
int IntRect::getX(){
|
||||
return this->x;
|
||||
}
|
||||
void IntRect::setX(int value)
|
||||
{
|
||||
this->x = value;
|
||||
}
|
||||
int IntRect::getY()
|
||||
{
|
||||
return this->y;
|
||||
}
|
||||
void IntRect::setY(int value)
|
||||
{
|
||||
this->y = value;
|
||||
}
|
||||
int IntRect::getWidth()
|
||||
{
|
||||
return this->width;
|
||||
}
|
||||
void IntRect::setWidth(int value)
|
||||
{
|
||||
this->width = value;
|
||||
}
|
||||
int IntRect::getHeight()
|
||||
{
|
||||
return this->height;
|
||||
}
|
||||
void IntRect::setHeight(int value)
|
||||
{
|
||||
this->height = value;
|
||||
}
|
||||
IntRect::IntRect(int x, int y, int width, int height)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
39
IntRect.h
Normal file
39
IntRect.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class IntRect : public virtual Object
|
||||
{
|
||||
private:
|
||||
int x;
|
||||
private:
|
||||
int y;
|
||||
private:
|
||||
int width;
|
||||
private:
|
||||
int height;
|
||||
public:
|
||||
int getX();
|
||||
public:
|
||||
void setX(int value);
|
||||
public:
|
||||
int getY();
|
||||
public:
|
||||
void setY(int value);
|
||||
public:
|
||||
int getWidth();
|
||||
public:
|
||||
void setWidth(int value);
|
||||
public:
|
||||
int getHeight();
|
||||
public:
|
||||
void setHeight(int value);
|
||||
public:
|
||||
IntRect(int x, int y, int width, int height);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
4
SCsub
Normal file
4
SCsub
Normal file
@ -0,0 +1,4 @@
|
||||
Import('env')
|
||||
|
||||
env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||
|
71
TileConsts.cpp
Normal file
71
TileConsts.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include "TileConsts.h"
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
bool TileConsts::isWall(char tile){
|
||||
switch (tile){
|
||||
case 11:
|
||||
return true;
|
||||
|
||||
case 12:
|
||||
return true;
|
||||
|
||||
case 13:
|
||||
return true;
|
||||
|
||||
case 14:
|
||||
return true;
|
||||
|
||||
case 15:
|
||||
return true;
|
||||
|
||||
case 16:
|
||||
return true;
|
||||
|
||||
case 17:
|
||||
return true;
|
||||
|
||||
case 18:
|
||||
return true;
|
||||
|
||||
case 21:
|
||||
return true;
|
||||
|
||||
case 22:
|
||||
return true;
|
||||
|
||||
case 23:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TileConsts::TileConsts()
|
||||
{
|
||||
Floor = 1;
|
||||
Floor_Var1 = 2;
|
||||
Floor_Up = 3;
|
||||
Floor_Left = 4;
|
||||
Floor_Down = 5;
|
||||
Floor_Right = 6;
|
||||
Floor_UpRight = 7;
|
||||
Floor_UpLeft = 8;
|
||||
Floor_DownLeft = 9;
|
||||
Floor_DownRight = 10;
|
||||
Wall_Up = 11;
|
||||
Wall_Right = 12;
|
||||
Wall_Down = 13;
|
||||
Wall_Left = 14;
|
||||
Wall_Corner_TopRight = 15;
|
||||
Wall_Corner_TopLeft = 16;
|
||||
Wall_Corner_BottomRight = 17;
|
||||
Wall_Corner_BottomRight_Outside = 23;
|
||||
Wall_Corner_BottomLeft = 18;
|
||||
Wall_Corner_BottomLeft_Outside = 21;
|
||||
Wall_Corner_BottomLeft_Half_Outside = 22;
|
||||
Roof_Wood_Single = 19;
|
||||
Stair_Down = 20;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
63
TileConsts.h
Normal file
63
TileConsts.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include <System/System.h>
|
||||
|
||||
using namespace System;
|
||||
namespace BS {
|
||||
namespace Levels {
|
||||
namespace Generator {
|
||||
class TileConsts : public virtual Object
|
||||
{
|
||||
public:
|
||||
char Floor;
|
||||
public:
|
||||
char Floor_Var1;
|
||||
public:
|
||||
char Floor_Up;
|
||||
public:
|
||||
char Floor_Left;
|
||||
public:
|
||||
char Floor_Down;
|
||||
public:
|
||||
char Floor_Right;
|
||||
public:
|
||||
char Floor_UpRight;
|
||||
public:
|
||||
char Floor_UpLeft;
|
||||
public:
|
||||
char Floor_DownLeft;
|
||||
public:
|
||||
char Floor_DownRight;
|
||||
public:
|
||||
char Wall_Up;
|
||||
public:
|
||||
char Wall_Right;
|
||||
public:
|
||||
char Wall_Down;
|
||||
public:
|
||||
char Wall_Left;
|
||||
public:
|
||||
char Wall_Corner_TopRight;
|
||||
public:
|
||||
char Wall_Corner_TopLeft;
|
||||
public:
|
||||
char Wall_Corner_BottomRight;
|
||||
public:
|
||||
char Wall_Corner_BottomRight_Outside;
|
||||
public:
|
||||
char Wall_Corner_BottomLeft;
|
||||
public:
|
||||
char Wall_Corner_BottomLeft_Outside;
|
||||
public:
|
||||
char Wall_Corner_BottomLeft_Half_Outside;
|
||||
public:
|
||||
char Roof_Wood_Single;
|
||||
public:
|
||||
char Stair_Down;
|
||||
public:
|
||||
static bool isWall(char tile);
|
||||
public:
|
||||
TileConsts();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
5
config.py
Normal file
5
config.py
Normal file
@ -0,0 +1,5 @@
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
def configure(env):
|
||||
pass
|
BIN
config.pyc
Normal file
BIN
config.pyc
Normal file
Binary file not shown.
10
register_types.cpp
Normal file
10
register_types.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "register_types.h"
|
||||
|
||||
void register_dungeon_generator_types() {
|
||||
//ClassDB::register_class<BSInputModifier>();
|
||||
}
|
||||
|
||||
void unregister_dungeon_generator_types() {
|
||||
|
||||
}
|
||||
|
3
register_types.h
Normal file
3
register_types.h
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
void register_dungeon_generator_types();
|
||||
void unregister_dungeon_generator_types();
|
Loading…
Reference in New Issue
Block a user