Skip to content

Commit

Permalink
Bonus level experimental feature
Browse files Browse the repository at this point in the history
- Crash when trying to load the bonus level.
  • Loading branch information
TokyoSU committed Apr 21, 2022
1 parent 676c7d4 commit f47ec07
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
12 changes: 12 additions & 0 deletions configs/TR2Main.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
" dynamic light when triggered. (minisub is not affected) ",
" Default is true. ",
" ",
" - 'bonuslevel' is used to enable the bonus level when all secrets ",
" in the game, the count for each level is stored in the ",
" 'secretperlevel' you need to specify the level id in the ",
" 'bonuslevelid' ",
" ",
" - 'bonuslevelid' is used when 'bonuslevel' is true, ",
" when all the secrets is found (use gameflow secret command), ",
" this level will be unlocked. (there is only 23 level available ",
" and it start at: 0:title, 1:gym) ",
" ",
" - 'semitransparent' is used for semitransparency parameters. ",
" It can contain: 'animtex', 'objects', 'statics', 'rooms' ",
" ",
Expand Down Expand Up @@ -96,6 +106,8 @@
"comment": "Default settings for all levels",
"watercolor": "80FFFF",
"bridgelightfix": true,
"bonuslevel": true,
"bonuslevelid": 19,
"semitransparent": {
"animtex": "auto",
"objects": [{
Expand Down
7 changes: 2 additions & 5 deletions game/gameflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ BOOL __cdecl GF_DoFrontEndSequence() {
int __cdecl GF_DoLevelSequence(DWORD levelID, GF_LEVEL_TYPE levelType) {
for( DWORD i = levelID; i < GF_GameFlow.num_Levels; ++i ) {
int direction = GF_InterpretSequence(GF_ScriptTable[i], levelType, 0);

if( GF_GameFlow.singleLevel >= 0 ||
(direction & ~0xFFu) != GF_LEVEL_COMPLETE )
{
if( GF_GameFlow.singleLevel >= 0 || (direction & ~0xFFu) != GF_LEVEL_COMPLETE ) {
return direction;
}
}
Expand Down Expand Up @@ -294,7 +291,7 @@ int __cdecl GF_InterpretSequence(__int16 *seq, GF_LEVEL_TYPE levelType, int seqT
break;

case GFE_GAMECOMPLETE :
DisplayCredits();
//DisplayCredits();
if( GameStats(CurrentLevel) ) {
return GF_EXIT_TO_TITLE;
}
Expand Down
18 changes: 18 additions & 0 deletions modding/mod_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ typedef struct {
bool isLoaded;
bool isBarefoot;
bool isBridgeLightFix;
bool isBonusLevel;
char loadingPix[256];
DWORD bonusLevelID;
DWORD waterColor;
SEMITRANS_CONFIG semitrans;
REFLECT_CONFIG reflect;
Expand Down Expand Up @@ -173,6 +175,14 @@ bool IsModBridgeLightFix() {
return ModConfig.isBridgeLightFix;
}

bool IsModBonusLevel() {
return ModConfig.isBonusLevel;
}

DWORD GetModBonusLevelID() {
return ModConfig.bonusLevelID;
}

const char *GetModLoadingPix() {
return *ModConfig.loadingPix ? ModConfig.loadingPix : NULL;
}
Expand Down Expand Up @@ -419,6 +429,14 @@ static bool ParseLevelConfiguration(json_value *root) {
if( field ) {
ModConfig.isBarefoot = field->u.boolean;
}
field = GetJsonField(root, json_boolean, "bonuslevel", NULL);
if( field ) {
ModConfig.isBonusLevel = field->u.boolean;
}
field = GetJsonField(root, json_integer, "bonuslevelid", NULL);
if( field ) {
ModConfig.bonusLevelID = field->u.integer;
}
field = GetJsonField(root, json_boolean, "bridgelightfix", NULL);
if( field ) {
ModConfig.isBridgeLightFix = field->u.boolean;
Expand Down
2 changes: 2 additions & 0 deletions modding/mod_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ bool EnumeratePolys(__int16 *ptrObj, bool isRoomMesh, ENUM_POLYS_CB callback, PO
bool IsModConfigLoaded();
bool IsModBarefoot();
bool IsModBridgeLightFix();
bool IsModBonusLevel();
DWORD GetModBonusLevelID();
const char *GetModLoadingPix();
DWORD GetModWaterColor();
bool IsModSemitransConfigLoaded();
Expand Down
37 changes: 35 additions & 2 deletions specific/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "game/camera.h"
#include "game/control.h"
#include "game/draw.h"
#include "game/gameflow.h"
#include "game/inventory.h"
#include "game/invtext.h"
#include "game/savegame.h"
Expand All @@ -46,6 +47,12 @@
extern DWORD StatsBackgroundMode;
#endif // FEATURE_BACKGROUND_IMPROVED

#ifdef FEATURE_MOD_CONFIG
#include "modding/mod_utils.h"
extern int GF_GetNumSecrets(DWORD levelID);
GF_LEVEL_TYPE CurrentLevelType = GFL_NOLEVEL;
#endif // FEATURE_MOD_CONFIG

#ifdef FEATURE_INPUT_IMPROVED
#include "modding/joy_output.h"
#endif // FEATURE_INPUT_IMPROVED
Expand Down Expand Up @@ -85,10 +92,10 @@ DWORD SavegameSlots = 16;
__int16 __cdecl StartGame(int levelID, GF_LEVEL_TYPE levelType) {
if( levelType == GFL_NORMAL || levelType == GFL_SAVED || levelType == GFL_DEMO )
CurrentLevel = levelID;

if( levelType != GFL_SAVED )
ModifyStartInfo(levelID);

CurrentLevelType = levelType; // NOTE: need it for the GameStats()
IsTitleLoaded = FALSE;

if( levelType != GFL_SAVED )
Expand Down Expand Up @@ -318,12 +325,38 @@ int __cdecl GameStats(int levelID) {
RemoveJoystickHintText(false, true, false);
#endif // FEATURE_HUD_IMPROVED

int totalLevels = (GF_GameFlow.num_Levels - GF_GameFlow.num_Demos) - 1;
// NOTE: in the original game, there is slightly different bonusFlag activation.
// Here removed bonuses initialization, and added the check that the level is final
if( CurrentLevel == GF_GameFlow.num_Levels-GF_GameFlow.num_Demos-1 ) {
if( CurrentLevel == totalLevels ) {
SaveGame.bonusFlag = true;
}

#ifdef FEATURE_MOD_CONFIG
if (!IsResetFlag && CurrentLevelType != GFL_STORY) {
if (IsModBonusLevel()) {
int bonusLevelID = GetModBonusLevelID();
if (levelID < bonusLevelID) {
int numSecretTotal = 0, numSecretGame = 0;
for ( int i = 0; i < totalLevels; i++ ) {
BYTE flags = SaveGame.start[i].statistics.secrets;
// check for secret 1, 2 or 3
numSecretTotal += CHK_ANY(flags, 0x1) + CHK_ANY(flags, 0x2) + CHK_ANY(flags, 0x4);
numSecretGame += GF_GetNumSecrets(i);
}
if (numSecretTotal >= numSecretGame) {
if (bonusLevelID != -1 && bonusLevelID <= totalLevels) {
SaveGame.start[bonusLevelID].available = 1;
SaveGame.currentLevel = bonusLevelID;
S_SaveGame(&SaveGame, sizeof(SAVEGAME_INFO), 0);
return 1;
}
}
}
}
}
#endif

#ifdef FEATURE_BACKGROUND_IMPROVED
BGND2_ShowPicture(0, 0, 10, 2, FALSE);
#endif // FEATURE_BACKGROUND_IMPROVED
Expand Down

0 comments on commit f47ec07

Please sign in to comment.