| 1291 | } |
| 1292 | |
| 1293 | static int32_t get_war_multiplier(df::item *item, df::caravan_state *caravan) { |
| 1294 | CHECK_NULL_POINTER(item); |
| 1295 | static const int32_t DEFAULT_WAR_MULTIPLIER = 256; |
| 1296 | if (!caravan) |
| 1297 | return DEFAULT_WAR_MULTIPLIER; |
| 1298 | |
| 1299 | auto caravan_he = df::historical_entity::find(caravan->entity); |
| 1300 | if (!caravan_he) |
| 1301 | return DEFAULT_WAR_MULTIPLIER; |
| 1302 | |
| 1303 | int32_t war_alignment = caravan_he->entity_raw->sphere_alignment[sphere_type::WAR]; |
| 1304 | if (war_alignment == DEFAULT_WAR_MULTIPLIER) |
| 1305 | return DEFAULT_WAR_MULTIPLIER; |
| 1306 | |
| 1307 | switch (item->getType()) |
| 1308 | { using namespace df::enums::item_type; |
| 1309 | case WEAPON: |
| 1310 | { |
| 1311 | auto weap_def = df::itemdef_weaponst::find(item->getSubtype()); |
| 1312 | auto caravan_cre_raw = df::creature_raw::find(caravan_he->race); |
| 1313 | if (!weap_def || !caravan_cre_raw || caravan_cre_raw->adultsize < weap_def->minimum_size) |
| 1314 | return DEFAULT_WAR_MULTIPLIER; |
| 1315 | break; |
| 1316 | } |
| 1317 | case ARMOR: |
| 1318 | case SHOES: |
| 1319 | case HELM: |
| 1320 | case GLOVES: |
| 1321 | case PANTS: |
| 1322 | { |
| 1323 | if (item->getEffectiveArmorLevel() <= 0) |
| 1324 | return DEFAULT_WAR_MULTIPLIER; |
| 1325 | |
| 1326 | auto caravan_cre_raw = df::creature_raw::find(caravan_he->race); |
| 1327 | auto maker_cre_raw = df::creature_raw::find(item->getMakerRace()); |
| 1328 | if (!caravan_cre_raw || !maker_cre_raw) |
| 1329 | return DEFAULT_WAR_MULTIPLIER; |
| 1330 | |
| 1331 | if (caravan_cre_raw->adultsize < ((maker_cre_raw->adultsize * 6) / 7)) |
| 1332 | return DEFAULT_WAR_MULTIPLIER; |
| 1333 | if (caravan_cre_raw->adultsize > ((maker_cre_raw->adultsize * 8) / 7)) |
| 1334 | return DEFAULT_WAR_MULTIPLIER; |
| 1335 | break; |
| 1336 | } |
| 1337 | case SHIELD: |
| 1338 | case AMMO: |
| 1339 | case BACKPACK: |
| 1340 | case QUIVER: |
| 1341 | break; |
| 1342 | default: |
| 1343 | return DEFAULT_WAR_MULTIPLIER; |
| 1344 | } |
| 1345 | return war_alignment; |
| 1346 | } |
| 1347 | |
| 1348 | static const int32_t DEFAULT_AGREEMENT_MULTIPLIER = 128; |
| 1349 | |