Example #1
0
static void guess_job_material(df::job *job, MaterialInfo &mat, df::dfhack_material_category &mat_mask)
{
    using namespace df::enums::job_type;

    if (job->job_type == PrepareMeal)
        mat.decode(-1);
    else
        mat.decode(job);

    mat_mask.whole = job->material_category.whole;

    // Material from the job enum
    const char *job_material = ENUM_ATTR(job_type, material, job->job_type);
    if (job_material)
    {
        MaterialInfo info;
        if (info.findBuiltin(job_material))
            mat = info;
        else
            parseJobMaterialCategory(&mat_mask, job_material);
    }

    // Material from the job reagent
    if (!mat.isValid() && !job->job_items.empty() &&
        (job->job_items.size() == 1 ||
         job->job_items[0]->item_type == item_type::PLANT))
    {
        mat.decode(job->job_items[0]);

        switch (job->job_items[0]->item_type)
        {
        case item_type::WOOD:
            mat_mask.bits.wood = mat_mask.bits.wood2 = true;
            break;

        default:
            break;
        }
    }
}
Example #2
0
int Items::getItemBaseValue(int16_t item_type, int16_t item_subtype, int16_t mat_type, int32_t mat_subtype)
{
    int value = 0;
    switch (item_type)
    {
    case item_type::BAR:
    case item_type::SMALLGEM:
    case item_type::BLOCKS:
    case item_type::SKIN_TANNED:
        value = 5;
        break;

    case item_type::ROUGH:
    case item_type::BOULDER:
    case item_type::WOOD:
        value = 3;
        break;

    case item_type::DOOR:
    case item_type::FLOODGATE:
    case item_type::BED:
    case item_type::CHAIR:
    case item_type::CHAIN:
    case item_type::FLASK:
    case item_type::GOBLET:
    case item_type::INSTRUMENT:
    case item_type::TOY:
    case item_type::CAGE:
    case item_type::BARREL:
    case item_type::BUCKET:
    case item_type::ANIMALTRAP:
    case item_type::TABLE:
    case item_type::COFFIN:
    case item_type::BOX:
    case item_type::BIN:
    case item_type::ARMORSTAND:
    case item_type::WEAPONRACK:
    case item_type::CABINET:
    case item_type::FIGURINE:
    case item_type::AMULET:
    case item_type::SCEPTER:
    case item_type::CROWN:
    case item_type::RING:
    case item_type::EARRING:
    case item_type::BRACELET:
    case item_type::GEM:
    case item_type::ANVIL:
    case item_type::TOTEM:
    case item_type::BACKPACK:
    case item_type::QUIVER:
    case item_type::BALLISTAARROWHEAD:
    case item_type::PIPE_SECTION:
    case item_type::HATCH_COVER:
    case item_type::GRATE:
    case item_type::QUERN:
    case item_type::MILLSTONE:
    case item_type::SPLINT:
    case item_type::CRUTCH:
    case item_type::SLAB:
    case item_type::BOOK:
        value = 10;
        break;

    case item_type::WINDOW:
    case item_type::STATUE:
        value = 25;
        break;

    case item_type::CORPSE:
    case item_type::CORPSEPIECE:
    case item_type::REMAINS:
        return 0;

    case item_type::WEAPON:
        if (size_t(item_subtype) < world->raws.itemdefs.weapons.size())
            value = world->raws.itemdefs.weapons[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::ARMOR:
        if (size_t(item_subtype) < world->raws.itemdefs.armor.size())
            value = world->raws.itemdefs.armor[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::SHOES:
        if (size_t(item_subtype) < world->raws.itemdefs.shoes.size())
            value = world->raws.itemdefs.shoes[item_subtype]->value;
        else
            value = 5;
        break;

    case item_type::SHIELD:
        if (size_t(item_subtype) < world->raws.itemdefs.shields.size())
            value = world->raws.itemdefs.shields[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::HELM:
        if (size_t(item_subtype) < world->raws.itemdefs.helms.size())
            value = world->raws.itemdefs.helms[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::GLOVES:
        if (size_t(item_subtype) < world->raws.itemdefs.gloves.size())
            value = world->raws.itemdefs.gloves[item_subtype]->value;
        else
            value = 5;
        break;

    case item_type::AMMO:
        if (size_t(item_subtype) < world->raws.itemdefs.ammo.size())
            value = world->raws.itemdefs.ammo[item_subtype]->value;
        else
            value = 1;
        break;

    case item_type::MEAT:
    case item_type::PLANT:
    case item_type::PLANT_GROWTH:
    case item_type::CHEESE:
        value = 2;
        break;

    case item_type::FISH:
    case item_type::FISH_RAW:
    case item_type::EGG:
        value = 2;
        if (size_t(mat_type) < world->raws.creatures.all.size())
        {
            auto creature = world->raws.creatures.all[mat_type];
            if (size_t(mat_subtype) < creature->caste.size())
            {
                auto caste = creature->caste[mat_subtype];
                mat_type = caste->misc.bone_mat;
                mat_subtype = caste->misc.bone_matidx;
            }
        }
        break;

    case item_type::VERMIN:
        value = 0;
        if (size_t(mat_type) < world->raws.creatures.all.size())
        {
            auto creature = world->raws.creatures.all[mat_type];
            if (size_t(mat_subtype) < creature->caste.size())
                value = creature->caste[mat_subtype]->misc.petvalue;
        }
        value /= 2;
        if (!value)
                return 1;
        return value;

    case item_type::PET:
        if (size_t(mat_type) < world->raws.creatures.all.size())
        {
            auto creature = world->raws.creatures.all[mat_type];
            if (size_t(mat_subtype) < creature->caste.size())
                return creature->caste[mat_subtype]->misc.petvalue;
        }
        return 0;

    case item_type::SEEDS:
    case item_type::DRINK:
    case item_type::POWDER_MISC:
    case item_type::LIQUID_MISC:
    case item_type::COIN:
    case item_type::GLOB:
    case item_type::ORTHOPEDIC_CAST:
        value = 1;
        break;

    case item_type::THREAD:
        value = 6;
        break;

    case item_type::CLOTH:
        value = 7;
        break;

    case item_type::PANTS:
        if (size_t(item_subtype) < world->raws.itemdefs.pants.size())
            value = world->raws.itemdefs.pants[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::CATAPULTPARTS:
    case item_type::BALLISTAPARTS:
    case item_type::TRAPPARTS:
        value = 30;
        break;

    case item_type::SIEGEAMMO:
    case item_type::TRACTION_BENCH:
        value = 20;
        break;

    case item_type::TRAPCOMP:
        if (size_t(item_subtype) < world->raws.itemdefs.trapcomps.size())
            value = world->raws.itemdefs.trapcomps[item_subtype]->value;
        else
            value = 10;
        break;

    case item_type::FOOD:
        return 10;

//  case item_type::ROCK:
    default:
        return 0;

    case item_type::TOOL:
        if (size_t(item_subtype) < world->raws.itemdefs.tools.size())
            value = world->raws.itemdefs.tools[item_subtype]->value;
        else
            value = 10;
        break;
    }

    MaterialInfo mat;
    if (mat.decode(mat_type, mat_subtype))
        value *= mat.material->material_value;
    return value;
}