2012-11-12 07:38:29 -07:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2010-05-02 03:27:16 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Error.h"
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "MemAccess.h"
|
|
|
|
#include "MiscUtils.h"
|
|
|
|
#include "Types.h"
|
|
|
|
#include "VersionInfo.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <map>
|
2014-07-03 08:36:55 -06:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2011-07-24 22:35:50 -06:00
|
|
|
#include <set>
|
2011-04-10 02:19:15 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "ModuleFactory.h"
|
2023-06-29 20:36:05 -06:00
|
|
|
#include "modules/Job.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "modules/MapCache.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Units.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/body_part_raw.h"
|
|
|
|
#include "df/body_part_template_flags.h"
|
2012-04-12 08:37:27 -06:00
|
|
|
#include "df/building.h"
|
2012-05-18 07:05:29 -06:00
|
|
|
#include "df/building_actual.h"
|
2023-06-29 20:36:05 -06:00
|
|
|
#include "df/building_tradedepotst.h"
|
2023-07-04 02:53:45 -06:00
|
|
|
#include "df/builtin_mats.h"
|
2023-07-03 19:05:30 -06:00
|
|
|
#include "df/caravan_state.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/caste_raw.h"
|
|
|
|
#include "df/creature_raw.h"
|
2023-07-04 02:53:45 -06:00
|
|
|
#include "df/dfhack_material_category.h"
|
2023-07-03 19:45:33 -06:00
|
|
|
#include "df/entity_buy_prices.h"
|
|
|
|
#include "df/entity_buy_requests.h"
|
2023-07-04 02:53:45 -06:00
|
|
|
#include "df/entity_sell_category.h"
|
2023-07-03 19:45:33 -06:00
|
|
|
#include "df/entity_sell_prices.h"
|
2023-07-03 19:05:30 -06:00
|
|
|
#include "df/entity_raw.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/general_ref.h"
|
|
|
|
#include "df/general_ref_building_holderst.h"
|
|
|
|
#include "df/general_ref_contained_in_itemst.h"
|
|
|
|
#include "df/general_ref_contains_itemst.h"
|
|
|
|
#include "df/general_ref_projectile.h"
|
|
|
|
#include "df/general_ref_unit_itemownerst.h"
|
|
|
|
#include "df/general_ref_unit_holderst.h"
|
|
|
|
#include "df/historical_entity.h"
|
|
|
|
#include "df/item.h"
|
2020-01-25 04:43:02 -07:00
|
|
|
#include "df/item_bookst.h"
|
|
|
|
#include "df/item_toolst.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/item_type.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
#include "df/itemdef_ammost.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/itemdef_armorst.h"
|
|
|
|
#include "df/itemdef_foodst.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
#include "df/itemdef_glovesst.h"
|
|
|
|
#include "df/itemdef_helmst.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/itemdef_instrumentst.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
#include "df/itemdef_pantsst.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/itemdef_shieldst.h"
|
|
|
|
#include "df/itemdef_shoesst.h"
|
|
|
|
#include "df/itemdef_siegeammost.h"
|
|
|
|
#include "df/itemdef_toolst.h"
|
|
|
|
#include "df/itemdef_toyst.h"
|
|
|
|
#include "df/itemdef_trapcompst.h"
|
|
|
|
#include "df/itemdef_weaponst.h"
|
2020-01-25 04:43:02 -07:00
|
|
|
#include "df/itemimprovement.h"
|
|
|
|
#include "df/itemimprovement_pagesst.h"
|
|
|
|
#include "df/itemimprovement_writingst.h"
|
2012-01-09 05:20:17 -07:00
|
|
|
#include "df/job_item.h"
|
2018-05-12 09:51:36 -06:00
|
|
|
#include "df/mandate.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/map_block.h"
|
2012-09-12 08:17:42 -06:00
|
|
|
#include "df/proj_itemst.h"
|
|
|
|
#include "df/proj_list_link.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/reaction_product_itemst.h"
|
|
|
|
#include "df/tool_uses.h"
|
|
|
|
#include "df/trapcomp_flags.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/plotinfost.h"
|
2012-05-15 04:01:59 -06:00
|
|
|
#include "df/unit.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/unit_inventory_item.h"
|
2018-05-12 12:49:30 -06:00
|
|
|
#include "df/vehicle.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/vermin.h"
|
2022-12-16 12:13:30 -07:00
|
|
|
#include "df/viewscreen.h"
|
2014-07-03 08:36:55 -06:00
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/world_site.h"
|
2020-01-25 04:43:02 -07:00
|
|
|
#include "df/written_content.h"
|
2012-05-15 04:01:59 -06:00
|
|
|
|
2010-05-02 03:27:16 -06:00
|
|
|
using namespace DFHack;
|
2012-01-09 05:20:17 -07:00
|
|
|
using namespace df::enums;
|
2012-01-16 21:12:58 -07:00
|
|
|
using df::global::world;
|
2023-01-05 18:11:01 -07:00
|
|
|
using df::global::plotinfo;
|
2012-05-20 11:57:45 -06:00
|
|
|
using df::global::ui_selected_unit;
|
2012-09-12 08:17:42 -06:00
|
|
|
using df::global::proj_next_id;
|
2012-05-15 04:01:59 -06:00
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
#define ITEMDEF_VECTORS \
|
2012-01-15 04:39:20 -07:00
|
|
|
ITEM(WEAPON, weapons, itemdef_weaponst) \
|
|
|
|
ITEM(TRAPCOMP, trapcomps, itemdef_trapcompst) \
|
|
|
|
ITEM(TOY, toys, itemdef_toyst) \
|
|
|
|
ITEM(TOOL, tools, itemdef_toolst) \
|
|
|
|
ITEM(INSTRUMENT, instruments, itemdef_instrumentst) \
|
|
|
|
ITEM(ARMOR, armor, itemdef_armorst) \
|
|
|
|
ITEM(AMMO, ammo, itemdef_ammost) \
|
|
|
|
ITEM(SIEGEAMMO, siege_ammo, itemdef_siegeammost) \
|
|
|
|
ITEM(GLOVES, gloves, itemdef_glovesst) \
|
|
|
|
ITEM(SHOES, shoes, itemdef_shoesst) \
|
|
|
|
ITEM(SHIELD, shields, itemdef_shieldst) \
|
|
|
|
ITEM(HELM, helms, itemdef_helmst) \
|
|
|
|
ITEM(PANTS, pants, itemdef_pantsst) \
|
|
|
|
ITEM(FOOD, food, itemdef_foodst)
|
2012-01-09 05:20:17 -07:00
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
int Items::getSubtypeCount(df::item_type itype)
|
2012-01-09 05:20:17 -07:00
|
|
|
{
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
|
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
switch (itype) {
|
|
|
|
#define ITEM(type,vec,tclass) \
|
|
|
|
case type: \
|
|
|
|
return defs.vec.size();
|
|
|
|
ITEMDEF_VECTORS
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
df::itemdef *Items::getSubtypeDef(df::item_type itype, int subtype)
|
|
|
|
{
|
|
|
|
using namespace df::enums::item_type;
|
2012-01-09 05:20:17 -07:00
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
|
|
|
|
|
|
|
|
switch (itype) {
|
2012-01-15 04:39:20 -07:00
|
|
|
#define ITEM(type,vec,tclass) \
|
2012-01-09 05:20:17 -07:00
|
|
|
case type: \
|
2012-10-20 07:06:33 -06:00
|
|
|
return vector_get(defs.vec, subtype);
|
2012-01-09 05:20:17 -07:00
|
|
|
ITEMDEF_VECTORS
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
default:
|
2012-10-20 07:06:33 -06:00
|
|
|
return NULL;
|
2012-01-09 05:20:17 -07:00
|
|
|
}
|
2012-10-20 07:06:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemTypeInfo::decode(df::item_type type_, int16_t subtype_)
|
|
|
|
{
|
|
|
|
type = type_;
|
|
|
|
subtype = subtype_;
|
|
|
|
custom = Items::getSubtypeDef(type_, subtype_);
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
return isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemTypeInfo::decode(df::item *ptr)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
|
|
|
return decode(item_type::NONE);
|
|
|
|
else
|
|
|
|
return decode(ptr->getType(), ptr->getSubtype());
|
|
|
|
}
|
|
|
|
|
2012-01-15 04:39:20 -07:00
|
|
|
std::string ItemTypeInfo::getToken()
|
2012-01-09 05:20:17 -07:00
|
|
|
{
|
|
|
|
std::string rv = ENUM_KEY_STR(item_type, type);
|
|
|
|
if (custom)
|
|
|
|
rv += ":" + custom->id;
|
2020-10-09 10:45:49 -06:00
|
|
|
else if (subtype != -1 && type != item_type::PLANT_GROWTH)
|
2012-01-09 05:20:17 -07:00
|
|
|
rv += stl_sprintf(":%d", subtype);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-01-15 04:39:20 -07:00
|
|
|
std::string ItemTypeInfo::toString()
|
|
|
|
{
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
#define ITEM(type,vec,tclass) \
|
|
|
|
case type: \
|
|
|
|
if (VIRTUAL_CAST_VAR(cv, df::tclass, custom)) \
|
|
|
|
return cv->name;
|
|
|
|
ITEMDEF_VECTORS
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
const char *name = ENUM_ATTR(item_type, caption, type);
|
|
|
|
if (name)
|
|
|
|
return name;
|
|
|
|
|
2012-01-15 04:39:20 -07:00
|
|
|
return toLower(ENUM_KEY_STR(item_type, type));
|
|
|
|
}
|
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
bool ItemTypeInfo::find(const std::string &token)
|
|
|
|
{
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
std::vector<std::string> items;
|
|
|
|
split_string(&items, token, ":");
|
|
|
|
|
|
|
|
type = NONE;
|
|
|
|
subtype = -1;
|
|
|
|
custom = NULL;
|
|
|
|
|
|
|
|
if (items.size() < 1 || items.size() > 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (items[0] == "NONE")
|
|
|
|
return true;
|
|
|
|
|
2012-03-15 10:46:08 -06:00
|
|
|
if (!find_enum_item(&type, items[0]))
|
|
|
|
return false;
|
2012-01-09 05:20:17 -07:00
|
|
|
if (type == NONE)
|
|
|
|
return false;
|
|
|
|
if (items.size() == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
|
|
|
|
|
|
|
|
switch (type) {
|
2012-01-15 04:39:20 -07:00
|
|
|
#define ITEM(type,vec,tclass) \
|
2012-01-09 05:20:17 -07:00
|
|
|
case type: \
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < defs.vec.size(); i++) { \
|
2012-01-09 05:20:17 -07:00
|
|
|
if (defs.vec[i]->id == items[1]) { \
|
|
|
|
subtype = i; custom = defs.vec[i]; return true; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
ITEMDEF_VECTORS
|
|
|
|
#undef ITEM
|
|
|
|
|
|
|
|
default:
|
2014-05-22 07:18:01 -06:00
|
|
|
if (items[1] == "NONE")
|
|
|
|
return true;
|
2012-01-09 05:20:17 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (subtype >= 0);
|
|
|
|
}
|
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
bool Items::isCasteMaterial(df::item_type itype)
|
|
|
|
{
|
|
|
|
return ENUM_ATTR(item_type, is_caste_mat, itype);
|
|
|
|
}
|
|
|
|
|
2012-10-20 11:01:22 -06:00
|
|
|
bool ItemTypeInfo::matches(df::job_item_vector_id vec_id)
|
|
|
|
{
|
|
|
|
auto other_id = ENUM_ATTR(job_item_vector_id, other, vec_id);
|
|
|
|
|
|
|
|
auto explicit_item = ENUM_ATTR(items_other_id, item, other_id);
|
|
|
|
if (explicit_item != item_type::NONE && type != explicit_item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto generic_item = ENUM_ATTR(items_other_id, generic_item, other_id);
|
|
|
|
if (generic_item.size > 0)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < generic_item.size; i++)
|
|
|
|
if (generic_item.items[i] == type)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-12 23:44:38 -07:00
|
|
|
bool ItemTypeInfo::matches(const df::job_item &item, MaterialInfo *mat,
|
|
|
|
bool skip_vector, df::item_type itype)
|
2012-01-09 05:20:17 -07:00
|
|
|
{
|
|
|
|
using namespace df::enums::item_type;
|
|
|
|
|
|
|
|
if (!isValid())
|
2020-11-12 23:44:38 -07:00
|
|
|
return mat ? mat->matches(item, itype) : false;
|
2012-01-09 05:20:17 -07:00
|
|
|
|
2012-10-20 07:06:33 -06:00
|
|
|
if (Items::isCasteMaterial(type) && mat && !mat->isNone())
|
|
|
|
return false;
|
|
|
|
|
2012-10-20 11:01:22 -06:00
|
|
|
if (!skip_vector && !matches(item.vector_id))
|
|
|
|
return false;
|
|
|
|
|
2012-10-20 11:16:00 -06:00
|
|
|
df::job_item_flags1 ok1, mask1, item_ok1, item_mask1, xmask1;
|
2012-10-20 10:31:45 -06:00
|
|
|
df::job_item_flags2 ok2, mask2, item_ok2, item_mask2, xmask2;
|
2012-01-09 05:20:17 -07:00
|
|
|
df::job_item_flags3 ok3, mask3, item_ok3, item_mask3;
|
|
|
|
|
2012-10-20 11:16:00 -06:00
|
|
|
ok1.whole = mask1.whole = item_ok1.whole = item_mask1.whole = xmask1.whole = 0;
|
2012-10-20 10:31:45 -06:00
|
|
|
ok2.whole = mask2.whole = item_ok2.whole = item_mask2.whole = xmask2.whole = 0;
|
2012-01-09 05:20:17 -07:00
|
|
|
ok3.whole = mask3.whole = item_ok3.whole = item_mask3.whole = 0;
|
|
|
|
|
|
|
|
if (mat) {
|
|
|
|
mat->getMatchBits(ok1, mask1);
|
|
|
|
mat->getMatchBits(ok2, mask2);
|
|
|
|
mat->getMatchBits(ok3, mask3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OK(id,name) item_ok##id.bits.name = true
|
|
|
|
#define RQ(id,name) item_mask##id.bits.name = true
|
|
|
|
|
|
|
|
// Set up the flag mask
|
|
|
|
|
|
|
|
RQ(1,millable); RQ(1,sharpenable); RQ(1,distillable); RQ(1,processable); RQ(1,bag);
|
|
|
|
RQ(1,extract_bearing_plant); RQ(1,extract_bearing_fish); RQ(1,extract_bearing_vermin);
|
|
|
|
RQ(1,processable_to_vial); RQ(1,processable_to_bag); RQ(1,processable_to_barrel);
|
|
|
|
RQ(1,solid); RQ(1,tameable_vermin); RQ(1,sand_bearing); RQ(1,milk); RQ(1,milkable);
|
2015-10-25 19:19:41 -06:00
|
|
|
RQ(1,not_bin); RQ(1,lye_bearing); RQ(1, undisturbed);
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
RQ(2,dye); RQ(2,dyeable); RQ(2,dyed); RQ(2,glass_making); RQ(2,screw);
|
2012-10-20 10:31:45 -06:00
|
|
|
RQ(2,building_material); RQ(2,fire_safe); RQ(2,magma_safe);
|
2012-01-09 05:20:17 -07:00
|
|
|
RQ(2,totemable); RQ(2,plaster_containing); RQ(2,body_part); RQ(2,lye_milk_free);
|
|
|
|
RQ(2,blunt); RQ(2,unengraved); RQ(2,hair_wool);
|
|
|
|
|
|
|
|
RQ(3,any_raw_material); RQ(3,non_pressed); RQ(3,food_storage);
|
|
|
|
|
2012-10-20 10:31:45 -06:00
|
|
|
// only checked if boulder
|
|
|
|
|
|
|
|
xmask2.bits.non_economic = true;
|
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
// Compute the ok mask
|
|
|
|
|
|
|
|
OK(1,solid);
|
|
|
|
OK(1,not_bin);
|
|
|
|
|
|
|
|
// TODO: furniture, ammo, finished good, craft
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PLANT:
|
|
|
|
OK(1,millable); OK(1,processable);
|
|
|
|
OK(1,distillable);
|
|
|
|
OK(1,extract_bearing_plant);
|
|
|
|
OK(1,processable_to_vial);
|
|
|
|
OK(1,processable_to_bag);
|
|
|
|
OK(1,processable_to_barrel);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOULDER:
|
|
|
|
OK(1,sharpenable);
|
2012-10-20 10:31:45 -06:00
|
|
|
xmask2.bits.non_economic = false;
|
2012-01-09 05:20:17 -07:00
|
|
|
case BAR:
|
|
|
|
OK(3,any_raw_material);
|
|
|
|
case BLOCKS:
|
|
|
|
case WOOD:
|
|
|
|
OK(2,building_material);
|
|
|
|
OK(2,fire_safe); OK(2,magma_safe);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERMIN:
|
|
|
|
OK(1,extract_bearing_fish);
|
|
|
|
OK(1,extract_bearing_vermin);
|
|
|
|
OK(1,tameable_vermin);
|
|
|
|
OK(1,milkable);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRINK:
|
|
|
|
item_ok1.bits.solid = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ROUGH:
|
|
|
|
OK(2,glass_making);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANIMALTRAP:
|
|
|
|
case CAGE:
|
|
|
|
OK(1,milk);
|
|
|
|
OK(1,milkable);
|
2012-10-20 11:16:00 -06:00
|
|
|
xmask1.bits.cookable = true;
|
2012-01-09 05:20:17 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUCKET:
|
2020-09-29 01:22:16 -06:00
|
|
|
OK(2,lye_milk_free);
|
2012-01-09 05:20:17 -07:00
|
|
|
case FLASK:
|
|
|
|
OK(1,milk);
|
2012-10-20 11:16:00 -06:00
|
|
|
xmask1.bits.cookable = true;
|
2012-01-09 05:20:17 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOL:
|
|
|
|
OK(1,lye_bearing);
|
|
|
|
OK(1,milk);
|
|
|
|
OK(2,lye_milk_free);
|
|
|
|
OK(2,blunt);
|
2012-10-20 11:16:00 -06:00
|
|
|
xmask1.bits.cookable = true;
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
if (VIRTUAL_CAST_VAR(def, df::itemdef_toolst, custom)) {
|
2012-01-23 18:40:02 -07:00
|
|
|
df::tool_uses key(tool_uses::FOOD_STORAGE);
|
2012-01-09 05:20:17 -07:00
|
|
|
if (linear_index(def->tool_use, key) >= 0)
|
|
|
|
OK(3,food_storage);
|
|
|
|
} else {
|
|
|
|
OK(3,food_storage);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BARREL:
|
|
|
|
OK(1,lye_bearing);
|
|
|
|
OK(1,milk);
|
|
|
|
OK(2,lye_milk_free);
|
|
|
|
OK(3,food_storage);
|
2012-10-20 11:16:00 -06:00
|
|
|
xmask1.bits.cookable = true;
|
2012-01-09 05:20:17 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-03 08:12:30 -06:00
|
|
|
// TODO: split this into BOX and BAG
|
2012-01-09 05:20:17 -07:00
|
|
|
case BOX:
|
|
|
|
OK(1,bag); OK(1,sand_bearing); OK(1,milk);
|
|
|
|
OK(2,dye); OK(2,plaster_containing);
|
2012-10-20 11:16:00 -06:00
|
|
|
xmask1.bits.cookable = true;
|
2012-01-09 05:20:17 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BIN:
|
|
|
|
item_ok1.bits.not_bin = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIQUID_MISC:
|
|
|
|
item_ok1.bits.solid = false;
|
|
|
|
OK(1,milk);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POWDER_MISC:
|
|
|
|
OK(2,dye);
|
|
|
|
case GLOB:
|
|
|
|
OK(3,any_raw_material);
|
|
|
|
OK(3,non_pressed);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case THREAD:
|
2015-10-25 19:19:41 -06:00
|
|
|
OK(1,undisturbed);
|
2012-01-09 05:20:17 -07:00
|
|
|
case CLOTH:
|
|
|
|
OK(2,dyeable); OK(2,dyed);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WEAPON:
|
|
|
|
case AMMO:
|
|
|
|
case ROCK:
|
|
|
|
OK(2,blunt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRAPCOMP:
|
|
|
|
if (VIRTUAL_CAST_VAR(def, df::itemdef_trapcompst, custom)) {
|
|
|
|
if (def->flags.is_set(trapcomp_flags::IS_SCREW))
|
|
|
|
OK(2,screw);
|
|
|
|
} else {
|
|
|
|
OK(2,screw);
|
|
|
|
}
|
|
|
|
OK(2,blunt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CORPSE:
|
|
|
|
case CORPSEPIECE:
|
|
|
|
OK(2,totemable);
|
|
|
|
OK(2,body_part);
|
|
|
|
OK(2,hair_wool);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAB:
|
|
|
|
OK(2,unengraved);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANVIL:
|
|
|
|
OK(2,fire_safe); OK(2,magma_safe);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((item_ok1.whole & ~item_mask1.whole) ||
|
|
|
|
(item_ok2.whole & ~item_mask2.whole) ||
|
|
|
|
(item_ok3.whole & ~item_mask3.whole))
|
2012-03-10 04:55:42 -07:00
|
|
|
Core::printerr("ItemTypeInfo.matches inconsistent\n");
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
#undef OK
|
|
|
|
#undef RQ
|
|
|
|
|
2012-10-20 11:16:00 -06:00
|
|
|
mask1.whole &= ~xmask1.whole;
|
2012-10-20 10:31:45 -06:00
|
|
|
mask2.whole &= ~xmask2.whole;
|
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
return bits_match(item.flags1.whole, ok1.whole, mask1.whole) &&
|
|
|
|
bits_match(item.flags2.whole, ok2.whole, mask2.whole) &&
|
|
|
|
bits_match(item.flags3.whole, ok3.whole, mask3.whole) &&
|
|
|
|
bits_match(item.flags1.whole, item_ok1.whole, item_mask1.whole) &&
|
|
|
|
bits_match(item.flags2.whole, item_ok2.whole, item_mask2.whole) &&
|
|
|
|
bits_match(item.flags3.whole, item_ok3.whole, item_mask3.whole);
|
|
|
|
}
|
|
|
|
|
2012-01-16 19:16:16 -07:00
|
|
|
df::item * Items::findItemByID(int32_t id)
|
2011-05-09 04:49:44 -06:00
|
|
|
{
|
|
|
|
if (id < 0)
|
|
|
|
return 0;
|
2012-01-16 21:12:58 -07:00
|
|
|
return df::item::find(id);
|
2010-05-02 02:35:23 -06:00
|
|
|
}
|
|
|
|
|
2012-01-16 19:16:16 -07:00
|
|
|
bool Items::copyItem(df::item * itembase, DFHack::dfh_item &item)
|
2010-05-02 02:35:23 -06:00
|
|
|
{
|
2011-10-24 20:48:06 -06:00
|
|
|
if(!itembase)
|
|
|
|
return false;
|
2012-01-16 19:16:16 -07:00
|
|
|
df::item * itreal = (df::item *) itembase;
|
2011-10-26 14:18:13 -06:00
|
|
|
item.origin = itembase;
|
2012-01-19 03:30:22 -07:00
|
|
|
item.x = itreal->pos.x;
|
|
|
|
item.y = itreal->pos.y;
|
|
|
|
item.z = itreal->pos.z;
|
2011-10-26 14:18:13 -06:00
|
|
|
item.id = itreal->id;
|
|
|
|
item.age = itreal->age;
|
|
|
|
item.flags = itreal->flags;
|
2012-11-16 14:35:34 -07:00
|
|
|
item.matdesc.item_type = itreal->getType();
|
|
|
|
item.matdesc.item_subtype = itreal->getSubtype();
|
|
|
|
item.matdesc.mat_type = itreal->getMaterial();
|
|
|
|
item.matdesc.mat_index = itreal->getMaterialIndex();
|
2011-10-24 20:48:06 -06:00
|
|
|
item.wear_level = itreal->getWear();
|
|
|
|
item.quality = itreal->getQuality();
|
|
|
|
item.quantity = itreal->getStackSize();
|
|
|
|
return true;
|
2010-05-02 02:35:23 -06:00
|
|
|
}
|
|
|
|
|
2012-05-03 01:47:04 -06:00
|
|
|
df::general_ref *Items::getGeneralRef(df::item *item, df::general_ref_type type)
|
2011-04-11 04:32:53 -06:00
|
|
|
{
|
2012-04-11 10:10:31 -06:00
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
return findRef(item->general_refs, type);
|
2012-05-03 01:47:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
df::specific_ref *Items::getSpecificRef(df::item *item, df::specific_ref_type type)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
return findRef(item->specific_refs, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
df::unit *Items::getOwner(df::item * item)
|
|
|
|
{
|
|
|
|
auto ref = getGeneralRef(item, general_ref_type::UNIT_ITEMOWNER);
|
2012-04-11 10:10:31 -06:00
|
|
|
|
2012-05-03 01:47:04 -06:00
|
|
|
return ref ? ref->getUnit() : NULL;
|
2011-05-12 10:30:42 -06:00
|
|
|
}
|
2011-04-11 04:32:53 -06:00
|
|
|
|
2012-04-11 10:10:31 -06:00
|
|
|
bool Items::setOwner(df::item *item, df::unit *unit)
|
2012-01-24 10:32:34 -07:00
|
|
|
{
|
2012-04-11 10:10:31 -06:00
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
for (int i = item->general_refs.size()-1; i >= 0; i--)
|
2012-01-24 10:32:34 -07:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
df::general_ref *ref = item->general_refs[i];
|
2012-04-11 10:10:31 -06:00
|
|
|
|
2014-04-23 07:23:34 -06:00
|
|
|
if (ref->getType() != general_ref_type::UNIT_ITEMOWNER)
|
2012-04-11 10:10:31 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (auto cur = ref->getUnit())
|
|
|
|
{
|
|
|
|
if (cur == unit)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
erase_from_vector(cur->owned_items, item->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete ref;
|
2012-11-12 07:27:58 -07:00
|
|
|
vector_erase_at(item->general_refs, i);
|
2012-01-24 10:32:34 -07:00
|
|
|
}
|
2012-04-11 10:10:31 -06:00
|
|
|
|
2012-04-12 00:54:53 -06:00
|
|
|
item->flags.bits.owned = false;
|
|
|
|
|
2012-04-11 10:10:31 -06:00
|
|
|
if (unit)
|
|
|
|
{
|
|
|
|
auto ref = df::allocate<df::general_ref_unit_itemownerst>();
|
|
|
|
if (!ref)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item->flags.bits.owned = true;
|
|
|
|
ref->unit_id = unit->id;
|
|
|
|
|
|
|
|
insert_into_vector(unit->owned_items, item->id);
|
2012-11-12 07:27:58 -07:00
|
|
|
item->general_refs.push_back(ref);
|
2012-04-11 10:10:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-01-24 10:32:34 -07:00
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
df::item *Items::getContainer(df::item * item)
|
2011-05-12 10:30:42 -06:00
|
|
|
{
|
2012-05-03 01:47:04 -06:00
|
|
|
auto ref = getGeneralRef(item, general_ref_type::CONTAINED_IN_ITEM);
|
2012-04-12 08:37:27 -06:00
|
|
|
|
2012-05-03 01:47:04 -06:00
|
|
|
return ref ? ref->getItem() : NULL;
|
2011-05-12 10:30:42 -06:00
|
|
|
}
|
2011-04-11 04:32:53 -06:00
|
|
|
|
2022-03-13 18:19:35 -06:00
|
|
|
void Items::getOuterContainerRef(df::specific_ref &spec_ref, df::item *item, bool init_ref)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
// Reverse-engineered from ambushing unit code
|
|
|
|
|
|
|
|
if (init_ref)
|
|
|
|
{
|
|
|
|
spec_ref.type = specific_ref_type::ITEM_GENERAL;
|
|
|
|
spec_ref.data.object = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->flags.bits.removed || !item->flags.bits.in_inventory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < item->general_refs.size(); i++)
|
|
|
|
{
|
|
|
|
auto g = item->general_refs[i];
|
|
|
|
switch (g->getType())
|
|
|
|
{
|
|
|
|
case general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
if (auto item2 = g->getItem())
|
|
|
|
return Items::getOuterContainerRef(spec_ref, item2);
|
|
|
|
break;
|
|
|
|
case general_ref_type::UNIT_HOLDER:
|
|
|
|
if (auto unit = g->getUnit())
|
|
|
|
return Units::getOuterContainerRef(spec_ref, unit);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto s = findRef(item->specific_refs, specific_ref_type::VERMIN_ESCAPED_PET);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
spec_ref.type = specific_ref_type::VERMIN_EVENT;
|
|
|
|
spec_ref.data.vermin = s->data.vermin;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
void Items::getContainedItems(df::item *item, std::vector<df::item*> *items)
|
2012-01-24 10:32:34 -07:00
|
|
|
{
|
2012-04-12 08:37:27 -06:00
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
items->clear();
|
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
for (size_t i = 0; i < item->general_refs.size(); i++)
|
2012-01-24 10:32:34 -07:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
df::general_ref *ref = item->general_refs[i];
|
2012-04-12 08:37:27 -06:00
|
|
|
if (ref->getType() != general_ref_type::CONTAINS_ITEM)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto child = ref->getItem();
|
|
|
|
if (child)
|
|
|
|
items->push_back(child);
|
2012-01-24 10:32:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 02:40:26 -06:00
|
|
|
df::building *Items::getHolderBuilding(df::item * item)
|
|
|
|
{
|
|
|
|
auto ref = getGeneralRef(item, general_ref_type::BUILDING_HOLDER);
|
|
|
|
|
|
|
|
return ref ? ref->getBuilding() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::unit *Items::getHolderUnit(df::item * item)
|
|
|
|
{
|
|
|
|
auto ref = getGeneralRef(item, general_ref_type::UNIT_HOLDER);
|
|
|
|
|
|
|
|
return ref ? ref->getUnit() : NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
df::coord Items::getPosition(df::item *item)
|
2011-05-12 10:30:42 -06:00
|
|
|
{
|
2012-04-12 08:37:27 -06:00
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
2012-05-17 09:56:55 -06:00
|
|
|
/* Function reverse-engineered from DF code. */
|
|
|
|
|
|
|
|
if (item->flags.bits.removed)
|
|
|
|
return df::coord();
|
|
|
|
|
|
|
|
if (item->flags.bits.in_inventory)
|
2012-04-12 08:37:27 -06:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
for (size_t i = 0; i < item->general_refs.size(); i++)
|
2012-04-12 08:37:27 -06:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
df::general_ref *ref = item->general_refs[i];
|
2012-04-12 08:37:27 -06:00
|
|
|
|
|
|
|
switch (ref->getType())
|
|
|
|
{
|
|
|
|
case general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
if (auto item2 = ref->getItem())
|
|
|
|
return getPosition(item2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case general_ref_type::UNIT_HOLDER:
|
|
|
|
if (auto unit = ref->getUnit())
|
2012-04-13 06:10:19 -06:00
|
|
|
return Units::getPosition(unit);
|
2012-04-12 08:37:27 -06:00
|
|
|
break;
|
|
|
|
|
2012-05-17 09:56:55 -06:00
|
|
|
/*case general_ref_type::BUILDING_HOLDER:
|
2012-04-12 08:37:27 -06:00
|
|
|
if (auto bld = ref->getBuilding())
|
|
|
|
return df::coord(bld->centerx, bld->centery, bld->z);
|
2012-05-17 09:56:55 -06:00
|
|
|
break;*/
|
|
|
|
|
|
|
|
default:
|
2012-04-12 08:37:27 -06:00
|
|
|
break;
|
2012-05-17 09:56:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < item->specific_refs.size(); i++)
|
|
|
|
{
|
|
|
|
df::specific_ref *ref = item->specific_refs[i];
|
|
|
|
|
|
|
|
switch (ref->type)
|
|
|
|
{
|
|
|
|
case specific_ref_type::VERMIN_ESCAPED_PET:
|
2020-04-15 19:05:15 -06:00
|
|
|
return ref->data.vermin->pos;
|
2012-04-20 03:30:37 -06:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-12 08:37:27 -06:00
|
|
|
}
|
|
|
|
}
|
2012-05-17 09:56:55 -06:00
|
|
|
|
|
|
|
return df::coord();
|
2012-04-12 08:37:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return item->pos;
|
2011-05-12 10:30:42 -06:00
|
|
|
}
|
2011-04-11 04:32:53 -06:00
|
|
|
|
2023-04-03 16:08:01 -06:00
|
|
|
static const char quality_table[] = {
|
|
|
|
'\0', // (base)
|
|
|
|
'-', // well-crafted
|
|
|
|
'+', // finely-crafted
|
|
|
|
'*', // superior quality
|
|
|
|
'\xF0', // (≡) exceptional
|
|
|
|
'\x0F' // (☼) masterful
|
|
|
|
};
|
2012-05-20 11:57:45 -06:00
|
|
|
|
|
|
|
static void addQuality(std::string &tmp, int quality)
|
|
|
|
{
|
|
|
|
if (quality > 0 && quality <= 5) {
|
2023-04-01 08:43:05 -06:00
|
|
|
char c = quality_table[quality];
|
|
|
|
tmp = c + tmp + c;
|
2012-05-20 11:57:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 04:43:02 -07:00
|
|
|
// It's not impossible the functionality of this operation is provided by one of the unmapped item functions.
|
2020-01-25 13:46:10 -07:00
|
|
|
std::string Items::getBookTitle(df::item *item)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
if (item->getType() == df::item_type::BOOK)
|
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
auto book = virtual_cast<df::item_bookst>(item);
|
|
|
|
|
|
|
|
if (book->title != "")
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
return book->title;
|
2020-01-25 04:43:02 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t i = 0; i < book->improvements.size(); i++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
if (auto page = virtual_cast<df::itemimprovement_pagesst>(book->improvements[i]))
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t k = 0; k < page->contents.size(); k++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
df::written_content *contents = world->written_contents.all[page->contents[k]];
|
2020-01-25 04:43:02 -07:00
|
|
|
if (contents->title != "")
|
|
|
|
{
|
|
|
|
return contents->title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 13:46:10 -07:00
|
|
|
else if (auto writing = virtual_cast<df::itemimprovement_writingst>(book->improvements[i]))
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t k = 0; k < writing->contents.size(); k++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
df::written_content *contents = world->written_contents.all[writing->contents[k]];
|
2020-01-25 04:43:02 -07:00
|
|
|
if (contents->title != "")
|
|
|
|
{
|
|
|
|
return contents->title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 13:46:10 -07:00
|
|
|
else if (item->getType() == df::item_type::TOOL)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
auto book = virtual_cast<df::item_toolst>(item);
|
|
|
|
|
|
|
|
if (book->hasToolUse(df::tool_uses::CONTAIN_WRITING))
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t i = 0; i < book->improvements.size(); i++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
if (auto page = virtual_cast<df::itemimprovement_pagesst>(book->improvements[i]))
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t k = 0; k < page->contents.size(); k++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
df::written_content *contents = world->written_contents.all[page->contents[k]];
|
|
|
|
if (contents->title != "")
|
|
|
|
{
|
|
|
|
return contents->title;
|
|
|
|
}
|
2020-01-25 04:43:02 -07:00
|
|
|
}
|
|
|
|
}
|
2020-01-25 13:46:10 -07:00
|
|
|
else if (auto writing = virtual_cast<df::itemimprovement_writingst>(book->improvements[i]))
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
for (size_t k = 0; k < writing->contents.size(); k++)
|
2020-01-25 04:43:02 -07:00
|
|
|
{
|
2020-01-25 13:46:10 -07:00
|
|
|
df::written_content *contents = world->written_contents.all[writing->contents[k]];
|
|
|
|
if (contents->title != "")
|
|
|
|
{
|
|
|
|
return contents->title;
|
|
|
|
}
|
2020-01-25 04:43:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
std::string Items::getDescription(df::item *item, int type, bool decorate)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
item->getItemDescription(&tmp, type);
|
|
|
|
|
|
|
|
if (decorate) {
|
|
|
|
addQuality(tmp, item->getQuality());
|
|
|
|
|
|
|
|
if (item->isImproved()) {
|
2023-04-03 16:08:01 -06:00
|
|
|
tmp = '\xAE' + tmp + '\xAF'; // («) + tmp + (»)
|
2012-05-20 11:57:45 -06:00
|
|
|
addQuality(tmp, item->getImprovementQuality());
|
|
|
|
}
|
2023-07-03 19:05:30 -06:00
|
|
|
|
|
|
|
if (item->flags.bits.foreign)
|
|
|
|
tmp = "(" + tmp + ")";
|
2012-05-20 11:57:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetUnitInvFlags(df::unit *unit, df::unit_inventory_item *inv_item)
|
|
|
|
{
|
|
|
|
if (inv_item->mode == df::unit_inventory_item::Worn ||
|
|
|
|
inv_item->mode == df::unit_inventory_item::WrappedAround)
|
|
|
|
{
|
|
|
|
unit->flags2.bits.calculated_inventory = false;
|
|
|
|
unit->flags2.bits.calculated_insulation = false;
|
|
|
|
}
|
|
|
|
else if (inv_item->mode == df::unit_inventory_item::StuckIn)
|
|
|
|
{
|
2014-04-04 12:34:39 -06:00
|
|
|
unit->flags3.bits.stuck_weapon_computed = false;
|
2012-05-20 11:57:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
static bool detachItem(MapExtras::MapCache &mc, df::item *item)
|
|
|
|
{
|
2012-05-20 11:57:45 -06:00
|
|
|
if (!item->specific_refs.empty())
|
|
|
|
return false;
|
|
|
|
if (item->world_data_id != -1)
|
|
|
|
return false;
|
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
for (size_t i = 0; i < item->general_refs.size(); i++)
|
2012-05-20 11:57:45 -06:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
df::general_ref *ref = item->general_refs[i];
|
2012-05-20 11:57:45 -06:00
|
|
|
|
|
|
|
switch (ref->getType())
|
|
|
|
{
|
|
|
|
case general_ref_type::BUILDING_HOLDER:
|
|
|
|
case general_ref_type::BUILDING_CAGED:
|
|
|
|
case general_ref_type::BUILDING_TRIGGER:
|
|
|
|
case general_ref_type::BUILDING_TRIGGERTARGET:
|
|
|
|
case general_ref_type::BUILDING_CIVZONE_ASSIGNED:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 20:21:27 -06:00
|
|
|
if (auto *ref =
|
2021-08-19 20:51:25 -06:00
|
|
|
virtual_cast<df::general_ref_projectile>(
|
|
|
|
Items::getGeneralRef(item, general_ref_type::PROJECTILE)))
|
2021-08-19 18:44:13 -06:00
|
|
|
{
|
2021-08-19 20:51:25 -06:00
|
|
|
return linked_list_remove(&world->proj_list, ref->projectile_id) &&
|
|
|
|
DFHack::removeRef(item->general_refs,
|
|
|
|
general_ref_type::PROJECTILE, ref->getID());
|
2021-08-19 18:44:13 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
if (item->flags.bits.on_ground)
|
2011-05-12 10:30:42 -06:00
|
|
|
{
|
2012-04-12 08:37:27 -06:00
|
|
|
if (!mc.removeItemOnGround(item))
|
|
|
|
Core::printerr("Item was marked on_ground, but not in block: %d (%d,%d,%d)\n",
|
|
|
|
item->id, item->pos.x, item->pos.y, item->pos.z);
|
|
|
|
|
|
|
|
item->flags.bits.on_ground = false;
|
|
|
|
return true;
|
2011-04-11 04:32:53 -06:00
|
|
|
}
|
2021-08-19 18:44:13 -06:00
|
|
|
|
|
|
|
if (item->flags.bits.in_inventory)
|
2012-04-12 08:37:27 -06:00
|
|
|
{
|
|
|
|
bool found = false;
|
2011-04-11 04:32:53 -06:00
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
for (int i = item->general_refs.size()-1; i >= 0; i--)
|
2012-04-12 08:37:27 -06:00
|
|
|
{
|
2012-11-12 07:27:58 -07:00
|
|
|
df::general_ref *ref = item->general_refs[i];
|
2012-04-12 08:37:27 -06:00
|
|
|
|
|
|
|
switch (ref->getType())
|
|
|
|
{
|
|
|
|
case general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
if (auto item2 = ref->getItem())
|
2012-04-13 06:10:19 -06:00
|
|
|
{
|
2022-12-16 12:13:30 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2012-05-20 11:57:45 -06:00
|
|
|
// Viewscreens hold general_ref_contains_itemst pointers
|
|
|
|
for (auto screen = Core::getTopViewscreen(); screen; screen = screen->parent)
|
|
|
|
{
|
|
|
|
auto vsitem = strict_virtual_cast<df::viewscreen_itemst>(screen);
|
|
|
|
if (vsitem && vsitem->item == item2)
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-16 12:13:30 -07:00
|
|
|
*/
|
2012-04-13 06:10:19 -06:00
|
|
|
item2->flags.bits.weight_computed = false;
|
|
|
|
|
2012-11-12 07:27:58 -07:00
|
|
|
removeRef(item2->general_refs, general_ref_type::CONTAINS_ITEM, item->id);
|
2012-04-13 06:10:19 -06:00
|
|
|
}
|
2012-04-12 08:37:27 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case general_ref_type::UNIT_HOLDER:
|
2012-05-20 11:57:45 -06:00
|
|
|
if (auto unit = ref->getUnit())
|
2012-05-15 04:01:59 -06:00
|
|
|
{
|
2023-01-01 02:03:42 -07:00
|
|
|
/* TODO: understand how this changes for v50
|
2012-05-20 11:57:45 -06:00
|
|
|
// Unit view sidebar holds inventory item pointers
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->main.mode == ui_sidebar_mode::ViewUnits &&
|
2012-05-20 11:57:45 -06:00
|
|
|
(!ui_selected_unit ||
|
|
|
|
vector_get(world->units.active, *ui_selected_unit) == unit))
|
|
|
|
return false;
|
2023-01-01 02:03:42 -07:00
|
|
|
*/
|
2012-05-20 11:57:45 -06:00
|
|
|
|
|
|
|
for (int i = unit->inventory.size()-1; i >= 0; i--)
|
2012-05-15 04:01:59 -06:00
|
|
|
{
|
2012-05-20 11:57:45 -06:00
|
|
|
df::unit_inventory_item *inv_item = unit->inventory[i];
|
|
|
|
if (inv_item->item != item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
resetUnitInvFlags(unit, inv_item);
|
|
|
|
|
|
|
|
vector_erase_at(unit->inventory, i);
|
|
|
|
delete inv_item;
|
2012-05-15 04:01:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-04-12 08:37:27 -06:00
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = true;
|
2012-11-12 07:27:58 -07:00
|
|
|
vector_erase_at(item->general_refs, i);
|
2012-04-12 08:37:27 -06:00
|
|
|
delete ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item->flags.bits.in_inventory = false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-19 18:44:13 -06:00
|
|
|
|
|
|
|
if (item->flags.bits.removed)
|
2012-09-14 08:49:02 -06:00
|
|
|
{
|
|
|
|
item->flags.bits.removed = false;
|
|
|
|
|
|
|
|
if (item->flags.bits.garbage_collect)
|
|
|
|
{
|
|
|
|
item->flags.bits.garbage_collect = false;
|
|
|
|
item->categorize(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-19 18:44:13 -06:00
|
|
|
|
|
|
|
return false;
|
2012-04-12 08:37:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void putOnGround(MapExtras::MapCache &mc, df::item *item, df::coord pos)
|
|
|
|
{
|
|
|
|
item->pos = pos;
|
|
|
|
item->flags.bits.on_ground = true;
|
|
|
|
|
|
|
|
if (!mc.addItemOnGround(item))
|
|
|
|
Core::printerr("Could not add item %d to ground at (%d,%d,%d)\n",
|
|
|
|
item->id, pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DFHack::Items::moveToGround(MapExtras::MapCache &mc, df::item *item, df::coord pos)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
if (!detachItem(mc, item))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
putOnGround(mc, item, pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DFHack::Items::moveToContainer(MapExtras::MapCache &mc, df::item *item, df::item *container)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
CHECK_NULL_POINTER(container);
|
|
|
|
|
2012-05-17 09:56:55 -06:00
|
|
|
auto cpos = getPosition(container);
|
|
|
|
if (!cpos.isValid())
|
|
|
|
return false;
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
auto ref1 = df::allocate<df::general_ref_contains_itemst>();
|
|
|
|
auto ref2 = df::allocate<df::general_ref_contained_in_itemst>();
|
|
|
|
|
|
|
|
if (!ref1 || !ref2)
|
|
|
|
{
|
|
|
|
delete ref1; delete ref2;
|
|
|
|
Core::printerr("Could not allocate container refs.\n");
|
2012-05-20 11:57:45 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!detachItem(mc, item))
|
|
|
|
{
|
|
|
|
delete ref1; delete ref2;
|
2012-04-12 08:37:27 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->pos = container->pos;
|
|
|
|
item->flags.bits.in_inventory = true;
|
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
container->flags.bits.container = true;
|
2012-04-13 06:10:19 -06:00
|
|
|
container->flags.bits.weight_computed = false;
|
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
ref1->item_id = item->id;
|
2012-11-12 07:27:58 -07:00
|
|
|
container->general_refs.push_back(ref1);
|
2012-05-20 11:57:45 -06:00
|
|
|
|
2012-04-12 08:37:27 -06:00
|
|
|
ref2->item_id = container->id;
|
2012-11-12 07:27:58 -07:00
|
|
|
item->general_refs.push_back(ref2);
|
2012-04-12 08:37:27 -06:00
|
|
|
|
|
|
|
return true;
|
2011-04-11 04:32:53 -06:00
|
|
|
}
|
2012-05-19 12:03:08 -06:00
|
|
|
|
2016-04-05 09:43:02 -06:00
|
|
|
bool DFHack::Items::moveToBuilding(MapExtras::MapCache &mc, df::item *item, df::building_actual *building,
|
|
|
|
int16_t use_mode, bool force_in_building)
|
2012-05-18 07:05:29 -06:00
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
CHECK_NULL_POINTER(building);
|
2012-05-20 11:57:45 -06:00
|
|
|
CHECK_INVALID_ARGUMENT(use_mode == 0 || use_mode == 2);
|
2012-05-18 07:05:29 -06:00
|
|
|
|
|
|
|
auto ref = df::allocate<df::general_ref_building_holderst>();
|
|
|
|
if(!ref)
|
|
|
|
{
|
|
|
|
delete ref;
|
|
|
|
Core::printerr("Could not allocate building holder refs.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-20 11:57:45 -06:00
|
|
|
|
2012-05-18 07:05:29 -06:00
|
|
|
if (!detachItem(mc, item))
|
|
|
|
{
|
|
|
|
delete ref;
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-20 11:57:45 -06:00
|
|
|
|
2012-05-18 07:05:29 -06:00
|
|
|
item->pos.x=building->centerx;
|
|
|
|
item->pos.y=building->centery;
|
|
|
|
item->pos.z=building->z;
|
2016-04-05 09:43:02 -06:00
|
|
|
if (use_mode == 2 || force_in_building)
|
|
|
|
item->flags.bits.in_building=true;
|
2012-05-18 07:05:29 -06:00
|
|
|
|
|
|
|
ref->building_id=building->id;
|
2012-11-12 07:27:58 -07:00
|
|
|
item->general_refs.push_back(ref);
|
2012-05-18 07:05:29 -06:00
|
|
|
|
|
|
|
auto con=new df::building_actual::T_contained_items;
|
|
|
|
con->item=item;
|
|
|
|
con->use_mode=use_mode;
|
|
|
|
building->contained_items.push_back(con);
|
2012-05-20 11:57:45 -06:00
|
|
|
|
2012-05-18 07:05:29 -06:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-15 04:01:59 -06:00
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
bool DFHack::Items::moveToInventory(
|
|
|
|
MapExtras::MapCache &mc, df::item *item, df::unit *unit,
|
|
|
|
df::unit_inventory_item::T_mode mode, int body_part
|
|
|
|
) {
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
CHECK_NULL_POINTER(unit);
|
|
|
|
CHECK_NULL_POINTER(unit->body.body_plan);
|
|
|
|
CHECK_INVALID_ARGUMENT(is_valid_enum_item(mode));
|
|
|
|
int body_plan_size = unit->body.body_plan->body_parts.size();
|
|
|
|
CHECK_INVALID_ARGUMENT(body_part < 0 || body_part <= body_plan_size);
|
|
|
|
|
|
|
|
auto holderReference = df::allocate<df::general_ref_unit_holderst>();
|
|
|
|
if (!holderReference)
|
2012-05-15 04:01:59 -06:00
|
|
|
{
|
2012-05-20 11:57:45 -06:00
|
|
|
Core::printerr("Could not allocate UNIT_HOLDER reference.\n");
|
2012-05-15 04:01:59 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
if (!detachItem(mc, item))
|
2012-05-15 04:01:59 -06:00
|
|
|
{
|
2012-05-20 11:57:45 -06:00
|
|
|
delete holderReference;
|
2012-05-15 04:01:59 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
item->flags.bits.in_inventory = true;
|
2012-05-15 04:01:59 -06:00
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
auto newInventoryItem = new df::unit_inventory_item();
|
2012-05-15 04:01:59 -06:00
|
|
|
newInventoryItem->item = item;
|
2012-05-20 11:57:45 -06:00
|
|
|
newInventoryItem->mode = mode;
|
|
|
|
newInventoryItem->body_part_id = body_part;
|
2012-05-15 04:01:59 -06:00
|
|
|
unit->inventory.push_back(newInventoryItem);
|
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
holderReference->unit_id = unit->id;
|
2012-11-12 07:27:58 -07:00
|
|
|
item->general_refs.push_back(holderReference);
|
2012-05-15 04:01:59 -06:00
|
|
|
|
2012-05-20 11:57:45 -06:00
|
|
|
resetUnitInvFlags(unit, newInventoryItem);
|
2012-05-15 04:01:59 -06:00
|
|
|
|
|
|
|
return true;
|
2012-05-19 11:09:13 -06:00
|
|
|
}
|
2012-09-12 08:17:42 -06:00
|
|
|
|
2012-09-14 08:49:02 -06:00
|
|
|
bool Items::remove(MapExtras::MapCache &mc, df::item *item, bool no_uncat)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
auto pos = getPosition(item);
|
|
|
|
|
|
|
|
if (!detachItem(mc, item))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pos.isValid())
|
|
|
|
item->pos = pos;
|
|
|
|
|
|
|
|
if (!no_uncat)
|
|
|
|
item->uncategorize();
|
|
|
|
|
|
|
|
item->flags.bits.removed = true;
|
|
|
|
item->flags.bits.garbage_collect = !no_uncat;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-12 08:17:42 -06:00
|
|
|
df::proj_itemst *Items::makeProjectile(MapExtras::MapCache &mc, df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
if (!world || !proj_next_id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto pos = getPosition(item);
|
|
|
|
if (!pos.isValid())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
auto ref = df::allocate<df::general_ref_projectile>();
|
|
|
|
if (!ref)
|
|
|
|
return NULL;
|
|
|
|
|
2014-04-30 11:28:02 -06:00
|
|
|
auto proj = df::allocate<df::proj_itemst>();
|
|
|
|
if (!proj) {
|
|
|
|
delete ref;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-12 08:17:42 -06:00
|
|
|
if (!detachItem(mc, item))
|
|
|
|
{
|
|
|
|
delete ref;
|
2014-04-30 11:28:02 -06:00
|
|
|
delete proj;
|
2012-09-12 08:17:42 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->pos = pos;
|
|
|
|
item->flags.bits.in_job = true;
|
|
|
|
|
|
|
|
proj->link = new df::proj_list_link();
|
|
|
|
proj->link->item = proj;
|
|
|
|
proj->id = (*proj_next_id)++;
|
|
|
|
|
|
|
|
proj->origin_pos = proj->target_pos = pos;
|
|
|
|
proj->cur_pos = proj->prev_pos = pos;
|
|
|
|
proj->item = item;
|
|
|
|
|
|
|
|
ref->projectile_id = proj->id;
|
2012-11-12 07:27:58 -07:00
|
|
|
item->general_refs.push_back(ref);
|
2012-09-12 08:17:42 -06:00
|
|
|
|
|
|
|
linked_list_append(&world->proj_list, proj->link);
|
|
|
|
|
|
|
|
return proj;
|
|
|
|
}
|
2014-04-25 10:04:21 -06:00
|
|
|
|
|
|
|
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::BLOCKS:
|
|
|
|
case item_type::SKIN_TANNED:
|
|
|
|
value = 5;
|
|
|
|
break;
|
|
|
|
|
2023-07-03 19:05:30 -06:00
|
|
|
case item_type::SMALLGEM:
|
|
|
|
value = 20;
|
|
|
|
break;
|
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
case item_type::BOULDER:
|
|
|
|
case item_type::WOOD:
|
|
|
|
value = 3;
|
|
|
|
break;
|
|
|
|
|
2023-07-03 19:05:30 -06:00
|
|
|
case item_type::ROUGH:
|
|
|
|
value = 6;
|
|
|
|
break;
|
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
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::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:
|
2023-07-03 19:05:30 -06:00
|
|
|
case item_type::BAG:
|
2014-04-25 10:04:21 -06:00
|
|
|
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:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.weapons.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.weapons[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::ARMOR:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.armor.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.armor[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::SHOES:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.shoes.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.shoes[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::SHIELD:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.shields.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.shields[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::HELM:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.helms.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.helms[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::GLOVES:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.gloves.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.gloves[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::AMMO:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.ammo.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.ammo[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::MEAT:
|
|
|
|
case item_type::PLANT:
|
2014-07-21 12:26:34 -06:00
|
|
|
case item_type::PLANT_GROWTH:
|
2014-04-25 10:04:21 -06:00
|
|
|
value = 2;
|
|
|
|
break;
|
|
|
|
|
2017-06-25 15:17:23 -06:00
|
|
|
case item_type::CHEESE:
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
case item_type::FISH:
|
|
|
|
case item_type::FISH_RAW:
|
|
|
|
case item_type::EGG:
|
|
|
|
value = 2;
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_type) < world->raws.creatures.all.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
{
|
|
|
|
auto creature = world->raws.creatures.all[mat_type];
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_subtype) < creature->caste.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
{
|
|
|
|
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;
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_type) < world->raws.creatures.all.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
{
|
|
|
|
auto creature = world->raws.creatures.all[mat_type];
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_subtype) < creature->caste.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = creature->caste[mat_subtype]->misc.petvalue;
|
|
|
|
}
|
|
|
|
value /= 2;
|
|
|
|
if (!value)
|
|
|
|
return 1;
|
|
|
|
return value;
|
|
|
|
|
|
|
|
case item_type::PET:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_type) < world->raws.creatures.all.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
{
|
|
|
|
auto creature = world->raws.creatures.all[mat_type];
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(mat_subtype) < creature->caste.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
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:
|
2023-07-03 19:05:30 -06:00
|
|
|
case item_type::BRANCH:
|
2014-04-25 10:04:21 -06:00
|
|
|
value = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::THREAD:
|
|
|
|
value = 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::CLOTH:
|
|
|
|
value = 7;
|
|
|
|
break;
|
|
|
|
|
2017-06-25 15:17:23 -06:00
|
|
|
case item_type::SHEET:
|
|
|
|
value = 5;
|
|
|
|
break;
|
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
case item_type::PANTS:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.pants.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
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:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.trapcomps.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.trapcomps[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case item_type::FOOD:
|
|
|
|
return 10;
|
|
|
|
|
|
|
|
case item_type::TOOL:
|
2014-04-30 10:44:22 -06:00
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.tools.size())
|
2014-04-25 10:04:21 -06:00
|
|
|
value = world->raws.itemdefs.tools[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
2017-06-25 15:17:23 -06:00
|
|
|
|
|
|
|
case item_type::INSTRUMENT:
|
|
|
|
if (size_t(item_subtype) < world->raws.itemdefs.instruments.size())
|
|
|
|
value = world->raws.itemdefs.instruments[item_subtype]->value;
|
|
|
|
else
|
|
|
|
value = 10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// case item_type::ROCK:
|
|
|
|
default:
|
|
|
|
return 0;
|
2014-04-25 10:04:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
MaterialInfo mat;
|
|
|
|
if (mat.decode(mat_type, mat_subtype))
|
|
|
|
value *= mat.material->material_value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:05:30 -06:00
|
|
|
static int32_t get_war_multiplier(df::item *item, df::caravan_state *caravan) {
|
2023-07-03 19:45:33 -06:00
|
|
|
static const int32_t DEFAULT_WAR_MULTIPLIER = 256;
|
2023-07-03 19:05:30 -06:00
|
|
|
|
|
|
|
if (!caravan)
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
auto caravan_he = df::historical_entity::find(caravan->entity);
|
|
|
|
if (!caravan_he)
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
int32_t war_alignment = caravan_he->entity_raw->sphere_alignment[df::sphere_type::WAR];
|
2023-07-03 19:45:33 -06:00
|
|
|
if (war_alignment == DEFAULT_WAR_MULTIPLIER)
|
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
switch (item->getType()) {
|
|
|
|
case df::item_type::WEAPON:
|
|
|
|
{
|
|
|
|
auto weap_def = df::itemdef_weaponst::find(item->getSubtype());
|
|
|
|
auto caravan_cre_raw = df::creature_raw::find(caravan_he->race);
|
|
|
|
if (!weap_def || !caravan_cre_raw || caravan_cre_raw->adultsize < weap_def->minimum_size)
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case df::item_type::ARMOR:
|
|
|
|
case df::item_type::SHOES:
|
|
|
|
case df::item_type::HELM:
|
|
|
|
case df::item_type::GLOVES:
|
|
|
|
case df::item_type::PANTS:
|
|
|
|
{
|
|
|
|
if (item->getEffectiveArmorLevel() <= 0)
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
auto caravan_cre_raw = df::creature_raw::find(caravan_he->race);
|
|
|
|
auto maker_cre_raw = df::creature_raw::find(item->getMakerRace());
|
|
|
|
if (!caravan_cre_raw || !maker_cre_raw)
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
if (caravan_cre_raw->adultsize < ((maker_cre_raw->adultsize * 6) / 7))
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
if (caravan_cre_raw->adultsize > ((maker_cre_raw->adultsize * 8) / 7))
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case df::item_type::SHIELD:
|
|
|
|
case df::item_type::AMMO:
|
|
|
|
case df::item_type::BACKPACK:
|
|
|
|
case df::item_type::QUIVER:
|
|
|
|
break;
|
|
|
|
default:
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_WAR_MULTIPLIER;
|
2023-07-03 19:05:30 -06:00
|
|
|
}
|
|
|
|
return war_alignment;
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:45:33 -06:00
|
|
|
static const int32_t DEFAULT_AGREEMENT_MULTIPLIER = 128;
|
|
|
|
|
|
|
|
static int32_t get_buy_request_multiplier(df::item *item, const df::entity_buy_prices *buy_prices) {
|
2023-07-04 02:53:45 -06:00
|
|
|
if (!buy_prices)
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
|
2023-07-03 19:45:33 -06:00
|
|
|
int16_t item_type = item->getType();
|
|
|
|
int16_t item_subtype = item->getSubtype();
|
|
|
|
int16_t mat_type = item->getMaterial();
|
|
|
|
int32_t mat_subtype = item->getMaterialIndex();
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < buy_prices->price.size(); ++idx) {
|
|
|
|
if (buy_prices->items->item_type[idx] != item_type)
|
|
|
|
continue;
|
|
|
|
if (buy_prices->items->item_subtype[idx] != -1 && buy_prices->items->item_subtype[idx] != item_subtype)
|
|
|
|
continue;
|
|
|
|
if (buy_prices->items->mat_types[idx] != -1 && buy_prices->items->mat_types[idx] != mat_type)
|
|
|
|
continue;
|
|
|
|
if (buy_prices->items->mat_indices[idx] != -1 && buy_prices->items->mat_indices[idx] != mat_subtype)
|
|
|
|
continue;
|
|
|
|
return buy_prices->price[idx];
|
|
|
|
}
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
}
|
|
|
|
|
2023-07-04 02:53:45 -06:00
|
|
|
template<typename T>
|
|
|
|
static int get_price(const std::vector<T> &res, int32_t val, const std::vector<int32_t> &pri) {
|
|
|
|
for (size_t idx = 0; idx < res.size(); ++idx) {
|
|
|
|
if (res[idx] == val && pri.size() > idx)
|
|
|
|
return pri[idx];
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T1, typename T2>
|
|
|
|
static int get_price(const std::vector<T1> &mat_res, int32_t mat, const std::vector<T2> &gloss_res, int32_t gloss, const std::vector<int32_t> &pri) {
|
|
|
|
for (size_t idx = 0; idx < mat_res.size(); ++idx) {
|
|
|
|
if (mat_res[idx] == mat && (gloss_res[idx] == -1 || gloss_res[idx] == gloss) && pri.size() > idx)
|
|
|
|
return pri[idx];
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint16_t PLANT_BASE = 419;
|
|
|
|
static const uint16_t NUM_PLANT_TYPES = 200;
|
|
|
|
|
|
|
|
static int32_t get_sell_request_multiplier(df::item *item, const df::historical_entity::T_resources &resources, const std::vector<int32_t> *prices) {
|
|
|
|
static const df::dfhack_material_category silk_cat(df::dfhack_material_category::mask_silk);
|
|
|
|
static const df::dfhack_material_category yarn_cat(df::dfhack_material_category::mask_yarn);
|
|
|
|
static const df::dfhack_material_category leather_cat(df::dfhack_material_category::mask_leather);
|
|
|
|
|
|
|
|
int16_t item_type = item->getType();
|
|
|
|
int16_t item_subtype = item->getSubtype();
|
|
|
|
int16_t mat_type = item->getMaterial();
|
|
|
|
int32_t mat_subtype = item->getMaterialIndex();
|
|
|
|
|
|
|
|
bool inorganic = mat_type == df::builtin_mats::INORGANIC;
|
|
|
|
bool is_plant = (uint16_t)(mat_type - PLANT_BASE) < NUM_PLANT_TYPES;
|
|
|
|
|
|
|
|
switch (item_type) {
|
|
|
|
case df::item_type::BAR:
|
|
|
|
if (inorganic) {
|
|
|
|
if (int32_t price = get_price(resources.metals, mat_subtype, prices[df::entity_sell_category::MetalBars]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::SMALLGEM:
|
|
|
|
if (inorganic) {
|
|
|
|
if (int32_t price = get_price(resources.gems, mat_subtype, prices[df::entity_sell_category::SmallCutGems]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::BLOCKS:
|
|
|
|
if (inorganic) {
|
|
|
|
if (int32_t price = get_price(resources.stones, mat_subtype, prices[df::entity_sell_category::StoneBlocks]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::ROUGH:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.glass.mat_type, mat_type, resources.misc_mat.glass.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Glass]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::BOULDER:
|
|
|
|
if (int32_t price = get_price(resources.stones, mat_subtype, prices[df::entity_sell_category::Stone]); price != -1)
|
|
|
|
return price;
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.clay.mat_type, mat_type, resources.misc_mat.clay.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Clay]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::WOOD:
|
|
|
|
if (int32_t price = get_price(resources.organic.wood.mat_type, mat_type, resources.organic.wood.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Wood]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::CHAIN:
|
|
|
|
if (is_plant) {
|
|
|
|
if (int32_t price = get_price(resources.organic.fiber.mat_type, mat_type, resources.organic.fiber.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::RopesPlant]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.decode(mat_type, mat_subtype);
|
|
|
|
if (mi.isValid()) {
|
|
|
|
if (mi.matches(silk_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.silk.mat_type, mat_type, resources.organic.silk.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::RopesSilk]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (mi.matches(yarn_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.wool.mat_type, mat_type, resources.organic.wool.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::RopesYarn]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::FLASK:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.flasks.mat_type, mat_type, resources.misc_mat.flasks.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::FlasksWaterskins]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::GOBLET:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.crafts.mat_type, mat_type, resources.misc_mat.crafts.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::CupsMugsGoblets]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::INSTRUMENT:
|
|
|
|
if (int32_t price = get_price(resources.instrument_type, mat_subtype, prices[df::entity_sell_category::Instruments]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::TOY:
|
|
|
|
if (int32_t price = get_price(resources.toy_type, mat_subtype, prices[df::entity_sell_category::Toys]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::CAGE:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.cages.mat_type, mat_type, resources.misc_mat.cages.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Cages]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::BARREL:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.barrels.mat_type, mat_type, resources.misc_mat.barrels.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Barrels]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::BUCKET:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.barrels.mat_type, mat_type, resources.misc_mat.barrels.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Buckets]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::WEAPON:
|
|
|
|
if (int32_t price = get_price(resources.weapon_type, mat_subtype, prices[df::entity_sell_category::Weapons]); price != -1)
|
|
|
|
return price;
|
|
|
|
if (int32_t price = get_price(resources.digger_type, mat_subtype, prices[df::entity_sell_category::DiggingImplements]); price != -1)
|
|
|
|
return price;
|
|
|
|
if (int32_t price = get_price(resources.training_weapon_type, mat_subtype, prices[df::entity_sell_category::TrainingWeapons]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::ARMOR:
|
|
|
|
if (int32_t price = get_price(resources.armor_type, mat_subtype, prices[df::entity_sell_category::Bodywear]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SHOES:
|
|
|
|
if (int32_t price = get_price(resources.shoes_type, mat_subtype, prices[df::entity_sell_category::Footwear]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SHIELD:
|
|
|
|
if (int32_t price = get_price(resources.shield_type, mat_subtype, prices[df::entity_sell_category::Shields]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::HELM:
|
|
|
|
if (int32_t price = get_price(resources.helm_type, mat_subtype, prices[df::entity_sell_category::Headwear]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::GLOVES:
|
|
|
|
if (int32_t price = get_price(resources.gloves_type, mat_subtype, prices[df::entity_sell_category::Handwear]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::BAG:
|
|
|
|
{
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.decode(mat_type, mat_subtype);
|
|
|
|
if (mi.isValid() && mi.matches(leather_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.leather.mat_type, mat_type, resources.organic.leather.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::BagsLeather]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (is_plant) {
|
|
|
|
if (int32_t price = get_price(resources.organic.fiber.mat_type, mat_type, resources.organic.fiber.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::BagsPlant]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (mi.isValid() && mi.matches(silk_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.silk.mat_type, mat_type, resources.organic.silk.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::BagsSilk]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (mi.isValid() && mi.matches(yarn_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.wool.mat_type, mat_type, resources.organic.wool.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::BagsYarn]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::FIGURINE:
|
|
|
|
case df::item_type::AMULET:
|
|
|
|
case df::item_type::SCEPTER:
|
|
|
|
case df::item_type::CROWN:
|
|
|
|
case df::item_type::RING:
|
|
|
|
case df::item_type::EARRING:
|
|
|
|
case df::item_type::BRACELET:
|
|
|
|
case df::item_type::TOTEM:
|
|
|
|
case df::item_type::BOOK:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.crafts.mat_type, mat_type, resources.misc_mat.crafts.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Crafts]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::AMMO:
|
|
|
|
if (int32_t price = get_price(resources.ammo_type, mat_subtype, prices[df::entity_sell_category::Ammo]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::GEM:
|
|
|
|
if (inorganic) {
|
|
|
|
if (int32_t price = get_price(resources.gems, mat_subtype, prices[df::entity_sell_category::LargeCutGems]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::ANVIL:
|
|
|
|
if (int32_t price = get_price(resources.metal.anvil.mat_type, mat_type, resources.metal.anvil.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Anvils]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::MEAT:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.meat.mat_type, mat_type, resources.misc_mat.meat.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Meat]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::FISH:
|
|
|
|
case df::item_type::FISH_RAW:
|
|
|
|
if (int32_t price = get_price(resources.fish_races, mat_type, resources.fish_castes, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Fish]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::VERMIN:
|
|
|
|
case df::item_type::PET:
|
|
|
|
if (int32_t price = get_price(resources.animals.pet_races, mat_type, resources.animals.pet_castes, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Pets]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SEEDS:
|
|
|
|
if (int32_t price = get_price(resources.seeds.mat_type, mat_type, resources.seeds.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Seeds]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::PLANT:
|
|
|
|
if (int32_t price = get_price(resources.plants.mat_type, mat_type, resources.plants.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Plants]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SKIN_TANNED:
|
|
|
|
if (int32_t price = get_price(resources.organic.leather.mat_type, mat_type, resources.organic.leather.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Leather]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::PLANT_GROWTH:
|
|
|
|
if (is_plant) {
|
|
|
|
if (int32_t price = get_price(resources.tree_fruit_plants, mat_type, resources.tree_fruit_growths, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::FruitsNuts]); price != -1)
|
|
|
|
return price;
|
|
|
|
if (int32_t price = get_price(resources.shrub_fruit_plants, mat_type, resources.shrub_fruit_growths, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::GardenVegetables]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::THREAD:
|
|
|
|
if (is_plant) {
|
|
|
|
if (int32_t price = get_price(resources.organic.fiber.mat_type, mat_type, resources.organic.fiber.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ThreadPlant]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.decode(mat_type, mat_subtype);
|
|
|
|
if (mi.isValid() && mi.matches(silk_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.silk.mat_type, mat_type, resources.organic.silk.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ThreadSilk]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (mi.isValid() && mi.matches(yarn_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.wool.mat_type, mat_type, resources.organic.wool.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ThreadYarn]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::CLOTH:
|
|
|
|
if (is_plant) {
|
|
|
|
if (int32_t price = get_price(resources.organic.fiber.mat_type, mat_type, resources.organic.fiber.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ClothPlant]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MaterialInfo mi;
|
|
|
|
mi.decode(mat_type, mat_subtype);
|
|
|
|
if (mi.isValid() && mi.matches(silk_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.silk.mat_type, mat_type, resources.organic.silk.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ClothSilk]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
if (mi.isValid() && mi.matches(yarn_cat)) {
|
|
|
|
if (int32_t price = get_price(resources.organic.wool.mat_type, mat_type, resources.organic.wool.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::ClothYarn]); price != -1)
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::item_type::PANTS:
|
|
|
|
if (int32_t price = get_price(resources.pants_type, mat_subtype, prices[df::entity_sell_category::Legwear]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::BACKPACK:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.backpacks.mat_type, mat_type, resources.misc_mat.backpacks.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Backpacks]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::QUIVER:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.quivers.mat_type, mat_type, resources.misc_mat.quivers.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Quivers]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::TRAPCOMP:
|
|
|
|
if (int32_t price = get_price(resources.trapcomp_type, mat_subtype, prices[df::entity_sell_category::TrapComponents]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::DRINK:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.booze.mat_type, mat_type, resources.misc_mat.booze.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Drinks]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::POWDER_MISC:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.powders.mat_type, mat_type, resources.misc_mat.powders.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Powders]); price != -1)
|
|
|
|
return price;
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.sand.mat_type, mat_type, resources.misc_mat.sand.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Sand]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::CHEESE:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.cheese.mat_type, mat_type, resources.misc_mat.cheese.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Cheese]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::LIQUID_MISC:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.extracts.mat_type, mat_type, resources.misc_mat.extracts.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Extracts]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SPLINT:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.barrels.mat_type, mat_type, resources.misc_mat.barrels.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Splints]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::CRUTCH:
|
|
|
|
if (int32_t price = get_price(resources.misc_mat.barrels.mat_type, mat_type, resources.misc_mat.barrels.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Crutches]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::TOOL:
|
|
|
|
if (int32_t price = get_price(resources.tool_type, mat_subtype, prices[df::entity_sell_category::Tools]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::EGG:
|
|
|
|
if (int32_t price = get_price(resources.egg_races, mat_type, resources.egg_castes, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Eggs]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
case df::item_type::SHEET:
|
|
|
|
if (int32_t price = get_price(resources.organic.parchment.mat_type, mat_type, resources.organic.parchment.mat_index, mat_subtype,
|
|
|
|
prices[df::entity_sell_category::Parchment]); price != -1)
|
|
|
|
return price;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < resources.wood_products.item_type.size(); ++idx) {
|
|
|
|
if (resources.wood_products.item_type[idx] == item_type &&
|
|
|
|
(resources.wood_products.item_subtype[idx] == -1 || resources.wood_products.item_subtype[idx] == item_subtype) &&
|
|
|
|
resources.wood_products.material.mat_type[idx] == mat_type &&
|
|
|
|
(resources.wood_products.material.mat_index[idx] == -1 || resources.wood_products.material.mat_index[idx] == mat_subtype) &&
|
|
|
|
prices[df::entity_sell_category::Miscellaneous].size() > idx)
|
|
|
|
return prices[df::entity_sell_category::Miscellaneous][idx];
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:45:33 -06:00
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
}
|
|
|
|
|
2023-07-04 02:53:45 -06:00
|
|
|
static int32_t get_sell_request_multiplier(df::item *item, const df::caravan_state *caravan) {
|
|
|
|
const df::entity_sell_prices *sell_prices = caravan->sell_prices;
|
|
|
|
if (!sell_prices)
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
|
|
|
|
auto caravan_he = df::historical_entity::find(caravan->entity);
|
|
|
|
if (!caravan_he)
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
|
|
|
|
return get_sell_request_multiplier(item, caravan_he->resources, &sell_prices->price[0]);
|
|
|
|
}
|
|
|
|
|
2023-08-28 16:42:56 -06:00
|
|
|
static int32_t get_sell_request_multiplier(df::unit *unit, const df::caravan_state *caravan) {
|
|
|
|
const df::entity_sell_prices *sell_prices = caravan->sell_prices;
|
|
|
|
if (!sell_prices)
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
|
|
|
|
auto caravan_he = df::historical_entity::find(caravan->entity);
|
|
|
|
if (!caravan_he)
|
|
|
|
return DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
|
|
|
|
auto & resources = caravan_he->resources;
|
|
|
|
int32_t price = get_price(resources.animals.pet_races, unit->race, resources.animals.pet_castes, unit->caste,
|
|
|
|
sell_prices->price[df::entity_sell_category::Pets]);
|
|
|
|
return (price != -1) ? price : DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
}
|
|
|
|
|
2023-07-06 04:21:19 -06:00
|
|
|
static bool is_requested_trade_good(df::item *item, df::caravan_state *caravan) {
|
|
|
|
auto trade_state = caravan->trade_state;
|
|
|
|
if (caravan->time_remaining <= 0 ||
|
|
|
|
(trade_state != df::caravan_state::T_trade_state::Approaching &&
|
|
|
|
trade_state != df::caravan_state::T_trade_state::AtDepot))
|
|
|
|
return false;
|
|
|
|
return get_buy_request_multiplier(item, caravan->buy_prices) > DEFAULT_AGREEMENT_MULTIPLIER;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Items::isRequestedTradeGood(df::item *item, df::caravan_state *caravan) {
|
|
|
|
if (caravan)
|
|
|
|
return is_requested_trade_good(item, caravan);
|
|
|
|
|
2023-07-04 04:58:45 -06:00
|
|
|
for (auto caravan : df::global::plotinfo->caravans) {
|
|
|
|
auto trade_state = caravan->trade_state;
|
|
|
|
if (caravan->time_remaining <= 0 ||
|
|
|
|
(trade_state != df::caravan_state::T_trade_state::Approaching &&
|
|
|
|
trade_state != df::caravan_state::T_trade_state::AtDepot))
|
|
|
|
continue;
|
|
|
|
if (get_buy_request_multiplier(item, caravan->buy_prices) > DEFAULT_AGREEMENT_MULTIPLIER)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-06 18:38:34 -06:00
|
|
|
int Items::getValue(df::item *item, df::caravan_state *caravan)
|
2014-04-25 10:04:21 -06:00
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
int16_t item_type = item->getType();
|
|
|
|
int16_t item_subtype = item->getSubtype();
|
|
|
|
int16_t mat_type = item->getMaterial();
|
|
|
|
int32_t mat_subtype = item->getMaterialIndex();
|
|
|
|
|
|
|
|
// Get base value for item type, subtype, and material
|
|
|
|
int value = getItemBaseValue(item_type, item_subtype, mat_type, mat_subtype);
|
|
|
|
|
2023-07-03 19:05:30 -06:00
|
|
|
// entity value modifications
|
|
|
|
value *= get_war_multiplier(item, caravan);
|
|
|
|
value >>= 8;
|
2014-04-25 10:04:21 -06:00
|
|
|
|
|
|
|
// Improve value based on quality
|
2023-07-03 19:05:30 -06:00
|
|
|
switch (item->getQuality()) {
|
|
|
|
case 1:
|
|
|
|
value *= 1.1;
|
|
|
|
value += 3;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
value *= 1.2;
|
|
|
|
value += 6;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
value *= 1.333;
|
|
|
|
value += 10;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
value *= 1.5;
|
|
|
|
value += 15;
|
|
|
|
break;
|
|
|
|
case 5:
|
2014-04-25 10:04:21 -06:00
|
|
|
value *= 2;
|
2023-07-03 19:05:30 -06:00
|
|
|
value += 30;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-25 10:04:21 -06:00
|
|
|
|
|
|
|
// Add improvement values
|
2023-07-03 19:05:30 -06:00
|
|
|
int impValue = item->getThreadDyeValue(caravan) + item->getImprovementsValue(caravan);
|
2014-04-25 10:04:21 -06:00
|
|
|
if (item_type == item_type::AMMO) // Ammo improvements are worth less
|
|
|
|
impValue /= 30;
|
|
|
|
value += impValue;
|
|
|
|
|
|
|
|
// Degrade value due to wear
|
|
|
|
switch (item->getWear())
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
value = value * 3 / 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
value = value / 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
value = value / 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore value bonuses from magic, since that never actually happens
|
|
|
|
|
|
|
|
// Artifacts have 10x value
|
|
|
|
if (item->flags.bits.artifact_mood)
|
|
|
|
value *= 10;
|
|
|
|
|
2023-07-03 19:45:33 -06:00
|
|
|
// modify buy/sell prices
|
2023-08-06 18:38:34 -06:00
|
|
|
if (caravan) {
|
|
|
|
value *= get_buy_request_multiplier(item, caravan->buy_prices);
|
|
|
|
value >>= 7;
|
|
|
|
value *= get_sell_request_multiplier(item, caravan);
|
|
|
|
value >>= 7;
|
|
|
|
}
|
2023-07-03 19:05:30 -06:00
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
// Boost value from stack size
|
|
|
|
value *= item->getStackSize();
|
|
|
|
// ...but not for coins
|
|
|
|
if (item_type == item_type::COIN)
|
|
|
|
{
|
2023-07-03 19:05:30 -06:00
|
|
|
value /= 50;
|
2014-04-25 10:04:21 -06:00
|
|
|
if (!value)
|
|
|
|
value = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle vermin swarms
|
|
|
|
if (item_type == item_type::VERMIN || item_type == item_type::PET)
|
|
|
|
{
|
2014-04-30 10:44:22 -06:00
|
|
|
int divisor = 1;
|
|
|
|
auto creature = vector_get(world->raws.creatures.all, mat_type);
|
|
|
|
if (creature && size_t(mat_subtype) < creature->caste.size())
|
|
|
|
divisor = creature->caste[mat_subtype]->misc.petvalue_divisor;
|
|
|
|
if (divisor > 1)
|
|
|
|
value /= divisor;
|
2014-04-25 10:04:21 -06:00
|
|
|
}
|
2023-08-28 16:42:56 -06:00
|
|
|
|
|
|
|
// Add in value from units contained in cages
|
|
|
|
if (item_type == item_type::CAGE) {
|
|
|
|
for (auto gref : item->general_refs) {
|
|
|
|
if (gref->getType() != df::general_ref_type::CONTAINS_UNIT)
|
|
|
|
continue;
|
|
|
|
auto unit = gref->getUnit();
|
|
|
|
if (!unit)
|
|
|
|
continue;
|
|
|
|
df::creature_raw *raw = world->raws.creatures.all[unit->race];
|
|
|
|
df::caste_raw *caste = raw->caste.at(unit->caste);
|
|
|
|
int unit_value = caste->misc.petvalue;
|
|
|
|
if (Units::isWar(unit) || Units::isHunter(unit))
|
|
|
|
unit_value *= 2;
|
|
|
|
if (caravan) {
|
|
|
|
unit_value *= get_sell_request_multiplier(unit, caravan);
|
|
|
|
unit_value >>= 7;
|
|
|
|
}
|
|
|
|
value += unit_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 10:04:21 -06:00
|
|
|
return value;
|
2014-07-03 08:36:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Items::createItem(df::item_type item_type, int16_t item_subtype, int16_t mat_type, int32_t mat_index, df::unit* unit) {
|
|
|
|
//based on Quietust's plugins/createitem.cpp
|
2015-06-09 12:02:42 -06:00
|
|
|
CHECK_NULL_POINTER(unit);
|
2014-07-03 08:36:55 -06:00
|
|
|
df::map_block* block = Maps::getTileBlock(unit->pos.x, unit->pos.y, unit->pos.z);
|
|
|
|
CHECK_NULL_POINTER(block);
|
|
|
|
df::reaction_product_itemst* prod = df::allocate<df::reaction_product_itemst>();
|
|
|
|
prod->item_type = item_type;
|
|
|
|
prod->item_subtype = item_subtype;
|
|
|
|
prod->mat_type = mat_type;
|
|
|
|
prod->mat_index = mat_index;
|
|
|
|
prod->probability = 100;
|
|
|
|
prod->count = 1;
|
|
|
|
switch(item_type) {
|
|
|
|
case df::item_type::BAR:
|
|
|
|
case df::item_type::POWDER_MISC:
|
|
|
|
case df::item_type::LIQUID_MISC:
|
|
|
|
case df::item_type::DRINK:
|
|
|
|
prod->product_dimension = 150;
|
|
|
|
break;
|
|
|
|
case df::item_type::THREAD:
|
|
|
|
prod->product_dimension = 15000;
|
|
|
|
break;
|
|
|
|
case df::item_type::CLOTH:
|
|
|
|
prod->product_dimension = 10000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prod->product_dimension = 1;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
//makeItem
|
2015-12-22 07:46:01 -07:00
|
|
|
vector<df::reaction_product*> out_products;
|
2014-07-03 08:36:55 -06:00
|
|
|
vector<df::item*> out_items;
|
|
|
|
vector<df::reaction_reagent*> in_reag;
|
|
|
|
vector<df::item*> in_items;
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
df::enums::game_type::game_type type = *df::global::gametype;
|
2015-12-22 07:46:01 -07:00
|
|
|
prod->produce(unit, &out_products, &out_items, &in_reag, &in_items, 1, job_skill::NONE,
|
2020-06-23 13:31:27 -06:00
|
|
|
0, df::historical_entity::find(unit->civ_id),
|
2023-01-05 18:11:01 -07:00
|
|
|
((type == df::enums::game_type::DWARF_MAIN) || (type == df::enums::game_type::DWARF_RECLAIM)) ? df::world_site::find(df::global::plotinfo->site_id) : NULL,
|
2020-06-23 13:31:27 -06:00
|
|
|
NULL);
|
2014-07-03 08:36:55 -06:00
|
|
|
if ( out_items.size() != 1 )
|
|
|
|
return -1;
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
for (size_t a = 0; a < out_items.size(); a++ ) {
|
|
|
|
out_items[a]->moveToGround(unit->pos.x, unit->pos.y, unit->pos.z);
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-07-03 08:36:55 -06:00
|
|
|
return out_items[0]->id;
|
|
|
|
}
|
|
|
|
|
2018-05-12 09:51:36 -06:00
|
|
|
/*
|
|
|
|
* Trade Info
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Items::checkMandates(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
for (df::mandate *mandate : world->mandates)
|
|
|
|
{
|
|
|
|
if (mandate->mode != df::mandate::T_mode::Export)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item->getType() != mandate->item_type ||
|
|
|
|
(mandate->item_subtype != -1 && item->getSubtype() != mandate->item_subtype))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mandate->mat_type != -1 && item->getMaterial() != mandate->mat_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mandate->mat_index != -1 && item->getMaterialIndex() != mandate->mat_index)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Items::canTrade(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
if (item->flags.bits.owned || item->flags.bits.artifact || item->flags.bits.spider_web || item->flags.bits.in_job)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (df::general_ref *ref : item->general_refs)
|
|
|
|
{
|
|
|
|
switch (ref->getType())
|
|
|
|
{
|
|
|
|
case general_ref_type::UNIT_HOLDER:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case general_ref_type::BUILDING_HOLDER:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (df::specific_ref *ref : item->specific_refs)
|
|
|
|
{
|
|
|
|
if (ref->type == specific_ref_type::JOB)
|
|
|
|
{
|
|
|
|
// Ignore any items assigned to a job
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkMandates(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Items::canTradeWithContents(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
if (item->flags.bits.in_inventory)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!canTrade(item))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vector<df::item*> contained_items;
|
|
|
|
getContainedItems(item, &contained_items);
|
|
|
|
for (df::item *cit : contained_items)
|
|
|
|
{
|
|
|
|
if (!canTrade(cit))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-12 12:49:30 -06:00
|
|
|
|
2023-07-16 12:55:45 -06:00
|
|
|
bool Items::canTradeAnyWithContents(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
if (item->flags.bits.in_inventory)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vector<df::item*> contained_items;
|
|
|
|
getContainedItems(item, &contained_items);
|
|
|
|
|
|
|
|
if (contained_items.empty())
|
|
|
|
return canTrade(item);
|
|
|
|
|
|
|
|
for (df::item *cit : contained_items) {
|
|
|
|
if (canTrade(cit))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-29 20:36:05 -06:00
|
|
|
bool Items::markForTrade(df::item *item, df::building_tradedepotst *depot) {
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
CHECK_NULL_POINTER(depot);
|
|
|
|
|
|
|
|
// validate that the depot is in a good state
|
|
|
|
if (depot->getBuildStage() < depot->getMaxBuildStage())
|
|
|
|
return false;
|
|
|
|
if (depot->jobs.size() && depot->jobs[0]->job_type == df::job_type::DestroyBuilding)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto href = df::allocate<df::general_ref_building_holderst>();
|
|
|
|
if (!href)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto job = new df::job();
|
|
|
|
job->job_type = df::job_type::BringItemToDepot;
|
|
|
|
job->pos = df::coord(depot->centerx, depot->centery, depot->z);
|
|
|
|
|
|
|
|
// job <-> item link
|
|
|
|
if (!Job::attachJobItem(job, item, df::job_item_ref::Hauled)) {
|
|
|
|
delete job;
|
|
|
|
delete href;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// job <-> building link
|
|
|
|
href->building_id = depot->id;
|
|
|
|
depot->jobs.push_back(job);
|
|
|
|
job->general_refs.push_back(href);
|
|
|
|
|
|
|
|
// add to job list
|
|
|
|
Job::linkIntoWorld(job);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-12 12:49:30 -06:00
|
|
|
bool Items::isRouteVehicle(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
int id = item->getVehicleID();
|
|
|
|
if (id < 0) return false;
|
|
|
|
|
|
|
|
auto vehicle = df::vehicle::find(id);
|
|
|
|
return vehicle && vehicle->route_id >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Items::isSquadEquipment(df::item *item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
2023-01-05 18:11:01 -07:00
|
|
|
if (!plotinfo)
|
2018-05-12 12:49:30 -06:00
|
|
|
return false;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
auto &vec = plotinfo->equipment.items_assigned[item->getType()];
|
2023-02-24 16:50:56 -07:00
|
|
|
return binsearch_index(vec, item->id) >= 0;
|
2018-05-12 12:49:30 -06:00
|
|
|
}
|
2023-10-16 10:08:36 -06:00
|
|
|
|
|
|
|
// reverse engineered, code reference: 0x140953150 in 50.11-win64-steam
|
|
|
|
// our name for this function: itemst::getCapacity
|
|
|
|
// bay12 name for this function: not known
|
|
|
|
|
|
|
|
int32_t Items::getCapacity(df::item* item)
|
|
|
|
{
|
|
|
|
CHECK_NULL_POINTER(item);
|
|
|
|
|
|
|
|
switch (item->getType()) {
|
|
|
|
case df::enums::item_type::FLASK:
|
|
|
|
case df::enums::item_type::GOBLET:
|
|
|
|
return 180;
|
|
|
|
case df::enums::item_type::CAGE:
|
|
|
|
case df::enums::item_type::BARREL:
|
|
|
|
case df::enums::item_type::COFFIN:
|
|
|
|
case df::enums::item_type::BOX:
|
|
|
|
case df::enums::item_type::BAG:
|
|
|
|
case df::enums::item_type::BIN:
|
|
|
|
case df::enums::item_type::ARMORSTAND:
|
|
|
|
case df::enums::item_type::WEAPONRACK:
|
|
|
|
case df::enums::item_type::CABINET:
|
|
|
|
return 6000;
|
|
|
|
case df::enums::item_type::BUCKET:
|
|
|
|
return 600;
|
|
|
|
case df::enums::item_type::ANIMALTRAP:
|
|
|
|
case df::enums::item_type::BACKPACK:
|
|
|
|
return 3000;
|
|
|
|
case df::enums::item_type::QUIVER:
|
|
|
|
return 1200;
|
|
|
|
case df::enums::item_type::TOOL:
|
2023-10-16 10:27:55 -06:00
|
|
|
{
|
|
|
|
auto tool = virtual_cast<df::item_toolst>(item);
|
|
|
|
if (tool)
|
|
|
|
return tool->subtype->container_capacity;
|
|
|
|
}
|
|
|
|
// fall through
|
2023-10-16 10:17:33 -06:00
|
|
|
default:
|
2023-10-16 10:27:55 -06:00
|
|
|
; // fall through to default exit
|
2023-10-16 10:08:36 -06:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|