From 08114cf574a6d9d9f57999f48651d5ecc72dbd66 Mon Sep 17 00:00:00 2001 From: expwnent Date: Fri, 31 May 2013 20:39:43 -0400 Subject: [PATCH] diggingInvaders: more fixes. Still a few issues with ramps probably. --- library/modules/Maps.cpp | 4 +++ plugins/diggingInvaders/assignJob.cpp | 19 +++++++++------ plugins/diggingInvaders/diggingInvaders.cpp | 14 +++++------ plugins/diggingInvaders/edgeCost.cpp | 27 +++++++++++++++------ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 477f3c3cd..4b8637c0f 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -564,6 +564,10 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2) if ( !index_tile(block1->walkable,pos1) || !index_tile(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; diff --git a/plugins/diggingInvaders/assignJob.cpp b/plugins/diggingInvaders/assignJob.cpp index 4a6973735..29520df37 100644 --- a/plugins/diggingInvaders/assignJob.cpp +++ b/plugins/diggingInvaders/assignJob.cpp @@ -50,14 +50,14 @@ int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map (%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_mapid, 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_mapjob_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; diff --git a/plugins/diggingInvaders/diggingInvaders.cpp b/plugins/diggingInvaders/diggingInvaders.cpp index d79f3b810..bf66fc9fd 100644 --- a/plugins/diggingInvaders/diggingInvaders.cpp +++ b/plugins/diggingInvaders/diggingInvaders.cpp @@ -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& 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 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; diff --git a/plugins/diggingInvaders/edgeCost.cpp b/plugins/diggingInvaders/edgeCost.cpp index 2d08146dd..dcef640f4 100644 --- a/plugins/diggingInvaders/edgeCost.cpp +++ b/plugins/diggingInvaders/edgeCost.cpp @@ -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 {