summaryrefslogtreecommitdiff
path: root/structures.lua
blob: bdf37ef8a8c77c334c4a485fe761211e4ba88021 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
-- cellworld test structures. Later, put this into separate mods

--[[ cellworld structure table
struct = {
	structure_set = "foo" -- the expected structure set. 
	size = {
		x = 1 -- how many grid units this spans horizontally in x direction
		y = 1 -- how many grid units this spans vertically in y direction
		z = 1 -- how many grid units this spans horizontally in z direction
	}
	
	no_rotate = false -- whether structure may not be rotated
	
	chance = 20 -- Chance of spawning this structure. = number of times inserted into the selection table
	
	-- to specify the structure, two approaches can be used: either table-based, or function-based
	-- Table-based:
	cells = {
		-- due to the way cellworld works, nodes are generated on a per-cell level. so, each grid_size^3 cube needs to be specified independently.
		["x|y|z" ] = {
			structure = {
				action = "fill", -- action to perform. Can be registered, to be specified later. For now, only 'fill' supported.
				node="default:air", -- remaining parameters are action-dependent. Here: node to fill with.
				param2 = 0, -- optional: param2 to set, defaults to 0, or
				param2 = {0,1,2,3}, -- table with 4 entries, per structure rotation
				coords = {-x,-y,-z, +x,+y,+z} -- specify bounds of filled area. Relative to node origin and rotated with structure rotation
			}
			exits = {
				[cellworld.EAST] = { -- the exit on the specified side of the structure exists and should be carved by this description if the neighboring structure also has an exit at this place.
					... actions ...
				}
			}
			-- exit definitions do nothing if the specified wall is not on the outside of the structure
			-- vertical exits do not exist currently.
			-- a missing exits table is synonym to an empty exits table.
		}
	}
	-- If an entry in cells does not exist (or the entire cells table), can also use
	cell = {
		..actions.. -- fallback if not in nodes table
	}
	
	-- function-based:
	make_node(gridnode_pos, vmiface) -- to be specified
	exit_exists(gridnode_pos, exit_dir)
	make_exit(gridnode_pos, exit_dir, vmiface)
}
]]--

-- Configure the current structure set. There can only be one active structure set at a time, so calling this twice results in an error.
cellworld.config_structure_set("space",{
	mapgen_base_node = "air",
	grid_size = 9,
	seed_structure = "space:platform",
})

cellworld.register_structure("space:nothing", {
	structure_set = "space", -- this could maybe also be a list... is there an use case for this?
	size = {
		x=1,
		y=1,
		z=1,
	},
	
	chance = 5,
	
	cell = {
		-- do nothing
		structure={},
		exits={}
	}
})

cellworld.register_structure("space:platform", {
	structure_set = "space",
	size = {
		x=1,
		y=1,
		z=1,
	},
	
	chance = 10,
	
	cell = {
		structure = {
			{action="fill", node="default:stone", coords = {2, 1, 2, 6, 1, 6}},
		},
		exits = {
			[cellworld.EAST] = {
				{action="fill", node="default:stone", coords = {7, 1, 3, 8, 1, 5}},
			},
			[cellworld.WEST] = {
				{action="fill", node="default:stone", coords = {0, 1, 3, 1, 1, 5}},
			},
			[cellworld.NORTH] = {
				{action="fill", node="default:stone", coords = {3, 1, 7, 5, 1, 8}},
			},
			[cellworld.SOUTH] = {
				{action="fill", node="default:stone", coords = {3, 1, 0, 5, 1, 1}},
			},
		}
	}
})

