MCPcopy Create free account
hub / github.com/DFHack/dfhack / findAndAssignInvasionJob

Function findAndAssignInvasionJob

plugins/diggingInvaders/diggingInvaders.cpp:346–598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344/////////////////////////////////////////////////////////////////////////////////////////
345
346void findAndAssignInvasionJob(color_ostream& out, void* tickTime) {
347 //returns the worker id of the job created //used to
348 //out.print("%s, %d: %d\n", __FILE__, __LINE__, (int32_t)tickTime);
349
350 if ( !enabled || !activeDigging ) {
351 clearDijkstra();
352 return;
353 }
354
355 //we're going to unregister just in case this function has been called 20 times or something.
356 EventManager::unregister(EventManager::EventType::TICK, findJobTickHandler);
357 EventManager::registerTick(findJobTickHandler, 1);
358
359 if ( fringe.empty() ) {
360 df::unit* lastDigger = df::unit::find(lastInvasionDigger);
361 if ( lastDigger && lastDigger->job.current_job && lastDigger->job.current_job->id == lastInvasionJob ) {
362 return;
363 }
364 //out.print("{},{}: lastDigger = {}, last job = {}, last digger's job = {}\n", __FILE__, __LINE__, lastInvasionDigger, lastInvasionJob, !lastDigger ? -1 : (!lastDigger->job.current_job ? -1 : lastDigger->job.current_job->id));
365 lastInvasionDigger = lastInvasionJob = -1;
366
367 clearDijkstra();
368 unordered_set<uint16_t> invaderConnectivity;
369 unordered_set<uint16_t> localConnectivity;
370
371 //find all locals and invaders
372 for ( size_t a = 0; a < world->units.all.size(); a++ ) {
373 df::unit* unit = world->units.all[a];
374 if ( !Units::isActive(unit) )
375 continue;
376 if ( Units::isCitizen(unit) ) {
377 if ( localPts.find(unit->pos) != localPts.end() )
378 continue;
379 localPts.insert(unit->pos);
380 df::map_block* block = Maps::getTileBlock(unit->pos);
381 localConnectivity.insert(block->walkable[unit->pos.x&0xF][unit->pos.y&0xF]);
382 } else if ( unit->flags1.bits.active_invader ) {
383 df::creature_raw* raw = df::creature_raw::find(unit->race);
384 if ( raw == NULL ) {
385 out.print("{},{}: WTF? Couldn't find creature raw.\n", __FILE__, __LINE__);
386 continue;
387 }
388 /*
389 if ( diggingRaces.find(raw->creature_id) == diggingRaces.end() )
390 continue;
391 */
392 if ( digAbilities.find(raw->creature_id) == digAbilities.end() )
393 continue;
394 if ( invaderPts.find(unit->pos) != invaderPts.end() )
395 continue;
396 //must be able to wield a pick: this is overly pessimistic
397 if ( unit->status2.limbs_grasp_max <= 0 || unit->status2.limbs_grasp_count < unit->status2.limbs_grasp_max )
398 continue;
399 df::map_block* block = Maps::getTileBlock(unit->pos);
400 invaderConnectivity.insert(block->walkable[unit->pos.x&0xF][unit->pos.y&0xF]);
401 if ( invaderPts.size() > 0 )
402 continue;
403 invaderPts.insert(unit->pos);

Callers 4

newInvasionHandlerFunction · 0.85
diggingInvadersCommandFunction · 0.85

Calls 15

clearDijkstraFunction · 0.85
getTileBlockFunction · 0.85
getEdgeSetFunction · 0.85
getEdgeCostFunction · 0.85
EdgeClass · 0.85
assignJobFunction · 0.85
findFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected