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

Function orders_import

plugins/orders.cpp:516–911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

514}
515
516static command_result orders_import(color_ostream &out, Json::Value &orders)
517{
518 std::map<int32_t, int32_t> id_mapping;
519 for (auto it : orders)
520 {
521 id_mapping[it["id"].asInt()] = world->manager_orders.manager_order_next_id;
522 world->manager_orders.manager_order_next_id++;
523 }
524
525 for (auto & it : orders)
526 {
527 df::manager_order *order = new df::manager_order();
528
529 order->id = id_mapping.at(it["id"].asInt());
530
531 if (!find_enum_item(&order->job_type, it["job"].asString()))
532 {
533 delete order;
534
535 out << COLOR_LIGHTRED << "Invalid job type for imported manager order: " << it["job"].asString() << std::endl;
536
537 return CR_FAILURE;
538 }
539
540 if (it.isMember("reaction"))
541 {
542 order->reaction_name = it["reaction"].asString();
543 }
544
545 if (it.isMember("item_type"))
546 {
547 if (!find_enum_item(&order->item_type, it["item_type"].asString()) || order->item_type == item_type::NONE)
548 {
549 delete order;
550
551 out << COLOR_LIGHTRED << "Invalid item type for imported manager order: " << it["item_type"].asString() << std::endl;
552
553 return CR_FAILURE;
554 }
555 }
556 if (it.isMember("item_subtype"))
557 {
558 df::itemdef *def = get_itemdef(out, order->item_type == item_type::NONE ? ENUM_ATTR(job_type, item, order->job_type) : order->item_type, it["item_subtype"].asString());
559
560 if (def)
561 {
562 order->item_subtype = def->subtype;
563 }
564 else
565 {
566 out << COLOR_LIGHTRED << "Invalid item subtype for imported manager order: " << enum_item_key(order->item_type) << ":" << it["item_subtype"].asString() << std::endl;
567
568 delete order;
569
570 return CR_FAILURE;
571 }
572 }
573

Callers 1

orders_import_commandFunction · 0.85

Calls 11

find_enum_itemFunction · 0.85
get_itemdefFunction · 0.85
enum_item_keyFunction · 0.85
json_array_to_bitfieldFunction · 0.85
findFunction · 0.50
findMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected