1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge pull request #5298 from IntelOrca/refactor/balloon

Refactor balloon to C++
This commit is contained in:
Ted John
2017-03-11 13:14:18 +00:00
committed by GitHub
7 changed files with 185 additions and 144 deletions

View File

@@ -19,6 +19,7 @@
652747EC1E41CE1B000F36FD /* SawyerEncoding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 652747EA1E41CE1B000F36FD /* SawyerEncoding.cpp */; };
656F6C8E1E45BFC200E0F770 /* Version.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 656F6C8C1E45BFC200E0F770 /* Version.cpp */; };
658F3D911E44A6C200388550 /* ParkImporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 658F3D8F1E44A6C200388550 /* ParkImporter.cpp */; };
6876808CD662C4B16392A9B4 /* Balloon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 437490DBD74ECF60C3363559 /* Balloon.cpp */; };
791166FB1D7486EF005912EA /* NetworkServerAdvertiser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */; };
85060FD31D8C17CC00DFA2B3 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; };
8594C0601D885CF600235E93 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; };
@@ -412,7 +413,6 @@
D44272961CC81B3200D84D28 /* track_place.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271D51CC81B3200D84D28 /* track_place.c */; };
D44272971CC81B3200D84D28 /* viewport.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271D61CC81B3200D84D28 /* viewport.c */; };
D44272981CC81B3200D84D28 /* water.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271D71CC81B3200D84D28 /* water.c */; };
D44272991CC81B3200D84D28 /* balloon.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271D91CC81B3200D84D28 /* balloon.c */; };
D442729A1CC81B3200D84D28 /* banner.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271DA1CC81B3200D84D28 /* banner.c */; };
D442729B1CC81B3200D84D28 /* climate.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271DC1CC81B3200D84D28 /* climate.c */; };
D442729C1CC81B3200D84D28 /* duck.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271DE1CC81B3200D84D28 /* duck.c */; };
@@ -479,6 +479,7 @@
D4EC48E81C2637710024B507 /* title in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E51C2637710024B507 /* title */; };
D4F5B5EF1DAD8A4300AB6075 /* CursorData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D4F5B5EC1DAD8A4300AB6075 /* CursorData.cpp */; };
D4F5B5F01DAD8A4300AB6075 /* Cursors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D4F5B5ED1DAD8A4300AB6075 /* Cursors.cpp */; };
F61331C839858250899F1E9B /* Balloon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 437490DBD74ECF60C3363559 /* Balloon.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -528,6 +529,7 @@
008BF7291CDAA5C30019A2AD /* track_design.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = track_design.h; sourceTree = "<group>"; };
00EFEE701CF1D80B0035213B /* NetworkKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkKey.cpp; sourceTree = "<group>"; usesTabs = 0; };
00EFEE711CF1D80B0035213B /* NetworkKey.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = NetworkKey.h; sourceTree = "<group>"; usesTabs = 0; };
437490DBD74ECF60C3363559 /* Balloon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Balloon.cpp; sourceTree = "<group>"; };
652076301E22EFE7000D0C04 /* Imaging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Imaging.cpp; sourceTree = "<group>"; };
652076311E22EFE7000D0C04 /* Imaging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Imaging.h; sourceTree = "<group>"; };
652747EA1E41CE1B000F36FD /* SawyerEncoding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SawyerEncoding.cpp; path = rct12/SawyerEncoding.cpp; sourceTree = "<group>"; };
@@ -988,7 +990,6 @@
D44271D51CC81B3200D84D28 /* track_place.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = track_place.c; sourceTree = "<group>"; };
D44271D61CC81B3200D84D28 /* viewport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = viewport.c; sourceTree = "<group>"; };
D44271D71CC81B3200D84D28 /* water.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = water.c; sourceTree = "<group>"; };
D44271D91CC81B3200D84D28 /* balloon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = balloon.c; sourceTree = "<group>"; };
D44271DA1CC81B3200D84D28 /* banner.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = banner.c; sourceTree = "<group>"; };
D44271DB1CC81B3200D84D28 /* banner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = banner.h; sourceTree = "<group>"; };
D44271DC1CC81B3200D84D28 /* climate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = climate.c; sourceTree = "<group>"; };
@@ -2036,7 +2037,7 @@
D44271D81CC81B3200D84D28 /* world */ = {
isa = PBXGroup;
children = (
D44271D91CC81B3200D84D28 /* balloon.c */,
437490DBD74ECF60C3363559 /* Balloon.cpp */,
D44271DA1CC81B3200D84D28 /* banner.c */,
D44271DB1CC81B3200D84D28 /* banner.h */,
D44271DC1CC81B3200D84D28 /* climate.c */,
@@ -2686,6 +2687,7 @@
C64FDAAC1D6D9A2100F259B9 /* splash_boats.c in Sources */,
C64FDAAD1D6D9A2100F259B9 /* submarine_ride.c in Sources */,
C64FDAAE1D6D9A2100F259B9 /* water_coaster.c in Sources */,
6876808CD662C4B16392A9B4 /* Balloon.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -3011,7 +3013,6 @@
D44271FF1CC81B3200D84D28 /* Console.cpp in Sources */,
D44272781CC81B3200D84D28 /* player.c in Sources */,
C686F9161CDBC3B7009F9BFC /* lay_down_roller_coaster.c in Sources */,
D44272991CC81B3200D84D28 /* balloon.c in Sources */,
D442727C1CC81B3200D84D28 /* ride_construction.c in Sources */,
D442724A1CC81B3200D84D28 /* track_data.c in Sources */,
D442725C1CC81B3200D84D28 /* editor_main.c in Sources */,
@@ -3044,6 +3045,7 @@
C6834A111DFDE8E300CE933A /* interop.c in Sources */,
C686F9231CDBC3B7009F9BFC /* steeplechase.c in Sources */,
D44272871CC81B3200D84D28 /* staff_list.c in Sources */,
F61331C839858250899F1E9B /* Balloon.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -335,7 +335,7 @@
<ClCompile Include="windows\title_command_editor.c" />
<ClCompile Include="windows\title_editor.c" />
<ClCompile Include="windows\maze_construction.c" />
<ClCompile Include="world\balloon.c" />
<ClCompile Include="world\Balloon.cpp" />
<ClCompile Include="world\duck.c" />
<ClCompile Include="world\money_effect.c" />
<ClCompile Include="world\particle.c" />

View File

@@ -1719,23 +1719,15 @@ void peep_update_sprite_type(rct_peep* peep)
peep->sprite_type == PEEP_SPRITE_TYPE_BALLOON &&
(scenario_rand() & 0xFFFF) <= 327
) {
uint8 bl = 0;
if (
(scenario_rand() & 0xFFFF) <= 13107 &&
peep->x != SPRITE_LOCATION_NULL
) {
bl = 1;
audio_play_sound_at_location(SOUND_BALLOON_POP, peep->x, peep->y, peep->z);
}
bool isBalloonPopped = false;
if (peep->x != SPRITE_LOCATION_NULL) {
create_balloon(peep->x, peep->y, peep->z + 9, peep->balloon_colour, bl);
if ((scenario_rand() & 0xFFFF) <= 13107) {
isBalloonPopped = true;
audio_play_sound_at_location(SOUND_BALLOON_POP, peep->x, peep->y, peep->z);
}
create_balloon(peep->x, peep->y, peep->z + 9, peep->balloon_colour, isBalloonPopped);
}
peep->item_standard_flags &= ~PEEP_ITEM_BALLOON;
peep->window_invalidate_flags |= PEEP_INVALIDATE_PEEP_INVENTORY;
}
@@ -2105,7 +2097,7 @@ static void peep_update_falling(rct_peep* peep){
peep->item_standard_flags &= ~PEEP_ITEM_BALLOON;
if (peep->sprite_type == PEEP_SPRITE_TYPE_BALLOON && peep->x != MAP_LOCATION_NULL) {
create_balloon(peep->x, peep->y, height, peep->balloon_colour, 0);
create_balloon(peep->x, peep->y, height, peep->balloon_colour, false);
peep->window_invalidate_flags |= PEEP_INVALIDATE_PEEP_INVENTORY;
peep_update_sprite_type(peep);
}
@@ -6987,7 +6979,7 @@ void peep_applause()
if (peep->item_standard_flags & PEEP_ITEM_BALLOON) {
peep->item_standard_flags &= ~PEEP_ITEM_BALLOON;
if (peep->x != MAP_LOCATION_NULL) {
create_balloon(peep->x, peep->y, peep->z + 9, peep->balloon_colour, 0);
create_balloon(peep->x, peep->y, peep->z + 9, peep->balloon_colour, false);
peep->window_invalidate_flags |= PEEP_INVALIDATE_PEEP_INVENTORY;
peep_update_sprite_type(peep);
}

View File

@@ -0,0 +1,145 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "../network/network.h"
extern "C"
{
#include "../audio/audio.h"
#include "../scenario/scenario.h"
#include "../util/util.h"
#include "sprite.h"
}
bool rct_sprite::IsBalloon()
{
return this->balloon.sprite_identifier == SPRITE_IDENTIFIER_MISC &&
this->balloon.misc_identifier == SPRITE_MISC_BALLOON;
}
rct_balloon * rct_sprite::AsBalloon()
{
rct_balloon * result = nullptr;
if (IsBalloon())
{
result = (rct_balloon *)this;
}
return result;
}
void rct_balloon::Update()
{
invalidate_sprite_2((rct_sprite *)this);
if (popped == 1)
{
frame += 256;
if (frame >= 1280)
{
sprite_remove((rct_sprite *)this);
}
}
else
{
sint32 original_var26a = var_26a;
var_26a += 85;
if (original_var26a >= 255 - 85)
{
var_26b++;
sprite_move(x, y, z + 1, (rct_sprite*)this);
sint32 maxZ = 1967 - ((x ^ y) & 31);
if (z >= maxZ)
{
Pop();
}
}
}
}
void rct_balloon::Press()
{
if (popped != 1)
{
// There is a random chance that pressing the balloon will not pop it
// and instead shift it slightly
uint32 random = scenario_rand();
if ((sprite_index & 7) || (random & 0xFFFF) < 0x2000)
{
Pop();
}
else
{
sint16 shift = ((random & 0x80000000) ? -6 : 6);
sprite_move(x + shift, y, z, (rct_sprite *)this);
}
}
}
void rct_balloon::Pop()
{
popped = 1;
frame = 0;
audio_play_sound_at_location(SOUND_BALLOON_POP, x, y, z);
}
static money32 game_command_balloon_press(uint16 spriteIndex, uint8 flags)
{
rct_sprite * sprite = try_get_sprite(spriteIndex);
if (sprite == nullptr || !sprite->IsBalloon())
{
log_error("Tried getting invalid sprite for balloon: %u", spriteIndex);
return MONEY32_UNDEFINED;
}
else
{
if (flags & GAME_COMMAND_FLAG_APPLY)
{
sprite->AsBalloon()
->Press();
}
return 0;
}
}
extern "C"
{
void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, bool isPopped)
{
rct_sprite* sprite = create_sprite(2);
if (sprite != nullptr)
{
sprite->balloon.var_14 = 13;
sprite->balloon.var_09 = 22;
sprite->balloon.var_15 = 11;
sprite->balloon.sprite_identifier = SPRITE_IDENTIFIER_MISC;
sprite_move(x, y, z, sprite);
sprite->balloon.misc_identifier = SPRITE_MISC_BALLOON;
sprite->balloon.frame = 0;
sprite->balloon.colour = colour;
sprite->balloon.popped = (isPopped ? 1 : 0);
}
}
void balloon_update(rct_balloon * balloon)
{
balloon->Update();
}
void game_command_balloon_press(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp)
{
*ebx = game_command_balloon_press(*eax & 0xFFFF, *ebx & 0xFF);
}
}

View File

@@ -1,122 +0,0 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "../audio/audio.h"
#include "../network/network.h"
#include "../scenario/scenario.h"
#include "../util/util.h"
#include "sprite.h"
/**
*
* rct2: 0x006736C7
*/
void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, uint8 bl)
{
rct_sprite* sprite = create_sprite(2);
if (sprite != NULL) {
sprite->balloon.var_14 = 13;
sprite->balloon.var_09 = 22;
sprite->balloon.var_15 = 11;
sprite->balloon.sprite_identifier = SPRITE_IDENTIFIER_MISC;
sprite_move(x, y, z, sprite);
sprite->balloon.misc_identifier = SPRITE_MISC_BALLOON;
sprite->balloon.frame = 0;
sprite->balloon.colour = colour;
sprite->balloon.popped = bl;
}
}
static void balloon_pop(rct_balloon *balloon)
{
balloon->popped = 1;
balloon->frame = 0;
audio_play_sound_at_location(SOUND_BALLOON_POP, balloon->x, balloon->y, balloon->z);
}
/**
*
* rct2: 0x0067342C
*/
void balloon_update(rct_balloon *balloon)
{
invalidate_sprite_2((rct_sprite*)balloon);
if (balloon->popped == 1) {
balloon->frame += 256;
if (balloon->frame >= 1280)
sprite_remove((rct_sprite*)balloon);
return;
}
sint32 original_var26a = balloon->var_26a;
balloon->var_26a += 85;
if (original_var26a < 255 - 85)
return;
balloon->var_26b++;
sprite_move(balloon->x, balloon->y, balloon->z + 1, (rct_sprite*)balloon);
sint32 maxZ = 1967 - ((balloon->x ^ balloon->y) & 31);
if (balloon->z < maxZ)
return;
balloon_pop(balloon);
}
/**
*
* rct2: 0x006E88ED
*/
static void balloon_press(rct_balloon *balloon)
{
if (balloon->popped == 1)
return;
uint32 random = scenario_rand();
if ((balloon->sprite_index & 7) || (random & 0xFFFF) < 0x2000) {
balloon_pop(balloon);
return;
}
sprite_move(
balloon->x + ((random & 0x80000000) ? -6 : 6),
balloon->y,
balloon->z,
(rct_sprite*)balloon
);
}
void game_command_balloon_press(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp)
{
uint32 balloon_num = *eax;
sint32 flags = *ebx;
*ebx = 0;
if (!(flags & GAME_COMMAND_FLAG_APPLY)) {
return;
}
if (balloon_num >= MAX_SPRITES) {
log_error("Tried getting invalid sprite for balloon: %u", balloon_num);
*ebx = MONEY32_UNDEFINED;
return;
}
rct_sprite* sprite = get_sprite(balloon_num);
if (sprite != NULL && sprite->balloon.sprite_identifier == SPRITE_IDENTIFIER_MISC && sprite->balloon.misc_identifier == SPRITE_MISC_BALLOON) {
balloon_press(&sprite->balloon);
}
}

View File

@@ -45,6 +45,16 @@ static rct_xyz16 _spritelocations2[MAX_SPRITES];
static size_t GetSpatialIndexOffset(sint32 x, sint32 y);
rct_sprite *try_get_sprite(size_t spriteIndex)
{
rct_sprite * sprite = NULL;
if (spriteIndex < MAX_SPRITES)
{
sprite = &_spriteList[spriteIndex];
}
return sprite;
}
rct_sprite *get_sprite(size_t sprite_idx)
{
openrct2_assert(sprite_idx < MAX_SPRITES, "Tried getting sprite %u", sprite_idx);

View File

@@ -127,6 +127,13 @@ typedef struct rct_balloon {
uint8 pad_28[4];
uint8 colour; // 0x2C
uint8 var_2D;
#ifdef __cplusplus
void Update();
void Pop();
void Press();
#endif
} rct_balloon;
assert_struct_size(rct_balloon, 0x2e);
@@ -337,6 +344,12 @@ typedef union {
rct_crashed_vehicle_particle crashed_vehicle_particle;
rct_crash_splash crash_splash;
rct_steam_particle steam_particle;
#ifdef __cplusplus
bool IsBalloon();
rct_balloon * AsBalloon();
#endif
} rct_sprite;
assert_struct_size(rct_sprite, 0x100);
@@ -376,6 +389,7 @@ enum {
LITTER_TYPE_EMPTY_BOWL_BLUE,
};
rct_sprite *try_get_sprite(size_t spriteIndex);
rct_sprite *get_sprite(size_t sprite_idx);
#ifdef NO_RCT2
@@ -414,7 +428,7 @@ void sprite_position_tween_reset();
///////////////////////////////////////////////////////////////
// Balloon
///////////////////////////////////////////////////////////////
void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, uint8 bl);
void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, bool isPopped);
void balloon_update(rct_balloon *balloon);
void game_command_balloon_press(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp);