Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable infiniteSky #5029

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ if(BUILD_SUPPORTED)
#dfhack_plugin(generated-creature-renamer generated-creature-renamer.cpp)
dfhack_plugin(getplants getplants.cpp)
dfhack_plugin(hotkeys hotkeys.cpp LINK_LIBRARIES lua)
#dfhack_plugin(infiniteSky infiniteSky.cpp)
dfhack_plugin(infiniteSky infiniteSky.cpp)
#dfhack_plugin(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote)
#dfhack_plugin(jobutils jobutils.cpp)
dfhack_plugin(lair lair.cpp)
Expand Down
96 changes: 71 additions & 25 deletions plugins/infiniteSky.cpp
NicksWorld marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,67 @@ void doInfiniteSky(color_ostream& out, int32_t howMany) {
CoreSuspender suspend;
int32_t x_count_block = world->map.x_count_block;
int32_t y_count_block = world->map.y_count_block;
for ( int32_t count = 0; count < howMany; count++ ) {
//change the size of the pointer stuff
int32_t z_count_block = world->map.z_count_block;
df::map_block**** block_index = world->map.block_index;
for ( int32_t a = 0; a < x_count_block; a++ ) {
for ( int32_t b = 0; b < y_count_block; b++ ) {
df::map_block** blockColumn = new df::map_block*[z_count_block+1];
memcpy(blockColumn, block_index[a][b], z_count_block*sizeof(df::map_block*));
blockColumn[z_count_block] = NULL;
delete[] block_index[a][b];
block_index[a][b] = blockColumn;

//deal with map_block_column stuff even though it'd probably be fine
df::map_block_column* column = world->map.column_index[a][b];
if ( !column ) {
out.print("%s, line %d: column is null (%d, %d).\n", __FILE__, __LINE__, a, b);
int32_t z_count_block = world->map.z_count_block;
df::map_block ****block_index = world->map.block_index;

for (int32_t a = 0; a < x_count_block; a++) {
for (int32_t b = 0; b < y_count_block; b++) {
// Allocate a new block column and copy over data from the old
df::map_block **blockColumn =
new df::map_block *[z_count_block + howMany];
memcpy(blockColumn, block_index[a][b],
z_count_block * sizeof(df::map_block *));
delete[] block_index[a][b];
block_index[a][b] = blockColumn;

df::map_block *last_air_block = blockColumn[z_count_block - 1];
for (int32_t count = 0; count < howMany; count++) {
df::map_block *air_block = new df::map_block();
std::fill(&air_block->tiletype[0][0],
&air_block->tiletype[0][0] + (16 * 16),
df::tiletype::OpenSpace);

// Set block positions properly (based on prior air layer)
air_block->map_pos = last_air_block->map_pos;
air_block->map_pos.z += count + 1;
air_block->region_pos = last_air_block->region_pos;

// Copy other potentially important metadata from prior air
// layer
std::memcpy(air_block->lighting, last_air_block->lighting,
sizeof(air_block->lighting));
std::memcpy(air_block->temperature_1,
last_air_block->temperature_1,
sizeof(air_block->temperature_1));
std::memcpy(air_block->temperature_2,
last_air_block->temperature_2,
sizeof(air_block->temperature_2));
std::memcpy(air_block->region_offset,
last_air_block->region_offset,
sizeof(air_block->region_offset));

// Create tile designations to inform lighting and
// outside markers
df::tile_designation designation{};
designation.bits.light = true;
designation.bits.outside = true;
std::fill(&air_block->designation[0][0],
&air_block->designation[0][0] + (16 * 16),
designation);

blockColumn[z_count_block + count] = air_block;
world->map.map_blocks.push_back(air_block);

// deal with map_block_column stuff even though it'd probably be
// fine
df::map_block_column *column = world->map.column_index[a][b];
if (!column) {
out.print("%s, line %d: column is null (%d, %d).\n",
__FILE__, __LINE__, a, b);
continue;
}
df::map_block_column::T_unmined_glyphs* glyphs = new df::map_block_column::T_unmined_glyphs;
df::map_block_column::T_unmined_glyphs *glyphs =
new df::map_block_column::T_unmined_glyphs;
glyphs->x[0] = 0;
glyphs->x[1] = 1;
glyphs->x[2] = 2;
Expand All @@ -129,16 +171,20 @@ void doInfiniteSky(color_ostream& out, int32_t howMany) {
column->unmined_glyphs.push_back(glyphs);
}
}
df::z_level_flags* flags = new df::z_level_flags[z_count_block+1];
memcpy(flags, world->map_extras.z_level_flags, z_count_block*sizeof(df::z_level_flags));
flags[z_count_block].whole = 0;
flags[z_count_block].bits.update = 1;
world->map.z_count_block++;
world->map.z_count++;
delete[] world->map_extras.z_level_flags;
world->map_extras.z_level_flags = flags;
}

// Update global z level flags
df::z_level_flags *flags = new df::z_level_flags[z_count_block + howMany];
memcpy(flags, world->map_extras.z_level_flags,
z_count_block * sizeof(df::z_level_flags));
for (int32_t count = 0; count < howMany; count++) {
flags[z_count_block + count].whole = 0;
flags[z_count_block + count].bits.update = 1;
}
world->map.z_count_block += howMany;
world->map.z_count += howMany;
delete[] world->map_extras.z_level_flags;
world->map_extras.z_level_flags = flags;
}

DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
Expand Down