diff options
| -rw-r--r-- | plugins/dig.cpp | 135 | ||||
| -rw-r--r-- | plugins/fastdwarf.cpp | 97 |
2 files changed, 214 insertions, 18 deletions
diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 21c19910..5e2bb9f8 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -24,7 +24,7 @@ command_result diglx (color_ostream &out, vector <string> & parameters); command_result digauto (color_ostream &out, vector <string> & parameters); command_result digexp (color_ostream &out, vector <string> & parameters); command_result digcircle (color_ostream &out, vector <string> & parameters); - +command_result digtype (color_ostream &out, vector <string> & parameters); DFHACK_PLUGIN("dig"); @@ -57,6 +57,18 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug commands.push_back(PluginCommand("digexp","Select or designate an exploratory pattern. Use 'digexp ?' for help.",digexp)); commands.push_back(PluginCommand("digcircle","Dig designate a circle (filled or hollow) with given radius.",digcircle)); //commands.push_back(PluginCommand("digauto","Mark a tile for continuous digging.",autodig)); + commands.push_back(PluginCommand("digtype", "Dig all veins of a given type.", digtype,Gui::cursor_hotkey, + "For every tile on the map of the same vein type as the selected tile, this command designates it to have the same designation as the selected tile. If the selected tile has no designation, they will be dig designated.\n" + "If an argument is given, the designation of the selected tile is ignored, and all appropriate tiles are set to the specified designation.\n" + "Options:\n" + " dig\n" + " channel\n" + " ramp\n" + " updown - up/down stairs\n" + " up - up stairs\n" + " down - down stairs\n" + " clear - clear designation\n" + )); return CR_OK; } @@ -951,7 +963,7 @@ command_result digexp (color_ostream &out, vector <string> & parameters) mx.setDesignationAt(pos,des); } } - mx.WriteAll(); + mx.WriteAll(); } else for(uint32_t x = 0; x < x_max; x++) { @@ -1129,6 +1141,7 @@ command_result digv (color_ostream &out, vector <string> & parameters) } } MCache->WriteAll(); + delete MCache; return CR_OK; } @@ -1342,6 +1355,7 @@ command_result digl (color_ostream &out, vector <string> & parameters) } } MCache->WriteAll(); + delete MCache; return CR_OK; } @@ -1350,3 +1364,120 @@ command_result digauto (color_ostream &out, vector <string> & parameters) { return CR_NOT_IMPLEMENTED; } + +command_result digtype (color_ostream &out, vector <string> & parameters) +{ + //mostly copy-pasted from digv + CoreSuspender suspend; + if ( parameters.size() > 1 ) + { + out.printerr("Too many parameters.\n"); + return CR_FAILURE; + } + + uint32_t targetDigType; + if ( parameters.size() == 1 ) + { + string parameter = parameters[0]; + if ( parameter == "clear" ) + targetDigType = tile_dig_designation::No; + else if ( parameter == "dig" ) + targetDigType = tile_dig_designation::Default; + else if ( parameter == "updown" ) + targetDigType = tile_dig_designation::UpDownStair; + else if ( parameter == "channel" ) + targetDigType = tile_dig_designation::Channel; + else if ( parameter == "ramp" ) + targetDigType = tile_dig_designation::Ramp; + else if ( parameter == "down" ) + targetDigType = tile_dig_designation::DownStair; + else if ( parameter == "up" ) + targetDigType = tile_dig_designation::UpStair; + else + { + out.printerr("Invalid parameter.\n"); + return CR_FAILURE; + } + } + else + { + targetDigType = -1; + } + + if (!Maps::IsValid()) + { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + + int32_t cx, cy, cz; + uint32_t xMax,yMax,zMax; + Maps::getSize(xMax,yMax,zMax); + uint32_t tileXMax = xMax * 16; + uint32_t tileYMax = yMax * 16; + Gui::getCursorCoords(cx,cy,cz); + if (cx == -30000) + { + out.printerr("Cursor is not active. Point the cursor at a vein.\n"); + return CR_FAILURE; + } + DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); + MapExtras::MapCache * mCache = new MapExtras::MapCache; + df::tile_designation baseDes = mCache->designationAt(xy); + df::tiletype tt = mCache->tiletypeAt(xy); + int16_t veinmat = mCache->veinMaterialAt(xy); + if( veinmat == -1 ) + { + out.printerr("This tile is not a vein.\n"); + delete mCache; + return CR_FAILURE; + } + out.print("(%d,%d,%d) tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, baseDes.whole); + + if ( targetDigType != -1 ) + { + baseDes.bits.dig = (tile_dig_designation::tile_dig_designation)targetDigType; + } + else + { + if ( baseDes.bits.dig == tile_dig_designation::No ) + { + baseDes.bits.dig = tile_dig_designation::Default; + } + } + + for( uint32_t z = 0; z < zMax; z++ ) + { + for( uint32_t x = 1; x < tileXMax-1; x++ ) + { + for( uint32_t y = 1; y < tileYMax-1; y++ ) + { + DFHack::DFCoord current(x,y,z); + int16_t vmat2 = mCache->veinMaterialAt(current); + if ( vmat2 != veinmat ) + continue; + tt = mCache->tiletypeAt(current); + if (!DFHack::isWallTerrain(tt)) + continue; + + //designate it for digging + df::tile_designation des = mCache->designationAt(current); + if ( !mCache->testCoord(current) ) + { + out.printerr("testCoord failed at (%d,%d,%d)\n", x, y, z); + delete mCache; + return CR_FAILURE; + } + + df::tile_designation designation = mCache->designationAt(current); + designation.bits.dig = baseDes.bits.dig; + mCache->setDesignationAt(current, designation); + } + } + } + + mCache->WriteAll(); + delete mCache; + return CR_OK; +} + diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 5a2e2f20..400bff23 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -23,33 +23,89 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) return CR_OK; } -static int enable_fastdwarf = false; +static bool enable_fastdwarf = false; +static bool enable_teledwarf = false; DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { // check run conditions - if(!world || !world->map.block_index || !enable_fastdwarf) + if(!world || !world->map.block_index) { - // give up if we shouldn't be running' + enable_fastdwarf = enable_teledwarf = false; return CR_OK; } int32_t race = ui->race_id; int32_t civ = ui->civ_id; - - for (size_t i = 0; i < world->units.all.size(); i++) - { - df::unit *unit = world->units.all[i]; - - if (unit->race == race && unit->civ_id == civ && unit->counters.job_counter > 0) - unit->counters.job_counter = 0; - // could also patch the unit->job.current_job->completion_timer + + if ( enable_fastdwarf ) { + for (size_t i = 0; i < world->units.all.size(); i++) + { + df::unit *unit = world->units.all[i]; + + if (unit->race == race && unit->civ_id == civ && unit->counters.job_counter > 0) + unit->counters.job_counter = 0; + // could also patch the unit->job.current_job->completion_timer + } + } + if ( enable_teledwarf ) { + for (size_t i = 0; i < world->units.all.size(); i++) + { + df::unit *unit = world->units.all[i]; + + if (unit->race != race || unit->civ_id != civ || unit->path.dest.x == -30000) + continue; + if (unit->relations.draggee_id != -1 || unit->relations.dragger_id != -1) + continue; + if (unit->relations.following != 0) + continue; + + //move immediately to destination + unit->pos.x = unit->path.dest.x; + unit->pos.y = unit->path.dest.y; + unit->pos.z = unit->path.dest.z; + } } return CR_OK; } static command_result fastdwarf (color_ostream &out, vector <string> & parameters) { - if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) + if (parameters.size() == 1) { + if ( parameters[0] == "0" ) { + enable_fastdwarf = false; + enable_teledwarf = false; + } else if ( parameters[0] == "1" ) { + enable_fastdwarf = true; + enable_teledwarf = false; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + } else if (parameters.size() == 2) { + if ( parameters[0] == "0" ) { + enable_fastdwarf = false; + } else if ( parameters[0] == "1" ) { + enable_fastdwarf = true; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + if ( parameters[1] == "0" ) { + enable_teledwarf = false; + } else if ( parameters[1] == "1" ) { + enable_teledwarf = true; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + } else if (parameters.size() == 0) { + //print status + out.print("Current state: fast = %d, teleport = %d.\n", enable_fastdwarf, enable_teledwarf); + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + /*if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) { if (parameters[0] == "0") enable_fastdwarf = 0; @@ -62,7 +118,7 @@ static command_result fastdwarf (color_ostream &out, vector <string> & parameter out.print("Makes your minions move at ludicrous speeds.\n" "Activate with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\n" "Current state: %d.\n", enable_fastdwarf); - } + }*/ return CR_OK; } @@ -70,8 +126,17 @@ static command_result fastdwarf (color_ostream &out, vector <string> & parameter DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) { commands.push_back(PluginCommand("fastdwarf", - "enable/disable fastdwarf (parameter=0/1)", - fastdwarf)); - + "enable/disable fastdwarf and teledwarf (parameters=0/1)", + fastdwarf, false, + "fastdwarf: controls speedydwarf and teledwarf. Speedydwarf makes dwarves move quickly and perform tasks quickly. Teledwarf makes dwarves move instantaneously, but do jobs at the same speed.\n" + "Usage:\n" + " fastdwarf 0 0: disable both speedydwarf and teledwarf\n" + " fastdwarf 0 1: disable speedydwarf, enable teledwarf\n" + " fastdwarf 1 0: enable speedydwarf, disable teledwarf\n" + " fastdwarf 1 1: enable speedydwarf, enable teledwarf\n" + " fastdwarf 0: disable speedydwarf, disable teledwarf\n" + " fastdwarf 1: enable speedydwarf, disable teledwarf\n" + )); + return CR_OK; } |
