From b988df876f36e373ca21e0001a91aefe87ecdd50 Mon Sep 17 00:00:00 2001 From: Flugente Date: Thu, 8 Nov 2018 20:11:25 +0000 Subject: [PATCH] Change: Regardless of whether or not an IMP is created via old/new method or by loading an existing callsign, gear costs exceeding IMP_PROFILE_COST are deducted extra. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8638 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Laptop/IMP Confirm.cpp | 37 ++++++++++++++++++++++++++----------- Laptop/IMP Confirm.h | 2 +- Laptop/IMP Gear.cpp | 2 +- Laptop/IMP MainPage.cpp | 2 +- Laptop/IMP Text System.cpp | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Laptop/IMP Confirm.cpp b/Laptop/IMP Confirm.cpp index a2149bf6..2509f738 100644 --- a/Laptop/IMP Confirm.cpp +++ b/Laptop/IMP Confirm.cpp @@ -323,7 +323,7 @@ void BtnIMPConfirmYes(GUI_BUTTON *btn,INT32 reason) // silversurfer: We need to store the profile cost here because right now our new IMP doesn't occupy a slot yet. // However function iGetProfileCost() will already calculate price including that slot. We would charge too much money after the IMP is created below. - INT32 iIMPCost = iGetProfileCost(); + INT32 iIMPCost = GetProfileCost(TRUE); if( LaptopSaveInfo.iCurrentBalance < iIMPCost ) { // not enough @@ -580,6 +580,21 @@ void DistributeInitialGear(MERCPROFILESTRUCT *pProfile) } } +INT32 GetEquippedGearCost( MERCPROFILESTRUCT *pProfile ) +{ + INT32 cost = 0; + + for ( int i = INV_START_POS; iinv[i] != NOTHING ) + { + cost += pProfile->bInvNumber[i] * Item[pProfile->inv[i]].usPrice; + } + } + + return cost; +} + void GiveItemsToPC( UINT8 ubProfileId ) { MERCPROFILESTRUCT *pProfile; @@ -1517,14 +1532,7 @@ BOOLEAN LoadImpCharacter( STR nickName ) if (iProfileId != -1) { LaptopSaveInfo.iIMPIndex = iProfileId; - - // silversurfer: Store current IMP cost. Function iGetProfileCost() already takes the new slot into account. - // If we create the IMP first we would charge too much. - INT32 iIMPCost = iGetProfileCost(); - - // read in the profile - //if ( !gMercProfiles[ iProfileId ].Load(hFile, false) ) - + // anv: before loading profile we need to set guiCurrentSaveGameVersion to profile's version // and set it back to SAVE_GAME_VERSION right after or else new saves will be broken! guiCurrentSaveGameVersion = version; @@ -1555,6 +1563,13 @@ BOOLEAN LoadImpCharacter( STR nickName ) //CHRISL: At this point, we need to resort profile inventory so that NewInv items don't accidentally appear in OldInv DistributeInitialGear(&gMercProfiles[iProfileId]); + // silversurfer: Store current IMP cost. Function iGetProfileCost() already takes the new slot into account. + // If we create the IMP first we would charge too much. + INT32 iIMPCost = GetProfileCost(FALSE); + + // Flugente: as we do not store the cost of the gear in the IMP file, we have to determine the cost here + iIMPCost += max(0, GetEquippedGearCost( &gMercProfiles[iProfileId] ) - gGameExternalOptions.iIMPProfileCost ); + // Changed to find actual IMP cost - SANDRO if( LaptopSaveInfo.iCurrentBalance < iIMPCost ) { @@ -1748,10 +1763,10 @@ void GiveIMPItems( MERCPROFILESTRUCT *pProfile, INT8 abilityValue, UINT8 typeInd } // SANDRO - Function to determine actual cost of profile -INT32 iGetProfileCost() +INT32 GetProfileCost( BOOLEAN aWithGearCost ) { // Flugente: aditional imp gear cost - INT32 impgearcost = GetIMPGearCost(); + INT32 impgearcost = aWithGearCost ? GetIMPGearCost() : 0; if (gGameExternalOptions.fDynamicIMPProfileCost) { diff --git a/Laptop/IMP Confirm.h b/Laptop/IMP Confirm.h index 7ce9f6a6..ff6bb00b 100644 --- a/Laptop/IMP Confirm.h +++ b/Laptop/IMP Confirm.h @@ -71,7 +71,7 @@ void ResetIMPCharactersEyesAndMouthOffsets( UINT8 ubMercProfileID ); BOOLEAN ImpExists ( STR fileName ); -INT32 iGetProfileCost( void ); // added by SANDRO +INT32 GetProfileCost( BOOLEAN aWithGearCost ); // added by SANDRO void MakeProfileInvItemAnySlot( MERCPROFILESTRUCT *pProfile, UINT16 usItem, UINT8 ubStatus, UINT8 ubHowMany ); diff --git a/Laptop/IMP Gear.cpp b/Laptop/IMP Gear.cpp index bf65254c..1e34d923 100644 --- a/Laptop/IMP Gear.cpp +++ b/Laptop/IMP Gear.cpp @@ -568,7 +568,7 @@ void BtnIMPGearFinishCallback( GUI_BUTTON *btn, INT32 reason ) INT32 GetIMPGearCost( ) { if ( IsIMPGearUsed( ) ) - return max( 0, gIMPGearCost - 3000 ); + return max( 0, gIMPGearCost - gGameExternalOptions.iIMPProfileCost ); return 0; } diff --git a/Laptop/IMP MainPage.cpp b/Laptop/IMP MainPage.cpp index e8dfd41d..ebe6f9ac 100644 --- a/Laptop/IMP MainPage.cpp +++ b/Laptop/IMP MainPage.cpp @@ -404,7 +404,7 @@ void BtnIMPMainPageBeginCallback(GUI_BUTTON *btn,INT32 reason) else { //if( LaptopSaveInfo.iCurrentBalance < COST_OF_PROFILE ) - if( LaptopSaveInfo.iCurrentBalance < iGetProfileCost() ) // SANDRO - changed to find actual profile cost in IMPConfirm + if( LaptopSaveInfo.iCurrentBalance < GetProfileCost(TRUE) ) // SANDRO - changed to find actual profile cost in IMPConfirm { DoLapTopMessageBox( MSG_BOX_IMP_STYLE, pImpPopUpStrings[ 3 ], LAPTOP_SCREEN, MSG_BOX_FLAG_OK, BeginMessageBoxCallBack); diff --git a/Laptop/IMP Text System.cpp b/Laptop/IMP Text System.cpp index fb907af3..2829a348 100644 --- a/Laptop/IMP Text System.cpp +++ b/Laptop/IMP Text System.cpp @@ -351,7 +351,7 @@ void PrintImpText( void ) //LoadAndDisplayIMPText( LAPTOP_SCREEN_UL_X + 160, LAPTOP_SCREEN_WEB_UL_Y + 145, ( 200 ), IMP_CON_3 , FONT12ARIAL, FONT_WHITE, TRUE, 0); // SANDRO - changed to show exact cost of profile CHAR16 chPayCost[1000]; - swprintf( chPayCost, gzIMPProfileCostText[ 0 ], iGetProfileCost() ); + swprintf( chPayCost, gzIMPProfileCostText[ 0 ], GetProfileCost(TRUE) ); DisplayWrappedString( LAPTOP_SCREEN_UL_X + 160, LAPTOP_SCREEN_WEB_UL_Y + 145, ( 200 ), 2, FONT12ARIAL, FONT_WHITE, chPayCost,FONT_BLACK,FALSE,LEFT_JUSTIFIED); break;