fallout2-ce/src/game_movie.cc

352 lines
8.0 KiB
C++
Raw Normal View History

2022-05-19 01:51:26 -07:00
#include "game_movie.h"
2022-09-15 02:38:23 -07:00
#include <stdio.h>
#include <string.h>
2022-05-19 01:51:26 -07:00
#include "color.h"
#include "cycle.h"
#include "debug.h"
#include "game.h"
#include "game_mouse.h"
#include "game_sound.h"
2022-10-04 23:23:27 -07:00
#include "input.h"
2022-10-03 02:41:33 -07:00
#include "mouse.h"
2022-05-19 01:51:26 -07:00
#include "movie.h"
#include "movie_effect.h"
#include "palette.h"
2022-06-18 06:52:03 -07:00
#include "platform_compat.h"
#include "settings.h"
2022-10-05 00:35:05 -07:00
#include "svga.h"
2022-05-19 01:51:26 -07:00
#include "text_font.h"
#include "window_manager.h"
2022-09-23 05:43:44 -07:00
namespace fallout {
2022-05-21 13:04:08 -07:00
#define GAME_MOVIE_WINDOW_WIDTH 640
#define GAME_MOVIE_WINDOW_HEIGHT 480
2022-06-18 06:52:03 -07:00
static char* gameMovieBuildSubtitlesFilePath(char* movieFilePath);
2022-05-19 01:51:26 -07:00
// 0x50352A
2022-06-18 06:52:03 -07:00
static const float flt_50352A = 0.032258064f;
2022-05-19 01:51:26 -07:00
// 0x518DA0
2022-06-18 06:52:03 -07:00
static const char* gMovieFileNames[MOVIE_COUNT] = {
2022-05-19 01:51:26 -07:00
"iplogo.mve",
"intro.mve",
"elder.mve",
"vsuit.mve",
"afailed.mve",
"adestroy.mve",
"car.mve",
"cartucci.mve",
"timeout.mve",
"tanker.mve",
"enclave.mve",
"derrick.mve",
"artimer1.mve",
"artimer2.mve",
"artimer3.mve",
"artimer4.mve",
"credits.mve",
};
// 0x518DE4
2022-06-18 06:52:03 -07:00
static const char* gMoviePaletteFilePaths[MOVIE_COUNT] = {
2022-05-19 01:51:26 -07:00
NULL,
"art\\cuts\\introsub.pal",
"art\\cuts\\eldersub.pal",
NULL,
"art\\cuts\\artmrsub.pal",
NULL,
NULL,
NULL,
"art\\cuts\\artmrsub.pal",
NULL,
NULL,
NULL,
"art\\cuts\\artmrsub.pal",
"art\\cuts\\artmrsub.pal",
"art\\cuts\\artmrsub.pal",
"art\\cuts\\artmrsub.pal",
"art\\cuts\\crdtssub.pal",
};
// 0x518E28
2022-06-18 06:52:03 -07:00
static bool gGameMovieIsPlaying = false;
2022-05-19 01:51:26 -07:00
// 0x518E2C
2022-06-18 06:52:03 -07:00
static bool gGameMovieFaded = false;
2022-05-19 01:51:26 -07:00
// 0x596C78
2022-06-18 06:52:03 -07:00
static unsigned char gGameMoviesSeen[MOVIE_COUNT];
2022-05-19 01:51:26 -07:00
// 0x596C89
2022-06-18 06:52:03 -07:00
static char gGameMovieSubtitlesFilePath[COMPAT_MAX_PATH];
2022-05-19 01:51:26 -07:00
// gmovie_init
// 0x44E5C0
int gameMoviesInit()
{
int v1 = 0;
if (backgroundSoundIsEnabled()) {
v1 = backgroundSoundGetVolume();
}
movieSetVolume(v1);
movieSetBuildSubtitleFilePathProc(gameMovieBuildSubtitlesFilePath);
memset(gGameMoviesSeen, 0, sizeof(gGameMoviesSeen));
gGameMovieIsPlaying = false;
gGameMovieFaded = false;
return 0;
}
// 0x44E60C
void gameMoviesReset()
{
memset(gGameMoviesSeen, 0, sizeof(gGameMoviesSeen));
gGameMovieIsPlaying = false;
gGameMovieFaded = false;
}
// 0x44E638
int gameMoviesLoad(File* stream)
{
if (fileRead(gGameMoviesSeen, sizeof(*gGameMoviesSeen), MOVIE_COUNT, stream) != MOVIE_COUNT) {
return -1;
}
return 0;
}
// 0x44E664
int gameMoviesSave(File* stream)
{
if (fileWrite(gGameMoviesSeen, sizeof(*gGameMoviesSeen), MOVIE_COUNT, stream) != MOVIE_COUNT) {
return -1;
}
return 0;
}
// gmovie_play
// 0x44E690
int gameMoviePlay(int movie, int flags)
{
gGameMovieIsPlaying = true;
const char* movieFileName = gMovieFileNames[movie];
debugPrint("\nPlaying movie: %s\n", movieFileName);
const char* language = settings.system.language.c_str();
2022-05-28 02:34:49 -07:00
char movieFilePath[COMPAT_MAX_PATH];
2022-05-19 01:51:26 -07:00
int movieFileSize;
bool movieFound = false;
if (compat_stricmp(language, ENGLISH) != 0) {
2022-12-08 12:05:50 -08:00
snprintf(movieFilePath, sizeof(movieFilePath), "art\\%s\\cuts\\%s", language, gMovieFileNames[movie]);
2022-05-19 01:51:26 -07:00
movieFound = dbGetFileSize(movieFilePath, &movieFileSize) == 0;
}
if (!movieFound) {
2022-12-08 12:05:50 -08:00
snprintf(movieFilePath, sizeof(movieFilePath), "art\\cuts\\%s", gMovieFileNames[movie]);
2022-05-19 01:51:26 -07:00
movieFound = dbGetFileSize(movieFilePath, &movieFileSize) == 0;
}
if (!movieFound) {
debugPrint("\ngmovie_play() - Error: Unable to open %s\n", gMovieFileNames[movie]);
gGameMovieIsPlaying = false;
return -1;
}
if ((flags & GAME_MOVIE_FADE_IN) != 0) {
paletteFadeTo(gPaletteBlack);
gGameMovieFaded = true;
}
2022-05-21 13:04:08 -07:00
int gameMovieWindowX = (screenGetWidth() - GAME_MOVIE_WINDOW_WIDTH) / 2;
int gameMovieWindowY = (screenGetHeight() - GAME_MOVIE_WINDOW_HEIGHT) / 2;
int win = windowCreate(gameMovieWindowX,
gameMovieWindowY,
GAME_MOVIE_WINDOW_WIDTH,
2022-05-21 13:04:08 -07:00
GAME_MOVIE_WINDOW_HEIGHT,
0,
2022-12-12 23:04:05 -08:00
WINDOW_MODAL);
2022-05-19 01:51:26 -07:00
if (win == -1) {
gGameMovieIsPlaying = false;
return -1;
}
if ((flags & GAME_MOVIE_STOP_MUSIC) != 0) {
backgroundSoundDelete();
} else if ((flags & GAME_MOVIE_PAUSE_MUSIC) != 0) {
backgroundSoundPause();
}
windowRefresh(win);
bool subtitlesEnabled = settings.preferences.subtitles;
2022-05-19 01:51:26 -07:00
int v1 = 4;
if (subtitlesEnabled) {
char* subtitlesFilePath = gameMovieBuildSubtitlesFilePath(movieFilePath);
int subtitlesFileSize;
if (dbGetFileSize(subtitlesFilePath, &subtitlesFileSize) == 0) {
v1 = 12;
} else {
subtitlesEnabled = false;
}
}
movieSetFlags(v1);
int oldTextColor;
int oldFont;
if (subtitlesEnabled) {
const char* subtitlesPaletteFilePath;
2022-05-19 01:51:26 -07:00
if (gMoviePaletteFilePaths[movie] != NULL) {
subtitlesPaletteFilePath = gMoviePaletteFilePaths[movie];
} else {
subtitlesPaletteFilePath = "art\\cuts\\subtitle.pal";
}
colorPaletteLoad(subtitlesPaletteFilePath);
2022-09-01 08:41:37 -07:00
oldTextColor = windowGetTextColor();
windowSetTextColor(1.0, 1.0, 1.0);
2022-05-19 01:51:26 -07:00
oldFont = fontGetCurrent();
2022-09-01 08:41:37 -07:00
windowSetFont(101);
2022-05-19 01:51:26 -07:00
}
bool cursorWasHidden = cursorIsHidden();
if (cursorWasHidden) {
gameMouseSetCursor(MOUSE_CURSOR_NONE);
mouseShowCursor();
}
while (mouseGetEvent() != 0) {
_mouse_info();
}
mouseHideCursor();
colorCycleDisable();
movieEffectsLoad(movieFilePath);
_zero_vid_mem();
_movieRun(win, movieFilePath);
int v11 = 0;
int buttons;
do {
2022-10-05 00:11:47 -07:00
if (!_moviePlaying() || _game_user_wants_to_quit || inputGetInput() != -1) {
2022-05-19 01:51:26 -07:00
break;
}
int x;
int y;
_mouse_get_raw_state(&x, &y, &buttons);
v11 |= buttons;
2022-08-01 09:47:09 -07:00
} while (((v11 & 1) == 0 && (v11 & 2) == 0) || (buttons & 1) != 0 || (buttons & 2) != 0);
2022-05-19 01:51:26 -07:00
_movieStop();
_moviefx_stop();
_movieUpdate();
paletteSetEntries(gPaletteBlack);
gGameMoviesSeen[movie] = 1;
colorCycleEnable();
gameMouseSetCursor(MOUSE_CURSOR_ARROW);
if (!cursorWasHidden) {
mouseShowCursor();
}
if (subtitlesEnabled) {
colorPaletteLoad("color.pal");
2022-09-01 08:41:37 -07:00
windowSetFont(oldFont);
2022-05-19 01:51:26 -07:00
float r = (float)((Color2RGB(oldTextColor) & 0x7C00) >> 10) * flt_50352A;
float g = (float)((Color2RGB(oldTextColor) & 0x3E0) >> 5) * flt_50352A;
float b = (float)(Color2RGB(oldTextColor) & 0x1F) * flt_50352A;
2022-09-01 08:41:37 -07:00
windowSetTextColor(r, g, b);
2022-05-19 01:51:26 -07:00
}
windowDestroy(win);
// CE: Destroying a window redraws only content it was covering (centered
// 640x480). This leads to everything outside this rect to remain black.
windowRefreshAll(&_scr_size);
2022-05-19 01:51:26 -07:00
if ((flags & GAME_MOVIE_PAUSE_MUSIC) != 0) {
backgroundSoundResume();
}
if ((flags & GAME_MOVIE_FADE_OUT) != 0) {
if (!subtitlesEnabled) {
colorPaletteLoad("color.pal");
}
paletteFadeTo(_cmap);
gGameMovieFaded = false;
}
gGameMovieIsPlaying = false;
return 0;
}
// 0x44EAE4
void gameMovieFadeOut()
{
if (gGameMovieFaded) {
paletteFadeTo(_cmap);
gGameMovieFaded = false;
}
}
// 0x44EB04
bool gameMovieIsSeen(int movie)
{
return gGameMoviesSeen[movie] == 1;
}
// 0x44EB14
bool gameMovieIsPlaying()
{
return gGameMovieIsPlaying;
}
// 0x44EB1C
2022-06-18 06:52:03 -07:00
static char* gameMovieBuildSubtitlesFilePath(char* movieFilePath)
2022-05-19 01:51:26 -07:00
{
char* path = movieFilePath;
char* separator = strrchr(path, '\\');
if (separator != NULL) {
path = separator + 1;
}
2022-12-08 12:05:50 -08:00
snprintf(gGameMovieSubtitlesFilePath, sizeof(gGameMovieSubtitlesFilePath), "text\\%s\\cuts\\%s", settings.system.language.c_str(), path);
2022-05-19 01:51:26 -07:00
char* pch = strrchr(gGameMovieSubtitlesFilePath, '.');
if (*pch != '\0') {
*pch = '\0';
}
strcpy(gGameMovieSubtitlesFilePath + strlen(gGameMovieSubtitlesFilePath), ".SVE");
return gGameMovieSubtitlesFilePath;
}
2022-09-23 05:43:44 -07:00
} // namespace fallout