diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index 3219244e..e994b880 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -839,6 +839,8 @@ static int l_ProfilesStrategicInsertionData (lua_State *L); static int l_ResetBoxers( lua_State *L ); +static int l_AddVolunteers( lua_State *L ); + using namespace std; UINT16 idProfil; @@ -1686,7 +1688,8 @@ void IniFunction(lua_State *L, BOOLEAN bQuests ) lua_register(L,"EnvBeginRainStorm", l_EnvBeginRainStorm); lua_register(L,"EnvEndRainStorm", l_EnvEndRainStorm); - + + lua_register( L, "AddVolunteers", l_AddVolunteers ); } #ifdef NEWMUSIC BOOLEAN LetLuaMusicControl(UINT8 Init) @@ -2592,6 +2595,38 @@ BOOLEAN LuaHandleQuestCodeOnSector( INT16 sSectorX, INT16 sSectorY, INT8 bSector return true; } +void LuaHandleSectorLiberation( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, BOOLEAN fFirstTime ) +{ + const char* filename = "scripts\\strategicmap.lua"; + + LuaScopeState _LS( true ); + + lua_register( _LS.L( ), "CheckFact", l_CheckFact ); + lua_register( _LS.L( ), "AddVolunteers", l_AddVolunteers ); + IniFunction( _LS.L( ), TRUE ); + IniGlobalGameSetting( _LS.L( ) ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); + + LuaFunction( _LS.L, "HandleSectorLiberation" ).Param( sSectorX ).Param( sSectorY ).Param( bSectorZ ).Param( fFirstTime ).Call( 4 ); +} + +void LuaRecruitRPCAdditionalHandling( UINT8 usProfile ) +{ + const char* filename = "scripts\\strategicmap.lua"; + + LuaScopeState _LS( true ); + + lua_register( _LS.L( ), "CheckFact", l_CheckFact ); + lua_register( _LS.L( ), "AddVolunteers", l_AddVolunteers ); + IniFunction( _LS.L( ), TRUE ); + IniGlobalGameSetting( _LS.L( ) ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); + + LuaFunction( _LS.L, "RecruitRPCAdditionalHandling" ).Param( usProfile ).Call( 1 ); +} + BOOLEAN LetLuaGameInit(UINT8 Init) { const char* filename = "scripts\\GameInit.lua"; @@ -12919,4 +12954,18 @@ static int l_SetStartingCashDifLevel (lua_State *L) } return 0; -} \ No newline at end of file +} + +// add volunteers +static int l_AddVolunteers( lua_State *L ) +{ + if ( lua_gettop( L ) ) + { + FLOAT num = lua_tointeger( L, 1 ); + + AddVolunteers( num ); + } + + return 0; +} + diff --git a/Strategic/LuaInitNPCs.h b/Strategic/LuaInitNPCs.h index ff2977d4..efbb0a20 100644 --- a/Strategic/LuaInitNPCs.h +++ b/Strategic/LuaInitNPCs.h @@ -58,6 +58,10 @@ extern BOOLEAN LuaHandleNPCTeamMemberDeath(UINT8 ProfileId, UINT8 Init); extern BOOLEAN LuaCheckForKingpinsMoneyMissing( BOOLEAN fFirstCheck, UINT8 Init); extern BOOLEAN LuaHandleQuestCodeOnSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT8 Init); //extern BOOLEAN LuaHandleQuestCodeOnSectorEntry( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT8 Init); + +void LuaHandleSectorLiberation( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, BOOLEAN fFirstTime ); +void LuaRecruitRPCAdditionalHandling( UINT8 usProfile ); + extern BOOLEAN LuaHandleDelayedItemsArrival( UINT32 uiReason, UINT8 Init); extern BOOLEAN LetLuaHandleNPCSystemEvent( UINT32 uiEvent, UINT8 Init); diff --git a/Strategic/Player Command.cpp b/Strategic/Player Command.cpp index 737ea0e2..e55f09c3 100644 --- a/Strategic/Player Command.cpp +++ b/Strategic/Player Command.cpp @@ -29,6 +29,7 @@ #include "PopUpBox.h" #include "CampaignStats.h" // added by Flugente #include "Town Militia.h" // added by Flugente + #include "LuaInitNPCs.h" // added by Flugente #endif #include "postalservice.h" @@ -387,11 +388,6 @@ BOOLEAN SetThisSectorAsPlayerControlled( INT16 sMapX, INT16 sMapY, INT8 bMapZ, B // Flugente: campaign stats if ( !SectorInfo[ SECTOR( sMapX, sMapY ) ].fSurfaceWasEverPlayerControlled ) { - //UINT8 ubSector = (UINT8)SECTOR( sMapX, sMapY ); - //UINT8 ubTraverseType = SectorInfo[ ubSector ].ubTraversability[ 4 ]; - - //if ( ubTraverseType == ) - UINT8 townid = GetTownIdForSector( sMapX, sMapY ); if ( townid != BLANK_SECTOR ) { @@ -407,6 +403,9 @@ BOOLEAN SetThisSectorAsPlayerControlled( INT16 sMapX, INT16 sMapY, INT8 bMapZ, B } } + // Flugente: if we take the surface sector for the first time, script-defined actions might happen + LuaHandleSectorLiberation( sMapX, sMapY, bMapZ, !SectorInfo[SECTOR( sMapX, sMapY )].fSurfaceWasEverPlayerControlled ); + if ( bMapZ == 0 ) { SectorInfo[ SECTOR( sMapX, sMapY ) ].fSurfaceWasEverPlayerControlled = TRUE; diff --git a/Tactical/Soldier Profile.cpp b/Tactical/Soldier Profile.cpp index 783a8d93..bbf25dec 100644 --- a/Tactical/Soldier Profile.cpp +++ b/Tactical/Soldier Profile.cpp @@ -51,6 +51,7 @@ #include "strategicmap.h" // added by SANDRO #include "drugs and alcohol.h" // added by Flugente #include "Campaign.h" + #include "LuaInitNPCs.h" // added by Flugente #endif #include "aim.h" @@ -1984,6 +1985,10 @@ BOOLEAN RecruitRPC( UINT8 ubCharNum ) //If this is a special NPC, play a quote from the team mates HandlePlayingQuoteWhenHiringNpc( pNewSoldier->ubProfile ); #endif + + // Flugente: external scripts might have extra functionality on recruiting someone + LuaRecruitRPCAdditionalHandling( ubCharNum ); + return( TRUE ); }