| 53 | } |
| 54 | |
| 55 | int32_t assignJob(color_ostream& out, Edge firstImportantEdge, unordered_map<df::coord,df::coord,PointHash> parentMap, unordered_map<df::coord,cost_t,PointHash>& costMap, vector<int32_t>& invaders, unordered_set<df::coord,PointHash>& requiresZNeg, unordered_set<df::coord,PointHash>& requiresZPos, MapExtras::MapCache& cache, DigAbilities& abilities ) { |
| 56 | df::unit* firstInvader = df::unit::find(invaders[0]); |
| 57 | if ( !firstInvader ) { |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | //do whatever you need to do at the first important edge |
| 62 | df::coord pt1 = firstImportantEdge.p1; |
| 63 | df::coord pt2 = firstImportantEdge.p2; |
| 64 | if ( costMap[pt1] > costMap[pt2] ) { |
| 65 | df::coord temp = pt1; |
| 66 | pt1 = pt2; |
| 67 | pt2 = temp; |
| 68 | } |
| 69 | //out.print("first important edge: (%d,%d,%d) -> (%d,%d,%d)\n", pt1.x,pt1.y,pt1.z, pt2.x,pt2.y,pt2.z); |
| 70 | |
| 71 | df::coord location; |
| 72 | df::building* building = Buildings::findAtTile(pt2); |
| 73 | df::coord buildingPos = pt2; |
| 74 | if ( pt1.z > pt2.z ) { |
| 75 | building = Buildings::findAtTile(df::coord(pt2.x,pt2.y,pt2.z+1)); |
| 76 | buildingPos = df::coord(pt2.x,pt2.y,pt2.z+1); |
| 77 | } |
| 78 | if ( building != NULL ) { |
| 79 | df::coord destroyFrom = parentMap[buildingPos]; |
| 80 | if ( destroyFrom.z != buildingPos.z ) { |
| 81 | //TODO: deal with this |
| 82 | } |
| 83 | //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); |
| 84 | |
| 85 | df::job* job = new df::job; |
| 86 | job->job_type = df::enums::job_type::DestroyBuilding; |
| 87 | //job->flags.bits.special = 1; |
| 88 | df::general_ref_building_holderst* buildingRef = df::allocate<df::general_ref_building_holderst>(); |
| 89 | buildingRef->building_id = building->id; |
| 90 | job->general_refs.push_back(buildingRef); |
| 91 | df::general_ref_unit_workerst* workerRef = df::allocate<df::general_ref_unit_workerst>(); |
| 92 | workerRef->unit_id = firstInvader->id; |
| 93 | job->general_refs.push_back(workerRef); |
| 94 | getRidOfOldJob(firstInvader); |
| 95 | firstInvader->job.current_job = job; |
| 96 | firstInvader->path.path.x.clear(); |
| 97 | firstInvader->path.path.y.clear(); |
| 98 | firstInvader->path.path.z.clear(); |
| 99 | firstInvader->path.dest = destroyFrom; |
| 100 | location = destroyFrom; |
| 101 | firstInvader->job.hunt_target = NULL; |
| 102 | firstInvader->job.destroy_target = NULL; |
| 103 | |
| 104 | building->jobs.clear(); |
| 105 | building->jobs.push_back(job); |
| 106 | Job::linkIntoWorld(job); |
| 107 | job->completion_timer = abilities.jobDelay[CostDimension::DestroyBuilding]; |
| 108 | } else { |
| 109 | df::tiletype* type1 = Maps::getTileType(pt1); |
| 110 | df::tiletype* type2 = Maps::getTileType(pt2); |
| 111 | df::tiletype_shape shape1 = ENUM_ATTR(tiletype, shape, *type1); |
| 112 | df::tiletype_shape shape2 = ENUM_ATTR(tiletype, shape, *type2); |
no test coverage detected