diff --git a/plugins/diggingInvaders/assignJob.cpp b/plugins/diggingInvaders/assignJob.cpp index f43eaf207..062813455 100644 --- a/plugins/diggingInvaders/assignJob.cpp +++ b/plugins/diggingInvaders/assignJob.cpp @@ -107,6 +107,7 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_mapjobs.push_back(job); Job::linkIntoWorld(job); jobId = job->id; + job->completion_timer = jobDelay[DestroyBuilding]; } else { df::tiletype* type1 = Maps::getTileType(pt1); df::tiletype* type2 = Maps::getTileType(pt2); @@ -131,6 +132,7 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_mapjob.destroy_target = NULL; Job::linkIntoWorld(job); jobId = job->id; + job->completion_timer = jobDelay[DestroyConstruction]; } else { bool walkable_low1 = shape1 == df::tiletype_shape::STAIR_DOWN || shape1 == df::tiletype_shape::STAIR_UPDOWN; bool walkable_low2 = shape2 == df::tiletype_shape::STAIR_DOWN || shape2 == df::tiletype_shape::STAIR_UPDOWN; @@ -193,6 +195,7 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_mappath.path.z.clear(); Job::linkIntoWorld(job); jobId = job->id; + job->completion_timer = jobDelay[Dig]; //TODO: test if he already has a pick bool hasPick = false; diff --git a/plugins/diggingInvaders/diggingInvaders.cpp b/plugins/diggingInvaders/diggingInvaders.cpp index ec416460d..9afa29f75 100644 --- a/plugins/diggingInvaders/diggingInvaders.cpp +++ b/plugins/diggingInvaders/diggingInvaders.cpp @@ -104,6 +104,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector = parameters.size() ) return CR_WRONG_USAGE; string costStr = parameters[a+1]; int32_t costDim = -1; if ( costStr == "walk" ) { costDim = CostDimension::Walk; + if ( parameters[a] == "setDelay" ) + return CR_WRONG_USAGE; } else if ( costStr == "destroyBuilding" ) { costDim = CostDimension::DestroyBuilding; } else if ( costStr == "dig" ) { @@ -213,9 +218,12 @@ command_result diggingInvadersCommand(color_ostream& out, std::vector> value; - if ( value <= 0 ) + if ( parameters[a] == "setCost" && value <= 0 ) return CR_WRONG_USAGE; - costWeight[costDim] = value; + if ( parameters[a] == "setCost" ) + costWeight[costDim] = value; + else + jobDelay[costDim] = value; a += 2; } else if ( parameters[a] == "edgeCost" ) { df::coord bob = Gui::getCursorPos(); diff --git a/plugins/diggingInvaders/edgeCost.cpp b/plugins/diggingInvaders/edgeCost.cpp index 1eaf07aa6..708ccddac 100644 --- a/plugins/diggingInvaders/edgeCost.cpp +++ b/plugins/diggingInvaders/edgeCost.cpp @@ -28,6 +28,17 @@ cost_t costWeight[] = { 100, }; +int32_t jobDelay[] = { +//Distance +-1, +//Destroy Building +1000, +//Dig +1000, +//DestroyConstruction +1000 +}; + using namespace std; /* @@ -388,15 +399,16 @@ cost_t getEdgeCostOld(color_ostream& out, df::coord pt1, df::coord pt2) { } vector* getEdgeSet(color_ostream &out, df::coord point, MapExtras::MapCache& cache, int32_t xMax, int32_t yMax, int32_t zMax) { - vector* result = new vector(26); - //result->reserve(26); + //vector* result = new vector(26); + vector* result = new vector(); + result->reserve(26); - size_t count = 0; + //size_t count = 0; for ( int32_t dx = -1; dx <= 1; dx++ ) { for ( int32_t dy = -1; dy <= 1; dy++ ) { for ( int32_t dz = -1; dz <= 1; dz++ ) { df::coord neighbor(point.x+dx, point.y+dy, point.z+dz); - if ( neighbor.x < 0 || neighbor.x >= xMax || neighbor.y < 0 || neighbor.y >= yMax || neighbor.z < 0 || neighbor.z >= zMax ) + if ( !Maps::isValidTilePos(neighbor) ) continue; if ( dz != 0 && /*(point.x == 0 || point.y == 0 || point.z == 0 || point.x == xMax-1 || point.y == yMax-1 || point.z == zMax-1) ||*/ (neighbor.x == 0 || neighbor.y == 0 || neighbor.z == 0 || neighbor.x == xMax-1 || neighbor.y == yMax-1 || neighbor.z == zMax-1) ) continue; @@ -406,9 +418,9 @@ vector* getEdgeSet(color_ostream &out, df::coord point, MapExtras::MapCach if ( cost == -1 ) continue; Edge edge(point, neighbor, cost); - //result->push_back(edge); - (*result)[count] = edge; - count++; + //(*result)[count] = edge; + result->push_back(edge); + //count++; } } } diff --git a/plugins/diggingInvaders/edgeCost.h b/plugins/diggingInvaders/edgeCost.h index fd1ab0e27..d2ef33ba4 100644 --- a/plugins/diggingInvaders/edgeCost.h +++ b/plugins/diggingInvaders/edgeCost.h @@ -24,6 +24,7 @@ enum CostDimension { typedef int64_t cost_t; extern cost_t costWeight[costDim]; +extern int32_t jobDelay[costDim]; /* const cost_t costWeight[] = { //Distance