Files
OpenRCT2-Web/src/openrct2/Intro.cpp
T

303 lines
9.8 KiB
C++
Raw Normal View History

2014-04-02 00:31:55 +01:00
/*****************************************************************************
2023-01-01 04:58:01 -06:00
* Copyright (c) 2014-2023 OpenRCT2 developers
2015-10-20 20:16:30 +02:00
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2015-10-20 20:16:30 +02:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2014-04-02 00:31:55 +01:00
*****************************************************************************/
2015-10-20 20:16:30 +02:00
2017-12-12 14:52:57 +01:00
#include "Intro.h"
2018-06-22 23:25:16 +02:00
#include "Context.h"
#include "audio/AudioChannel.h"
2018-06-22 23:25:16 +02:00
#include "audio/AudioMixer.h"
#include "audio/audio.h"
#include "drawing/Drawing.h"
2016-12-01 15:05:00 +01:00
#include "sprites.h"
2014-04-02 16:46:58 +01:00
2022-07-29 18:45:10 +02:00
#include <memory>
using namespace OpenRCT2::Audio;
2018-06-22 23:25:16 +02:00
#define BACKROUND_COLOUR_DARK PALETTE_INDEX_10
#define BACKROUND_COLOUR_LOGO PALETTE_INDEX_245
#define BORDER_COLOUR_PUBLISHER PALETTE_INDEX_129
2016-05-13 21:36:07 +01:00
2019-10-23 22:37:34 -03:00
constexpr int32_t PALETTE_G1_IDX_DEVELOPER = 23217;
constexpr int32_t PALETTE_G1_IDX_LOGO = 23224;
2016-05-13 21:36:07 +01:00
IntroState gIntroState;
2016-05-13 21:36:07 +01:00
// Used mainly for timing but also for Y coordinate and fading.
static int32_t _introStateCounter;
2016-05-13 21:36:07 +01:00
static std::shared_ptr<IAudioChannel> _soundChannel = nullptr;
2016-05-13 21:36:07 +01:00
static bool _chainLiftFinished;
2014-04-02 16:46:58 +01:00
static void screen_intro_process_mouse_input();
static void screen_intro_process_keyboard_input();
static void screen_intro_skip_part();
2018-06-22 23:25:16 +02:00
static void screen_intro_draw_logo(rct_drawpixelinfo* dpi);
2014-04-02 00:31:55 +01:00
// rct2: 0x0068E966
void intro_update()
{
2017-06-06 23:24:18 +02:00
screen_intro_process_mouse_input();
screen_intro_process_keyboard_input();
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
switch (gIntroState)
{
case IntroState::Disclaimer1:
case IntroState::Disclaimer2:
2018-06-22 23:25:16 +02:00
// Originally used for the disclaimer text
gIntroState = IntroState::PublisherBegin;
2019-01-02 22:22:52 +01:00
[[fallthrough]];
case IntroState::PublisherBegin:
LoadPalette();
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Set the Y for the Infogrames logo
_introStateCounter = -580;
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Play the chain lift sound
_soundChannel = CreateAudioChannel(SoundId::LiftBM, true);
2018-06-22 23:25:16 +02:00
_chainLiftFinished = false;
gIntroState = IntroState::PublisherScroll;
2018-06-22 23:25:16 +02:00
break;
case IntroState::PublisherScroll:
2018-06-22 23:25:16 +02:00
// Move the Infogrames logo down
_introStateCounter += 5;
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Check if logo is off the screen...ish
2022-11-06 20:49:07 +00:00
if (_introStateCounter > ContextGetHeight() - 120)
2018-06-22 23:25:16 +02:00
{
_introStateCounter = -116;
gIntroState = IntroState::DeveloperBegin;
2018-06-22 23:25:16 +02:00
}
break;
case IntroState::DeveloperBegin:
2018-06-22 23:25:16 +02:00
// Set the Y for the Chris Sawyer logo
2017-06-06 23:24:18 +02:00
_introStateCounter = -116;
2018-06-22 23:25:16 +02:00
gIntroState = IntroState::DeveloperScroll;
2018-06-22 23:25:16 +02:00
break;
case IntroState::DeveloperScroll:
2018-06-22 23:25:16 +02:00
_introStateCounter += 5;
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Check if logo is almost scrolled to the bottom
2022-11-06 20:49:07 +00:00
if (!_chainLiftFinished && _introStateCounter >= ContextGetHeight() + 40 - 421)
2018-06-22 23:25:16 +02:00
{
_chainLiftFinished = true;
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Stop the chain lift sound
if (_soundChannel != nullptr)
{
_soundChannel->Stop();
2018-06-22 23:25:16 +02:00
_soundChannel = nullptr;
}
2016-05-13 21:36:07 +01:00
2018-06-22 23:25:16 +02:00
// Play the track friction sound
_soundChannel = CreateAudioChannel(SoundId::TrackFrictionBM, true, MIXER_VOLUME_MAX, 0.25f, 0.75);
2018-06-22 23:25:16 +02:00
}
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Check if logo is off the screen...ish
2022-11-06 20:49:07 +00:00
if (_introStateCounter >= ContextGetHeight() + 40)
2018-06-22 23:25:16 +02:00
{
// Stop the track friction sound
if (_soundChannel != nullptr)
{
_soundChannel->Stop();
2018-06-22 23:25:16 +02:00
_soundChannel = nullptr;
}
// Play long peep scream sound
_soundChannel = CreateAudioChannel(SoundId::Scream1);
2018-06-22 23:25:16 +02:00
gIntroState = IntroState::LogoFadeIn;
2018-06-22 23:25:16 +02:00
_introStateCounter = 0;
}
break;
case IntroState::LogoFadeIn:
2018-06-22 23:25:16 +02:00
// Fade in, add 4 / 256 to fading
_introStateCounter += 0x400;
if (_introStateCounter > 0xFF00)
{
gIntroState = IntroState::LogoWait;
2018-06-22 23:25:16 +02:00
_introStateCounter = 0;
}
break;
case IntroState::LogoWait:
2018-06-22 23:25:16 +02:00
// Wait 80 game ticks
_introStateCounter++;
if (_introStateCounter >= 80)
{
// Set fading to 256
_introStateCounter = 0xFF00;
gIntroState = IntroState::LogoFadeOut;
2018-06-22 23:25:16 +02:00
}
break;
case IntroState::LogoFadeOut:
2018-06-22 23:25:16 +02:00
// Fade out, subtract 4 / 256 from fading
_introStateCounter -= 0x400;
if (_introStateCounter < 0)
{
gIntroState = IntroState::Clear;
2018-06-22 23:25:16 +02:00
}
break;
case IntroState::Clear:
2018-06-22 23:25:16 +02:00
// Stop any playing sound
if (_soundChannel != nullptr)
{
_soundChannel->Stop();
2018-01-04 06:58:44 +01:00
_soundChannel = nullptr;
2017-06-06 23:24:18 +02:00
}
2014-04-02 16:46:58 +01:00
2018-06-22 23:25:16 +02:00
// Move to next part
gIntroState = IntroState::Finish;
2017-06-06 23:24:18 +02:00
_introStateCounter = 0;
2018-06-22 23:25:16 +02:00
break;
case IntroState::Finish:
gIntroState = IntroState::None;
LoadPalette();
2020-10-07 00:34:42 +03:00
OpenRCT2::Audio::PlayTitleMusic();
2018-06-22 23:25:16 +02:00
break;
default:
break;
2017-06-06 23:24:18 +02:00
}
2014-04-02 16:46:58 +01:00
}
2018-06-22 23:25:16 +02:00
void intro_draw(rct_drawpixelinfo* dpi)
2016-06-05 15:40:19 +01:00
{
2022-11-06 20:49:07 +00:00
int32_t screenWidth = ContextGetWidth();
2016-11-13 20:17:49 +01:00
2018-06-22 23:25:16 +02:00
switch (gIntroState)
{
case IntroState::Disclaimer1:
case IntroState::Disclaimer2:
2018-06-22 23:25:16 +02:00
break;
case IntroState::PublisherBegin:
GfxClear(dpi, BACKROUND_COLOUR_DARK);
2018-06-22 23:25:16 +02:00
break;
case IntroState::PublisherScroll:
GfxClear(dpi, BACKROUND_COLOUR_DARK);
2016-06-05 15:40:19 +01:00
2018-06-22 23:25:16 +02:00
// Draw a white rectangle for the logo background (gives a bit of white margin)
GfxFillRect(
dpi,
{ { (screenWidth / 2) - 320 + 50, _introStateCounter + 50 },
{ (screenWidth / 2) - 320 + 50 + 540, _introStateCounter + 50 + 425 } },
BORDER_COLOUR_PUBLISHER);
2016-06-05 15:40:19 +01:00
2018-06-22 23:25:16 +02:00
// Draw Infogrames logo
GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_00), { (screenWidth / 2) - 320 + 69, _introStateCounter + 69 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_10), { (screenWidth / 2) - 320 + 319, _introStateCounter + 69 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_01), { (screenWidth / 2) - 320 + 69, _introStateCounter + 319 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_11), { (screenWidth / 2) - 320 + 319, _introStateCounter + 319 });
2018-06-22 23:25:16 +02:00
break;
case IntroState::DeveloperBegin:
GfxClear(dpi, BACKROUND_COLOUR_DARK);
GfxTransposePalette(PALETTE_G1_IDX_DEVELOPER, 255);
2018-06-22 23:25:16 +02:00
break;
case IntroState::DeveloperScroll:
GfxClear(dpi, BACKROUND_COLOUR_DARK);
2016-06-05 15:40:19 +01:00
2018-06-22 23:25:16 +02:00
// Draw Chris Sawyer logo
GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_00), { (screenWidth / 2) - 320 + 70, _introStateCounter });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_10), { (screenWidth / 2) - 320 + 320, _introStateCounter });
2018-06-22 23:25:16 +02:00
break;
case IntroState::LogoFadeIn:
2018-06-22 23:25:16 +02:00
if (_introStateCounter <= 0xFF00)
{
GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF);
2018-06-22 23:25:16 +02:00
}
else
{
GfxTransposePalette(PALETTE_G1_IDX_LOGO, 255);
2018-06-22 23:25:16 +02:00
}
screen_intro_draw_logo(dpi);
break;
case IntroState::LogoWait:
2018-06-22 23:25:16 +02:00
screen_intro_draw_logo(dpi);
break;
case IntroState::LogoFadeOut:
2018-06-22 23:25:16 +02:00
if (_introStateCounter >= 0)
{
GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF);
2018-06-22 23:25:16 +02:00
}
else
{
GfxTransposePalette(PALETTE_G1_IDX_LOGO, 0);
2018-06-22 23:25:16 +02:00
}
screen_intro_draw_logo(dpi);
break;
case IntroState::Clear:
GfxClear(dpi, BACKROUND_COLOUR_DARK);
2018-06-22 23:25:16 +02:00
break;
default:
break;
2017-06-06 23:24:18 +02:00
}
2016-06-05 15:40:19 +01:00
}
2014-04-02 16:46:58 +01:00
static void screen_intro_process_mouse_input()
{
2022-11-06 20:49:07 +00:00
if (ContextGetCursorState()->any == CURSOR_PRESSED)
2018-06-22 23:25:16 +02:00
{
2017-06-06 23:24:18 +02:00
screen_intro_skip_part();
}
2014-04-02 16:46:58 +01:00
}
/**
*
* rct2: 0x006E3AEC
*/
2014-04-02 16:46:58 +01:00
static void screen_intro_process_keyboard_input()
{
2022-11-06 20:49:07 +00:00
const uint8_t* keys = ContextGetKeysState();
2018-06-22 23:25:16 +02:00
for (int i = 0; i < 256; i++)
{
if (keys[i] != 0)
{
2017-06-06 23:24:18 +02:00
screen_intro_skip_part();
break;
}
}
2014-04-02 16:46:58 +01:00
}
static void screen_intro_skip_part()
{
2018-06-22 23:25:16 +02:00
switch (gIntroState)
{
case IntroState::None:
2018-06-22 23:25:16 +02:00
break;
case IntroState::Disclaimer2:
gIntroState = IntroState::PublisherBegin;
2018-06-22 23:25:16 +02:00
break;
default:
gIntroState = IntroState::Clear;
2018-06-22 23:25:16 +02:00
break;
2017-06-06 23:24:18 +02:00
}
}
2016-05-13 21:36:07 +01:00
2018-06-22 23:25:16 +02:00
static void screen_intro_draw_logo(rct_drawpixelinfo* dpi)
2016-05-13 21:36:07 +01:00
{
2022-11-06 20:49:07 +00:00
int32_t screenWidth = ContextGetWidth();
int32_t imageWidth = 640;
int32_t imageX = (screenWidth - imageWidth) / 2;
2016-05-13 21:36:07 +01:00
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_00);
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_10);
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_20);
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_01);
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_11);
DrawingEngineInvalidateImage(SPR_INTRO_LOGO_21);
2016-06-05 19:25:01 +01:00
GfxClear(dpi, BACKROUND_COLOUR_LOGO);
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_00), { imageX + 0, 0 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_10), { imageX + 220, 0 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_20), { imageX + 440, 0 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_01), { imageX + 0, 240 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_11), { imageX + 220, 240 });
GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_21), { imageX + 440, 240 });
2016-05-13 21:36:07 +01:00
}