From 3b3abc2bc6c100e74d4df28f9a69e043fd7ca370 Mon Sep 17 00:00:00 2001 From: Flugente Date: Wed, 17 Jun 2020 20:21:39 +0000 Subject: [PATCH] We can play external dialogue lines for NPC merchants via the lua function HandleNPCMerchantQuote(...) For more info, see http://thepit.ja-galaxy-forum.com/index.php?t=msg&th=20611&goto=360388&#msg_360388 Requires GameDir >= r2550. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8821 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/LuaInitNPCs.cpp | 14 ++++++++++++++ Strategic/LuaInitNPCs.h | 1 + Tactical/Dialogue Control.cpp | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index e2504702..9dceea5d 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -13365,6 +13365,20 @@ void LuaHandleReplaceQuote( UINT8 ubProfile, UINT16 usQuoteNum ) LuaFunction( _LS.L, "HandleReplaceQuote" ).Param( ubProfile ).Param( usQuoteNum ).Call( 2 ); } +void LuaHandleNPCMerchantQuote( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 ubMerchantID, UINT8 ubBodyType, UINT16 usQuoteNum ) +{ + const char* filename = "scripts\\Overhead.lua"; + + LuaScopeState _LS( true ); + + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); + + LuaFunction( _LS.L, "HandleNPCMerchantQuote" ).Param( sSectorX ).Param( sSectorY ).Param( bSectorZ ).Param( ubMerchantID ).Param( ubBodyType ).Param( usQuoteNum ).Call( 6 ); +} + void LuaAddArmsDealerAdditionalIntelData() { const char* filename = "scripts\\Overhead.lua"; diff --git a/Strategic/LuaInitNPCs.h b/Strategic/LuaInitNPCs.h index fd9ef4ca..ed419d1b 100644 --- a/Strategic/LuaInitNPCs.h +++ b/Strategic/LuaInitNPCs.h @@ -94,6 +94,7 @@ extern BOOLEAN LetLuaMusicControl(UINT8 Init); void LuaHandleAdditionalDialogue( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT8 ubProfile, INT32 iFaceIndex, UINT16 usEventNr, UINT32 aData1, UINT32 aData2, UINT32 aData3 ); void LuaHandleReplaceQuote( UINT8 ubProfile, UINT16 usQuoteNum ); +void LuaHandleNPCMerchantQuote( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 ubMerchantID, UINT8 ubBodyType, UINT16 usQuoteNum ); void LuaAddArmsDealerAdditionalIntelData(); void LuaAddPhotoData( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, INT32 sGridNo, INT8 bLevel, UINT8 ubPhotographerProfile, UINT16 room, UINT8 usTargetProfile ); void LuaGetPhotoData( UINT8 aType ); diff --git a/Tactical/Dialogue Control.cpp b/Tactical/Dialogue Control.cpp index f9eb537f..110fbe49 100644 --- a/Tactical/Dialogue Control.cpp +++ b/Tactical/Dialogue Control.cpp @@ -211,6 +211,7 @@ extern void HandlePendingInitConv( ); extern BOOLEAN WillMercRenew( SOLDIERTYPE *pSoldier, BOOLEAN fSayQuote ); extern void DrawFace( INT16 sCharNumber ); extern void LuaHandleReplaceQuote( UINT8 ubProfile, UINT16 usQuoteNum ); +extern void LuaHandleNPCMerchantQuote( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 ubMerchantID, UINT8 ubBodyType, UINT16 usQuoteNum ); // the next said quote will pause time BOOLEAN fPausedTimeDuringQuote = FALSE; @@ -2045,6 +2046,9 @@ BOOLEAN SpecialCharacterDialogueEventWithExtraParam( UINT32 uiSpecialEventFlag, return( TRUE ); } +extern INT8 gbSelectedArmsDealerID; +extern UINT8 gusIDOfCivTrader; + BOOLEAN ExecuteCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier ) { UINT32 uiSoundID; @@ -2146,6 +2150,22 @@ BOOLEAN ExecuteCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 // anv: have to do it now for single sounds subsequentsounds.ubMaxSndCounter = 0; + // Flugente: if this an NPC merchant we don't say anything normally. So instead we call lua so that modders can add dislogue of their own + if ( bUIHandlerID == DIALOGUE_SHOPKEEPER_UI + && ubCharacterNum == NO_PROFILE + && iFaceIndex == -1 + && gusIDOfCivTrader != NOBODY ) + { + SOLDIERTYPE* pShopkeeper = MercPtrs[gusIDOfCivTrader]; + + if ( pShopkeeper ) + { + LuaHandleNPCMerchantQuote( gWorldSectorX, gWorldSectorY, gbWorldSectorZ, gbSelectedArmsDealerID, pShopkeeper->ubBodyType, usQuoteNum ); + + return TRUE; + } + } + // Check face index CHECKF( iFaceIndex != -1 );