Compare commits

...
Author SHA1 Message Date
phobos2077 39b369f7df Fix build after last merge 2024-06-07 17:53:37 +02:00
phobos2077 76ac71bc08 Merge remote-tracking branch 'y0lo/feature/y0lo/fast-barter-auto-calc-change-money' into sfall-port
# Conflicts:
#	src/inventory.cc
2024-06-04 15:03:52 +02:00
Ivan Sokolov 0e31ac4753 Simplyfy logic to calc suggested amount of barter money 2023-06-22 00:38:18 +08:00
Ivan Sokolov a949178e30 Set recomended ammount of money to be moved for barter
The feature works in any direction to move from/to player/npc and from/to inventory/table
2023-06-21 21:13:06 +08:00
Ivan Sokolov 0e806d9be3 Add feature for automatic calculation of barter money 2023-06-20 17:21:10 +08:00
+33 -7
View File
@@ -269,6 +269,7 @@ static void inventoryWindowOpenContextMenu(int eventCode, int inventoryWindowTyp
static InventoryMoveResult _move_inventory(Object* item, int slotIndex, Object* targetObj, bool isPlanting); static InventoryMoveResult _move_inventory(Object* item, int slotIndex, Object* targetObj, bool isPlanting);
static int _barter_compute_value(Object* dude, Object* npc); static int _barter_compute_value(Object* dude, Object* npc);
static int _barter_attempt_transaction(Object* dude, Object* offerTable, Object* npc, Object* barterTable); static int _barter_attempt_transaction(Object* dude, Object* offerTable, Object* npc, Object* barterTable);
static int _barter_get_quantity_moved_items(Object* item, int maxQuantity, bool fromDude, bool fromInventory);
static void _barter_move_inventory(Object* item, int quantity, int slotIndex, int indexOffset, Object* npc, Object* sourceTable, bool fromDude); static void _barter_move_inventory(Object* item, int quantity, int slotIndex, int indexOffset, Object* npc, Object* sourceTable, bool fromDude);
static void _barter_move_from_table_inventory(Object* item, int quantity, int slotIndex, Object* npc, Object* sourceTable, bool fromDude); static void _barter_move_from_table_inventory(Object* item, int quantity, int slotIndex, Object* npc, Object* sourceTable, bool fromDude);
static void inventoryWindowRenderInnerInventories(int win, Object* leftTable, Object* rightTable, int draggedSlotIndex); static void inventoryWindowRenderInnerInventories(int win, Object* leftTable, Object* rightTable, int draggedSlotIndex);
@@ -277,7 +278,7 @@ static void _container_exit(int keyCode, int inventoryWindowType);
static int _drop_into_container(Object* container, Object* item, int sourceIndex, Object** itemSlot, int quantity); static int _drop_into_container(Object* container, Object* item, int sourceIndex, Object** itemSlot, int quantity);
static int _drop_ammo_into_weapon(Object* weapon, Object* ammo, Object** ammoItemSlot, int quantity, int keyCode); static int _drop_ammo_into_weapon(Object* weapon, Object* ammo, Object** ammoItemSlot, int quantity, int keyCode);
static void _draw_amount(int value, int inventoryWindowType); static void _draw_amount(int value, int inventoryWindowType);
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int maximum); static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int defaultValue = 1);
static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item); static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item);
static int inventoryQuantityWindowFree(int inventoryWindowType); static int inventoryQuantityWindowFree(int inventoryWindowType);
@@ -4761,6 +4762,31 @@ static int _barter_attempt_transaction(Object* dude, Object* offerTable, Object*
return 0; return 0;
} }
static int _barter_get_quantity_moved_items(
Object* item,
int maxQuantity,
bool fromPlayer,
bool fromInventory
) {
if (maxQuantity <= 1) {
return maxQuantity;
}
int suggestedValue = 1;
if (item->pid == PROTO_ID_MONEY && !gGameDialogSpeakerIsPartyMember) {
// Calculate change money automatically
int totalCostPlayer = objectGetCost(_ptable);
int totalCostNpc = _barter_compute_value(gDude, _target_stack[0]);
// 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);
}
// 0x474DAC // 0x474DAC
static void _barter_move_inventory(Object* item, int quantity, int slotIndex, int indexOffset, Object* npc, Object* sourceTable, bool fromDude) static void _barter_move_inventory(Object* item, int quantity, int slotIndex, int indexOffset, Object* npc, Object* sourceTable, bool fromDude)
{ {
@@ -4819,7 +4845,7 @@ static void _barter_move_inventory(Object* item, int quantity, int slotIndex, in
if (fromDude) { if (fromDude) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y)) { if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, item, quantity) : 1; int quantityToMove = _barter_get_quantity_moved_items(item, quantity, true, true);
if (quantityToMove != -1) { if (quantityToMove != -1) {
if (itemMoveForce(_inven_dude, sourceTable, item, quantityToMove) == -1) { if (itemMoveForce(_inven_dude, sourceTable, item, quantityToMove) == -1) {
// There is no space left for that item. // There is no space left for that item.
@@ -4832,7 +4858,7 @@ static void _barter_move_inventory(Object* item, int quantity, int slotIndex, in
} }
} else { } else {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y)) { if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, item, quantity) : 1; int quantityToMove = _barter_get_quantity_moved_items(item, quantity, false, true);
if (quantityToMove != -1) { if (quantityToMove != -1) {
if (itemMoveForce(npc, sourceTable, item, quantityToMove) == -1) { if (itemMoveForce(npc, sourceTable, item, quantityToMove) == -1) {
// You cannot pick that up. You are at your maximum weight capacity. // You cannot pick that up. You are at your maximum weight capacity.
@@ -4906,7 +4932,7 @@ static void _barter_move_from_table_inventory(Object* item, int quantity, int sl
if (fromDude) { if (fromDude) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y)) { if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, item, quantity) : 1; int quantityToMove = _barter_get_quantity_moved_items(item, quantity, true, false);
if (quantityToMove != -1) { if (quantityToMove != -1) {
if (itemMoveForce(sourceTable, _inven_dude, item, quantityToMove) == -1) { if (itemMoveForce(sourceTable, _inven_dude, item, quantityToMove) == -1) {
// There is no space left for that item. // There is no space left for that item.
@@ -4919,7 +4945,7 @@ static void _barter_move_from_table_inventory(Object* item, int quantity, int sl
} }
} else { } else {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y)) { if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, item, quantity) : 1; int quantityToMove = _barter_get_quantity_moved_items(item, quantity, false, false);
if (quantityToMove != -1) { if (quantityToMove != -1) {
if (itemMoveForce(sourceTable, npc, item, quantityToMove) == -1) { if (itemMoveForce(sourceTable, npc, item, quantityToMove) == -1) {
// You cannot pick that up. You are at your maximum weight capacity. // You cannot pick that up. You are at your maximum weight capacity.
@@ -5581,7 +5607,7 @@ static void _draw_amount(int value, int inventoryWindowType)
} }
// 0x47688C // 0x47688C
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max) static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max, int defaultValue)
{ {
ScopedGameMode gm(GameMode::kCounter); ScopedGameMode gm(GameMode::kCounter);
@@ -5590,11 +5616,11 @@ static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int ma
int value; int value;
int min; int min;
if (inventoryWindowType == INVENTORY_WINDOW_TYPE_MOVE_ITEMS) { if (inventoryWindowType == INVENTORY_WINDOW_TYPE_MOVE_ITEMS) {
value = 1;
if (max > 99999) { if (max > 99999) {
max = 99999; max = 99999;
} }
min = 1; min = 1;
value = std::clamp(defaultValue, min, max);
} else { } else {
value = 60; value = 60;
min = 10; min = 10;