diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index ab98eaf4..51634477 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -873,6 +873,7 @@ static int l_SetMiniGameType( lua_State *L ); static int l_SoldierSpendMoney( lua_State *L ); static int l_SetAdditionalDialogue( lua_State *L ); +static int l_SetReplaceDialogue( lua_State *L ); static int l_PlaySound( lua_State *L ); static int l_AddArmsDealerAdditionalIntelDataItem( lua_State *L ); @@ -1758,6 +1759,7 @@ void IniFunction(lua_State *L, BOOLEAN bQuests ) lua_register( L, "SoldierSpendMoney", l_SoldierSpendMoney ); lua_register( L, "SetAdditionalDialogue", l_SetAdditionalDialogue ); + lua_register( L, "SetReplaceDialogue", l_SetReplaceDialogue ); lua_register( L, "PlaySound", l_PlaySound ); lua_register( L, "AddArmsDealerAdditionalIntelDataItem", l_AddArmsDealerAdditionalIntelDataItem ); @@ -12879,7 +12881,7 @@ static int l_AddVolunteers( lua_State *L ) { if ( lua_gettop( L ) ) { - FLOAT num = lua_tointeger( L, 1 ); + FLOAT num = lua_tonumber( L, 1 ); AddVolunteers( num ); } @@ -13238,6 +13240,33 @@ static int l_SetAdditionalDialogue( lua_State *L ) return 0; } +extern void SetSoundString( const char* aStr ); + +static int l_SetReplaceDialogue( lua_State *L ) +{ + if ( lua_gettop( L ) >= 2 ) + { + size_t len = 0; + const char* str = lua_tolstring( L, 1, &len ); + + { + size_t len = 0; + const char* str = lua_tolstring( L, 2, &len ); + + CHAR16 quote_str[1000]; + + MultiByteToWideChar( CP_UTF8, 0, str, -1, quote_str, sizeof( quote_str ) / sizeof( quote_str[0] ) ); + quote_str[sizeof( quote_str ) / sizeof( quote_str[0] ) - 1] = '\0'; + + SetQuoteStr( quote_str ); + } + + SetSoundString( str ); + } + + return 0; +} + static int l_PlaySound( lua_State *L ) { if ( lua_gettop( L ) >= 1 ) @@ -13270,6 +13299,21 @@ void LuaHandleAdditionalDialogue( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, LuaFunction( _LS.L, "HandleAdditionalDialogue" ).Param( sSectorX ).Param( sSectorY ).Param( bSectorZ ).Param( ubProfile ).Param( iFaceIndex ).Param( usEventNr ).Param( aData1 ).Param( aData2 ).Param( aData3 ).Call( 9 ); } +void LuaHandleReplaceQuote( UINT8 ubProfile, UINT16 usQuoteNum ) +{ + const char* filename = "scripts\\Overhead.lua"; + + LuaScopeState _LS( true ); + + lua_register( _LS.L(), "CheckFact", l_CheckFact ); + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); + + LuaFunction( _LS.L, "HandleReplaceQuote" ).Param( ubProfile ).Param( usQuoteNum ).Call( 2 ); +} + void LuaAddArmsDealerAdditionalIntelData() { const char* filename = "scripts\\Overhead.lua"; diff --git a/Strategic/LuaInitNPCs.h b/Strategic/LuaInitNPCs.h index 912c3869..0a1a1b14 100644 --- a/Strategic/LuaInitNPCs.h +++ b/Strategic/LuaInitNPCs.h @@ -93,6 +93,7 @@ extern BOOLEAN LuaIDScripts(UINT8 Init, UINT8 ubTargetNPC, UINT16 usActionCode, 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 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 68ac2631..7bb02a38 100644 --- a/Tactical/Dialogue Control.cpp +++ b/Tactical/Dialogue Control.cpp @@ -192,6 +192,7 @@ INT32 giTextBoxOverlay = -1; BOOLEAN gfFacePanelActive = FALSE; UINT32 guiScreenIDUsedWhenUICreated; CHAR16 gzQuoteStr[ QUOTE_MESSAGE_SIZE ]; +CHAR8 gzSoundString[164]; MOUSE_REGION gTextBoxMouseRegion; MOUSE_REGION gFacePopupMouseRegion; BOOLEAN gfUseAlternateDialogueFile = FALSE; @@ -2041,7 +2042,6 @@ BOOLEAN SpecialCharacterDialogueEventWithExtraParam( UINT32 uiSpecialEventFlag, BOOLEAN ExecuteCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier ) { - CHAR8 zSoundString[ 164 ]; UINT32 uiSoundID; SOLDIERTYPE *pSoldier; @@ -2144,28 +2144,25 @@ BOOLEAN ExecuteCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 // Check face index CHECKF( iFaceIndex != -1 ); - if ( !GetDialogue( ubCharacterNum, - usQuoteNum, DIALOGUESIZE, gzQuoteStr, &uiSoundID, zSoundString) ) + if ( !GetDialogue( ubCharacterNum, usQuoteNum, DIALOGUESIZE, gzQuoteStr, &uiSoundID, gzSoundString ) ) { return( FALSE ); } + // Flugente: hijack the quote for possible replacement by additional dialogue + extern void LuaHandleReplaceQuote( UINT8 ubProfile, UINT16 usQuoteNum ); + + LuaHandleReplaceQuote( ubCharacterNum, usQuoteNum ); + // sevenfm: stop high speed timer for any talking face if (IsFastForwardMode()) { SetFastForwardMode(FALSE); } - if( bUIHandlerID == DIALOGUE_EXTERNAL_NPC_UI ) - { - // external NPC - SetFaceTalking( iFaceIndex , zSoundString, gzQuoteStr, RATE_11025, 30, 1, MIDDLEPAN ); - } - else - { - // start "talking" system (portrait animation and start wav sample) - SetFaceTalking( iFaceIndex, zSoundString, gzQuoteStr, RATE_11025, 30, 1, MIDDLEPAN ); - } + // start "talking" system (portrait animation and start wav sample) + SetFaceTalking( iFaceIndex, gzSoundString, gzQuoteStr, RATE_11025, 30, 1, MIDDLEPAN ); + // pSoldier can be null here... ( if NOT from an alive soldier ) CreateTalkingUI( bUIHandlerID, iFaceIndex, ubCharacterNum, pSoldier, gzQuoteStr ); @@ -2229,6 +2226,12 @@ void SetQuoteStr( STR16 aStr ) wcscpy( gzQuoteStr, aStr ); } +void SetSoundString( const char* aStr ) +{ + //Copy the original string over to the temp string + strcpy( gzSoundString, aStr ); +} + BOOLEAN LuaCallsToDoDialogueStuff( UINT8 ubProfile, INT32 iFaceIndex, const char* azSoundString ) { SOLDIERTYPE *pSoldier = FindSoldierByProfileID( ubProfile, TRUE );