Use PEEP_SPRITE_TYPE enum

Use the PEEP_SPRITE_TYPE enum for rct_peep::sprite_type so we get type safety on it.
This commit is contained in:
Richard Fine 2019-01-01 22:40:59 +00:00
parent 88850cdab2
commit f3292194f5
5 changed files with 17 additions and 15 deletions

View File

@ -6644,7 +6644,7 @@ static bool peep_find_ride_to_look_at(rct_peep* peep, uint8_t edge, uint8_t* rid
}
/* Part of 0x0069B8CC rct2: 0x0069BC31 */
void rct_peep::SetSpriteType(uint8_t new_sprite_type)
void rct_peep::SetSpriteType(PEEP_SPRITE_TYPE new_sprite_type)
{
if (sprite_type == new_sprite_type)
return;
@ -6684,7 +6684,7 @@ struct item_pref_t
{
uint8_t type; // 0 for standard, 1 for extra
uint32_t item; // And this with the relevant flags
uint8_t sprite_type;
PEEP_SPRITE_TYPE sprite_type;
};
// clang-format off
@ -6720,7 +6720,7 @@ static item_pref_t item_order_preference[] = {
{ 0, PEEP_ITEM_BALLOON, PEEP_SPRITE_TYPE_BALLOON },
{ 0, PEEP_ITEM_HAT, PEEP_SPRITE_TYPE_HAT },
{ 1, PEEP_ITEM_SUNGLASSES, PEEP_SPRITE_TYPE_SUNGLASSES },
{ 0xFF, 0xFFFFFFFF, 0xFF}
{ 0xFF, 0xFFFFFFFF, PEEP_SPRITE_TYPE_INVALID }
};
// clang-format on

View File

@ -443,7 +443,7 @@ enum PEEP_ITEM
PEEP_ITEM_EMPTY_BOWL_BLUE = (1 << 21),
};
enum PEEP_SPRITE_TYPE
enum PEEP_SPRITE_TYPE : uint8_t
{
PEEP_SPRITE_TYPE_NORMAL = 0,
PEEP_SPRITE_TYPE_HANDYMAN = 1,
@ -494,6 +494,8 @@ enum PEEP_SPRITE_TYPE
PEEP_SPRITE_TYPE_SOUP = 46,
PEEP_SPRITE_TYPE_SANDWICH = 47,
PEEP_SPRITE_TYPE_COUNT,
PEEP_SPRITE_TYPE_INVALID = 255
};
// Flags used by peep->window_invalidate_flags
@ -556,7 +558,7 @@ struct rct_peep
uint8_t outside_of_park; // 0x2A
PEEP_STATE state; // 0x2B
uint8_t sub_state; // 0x2C
uint8_t sprite_type; // 0x2D
PEEP_SPRITE_TYPE sprite_type; // 0x2D
PEEP_TYPE type; // 0x2E
union
{
@ -838,7 +840,7 @@ public: // Guest
void CheckCantFindRide();
void CheckCantFindExit();
bool DecideAndBuyItem(uint8_t rideIndex, int32_t shopItem, money32 price);
void SetSpriteType(uint8_t new_sprite_type);
void SetSpriteType(PEEP_SPRITE_TYPE new_sprite_type);
};
assert_struct_size(rct_peep, 0x100);
#pragma pack(pop)

View File

@ -284,17 +284,17 @@ static money32 staff_hire_new_staff_member(
};
/* rct2: 0x009929FC */
static constexpr const uint8_t spriteTypes[] = {
static constexpr const PEEP_SPRITE_TYPE spriteTypes[] = {
PEEP_SPRITE_TYPE_HANDYMAN,
PEEP_SPRITE_TYPE_MECHANIC,
PEEP_SPRITE_TYPE_SECURITY,
PEEP_SPRITE_TYPE_ENTERTAINER_PANDA,
};
uint8_t sprite_type = spriteTypes[staff_type];
PEEP_SPRITE_TYPE sprite_type = spriteTypes[staff_type];
if (staff_type == STAFF_TYPE_ENTERTAINER)
{
sprite_type = PEEP_SPRITE_TYPE_ENTERTAINER_PANDA + entertainerType;
sprite_type = static_cast<PEEP_SPRITE_TYPE>(PEEP_SPRITE_TYPE_ENTERTAINER_PANDA + entertainerType);
}
newPeep->name_string_idx = staffNames[staff_type];
newPeep->sprite_type = sprite_type;
@ -402,8 +402,7 @@ void game_command_set_staff_order(
rct_peep* peep = &get_sprite(sprite_id)->peep;
if (order_id & 0x80)
{ // change costume
uint8_t sprite_type = order_id & ~0x80;
sprite_type += 4;
auto sprite_type = static_cast<PEEP_SPRITE_TYPE>((order_id & ~0x80) + 4);
if (sprite_type >= std::size(peep_slow_walking_types))
{
log_error("Invalid change costume order for sprite_type %u", sprite_type);
@ -2300,7 +2299,7 @@ void rct_peep::Tick128UpdateStaff()
if (staff_type != STAFF_TYPE_SECURITY)
return;
uint8_t newSpriteType = PEEP_SPRITE_TYPE_SECURITY_ALT;
PEEP_SPRITE_TYPE newSpriteType = PEEP_SPRITE_TYPE_SECURITY_ALT;
if (state != PEEP_STATE_PATROLLING)
newSpriteType = PEEP_SPRITE_TYPE_SECURITY;

View File

@ -66,9 +66,9 @@ namespace RCT1
return map[colour];
}
uint8_t GetPeepSpriteType(uint8_t rct1SpriteType)
PEEP_SPRITE_TYPE GetPeepSpriteType(uint8_t rct1SpriteType)
{
static constexpr const uint8_t map[] =
static constexpr const PEEP_SPRITE_TYPE map[] =
{
PEEP_SPRITE_TYPE_NORMAL, // 0x00
PEEP_SPRITE_TYPE_HANDYMAN, // 0x01

View File

@ -10,6 +10,7 @@
#pragma once
#include "../common.h"
#include "../peep/Peep.h"
#include <vector>
@ -21,7 +22,7 @@ namespace RCT1
};
colour_t GetColour(colour_t colour);
uint8_t GetPeepSpriteType(uint8_t rct1SpriteType);
PEEP_SPRITE_TYPE GetPeepSpriteType(uint8_t rct1SpriteType);
uint8_t GetTerrain(uint8_t terrain);
uint8_t GetTerrainEdge(uint8_t terrainEdge);