MCPcopy Create free account
hub / github.com/DFHack/dfhack / addBlockColumns

Function addBlockColumns

plugins/infinite-sky.cpp:139–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void addBlockColumns(color_ostream& out, int32_t quantity) {
140 int32_t z_count_block = world->map.z_count_block;
141 df::map_block ****block_index = world->map.block_index;
142
143 cuboid last_air_layer(
144 0, 0, world->map.z_count_block - 1,
145 world->map.x_count_block - 1, world->map.y_count_block - 1, world->map.z_count_block - 1);
146
147 last_air_layer.forCoord([&](df::coord bpos) {
148 // Allocate a new block column and copy over data from the old
149 df::map_block **blockColumn =
150 new df::map_block *[z_count_block + quantity];
151 memcpy(blockColumn, block_index[bpos.x][bpos.y],
152 z_count_block * sizeof(df::map_block *));
153 delete[] block_index[bpos.x][bpos.y];
154 block_index[bpos.x][bpos.y] = blockColumn;
155
156 df::map_block *last_air_block = blockColumn[bpos.z];
157 for (int32_t count = 0; count < quantity; count++) {
158 df::map_block *air_block = new df::map_block();
159 std::fill(&air_block->tiletype[0][0],
160 &air_block->tiletype[0][0] + (16 * 16),
161 df::tiletype::OpenSpace);
162
163 // Set block positions properly (based on prior air layer)
164 air_block->map_pos = last_air_block->map_pos;
165 air_block->map_pos.z += count + 1;
166 air_block->region_pos = last_air_block->region_pos;
167
168 // Copy other potentially important metadata from prior air
169 // layer
170 std::memcpy(air_block->lighting, last_air_block->lighting,
171 sizeof(air_block->lighting));
172 std::memcpy(air_block->temperature_1, last_air_block->temperature_1,
173 sizeof(air_block->temperature_1));
174 std::memcpy(air_block->temperature_2, last_air_block->temperature_2,
175 sizeof(air_block->temperature_2));
176 std::memcpy(air_block->region_offset, last_air_block->region_offset,
177 sizeof(air_block->region_offset));
178
179 // Create tile designations to inform lighting and
180 // outside markers
181 df::tile_designation designation{};
182 designation.bits.light = true;
183 designation.bits.outside = true;
184 std::fill(&air_block->designation[0][0],
185 &air_block->designation[0][0] + (16 * 16), designation);
186
187 blockColumn[z_count_block + count] = air_block;
188 world->map.map_blocks.push_back(air_block);
189
190 // deal with map_block_column stuff even though it'd probably be
191 // fine
192 df::map_block_column *column =
193 world->map.column_index[bpos.x][bpos.y];
194 if (!column) {
195 DEBUG(cycle, out)
196 .print("{}, line {}: column is null ({}).\n", __FILE__, __LINE__, bpos);

Callers 1

doInfiniteSkyFunction · 0.85

Calls 2

forCoordMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected