diggingInvaders: more fixes. Still a few issues with ramps probably.

develop
expwnent 2013-05-31 20:39:43 -04:00
parent 2b7dfca21e
commit 08114cf574
4 changed files with 42 additions and 22 deletions

@ -564,6 +564,10 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
if ( !index_tile<uint16_t>(block1->walkable,pos1) || !index_tile<uint16_t>(block2->walkable,pos2) ) {
return false;
}
if ( block1->designation[pos1.x&0xF][pos1.y&0xF].bits.flow_size >= 4 ||
block2->designation[pos2.x&0xF][pos2.y&0xF].bits.flow_size >= 4 )
return false;
if ( dz == 0 )
return true;

@ -50,14 +50,14 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
pt1 = pt2;
pt2 = temp;
}
out.print("first important edge: (%d,%d,%d) -> (%d,%d,%d)\n", pt1.x,pt1.y,pt1.z, pt2.x,pt2.y,pt2.z);
//out.print("first important edge: (%d,%d,%d) -> (%d,%d,%d)\n", pt1.x,pt1.y,pt1.z, pt2.x,pt2.y,pt2.z);
int32_t jobId = -1;
df::map_block* block1 = Maps::getTileBlock(pt1);
df::map_block* block2 = Maps::getTileBlock(pt2);
bool passable1 = block1->walkable[pt1.x&0x0F][pt1.y&0x0F];
bool passable2 = block2->walkable[pt2.x&0x0F][pt2.y&0x0F];
bool passable1 = block1->walkable[pt1.x&0xF][pt1.y&0xF];
bool passable2 = block2->walkable[pt2.x&0xF][pt2.y&0xF];
df::coord location;
df::building* building = Buildings::findAtTile(pt2);
@ -68,6 +68,9 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
}
if ( building != NULL ) {
df::coord destroyFrom = parentMap[buildingPos];
if ( destroyFrom.z != buildingPos.z ) {
//TODO: deal with this
}
//out.print("%s, line %d: Destroying building %d at (%d,%d,%d) from (%d,%d,%d).\n", __FILE__, __LINE__, building->id, buildingPos.x,buildingPos.y,buildingPos.z, destroyFrom.x,destroyFrom.y,destroyFrom.z);
df::job* job = new df::job;
@ -152,18 +155,18 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df:
df::job* job = new df::job;
if ( up && down ) {
job->job_type = df::enums::job_type::CarveUpDownStaircase;
out.print("%s, line %d: type = up/down\n", __FILE__, __LINE__);
//out.print("%s, line %d: type = up/down\n", __FILE__, __LINE__);
} else if ( up && !down ) {
job->job_type = df::enums::job_type::CarveUpwardStaircase;
out.print("%s, line %d: type = up\n", __FILE__, __LINE__);
//out.print("%s, line %d: type = up\n", __FILE__, __LINE__);
} else if ( !up && down ) {
job->job_type = df::enums::job_type::CarveDownwardStaircase;
out.print("%s, line %d: type = down\n", __FILE__, __LINE__);
//out.print("%s, line %d: type = down\n", __FILE__, __LINE__);
} else {
job->job_type = df::enums::job_type::Dig;
out.print("%s, line %d: type = dig\n", __FILE__, __LINE__);
//out.print("%s, line %d: type = dig\n", __FILE__, __LINE__);
}
out.print("%s, line %d: up=%d,up1=%d,up2=%d, down=%d,down1=%d,down2=%d\n", __FILE__, __LINE__, up,up1,up2, down,down1,down2);
//out.print("%s, line %d: up=%d,up1=%d,up2=%d, down=%d,down1=%d,down2=%d\n", __FILE__, __LINE__, up,up1,up2, down,down1,down2);
job->pos = workHere;
firstInvader->path.dest = goHere;
location = goHere;

@ -185,7 +185,7 @@ void watchForJobComplete(color_ostream& out, void* ptr) {
}
int32_t manageInvasion(color_ostream& out) {
EventManager::unregisterAll(plugin_self);
//EventManager::unregisterAll(plugin_self);
if ( !enabled ) {
return -1;
}
@ -214,13 +214,13 @@ int32_t manageInvasion(color_ostream& out) {
//return 1; //still invading, but nothing new done
}
*df::global::pause_state = true;
int32_t unitId = findAndAssignInvasionJob(out);
if ( unitId == -1 ) {
//might need to do more digging later, after we've killed off a few locals
//out.print("DiggingInvaders is waiting.\n");
return -1;
}
*df::global::pause_state = true;
lastInvasionDigger = unitId;
{
@ -299,7 +299,7 @@ command_result diggingInvadersFunc(color_ostream& out, std::vector<std::string>&
return CR_WRONG_USAGE;
}
}
if ( parameters.size() == 0 )
manageInvasion(out);
return CR_OK;
@ -371,9 +371,9 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
return -1;
}
df::unit* firstInvader = invaders[0];
out << firstInvader->id << endl;
out << firstInvader->pos.x << ", " << firstInvader->pos.y << ", " << firstInvader->pos.z << endl;
out << __LINE__ << endl;
//out << firstInvader->id << endl;
//out << firstInvader->pos.x << ", " << firstInvader->pos.y << ", " << firstInvader->pos.z << endl;
//out << __LINE__ << endl;
int32_t localPtsFound = 0;
unordered_set<df::coord,PointHash> closedSet;
@ -435,7 +435,7 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
delete myEdges;
}
clock_t time = clock() - t0;
out.print("time = %d, totalEdgeTime = %d, total points = %d, total edges = %d, time per point = %.3f, time per edge = %.3f\n", time, totalEdgeTime, closedSet.size(), edgeCount, (float)time / closedSet.size(), (float)time / edgeCount);
//out.print("time = %d, totalEdgeTime = %d, total points = %d, total edges = %d, time per point = %.3f, time per edge = %.3f, clocks/sec = %d\n", time, totalEdgeTime, closedSet.size(), edgeCount, (float)time / closedSet.size(), (float)time / edgeCount, CLOCKS_PER_SEC);
if ( !foundTarget )
return -1;

@ -40,12 +40,8 @@ int64_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2) {
int32_t dy = pt2.y - pt1.y;
int32_t dz = pt2.z - pt1.z;
int64_t cost = costWeight[CostDimension::Walk];
if ( Maps::canStepBetween(pt1, pt2) ) {
return cost;
}
if ( Maps::getTileBlock(pt2) == NULL )
if ( Maps::getTileBlock(pt1) == NULL || Maps::getTileBlock(pt2) == NULL )
return -1;
df::tiletype* type2 = Maps::getTileType(pt2);
@ -62,6 +58,17 @@ int64_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2) {
if ( shape2 == df::enums::tiletype_shape::TREE )
return -1;
/*
if () {
df::map_block* temp = Maps::getTileBlock(df::coord(pt1.x,pt1.y,pt1.z-1));
if ( temp && temp->designation[pt1.x&0xF][pt1.y&0xF]
}
*/
if ( Maps::canStepBetween(pt1, pt2) ) {
return cost;
}
df::building* building2 = Buildings::findAtTile(pt2);
if ( building2 ) {
@ -77,7 +84,9 @@ int64_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2) {
if ( dz == 0 ) {
if ( !building2 && !construction2 ) {
//it has to be a wall
if ( shape2 != df::enums::tiletype_shape::WALL ) {
if ( shape2 == df::enums::tiletype_shape::RAMP_TOP ) {
return -1;
} else if ( shape2 != df::enums::tiletype_shape::WALL ) {
//out << "shape = " << (int32_t)shape2 << endl;
//out << __FILE__ << ", line " << __LINE__ << ": WTF?" << endl;
return cost;
@ -191,6 +200,7 @@ int64_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2) {
forbidden = true;
}
//you can deconstruct a hatch from the side
if ( building1 && forbidden /*&& building1->getType() == df::building_type::Hatch*/ ) {
df::coord support[] = {df::coord(pt1.x-1, pt1.y, pt1.z), df::coord(pt1.x+1,pt1.y,pt1.z), df::coord(pt1.x,pt1.y-1,pt1.z), df::coord(pt1.x,pt1.y+1,pt1.z)};
int64_t minCost = -1;
@ -229,6 +239,9 @@ int64_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2) {
if ( minCost == -1 )
return -1;
cost += minCost;
//note: assignJob is not ready for this level of sophistication, so don't allow it
return -1;
}
}
} else {