|
3 | 3 | #include "DataDefs.h"
|
4 | 4 | #include "Debug.h"
|
5 | 5 | #include "Export.h"
|
| 6 | +#include "LuaTools.h" |
6 | 7 | #include "PluginManager.h"
|
7 | 8 |
|
8 | 9 | #include "modules/World.h"
|
@@ -228,18 +229,42 @@ void doInfiniteSky(color_ostream& out, int32_t howMany) {
|
228 | 229 | world->map_extras.z_level_flags = flags;
|
229 | 230 | }
|
230 | 231 |
|
231 |
| -command_result infiniteSky (color_ostream &out, std::vector <std::string> & parameters) |
232 |
| -{ |
233 |
| - if ( parameters.size() > 1 ) |
| 232 | +struct infinitesky_options { |
| 233 | + // whether to display help |
| 234 | + bool help = false; |
| 235 | + |
| 236 | + // how many z levels to generate immediately (0 for none) |
| 237 | + int32_t n = 0; |
| 238 | + |
| 239 | + static struct_identity _identity; |
| 240 | +}; |
| 241 | +static const struct_field_info infinitesky_options_fields[] = { |
| 242 | + {struct_field_info::PRIMITIVE, "help", offsetof(infinitesky_options, help), &df::identity_traits<bool>::identity, 0, 0}, |
| 243 | + {struct_field_info::PRIMITIVE, "n", offsetof(infinitesky_options, n), &df::identity_traits<int32_t>::identity, 0, 0} |
| 244 | +}; |
| 245 | +struct_identity infinitesky_options::_identity{sizeof(infinitesky_options), &df::allocator_fn<infinitesky_options>, NULL, "infinitesky_options", NULL, infinitesky_options_fields}; |
| 246 | + |
| 247 | +command_result infiniteSky(color_ostream &out, |
| 248 | + std::vector<std::string> ¶meters) { |
| 249 | + if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) { |
| 250 | + out.printerr("Cannot run %s without a loaded fort.\n", plugin_name); |
| 251 | + return CR_FAILURE; |
| 252 | + } |
| 253 | + |
| 254 | + infinitesky_options opts; |
| 255 | + if (!Lua::CallLuaModuleFunction(out, "plugins.infiniteSky", |
| 256 | + "parse_commandline", |
| 257 | + std::make_tuple(&opts, parameters)) || |
| 258 | + opts.help) |
234 | 259 | return CR_WRONG_USAGE;
|
235 |
| - if (parameters.size() == 0) { |
| 260 | + |
| 261 | + if (opts.n != 0) { |
| 262 | + out.print("InfiniteSky: creating %d new z-level%s of sky.\n", opts.n, |
| 263 | + opts.n == 1 ? "" : "s"); |
| 264 | + doInfiniteSky(out, opts.n); |
| 265 | + } else { |
236 | 266 | out.print("Construction monitoring is %s.\n",
|
237 | 267 | is_enabled ? "enabled" : "disabled");
|
238 |
| - return CR_OK; |
239 | 268 | }
|
240 |
| - int32_t howMany = 0; |
241 |
| - howMany = atoi(parameters[0].c_str()); |
242 |
| - out.print("InfiniteSky: creating %d new z-level%s of sky.\n", howMany, howMany == 1 ? "" : "s" ); |
243 |
| - doInfiniteSky(out, howMany); |
244 | 269 | return CR_OK;
|
245 | 270 | }
|
0 commit comments