diggingInvaders: only path from one guy, and other minor tweaks.

develop
expwnent 2013-06-09 17:52:13 -04:00
parent d26b11eb40
commit c4533dcb0c
1 changed files with 11 additions and 9 deletions

@ -217,20 +217,20 @@ int32_t manageInvasion(color_ostream& out) {
//out.print("DiggingInvaders is waiting.\n"); //out.print("DiggingInvaders is waiting.\n");
return -1; return -1;
} }
*df::global::pause_state = true;
lastInvasionDigger = unitId; lastInvasionDigger = unitId;
{ {
int32_t index = df::unit::binsearch_index(df::global::world->units.all, unitId); df::unit* unit = df::unit::find(unitId);
if ( index == -1 ) { if ( !unit ) {
//out.print("Error %s line %d: unitId = %d, index = %d.\n", __FILE__, __LINE__, unitId, index); //out.print("Error %s line %d: unitId = %d, index = %d.\n", __FILE__, __LINE__, unitId, index);
return -1; return -1;
} }
lastInvasionJob = df::global::world->units.all[index]->job.current_job->id; lastInvasionJob = unit->job.current_job->id;
} }
//EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, jobCompleteHandler, plugin_self); //EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, jobCompleteHandler, plugin_self);
//out.print("DiggingInvaders: job assigned.\n"); //out.print("DiggingInvaders: job assigned.\n");
*df::global::pause_state = true;
return 0; //did something return 0; //did something
} }
@ -340,18 +340,20 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
continue; continue;
if ( invaderPts.find(unit->pos) != invaderPts.end() ) if ( invaderPts.find(unit->pos) != invaderPts.end() )
continue; continue;
df::map_block* block = Maps::getTileBlock(unit->pos);
invaderConnectivity.insert(block->walkable[unit->pos.x&0xF][unit->pos.y&0xF]);
if ( invaderPts.size() > 0 )
continue;
invaderPts.insert(unit->pos); invaderPts.insert(unit->pos);
costMap[unit->pos] = 0; costMap[unit->pos] = 0;
fringe.insert(unit->pos); fringe.insert(unit->pos);
invaders.push_back(unit); invaders.push_back(unit);
df::map_block* block = Maps::getTileBlock(unit->pos);
invaderConnectivity.insert(block->walkable[unit->pos.x&0xF][unit->pos.y&0xF]);
} else { } else {
continue; continue;
} }
} }
if ( invaders.empty() ) { if ( invaders.empty() || localPts.empty() ) {
return -1; return -1;
} }
@ -432,7 +434,7 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
delete myEdges; delete myEdges;
} }
clock_t time = clock() - t0; 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, clocks/sec = %d\n", time, totalEdgeTime, closedSet.size(), edgeCount, (float)time / closedSet.size(), (float)time / edgeCount, CLOCKS_PER_SEC); 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 ) if ( !foundTarget )
return -1; return -1;