diggingInvaders: make invaders dig slowly, in a configurable way.

develop
expwnent 2013-06-11 05:14:56 -04:00
parent 3e7bce8f2f
commit f557376c3a
4 changed files with 34 additions and 10 deletions

@ -107,6 +107,7 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
building->jobs.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_map<df:
firstInvader->job.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_map<df:
firstInvader->path.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;

@ -104,6 +104,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" diggingInvaders setCost destroyBuilding n\n"
" diggingInvaders setCost dig n\n"
" diggingInvaders setCost destroyConstruction n\n"
" diggingInvaders setDelay destroyBuilding n\n adds to the job_completion_timer of destroy building jobs that are assigned to invaders\n"
" diggingInvaders setDelay dig n\n"
" diggingInvaders setDelay destroyConstruction n\n"
" diggingInvaders now\n makes invaders try to dig now, if plugin is enabled\n"
" diggingInvaders clear\n clears all digging invader races\n"
" diggingInvaders edgesPerTick n\n makes the pathfinding algorithm work on at most n edges per tick. Set to 0 or lower to make it unlimited."
@ -194,13 +197,15 @@ command_result diggingInvadersCommand(color_ostream& out, std::vector<std::strin
diggingRaces.erase(race);
}
a++;
} else if ( parameters[a] == "setCost" ) {
} else if ( parameters[a] == "setCost" || parameters[a] == "setDelay" ) {
if ( a+2 >= 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<std::strin
cost_t value;
stringstream asdf(parameters[a+2]);
asdf >> 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();

@ -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<Edge>* getEdgeSet(color_ostream &out, df::coord point, MapExtras::MapCache& cache, int32_t xMax, int32_t yMax, int32_t zMax) {
vector<Edge>* result = new vector<Edge>(26);
//result->reserve(26);
//vector<Edge>* result = new vector<Edge>(26);
vector<Edge>* result = new vector<Edge>();
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<Edge>* 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++;
}
}
}

@ -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