Merge pull request #3706 from myk002/myk_cage_price

add in value for units contained in cages
develop
Myk 2023-08-28 18:04:30 -07:00 committed by GitHub
commit fb3ec4947a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

@ -62,6 +62,7 @@ Template for new versions:
- Core: reload scripts in mods when a world is unloaded and immediately loaded again
- Core: fix text getting added to DFHack text entry widgets when Alt- or Ctrl- keys are hit
- `orders`: prevent import/export overlay from appearing on the create workorder screen
- `caravan`: corrected prices for cages that have units inside of them
## Misc Improvements
- Surround DFHack-specific UI elements with square brackets instead of red-yellow blocks for better readability

@ -1910,6 +1910,21 @@ static int32_t get_sell_request_multiplier(df::item *item, const df::caravan_sta
return get_sell_request_multiplier(item, caravan_he->resources, &sell_prices->price[0]);
}
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;
}
static bool is_requested_trade_good(df::item *item, df::caravan_state *caravan) {
auto trade_state = caravan->trade_state;
if (caravan->time_remaining <= 0 ||
@ -2031,6 +2046,28 @@ int Items::getValue(df::item *item, df::caravan_state *caravan)
if (divisor > 1)
value /= divisor;
}
// 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;
}
}
return value;
}