Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global scripts #294

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/sfall_config.h"
"src/sfall_global_vars.cc"
"src/sfall_global_vars.h"
"src/sfall_global_scripts.cc"
"src/sfall_global_scripts.h"
"src/sfall_ini.cc"
"src/sfall_ini.h"
"src/sfall_lists.cc"
Expand Down
5 changes: 5 additions & 0 deletions src/combat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "scripts.h"
#include "settings.h"
#include "sfall_config.h"
#include "sfall_global_scripts.h"
#include "skill.h"
#include "stat.h"
#include "svga.h"
Expand Down Expand Up @@ -3144,6 +3145,10 @@ static int _combat_input()
}

int keyCode = inputGetInput();

// SFALL: CombatLoopHook.
sfall_gl_scr_process_main();

if (_action_explode_running()) {
// NOTE: Uninline.
_combat_turn_run();
Expand Down
6 changes: 3 additions & 3 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static bool configParseLine(Config* config, char* string)
// keys there.

// Skip leading whitespace.
while (isspace(*string)) {
while (isspace(static_cast<unsigned char>(*string))) {
string++;
}

Expand Down Expand Up @@ -500,7 +500,7 @@ static bool configTrimString(char* string)
// Starting from the end of the string, loop while it's a whitespace and
// decrement string length.
char* pch = string + length - 1;
while (length != 0 && isspace(*pch)) {
while (length != 0 && isspace(static_cast<unsigned char>(*pch))) {
length--;
pch--;
}
Expand All @@ -511,7 +511,7 @@ static bool configTrimString(char* string)
// Starting from the beginning of the string loop while it's a whitespace
// and decrement string length.
pch = string;
while (isspace(*pch)) {
while (isspace(static_cast<unsigned char>(*pch))) {
pch++;
length--;
}
Expand Down
8 changes: 8 additions & 0 deletions src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "settings.h"
#include "sfall_arrays.h"
#include "sfall_config.h"
#include "sfall_global_scripts.h"
#include "sfall_global_vars.h"
#include "sfall_ini.h"
#include "sfall_lists.h"
Expand Down Expand Up @@ -355,6 +356,11 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
return -1;
}

if (!sfall_gl_scr_init()) {
debugPrint("Failed on sfall_gl_scr_init");
return -1;
}

char* customConfigBasePath;
configGetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_INI_CONFIG_FOLDER, &customConfigBasePath);
sfall_ini_set_base_path(customConfigBasePath);
Expand Down Expand Up @@ -407,6 +413,7 @@ void gameReset()
sfallListsReset();
messageListRepositoryReset();
sfallArraysReset();
sfall_gl_scr_reset();
}

// 0x442C34
Expand All @@ -415,6 +422,7 @@ void gameExit()
debugPrint("\nGame Exit\n");

// SFALL
sfall_gl_scr_exit();
sfallArraysExit();
sfallListsExit();
sfallGlobalVarsExit();
Expand Down
3 changes: 1 addition & 2 deletions src/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static opcode_t programReturnStackPopInt16(Program* program);
static int programReturnStackPopInt32(Program* program);
static void _detachProgram(Program* program);
static void _purgeProgram(Program* program);
static void programFree(Program* program);
static opcode_t _getOp(Program* program);
static void programMarkHeap(Program* program);
static void opNoop(Program* program);
Expand Down Expand Up @@ -421,7 +420,7 @@ static void _purgeProgram(Program* program)
}

// 0x467614
static void programFree(Program* program)
void programFree(Program* program)
{
// NOTE: Uninline.
_detachProgram(program);
Expand Down
1 change: 1 addition & 0 deletions src/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void _interpretOutputFunc(int (*func)(char*));
int _interpretOutput(const char* format, ...);
[[noreturn]] void programFatalError(const char* str, ...);
void _interpretDecStringRef(Program* program, opcode_t a2, int a3);
void programFree(Program* program);
Program* programCreateByPath(const char* path);
char* programGetString(Program* program, opcode_t opcode, int offset);
char* programGetIdentifier(Program* program, int offset);
Expand Down
4 changes: 4 additions & 0 deletions src/loadsave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "random.h"
#include "scripts.h"
#include "settings.h"
#include "sfall_global_scripts.h"
#include "skill.h"
#include "stat.h"
#include "svga.h"
Expand Down Expand Up @@ -1676,6 +1677,9 @@ static int lsgLoadGameInSlot(int slot)

_loadingGame = 0;

// SFALL: Start global scripts.
sfall_gl_scr_exec_start_proc();

return 0;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "selfrun.h"
#include "settings.h"
#include "sfall_config.h"
#include "sfall_global_scripts.h"
#include "svga.h"
#include "text_font.h"
#include "window.h"
Expand Down Expand Up @@ -148,6 +149,9 @@ int falloutMain(int argc, char** argv)
_main_load_new(mapNameCopy);
free(mapNameCopy);

// SFALL: AfterNewGameStartHook.
sfall_gl_scr_exec_start_proc();

mainLoop();
paletteFadeTo(gPaletteWhite);

Expand Down Expand Up @@ -357,6 +361,10 @@ static void mainLoop()
sharedFpsLimiter.mark();

int keyCode = inputGetInput();

// SFALL: MainLoopHook.
sfall_gl_scr_process_main();

gameHandleKey(keyCode, false);

scriptsHandleRequests();
Expand Down
6 changes: 5 additions & 1 deletion src/scripts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "queue.h"
#include "sfall_arrays.h"
#include "sfall_config.h"
#include "sfall_global_scripts.h"
#include "stat.h"
#include "svga.h"
#include "tile.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ static const int gGameTimeDaysPerMonth[12] = {
};

// 0x51C758
static const char* gScriptProcNames[28] = {
const char* gScriptProcNames[SCRIPT_PROC_COUNT] = {
"no_p_proc",
"start",
"spatial_p_proc",
Expand Down Expand Up @@ -2589,6 +2590,9 @@ void scriptsExecMapUpdateProc()
// 0x4A67EC
void scriptsExecMapUpdateScripts(int proc)
{
// SFALL: Run global scripts.
sfall_gl_scr_exec_map_update_scripts(proc);

_scr_SpatialsEnabled = false;

int fixedParam = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ typedef struct Script {
int field_DC;
} Script;

extern const char* gScriptProcNames[SCRIPT_PROC_COUNT];

int gameTimeGetTime();
void gameTimeGetDate(int* monthPtr, int* dayPtr, int* yearPtr);
int gameTimeGetHour();
Expand Down
1 change: 1 addition & 0 deletions src/sfall_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bool sfallConfigInit(int argc, char** argv)
configSetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MOVIE_TIMER_ARTIMER4, 360);

configSetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_INI_CONFIG_FOLDER, "");
configSetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_GLOBAL_SCRIPT_PATHS, "");

char path[COMPAT_MAX_PATH];
char* executable = argv[0];
Expand Down
1 change: 1 addition & 0 deletions src/sfall_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace fallout {
#define SFALL_CONFIG_EXTRA_MESSAGE_LISTS_KEY "ExtraGameMsgFileList"
#define SFALL_CONFIG_NUMBERS_IS_DIALOG_KEY "NumbersInDialogue"
#define SFALL_CONFIG_INI_CONFIG_FOLDER "IniConfigFolder"
#define SFALL_CONFIG_GLOBAL_SCRIPT_PATHS "GlobalScriptPaths"

#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_MULTIPLIER 1
#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_DIVISOR 3
Expand Down
Loading