mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Code cleanup and better comments
This commit is contained in:
+1
-1
@@ -662,7 +662,7 @@ ReloadReserve=-1
|
|||||||
;Set to 1 to change the counter in the 'Move Items' window to start with maximum number, except in the barter screen
|
;Set to 1 to change the counter in the 'Move Items' window to start with maximum number, except in the barter screen
|
||||||
ItemCounterDefaultMax=0
|
ItemCounterDefaultMax=0
|
||||||
|
|
||||||
;Set to 1 to set default value in 'Move Items' window to amount of caps that will balance the tables
|
;Set to 1 to enable caps auto-balancing: when dragging caps between tables in the barter screen, 'Move Items' window will be shown with correct number pre-filled that balances the tables
|
||||||
ItemCounterAutoCaps=0
|
ItemCounterAutoCaps=0
|
||||||
|
|
||||||
;Set to 1 to leave the music playing in dialogue with talking heads
|
;Set to 1 to leave the music playing in dialogue with talking heads
|
||||||
|
|||||||
@@ -100,14 +100,14 @@ static void __declspec(naked) OverrideCost_BarterPriceHook() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BarterGetTableCosts(long* outPcTableCost, long* outNpcTableCost) {
|
void BarterPriceHook_GetLastCosts(long& outPcTableCost, long& outNpcTableCost) {
|
||||||
if (!HookScripts::HookHasScript(HOOK_BARTERPRICE)) {
|
if (!HookScripts::HookHasScript(HOOK_BARTERPRICE)) {
|
||||||
*outPcTableCost = fo::func::item_total_cost(fo::var::ptable);
|
outPcTableCost = fo::func::item_total_cost(fo::var::ptable);
|
||||||
*outNpcTableCost = fo::func::barter_compute_value(fo::var::obj_dude, fo::var::target_stack[0]);
|
outNpcTableCost = fo::func::barter_compute_value(fo::var::obj_dude, fo::var::target_stack[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*outPcTableCost = lastTableCostPC;
|
outPcTableCost = lastTableCostPC;
|
||||||
*outNpcTableCost = lastTableCostNPC;
|
outNpcTableCost = lastTableCostNPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fo::GameObject* sourceSkillOn = nullptr;
|
static fo::GameObject* sourceSkillOn = nullptr;
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ void Inject_RollCheckHook();
|
|||||||
|
|
||||||
long PerceptionRangeHook_Invoke(fo::GameObject* watcher, fo::GameObject* target, long type, long result);
|
long PerceptionRangeHook_Invoke(fo::GameObject* watcher, fo::GameObject* target, long type, long result);
|
||||||
|
|
||||||
void BarterGetTableCosts(long* outPcTableCost, long* outNpcTableCost);
|
void BarterPriceHook_GetLastCosts(long& outPcTableCost, long& outNpcTableCost);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-15
@@ -620,31 +620,27 @@ end:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static long CalculateSuggestedMoveCount(fo::GameObject* item, long maxQuantity, bool fromPlayer, bool fromInventory) {
|
static long CalculateSuggestedMoveCount(fo::GameObject* item, long maxQuantity, bool fromPlayer, bool fromInventory) {
|
||||||
if (maxQuantity <= 1) {
|
// This is an exact copy of logic from https://github.com/alexbatalov/fallout2-ce/pull/311
|
||||||
return maxQuantity;
|
|
||||||
}
|
|
||||||
long suggestedValue = 1;
|
|
||||||
if (item->protoId == fo::PID_BOTTLE_CAPS && !fo::var::dialog_target_is_party) {
|
if (item->protoId == fo::PID_BOTTLE_CAPS && !fo::var::dialog_target_is_party) {
|
||||||
// Calculate change money automatically
|
// Calculate change money automatically
|
||||||
long totalCostPlayer;
|
long totalCostPlayer;
|
||||||
long totalCostNpc;
|
long totalCostNpc;
|
||||||
BarterGetTableCosts(&totalCostPlayer, &totalCostNpc);
|
BarterPriceHook_GetLastCosts(totalCostPlayer, totalCostNpc);
|
||||||
// Actor's balance: negative - the actor must add money to balance the tables and vice versa
|
// Actor's balance: negative - the actor must add money to balance the tables and vice versa
|
||||||
long balance = fromPlayer ? totalCostPlayer - totalCostNpc : totalCostNpc - totalCostPlayer;
|
long balance = fromPlayer ? totalCostPlayer - totalCostNpc : totalCostNpc - totalCostPlayer;
|
||||||
|
|
||||||
if ((balance < 0 && fromInventory) || (balance > 0 && !fromInventory)) {
|
if ((balance < 0 && fromInventory) || (balance > 0 && !fromInventory)) {
|
||||||
suggestedValue = min(std::abs(balance), maxQuantity);
|
return min(std::abs(balance), maxQuantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return suggestedValue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool itemCounterDefaultMax;
|
static bool itemCounterDefaultMax;
|
||||||
static bool itemCounterAutoCaps;
|
static bool itemCounterAutoCaps;
|
||||||
static long __fastcall CalculateDefaultMoveCount(fo::GameObject* item, DWORD retAddr, DWORD maxValue) {
|
static long __fastcall CalculateDefaultMoveCount(DWORD maybeItem, DWORD retAddr, DWORD maxValue) {
|
||||||
maxValue = min(maxValue, 99999); // capped like in vanilla
|
maxValue = min(maxValue, 99999); // capped like in vanilla
|
||||||
if ((GetLoopFlags() & BARTER) != 0) {
|
if ((GetLoopFlags() & BARTER) != 0) {
|
||||||
if (itemCounterAutoCaps && maxValue > 0) {
|
if (itemCounterAutoCaps && maxValue > 1) {
|
||||||
bool fromPlayer;
|
bool fromPlayer;
|
||||||
bool fromInventory;
|
bool fromInventory;
|
||||||
switch (retAddr) {
|
switch (retAddr) {
|
||||||
@@ -667,7 +663,8 @@ static long __fastcall CalculateDefaultMoveCount(fo::GameObject* item, DWORD ret
|
|||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return CalculateSuggestedMoveCount(item, maxValue, fromPlayer, fromInventory);
|
// maybeItem may not contain object pointer in all cases, but it does in all 4 from above.
|
||||||
|
return CalculateSuggestedMoveCount((fo::GameObject*)maybeItem, maxValue, fromPlayer, fromInventory);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -676,13 +673,13 @@ static long __fastcall CalculateDefaultMoveCount(fo::GameObject* item, DWORD ret
|
|||||||
|
|
||||||
static void __declspec(naked) do_move_timer_hack() {
|
static void __declspec(naked) do_move_timer_hack() {
|
||||||
__asm {
|
__asm {
|
||||||
pushadc;
|
push ecx;
|
||||||
push ebp; // max
|
push ebp; // max
|
||||||
mov edx, dword ptr[esp + 40]; // return address
|
mov edx, dword ptr[esp + 32]; // return address
|
||||||
mov ecx, dword ptr[esp + 28]; // item
|
mov ecx, dword ptr[esp + 20]; // item, potentially
|
||||||
call CalculateDefaultMoveCount;
|
call CalculateDefaultMoveCount;
|
||||||
mov ebx, eax;
|
mov ebx, eax;
|
||||||
popadc;
|
pop ecx;
|
||||||
retn;
|
retn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user