cellworld.register_structure("space:fountain", {
	structure_set = "space",
	size = {
		x=3,
		y=1,
		z=3,
	},
	
	chance = 1,
	
	cells = {
		["1|0|0"]={ -- south exit
			structure = {
				{action="fill", node="default:stonebrick", coords = {2, 1, 2, 6, 1, 6}},
				{action="fill", node="default:stonebrick", coords = {0, 1, 7, 8, 1, 8}},
			},
			exits = {
				[cellworld.SOUTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 0, 5, 1, 1}},
				},
			}
		},
		["1|0|2"]={ -- north exit
			structure = {
				{action="fill", node="default:stonebrick", coords = {2, 1, 2, 6, 1, 6}},
				{action="fill", node="default:stonebrick", coords = {0, 1, 0, 8, 1, 1}},
			},
			exits = {
				[cellworld.NORTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 7, 5, 1, 8}},
				},
			}
		},
		["0|0|1"]={ -- west exit
			structure = {
				{action="fill", node="default:stonebrick", coords = {2, 1, 2, 6, 1, 6}},
				{action="fill", node="default:stonebrick", coords = {7, 1, 0, 8, 1, 8}},
			},
			exits = {
				[cellworld.WEST] = {
					{action="fill", node="default:stone", coords = {0, 1, 3, 1, 1, 5}},
				},
			}
		},
		["2|0|1"]={ -- east exit
			structure = {
				{action="fill", node="default:stonebrick", coords = {2, 1, 2, 6, 1, 6}},
				{action="fill", node="default:stonebrick", coords = {0, 1, 0, 1, 1, 8}},
			},
			exits = {
				[cellworld.EAST] = {
					{action="fill", node="default:stone", coords = {7, 1, 3, 8, 1, 5}},
				},
			}
		},
		["1|0|1"]={ -- center
			structure = {
				{action="fill", node="default:stonebrick", coords = {0, 1, 0, 8, 1, 8}},
				{action="fill", node="default:stonebrick", coords = {2, 2, 2, 6, 2, 6}},
				{action="fill", node="air", coords = {3, 2, 3, 5, 2, 5}},
				{action="fill", node="default:water_source", coords = {4, 4, 4, 4, 4, 4}},
			},
		},
	},
	
	cell = {
		structure = {
		},
	}
})

cellworld.register_structure("space:stair", {
	structure_set = "space",
	size = {
		x=3,
		y=2,
		z=1,
	},
	
	chance = 5,
	
	cells = {
		["0|0|0"]={
			structure = {
				{action="fill", node="default:stone", coords = {2, 1, 2, 8, 1, 6}},
			},
			exits = {
				[cellworld.WEST] = {
					{action="fill", node="default:stone", coords = {0, 1, 3, 1, 1, 5}},
				},
				[cellworld.NORTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 7, 5, 1, 8}},
				},
				[cellworld.SOUTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 0, 5, 1, 1}},
				},
			}
		},
		["1|0|0"]={ -- middle lower part
			structure = {
				{action="fill", node="default:stone", coords = {8, 8, 2, 8, 8, 6}},
				{action="fill", node="default:stone", coords = {7, 7, 2, 7, 7, 6}},
				{action="fill", node="default:stone", coords = {6, 6, 2, 6, 6, 6}},
				{action="fill", node="default:stone", coords = {5, 5, 2, 5, 5, 6}},
				{action="fill", node="default:stone", coords = {4, 4, 2, 4, 4, 6}},
				{action="fill", node="default:stone", coords = {3, 3, 2, 3, 3, 6}},
				{action="fill", node="default:stone", coords = {2, 2, 2, 2, 2, 6}},
				{action="fill", node="default:stone", coords = {0, 1, 2, 1, 1, 6}},
			},
		},
		["2|1|0"]={
			structure = {
				{action="fill", node="default:stone", coords = {1, 1, 2, 6, 1, 6}},
				{action="fill", node="default:stone", coords = {0, 0, 2, 0, 0, 6}},
			},
			exits = {
				[cellworld.EAST] = {
					{action="fill", node="default:stone", coords = {7, 1, 3, 8, 1, 5}},
				},
				[cellworld.NORTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 7, 5, 1, 8}},
				},
				[cellworld.SOUTH] = {
					{action="fill", node="default:stone", coords = {3, 1, 0, 5, 1, 1}},
				},
			}
		},
	},
	
	cell = {
		structure = {
			--{action="fill", node="default:stone", coords = {4, 4, 4, 4, 4, 4}},
		},
	}
})