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

Function push_constraint

plugins/workflow.cpp:1353–1417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1351}
1352
1353static void push_constraint(lua_State *L, ItemConstraint *cv)
1354{
1355 lua_newtable(L);
1356 int ctable = lua_gettop(L);
1357
1358 Lua::SetField(L, -cv->config.fake_df_id(), ctable, "id");
1359 Lua::SetField(L, cv->config.val(), ctable, "token");
1360
1361 // Constraint key
1362
1363 Lua::SetField(L, cv->item.type, ctable, "item_type");
1364 Lua::SetField(L, cv->item.subtype, ctable, "item_subtype");
1365
1366 Lua::SetField(L, cv->is_craft, ctable, "is_craft");
1367
1368 lua_getglobal(L, "copyall");
1369 Lua::PushDFObject(L, &cv->mat_mask);
1370 lua_call(L, 1, 1);
1371 lua_setfield(L, -2, "mat_mask");
1372
1373 Lua::SetField(L, cv->material.type, ctable, "mat_type");
1374 Lua::SetField(L, cv->material.index, ctable, "mat_index");
1375
1376 Lua::SetField(L, (int)cv->min_quality, ctable, "min_quality");
1377 Lua::SetField(L, (bool)cv->is_local, ctable, "is_local");
1378
1379 // Constraint value
1380
1381 Lua::SetField(L, cv->goalByCount(), ctable, "goal_by_count");
1382 Lua::SetField(L, cv->goalCount(), ctable, "goal_value");
1383 Lua::SetField(L, cv->goalGap(), ctable, "goal_gap");
1384
1385 Lua::SetField(L, cv->item_amount, ctable, "cur_amount");
1386 Lua::SetField(L, cv->item_count, ctable, "cur_count");
1387 Lua::SetField(L, cv->item_inuse_amount, ctable, "cur_in_use_amount");
1388 Lua::SetField(L, cv->item_inuse_count, ctable, "cur_in_use_count");
1389
1390 // Current state value
1391
1392 if (cv->request_resume)
1393 Lua::SetField(L, "resume", ctable, "request");
1394 else if (cv->request_suspend)
1395 Lua::SetField(L, "suspend", ctable, "request");
1396
1397 lua_newtable(L);
1398
1399 bool resumed = false, want_resumed = false;
1400
1401 for (size_t i = 0, j = 0; i < cv->jobs.size(); i++)
1402 {
1403 if (!cv->jobs[i]->isLive()) continue;
1404 Lua::PushDFObject(L, cv->jobs[i]->actual_job);
1405 lua_rawseti(L, -2, ++j);
1406
1407 if (cv->jobs[i]->want_resumed) {
1408 want_resumed = true;
1409 resumed = resumed || cv->jobs[i]->isActuallyResumed();
1410 }

Callers 3

listConstraintsFunction · 0.85
findConstraintFunction · 0.85
setConstraintFunction · 0.85

Calls 13

lua_gettopFunction · 0.85
SetFieldFunction · 0.85
lua_getglobalFunction · 0.85
PushDFObjectFunction · 0.85
lua_setfieldFunction · 0.85
lua_rawsetiFunction · 0.85
fake_df_idMethod · 0.80
goalByCountMethod · 0.80
goalCountMethod · 0.80
goalGapMethod · 0.80
isLiveMethod · 0.80
isActuallyResumedMethod · 0.80

Tested by

no test coverage detected