1
1
2
2
#include " Core.h"
3
- #include " DataDefs.h"
4
3
#include " Debug.h"
5
- #include " Export.h"
6
4
#include " LuaTools.h"
7
5
#include " PluginManager.h"
8
6
9
- #include " modules/World.h"
10
7
#include " modules/EventManager.h"
8
+ #include " modules/Maps.h"
9
+ #include " modules/World.h"
11
10
12
11
#include " df/construction.h"
13
12
#include " df/map_block.h"
19
18
#include < string>
20
19
#include < vector>
21
20
22
- using namespace std ;
21
+ using std::string;
22
+ using std::vector;
23
23
24
24
using namespace DFHack ;
25
25
using namespace df ::enums;
@@ -45,7 +45,7 @@ enum ConfigValues {
45
45
command_result infiniteSky (color_ostream &out, std::vector <std::string> & parameters);
46
46
47
47
static void constructionEventHandler (color_ostream& out, void * ptr);
48
- EventManager::EventHandler handler (plugin_self, constructionEventHandler,0 );
48
+ EventManager::EventHandler handler (plugin_self, constructionEventHandler,11 );
49
49
50
50
DFhackCExport command_result plugin_init (color_ostream &out,
51
51
std::vector<PluginCommand> &commands) {
@@ -87,11 +87,6 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
87
87
return CR_OK;
88
88
}
89
89
90
- DFhackCExport command_result plugin_shutdown (color_ostream &out) {
91
- cleanup ();
92
- return CR_OK;
93
- }
94
-
95
90
DFhackCExport command_result plugin_load_site_data (color_ostream &out) {
96
91
config = World::GetPersistentSiteData (CONFIG_KEY);
97
92
@@ -102,7 +97,6 @@ DFhackCExport command_result plugin_load_site_data(color_ostream &out) {
102
97
config.set_bool (CONFIG_IS_ENABLED, is_enabled);
103
98
}
104
99
105
-
106
100
// Call plugin_enable to set value to ensure the event handler is properly registered
107
101
plugin_enable (out, config.get_bool (CONFIG_IS_ENABLED));
108
102
DEBUG (control, out)
@@ -118,6 +112,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out,
118
112
DEBUG (control, out)
119
113
.print (" world unloaded; disabling %s\n " , plugin_name);
120
114
is_enabled = false ;
115
+ cleanup ();
121
116
}
122
117
}
123
118
return CR_OK;
@@ -134,86 +129,84 @@ static void constructionEventHandler(color_ostream &out, void *ptr) {
134
129
135
130
void doInfiniteSky (color_ostream& out, int32_t howMany) {
136
131
CoreSuspender suspend;
137
- int32_t x_count_block = world->map .x_count_block ;
138
- int32_t y_count_block = world->map .y_count_block ;
139
132
int32_t z_count_block = world->map .z_count_block ;
140
133
df::map_block ****block_index = world->map .block_index ;
141
134
142
- for (int32_t a = 0 ; a < x_count_block; a++) {
143
- for (int32_t b = 0 ; b < y_count_block; b++) {
144
- // Allocate a new block column and copy over data from the old
145
- df::map_block **blockColumn =
146
- new df::map_block *[z_count_block + howMany];
147
- memcpy (blockColumn, block_index[a][b],
148
- z_count_block * sizeof (df::map_block *));
149
- delete[] block_index[a][b];
150
- block_index[a][b] = blockColumn;
151
-
152
- df::map_block *last_air_block = blockColumn[z_count_block - 1 ];
153
- for (int32_t count = 0 ; count < howMany; count++) {
154
- df::map_block *air_block = new df::map_block ();
155
- std::fill (&air_block->tiletype [0 ][0 ],
156
- &air_block->tiletype [0 ][0 ] + (16 * 16 ),
157
- df::tiletype::OpenSpace);
158
-
159
- // Set block positions properly (based on prior air layer)
160
- air_block->map_pos = last_air_block->map_pos ;
161
- air_block->map_pos .z += count + 1 ;
162
- air_block->region_pos = last_air_block->region_pos ;
163
-
164
- // Copy other potentially important metadata from prior air
165
- // layer
166
- std::memcpy (air_block->lighting , last_air_block->lighting ,
167
- sizeof (air_block->lighting ));
168
- std::memcpy (air_block->temperature_1 ,
169
- last_air_block->temperature_1 ,
170
- sizeof (air_block->temperature_1 ));
171
- std::memcpy (air_block->temperature_2 ,
172
- last_air_block->temperature_2 ,
173
- sizeof (air_block->temperature_2 ));
174
- std::memcpy (air_block->region_offset ,
175
- last_air_block->region_offset ,
176
- sizeof (air_block->region_offset ));
177
-
178
- // Create tile designations to inform lighting and
179
- // outside markers
180
- df::tile_designation designation{};
181
- designation.bits .light = true ;
182
- designation.bits .outside = true ;
183
- std::fill (&air_block->designation [0 ][0 ],
184
- &air_block->designation [0 ][0 ] + (16 * 16 ),
185
- 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 = world->map .column_index [a][b];
193
- if (!column) {
194
- DEBUG (cycle, out)
195
- .print (" %s, line %d: column is null (%d, %d).\n " ,
196
- __FILE__, __LINE__, a, b);
197
- continue ;
198
- }
199
- df::map_block_column::T_unmined_glyphs *glyphs =
200
- new df::map_block_column::T_unmined_glyphs;
201
- glyphs->x [0 ] = 0 ;
202
- glyphs->x [1 ] = 1 ;
203
- glyphs->x [2 ] = 2 ;
204
- glyphs->x [3 ] = 3 ;
205
- glyphs->y [0 ] = 0 ;
206
- glyphs->y [1 ] = 0 ;
207
- glyphs->y [2 ] = 0 ;
208
- glyphs->y [3 ] = 0 ;
209
- glyphs->tile [0 ] = ' e' ;
210
- glyphs->tile [1 ] = ' x' ;
211
- glyphs->tile [2 ] = ' p' ;
212
- glyphs->tile [3 ] = ' ^' ;
213
- column->unmined_glyphs .push_back (glyphs);
135
+ cuboid last_air_layer (
136
+ 0 , 0 , world->map .z_count_block - 1 ,
137
+ world->map .x_count_block - 1 , world->map .y_count_block - 1 , world->map .z_count_block - 1 );
138
+
139
+ last_air_layer.forCoord ([&](df::coord bpos) {
140
+ // Allocate a new block column and copy over data from the old
141
+ df::map_block **blockColumn =
142
+ new df::map_block *[z_count_block + howMany];
143
+ memcpy (blockColumn, block_index[bpos.x ][bpos.y ],
144
+ z_count_block * sizeof (df::map_block *));
145
+ delete[] block_index[bpos.x ][bpos.y ];
146
+ block_index[bpos.x ][bpos.y ] = blockColumn;
147
+
148
+ df::map_block *last_air_block = blockColumn[bpos.z ];
149
+ for (int32_t count = 0 ; count < howMany; count++) {
150
+ df::map_block *air_block = new df::map_block ();
151
+ std::fill (&air_block->tiletype [0 ][0 ],
152
+ &air_block->tiletype [0 ][0 ] + (16 * 16 ),
153
+ df::tiletype::OpenSpace);
154
+
155
+ // Set block positions properly (based on prior air layer)
156
+ air_block->map_pos = last_air_block->map_pos ;
157
+ air_block->map_pos .z += count + 1 ;
158
+ air_block->region_pos = last_air_block->region_pos ;
159
+
160
+ // Copy other potentially important metadata from prior air
161
+ // layer
162
+ std::memcpy (air_block->lighting , last_air_block->lighting ,
163
+ sizeof (air_block->lighting ));
164
+ std::memcpy (air_block->temperature_1 , last_air_block->temperature_1 ,
165
+ sizeof (air_block->temperature_1 ));
166
+ std::memcpy (air_block->temperature_2 , last_air_block->temperature_2 ,
167
+ sizeof (air_block->temperature_2 ));
168
+ std::memcpy (air_block->region_offset , last_air_block->region_offset ,
169
+ sizeof (air_block->region_offset ));
170
+
171
+ // Create tile designations to inform lighting and
172
+ // outside markers
173
+ df::tile_designation designation{};
174
+ designation.bits .light = true ;
175
+ designation.bits .outside = true ;
176
+ std::fill (&air_block->designation [0 ][0 ],
177
+ &air_block->designation [0 ][0 ] + (16 * 16 ), designation);
178
+
179
+ blockColumn[z_count_block + count] = air_block;
180
+ world->map .map_blocks .push_back (air_block);
181
+
182
+ // deal with map_block_column stuff even though it'd probably be
183
+ // fine
184
+ df::map_block_column *column =
185
+ world->map .column_index [bpos.x ][bpos.y ];
186
+ if (!column) {
187
+ DEBUG (cycle, out)
188
+ .print (" %s, line %d: column is null (%d, %d).\n " , __FILE__,
189
+ __LINE__, bpos.x , bpos.y );
190
+ continue ;
214
191
}
192
+ df::map_block_column::T_unmined_glyphs *glyphs =
193
+ new df::map_block_column::T_unmined_glyphs;
194
+ glyphs->x [0 ] = 0 ;
195
+ glyphs->x [1 ] = 1 ;
196
+ glyphs->x [2 ] = 2 ;
197
+ glyphs->x [3 ] = 3 ;
198
+ glyphs->y [0 ] = 0 ;
199
+ glyphs->y [1 ] = 0 ;
200
+ glyphs->y [2 ] = 0 ;
201
+ glyphs->y [3 ] = 0 ;
202
+ glyphs->tile [0 ] = ' e' ;
203
+ glyphs->tile [1 ] = ' x' ;
204
+ glyphs->tile [2 ] = ' p' ;
205
+ glyphs->tile [3 ] = ' ^' ;
206
+ column->unmined_glyphs .push_back (glyphs);
215
207
}
216
- }
208
+ return true ;
209
+ });
217
210
218
211
// Update global z level flags
219
212
df::z_level_flags *flags = new df::z_level_flags[z_count_block + howMany];
@@ -258,7 +251,7 @@ command_result infiniteSky(color_ostream &out,
258
251
opts.help )
259
252
return CR_WRONG_USAGE;
260
253
261
- if (opts.n != 0 ) {
254
+ if (opts.n > 0 ) {
262
255
out.print (" Infinite-sky: creating %d new z-level%s of sky.\n " , opts.n ,
263
256
opts.n == 1 ? " " : " s" );
264
257
doInfiniteSky (out, opts.n );
0 commit comments