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

Function update_jobs_by_constraints

plugins/workflow.cpp:1194–1285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1192}
1193
1194static void update_jobs_by_constraints(color_ostream &out)
1195{
1196 for (TKnownJobs::const_iterator it = known_jobs.begin(); it != known_jobs.end(); ++it)
1197 {
1198 ProtectedJob *pj = it->second;
1199 if (!pj->isLive())
1200 continue;
1201
1202 if (pj->actual_job->job_type == job_type::MeltMetalObject &&
1203 isOptionEnabled(CF_AUTOMELT))
1204 {
1205 setJobResumed(out, pj, meltable_count > 0);
1206 continue;
1207 }
1208
1209 if (pj->constraints.empty())
1210 continue;
1211
1212 int resume_weight = -1;
1213 int suspend_weight = -1;
1214
1215 for (size_t i = 0; i < pj->constraints.size(); i++)
1216 {
1217 if (pj->constraints[i]->request_resume)
1218 resume_weight = std::max(resume_weight, pj->constraints[i]->weight);
1219 if (pj->constraints[i]->request_suspend)
1220 suspend_weight = std::max(suspend_weight, pj->constraints[i]->weight);
1221 }
1222
1223 bool goal = pj->isResumed();
1224
1225 if (resume_weight >= 0 && resume_weight >= suspend_weight)
1226 goal = true;
1227 else if (suspend_weight >= 0 && suspend_weight >= resume_weight)
1228 goal = false;
1229
1230 setJobResumed(out, pj, goal);
1231 }
1232
1233 for (size_t i = 0; i < constraints.size(); i++)
1234 {
1235 ItemConstraint *ct = constraints[i];
1236
1237 bool is_running = false;
1238 for (size_t j = 0; j < ct->jobs.size(); j++)
1239 if (!!(is_running = ct->jobs[j]->isResumed()))
1240 break;
1241
1242 std::string info = ct->item.toString();
1243
1244 if (ct->is_craft)
1245 info = "crafts";
1246
1247 if (ct->material.isValid())
1248 info = ct->material.toString() + " " + info;
1249 else if (ct->mat_mask.whole)
1250 info = bitfield_to_string(ct->mat_mask) + " " + info;
1251

Callers 1

process_constraintsFunction · 0.85

Calls 14

setJobResumedFunction · 0.85
isLiveMethod · 0.80
isResumedMethod · 0.80
goalCountMethod · 0.80
goalGapMethod · 0.80
curItemStockMethod · 0.80
isOptionEnabledFunction · 0.70
bitfield_to_stringFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected