Simplyfy logic to calc suggested amount of barter money

This commit is contained in:
Ivan Sokolov 2023-06-22 00:38:18 +08:00
parent a949178e30
commit 0e31ac4753
1 changed files with 8 additions and 21 deletions

View File

@ -272,7 +272,7 @@ static void _container_exit(int keyCode, int inventoryWindowType);
static int _drop_into_container(Object* a1, Object* a2, int a3, Object** a4, int quantity);
static int _drop_ammo_into_weapon(Object* weapon, Object* ammo, Object** a3, int quantity, int keyCode);
static void _draw_amount(int value, int inventoryWindowType);
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int suggestedValue=1);
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int defaultValue=1);
static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item);
static int inventoryQuantityWindowFree(int inventoryWindowType);
@ -4771,24 +4771,11 @@ static int _barter_get_quantity_moved_items(
// Calculate change money automatically
int totalCostPlayer = objectGetCost(_ptable);
int totalCostNpc = _barter_compute_value(gDude, _target_stack[0]);
int balance = totalCostPlayer - totalCostNpc;
bool balancePositive = true;
if (balance < 0) {
balancePositive = false;
balance = -balance;
}
// fromPlayer | fromInventory | balancePositive | suggestedVale
// 0 | 0 | 0 | abs(balance)
// 0 | 0 | 1 | 1
// 0 | 1 | 0 | 1
// 0 | 1 | 1 | balance
// 1 | 0 | 0 | 1
// 1 | 0 | 1 | balance
// 1 | 1 | 0 | abs(balance)
// 1 | 1 | 1 | 1
// if balance 0 then suggestedVale is 1
if (balance != 0 && !(fromPlayer ^ fromInventory ^ balancePositive)) {
suggestedValue = std::min(balance, maxQuantity);
// Actor's balance: negative - the actor must add money to balance the tables and vice versa
int balance = fromPlayer ? totalCostPlayer - totalCostNpc : totalCostNpc - totalCostPlayer;
if ( (balance < 0 && fromInventory) || (balance > 0 && !fromInventory) ) {
suggestedValue = std::min(std::abs(balance), maxQuantity);
}
}
return inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, item, maxQuantity, suggestedValue);
@ -5613,7 +5600,7 @@ static void _draw_amount(int value, int inventoryWindowType)
}
// 0x47688C
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int suggestedValue)
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int defaultValue)
{
ScopedGameMode gm(GameMode::kCounter);
@ -5622,11 +5609,11 @@ static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int ma
int value;
int min;
if (inventoryWindowType == INVENTORY_WINDOW_TYPE_MOVE_ITEMS) {
value = suggestedValue;
if (max > 99999) {
max = 99999;
}
min = 1;
value = std::clamp(defaultValue, min, max);
} else {
value = 60;
min = 10;