@@ -157,8 +157,6 @@ int32_t findAndAssignInvasionJob(color_ostream& out);
157157void initiateDigging (color_ostream& out, void * ptr) {
158158 // called when there's a new invasion
159159 // TODO: check if invaders can dig
160- lastInvasionJob = -1 ;
161- lastInvasionDigger = -1 ;
162160 if ( manageInvasion (out) == -2 )
163161 return ;
164162
@@ -179,10 +177,7 @@ void watchForJobComplete(color_ostream& out, void* ptr) {
179177
180178 EventManager::unregister (EventManager::EventType::JOB_COMPLETED , jobCompleteHandler, diggingInvadersPlugin);
181179
182- lastInvasionJob = -1 ;
183- lastInvasionDigger = -1 ;
184- std::vector<string> parameters;
185- diggingInvadersFunc (out, parameters);
180+ manageInvasion (out);
186181}
187182
188183int32_t manageInvasion (color_ostream& out) {
@@ -202,7 +197,9 @@ int32_t manageInvasion(color_ostream& out) {
202197 out.print (" Error %s line %d.\n " , __FILE__, __LINE__);
203198 return -1 ;
204199 }
205- if ( lastInvasionJob == df::global::world->units .all [index]->job .current_job ->id ) {
200+ df::job* job = df::global::world->units .all [index]->job .current_job ;
201+ out.print (" job id: old = %d, new = %d\n " , lastInvasionJob, job == NULL ? -1 : job->id );
202+ if ( job != NULL && lastInvasionJob == job->id ) {
206203 out.print (" Still working on the previous job.\n " );
207204 return -1 ;
208205 }
@@ -212,8 +209,8 @@ int32_t manageInvasion(color_ostream& out) {
212209 int32_t unitId = findAndAssignInvasionJob (out);
213210 if ( unitId == -1 ) {
214211 // might need to do more digging later, after we've killed off a few locals
215- EventManager::EventHandler checkPeriodically (initiateDigging, 1000 );
216- EventManager::registerTick (checkPeriodically, checkPeriodically.freq , diggingInvadersPlugin);
212+ // EventManager::EventHandler checkPeriodically(initiateDigging, 1000);
213+ // EventManager::registerTick(checkPeriodically, checkPeriodically.freq, diggingInvadersPlugin);
217214 out.print (" DiggingInvaders is waiting.\n " );
218215 return -1 ;
219216 }
@@ -344,6 +341,7 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
344341 int32_t localPtsFound = 0 ;
345342 unordered_set<df::coord,PointHash> closedSet;
346343 unordered_map<df::coord,int32_t ,PointHash> workNeeded; // non-walking work needed to get there
344+ bool foundTarget = false ;
347345
348346 clock_t t0 = clock ();
349347 clock_t totalEdgeTime = 0 ;
@@ -359,8 +357,10 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
359357
360358 if ( localPts.find (pt) != localPts.end () ) {
361359 localPtsFound++;
362- if ( localPtsFound >= localPts.size () )
360+ if ( localPtsFound >= localPts.size () ) {
361+ foundTarget = true ;
363362 break ;
363+ }
364364 if ( workNeeded.find (pt) == workNeeded.end () || workNeeded[pt] == 0 ) {
365365 // there are still dwarves to kill that don't require digging to get to
366366 return -1 ;
@@ -396,6 +396,9 @@ int32_t findAndAssignInvasionJob(color_ostream& out) {
396396 clock_t time = clock () - t0;
397397 out.print (" time = %d, totalEdgeTime = %d\n " , time, totalEdgeTime);
398398
399+ if ( !foundTarget )
400+ return -1 ;
401+
399402 unordered_set<df::coord, PointHash> requiresZNeg;
400403 unordered_set<df::coord, PointHash> requiresZPos;
401404
0 commit comments