From 9dfbc7d39491b65089f1633bfaa9399937fc2d15 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:29:28 +0200 Subject: [PATCH 1/3] Use correct gridno for XY conversion (#289) --- Tactical/Weapons.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index cdc60e02..4aea8f81 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -5692,7 +5692,7 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN if ( pBullet->fFragment == false) { INT16 sX, sY; - ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); if ( Item[usWeaponIndex].singleshotrocketlauncher ) { From bf01f87cb4a48f4e4c5df92516039a91ba68cb64 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:00:04 +0200 Subject: [PATCH 2/3] Revert "Cache result of evaluating strategicmap.lua (#32)" (#293) This reverts commit 8f22d13fd9d28c7a2a5b65ec1d10239615e9fa80. --- Strategic/LuaInitNPCs.cpp | 57 +++++++++++++++------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index be83d757..519dc005 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -13603,58 +13603,43 @@ static int l_GetNumHostilesInSector( lua_State *L ) void LuaGetIntelAndQuestMapData( INT32 aLevel ) { - static LuaScopeState _LS(true); - static bool isInitialized = false; + const char* filename = "scripts\\strategicmap.lua"; - // Initialize only once during lifetime of program - if (!isInitialized) - { - isInitialized = true; - IniFunction(_LS.L(), TRUE); - IniGlobalGameSetting(_LS.L()); - const char* filename = "scripts\\strategicmap.lua"; - SGP_THROW_IFFALSE(_LS.L.EvalFile(filename), _BS("Cannot open file: ") << filename << _BS::cget); - } + LuaScopeState _LS( true ); + + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); - IniGlobalGameSetting(_LS.L()); LuaFunction( _LS.L, "GetIntelAndQuestMapData" ).Param( aLevel ).Call( 1 ); } void SetFactoryLeftoverProgress( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usFacilityType, UINT16 usProductionNumber, INT32 sProgressLeft ) { - static LuaScopeState _LS(true); - static bool isInitialized = false; + const char* filename = "scripts\\strategicmap.lua"; - // Initialize only once during lifetime of program - if (!isInitialized) - { - isInitialized = true; - IniFunction(_LS.L(), TRUE); - IniGlobalGameSetting(_LS.L()); - const char* filename = "scripts\\strategicmap.lua"; - SGP_THROW_IFFALSE(_LS.L.EvalFile(filename), _BS("Cannot open file: ") << filename << _BS::cget); - } + LuaScopeState _LS( true ); + + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); - IniGlobalGameSetting(_LS.L()); LuaFunction( _LS.L, "SetFactoryLeftoverProgress" ).Param( sSectorX ).Param( sSectorY ).Param( bSectorZ ).Param( usFacilityType ).Param( usProductionNumber ).Param( sProgressLeft ).Call( 6 ); } INT32 GetFactoryLeftoverProgress( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usFacilityType, UINT16 usProductionNumber ) { - static LuaScopeState _LS( true ); - static bool isInitialized = false; + const char* filename = "scripts\\strategicmap.lua"; - // Initialize only once during lifetime of program - if (!isInitialized) - { - isInitialized = true; - IniFunction( _LS.L(), TRUE ); - IniGlobalGameSetting(_LS.L()); - const char* filename = "scripts\\strategicmap.lua"; - SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); - } + LuaScopeState _LS( true ); + + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile( filename ), _BS( "Cannot open file: " ) << filename << _BS::cget ); - IniGlobalGameSetting(_LS.L()); LuaFunction( _LS.L, "GetFactoryLeftoverProgress" ).Param( sSectorX ).Param( sSectorY ).Param( bSectorZ ).Param( usFacilityType ).Param( usProductionNumber ).Call( 5 ); if ( lua_gettop( _LS.L() ) >= 0 ) From e6c5f95d733c0dd3cc005ffe66d097bf869fdfce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Fa=C5=82kowski?= Date: Sat, 16 Mar 2024 15:48:22 +0100 Subject: [PATCH 3/3] Fixed drugtypes and drugitems background tags causing subsequent tags in the same background to be skipped --- Tactical/XML_Background.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tactical/XML_Background.cpp b/Tactical/XML_Background.cpp index 5caac1cd..26fa67b8 100644 --- a/Tactical/XML_Background.cpp +++ b/Tactical/XML_Background.cpp @@ -168,7 +168,7 @@ backgroundStartElementHandle(void *userData, const XML_Char *name, const XML_Cha else if (strcmp(name, "drugitems") == 0 && pData->curElement == ELEMENT) { pData->curElement = ELEMENT_VECTOR_OF_NUMBERS; - pData->curBackground.valueVectors[BackgroundVectorTypes::BG_DRUGUSE_TYPES].clear(); + pData->curBackground.valueVectors[BackgroundVectorTypes::BG_DRUGUSE_ITEMS].clear(); pData->maxReadDepth++; //we are not skipping this element } @@ -693,6 +693,14 @@ backgroundEndElementHandle(void *userData, const XML_Char *name) pData->curElement = ELEMENT; pData->curBackground.uiFlags |= (UINT16)atol(pData->szCharData) ? BACKGROUND_CIVGROUPLOYAL : 0; } + else if (strcmp(name, "drugtypes") == 0) + { + pData->curElement = ELEMENT; + } + else if (strcmp(name, "drugitems") == 0) + { + pData->curElement = ELEMENT; + } else if (strcmp(name, "drugtype") == 0) { pData->curElement = ELEMENT_VECTOR_OF_NUMBERS;