| 1387 | } |
| 1388 | |
| 1389 | static int32_t get_sell_request_multiplier(df::item *item, |
| 1390 | const df::historical_entity::T_resources &resources, const vector<int32_t> *prices) |
| 1391 | { |
| 1392 | CHECK_NULL_POINTER(item); |
| 1393 | CHECK_NULL_POINTER(prices); |
| 1394 | static const df::dfhack_material_category silk_cat(df::dfhack_material_category::mask_silk); |
| 1395 | static const df::dfhack_material_category yarn_cat(df::dfhack_material_category::mask_yarn); |
| 1396 | static const df::dfhack_material_category leather_cat(df::dfhack_material_category::mask_leather); |
| 1397 | |
| 1398 | int16_t item_type = item->getType(); |
| 1399 | int16_t item_subtype = item->getSubtype(); |
| 1400 | int16_t mat_type = item->getMaterial(); |
| 1401 | int32_t mat_subtype = item->getMaterialIndex(); |
| 1402 | |
| 1403 | MaterialInfo mi(mat_type, mat_subtype); |
| 1404 | |
| 1405 | #define TRY_RETURN_PRICE(res, cat) \ |
| 1406 | if (int32_t price = get_price(resources.res, mat_subtype, \ |
| 1407 | prices[entity_sell_category::cat]); price != -1) return price |
| 1408 | #define TRY_RETURN_PRICE_2(mat_res, gloss_res, cat) \ |
| 1409 | if (int32_t price = get_price(resources.mat_res, mat_type, \ |
| 1410 | resources.gloss_res, mat_subtype, \ |
| 1411 | prices[entity_sell_category::cat]); price != -1) return price |
| 1412 | |
| 1413 | switch (item_type) |
| 1414 | { using namespace df::enums::item_type; |
| 1415 | case BAR: |
| 1416 | if (mi.mode == MaterialInfo::Inorganic) |
| 1417 | TRY_RETURN_PRICE(metals, MetalBars); |
| 1418 | break; |
| 1419 | case SMALLGEM: |
| 1420 | if (mi.mode == MaterialInfo::Inorganic) |
| 1421 | TRY_RETURN_PRICE(gems, SmallCutGems); |
| 1422 | break; |
| 1423 | case BLOCKS: |
| 1424 | if (mi.mode == MaterialInfo::Inorganic) |
| 1425 | TRY_RETURN_PRICE(stones, StoneBlocks); |
| 1426 | break; |
| 1427 | case ROUGH: |
| 1428 | TRY_RETURN_PRICE_2(misc_mat.glass.mat_type, misc_mat.glass.mat_index, Glass); |
| 1429 | break; |
| 1430 | case BOULDER: |
| 1431 | TRY_RETURN_PRICE(stones, Stone); |
| 1432 | TRY_RETURN_PRICE_2(misc_mat.clay.mat_type, misc_mat.clay.mat_index, Clay); |
| 1433 | break; |
| 1434 | case WOOD: |
| 1435 | TRY_RETURN_PRICE_2(organic.wood.mat_type, organic.wood.mat_index, Wood); |
| 1436 | break; |
| 1437 | case CHAIN: |
| 1438 | if (mi.mode == MaterialInfo::Plant) |
| 1439 | TRY_RETURN_PRICE_2(organic.fiber.mat_type, organic.fiber.mat_index, RopesPlant); |
| 1440 | if (mi.matches(silk_cat)) |
| 1441 | TRY_RETURN_PRICE_2(organic.silk.mat_type, organic.silk.mat_index, RopesSilk); |
| 1442 | if (mi.matches(yarn_cat)) |
| 1443 | TRY_RETURN_PRICE_2(organic.wool.mat_type, organic.wool.mat_index, RopesYarn); |
| 1444 | break; |
| 1445 | case FLASK: |
| 1446 | TRY_RETURN_PRICE_2(misc_mat.flasks.mat_type, misc_mat.flasks.mat_index, FlasksWaterskins); |