-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path015.as
More file actions
109 lines (93 loc) · 3.26 KB
/
Copy path015.as
File metadata and controls
109 lines (93 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using namespace B3D;
using namespace CB;
#include "library.as"
/**
* @brief Given a desired room shape, it will do a weighted pick of the registered SCP-015 rooms.
*
* @param desiredShape The desired room shape.
* @return Selected string index
*/
int RandomStringPickWeightedIndex015(const RoomShape015 desiredShape) {
int totalWeight = 0; int i = -1;
foreach(int v : roomWeights) {
i++;
if (roomShapes[i] != desiredShape) { continue; }
totalWeight += v;
}
int picker = Rnd(totalWeight); int ticker = 0; i = -1;
foreach(int v : roomWeights) {
i++;
if (roomShapes[i] != desiredShape) { continue; }
ticker += v;
if (ticker > picker) { return i; }
}
return 0;
}
enum RoomShape015 {
ONE_WAY,
TWO_WAY,
TWO_WAY_CORNER,
THREE_WAY,
FOUR_WAY
}
enum RoomDirection015 {
FORWARD,
RIGHT,
BACKWARD,
LEFT
}
array<string> roomNames;
array<RoomShape015> roomShapes;
array<int> roomWeights;
void Register015Room(string name, RoomShape015 shape, int weight) {
roomNames.InsertLast(name);
roomShapes.InsertLast(shape);
roomWeights.InsertLast(weight);
}
int directionToDegrees(RoomDirection015 direction) {
if (direction == RoomDirection015::FORWARD) { return 0; }
else if (direction == RoomDirection015::RIGHT) { return 90; }
else if (direction == RoomDirection015::BACKWARD) { return 180; }
else if (direction == RoomDirection015::LEFT) { return 270; }
return 0;
}
void Create015Room(const string name, RoomDirection015 direction, float x, float y, float z) {
string roomDirectory = "GFX/map/";
Pivot@ room = LoadRMesh(roomDirectory + name + ".rm");
room.Scale(1 / 256.f, 1 / 256.f, 1 / 256.f, true);
room.Position(x, y, z, true);
room.Rotate(0, directionToDegrees(direction), 0, true);
}
int GridPos(float n) {
return n * 4;
}
void Generate015Nightmare() {
const int originX = 120;
const int originY = 120;
const int originZ = 120;
// generate one part of 015
for (int i = -10; i < 10; i++) {
if (Rnd(0, 1) > 0.75f) {
int roomIndex = RandomStringPickWeightedIndex015(THREE_WAY);
int direction = Rand(0,1);
if (direction == 0) {
Create015Room(roomNames[roomIndex], RoomDirection015::RIGHT, originX, originY, originZ + GridPos(i));
for (int j = 0; j < 10; j++) {
roomIndex = RandomStringPickWeightedIndex015(TWO_WAY);
Create015Room(roomNames[roomIndex], RoomDirection015::LEFT, originX + GridPos(j + 1), originY, originZ + GridPos(i));
}
}
else {
Create015Room(roomNames[roomIndex], RoomDirection015::LEFT, originX, originY, originZ + GridPos(i));
for (int j = 0; j < 10; j++) {
roomIndex = RandomStringPickWeightedIndex015(TWO_WAY);
Create015Room(roomNames[roomIndex], RoomDirection015::RIGHT, originX - GridPos(j + 1), originY, originZ + GridPos(i));
}
}
}
else {
int roomIndex = RandomStringPickWeightedIndex015(TWO_WAY);
Create015Room(roomNames[roomIndex], RoomDirection015::FORWARD, originX, originY, originZ + GridPos(i));
}
}
}