diff --git a/plugins/filltraffic.cpp b/plugins/filltraffic.cpp index c27029a85..29ebdebaf 100644 --- a/plugins/filltraffic.cpp +++ b/plugins/filltraffic.cpp @@ -1,7 +1,8 @@ // Wide-area traffic designation utility. // Flood-fill from cursor or fill entire map. -#include //For toupper(). +#include //For toupper(). +#include //for min(). #include #include #include @@ -15,8 +16,22 @@ using std::stack; using MapExtras::MapCache; using namespace DFHack; +//Function pointer type for whole-map tile checks. +typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache *); + +//Forward Declarations for Commands DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector & params); -DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vector & params); +DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector & params); + +//Forward Declarations for Utility Functions +DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkProc, + DFHack::DFCoord minCoord = DFHack::DFCoord(0, 0, 0), + DFHack::DFCoord maxCoord = DFHack::DFCoord(0xFFFF, 0xFFFF, 0xFFFFFFFF)); + +void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map); DFhackCExport const char * plugin_name ( void ) { @@ -27,7 +42,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector { commands.clear(); commands.push_back(PluginCommand("filltraffic","Flood-fill with selected traffic designation from cursor",filltraffic)); - commands.push_back(PluginCommand("tiletraffic","Set traffic for all tiles based on given criteria",tiletraffic)); + commands.push_back(PluginCommand("alltraffic","Set traffic for the entire map",alltraffic)); + return CR_OK; } @@ -60,7 +76,7 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector & params) +DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector & params) { - //Target traffic types. - e_traffic target = traffic_normal; - //!!! Options Later !!! - + void (*proc)(DFHack::DFCoord, MapExtras::MapCache *) = allNormal; + //Loop through parameters for(int i = 0; i < params.size();i++) { @@ -248,19 +262,30 @@ DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vectorSuspend(); @@ -280,27 +305,76 @@ DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vector maxCoord.x) + { + c->con.printerr("Minimum x coordinate is greater than maximum x coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + if (minCoord.y > maxCoord.y) + { + c->con.printerr("Minimum y coordinate is greater than maximum y coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + if (minCoord.z > maxCoord.y) + { + c->con.printerr("Minimum z coordinate is greater than maximum z coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); - c->con.print("Entire map ... FILLING!\n"); + c->con.print("Setting traffic...\n"); //Loop through every single tile - for(uint32_t x = 0; x <= tx_max; x++) + for(uint32_t x = minCoord.x; x <= maxCoord.x; x++) { - for(uint32_t y = 0; y <= ty_max; y++) + for(uint32_t y = minCoord.y; y <= maxCoord.y; y++) { - for(uint32_t z = 0; z <= z_max; z++) + for(uint32_t z = minCoord.z; z <= maxCoord.z; z++) { DFHack::DFCoord tile = DFHack::DFCoord(x, y, z); - DFHack::t_designation des = MCache->designationAt(tile); - - des.bits.traffic = target; - MCache->setDesignationAt(tile, des); + checkProc(tile, MCache); } } } MCache->WriteAll(); + c->con.print("Complete!\n"); c->Resume(); return CR_OK; +} + +//Unconditionally set map to target traffic type +void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_high; + map->setDesignationAt(coord, des); +} +void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_normal; + map->setDesignationAt(coord, des); +} +void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_low; + map->setDesignationAt(coord, des); +} +void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_restricted; + map->setDesignationAt(coord, des); } \ No newline at end of file