Replace a ton of trivial #ifdefs with runtime checks

This one is big, but unless I missed something, should be all be
trivial.

scripted-diff with the following, then manually tweaked whatever needed:
```

if [ $# -ne 3 ]; then
    echo "Usage: $0 '<pattern>' '<replacement>' '<filename>'"
    exit 1
fi

pattern="$1"
replacement="$2"
filename="$3"

if [ ! -f "$filename" ]; then
    echo "Error: File $filename does not exist."
    exit 1
fi

sed -i '/'"$pattern"'/ {
    :loop
    $ !{
        N
        /'"$pattern"'.*\n.*#endif/ {
            s/'"$pattern"'/'"$replacement"'/
            s/#else/} else {/
            s/#endif/}/
            P
            D
        }
        /'"$pattern"'/ b loop
    }
}' "$filename"

echo "Replacement complete in $filename"
```

h/t to Grok2 for the sed command
This commit is contained in:
Marco Antonio J. Costa
2024-12-31 16:28:44 -03:00
parent cd69f5f3ae
commit d008d10b31
18 changed files with 413 additions and 396 deletions
+7 -6
View File
@@ -56,6 +56,7 @@
#include "MilitiaSquads.h"
#include "LaptopSave.h"
#include <language.hpp>
// added by Flugente
extern CHAR16 gzSectorNames[256][4][MAX_SECTOR_NAME_LENGTH];
@@ -1199,11 +1200,11 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Map Screen1");
// don't show loyalty string until loyalty tracking for that town has been started
if( gTownLoyalty[ bTown ].fStarted && gfTownUsesLoyalty[ bTown ])
{
#ifdef CHINESE
if ( g_lang == i18n::Lang::zh ) {
swprintf( sStringA, L"%d%£¥%% %s", gTownLoyalty[ bTown ].ubRating, gsLoyalString[ 0 ]);
#else
} else {
swprintf( sStringA, L"%d%%%% %s", gTownLoyalty[ bTown ].ubRating, gsLoyalString[ 0 ]);
#endif
}
// if loyalty is too low to train militia, and militia training is allowed here
if ( ( gTownLoyalty[ bTown ].ubRating < iMinLoyaltyToTrain ) && MilitiaTrainingAllowedInTown( bTown ) )
@@ -4873,11 +4874,11 @@ void BlitMineText( INT16 sMapX, INT16 sMapY )
// if potential is not nil, show percentage of the two
if (GetMaxPeriodicRemovalFromMine(ubMineIndex) > 0)
{
#ifdef CHINESE
if ( g_lang == i18n::Lang::zh ) {
swprintf( wSubString, L" (%d%£¥%%)", (PredictDailyIncomeFromAMine(ubMineIndex, TRUE) * 100 ) / GetMaxDailyRemovalFromMine(ubMineIndex) );
#else
} else {
swprintf( wSubString, L" (%d%%%%)", (PredictDailyIncomeFromAMine(ubMineIndex, TRUE) * 100 ) / GetMaxDailyRemovalFromMine(ubMineIndex) );
#endif
}
wcscat( wString, wSubString );
}
+4 -3
View File
@@ -40,6 +40,7 @@
#include "Luaglobal.h"
#include "LuaInitNPCs.h"
#include "Interface.h"
#include <language.hpp>
#include "GameInitOptionsScreen.h"
extern WorldItems gAllWorldItems;
@@ -1631,12 +1632,12 @@ void AdjustLoyaltyForCivsEatenByMonsters( INT16 sSectorX, INT16 sSectorY, UINT8
swprintf( str, gpStrategicString[STR_PB_BANDIT_KILLCIVS_IN_SECTOR], ubHowMany, pSectorString );
else
{
#ifdef CHINESE
if( g_lang == i18n::Lang::zh ) {
//diffrent order of words in Chinese
swprintf( str, gpStrategicString[STR_DIALOG_CREATURES_KILL_CIVILIANS], pSectorString, ubHowMany );
#else
} else {
swprintf( str, gpStrategicString[STR_DIALOG_CREATURES_KILL_CIVILIANS], ubHowMany, pSectorString );
#endif
}
}
DoScreenIndependantMessageBox( str, MSG_BOX_FLAG_OK, MapScreenDefaultOkBoxCallback );
+9 -9
View File
@@ -9665,27 +9665,27 @@ void BltCharInvPanel()
// print armor/weight/camo labels
mprintf(UI_CHARINV.Text.ArmorLabel.iX, UI_CHARINV.Text.ArmorLabel.iY, pInvPanelTitleStrings[ 0 ] );
#ifdef CHINESE
if( g_lang == i18n::Lang::zh ) {
mprintf(UI_CHARINV.Text.ArmorPercent.iX, UI_CHARINV.Text.ArmorPercent.iY, ChineseSpecString1 );
#else
} else {
mprintf(UI_CHARINV.Text.ArmorPercent.iX, UI_CHARINV.Text.ArmorPercent.iY, L"%%" );
#endif
}
mprintf(UI_CHARINV.Text.WeightLabel.iX, UI_CHARINV.Text.WeightLabel.iY, pInvPanelTitleStrings[ 1 ] );
#ifdef CHINESE
if( g_lang == i18n::Lang::zh ) {
mprintf(UI_CHARINV.Text.WeightPercent.iX, UI_CHARINV.Text.WeightPercent.iY, ChineseSpecString1 );
#else
} else {
mprintf(UI_CHARINV.Text.WeightPercent.iX, UI_CHARINV.Text.WeightPercent.iY, L"%%" );
#endif
}
mprintf(UI_CHARINV.Text.CamoLabel.iX, UI_CHARINV.Text.CamoLabel.iY, pInvPanelTitleStrings[ 2 ] );
#ifdef CHINESE
if( g_lang == i18n::Lang::zh ) {
mprintf(UI_CHARINV.Text.CamoPercent.iX, UI_CHARINV.Text.CamoPercent.iY, ChineseSpecString1 );
#else
} else {
mprintf(UI_CHARINV.Text.CamoPercent.iX, UI_CHARINV.Text.CamoPercent.iY, L"%%" );
#endif
}
const auto width = UI_CHARINV.Text.PercentWidth;
const auto height = UI_CHARINV.Text.PercentHeight;